📄 mp4audec.c
字号:
case 2 :*numChannel=2; break; default: CommonExit(1,"wrong channel config"); } switch (audSpC->audioDecoderType.value) { case PARA:#if 0 DecParInit(*numChannel,fSample,decBitRate,decPara, bitHeader,&frameMaxNumSample,&delayNumSample );#else#pragma warning "DecParInit is still missing for mp4ff mode " CommonExit(1,"mp4ff for para not yet supported");#endif break; /* AI 990616 */ case HVXC: *hvxcD = DecHvxcInitNew(decPara, fD, layer ); break; case CELP: DecLpcInitNew(decPara, fD, lpcD, layer ); break; case GA: if (!aacEOF) { CommonWarning("Decode: option '-aaceof' is recommended in AAC mode"); } if (tfInit==0){ /* call it only once for all aac layers */ tfInit=1; DecTfInitNew ( decPara, aacDebugString, &hFault->hVm, &hFault->hHcrSpecData, fD, tfD, lpcD, nttData, mainDebugLevel, layer ); } break; default : CommonExit(1,"unknown decoder type"); } } /* for (layer= ...) */}static void flexMuxDec(BsBitStream* bitStream, int numChannel, 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 */ AudioFile* audioFile, HANDLE_FAULT_TOLERANT hFault ){ int i_ch,numBits; unsigned int i; unsigned int layer,frame=0; unsigned int lastLayer = fD->od->streamCount.value-1 ; unsigned int audioDecType,coreDecType ,decType ; unsigned int haveAllAU; int eofFlag=0; /* loop while bit in bitstream */ if ( fD->od->ESDescriptor[lastLayer]->DecConfigDescr.streamType.value != 6) CommonExit(1,"not a audio object"); audioDecType = fD->od->ESDescriptor[lastLayer]->DecConfigDescr.audioSpecificConfig.audioDecoderType.value; coreDecType = fD->od->ESDescriptor[0]->DecConfigDescr.audioSpecificConfig.audioDecoderType.value; decType= audioDecType; lastLayer=fD->scalOutSelect; if (tfD && (tfD->output_select==0) ) { if ((strstr(decPara, "-celp_mdct") == NULL)){ decType= coreDecType; /* write only core signal at core sampling rate */ } else { CommonWarning("output of core at hightlayer sampling rate just for debugging purposes"); /* lastLayer++; */ } } for ( i=0; i<=lastLayer; i++ ){ fD->layer[i].NoAUInBuffer=0;/* each decoder must decrease this by the number of decoded AU */ } while ( ! BsEof ( bitStream, 8)) { /* read until next frame of highest layer and fill bitstream buffers for each layer*/ int debugCnt=0;#ifdef FHG_DEBUGPLOT plotInit(framePlot);#endif haveAllAU=1; for ( i=0; i<=lastLayer; i++ ){ /* does not yet really work if more than one celp AU is needed to decode one combined scalable tf frame , but it will work as long as celp AU are transmitted/stored bevor corresponding AAC AUs */ haveAllAU = haveAllAU & ( (fD->layer[i].NoAUInBuffer>0)?1:0) ; } while((!haveAllAU) && (eofFlag==0)) { eofFlag = nextAccessUnit( bitStream, /* read directly from file */ &layer, /* output : No. of current layer to which this AU belongs to */ fD); debugCnt++; if (debugCnt>19) CommonExit(1,"access unit not found "); /* up to 8 layers are possible, but in case of Celp+AAC up to 12 Celp frame belongs to one AAC frame; (total num of scal. layers <=8; one celp layer (with 12 frames per aac-frame) plus 7 aac layers: 12+7=19 AUs for one frame) this loop assumes that data of all layer are interleaved , order of the AUs is free . but if AU that belongs to one frame are not transmitted/stored together buffer overflow could occure */ haveAllAU=1; for ( i=0; i<=lastLayer; i++ ){ /* does not yet really work if more than one celp AU is needed to decode one combined scalable tf frame , but it will work as long as celp AU are transmitted/stored bevor corresponding AAC AUs */ haveAllAU = haveAllAU & ( (fD->layer[i].NoAUInBuffer>0)?1:0) ; } } if (eofFlag==0) { /* call actual decoding functions */ switch (decType) { case 0 : DecTfFrameNew(numChannel, fD, tfD, lpcD, nttData, hFault , AAC_SCALABLE); /* convert time data from double to float */ for (i_ch=0; i_ch<numChannel; i_ch++){ /* needed to prevent clipping for a 0dB sine wave, tmn990507*/ double fact=((double)32767.0/(double)37594.0); for( i=0; i<(unsigned int)tfD->block_size_samples; i++ ) { tfD->sampleBuf[i_ch][i] = (float)((tfD->time_sample_vector[i_ch][i])*fact); } } AudioWriteData(audioFile,tfD->sampleBuf,tfD->block_size_samples); break; case 1 : DecLpcFrameNew(fD->layer[0].bitBuf, lpcD->sampleBuf, lpcD, &numBits );/* fD->layer[0].bitBuf->numBit -=numBits; * work around as long as celp decoder does not use official bitstream functions */ fD->layer[0].NoAUInBuffer--; /* normaly done by the decoder itself */ AudioWriteData(audioFile,lpcD->sampleBuf,lpcD->frameNumSample); break; case 5: /* hvxc decode using system interface(AI 990616) */ if(SpeedControlMode) { DecHvxcFrame(hvxcD, fD->layer[0].bitBuf, hvxcD->sampleBuf, &numBits, &hvxcD->frameNumSample, 1, pitchFact ); } else { DecHvxcFrame(hvxcD, fD->layer[0].bitBuf, hvxcD->sampleBuf, &numBits, &hvxcD->frameNumSample, speedFact, pitchFact ); } fD->layer[0].NoAUInBuffer--; /* normaly done by the decoder itself */ AudioWriteData(audioFile,hvxcD->sampleBuf,hvxcD->frameNumSample); break; default : CommonExit(1," streamType not yet supported "); break; } /* write audio buffers to file */ if (mainDebugLevel >= 1) { fprintf(stderr,"\rframe %4d ",frame); fflush(stderr); } frame++;#ifdef DEBUGPLOT framePlot++; plotDisplay(0);#endif } } /* endloop , bitstream is empty */}/* Decode() *//* Decode bit stream and generate audio file. *//* (This function evaluates the global xxxDebugLevel variables !!!) */static int Decode ( char *bitFileName, /* in: bit stream file name */ char *audioFileName, /* in: audio file name */ char *audioFileFormat, /* in: audio file format (au, wav, aif, raw) */ float decBitRate, /* in: decoder bit rate (0=as encoder) */ int testBitStream, /* in: 0=normal decoding */ /* 1=test bit stream (disable decoder) */ int numChannelOut, /* in: num audio channels */ float fSampleOut, /* in: sampling frequency [Hz] */ float speedFact, /* in: speed change factor */ float pitchFact, /* in: pitch change factor */ char *decPara, /* in: decoder parameter string */ float regionStart, /* in: start time of region */ float regionDurat /* in: duration of region */ ) /* returns: 0=OK 1=error */{ unsigned int x; int mode; /* enum MP4Mode */ float fSample,fSampleOri,bitRate; long totNumSample; int numChannel,numChannelOri; int frameMaxNumSample,frameBufNumSample,delayNumSample; int frameMinNumBit,frameMaxNumBit; long fSampleLong,bitRateLong; char* info; char* codecMode; int bitReservSize; int bitReservInit; int bitHeaderNumBit; ADIF_INFO adifInfo; BsBitBuffer* bitBuf = NULL; float** sampleBuf = NULL; BsBitStream* bitStream; AudioFile* audioFile = NULL; BsBitBuffer* bitHeader; int numSample; int frameNumBit,frameAvailNumBit,usedNumBit; int frameDecNumBit; int headerNumBit; long totDataNumBit,totPadNumBit; int ch; int bsVersion; int decNumFrame; HANDLE_RESILIENCE hResilience = NULL; HANDLE_BUFFER hVm = NULL; HANDLE_BUFFER hHcrSpecData = NULL; HANDLE_HCR hHcrInfo = NULL; HANDLE_EP_INFO hEpInfo = NULL; HANDLE_CONCEALMENT hConcealment = NULL; OBJECT_DESCRIPTOR objDescr; int decStartFrame; int decodeFrame; /* for speed control (PICOLA) */ float** PicolaBuffer = NULL; static int PicolaDecodeFlag = 1; static int PicolaOutputFlag = 1; long PicolaNumSample; int PicolaNumInputSample; int sn_ovrhd = 0; int refillBits=0; int EOFreached = 0; unsigned char decodeNext;#if 0 int alignBits; int padNumBit;#endif /* init */ if (mainDebugLevel >= 3) { printf("Decode:\n"); printf("bitFileName=\"%s\"\n",bitFileName); printf("audioFileName=\"%s\"\n",audioFileName); printf("audioFileFormat=\"%s\"\n",audioFileFormat); printf("decBitRate=%.3f\n",decBitRate); printf("testBitStream=%d\n",testBitStream); printf("decPara=\"%s\"\n",decPara?decPara:"(NULL)"); printf("regionStart=%.6f\n",regionStart); printf("regionDurat=%.6f\n",regionDurat); } numChannelOri = 1 ; BsInit(bitBufSize,bitDebugLevel,aacEOF); initObjDescr( &objDescr); AudioInit(NULL,audioDebugLevel); info = NULL; /* open bit stream file */ if ((strstr(decPara, "-aac_raw") != NULL) || (strstr(decPara, "-aac_sca") != NULL) || (strstr(decPara, "-aac_core_bsac") != NULL) ) bitStream = BsOpenFileRead(bitFileName,NULL,&info); else bitStream = BsOpenFileRead(bitFileName,MP4_MAGIC,&info); if (bitStream==NULL) { CommonWarning("Decode: error opening bit stream file %s",bitFileName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -