diff --git a/lib_com/bits_alloc.c b/lib_com/bits_alloc.c index cb3945a6ce41d683081b5c60a8eb523438f7b39c..30a9dba84a32920e52d890906e050101263d2711 100644 --- a/lib_com/bits_alloc.c +++ b/lib_com/bits_alloc.c @@ -531,17 +531,20 @@ static ivas_error acelp_FCB_allocator( *--------------------------------------------------------------------*/ ivas_error config_acelp1( - const int16_t enc_dec, /* i : encoder/decoder flag */ - const int32_t total_brate, /* i : total bitrate */ - const int32_t core_brate_inp, /* i : core bitrate */ - const int16_t core, /* i : core */ - const int16_t extl, /* i : extension layer */ - const int32_t extl_brate, /* i : extension layer bitrate */ - const int16_t L_frame, /* i : frame length at internal Fs */ - const int16_t GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ - const int16_t signaling_bits, /* i : number of signaling bits */ - const int16_t coder_type, /* i : coder type */ + const int16_t enc_dec, /* i : encoder/decoder flag */ + const int32_t total_brate, /* i : total bitrate */ + const int32_t core_brate_inp, /* i : core bitrate */ + const int16_t core, /* i : core */ + const int16_t extl, /* i : extension layer */ + const int32_t extl_brate, /* i : extension layer bitrate */ + const int16_t L_frame, /* i : frame length at internal Fs */ + const int16_t GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ + ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ + const int16_t signaling_bits, /* i : number of signaling bits */ + const int16_t coder_type, /* i : coder type */ +#ifdef NONBE_FIX_GSC_BSTR + const int16_t inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ +#endif const int16_t tc_subfr, /* i : TC subfr ID */ const int16_t tc_call, /* i : TC call number (0,1,2,3,5(DEC)) */ int16_t *nBits_es_Pred, /* o : number of bits for Es_pred Q */ @@ -775,7 +778,13 @@ ivas_error config_acelp1( } /* gain Q bit-budget - part 1 */ +#ifdef NONBE_FIX_GSC_BSTR + if ( ( coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !( core_brate <= ACELP_8k00 && coder_type != TRANSITION ) ) /* mid bitrates in GC and VC, low+mid bitrates in TC */ || + ( coder_type == INACTIVE && !inactive_coder_type_flag ) /* AVQ inactive */ + ) +#else if ( ( coder_type != UNVOICED && coder_type != AUDIO && coder_type != INACTIVE && !( core_brate <= ACELP_8k00 && coder_type != TRANSITION ) ) || ( coder_type == INACTIVE && total_brate > MAX_GSC_INACTIVE_BRATE ) ) +#endif { *nBits_es_Pred = Es_pred_bits_tbl[BIT_ALLOC_IDX( core_brate, coder_type, -1, -1 )]; bits -= *nBits_es_Pred; @@ -868,7 +877,11 @@ ivas_error config_acelp1( } else if ( core_brate >= ACELP_11k60 && ( coder_type != AUDIO && !( coder_type == INACTIVE && L_frame == L_FRAME ) ) ) { +#ifdef NONBE_FIX_GSC_BSTR + if ( coder_type == INACTIVE && L_frame == L_FRAME16k && inactive_coder_type_flag ) /* GSC Inactive @16kHz */ +#else if ( coder_type == INACTIVE && L_frame == L_FRAME16k && total_brate <= MAX_GSC_INACTIVE_BRATE ) /* GSC Inactive @16kHz */ +#endif { acelp_cfg->ltf_mode = FULL_BAND; } @@ -1052,7 +1065,13 @@ ivas_error config_acelp1( acelp_cfg->fixed_cdk_index[2] = -1; acelp_cfg->fixed_cdk_index[3] = -1; } +#ifdef NONBE_FIX_GSC_BSTR + else if ( ( coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO ) || /* @12.8kHz core except of GSC */ + ( nb_subfr == NB_SUBFR16k && ( !inactive_coder_type_flag || coder_type != INACTIVE ) ) /* @16kHz core GC, TC, AVQ inactive */ + || core == HQ_CORE /* ACELP -> HQ switching in EVS */ ) +#else else if ( ( coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO ) || ( nb_subfr == NB_SUBFR16k && ( total_brate > MAX_GSC_INACTIVE_BRATE || coder_type != INACTIVE ) ) || core == HQ_CORE ) +#endif { /* pitch Q & gain Q bit-budget - part 2*/ for ( i = 0; i < nb_subfr; i++ ) @@ -1100,7 +1119,13 @@ ivas_error config_acelp1( } /* algebraic codebook bit-budget */ +#ifdef NONBE_FIX_GSC_BSTR + if ( flag_hardcoded || /* EVS */ + ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) /* high-birate ACELP except IC */ || + ( !inactive_coder_type_flag && coder_type == INACTIVE ) /* AVQ inactive */ ) +#else if ( flag_hardcoded || ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) || ( total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE ) ) +#endif { for ( i = 0; i < nb_subfr; i++ ) { @@ -1187,7 +1212,12 @@ ivas_error config_acelp1( } /* AVQ codebook */ +#ifdef NONBE_FIX_GSC_BSTR + if ( ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) /* high-birate ACELP except IC */ || + ( !inactive_coder_type_flag && coder_type == INACTIVE ) /* AVQ inactive */ ) +#else if ( ( core_brate_inp >= MIN_BRATE_AVQ_EXC && coder_type != INACTIVE ) || ( total_brate > MAX_GSC_INACTIVE_BRATE && coder_type == INACTIVE ) ) +#endif { for ( i = 0; i < nb_subfr; i++ ) { @@ -1222,7 +1252,13 @@ ivas_error config_acelp1( } } } +#ifdef NONBE_FIX_GSC_BSTR + else if ( ( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) /* LBR secondary channel in TD stereo */ || + ( ( coder_type == INACTIVE || coder_type == AUDIO ) && nb_subfr == NB_SUBFR ) /* GSC @12.8kHz */ || + ( coder_type == INACTIVE && inactive_coder_type_flag ) /* AVQ inactive */ ) +#else else if ( ( coder_type == UNVOICED && tdm_low_rate_mode == 1 && element_mode == IVAS_CPE_TD ) || ( ( coder_type == INACTIVE || coder_type == AUDIO ) && nb_subfr == NB_SUBFR ) || ( coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE ) ) +#endif { int32_t Local_BR, Pitch_BR; int16_t Pitch_CT; @@ -1315,7 +1351,12 @@ ivas_error config_acelp1( /* sanity check */ if ( ( coder_type != INACTIVE && nb_subfr == NB_SUBFR && coder_type != AUDIO ) || nb_subfr == NB_SUBFR16k ) { +#ifdef NONBE_FIX_GSC_BSTR + if ( ( L_frame == L_FRAME16k && coder_type == INACTIVE && inactive_coder_type_flag ) /* GSC Inactive @16kHz */ || + ( GSC_IVAS_mode > 0 && L_frame == L_FRAME16k ) ) /* IVAS GSC @16kHz */ +#else if ( ( L_frame == L_FRAME16k && coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE ) || ( GSC_IVAS_mode > 0 && L_frame == L_FRAME16k ) ) /* GSC Inactive @16kHz */ +#endif { acelp_cfg->ubits = 0; } diff --git a/lib_com/gs_inact_switching.c b/lib_com/gs_inact_switching.c index cd380e86e01e4776259663a806c235b331b60bfc..cc90bad98ffe5a81bf1ffc43d5ec62c32da84227 100644 --- a/lib_com/gs_inact_switching.c +++ b/lib_com/gs_inact_switching.c @@ -59,12 +59,17 @@ *-------------------------------------------------------------------*/ void inact_switch_ematch( - float exc2[], /* i/o: CELP/GSC excitation buffer */ - float dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - float lt_ener_per_band[], /* i/o: Long term energy per band */ - const int16_t coder_type, /* i : Coder type */ - const int16_t L_frame, /* i : Frame length */ - const int32_t total_brate, /* i : Total bitrate */ + float exc2[], /* i/o: CELP/GSC excitation buffer */ + float dct_exc_tmp[], /* i : GSC excitation in DCT domain */ + float lt_ener_per_band[], /* i/o: Long term energy per band */ + const int16_t coder_type, /* i : Coder type */ +#ifdef NONBE_FIX_GSC_BSTR + const int16_t inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ +#endif + const int16_t L_frame, /* i : Frame length */ +#ifndef NONBE_FIX_GSC_BSTR + const int32_t total_brate, /* i : Total bitrate */ +#endif const int16_t bfi, /* i : frame lost indicator */ const int16_t last_core, /* i : Last core used */ const int16_t last_codec_mode, /* i : Last codec mode */ @@ -105,7 +110,11 @@ void inact_switch_ematch( lt_ener_per_band[i] = Ener_per_bd[i]; } } +#ifdef NONBE_FIX_GSC_BSTR + else if ( coder_type == INACTIVE && inactive_coder_type_flag ) +#else else if ( coder_type == INACTIVE && total_brate <= MAX_GSC_INACTIVE_BRATE ) +#endif { /* Find spectrum and energy per band for inactive frames */ edct( exc2, dct_exc_tmp, L_frame, element_mode ); diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index e88f540752a0cd5888c57ca4cb4f0b61f841b7ad..b3f2f932cf5bcde3863b1a0b6c761214442c3211 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1147,6 +1147,9 @@ enum #endif #define BITS_MASA2TOTTAL_DCT0 6 #define STEP_M2T 0.1f +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +#define STEP_M2T_FX 214748365 // Q31 +#endif #define MASA_HEADER_BITS 2 #define MASA_SUBFRAME_BITS 1 #define MASA_LOWBITRATE_MODE_BITS 1 diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index e39433fece03bb7fbc3bc5d59d3e88289dd97d47..a55aacc85de6da49f8988667c23350770c1e26aa 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -199,7 +199,10 @@ ivas_error pre_proc_front_ivas( const int16_t force_front_vad, /* i : flag to force VAD decision */ const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ const IVAS_FORMAT ivas_format, /* i : IVAS format */ - const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ + const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ +#ifdef NONBE_1211_DTX_BR_SWITCHING + const int32_t last_ivas_total_brate, /* i : last IVAS total bitrate */ +#endif const int32_t ivas_total_brate /* i : IVAS total bitrate */ #ifdef DEBUG_MODE_INFO , const int16_t ch_idx @@ -756,6 +759,32 @@ int16_t get_igf_startline( float rand_triangular_signed( int16_t *seed ); +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +Word16 matrix_product_fx( + const Word32 *X_fx, /* i : left hand matrix Qx*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Qy*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Qx + Qy - 31*/ +); + +Word16 matrix_product_q30_fx( + const Word32 *X_fx, /* i : left hand matrix Q31*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Q25*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Q30*/ +); +#endif + void dtx_read_padding_bits( DEC_CORE_HANDLE st, const int16_t num_bits diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index 58dc6dc974063e216325393cf6d9a68149c5e306..481abd06f6b12afd59bfa555afb27f06f27303e4 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -2833,6 +2833,48 @@ const int32_t sep_object_brate[][MAX_NUM_OBJECTS] = }; /* column wise DCT matrices for 4 5, and 8 dim */ +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +const Word32 dct4_fx[4 * 4] = { // Q31 + 1073741824, 1402951040, 1073741824, 581109056, + 1073741824, 581109056, -1073741824, -1402951040, + 1073741824, -581109056, -1073741824, 1402951040, + 1073741824, -1402951040, 1073741824, -581109056 +}; + +const Word32 dct5_fx[5 * 5] = { // Q31 + 960354688, 1291711360, 1098867328, 798219648, 419618304, + 960354688, 798219648, -419618304, -1291711360, -1098867328, + 960354688, 0, -1358283392, 0, 1358283392, + 960354688, -798219648, -419618304, 1291711360, -1098867328, + 960354688, -1291711360, 1098867328, -798219648, 419618304 +}; + +const Word32 dct8_fx[8 * 8] = { // Q31 + 759350208, 1053125952, 991922688, 892708928, 759350208, 596570944, 410813632, 209379648, + 759350208, 892708928, 410813632, -209379648, -759350208, -1053125952, -991922688, -596570944, + 759350208, 596570944, -410813632, -1053125952, -759350208, 209379648, 991922688, 892708928, + 759350208, 209379648, -991922688, -596570944, 759350208, 892708928, -410813632, -1053125952, + 759350208, -209379648, -991922688, 596570944, 759350208, -892708928, -410813632, 1053125952, + 759350208, -596570944, -410813632, 1053125952, -759350208, -209379648, 991922688, -892708928, + 759350208, -892708928, 410813632, 209379648, -759350208, 1053125952, -991922688, 596570944, + 759350208, -1053125952, 991922688, -892708928, 759350208, -596570944, 410813632, -209379648 +}; + +const Word32 dct12_fx[12 * 12] = { // Q31 + 619978560, 869301376, 846752832, 810030848, 759350208, 695569984, 619978560, 533649696, 438301408, 335436960, 226989024, 114460880, + 619978560, 810030848, 619978560, 335436960, 0, -335436960, -619978560, -810030848, -876602816, -810030848, -619978560, -335436960, + 619978560, 695569984, 226989024, -335436960, -759350208, -869301376, -619978560, -114460880, 438301408, 810030848, 846752832, 533649696, + 619978560, 533649696, -226989024, -810030848, -759350208, -114460880, 619978560, 869301376, 438301408, -335436960, -846752832, -695569984, + 619978560, 335436960, -619978560, -810030848, 0, 810030848, 619978560, -335436960, -876602816, -335436960, 619978560, 810030848, 619978560, + 114460880, -846752832, -335436960, 759350208, 533649696, -619978560, -695569984, 438301408, 810030848, -226989024, -869301376, 619978560, + -114460880, -846752832, 335436960, 759350208, -533649696, -619978560, 695569984, 438301408, -810030848, -226989024, 869301376, 619978560, + -335436960, -619978560, 810030848, 0, -810030848, 619978560, 335436960, -876602816, 335436960, 619978560, -810030848, 619978560, -533649696, + -226989024, 810030848, -759350208, 114460880, 619978560, -869301376, 438301408, 335436960, -846752832, 695569984, 619978560, -695569984, + 226989024, 335436960, -759350208, 869301376, -619978560, 114460880, 438301408, -810030848, 846752832, -533649696, 619978560, -810030848, + 619978560, -335436960, 0, 335436960, -619978560, 810030848, -876602816, 810030848, -619978560, 335436960, 619978560, -869301376, 846752832, + -810030848, 759350208, -695569984, 619978560, -533649696, 438301408, -335436960, 226989024, -114460880 +}; +#endif const float dct4[4*4] = { 0.5000f, 0.6533f, 0.5000f, 0.2706f, diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index f597fe8b90efcd7d98788e61c8840f90a1a192af..35e3950fde88dac199953f1f04f3811f45dabf07 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -327,6 +327,12 @@ extern const float dct4[]; extern const float dct5[]; extern const float dct8[]; extern const float dct12[]; +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +extern const Word32 dct4_fx[]; +extern const Word32 dct5_fx[]; +extern const Word32 dct8_fx[]; +extern const Word32 dct12_fx[]; +#endif /*----------------------------------------------------------------------------------* * ISM ROM tables diff --git a/lib_com/ivas_tools.c b/lib_com/ivas_tools.c index ee7a06ca7d9b7300b7fd00eff316ef8ccf6ed775..d095c0ebe15e409aa70edf40c384a7404b072116 100644 --- a/lib_com/ivas_tools.c +++ b/lib_com/ivas_tools.c @@ -41,7 +41,9 @@ #include "ivas_prot.h" #include "wmc_auto.h" #include "ivas_rom_com.h" - +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +#include "basop_settings.h" +#endif /*--------------------------------------------------------------- * sumAbs() * @@ -1252,3 +1254,243 @@ float rand_triangular_signed( return 0.5f - 0.5f * sqrtf( 1.0f - rand_val ); } } + +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +Word16 matrix_product_fx( + const Word32 *X_fx, /* i : left hand matrix Qx*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Qy*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Qx + Qy - 31*/ +) +{ + Word16 i, j, k; + Word16 x_idx, y_idx; + Word32 *Zp_fx = Z_fx; + + /* Processing */ + + if ( transpX == 1 && transpY == 0 ) /* We use X transpose */ + { + if ( rowsX != rowsY ) + { + return EXIT_FAILURE; + } + for ( j = 0; j < colsY; ++j ) + { + for ( i = 0; i < colsX; ++i ) + { + ( *Zp_fx ) = 0; + + for ( k = 0; k < rowsX; ++k ) + { + x_idx = k + i * rowsX; /*Q0*/ + y_idx = k + j * rowsY; /*Q0*/ + ( *Zp_fx ) = *Zp_fx + Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Qx + Qy - 31*/ + } + Zp_fx++; + } + } + } + else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */ + { + if ( colsX != colsY ) + { + return EXIT_FAILURE; + } + for ( j = 0; j < rowsY; ++j ) + { + for ( i = 0; i < rowsX; ++i ) + { + ( *Zp_fx ) = 0; + for ( k = 0; k < colsX; ++k ) + { + x_idx = i + k * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + ( *Zp_fx ) = ( *Zp_fx ) + Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Qx + Qy - 31*/ + } + Zp_fx++; + } + } + } + else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */ + { + if ( rowsX != colsY ) + { + return EXIT_FAILURE; + } + for ( j = 0; j < rowsY; ++j ) + { + for ( i = 0; i < colsX; ++i ) + { + ( *Zp_fx ) = 0; + + for ( k = 0; k < colsX; ++k ) + { + x_idx = k + i * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + ( *Zp_fx ) = ( *Zp_fx ) + Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Qx + Qy - 31*/ + } + + Zp_fx++; + } + } + } + else /* Regular case */ + { + if ( colsX != rowsY ) + { + return EXIT_FAILURE; + } + + for ( j = 0; j < colsY; ++j ) + { + for ( i = 0; i < rowsX; ++i ) + { + ( *Zp_fx ) = 0; + + for ( k = 0; k < colsX; ++k ) + { + x_idx = i + k * rowsX; /*Q0*/ + y_idx = k + j * rowsY; /*Q0*/ + ( *Zp_fx ) = ( *Zp_fx ) + Mpy_32_32( X_fx[x_idx], Y_fx[y_idx] ); /*Qx + Qy - 31 L_sat_add() */ + /* TODO: overflow of Z_fx to be checked */ + move32(); + } + Zp_fx++; + } + } + } + + return EXIT_SUCCESS; +} + +Word16 matrix_product_q30_fx( + const Word32 *X_fx, /* i : left hand matrix Q31*/ + const Word16 rowsX, /* i : number of rows of the left hand matrix Q0*/ + const Word16 colsX, /* i : number of columns of the left hand matrix Q0*/ + const Word16 transpX, /* i : flag indicating the transposition of the left hand matrix prior to the multiplication Q0*/ + const Word32 *Y_fx, /* i : right hand matrix Q25*/ + const Word16 rowsY, /* i : number of rows of the right hand matrix Q0*/ + const Word16 colsY, /* i : number of columns of the right hand matrix Q0*/ + const Word16 transpY, /* i : flag indicating the transposition of the right hand matrix prior to the multiplication Q0*/ + Word32 *Z_fx /* o : resulting matrix after the matrix multiplication Q30*/ +) +{ + Word16 i, j, k; + Word16 x_idx, y_idx; + Word32 *Zp_fx = Z_fx; + int64_t W_tmp; + + /* Processing */ + test(); + test(); + test(); + if ( transpX == 1 && transpY == 0 ) /* We use X transpose */ + { + if ( rowsX != rowsY ) + { + return EXIT_FAILURE; + } + for ( j = 0; j < colsY; ++j ) + { + for ( i = 0; i < colsX; ++i ) + { + W_tmp = 0; + for ( k = 0; k < rowsX; ++k ) + { + /*( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[k + j * rowsY] ) ); */ + x_idx = k + i * rowsX; /* Q0 */ + y_idx = k + j * rowsY; /* Q0 */ + W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56 */ + } + W_tmp = W_tmp * 64; /* W_shl( W_tmp, 6 ); */ /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /* W_round64_L( W_tmp ); */ /*Q30*/ + Zp_fx++; + } + } + } + else if ( transpX == 0 && transpY == 1 ) /* We use Y transpose */ + { + if ( colsX != colsY ) + { + return EXIT_FAILURE; + } + for ( j = 0; j < rowsY; ++j ) + { + for ( i = 0; i < rowsX; ++i ) + { + W_tmp = 0; + for ( k = 0; k < colsX; ++k ) + { + /* ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[j + k * rowsY] ) ); */ + x_idx = i + k * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56 */ + } + W_tmp = W_tmp * 64; /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ + Zp_fx++; + } + } + } + else if ( transpX == 1 && transpY == 1 ) /* We use both transpose */ + { + if ( rowsX != colsY ) + { + return EXIT_FAILURE; + } + for ( j = 0; j < rowsY; ++j ) + { + for ( i = 0; i < colsX; ++i ) + { + W_tmp = 0; + for ( k = 0; k < colsX; ++k ) + { + /* ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[k + i * rowsX], Y_fx[j + k * rowsY] ) ); */ + x_idx = k + i * rowsX; /*Q0*/ + y_idx = j + k * rowsY; /*Q0*/ + W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56*/ + } + W_tmp = W_tmp * 64; /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ + + Zp_fx++; + } + } + } + else /* Regular case */ + { + if ( colsX != rowsY ) + { + return EXIT_FAILURE; + } + + for ( j = 0; j < colsY; ++j ) + { + for ( i = 0; i < rowsX; ++i ) + { + W_tmp = 0; + + for ( k = 0; k < colsX; ++k ) + { + /* ( *Zp_fx ) = L_add( *Zp_fx, Mpy_32_32( X_fx[i + k * rowsX], Y_fx[k + j * rowsY] ) ); */ + x_idx = i + k * rowsX; /*Q0*/ + y_idx = k + j * rowsY; /*Q0*/ + W_tmp += ( (int64_t) X_fx[x_idx] * (int64_t) Y_fx[y_idx] ); /* Q56*/ + } + W_tmp = W_tmp * 64; /*Q62*/ + ( *Zp_fx ) = ( W_tmp + 0x80000000 ) >> 32; /*Q30*/ + + Zp_fx++; + } + } + } + + return EXIT_SUCCESS; +} +#endif diff --git a/lib_com/options.h b/lib_com/options.h index e2194149a3f9f6d80eb16190fce389995f03c987..a95e3f51fb5654949c3b38f1c223c838763a2044 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -174,6 +174,14 @@ #define NONBE_1233_HQ_CLASSIFIER_DIV_BY_ZERO /* Eri: issue 1233: Address possible division by zero in hf_spectrum_sparseness() */ #define NONE_BE_FIX_BASOP_1044_OSBA_PRERENDER_MIX_GAINS /* DLB: adjust prerendering and mixing gain in OSBA encoder. This is fix to float codes*/ +#define NONBE_1211_DTX_BR_SWITCHING /* VA: port float issue 1211: fix crash in MASA DTX bitrate switching */ +#define NONBE_FIX_1189_GSC_IVAS_OMASA /* VA: Fix for issue 1189: Bitstream desynchornization due to reading/writing of the GSC_IVAS_mode parameter */ +#define NONBE_FIX_1087_OOB_SBA_DTX_RS /* VA: issue 1087: Extend the length of the buffer for MCT decoding to avoid out-of-bound writing in SBA SID bitrate switching decoding */ +#define FIX_920_IGF_INIT_ERROR /* FhG: issue 920: fix bitrate mismatch in initial IGF config to avoid error message in same cases */ +#define NONBE_1273_ISM_METADATA_COUNTER /* VA: FLP issue 1273: fix counter overflow in ISM metadata encoder */ +#define NONBE_FIX_GSC_BSTR /* VA: issue 1264 FLP (1189 BASOP): Fix bitstream synchronization between encoder and decoder in ACELP GSC in OMASA */ + +#define NONBE_1319_M2R_PRECISION_ALIGN /* Nokia: bring updates from PC code related to OMASA masa2total ratios */ /* #################### End FIXES switches ############################ */ #define BASOP_NOGLOB /* Disable global symbols in BASOPs, Overflow/Carry in BASOPs disabled, additional BASOPs in case of Overflow */ diff --git a/lib_com/prot.h b/lib_com/prot.h index 8a674e9827e7672501885f8dbdfdc7cc88b77529..61352b5d1880d7036a4c759a04c0f80d21bf1de3 100644 --- a/lib_com/prot.h +++ b/lib_com/prot.h @@ -3548,12 +3548,17 @@ void highband_exc_dct_in( ); void inact_switch_ematch( - float exc2[], /* i/o: CELP/GSC excitation buffer */ - float dct_exc_tmp[], /* i : GSC excitation in DCT domain */ - float lt_ener_per_band[], /* i/o: long-term energy per band */ - const int16_t coder_type, /* i : coder type */ - const int16_t L_frame, /* i : frame length */ - const int32_t total_brate, /* i : Total bitrate */ + float exc2[], /* i/o: CELP/GSC excitation buffer */ + float dct_exc_tmp[], /* i : GSC excitation in DCT domain */ + float lt_ener_per_band[], /* i/o: long-term energy per band */ + const int16_t coder_type, /* i : coder type */ +#ifdef NONBE_FIX_GSC_BSTR + const int16_t inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ +#endif + const int16_t L_frame, /* i : frame length */ +#ifndef NONBE_FIX_GSC_BSTR + const int32_t total_brate, /* i : Total bitrate */ +#endif const int16_t bfi, /* i : frame lost indicator */ const int16_t last_core, /* i : Last core used */ const int16_t last_codec_mode, /* i : Last codec mode */ @@ -3902,8 +3907,11 @@ void td_cng_enc_init( ); void dtx( - Encoder_State *st, /* i/o: encoder state structure */ - const int32_t ivas_total_brate, /* i : IVAS total bitrate */ + Encoder_State *st, /* i/o: encoder state structure */ +#ifdef NONBE_1211_DTX_BR_SWITCHING + const int32_t last_ivas_total_brate, /* i : last IVAS total bitrate */ +#endif + const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t vad, /* i : VAD flag for DTX */ const float speech[] /* i : Pointer to the speech frame */ ); @@ -6759,7 +6767,10 @@ float correlation_shift( void init_coder_ace_plus( Encoder_State *st, /* i : Encoder state handle */ const int32_t last_total_brate, /* i : last total bitrate */ - const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ +#ifdef FIX_920_IGF_INIT_ERROR + const int32_t igf_brate, /* i : IGF configuration bitrate */ +#endif + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0)*/ ); void core_coder_reconfig( @@ -9081,17 +9092,20 @@ int16_t BITS_ALLOC_config_acelp( ); ivas_error config_acelp1( - const int16_t enc_dec, /* i : encoder/decoder flag */ - const int32_t total_brate, /* i : total bitrate */ - const int32_t core_brate_inp, /* i : core bitrate */ - const int16_t core, /* i : core */ - const int16_t extl, /* i : extension layer */ - const int32_t extl_brate, /* i : extension layer bitrate */ - const int16_t L_frame, /* i : frame length at internal Fs */ - const int16_t GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ - ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ - const int16_t signaling_bits, /* i : number of signaling bits */ - const int16_t coder_type, /* i : coder type */ + const int16_t enc_dec, /* i : encoder/decoder flag */ + const int32_t total_brate, /* i : total bitrate */ + const int32_t core_brate_inp, /* i : core bitrate */ + const int16_t core, /* i : core */ + const int16_t extl, /* i : extension layer */ + const int32_t extl_brate, /* i : extension layer bitrate */ + const int16_t L_frame, /* i : frame length at internal Fs */ + const int16_t GSC_noisy_speech, /* i : GSC on SWB noisy speech flag */ + ACELP_config *acelp_cfg, /* i : ACELP bit-allocation */ + const int16_t signaling_bits, /* i : number of signaling bits */ + const int16_t coder_type, /* i : coder type */ +#ifdef NONBE_FIX_GSC_BSTR + const int16_t inactive_coder_type_flag, /* i : AVQ (0) or GSC (1) IC flag */ +#endif const int16_t tc_subfr, /* i : TC subfr ID */ const int16_t tc_call, /* i : TC call number (0,1,2) */ int16_t *nBits_es_Pred, /* o : number of bits for Es_pred Q */ diff --git a/lib_dec/FEC.c b/lib_dec/FEC.c index c0db9325f504d743f2416272dc16a8e2859f7552..4f4fb45032529f446dc3d554632cd23a3a2cb3fe 100644 --- a/lib_dec/FEC.c +++ b/lib_dec/FEC.c @@ -332,7 +332,11 @@ void FEC_exc_estim( * Replicate the last spectrum in case the last good frame was coded by GSC *-----------------------------------------------------------------*/ +#ifdef NONBE_FIX_GSC_BSTR + if ( ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) && st->inactive_coder_type_flag && !st->Opt_AMR_WB ) +#else if ( ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) && st->total_brate <= MAX_GSC_INACTIVE_BRATE && !st->Opt_AMR_WB ) +#endif { /* Replication of the last spectrum, with a slight downscaling of its dynamic */ st->GSC_noisy_speech = st->Last_GSC_noisy_speech_flag; @@ -405,7 +409,11 @@ void FEC_exc_estim( * Total excitation *-----------------------------------------------------------------*/ +#ifdef NONBE_FIX_GSC_BSTR + if ( ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) && st->inactive_coder_type_flag && !st->Opt_AMR_WB ) +#else if ( ( st->last_coder_type == AUDIO || st->last_good == INACTIVE_CLAS ) && st->total_brate <= MAX_GSC_INACTIVE_BRATE && !st->Opt_AMR_WB ) +#endif { /* For GSC - the excitation is already computed */ mvr2r( exc, exc2, st->L_frame ); diff --git a/lib_dec/acelp_core_dec.c b/lib_dec/acelp_core_dec.c index 8233e26376bf2c4347a0f3750068b41b9cb3b3d6..121985ef2096fbfea4ec6acb1e5032839885e43f 100644 --- a/lib_dec/acelp_core_dec.c +++ b/lib_dec/acelp_core_dec.c @@ -487,7 +487,11 @@ ivas_error acelp_core_dec( if ( st->element_mode > EVS_MONO && st->idchan == 0 && !( st->core_brate == FRAME_NO_DATA || st->core_brate == SID_2k40 ) && !tdm_low_rate_mode ) { +#ifdef NONBE_FIX_1189_GSC_IVAS_OMASA + if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->inactive_coder_type_flag ) ) +#else if ( st->coder_type == AUDIO || ( st->coder_type == INACTIVE && st->total_brate <= MAX_GSC_INACTIVE_BRATE ) ) +#endif { st->GSC_IVAS_mode = get_next_indice( st, 2 ); } @@ -617,11 +621,19 @@ ivas_error acelp_core_dec( nb_bits = -1; } +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr_tmp, 1, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif if ( st->coder_type == TRANSITION && tc_subfr < L_SUBFR && st->L_frame == L_FRAME ) { +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, TRANSITION, -1, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, tc_subfr, 2, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif } } @@ -843,7 +855,11 @@ ivas_error acelp_core_dec( * Apply energy matching when switching to inactive frames *-----------------------------------------------------------------*/ +#ifdef NONBE_FIX_GSC_BSTR + inact_switch_ematch( exc2, dct_exc_tmp, st->hGSCDec->lt_ener_per_band, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); +#else inact_switch_ematch( exc2, dct_exc_tmp, st->hGSCDec->lt_ener_per_band, st->coder_type, st->L_frame, st->total_brate, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); +#endif /*------------------------------------------------------------* * Decode information and modify the excitation signal of stationary unvoiced frames @@ -979,7 +995,11 @@ ivas_error acelp_core_dec( } /* Apply energy matching when switching to inactive frames */ +#ifdef NONBE_FIX_GSC_BSTR + inact_switch_ematch( exc2, dct_exc_tmp, st->hGSCDec->lt_ener_per_band, st->coder_type, st->inactive_coder_type_flag, st->L_frame, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); +#else inact_switch_ematch( exc2, dct_exc_tmp, st->hGSCDec->lt_ener_per_band, st->coder_type, st->L_frame, st->total_brate, st->bfi, st->last_core, st->last_codec_mode, tdm_low_rate_mode, st->element_mode ); +#endif /* update past excitation signals for LD music post-filter */ if ( st->hMusicPF != NULL ) diff --git a/lib_dec/acelp_core_switch_dec.c b/lib_dec/acelp_core_switch_dec.c index 51d459b205e980505dd12a2d5c87795b95244c8b..065e77b5ec5185d3fd20307e39532d26ad769cf5 100644 --- a/lib_dec/acelp_core_switch_dec.c +++ b/lib_dec/acelp_core_switch_dec.c @@ -158,7 +158,11 @@ ivas_error acelp_core_switch_dec( * Excitation decoding *----------------------------------------------------------------*/ +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( DEC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, GENERIC, st->inactive_coder_type_flag, -1, -1, &decode_bwe /* dummy */, &i, st->element_mode, &i /*dummy*/, 0, 0, st->idchan, st->active_cnt, 0, 0, 0 /*st->GSC_IVAS_mode*/ ); +#else config_acelp1( DEC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), st->next_bit_pos, GENERIC, -1, -1, &decode_bwe /* dummy */, &i, st->element_mode, &i /*dummy*/, 0, 0, st->idchan, st->active_cnt, 0, 0, 0 /*st->GSC_IVAS_mode*/ ); +#endif decod_gen_voic_core_switch( st, L_frame_for_cs, 0, Aq, exc, cbrate ); diff --git a/lib_dec/dec_gen_voic.c b/lib_dec/dec_gen_voic.c index c8220be8611da8f6014840912da1be0402ad74d5..7056adb3d43abf57a3744d7e1cd4551c5442b950 100644 --- a/lib_dec/dec_gen_voic.c +++ b/lib_dec/dec_gen_voic.c @@ -174,7 +174,11 @@ ivas_error decod_gen_voic( * Transform-domain contribution decoding (inactive frames) *-----------------------------------------------------------------*/ +#ifdef NONBE_FIX_GSC_BSTR + if ( !st->inactive_coder_type_flag && st->coder_type == INACTIVE ) +#else if ( st->total_brate >= MAX_GSC_INACTIVE_BRATE && st->coder_type == INACTIVE ) +#endif { transf_cdbk_dec( st, 0, i_subfr, Es_pred, gain_code, &gain_preQ, &norm_gain_preQ, code_preQ, unbits ); } @@ -196,7 +200,6 @@ ivas_error decod_gen_voic( * Add the ACELP pre-quantizer contribution *-----------------------------------------------------------------*/ - /* if( (coder_type == GENERIC && st->core_brate >= MIN_BRATE_AVQ_EXC) || (coder_type == INACTIVE && st->total_brate > MAX_GSC_INACTIVE_BRATE) ) */ if ( gain_preQ != 0 ) { for ( i = 0; i < L_SUBFR; i++ ) diff --git a/lib_dec/gs_dec.c b/lib_dec/gs_dec.c index 30f6d17143c20e63054e0e873a468eb1bdf49d98..3269374dea154fd1eb8aec3722196a709ec2c3da 100644 --- a/lib_dec/gs_dec.c +++ b/lib_dec/gs_dec.c @@ -111,7 +111,11 @@ void decod_audio( } /* set bit-allocation */ +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, st->inactive_coder_type_flag, -1, 1, &nb_bits, NULL, st->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( DEC, st->total_brate, st->core_brate, st->core, st->extl_orig, st->extl_brate_orig, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), st->next_bit_pos, st->coder_type, -1, 1, &nb_bits, NULL, st->element_mode, &nbits /*dummy*/, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif /*---------------------------------------------------------------* * Decode energy dynamics diff --git a/lib_dec/ivas_mct_dec.c b/lib_dec/ivas_mct_dec.c index 55750ed95da209cc83804cd2f34866826c97c3e1..08f574e24d221de559414a7363871765e994a8aa 100644 --- a/lib_dec/ivas_mct_dec.c +++ b/lib_dec/ivas_mct_dec.c @@ -83,6 +83,9 @@ ivas_error ivas_mct_dec( STnsData tnsData[MCT_MAX_BLOCKS][CPE_CHANNELS][NB_DIV]; Decoder_State **sts; float synth[CPE_CHANNELS][L_FRAME_PLUS]; +#ifdef NONBE_FIX_1087_OOB_SBA_DTX_RS + float *p_output_orig[2]; +#endif float output_lfe_ch[L_FRAME48k]; int32_t ivas_total_brate; ivas_error error; @@ -144,6 +147,18 @@ ivas_error ivas_mct_dec( /* MCT side bits decoder */ ivas_mct_side_bits( hMCT, st_ivas->hCPE, nCPE, st_ivas->hCPE[0]->hCoreCoder[0], st_ivas->bfi, st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream, ivas_total_brate, nb_bits_metadata ); +#ifdef NONBE_FIX_1087_OOB_SBA_DTX_RS + /* in case of switching from an SID frame (with ACELP core) to MCT, buffer of L_FRAME_PLUS samples is needed -> use synth[] as a temporary buffer */ + if ( st_ivas->hCPE[0]->hCoreCoder[0]->last_core == ACELP_CORE ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + p_output_orig[n] = output[n]; + output[n] = synth[n]; + } + } +#endif + for ( cpe_id = 0; cpe_id < nCPE; cpe_id++ ) { st_ivas->hCPE[cpe_id]->hCoreCoder[0]->BER_detect |= st_ivas->BER_detect; @@ -228,6 +243,17 @@ ivas_error ivas_mct_dec( ivas_mdct_core_reconstruct( hCPE, x, synth, fUseTns[cpe_id], 1 ); +#ifdef NONBE_FIX_1087_OOB_SBA_DTX_RS + /* set pointers back */ + if ( cpe_id == 0 && st_ivas->hCPE[0]->hCoreCoder[0]->last_core == ACELP_CORE ) + { + for ( n = 0; n < CPE_CHANNELS; n++ ) + { + output[n] = p_output_orig[n]; + } + } + +#endif /*----------------------------------------------------------------* * CoreCoder Post-processing and updates *----------------------------------------------------------------*/ diff --git a/lib_dec/ivas_qmetadata_dec.c b/lib_dec/ivas_qmetadata_dec.c index 414bef715a83e6d808cddf389f7037988b89b124..0d5fc1bb3ad0e6e51d2b64a0518676b6fd872aa6 100644 --- a/lib_dec/ivas_qmetadata_dec.c +++ b/lib_dec/ivas_qmetadata_dec.c @@ -40,6 +40,9 @@ #include "ivas_rom_dec.h" #include "wmc_auto.h" #include "prot.h" +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +#include "basop_settings.h" +#endif /*-----------------------------------------------------------------------* * Local function prototypes @@ -97,8 +100,11 @@ static int16_t read_surround_coherence_hr( uint16_t *bitstream, int16_t *p_bit_p static int16_t read_coherence_data_hr_512( uint16_t *bitstream, int16_t *p_bit_pos, IVAS_QMETADATA *hQMetaData, const int16_t idx_dir, const int16_t nbits_coh ); +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +static void read_stream_dct_coeffs_omasa( int16_t *q_idx, Word32 *q_dct_data_fx, const int16_t len_stream, uint16_t *bit_stream, int16_t *index, const int16_t first_line ); +#else static void read_stream_dct_coeffs_omasa( int16_t *q_idx, float *q_dct_data, const int16_t len_stream, uint16_t *bit_stream, int16_t *index, const int16_t first_line ); - +#endif /*-----------------------------------------------------------------------* * Global function definitions @@ -4247,7 +4253,11 @@ static void decode_combined_index( static void read_stream_dct_coeffs_omasa( int16_t *q_idx, +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + Word32 *q_dct_data_fx, +#else float *q_dct_data, +#endif const int16_t len_stream, uint16_t *bit_stream, int16_t *index, @@ -4255,11 +4265,16 @@ static void read_stream_dct_coeffs_omasa( { int16_t sign, nbits; int16_t i, j, i_min; - +#ifndef NONBE_1319_M2R_PRECISION_ALIGN float step; +#endif int16_t GR1, GR2; - +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + int64_t step_fx; + step_fx = STEP_M2T_FX; +#else step = STEP_M2T; +#endif nbits = 0; sign = 1; if ( first_line == 0 ) @@ -4326,6 +4341,20 @@ static void read_stream_dct_coeffs_omasa( } /* deindex */ +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + q_dct_data_fx[0] = (Word32) ( ( step_fx * q_idx[0] ) >> 6 ); /* Q25 */ + for ( i = 1; i < len_stream; i++ ) + { + if ( ( q_idx[i] & 1 ) == 0 ) + { + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( -q_idx[i] ) ) >> 7 ); /* Q25 */ + } + ELSE + { + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( q_idx[i] + 1 ) ) >> 7 ); /* Q25 */ + } + } +#else q_dct_data[0] = q_idx[0] * step; for ( i = 1; i < len_stream; i++ ) { @@ -4338,7 +4367,7 @@ static void read_stream_dct_coeffs_omasa( q_dct_data[i] = ( ( q_idx[i] + 1 ) >> 1 ) * step; } } - +#endif return; } @@ -4357,11 +4386,18 @@ void ivas_omasa_decode_masa_to_total( { int16_t i, j, k; int16_t q_idx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + Word32 q_dct_data_fx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS], + dct_data_tmp_fx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; +#else float q_dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS], dct_data_tmp[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; +#endif int16_t n_streams, len_stream; +#ifndef NONBE_1319_M2R_PRECISION_ALIGN #ifdef NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL int32_t int_tmp; +#endif #endif /* Setup coding parameters */ n_streams = 1; @@ -4375,10 +4411,95 @@ void ivas_omasa_decode_masa_to_total( set_s( q_idx, 0, nbands * nblocks ); for ( i = 0; i < n_streams; i++ ) { - read_stream_dct_coeffs_omasa( &q_idx[i * len_stream], &q_dct_data[i * len_stream], len_stream, bit_stream, index, i == 0 ); + read_stream_dct_coeffs_omasa( &q_idx[i * len_stream], +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + &q_dct_data_fx[i * len_stream], +#else + &q_dct_data[i * len_stream], +#endif + len_stream, bit_stream, index, i == 0 ); } /* inverse DCT2 transform */ +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + SWITCH( len_stream ) + { + case 4: + matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data_fx, nblocks, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q30*/ + BREAK; + case 5: + matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 8: + matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 12: + matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 20: + matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); + matrix_product_q30_fx( dct_data_tmp_fx, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data_fx ); /* reuse of variable*/ + BREAK; + case 32: + matrix_product_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); + matrix_product_q30_fx( dct_data_tmp_fx, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data_fx ); + BREAK; + default: + printf( "Incorrect number of coefficients for OMASA.\n" ); + BREAK; + } + + /* this is to make sure the comparison to the threshold 0.98 will go the same way in */ + /* fixed point and floating point without having to drag the fixed point values to the */ + /* comparison place in the code; 1052266987 is 0.98 in Q30 it is not needed in the fixed point*/ + + for ( i = 0; i < nblocks * nbands; i++ ) + { + if ( q_dct_data_fx[i] >= 1052266987 && q_dct_data_fx[i] < 1052400000 ) + { + q_dct_data_fx[i] = 1052400000; + } + } + + k = 0; + for ( i = 0; i < nblocks; i++ ) + { + for ( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = q_dct_data_fx[k] / (float) ( 1 << 30 ); + masa_to_total_energy_ratio[i][j] = max( 0.0f, masa_to_total_energy_ratio[i][j] ); + masa_to_total_energy_ratio[i][j] = min( 1.0f, masa_to_total_energy_ratio[i][j] ); + k++; + } + } + + if ( nblocks == 1 ) + { + for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[0][j]; + } + } + } + + if ( nbands == 1 ) + { + for ( j = 1; j < 5; j++ ) + { + for ( i = 0; i < nblocks; i++ ) + { + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[i][0]; + } + } + } + +#else switch ( len_stream ) { case 4: @@ -4454,6 +4575,6 @@ void ivas_omasa_decode_masa_to_total( } } } - +#endif return; } diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index e9c3d78869022c3faf4022ff14687a9addbb2650..7af547aae320680cb878bab04ca25f2845e5748b 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -372,7 +372,11 @@ ivas_error acelp_core_enc( if ( !nelp_mode && !ppp_mode ) { +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, st->GSC_noisy_speech, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif } /*-----------------------------------------------------------------* @@ -495,7 +499,11 @@ ivas_error acelp_core_enc( { tc_classif_enc( st->L_frame, &tc_subfr, &position, attack_flag, st->pitch[0], res ); +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 1, NULL, unbits, st->element_mode, &uc_two_stage_flag, tdm_lp_reuse_flag, tdm_low_rate_mode, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif } /*---------------------------------------------------------------* @@ -553,7 +561,11 @@ ivas_error acelp_core_enc( lsf_syn_mem_restore( st, tilt_code_bck, gc_threshold_bck, clip_var_bck, next_force_sf_bck, lsp_new, lsp_mid, clip_var, mem_AR, mem_MA, lsp_new_bck, lsp_mid_bck, Bin_E, Bin_E_old, mem_syn_bck, mem_w0_bck, streaklimit, pstreaklen ); /* Configure ACELP bit allocation */ +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, st->inactive_coder_type_flag, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, st->coder_type, tc_subfr, 0, &nb_bits, unbits, 0, &uc_two_stage_flag, 0, 0, st->idchan, st->active_cnt, tdm_Pitch_reuse_flag, st->tdm_LRTD_flag, st->GSC_IVAS_mode ); +#endif /* redo LSF quantization */ lsf_enc( st, lsf_new, lsp_new, lsp_mid, Aq, tdm_low_rate_mode, 0, NULL ); diff --git a/lib_enc/acelp_core_switch_enc.c b/lib_enc/acelp_core_switch_enc.c index efa33ff8a7fde9dbffa0879969b7131316622383..363dae223d0b7d4109934a942e2c3cfd4d8a5864 100644 --- a/lib_enc/acelp_core_switch_enc.c +++ b/lib_enc/acelp_core_switch_enc.c @@ -132,7 +132,11 @@ void acelp_core_switch_enc( * Excitation encoding *----------------------------------------------------------------*/ +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( ENC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, st->inactive_coder_type_flag, -1, -1, &j, &i, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); +#else config_acelp1( ENC, st->total_brate, cbrate, st->core, -1, -1, st->last_L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, GENERIC, -1, -1, &j, &i, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, 0, 0 /*GSC_IVAS_mode*/ ); +#endif encod_gen_voic_core_switch( st, st->last_L_frame, inp, Aq, A, T_op, st->voicing, exc, cbrate ); diff --git a/lib_enc/amr_wb_enc.c b/lib_enc/amr_wb_enc.c index e921698e5aaa5270cd4aa4be7ebf0d70ad09e115..010917925d356aced217e81b84969a24d4d916d8 100644 --- a/lib_enc/amr_wb_enc.c +++ b/lib_enc/amr_wb_enc.c @@ -310,7 +310,13 @@ void amr_wb_enc( { st->fd_cng_reset_flag = 0; } + +#ifdef NONBE_1211_DTX_BR_SWITCHING + dtx( st, -1, -1, vad_flag_dtx, inp ); +#else dtx( st, -1, vad_flag_dtx, inp ); +#endif + /*----------------------------------------------------------------* * Noise energy down-ward update and total noise energy estimation * Long-term energies and relative frame energy updates diff --git a/lib_enc/core_enc_init.c b/lib_enc/core_enc_init.c index b307e0361d600db278ef3c98645bd9164670b172..9d61013db7eeba10827aff68b0ae17d9fc3079a3 100644 --- a/lib_enc/core_enc_init.c +++ b/lib_enc/core_enc_init.c @@ -64,7 +64,10 @@ static void init_modes( Encoder_State *st, const int32_t last_total_brate ); void init_coder_ace_plus( Encoder_State *st, /* i : Encoder state */ const int32_t last_total_brate, /* i : last total bitrate */ - const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ +#ifdef FIX_920_IGF_INIT_ERROR + const int32_t igf_brate, /* i : IGF configuration bitrate */ +#endif + const int16_t MCT_flag /* i : hMCT handle allocated (1) or not (0) */ ) { TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; @@ -154,7 +157,11 @@ void init_coder_ace_plus( if ( st->igf && st->hIGFEnc != NULL ) { +#ifdef FIX_920_IGF_INIT_ERROR + IGFEncSetMode( st->hIGFEnc, igf_brate, st->bwidth, st->element_mode, st->rf_mode ); +#else IGFEncSetMode( st->hIGFEnc, st->total_brate, st->bwidth, st->element_mode, st->rf_mode ); +#endif } else if ( st->hIGFEnc != NULL ) { diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index 44952cc1daab965d2eea5d3264c8e6889c5ab396..df81980d81c6cf06adecc67f0ef36bd2c634ed0e 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -152,7 +152,11 @@ void core_coder_mode_switch( else { st->igf = getIgfPresent( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); +#ifdef FIX_920_IGF_INIT_ERROR + init_coder_ace_plus( st, last_total_brate, st->total_brate, MCT_flag ); +#else init_coder_ace_plus( st, last_total_brate, MCT_flag ); +#endif } if ( st->igf && st->hBWE_TD != NULL ) diff --git a/lib_enc/dtx.c b/lib_enc/dtx.c index 606c8aaaf98b43a1c02e08ffd97254f3f5bc7b4d..c1e842e589a35df5626844bfaa2c84fda9d2758a 100644 --- a/lib_enc/dtx.c +++ b/lib_enc/dtx.c @@ -78,7 +78,10 @@ static void update_SID_cnt( DTX_ENC_HANDLE hDtxEnc, const int32_t core_brate, co *-------------------------------------------------------------------*/ void dtx( - Encoder_State *st, /* i/o: encoder state structure */ + Encoder_State *st, /* i/o: encoder state structure */ +#ifdef NONBE_1211_DTX_BR_SWITCHING + const int32_t last_ivas_total_brate, /* i : last IVAS total bitrate */ +#endif const int32_t ivas_total_brate, /* i : IVAS total bitrate */ const int16_t vad, /* i : VAD flag for DTX */ const float speech[] /* i : Pointer to the speech frame */ @@ -87,17 +90,31 @@ void dtx( float alpha; DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc; int16_t last_br_cng_flag, last_br_flag, br_dtx_flag; +#ifdef NONBE_1211_DTX_BR_SWITCHING + int32_t total_brate_ref; + + total_brate_ref = st->total_brate; +#endif + if ( st->dtx_sce_sba != 0 ) { last_br_cng_flag = 1; last_br_flag = 1; +#ifndef NONBE_1211_DTX_BR_SWITCHING br_dtx_flag = 1; +#endif } else { last_br_cng_flag = st->last_total_brate_cng <= MAX_BRATE_DTX_EVS || st->lp_noise < 15 || ( st->element_mode == IVAS_SCE && st->last_total_brate_cng <= MAX_BRATE_DTX_IVAS ); +#ifdef NONBE_1211_DTX_BR_SWITCHING + last_br_flag = ( st->element_mode == EVS_MONO && st->last_total_brate <= MAX_BRATE_DTX_EVS ) || + ( st->element_mode != EVS_MONO && last_ivas_total_brate <= MAX_BRATE_DTX_IVAS ) || + st->lp_noise < 15; +#else last_br_flag = st->last_total_brate <= MAX_BRATE_DTX_EVS || st->lp_noise < 15 || ( st->element_mode == IVAS_SCE && st->last_total_brate <= MAX_BRATE_DTX_IVAS ); br_dtx_flag = 0; +#endif } /* Initialization */ @@ -127,6 +144,7 @@ void dtx( last_br_cng_flag ) { st->total_brate = st->last_total_brate_cng; + if ( !( st->total_brate == ACELP_7k20 && st->Opt_SC_VBR ) ) { st->Opt_SC_VBR = 0; @@ -170,6 +188,9 @@ void dtx( * Select SID or FRAME_NO_DATA frame if DTX is enabled *------------------------------------------------------------------------*/ +#ifdef NONBE_1211_DTX_BR_SWITCHING + br_dtx_flag = 1; +#endif if ( st->dtx_sce_sba == 0 ) { br_dtx_flag = ( st->element_mode == EVS_MONO && st->total_brate <= MAX_BRATE_DTX_EVS ) || @@ -258,6 +279,12 @@ void dtx( reset_indices_enc( st->hBstr, st->hBstr->nb_ind_tot ); } } +#ifdef NONBE_1211_DTX_BR_SWITCHING + else if ( st->element_mode != EVS_MONO ) + { + st->total_brate = total_brate_ref; + } +#endif /*------------------------------------------------------------------------* * Reset counters when in active frame (neither SID nor FRAME_NO_DATA frame) diff --git a/lib_enc/enc_gen_voic.c b/lib_enc/enc_gen_voic.c index 4c78b484c0a220df9d0afc91326e66b0e182e0fe..183655ddba45d42d8177de581bcaaaf0d520dccb 100644 --- a/lib_enc/enc_gen_voic.c +++ b/lib_enc/enc_gen_voic.c @@ -255,7 +255,11 @@ void encod_gen_voic( * Transform-domain contribution (inactive frames) *-----------------------------------------------------------------*/ +#ifdef NONBE_FIX_GSC_BSTR + if ( !st->inactive_coder_type_flag && st->coder_type == INACTIVE ) +#else if ( st->total_brate >= MAX_GSC_INACTIVE_BRATE && st->coder_type == INACTIVE ) +#endif { transf_cdbk_enc( st, 0, i_subfr, cn, exc, p_Aq, p_Aw, h1, xn, xn2, y1, y2, Es_pred, &gain_pit, gain_code, g_corr, clip_gain, &gain_preQ, code_preQ, unbits ); } diff --git a/lib_enc/init_enc.c b/lib_enc/init_enc.c index e722d835000c205114718aa84c7e05bae70d5b32..b441c2b07abc9c84280853cc5a0c4e9bab534469 100644 --- a/lib_enc/init_enc.c +++ b/lib_enc/init_enc.c @@ -825,7 +825,11 @@ ivas_error init_encoder( set_f( st->totalNoise_increase_hist, 0.f, TOTALNOISE_HIST_SIZE ); st->totalNoise_increase_len = 0; +#ifdef FIX_920_IGF_INIT_ERROR + init_coder_ace_plus( st, st->last_total_brate, igf_brate, 0 /* initialization value */ ); +#else init_coder_ace_plus( st, st->last_total_brate, 0 /* initialization value */ ); +#endif /*-----------------------------------------------------------------* * FD-CNG encoder diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index 129177c0c11edd78c053a2817d7dcc0801ec2282..ed76551417301bd96bd0a549baa1a5cc9054650b 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -209,7 +209,11 @@ ivas_error pre_proc_ivas( } else if ( st->total_brate > MAX_GSC_INACTIVE_BRATE && ( ( st->vad_flag == 0 && st->bwidth >= SWB && st->max_bwidth >= SWB ) || ( st->localVAD == 0 && ( st->bwidth <= WB || st->max_bwidth <= WB ) ) ) ) { +#ifdef NONBE_FIX_GSC_BSTR + /* inactive frames will be coded by AVQ technology (exceptionally it can be later rewritten to GSC technology in ivas_combined_format_brate_sanity()) */ +#else /* inactive frames will be coded by AVQ technology */ +#endif st->coder_type = INACTIVE; } diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index 79003e2974ddd75406a280fbde8991e85da03be3..da3b4ce0bf6e9247ba62a857cdf80f3a0b0174cc 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -112,7 +112,10 @@ ivas_error pre_proc_front_ivas( const int16_t front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const int16_t MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const int32_t ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ +#ifdef NONBE_1211_DTX_BR_SWITCHING + const int32_t last_ivas_total_brate, /* i : last IVAS total bitrate */ +#endif + const int32_t ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ #ifdef DEBUG_MODE_INFO , const int16_t ch_idx @@ -227,7 +230,9 @@ ivas_error pre_proc_front_ivas( } #ifdef DEBUG_MODE_INFO + if ( !( hCPE != NULL && hCPE->hStereoTD != NULL && ch_idx > 0 ) ) { + /* for TD stereo only write out first channel. The existence of a second channel can vary, this is just easier to handle */ int16_t tmp_dmx_in[L_FRAME48k]; mvr2s( signal_in - NS2SA( st->input_Fs, ACELP_LOOK_NS ), tmp_dmx_in, input_frame ); dbgwrite( tmp_dmx_in, sizeof( int16_t ), input_frame, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, ch_idx + 1, ENC ), ".pcm" ) ); @@ -559,7 +564,11 @@ ivas_error pre_proc_front_ivas( st->cng_type = LP_CNG; } +#ifdef NONBE_1211_DTX_BR_SWITCHING + dtx( st, last_ivas_total_brate, ivas_total_brate, *vad_flag_dtx, inp_12k8 ); +#else dtx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8 ); +#endif if ( hCPE != NULL && hCPE->hStereoDft != NULL && st->core_brate == SID_2k40 ) { diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 441d8c16db9f2f40a8c2739649169034168c2dad..66fb8bfc2e907e13ec2323ff98e8707c38380b92 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -485,7 +485,11 @@ ivas_error ivas_cpe_enc( error = pre_proc_front_ivas( NULL, hCPE, hCPE->element_brate, nb_bits_metadata, input_frame, n, old_inp_12k8[n], old_inp_16k[n], &ener[n], &relE[n], A[n], Aw[n], epsP[n], lsp_new[n], lsp_mid[n], &vad_hover_flag[n], &attack_flag[n], realBuffer[n], imagBuffer[n], old_wsp[n], pitch_fr[n], voicing_fr[n], &loc_harm[n], &cor_map_sum[n], &vad_flag_dtx[n], enerBuffer[n], +#ifdef NONBE_1211_DTX_BR_SWITCHING + fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, st_ivas->hEncoderConfig->last_ivas_total_brate, ivas_total_brate +#else fft_buff[n], A[0], lsp_new[0], currFlatness[n], tdm_ratio_idx, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, band_energies_LR, 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate +#endif #ifdef DEBUG_MODE_INFO , ( st_ivas->nSCE + ( cpe_id * CPE_CHANNELS ) + n ) diff --git a/lib_enc/ivas_front_vad.c b/lib_enc/ivas_front_vad.c index 52c3b8cd45c474b9a11bfaf6107b8a3d20717616..49268e52393a0ee9133ad5a85894a28eed4a9f43 100644 --- a/lib_enc/ivas_front_vad.c +++ b/lib_enc/ivas_front_vad.c @@ -423,7 +423,12 @@ ivas_error front_vad_spar( noise_est_down( fr_bands[0], hFrontVad->hNoiseEst->bckr, tmpN, tmpE, st->min_band, st->max_band, &hFrontVad->hNoiseEst->totalNoise, Etot[0], &hFrontVad->hNoiseEst->Etot_last, &hFrontVad->hNoiseEst->Etot_v_h2 ); corr_shift = correlation_shift( hFrontVad->hNoiseEst->totalNoise ); +#ifdef NONBE_1211_DTX_BR_SWITCHING + dtx( st, hEncoderConfig->last_ivas_total_brate, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8 ); +#else dtx( st, hEncoderConfig->ivas_total_brate, vad_flag_dtx[0], inp_12k8 ); +#endif + /* linear prediction analysis */ alw_pitch_lag_12k8[0] = st->old_pitch_la; alw_pitch_lag_12k8[1] = st->old_pitch_la; diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index bc7ced57ffc6597380739021f11b7162f9e53fdf..1502b523b0be69e516abdc9c2efbc8c92b0d7262 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -175,7 +175,11 @@ ivas_error ivas_ism_enc( error = pre_proc_front_ivas( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8[sce_id][0], old_inp_16k[sce_id][0], &ener[sce_id][0], &relE[sce_id][0], A[sce_id][0], Aw[sce_id][0], epsP[sce_id][0], lsp_new[sce_id][0], lsp_mid[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer[sce_id][0], imagBuffer[sce_id][0], old_wsp[sce_id][0], pitch_fr[sce_id][0], voicing_fr[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer[sce_id][0], +#ifdef NONBE_1211_DTX_BR_SWITCHING + fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate +#else fft_buff[sce_id][0], A[sce_id][0], lsp_new[sce_id][0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate +#endif #ifdef DEBUG_MODE_INFO , st->id_element diff --git a/lib_enc/ivas_ism_metadata_enc.c b/lib_enc/ivas_ism_metadata_enc.c index 849b7957ae86da6e1152d7fa864db63aac05e6a7..55d6eaebbffb76977920e308393fcb2801d33023 100644 --- a/lib_enc/ivas_ism_metadata_enc.c +++ b/lib_enc/ivas_ism_metadata_enc.c @@ -277,7 +277,9 @@ ivas_error ivas_ism_metadata_enc( } else if ( hIsmMeta[ch]->ism_md_fec_cnt_enc == ISM_MD_FEC_CNT_MAX ) { - +#ifdef NONBE_1273_ISM_METADATA_COUNTER + hIsmMeta[ch]->ism_md_fec_cnt_enc = 0; +#endif lowrate_metadata_flag[ch] = 1; hIsmMeta[ch]->position_angle.angle1_diff_cnt = ISM_FEC_MAX; @@ -555,6 +557,9 @@ ivas_error ivas_ism_metadata_enc( if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { hIsmMeta[ch]->ism_md_fec_cnt_enc++; +#ifdef NONBE_1273_ISM_METADATA_COUNTER + hIsmMeta[ch]->ism_md_fec_cnt_enc = min( hIsmMeta[ch]->ism_md_fec_cnt_enc, ISM_MD_FEC_CNT_MAX ); +#endif } else { @@ -699,6 +704,9 @@ ivas_error ivas_ism_metadata_enc( if ( hIsmMeta[ch]->ism_metadata_flag == 0 ) { hIsmMeta[ch]->ism_md_fec_cnt_enc++; +#ifdef NONBE_1273_ISM_METADATA_COUNTER + hIsmMeta[ch]->ism_md_fec_cnt_enc = min( hIsmMeta[ch]->ism_md_fec_cnt_enc, ISM_MD_FEC_CNT_MAX ); +#endif } else { diff --git a/lib_enc/ivas_osba_enc.c b/lib_enc/ivas_osba_enc.c index dffebcf19d5d66046731cc3f86559ead7a2a6cda..bd0d6b1b58b02d9788bca21fefaed9d50f7e48ec 100644 --- a/lib_enc/ivas_osba_enc.c +++ b/lib_enc/ivas_osba_enc.c @@ -447,7 +447,6 @@ static void ivas_osba_render_ism_to_sba( int16_t azimuth, elevation; float gains[MAX_INPUT_CHANNELS]; float g1, g2; - float output_gain; int16_t nchan_sba; diff --git a/lib_enc/ivas_qmetadata_enc.c b/lib_enc/ivas_qmetadata_enc.c index 9a4be19f400a45f4d4901aef892a4aac61a73da0..52dc52772c92c80d1fa30038a24e2026ad9104b1 100644 --- a/lib_enc/ivas_qmetadata_enc.c +++ b/lib_enc/ivas_qmetadata_enc.c @@ -41,7 +41,9 @@ #include "ivas_stat_enc.h" #include "wmc_auto.h" #include "prot.h" - +#ifdef NONBE_1319_M2R_PRECISION_ALIGN +#include "basop_settings.h" +#endif /*-----------------------------------------------------------------------* * Local function prototypes @@ -6016,10 +6018,17 @@ void ivas_omasa_encode_masa_to_total( float dct_data[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; int16_t bits_pos, nb_bits; int16_t n_streams, len_stream; +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + Word32 q_dct_data_fx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS], + dct_data_tmp_fx[MAX_PARAM_SPATIAL_SUBFRAMES * MASA_FREQUENCY_BANDS]; + + int64_t step_fx; + step_fx = STEP_M2T_FX; +#else #ifdef NON_BE_FIX_BASOP_819_THRESHOLD_MASA2TOTAL int32_t int_tmp; #endif - +#endif #ifdef DEBUG_MODE_QMETADATA static FILE *pF = NULL; static FILE *pF_ratio = NULL; @@ -6128,6 +6137,97 @@ void ivas_omasa_encode_masa_to_total( } /* reconstruct masa2total */ +#ifdef NONBE_1319_M2R_PRECISION_ALIGN + q_dct_data_fx[0] = (Word32) ( ( step_fx * q_idx[0] ) >> 6 ); // Q25 + for ( i = 1; i < len_stream; i++ ) + { + if ( ( q_idx[i] & 1 ) == 0 ) + { + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( -q_idx[i] ) ) >> 7 ); // Q25 + } + ELSE + { + q_dct_data_fx[i] = (Word32) ( ( step_fx * ( q_idx[i] + 1 ) ) >> 7 ); // Q25 + } + } + SWITCH( len_stream ) + { + case 4: + matrix_product_q30_fx( dct4_fx, nblocks, nblocks, 1, q_dct_data_fx, nblocks, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nblocks ); /*Q30*/ + BREAK; + case 5: + matrix_product_q30_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 8: + matrix_product_q30_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 12: + matrix_product_q30_fx( dct12_fx, nbands, nbands, 1, q_dct_data_fx, nbands, 1, 0, dct_data_tmp_fx ); + mvl2l( dct_data_tmp_fx, q_dct_data_fx, nbands ); /*Q30*/ + BREAK; + case 20: + matrix_product_fx( dct5_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); + matrix_product_q30_fx( dct_data_tmp_fx, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data_fx ); /* reuse of variable*/ + BREAK; + case 32: + matrix_product_fx( dct8_fx, nbands, nbands, 1, q_dct_data_fx, nbands, nblocks, 0, dct_data_tmp_fx ); + matrix_product_q30_fx( dct_data_tmp_fx, nbands, nblocks, 0, dct4_fx, nblocks, nblocks, 0, q_dct_data_fx ); + BREAK; + default: + printf( "Incorrect number of coefficients for OMASA.\n" ); + BREAK; + } + + /* this is to make sure the comparison to the threshold 0.98 will go the same way in */ + /* fixed point and floating point without having to drag the fixed point values to the */ + /* comparison place in the code; */ + /* 1052266987 is 0.98 in Q30 it is not needed in the fixed point */ + for ( i = 0; i < nblocks * nbands; i++ ) + { + if ( q_dct_data_fx[i] >= 1052266987 && q_dct_data_fx[i] < 1052400000 ) + { + q_dct_data_fx[i] = 1052400000; + } + } + + k = 0; + for ( i = 0; i < nblocks; i++ ) + { + for ( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = q_dct_data_fx[k] / (float) ( 1 << 30 ); + masa_to_total_energy_ratio[i][j] = max( 0.0f, masa_to_total_energy_ratio[i][j] ); + masa_to_total_energy_ratio[i][j] = min( 1.0f, masa_to_total_energy_ratio[i][j] ); + k++; + } + } + + if ( nblocks == 1 ) + { + for ( i = 1; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) + { + for ( j = 0; j < nbands; j++ ) + { + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[0][j]; + } + } + } + + if ( nbands == 1 ) + { + for ( j = 1; j < 5; j++ ) + { + for ( i = 0; i < nblocks; i++ ) + { + masa_to_total_energy_ratio[i][j] = masa_to_total_energy_ratio[i][0]; + } + } + } + +#else q_dct_data[0] = q_idx[0] * step; for ( i = 1; i < len_stream; i++ ) { @@ -6187,6 +6287,7 @@ void ivas_omasa_encode_masa_to_total( k++; } } +#endif assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) ); #ifdef DEBUG_MODE_QMETADATA diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index a1d6d594581625685ab129995381dbcdd87bac38..1db9b2b17f81bfdcf7e8f5ff2ef824b2af2ddb51 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -183,7 +183,11 @@ ivas_error ivas_sce_enc( &ener[0], &relE[0], A[0], Aw[0], epsP[0], lsp_new[0], lsp_mid[0], &vad_hover_flag[0], &attack_flag[0], realBuffer[0], imagBuffer[0], old_wsp[0], pitch_fr[0], voicing_fr[0], &loc_harm[0], &cor_map_sum[0], &vad_flag_dtx[0], enerBuffer[0], fft_buff[0], A[0], lsp_new[0], currFlatness[0], 0, fr_bands, Etot_LR, lf_E, localVAD_HE_SAD, NULL, flag_16k_smc, +#ifdef NONBE_1211_DTX_BR_SWITCHING + st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->last_ivas_total_brate, st_ivas->hEncoderConfig->ivas_total_brate +#else st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->force_front_vad : 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_dtx_flag : 0, ivas_format, 0, st_ivas->hEncoderConfig->ivas_total_brate +#endif #ifdef DEBUG_MODE_INFO , st->id_element diff --git a/lib_enc/lib_enc.c b/lib_enc/lib_enc.c index 0fb8eabb35b33afae2b250b7e9673fa3cf4e4e03..e2ad1d2672510b716ce876f68a0c9eca13ae1004 100644 --- a/lib_enc/lib_enc.c +++ b/lib_enc/lib_enc.c @@ -1324,6 +1324,11 @@ ivas_error IVAS_ENC_EncodeFrameToSerial( } else { +#ifdef DEBUG_MODE_INFO + int16_t tmp_dmx_in[L_FRAME48k]; + mvr2s( inputBuffer, tmp_dmx_in, inputBufferSize ); + dbgwrite( tmp_dmx_in, sizeof( int16_t ), inputBufferSize, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, 1, ENC ), ".pcm" ) ); +#endif if ( ( error = evs_enc( hCoreCoder, inputBuffer, st_ivas->mem_hp20_in[0], inputBufferSize ) ) != IVAS_ERR_OK ) { return error; diff --git a/lib_enc/pre_proc.c b/lib_enc/pre_proc.c index 5301559d2fd5ba1aa38c1fbb340273d7e3bd820e..32de5ec3084e0e182d89646428eb16c3597b6bb2 100644 --- a/lib_enc/pre_proc.c +++ b/lib_enc/pre_proc.c @@ -250,7 +250,13 @@ void pre_proc( /*-----------------------------------------------------------------* * Select SID or FRAME_NO_DATA frame if DTX enabled *-----------------------------------------------------------------*/ + +#ifdef NONBE_1211_DTX_BR_SWITCHING + dtx( st, -1, -1, vad_flag_dtx, inp_12k8 ); +#else dtx( st, -1, vad_flag_dtx, inp_12k8 ); +#endif + /*----------------------------------------------------------------* * Adjust FD-CNG Noise Estimator *----------------------------------------------------------------*/ diff --git a/lib_enc/transition_enc.c b/lib_enc/transition_enc.c index 925a6f1c322e2582ab7e214c0eade34cfbbdf055..2ab5b04bb06beea09069afed49e9e4d61a25c232 100644 --- a/lib_enc/transition_enc.c +++ b/lib_enc/transition_enc.c @@ -178,7 +178,11 @@ void transition_enc( if ( *tc_subfr == TC_0_0 ) { /* this is called only to compute unused bits */ +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, L_FRAME, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, TC_0_0, 3, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, L_FRAME, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, TC_0_0, 3, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); +#endif } *clip_gain = gp_clip( st->element_mode, st->core_brate, st->voicing, i_subfr, TRANSITION, xn, gp_cl ); @@ -274,7 +278,11 @@ void transition_enc( if ( i_subfr - *tc_subfr <= L_SUBFR ) { +#ifdef NONBE_FIX_GSC_BSTR + config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, -1, *tc_subfr, 2, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); +#else config_acelp1( ENC, st->total_brate, st->core_brate, st->core, st->extl, st->extl_brate, st->L_frame, -1, &( st->acelp_cfg ), hBstr->nb_bits_tot, TRANSITION, *tc_subfr, 2, NULL, unbits_ACELP, st->element_mode, &i /*dummy*/, 0 /*tdm_lp_reuse_flag*/, 0 /*tdm_low_rate_mode*/, st->idchan, st->active_cnt, 0 /*tdm_Pitch_reuse_flag*/, st->tdm_LRTD_flag, 0 /*GSC_IVAS_mode*/ ); +#endif } /*-----------------------------------------------------------------*