diff options
Diffstat (limited to 'libDRCdec')
-rw-r--r-- | libDRCdec/src/FDK_drcDecLib.cpp | 22 | ||||
-rw-r--r-- | libDRCdec/src/drcDec_reader.cpp | 16 | ||||
-rw-r--r-- | libDRCdec/src/drcDec_selectionProcess.cpp | 39 | ||||
-rw-r--r-- | libDRCdec/src/drcDec_types.h | 8 | ||||
-rw-r--r-- | libDRCdec/src/drcGainDec_init.cpp | 6 | ||||
-rw-r--r-- | libDRCdec/src/drcGainDec_preprocess.cpp | 5 |
6 files changed, 61 insertions, 35 deletions
diff --git a/libDRCdec/src/FDK_drcDecLib.cpp b/libDRCdec/src/FDK_drcDecLib.cpp index b29b79d..16b8152 100644 --- a/libDRCdec/src/FDK_drcDecLib.cpp +++ b/libDRCdec/src/FDK_drcDecLib.cpp @@ -173,13 +173,11 @@ static int isResetNeeded(HANDLE_DRC_DECODER hDrcDec, return resetNeeded; } -static DRC_DEC_ERROR startSelectionProcess(HANDLE_DRC_DECODER hDrcDec) { - DRC_ERROR dErr = DE_OK; - DRCDEC_SELECTION_PROCESS_RETURN sErr = DRCDEC_SELECTION_PROCESS_NO_ERROR; +static void startSelectionProcess(HANDLE_DRC_DECODER hDrcDec) { int uniDrcConfigHasChanged = 0; SEL_PROC_OUTPUT oldSelProcOutput = hDrcDec->selProcOutput; - if (!hDrcDec->status) return DRC_DEC_NOT_READY; + if (!hDrcDec->status) return; if (hDrcDec->functionalRange & DRC_DEC_SELECTION) { uniDrcConfigHasChanged = hDrcDec->uniDrcConfig.diff; @@ -189,10 +187,9 @@ static DRC_DEC_ERROR startSelectionProcess(HANDLE_DRC_DECODER hDrcDec) { */ hDrcDec->selProcOutput.numSelectedDrcSets = 0; - sErr = drcDec_SelectionProcess_Process( + drcDec_SelectionProcess_Process( hDrcDec->hSelectionProc, &(hDrcDec->uniDrcConfig), &(hDrcDec->loudnessInfoSet), &(hDrcDec->selProcOutput)); - if (sErr) return DRC_DEC_OK; hDrcDec->selProcInputDiff = 0; hDrcDec->uniDrcConfig.diff = 0; @@ -202,15 +199,12 @@ static DRC_DEC_ERROR startSelectionProcess(HANDLE_DRC_DECODER hDrcDec) { if (hDrcDec->functionalRange & DRC_DEC_GAIN) { if (isResetNeeded(hDrcDec, oldSelProcOutput) || uniDrcConfigHasChanged) { - dErr = - drcDec_GainDecoder_Config(hDrcDec->hGainDec, &(hDrcDec->uniDrcConfig), - hDrcDec->selProcOutput.numSelectedDrcSets, - hDrcDec->selProcOutput.selectedDrcSetIds, - hDrcDec->selProcOutput.selectedDownmixIds); - if (dErr) return DRC_DEC_OK; + drcDec_GainDecoder_Config(hDrcDec->hGainDec, &(hDrcDec->uniDrcConfig), + hDrcDec->selProcOutput.numSelectedDrcSets, + hDrcDec->selProcOutput.selectedDrcSetIds, + hDrcDec->selProcOutput.selectedDownmixIds); } } - return DRC_DEC_OK; } DRC_DEC_ERROR @@ -721,9 +715,9 @@ FDK_drcDec_ReadUniDrc(HANDLE_DRC_DECODER hDrcDec, drcDec_GainDecoder_GetFrameSize(hDrcDec->hGainDec), drcDec_GainDecoder_GetDeltaTminDefault(hDrcDec->hGainDec), &(hDrcDec->uniDrcGain)); - if (dErr) return DRC_DEC_NOT_OK; startSelectionProcess(hDrcDec); + if (dErr) return DRC_DEC_NOT_OK; hDrcDec->status = DRC_DEC_NEW_GAIN_PAYLOAD; diff --git a/libDRCdec/src/drcDec_reader.cpp b/libDRCdec/src/drcDec_reader.cpp index 6fe7a04..a784457 100644 --- a/libDRCdec/src/drcDec_reader.cpp +++ b/libDRCdec/src/drcDec_reader.cpp @@ -185,10 +185,18 @@ drcDec_readUniDrc(HANDLE_FDK_BITSTREAM hBs, HANDLE_UNI_DRC_CONFIG hUniDrcConfig, uniDrcConfigPresent = FDKreadBits(hBs, 1); if (uniDrcConfigPresent) { err = drcDec_readUniDrcConfig(hBs, hUniDrcConfig); - if (err) return err; + if (err) { + /* clear config, if parsing error occured */ + FDKmemclear(hUniDrcConfig, sizeof(UNI_DRC_CONFIG)); + hUniDrcConfig->diff = 1; + } } err = drcDec_readLoudnessInfoSet(hBs, hLoudnessInfoSet); - if (err) return err; + if (err) { + /* clear config, if parsing error occured */ + FDKmemclear(hLoudnessInfoSet, sizeof(LOUDNESS_INFO_SET)); + hLoudnessInfoSet->diff = 1; + } } if (hUniDrcGain != NULL) { @@ -1130,7 +1138,7 @@ static DRC_ERROR _readDrcCoefficientsUniDrc(HANDLE_FDK_BITSTREAM hBs, drcCharacteristicLeftPresent = FDKreadBits(hBs, 1); if (drcCharacteristicLeftPresent) { pCoef->characteristicLeftCount = FDKreadBits(hBs, 4); - if ((pCoef->characteristicLeftCount + 1) > 8) return DE_MEMORY_ERROR; + if ((pCoef->characteristicLeftCount + 1) > 16) return DE_MEMORY_ERROR; for (i = 0; i < pCoef->characteristicLeftCount; i++) { err = _readCustomDrcCharacteristic( hBs, CS_LEFT, &(pCoef->characteristicLeftFormat[i + 1]), @@ -1141,7 +1149,7 @@ static DRC_ERROR _readDrcCoefficientsUniDrc(HANDLE_FDK_BITSTREAM hBs, drcCharacteristicRightPresent = FDKreadBits(hBs, 1); if (drcCharacteristicRightPresent) { pCoef->characteristicRightCount = FDKreadBits(hBs, 4); - if ((pCoef->characteristicRightCount + 1) > 8) return DE_MEMORY_ERROR; + if ((pCoef->characteristicRightCount + 1) > 16) return DE_MEMORY_ERROR; for (i = 0; i < pCoef->characteristicRightCount; i++) { err = _readCustomDrcCharacteristic( hBs, CS_RIGHT, &(pCoef->characteristicRightFormat[i + 1]), diff --git a/libDRCdec/src/drcDec_selectionProcess.cpp b/libDRCdec/src/drcDec_selectionProcess.cpp index 54b731d..5653e22 100644 --- a/libDRCdec/src/drcDec_selectionProcess.cpp +++ b/libDRCdec/src/drcDec_selectionProcess.cpp @@ -1006,15 +1006,23 @@ static DRCDEC_SELECTION_PROCESS_RETURN _preSelectionRequirement7( return DRCDEC_SELECTION_PROCESS_NO_ERROR; } -static void _setSelectionDataInfo(DRCDEC_SELECTION_DATA* pData, - FIXP_DBL loudness, - FIXP_DBL loudnessNormalizationGainDb, - FIXP_DBL loudnessNormalizationGainDbMax, - FIXP_DBL loudnessDeviationMax, - FIXP_DBL signalPeakLevel, - FIXP_DBL outputPeakLevelMax, - int applyAdjustment) { - FIXP_DBL adjustment = 0; +static void _setSelectionDataInfo( + DRCDEC_SELECTION_DATA* pData, FIXP_DBL loudness, /* e = 7 */ + FIXP_DBL loudnessNormalizationGainDb, /* e = 7 */ + FIXP_DBL loudnessNormalizationGainDbMax, /* e = 7 */ + FIXP_DBL loudnessDeviationMax, /* e = 7 */ + FIXP_DBL signalPeakLevel, /* e = 7 */ + FIXP_DBL outputPeakLevelMax, /* e = 7 */ + int applyAdjustment) { + FIXP_DBL adjustment = 0; /* e = 8 */ + + /* use e = 8 for all function parameters to prevent overflow */ + loudness >>= 1; + loudnessNormalizationGainDb >>= 1; + loudnessNormalizationGainDbMax >>= 1; + loudnessDeviationMax >>= 1; + signalPeakLevel >>= 1; + outputPeakLevelMax >>= 1; if (applyAdjustment) { adjustment = @@ -1028,6 +1036,14 @@ static void _setSelectionDataInfo(DRCDEC_SELECTION_DATA* pData, pData->outputLoudness = loudness + pData->loudnessNormalizationGainDbAdjusted; pData->outputPeakLevel = signalPeakLevel + pData->loudnessNormalizationGainDbAdjusted; + + /* shift back to e = 7 using saturation */ + pData->loudnessNormalizationGainDbAdjusted = SATURATE_LEFT_SHIFT( + pData->loudnessNormalizationGainDbAdjusted, 1, DFRACT_BITS); + pData->outputLoudness = + SATURATE_LEFT_SHIFT(pData->outputLoudness, 1, DFRACT_BITS); + pData->outputPeakLevel = + SATURATE_LEFT_SHIFT(pData->outputPeakLevel, 1, DFRACT_BITS); } static int _targetLoudnessInRange( @@ -2157,6 +2173,9 @@ static DRCDEC_SELECTION_PROCESS_RETURN _selectDownmixMatrix( if (hSelProcOutput->activeDownmixId != 0) { for (i = 0; i < hUniDrcConfig->downmixInstructionsCount; i++) { DOWNMIX_INSTRUCTIONS* pDown = &(hUniDrcConfig->downmixInstructions[i]); + if (pDown->targetChannelCount > 8) { + continue; + } if (hSelProcOutput->activeDownmixId == pDown->downmixId) { hSelProcOutput->targetChannelCount = pDown->targetChannelCount; @@ -2809,6 +2828,8 @@ static int _downmixCoefficientsArePresent(HANDLE_UNI_DRC_CONFIG hUniDrcConfig, for (i = 0; i < hUniDrcConfig->downmixInstructionsCount; i++) { if (hUniDrcConfig->downmixInstructions[i].downmixId == downmixId) { if (hUniDrcConfig->downmixInstructions[i].downmixCoefficientsPresent) { + if (hUniDrcConfig->downmixInstructions[i].targetChannelCount > 8) + return 0; *pIndex = i; return 1; } diff --git a/libDRCdec/src/drcDec_types.h b/libDRCdec/src/drcDec_types.h index 28c17f3..6b99018 100644 --- a/libDRCdec/src/drcDec_types.h +++ b/libDRCdec/src/drcDec_types.h @@ -249,11 +249,11 @@ typedef struct { UCHAR drcFrameSizePresent; USHORT drcFrameSize; UCHAR characteristicLeftCount; - UCHAR characteristicLeftFormat[8]; - CUSTOM_DRC_CHAR customCharacteristicLeft[8]; + UCHAR characteristicLeftFormat[16]; + CUSTOM_DRC_CHAR customCharacteristicLeft[16]; UCHAR characteristicRightCount; - UCHAR characteristicRightFormat[8]; - CUSTOM_DRC_CHAR customCharacteristicRight[8]; + UCHAR characteristicRightFormat[16]; + CUSTOM_DRC_CHAR customCharacteristicRight[16]; UCHAR gainSequenceCount; /* unsaturated value, i.e. as provided in bitstream */ UCHAR gainSetCount; /* saturated to 12 */ diff --git a/libDRCdec/src/drcGainDec_init.cpp b/libDRCdec/src/drcGainDec_init.cpp index 38f3243..c9f87d7 100644 --- a/libDRCdec/src/drcGainDec_init.cpp +++ b/libDRCdec/src/drcGainDec_init.cpp @@ -336,9 +336,11 @@ initActiveDrcOffset(HANDLE_DRC_GAIN_DECODER hGainDec) { for (a = 0; a < hGainDec->nActiveDrcs; a++) { hGainDec->activeDrc[a].activeDrcOffset = accGainElementCount; accGainElementCount += hGainDec->activeDrc[a].gainElementCount; + if (accGainElementCount > 12) { + hGainDec->nActiveDrcs = a; + return DE_NOT_OK; + } } - if (accGainElementCount > 12) return DE_NOT_OK; - return DE_OK; } diff --git a/libDRCdec/src/drcGainDec_preprocess.cpp b/libDRCdec/src/drcGainDec_preprocess.cpp index 7919589..c543c53 100644 --- a/libDRCdec/src/drcGainDec_preprocess.cpp +++ b/libDRCdec/src/drcGainDec_preprocess.cpp @@ -300,8 +300,9 @@ static DRC_ERROR _compressorIO_sigmoid(const CUSTOM_DRC_CHAR_SIGMOID* pCChar, FIXP_SGL exp = pCChar->exp; DRC_ERROR err = DE_OK; - tmp = fMultDiv2(DRC_INPUT_LOUDNESS_TARGET - inLevelDb, pCChar->ioRatio); - tmp = SATURATE_LEFT_SHIFT(tmp, 2 + 1, DFRACT_BITS); + tmp = fMultDiv2((DRC_INPUT_LOUDNESS_TARGET >> 1) - (inLevelDb >> 1), + pCChar->ioRatio); + tmp = SATURATE_LEFT_SHIFT(tmp, 2 + 1 + 1, DFRACT_BITS); if (exp < (FIXP_SGL)MAXVAL_SGL) { /* x = tmp / gainDbLimit; */ /* *outGainDb = tmp / pow(1.0f + pow(x, exp), 1.0f/exp); */ |