Loading lib_com/gs_bitallocation.c +76 −32 Original line number Diff line number Diff line Loading @@ -46,14 +46,12 @@ #include "ivas_prot.h" #include "wmc_auto.h" #ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING /*-------------------------------------------------------------------* * Local function prototypes * Local constants *-------------------------------------------------------------------*/ static float Find_bit_frac( const int16_t nb_band, const int16_t remaining_bits ); static void reajust_bits( float *bits_per_bands, const int16_t st_band, const int16_t end_band, const int16_t sum_bit_in, const int16_t bit_bdgt_in ); #ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING #define Q15_0_33 10922 /* 0.33 */ #define Q18_0_1 26214 /* 0.1 */ #define Q18_0_50 131072 /* 0.50 */ Loading @@ -72,9 +70,24 @@ static void reajust_bits( float *bits_per_bands, const int16_t st_band, const in #define Q31_0_02 42949673 /* 0.02 */ #define Q31_0_17 365072220 /* 0.17 */ #define Q31_0_23 493921239 /* 0.23 */ #endif /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ static float Find_bit_frac( const int16_t nb_band, const int16_t remaining_bits ); static void reajust_bits( float *bits_per_bands, const int16_t st_band, const int16_t end_band, const int16_t sum_bit_in, const int16_t bit_bdgt_in ); #ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING static Word16 Find_norm_inv( const Word32 ToDivide, Word16 *e_div ); static Word16 Find_bit_alloc_IVAS_int( const Word32 core_brate, const Word16 GSC_IVAS_mode, const Word16 Diff_len, const Word16 nb_tot_bands, const Word16 L_frame, Word16 *bit, Word16 *max_ener_band, float *ener_vec, float *bits_per_bands ); static Word16 maximum_fx( const Word16 *vec_fx, const Word16 lvec_fx, Word16 *max_fx ); #endif /*-------------------------------------------------------------------* Loading Loading @@ -398,7 +411,7 @@ void bands_and_bit_alloc( } } #else nb_tot_bands = Find_bit_alloc_IVAS_int( core_brate, GSC_IVAS_mode, Diff_len, nb_tot_bands, L_frame, bit, max_ener_band, ener_vec, bits_per_bands ); nb_tot_bands = (int16_t) Find_bit_alloc_IVAS_int( (Word32) core_brate, (Word16) GSC_IVAS_mode, (Word16) Diff_len, (Word16) nb_tot_bands, (Word16) L_frame, (Word16 *) bit, (Word16 *) max_ener_band, ener_vec, bits_per_bands ); nb_bands = nb_tot_bands; #endif } Loading Loading @@ -962,9 +975,17 @@ static float Find_bit_frac( return ( var_out ); } #ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING static Word16 Find_bit_alloc_IVAS_int( /*o: Number of band to encode */ /*-------------------------------------------------------------------* * Find_bit_alloc_IVAS_int() * * *-------------------------------------------------------------------*/ static Word16 Find_bit_alloc_IVAS_int( /*o: Number of band to encode */ const Word32 core_brate, /* i : core bit rate */ const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ const Word16 Diff_len, /* i : Length of the difference signal (before pure spectral)*/ Loading @@ -978,27 +999,26 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number { Word32 mp, mb, nb_bands_adj, bit_adj; Word16 nb_pulse_per_band[MBANDS_GN_BITALLOC16k]; Word32 SWB_bit_budget; // Q0 -> Q18 Word32 SWB_bit_budget; /* Q0 -> Q18 */ Word16 i, j, nb_bands_max, st_band, nb_tot_bands_loc, etmp; Word32 sum_bit /*Q18*/, bit_fracf /*Q18*/; Word16 d_tmp, e_div, tmp16, ener_vec[MBANDS_GN_BITALLOC16k]; Word32 Ltmp, etmp_32fx, bits_per_bands[MBANDS_GN_BITALLOC16k]; SWB_bit_budget = *bit; // Q0 SWB_bit_budget = *bit; /* Q0 */ st_band = 5; nb_bands_max = nb_tot_bands_in; for ( i = 0; i < MBANDS_GN; i++ ) { ener_vec[i] = (short) ( ener_vec_io[i] ); /* Q12 -> Q12 */ ener_vec[i] = (Word16) ( ener_vec_io[i] ); /* Q12 -> Q12 */ } if ( L_frame == L_FRAME16k ) { for ( i = MBANDS_GN; i < MBANDS_GN_BITALLOC16k; i++ ) { ener_vec[i] = (short) ( ener_vec_io[i] * 4096.0 + 0.5f ); /* Q0 -> Q12 */ ener_vec[i] = (Word16) ( ener_vec_io[i] * 4096.0 + 0.5f ); /* Q0 -> Q12 */ } } Loading @@ -1020,12 +1040,14 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number { nb_bands_max -= 6; } if ( GSC_IVAS_mode == 2 ) { /* bit_fracf += 0.1f; */ bit_fracf += Q18_0_1; /* Q18*/ nb_bands_max -= 1; } if ( GSC_IVAS_mode == 3 ) { /* bit_fracf -= 0.1f; */ Loading @@ -1041,12 +1063,12 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number if ( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG ) { /* nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;*/ nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, 18 ) ), Q18_0_75 ); // Q18 nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, 18 ) ), Q18_0_75 ); /* Q18 */ } else if ( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG ) { /*nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;*/ nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, 18 ) ), Q18_1_2 ); // Q18 nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, 18 ) ), Q18_1_2 ); /* Q18 */ } /*nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f);*/ Loading Loading @@ -1155,9 +1177,10 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number bits_per_bands[max_ener_band[j]] = mb; } mb -= bit_fracf; SWB_bit_budget -= bits_per_bands[max_ener_band[j]]; // Q18 SWB_bit_budget -= bits_per_bands[max_ener_band[j]]; /* Q18 */ } } /* Series of verification in case bit allocated != the budget */ if ( SWB_bit_budget > 0 ) { Loading Loading @@ -1191,7 +1214,6 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number bits_per_bands[i] = Q18_112; j = add( j, add( i, 1 ) ); } /* safety check for overage bit reallocation */ /* else if (bits_per_bands[i] + sum_bit / 3 > 112) */ else if ( L_add( bits_per_bands[i], Mpy_32_16_1( sum_bit, Q15_0_33 ) ) > Q18_112 ) Loading @@ -1210,24 +1232,46 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit ); } } for ( i = 0; i < MBANDS_GN_BITALLOC16k; i++ ) { bits_per_bands_o[i] = (float) bits_per_bands[i] / 262144.0f; /* Q18 -> float */ } return nb_tot_bands_loc; } static Word16 Find_norm_inv( const Word32 ToDivide, Word16 *e_div ) /* Find normalized 1 / ToDivide */ /*-------------------------------------------------------------------* * Find_norm_inv() * * Find normalized 1 / ToDivide *-------------------------------------------------------------------*/ static Word16 Find_norm_inv( const Word32 ToDivide, Word16 *e_div ) { Word16 d_tmp, e_tmp; e_tmp = norm_l( ToDivide ); d_tmp = round_fx( L_shl( ToDivide, e_tmp ) ); d_tmp = div_s( 16384, d_tmp ); /* 1.0 in Q14, dividend is normalize so >= 16384 as required for the division */ *e_div = sub( 14, e_tmp ); move16(); return d_tmp; } static Word16 maximum_fx( /* o : index of the maximum value in the input vector */ /*-------------------------------------------------------------------* * maximum_fx() * * *-------------------------------------------------------------------*/ /*! r: index of the maximum value in the input vector */ static Word16 maximum_fx( const Word16 *vec_fx, /* i : input vector */ const Word16 lvec_fx, /* i : length of input vector */ Word16 *max_fx /* o : maximum value in the input vector */ Loading @@ -1235,8 +1279,8 @@ static Word16 maximum_fx( /* o : index of the maximum val { Word16 j, ind; Word16 tmp; ind = 0; ind = 0; tmp = vec_fx[0]; for ( j = 1; j < lvec_fx; j++ ) Loading Loading
lib_com/gs_bitallocation.c +76 −32 Original line number Diff line number Diff line Loading @@ -46,14 +46,12 @@ #include "ivas_prot.h" #include "wmc_auto.h" #ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING /*-------------------------------------------------------------------* * Local function prototypes * Local constants *-------------------------------------------------------------------*/ static float Find_bit_frac( const int16_t nb_band, const int16_t remaining_bits ); static void reajust_bits( float *bits_per_bands, const int16_t st_band, const int16_t end_band, const int16_t sum_bit_in, const int16_t bit_bdgt_in ); #ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING #define Q15_0_33 10922 /* 0.33 */ #define Q18_0_1 26214 /* 0.1 */ #define Q18_0_50 131072 /* 0.50 */ Loading @@ -72,9 +70,24 @@ static void reajust_bits( float *bits_per_bands, const int16_t st_band, const in #define Q31_0_02 42949673 /* 0.02 */ #define Q31_0_17 365072220 /* 0.17 */ #define Q31_0_23 493921239 /* 0.23 */ #endif /*-------------------------------------------------------------------* * Local function prototypes *-------------------------------------------------------------------*/ static float Find_bit_frac( const int16_t nb_band, const int16_t remaining_bits ); static void reajust_bits( float *bits_per_bands, const int16_t st_band, const int16_t end_band, const int16_t sum_bit_in, const int16_t bit_bdgt_in ); #ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING static Word16 Find_norm_inv( const Word32 ToDivide, Word16 *e_div ); static Word16 Find_bit_alloc_IVAS_int( const Word32 core_brate, const Word16 GSC_IVAS_mode, const Word16 Diff_len, const Word16 nb_tot_bands, const Word16 L_frame, Word16 *bit, Word16 *max_ener_band, float *ener_vec, float *bits_per_bands ); static Word16 maximum_fx( const Word16 *vec_fx, const Word16 lvec_fx, Word16 *max_fx ); #endif /*-------------------------------------------------------------------* Loading Loading @@ -398,7 +411,7 @@ void bands_and_bit_alloc( } } #else nb_tot_bands = Find_bit_alloc_IVAS_int( core_brate, GSC_IVAS_mode, Diff_len, nb_tot_bands, L_frame, bit, max_ener_band, ener_vec, bits_per_bands ); nb_tot_bands = (int16_t) Find_bit_alloc_IVAS_int( (Word32) core_brate, (Word16) GSC_IVAS_mode, (Word16) Diff_len, (Word16) nb_tot_bands, (Word16) L_frame, (Word16 *) bit, (Word16 *) max_ener_band, ener_vec, bits_per_bands ); nb_bands = nb_tot_bands; #endif } Loading Loading @@ -962,9 +975,17 @@ static float Find_bit_frac( return ( var_out ); } #ifdef NON_BE_FIX_1137_GSC_IVAS_FXFLT_DECODING static Word16 Find_bit_alloc_IVAS_int( /*o: Number of band to encode */ /*-------------------------------------------------------------------* * Find_bit_alloc_IVAS_int() * * *-------------------------------------------------------------------*/ static Word16 Find_bit_alloc_IVAS_int( /*o: Number of band to encode */ const Word32 core_brate, /* i : core bit rate */ const Word16 GSC_IVAS_mode, /* i : GSC IVAS mode */ const Word16 Diff_len, /* i : Length of the difference signal (before pure spectral)*/ Loading @@ -978,27 +999,26 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number { Word32 mp, mb, nb_bands_adj, bit_adj; Word16 nb_pulse_per_band[MBANDS_GN_BITALLOC16k]; Word32 SWB_bit_budget; // Q0 -> Q18 Word32 SWB_bit_budget; /* Q0 -> Q18 */ Word16 i, j, nb_bands_max, st_band, nb_tot_bands_loc, etmp; Word32 sum_bit /*Q18*/, bit_fracf /*Q18*/; Word16 d_tmp, e_div, tmp16, ener_vec[MBANDS_GN_BITALLOC16k]; Word32 Ltmp, etmp_32fx, bits_per_bands[MBANDS_GN_BITALLOC16k]; SWB_bit_budget = *bit; // Q0 SWB_bit_budget = *bit; /* Q0 */ st_band = 5; nb_bands_max = nb_tot_bands_in; for ( i = 0; i < MBANDS_GN; i++ ) { ener_vec[i] = (short) ( ener_vec_io[i] ); /* Q12 -> Q12 */ ener_vec[i] = (Word16) ( ener_vec_io[i] ); /* Q12 -> Q12 */ } if ( L_frame == L_FRAME16k ) { for ( i = MBANDS_GN; i < MBANDS_GN_BITALLOC16k; i++ ) { ener_vec[i] = (short) ( ener_vec_io[i] * 4096.0 + 0.5f ); /* Q0 -> Q12 */ ener_vec[i] = (Word16) ( ener_vec_io[i] * 4096.0 + 0.5f ); /* Q0 -> Q12 */ } } Loading @@ -1020,12 +1040,14 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number { nb_bands_max -= 6; } if ( GSC_IVAS_mode == 2 ) { /* bit_fracf += 0.1f; */ bit_fracf += Q18_0_1; /* Q18*/ nb_bands_max -= 1; } if ( GSC_IVAS_mode == 3 ) { /* bit_fracf -= 0.1f; */ Loading @@ -1041,12 +1063,12 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number if ( GSC_IVAS_mode == 1 && core_brate < GSC_L_RATE_STG ) { /* nb_bands_adj = 0.0125f * SWB_bit_budget - 0.75f;*/ nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, 18 ) ), Q18_0_75 ); // Q18 nb_bands_adj = L_sub( Mpy_32_32( Q31_0_0125, L_shl( SWB_bit_budget, 18 ) ), Q18_0_75 ); /* Q18 */ } else if ( GSC_IVAS_mode != 2 && core_brate > GSC_H_RATE_STG ) { /*nb_bands_adj = 0.02f * SWB_bit_budget - 1.2f;*/ nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, 18 ) ), Q18_1_2 ); // Q18 nb_bands_adj = L_sub( Mpy_32_32( Q31_0_02, L_shl( SWB_bit_budget, 18 ) ), Q18_1_2 ); /* Q18 */ } /*nb_bands_max = (int16_t)(nb_bands_max * nb_bands_adj + 0.5f);*/ Loading Loading @@ -1155,9 +1177,10 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number bits_per_bands[max_ener_band[j]] = mb; } mb -= bit_fracf; SWB_bit_budget -= bits_per_bands[max_ener_band[j]]; // Q18 SWB_bit_budget -= bits_per_bands[max_ener_band[j]]; /* Q18 */ } } /* Series of verification in case bit allocated != the budget */ if ( SWB_bit_budget > 0 ) { Loading Loading @@ -1191,7 +1214,6 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number bits_per_bands[i] = Q18_112; j = add( j, add( i, 1 ) ); } /* safety check for overage bit reallocation */ /* else if (bits_per_bands[i] + sum_bit / 3 > 112) */ else if ( L_add( bits_per_bands[i], Mpy_32_16_1( sum_bit, Q15_0_33 ) ) > Q18_112 ) Loading @@ -1210,24 +1232,46 @@ static Word16 Find_bit_alloc_IVAS_int( /*o: Number bits_per_bands[i] = L_add( bits_per_bands[i], sum_bit ); } } for ( i = 0; i < MBANDS_GN_BITALLOC16k; i++ ) { bits_per_bands_o[i] = (float) bits_per_bands[i] / 262144.0f; /* Q18 -> float */ } return nb_tot_bands_loc; } static Word16 Find_norm_inv( const Word32 ToDivide, Word16 *e_div ) /* Find normalized 1 / ToDivide */ /*-------------------------------------------------------------------* * Find_norm_inv() * * Find normalized 1 / ToDivide *-------------------------------------------------------------------*/ static Word16 Find_norm_inv( const Word32 ToDivide, Word16 *e_div ) { Word16 d_tmp, e_tmp; e_tmp = norm_l( ToDivide ); d_tmp = round_fx( L_shl( ToDivide, e_tmp ) ); d_tmp = div_s( 16384, d_tmp ); /* 1.0 in Q14, dividend is normalize so >= 16384 as required for the division */ *e_div = sub( 14, e_tmp ); move16(); return d_tmp; } static Word16 maximum_fx( /* o : index of the maximum value in the input vector */ /*-------------------------------------------------------------------* * maximum_fx() * * *-------------------------------------------------------------------*/ /*! r: index of the maximum value in the input vector */ static Word16 maximum_fx( const Word16 *vec_fx, /* i : input vector */ const Word16 lvec_fx, /* i : length of input vector */ Word16 *max_fx /* o : maximum value in the input vector */ Loading @@ -1235,8 +1279,8 @@ static Word16 maximum_fx( /* o : index of the maximum val { Word16 j, ind; Word16 tmp; ind = 0; ind = 0; tmp = vec_fx[0]; for ( j = 1; j < lvec_fx; j++ ) Loading