📄 mp4audec.c
字号:
/**********************************************************************MPEG-4 Audio VMDecoder frame workThis software module was originally developed byHeiko Purnhagen (University of Hannover / ACTS-MoMuSys)and edited byNaoya Tanaka (Matsushita Communication Industrial Co., Ltd.)Ralph Sperschneider (Fraunhofer Gesellschaft IIS)Ali Nowbakht-Irani (Fraunhofer Gesellschaft IIS)in the course of development of the MPEG-2 NBC/MPEG-4 Audio standardISO/IEC 13818-7, 14496-1,2 and 3. This software module is animplementation of a part of one or more MPEG-2 NBC/MPEG-4 Audio toolsas specified by the MPEG-2 NBC/MPEG-4 Audio standard. ISO/IEC givesusers of the MPEG-2 NBC/MPEG-4 Audio standards free license to thissoftware module or modifications thereof for use in hardware orsoftware products claiming conformance to the MPEG-2 NBC/ MPEG-4 Audiostandards. Those intending to use this software module in hardware orsoftware products are advised that this use may infringe existingpatents. The original developer of this software module and his/hercompany, the subsequent editors and their companies, and ISO/IEC haveno liability for use of this software module or modifications thereofin an implementation. Copyright is not released for non MPEG-2NBC/MPEG-4 Audio conforming products. The original developer retainsfull right to use the code for his/her own purpose, assign or donatethe code to a third party and to inhibit third party from using thecode for non MPEG-2 NBC/MPEG-4 Audio conforming products. Thiscopyright notice must be included in all copies or derivative works.Copyright (c) 1997.Source file: mp4dec.c$Id: mp4audec.c,v 1.15 1999/08/09 16:21:39 purnhage Exp $Required modules:common.o common modulecmdline.o command line modulebitstream.o bit stream moduleaudio.o audio i/o moduledec_par.o decoder core (parametric)dec_lpc.o decoder core (CELP)dec_tf.o decoder core (T/F)dec_g729.o decoder core (G729)dec_g723.o decoder core (G723)Authors:HP Heiko Purnhagen, Uni Hannover <purnhage@tnt.uni-hannover.de>NT Naoya Tanaka, Panasonic <natanaka@telecom.mci.mei.co.jp>BT Bodo Teichmann, FhG/IIS <tmn@iis.fhg.de>CCETT N.N., CCETT <@ccett.fr>Changes:18-jun-96 HP first version19-jun-96 HP added .wav format / using new ComposeFileName()26-jun-96 HP improved handling of switch -o04-jul-96 HP joined with t/f code by BG09-aug-96 HP adapted to new cmdline module, added mp4.h16-aug-96 HP adapted to new dec.h added multichannel signal handling added cmdline parameters for numChannel, fSample26-aug-96 HP CVS03-sep-96 HP added speed change & pitch change for parametric core30-oct-96 HP additional frame work options15-nov-96 HP adapted to new bitstream module18-nov-96 HP changed int to long where required added bit stream header options10-dec-96 HP added variable bit rate10-jan-97 HP using BsGetSkip()23-jan-97 HP added audio i/o module03-feb-97 HP audio module bug fix07-feb-97 NT added PICOLA speed control14-mar-97 HP merged FhG AAC code21-mar-97 BT various changes (t/f, AAC)04-apr-97 HP new option -r for scalable decoder26-mar-97 CCETT added G729 decoder07-apr-97 HP i/o filename handling improved / "-" supported05-nov-97 HP update by FhG/UER30-mar-98 HP added ts option06-may-98 HP aacEOF07-jul-98 HP improved bitrate statistics debug output02-dec-98 HP merged most FDIS contributions ...20-jan-99 HP due to the nature of some of the modifications merged into this code, I disclaim any responsibility for this code and/or its readability -- sorry ...21-jan-99 HP trying to clean up a bit ...22-jan-99 HP stdin/stdout "-" support, -d 1 uses stderr22-apr-99 HP merging all contributions**********************************************************************/#include <assert.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include "block.h" /* handler, defines, enums */#include "buffersHandle.h" /* handler, defines, enums */#include "concealmentHandle.h" /* handler, defines, enums */#include "interface.h" /* handler, defines, enums */#include "mod_bufHandle.h" /* handler, defines, enums */#include "reorderspecHandle.h" /* handler, defines, enums */#include "resilienceHandle.h" /* handler, defines, enums */#include "tf_mainHandle.h" /* handler, defines, enums */#include "nok_ltp_common.h" /* structs */#include "bitstreamStruct.h" /* structs */#include "obj_descr.h" /* structs */#include "tf_mainStruct.h" /* structs */#include "adif.h"#include "common_m4a.h" /* common module */#include "cmdline.h" /* command line module */#include "bitstream.h" /* bit stream module */#include "audio.h" /* audio i/o module */#include "mp4au.h" /* frame work common declarations */#include "flex_mux.h"#include "lpc_common.h"#include "hvxc_struct.h" /* struct for HVXC(AI 990616) */#include "dec_par.h" /* decoder cores ... */#include "dec_lpc.h"#include "dec_tf.h"#include "dec_g723.h"#include "dec_g729.h"#include "plotmtv.h"#include "pan_picola.h" /* for speed control (PICOLA) */#include "buffers.h"#ifdef MP4FF#include "mp4ifc.h"#endif/* ---------- declarations ---------- */#define PROGVER "MPEG-4 Natural Audio Decoder V1.0 30-Jul-1999"#define CVSID "$Id: mp4audec.c,v 1.15 1999/08/09 16:21:39 purnhage Exp $"#ifndef max#define max(a,b) ((a) > (b) ? (a) : (b))#endif/* ---------- variables ---------- *//* command line module */static float decBitRate;static int decBitRateUsed;static int numChannelOut;static float fSampleOut;static float speedFact;static float pitchFact;static float regionStart;static float regionDurat;static int regionDuratUsed;static char* decPara;static char* outFileName;static int outFileNameUsed;static char* bitPath;static char* decPath;static int bitPathUsed;static int decPathUsed;static char* bitExt;static char* decExt;static int decExtUsed;static int testBitStream = 0;static int bitBufSize;static int mainDebugLevel;static int audioDebugLevel;static int bitDebugLevel;static int cmdDebugLevel;static char* aacDebugString; /* Debug options for aac */static int epDebugLevel;static int* varArgIdx;/* memory for following data should be allocated dynamically in the future */static FRAME_DATA frameData;static TF_DATA tfData;static LPC_DATA lpcData;static ntt_DATA nttData;static FAULT_TOLERANT_DATA faultData;static HANDLE_FAULT_TOLERANT hFault = &faultData;static HvxcDecStatus *hvxcData; /* HVXC decoder handle (AI 990616) */#ifdef DEBUGPLOTextern int framePlot; /* global for debugging purposes */extern int firstFrame;#endifstatic int frame;static int aacEOF = 0; /* HP 980506 AAC bitstream EOF detection */extern int samplFreqIndex[]; /* undesired, but ... *//* for speed control (PICOLA) */static int SpeedControlMode;static CmdLinePara paraList[] = { {&varArgIdx,NULL,"<bit stream file(s) (- = stdin)>"}, {NULL,NULL,NULL}};static CmdLineSwitch switchList[] = { {"h",NULL,NULL,NULL,NULL,"print help"}, {"r",&decBitRate,"%f",NULL,&decBitRateUsed, "decoder bit rate for scalability [bit/s]\n" "(dflt: encoder bit rate)"}, {"n",&numChannelOut,"%d","0",NULL,"number of audio channels " "(0=as original)"}, {"s",&fSampleOut,"%f","0",NULL,"sampling frequency [Hz] " "(0=as original)"}, {"sf",&speedFact,"%f","1",NULL,"speed change factor"}, {"pf",&pitchFact,"%f","1",NULL,"pitch change factor"}, {"c",&decPara,"%s","",NULL, "decoder parameter string"}, {"ts",®ionStart,"%f","0",NULL,"start time of decoded region [sec]"}, {"td",®ionDurat,"%f",NULL,®ionDuratUsed, "duration of decoded region [sec]\n" "(dflt: until end of bit stream)"}, {"o",&outFileName,"%s",NULL,&outFileNameUsed, "output file name (- = stdout)"}, {"pb",&bitPath,"%s",NULL,&bitPathUsed, "default path bit stream files (dflt: $" MP4_BIT_PATH_ENV ")"}, {"pd",&decPath,"%s",NULL,&decPathUsed, "default path decoded audio files (dflt: $" MP4_DEC_PATH_ENV ")"}, {"eb",&bitExt,"%s",MP4_BIT_EXT,NULL,"bit stream file extension"}, {"ed",&decExt,"%s",NULL,&decExtUsed, "decoded audio file extension\n" "supported file formats: .au, .snd, .wav, .aif, .raw\n" "(dflt: $" MP4_DEC_FMT_ENV " / " MP4_DEC_EXT ")\n" "(raw format: integer16, native)"}, {"t",&testBitStream,NULL,NULL,NULL,"test bit stream (decoder disabled)"}, {"bb",&bitBufSize,"%i",def2str(MAXREADAHEAD),NULL, "bitstream buffer size [bit]"}, {"d",&mainDebugLevel,"%i","0",NULL,"main debug level"},#ifdef DEBUGPLOT {"ps",&firstFrame,"%i","9999",NULL,"start plot at frame%"},#endif {"da",&audioDebugLevel,"%i","0",NULL,"audio file debug level"}, {"db",&bitDebugLevel,"%i","0",NULL,"bit stream debug level"}, {"dc",&cmdDebugLevel,"%i","0",NULL,"cmd line debug level"}, {"daac",&aacDebugString,"%s","",NULL,"[a-Z] Debug Options for aac-Decoder"}, {"dep",&epDebugLevel,"%i","0",NULL,"error protection debug level"}, {"picola", &SpeedControlMode, NULL, NULL, NULL, "speed control by PICOLA"}, {"aaceof", &aacEOF, NULL, NULL, NULL, "AAC bitstream end detection"}, {NULL,NULL,NULL,NULL,NULL,NULL}};/* ---------- functions ---------- */static void flexMuxDecInit ( int* numChannel, char* decPara, /* in: decoder parameter string */ FRAME_DATA* fD, /* config data ,one bitstream buffer for each layer, obj descr. etc. */ TF_DATA* tfD, LPC_DATA* lpcD, ntt_DATA* nttData, HvxcDecStatus** hvxcD, /* AI 990616 */ char* audioFileName, float* fSampleOut ){ unsigned int layer,numLayer; float fSample; int tfInit = 0; char* outLayNr; /* float delayNumSample; */ /* float decBitRate; */ /* int frameMaxNumSample; */ if ( ( outLayNr = strstr( decPara, "-out") ) ){ sscanf(&outLayNr[4],"%d",&(fD->scalOutSelect)); if ( fD->scalOutSelect > 7 ){ CommonExit(-1,"\n errorn in output layer select %d ",fD->scalOutSelect); } if ( mainDebugLevel ) { printf("\n layer nr. %d is selected \n",fD->scalOutSelect); } } fD->scalOutSelect = min(fD->scalOutSelect+1,fD->od->streamCount.value)-1; numLayer=fD->scalOutSelect+1; *fSampleOut = samplFreqIndex[fD->od->ESDescriptor[fD->od->streamCount.value-1]->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.value]; if (fD->scalOutSelect == 0 ) { if ((strstr(decPara, "-celp_mdct") == NULL)){ /* write only core signal at core sampling rate */ *fSampleOut = samplFreqIndex[fD->od->ESDescriptor[0]->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.value]; } else { numLayer++; /* for debugging purposes: init tf layer as well */ } } for ( layer = 0; layer < numLayer; layer++ ){ AUDIO_SPECIFIC_CONFIG *audSpC = &fD->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig; fSample=samplFreqIndex[fD->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.value]; fD->layer[layer].bitBuf = BsAllocBuffer(64000); /* currently in dec_tf.c, line 529 */ switch (audSpC->channelConfiguration.value) { case 1 :*numChannel=1; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -