📄 musicout.c
字号:
/********************************************************************** * ISO MPEG Audio Subgroup Software Simulation Group (1996) * ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension * * $Id: musicout.c.rca 1.2 Fri Dec 13 00:30:54 2002 franklej Experimental $ * * Received from FhG **********************************************************************//********************************************************************** * 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. * *19 aug 92 Soren H. Nielsen Changed MS-DOS file name extensions. * * 8/27/93 Seymour Shlien, Fixes in Unix and MSDOS ports, * * Daniel Lauzon, and * * Bill Truerniet * *--------------------------------------------------------------------* * 4/23/92 J. Pineda Added code for layer III. LayerIII * * Amit Gulati decoding is currently performed in * * two-passes for ease of sideinfo and * * maindata buffering and decoding. * * The second (computation) pass is * * activated with "decode -3 <outfile>" * * 10/25/92 Amit Gulati Modified usage() for layerIII * * 12/10/92 Amit Gulati Changed processing order of re-order- * * -ing step. Fixed adjustment of * * main_data_end pointer to exclude * * side information. * * 9/07/93 Toshiyuki Ishino Integrated Layer III with Ver 3.9. * *--------------------------------------------------------------------* * 11/20/93 Masahiro Iwadare Integrated Layer III with Ver 4.0. * *--------------------------------------------------------------------* * 7/14/94 Juergen Koller Bug fixes in Layer III code * *--------------------------------------------------------------------* * 08/11/94 IIS Bug fixes in Layer III code * *--------------------------------------------------------------------* * 11/04/94 Jon Rowlands Prototype fixes * *--------------------------------------------------------------------* * 7/12/95 Soeren H. Nielsen Changes for LSF Layer I and II * *--------------------------------------------------------------------* * 7/14/94 Juergen Koller Bug fixes in Layer III code * *--------------------------------------------------------------------* * 8/95 Roland Bitto addapdet to MPEG 2 * *--------------------------------------------------------------------* * 11/22/95 Heiko Purnhagen skip ancillary data in bitstream * **********************************************************************/#include "common.h"#include "decoder.h"/********************************************************************/*/* This part contains the MPEG I decoder for Layers I & II./*/*********************************************************************//****************************************************************/*/* For MS-DOS user (Turbo c) change all instance of malloc/* to _farmalloc and free to _farfree. Compiler model hugh/* Also make sure all the pointer specified are changed to far./*/*****************************************************************//* local functions definition */static void usage();static void GetArguments(); /*********************************************************************/*/* Core of the Layer II decoder. Default layer is Layer II./*/*********************************************************************//* Global variable definitions for "musicout.c" */char *programName;int main_data_slots();int side_info_slots();/* Implementations */main(argc, argv)int argc;char **argv;{/*typedef short PCM[2][3][SBLIMIT];*/typedef OUTPUT_TYPE PCM[2][SSLIMIT][SBLIMIT]; PCM FAR *pcm_sample;typedef unsigned int SAM[2][3][SBLIMIT]; SAM FAR *sample;typedef double FRA[2][3][SBLIMIT]; FRA FAR *fraction;typedef double VE[2][HAN_SIZE]; VE FAR *w; Bit_stream_struc bs; frame_params fr_ps; layer info; FILE *musicout; unsigned long sample_frames; int i, j, k, stereo, done=FALSE, clip, sync; int error_protection, crc_error_count, total_error_count; unsigned int old_crc, new_crc; unsigned int bit_alloc[2][SBLIMIT], scfsi[2][SBLIMIT], scale_index[2][3][SBLIMIT]; unsigned long bitsPerSlot, samplesPerFrame, frameNum = 0; unsigned long frameBits, gotBits = 0; IFF_AIFF pcm_aiff_data; Arguments_t Arguments; int Max_gr; int huffman_start; int bit_num = 0; int bbq; FILE *fp_capt_bs; FILE *fp_huffman; FILE *fp_requan; FILE *fp_scalefac; FILE *fp_stereo; FILE *fp_reorder; FILE *fp_antialias; FILE *fp_imdct; FILE *fp_compen; FILE *fp_poly; FILE *fp_capt_codebook; III_scalefac_t III_scalefac;III_side_info_t III_side_info;#ifdef CAPT_CODE_BOOK fp_capt_codebook = fopen("code_book.txt","w+"); if (fp_capt_codebook == NULL) { printf("error! the code book file can't be opened!\n"); fclose(fp_capt_codebook); exit(1); } #endif #ifdef DEBUG_PRINT #ifdef DEBUG_HUFFMAN fp_huffman = fopen("huffman_debug.txt","w+"); if (fp_huffman == NULL) { printf("error! the debug huffman file can't be opened!\n"); fclose(fp_huffman); exit(1); }#endif#ifdef DEBUG_REQUAN fp_requan = fopen("requan_debug.txt","w+"); if (fp_requan == NULL) { printf("error! the debug requan file can't be opened!\n"); fclose(fp_requan); exit(1); }#endif #ifdef DEBUG_SCALEFAC fp_scalefac = fopen("scalefac_debug.txt","w+"); if (fp_scalefac == NULL) { printf("error! the debug scalefac file can't be opened!\n"); fclose(fp_scalefac); exit(1); }#endif#ifdef DEBUG_STEREO fp_stereo = fopen("stereo_debug.txt","w+"); if (fp_stereo == NULL) { printf("error! the debug stereo file can't be opened!\n"); fclose(fp_stereo); exit(1); }#endif #ifdef DEBUG_REORDER fp_reorder = fopen("reorder_debug.txt","w+"); if (fp_reorder == NULL) { printf("error! the debug reorder file can't be opened!\n"); fclose(fp_reorder); exit(1); }#endif #ifdef DEBUG_ANTIALIAS fp_antialias = fopen("antialias_debug.txt","w+"); if (fp_antialias == NULL) { printf("error! the debug antialias file can't be opened!\n"); fclose(fp_antialias); exit(1); }#endif #ifdef DEBUG_IMDCT fp_imdct = fopen("imdct_debug.txt","w+"); if (fp_imdct == NULL) { printf("error! the debug imdct file can't be opened!\n"); fclose(fp_imdct); exit(1); }#endif#ifdef DEBUG_COMPEN fp_compen = fopen("compen_debug.txt","w+"); if (fp_compen == NULL) { printf("error! the debug compensation file can't be opened!\n"); fclose(fp_compen); exit(1); }#endif #ifdef DEBUG_POLY fp_poly = fopen("poly_debug.txt","w+"); if (fp_poly == NULL) { printf("error! the debug polyphase file can't be opened!\n"); fclose(fp_poly); exit(1); }#endif #endif#ifdef CAPT_BS fp_capt_bs = fopen("capt_bs.txt","w+"); if (fp_capt_bs == NULL) { printf("error! the capt_bs file can't be opened!\n"); fclose(fp_capt_bs); exit(1); }#endif #ifdef MACINTOSH console_options.nrows = MAC_WINDOW_SIZE; argc = ccommand(&argv);#endif /* Most large variables are declared dynamically to ensure
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -