📄 musicin.c
字号:
/********************************************************************** * ISO MPEG Audio Subgroup Software Simulation Group (1996) * ISO 13818-3 MPEG-2 Audio Multichannel Encoder * * $Id: musicin.c 1.9 1996/02/12 07:13:35 rowlands Exp $ * * $Log: musicin.c $ * Revision 1.9 1996/02/12 07:13:35 rowlands * Release following Munich meeting * * Revision 1.6.2.1 1995/11/06 04:19:12 rowlands * Received from Uwe Felderhoff (IRT) * * Revision 1.8 1995/08/14 07:57:11 tenkate * ML-LSF added Warner ten Kate 7/8/95 (Philips) * debugging (whole packet) * obtain_params() and parse_args() cleaned up. * get_audio_ml() and Psycho_one_ml() only add odd frames upon LSF-ML. * II_smr() is called separately because of that. * sample shifting is added because of that. * * Revision 1.7 1995/07/31 07:49:58 tenkate * addition of phantom coding, at sevral lines, 25/07/95 WtK * * Revision 1.4.3.1 1995/06/16 08:25:11 rowlands * Input from Sang Wook Kim (Samsung AIT) * * Revision 1.4.2.1 1995/06/16 03:46:42 rowlands * Input from Susanne Ritscher (IRT) * * Revision 1.4.1.4 1995/06/16 02:49:33 rowlands * Added dematrix procedure 2 * * Added support for dematrix procedure 2, without predistortion yet. * Calculated the compatible stereo signal subband samples by * transforming the compatible signal used for the psychoacoustics, * instead of recalculating in the subband domain from the other * channels. * **********************************************************************//********************************************************************** * date programmers comment * * 3/01/91 Douglas Wong, start of version 1.1 records * * Davis Pan * * 3/06/91 Douglas Wong, rename: setup.h to endef.h * * removed extraneous variables * * 3/21/91 J.Georges Fritsch introduction of the bit-stream * * package. This package allows you * * to generate the bit-stream in a * * binary or ascii format * * 3/31/91 Bill Aspromonte replaced the read of the SB matrix * * by an "code generated" one * * 5/10/91 W. Joseph Carter Ported to Macintosh and Unix. * * Incorporated Jean-Georges Fritsch's * * "bitstream.c" package. * * Modified to strictly adhere to * * encoded bitstream specs, including * * "Berlin changes". * * Modified user interface dialog & code * * to accept any input & output * * filenames desired. Also added * * de-emphasis prompt and final bail-out * * opportunity before encoding. * * Added AIFF PCM sound file reading * * capability. * * Modified PCM sound file handling to * * process all incoming samples and fill * * out last encoded frame with zeros * * (silence) if needed. * * Located and fixed numerous software * * bugs and table data errors. * * 27jun91 dpwe (Aware Inc) Used new frame_params struct. * * Clear all automatic arrays. * * Changed some variable names, * * simplified some code. * * Track number of bits actually sent. * * Fixed padding slot, stereo bitrate * * Added joint-stereo : scales L+R. * * 6/12/91 Earle Jennings added fix for MS_DOS in obtain_param * * 6/13/91 Earle Jennings added stack length adjustment before * * main for MS_DOS * * 7/10/91 Earle Jennings conversion of all float to FLOAT * * port to MsDos from MacIntosh completed* * 8/ 8/91 Jens Spille Change for MS-C6.00 * * 8/22/91 Jens Spille new obtain_parameters() * *10/ 1/91 S.I. Sudharsanan, Ported to IBM AIX platform. * * Don H. Lee, * * Peter W. Farrett * *10/ 3/91 Don H. Lee implemented CRC-16 error protection * * newly introduced functions are * * I_CRC_calc, II_CRC_calc and encode_CRC* * Additions and revisions are marked * * with "dhl" for clarity * *11/11/91 Katherine Wang Documentation of code. * * (variables in documentation are * * surround by the # symbol, and an '*'* * denotes layer I or II versions) * * 2/11/92 W. Joseph Carter Ported new code to Macintosh. Most * * important fixes involved changing * * 16-bit ints to long or unsigned in * * bit alloc routines for quant of 65535 * * and passing proper function args. * * Removed "Other Joint Stereo" option * * and made bitrate be total channel * * bitrate, irrespective of the mode. * * Fixed many small bugs & reorganized. * * 2/25/92 Masahiro Iwadare made code cleaner and more consistent * *10 jul 92 Susanne Ritscher Bug fix in main, scale factor calc. * * 5 aug 92 Soren H. Nielsen Printout of bit allocation. * *19 aug 92 Soren H. Nielsen Changed MS-DOS file name extensions. * * 2 dec 92 Susanne Ritscher Start of changes to multi-channel with* * several options * * ********************************************************************** * * * * * MPEG/audio Phase 2 coding/decoding multichannel * * * * * * 7/27/93 Susanne Ritscher, IRT Munich * * * * * * 8/13/93 implemented channel-switching by changing * * a lot in encode.c * * * * 8/27/93 Susanne Ritscher, IRT Munich * * Channel-Switching is working * * 9/1/93 Susanne Ritscher, IRT Munich * * all channels normalized * * 9/20/93 channel-switching is only performed at a * * certain limit of TC_ALLOC dB, which is included * * in encoder.h * * 1/04/94 try get all the rubbish out! * * * * * * Version 1.0 * * * * 07/12/94 Susanne Ritscher, IRT Munich * * * * Version 1.1 * * * * 02/23/95 Susanne Ritscher, IRT Munich * * corrected some bugs * * extension bitstream is working * * * * Version 2.0 * * * * 01/28/97 Frans de Bont, Philips Sound & Vision, Eindhoven * * - dynamic crosstalk working for all configurations* * - prediction working for all configurations * * - extension bitstream fixed * * - fully compliant to DIS 13818-3.2 * * * * **********************************************************************//********************************************************************** * * * 06/06/95 Yeon Bae Thomas Kim, Samsung AIT * * ancillary data is working * * * * 06/06/95 Sang Wook Kim, Samsung AIT * * corrected some bugs * * * **********************************************************************/#ifdef MS_DOS#include <dos.h>#endif#include "common.h"#include "encoder.h"#include <math.h>/* Global variable definitions for "musicin.c" */FILE *musicin;FILE *musicin_ml; /* 08/03/1995 JMZ Multilingual */Bit_stream_struc bs;Bit_stream_struc bs_ext;Bit_stream_struc bs_mpg;char *programName;int mesg_index=0; /* YBKim060695 ancillary */int verbosity;char multilingual_file_name[MAX_NAME_SIZE]; /* 08/03/1995 JMZ Multilingual *//* Implementations *//************************************************************************/*/* obtain_parameters/*/* PURPOSE: Prompts for and reads user input for encoding parameters/*/* SEMANTICS: The parameters read are:/* - input and output filenames/* - sampling frequency (if AIFF file, will read from the AIFF file header)/* - layer number/* - mode (stereo, joint stereo, dual channel or mono)/* - psychoacoustic model (I or II)/* - total bitrate, irrespective of the mode/* - de-emphasis, error protection, copyright and original or copy flags/*/************************************************************************/voidobtain_parameters ( frame_params *fr_ps, int *psy, long unsigned int *num_samples, long unsigned int *num_samples_ml, char *original_file_name, char *encoded_file_name, IFF_AIFF *pcm_aiff_data, IFF_AIFF *pcm_aiff_data_ml, int *aiff, int *byte_per_sample, int *mat_mode, int *aug_mat_mode, int *cha_sw, int *aug_cha_sw, char *encoded_file_name_ext, int *bit_rate, char *encoded_file_name_mpg, int *dyn_cr, int *dyn_cr_LR, int *aug_dyn_cr, int *ancillaryUse, int *verbosity){ int j, bool, max_rate, max_rate_index; long int i; int tot_channels = 0; /* 21/03/1995 JMZ Multimode */ char configuration[50]; /* 21/03/1995 JMZ Multimode */ char t[50]; layer *info = fr_ps->header; *aiff = 0; /* flag for AIFF-Soundfile*/ do { printf ("Enter PCM input file name <required>: "); gets (original_file_name); if (original_file_name[0] == NULL_CHAR) printf ("PCM input file name is required.\n"); } while (original_file_name[0] == NULL_CHAR); printf(">>> PCM input file name is: %s\n", original_file_name); if ((musicin = fopen (original_file_name, "rb")) == NULL) { printf ("Could not find \"%s\".\n", original_file_name); exit (1); }/***************************************************************************//* 08/03/1995 Multi lingual extension JMZ */ printf ("Do you have multi lingual channels? (Y)es, (<N>)o: "); gets (multilingual_file_name); if ((*multilingual_file_name == 'Y') || (multilingual_file_name[0] == 'y')) { printf ("Enter multilingual input file name <%s.%s>: ", original_file_name, DFLT_ML_EXT); gets (multilingual_file_name); if (multilingual_file_name[0] == NULL_CHAR) { printf ("Null char\n"); strcat (strcpy (multilingual_file_name, original_file_name), DFLT_ML_EXT); } if ((musicin_ml = fopen (multilingual_file_name, "rb")) == NULL) { printf ("Could not find \"%s\".\n", multilingual_file_name); exit (1); } /*remplir fr_ps il y a au moins un multilingual*/ if (aiff_read_headers (musicin_ml, pcm_aiff_data_ml, byte_per_sample) == 0) { printf (">>> Using Audio IFF multilingual file headers\n"); info->multiling_ch = pcm_aiff_data_ml->numChannels; printf (">>> Using %d multilingual channels\n",info->multiling_ch); *num_samples_ml = pcm_aiff_data_ml->numChannels * pcm_aiff_data_ml->numSampleFrames; } else /* Not using Audio IFF sound file headers. */ { printf ("***WARNING: Could not read AIFF header - No MultiLingual coding!!\n"); info->multiling_ch = 0; } } else { printf ("no multi lingual coding!!\n"); info->multiling_ch = 0; }/* 08/03/1995 Multi lingual extension JMZ *//***************************************************************************/ printf("Enter MPEG encoded output file name <%s%s>: ", original_file_name, DFLT_EXT); gets (encoded_file_name); if (encoded_file_name[0] == NULL_CHAR) { strcat (strcpy (encoded_file_name_ext, original_file_name), DFLT_EXT_EXT); strcat (strcpy (encoded_file_name, original_file_name), DFLT_EXT); strcat (strcpy (encoded_file_name_mpg, encoded_file_name), DFLT_EXT); } else { strcat (strcpy (encoded_file_name_ext, encoded_file_name), DFLT_EXT_EXT); strcat (encoded_file_name, DFLT_EXT); strcat (strcpy (encoded_file_name_mpg, encoded_file_name), DFLT_EXT); } printf(">>> MPEG encoded output file name is: %s\n", encoded_file_name); open_bit_stream_w (&bs, encoded_file_name, BUFFER_SIZE); if (aiff_read_headers (musicin, pcm_aiff_data, byte_per_sample) == 0) { *aiff = 1; printf(">>> Using Audio IFF sound file headers\n");/**********************************************************//* 21/03/1995 JMZ Multimode */ tot_channels = pcm_aiff_data->numChannels; printf (">>> Using %d audio channels\n", tot_channels); /********* 27/01/97, FdB, select LFE ********************/ if (tot_channels > 1) { printf ("Do you want to use LFE coding? (y/<n>) "); gets (t); if ((*t == 'y') || (*t == 'Y')) { printf (">>> LFE coding is used.\n"); info->lfe = 1; } else { printf (">>> No LFE coding.\n"); info->lfe = 0; } }#ifdef Augmentation_7ch if (tot_channels - info->lfe == 7) { if (info->multiling_ch > 0) { printf ("7.1 channel augmentation and multilingual cannot be combined\n"); exit (1); } fr_ps->stereomc = 3; fr_ps->stereoaug = 2; fr_ps->lfe_pos = 3; info->center = 1; info->surround = 2; fr_ps->config = 320; printf (">>> Using 5/2 configuration.\n"); } else#endif if (tot_channels - info->lfe == 5) { fr_ps->stereomc = 3; fr_ps->stereoaug = 0; fr_ps->lfe_pos = 3; printf ("Which configuration do you want to use?\n"); printf ("Available: 3/2 (<1>), 3/0 + 2/0 (2): "); gets (configuration); switch (*configuration) { case '1': info->center = 1; info->surround = 2; fr_ps->config = 320; printf (">>> Using 3/2 configuration.\n"); break; case '2': info->center = 1; info->surround = 3; fr_ps->config = 302; printf (">>> Using 3/0 + 2/0 configuration.\n"); break; default: info->center = 1; info->surround = 2; fr_ps->config = 320; printf (">>> Using default 3/2 configuration.\n"); break; } } else if (tot_channels - info->lfe == 4) { fr_ps->stereomc = 2; fr_ps->stereoaug = 0; printf ("Which configuration do you want to use?\n"); printf ("Available: 3/1 (<1>), 2/2 (2), 2/0 + 2/0 (3): "); gets (configuration); switch (*configuration) { case '1': info->center = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -