From b02c3b15dc15a7451b88d5cc5e181991cbc9f4c4 Mon Sep 17 00:00:00 2001 From: advasila Date: Thu, 10 Aug 2023 12:41:43 +0300 Subject: [PATCH 1/2] fix overindexing in ACELP table --- lib_com/bits_alloc.c | 61 ++++++++++++++++++++++++++++++++------------ lib_com/options.h | 2 +- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 56e523b392..83e17c9ed1 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -394,6 +394,9 @@ static ivas_error acelp_FCB_allocator( int16_t nBits_tmp; int16_t *p_fixed_cdk_index; ivas_error error; +#ifdef FIX_680_ACELP_TABLE_OMASA + int16_t max_n; +#endif error = IVAS_ERR_OK; @@ -424,13 +427,31 @@ static ivas_error acelp_FCB_allocator( } /* distribute the bit-budget equally between subframes */ +#ifdef FIX_680_ACELP_TABLE_OMASA + if ( L_subfr > L_SUBFR ) /* access fast_FCB_bits_2sfr */ + { + max_n = 6; + } + else + { + max_n = ACELP_FIXED_CDK_NB; + } + for ( cdbk = 0; cdbk < max_n; cdbk++ ) + { + if ( fcb_table( cdbk, L_subfr ) * nb_subfr > *nBits ) + { + break; + } + } + cdbk--; +#else cdbk = 0; while ( fcb_table( cdbk, L_subfr ) * nb_subfr <= *nBits ) { cdbk++; } cdbk--; - +#endif #ifdef DEBUGGING if ( cdbk < 0 && coder_type != TRANSITION ) { @@ -455,29 +476,35 @@ static ivas_error acelp_FCB_allocator( *nBits -= nBits_tmp * nb_subfr; /* try to increase the FCB bit-budget of the first subframe(s) */ - step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp; - while ( *nBits >= step ) +#ifdef FIX_680_ACELP_TABLE_OMASA + if ( cdbk < ACELP_FIXED_CDK_NB - 1 ) { - ( *p_fixed_cdk_index )++; - *nBits -= step; - p_fixed_cdk_index++; - } - - /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ - step = fcb_table( fixed_cdk_index[sfr] + 1, L_subfr ) - fcb_table( fixed_cdk_index[sfr], L_subfr ); - if ( *nBits >= step && cdbk >= 0 ) - { - fixed_cdk_index[sfr]++; - *nBits -= step; +#endif + step = fcb_table( cdbk + 1, L_subfr ) - nBits_tmp; + while ( *nBits >= step ) + { + ( *p_fixed_cdk_index )++; + *nBits -= step; + p_fixed_cdk_index++; + } - if ( *nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1 ) + /* try to increase the FCB of the first subframe in cases when the next step is lower than the current step */ + step = fcb_table( fixed_cdk_index[sfr] + 1, L_subfr ) - fcb_table( fixed_cdk_index[sfr], L_subfr ); + if ( *nBits >= step && cdbk >= 0 ) { - sfr++; fixed_cdk_index[sfr]++; *nBits -= step; + + if ( *nBits >= step && fixed_cdk_index[sfr + 1] == fixed_cdk_index[sfr] - 1 ) + { + sfr++; + fixed_cdk_index[sfr]++; + *nBits -= step; + } } +#ifdef FIX_680_ACELP_TABLE_OMASA } - +#endif /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ if ( tc_subfr >= L_SUBFR ) { diff --git a/lib_com/options.h b/lib_com/options.h index 4b7274c878..afa14e30bc 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -229,7 +229,7 @@ #define FIX_653_BUG_IN_SKIP_MATRIX /* Dlb: fix for issue #653, bug in the ivas_spar_get_skip_mat function*/ #define FIX_663_PARAM_ISM_EXT /* FhG: Issue 663: ParamISM EXT output improvement */ #define FIX_673_OMASA_OBJ_MD_SYNC /* Nokia: Fix issue 673 by updating metadata in the third subframe to account for audio delay. */ - +#define FIX_680_ACELP_TABLE_OMASA /* Nokia: Fix for issue 680 preventing overindexing of PulseConfTable */ /* ################## End BE DEVELOPMENT switches ######################### */ -- GitLab From 26093fe9d2c19218f1ec8bbf8e730ca37ab626fe Mon Sep 17 00:00:00 2001 From: Tapani Pihlajakuja Date: Thu, 10 Aug 2023 13:51:48 +0300 Subject: [PATCH 2/2] Apply clang format --- lib_com/bits_alloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index 83e17c9ed1..3837d62543 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -394,7 +394,7 @@ static ivas_error acelp_FCB_allocator( int16_t nBits_tmp; int16_t *p_fixed_cdk_index; ivas_error error; -#ifdef FIX_680_ACELP_TABLE_OMASA +#ifdef FIX_680_ACELP_TABLE_OMASA int16_t max_n; #endif @@ -427,7 +427,7 @@ static ivas_error acelp_FCB_allocator( } /* distribute the bit-budget equally between subframes */ -#ifdef FIX_680_ACELP_TABLE_OMASA +#ifdef FIX_680_ACELP_TABLE_OMASA if ( L_subfr > L_SUBFR ) /* access fast_FCB_bits_2sfr */ { max_n = 6; @@ -476,7 +476,7 @@ static ivas_error acelp_FCB_allocator( *nBits -= nBits_tmp * nb_subfr; /* try to increase the FCB bit-budget of the first subframe(s) */ -#ifdef FIX_680_ACELP_TABLE_OMASA +#ifdef FIX_680_ACELP_TABLE_OMASA if ( cdbk < ACELP_FIXED_CDK_NB - 1 ) { #endif @@ -502,7 +502,7 @@ static ivas_error acelp_FCB_allocator( *nBits -= step; } } -#ifdef FIX_680_ACELP_TABLE_OMASA +#ifdef FIX_680_ACELP_TABLE_OMASA } #endif /* TRANSITION coding: allocate highest FCBQ bit-budget to the subframe with the glottal-shape codebook */ -- GitLab