From 4204c466656c770c09716f89355fe485c1418c4e Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 17 Apr 2020 15:11:03 +0200 Subject: Overcome SBR encoder coupling quality issue in ELD. Bug 177604812 Test: see SBR/PS encoder Change-Id: Ie7b9f8d1dec3708557d1e1189d45bc0e3bf5444c --- libSBRenc/src/env_est.cpp | 22 +++++++++++++++------- libSBRenc/src/sbr_encoder.cpp | 5 ++--- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'libSBRenc') diff --git a/libSBRenc/src/env_est.cpp b/libSBRenc/src/env_est.cpp index 0eb8425..cc8780a 100644 --- a/libSBRenc/src/env_est.cpp +++ b/libSBRenc/src/env_est.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -1267,6 +1267,7 @@ void FDKsbrEnc_extractSbrEnvelope2( sbrExtrEnv->pre_transient_info[1] = ed->transient_info[1]; /* tran_flag */ hEnvChan->encEnvData.noOfEnvelopes = ed->nEnvelopes = ed->frame_info->nEnvelopes; /* number of envelopes of current frame */ + hEnvChan->encEnvData.currentAmpResFF = (AMP_RES)h_con->initAmpResFF; /* Check if the current frame is divided into one envelope only. If so, set @@ -1274,8 +1275,9 @@ void FDKsbrEnc_extractSbrEnvelope2( */ if ((hEnvChan->encEnvData.hSbrBSGrid->frameClass == FIXFIX) && (ed->nEnvelopes == 1)) { + AMP_RES currentAmpResFF = SBR_AMP_RES_1_5; if (h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY) { - /* Note: global_tonaliy_float_value == + /* Note: global_tonality_float_value == ((float)hEnvChan->encEnvData.global_tonality/((INT64)(1)<<(31-(19+2)))/0.524288*(2.0/3.0))); threshold_float_value == ((float)h_con->thresholdAmpResFF_m/((INT64)(1)<<(31-(h_con->thresholdAmpResFF_e)))/0.524288*(2.0/3.0))); @@ -1289,14 +1291,13 @@ void FDKsbrEnc_extractSbrEnvelope2( } else { hEnvChan->encEnvData.currentAmpResFF = SBR_AMP_RES_3_0; } - } else - hEnvChan->encEnvData.currentAmpResFF = SBR_AMP_RES_1_5; + currentAmpResFF = hEnvChan->encEnvData.currentAmpResFF; + } - if (hEnvChan->encEnvData.currentAmpResFF != - hEnvChan->encEnvData.init_sbr_amp_res) { + if (currentAmpResFF != hEnvChan->encEnvData.init_sbr_amp_res) { FDKsbrEnc_InitSbrHuffmanTables( &hEnvChan->encEnvData, &hEnvChan->sbrCodeEnvelope, - &hEnvChan->sbrCodeNoiseFloor, hEnvChan->encEnvData.currentAmpResFF); + &hEnvChan->sbrCodeNoiseFloor, currentAmpResFF); } } else { if (sbrHeaderData->sbr_amp_res != hEnvChan->encEnvData.init_sbr_amp_res) { @@ -1355,6 +1356,13 @@ void FDKsbrEnc_extractSbrEnvelope2( } } + if (h_con->sbrSyntaxFlags & SBR_SYNTAX_LOW_DELAY && + stereoMode == SBR_SWITCH_LRC && + h_envChan[0]->encEnvData.currentAmpResFF != + h_envChan[1]->encEnvData.currentAmpResFF) { + stereoMode = SBR_LEFT_RIGHT; + } + /* Extract envelope of current frame. */ diff --git a/libSBRenc/src/sbr_encoder.cpp b/libSBRenc/src/sbr_encoder.cpp index c1e083f..c3da072 100644 --- a/libSBRenc/src/sbr_encoder.cpp +++ b/libSBRenc/src/sbr_encoder.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -1450,8 +1450,6 @@ static INT initEnvChannel(HANDLE_SBR_CONFIG_DATA sbrConfigData, params->deltaTAcrossFrames, 0, 0)) return (1); - sbrConfigData->initAmpResFF = params->init_amp_res_FF; - if (FDKsbrEnc_InitSbrHuffmanTables(&hEnv->encEnvData, &hEnv->sbrCodeEnvelope, &hEnv->sbrCodeNoiseFloor, sbrHeaderData->sbr_amp_res)) @@ -1749,6 +1747,7 @@ static INT FDKsbrEnc_EnvInit(HANDLE_SBR_ELEMENT hSbrElement, hSbrElement->sbrHeaderData.sbr_data_extra = 1; hSbrElement->sbrHeaderData.sbr_amp_res = (AMP_RES)params->amp_res; + hSbrElement->sbrConfigData.initAmpResFF = params->init_amp_res_FF; /* header_extra_1 */ hSbrElement->sbrHeaderData.freqScale = params->freqScale; -- cgit v1.2.3 From 8264e376ea6f2fdaa3813ff1a8463e368d95083c Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Fri, 10 Nov 2023 11:39:50 +0200 Subject: Saturate additions in getEnvSfbEnergy in SBR encoding This avoids wraparounds, which can trigger failed asserts with some inputs. This fixes https://github.com/mstorsjo/fdk-aac/issues/158. The implementation of saturated addition loses the contents of the lowest bit though, thus this change affects the output - but the change is said to be acceptable. --- libSBRenc/src/env_est.cpp | 4 ++-- test/ref-mono.txt | 4 ++-- test/ref-stereo.txt | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'libSBRenc') diff --git a/libSBRenc/src/env_est.cpp b/libSBRenc/src/env_est.cpp index cc8780a..e7eea37 100644 --- a/libSBRenc/src/env_est.cpp +++ b/libSBRenc/src/env_est.cpp @@ -637,8 +637,8 @@ static FIXP_DBL getEnvSfbEnergy( for (; l < stop_pos; l++) { nrg2 += YBuffer[l >> YBufferSzShift][k] >> sc1; } - accu1 += (nrg1 >> dynScale1); - accu2 += (nrg2 >> dynScale2); + accu1 = fAddSaturate(accu1, (nrg1 >> dynScale1)); + accu2 = fAddSaturate(accu2, (nrg2 >> dynScale2)); } /* This shift factor is always positive. See comment above. */ nrgSum += diff --git a/test/ref-mono.txt b/test/ref-mono.txt index 22a84f2..39fa6df 100644 --- a/test/ref-mono.txt +++ b/test/ref-mono.txt @@ -1,2 +1,2 @@ -encode hash: 516e51016cbba6068f1aa285a8fdd55b00ada6b0 -decode hash: 3b3b3a17cc5ba50ade75b3ef1a37f96017935fe5 +encode hash: 7f00e85a1eda67964e1b4044a5659a62e3952af2 +decode hash: af682b197a94e32fce09643857fa77b364574571 diff --git a/test/ref-stereo.txt b/test/ref-stereo.txt index 3de5276..a765c93 100644 --- a/test/ref-stereo.txt +++ b/test/ref-stereo.txt @@ -1,2 +1,2 @@ -encode hash: 1179940ca3a5c62de45b6823efbdbe42fce11de2 -decode hash: 85f2a154b46cc6cfa2792ff95c67b4200ce4463b +encode hash: 8411e71bf6b32576d287764cfa577ea0e9b73280 +decode hash: 30ad42bc97b53c03139cca5437b7d9a861de0e92 -- cgit v1.2.3