diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index 5bff71481a5c4b3a6261213d22d22b099e737e97..1cc4f2a8e5411270f718867305ad9cf01da3002d 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1390,7 +1390,8 @@ typedef enum #define MCMASA_LFE_THETA_Q14 (21299) // Q14 #define MCMASA_LFE_QLOW_Q12 (-26624) // Q12 #define MCMASA_LFE_DELTA_Q11 (2048) // Q11 - +#define MCMASA_LFE_QLOW_Q11 (-13312) // Q11 +#define MCMASA_LFE_DELTA_Q10 (1024) // Q10 #define NUM_ELEVATED_SPEAKERS 4 #define MCMASA_MIN_SPEAKERS_SEPARATE_CENTER 4 diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index 87ddacd3d5494909772f56bcee578bd6c4f5187d..7a7126490db82d87e25a8f2c7f077977b198387f 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -248,7 +248,8 @@ ivas_error pre_proc_front_ivas_fx( const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word32 ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX */ + Word16 *Q_new #ifdef DEBUG_MODE_INFO , const Word16 ch_idx @@ -408,6 +409,7 @@ ivas_error ivas_core_enc( const int16_t n_CoreChannels, /* i : number of core channels to be coded */ Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal */ Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal */ + Word16 Q_new[], Word32 ener_fx[], /* i : residual energy from Levinson-Durbin Q6*/ Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes*/ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ecebf22dc7b5f75df4dd33c9a31aa81736311484..6fd0c777fb04e5fd0fd5f8c67e88a7735d58a080 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -864,7 +864,8 @@ void td_stereo_param_updt_fx( ); void updt_enc_common_ivas_fx( - Encoder_State *st /* i/o: encoder state structure */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 Q_new /* i : CUrrent frame scaling */ ); @@ -5806,14 +5807,14 @@ ivas_error ivas_sce_enc_fx( ); ivas_error ivas_cpe_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx) */ - Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */ - Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ -); + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx) */ + Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata, /* i : number of metadata bits */ + Word16 Q_new_out[] ); ivas_error ivas_mct_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ @@ -5839,7 +5840,8 @@ ivas_error ivas_compute_core_buffers_fx( Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ Word16 Q_old_inp_16k, Word16 Q_r[2], - Word16 *Q_new ); + Word16 *Q_new, + Word16 downscale_buf_speech_enc_pe ); ivas_error ivas_enc_fx( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index e743c6ff0749c790d721a15211333c712c8aef14..c0a5af265ae1351485687720657456215c456dd0 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10740,7 +10740,8 @@ void core_encode_update_ivas_fx( ); void updt_enc_common_ivas_fx( - Encoder_State *st /* i/o: encoder state structure */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 Q_new /* i : CUrrent frame scaling */ ); // tools.c diff --git a/lib_enc/acelp_core_enc.c b/lib_enc/acelp_core_enc.c index 48f1e417f07330c9fb1dde0dd9e83f6d3b8a75c1..d3d542f321dd3fc4ec9043fc0aead352da399fab 100644 --- a/lib_enc/acelp_core_enc.c +++ b/lib_enc/acelp_core_enc.c @@ -962,8 +962,6 @@ ivas_error acelp_core_enc( update_average_rate_fx( st->hSC_VBR, st->core_brate ); } } - st->prev_Q_new = Q_new; - move16(); pop_wmops(); return error; diff --git a/lib_enc/analy_sp_fx.c b/lib_enc/analy_sp_fx.c index 183b0c3e3f0f76bd802333ecfaf319c30ff49560..3cef21224e05d087a340e45f2d3d5a3925a092ef 100644 --- a/lib_enc/analy_sp_fx.c +++ b/lib_enc/analy_sp_fx.c @@ -409,12 +409,8 @@ static void find_enr_dft_fx( tmp_fx = L_add( tmp_fx, band_fx[i] ); // Qout } *Etot_fx = tmp_fx; - - // To Be Checked - Scale_sig32( band_fx, NB_BANDS, 2 ); - // To Be Checked - Scale_sig32( band_ener_fx, NB_BANDS, 2 ); move32(); + return; } /*-------------------------------------------------------------------* @@ -573,18 +569,18 @@ void ivas_analy_sp_fx_front( const Word32 input_Fs, /* i : input sampling rate */ Word16 *speech, /* i : speech buffer Q_new - preemph_bits */ const Word16 Q_new, /* i : current scaling exp Q0 */ - Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE */ - Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2*/ + Word32 *fr_bands, /* o : energy in critical frequency bands Q_new + QSCALE - 2 */ + Word32 *lf_E, /* o : per bin E for first... Q_new + QSCALE - 2 */ Word16 *Etot, /* o : total input energy Q8 */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ - const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE */ + const Word32 e_min_scaled, /* i : minimum energy scaled Q_new + QSCALE - 2 */ Word16 Scale_fac[2], /* o : FFT scales factors (2 values by frame) Q0 */ Word32 *Bin_E, /* o : per-bin energy spectrum Q7 */ Word32 *Bin_E_old, /* o : per-bin energy spectrum of the previous frame Q7 */ Word32 *PS, /* o : per-bin energy spectrum Q_new + QSCALE - 2 */ Word16 *EspecdB, /* o : per-bin log energy spectrum (with f=0) Q7 */ - Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (Q_new + QSCALE)*/ + Word32 *band_energies, /* o : energy in critical frequency bands without minimum noise floor MODE2_E_MIN (Q_new + QSCALE - 2)*/ Word16 *fft_buff /* o : FFT coefficients (Q_new + Scale_fac[i_subfr]) */ ) { @@ -594,6 +590,7 @@ void ivas_analy_sp_fx_front( Word32 Ltmp, LEtot; Word16 *pt_fft; Word32 temp32_log; + Word16 max_pfft; /*-----------------------------------------------------------------* * Compute spectrum * find energy per critical frequency band and total energy in dB @@ -632,8 +629,13 @@ void ivas_analy_sp_fx_front( move16(); } - Scale_fac[i_subfr] = -2; - move16(); + maximum_abs_16_fx( pt_fft, L_FFT, &max_pfft ); + IF( max_pfft > 0 ) + { + Scale_fac[i_subfr] = sub( norm_s( max_pfft ), LOG2_L_FFT ); + move16(); + } + Scale_sig( pt_fft, L_FFT, Scale_fac[i_subfr] ); /* compute the spectrum */ @@ -990,17 +992,17 @@ static void ivas_find_enr( /* Merge with ivas_find_enr function once analy_sp is unified */ static void ivas_find_enr1( Word16 data[], /* i : fft result */ - Word16 q_data, /* i : Q of fft result */ - Word32 band[], /* o : per band energy Q_new + QSCALE */ - Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ - Word32 *LEtot, /* o : total energy Q_new + QSCALE-1 */ + Word16 q_data, /* i : Q of fft result */ + Word32 band[], /* o : per band energy Q_new + QSCALE-2 */ + Word32 *ptE, /* o : per bin energy for low frequencies Q_new + QSCALE-2 */ + Word32 *LEtot, /* o : total energy Q_new + QSCALE-2 */ const Word16 min_band, /* i : minimum critical band Q0 */ const Word16 max_band, /* i : maximum critical band Q0 */ const Word16 Q_new, /* i : scaling factor Q0 */ - const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE */ - Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ + const Word32 e_min, /* i : minimum energy scaled Q_new + QSCALE-2 */ + Word32 *Bin_E, /* o : Per bin energy Q_new + QSCALE-2 */ Word16 BIN_FREQ_FX, /* i : Number of frequency bins */ - Word32 *band_energies /* o : per band energy without MODE2_E_MIN */ + Word32 *band_energies /* o : per band energy without MODE2_E_MIN Q_new + QSCALE-2 */ ) { Word16 i, cnt; @@ -1049,7 +1051,7 @@ static void ivas_find_enr1( *Bin_E++ = *ptE; // Q_new + QSCALE - 2 move32(); - band[i] = L_add( band[i], *ptE++ ); // Q_new + QSCALE - 2 + band[i] = L_add_sat( band[i], *ptE++ ); // Q_new + QSCALE - 2 move32(); ptR++; ptI--; @@ -1058,16 +1060,15 @@ static void ivas_find_enr1( cnt = add( cnt, 1 ); } - Ltmp = Mpy_32_16_1( band[i], inv_tbl_fx[cnt] ); /* normalization per frequency bin */ // Q_new + QSCALE - 2 - band[i] = L_shl( Ltmp, Q2 ); // Q_new + QSCALE + band[i] = Mpy_32_16_1( band[i], inv_tbl_fx[cnt] ); /* normalization per frequency bin */ // Q_new + QSCALE - 2 move32(); - band_energies[i] = band[i]; /* per band energy without E_MIN */ // Q_new + QSCALE + band_energies[i] = band[i]; /* per band energy without E_MIN */ // Q_new + QSCALE - 2 move32(); - if ( LT_32( band[i], e_min ) ) // Q_new + QSCALE + if ( LT_32( band[i], e_min ) ) // Q_new + QSCALE - 2 { - band[i] = e_min; // Q_new + QSCALE + band[i] = e_min; // Q_new + QSCALE - 2 move32(); } } @@ -1097,7 +1098,7 @@ static void ivas_find_enr1( *Bin_E = L_shl( Ltmp, sub( add( Q_new, QSCALE - 2 ), add( shl( q_data, Q1 ), sub( te_exp, 32 ) ) ) ); // Q_new + QSCALE - 2 move32(); - band[i] = L_add( band[i], *Bin_E++ ); // Q_new + QSCALE - 2 + band[i] = L_add_sat( band[i], *Bin_E++ ); // Q_new + QSCALE - 2 move32(); ptR++; ptI--; @@ -1106,16 +1107,15 @@ static void ivas_find_enr1( cnt = add( cnt, 1 ); } - Ltmp = Mpy_32_16_1( band[i], inv_tbl_fx[cnt] ); /* normalization per frequency bin */ // Q_new + QSCALE - 2 - band[i] = L_shl( Ltmp, Q2 ); // Q_new + QSCALE + band[i] = Mpy_32_16_1( band[i], inv_tbl_fx[cnt] ); /* normalization per frequency bin */ // Q_new + QSCALE - 2 move32(); - band_energies[i] = band[i]; /* per band energy without E_MIN */ // Q_new + QSCALE + band_energies[i] = band[i]; /* per band energy without E_MIN */ // Q_new + QSCALE - 2 move32(); - if ( LT_32( band[i], e_min ) ) // Q_new + QSCALE + if ( LT_32( band[i], e_min ) ) // Q_new + QSCALE - 2 { - band[i] = e_min; // Q_new + QSCALE + band[i] = e_min; // Q_new + QSCALE - 2 move32(); } } @@ -1129,7 +1129,7 @@ static void ivas_find_enr1( move32(); FOR( i = min_band; i <= max_band; i++ ) { - etot = L_add_sat( etot, L_shr( band[i], Q1 ) ); // Q_new + QSCALE - 1 + etot = L_add_sat( etot, band[i] ); // Q_new + QSCALE - 2 } *LEtot = etot; move32(); diff --git a/lib_enc/core_enc_reconf.c b/lib_enc/core_enc_reconf.c index 911e4b7a4be548036201f1235cddb4a3aca68463..24729c1241da0adae89e9cbe65962bb739122ed3 100644 --- a/lib_enc/core_enc_reconf.c +++ b/lib_enc/core_enc_reconf.c @@ -48,200 +48,6 @@ * - reconfig core coder when switching to another frame type * *-----------------------------------------------------------------*/ -void core_coder_reconfig( - Encoder_State *st, - const int32_t last_total_brate ) -{ - TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - int16_t bwidth, i, index; - - /*Configuration of ACELP*/ - BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) ); - - /*Configuration of partial copy*/ - if ( st->Opt_RF_ON ) - { - st->hRF->acelp_cfg_rf.mode_index = 1; - st->hRF->acelp_cfg_rf.midLpc = 0; - st->hRF->acelp_cfg_rf.midLpc_enable = 0; - st->hRF->acelp_cfg_rf.pre_emphasis = 0; - st->hRF->acelp_cfg_rf.formant_enh = 1; - st->hRF->acelp_cfg_rf.formant_tilt = 1; - st->hRF->acelp_cfg_rf.voice_tilt = 1; - st->hRF->acelp_cfg_rf.formant_enh_num = FORMANT_SHARPENING_G1; - st->hRF->acelp_cfg_rf.formant_enh_den = FORMANT_SHARPENING_G2; - } - - if ( st->element_mode == IVAS_CPE_MDCT ) - { - st->nb_bits_header_tcx = 2; /* signal class */ - } - else if ( st->tcxonly ) - { - st->nb_bits_header_tcx = 1 + 1; /*TCX20/TCX10 + last_core*/ - st->nb_bits_header_tcx += 2; /* Siganl class*/ - } - else - { - st->nb_bits_header_ace = 1 + 2 + 1; /*TCX/ACELP+coder_type + last_core*/ - st->nb_bits_header_tcx = st->nb_bits_header_ace; - - if ( st->hTcxCfg != NULL ) - { - if ( st->hTcxCfg->lfacNext <= 0 ) - { - st->nb_bits_header_ace--; /*No last_core*/ - } - } - } - - /*Switch off TCX or ACELP?*/ - if ( st->sr_core == INT_FS_12k8 ) - { - st->acelpEnabled = ( st->restrictedMode & 1 ) == 1; - st->tcx20Enabled = ( st->restrictedMode & 2 ) == 2; - } - st->prevEnergyHF_fx = st->currEnergyHF_fx = 1073725440l /*65535.0f Q14*/; /* prevent block switch */ - st->currEnergyHF_e_fx = 17; - move32(); - move32(); - move16(); - - /* TCX-LTP */ - if ( st->hTcxEnc != NULL ) - { - st->hTcxEnc->tcxltp = getTcxLtp( st->sr_core ); - } - - /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/ - st->acelp_autocorr = 1; - if ( st->total_brate <= ACELP_9k60 && st->sr_core == INT_FS_12k8 ) - { - st->acelp_autocorr = 0; - } - - /*Get audio bandwidth info*/ - if ( st->narrowBand ) - { - bwidth = NB; - } - else if ( st->sr_core <= INT_FS_16k ) - { - bwidth = WB; - } - else - { - bwidth = SWB; - } - - /*Scale TCX for non-active frames to adjust loudness with ACELP*/ - if ( st->hTcxCfg != NULL ) - { - st->hTcxCfg->na_scale = 32767; - if ( bwidth < SWB && !( st->tcxonly ) ) - { - for ( i = 0; i < SIZE_SCALE_TABLE_TCX; i++ ) - { - if ( ( bwidth == scaleTcxTable[i].bwmode ) && - ( st->total_brate >= scaleTcxTable[i].bitrateFrom ) && - ( st->total_brate < scaleTcxTable[i].bitrateTo ) ) - { - if ( st->rf_mode ) - { - i--; - } - st->hTcxCfg->na_scale = scaleTcxTable[i].scale; - break; - } - } - } - } - - if ( st->element_mode > IVAS_SCE ) - { - st->enableTcxLpc = ( st->lpcQuantization == 1 ) && ( st->total_brate <= LOWRATE_TCXLPC_MAX_BR_CPE || st->rf_mode ); - } - else - { - st->enableTcxLpc = ( st->lpcQuantization == 1 ) && ( st->total_brate <= LOWRATE_TCXLPC_MAX_BR || st->rf_mode ); - } - - if ( st->ini_frame == 0 || st->last_codec_mode == MODE1 ) - { - st->envWeighted = 0; - } - - if ( st->bwidth == SWB && ( st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) - { - if ( st->tec_tfa == 0 ) - { - set16_fx( st->hTECEnc->loBuffer, 0, MAX_TEC_SMOOTHING_DEG ); - } - st->tec_tfa = 1; - } - else - { - st->tec_tfa = 0; - } - - st->enablePlcWaveadjust = 0; - if ( st->total_brate >= HQ_48k ) - { - st->enablePlcWaveadjust = 1; - } - - st->glr = 0; - if ( ( st->total_brate == ACELP_9k60 || st->total_brate == ACELP_16k40 || st->total_brate == ACELP_24k40 ) && st->element_mode == EVS_MONO ) - { - st->glr = 1; - } - - if ( st->glr ) - { - st->nb_bits_header_ace += G_LPC_RECOVERY_BITS; - } - - if ( hTcxEnc != NULL ) - { - if ( st->bwidth == NB || st->bwidth == WB ) - { - index = min( N_TCX_STARTLINE_NOISE_WB - 1, (uint16_t) max( 0, ( st->rf_mode == 0 ) ? st->frame_size_index : st->frame_size_index - 1 ) ); - hTcxEnc->nmStartLine = startLineWB[index]; - } - else /* (st->bwidth == SWB || st->bwidth == FB) */ - { - index = min( N_TCX_STARTLINE_NOISE_SWB - 1, (uint16_t) max( 3, ( st->rf_mode == 0 ) ? st->frame_size_index : st->frame_size_index - 1 ) - 3 ); - if ( st->total_brate >= IVAS_96k && st->total_brate <= IVAS_192k && st->element_mode > IVAS_SCE ) - { - index--; - } - hTcxEnc->nmStartLine = startLineSWB[index]; - if ( st->total_brate == IVAS_48k && st->element_mode == IVAS_CPE_MDCT && hTcxEnc->nmStartLine * 5 < st->L_frame * 4 ) - { - hTcxEnc->nmStartLine = ( hTcxEnc->nmStartLine * 5 ) >> 2; /* low-rate stereo is more efficient than dual-mono due to stereo processing */ - } - } - } - - if ( hTcxEnc != NULL ) - { - if ( st->total_brate < ACELP_24k40 && ( ( st->total_brate > last_total_brate ) || ( st->last_codec_mode == MODE1 ) ) ) - { - /* low-freq memQuantZeros must be reset partially if bitrate increased */ - set_c( hTcxEnc->memQuantZeros, 0, hTcxEnc->nmStartLine ); - } - else - { - if ( st->total_brate >= ACELP_24k40 && st->total_brate <= ACELP_32k && last_total_brate >= ACELP_13k20 && last_total_brate < ACELP_24k40 ) - { - set_c( hTcxEnc->memQuantZeros, 0, st->L_frame ); - } - } - } - - return; -} - void core_coder_reconfig_ivas_fx( Encoder_State *st ) { @@ -270,6 +76,7 @@ void core_coder_reconfig_ivas_fx( move16(); move16(); move16(); + move16(); } IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) @@ -305,8 +112,8 @@ void core_coder_reconfig_ivas_fx( /*Switch off TCX or ACELP?*/ IF( EQ_32( st->sr_core, INT_FS_12k8 ) ) { - st->acelpEnabled = (Word16) EQ_16( ( s_and( st->restrictedMode, 1 ) ), 1 ); - st->tcx20Enabled = (Word16) EQ_16( ( s_and( st->restrictedMode, 2 ) ), 2 ); + st->acelpEnabled = extract_l( EQ_16( ( s_and( st->restrictedMode, 1 ) ), 1 ) ); + st->tcx20Enabled = extract_l( EQ_16( ( s_and( st->restrictedMode, 2 ) ), 2 ) ); move16(); move16(); } @@ -455,7 +262,7 @@ void core_coder_reconfig_ivas_fx( test(); test(); test(); - if ( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) + if ( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( st->element_mode == EVS_MONO ) ) { move16(); st->glr = 1; @@ -502,7 +309,7 @@ void core_coder_reconfig_ivas_fx( move16(); test(); test(); - if ( EQ_32( st->total_brate, IVAS_48k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LT_16( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), shl( st->L_frame, 2 ) ) ) + IF( EQ_32( st->total_brate, IVAS_48k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LT_16( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), shl( st->L_frame, 2 ) ) ) { hTcxEnc->nmStartLine = shr( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), 2 ); /* low-rate stereo is more efficient than dual-mono due to stereo processing */ move16(); diff --git a/lib_enc/core_enc_reconf_fx.c b/lib_enc/core_enc_reconf_fx.c index c11dd9959af47ec89ff3c687936dd24f2926d496..3140422be5d88531fba60b90693049aa84388a8b 100644 --- a/lib_enc/core_enc_reconf_fx.c +++ b/lib_enc/core_enc_reconf_fx.c @@ -31,7 +31,7 @@ void core_coder_reconfig_fx( BITS_ALLOC_init_config_acelp( st->total_brate, st->narrowBand, st->nb_subfr, &( st->acelp_cfg ) ); /*Configuration of partial copy*/ - if ( st->Opt_RF_ON ) + IF( st->Opt_RF_ON ) { st->hRF->acelp_cfg_rf.mode_index = 1; st->hRF->acelp_cfg_rf.midLpc = 0; @@ -58,6 +58,7 @@ void core_coder_reconfig_fx( IF( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) { st->nb_bits_header_tcx = 2; /* signal class */ + move16(); } ELSE IF( st->tcxonly == 0 ) { @@ -71,6 +72,7 @@ void core_coder_reconfig_fx( { /*st->nb_bits_header_ace--;*/ /*No Last_mode*/ st->nb_bits_header_ace = sub( st->nb_bits_header_ace, 1 ); + move16(); } } } @@ -78,6 +80,7 @@ void core_coder_reconfig_fx( if ( st->tcxonly ) { st->nb_bits_header_tcx = add( st->nb_bits_header_tcx, 2 ); + move16(); } @@ -109,11 +112,11 @@ void core_coder_reconfig_fx( st->currEnergyHF_e_fx = 17; /*Sanity check : don't need to be instrumented*/ - if ( st->tcxonly == 0 ) + IF( st->tcxonly == 0 ) { assert( st->acelpEnabled || st->tcx20Enabled || st->frame_size_index == 0 ); } - else + ELSE { assert( st->tcx10Enabled || st->tcx20Enabled || st->frame_size_index == 0 ); } @@ -122,6 +125,7 @@ void core_coder_reconfig_fx( IF( st->hTcxEnc != NULL ) { hTcxEnc->tcxltp = getTcxLtp( st->sr_core ); + move16(); } /*Use for 12.8 kHz sampling rate and low bitrates, the conventional pulse search->better SNR*/ @@ -157,6 +161,7 @@ void core_coder_reconfig_fx( IF( st->hTcxCfg != NULL ) { st->hTcxCfg->na_scale = 32767 /*1.0f Q15*/; + move16(); test(); IF( LT_16( bwidth, 2 ) && ( st->tcxonly == 0 ) ) @@ -174,7 +179,7 @@ void core_coder_reconfig_fx( { if ( st->rf_mode ) { - i--; + i = sub( i, 1 ); } move16(); st->hTcxCfg->na_scale = scaleTcxTable[i].scale; @@ -242,11 +247,11 @@ void core_coder_reconfig_fx( move16(); st->glr = 0; + test(); test(); test(); - test(); - if ( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) + if ( ( EQ_32( st->total_brate, ACELP_9k60 ) || EQ_32( st->total_brate, ACELP_16k40 ) || EQ_32( st->total_brate, ACELP_24k40 ) ) && ( st->element_mode == EVS_MONO ) ) { move16(); st->glr = 1; @@ -256,13 +261,14 @@ void core_coder_reconfig_fx( { st->nb_bits_header_ace = add( st->nb_bits_header_ace, G_LPC_RECOVERY_BITS ); + move16(); } IF( hTcxEnc != NULL ) { test(); IF( EQ_16( st->bwidth, NB ) || EQ_16( st->bwidth, WB ) ) { - test(); + IF( st->rf_mode == 0 ) { index = s_min( N_TCX_STARTLINE_NOISE_WB - 1, s_max( 3, st->frame_size_index ) ); @@ -292,9 +298,12 @@ void core_coder_reconfig_fx( } hTcxEnc->nmStartLine = startLineSWB[index]; move16(); + test(); + test(); if ( EQ_32( st->total_brate, IVAS_48k ) && EQ_16( st->element_mode, IVAS_CPE_MDCT ) && LT_16( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), shl( st->L_frame, 2 ) ) ) { hTcxEnc->nmStartLine = shr( add( hTcxEnc->nmStartLine, shl( hTcxEnc->nmStartLine, 2 ) ), 2 ); /* low-rate stereo is more efficient than dual-mono due to stereo processing */ + move16(); } } } diff --git a/lib_enc/core_enc_switch.c b/lib_enc/core_enc_switch.c index f5a2e1245547d834d87ff8b2404103c6ddc8e265..ba842b9ccd1542e261c12e381de5cab619dc2661 100644 --- a/lib_enc/core_enc_switch.c +++ b/lib_enc/core_enc_switch.c @@ -68,7 +68,7 @@ void core_coder_mode_switch_ivas_fx( move16(); - IF( EQ_16( st->last_core, AMR_WB_CORE ) ) + if ( EQ_16( st->last_core, AMR_WB_CORE ) ) { bSwitchFromAmrwbIO = 1; move16(); @@ -99,7 +99,7 @@ void core_coder_mode_switch_ivas_fx( st->sr_core = sr_core; move16(); Word16 tmp = BASOP_Util_Divide3232_Scale( sr_core, FRAMES_PER_SEC, &exp_res ); - st->L_frame = shr( tmp, 15 - exp_res ); + st->L_frame = shr( tmp, sub( 15, exp_res ) ); // Q0 move16(); st->tcxonly = getTcxonly_fx( st->element_mode, st->total_brate, MCT_flag, st->is_ism_format ); @@ -119,7 +119,7 @@ void core_coder_mode_switch_ivas_fx( Word32 tmp4 = L_mult0( tmp1, tmp2 ); // exp_tmp1 + exp_tmp2 Word32 tmp5 = L_shl( Mpy_32_16_1( tmp4, tmp3 ), 1 ); // exp_tmp1 + exp_tmp2 + exp_tmp3 - st->bits_frame_nominal = (Word16) L_shr( tmp5, sub( 31, ( add( add( exp_tmp1, exp_tmp2 ), exp_tmp3 ) ) ) ); + st->bits_frame_nominal = extract_l( L_shr( tmp5, sub( 31, ( add( add( exp_tmp1, exp_tmp2 ), exp_tmp3 ) ) ) ) ); move16(); st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); move16(); @@ -133,12 +133,30 @@ void core_coder_mode_switch_ivas_fx( st->hTcxCfg->bandwidth = getTcxBandwidth( st->bwidth ); move16(); - st->hTcxCfg->tcxRateLoopOpt = ( st->tcxonly ) ? 2 : 0; - st->hTcxCfg->tcxRateLoopOpt = ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) ? 3 : st->hTcxCfg->tcxRateLoopOpt; + if ( st->tcxonly ) + { + st->hTcxCfg->tcxRateLoopOpt = 2; + move16(); + } + else + { + st->hTcxCfg->tcxRateLoopOpt = 0; + move16(); + } + if ( EQ_16( st->element_mode, IVAS_CPE_MDCT ) ) + { + st->hTcxCfg->tcxRateLoopOpt = 3; + move16(); + } st->hTcxCfg->ctx_hm = getCtxHm( st->element_mode, st->total_brate, st->rf_mode ); st->hTcxCfg->resq = getResq( st->total_brate ); hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, st->rf_mode, st->element_mode ); - st->hTcxCfg->tcxRateLoopOpt = ( st->hTcxCfg->resq && !st->tcxonly ) ? 1 : st->hTcxCfg->tcxRateLoopOpt; + test(); + if ( st->hTcxCfg->resq && !st->tcxonly ) + { + st->hTcxCfg->tcxRateLoopOpt = 1; + move16(); + } st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf, st->element_mode ); move16(); move16(); @@ -174,7 +192,7 @@ void core_coder_mode_switch_ivas_fx( FOR( i = 0; i < FRAME_SIZE_NB; i++ ) { - IF( FrameSizeConfig[i].frame_bits == st->bits_frame_nominal ) + IF( EQ_32( FrameSizeConfig[i].frame_bits, st->bits_frame_nominal ) ) { st->frame_size_index = i; st->bits_frame = FrameSizeConfig[i].frame_bits; @@ -182,7 +200,7 @@ void core_coder_mode_switch_ivas_fx( move16(); move16(); move16(); - break; + BREAK; } } @@ -210,7 +228,7 @@ void core_coder_mode_switch_ivas_fx( st->exp_old_inp_12k8 = sub( st->exp_old_inp_12k8, shift ); move16(); init_coder_ace_plus_ivas_fx( st, last_total_brate, MCT_flag ); - IF( st->hLPDmem != NULL ) + if ( st->hLPDmem != NULL ) { st->hLPDmem->q_lpd_old_exc = st->prev_Q_new; move16(); @@ -268,7 +286,7 @@ void core_coder_mode_switch_ivas_fx( test(); test(); - IF( ( GT_32( last_total_brate, HQ_32k ) || EQ_16( st->last_codec_mode, MODE1 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) + if ( ( GT_32( last_total_brate, HQ_32k ) || EQ_16( st->last_codec_mode, MODE1 ) ) && ( st->element_mode == EVS_MONO ) ) { st->glr_reset = 1; move16(); diff --git a/lib_enc/core_enc_switch_fx.c b/lib_enc/core_enc_switch_fx.c index b3738eef9b47869bba55402da711c34d8187f4d8..1096cfb492cb75edc8ad6ba65069ae4690ec5ef6 100644 --- a/lib_enc/core_enc_switch_fx.c +++ b/lib_enc/core_enc_switch_fx.c @@ -29,8 +29,7 @@ void core_coder_mode_switch_fx( TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD; TCX_ENC_HANDLE hTcxEnc = st->hTcxEnc; - move16(); - move16(); + move16(); move16(); @@ -43,7 +42,7 @@ void core_coder_mode_switch_fx( } sr_core = getCoreSamplerateMode2( st->element_mode, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, st->is_ism_format ); - move16(); + move32(); fscale = sr2fscale( sr_core ); move16(); @@ -59,7 +58,6 @@ void core_coder_mode_switch_fx( tcxonly_tmp = getTcxonly( st->total_brate ); #endif - test(); if ( NE_16( tcxonly_tmp, st->tcxonly ) ) { move16(); @@ -85,9 +83,9 @@ void core_coder_mode_switch_fx( /* st->bits_frame_nominal = extract_l(L_shr(Mpy_32_16_1( L_shl(st->bitrate,8), mult_r(div_s(st->fscale, shl(st->L_frame,4)), FL2WORD16(FSCALE_DENOM/12800.f))), 6)); */ tmp32 = L_shl( st->total_brate, 1 ); /* (float)st->L_frame/(float)st->fscale * (float)FSCALE_DENOM/128.0f * (float)st->bitrate */ st->bits_frame_nominal = extract_l( L_shr( Mpy_32_16_1( tmp32, 20972 ), 6 ) ); /* 20972 = 0.01 * 64 * 32768 */ - + move16(); st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); - + move16(); /* switch IGF configuration */ IF( st->igf ) { @@ -111,7 +109,7 @@ void core_coder_mode_switch_fx( st->hTcxCfg->resq = getResq( st->total_brate ); move16(); hTcxEnc->tcx_lpc_shaped_ari = getTcxLpcShapedAri( st->total_brate, st->rf_mode, st->element_mode ); - + move16(); test(); if ( st->hTcxCfg->resq != 0 && st->tcxonly == 0 ) { @@ -119,6 +117,7 @@ void core_coder_mode_switch_fx( move16(); } st->hTcxCfg->fIsTNSAllowed = getTnsAllowed( st->total_brate, st->igf, st->element_mode ); + move16(); IF( st->hTcxCfg->fIsTNSAllowed != 0 ) { InitTnsConfigs( st->bwidth, st->hTcxCfg->tcx_coded_lines, st->hTcxCfg->tnsConfig, st->hIGFEnc->infoStopFrequency, st->total_brate, st->element_mode, MCT_flag ); @@ -126,7 +125,6 @@ void core_coder_mode_switch_fx( SetAllowTnsOnWhite( st->hTcxCfg->tnsConfig, EQ_16( st->element_mode, IVAS_CPE_MDCT ) ); #endif } - move16(); st->narrowBand = 0; move16(); @@ -166,12 +164,13 @@ void core_coder_mode_switch_fx( } st->restrictedMode = getRestrictedMode( st->element_mode, st->total_brate, 0 ); - + move16(); core_coder_reconfig_fx( st, last_total_bitrate ); } ELSE { st->igf = getIgfPresent_fx( st->element_mode, st->total_brate, st->bwidth, st->rf_mode ); + move16(); init_coder_ace_plus_fx( st, last_total_bitrate, shift, MCT_flag ); } @@ -218,7 +217,7 @@ void core_coder_mode_switch_fx( } test(); - IF( ( GT_32( last_total_bitrate, HQ_32k ) || EQ_32( st->last_codec_mode, MODE1 ) ) && EQ_16( st->element_mode, EVS_MONO ) ) + IF( ( GT_32( last_total_bitrate, HQ_32k ) || EQ_32( st->last_codec_mode, MODE1 ) ) && ( st->element_mode == EVS_MONO ) ) { move16(); st->glr_reset = 1; diff --git a/lib_enc/core_enc_updt.c b/lib_enc/core_enc_updt.c index ff9f3762844609e86afe28c847175b2b4a861714..92a2a7b9e16bca99edaa15efd4e6acc4bdbca01e 100644 --- a/lib_enc/core_enc_updt.c +++ b/lib_enc/core_enc_updt.c @@ -72,17 +72,18 @@ void core_encode_update_ivas_fx( test(); test(); test(); - IF( EQ_16( st->core, ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) + IF( ( st->core == ACELP_CORE ) || EQ_16( st->core, AMR_WB_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || ( st->core_brate == FRAME_NO_DATA ) ) { Word16 max_e = s_max( st->hTcxEnc->exp_buf_speech_ltp, hTcxEnc->exp_buf_speech_ltp ); - Scale_sig( hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, -( max_e - st->hTcxEnc->exp_buf_speech_ltp ) ); - Copy_Scale_sig( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame, -( max_e - st->exp_buf_speech_enc ) ); + Scale_sig( hTcxEnc->buf_speech_ltp, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, negate( sub( max_e, st->hTcxEnc->exp_buf_speech_ltp ) ) ); // Q(31-max_e) + Copy_Scale_sig( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame, negate( sub( max_e, st->exp_buf_speech_enc ) ) ); // Q(31-max_e) st->hTcxEnc->exp_buf_speech_ltp = max_e; + move16(); } } n = add( st->encoderPastSamples_enc, st->encoderLookahead_enc ); - Copy( st->buf_synth + st->L_frame, st->buf_synth, st->L_frame + L_SUBFR ); + Copy( st->buf_synth + st->L_frame, st->buf_synth, add( st->L_frame, L_SUBFR ) ); IF( hTcxEnc != NULL ) { Copy( hTcxEnc->buf_speech_ltp + st->L_frame, hTcxEnc->buf_speech_ltp, n ); @@ -105,7 +106,8 @@ void core_encode_update_ivas_fx( test(); test(); test(); - IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && ( EQ_16( st->codec_mode, MODE2 ) || GT_16( st->element_mode, EVS_MONO ) ) ) ) + test(); + IF( ( st->Opt_DTX_ON && LE_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) || ( st->tcxonly && ( EQ_16( st->codec_mode, MODE2 ) || ( st->element_mode > EVS_MONO ) ) ) ) { /* reset LP memories */ set16_fx( st->mem_MA_fx, 0, M ); diff --git a/lib_enc/core_enc_updt_fx.c b/lib_enc/core_enc_updt_fx.c index bd6f5b5482e700c59c0be1cca2375df718a2e21f..125f0cd524c024eacb7ba95c1e8df1394853be01 100644 --- a/lib_enc/core_enc_updt_fx.c +++ b/lib_enc/core_enc_updt_fx.c @@ -38,7 +38,7 @@ void core_encode_update_fx( Encoder_State *st ) IF( hTcxEnc != NULL ) { - IF( EQ_16( st->core, ACELP_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) || EQ_32( st->core, AMR_WB_CORE ) ) + IF( ( st->core == ACELP_CORE ) || EQ_32( st->core_brate, SID_2k40 ) || ( st->core_brate == FRAME_NO_DATA ) || EQ_32( st->core, AMR_WB_CORE ) ) { Copy( st->buf_speech_enc + st->L_frame, hTcxEnc->buf_speech_ltp + st->L_frame, st->L_frame ); } @@ -146,7 +146,7 @@ void core_encode_update_cng_fx( IF( EQ_32( st->core_brate, SID_2k40 ) ) { /*IVAS_CODE CNG_att is missing */ - enr = cng_energy_fx( st->element_mode, st->bwidth, hDtxEnc->CNG_mode, /*st->hTdCngEnc->CNG_att*/ 0, hLPDmem->old_exc + s_max( L_EXC_MEM - st->L_frame, 0 ), st->L_frame, Q_new ); + enr = cng_energy_fx( st->element_mode, st->bwidth, hDtxEnc->CNG_mode, /*st->hTdCngEnc->CNG_att*/ 0, hLPDmem->old_exc + s_max( sub( L_EXC_MEM, st->L_frame ), 0 ), st->L_frame, Q_new ); /* calculate the energy quantization index */ enr_index = add( enr, 512 /* Q8(2.0) */ ); /* enr + 2.0 */ @@ -157,24 +157,24 @@ void core_encode_update_cng_fx( enr_index = s_max( enr_index, 0 ); hTdCngEnc->old_enr_index = enr_index; + move16(); } /* Update weighted synthesis memory */ - move16(); p_A = Aw; FOR( i = 0; i < st->L_frame; i += L_SUBFR ) { Residu3_fx( p_A, &synth[i], &wsyn[i], L_SUBFR, 0 ); p_A += ( M + 1 ); } - move16(); tmp = sub( st->wspeech_enc[-1], shl( hLPDmem->mem_w0, shift ) ); - E_UTIL_deemph2( -shift, wsyn, st->preemph_fac, st->L_frame, &tmp ); + E_UTIL_deemph2( negate( shift ), wsyn, st->preemph_fac, st->L_frame, &tmp ); hLPDmem->mem_w0 = sub( st->wspeech_enc[st->L_frame - 1], tmp ); hLPDmem->mem_w0 = shr( hLPDmem->mem_w0, shift ); - + move16(); + move16(); /* Update LPC-related memories */ Copy( lsp, st->lsp_old_fx, M ); @@ -193,7 +193,9 @@ void core_encode_update_cng_fx( hLPDmem->dm_fx.prev_state = 0; hLPDmem->tilt_code = TILT_CODE; hLPDmem->gc_threshold = L_deposit_l( 0 ); - + move16(); + move16(); + move16(); /* Update ace/tcx mode */ move16(); st->core = ACELP_CORE; diff --git a/lib_enc/core_switching_enc.c b/lib_enc/core_switching_enc.c index d53e0892a1176136e9b67d43b5294876981d39c5..06d140a094d3066cc7e8c7189070f5e6e026e21b 100644 --- a/lib_enc/core_switching_enc.c +++ b/lib_enc/core_switching_enc.c @@ -48,9 +48,9 @@ void core_switching_pre_enc_ivas_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz */ + const Word16 *old_inp_12k8, /* i : old input signal @12.8kHz q_old_inp_12k8 */ const Word16 q_old_inp_12k8, /* i : Q old input signal @12.8kHz */ - const Word16 *old_inp_16k, /* i : old input signal @16kHz */ + const Word16 *old_inp_16k, /* i : old input signal @16kHz q_old_inp_16k */ const Word16 q_old_inp_16k, /* i : Q old input signal @16kHz */ const Word16 active_cnt, /* i : active frame counter */ const Word16 last_element_mode /* i : last_element_mode */ @@ -70,7 +70,7 @@ void core_switching_pre_enc_ivas_fx( test(); test(); test(); - IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && GT_16( st_fx->element_mode, EVS_MONO ) ) ) ) + IF( EQ_16( st_fx->last_codec_mode, MODE2 ) || ( ( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) && ( st_fx->element_mode > EVS_MONO ) ) ) ) { IF( hLPDmem != NULL ) { @@ -87,11 +87,12 @@ void core_switching_pre_enc_ivas_fx( IF( hBWE_TD != NULL ) { - IF( NE_16( st_fx->last_core, ACELP_CORE ) ) + IF( st_fx->last_core != ACELP_CORE ) { /* reset BWE memories */ set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = L_deposit_l( 0 ); + move32(); } set16_fx( hBWE_FD->old_syn_12k8_16k_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) ); @@ -99,7 +100,7 @@ void core_switching_pre_enc_ivas_fx( test(); IF( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) { - if ( EQ_16( st_fx->element_mode, EVS_MONO ) ) + if ( st_fx->element_mode == EVS_MONO ) { st_fx->last_core = HQ_CORE; move16(); @@ -122,8 +123,9 @@ void core_switching_pre_enc_ivas_fx( hHQ_core->prev_stab_hfe2 = 0; move16(); } + test(); /*ALDO overlap windowed past: also used in MODE2 but for other MDCT-LB*/ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) && hTcxEnc != NULL ) + IF( ( st_fx->element_mode == EVS_MONO ) && hTcxEnc != NULL ) { set16_fx( hTcxEnc->old_out_fx, 0, L_FRAME32k ); } @@ -135,6 +137,7 @@ void core_switching_pre_enc_ivas_fx( Copy( st_fx->lsp_old_fx, st_fx->lsp_old16k_fx, M ); st_fx->rate_switching_reset_16kHz = lsp_convert_poly_fx( st_fx->lsp_old16k_fx, st_fx->L_frame, 0 ); + move16(); } st_fx->use_acelp_preq = 0; @@ -144,7 +147,7 @@ void core_switching_pre_enc_ivas_fx( test(); test(); test(); - IF( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) ) + if ( EQ_16( st_fx->last_core, -1 ) && ( EQ_16( st_fx->core, HQ_CORE ) || EQ_16( st_fx->core, TCX_20_CORE ) || EQ_16( st_fx->core, TCX_10_CORE ) ) ) { /* very first frame is HQ_CORE */ st_fx->last_core = HQ_CORE; @@ -153,7 +156,7 @@ void core_switching_pre_enc_ivas_fx( test(); test(); - IF( EQ_16( st_fx->core, HQ_CORE ) && ( EQ_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* HQ init */ + IF( EQ_16( st_fx->core, HQ_CORE ) && ( ( st_fx->last_core == ACELP_CORE ) || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) ) /* HQ init */ { set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); @@ -171,7 +174,7 @@ void core_switching_pre_enc_ivas_fx( hHQ_core->prev_stab_hfe2 = 0; move16(); - if ( hTcxEnc != NULL ) + IF( hTcxEnc != NULL ) { set16_fx( hTcxEnc->old_out_fx, 0, L_FRAME32k ); } @@ -181,7 +184,7 @@ void core_switching_pre_enc_ivas_fx( within ACELP_CORE if switching from another bitarate to vbr, last_ppp and last_nelp is always updated in the previous frame */ test(); test(); - IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) + IF( ( st_fx->core == ACELP_CORE ) && ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) ) ) { IF( hSC_VBR != NULL ) { @@ -197,7 +200,7 @@ void core_switching_pre_enc_ivas_fx( test(); test(); test(); - IF( EQ_16( st_fx->core, ACELP_CORE ) && ( NE_16( st_fx->last_core, ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || LE_32( st_fx->last_total_brate, PPP_NELP_2k80 ) ) ) + IF( ( st_fx->core == ACELP_CORE ) && ( ( st_fx->last_core != ACELP_CORE ) || EQ_16( st_fx->last_codec_mode, MODE2 ) || LE_32( st_fx->last_total_brate, PPP_NELP_2k80 ) ) ) { st_fx->act_count = 3; move16(); @@ -207,7 +210,12 @@ void core_switching_pre_enc_ivas_fx( test(); test(); - IF( ( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) || + test(); + test(); + test(); + test(); + test(); + IF( ( ( ( st_fx->core == ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && EQ_16( st_fx->last_core, HQ_CORE ) ) || ( ( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) || ( EQ_16( st_fx->element_mode, IVAS_CPE_MDCT ) && EQ_16( last_element_mode, IVAS_CPE_DFT ) ) ) && EQ_16( active_cnt, 1 ) ) ) { IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) @@ -222,6 +230,7 @@ void core_switching_pre_enc_ivas_fx( } st_fx->mem_deemph_fx = 0; + move16(); /* Reset ACELP parameters */ IF( hLPDmem != NULL ) { @@ -255,7 +264,6 @@ void core_switching_pre_enc_ivas_fx( move16(); tmp16 = add( NB_SUBFR, 1 ); - move16(); if ( EQ_16( st_fx->L_frame, L_FRAME ) ) { @@ -268,7 +276,7 @@ void core_switching_pre_enc_ivas_fx( /* Reset old ACELP buffers */ test(); - IF( EQ_16( st_fx->element_mode, EVS_MONO ) && hLPDmem != NULL ) + IF( ( st_fx->element_mode == EVS_MONO ) && hLPDmem != NULL ) { set16_fx( hLPDmem->old_exc, 0, L_EXC_MEM ); } @@ -278,6 +286,7 @@ void core_switching_pre_enc_ivas_fx( /* reset BWE memories */ hBWE_TD->bwe_non_lin_prev_scale_fx = 0; + move32(); } IF( hBWE_FD != NULL ) { @@ -287,7 +296,7 @@ void core_switching_pre_enc_ivas_fx( test(); test(); test(); - IF( ( EQ_16( st_fx->core, ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) ) + IF( ( ( st_fx->core == ACELP_CORE ) || EQ_16( st_fx->core, AMR_WB_CORE ) ) && ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) ) ) { /* Reset the ACELP core in case of TCX->ACELP core switching */ st_fx->Nb_ACELP_frames = 0; @@ -305,7 +314,8 @@ void core_switching_pre_enc_ivas_fx( set16_fx( hLPDmem->dm_fx.prev_gain_pit, 0, 6 ); hLPDmem->dm_fx.prev_state = 0; move16(); - hLPDmem->dm_fx.prev_gain_code = L_deposit_l( 0 ); + hLPDmem->dm_fx.prev_gain_code = 0; + move32(); } st_fx->last_coder_type = GENERIC; @@ -320,7 +330,7 @@ void core_switching_pre_enc_ivas_fx( { set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 ); hBWE_TD->bwe_non_lin_prev_scale_fx = 0; - move16(); + move32(); } /* reset BWE memories */ @@ -361,7 +371,7 @@ void core_switching_pre_enc_ivas_fx( { Sample_Delay_HP = NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS + DELAY_FIR_RESAMPL_NS - DELAY_CLDFB_NS ); Sample_Delay_LP = NS2SA( 12800, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_12k8_NS ); - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + IF( ( st_fx->element_mode > EVS_MONO ) ) { IF( EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) { @@ -371,11 +381,11 @@ void core_switching_pre_enc_ivas_fx( } IF( GT_16( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ) { - Copy_Scale_sig( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_12k8 ) ); + Copy_Scale_sig( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_12k8 ) ); // prev_Q_input_lp } ELSE { - Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ); + Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_12k8, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_12k8 hBWE_FD->prev_Q_input_lp = q_old_inp_12k8; move16(); Copy( old_inp_12k8 + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); @@ -395,19 +405,19 @@ void core_switching_pre_enc_ivas_fx( } IF( GT_16( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ) { - Copy_Scale_sig( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_16k ) ); + Copy_Scale_sig( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP, sub( hBWE_FD->prev_Q_input_lp, q_old_inp_16k ) ); // prev_Q_input_lp } ELSE { - Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ); + Scale_sig( hBWE_FD->old_input_lp_fx, NS2SA( 16000, ACELP_LOOK_NS + DELAY_FD_BWE_ENC_NS ), sub( q_old_inp_16k, hBWE_FD->prev_Q_input_lp ) ); // q_old_inp_16k hBWE_FD->prev_Q_input_lp = q_old_inp_16k; + move16(); Copy( old_inp_16k + sub( L_INP_MEM + L_FRAME, Sample_Delay_LP ), hBWE_FD->old_input_lp_fx, Sample_Delay_LP ); } } tmp = sub( L_LOOK_16k + L_SUBFR16k, Sample_Delay_HP ); Copy( &hBWE_TD->old_speech_shb_fx[tmp], hBWE_FD->new_input_hp_fx, Sample_Delay_HP ); - add( 0, 0 ); IF( NE_16( st_fx->last_extl, WB_BWE ) ) { @@ -416,7 +426,8 @@ void core_switching_pre_enc_ivas_fx( hBWE_FD->modeCount = 0; move16(); } - hBWE_FD->EnergyLF_fx = L_deposit_l( 0 ); + hBWE_FD->EnergyLF_fx = 0; + move32(); hBWE_FD->prev_L_swb_norm1 = 8; move16(); /*8.0 in Q0 */ st_fx->EnergyLT_fx_exp = 30; @@ -425,19 +436,21 @@ void core_switching_pre_enc_ivas_fx( /*---------------------------------------------------------------------* * band-width switching from WB -> SWB/FB *---------------------------------------------------------------------*/ - IF( GT_16( st_fx->element_mode, EVS_MONO ) ) + IF( st_fx->element_mode > EVS_MONO ) { IF( st_fx->bwidth_sw_cnt == 0 ) { + test(); IF( GE_16( st_fx->bwidth, SWB ) && EQ_16( st_fx->last_bwidth, WB ) ) { st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 ); + move16(); } } ELSE { st_fx->bwidth_sw_cnt = add( st_fx->bwidth_sw_cnt, 1 ); - + move16(); IF( EQ_16( st_fx->bwidth_sw_cnt, BWS_TRAN_PERIOD ) ) { st_fx->bwidth_sw_cnt = 0; @@ -532,7 +545,7 @@ void core_switching_post_enc_ivas_fx( test(); test(); test(); - test(); + IF( ( EQ_16( st->extl, SWB_TBE ) || EQ_16( st->extl, FB_TBE ) ) && ( EQ_16( st->last_core, HQ_CORE ) || NE_16( st->L_frame, st->last_L_frame ) || ( NE_16( st->last_extl, SWB_TBE ) && NE_16( st->last_extl, FB_TBE ) && NE_16( st->last_core, TCX_20_CORE ) && NE_16( st->last_core, TCX_10_CORE ) ) ) ) { @@ -573,11 +586,11 @@ void core_switching_post_enc_ivas_fx( /* Fade towards init value for non HQ_CORE */ IF( st->hHQ_core != NULL ) { - st->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_THRESHOLD_FX ) ); /*Q28*/ + st->hHQ_core->crest_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), HQ_CREST_THRESHOLD_FX ) ); /*Q28*/ move32(); st->hHQ_core->crest_lp_q = Q28; move16(); - st->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( 2147483647, HQ_CREST_FAC_SM_FX ), HQ_CREST_MOD_THRESHOLD_FX ) ); /*Q29*/ + st->hHQ_core->crest_mod_lp_fx = L_add( Mpy_32_32( HQ_CREST_FAC_SM_FX, st->hHQ_core->crest_mod_lp_fx ), Mpy_32_32( L_sub( ONE_IN_Q31, HQ_CREST_FAC_SM_FX ), HQ_CREST_MOD_THRESHOLD_FX ) ); /*Q29*/ move32(); st->hHQ_core->crest_mod_lp_q = Q29; move16(); diff --git a/lib_enc/ivas_core_enc.c b/lib_enc/ivas_core_enc.c index e9b45a8c9029809bc9aceaa5146feaceffe0a334..a2a87bacc5234fd072009af9a79a19c6798ec827 100644 --- a/lib_enc/ivas_core_enc.c +++ b/lib_enc/ivas_core_enc.c @@ -54,12 +54,13 @@ * Principal IVAS core coder routine, where number of core channels is 1 or 2 *-------------------------------------------------------------------*/ ivas_error ivas_core_enc( - SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ - CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ - MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ - const Word16 n_CoreChannels, /* i : number of core channels to be coded */ - Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal */ - Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal */ + SCE_ENC_HANDLE hSCE, /* i/o: SCE encoder structure */ + CPE_ENC_HANDLE hCPE, /* i/o: CPE encoder structure */ + MCT_ENC_HANDLE hMCT, /* i/o: MCT encoder structure */ + const Word16 n_CoreChannels, /* i : number of core channels to be coded */ + Word16 old_inp_12k8_fx[][L_INP_12k8], /* i : buffer of old input signal */ + Word16 old_inp_16k_fx[][L_INP], /* i : buffer of old input signal */ + Word16 Q_new[], Word32 ener_fx[], /* i : residual energy from Levinson-Durbin epsP_fx_q */ Word16 A_fx[][NB_SUBFR16k * ( M + 1 )], /* i : A(z) unquantized for the 4 subframes */ Word16 Aw_fx[][NB_SUBFR16k * ( M + 1 )], /* i : weighted A(z) unquantized for subframes */ @@ -90,7 +91,6 @@ ivas_error ivas_core_enc( Encoder_State **sts, *st; STEREO_ICBWE_ENC_HANDLE hStereoICBWE; STEREO_TD_ENC_DATA_HANDLE hStereoTD; - Word16 Q_new[CPE_CHANNELS] = { 0 }; move16(); move16(); Word16 voice_factors_fx[CPE_CHANNELS][NB_SUBFR16k]; /* Q15 */ @@ -834,7 +834,7 @@ ivas_error ivas_core_enc( IF( !MCT_flag ) /* for MCT do this later, otherwise there can be a problem because TCX quant happens later and might get the wrong last_core on a bit rate switch */ { - updt_enc_common_ivas_fx( st ); + updt_enc_common_ivas_fx( st, Q_new[n] ); } IF( st->hBWE_FD != NULL ) diff --git a/lib_enc/ivas_core_pre_proc.c b/lib_enc/ivas_core_pre_proc.c index e57e55c21f69afa45359fd349232be3cde493214..edef59ba2c0009b043ca84beb1f0eca704c3d283 100644 --- a/lib_enc/ivas_core_pre_proc.c +++ b/lib_enc/ivas_core_pre_proc.c @@ -56,8 +56,8 @@ ivas_error pre_proc_ivas( const Word32 element_brate, /* i : element bitrate */ const Word32 last_element_brate, /* i : last element bitrate */ const Word16 input_frame, /* i : frame length */ - Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal */ - Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz */ + Word16 old_inp_12k8_fx[], /* i/o: buffer of old input signal Q_new-1 */ + Word16 old_inp_16k_fx[], /* i/o: buffer of old input signal @ 16kHz Q_new-1 */ Word16 **inp_fx, /* o : ptr. to inp. signal in the current frame*/ Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q */ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* i/o: A(z) unquantized for the 4 subframes */ @@ -571,20 +571,22 @@ ivas_error pre_proc_ivas( Scale_sig( st->buf_wspeech_enc, L_FRAME16k + L_SUBFR + L_FRAME16k + L_NEXT_MAX_16k + 320, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_wspeech_enc ) ) ); st->exp_buf_wspeech_enc = sub( Q15, Q_old_inp_16k ); move16(); + Word16 Q_old_inp_128k = *Q_new; + move16(); IF( !flag_16k_smc ) { error = ivas_compute_core_buffers_fx( st, &inp_16k_fx, old_inp_16k_fx, new_inp_resamp16k_fx, input_frame, last_element_mode, sr_core_tmp, ener_fx, A_fx, Aw_fx, epsP_fx, - lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new ); + lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new, 0 ); IF( NE_32( error, IVAS_ERR_OK ) ) { return error; } *epsP_fx_q = add( Q_r[0], 1 ); + move16(); } test(); - Scale_sig( old_inp_12k8_fx, L_INP_12k8, *Q_new ); // Q_new-1 IF( !( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) ) { /* update signal buffers */ @@ -631,6 +633,8 @@ ivas_error pre_proc_ivas( IF( EQ_16( st->L_frame, L_FRAME ) ) { *inp_fx = inp_12k8_fx; + *Q_new = Q_old_inp_128k; + move16(); } ELSE { @@ -687,7 +691,8 @@ ivas_error ivas_compute_core_buffers_fx( Word16 lsp_mid_fx[M], /* i/o: LSPs in the middle of the frame */ Word16 Q_old_inp_16k, Word16 Q_r[2], - Word16 *Q_new ) + Word16 *Q_new, + Word16 downscale_buf_speech_enc_pe ) { Word16 *inp_16k_fx, *new_inp_16k_fx; Word16 delay, element_mode; @@ -914,257 +919,165 @@ ivas_error ivas_compute_core_buffers_fx( test(); test(); - IF( Q_new ) + + *Q_new = 0; + move16(); + set32_fx( sig_out, 0, 960 ); + test(); + test(); + if ( ( ( EQ_16( st->bwidth, NB ) ) || ( EQ_16( st->max_bwidth, NB ) ) ) && ( GT_32( st->input_Fs, 8000 ) ) ) { - *Q_new = 0; - move16(); - set32_fx( sig_out, 0, 960 ); - test(); - test(); - if ( ( ( EQ_16( st->bwidth, NB ) ) || ( EQ_16( st->max_bwidth, NB ) ) ) && ( GT_32( st->input_Fs, 8000 ) ) ) + headroom = add( headroom, 1 ); + } + test(); + test(); + IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) + { + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - headroom = add( headroom, 1 ); + Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw_fx, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching */ + + st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; + move16(); + st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; + move16(); + + IF( EQ_16( st->L_frame, L_FRAME16k ) ) + { + Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); + } + // PREEMPH_FX(new_inp_16k_fx - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); + PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); + tmp_fx = st->mem_preemph16k_fx; + move16(); + + // PREEMPH_FX(new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx); + PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx ); + preemp_start_idx = new_inp_16k_fx - STEREO_DFT_OVL_16k; + move16(); + preemp_len = STEREO_DFT_OVL_16k + L_FRAME16k; + move16(); } - test(); - test(); - IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) + ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) { - IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + IF( EQ_16( last_element_mode, IVAS_CPE_DFT ) ) { - Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw_fx, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching */ - st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; move16(); - st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; - move16(); - - IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); - } - // PREEMPH_FX(new_inp_16k_fx - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); - PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - tmp_fx = st->mem_preemph16k_fx; + Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); + // PREEMPH_FX(new_inp_16k_fx - L_MEM_RECALC_16K - (STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k), PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx); + PREEMPH_32FX( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), sig_out, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx ); + preemp_start_idx = new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); move16(); - - // PREEMPH_FX(new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx); - PREEMPH_32FX( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx ); - preemp_start_idx = new_inp_16k_fx - STEREO_DFT_OVL_16k; - move16(); - preemp_len = STEREO_DFT_OVL_16k + L_FRAME16k; + preemp_len = STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k; move16(); } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - IF( EQ_16( last_element_mode, IVAS_CPE_DFT ) ) - { - st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; - move16(); - Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - // PREEMPH_FX(new_inp_16k_fx - L_MEM_RECALC_16K - (STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k), PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx); - PREEMPH_32FX( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), sig_out, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx ); - preemp_start_idx = new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - move16(); - preemp_len = STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k; - move16(); - } - - st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; - move16(); - /* preemphasise past segment of input signal when switching from MDCT stereo */ - IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) - { - Word16 length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); - move16(); - - // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k - length_16k, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx); - PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k - length_16k, sig_out, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); - preemp_start_idx = new_inp_16k_fx - lMemRecalc_16k - length_16k; - preemp_len = length_16k; - move16(); - } - - IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ) ); - } - // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); - PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k, sig_out + preemp_len, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - tmp_fx = st->mem_preemph16k_fx; - move16(); - // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx); - PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, sig_out + preemp_len + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx ); - IF( preemp_start_idx && preemp_len ) - { - preemp_len = add( preemp_len, add( L_FRAME16k + L_FILT16k, lMemRecalc_16k ) ); - move16(); - } - ELSE - { - preemp_start_idx = new_inp_16k_fx - lMemRecalc_16k; - preemp_len = add( L_FRAME16k + L_FILT16k, lMemRecalc_16k ); - move16(); - } - } - ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) - { - // PREEMPH_FX(new_inp_16k_fx, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); - PREEMPH_32FX( new_inp_16k_fx, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - tmp_fx = st->mem_preemph16k_fx; - move16(); - // PREEMPH_FX(new_inp_16k_fx + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx); - PREEMPH_32FX( new_inp_16k_fx + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx ); - preemp_start_idx = new_inp_16k_fx; - preemp_len = L_FRAME16k + L_FILT16k; - move16(); - } - maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); - inp_max = s_max( extract_h( max_32 ), 1 ); - - Word16 shift = sub( norm_s( inp_max ), headroom ); - Word16 Q_min, i; - shift = s_max( shift, 0 ); - shift = s_min( shift, Q_MAX ); - minimum_fx( st->Q_max_16k, L_Q_MEM, &Q_min ); - *Q_new = s_min( shift, Q_min ); + st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; move16(); - IF( inp_max == 0 ) - { - IF( NE_16( st->last_coder_type, UNVOICED ) ) - { - *Q_new = s_min( *Q_new, 1 ); - move16(); - } - } - FOR( i = L_Q_MEM - 1; i > 0; i-- ) + /* preemphasise past segment of input signal when switching from MDCT stereo */ + IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) { - st->Q_max_16k[i] = st->Q_max_16k[i - 1]; + Word16 length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); move16(); - } - st->Q_max_16k[i] = shift; - move16(); - - Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, *Q_new ); - Scale_sig( old_inp_16k_fx, (Word16) ( preemp_start_idx - old_inp_16k_fx ), *Q_new ); - } - ELSE IF( GT_32( input_Fs, 8000 ) ) /* keep memory up-to-date in case of bitrate switching */ - { - IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) - { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; + // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k - length_16k, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx); + PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k - length_16k, sig_out, PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); + preemp_start_idx = new_inp_16k_fx - lMemRecalc_16k - length_16k; + preemp_len = length_16k; move16(); } - ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) + + IF( EQ_16( st->L_frame, L_FRAME16k ) ) { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - lMemRecalc_16k - 1]; - move16(); + Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ) ); } - ELSE IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) + // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); + PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k, sig_out + preemp_len, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); + tmp_fx = st->mem_preemph16k_fx; + move16(); + // PREEMPH_FX(new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx); + PREEMPH_32FX( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, sig_out + preemp_len + L_FRAME16k, PREEMPH_FAC_16k, lMemRecalc_16k + L_FILT16k, &tmp_fx ); + IF( preemp_start_idx && preemp_len ) { - st->mem_preemph16k_fx = 0; + preemp_len = add( preemp_len, add( L_FRAME16k + L_FILT16k, lMemRecalc_16k ) ); move16(); } - ELSE /* SCE */ + ELSE { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - 1]; + preemp_start_idx = new_inp_16k_fx - lMemRecalc_16k; + preemp_len = add( L_FRAME16k + L_FILT16k, lMemRecalc_16k ); move16(); } - st->mem_preemph16k_DFT_fx = st->mem_preemph16k_fx; + } + ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) + { + // PREEMPH_FX(new_inp_16k_fx, PREEMPH_FAC_16k, L_FRAME16k, &(st->mem_preemph16k_fx)); + PREEMPH_32FX( new_inp_16k_fx, sig_out, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); + tmp_fx = st->mem_preemph16k_fx; + move16(); + // PREEMPH_FX(new_inp_16k_fx + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx); + PREEMPH_32FX( new_inp_16k_fx + L_FRAME16k, sig_out + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx ); + preemp_start_idx = new_inp_16k_fx; + preemp_len = L_FRAME16k + L_FILT16k; move16(); } - } - ELSE - { - test(); - test(); - IF( GT_32( input_Fs, 8000 ) && EQ_32( sr_core, INT_FS_16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) + maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); + inp_max = s_max( extract_h( max_32 ), 1 ); + + Word16 shift = sub( norm_s( inp_max ), headroom ); + Word16 Q_min, i; + shift = s_max( shift, 0 ); + shift = s_min( shift, Q_MAX ); + minimum_fx( st->Q_max_16k, L_Q_MEM, &Q_min ); + *Q_new = s_min( shift, Q_min ); + move16(); + IF( inp_max == 0 ) { - IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + IF( NE_16( st->last_coder_type, UNVOICED ) ) { - Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, st->inp_16k_mem_stereo_sw_fx, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); /* update for TD/DFT stereo switching */ - - st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; - move16(); - st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; + *Q_new = s_min( *Q_new, 1 ); move16(); + } + } - IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); - } - PREEMPH_FX( new_inp_16k_fx - STEREO_DFT_OVL_16k, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - tmp_fx = st->mem_preemph16k_fx; - move16(); + FOR( i = L_Q_MEM - 1; i > 0; i-- ) + { + st->Q_max_16k[i] = st->Q_max_16k[i - 1]; + move16(); + } + st->Q_max_16k[i] = shift; + move16(); - PREEMPH_FX( new_inp_16k_fx - STEREO_DFT_OVL_16k + L_FRAME16k, PREEMPH_FAC_16k, STEREO_DFT_OVL_16k, &tmp_fx ); - } - ELSE IF( EQ_16( st->element_mode, IVAS_CPE_TD ) ) - { - IF( EQ_16( last_element_mode, IVAS_CPE_DFT ) ) - { - st->mem_preemph16k_fx = st->mem_preemph16k_DFT_fx; - move16(); - Copy( st->inp_16k_mem_stereo_sw_fx, new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ); - PREEMPH_FX( new_inp_16k_fx - L_MEM_RECALC_16K - ( STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k ), PREEMPH_FAC_16k, STEREO_DFT_OVL_16k - L_MEM_RECALC_16K - L_FILT16k, &st->mem_preemph16k_fx ); - } - - st->mem_preemph16k_DFT_fx = old_inp_16k_fx[L_INP_MEM - STEREO_DFT_OVL_16k + L_FRAME16k - 1]; - move16(); + Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, *Q_new ); - /* preemphasise past segment of input signal when switching from MDCT stereo */ - IF( EQ_16( last_element_mode, IVAS_CPE_MDCT ) ) - { - Word16 length_16k = NS2SA( INT_FS_16k, L_MEM_RECALC_SCH_NS - DELAY_FIR_RESAMPL_NS ); - move16(); - - PREEMPH_FX( new_inp_16k_fx - add( lMemRecalc_16k, length_16k ), PREEMPH_FAC, length_16k, &st->mem_preemph16k_fx ); - } - - IF( EQ_16( st->L_frame, L_FRAME16k ) ) - { - Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc + sub( L_FRAME16k - L_FILT16k, lMemRecalc_16k ), add( lMemRecalc_16k, L_FRAME16k + L_FILT16k ) ); - } - PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - tmp_fx = st->mem_preemph16k_fx; - move16(); - PREEMPH_FX( new_inp_16k_fx - lMemRecalc_16k + L_FRAME16k, PREEMPH_FAC_16k, add( lMemRecalc_16k, L_FILT16k ), &tmp_fx ); - } - ELSE IF( EQ_16( element_mode, IVAS_SCE ) ) - { - PREEMPH_FX( new_inp_16k_fx, PREEMPH_FAC_16k, L_FRAME16k, &( st->mem_preemph16k_fx ) ); - tmp_fx = st->mem_preemph16k_fx; - move16(); - PREEMPH_FX( new_inp_16k_fx + L_FRAME16k, PREEMPH_FAC_16k, L_FILT16k, &tmp_fx ); - } + Scale_sig( old_inp_16k_fx, (Word16) ( preemp_start_idx - old_inp_16k_fx ), *Q_new ); + } + ELSE IF( GT_32( input_Fs, 8000 ) ) /* keep memory up-to-date in case of bitrate switching */ + { + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; + move16(); } - ELSE IF( GT_32( input_Fs, 8000 ) ) /* keep memory up-to-date in case of bitrate switching */ + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { - IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) - { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - STEREO_DFT_OVL_16k - 1]; - move16(); - } - ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) - { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - lMemRecalc_16k - 1]; - move16(); - } - ELSE IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) - { - st->mem_preemph16k_fx = 0; - move16(); - } - ELSE /* SCE */ - { - st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - 1]; - move16(); - } - st->mem_preemph16k_DFT_fx = st->mem_preemph16k_fx; + st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - lMemRecalc_16k - 1]; move16(); } + ELSE IF( EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + st->mem_preemph16k_fx = 0; + move16(); + } + ELSE /* SCE */ + { + st->mem_preemph16k_fx = new_inp_16k_fx[L_frame_tmp - 1]; + move16(); + } + st->mem_preemph16k_DFT_fx = st->mem_preemph16k_fx; + move16(); } /*-----------------------------------------------------------------* @@ -1176,18 +1089,28 @@ ivas_error ivas_compute_core_buffers_fx( IF( EQ_16( st->L_frame, L_FRAME16k ) && NE_16( element_mode, IVAS_CPE_MDCT ) ) { /* update signal buffers */ + Word16 shift; + IF( downscale_buf_speech_enc_pe ) + { + shift = negate( *Q_new ); + } + ELSE + { + shift = 0; + } + move16(); IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) { - Copy( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc_pe + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k ); + Copy_Scale_sig( new_inp_16k_fx - STEREO_DFT_OVL_16k, st->buf_speech_enc_pe + L_FRAME16k - STEREO_DFT_OVL_16k, L_FRAME16k + STEREO_DFT_OVL_16k, shift ); // Q-1 } ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) ) { - Copy( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc_pe + L_FRAME16k - lMemRecalc_16k - L_FILT16k, L_FRAME16k + lMemRecalc_16k + L_FILT16k ); + Copy_Scale_sig( new_inp_16k_fx - lMemRecalc_16k, st->buf_speech_enc_pe + L_FRAME16k - lMemRecalc_16k - L_FILT16k, L_FRAME16k + lMemRecalc_16k + L_FILT16k, shift ); // Q-1 } ELSE { Copy( new_inp_resamp16k_fx, st->buf_speech_enc + L_FRAME16k, L_FRAME16k ); - Copy( new_inp_16k_fx, st->buf_speech_enc_pe + L_FRAME16k, L_FRAME16k ); + Copy_Scale_sig( new_inp_16k_fx, st->buf_speech_enc_pe + L_FRAME16k, L_FRAME16k, shift ); // Q-1 } /*--------------------------------------------------------------* diff --git a/lib_enc/ivas_core_pre_proc_front.c b/lib_enc/ivas_core_pre_proc_front.c index c0db284df22b26359436e906377b1dec6a87f88b..66e8b9fcf91ad2e9e0cc7e83cb8ec8f985cfaa21 100644 --- a/lib_enc/ivas_core_pre_proc_front.c +++ b/lib_enc/ivas_core_pre_proc_front.c @@ -90,9 +90,9 @@ ivas_error pre_proc_front_ivas_fx( const Word16 nb_bits_metadata, /* i : number of metadata bits */ const Word16 input_frame, /* i : frame length */ const Word16 n, /* i : channel number */ - Word16 old_inp_12k8_fx[], /* o : (Q-1) buffer of old input signal */ - Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q-1 */ - Word32 *ener_fx, /* o : residual energy from Levinson-Durbin Q_r */ + Word16 old_inp_12k8_fx[], /* o : buffer of old input signal Q_new-1 */ + Word16 old_inp_16k_fx[], /* o : buffer of old input signal @16kHz Q_new-1 */ + Word32 *ener_fx, /* o : residual energy from Levinson-Durbin epsP_fx_q */ Word16 *relE_fx, /* o : frame relative energy Q8 */ Word16 A_fx[NB_SUBFR16k * ( M + 1 )], /* o : A(z) unquantized for the 4 subframes Q12 */ Word16 Aw_fx[NB_SUBFR16k * ( M + 1 )], /* o : weighted A(z) unquantized for subframes Q12 */ @@ -134,7 +134,8 @@ ivas_error pre_proc_front_ivas_fx( const Word16 front_vad_dtx_flag, /* i : front-VAD DTX flag to overwrite VAD decision*/ const IVAS_FORMAT ivas_format, /* i : IVAS format */ const Word16 MCT_flag, /* i : hMCT handle allocated (1) or not (0) */ - const Word32 ivas_total_brate /* i : IVAS total bitrate - for setting the DTX */ + const Word32 ivas_total_brate, /* i : IVAS total bitrate - for setting the DTX */ + Word16 *Q_new #ifdef DEBUG_MODE_INFO , const Word16 ch_idx @@ -607,151 +608,143 @@ ivas_error pre_proc_front_ivas_fx( * Perform fixed preemphasis (12.8 kHz signal) through 1 - g*z^-1 *-----------------------------------------------------------------*/ - Word16 Q_new = 1; + *Q_new = 0; move16(); + set32_fx( sig_out, 0, 960 ); - IF( Q_new ) - { - Q_new = 0; - move16(); - set32_fx( sig_out, 0, 960 ); - - headroom = 1; - move16(); + headroom = 1; + move16(); - test(); - test(); - IF( ( st->bwidth == NB || st->max_bwidth == NB ) && GT_32( st->input_Fs, 8000 ) ) - { - headroom = add( headroom, 1 ); - } + test(); + test(); + IF( ( st->bwidth == NB || st->max_bwidth == NB ) && GT_32( st->input_Fs, 8000 ) ) + { + headroom = add( headroom, 1 ); + } - test(); - IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) - { - Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ + test(); + IF( EQ_16( element_mode, IVAS_CPE_DFT ) ) + { + Copy( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, st->inp_12k8_mem_stereo_sw_fx, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); /* memory for TD/DFT stereo switching */ - st->mem_preemph_fx = st->mem_preemph_DFT_fx; - move16(); - st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; - move16(); + st->mem_preemph_fx = st->mem_preemph_DFT_fx; + move16(); + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; + move16(); - // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - dummy_fx = st->mem_preemph_fx; - move16(); + // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; + move16(); - // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); - PREEMPH_32FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, sig_out + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); - preemp_start_idx = new_inp_12k8_fx - STEREO_DFT_OVL_12k8; - move16(); - preemp_len = STEREO_DFT_OVL_12k8 + L_FRAME; - move16(); - } - ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + // PREEMPH_FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); + PREEMPH_32FX( new_inp_12k8_fx - STEREO_DFT_OVL_12k8 + L_FRAME, sig_out + L_FRAME, PREEMPH_FAC, STEREO_DFT_OVL_12k8, &dummy_fx ); + preemp_start_idx = new_inp_12k8_fx - STEREO_DFT_OVL_12k8; + move16(); + preemp_len = STEREO_DFT_OVL_12k8 + L_FRAME; + move16(); + } + ELSE IF( EQ_16( element_mode, IVAS_CPE_TD ) || EQ_16( element_mode, IVAS_CPE_MDCT ) ) + { + IF( st->idchan == 0 ) { - IF( st->idchan == 0 ) + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) { - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) ) - { - st->mem_preemph_fx = st->mem_preemph_DFT_fx; - move16(); - Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); - // PREEMPH_FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), sig_out, PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); - preemp_start_idx = new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); - move16(); - preemp_len = STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT; - move16(); - } - - st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ + st->mem_preemph_fx = st->mem_preemph_DFT_fx; move16(); - } - - /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ - test(); - IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) - { - Word16 length_12k8 = NS2SA_FX2( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); + Copy( st->inp_12k8_mem_stereo_sw_fx, new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); + // PREEMPH_FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ), sig_out, PREEMPH_FAC, STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT, &st->mem_preemph_fx ); + preemp_start_idx = new_inp_12k8_fx - L_MEM_RECALC_12K8 - ( STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT ); move16(); - // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, sig_out, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); - preemp_start_idx = new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8; - preemp_len = length_12k8; + preemp_len = STEREO_DFT_OVL_12k8 - L_MEM_RECALC_12K8 - L_FILT; move16(); } - // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8, sig_out + preemp_len, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - dummy_fx = st->mem_preemph_fx; + st->mem_preemph_DFT_fx = old_inp_12k8_fx[L_INP_MEM - STEREO_DFT_OVL_12k8 + L_FRAME - 1]; /* == inp_12k8[L_FRAME-1] */ move16(); - // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); - PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, sig_out + preemp_len + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); - - test(); - IF( preemp_start_idx && preemp_len ) - { - preemp_len = add( preemp_len, add( L_FRAME + L_FILT, lMemRecalc_12k8 ) ); - move16(); - } - ELSE - { - preemp_start_idx = new_inp_12k8_fx - lMemRecalc_12k8; - preemp_len = add( L_FRAME + L_FILT, lMemRecalc_12k8 ); - move16(); - } } - ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ + + /* preemphasise past segment of the Secondary channel input signal when switching from DFT stereo */ + test(); + IF( EQ_16( hCPE->last_element_mode, IVAS_CPE_DFT ) && EQ_16( st->idchan, 1 ) ) { - // PREEMPH_FX( new_inp_12k8_fx, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - PREEMPH_32FX( new_inp_12k8_fx, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); - dummy_fx = st->mem_preemph_fx; + Word16 length_12k8 = NS2SA_FX2( INT_FS_12k8, L_MEM_RECALC_SCH_NS ); move16(); - // PREEMPH_FX( new_inp_12k8_fx + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); - PREEMPH_32FX( new_inp_12k8_fx + L_FRAME, sig_out + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); - preemp_start_idx = new_inp_12k8_fx; - preemp_len = L_FRAME + L_FILT; + // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8, sig_out, PREEMPH_FAC, length_12k8, &st->mem_preemph_fx ); + preemp_start_idx = new_inp_12k8_fx - lMemRecalc_12k8 - length_12k8; + preemp_len = length_12k8; move16(); } - maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); - inp_max = s_max( extract_h( max_32 ), 1 ); - - shift = sub( norm_s( inp_max ), headroom ); - Word16 Q_min; - shift = s_max( shift, 0 ); - shift = s_min( shift, Q_MAX ); - minimum_fx( st->Q_max, L_Q_MEM, &Q_min ); - Q_new = s_min( shift, Q_min ); + // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8, sig_out + preemp_len, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; move16(); - IF( inp_max == 0 ) + // PREEMPH_FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); + PREEMPH_32FX( new_inp_12k8_fx - lMemRecalc_12k8 + L_FRAME, sig_out + preemp_len + L_FRAME, PREEMPH_FAC, lMemRecalc_12k8 + L_FILT, &dummy_fx ); + + test(); + IF( preemp_start_idx && preemp_len ) { - IF( NE_16( st->last_coder_type, UNVOICED ) ) - { - Q_new = s_min( Q_new, 1 ); - move16(); - } + preemp_len = add( preemp_len, add( L_FRAME + L_FILT, lMemRecalc_12k8 ) ); + move16(); } - - FOR( i = L_Q_MEM - 1; i > 0; i-- ) + ELSE { - st->Q_max[i] = st->Q_max[i - 1]; + preemp_start_idx = new_inp_12k8_fx - lMemRecalc_12k8; + preemp_len = add( L_FRAME + L_FILT, lMemRecalc_12k8 ); move16(); } - st->Q_max[i] = shift; + } + ELSE /* IVAS_SCE or IVAS_CPE_MDCT */ + { + // PREEMPH_FX( new_inp_12k8_fx, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + PREEMPH_32FX( new_inp_12k8_fx, sig_out, PREEMPH_FAC, L_FRAME, &st->mem_preemph_fx ); + dummy_fx = st->mem_preemph_fx; move16(); + // PREEMPH_FX( new_inp_12k8_fx + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); + PREEMPH_32FX( new_inp_12k8_fx + L_FRAME, sig_out + L_FRAME, PREEMPH_FAC, L_FILT, &dummy_fx ); + preemp_start_idx = new_inp_12k8_fx; + preemp_len = L_FRAME + L_FILT; + move16(); + } - Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, Q_new ); - - Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), Q_new ); + maximum_abs_32_fx( sig_out, preemp_len, &max_32 ); + inp_max = s_max( extract_h( max_32 ), 1 ); - Q_new = add( Q_new, Q_to_be_looked_into ); + shift = sub( norm_s( inp_max ), headroom ); + Word16 Q_min; + shift = s_max( shift, 0 ); + shift = s_min( shift, Q_MAX ); + minimum_fx( st->Q_max, L_Q_MEM, &Q_min ); + *Q_new = s_min( shift, Q_min ); + move16(); + IF( inp_max == 0 ) + { + IF( NE_16( st->last_coder_type, UNVOICED ) ) + { + *Q_new = s_min( *Q_new, 1 ); + move16(); + } } - ELSE + + FOR( i = L_Q_MEM - 1; i > 0; i-- ) { - // See if needed + st->Q_max[i] = st->Q_max[i - 1]; + move16(); } + st->Q_max[i] = shift; + move16(); + + Copy_Scale_sig32_16( sig_out, preemp_start_idx, preemp_len, *Q_new ); + + Scale_sig( old_inp_12k8_fx, (Word16) ( preemp_start_idx - old_inp_12k8_fx ), *Q_new ); + + *Q_new = add( *Q_new, Q_to_be_looked_into ); + move16(); + cldfbScale.hb_scale = cldfbScale.lb_scale; move16(); @@ -771,17 +764,29 @@ ivas_error pre_proc_front_ivas_fx( Word16 Scale_fac[2] = { 0 }; move16(); move16(); - Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); - st->q_Bin_E = add( Q_new, Q_SCALE - 2 ); + Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( *Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); + st->q_Bin_E = add( *Q_new, Q_SCALE - 2 ); move16(); - Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); - ivas_analy_sp_fx_front( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, Q_new, fr_bands_fx, lf_E_fx, &Etot_fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, PS_fx, lgBin_E_fx, band_energies_fx, fft_buff_fx /*, Q_inp_dmx*/ ); - st->q_Bin_E_old = add( Q_new, Q_SCALE - 2 ); + Word32 Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( *Q_new, QSCALE - 2 ) ) ), 1 ), 1 ); + ivas_analy_sp_fx_front( element_mode, hCPE, input_Fs, inp_12k8_fx /*old_inp_12k8_e*/, *Q_new, fr_bands_fx, lf_E_fx, &Etot_fx, st->min_band, st->max_band, Le_min_scaled, Scale_fac, st->Bin_E_fx, st->Bin_E_old_fx, PS_fx, lgBin_E_fx, band_energies_fx, fft_buff_fx /*, Q_inp_dmx*/ ); + st->q_Bin_E_old = add( *Q_new, Q_SCALE - 2 ); move16(); - fr_bands_fx_q = add( Q_new, QSCALE ); - band_energies_fx_exp = sub( 31, add( Q_new, QSCALE ) ); - Qfact_PS = add( Q_new, QSCALE - 2 ); - q_lf_E_fx = add( Q_new, QSCALE - 2 ); + fr_bands_fx_q = add( *Q_new, QSCALE - 2 ); + band_energies_fx_exp = sub( 31, add( *Q_new, QSCALE - 2 ) ); + Word16 tmp_norm = L_norm_arr( fr_bands_fx, 2 * NB_BANDS ); + IF( GE_16( tmp_norm, 2 ) ) + { + scale_sig32( fr_bands_fx, 2 * NB_BANDS, 2 ); + fr_bands_fx_q = add( fr_bands_fx_q, 2 ); + } + tmp_norm = L_norm_arr( band_energies_fx, 2 * NB_BANDS ); + IF( GE_16( tmp_norm, 2 ) ) + { + scale_sig32( band_energies_fx, 2 * NB_BANDS, 2 ); + band_energies_fx_exp = sub( band_energies_fx_exp, 2 ); + } + Qfact_PS = add( *Q_new, QSCALE - 2 ); + q_lf_E_fx = add( *Q_new, QSCALE - 2 ); IF( lgBin_E_fx != NULL ) { Copy_Scale_sig_16_32( st->lgBin_E_fx, st->Bin_E_fx, L_FFT / 2, sub( st->q_Bin_E, Q7 ) ); @@ -791,7 +796,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 i_sbfr; FOR( i_sbfr = 0; i_sbfr < 2; i_sbfr++ ) { - fft_q[i_sbfr] = add( Q_new, Scale_fac[i_sbfr] ); + fft_q[i_sbfr] = add( *Q_new, Scale_fac[i_sbfr] ); move16(); min_q = s_min( min_q, fft_q[i_sbfr] ); } @@ -806,11 +811,11 @@ ivas_error pre_proc_front_ivas_fx( move16(); move16(); - Scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( add( Q_new, QSCALE ), st->hNoiseEst->q_bckr ) ); - st->hNoiseEst->q_bckr = add( Q_new, QSCALE ); + Scale_sig32( st->hNoiseEst->bckr_fx, NB_BANDS, sub( add( *Q_new, QSCALE ), st->hNoiseEst->q_bckr ) ); + st->hNoiseEst->q_bckr = add( *Q_new, QSCALE ); move16(); - Scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, sub( add( Q_new, QSCALE ), st->hNoiseEst->q_enrO ) ); - st->hNoiseEst->q_enrO = add( Q_new, QSCALE ); + Scale_sig32( st->hNoiseEst->enrO_fx, NB_BANDS, sub( add( *Q_new, QSCALE ), st->hNoiseEst->q_enrO ) ); + st->hNoiseEst->q_enrO = add( *Q_new, QSCALE ); move16(); IF( hStereoClassif != NULL ) @@ -851,7 +856,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); } - st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float + st->vad_flag = wb_vad_ivas_fx( st, fr_bands_fx, &i, &i, &i, &snr_sum_he_fx, &localVAD_HE_SAD, &( st->flag_noisy_speech_snr ), *Q_new, NULL, NULL, -MAX_16, -MAX_16 ); //-100000f == max 16bit float move16(); test(); @@ -937,10 +942,10 @@ ivas_error pre_proc_front_ivas_fx( * Correlation correction as a function of total noise level *----------------------------------------------------------------*/ - Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( Q_new, QSCALE ) ) ), 1 ), 1 ); + Le_min_scaled = L_shr_r( L_add( L_shr( E_MIN_FXQ15, sub( 14, add( *Q_new, QSCALE ) ) ), 1 ), 1 ); - noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, Q_new, Le_min_scaled ); - st->hNoiseEst->q_bckr = add( Q_new, QSCALE ); + noise_est_down_fx( fr_bands_fx, st->hNoiseEst->bckr_fx, tmpN_fx, tmpE_fx, st->min_band, st->max_band, &st->hNoiseEst->totalNoise_fx, Etot_fx, &st->hNoiseEst->Etot_last_fx, &st->hNoiseEst->Etot_v_h2_fx, *Q_new, Le_min_scaled ); + st->hNoiseEst->q_bckr = add( *Q_new, QSCALE ); move16(); test(); @@ -968,7 +973,7 @@ ivas_error pre_proc_front_ivas_fx( move16(); move16(); } - q_tmpN = q_tmpE = add( Q_new, QSCALE ); + q_tmpN = q_tmpE = add( *Q_new, QSCALE ); move16(); *relE_fx = sub( Etot_fx, st->lp_speech_fx ); move16(); @@ -1083,7 +1088,7 @@ ivas_error pre_proc_front_ivas_fx( st->cng_type = LP_CNG; move16(); } - dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, Q_new ); + dtx_ivas_fx( st, ivas_total_brate, *vad_flag_dtx, inp_12k8_fx, *Q_new ); test(); test(); @@ -1174,7 +1179,7 @@ ivas_error pre_proc_front_ivas_fx( Word16 Q_new_loc; Word16 Q_r[2]; set16_fx( Q_r, 0, 2 ); - Q_new_loc = Q_new; + Q_new_loc = *Q_new; move16(); alw_pitch_lag_12k8[0] = st->old_pitch_la; @@ -1223,7 +1228,7 @@ ivas_error pre_proc_front_ivas_fx( *----------------------------------------------------------------*/ Word32 speech_buff[L_FRAME + M]; Copy_Scale_sig_16_32( inp_12k8_fx - M, speech_buff, L_FRAME + M, Q12 ); - hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), add( Q_new, 12 ) ); + hCPE->hStereoTD->tdm_lp_reuse_flag = tdm_lp_comparison_fx( hCPE->hStereoTD, hCPE->hStereoClassif, st, &speech_buff[0], tdm_A_PCh_fx, A_fx, M, tdm_lsp_new_PCh_fx, lsp_new_fx, L_FRAME, L_sub( element_brate, imult3216( FRAMES_PER_SEC, nb_bits_metadata ) ), add( *Q_new, 12 ) ); move16(); } @@ -1234,14 +1239,14 @@ ivas_error pre_proc_front_ivas_fx( * 1/4 pitch precision improvement *----------------------------------------------------------------*/ - st->mem_wsp_fx = shl( st->mem_wsp_fx, sub( Q_new, st->mem_wsp_q ) ); - st->mem_wsp_q = Q_new; + st->mem_wsp_fx = shl( st->mem_wsp_fx, sub( *Q_new, st->mem_wsp_q ) ); + st->mem_wsp_q = *Q_new; move16(); move16(); ivas_find_wsp( L_FRAME, L_SUBFR, NB_SUBFR, A_fx, Aw_fx, inp_12k8_fx, TILT_FAC_FX, wsp_fx, &st->mem_wsp_fx, GAMMA1, L_LOOK_12k8 ); - Word16 Q_wsp = Q_new; + Word16 Q_wsp = *Q_new; move16(); IF( st->vad_flag == 0 ) { @@ -1341,7 +1346,7 @@ ivas_error pre_proc_front_ivas_fx( q_fr_bands = s_min( q_fr_bands, hCPE->hFrontVad[j]->hNoiseEst->ave_enr_q ); } } - Word16 q_inp_12k8 = Q_new; // inp_12k8_fx + Word16 q_inp_12k8 = *Q_new; // inp_12k8_fx move16(); scale_sig32( lf_E_fx, 2 * VOIC_BINS, sub( sub( q_fr_bands, 2 ), q_lf_E_fx ) ); @@ -1541,10 +1546,6 @@ ivas_error pre_proc_front_ivas_fx( * TC frame selection *-----------------------------------------------------------------*/ - Word16 oi12k8_fx[L_INP_12k8]; - Copy_Scale_sig( old_inp_12k8_fx, oi12k8_fx, L_INP_12k8, negate( Q_new ) ); // Q0 - Word16 *ni12k8_fx = oi12k8_fx + L_INP_MEM; - inp_12k8_fx = ni12k8_fx - L_look; st->clas = signal_clas_fx( st, inp_12k8_fx, ee_fx, *relE_fx, L_look, tdm_SM_last_clas ); select_TC_fx( MODE1, st->tc_cnt, &st->coder_type, st->localVAD ); @@ -1725,11 +1726,14 @@ ivas_error pre_proc_front_ivas_fx( Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( Q_old_inp_16k, sub( Q15, st->exp_buf_speech_enc ) ) ); st->exp_buf_speech_enc = sub( Q15, Q_old_inp_16k ); move16(); + + Word16 Q_old_inp_12k8 = *Q_new; + move16(); /* Compute core-coder buffers at internal sampling rate */ error = ivas_compute_core_buffers_fx( st, NULL, old_inp_16k_fx, NULL, input_frame, IVAS_SCE /*last_element_mode*/, INT_FS_16k /*sr_core_tmp*/, ener_fx, A_fx, Aw_fx, epsP_fx, - lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, NULL ); + lsp_new_fx, lsp_mid_fx, Q_old_inp_16k, Q_r, Q_new, 1 ); IF( error != IVAS_ERR_OK ) { return error; @@ -1737,6 +1741,13 @@ ivas_error pre_proc_front_ivas_fx( *epsP_fx_q = add( Q_r[0], 1 ); move16(); + st->mem_wsp_enc = shr_r( st->mem_wsp_enc, *Q_new ); // Q_new - 1 -> Q-1 + move16(); + + *Q_new = add( *Q_new, Q_to_be_looked_into ); // actual Q_new + move16(); + Scale_sig( old_inp_12k8_fx, L_INP_12k8, sub( *Q_new, Q_old_inp_12k8 ) ); + Scale_sig( st->buf_speech_enc, L_PAST_MAX_32k + L_FRAME32k + L_NEXT_MAX_32k, sub( 0, sub( Q15, st->exp_buf_speech_enc ) ) ); st->exp_buf_speech_enc = Q15; move16(); @@ -1744,12 +1755,12 @@ ivas_error pre_proc_front_ivas_fx( } ELSE { - Scale_sig( old_wsp_fx, L_WSP, sub( Q_new, *q_old_wsp ) ); - *q_old_wsp = Q_new; + Scale_sig( old_wsp_fx, L_WSP, sub( *Q_new, *q_old_wsp ) ); + *q_old_wsp = *Q_new; move16(); - Q_wsp = Q_new; + Q_wsp = *Q_new; move16(); - smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, Q_new, wsp_fx, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); + smc_dec = ivas_acelp_tcx20_switching_fx( st, inp_12k8_fx, *Q_new, wsp_fx, non_staX_fx, pitch_fr_fx, voicing_fr_fx, currFlatness_fx, lsp_mid_fx, stab_fac_fx, res_cod_SNR_M_fx, res_cod_SNR_M_fx_e, flag_16k_smc ); } } /* Switch to ACELP for non-harmonic transient signals */ @@ -1777,11 +1788,11 @@ ivas_error pre_proc_front_ivas_fx( } } - Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); - st->q_Bin_E = add( Q_new, Q_SCALE - 2 ); + Scale_sig32( st->Bin_E_fx, L_FFT, sub( add( *Q_new, Q_SCALE - 2 ), st->q_Bin_E ) ); + st->q_Bin_E = add( *Q_new, Q_SCALE - 2 ); move16(); /* 2nd stage speech/music classification (ACELP/GSC/TCX core selection) */ - ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, Etot_fx, attack_flag, inp_12k8_fx, Q_new, S_map_fx, flag_spitch ); + ivas_smc_mode_selection_fx( st, element_brate, smc_dec, *relE_fx, Etot_fx, attack_flag, inp_12k8_fx, *Q_new, S_map_fx, flag_spitch ); } /*----------------------------------------------------------------* @@ -1801,10 +1812,13 @@ ivas_error pre_proc_front_ivas_fx( *-----------------------------------------------------------------*/ shift = getScaleFactor16( &old_inp_12k8_fx[L_FRAME], L_INP_MEM ); Copy_Scale_sig( &old_inp_12k8_fx[L_FRAME], st->old_inp_12k8_fx, L_INP_MEM, shift ); - st->exp_old_inp_12k8 = sub( Q15, add( Q_new, shift ) ); + st->exp_old_inp_12k8 = sub( Q15, add( *Q_new, shift ) ); move16(); - Scale_sig( old_inp_12k8_fx, L_INP_12k8, negate( add( Q_new, 1 ) ) ); + // Scale_sig( old_inp_12k8_fx, L_INP_12k8, negate( add( *Q_new, 1 ) ) ); + + *Q_new = sub( *Q_new, Q_to_be_looked_into ); // ivas_core_enc will assume inp signal (12k8 and 16k) in Q_new - 1 + move16(); free( mem_decim_dummy_fx ); free( temp1F_icatdmResampBuf_fx ); diff --git a/lib_enc/ivas_cpe_enc.c b/lib_enc/ivas_cpe_enc.c index 1e57c194dcd0a44496a119baa2445fd7cab3c89a..630fcf38e43fc41e1fa549834005d23d0247153d 100644 --- a/lib_enc/ivas_cpe_enc.c +++ b/lib_enc/ivas_cpe_enc.c @@ -61,24 +61,25 @@ static void stereo_mode_combined_format_enc_fx( const Encoder_Struct *st_ivas, C * Channel Pair Element (CPE) encoding routine *-------------------------------------------------------------------*/ ivas_error ivas_cpe_enc_fx( - Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ - const Word16 cpe_id, /* i : CPE # identifier */ - Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx) */ - Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */ - Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ - const Word16 input_frame, /* i : input frame length per channel */ - const Word16 nb_bits_metadata /* i : number of metadata bits */ -) + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const Word16 cpe_id, /* i : CPE # identifier */ + Word32 data_fx_ch0[], /* i : input signal for channel 0 Q(q_data_fx) */ + Word32 data_fx_ch1[], /* i : input signal for channel 1 Q(q_data_fx) */ + Word16 q_data_fx, /* i : Q-factor of input signal for both channels */ + const Word16 input_frame, /* i : input frame length per channel */ + const Word16 nb_bits_metadata, /* i : number of metadata bits */ + Word16 Q_new_out[] ) { CPE_ENC_HANDLE hCPE; Encoder_State **sts; Word16 n, n_CoreChannels; Word32 old_inp_12k8_fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 Q16 */ - Word16 old_inp_12k8_16fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 Q-1 */ + Word16 old_inp_12k8_16fx[CPE_CHANNELS][L_INP_12k8]; /* buffer of input signal @ 12k8 Q_new-1 */ Word32 old_inp_16k_fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz Q16 */ - Word16 old_inp_16k_16fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz Q-1 */ - Word16 fft_buff_fx[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ - Word16 fft_buff_fx_q[CPE_CHANNELS]; /* FFT buffer */ + Word16 old_inp_16k_16fx[CPE_CHANNELS][L_INP]; /* buffer of input signal @ 16kHz Q_new-1 */ + Word16 Q_new[CPE_CHANNELS] = { 0 }; + Word16 fft_buff_fx[CPE_CHANNELS][2 * L_FFT]; /* FFT buffer */ + Word16 fft_buff_fx_q[CPE_CHANNELS]; /* FFT buffer */ Word16 fft_buff_fx_final_q = MAX_16; Word32 ener_fx[CPE_CHANNELS]; /* residual energy from Levinson-Durbin Q6 */ Word16 relE_fx[CPE_CHANNELS]; /* frame relative energy Q8 */ @@ -123,6 +124,8 @@ ivas_error ivas_cpe_enc_fx( Word16 last_bits_frame_nominal; /* last_bits_frame_nominal for M or PCh channel */ Word16 old_wsp_fx[CPE_CHANNELS][L_WSP]; Word16 e_old_wsp[CPE_CHANNELS], q_old_wsp; + move16(); // Q_new + move16(); // Q_new error = IVAS_ERR_OK; move32(); @@ -803,7 +806,7 @@ ivas_error ivas_cpe_enc_fx( &ener_fx[n], &relE_fx[n], A_fx[n], Aw_fx[n], epsP_fx[n], &epsP_fx_q[n], lsp_new_fx[n], lsp_mid_fx[n], &vad_hover_flag[n], &attack_flag[n], realBuffer_fx[n], imagBuffer_fx[n], &q_re_im_buf[n], old_wsp_fx[n], &q_old_wsp, pitch_fr_fx[n], voicing_fr_fx[n], &loc_harm[n], &cor_map_sum_fx[n], &vad_flag_dtx[n], enerBuffer_fx[n], &enerBuffer_fx_exp[n], fft_buff_fx[n], &fft_buff_fx_q[n], A_fx[0], lsp_new_fx[0], currFlatness_fx[n], tdm_ratio_idx, fr_bands_fx, add( Q_buffer[n], QSCALE ), Etot_LR_fx, lf_E_fx, add( Q_buffer[n], QSCALE - 2 ), localVAD_HE_SAD, - band_energies_LR_fx, sub( add( Q_buffer[n], QSCALE ), band_ener_guardbits ), 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate + band_energies_LR_fx, sub( add( Q_buffer[n], QSCALE ), band_ener_guardbits ), 0, st_ivas->hSpar != NULL ? st_ivas->hSpar->front_vad_flag : 0, 0, 0, ivas_format, st_ivas->hMCT != NULL, ivas_total_brate, &Q_new[n] #ifdef DEBUG_MODE_INFO , ( st_ivas->nSCE + ( cpe_id * CPE_CHANNELS ) + n ) @@ -1064,7 +1067,7 @@ ivas_error ivas_cpe_enc_fx( e_old_wsp[n] = 16; move16(); } - IF( NE_32( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8_16fx, old_inp_16k_16fx, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_core_enc( NULL, hCPE, st_ivas->hMCT, n_CoreChannels, old_inp_12k8_16fx, old_inp_16k_16fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, tdm_SM_or_LRTD_Pri, ivas_format, 0 ) ), IVAS_ERR_OK ) ) { return error; } @@ -1117,6 +1120,12 @@ ivas_error ivas_cpe_enc_fx( sts[n]->hTranDet->transientDetector.prev_bIsAttackPresent = sts[n]->hTranDet->transientDetector.bIsAttackPresent; } + IF( Q_new_out ) + { + Copy( Q_new, Q_new_out, CPE_CHANNELS ); + } + + #ifdef DEBUG_MODE_INFO { float tmpF = ivas_total_brate / 1000.0f; diff --git a/lib_enc/ivas_enc.c b/lib_enc/ivas_enc.c index bf9cc3c34c520d2452eccdb2d31f5fd5c9b0dff2..3979326e44c485ed93ca92f7fe6fa48a03576d08 100644 --- a/lib_enc/ivas_enc.c +++ b/lib_enc/ivas_enc.c @@ -179,7 +179,7 @@ ivas_error ivas_enc_fx( { st_ivas->hCPE[0]->element_brate = ivas_total_brate; move32(); - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, 0 /* no metadata */ ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, 0 /* no metadata */, NULL ) ), IVAS_ERR_OK ) ) { return error; } @@ -285,7 +285,7 @@ ivas_error ivas_enc_fx( } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ), IVAS_ERR_OK ) ) { return error; } @@ -342,7 +342,7 @@ ivas_error ivas_enc_fx( { norm_data_in = s_min( norm_data_in, L_norm_arr( data_fx[i], input_frame ) ); } - norm_data_in = sub( norm_data_in, 6 ); /*guard bit is 3->to handle overflow in cldfbAnalysis*/ + norm_data_in = sub( norm_data_in, 7 ); /*guard bit is 4->to handle overflow in cldfbAnalysis*/ FOR( i = 0; i < hEncoderConfig->nchan_ism + st_ivas->nchan_transport; i++ ) { scale_sig32( data_fx[i], input_frame, norm_data_in ); @@ -414,7 +414,7 @@ ivas_error ivas_enc_fx( ); /* Encode MASA transport channels */ - IF( ( ivas_cpe_enc_fx( st_ivas, 0, data_fx[n], data_fx[n + 1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK ) + IF( ( ivas_cpe_enc_fx( st_ivas, 0, data_fx[n], data_fx[n + 1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ) != IVAS_ERR_OK ) { return error; } @@ -498,7 +498,7 @@ ivas_error ivas_enc_fx( } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, nb_bits_metadata[0], NULL ) ), IVAS_ERR_OK ) ) { return error; } @@ -583,7 +583,7 @@ ivas_error ivas_enc_fx( IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ), IVAS_ERR_OK ) ) { return error; } @@ -641,7 +641,7 @@ ivas_error ivas_enc_fx( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot; - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ), IVAS_ERR_OK ) ) { return error; } @@ -657,7 +657,7 @@ ivas_error ivas_enc_fx( } ELSE IF( EQ_16( st_ivas->nCPE, 1 ) ) /* Stereo DMX */ { - IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_cpe_enc_fx( st_ivas, 0, data_fx[0], data_fx[1], st_ivas->q_data_fx, input_frame, hMetaData->nb_bits_tot, NULL ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_ism_enc.c b/lib_enc/ivas_ism_enc.c index b39a26f28bad07cea595c6fe8c04a364156660b4..1a956f4c5a583fd8297302d0977672a3b37c78e7 100644 --- a/lib_enc/ivas_ism_enc.c +++ b/lib_enc/ivas_ism_enc.c @@ -62,10 +62,11 @@ ivas_error ivas_ism_enc_fx( SCE_ENC_HANDLE hSCE; Encoder_State *st; Word16 sce_id; - Word16 old_inp_12k8_fx[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q-1 */ - Word16 old_inp_16k_fx[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 12k8 Q-1 */ - Word16 vad_flag[MAX_NUM_OBJECTS]; /* VAD flag */ - Word32 ener_fx[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin Q6 */ + Word16 old_inp_12k8_fx[MAX_NUM_OBJECTS][1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q_new-1 */ + Word16 old_inp_16k_fx[MAX_NUM_OBJECTS][1][L_INP]; /* buffer of input signal @ 12k8 Q_new-1 */ + Word16 Q_new[MAX_NUM_OBJECTS][1] = { 0 }; + Word16 vad_flag[MAX_NUM_OBJECTS]; /* VAD flag */ + Word32 ener_fx[MAX_NUM_OBJECTS][1]; /* residual energy from Levinson-Durbin Q6 */ Word16 relE_fx[MAX_NUM_OBJECTS][1]; /* frame relative energy, Q8 */ Word16 A_fx[MAX_NUM_OBJECTS][1][NB_SUBFR16k * ( M + 1 )] = { 0 }; /* A(z) unquantized for subframes */ @@ -103,6 +104,10 @@ ivas_error ivas_ism_enc_fx( Word16 i, nchan_transport_ism; Word16 q_st_inp_16; ivas_error error; + move16(); // Q_new + move16(); // Q_new + move16(); // Q_new + move16(); // Q_new push_wmops( "ivas_ism_enc" ); @@ -236,7 +241,7 @@ ivas_error ivas_ism_enc_fx( error = pre_proc_front_ivas_fx( hSCE, NULL, hSCE->element_brate, nb_bits_metadata[sce_id], input_frame, 0, old_inp_12k8_fx[sce_id][0], old_inp_16k_fx[sce_id][0], &ener_fx[sce_id][0], &relE_fx[sce_id][0], A_fx[sce_id][0], Aw_fx[sce_id][0], epsP_fx[sce_id][0], &epsP_fx_q[sce_id][0], lsp_new_fx[sce_id][0], lsp_mid_fx[sce_id][0], &vad_hover_flag[sce_id][0], &attack_flag[sce_id][0], realBuffer_fx[sce_id][0], imagBuffer_fx[sce_id][0], &q_re_im_buf[sce_id], old_wsp_fx[sce_id][0], &q_old_wsp, pitch_fr_fx[sce_id][0], voicing_fr_fx[sce_id][0], &loc_harm[sce_id][0], &cor_map_sum_fx[sce_id][0], &vad_flag_dtx[sce_id][0], enerBuffer_fx[sce_id][0], &enerBuffer_fx_exp[sce_id][0], - fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate + fft_buff_fx[sce_id][0], &fft_buff_fx_q[sce_id][0], A_fx[sce_id][0], lsp_new_fx[sce_id][0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, 0, 0, 0, 0, ISM_FORMAT, 0, st_ivas->hEncoderConfig->ivas_total_brate, &Q_new[sce_id][0] #ifdef DEBUG_MODE_INFO , st->id_element @@ -435,7 +440,7 @@ ivas_error ivas_ism_enc_fx( Scale_sig( old_wsp_fx[sce_id][0], L_WSP, sub( e_old_wsp[sce_id][0], Q16 ) ); e_old_wsp[sce_id][0] = 16; move16(); - IF( NE_32( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx[sce_id], old_inp_16k_fx[sce_id], Q_new[sce_id], ener_fx[sce_id], A_fx[sce_id], Aw_fx[sce_id], epsP_fx[sce_id], epsP_fx_q[sce_id], lsp_new_fx[sce_id], lsp_mid_fx[sce_id], vad_hover_flag[sce_id], attack_flag[sce_id], realBuffer_fx[sce_id], imagBuffer_fx[sce_id], &q_re_im_buf[sce_id], old_wsp_fx[sce_id], e_old_wsp[sce_id], loc_harm[sce_id], cor_map_sum_fx[sce_id], vad_flag_dtx[sce_id], enerBuffer_fx[sce_id], enerBuffer_fx_exp[sce_id], fft_buff_fx[sce_id], 0, ISM_FORMAT, 0 ) ), IVAS_ERR_OK ) ) { return error; } diff --git a/lib_enc/ivas_masa_enc.c b/lib_enc/ivas_masa_enc.c index c7c0777db269a2da359c6cd375031803c4f9b638..abf70944298a06a45d20d58667e4967a3ca28ba2 100644 --- a/lib_enc/ivas_masa_enc.c +++ b/lib_enc/ivas_masa_enc.c @@ -2763,7 +2763,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( /* Do 1st stage scalar quantization */ lfeToTotalEnergyRatioIndices[0] = 1; move16(); - lfeToTotalEnergyRatioIndices[1] = usquant_fx( extract_l( L_shr( log2LFEaverage, Q13 ) ), &xq, MCMASA_LFE_QLOW_Q12, MCMASA_LFE_DELTA_Q11, 8 ); + lfeToTotalEnergyRatioIndices[1] = usquant_fx( extract_l( L_shr( log2LFEaverage, Q14 ) ), &xq, MCMASA_LFE_QLOW_Q11, MCMASA_LFE_DELTA_Q10, 8 ); move16(); IF( GE_32( ivas_total_brate, IVAS_24k4 ) ) /* Vector quantization is applied if bitrate >= 24.4 kbps */ @@ -2771,7 +2771,7 @@ static Word16 encode_lfe_to_total_energy_ratio_fx( /* Remove scalar value from the vector*/ FOR( i = 0; i < MAX_PARAM_SPATIAL_SUBFRAMES; i++ ) { - log2LFEratio[i] = L_sub( log2LFEratio[i], L_shl( xq, Q13 ) ); // Q25 + log2LFEratio[i] = L_sub( log2LFEratio[i], L_shl( xq, Q14 ) ); // Q25 move32(); } diff --git a/lib_enc/ivas_mct_enc.c b/lib_enc/ivas_mct_enc.c index 510f94cf1ea88f4b481431db810af5089f4a2548..98bf7a3a5ca0ba88e91ba6f3a09c81fe1a3f8910 100644 --- a/lib_enc/ivas_mct_enc.c +++ b/lib_enc/ivas_mct_enc.c @@ -273,9 +273,10 @@ ivas_error ivas_mct_enc_fx( map_input_to_cpe_channels_ivas_fx( st_ivas, pdata_fx, data_fx ); /* pre-processing */ + Word16 Q_new_out[MCT_MAX_BLOCKS][CPE_CHANNELS]; FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ ) { - IF( ( error = ivas_cpe_enc_fx( st_ivas, cpe_id, pdata_fx[cpe_id * CPE_CHANNELS], pdata_fx[cpe_id * CPE_CHANNELS + 1], q_data_fx, input_frame, nb_bits_metadata ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_cpe_enc_fx( st_ivas, cpe_id, pdata_fx[cpe_id * CPE_CHANNELS], pdata_fx[cpe_id * CPE_CHANNELS + 1], q_data_fx, input_frame, nb_bits_metadata, Q_new_out[cpe_id] ) ) != IVAS_ERR_OK ) { return error; } @@ -523,7 +524,7 @@ ivas_error ivas_mct_enc_fx( } #endif - updt_enc_common_ivas_fx( st ); + updt_enc_common_ivas_fx( st, Q_new_out[cpe_id][n] ); #ifdef IVAS_FLOAT_FIXED_CONVERSIONS IF( st->hTcxEnc != NULL ) diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index 881d480cbfc7057e79f32c050b4bb9176bd4ef40..52c899f08009118c9ce9eb584683339d96dde98b 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -90,21 +90,23 @@ ivas_error ivas_sce_enc_fx( Word32 fr_bands_fx[1][2 * NB_BANDS]; /* energy in frequency bands */ Word32 lf_E_fx[1][2 * VOIC_BINS]; /* per bin spectrum energy in lf */ - Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q-1 */ - Word16 old_inp_16k_fx[1][L_INP]; /* buffer of input signal @ 12k8 Q-1 */ - Word16 vad_hover_flag[1]; /* VAD hangover flag */ - Word16 attack_flag[1]; /* attack flag (GSC or TC) */ - Word16 loc_harm[1]; /* harmonicity flag */ - Word16 vad_flag_dtx[1]; /* HE-SAD flag with additional DTX HO */ - Word16 fft_buff_fx[1][2 * L_FFT]; /* FFT buffer */ - Word16 fft_buff_fx_q[1]; /* FFT buffer */ - Word16 localVAD_HE_SAD[1]; /* local HE SAD */ + Word16 old_inp_12k8_fx[1][L_INP_12k8]; /* buffer of input signal @ 12k8 Q_new-1 */ + Word16 old_inp_16k_fx[1][L_INP]; /* buffer of input signal @ 12k8 Q_new-1 */ + Word16 Q_new[1] = { 0 }; + Word16 vad_hover_flag[1]; /* VAD hangover flag */ + Word16 attack_flag[1]; /* attack flag (GSC or TC) */ + Word16 loc_harm[1]; /* harmonicity flag */ + Word16 vad_flag_dtx[1]; /* HE-SAD flag with additional DTX HO */ + Word16 fft_buff_fx[1][2 * L_FFT]; /* FFT buffer */ + Word16 fft_buff_fx_q[1]; /* FFT buffer */ + Word16 localVAD_HE_SAD[1]; /* local HE SAD */ SCE_ENC_HANDLE hSCE; Encoder_State *st; IVAS_FORMAT ivas_format; ivas_error error; Word16 flag_16k_smc; Word16 q_input; /*stores q for input_fx*/ + move16(); // Q_new push_wmops( "ivas_sce_enc" ); @@ -251,7 +253,7 @@ ivas_error ivas_sce_enc_fx( &ener_fx[0], &relE_fx[0], A_fx[0], Aw_fx[0], epsP_fx[0], &epsP_fx_q[0], lsp_new_fx[0], lsp_mid_fx[0], &vad_hover_flag[0], &attack_flag[0], realBuffer_fx[0], imagBuffer_fx[0], &q_re_im_buf, old_wsp_fx[0], &q_old_wsp, pitch_fr_fx[0], voicing_fr_fx[0], &loc_harm[0], &cor_map_sum_fx[0], &vad_flag_dtx[0], enerBuffer_fx[0], &enerBuffer_fx_exp[0], fft_buff_fx[0], &fft_buff_fx_q[0], A_fx[0], lsp_new_fx[0], currFlatness_fx[0], 0, fr_bands_fx, 31, Etot_LR_fx, lf_E_fx, 31, localVAD_HE_SAD, NULL, 31, flag_16k_smc, - 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 + 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, &Q_new[0] #ifdef DEBUG_MODE_INFO , st->id_element @@ -349,7 +351,7 @@ ivas_error ivas_sce_enc_fx( Scale_sig( old_wsp_fx[0], L_WSP, sub( e_old_wsp[0], Q16 ) ); e_old_wsp[0] = 16; move16(); - IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) + IF( ( error = ivas_core_enc( hSCE, NULL, NULL, 1, old_inp_12k8_fx, old_inp_16k_fx, Q_new, ener_fx, A_fx, Aw_fx, epsP_fx, epsP_fx_q, lsp_new_fx, lsp_mid_fx, vad_hover_flag, attack_flag, realBuffer_fx, imagBuffer_fx, &q_re_im_buf, old_wsp_fx, e_old_wsp, loc_harm, cor_map_sum_fx, vad_flag_dtx, enerBuffer_fx, enerBuffer_fx_exp, fft_buff_fx, 0, ivas_format, flag_16k_smc ) ) != IVAS_ERR_OK ) { return error; } diff --git a/lib_enc/updt_enc.c b/lib_enc/updt_enc.c index 6433b6bc54aac484cbf49a5dfb26178c088898f1..cb36dd4b04c94cce04cb194654b8bf337ab9c5cd 100644 --- a/lib_enc/updt_enc.c +++ b/lib_enc/updt_enc.c @@ -52,7 +52,8 @@ void updt_enc_common_ivas_fx( - Encoder_State *st /* i/o: encoder state structure */ + Encoder_State *st, /* i/o: encoder state structure */ + const Word16 Q_new /* i : CUrrent frame scaling */ ) { /*---------------------------------------------------------------------* @@ -81,6 +82,8 @@ void updt_enc_common_ivas_fx( move16(); st->last_coder_type_raw = st->coder_type_raw; move16(); + st->prev_Q_new = Q_new; + move16(); test(); IF( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL )