char GetMaximumTnsBands(CIcsInfo *pIcsInfo) { int idx = IsLongBlock(pIcsInfo) ? 0 : 1; COUNT_sub_start("GetMaximumTnsBands"); FUNC(1); MOVE(1); /* counting previous operation */ INDIRECT(1); /* counting post operation */ COUNT_sub_end(); return tns_max_bands_tbl[pIcsInfo->SamplingRateIndex][idx]; }
const short *GetScaleFactorBandOffsets(CIcsInfo *pIcsInfo) { COUNT_sub_start("GetScaleFactorBandOffsets"); FUNC(1); BRANCH(1); if (IsLongBlock(pIcsInfo)) { INDIRECT(1); COUNT_sub_end(); return SamplingRateInfoTable[pIcsInfo->SamplingRateIndex].ScaleFactorBands_Long; } else { INDIRECT(1); COUNT_sub_end(); return SamplingRateInfoTable[pIcsInfo->SamplingRateIndex].ScaleFactorBands_Short; } }
INT CPulseData_Read( HANDLE_FDK_BITSTREAM bs, CPulseData *const PulseData, const SHORT *sfb_startlines, const void *pIcsInfo, const SHORT frame_length ) { int i, k=0; const UINT MaxSfBands = GetScaleFactorBandsTransmitted((CIcsInfo*)pIcsInfo); /* reset pulse data flag */ PulseData->PulseDataPresent = 0; if ((PulseData->PulseDataPresent = (UCHAR) FDKreadBit(bs)) != 0) { if (!IsLongBlock((CIcsInfo*)pIcsInfo)) { return AAC_DEC_DECODE_FRAME_ERROR; } PulseData->NumberPulse = (UCHAR) FDKreadBits(bs,2); PulseData->PulseStartBand = (UCHAR) FDKreadBits(bs,6); if (PulseData->PulseStartBand >= MaxSfBands) { return AAC_DEC_DECODE_FRAME_ERROR; } k = sfb_startlines[PulseData->PulseStartBand]; for (i=0; i<=PulseData->NumberPulse; i++) { PulseData->PulseOffset[i] = (UCHAR) FDKreadBits(bs,5); PulseData->PulseAmp[i] = (UCHAR) FDKreadBits(bs,4); k += PulseData->PulseOffset[i]; } if (k >= frame_length) { return AAC_DEC_DECODE_FRAME_ERROR; } } return 0; }
void CChannel_CodebookTableInit(CAacDecoderChannelInfo *pAacDecoderChannelInfo) { int b, w, maxBands, maxWindows; int maxSfb = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo); UCHAR *pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook; if ( IsLongBlock(&pAacDecoderChannelInfo->icsInfo) ) { maxBands = 64; maxWindows = 1; } else { maxBands = 16; maxWindows = 8; } for (w = 0; w<maxWindows; w++) { for (b = 0; b < maxSfb; b++) { pCodeBook[b] = ESCBOOK; } for (; b<maxBands; b++) { pCodeBook[b] = ZERO_HCB; } pCodeBook += maxBands; } }
AAC_DECODER_ERROR IcsReadMaxSfb ( HANDLE_FDK_BITSTREAM bs, CIcsInfo *pIcsInfo, const SamplingRateInfo *pSamplingRateInfo ) { AAC_DECODER_ERROR ErrorStatus = AAC_DEC_OK; int nbits; if (IsLongBlock(pIcsInfo)) { nbits = 6; pIcsInfo->TotalSfBands = pSamplingRateInfo->NumberOfScaleFactorBands_Long; } else { nbits = 4; pIcsInfo->TotalSfBands = pSamplingRateInfo->NumberOfScaleFactorBands_Short; } pIcsInfo->MaxSfBands = (UCHAR) FDKreadBits(bs, nbits); if (pIcsInfo->MaxSfBands > pIcsInfo->TotalSfBands){ ErrorStatus = AAC_DEC_PARSE_ERROR; } return ErrorStatus; }
/*! The function decodes one aac frame. The decoding of coupling channel elements are not supported. The transport layer might signal, that the data of the current frame is invalid, e.g. as a result of a packet loss in streaming mode. */ int CAacDecoder_DecodeFrame(AACDECODER self, /*!< pointer to aacdecoder structure */ int *frameSize, /*!< pointer to frame size */ int *sampleRate, /*!< pointer to sample rate */ int *numChannels, /*!< pointer to number of channels */ char *channelMode, /*!< mode: 0=mono, 1=stereo */ char frameOK /*!< indicates if current frame data is valid */ ) { unsigned char aacChannels=0; long tmp; unsigned char ch; int type = 0; int ErrorStatus = frameOK; static int BlockNumber = 0; HANDLE_BIT_BUF bs = self->pBs; int previous_element; int channel; COUNT_sub_start("CAacDecoder_DecodeFrame"); MOVE(7); INDIRECT(1); PTR_INIT(1); /* counting previous operations */ /* initialize pointer to CAacDecoderChannelInfo for each channel */ PTR_INIT(4); /* self->pAacDecoderChannelInfo[ch] pAacDecoderChannelInfoInit[ch]; pAacDecoderDynamicDataInit[ch] WorkBufferCore[ch*MaximumBinsLong]; */ LOOP(1); for (ch=0; ch<Channels; ch++) { INDIRECT(1); PTR_INIT(5); self->pAacDecoderChannelInfo[ch] = pAacDecoderChannelInfoInit[ch]; self->pAacDecoderChannelInfo[ch]->pCodeBook = pAacDecoderDynamicDataInit[ch]->aCodeBook; self->pAacDecoderChannelInfo[ch]->pScaleFactor = pAacDecoderDynamicDataInit[ch]->aScaleFactor; self->pAacDecoderChannelInfo[ch]->pSpectralCoefficient = &WorkBufferCore[ch*MaximumBinsLong]; self->pAacDecoderChannelInfo[ch]->pJointStereoData = &pAacDecoderDynamicCommonDataInit->JointStereoData; self->pAacDecoderChannelInfo[ch]->pPnsInterChannelData = &pAacDecoderDynamicCommonDataInit->PnsInterChannelData; self->pAacDecoderChannelInfo[ch]->pPnsStaticInterChannelData = &PnsStaticInterChannelData; } INDIRECT(1); MOVE(1); self->frameOK = 1; PTR_INIT(1); /* self->pAacDecoderChannelInfo[channel] */ LOOP(1); for (channel=0; channel < Channels; channel++) { FUNC(1); CPns_InitPns(self->pAacDecoderChannelInfo[channel]); } INDIRECT(1); FUNC(1); CPns_InitInterChannelData(self->pAacDecoderChannelInfo[0]); MOVE(1); aacChannels = 0; INDIRECT(1); PTR_INIT(1); FUNC(2); ByteAlign(bs,&self->byteAlignBits); MOVE(1); previous_element = ID_END; LOOP(1); while ( (type != ID_END) && self->frameOK ) { ADD(1); LOGIC(1); /* while() condition */ FUNC(2); type = GetBits(bs,3); INDIRECT(1); BRANCH(1); if (bs->cntBits < 0) { INDIRECT(1); MOVE(1); self->frameOK = 0; } BRANCH(1); switch (type) { case ID_SCE: /* Consistency check */ ADD(1); BRANCH(1); if(aacChannels >= Channels){ INDIRECT(1); MOVE(1); self->frameOK = 0; break; } INDIRECT(1); MOVE(1); self->pStreamSbr->sbrElement[self->pStreamSbr->NrElements].ElementID = SBR_ID_SCE; INDIRECT(1); BRANCH(1); if(self->frameOK) { INDIRECT(3); PTR_INIT(1); FUNC(3); ErrorStatus = CSingleChannelElement_Read(bs,self->pAacDecoderChannelInfo,self->pStreamInfo); BRANCH(1); if (ErrorStatus) { INDIRECT(1); MOVE(1); self->frameOK = 0; } } INDIRECT(1); BRANCH(1); if ( self->frameOK ) { INDIRECT(1); FUNC(1); CSingleChannelElement_Decode(self->pAacDecoderChannelInfo); ADD(1); aacChannels += 1; } break; case ID_CPE: /* Consistency check */ ADD(1); BRANCH(1); if(aacChannels >= Channels){ INDIRECT(1); MOVE(1); self->frameOK = 0; break; } INDIRECT(1); MOVE(1); self->pStreamSbr->sbrElement[self->pStreamSbr->NrElements].ElementID = SBR_ID_CPE; INDIRECT(1); BRANCH(1); if (self->frameOK) { INDIRECT(3); PTR_INIT(1); FUNC(3); ErrorStatus = CChannelPairElement_Read(bs,self->pAacDecoderChannelInfo,self->pStreamInfo); BRANCH(1); if (ErrorStatus) { INDIRECT(1); MOVE(1); self->frameOK = 0; } } INDIRECT(1); BRANCH(1); if ( self->frameOK ){ INDIRECT(1); FUNC(1); CChannelPairElement_Decode(self->pAacDecoderChannelInfo); ADD(1); aacChannels += 2; } break; case ID_CCE: INDIRECT(1); MOVE(2); ErrorStatus = AAC_DEC_UNIMPLEMENTED_CCE; self->frameOK = 0; break; case ID_LFE: INDIRECT(1); MOVE(2); ErrorStatus = AAC_DEC_UNIMPLEMENTED_LFE; self->frameOK = 0; break; case ID_DSE: INDIRECT(1); PTR_INIT(1); FUNC(2); CDse_Read(bs, &self->byteAlignBits); break; case ID_PCE: INDIRECT(1); MOVE(2); ErrorStatus = AAC_DEC_UNIMPLEMENTED_PCE; self->frameOK = 0; break; case ID_FIL: INDIRECT(1); MOVE(1); tmp = bs->cntBits; FFRaacplus_checkForPayload(bs,self->pStreamSbr,previous_element); break; case ID_END: break; } MOVE(1); previous_element = type; } /* Update number of channels (if valid) */ INDIRECT(1); BRANCH(1); if (self->frameOK) { INDIRECT(1); MOVE(1); self->pStreamInfo->Channels = aacChannels; } INDIRECT(1); LOGIC(1); STORE(1); self->frameOK = self->frameOK && frameOK; /* Inverse transform */ PTR_INIT(3); /* self->pAacDecoderStaticChannelInfo[ch] self->pAacDecoderChannelInfo[ch] self->pTimeData[ch*MaximumBinsLong] */ INDIRECT(1); LOOP(1); for (ch=0; ch<self->pStreamInfo->Channels; ch++) { /* Conceal erred spectral data */ FUNC(3); CConcealment_Apply(self->pAacDecoderStaticChannelInfo[ch], self->pAacDecoderChannelInfo[ch], self->frameOK); PTR_INIT(1); FUNC(1); BRANCH(1); if (IsLongBlock(&self->pAacDecoderChannelInfo[ch]->IcsInfo)) { PTR_INIT(1); FUNC(4); CLongBlock_FrequencyToTime(self->pAacDecoderStaticChannelInfo[ch], self->pAacDecoderChannelInfo[ch], &self->pTimeData[ch*MaximumBinsLong], 1); } else { PTR_INIT(1); FUNC(4); CShortBlock_FrequencyToTime(self->pAacDecoderStaticChannelInfo[ch], self->pAacDecoderChannelInfo[ch], &self->pTimeData[ch*MaximumBinsLong], 1); } } INDIRECT(1); PTR_INIT(1); FUNC(2); ByteAlign(bs,&self->byteAlignBits); INDIRECT(3); MOVE(3); *frameSize = self->pStreamInfo->SamplesPerFrame; *sampleRate = self->pStreamInfo->SamplingRate; *numChannels = self->pStreamInfo->Channels; ADD(1); BRANCH(1); if (*numChannels == 1) { MOVE(1); *channelMode = 0; } else { BRANCH(1); MOVE(1); if (*numChannels == 2) *channelMode = 1; else *channelMode = 2; } ADD(1); BlockNumber++; COUNT_sub_end(); return ErrorStatus; }
int IcsRead(HANDLE_BIT_BUF bs, CIcsInfo *pIcsInfo) { int i; char mask; char PredictorDataPresent; int ErrorStatus = AAC_DEC_OK; COUNT_sub_start("IcsRead"); MOVE(1); /* counting previous operation */ INDIRECT(1); FUNC(2); STORE(1); pIcsInfo->IcsReservedBit = (char) GetBits(bs,1); INDIRECT(1); FUNC(2); STORE(1); pIcsInfo->WindowSequence = (char) GetBits(bs,2); INDIRECT(1); FUNC(2); STORE(1); pIcsInfo->WindowShape = (char) GetBits(bs,1); FUNC(1); BRANCH(1); if (IsLongBlock(pIcsInfo)) { INDIRECT(2); MOVE(1); pIcsInfo->TotalSfBands = SamplingRateInfoTable[pIcsInfo->SamplingRateIndex].NumberOfScaleFactorBands_Long; INDIRECT(1); FUNC(2); STORE(1); pIcsInfo->MaxSfBands = (char) GetBits(bs,6); FUNC(2); BRANCH(1); if ((PredictorDataPresent = (char) GetBits(bs,1))) { COUNT_sub_end(); return (AAC_DEC_PREDICTION_NOT_SUPPORTED_IN_LC_AAC); } INDIRECT(2); MOVE(2); pIcsInfo->WindowGroups = 1; pIcsInfo->WindowGroupLength[0] = 1; } else { INDIRECT(2); MOVE(1); pIcsInfo->TotalSfBands = SamplingRateInfoTable[pIcsInfo->SamplingRateIndex].NumberOfScaleFactorBands_Short; INDIRECT(1); FUNC(2); STORE(1); pIcsInfo->MaxSfBands = (char) GetBits(bs,4); INDIRECT(1); FUNC(2); STORE(1); pIcsInfo->ScaleFactorGrouping = (char) GetBits(bs,7); INDIRECT(1); MOVE(1); pIcsInfo->WindowGroups = 0 ; PTR_INIT(1); /* pIcsInfo->WindowGroupLength[] */ LOOP(1); for (i=0; i < 7; i++) { ADD(1); SHIFT(1); mask = 1 << (6 - i); MOVE(1); pIcsInfo->WindowGroupLength[i] = 1; INDIRECT(1); LOGIC(1); BRANCH(1); if (pIcsInfo->ScaleFactorGrouping & mask) { INDIRECT(1); ADD(1); STORE(1); pIcsInfo->WindowGroupLength[pIcsInfo->WindowGroups]++; } else { INDIRECT(1); ADD(1); STORE(1); pIcsInfo->WindowGroups++; } } /* loop runs to i < 7 only */ INDIRECT(1); MOVE(1); pIcsInfo->WindowGroupLength[7] = 1; INDIRECT(1); ADD(1); STORE(1); pIcsInfo->WindowGroups++; } INDIRECT(1); MOVE(1); pIcsInfo->Valid = 1; COUNT_sub_end(); return ErrorStatus; }
AAC_DECODER_ERROR CBlock_ReadSectionData(HANDLE_FDK_BITSTREAM bs, CAacDecoderChannelInfo *pAacDecoderChannelInfo, const SamplingRateInfo *pSamplingRateInfo, const UINT flags) { int top, band; int sect_len, sect_len_incr; int group; UCHAR sect_cb; UCHAR *pCodeBook = pAacDecoderChannelInfo->pDynData->aCodeBook; /* HCR input (long) */ SHORT *pNumLinesInSec = pAacDecoderChannelInfo->pDynData->specificTo.aac.aNumLineInSec4Hcr; int numLinesInSecIdx = 0; UCHAR *pHcrCodeBook = pAacDecoderChannelInfo->pDynData->specificTo.aac.aCodeBooks4Hcr; const SHORT *BandOffsets = GetScaleFactorBandOffsets(&pAacDecoderChannelInfo->icsInfo, pSamplingRateInfo); pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection = 0; AAC_DECODER_ERROR ErrorStatus = AAC_DEC_OK; FDKmemclear(pCodeBook, sizeof(UCHAR)*(8*16)); const int nbits = (IsLongBlock(&pAacDecoderChannelInfo->icsInfo) == 1) ? 5 : 3; int sect_esc_val = (1 << nbits) - 1 ; UCHAR ScaleFactorBandsTransmitted = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo->icsInfo); for (group=0; group<GetWindowGroups(&pAacDecoderChannelInfo->icsInfo); group++) { for (band=0; band < ScaleFactorBandsTransmitted; ) { sect_len = 0; if ( flags & AC_ER_VCB11 ) { sect_cb = (UCHAR) FDKreadBits(bs,5); } else sect_cb = (UCHAR) FDKreadBits(bs,4); if ( ((flags & AC_ER_VCB11) == 0) || ( sect_cb < 11 ) || ((sect_cb > 11) && (sect_cb < 16)) ) { sect_len_incr = FDKreadBits(bs, nbits); while (sect_len_incr == sect_esc_val) { sect_len += sect_esc_val; sect_len_incr = FDKreadBits(bs, nbits); } } else { sect_len_incr = 1; } sect_len += sect_len_incr; top = band + sect_len; if (flags & AC_ER_HCR) { /* HCR input (long) -- collecting sideinfo (for HCR-_long_ only) */ if (numLinesInSecIdx >= MAX_SFB_HCR) { return AAC_DEC_PARSE_ERROR; } pNumLinesInSec[numLinesInSecIdx] = BandOffsets[top] - BandOffsets[band]; numLinesInSecIdx++; if (sect_cb == BOOKSCL) { return AAC_DEC_INVALID_CODE_BOOK; } else { *pHcrCodeBook++ = sect_cb; } pAacDecoderChannelInfo->pDynData->specificTo.aac.numberSection++; } /* Check spectral line limits */ if (IsLongBlock( &(pAacDecoderChannelInfo->icsInfo) )) { if (top > 64) { return AAC_DEC_DECODE_FRAME_ERROR; } } else { /* short block */ if (top + group*16 > (8 * 16)) { return AAC_DEC_DECODE_FRAME_ERROR; } } /* Check if decoded codebook index is feasible */ if ( (sect_cb == BOOKSCL) || ( (sect_cb == INTENSITY_HCB || sect_cb == INTENSITY_HCB2) && pAacDecoderChannelInfo->pDynData->RawDataInfo.CommonWindow == 0) ) { return AAC_DEC_INVALID_CODE_BOOK; } /* Store codebook index */ for (; band < top; band++) { pCodeBook[group*16+band] = sect_cb; } } } return ErrorStatus; }
/* * Arbitrary order bitstream parser */ AAC_DECODER_ERROR CChannelElement_Read( HANDLE_FDK_BITSTREAM hBs, CAacDecoderChannelInfo *pAacDecoderChannelInfo[], CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[], const AUDIO_OBJECT_TYPE aot, SamplingRateInfo *pSamplingRateInfo, const UINT flags, const UINT elFlags, const UINT frame_length, const UCHAR numberOfChannels, const SCHAR epConfig, HANDLE_TRANSPORTDEC pTpDec) { AAC_DECODER_ERROR error = AAC_DEC_OK; const element_list_t *list; int i, ch, decision_bit; int crcReg1 = -1, crcReg2 = -1; int cplxPred; int ind_sw_cce_flag = 0, num_gain_element_lists = 0; FDK_ASSERT((numberOfChannels == 1) || (numberOfChannels == 2)); /* Get channel element sequence table */ list = getBitstreamElementList(aot, epConfig, numberOfChannels, 0, elFlags); if (list == NULL) { error = AAC_DEC_UNSUPPORTED_FORMAT; goto bail; } CTns_Reset(&pAacDecoderChannelInfo[0]->pDynData->TnsData); /* Set common window to 0 by default. If signalized in the bit stream it will * be overwritten later explicitely */ pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 0; if (flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) { pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active = 0; pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_on_lr = 0; } if (numberOfChannels == 2) { CTns_Reset(&pAacDecoderChannelInfo[1]->pDynData->TnsData); pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = 0; } cplxPred = 0; if (pAacDecoderStaticChannelInfo != NULL) { if (elFlags & AC_EL_USAC_CP_POSSIBLE) { pAacDecoderChannelInfo[0]->pComData->jointStereoData.cplx_pred_flag = 0; cplxPred = 1; } } if (0 || (flags & (AC_ELD | AC_SCALABLE))) { pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 1; if (numberOfChannels == 2) { pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow; } } /* Iterate through sequence table */ i = 0; ch = 0; decision_bit = 0; do { switch (list->id[i]) { case element_instance_tag: pAacDecoderChannelInfo[0]->ElementInstanceTag = FDKreadBits(hBs, 4); if (numberOfChannels == 2) { pAacDecoderChannelInfo[1]->ElementInstanceTag = pAacDecoderChannelInfo[0]->ElementInstanceTag; } break; case common_window: decision_bit = pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.CommonWindow = FDKreadBits(hBs, 1); if (numberOfChannels == 2) { pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow; } break; case ics_info: /* store last window sequence (utilized in complex stereo prediction) * before reading new channel-info */ if (cplxPred) { if (pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow) { pAacDecoderStaticChannelInfo[0] ->pCpeStaticData->jointStereoPersistentData.winSeqPrev = pAacDecoderChannelInfo[0]->icsInfo.WindowSequence; pAacDecoderStaticChannelInfo[0] ->pCpeStaticData->jointStereoPersistentData.winShapePrev = pAacDecoderChannelInfo[0]->icsInfo.WindowShape; } } /* Read individual channel info */ error = IcsRead(hBs, &pAacDecoderChannelInfo[ch]->icsInfo, pSamplingRateInfo, flags); if (elFlags & AC_EL_LFE && GetWindowSequence(&pAacDecoderChannelInfo[ch]->icsInfo) != BLOCK_LONG) { error = AAC_DEC_PARSE_ERROR; break; } if (numberOfChannels == 2 && pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow) { pAacDecoderChannelInfo[1]->icsInfo = pAacDecoderChannelInfo[0]->icsInfo; } break; case common_max_sfb: if (FDKreadBit(hBs) == 0) { error = IcsReadMaxSfb(hBs, &pAacDecoderChannelInfo[1]->icsInfo, pSamplingRateInfo); } break; case ltp_data_present: if (FDKreadBits(hBs, 1) != 0) { error = AAC_DEC_UNSUPPORTED_PREDICTION; } break; case ms: INT max_sfb_ste; INT max_sfb_ste_clear; max_sfb_ste = GetScaleMaxFactorBandsTransmitted( &pAacDecoderChannelInfo[0]->icsInfo, &pAacDecoderChannelInfo[1]->icsInfo); max_sfb_ste_clear = 64; pAacDecoderChannelInfo[0]->icsInfo.max_sfb_ste = (UCHAR)max_sfb_ste; pAacDecoderChannelInfo[1]->icsInfo.max_sfb_ste = (UCHAR)max_sfb_ste; if (flags & (AC_USAC | AC_RSV603DA) && pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.CommonWindow == 0) { Clean_Complex_Prediction_coefficients( &pAacDecoderStaticChannelInfo[0] ->pCpeStaticData->jointStereoPersistentData, GetWindowGroups(&pAacDecoderChannelInfo[0]->icsInfo), 0, 64); } if (CJointStereo_Read( hBs, &pAacDecoderChannelInfo[0]->pComData->jointStereoData, GetWindowGroups(&pAacDecoderChannelInfo[0]->icsInfo), max_sfb_ste, max_sfb_ste_clear, /* jointStereoPersistentData and cplxPredictionData are only available/allocated if cplxPred is active. */ ((cplxPred == 0) || (pAacDecoderStaticChannelInfo == NULL)) ? NULL : &pAacDecoderStaticChannelInfo[0] ->pCpeStaticData->jointStereoPersistentData, ((cplxPred == 0) || (pAacDecoderChannelInfo[0] == NULL)) ? NULL : pAacDecoderChannelInfo[0] ->pComStaticData->cplxPredictionData, cplxPred, GetScaleFactorBandsTotal(&pAacDecoderChannelInfo[0]->icsInfo), GetWindowSequence(&pAacDecoderChannelInfo[0]->icsInfo), flags)) { error = AAC_DEC_PARSE_ERROR; } break; case global_gain: pAacDecoderChannelInfo[ch]->pDynData->RawDataInfo.GlobalGain = (UCHAR)FDKreadBits(hBs, 8); break; case section_data: error = CBlock_ReadSectionData(hBs, pAacDecoderChannelInfo[ch], pSamplingRateInfo, flags); break; case scale_factor_data_usac: pAacDecoderChannelInfo[ch]->currAliasingSymmetry = 0; /* Set active sfb codebook indexes to HCB_ESC to make them "active" */ CChannel_CodebookTableInit( pAacDecoderChannelInfo[ch]); /* equals ReadSectionData(self, bs) in float soft. block.c line: ~599 */ /* Note: The missing "break" is intentional here, since we need to call * CBlock_ReadScaleFactorData(). */ case scale_factor_data: if (flags & AC_ER_RVLC) { /* read RVLC data from bitstream (error sens. cat. 1) */ CRvlc_Read(pAacDecoderChannelInfo[ch], hBs); } else { error = CBlock_ReadScaleFactorData(pAacDecoderChannelInfo[ch], hBs, flags); } break; case pulse: if (CPulseData_Read( hBs, &pAacDecoderChannelInfo[ch]->pDynData->specificTo.aac.PulseData, pSamplingRateInfo->ScaleFactorBands_Long, /* pulse data is only allowed to be present in long blocks! */ (void *)&pAacDecoderChannelInfo[ch]->icsInfo, frame_length) != 0) { error = AAC_DEC_DECODE_FRAME_ERROR; } break; case tns_data_present: CTns_ReadDataPresentFlag( hBs, &pAacDecoderChannelInfo[ch]->pDynData->TnsData); if (elFlags & AC_EL_LFE && pAacDecoderChannelInfo[ch]->pDynData->TnsData.DataPresent) { error = AAC_DEC_PARSE_ERROR; } break; case tns_data: /* tns_data_present is checked inside CTns_Read(). */ error = CTns_Read(hBs, &pAacDecoderChannelInfo[ch]->pDynData->TnsData, &pAacDecoderChannelInfo[ch]->icsInfo, flags); break; case gain_control_data: break; case gain_control_data_present: if (FDKreadBits(hBs, 1)) { error = AAC_DEC_UNSUPPORTED_GAIN_CONTROL_DATA; } break; case tw_data: break; case common_tw: break; case tns_data_present_usac: if (pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active) { CTns_ReadDataPresentUsac( hBs, &pAacDecoderChannelInfo[0]->pDynData->TnsData, &pAacDecoderChannelInfo[1]->pDynData->TnsData, &pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_on_lr, &pAacDecoderChannelInfo[0]->icsInfo, flags, elFlags, pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow); } else { pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_on_lr = (UCHAR)1; } break; case core_mode: decision_bit = FDKreadBits(hBs, 1); pAacDecoderChannelInfo[ch]->data.usac.core_mode = decision_bit; if ((ch == 1) && (pAacDecoderChannelInfo[0]->data.usac.core_mode != pAacDecoderChannelInfo[1]->data.usac.core_mode)) { /* StereoCoreToolInfo(core_mode[ch] ) */ pAacDecoderChannelInfo[0]->pDynData->RawDataInfo.CommonWindow = 0; pAacDecoderChannelInfo[1]->pDynData->RawDataInfo.CommonWindow = 0; } break; case tns_active: pAacDecoderChannelInfo[0]->pDynData->specificTo.usac.tns_active = FDKreadBit(hBs); break; case noise: if (elFlags & AC_EL_USAC_NOISE) { pAacDecoderChannelInfo[ch] ->pDynData->specificTo.usac.fd_noise_level_and_offset = FDKreadBits(hBs, 3 + 5); /* Noise level */ } break; case lpd_channel_stream: { error = CLpdChannelStream_Read(/* = lpd_channel_stream() */ hBs, pAacDecoderChannelInfo[ch], pAacDecoderStaticChannelInfo[ch], pSamplingRateInfo, flags); } pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_LPD; break; case fac_data: { int fFacDatPresent = FDKreadBit(hBs); /* Wee need a valid fac_data[0] even if no FAC data is present (as * temporal buffer) */ pAacDecoderChannelInfo[ch]->data.usac.fac_data[0] = pAacDecoderChannelInfo[ch]->data.usac.fac_data0; if (fFacDatPresent) { if (elFlags & AC_EL_LFE) { error = AAC_DEC_PARSE_ERROR; break; } /* FAC data present, this frame is FD, so the last mode had to be * ACELP. */ if (pAacDecoderStaticChannelInfo[ch]->last_core_mode != LPD || pAacDecoderStaticChannelInfo[ch]->last_lpd_mode != 0) { pAacDecoderChannelInfo[ch]->data.usac.core_mode_last = LPD; pAacDecoderChannelInfo[ch]->data.usac.lpd_mode_last = 0; /* We can't change the past! So look to the future and go ahead! */ } CLpd_FAC_Read(hBs, pAacDecoderChannelInfo[ch]->data.usac.fac_data[0], pAacDecoderChannelInfo[ch]->data.usac.fac_data_e, CLpd_FAC_getLength( IsLongBlock(&pAacDecoderChannelInfo[ch]->icsInfo), pAacDecoderChannelInfo[ch]->granuleLength), 1, 0); } else { if (pAacDecoderStaticChannelInfo[ch]->last_core_mode == LPD && pAacDecoderStaticChannelInfo[ch]->last_lpd_mode == 0) { /* ACELP to FD transitons without FAC are possible. That is why we zero it out (i.e FAC will not be considered in the subsequent calculations */ FDKmemclear(pAacDecoderChannelInfo[ch]->data.usac.fac_data0, LFAC * sizeof(FIXP_DBL)); } } } break; case esc2_rvlc: if (flags & AC_ER_RVLC) { CRvlc_Decode(pAacDecoderChannelInfo[ch], pAacDecoderStaticChannelInfo[ch], hBs); } break; case esc1_hcr: if (flags & AC_ER_HCR) { CHcr_Read(hBs, pAacDecoderChannelInfo[ch], numberOfChannels == 2 ? ID_CPE : ID_SCE); } break; case spectral_data: error = CBlock_ReadSpectralData(hBs, pAacDecoderChannelInfo[ch], pSamplingRateInfo, flags); if (flags & AC_ELD) { pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_ELDFB; } else { if (flags & AC_HDAAC) { pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_INTIMDCT; } else { pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_IMDCT; } } break; case ac_spectral_data: error = CBlock_ReadAcSpectralData( hBs, pAacDecoderChannelInfo[ch], pAacDecoderStaticChannelInfo[ch], pSamplingRateInfo, frame_length, flags); pAacDecoderChannelInfo[ch]->renderMode = AACDEC_RENDER_IMDCT; break; case coupled_elements: { int num_coupled_elements, c; ind_sw_cce_flag = FDKreadBit(hBs); num_coupled_elements = FDKreadBits(hBs, 3); for (c = 0; c < (num_coupled_elements + 1); c++) { int cc_target_is_cpe; num_gain_element_lists++; cc_target_is_cpe = FDKreadBit(hBs); /* cc_target_is_cpe[c] */ FDKreadBits(hBs, 4); /* cc_target_tag_select[c] */ if (cc_target_is_cpe) { int cc_l, cc_r; cc_l = FDKreadBit(hBs); /* cc_l[c] */ cc_r = FDKreadBit(hBs); /* cc_r[c] */ if (cc_l && cc_r) { num_gain_element_lists++; } } } FDKreadBit(hBs); /* cc_domain */ FDKreadBit(hBs); /* gain_element_sign */ FDKreadBits(hBs, 2); /* gain_element_scale */ } break; case gain_element_lists: { const CodeBookDescription *hcb; UCHAR *pCodeBook; int c; hcb = &AACcodeBookDescriptionTable[BOOKSCL]; pCodeBook = pAacDecoderChannelInfo[ch]->pDynData->aCodeBook; for (c = 1; c < num_gain_element_lists; c++) { int cge; if (ind_sw_cce_flag) { cge = 1; } else { cge = FDKreadBits(hBs, 1); /* common_gain_element_present[c] */ } if (cge) { /* Huffman */ CBlock_DecodeHuffmanWord( hBs, hcb); /* hcod_sf[common_gain_element[c]] 1..19 */ } else { int g, sfb; for (g = 0; g < GetWindowGroups(&pAacDecoderChannelInfo[ch]->icsInfo); g++) { for (sfb = 0; sfb < GetScaleFactorBandsTransmitted( &pAacDecoderChannelInfo[ch]->icsInfo); sfb++) { if (pCodeBook[sfb] != ZERO_HCB) { /* Huffman */ CBlock_DecodeHuffmanWord( hBs, hcb); /* hcod_sf[dpcm_gain_element[c][g][sfb]] 1..19 */ } } } } } } break; /* CRC handling */ case adtscrc_start_reg1: if (pTpDec != NULL) { crcReg1 = transportDec_CrcStartReg(pTpDec, 192); } break; case adtscrc_start_reg2: if (pTpDec != NULL) { crcReg2 = transportDec_CrcStartReg(pTpDec, 128); } break; case adtscrc_end_reg1: case drmcrc_end_reg: if (pTpDec != NULL) { transportDec_CrcEndReg(pTpDec, crcReg1); crcReg1 = -1; } break; case adtscrc_end_reg2: if (crcReg1 != -1) { error = AAC_DEC_DECODE_FRAME_ERROR; } else if (pTpDec != NULL) { transportDec_CrcEndReg(pTpDec, crcReg2); crcReg2 = -1; } break; case drmcrc_start_reg: if (pTpDec != NULL) { crcReg1 = transportDec_CrcStartReg(pTpDec, 0); } break; /* Non data cases */ case next_channel: ch = (ch + 1) % numberOfChannels; break; case link_sequence: list = list->next[decision_bit]; i = -1; break; default: error = AAC_DEC_UNSUPPORTED_FORMAT; break; } if (error != AAC_DEC_OK) { goto bail; } i++; } while (list->id[i] != end_of_sequence); for (ch = 0; ch < numberOfChannels; ch++) { if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_IMDCT || pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_ELDFB) { /* Shows which bands are empty. */ UCHAR *band_is_noise = pAacDecoderChannelInfo[ch]->pDynData->band_is_noise; FDKmemset(band_is_noise, (UCHAR)1, sizeof(UCHAR) * (8 * 16)); error = CBlock_InverseQuantizeSpectralData( pAacDecoderChannelInfo[ch], pSamplingRateInfo, band_is_noise, 1); if (error != AAC_DEC_OK) { return error; } if (elFlags & AC_EL_USAC_NOISE) { CBlock_ApplyNoise(pAacDecoderChannelInfo[ch], pSamplingRateInfo, &pAacDecoderStaticChannelInfo[ch]->nfRandomSeed, band_is_noise); } /* if (elFlags & AC_EL_USAC_NOISE) */ } } bail: if (crcReg1 != -1 || crcReg2 != -1) { if (error == AAC_DEC_OK) { error = AAC_DEC_DECODE_FRAME_ERROR; } if (crcReg1 != -1) { transportDec_CrcEndReg(pTpDec, crcReg1); } if (crcReg2 != -1) { transportDec_CrcEndReg(pTpDec, crcReg2); } } return error; }
/*! \brief Decode channel pair element The function decodes a channel pair element. \return none */ void CChannelElement_Decode( CAacDecoderChannelInfo *pAacDecoderChannelInfo[2], /*!< pointer to aac decoder channel info */ CAacDecoderStaticChannelInfo *pAacDecoderStaticChannelInfo[2], SamplingRateInfo *pSamplingRateInfo, UINT flags, UINT elFlags, int el_channels) { int ch = 0; int maxSfBandsL = 0, maxSfBandsR = 0; int maybe_jstereo = (el_channels > 1); if (flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA) && el_channels == 2) { if (pAacDecoderChannelInfo[L]->data.usac.core_mode || pAacDecoderChannelInfo[R]->data.usac.core_mode) { maybe_jstereo = 0; } } if (maybe_jstereo) { maxSfBandsL = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[L]->icsInfo); maxSfBandsR = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[R]->icsInfo); /* apply ms */ if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) { if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { if (pAacDecoderChannelInfo[L]->data.aac.PnsData.PnsActive || pAacDecoderChannelInfo[R]->data.aac.PnsData.PnsActive) { MapMidSideMaskToPnsCorrelation(pAacDecoderChannelInfo); } } /* if tns_on_lr == 1 run MS */ /* && (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_active == 1) */ if (((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == 1)) || ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) == 0)) { int max_sfb_ste = (INT)(pAacDecoderChannelInfo[L]->icsInfo.max_sfb_ste); CJointStereo_ApplyMS( pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, pAacDecoderChannelInfo[L]->pSpectralCoefficient, pAacDecoderChannelInfo[R]->pSpectralCoefficient, pAacDecoderChannelInfo[L]->pDynData->aSfbScale, pAacDecoderChannelInfo[R]->pDynData->aSfbScale, pAacDecoderChannelInfo[L]->specScale, pAacDecoderChannelInfo[R]->specScale, GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, pSamplingRateInfo), GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), max_sfb_ste, maxSfBandsL, maxSfBandsR, pAacDecoderChannelInfo[L] ->pComData->jointStereoData.store_dmx_re_prev, &(pAacDecoderChannelInfo[L] ->pComData->jointStereoData.store_dmx_re_prev_e), 1); } /* if ( ((elFlags & AC_EL_USAC_CP_POSSIBLE).... */ } /* if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow)*/ /* apply intensity stereo */ /* modifies pAacDecoderChannelInfo[]->aSpecSfb */ if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { if ((pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow == 1) && (el_channels == 2)) { CJointStereo_ApplyIS( pAacDecoderChannelInfo, GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, pSamplingRateInfo), GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), GetScaleFactorBandsTransmitted( &pAacDecoderChannelInfo[L]->icsInfo)); } } } /* maybe_stereo */ for (ch = 0; ch < el_channels; ch++) { if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_LPD) { /* Decode LPD data */ CLpdChannelStream_Decode(pAacDecoderChannelInfo[ch], pAacDecoderStaticChannelInfo[ch], flags); } else { UCHAR noSfbs = GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[ch]->icsInfo); /* For USAC common window: max_sfb of both channels may differ * (common_max_sfb == 0). */ if ((maybe_jstereo == 1) && (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow == 1)) { noSfbs = fMax(maxSfBandsL, maxSfBandsR); } int CP_active = 0; if (elFlags & AC_EL_USAC_CP_POSSIBLE) { CP_active = pAacDecoderChannelInfo[ch] ->pComData->jointStereoData.cplx_pred_flag; } /* Omit writing of pAacDecoderChannelInfo[ch]->specScale for complex stereo prediction since scaling has already been carried out. */ int max_sfb_ste = (INT)(pAacDecoderChannelInfo[L]->icsInfo.max_sfb_ste); if ((!CP_active) || (CP_active && (max_sfb_ste < noSfbs)) || ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == 0))) { CBlock_ScaleSpectralData(pAacDecoderChannelInfo[ch], noSfbs, pSamplingRateInfo); /*Active for the case of TNS applied before MS/CP*/ if ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == 0)) { if (IsLongBlock(&pAacDecoderChannelInfo[ch]->icsInfo)) { for (int i = 0; i < noSfbs; i++) { pAacDecoderChannelInfo[ch]->pDynData->aSfbScale[i] = pAacDecoderChannelInfo[ch]->specScale[0]; } } else { for (int i = 0; i < 8; i++) { for (int j = 0; j < noSfbs; j++) { pAacDecoderChannelInfo[ch]->pDynData->aSfbScale[i * 16 + j] = pAacDecoderChannelInfo[ch]->specScale[i]; } } } } } } } /* End "for (ch = 0; ch < el_channels; ch++)" */ if (maybe_jstereo) { /* apply ms */ if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) { } /* CommonWindow */ else { if (elFlags & AC_EL_USAC_CP_POSSIBLE) { FDKmemclear( pAacDecoderStaticChannelInfo[L] ->pCpeStaticData->jointStereoPersistentData.alpha_q_re_prev, JointStereoMaximumGroups * JointStereoMaximumBands * sizeof(SHORT)); FDKmemclear( pAacDecoderStaticChannelInfo[L] ->pCpeStaticData->jointStereoPersistentData.alpha_q_im_prev, JointStereoMaximumGroups * JointStereoMaximumBands * sizeof(SHORT)); } } } /* if (maybe_jstereo) */ for (ch = 0; ch < el_channels; ch++) { if (pAacDecoderChannelInfo[ch]->renderMode == AACDEC_RENDER_LPD) { } else { if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { /* Use same seed for coupled channels (CPE) */ int pnsCh = (ch > 0) ? L : ch; CPns_UpdateNoiseState( &pAacDecoderChannelInfo[ch]->data.aac.PnsData, pAacDecoderChannelInfo[pnsCh]->data.aac.PnsData.currentSeed, pAacDecoderChannelInfo[ch]->pComData->pnsRandomSeed); } if ((!(flags & (AC_USAC))) || ((flags & (AC_USAC)) && (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_active == 1)) || (maybe_jstereo == 0)) { ApplyTools( pAacDecoderChannelInfo, pSamplingRateInfo, flags, elFlags, ch, pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow); } } /* End "} else" */ } /* End "for (ch = 0; ch < el_channels; ch++)" */ if (maybe_jstereo) { /* apply ms */ if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) { /* if tns_on_lr == 0 run MS */ if ((flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA)) && (pAacDecoderChannelInfo[L]->pDynData->specificTo.usac.tns_on_lr == 0)) { int max_sfb_ste = (INT)(pAacDecoderChannelInfo[L]->icsInfo.max_sfb_ste); CJointStereo_ApplyMS( pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, pAacDecoderChannelInfo[L]->pSpectralCoefficient, pAacDecoderChannelInfo[R]->pSpectralCoefficient, pAacDecoderChannelInfo[L]->pDynData->aSfbScale, pAacDecoderChannelInfo[R]->pDynData->aSfbScale, pAacDecoderChannelInfo[L]->specScale, pAacDecoderChannelInfo[R]->specScale, GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, pSamplingRateInfo), GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), max_sfb_ste, maxSfBandsL, maxSfBandsR, pAacDecoderChannelInfo[L] ->pComData->jointStereoData.store_dmx_re_prev, &(pAacDecoderChannelInfo[L] ->pComData->jointStereoData.store_dmx_re_prev_e), 1); } } /* if (pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow) */ } /* if (maybe_jstereo) */ for (ch = 0; ch < el_channels; ch++) { if (elFlags & AC_EL_USAC_CP_POSSIBLE) { pAacDecoderStaticChannelInfo[L] ->pCpeStaticData->jointStereoPersistentData.clearSpectralCoeffs = 0; } } CRvlc_ElementCheck(pAacDecoderChannelInfo, pAacDecoderStaticChannelInfo, flags, el_channels); }
AAC_DECODER_ERROR IcsRead(HANDLE_FDK_BITSTREAM bs, CIcsInfo *pIcsInfo, const SamplingRateInfo* pSamplingRateInfo, const UINT flags) { AAC_DECODER_ERROR ErrorStatus = AAC_DEC_OK; pIcsInfo->Valid = 0; if (flags & AC_ELD){ pIcsInfo->WindowSequence = OnlyLongSequence; pIcsInfo->WindowShape = 0; } else { if ( !(flags & (AC_USAC|AC_RSVD50)) ) { FDKreadBits(bs,1); } pIcsInfo->WindowSequence = (UCHAR) FDKreadBits(bs,2); pIcsInfo->WindowShape = (UCHAR) FDKreadBits(bs,1); if (flags & AC_LD) { if (pIcsInfo->WindowShape) { pIcsInfo->WindowShape = 2; /* select low overlap instead of KBD */ } } } /* Sanity check */ if ( (flags & (AC_ELD|AC_LD)) && pIcsInfo->WindowSequence != OnlyLongSequence) { pIcsInfo->WindowSequence = OnlyLongSequence; ErrorStatus = AAC_DEC_PARSE_ERROR; goto bail; } ErrorStatus = IcsReadMaxSfb(bs, pIcsInfo, pSamplingRateInfo); if (ErrorStatus != AAC_DEC_OK) { goto bail; } if (IsLongBlock(pIcsInfo)) { if ( !(flags & (AC_ELD|AC_SCALABLE|AC_BSAC|AC_USAC|AC_RSVD50)) ) /* If not ELD nor Scalable nor BSAC nor USAC syntax then ... */ { if ((UCHAR)FDKreadBits(bs,1) != 0 ) /* UCHAR PredictorDataPresent */ { ErrorStatus = AAC_DEC_UNSUPPORTED_PREDICTION; goto bail; } } pIcsInfo->WindowGroups = 1; pIcsInfo->WindowGroupLength[0] = 1; } else { INT i; UINT mask; pIcsInfo->ScaleFactorGrouping = (UCHAR) FDKreadBits(bs,7); pIcsInfo->WindowGroups = 0 ; for (i=0; i < (8-1); i++) { mask = 1 << (6 - i); pIcsInfo->WindowGroupLength[i] = 1; if (pIcsInfo->ScaleFactorGrouping & mask) { pIcsInfo->WindowGroupLength[pIcsInfo->WindowGroups]++; } else { pIcsInfo->WindowGroups++; } } /* loop runs to i < 7 only */ pIcsInfo->WindowGroupLength[8-1] = 1; pIcsInfo->WindowGroups++; } bail: if (ErrorStatus == AAC_DEC_OK) pIcsInfo->Valid = 1; return ErrorStatus; }
/*! \brief Read tns data from bitstream The function reads the elements for tns from the bitstream. \return none */ AAC_DECODER_ERROR CTns_Read(HANDLE_FDK_BITSTREAM bs, CTnsData *pTnsData, const CIcsInfo *pIcsInfo, const UINT flags) { UCHAR n_filt,order; UCHAR length,coef_res,coef_compress; UCHAR window; UCHAR wins_per_frame = GetWindowsPerFrame(pIcsInfo); UCHAR isLongFlag = IsLongBlock(pIcsInfo); AAC_DECODER_ERROR ErrorStatus = AAC_DEC_OK; if (!pTnsData->DataPresent) { return ErrorStatus; } for (window = 0; window < wins_per_frame; window++) { pTnsData->NumberOfFilters[window] = n_filt = (UCHAR) FDKreadBits(bs, isLongFlag ? 2 : 1); if (pTnsData->NumberOfFilters[window] > TNS_MAXIMUM_FILTERS){ pTnsData->NumberOfFilters[window] = n_filt = TNS_MAXIMUM_FILTERS; } if (n_filt) { int index; UCHAR nextstopband; coef_res = (UCHAR) FDKreadBits(bs,1); nextstopband = GetScaleFactorBandsTotal(pIcsInfo); for (index=0; index < n_filt; index++) { CFilter *filter = &pTnsData->Filter[window][index]; length = (UCHAR)FDKreadBits(bs, isLongFlag ? 6 : 4); if (length > nextstopband){ length = nextstopband; } filter->StartBand = nextstopband - length; filter->StopBand = nextstopband; nextstopband = filter->StartBand; { filter->Order = order = (UCHAR) FDKreadBits(bs, isLongFlag ? 5 : 3); } if (filter->Order > TNS_MAXIMUM_ORDER){ filter->Order = order = TNS_MAXIMUM_ORDER; } if (order) { UCHAR coef,s_mask; UCHAR i; SCHAR n_mask; static const UCHAR sgn_mask[] = { 0x2, 0x4, 0x8 }; static const SCHAR neg_mask[] = { ~0x3, ~0x7, ~0xF }; filter->Direction = FDKreadBits(bs,1) ? -1 : 1; coef_compress = (UCHAR) FDKreadBits(bs,1); filter->Resolution = coef_res + 3; s_mask = sgn_mask[coef_res + 1 - coef_compress]; n_mask = neg_mask[coef_res + 1 - coef_compress]; for (i=0; i < order; i++) { coef = (UCHAR) FDKreadBits(bs,filter->Resolution - coef_compress); filter->Coeff[i] = (coef & s_mask) ? (coef | n_mask) : coef; } } } } } pTnsData->Active = 1; return ErrorStatus; }