📄 musicout.c
字号:
/**********************************************************************
* ISO MPEG Audio Subgroup Software Simulation Group (1996)
* ISO 13818-3 MPEG-2 Audio Multichannel Decoder
*
* $Id: musicout.c 1.11 1996/04/18 05:37:23 rowlands Exp $
*
* $Log: musicout.c $
* Revision 1.11 1996/04/18 05:37:23 rowlands
* Release following Florence meeting
*
* Revision 1.10 1996/02/12 07:13:06 rowlands
* Release following Munich meeting
*
* Revision 1.9.1.1 1996/01/20 17:28:45 rowlands
* Received from Ralf Schwalbe (Telekom FTZ) - includes prediction
*
* Revision 1.7.1.3 1995/08/14 08:13:37 tenkate
* ML-LSF added Warner ten Kate 7/8/95 (Philips)
* debugging
* change "alloc" and "sblimit" into "alloc_ml" and
* "sblimit_ml" where appropriate.
* adapt sample-loops to 6 or 12 depending on half or full ML rate.
*
* Revision 1.7.1.1 1995/07/14 06:12:46 rowlands
* Updated dynamic crosstalk from FTZ: revision FTZ_03
*
* Revision 1.3.3.1 1995/06/16 08:00:46 rowlands
* Input from Sang Wook Kim (Samsung AIT)
*
* Revision 1.3.1.1 1995/06/14 04:36:30 rowlands
* Added support for dematrixing procedure 2.
*
**********************************************************************/
/**********************************************************************
* date programmers comment *
* 2/25/91 Douglas Wong start of version 1.0 records *
* 3/06/91 Douglas Wong rename setup.h to dedef.h *
* removed extraneous variables *
* removed window_samples (now part of *
* filter_samples) *
* 3/07/91 Davis Pan changed output file to "codmusic" *
* 5/10/91 Vish (PRISM) Ported to Macintosh and Unix. *
* Incorporated new "out_fifo()" which *
* writes out last incomplete buffer. *
* Incorporated all AIFF routines which *
* are also compatible with SUN. *
* Incorporated user interface for *
* specifying sound file names. *
* Also incorporated user interface for *
* writing AIFF compatible sound files. *
* 27jun91 dpwe (Aware) Added musicout and &sample_frames as *
* args to out_fifo (were glob refs). *
* Used new 'frame_params' struct. *
* Clean,simplify, track clipped output *
* and total bits/frame received. *
* 7/10/91 Earle Jennings changed to floats to FLOAT *
*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 *
* buffer_CRC and recover_CRC_error *
* Additions and revisions are marked *
* with "dhl" for clarity *
* 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. *
**********************************************************************
* *
* *
* MPEG/audio Phase 2 coding/decoding multichannel *
* *
* Version 1.0 *
* *
* 7/27/93 Susanne Ritscher, IRT Munich *
* *
* thanks to *
* Ralf Schwalbe, Telekom FTZ Berlin *
* Heiko Purnhagen, Uni Hannover *
* *
* Version 2.0 *
* *
* 8/27/93 Susanne Ritscher, IRT Munich *
* Channel-Switching is working *
* *
* Version 2.1 *
* *
* 9/1/93 Susanne Ritscher, IRT Munich *
* all channels normalized *
* *
* Version 3.0 *
* *
* 06/16/94 Ralf Schwalbe, Telekom FTZ Berlin *
* all sources and variables adapted due to MPEG-2 - *
* DIS from March 1994 *
* - dematrix and denormalize procedure *
* - new tc - allocation (0-7) *
* - some new structures and variables as a basis *
* for further decoding modes *
**********************************************************************
* *
* Version 1.0 *
* *
* 11/04/94 Ralf Schwalbe, Telekom FTZ Berlin *
* - decoding tc-allocation *
* - some new subroutines, globale variables and *
* structures (important to handle the ext. bitst.)*
* - changed all functions to ANSI-C funktion header *
* - corrected some bugs to decode bitstreams > 512kB*
* *
* Version 1.1 *
* *
* 12/07/94 Ralf Schwalbe, Telekom FTZ Berlin *
* - decoding extension bitstream *
* *
* Version 1.1.1 *
* Ralf Schwalbe, Telekom FTZ Berlin *
* - fixed some bugs *
* *
* Version 1.2 *
* *
* 6/21/95 Ralf Schwalbe, Deutsche Telekom FTZ Berlin *
* - decoding dynamic crosstalk *
* - decoding phantom center *
* - decoding MPEG1 compatible part only (stereo) *
* - corrected some settings and bugs *
* *
* 7/12/95 Ralf Schwalbe, Deutsche Telekom FTZ Berlin *
* - corrected dynamic crosstalk *
* - 3/2,3/1,3/0,2/1, channel configurations *
* are working *
* *
* 10/31/95 Ralf Schwalbe, Deutsche Telekom FTZ Berlin *
* - decoding of LFE-channel is working *
* - corrected any settings and bugs *
* - corrected table-switch for channel mode < 3/2 *
* and tc-allocation / dyn-crosstalk *
* - still a problem with compl. bitstream 18/19 *
* 01/12/96 Ralf Schwalbe, Deutsche Telekom TZ Darmstadt *
* - decoder prediction installed *
* - problem with compl. bitstream 19 solved, *
* 03/27/96 Ralf Schwalbe, Deutsche Telekom TZ Darmstadt *
* - Multilingual mode adapted for max. 7 channels *
* * *
* Version 2.0 *
* *
* 01/28/97 Frans de Bont, Philips Sound & Vision, Eindhoven *
* - simultaneous use of tc allocation and dynamic *
* crosstalk working for all configurations *
* - prediction working for all configurations *
* - layer 1 MC working *
* - variable bit rate and extension bitstreams *
* - fully compliant to 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 *
* *
**********************************************************************/
#include "common.h"
#include "decoder.h"
/********************************************************************
*
* This part contains the MPEG I / II decoder for Layers II.
*
* Core of the Layer II decoder. Default layer is Layer II.
*
*********************************************************************/
/* Global variable definitions for "musicout.c" */
char *programName;
int Frame_Bits,Bitrate;
double S_freq;
/* Implementations */
main (int argc, char **argv) /* R.S. 7 channels for ML */
{
typedef long PCM[7][3][SBLIMIT];
PCM *pcm_sample;
PCM *pcm_sample_ml; /* 10/03/1995 JMZ Multilingual*/
typedef unsigned int SAM[7][3][SBLIMIT];
SAM *sample;
SAM *sample_ml; /* 10/03/1995 JMZ Multilingual*/
typedef double FRA[7][SBLIMIT][3][12]; /* 7.10.93 R.S. mem - alloc for DOS */
FRA *fraction;
FRA *fraction_ml; /*JMZ 09/03/1995 Multilingual */
typedef double FRA_HELP[12][7][3][SBLIMIT]; /* 10/03/1995 JMZ Multilingual*/
FRA_HELP *fraction_help;
FRA_HELP *fraction_help_ml;
typedef double FRA_BUF[2][8][36+PREDDEL];
FRA_BUF *pred_buf;
typedef double VE[7][HAN_SIZE];
VE *w;
frame_params fr_ps;
layer info;
Bit_stream bs_mpg, bs_ext, bs_mc;
FILE *musicout, *lfe;
FILE *musicout_ml; /* 10/03/1995 JMZ Multilingual*/
unsigned long sample_frames;
unsigned long sample_frames_ml;
int i,jj, j, k, ii, stereo, done=FALSE, clip, sync,f;
int error_protection, crc_check = 1;
int crc_error_count, total_error_count;
int crc_error_count_mc, total_error_count_mc;
#ifdef Augmentation_7ch
int crc_error_count_aug, total_error_count_aug;
#endif
unsigned int old_crc, new_crc;
unsigned int I_bit_alloc[3][7][SBLIMIT];
unsigned int bit_alloc[7][SBLIMIT], scfsi[7][SBLIMIT],
scale_index[7][3][SBLIMIT];
unsigned int bit_alloc_ml[7][SBLIMIT], scfsi_ml[7][SBLIMIT],
scale_index_ml[7][3][SBLIMIT]; /* 09/03/1995 JMZ Multilingual */
unsigned long bitsPerSlot, samplesPerFrame;
IFF_AIFF pcm_aiff_data;
char encoded_file_name[MAX_NAME_SIZE];
char encoded_file_name1[MAX_NAME_SIZE]; /* 8/11/92.sr*/
char decoded_file_name[MAX_NAME_SIZE];
char decoded_file_name_ml[MAX_NAME_SIZE];/* 10/03/1995 JMZ Multilingual*/
char ext_bitstream_name[MAX_NAME_SIZE];
char frame_name[MAX_NAME_SIZE];
char lfe_file_name[MAX_NAME_SIZE];
char t[50];
int need_aiff;
int l, m, print_out = 0, ml =0;
int ch_start,lfe_init = 1;
int tca_log = 0, dynx_log = 0, bits_log = 0, rate_log = 0, scfsi_log = 0, any_log = 0;
short int lfe_tmp[12];
unsigned int sym_sample_ml[12][7][3][SBLIMIT]; /* 18/03/1996 FDB Multilingual*/
int part, layer_I_frames;
int mpeg = 2; /* R.S. mpeg default for mc */
int channels=2, mc_channel=0;
unsigned long frameNum = 0L;
unsigned long frameMod = 1L;
unsigned long frameBits;
/*****************************************************************************/
int hi, hu, ho;
FILE *fp1;
FILE *fp2;
FILE *fp3;
FILE *fp4;
FILE *fp5;
FILE *fp6;
/******************************************************************************/
#ifdef MACINTOSH
console_options.nrows = MAC_WINDOW_SIZE;
argc = ccommand(&argv);
#endif
/* Most large variables are declared dynamically to ensure
compatibility with smaller machines */
pcm_sample = (PCM *) mem_alloc((long) sizeof(PCM), "PCM Samp");
pcm_sample_ml = (PCM *) mem_alloc((long) sizeof(PCM), "PCM Samp");
sample = (SAM *) mem_alloc((long) sizeof(SAM), "Sample");
sample_ml = (SAM *) mem_alloc((long) sizeof(SAM), "Sample");
fraction = (FRA *) mem_alloc((long) sizeof(FRA), "fraction"); /* R.S. */
fraction_ml = (FRA *) mem_alloc((long) sizeof(FRA), "fraction"); /* R.S. */
fraction_help = (FRA_HELP *) mem_alloc((long) sizeof(FRA_HELP), "fraction");
fraction_help_ml = (FRA_HELP *) mem_alloc((long) sizeof(FRA_HELP), "fraction");
pred_buf = (FRA_BUF *) mem_alloc((long) sizeof(FRA_BUF), "pred_buf");
w = (VE *) mem_alloc((long) sizeof(VE), "w");
bs_mpg.header_size = 0;
bs_mpg.bits = (unsigned char *) mem_alloc ((long) 13824, "MPG Bits");
bs_ext.header_size = 0;
bs_ext.bits = (unsigned char *) mem_alloc ((long) 16376, "EXT Bits");
bs_mc.bits = (unsigned char *) mem_alloc ((long) 30208, "MC Bits");
fr_ps.header = &info;
fr_ps.bs_mpg = &bs_mpg;
fr_ps.bs_ext = &bs_ext;
fr_ps.bs_mc = &bs_mc;
fr_ps.tab_num = -1; /* no table loaded */
fr_ps.tab_num_mc = -1; /* no table loaded */
fr_ps.tab_num_ml = -1;
fr_ps.alloc = NULL;
fr_ps.alloc_mc = NULL;
fr_ps.alloc_ml = NULL;
info.mode_ext = 0;
info.version = MPEG_AUDIO_ID;
info.bitrate_index = 0;
info.lfe = 0; /* no low frequency effect channel present! */
info.no_of_multi_lingual_ch = 0;
info.multi_lingual_fs = 0;
info.multi_lingual_layer = 0;
info.ext_bit_stream_present = 0;
info.ext_length = 0;
info.n_ad_bytes = 0; /* 7.12.94 R.S. */
info.lfe = 0;
for (i=0;i<HAN_SIZE;i++) for (j=0;j<5;j++) (*w)[j][i] = 0.0;
program_information();
programName = argv[0];
if(argc==1)
{ /* no command line args -> interact */
do
{
printf ("Enter encoded file name <required>: ");
gets (encoded_file_name);
f = strlen(encoded_file_name)-4; /*cut off extension.8/11/92.sr*/
if (encoded_file_name[0] == NULL_CHAR)
printf ("Encoded file name is required. \n");
} while (encoded_file_name[0] == NULL_CHAR);
printf (">>> Encoded file name is: %s \n", encoded_file_name);
strcpy(encoded_file_name1, encoded_file_name); /*8/11/92.sr*/
strcpy(&encoded_file_name1[f], DFLT_OPEXT_DEC); /*.dec-extension.8/11/92.sr*/
printf ("Enter MPEG decoded file name <%s>: ", encoded_file_name1);
gets (decoded_file_name);
if (decoded_file_name[0] == NULL_CHAR)
strcpy(decoded_file_name, encoded_file_name1);
/* JMZ 10/03/1995 Multilingual */
printf (">>> MPEG decoded file name is: %s \n", decoded_file_name);
/* encoded_file_name1 only for help */
strcpy(encoded_file_name1, encoded_file_name);
strcpy(&encoded_file_name1[f], DFLT_IPEXT_EXT); /* .ext */
printf (">>> Enter MPEG 2 decoded extension filename <%s>: ", encoded_file_name1);
gets(ext_bitstream_name);
if( ext_bitstream_name[0] == NULL_CHAR )
strcpy(ext_bitstream_name, encoded_file_name1);
printf("Extension bitstream <%s> will be decoded \n",ext_bitstream_name);
/* 6/21/95 Ralf Schwalbe: stand a chance to decode MPEG1 compatible part */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -