From c096e49aadfadc263a0401df302ba2885d810f1b Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 9 Jan 2026 14:54:31 +0100 Subject: [PATCH 1/2] fix issue 2257 (includes MR2695) using more fix and dynamic headroom for complex FFT10 --- apps/renderer.c | 4 ++++ lib_com/fft_cldfb_fx.c | 25 ++++++++++++++++++++++++- lib_com/options.h | 3 +++ lib_rend/lib_rend_fx.c | 5 +++++ 4 files changed, 36 insertions(+), 1 deletion(-) mode change 100644 => 100755 lib_com/fft_cldfb_fx.c mode change 100644 => 100755 lib_rend/lib_rend_fx.c diff --git a/apps/renderer.c b/apps/renderer.c index 464a9f893..76b883ec0 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -1642,8 +1642,12 @@ int main( ObjectPositionBuffer mtdBuffer; outBuffer.pq_fact = &outBuffer.q_factor; +#ifdef FIX_2257_INCR_GUARD_BITS + Word16 gd_bits = find_guard_bits( frameSize_smpls ); +#else Word16 subframe_len = (Word16) ( args.sampleRate / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ); Word16 gd_bits = find_guard_bits( subframe_len ); +#endif Word16 prev_q_fact = Q11; while ( 1 ) { diff --git a/lib_com/fft_cldfb_fx.c b/lib_com/fft_cldfb_fx.c old mode 100644 new mode 100755 index 230dd7ac5..153fa67ce --- a/lib_com/fft_cldfb_fx.c +++ b/lib_com/fft_cldfb_fx.c @@ -19,7 +19,7 @@ contributions. This software is provided "AS IS", without any express or implied warranties. The software is in the - development stage. It is intended exclusively for experts who have experience with such software and + development stage. It is int exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. @@ -257,6 +257,17 @@ static void fft10_with_cmplx_data( cmplx *inp_data /*Qx*/ ) cmplx x0, x1, x2, x3, x4, t; cmplx y[10]; +#ifdef FIX_ISSUE_2257_ADD_HEADROOM_IN_FFT10 + Word16 headroom = L_norm_arr( (Word32 *) inp_data, 2 * 10 ); + Word16 headroom_fix = ( headroom < 5 /* SCALEFACTOR10 */ ) ? ( 5 /* SCALEFACTOR10 */ - headroom ) : 0; + if ( headroom_fix != 0 ) + { + for ( Word16 i = 0; i < 10; i++ ) + { + inp_data[i] = CL_shr( inp_data[i], headroom_fix ); + } + } +#endif /* FOR i=0 */ { x0 = CL_shr( inp_data[0], SCALEFACTOR10 ); @@ -343,6 +354,17 @@ static void fft10_with_cmplx_data( cmplx *inp_data /*Qx*/ ) #ifdef WMOPS multiCounter[currCounter].CL_move += 10; #endif + +#ifdef FIX_ISSUE_2257_ADD_HEADROOM_IN_FFT10 + if ( headroom_fix != 0 ) + { + for (Word16 i = 0; i < 10; i++) + { + /* We want to get assertion in case of overflow, no saturation */ + inp_data[i] = CL_shl(inp_data[i], headroom_fix); + } + } +#endif } /** @@ -1004,6 +1026,7 @@ static void fft30_with_cmplx_data( cmplx *inp /*Qx*/ ) #ifdef WMOPS multiCounter[currCounter].CL_move += 30; #endif + } /*-------------------------------------------------------------------* diff --git a/lib_com/options.h b/lib_com/options.h index 2c70dd14f..9103d3b82 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -119,6 +119,9 @@ #define FIX_1466_EXTREND /* FhG: float issue 1466: enable rendering of mono/stereo to other formats in the external renderer */ #define FIX_1381_BWD /* VA: issue 1381: apply no hysteresis in BWD at higher bitrates also in mono MASA and OMASA */ #define FIX_2285_CODE_DECODER_INIT_BW /* VA: basop issue 2285: fix core-decoder initialization bandwidth */ +#define FIX_2257_INCR_GUARD_BITS /* FhG: take correct rendering frame-size into account for guard-bits calculation */ +#define FIX_ISSUE_2257_INCREASE_GUARD_BITS /* FhG: (tri) adds +1 to result of find_guard_bits of len=320: 9 -> 10 */ +#define FIX_ISSUE_2257_ADD_HEADROOM_IN_FFT10 /* FhG: (tri) optional scale-down at entry and scale-up at end of FFT10, if headroom too small */ /* ##################### End NON-BE switches ########################### */ diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c old mode 100644 new mode 100755 index 9a1dbfe5b..9ff3a2206 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -7216,7 +7216,12 @@ static void renderIsmToMasa( q_min = s_min( q_min, L_norm_arr( tmpRendBuffer_fx[i], ismInput->base.inputBuffer.config.numSamplesPerChannel ) ); } +#ifdef FIX_ISSUE_2257_INCREASE_GUARD_BITS + guard_bits = add( 1, find_guarded_bits_fx( ismInput->base.inputBuffer.config.numSamplesPerChannel ) ); +#else guard_bits = find_guarded_bits_fx( ismInput->base.inputBuffer.config.numSamplesPerChannel ); +#endif + q_min = sub( add( q_min, *outAudio.pq_fact ), guard_bits ); q_diff = sub( q_min, *outAudio.pq_fact ); -- GitLab From 200b2b96c81a594c7a06d295d64f5242e686b709 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 9 Jan 2026 17:36:06 +0100 Subject: [PATCH 2/2] fix clang format issue --- lib_com/fft_cldfb_fx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) mode change 100755 => 100644 lib_com/fft_cldfb_fx.c diff --git a/lib_com/fft_cldfb_fx.c b/lib_com/fft_cldfb_fx.c old mode 100755 new mode 100644 index 153fa67ce..948854d36 --- a/lib_com/fft_cldfb_fx.c +++ b/lib_com/fft_cldfb_fx.c @@ -358,10 +358,10 @@ static void fft10_with_cmplx_data( cmplx *inp_data /*Qx*/ ) #ifdef FIX_ISSUE_2257_ADD_HEADROOM_IN_FFT10 if ( headroom_fix != 0 ) { - for (Word16 i = 0; i < 10; i++) + for ( Word16 i = 0; i < 10; i++ ) { /* We want to get assertion in case of overflow, no saturation */ - inp_data[i] = CL_shl(inp_data[i], headroom_fix); + inp_data[i] = CL_shl( inp_data[i], headroom_fix ); } } #endif @@ -1026,7 +1026,6 @@ static void fft30_with_cmplx_data( cmplx *inp /*Qx*/ ) #ifdef WMOPS multiCounter[currCounter].CL_move += 30; #endif - } /*-------------------------------------------------------------------* -- GitLab