From 15e3c6d566afd9d47d9bd178f31faa82ad19780d Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 19:58:47 +0100 Subject: [PATCH 01/11] [cleanup] accept HARM_HQ_CORE --- lib_com/fill_spectrum_fx.c | 273 ---- lib_com/fine_gain_bits_fx.c | 93 -- lib_com/hq_bit_allocation_fx.c | 221 --- lib_com/hq_conf_fx.c | 525 ------- lib_com/hq_tools_fx.c | 311 ---- lib_com/interleave_spectrum_fx.c | 185 --- lib_com/ivas_prot_fx.h | 182 --- lib_com/low_rate_band_att_fx.c | 128 -- lib_com/options.h | 1 - lib_com/prot_fx.h | 125 -- lib_com/rom_com.h | 6 - lib_com/rom_com_fx.c | 16 - lib_com/swb_bwe_com_fx.c | 555 -------- lib_dec/FEC_HQ_phase_ecu_fx.c | 2271 +++--------------------------- lib_dec/evs_dec_fx.c | 4 - lib_dec/hq_classifier_dec_fx.c | 76 - lib_dec/hq_core_dec_fx.c | 505 ------- lib_dec/hq_hr_dec_fx.c | 365 ----- lib_dec/ivas_core_dec_fx.c | 4 - lib_dec/peak_vq_dec_fx.c | 5 - lib_dec/pvq_core_dec_fx.c | 95 -- lib_enc/gs_enc_fx.c | 9 - lib_enc/hq_classifier_enc_fx.c | 678 --------- lib_enc/hq_core_enc_fx.c | 237 ---- lib_enc/hq_env_enc_fx.c | 536 ------- lib_enc/hq_hr_enc_fx.c | 285 ---- lib_enc/hvq_enc_fx.c | 185 --- lib_enc/ivas_core_enc_fx.c | 4 - lib_enc/peak_vq_enc_fx.c | 920 ++---------- lib_enc/prot_fx_enc.h | 171 --- lib_enc/pvq_core_enc_fx.c | 776 +--------- lib_enc/pvq_encode_fx.c | 206 --- lib_enc/swb_bwe_enc_fx.c | 225 --- 33 files changed, 374 insertions(+), 9804 deletions(-) diff --git a/lib_com/fill_spectrum_fx.c b/lib_com/fill_spectrum_fx.c index 7353485a6..8dcb7150d 100644 --- a/lib_com/fill_spectrum_fx.c +++ b/lib_com/fill_spectrum_fx.c @@ -43,7 +43,6 @@ #include "ivas_prot_fx.h" -#ifdef HARM_HQ_CORE /*--------------------------------------------------------------------------* * fill_spectrum() * @@ -53,9 +52,6 @@ *--------------------------------------------------------------------------*/ void fill_spectrum_fx( -#else -void ivas_fill_spectrum_fx( -#endif Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ const Word16 *R, /* i : number of pulses per band Q0 */ @@ -265,11 +261,7 @@ void ivas_fill_spectrum_fx( test(); IF( EQ_16( HQ_mode, HQ_HARMONIC ) ) { -#ifdef HARM_HQ_CORE harm_bwe_fx( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out, element_mode ); -#else - ivas_harm_bwe_fx( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out, element_mode ); -#endif } ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) ) { @@ -278,11 +270,7 @@ void ivas_fill_spectrum_fx( } ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) { -#ifdef HARM_HQ_CORE hq_bwe_fx( element_mode, HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R ); -#else - hq_bwe_ivas_fx( HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R ); -#endif } /*----------------------------------------------------------------* @@ -325,264 +313,3 @@ void ivas_fill_spectrum_fx( return; } -#ifndef HARM_HQ_CORE -void fill_spectrum_fx( - Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ - Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ - const Word16 *R, /* i : number of pulses per band Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - Word16 norm[], /* i : quantization indices for norms Q0 */ - const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ - const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ - const Word16 nf_idx, /* i : noise fill index Q0 */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ - const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0 */ - const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ - const Word16 core_sfm, /* i : index of the end band for core Q0 */ - const Word16 HQ_mode, /* i : HQ mode Q0 */ - Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ - const Word32 L_core_brate, /* i : target bit-rate Q0 */ - Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ - Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ - const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ - const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ - const Word16 *npulses, /* i : number of pulses per band Q0 */ - const Word16 prev_is_transient, /* i : previous transient flag Q0 */ - Word32 *prev_normq, /* i/o: previous norms Q14 */ - Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ - const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ - const Word16 *sfmsize, /* i : Length of bands Q0 */ - const Word16 *sfm_start, /* i : Start of bands Q0 */ - const Word16 *sfm_end, /* i : End of bands Q0 */ - Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ - const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ - const Word16 num_sfm, /* i : Total number of bands Q0 */ - Word16 *prev_env_Q, - const Word16 num_env_bands, /* i : Number sub bands to be encoded for HQ_GEN Q0 */ - const Word16 element_mode /* i : IVAS element mode */ -) -{ - Word16 CodeBook[FREQ_LENGTH]; /* Q12 */ - Word16 cb_size; - Word16 last_sfm; - Word16 CodeBook_mod[FREQ_LENGTH]; /*Q12 */ - Word16 norm_adj[NB_SFM]; /*Q15 */ - Word16 high_sfm; - Word16 flag_32K_env_hangover; - Word16 bin_th; - Word16 peak_pos[L_HARMONIC_EXC]; - Word16 bwe_peaks[L_FRAME48k]; - Word32 L_normq_v[NB_SFM]; /*Q14 */ - Word16 coeff_fine[L_SPEC48k_EXT]; /*Q15 */ - Word32 L_coeff_out1[L_SPEC48k_EXT]; /*Q12 */ - set16_fx( peak_pos, 0, L_HARMONIC_EXC ); - set16_fx( bwe_peaks, 0, L_FRAME48k ); - set16_fx( norm_adj, 32767, num_sfm ); /* 1.0, Q15 */ - cb_size = 0; - move16(); - bin_th = 0; - move16(); - high_sfm = 23; - move16(); - - test(); - IF( EQ_16( HQ_mode, HQ_TRANSIENT ) ) - { - last_sfm = sub( num_sfm, 1 ); - } - ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) - { - last_sfm = s_max( core_sfm, sub( num_env_bands, 1 ) ); - } - ELSE - { - last_sfm = core_sfm; - move16(); - } - - IF( EQ_16( HQ_mode, HQ_HARMONIC ) ) - { - /*high_sfm = (core_brate == HQ_BWE_CROSSOVER_BRATE) ? HVQ_THRES_SFM_24k-1 : HVQ_THRES_SFM_32k-3; */ - high_sfm = sub( HVQ_THRES_SFM_32k, 1 ); - if ( LT_32( L_core_brate, HQ_BWE_CROSSOVER_BRATE ) ) - { - high_sfm = sub( HVQ_THRES_SFM_24k, 1 ); - } - - if ( LT_16( last_sfm, high_sfm ) ) - { - last_sfm = high_sfm; - move16(); - } - } - ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) ) - { - bin_th = sfm_end[last_sfm]; - move16(); - } - - /* Transient analysis for envelope stability measure */ - IF( EQ_16( length, L_FRAME32k ) ) - { - env_stab_transient_detect_fx( is_transient, length, norm, no_att_hangover, L_energy_lt, HQ_mode, bin_th, L_coeff_out, 12 ); - } - - test(); - test(); - test(); - test(); - IF( EQ_16( length, L_FRAME16k ) || - ( ( EQ_16( length, L_FRAME32k ) && NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) ) && *no_att_hangover == 0 ) ) - { - /* Norm adjustment function */ - env_adj_fx( npulses, length, last_sfm, norm_adj, env_stab, sfmsize ); - } - - /*flag_32K_env_hangover = ( length == L_FRAME32k && ( (env_stab < 0.5f && *no_att_hangover == 0) || HQ_mode == HQ_HVQ ) ); */ - flag_32K_env_hangover = 0; - move16(); - test(); - test(); - test(); - if ( EQ_16( length, L_FRAME32k ) && ( ( LT_16( env_stab, 16384 /*0.5.Q15*/ ) && *no_att_hangover == 0 ) || EQ_16( HQ_mode, HQ_HVQ ) ) ) - { - flag_32K_env_hangover = 1; - move16(); - } - - - /*----------------------------------------------------------------* - * Build noise-fill codebook - *----------------------------------------------------------------*/ - - IF( NE_16( HQ_mode, HQ_HVQ ) ) - { - cb_size = build_nf_codebook_fx( flag_32K_env_hangover, coeff, sfm_start, sfmsize, sfm_end, last_sfm, R, CodeBook, CodeBook_mod ); - } - /*----------------------------------------------------------------* - * Prepare fine structure for Harmonic and HVQ - *----------------------------------------------------------------*/ - - IF( EQ_16( HQ_mode, HQ_HARMONIC ) ) - { - harm_bwe_fine_fx( R, last_sfm, high_sfm, num_sfm, norm, sfm_start, sfm_end, prev_L_swb_norm, coeff, L_coeff_out, coeff_fine ); - } - ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) ) - { - hvq_bwe_fine_fx( last_sfm, num_sfm, sfm_end, peak_idx, Npeaks, peak_pos, prev_L_swb_norm, L_coeff_out, bwe_peaks, coeff_fine ); - } - - /*----------------------------------------------------------------* - * Apply noise-fill - *----------------------------------------------------------------*/ - - test(); - IF( NE_16( HQ_mode, HQ_HVQ ) && cb_size > 0 ) - { - apply_noisefill_HQ_fx( R, length, flag_32K_env_hangover, L_core_brate, last_sfm, CodeBook, - CodeBook_mod, cb_size, sfm_start, sfm_end, sfmsize, coeff ); - } - - /*----------------------------------------------------------------* - * Normal mode BWE - *----------------------------------------------------------------*/ - - IF( HQ_mode == HQ_NORMAL ) - { - hq_fold_bwe_fx( last_sfm, sfm_end, num_sfm, coeff ); - } - - /*----------------------------------------------------------------* - * Apply noise-fill adjustment - *----------------------------------------------------------------*/ - - test(); - test(); - test(); - IF( ( GE_16( length, L_FRAME32k ) || GT_32( L_core_brate, HQ_32k ) || LT_32( L_core_brate, HQ_24k40 ) ) && NE_16( HQ_mode, HQ_HVQ ) ) - { - apply_nf_gain_fx( nf_idx, last_sfm, R, sfm_start, sfm_end, coeff ); - } - - /*----------------------------------------------------------------* - * Prepare fine strucutre for HQ GENERIC - *----------------------------------------------------------------*/ - test(); - IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) - { - hq_generic_fine_fx( coeff, last_sfm, sfm_start, sfm_end, bwe_seed, coeff_fine ); - } - - /*----------------------------------------------------------------* - * Apply envelope - *----------------------------------------------------------------*/ - - test(); - IF( NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) ) - { - apply_envelope_fx( coeff, norm, norm_adj, num_sfm, last_sfm, HQ_mode, length, sfm_start, sfm_end, - L_normq_v, L_coeff_out, coeff_fine, L_coeff_out1 ); - } - - /*----------------------------------------------------------------* - * Harmonic BWE, HVQ BWE and HQ SWB BWE - *----------------------------------------------------------------*/ - test(); - IF( EQ_16( HQ_mode, HQ_HARMONIC ) ) - { - harm_bwe_fx( coeff_fine, coeff, num_sfm, sfm_start, sfm_end, last_sfm, R, prev_hq_mode, norm, noise_level, prev_noise_level, bwe_seed, L_coeff_out, element_mode ); - } - ELSE IF( EQ_16( HQ_mode, HQ_HVQ ) ) - { - hvq_bwe_fx( L_coeff_out, coeff_fine, sfm_start, sfm_end, sfmsize, last_sfm, prev_hq_mode, bwe_peaks, bin_th, num_sfm, L_core_brate, R, norm, - noise_level, prev_noise_level, bwe_seed, L_coeff_out, 15, 12 ); - } - ELSE IF( EQ_16( HQ_mode, HQ_GEN_SWB ) || EQ_16( HQ_mode, HQ_GEN_FB ) ) - { - hq_bwe_fx( HQ_mode, L_coeff_out1, hq_generic_fenv, L_coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, sfm_end, num_sfm, num_env_bands, R ); - } - - /*----------------------------------------------------------------* - * HQ WB BWE refinements - *----------------------------------------------------------------*/ - test(); - IF( EQ_16( length, L_FRAME16k ) && LE_32( L_core_brate, HQ_32k ) ) - { - hq_wb_nf_bwe_fx( coeff, is_transient, prev_bfi, L_normq_v, num_sfm, sfm_start, sfm_end, sfmsize, last_sfm, R, - prev_is_transient, prev_normq, prev_env, bwe_seed, prev_coeff_out, prev_R, L_coeff_out, prev_env_Q ); - } - - /*----------------------------------------------------------------* - * Update memories - *----------------------------------------------------------------*/ - - test(); - IF( NE_16( HQ_mode, HQ_HARMONIC ) && NE_16( HQ_mode, HQ_HVQ ) ) - { - prev_noise_level[0] = 3277; - move16(); /* 0.1 in Q15 */ - prev_noise_level[1] = 3277; - move16(); /* 0.1 in Q15 */ - } - test(); - IF( !( EQ_16( length, L_FRAME16k ) && LE_32( L_core_brate, HQ_32k ) ) ) - { - set32_fx( prev_env, 0, SFM_N_WB ); - set32_fx( prev_normq, 0, SFM_N_WB ); - } - - test(); - IF( EQ_16( length, L_FRAME32k ) && LE_32( L_core_brate, HQ_32k ) ) - { - *prev_R = R[SFM_N_WB - 1]; - move16(); - Copy32( L_coeff_out + L_FRAME16k - L_HQ_WB_BWE, prev_coeff_out, L_HQ_WB_BWE ); - } - - return; -} -#endif diff --git a/lib_com/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index d982b94e2..1d4ad2a7d 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -16,9 +16,7 @@ *--------------------------------------------------------------------------*/ static void subband_gain_bits_fx( -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif const Word16 *Rk, /* i : bit allocation per band Q3 */ const Word16 N, /* i : number of bands */ Word16 *bits, /* o : gain bits per band */ @@ -34,13 +32,11 @@ static void subband_gain_bits_fx( FOR( i = 0; i < N; i++ ) { /*bps = (short)(Rk[i]*((word16)min(32767, ceil(32767.0f/sfmsize[i]); inexact C-integer division approx. */ -#ifdef HARM_HQ_CORE if ( element_mode > EVS_MONO ) { bps = extract_l( L_shr( L_mult0( Rk[i], fg_inv_tbl_fx[sfmsize[i] >> 3] ), 18 ) ); /* 3+15 */ } ELSE -#endif { bps = extract_l( L_shr( L_mult0( Rk[i], inv_tbl_fx[sfmsize[i]] ), 18 ) ); /* 3+15 */ } @@ -76,9 +72,7 @@ static void subband_gain_bits_fx( /* o : Number of assigned gain bits */ Word16 assign_gain_bits_fx( -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif const Word16 core, /* i : HQ core */ const Word16 BANDS, /* i : Number of bands */ const Word16 *band_width, /* i : Sub band bandwidth */ @@ -93,11 +87,7 @@ Word16 assign_gain_bits_fx( /* Allocate gain bits for every subband used, based on bit rate and bandwidth */ IF( EQ_16( core, HQ_CORE ) ) { -#ifdef HARM_HQ_CORE subband_gain_bits_fx( element_mode, Rk, BANDS, gain_bits_array, band_width ); -#else - subband_gain_bits_fx( Rk, BANDS, gain_bits_array, band_width ); -#endif } ELSE { @@ -123,86 +113,3 @@ Word16 assign_gain_bits_fx( return gain_bits_tot; } -#ifndef HARM_HQ_CORE -static void ivas_subband_gain_bits_fx( - const Word16 *Rk, /* i : bit allocation per band Q3 */ - const Word16 N, /* i : number of bands */ - Word16 *bits, /* o : gain bits per band */ - const Word16 *sfmsize /* i : Size of bands */ -) -{ - Word16 i, b, tot; - Word16 bps; - - tot = 0; - move16(); - - FOR( i = 0; i < N; i++ ) - { - /*bps = (short)(Rk[i]*((word16)min(32767, ceil(32767.0f/sfmsize[i]); inexact C-integer division approx. */ - bps = extract_l( L_shr( L_mult0( Rk[i], fg_inv_tbl_fx[sfmsize[i] >> 3] ), 18 ) ); /* 3+15 */ - if ( EQ_32( L_shl( L_mult0( sfmsize[i], add( bps, 1 ) ), 3 ), Rk[i] ) ) - { - bps = add( bps, 1 ); - } - - bps = s_min( 7, bps ); - b = fine_gain_bits[bps]; - move16(); - bits[i] = b; - move16(); - tot = add( tot, b ); - } - - if ( tot == 0 ) - { - /* If no gain bits were assigned, use one bit anyway for potential PVQ overage */ - bits[0] = 1; - move16(); - } - - return; -} - -Word16 ivas_assign_gain_bits_fx( /* o : Number of assigned gain bits */ - const Word16 core, /* i : HQ core */ - const Word16 BANDS, /* i : Number of bands */ - const Word16 *band_width, /* i : Sub band bandwidth */ - Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *gain_bits_array, /* o : Assigned gain bits */ - Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ -) -{ - Word16 gain_bits_tot; - Word16 i; - - /* Allocate gain bits for every subband used, based on bit rate and bandwidth */ - IF( EQ_16( core, HQ_CORE ) ) - { - ivas_subband_gain_bits_fx( Rk, BANDS, gain_bits_array, band_width ); - } - ELSE - { - set16_fx( gain_bits_array, 0, BANDS ); - } - - /* Re-adjust bit budget for gain quantization */ - gain_bits_tot = 0; - move16(); - *Rcalc = 0; - move16(); - FOR( i = 0; i < BANDS; i++ ) - { - IF( Rk[i] > 0 ) - { - Rk[i] = sub( Rk[i], shl( gain_bits_array[i], 3 ) ); - move16(); - gain_bits_tot = add( gain_bits_tot, gain_bits_array[i] ); - *Rcalc = add( *Rcalc, Rk[i] ); - move16(); - } - } - - return gain_bits_tot; -} -#endif diff --git a/lib_com/hq_bit_allocation_fx.c b/lib_com/hq_bit_allocation_fx.c index 29d281cfd..1ba994e95 100644 --- a/lib_com/hq_bit_allocation_fx.c +++ b/lib_com/hq_bit_allocation_fx.c @@ -14,11 +14,7 @@ * Assign bits for HQ fine structure coding with PVQ *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE void hq_bit_allocation_fx( -#else -void ivas_hq_bit_allocation_fx( -#endif const Word32 core_brate, /* i : Core bit-rate Q0 */ const Word16 length, /* i : Frame length Q0 */ const Word16 hqswb_clas, /* i : HQ class Q0 */ @@ -231,220 +227,3 @@ void ivas_hq_bit_allocation_fx( return; } -#ifndef HARM_HQ_CORE - -void hq_bit_allocation_fx( - const Word32 core_brate, /* i : Core bit-rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ class Q0 */ - Word16 *num_bits, /* i/o: Remaining bit budget Q0 */ - const Word16 *normqlg2, /* i : Quantized norms Q0 */ - const Word16 nb_sfm, /* i : Number sub bands to be encoded Q0 */ - const Word16 *sfmsize, /* i : Sub band bandwidths Q0 */ - Word16 *noise_level, /* o : HVQ noise level Q15 */ - Word16 *R, /* o : Bit allocation per sub band Q0 */ - Word16 *Rsubband, /* o : Fractional bit allocation Q3 */ - Word16 *sum, /* o : Sum of allocated shape bits Q0 */ - Word16 *core_sfm, /* o : Last coded band in core Q0 */ - const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_GEN Q0 */ -) -{ - Word16 i; - Word16 idx[NB_SFM]; - Word16 wnorm[NB_SFM]; - Word16 avrg_wnorm; - Word16 tmp, tmp2; - Word16 E_low; - Word16 E_hb_mean; - Word16 E_max; - Word16 i_max; - /* Temp */ - - Word16 sfm_limit = nb_sfm; - move16(); - - set16_fx( R, 0, NB_SFM ); - FOR( i = 0; i < nb_sfm; i++ ) - { - idx[i] = i; - move16(); - } - test(); - test(); - test(); - if ( NE_16( hqswb_clas, HQ_TRANSIENT ) && NE_16( hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && EQ_32( core_brate, HQ_32k ) ) ) - { - /* 'nf_idx' 2-bits index written later */ - *num_bits = sub( *num_bits, 2 ); - } - - test(); - IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) - { - IF( EQ_32( core_brate, HQ_32k ) ) - { - *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS2 ); - move16(); - } - ELSE - { - *num_bits = sub( *num_bits, HQ_GENERIC_SWB_NBITS ); - move16(); - } - - if ( EQ_16( hqswb_clas, HQ_GEN_FB ) ) - { - *num_bits = sub( *num_bits, HQ_GENERIC_FB_NBITS ); - move16(); - } - } - - test(); - test(); - IF( ( EQ_16( length, L_FRAME48k ) ) && ( NE_16( hqswb_clas, HQ_HARMONIC ) ) && ( NE_16( hqswb_clas, HQ_HVQ ) ) ) - { - tmp = 0; - move16(); - if ( EQ_16( hqswb_clas, HQ_TRANSIENT ) ) - { - tmp = 1; - move16(); - } - map_quant_weight_fx( normqlg2, wnorm, tmp ); - } - ELSE - { - Copy( normqlg2, wnorm, nb_sfm ); - } - - IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - /* classification and limit bandwidth for bit allocation */ - sfm_limit = sub( sfm_limit, 2 ); - limit_band_noise_level_calc_fx( wnorm, &sfm_limit, core_brate, noise_level ); - - /* Detect important band in high frequency region */ - E_low = sum16_fx( wnorm, SFM_G1 ); - i_max = 0; - move16(); - E_max = MIN16B; - move16(); - E_hb_mean = 0; - move16(); - FOR( i = SFM_G1; i < nb_sfm; i++ ) - { - E_hb_mean = add( E_hb_mean, wnorm[i] ); - IF( GT_16( wnorm[i], E_max ) ) - { - E_max = wnorm[i]; - move16(); - i_max = i; - move16(); - } - } - E_hb_mean = shr( E_hb_mean, 4 ); /* Truncated division by SFM_G1 */ - set16_fx( wnorm + sfm_limit, -20, sub( nb_sfm, sfm_limit ) ); - IF( L_msu0( L_deposit_l( E_low ), E_max, 15 ) <= 0 ) - { - IF( L_msu( L_deposit_h( E_hb_mean ), E_max, 21955 ) <= 0 ) /* 21955 = 0.67 (Q15) */ - { - if ( GE_16( i_max, sfm_limit ) ) - { - wnorm[i_max] = E_max; - move16(); - } - } - } - } - test(); - test(); - test(); - test(); - IF( EQ_16( hqswb_clas, HQ_HVQ ) ) - { - *sum = 0; - move16(); - } - ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || ( EQ_16( hqswb_clas, HQ_TRANSIENT ) && EQ_16( length, L_FRAME32k ) && LE_32( core_brate, HQ_32k ) ) ) - { - *sum = BitAllocF_fx( wnorm, core_brate, *num_bits, nb_sfm, R, Rsubband, hqswb_clas, num_env_bands ); - move16(); - } - ELSE IF( EQ_16( length, L_FRAME16k ) && EQ_32( core_brate, HQ_32k ) ) - { - IF( NE_16( hqswb_clas, HQ_TRANSIENT ) ) - { - avrg_wnorm = wnorm[10]; - move16(); - FOR( i = 11; i < 18; i++ ) - { - avrg_wnorm = add( avrg_wnorm, wnorm[i] ); - } - - avrg_wnorm = shr( avrg_wnorm, 3 ); - FOR( i = 0; i < 4; i++ ) - { - if ( LT_16( wnorm[i], avrg_wnorm ) ) - { - wnorm[i] = avrg_wnorm; - move16(); - } - } - - /* Estimate number of bits per band */ - *sum = BitAllocWB_fx( wnorm, *num_bits, nb_sfm, R, Rsubband ); - move16(); - } - ELSE - { - reordvct_fx( wnorm, nb_sfm, idx ); - bitalloc_fx( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas ); - bitallocsum_fx( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize ); - } - } - ELSE - { - reordvct_fx( wnorm, nb_sfm, idx ); - - /* enlarge the wnorm value so that more bits can be allocated to (sfm_limit/2 ~ sfm_limit) range */ - IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - tmp = shr( sfm_limit, 1 ); - tmp2 = sub( tmp, 1 ); - FOR( i = tmp; i < sfm_limit; i++ ) - { - wnorm[i] = wnorm[tmp2]; - move16(); - } - } - bitalloc_fx( wnorm, idx, *num_bits, nb_sfm, QBIT_MAX2, R, sfmsize, hqswb_clas ); - bitallocsum_fx( R, nb_sfm, sum, Rsubband, *num_bits, length, sfmsize ); - } - - /* Find last coded core band */ - *core_sfm = sub( nb_sfm, 1 ); - move16(); - test(); - test(); - IF( hqswb_clas == HQ_NORMAL || EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - *core_sfm = find_last_band_fx( R, nb_sfm ); - move16(); - } - ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) - { - *core_sfm = find_last_band_fx( R, nb_sfm ); - move16(); - IF( LT_16( *core_sfm, num_env_bands ) ) - { - *core_sfm = sub( num_env_bands, 1 ); - move16(); - } - } - - *num_bits = sub( *num_bits, *sum ); - move16(); - - return; -} -#endif diff --git a/lib_com/hq_conf_fx.c b/lib_com/hq_conf_fx.c index 9450e6314..5583e231e 100644 --- a/lib_com/hq_conf_fx.c +++ b/lib_com/hq_conf_fx.c @@ -15,531 +15,6 @@ * * Configuration routine for HQ mode *--------------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE -void ivas_hq_configure_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ - Word16 *num_sfm, /* o : Total number of subbands Q0 */ - Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ - Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ - Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ - Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ - Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 *sfmsize, /* o : Subband bandwidths Q0 */ - Word16 *sfm_start, /* o : Subband start coefficients Q0 */ - Word16 *sfm_end /* o : Subband end coefficients Q0 */ -) -{ - const Word16 *p_sfmsize; - const Word16 *p_sfm_start; - const Word16 *p_sfm_end; - Word16 i, bw_ext; - - bw_ext = 0; - move16(); - - *start_norm = 0; - move16(); - - IF( EQ_16( length, L_SPEC48k ) ) - { - IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) - { - *num_sfm = NB_SFM; - move16(); - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - - IF( GE_32( core_brate, HQ_32k ) ) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; - move16(); - *num_env_bands = SFM_N_STA_10k; - move16(); - } - ELSE /*IF(EQ_32(core_brate, HQ_16k40) || EQ_32(core_brate, HQ_24k40))*/ - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; - move16(); - *num_env_bands = SFM_N_STA_8k; - move16(); - } - *nb_sfm = *num_sfm; - move16(); - } - ELSE - { - IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - *num_sfm = SFM_N_HARM_FB; - move16(); - *nb_sfm = SFM_N_HARM_FB; - move16(); - *num_env_bands = SFM_N_HARM_FB; - move16(); - - p_sfmsize = band_len_harm; /* Q0 */ - p_sfm_start = band_start_harm; /* Q0 */ - p_sfm_end = band_end_harm; /* Q0 */ - } - ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) - { - IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) - { - *num_sfm = SFM_N_HARM_FB; - move16(); - *nb_sfm = HVQ_THRES_SFM_24k; - move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ - move16(); - *start_norm = HVQ_THRES_SFM_24k; - move16(); - } - ELSE - { - *num_sfm = SFM_N_HARM_FB; - move16(); - *nb_sfm = HVQ_THRES_SFM_32k; - move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ - move16(); - *start_norm = HVQ_THRES_SFM_32k; - move16(); - } - p_sfmsize = band_len_harm; /* Q0 */ - p_sfm_start = band_start_harm; /* Q0 */ - p_sfm_end = band_end_harm; /* Q0 */ - } - ELSE - { - *num_sfm = NB_SFM; - move16(); - *nb_sfm = *num_sfm; /* Q0 */ - move16(); - *num_env_bands = NB_SFM; - move16(); - - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - } - } - } - ELSE IF( EQ_16( length, L_SPEC32k ) ) - { - IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - *num_sfm = SFM_N_HARM; - move16(); - *nb_sfm = SFM_N_HARM; - move16(); - *num_env_bands = SFM_N_HARM; - move16(); - - p_sfmsize = band_len_harm; /* Q0 */ - p_sfm_start = band_start_harm; /* Q0 */ - p_sfm_end = band_end_harm; /* Q0 */ - } - ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) - { - IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) - { - *num_sfm = SFM_N_HARM; - move16(); - *nb_sfm = HVQ_THRES_SFM_24k; - move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ - move16(); - - *start_norm = HVQ_THRES_SFM_24k; - move16(); - } - ELSE - { - *num_sfm = SFM_N_HARM; - move16(); - *nb_sfm = HVQ_THRES_SFM_32k; - move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ - move16(); - - *start_norm = HVQ_THRES_SFM_32k; - move16(); - } - p_sfmsize = band_len_harm; - p_sfm_start = band_start_harm; - p_sfm_end = band_end_harm; - } - ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) ) - { - *num_sfm = SFM_N_SWB; - move16(); - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - - IF( GE_32( core_brate, HQ_32k ) ) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; - move16(); - *num_env_bands = SFM_N_STA_10k; - move16(); - } - ELSE /*if( EQ_32(core_brate, HQ_24k40))*/ - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; - move16(); - *num_env_bands = SFM_N_STA_8k; - move16(); - } - - *nb_sfm = *num_sfm; - move16(); - } - ELSE - { - /* HQ_NORMAL and HQ_TRANSIENT */ - *num_sfm = SFM_N_SWB; - move16(); - *nb_sfm = *num_sfm; /* Q0 */ - move16(); - *num_env_bands = SFM_N_SWB; - move16(); - - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - } - } - ELSE IF( EQ_16( length, L_SPEC48k_EXT ) ) - { - bw_ext = 1; - move16(); - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - *num_sfm = NB_SFM; - move16(); - } - ELSE IF( EQ_16( length, L_SPEC16k_EXT ) ) - { - bw_ext = 1; - move16(); - p_sfmsize = band_len_wb; /* Q0 */ - p_sfm_start = band_start_wb; /* Q0 */ - p_sfm_end = band_end_wb; /* Q0 */ - *num_sfm = SFM_N_WB; - move16(); - } - ELSE - { - *num_sfm = SFM_N_WB; - move16(); - *nb_sfm = *num_sfm; /* Q0 */ - move16(); - *num_env_bands = SFM_N_WB; - move16(); - - p_sfmsize = band_len_wb; /* Q0 */ - p_sfm_start = band_start_wb; /* Q0 */ - p_sfm_end = band_end_wb; /* Q0 */ - } - IF( bw_ext ) - { - FOR( i = 0; i < *num_sfm; i++ ) - { - /*sfmsize[i] = (int16_t)(1.25f * p_sfmsize[i]);*/ - sfmsize[i] = mult_r( shl( p_sfmsize[i], 1 ), 20480 /* 1.25 in Q14 */ ); /* Q0 */ - move16(); - /*sfm_start[i] = (int16_t)(1.25f * p_sfm_start[i]);*/ - sfm_start[i] = mult_r( shl( p_sfm_start[i], 1 ), 20480 /* 1.25 in Q14 */ ); /* Q0 */ - move16(); - /*sfm_end[i] = (int16_t)(1.25f * p_sfm_end[i]);*/ - sfm_end[i] = mult_r( shl( p_sfm_end[i], 1 ), 20480 /* 1.25 in Q14 */ ); /* Q0 */ - move16(); - } - *nb_sfm = *num_sfm; /* Q0 */ - *num_env_bands = *num_sfm; /* Q0 */ - move16(); - move16(); - } - ELSE - { - Copy( p_sfmsize, sfmsize, *num_sfm ); - Copy( p_sfm_start, sfm_start, *num_sfm ); - Copy( p_sfm_end, sfm_end, *num_sfm ); - } - - *numnrmibits = extract_l( L_mult0( sub( *num_env_bands, 1 ), NORMI_BITS ) ); - move16(); - - return; -} - -void hq_configure_evs_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ - Word16 *num_sfm, /* o : Total number of subbands Q0 */ - Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ - Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ - Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ - Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ - Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 *sfmsize, /* o : Subband bandwidths Q0 */ - Word16 *sfm_start, /* o : Subband start coefficients Q0 */ - Word16 *sfm_end /* o : Subband end coefficients Q0 */ -) -{ - const Word16 *p_sfmsize; - const Word16 *p_sfm_start; - const Word16 *p_sfm_end; - Word16 i, bw_ext; - - bw_ext = 0; - move16(); - - *start_norm = 0; - move16(); - - IF( EQ_16( length, L_FRAME48k ) ) /*tbv SOLVED_COMP_ENC_DEC*/ - { - IF( EQ_16( hqswb_clas, HQ_GEN_FB ) ) - { - *num_sfm = NB_SFM; - move16(); - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - - IF( GE_32( core_brate, HQ_32k ) ) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; - move16(); - *num_env_bands = SFM_N_STA_10k; - move16(); - } - ELSE /*IF(EQ_32(core_brate, HQ_16k40) || EQ_32(core_brate, HQ_24k40))*/ - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; - *num_env_bands = SFM_N_STA_8k; - move16(); - move16(); - } - *nb_sfm = *num_sfm; /* Q0 */ - move16(); - } - ELSE - { - IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - *num_sfm = SFM_N_HARM_FB; - move16(); - *nb_sfm = SFM_N_HARM_FB; - move16(); - *num_env_bands = SFM_N_HARM_FB; - move16(); - - p_sfmsize = band_len_harm; /* Q0 */ - p_sfm_start = band_start_harm; /* Q0 */ - p_sfm_end = band_end_harm; /* Q0 */ - } - ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) - { - IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) - { - *num_sfm = SFM_N_HARM_FB; - move16(); - *nb_sfm = HVQ_THRES_SFM_24k; - move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ - move16(); - *start_norm = HVQ_THRES_SFM_24k; - move16(); - } - ELSE - { - *num_sfm = SFM_N_HARM_FB; - move16(); - *nb_sfm = HVQ_THRES_SFM_32k; - move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); /* Q0 */ - move16(); - *start_norm = HVQ_THRES_SFM_32k; - move16(); - } - p_sfmsize = band_len_harm; /* Q0 */ - p_sfm_start = band_start_harm; /* Q0 */ - p_sfm_end = band_end_harm; /* Q0 */ - } - ELSE - { - *num_sfm = NB_SFM; - move16(); - *nb_sfm = *num_sfm; /* Q0 */ - move16(); - *num_env_bands = NB_SFM; - move16(); - - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - } - } - } - ELSE IF( EQ_16( length, L_SPEC32k ) ) - { - IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - *num_sfm = SFM_N_HARM; - move16(); - *nb_sfm = SFM_N_HARM; - move16(); - *num_env_bands = SFM_N_HARM; - move16(); - - p_sfmsize = band_len_harm; /* Q0 */ - p_sfm_start = band_start_harm; /* Q0 */ - p_sfm_end = band_end_harm; /* Q0 */ - } - ELSE IF( EQ_16( hqswb_clas, HQ_HVQ ) ) - { - IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) - { - *num_sfm = SFM_N_HARM; - move16(); - *nb_sfm = HVQ_THRES_SFM_24k; - move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); - move16(); - - *start_norm = HVQ_THRES_SFM_24k; - move16(); - } - ELSE - { - *num_sfm = SFM_N_HARM; - move16(); - *nb_sfm = HVQ_THRES_SFM_32k; - move16(); - *num_env_bands = sub( *num_sfm, *nb_sfm ); - move16(); - - *start_norm = HVQ_THRES_SFM_32k; - move16(); - } - p_sfmsize = band_len_harm; /* Q0 */ - p_sfm_start = band_start_harm; /* Q0 */ - p_sfm_end = band_end_harm; /* Q0 */ - } - ELSE IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) ) - { - *num_sfm = SFM_N_SWB; - move16(); - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - - IF( GE_32( core_brate, HQ_32k ) ) - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_32K; - move16(); - *num_env_bands = SFM_N_STA_10k; - move16(); - } - ELSE /*if( EQ_32(core_brate, HQ_24k40))*/ - { - *hq_generic_offset = HQ_GENERIC_FOFFSET_24K4; - move16(); - *num_env_bands = SFM_N_STA_8k; - move16(); - } - - *nb_sfm = *num_sfm; - move16(); - } - ELSE - { - /* HQ_NORMAL and HQ_TRANSIENT */ - *num_sfm = SFM_N_SWB; - move16(); - *nb_sfm = *num_sfm; - move16(); - *num_env_bands = SFM_N_SWB; - move16(); - - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - } - } - ELSE IF( EQ_16( length, L_SPEC48k_EXT ) ) - { - bw_ext = 1; - move16(); - p_sfmsize = band_len_HQ; /* Q0 */ - p_sfm_start = band_start_HQ; /* Q0 */ - p_sfm_end = band_end_HQ; /* Q0 */ - *num_sfm = NB_SFM; - move16(); - } - ELSE IF( EQ_16( length, L_SPEC16k_EXT ) ) - { - bw_ext = 1; - move16(); - p_sfmsize = band_len_wb; /* Q0 */ - p_sfm_start = band_start_wb; /* Q0 */ - p_sfm_end = band_end_wb; /* Q0 */ - *num_sfm = SFM_N_WB; - move16(); - } - ELSE - { - *num_sfm = SFM_N_WB; - move16(); - *nb_sfm = *num_sfm; - move16(); - *num_env_bands = SFM_N_WB; - move16(); - - p_sfmsize = band_len_wb; /* Q0 */ - p_sfm_start = band_start_wb; /* Q0 */ - p_sfm_end = band_end_wb; /* Q0 */ - } - IF( bw_ext ) - { - FOR( i = 0; i < *num_sfm; i++ ) - { - /*sfmsize[i] = (int16_t)(1.25f * p_sfmsize[i]);*/ - sfmsize[i] = mult_r( shl( p_sfmsize[i], 1 ), 20480 /* 1.25 in Q14 */ ); - move16(); - /*sfm_start[i] = (int16_t)(1.25f * p_sfm_start[i]);*/ - sfm_start[i] = mult_r( shl( p_sfm_start[i], 1 ), 20480 /* 1.25 in Q14 */ ); - move16(); - /*sfm_end[i] = (int16_t)(1.25f * p_sfm_end[i]);*/ - sfm_end[i] = mult_r( shl( p_sfm_end[i], 1 ), 20480 /* 1.25 in Q14 */ ); - move16(); - } - *nb_sfm = *num_sfm; - *num_env_bands = *num_sfm; - move16(); - move16(); - } - ELSE - { - Copy( p_sfmsize, sfmsize, *num_sfm ); - Copy( p_sfm_start, sfm_start, *num_sfm ); - Copy( p_sfm_end, sfm_end, *num_sfm ); - } - - *numnrmibits = extract_l( L_mult0( sub( *num_env_bands, 1 ), NORMI_BITS ) ); - move16(); - - return; -} -#endif void hq_configure_fx( const Word16 length, /* i : Frame length Q0 */ diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 31ee54b86..bdd99ac97 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -48,9 +48,7 @@ *--------------------------------------------------------------------------*/ static void overlap_hq_bwe_fx( const Word32 *hq_swb_overlap_buf, Word32 *coeff_out, const Word16 n_swb_overlap_offset, const Word16 n_swb_overlap, const Word16 *R, const Word16 num_env_bands, const Word16 num_sfm, const Word16 *sfm_end ); -#ifdef HARM_HQ_CORE static void noise_mix_fx( const Word16 *coeff_fine, const Word32 L_E, const Word32 L_normq, Word16 *seed, const Word16 istart, const Word16 iend, const Word16 noise_level, Word32 *L_coeff_out, const Word16 qin, const Word16 qout ); -#endif /*--------------------------------------------------------------------------* @@ -812,11 +810,7 @@ void apply_nf_gain_fx( * HQ Harmonic BWE *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE void harm_bwe_fx( -#else -void ivas_harm_bwe_fx( -#endif const Word16 *coeff_fine, /* i : fine structure for BWE Q12*/ const Word16 *coeff, /* i : coded/noisefilled normalized spectrum Q12*/ const Word16 num_sfm, /* i : Number of subbands Q0*/ @@ -980,170 +974,6 @@ void ivas_harm_bwe_fx( return; } -#ifndef HARM_HQ_CORE -void harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE Q12*/ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum Q12*/ - const Word16 num_sfm, /* i : Number of subbands Q0*/ - const Word16 *sfm_start, /* i : Subband start coefficient Q0*/ - const Word16 *sfm_end, /* i : Subband end coefficient Q0*/ - const Word16 last_sfm, /* i : last coded subband Q0*/ - const Word16 *R, /* i : bit allocation Q0*/ - const Word16 prev_hq_mode, /* i : previous hq mode Q0*/ - Word16 *norm, /* i/o: quantization indices for norms Q0*/ - Word16 *noise_level, /* i/o: noise levels for harmonic modes Q15*/ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame Q15*/ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input Q0*/ - Word32 *coeff_out, /* o : coded/noisefilled spectrum Q12*/ - const Word16 element_mode /* i : IVAS element mode Q0*/ -) -{ - Word16 i, j; - Word16 sfm, band_width; - Word32 normq, L_tmp, L_tmp2; - Word32 E_L; - Word16 alfa = 16384; - move16(); - Word16 tmp, tmp1, exp1; - Word16 beta; - Word32 *src, *dst; - - move16(); /* alfa */ - - FOR( sfm = 0; sfm <= last_sfm; sfm++ ) - { - IF( R[sfm] == 0 ) - { - normq = dicn_fx[norm[sfm]]; /*Q14 */ - move16(); - - FOR( i = sfm_start[sfm]; i < sfm_end[sfm]; i++ ) - { - coeff_out[i] = L_shl( Mult_32_16( normq, coeff[i] ), 1 ); /*12 Q(14 +12+1-16 +1) */ - move32(); - } - } - } - noise_level[1] = noise_level[0]; /*Q15*/ - move16(); - - /* shaping the BWE spectrum further by envelopes and noise factors */ - L_tmp = L_mult( 29491, prev_noise_level[0] ); /* 15 +1 +15 */ - noise_level[0] = round_fx( L_mac( L_tmp, 3277, noise_level[0] ) ); /*15 */ - move16(); - - L_tmp = L_mult( 29491 /*0.9 in Q15*/, prev_noise_level[1] ); /*Q31*/ - noise_level[1] = round_fx( L_mac( L_tmp, 3277, noise_level[1] ) ); /*Q15*/ - move16(); - - test(); - IF( prev_hq_mode == HQ_NORMAL || EQ_16( prev_hq_mode, HQ_GEN_SWB ) ) - { - IF( LT_16( noise_level[0], 8192 /*Q15*/ ) ) - { - noise_level[0] = shl( noise_level[0], 2 ); /*Q15*/ - move16(); - } - - IF( LT_16( noise_level[1], 8192 /*Q15*/ ) ) - { - noise_level[1] = shl( noise_level[1], 2 ); /*Q15*/ - move16(); - } - } - - FOR( i = add( last_sfm, 1 ); i < num_sfm; i++ ) - { - E_L = 1; - move32(); - FOR( j = sfm_start[i]; j < sfm_end[i]; j++ ) - { - L_tmp = L_mult0( coeff_fine[j], coeff_fine[j] ); /*Q30 */ - E_L = L_add( E_L, L_shr( L_tmp, 6 ) ); /*Q24 */ - } - - normq = dicn_fx[norm[i]]; /*Q14*/ - move32(); - - alfa = noise_level[0]; /*Q15*/ - move16(); - if ( GT_16( i, 27 ) ) - { - alfa = noise_level[1]; /*Q15*/ - move16(); - } - - band_width = sub( sfm_end[i], sfm_start[i] ); /* */ - exp1 = norm_l( E_L ); - IF( exp1 == 0 ) - { - E_L = Mult_32_16( E_L, inv_tbl_fx[band_width] ); /* Q24 (24+15+1-16) */ /*24+15+1-16 */ - tmp = div_l( E_L, sub( 32767, alfa ) ); /*Q24-15-1 =8 */ - tmp = s_max( 1, tmp ); - L_tmp = L_deposit_h( tmp ); /*24 */ - E_L = Isqrt( L_tmp ); /* Q19 (31-24/2) */ - } - ELSE - { - exp1 = sub( exp1, 1 ); - E_L = Mult_32_16( L_shl( E_L, exp1 ), inv_tbl_fx[band_width] ); /* Q24+exp1 (24+exp1+15+1-16) */ - tmp = div_l( E_L, sub( 32767, alfa ) ); /*Q24+exp1-15-1 =8+exp1 */ - tmp = s_max( 1, tmp ); - L_tmp = L_shl( L_deposit_l( tmp ), sub( 16, exp1 ) ); /*24 8+exp1+16-exp1 */ - E_L = Isqrt( L_tmp ); /* Q19 (31-24/2) */ - } - - exp1 = norm_s( alfa ); - tmp1 = shl( alfa, exp1 ); - if ( EQ_16( element_mode, EVS_MONO ) ) - { - exp1 = add( 1, exp1 ); - } - tmp1 = s_max( tmp1, 16384 ); - tmp1 = div_s( 16384, tmp1 ); /*Q15*/ - L_tmp2 = L_deposit_h( tmp1 ); /*Q31*/ - L_tmp2 = Isqrt_lc( L_tmp2, &exp1 ); /*Q31 - exp1*/ - - beta = round_fx( L_shl( L_tmp2, exp1 ) ); /*Q15*/ - beta = shr( beta, 1 ); /*Q15 */ - - - FOR( sfm = sfm_start[i]; sfm < sfm_end[i]; sfm++ ) - { - L_tmp = Mult_32_16( E_L, coeff_fine[sfm] ); /*Q19 19 + 15 +1-16 */ - L_tmp = L_shl_sat( L_tmp, 9 ); /*Q28 */ - tmp = Random( bwe_seed ); /*Q15 */ - L_tmp2 = L_shr( L_mult( beta, tmp ), 3 ); /* Q28 31-3 15+15 +1-3 */ - L_tmp = L_add_sat( L_tmp, L_tmp2 ); /*Q28 */ - coeff_out[sfm] = L_shl_sat( Mult_32_32( L_tmp, normq ), 1 ); /*Q12 28 +14 +1 -31 */ - move32(); - } - } - - prev_noise_level[0] = noise_level[0]; /*Q15*/ - move16(); - prev_noise_level[1] = noise_level[1]; /*Q15*/ - move16(); - - src = &coeff_out[( sfm_end[last_sfm] + L_HARMONIC_EXC - START_EXC )]; /*Q12 */ - - dst = src - 1; - FOR( i = 0; i < 16; i++ ) - { - *src = Mult_32_16( *src, hvq_bwe_fac_fx[i] ); /* Q12 (12+15+1-16) */ - move32(); - src++; - *dst = Mult_32_16( *dst, hvq_bwe_fac_fx[i] ); /* Q12 (12+15+1-16) */ - move32(); - dst--; - } - IF( EQ_16( num_sfm, 33 ) ) - { - set32_fx( &coeff_out[800], 0, 160 ); - } - return; -} -#endif /*--------------------------------------------------------------------------* * HVQ_bwe_fx() @@ -1552,11 +1382,7 @@ void hvq_concat_bands_fx( * *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE static void noise_mix_fx( -#else -void noise_mix_fx( -#endif const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ const Word32 L_E, /* i : normalization factor Q17 */ const Word32 L_normq, /* i : quantized norm Q14 */ @@ -1901,104 +1727,6 @@ Word16 get_nor_delta_hf_fx( return add_bits_denv; } -#ifndef HARM_HQ_CORE -/*-------------------------------------------------------------------* - * calc_nor_delta_hf() - * - * - *--------------------------------------------------------------------------*/ -Word16 calc_nor_delta_hf_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *t_audio, /* i : transform-domain coefficients Qx*/ - Word16 *ynrm, /* i/o: norm indices Q0*/ - Word16 *Rsubband, /* i/o: sub-band bit allocation Q0*/ - const Word16 num_env_bands, /* i : Number coded envelope bands Q0*/ - const Word16 nb_sfm, /* i : Number of envelope bands Q0*/ - const Word16 *sfmsize, /* i : band length Q0*/ - const Word16 *sfm_start, /* i : Start index of bands Q0*/ - const Word16 core_sfm /* i : index of the end band for core Q0*/ -) -{ - Word16 i; - Word16 ynrm_t[44], normqlg2_t[44]; - Word16 delta, max_delta, min_delta, bitsforDelta, add_bits_denv; - - max_delta = -100; - move16(); - calc_norm_fx( t_audio, 12, ynrm_t, normqlg2_t, 0, nb_sfm, sfmsize, sfm_start ); - add_bits_denv = 0; - move16(); - FOR( i = num_env_bands; i < nb_sfm; ++i ) - { - IF( Rsubband[i] != 0 ) - { - delta = sub( ynrm_t[i], ynrm[i] ); /*Q0*/ - IF( delta > 0 ) - { - delta = add( delta, 1 ); /*Q0*/ - } - ELSE - { - delta = negate( delta ); /*Q0*/ - } - if ( GT_16( delta, max_delta ) ) - { - max_delta = delta; /*Q0*/ - move16(); - } - } - } - IF( GE_16( core_sfm, num_env_bands ) ) - { - IF( LT_16( max_delta, 16 ) ) - { - bitsforDelta = 2; - move16(); - FOR( ; max_delta >= 2; max_delta >>= 1 ) - { - bitsforDelta = add( bitsforDelta, 1 ); /*Q0*/ - } - } - ELSE - { - bitsforDelta = 5; - move16(); - } - max_delta = sub( shl( 1, sub( bitsforDelta, 1 ) ), 1 ); /*Q0*/ - min_delta = negate( add( max_delta, 1 ) ); /*Q0*/ - - /* updating norm & storing delta norm */ - add_bits_denv = 2; - move16(); - push_indice( hBstr, IND_DELTA_ENV_HQ, sub( bitsforDelta, 2 ), 2 ); - FOR( i = num_env_bands; i < nb_sfm; ++i ) - { - IF( Rsubband[i] != 0 ) - { - delta = sub( ynrm_t[i], ynrm[i] ); - IF( GT_16( delta, max_delta ) ) - { - delta = max_delta; /*Q0*/ - move16(); - } - ELSE IF( LT_16( delta, min_delta ) ) - { - delta = min_delta; /*Q0*/ - move16(); - } - push_indice( hBstr, IND_DELTA_ENV_HQ, delta - min_delta, bitsforDelta ); - ynrm[i] = add( ynrm[i], delta ); /*Q0*/ - move16(); - add_bits_denv = add( add_bits_denv, bitsforDelta ); - } - } - - /* updating bit allocation */ - update_rsubband_fx( nb_sfm, Rsubband, add_bits_denv ); - } - return add_bits_denv; -} -#endif /*-------------------------------------------------------------------* * calc_nor_delta_hf() @@ -2105,44 +1833,9 @@ Word16 calc_nor_delta_hf_fx( * * HQ GENERIC *--------------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE -void hq_bwe_fx( - const Word16 HQ_mode, /* i : HQ mode Q0*/ - Word32 *coeff_out1, /* i/o: BWE input & temporary buffer Q12*/ - const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes Q1*/ - Word32 *coeff_out, /* o : SWB signal in MDCT domain Q12*/ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic Q0*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length Q0*/ - const Word16 hq_generic_exc_clas, /* i : hq generic hf excitation class Q0*/ - const Word16 *sfm_end, /* i : End of bands Q0*/ - const Word16 num_sfm, /* i : Number of bands Q0*/ - const Word16 num_env_bands, /* i : Number of coded envelope bands Q0*/ - const Word16 *R /* i : Bit allocation Q0*/ -) -{ - Word16 n_swb_overlap_offset, n_swb_overlap; - Word32 hq_swb_overlap_buf_fx[L_FRAME32k]; - n_swb_overlap_offset = add( swb_bwe_subband[0], hq_generic_offset ); - n_swb_overlap = sub( sfm_end[( num_env_bands - 1 )], n_swb_overlap_offset ); /*Q0*/ - - - Copy32( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub( add( n_swb_overlap, sfm_end[( num_sfm - 1 )] ), sfm_end[( num_env_bands - 1 )] ) ); /*Q12*/ - - hq_generic_decoding_fx( HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R ); - - overlap_hq_bwe_fx( hq_swb_overlap_buf_fx, coeff_out, n_swb_overlap_offset, n_swb_overlap, R, num_env_bands, num_sfm, sfm_end ); - - return; -} -#endif - -#ifdef HARM_HQ_CORE void hq_bwe_fx( const Word16 element_mode, /* i : element mode */ -#else -void hq_bwe_ivas_fx( -#endif const Word16 HQ_mode, /* i : HQ mode Q0*/ Word32 *coeff_out1, /* i/o: BWE input & temporary buffer Q12*/ const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes Q1*/ @@ -2164,11 +1857,7 @@ void hq_bwe_ivas_fx( Copy32( &coeff_out[n_swb_overlap_offset], hq_swb_overlap_buf_fx, sub( add( n_swb_overlap, sfm_end[( num_sfm - 1 )] ), sfm_end[( num_env_bands - 1 )] ) ); /*Q12*/ -#ifdef HARM_HQ_CORE hq_generic_decoding_fx( element_mode, HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R ); -#else - hq_generic_decoding_ivas_fx( HQ_mode, coeff_out1, hq_generic_fenv, coeff_out, hq_generic_offset, prev_L_swb_norm, hq_generic_exc_clas, R ); -#endif overlap_hq_bwe_fx( hq_swb_overlap_buf_fx, coeff_out, n_swb_overlap_offset, n_swb_overlap, R, num_env_bands, num_sfm, sfm_end ); diff --git a/lib_com/interleave_spectrum_fx.c b/lib_com/interleave_spectrum_fx.c index 1ad331a5b..0b04475d9 100644 --- a/lib_com/interleave_spectrum_fx.c +++ b/lib_com/interleave_spectrum_fx.c @@ -53,92 +53,6 @@ void interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ ) -#ifndef HARM_HQ_CORE -{ - Word16 i, j, k; - Word32 *p1, *p2, *p3, *p4; - Word32 *p_out; - Word32 coefs_out[L_FRAME48k]; - Word16 sublen[3] = { 240, 160, 80 }; - Word16 grps; - const Word16 *bw; - const Word16 *cnt; - - move16(); - move16(); - move16(); - /* Common inits */ - p1 = coefs; /*Q12*/ - p_out = coefs_out; - IF( EQ_16( length, L_FRAME48k ) ) - { - bw = intl_bw_48; /*Q0*/ - cnt = intl_cnt_48; /*Q0*/ - grps = N_INTL_GRP_48; - move16(); - p2 = p1 + sublen[0]; - p3 = p2 + sublen[0]; - p4 = p3 + sublen[0]; - } - ELSE IF( EQ_16( length, L_SPEC32k ) ) - { - bw = intl_bw_32; /*Q0*/ - cnt = intl_cnt_32; /*Q0*/ - grps = N_INTL_GRP_32; - move16(); - p2 = p1 + sublen[1]; - p3 = p2 + sublen[1]; - p4 = p3 + sublen[1]; - } - ELSE /* length == L_SPEC16k */ - { - bw = intl_bw_16; /*Q0*/ - cnt = intl_cnt_16; /*Q0*/ - grps = N_INTL_GRP_16; - move16(); - p2 = p1 + sublen[2]; - p3 = p2 + sublen[2]; - p4 = p3 + sublen[2]; - } - - FOR( i = 0; i < grps; i++ ) - { - FOR( j = 0; j < cnt[i]; j++ ) - { - FOR( k = 0; k < bw[i]; k++ ) - { - *p_out++ = *p1++; /*Q12*/ - move32(); - } - FOR( k = 0; k < bw[i]; k++ ) - { - *p_out++ = *p2++; /*Q12*/ - move32(); - } - FOR( k = 0; k < bw[i]; k++ ) - { - *p_out++ = *p3++; /*Q12*/ - move32(); - } - FOR( k = 0; k < bw[i]; k++ ) - { - *p_out++ = *p4++; /*Q12*/ - move32(); - } - } - } - - /* For FB the interleaved spectrum is 800 samples */ - Copy32( coefs_out, coefs, (Word16) ( p_out - coefs_out ) ); - - return; -} - -void interleave_spectrum_ivas_fx( - Word32 *coefs, /* i/o: input and output coefficients Q12 */ - const Word16 length /* i : length of spectrum Q0 */ -) -#endif { Word16 i, j, k; Word32 *p1, *p2, *p3, *p4; @@ -227,11 +141,7 @@ void interleave_spectrum_ivas_fx( * Deinterleave the spectrum *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE void de_interleave_spectrum_fx( -#else -void ivas_de_interleave_spectrum_fx( -#endif Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ ) @@ -325,98 +235,3 @@ void ivas_de_interleave_spectrum_fx( return; } -#ifndef HARM_HQ_CORE - -void de_interleave_spectrum_fx( - Word32 *coefs, /* i/o: input and output coefficients Q12 */ - const Word16 length /* i : length of spectrum Q0 */ -) -{ - Word16 i, j, k; - Word32 *p1, *p2, *p3, *p4; - Word32 *p_in; - Word32 coefs_out[L_FRAME48k]; - Word16 sublen[] = { 80, 160, 240, 320, 480, 720 }; - move16(); - move16(); - move16(); - move16(); - move16(); - move16(); - Word16 grps; - Word16 l_frame; - const Word16 *bw; - const Word16 *cnt; - - /* common for all groups */ - p1 = coefs_out; - l_frame = length; - move16(); - IF( EQ_16( length, L_FRAME48k ) ) - { - bw = intl_bw_48; /*Q0*/ - cnt = intl_cnt_48; /*Q0*/ - grps = N_INTL_GRP_48; - move16(); - p2 = coefs_out + sublen[2]; /* 240, length/4 */ - p3 = coefs_out + sublen[4]; /* 480, 2*length/4 */ - p4 = coefs_out + sublen[5]; /* 720, 3*length/4 */ - } - ELSE IF( EQ_16( length, L_SPEC32k ) ) - { - bw = intl_bw_32; /*Q0*/ - cnt = intl_cnt_32; /*Q0*/ - grps = N_INTL_GRP_32; - move16(); - - p2 = coefs_out + sublen[1]; /* 160 */ - p3 = coefs_out + sublen[3]; /* 320 */ - p4 = coefs_out + sublen[4]; /* 480 */ - } - ELSE /* length == L_SPEC16k */ - { - bw = intl_bw_16; /*Q0*/ - cnt = intl_cnt_16; /*Q0*/ - grps = N_INTL_GRP_16; - move16(); - - p2 = coefs_out + sublen[0]; /* 80 */ - p3 = coefs_out + sublen[1]; /* 160 */ - p4 = coefs_out + sublen[2]; /* 240 */ - } - - set32_fx( coefs_out, 0, L_FRAME48k ); - p_in = coefs; /*Q12*/ - - FOR( i = 0; i < grps; i++ ) - { - FOR( j = 0; j < cnt[i]; j++ ) - { - FOR( k = 0; k < bw[i]; k++ ) - { - *p1++ = *p_in++; /*Q12*/ - move32(); - } - FOR( k = 0; k < bw[i]; k++ ) - { - *p2++ = *p_in++; /*Q12*/ - move32(); - } - FOR( k = 0; k < bw[i]; k++ ) - { - *p3++ = *p_in++; /*Q12*/ - move32(); - } - FOR( k = 0; k < bw[i]; k++ ) - { - *p4++ = *p_in++; /*Q12*/ - move32(); - } - } - } - - Copy32( coefs_out, coefs, l_frame ); - - return; -} -#endif diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ee47b1e48..fa5928478 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1581,94 +1581,6 @@ ivas_error ivas_osba_render_sf_fx( Word32 *p_output[] /* o : rendered time signal */ ); -#ifndef HARM_HQ_CORE -void ivas_hq_core_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis */ - Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length */ - const Word16 hq_core_type, /* i : HQ core type */ - const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ - Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ -); - -/* o : Consumed bits Q0 */ -Word16 ivas_hq_classifier_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : Core bit rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - Word16 *is_transient, /* o : Transient flag Q0 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ -); - -void ivas_hq_hr_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word32 *t_audio_q, /* o : transform-domain coefficients Q12 */ - const Word16 length, /* i : frame length Q0 */ - Word16 num_bits, /* i : number of available bits Q0 */ - Word16 *ynrm, /* o : norm quantization index vector Q0 */ - Word16 *is_transient, /* o : transient flag Q0 */ - Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ - Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag */ -); - -void ivas_hq_configure_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ - Word16 *num_sfm, /* o : Total number of subbands Q0 */ - Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ - Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ - Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ - Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ - Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 *sfmsize, /* o : Subband bandwidths Q0 */ - Word16 *sfm_start, /* o : Subband start coefficients Q0 */ - Word16 *sfm_end /* o : Subband end coefficients Q0 */ -); - -void ivas_hq_bit_allocation_fx( - const Word32 core_brate, /* i : Core bit-rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ class Q0 */ - Word16 *num_bits, /* i/o: Remaining bit budget Q0 */ - const Word16 *normqlg2, /* i : Quantized norms Q0 */ - const Word16 nb_sfm, /* i : Number sub bands to be encoded Q0 */ - const Word16 *sfmsize, /* i : Sub band bandwidths Q0 */ - Word16 *noise_level, /* o : HVQ noise level Q15 */ - Word16 *R, /* o : Bit allocation per sub band Q0 */ - Word16 *Rsubband, /* o : Fractional bit allocation Q3 */ - Word16 *sum, /* o : Sum of allocated shape bits Q0 */ - Word16 *core_sfm, /* o : Last coded band in core Q0 */ - const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_GEN Q0 */ -); - -/* o : Number of assigned gain bits */ -Word16 ivas_assign_gain_bits_fx( - const Word16 core, /* i : HQ core */ - const Word16 BANDS, /* i : Number of bands */ - const Word16 *band_width, /* i : Sub band bandwidth */ - Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *gain_bits_array, /* o : Assigned gain bits */ - Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ -); - -void ivas_fine_gain_pred_fx( - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - const Word16 *sfm_size, /* i : Sub band bandwidths */ - const Word16 *i_sort, /* i : Energy sorting indices */ - const Word16 *K, /* i : Number of pulses per band */ - const Word16 *maxpulse, /* i : Maximum pulse per band */ - const Word16 *R, /* i : Bits per sub band Q3 */ - const Word16 num_sfm, /* i : Number of sub bands */ - Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) Q0*/ - Word16 *fg_pred, /* o : Predicted fine gains Q12 */ - const Word16 core /* i : Core */ -); -#endif Word16 ivas_pvq_core_dec_fx( Decoder_State *st_fx, const Word16 *sfm_start, @@ -1685,100 +1597,6 @@ Word16 ivas_pvq_core_dec_fx( const Word16 core ); -#ifndef HARM_HQ_CORE -void ivas_hq_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal */ - Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses */ - Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ - Word16 *Q_spec, /* i/o: Q value of stored spectrum */ - Word16 *num_p, /* i/o: Number of identified peaks */ - Word16 *plocs, /* i/o: Peak locations */ - Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ - const Word16 env_stab, /* i : Envelope stability parameter */ - Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ - const Word16 ph_ecu_HqVoicing, /* i : HQ Voicing flag */ - Word16 *ph_ecu_active, /* i : Phase ECU active flag */ - Word16 *gapsynth, /* o : Gap synthesis */ - const Word16 prev_bfi, /* i : indicating burst frame error */ - const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ - Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients */ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to */ - Word16 *beta_mute, /* o : Factor for long-term mute */ - const Word16 output_frame, /* i : frame length */ - Decoder_State *st_fx /* i/o: decoder state structure */ -); - -void ivas_fill_spectrum_fx( - Word16 *coeff, /* i/o: normalized MLT spectrum / nf spectrum Q12 */ - Word32 *L_coeff_out, /* i/o: Noisefilled MLT spectrum Q12 */ - const Word16 *R, /* i : number of pulses per band Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - Word16 norm[], /* i : quantization indices for norms Q0 */ - const Word16 *hq_generic_fenv, /* i : HQ GENERIC envelope Q1 */ - const Word16 hq_generic_offset, /* i : HQ GENERIC offset Q0 */ - const Word16 nf_idx, /* i : noise fill index Q0 */ - const Word16 length, /* i : Length of spectrum (32 or 48 kHz) Q0 */ - const Word16 env_stab, /* i : Envelope stability measure [0..1] Q15 */ - Word16 *no_att_hangover, /* i/o: Frame counter for attenuation hangover Q0 */ - Word32 *L_energy_lt, /* i/o: Long-term energy measure for transient detection Q13 */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE i Q0 */ - const Word16 hq_generic_exc_clas, /* i : BWE excitation class Q0 */ - const Word16 core_sfm, /* i : index of the end band for core Q0 */ - const Word16 HQ_mode, /* i : HQ mode Q0 */ - Word16 noise_level[], /* i : noise levels for harmonic modes Q15 */ - const Word32 L_core_brate, /* i : target bit-rate Q0 */ - Word16 prev_noise_level[], /* i/o: noise factor in previous frame Q15 */ - Word16 *prev_R, /* i/o: bit allocation info. in previous frame Q0 */ - Word32 *prev_coeff_out, /* i/o: decoded spectrum in previous frame Q12 */ - const Word16 *peak_idx, /* i : peak indices for hvq Q0 */ - const Word16 Npeaks, /* i : number of peaks in hvq Q0 */ - const Word16 *npulses, /* i : number of pulses per band Q0 */ - const Word16 prev_is_transient, /* i : previous transient flag Q0 */ - Word32 *prev_normq, /* i/o: previous norms Q14 */ - Word32 *prev_env, /* i/o: previous noise envelopes Q(prev_env_Q) */ - const Word16 prev_bfi, /* i : previous bad frame indicator Q0 */ - const Word16 *sfmsize, /* i : Length of bands Q0 */ - const Word16 *sfm_start, /* i : Start of bands Q0 */ - const Word16 *sfm_end, /* i : End of bands Q0 */ - Word16 *prev_L_swb_norm, /* i/o: HVQ/Harmonic mode normalization length Q0 */ - const Word16 prev_hq_mode, /* i : Previous HQ mode Q0 */ - const Word16 num_sfm, /* i : Total number of bands Q0 */ - Word16 *prev_env_Q, - const Word16 num_env_bands, - const Word16 element_mode -); - -void ivas_de_interleave_spectrum_fx( - Word32 *coefs, /* i/o: input and output coefficients Q12 */ - const Word16 length /* i : length of spectrum Q0 */ -); - -void ivas_harm_bwe_fx( - const Word16 *coeff_fine, /* i : fine structure for BWE */ - const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ - const Word16 num_sfm, /* i : Number of subbands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 last_sfm, /* i : last coded subband */ - const Word16 *R, /* i : bit allocation */ - const Word16 prev_hq_mode, /* i : previous hq mode */ - Word16 *norm, /* i/o: quantization indices for norms */ - Word16 *noise_level, /* i/o: noise levels for harmonic modes */ - Word16 *prev_noise_level, /* i/o: noise factor in previous frame */ - Word16 *bwe_seed, /* i/o: random seed for generating BWE input */ - Word32 *coeff_out, /* o : coded/noisefilled spectrum */ - const Word16 element_mode /* i : IVAS element mode */ -); - -void ivas_hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector */ - const Word16 length, /* i : frame length */ - const Word16 hqswb_clas, /* i : HQ SWB class */ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1 */ -); -#endif void synchro_synthesis_fx( const Word32 ivas_total_brate, /* i : IVAS total bitrate */ CPE_DEC_HANDLE hCPE, /* i/o: CPE decoder structure */ diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 350b6fad9..9ec3ff357 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -15,11 +15,7 @@ * Fine gain prediction *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE void fine_gain_pred_fx( -#else -void ivas_fine_gain_pred_fx( -#endif const Word16 *sfm_start, /* i : Sub band start indices */ const Word16 *sfm_end, /* i : Sub band end indices */ const Word16 *sfm_size, /* i : Sub band bandwidths */ @@ -31,9 +27,7 @@ void ivas_fine_gain_pred_fx( Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ Word16 *y, /* i/o: Quantized vector (int) Q0 */ Word16 *fg_pred, /* o : Predicted fine gains Q12 */ -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif const Word16 core /* i : Core */ ) { @@ -42,9 +36,7 @@ void ivas_fine_gain_pred_fx( Word32 xx; Word16 accuracy; Word16 k, bw; -#ifdef HARM_HQ_CORE Word16 tmp1; -#endif Word16 shift, bw_idx; Word16 tmp, exp, exp2; Word32 L_tmp; @@ -61,18 +53,10 @@ void ivas_fine_gain_pred_fx( bw = sfm_size[i_sort[band]]; move16(); // Extending for IVAS /* allowed. 8, 16, 24,32,40,48,64,80,96*/ -#ifdef HARM_HQ_CORE bw_idx = band_len_idx[shr( bw, 3 )]; -#else - bw_idx = ivas_band_len_idx[shr( bw, 3 )]; -#endif move16(); /* bw_idx= 0: 8 */ xx = L_deposit_l( 0 ); -#ifdef HARM_HQ_CORE shift = band_len_ener_shift[bw_idx]; -#else - shift = ivas_band_len_ener_shift[bw_idx]; -#endif move16(); FOR( i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++ ) { @@ -90,7 +74,6 @@ void ivas_fine_gain_pred_fx( exp = sub( 31, add( exp, sub( 30, shl( shift, 1 ) ) ) ); L_tmp = Isqrt_lc( L_tmp, &exp ); /*31 - exp */ -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { tmp1 = fine_gain_pred_sqrt_bw[bw_idx]; @@ -113,12 +96,6 @@ void ivas_fine_gain_pred_fx( #endif } } -#else - Word16 norm = norm_s( bw ); - Word16 tmp1, tmp_exp = sub( 15, norm ); - tmp1 = Sqrt16( shl( bw, norm ), &tmp_exp ); - tmp1 = shr( tmp1, sub( sub( 15, tmp_exp ), Q11 ) ); -#endif Mpy_32_16_ss( L_tmp, tmp1, &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ gp = round_fx_sat( L_shl_sat( L_tmp, add( 1, exp ) ) ); /*27-exp+1+exp-16=12 */ test(); @@ -168,111 +145,6 @@ void ivas_fine_gain_pred_fx( return; } -#ifndef HARM_HQ_CORE -void fine_gain_pred_fx( - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - const Word16 *sfm_size, /* i : Sub band bandwidths */ - const Word16 *i_sort, /* i : Energy sorting indices */ - const Word16 *K, /* i : Number of pulses per band */ - const Word16 *maxpulse, /* i : Maximum pulse per band */ - const Word16 *R, /* i : Bits per sub band Q3 */ - const Word16 num_sfm, /* i : Number of sub bands */ - Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ - Word16 *fg_pred, /* o : Predicted fine gains Q12 */ - const Word16 core /* i : Core */ -) -{ - Word16 i, band; - Word16 gp; - Word32 xx; - Word16 accuracy; - Word16 k, bw; - - Word16 shift, bw_idx; - Word16 tmp, exp, exp2; - Word32 L_tmp; - UWord16 lsb; - - FOR( band = 0; band < num_sfm; band++ ) - { - k = K[i_sort[band]]; - move16(); - - IF( k > 0 ) - { - /* bw, bw_idx only used if k>0 */ - bw = sfm_size[i_sort[band]]; - move16(); /* allowed. 8, 16, 24,32,48,64,80,96 */ - bw_idx = band_len_idx[shr( bw, 3 )]; - move16(); /* bw_idx= 0: 7 */ - xx = L_deposit_l( 0 ); - shift = band_len_ener_shift[bw_idx]; - FOR( i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++ ) - { - /*xx += xq[i] * xq[i]; */ - tmp = shr( xq[i], shift ); /*15-shift */ - xx = L_mac0( xx, tmp, tmp ); /*30-2*shift */ - } - - IF( xx > 0 ) - { - /* Normalize synthesis to RMS=1.0 */ - /*gp = (float) sqrt(bw / xx); */ - exp = norm_l( xx ); - L_tmp = L_shl( xx, exp ); /*2*(15-shift)+exp */ - exp = sub( 31, add( exp, sub( 30, shl( shift, 1 ) ) ) ); - L_tmp = Isqrt_lc( L_tmp, &exp ); /*31 - exp */ - Mpy_32_16_ss( L_tmp, fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ - gp = round_fx_sat( L_shl_sat( L_tmp, add( 1, exp ) ) ); /*27-exp+1+exp-16=12 */ - test(); - test(); - IF( EQ_16( core, HQ_CORE ) && R != NULL && LE_16( R[i_sort[band]], 256 ) ) /* 256 is 32 in Q3 */ - { - /*accuracy = ((float)k/(float)bw)*maxpulse[i_sort[band]]; */ - L_tmp = L_mult( k, inv_tbl_fx[bw] ); /*0+15+1 */ - exp2 = norm_l( L_tmp ); - tmp = round_fx( L_shl( L_tmp, exp2 ) ); /*16+exp2-16 */ - L_tmp = L_mult0( maxpulse[i_sort[band]], tmp ); /*0+exp2 */ - exp = norm_l( L_tmp ); - accuracy = round_fx( L_shl( L_tmp, exp ) ); /*exp2+exp-16=exp-16 */ - exp = add( exp, exp2 ); - - /*gp *= 1.0f - 0.05f / accuracy; */ - tmp = div_s( 13107, accuracy ); /* 0.05 in Q18 */ - tmp = shr_sat( tmp, sub( 34, exp ) ); /*15+18-exp+16-15=34-exp */ - tmp = sub( 32767, tmp ); - tmp = s_max( 27554, tmp ); /* Limit attenuation to norm quantizer error, 2^-0.25 in Q15 */ - gp = mult_r( tmp, gp ); /*15+12+1-16=12 */ - } - - fg_pred[band] = gp; - move16(); - } - ELSE - { - fg_pred[band] = 0; - move16(); - } - } - ELSE - { - fg_pred[band] = 0; - move16(); - FOR( i = sfm_start[i_sort[band]]; i < sfm_end[i_sort[band]]; i++ ) - { - y[i] = 0; - move16(); - xq[i] = 0; - move16(); - } - } - } - - return; -} -#endif /*--------------------------------------------------------------------------* * get_max_pulses() diff --git a/lib_com/options.h b/lib_com/options.h index 0ca54bb9d..89dee9b69 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,7 +83,6 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ -#define HARM_HQ_CORE /* harmonize HQ core functions */ #define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ #define HARMONIZE_TBE3 /* VA: basop issue 2399: Remove duplicated code: TBE, step 3 */ #define FIX_2459_USAN_AMR_SIDSTART /* FhG: basop issue 2459: fix msan complaint */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index f42f8a0ad..fb8805407 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -274,17 +274,6 @@ void calc_normal_length_fx_32( Word16 *prev_L_swb_norm /*i/o : last normalize length : Q0 */ ); -#ifndef HARM_HQ_CORE -void hq_generic_decoding_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ - const Word16 *R ); -#endif Word16 WB_BWE_gain_pred_fx( Word16 *WB_fenv, /* o : WB frequency envelopes */ const Word16 *core_dec_freq, /* i : Frequency domain core decoded signal */ @@ -384,9 +373,7 @@ void time_reduce_pre_echo_fx( Word16 Q_synth ); void hq_generic_decoding_fx( -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif const Word16 HQ_mode, /* i : HQ mode */ Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ @@ -396,17 +383,6 @@ void hq_generic_decoding_fx( const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ const Word16 *R ); -#ifndef HARM_HQ_CORE -void hq_generic_decoding_ivas_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic*/ - Word16 *prev_L_swb_norm, /* i/o: last normalize length */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ - const Word16 *R ); -#endif void save_old_syn_fx( const Word16 L_frame, /* i : frame length */ const Word16 syn[], /* i : ACELP synthesis */ @@ -611,19 +587,6 @@ void hvq_concat_bands_fx( Word16 *hvq_band_end /* i : Band end indices */ ); -#ifndef HARM_HQ_CORE -void noise_mix_fx( - const Word16 *coeff_fine, /* i : normalized fine structure spectrum Qin */ - const Word32 L_E, /* i : normalization factor Q17 */ - const Word32 L_normq, /* i : quantized norm Q14 */ - Word16 *seed, /* i/o: random seed Q0 */ - const Word16 istart, /* i : start coefficient Q0 */ - const Word16 iend, /* i : end coefficient Q0 */ - const Word16 noise_level, /* i : noise_level Q0 */ - Word32 *L_coeff_out, /* o : noisemixed spectrum Qout*/ - const Word16 qin, - const Word16 qout ); -#endif void hq_generic_fine_fx( Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ const Word16 last_sfm, /* i : Last coded band */ @@ -662,38 +625,8 @@ Word16 calc_nor_delta_hf_fx( const Word16 core_sfm /* i : index of the end band for core */ ); -#ifndef HARM_HQ_CORE -Word16 calc_nor_delta_hf_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *t_audio, /* i : transform-domain coefficients Qx*/ - Word16 *ynrm, /* i/o: norm indices */ - Word16 *Rsubband, /* i/o: sub-band bit allocation */ - const Word16 num_env_bands, /* i : Number coded envelope bands */ - const Word16 nb_sfm, /* i : Number of envelope bands */ - const Word16 *sfmsize, /* i : band length */ - const Word16 *sfm_start, /* i : Start index of bands */ - const Word16 core_sfm /* i : index of the end band for core */ -); - -void hq_bwe_fx( - const Word16 HQ_mode, /* i : HQ mode */ - Word32 *coeff_out1, /* i/o: BWE i & temporary buffer */ - const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ - Word32 *coeff_out, /* o : SWB signal in MDCT domain */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generic bwe*/ - Word16 *prev_L_swb_norm, /*i/o : last normalize length */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class */ - const Word16 *sfm_end, /* i : End of bands */ - const Word16 num_sfm, - const Word16 num_env_bands, - const Word16 *R ); -#endif -#ifdef HARM_HQ_CORE void hq_bwe_fx( const Word16 element_mode, /* i : element mode */ -#else -void hq_bwe_ivas_fx( -#endif const Word16 HQ_mode, /* i : HQ mode */ Word32 *coeff_out1, /* i/o: BWE i & temporary buffer */ const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ @@ -1407,22 +1340,6 @@ void hq_configure_fx( Word16 *sfm_end /* o : Subband end coefficients Q0 */ ); -#ifndef HARM_HQ_CORE -void hq_configure_evs_fx( - const Word16 length, /* i : Frame length Q0 */ - const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ - const Word32 core_brate, /* i : Codec bitrate Q0 */ - Word16 *num_sfm, /* o : Total number of subbands Q0 */ - Word16 *nb_sfm, /* o : Total number of coded bands Q0 */ - Word16 *start_norm, /* o : First norm to be SDE encoded Q0 */ - Word16 *num_env_bands, /* o : Number coded envelope bands Q0 */ - Word16 *numnrmibits, /* o : Number of bits in fall-back norm encoding Q0 */ - Word16 *hq_generic_offset, /* o : Freq offset for HQ GENERIC Q0 */ - Word16 *sfmsize, /* o : Subband bandwidths Q0 */ - Word16 *sfm_start, /* o : Subband start coefficients Q0 */ - Word16 *sfm_end /* o : Subband end coefficients Q0 */ -); -#endif void hp20( Word16 signal[], /* i/o: signal to filter any */ const Word16 stride, /* i : stride to be applied accessing signal */ @@ -1608,12 +1525,6 @@ void interleave_spectrum_fx( const Word16 length /* i : length of spectrum Q0 */ ); -#ifndef HARM_HQ_CORE -void interleave_spectrum_ivas_fx( - Word32 *coefs, /* i/o: input and output coefficients Q12 */ - const Word16 length /* i : length of spectrum Q0 */ -); -#endif /* o : impulse response energy Q3 */ Word16 findpulse_fx( const Word16 L_frame, /* i : length of the frame */ @@ -4593,9 +4504,7 @@ void fine_gain_pred_fx( Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ Word16 *y, /* i/o: Quantized vector (int) */ Word16 *fg_pred, /* o : Predicted fine gains Q12 */ -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif const Word16 core /* i : Core */ ); @@ -4628,9 +4537,7 @@ void fine_gain_dec_fx( /* o : Number of assigned gain bits */ Word16 assign_gain_bits_fx( -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif const Word16 core, /* i : HQ core */ const Word16 BANDS, /* i : Number of bands */ const Word16 *band_width, /* i : Sub band bandwidth */ @@ -6710,22 +6617,6 @@ Word16 pvq_core_dec_fx( Word16 *maxpulse, const Word16 core ); -#ifndef HARM_HQ_CORE -Word16 ivas_pvq_core_dec_fx( - Decoder_State *st_fx, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ - Word16 *Q_coefs, - Word16 bits_tot, - Word16 nb_sfm, - Word16 *R, /* Q3 */ - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core ); -#endif void decode_energies_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ @@ -7006,28 +6897,14 @@ void fd_bwe_dec_init( FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ ); -#ifndef HARM_HQ_CORE -void hq_core_enc_ivas_fx( - Encoder_State *st, /* i/o: encoder state structure */ - const Word16 *audio_fx, /* i : input audio signal Q0 */ - const Word16 input_frame, /* i : frame length Q0*/ - const Word16 hq_core_type, /* i : HQ core type Q0*/ - const Word16 Voicing_flag, /* i : Voicing flag for FER method selection Q0*/ - const Word16 vad_hover_flag /* i : VAD hangover flag Q0*/ -); -#endif void hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ const Word16 output_frame, /* i : output frame length Q0*/ const Word16 hq_core_type, /* i : HQ core type Q0*/ -#ifdef HARM_HQ_CORE const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ -#else - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ -#endif ); void HQ_core_dec_init_fx( @@ -10120,9 +9997,7 @@ void IGFEncConcatenateBitstream( ); void hq_generic_hf_encoding_fx( -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope */ const Word16 hq_generic_offset, /* i : frequency offset for extracting energy */ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 69be48471..aeea3f8b2 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1491,14 +1491,8 @@ extern const Word16 mfreq_loc_div_25[]; // Q0 extern const Word16 band_len_idx[]; // Q0 extern const Word16 band_len_ener_shift[]; // Q0 extern const Word16 fine_gain_pred_sqrt_bw[]; // Q11 -#ifndef HARM_HQ_CORE -extern const Word16 ivas_band_len_idx[]; // Q0 -extern const Word16 ivas_band_len_ener_shift[]; // Q0 -extern const Word16 ivas_fine_gain_pred_sqrt_bw[]; // Q11 -#else extern const Word16 fine_gain_pred_sqrt_bw_ext[]; // Q11 extern const Word16 band_len_idx_ext[1 + ( MAX_SFM_LEN_FX * 5 / 4 / 8 )]; // Q11 -#endif extern const Word16 Mean_isf_wb[]; // Q2.56 extern const Word16 lsp_shb_prev_tbl_fx[]; // Q15 extern const Word16 lsp_shb_prev_tbl_swb_tbe_enc_fx[]; // Q15 diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index 57297c3f5..376333284 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -25777,7 +25777,6 @@ const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 15 /* sfm/8= [ 1 2 3 4 6 8 10 12]; */ /* % idx= 0 1 2 3 4 5 6 7; */ /* call with band_len_idx[sfm_size>>3] */ -#ifdef HARM_HQ_CORE const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, 4 /*40*/, 5 /*48 */, -1, 6 /*64 */, -1, 7 /*80*/, -1, 8 /*96*/ @@ -25787,21 +25786,6 @@ const Word16 fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 1418 /* For extended frames in ACELP->HQ transitions in IVAS, map indices floor(sfms*1.25/8)=[1 2 3 5 7 10 12 15] from extended bws: */ const Word16 band_len_idx_ext[1 + ( MAX_SFM_LEN_FX * 5 / 4 / 8 )] = { -1, 0 /*10*/, 1 /*20*/, 2 /*30*/, -1, 3 /*40*/, -1, 4 /*60*/, -1, -1, 5 /*80*/, -1, 6 /*100*/ - 1, -1, 7 /*120*/ }; const Word16 fine_gain_pred_sqrt_bw_ext[9] = { 6476, 9159, 11217, 12953, 15863, 18317, 20480, 22434 }; /* (Q11) */ -#else -const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { - // Q0 - /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ - -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, -1, 4 /*48 */, -1, 5 /*64 */, -1, 6 /*80*/, -1, 7 /*96*/ -}; -const Word16 band_len_ener_shift[8] = { 1, 2, 2, 2, 3, 3, 4 /*sfm==80*/, 4 /*sfm==96*/ }; /* 96 requires 1 bit more than 48 */ // Q0 -/*% sfms=[8,16,24,32,48,64,80,96], round(sqrt(sfms)*2^11) */ -const Word16 fine_gain_pred_sqrt_bw[8] = { 5793, 8192, 10033, 11585, 14189, 16384, 18318, 20066 }; /* (Q11) */ -const Word16 ivas_band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { - /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ - -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, 4 /*40*/, 5 /*48 */, -1, 6 /*64 */, -1, 7 /*80*/, -1, 8 /*96*/ -}; // Q0 -const Word16 ivas_band_len_ener_shift[9] = { 1, 2, 2, 2, 3, 3, 3, 4 /*sfm==80*/, 4 /*sfm==96*/ }; // Q0 /* 96 requires 1 bit more than 48 */ -#endif /*% sfms=[8,16,24,32,40,48,64,80,96], round(sqrt(sfms)*2^11) */ diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 9b7c2424f..b455267be 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -2413,9 +2413,7 @@ void calc_norm_envelop_fx_32( *-------------------------------------------------------------------*/ void hq_generic_decoding_fx( -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif const Word16 HQ_mode, /* i : HQ mode : Q0 */ Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */ const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ @@ -2725,16 +2723,13 @@ void hq_generic_decoding_fx( L_tmp1 = L_deposit_l( 0 ); L_tmp2 = L_deposit_l( 0 ); -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { -#endif FOR( i = 0; i < 5; ++i ) { L_tmp1 = L_add( L_tmp1, L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset + i] ) ); L_tmp2 = L_add( L_tmp2, L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ) ); } -#ifdef HARM_HQ_CORE } ELSE { @@ -2744,7 +2739,6 @@ void hq_generic_decoding_fx( L_tmp2 = L_add( L_tmp2, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ), 3 ) ); // adding guard bits } } -#endif pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset]; L_tmp1 = L_max( L_tmp1, 1 ); @@ -2977,555 +2971,6 @@ void hq_generic_decoding_fx( return; } -#ifndef HARM_HQ_CORE -void hq_generic_decoding_ivas_fx( - const Word16 HQ_mode, /* i : HQ mode : Q0 */ - Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */ - const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ - Word32 *coeff_out_fx, /* o : SWB signal in MDCT domain : Q12 */ - const Word16 hq_generic_offset, /* i : frequency offset for representing hq generci : Q0 */ - Word16 *prev_L_swb_norm, /* i/o: last normalize length : Q0 */ - const Word16 hq_generic_exc_clas, /* i : bwe excitation class " Q0 */ - const Word16 *R ) -{ - Word16 i, n_freq, n_band, L_swb_norm; - Word16 k; - Word16 nenv; - Word16 tenv; - - Word16 exp, exp1, exp2, frac, tmp, tmp2, cs; - Word32 L_tmp, L_tmp1, L_tmp2, max_coeff_fx; - Word16 fenvL_fx, wfenv_fx, factor_fx; - Word32 *pit1_fx; - Word16 tmp1_fx, tmp2_fx, tmp3_fx, tmp4_fx; - Word32 energy_fx; - - Word32 envelope_fx[L_FRAME16k]; - Word32 mean_vector_fx[20]; - Word16 rn_weight0_fx; - Word16 s; - Word16 blen, nband_lf, sfidx, efidx; - Word16 bwe_seed; - Word16 signum[L_FRAME16k]; - - nenv = sub( SWB_FENV, 2 ); - if ( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) - { - nenv = SWB_FENV; - move16(); - } - - tenv = nenv; - move16(); - if ( EQ_16( HQ_mode, HQ_GEN_FB ) ) - { - tenv = add( nenv, DIM_FB ); - } - - max_coeff_fx = 0; - move16(); - tmp = add( swb_bwe_subband[0], hq_generic_offset ); - FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp; n_freq++ ) - { - max_coeff_fx = L_max( max_coeff_fx, L_abs( coeff_out1_fx[n_freq] ) ); - } - cs = norm_l( max_coeff_fx ); - - L_tmp = 0; - move16(); - tmp2 = add( swb_bwe_subband[0], hq_generic_offset ); - FOR( n_freq = add( HQ_GENERIC_ST_FREQ, hq_generic_offset ); n_freq < tmp2; n_freq++ ) - { - tmp = extract_h( L_shl( coeff_out1_fx[n_freq], cs ) ); /*12 + cs - 16 */ - L_tmp1 = L_mult0( tmp, tmp ); /*2*(cs-2) */ - L_tmp = L_add( L_tmp, L_shr( L_tmp1, 5 ) ); /*2*(cs-2) - 5 */ - } - cs = sub( shl( cs, 1 ), 9 ); - fenvL_fx = 0; - move16(); - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - frac = round_fx_sat( L_shl( L_tmp, exp ) ); /*cs+exp-16 */ - tmp = div_s( 16384, frac ); /*15 + 14 - (cs+exp-16) */ - exp = sub( add( cs, exp ), 30 ); - L_tmp = Isqrt_lc( L_deposit_h( tmp ), &exp ); /*Q31 - exp */ - fenvL_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /*Q1 */ - } - - calc_normal_length_fx_32( HQ_CORE, coeff_out1_fx, HQ_GEN_SWB, -1, &L_swb_norm, prev_L_swb_norm ); - - calc_norm_envelop_lf_fx( coeff_out1_fx, envelope_fx, &L_swb_norm, HQ_mode, hq_generic_offset, &sfidx, &efidx ); - - blen = 16; - move16(); - - IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) ) - { - rn_weight0_fx = 819; - move16(); /* 0.8 Q10 */ - } - ELSE IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC1 ) ) - { - rn_weight0_fx = 51; - move16(); /* 0.05 Q10*/ - } - ELSE - { - rn_weight0_fx = 205; - move16(); /* 0.02 Q10 */ - } - - tmp = sub( efidx, sfidx ); - IF( tmp == 0 ) - { - nband_lf = 0; - move16(); - } - ELSE - { - exp = norm_s( tmp ); - nband_lf = shl( tmp, sub( exp, 1 ) ); - exp1 = norm_s( blen ); - tmp = shl( blen, exp1 ); - nband_lf = shr( div_s( nband_lf, tmp ), add( sub( 14, exp1 ), exp ) ); /* 15 + exp-1 - exp1, Q0*/ - } - - FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) - { - IF( coeff_out1_fx[n_freq] < 0 ) - { - signum[n_freq] = -1; - move16(); - coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); - move32(); - } - ELSE - { - signum[n_freq] = 1; - move16(); - } - } - - /* applying whitening */ - FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) - { - exp = norm_l( coeff_out1_fx[n_freq] ) - 1; - exp1 = norm_l( envelope_fx[n_freq] ); - - L_tmp = L_shl( coeff_out1_fx[n_freq], exp ); - L_tmp1 = L_shl( envelope_fx[n_freq], exp1 ); - - logic16(); - coeff_out1_fx[n_freq] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); - move32(); /*31 + exp1 - exp2*/ - - exp = add( 31, sub( exp, exp1 ) ); - coeff_out1_fx[n_freq] = L_shl( coeff_out1_fx[n_freq], sub( 20, exp ) ); - move32(); /*Q12->Q20*/ - } - - /* mean vector generation for controlling dynamic range */ - FOR( k = 0; k < nband_lf; ++k ) - { - energy_fx = 1; - move16(); - - tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); - FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i ) - { - energy_fx = L_add( energy_fx, coeff_out1_fx[i] ); - } - exp = sub( norm_l( energy_fx ), 1 ); - L_tmp = L_shl( energy_fx, exp ); - exp1 = norm_l( L_and( blen, 0x00007fff ) ); - L_tmp1 = L_shl( blen, exp1 ); - logic16(); - mean_vector_fx[k] = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); - move32(); /*31 + 20 + exp1 - exp2*/ - exp = add( 51, sub( exp, exp1 ) ); - mean_vector_fx[k] = L_shl( mean_vector_fx[k], sub( 20, exp ) ); - move32(); /*Q12->Q20*/ - } - - /* dynamics control */ - FOR( k = 0; k < nband_lf; ++k ) - { - tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); - FOR( i = add( i_mult2( k, blen ), sfidx ); i < tmp; ++i ) - { - L_tmp = L_sub( coeff_out1_fx[i], mean_vector_fx[k] ); - exp = norm_l( L_tmp ); - L_tmp = L_shl( L_tmp, exp ); /* exp+12*/ - exp1 = norm_l( rn_weight0_fx ); - L_tmp1 = L_shl( rn_weight0_fx, exp1 ); /* exp1+10*/ - L_tmp = L_mult( extract_h( L_tmp ), extract_h( L_tmp1 ) ); - L_tmp = L_shr( L_tmp, add( exp, sub( exp1, 21 ) ) ); /* Q20*/ - coeff_out1_fx[i] = L_sub( coeff_out1_fx[i], L_tmp ); - move32(); - } - } - - IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_EXC0 ) ) - { - bwe_seed = add( add( shl( R[0], 3 ), shl( R[1], 2 ) ), add( shl( R[2], 1 ), R[3] ) ); - - FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) - { - IF( signum[n_freq] < 0 ) - { - coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); - move32(); - } - - IF( Random( &bwe_seed ) < 0 ) - { - coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); - move32(); - } - } - } - ELSE - { - FOR( n_freq = sfidx; n_freq < efidx; n_freq++ ) - { - IF( signum[n_freq] < 0 ) - { - coeff_out1_fx[n_freq] = L_negate( coeff_out1_fx[n_freq] ); - move32(); - } - } - } - - /* normalizing modified low frequency spectrum */ - FOR( k = 0; k < nband_lf; ++k ) - { - energy_fx = 1; - move16(); - tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); - FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i ) - { - exp = norm_l( coeff_out1_fx[i] ); - L_tmp1 = L_shl( coeff_out1_fx[i], exp ); /* exp + 12*/ - - L_tmp = Mult_32_32( L_tmp1, L_tmp1 ); - L_tmp = L_shr( L_tmp, sub( i_mult2( 2, exp ), 11 ) ); /*Q20 */ - energy_fx = L_add( energy_fx, L_tmp ); - } - - exp = norm_l( energy_fx ); - L_tmp = L_shl( energy_fx, sub( exp, 1 ) ); - exp1 = norm_s( blen ); - L_tmp1 = L_shl( (Word32) blen, add( exp1, 16 ) ); - - L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); - exp = sub( add( 34, exp ), exp1 ); - L_tmp = L_shr( L_tmp, sub( exp, 31 ) ); - exp = 31; - move16(); - - exp = sub( 31, exp ); - IF( exp & 0x1 ) - { - L_tmp = L_shr( L_tmp, 1 ); - exp = add( exp, 1 ); - } - L_tmp = Sqrt_l( L_tmp, &exp1 ); - exp = add( 31, sub( shr( exp1, 1 ), shr( exp, 1 ) ) ); - energy_fx = L_shl( L_tmp, sub( 31, exp ) ); /*Q31*/ - - tmp = add( i_mult2( add( k, 1 ), blen ), sfidx ); - FOR( i = add( ( i_mult2( k, blen ) ), sfidx ); i < tmp; ++i ) - { - IF( NE_32( L_abs( coeff_out1_fx[i] ), coeff_out1_fx[i] ) ) - { - s = -1; - move16(); - coeff_out1_fx[i] = L_abs( coeff_out1_fx[i] ); - move32(); - } - ELSE - { - s = 0; - move16(); - } - exp = norm_l( coeff_out1_fx[i] ); - L_tmp = L_shl( coeff_out1_fx[i], sub( exp, 1 ) ); - exp1 = norm_l( energy_fx ); - L_tmp1 = L_shl( (Word32) energy_fx, exp1 ); - logic16(); - L_tmp = Div_32( L_tmp, extract_h( L_tmp1 ), extract_l( L_shr( L_tmp1, 1 ) ) & 0x00007fff ); - exp = add( sub( 19, exp1 ), exp ); - coeff_out1_fx[i] = L_shl( L_tmp, add( sub( 12, exp ), 15 ) ); - move32(); /* Q12 -> Q27 */ - IF( s ) - { - coeff_out1_fx[i] = L_negate( coeff_out1_fx[i] ); - move32(); - } - } - } - - Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH0 + hq_generic_offset], HQ_GENERIC_LEN0 ); - Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET], &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset], HQ_GENERIC_LEN0 ); - - IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) - { - Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0], &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset], HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2 ); - } - - IF( EQ_16( HQ_mode, HQ_GEN_FB ) ) - { - IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) - { - Copy32( &coeff_out1_fx[HQ_GENERIC_LOW0 + HQ_GENERIC_END_FREQ - HQ_GENERIC_HIGH2], &coeff_out_fx[fb_bwe_subband[0]], 160 ); - } - ELSE - { - Copy32( &coeff_out1_fx[HQ_GENERIC_OFFSET + HQ_GENERIC_LEN0], &coeff_out_fx[fb_bwe_subband[0]], 160 ); - } - } - - - L_tmp1 = L_deposit_l( 0 ); - L_tmp2 = L_deposit_l( 0 ); - FOR( i = 0; i < 5; ++i ) - { - L_tmp1 = L_add( L_tmp1, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset + i] ), 3 ) ); // adding guard bits - L_tmp2 = L_add( L_tmp2, L_shr( L_abs( coeff_out_fx[HQ_GENERIC_HIGH1 - 2 + hq_generic_offset - i] ), 3 ) ); // adding guard bits - } - - pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset]; - L_tmp1 = L_max( L_tmp1, 1 ); - L_tmp2 = L_max( L_tmp2, 1 ); - exp1 = norm_l( L_tmp1 ); - exp2 = sub( norm_l( L_tmp2 ), 1 ); - tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); - tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); - tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ - - if ( LT_16( tmp3_fx, 307 /*0.3 in Q10 */ ) ) - { - tmp3_fx = 307 /*0.3 in Q10 */; - move16(); - } - FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) - { - *pit1_fx = Mult_32_16( *pit1_fx, shl( tmp3_fx, 5 ) ); - move32(); /*15 + 5 + 10 -15 */ - pit1_fx++; - } - - pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 - 1 + hq_generic_offset]; - - exp1 = sub( norm_l( L_tmp1 ), 1 ); - exp2 = norm_l( L_tmp2 ); - tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); - tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); - tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */ - - IF( GT_16( tmp3_fx, 5120 ) ) - { - FOR( tmp3_fx = 5120; tmp3_fx > 1024; tmp3_fx -= 512 ) - { - /* Adding saturation suggested as fix for issue #957 */ - L_tmp1 = L_shl_sat( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ - *pit1_fx-- = L_tmp1; - move32(); - } - } - - IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) - { - L_tmp1 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 + 1 + hq_generic_offset] ) ); - L_tmp2 = L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 4 + hq_generic_offset] ), L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 3 + hq_generic_offset] ), - L_add( L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 2 + hq_generic_offset] ), L_abs( coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset] ) ) ) ); - - pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 + hq_generic_offset]; - - L_tmp1 = L_max( L_tmp1, 1 ); - L_tmp2 = L_max( L_tmp2, 1 ); - exp1 = norm_l( L_tmp1 ); - exp2 = sub( norm_l( L_tmp2 ), 1 ); - tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); - tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); - tmp3_fx = div_s( tmp2_fx, tmp1_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr_sat( tmp3_fx, add( 5, sub( exp2, exp1 ) ) ); /*10 */ - if ( LT_16( tmp3_fx, 307 /* 0.3 in Q10*/ ) ) - { - tmp3_fx = 307; /* 0.3 in Q10*/ - move16(); - } - FOR( ; tmp3_fx < 1024; tmp3_fx += 102 ) - { - L_tmp = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ - *pit1_fx++ = L_tmp; - move32(); - } - - pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH2 - 1 + hq_generic_offset]; - - exp1 = sub( norm_l( L_tmp1 ), 1 ); - exp2 = norm_l( L_tmp2 ); - tmp1_fx = extract_h( L_shl( L_tmp1, exp1 ) ); - tmp2_fx = extract_h( L_shl( L_tmp2, exp2 ) ); - tmp3_fx = div_s( tmp1_fx, tmp2_fx ); /*15 + exp2 + 15 - (exp1 + 15) */ - tmp3_fx = shr( tmp3_fx, add( 5, sub( exp1, exp2 ) ) ); /*10 */ - tmp3_fx = shr( tmp3_fx, 1 ); - tmp4_fx = mult_r( tmp3_fx, 1638 /* 0.05 in Q15 */ ); - WHILE( tmp3_fx > 1024 /* 1 in Q10*/ ) - { - L_tmp1 = L_shl( Mult_32_16( *pit1_fx, tmp3_fx ), 5 ); /*15 + 5 + 10 -15 */ - *pit1_fx-- = L_tmp1; - move32(); - tmp3_fx = sub( tmp3_fx, tmp4_fx ); - } - } - - - wfenv_fx = hq_generic_fenv_fx[0]; - move16(); /*1 */ - i = 0; - move16(); - tmp2 = add( add( swb_bwe_subband[0], hq_generic_offset ), 8 ); - FOR( n_freq = add( swb_bwe_subband[0], hq_generic_offset ); n_freq < tmp2; n_freq++ ) - { - factor_fx = shl( i, 12 ); /*15 */ - L_tmp1 = L_mult( sub( 32767, factor_fx ), fenvL_fx ); /*17 */ - L_tmp2 = L_mult( factor_fx, wfenv_fx ); /*17 */ - L_tmp1 = L_add( L_tmp1, L_tmp2 ); /*17 */ - - cs = norm_l( L_tmp1 ); - tmp = extract_h( L_shl( L_tmp1, cs ) ); /*17 + cs - 16 */ - L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 17 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shr( L_tmp, add( 1, cs ) ); - move32(); /*12 */ - i++; - move16(); - } - - k = sub( nenv, 2 ); - FOR( n_band = 0; n_band < k; n_band++ ) - { - wfenv_fx = hq_generic_fenv_fx[n_band + 1]; - move16(); /*1 */ - - tmp2 = swb_bwe_sm_subband[n_band + 1] + hq_generic_offset; - FOR( i = 0; n_freq < tmp2; i++ ) - { - L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band] ), smooth_factor_fx[n_band] ); /*17 */ - L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ - L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band], 11 ) ); /*12 */ - - cs = norm_l( L_tmp1 ); - tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */ - L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) ); - move32(); /*12 */ - n_freq++; - } - } - - wfenv_fx = hq_generic_fenv_fx[nenv - 1]; - move16(); /*1 */ - tmp2 = add( swb_bwe_sm_subband[nenv - 1], hq_generic_offset ); - FOR( i = 0; n_freq < tmp2; i++ ) - { - L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[nenv - 2] ), smooth_factor_fx[nenv - 2] ); /*17 */ - L_tmp1 = Mult_32_16( L_tmp1, shl( i, 10 ) ); /*17 + 10 - 15 */ - L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[nenv - 2], 11 ) ); /*12 */ - - cs = norm_l( L_tmp1 ); - tmp = extract_h( L_shl( L_tmp1, cs ) ); /*12 + cs - 16 */ - L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 12 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 4, cs ) ); - move32(); /*12 */ - n_freq++; - } - - IF( EQ_16( HQ_mode, HQ_GEN_SWB ) ) - { - FOR( n_band = sub( nenv, 1 ); n_band < nenv; ++n_band ) - { - wfenv_fx = hq_generic_fenv_fx[n_band]; - move16(); /*1 */ - tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); - FOR( ; n_freq < tmp2; n_freq++ ) - { - L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); - move32(); /*12 */ - } - } - } - ELSE - { - test(); - IF( GT_16( sub( hq_generic_fenv_fx[nenv - 1], hq_generic_fenv_fx[nenv] ), 30 ) || LT_16( hq_generic_fenv_fx[nenv], 10 ) ) - { - wfenv_fx = hq_generic_fenv_fx[nenv - 1]; - move16(); /*1 */ - FOR( i = 0; n_freq < fb_bwe_subband[0]; i++ ) - { - L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); - move32(); /*12 */ - n_freq++; - } - - FOR( n_band = 0; n_band < DIM_FB; n_band++ ) - { - wfenv_fx = hq_generic_fenv_fx[n_band + nenv]; - move16(); /*1 */ - tmp2 = fb_bwe_subband[n_band + 1]; - FOR( i = 0; n_freq < tmp2; i++ ) - { - L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); - move32(); /*12 */ - n_freq++; - } - } - } - ELSE - { - FOR( n_band = 0; n_band < DIM_FB; n_band++ ) - { - wfenv_fx = hq_generic_fenv_fx[n_band + nenv - 1]; - move16(); /*1 */ - - FOR( i = 0; n_freq < fb_bwe_sm_subband[n_band]; i++ ) - { - L_tmp1 = L_mult( sub( wfenv_fx, hq_generic_fenv_fx[n_band + nenv] ), fb_smooth_factor_fx[n_band] ); /*17 */ - L_tmp1 = Mult_32_16( L_tmp1, shl( i, 9 ) ); /*17 + 9 - 15 */ - L_tmp1 = L_add( L_tmp1, L_shl( hq_generic_fenv_fx[n_band + nenv], 10 ) ); /*11 */ - - cs = norm_l( L_tmp1 ); - tmp = extract_h( L_shl( L_tmp1, cs ) ); /*11 + cs - 16 */ - L_tmp = Mult_32_16( coeff_out_fx[n_freq], tmp ); /*12 + 15 + 11 + cs - 16 - 15 */ - coeff_out_fx[n_freq] = L_shl( L_tmp, sub( 5, cs ) ); - move32(); /*12 */ - n_freq = add( n_freq, 1 ); - } - } - - wfenv_fx = hq_generic_fenv_fx[tenv - 1]; - move16(); /*1 */ - - FOR( ; n_freq < fb_bwe_subband[DIM_FB]; n_freq++ ) - { - L_tmp = Mult_32_16( coeff_out_fx[n_freq], wfenv_fx ); /*15 + 12 + 1 - 15 */ - coeff_out_fx[n_freq] = L_shr( L_tmp, 1 ); - move32(); /*12 */ - } - } - } - - return; -} -#endif /*-------------------------------------------------------------------* * save_old_syn() diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 159324461..b76037653 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -68,22 +68,10 @@ static void windowing( const Word16 *, Word16 *, const Word16 *, const Word16, c static void windowing_ROM_optimized( const Word16 *, Word16 *, const Word16, const Word16, const Word16 ); static void fft_spec2_fx( const Word16[], Word32[], const Word16 ); static void trans_ana_fx( const Word16 *, Word16 *, Word16 *, Word16 *, const Word16, const Word16, const Word16, const Word16, const Word16, Word16 *, Word16 *, Word16 *, Word16 * ); -#ifdef HARM_HQ_CORE static void peakfinder_fx( const Word16 *x0, const Word16 len0, Word16 *plocs, Word16 *cInd, const Word16 sel, const Word16 endpoints ); -#else -static void peakfinder_fx( const Word16 *, const Word16, Word16 *, Word16 *, const Word16 ); -#endif static Word16 imax_fx( const Word16 *, const Word16 ); -#ifdef HARM_HQ_CORE static void spec_ana_fx( const Word16 *prevsynth, Word16 *plocs, Word32 *plocsi, Word16 *num_plocs, Word16 *X_sav, const Word16 output_frame, const Word16 bwidth_fx, Word16 *Q, const Word16 element_mode, Word16 *noise_fac, const Word16 pcorr ); -#else -static void spec_ana_fx( const Word16 *prevsynth, Word16 *plocs, Word32 *plocsi, Word16 *num_plocs, Word16 *X_sav, const Word16 output_frame, const Word16 bwidth_fx, Word16 *Q ); -#endif -#ifdef HARM_HQ_CORE static void subst_spec_fx( const Word16 *plocs, const Word32 *plocsi, Word16 *num_plocs, const Word16 time_offs, Word16 *X, const Word16 *mag_chg, const Word16 ph_dith, const Word16 *is_trans, const Word16 output_frame, Word16 *seed, const Word16 *alpha, const Word16 *beta, Word16 beta_mute, const Word16 *Xavg, const Word16 element_mode, const Word16 ph_ecu_lookahead, const Word16 noise_fac ); -#else -static void subst_spec_fx( const Word16 *, const Word32 *, Word16 *, const Word16, Word16 *, const Word16 *, const Word16, const Word16 *, const Word16, Word16 *, const Word16 *, const Word16 *, Word16, const Word16 * ); -#endif static Word16 rand_phase_fx( const Word16 seed, Word16 *sin_F, Word16 *cos_F ); @@ -639,11 +627,7 @@ static void trans_ana_fx( * Peak-picking algorithm *----------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE static void peakfinder_fx( -#else -static void ivas_peakfinder_fx( -#endif const Word16 *x0, /* i : vector from which the maxima will be found */ const Word16 len0, /* i : length of input vector */ Word16 *plocs, /* o : the indices of the identified peaks in x0 Q0 */ @@ -935,373 +919,108 @@ static void ivas_peakfinder_fx( return; } -#ifndef HARM_HQ_CORE -static void peakfinder_fx( - const Word16 *x0, /* i : vector from which the maxima will be found */ - const Word16 len0, /* i : length of input vector */ - Word16 *plocs, /* o : the indices of the identified peaks in x0 Q0 */ - Word16 *cInd, /* o : number of identified peaks Q0 */ - const Word16 sel /* i : The amount above surrounding data for a peak to be identified */ + +/*----------------------------------------------------------------------------- + * imax_fx() + * + * Get interpolated maximum position + *-----------------------------------------------------------------------------*/ + +/* o: The location, relative to the middle of the 3 given data point, of the maximum. (Q15) */ +static Word16 imax_fx( + const Word16 *y, /* i : The 3 given data points. */ + const Word16 special /* i : -1 = left edge special case, 0 = normal, +1 = right edge special case */ ) { - const Word16 *pX0; - Word16 minMag, tempMag, leftMin; - Word16 dx0[L_PROT48k_2], x[L_PROT48k_2 + 1], peakMag[MAX_PLOCS]; - Word16 *pDx0, *pDx01, *pX; - Word16 i, len, tempLoc, foundPeak, ii, xInd, tmp16, threshold, xAt0, xAt1, xAt2; - Word16 len0Minus1, len0Minus2, lenMinus1; - Word16 indarr[L_PROT48k_2 + 1], peakLoc[MAX_PLOCS]; - Word16 *pInd; - - tempLoc = 0; + Word16 posi; + Word16 y1, y2, y3, man, expo, edge; + const Word16 *pY; + Word32 numer, denom, sign, acc, y3_y1; + /* Seek the extremum of the parabola P(x) defined by 3 consecutive points + so that P([-1 0 1]) = [y1 y2 y3] */ + pY = y; + y1 = *pY++, y2 = *pY++, y3 = *pY; + move16(); + move16(); move16(); - /* Find derivative */ - len0Minus1 = sub( len0, 1 ); - pX0 = x0 + 1; - Vr_subt( pX0, x0, dx0, len0Minus1 ); - - FOR( i = 0; i < len0Minus1; i++ ) - { - if ( dx0[i] == 0 ) - { - dx0[i] = -1; - move16(); - } - } + /* The extremum value: + * y2i = -0.125f * SQR(y3_y1) / (y1+y3-2*y2)+y2 + * is not computed. Alternatively, the derivative of the parabola evaluated at y=0, + * dP/dy|y=0, is used to determine whether the extremum is maximum or not. + */ - /* Find where the derivative changes sign - Include endpoints in potential peaks and valleys */ - pX = x; - pX0 = x0; - pInd = indarr; - pDx01 = dx0; - pDx0 = pDx01 + 1; + /* Compute the extremum location: posi = (y3 - y1)/(4*y2 - 2*y1 - 2*y3). */ + y3_y1 = L_sub( y3, y1 ); + acc = L_shl( y2, 1 ); /* N.B. y2 is multiplied by 2 not 4. */ + acc = L_sub( acc, y1 ); /* N.B. Y1 is not multiplied by 2. */ + denom = L_sub( acc, y3 ); /* N.B. Y3 is not multiplied by 2. */ + sign = L_xor( y3_y1, denom ); /* Preserve the sign since div_s() only takes positive arguments. */ + numer = L_abs( y3_y1 ); + denom = L_abs( denom ); + IF( numer == 0 ) { - *pX++ = *pX0++; - move16(); - *pInd++ = 0; - move16(); - len = 2; - move16(); + return 0; } - len0Minus2 = sub( len0, 2 ); - - FOR( i = 0; i < len0Minus2; i++ ) + IF( denom == 0 ) { - IF( s_xor( *pDx01++, *pDx0++ ) < 0 ) /* Detect sign change. */ - { - *pInd++ = add( i, 1 ); - move16(); - *pX++ = *pX0; - move16(); - len = add( len, 1 ); - } - pX0++; + return 0; } + /* Although the output of ratio() is in Q14, adding the missing factor of 2 (See above) + * in the denominator, the output is now considered to be in Q15. */ + man = ratio( numer, denom, &expo ); /* The mantissa is considered in Q15 */ + posi = shr_sat( man, expo ); /* in Q15 (Due to saturation, it is automatically bound inside [-1.0,1.0].) */ + if ( sign < 0 ) /* Restore the sign. */ { - *pInd = len0Minus1; - move16(); - *pX = *pX0; - move16(); + posi = negate( posi ); } - /* x[] only has the peaks, valleys, and endpoints */ - minimum_fx( x, len, &minMag ); - pInd = indarr; - IF( GT_16( len, 2 ) ) + /* For both edges (left and right), the extremum found above may be minimum. + * It needs to reject the minimum. */ + IF( special != 0 ) /* Either edge specical case. */ { - /* Set initial parameters for loop */ - tempMag = minMag; - move16(); - foundPeak = 0; - move16(); - leftMin = minMag; + edge = 0x7fff; /* 1 in Q15 for the right edge special case */ move16(); - threshold = add( leftMin, sel ); - + if ( special < 0 ) { - /* Deal with first point a little differently since tacked it on - Calculate the sign of the derivative since we took the first point - on it does not necessarily alternate like the rest. */ - - /* The first point is larger or equal to the second */ - pX = x; - xAt0 = *pX++; - move16(); - xAt1 = *pX++; - move16(); - xAt2 = *pX--; /* After decrement, pX points to x[1]. */ + edge = 0; /* Left edge special case */ move16(); - IF( GE_16( xAt0, xAt1 ) ) + } + + /* The derivative (slope) of the interpolating parabola = 2*A*y + B, + * where A = (y3 + y1)/2 - y2 + * and B = (y3 - y1)/2. + * Therefore, the slope at y=0 is simply B. Use this slope to determine + * if the parabola is concave upward or downward. + */ + IF( posi > 0 ) /* The extremum is in between the middle and the right given data points. */ + { + IF( LE_16( y3, y1 ) ) /* Check the slope at y=0, i.e., at the middle given data point. */ { - ii = -1; + posi = edge; /* minimum case */ move16(); - IF( GE_16( xAt1, xAt2 ) ) /* x[1] is not extremum -> overwrite with x[0] */ - { - *pX = xAt0; /* x[1] = x[0] */ - move16(); - tmp16 = *pInd++; - move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ - move16(); - len = sub( len, 1 ); - } - pX--; /* After decrement, pX points to x[0]. */ } - ELSE /* First point is smaller than the second */ + ELSE { - ii = 0; - move16(); - IF( LT_16( xAt1, xAt2 ) ) /* x[1] is not extremum -> overwrite with x[0] */ - { - *pX = xAt0; /* x[1] = x[0] */ - move16(); - tmp16 = *pInd++; - move16(); - *pInd++ = tmp16; /* ind[1] = ind[0] */ - move16(); - len = sub( len, 1 ); - } + posi = sub( 0x7fff, posi ); /* maximum case */ } - pX--; /* After decrement, pX points to either x[-1] or x[0]. */ } - *cInd = 0; - move16(); - /*Loop through extrema which should be peaks and then valleys*/ - lenMinus1 = sub( len, 1 ); - FOR( ;; ) + ELSE /* The extremum is in between the left and the middle given data points. */ { - ii = add( ii, 1 ); /* This is a peak */ - - /* Make sure we don't iterate past the length of our vector */ - IF( GE_16( ii, lenMinus1 ) ) - { - BREAK; - } - - /*Reset peak finding if we had a peak and the next peak is bigger - than the last or the left min was small enough to reset.*/ - IF( foundPeak > 0 ) + IF( GE_16( y3, y1 ) ) { - tempMag = minMag; - move16(); - foundPeak = 0; + posi = edge; /* minimum case */ move16(); } - - /* Found new peak that was larger than temp mag and selectivity larger - than the minimum to its left. */ - IF( GT_16( *( ++pX ), tempMag ) ) + ELSE { - IF( GT_16( *pX, threshold ) ) /* threshold = leftMin + sel */ - { - tempLoc = ii; - move16(); - tempMag = *pX; - move16(); - } + posi = add( 0x7fff, posi ); /* maximum case */ } + } + } - ii = add( ii, 1 ); /* Move onto the valley */ - pX++; - - /* Come down at least sel from peak */ - IF( foundPeak == 0 ) - { - IF( GT_16( tempMag, add( sel, *pX ) ) ) - { - foundPeak = 1; /* We have found a peak */ - move16(); - leftMin = *pX; - move16(); - threshold = add( leftMin, sel ); - peakLoc[*cInd] = tempLoc; /* Add peak to index */ - move16(); - peakMag[*cInd] = tempMag; - move16(); - *cInd = add( *cInd, 1 ); - move16(); - } - } - IF( foundPeak == 0 ) /* The above IF-block has not found the peak yet. */ - { - IF( LT_16( *pX, leftMin ) ) /* New left minimum */ - { - leftMin = *pX; - move16(); - threshold = add( leftMin, sel ); - } - } - } - - /* Check end point */ - IF( GT_16( x[lenMinus1], tempMag ) ) - { - IF( GT_16( x[lenMinus1], threshold ) ) /* threshold = leftMin + sel */ - { - peakLoc[*cInd] = lenMinus1; - move16(); - peakMag[*cInd] = x[lenMinus1]; - move16(); - *cInd = add( *cInd, 1 ); - foundPeak = 1; - move16(); - } - } - IF( foundPeak == 0 ) /* Check if we still need to add the last point */ - { - IF( GT_16( tempMag, minMag ) ) - { - peakLoc[*cInd] = tempLoc; - move16(); - peakMag[*cInd] = tempMag; - move16(); - *cInd = add( *cInd, 1 ); - move16(); - } - } - - /* Create output */ - FOR( i = 0; i < *cInd; i++ ) - { - plocs[i] = *( indarr + peakLoc[i] ); - move16(); - } - } - ELSE /* This is a monotone function where an endpoint is the only peak */ - { - { - xInd = 1; - move16(); - if ( GT_16( x[0], x[1] ) ) - { - xInd = 0; - move16(); - } - - peakMag[0] = x[xInd]; - move16(); - IF( GT_16( peakMag[0], add( minMag, sel ) ) ) - { - plocs[0] = *( indarr + xInd ); - move16(); - *cInd = 1; - move16(); - } - ELSE - { - *cInd = 0; - move16(); - } - } - } - - return; -} -#endif - -/*----------------------------------------------------------------------------- - * imax_fx() - * - * Get interpolated maximum position - *-----------------------------------------------------------------------------*/ - -/* o: The location, relative to the middle of the 3 given data point, of the maximum. (Q15) */ -static Word16 imax_fx( - const Word16 *y, /* i : The 3 given data points. */ - const Word16 special /* i : -1 = left edge special case, 0 = normal, +1 = right edge special case */ -) -{ - Word16 posi; - Word16 y1, y2, y3, man, expo, edge; - const Word16 *pY; - Word32 numer, denom, sign, acc, y3_y1; - /* Seek the extremum of the parabola P(x) defined by 3 consecutive points - so that P([-1 0 1]) = [y1 y2 y3] */ - pY = y; - y1 = *pY++, y2 = *pY++, y3 = *pY; - move16(); - move16(); - move16(); - - /* The extremum value: - * y2i = -0.125f * SQR(y3_y1) / (y1+y3-2*y2)+y2 - * is not computed. Alternatively, the derivative of the parabola evaluated at y=0, - * dP/dy|y=0, is used to determine whether the extremum is maximum or not. - */ - - /* Compute the extremum location: posi = (y3 - y1)/(4*y2 - 2*y1 - 2*y3). */ - y3_y1 = L_sub( y3, y1 ); - acc = L_shl( y2, 1 ); /* N.B. y2 is multiplied by 2 not 4. */ - acc = L_sub( acc, y1 ); /* N.B. Y1 is not multiplied by 2. */ - denom = L_sub( acc, y3 ); /* N.B. Y3 is not multiplied by 2. */ - sign = L_xor( y3_y1, denom ); /* Preserve the sign since div_s() only takes positive arguments. */ - numer = L_abs( y3_y1 ); - denom = L_abs( denom ); - IF( numer == 0 ) - { - return 0; - } - IF( denom == 0 ) - { - return 0; - } - /* Although the output of ratio() is in Q14, adding the missing factor of 2 (See above) - * in the denominator, the output is now considered to be in Q15. */ - man = ratio( numer, denom, &expo ); /* The mantissa is considered in Q15 */ - posi = shr_sat( man, expo ); /* in Q15 (Due to saturation, it is automatically bound inside [-1.0,1.0].) */ - if ( sign < 0 ) /* Restore the sign. */ - { - posi = negate( posi ); - } - - /* For both edges (left and right), the extremum found above may be minimum. - * It needs to reject the minimum. */ - IF( special != 0 ) /* Either edge specical case. */ - { - edge = 0x7fff; /* 1 in Q15 for the right edge special case */ - move16(); - if ( special < 0 ) - { - edge = 0; /* Left edge special case */ - move16(); - } - - /* The derivative (slope) of the interpolating parabola = 2*A*y + B, - * where A = (y3 + y1)/2 - y2 - * and B = (y3 - y1)/2. - * Therefore, the slope at y=0 is simply B. Use this slope to determine - * if the parabola is concave upward or downward. - */ - IF( posi > 0 ) /* The extremum is in between the middle and the right given data points. */ - { - IF( LE_16( y3, y1 ) ) /* Check the slope at y=0, i.e., at the middle given data point. */ - { - posi = edge; /* minimum case */ - move16(); - } - ELSE - { - posi = sub( 0x7fff, posi ); /* maximum case */ - } - } - ELSE /* The extremum is in between the left and the middle given data points. */ - { - IF( GE_16( y3, y1 ) ) - { - posi = edge; /* minimum case */ - move16(); - } - ELSE - { - posi = add( 0x7fff, posi ); /* maximum case */ - } - } - } - - return posi; /* Q15. The position either left or right relative to the index of the middle of the 3 given data points. */ -} + return posi; /* Q15. The position either left or right relative to the index of the middle of the 3 given data points. */ +} /*----------------------------------------------------------------------------- @@ -1310,11 +1029,7 @@ static Word16 imax_fx( * Spectral analysis *-----------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE static void spec_ana_fx( -#else -static void ivas_spec_ana_fx( -#endif const Word16 *prevsynth, /* i : Input signal */ Word16 *plocs, /* o : The indicies of the identified peaks Q0 */ Word32 *plocsi, /* o : Interpolated positions of the identified peaks Q16 */ @@ -1505,11 +1220,7 @@ static void ivas_spec_ana_fx( sel = mult_r( sub( Xmax, Xmin ), CMPLMNT_ST_PFIND_SENS_FX ); } -#ifdef HARM_HQ_CORE peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel, TRUE ); -#else - ivas_peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel, TRUE ); -#endif /* Currently not the pitch correlation but some LF correlation */ if ( element_mode != EVS_MONO && *num_plocs > 50 && pcorr < 19661 /* 0.6f in Q15 */ ) @@ -1693,289 +1404,90 @@ static void ivas_spec_ana_fx( return; } -#ifndef HARM_HQ_CORE -static void spec_ana_fx( - const Word16 *prevsynth, /* i : Input signal */ - Word16 *plocs, /* o : The indicies of the identified peaks Q0 */ - Word32 *plocsi, /* o : Interpolated positions of the identified peaks Q16 */ - Word16 *num_plocs, /* o : Number of identified peaks Q0 */ - Word16 *X_sav, /* o : Stored fft spectrum */ - const Word16 output_frame, /* i : Frame length Q0 */ - const Word16 bwidth_fx, /* i : Encoded bandwidth index Q0 */ - Word16 *Q /* o : Q value of the fft spectrum */ + +/*-------------------------------------------------------------------* + * subst_spec_fx() + * + * Substitution spectrum calculation + *-------------------------------------------------------------------*/ + +static void subst_spec_fx( + const Word16 *plocs, /* i : The indices of the identified peaks Q0 */ + const Word32 *plocsi, /* i : Interpolated positions of the identified peaks Q16 */ + Word16 *num_plocs, /* i/o : Number of identified peaks Q0 */ + const Word16 time_offs, /* i : Time offset Q0 */ + Word16 *X, /* i/o : FFT spectrum */ + const Word16 *mag_chg, /* i : Magnitude modification Q15 */ + const Word16 ph_dith, /* i : Phase dither, 2*PI is not included. (Q15, i.e., between 0.0 and 1.0) */ + const Word16 *is_trans, /* i : Transient flags (either 0 or 1) */ + const Word16 output_frame, /* i : Frame length Q0 */ + Word16 *seed, /* i/o : Random seed */ + const Word16 *alpha, /* i : Magnitude modification factors for fade to average Q15 */ + const Word16 *beta, /* i : Magnitude modification factors for fade to average Q15 */ + Word16 beta_mute, /* i : Factor for long-term mute Q15 */ + const Word16 *Xavg, /* i : Frequency group averages to fade to Q0 */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 ph_ecu_lookahead, /* i : Phase ECU lookahead */ + const Word16 noise_fac /* i : noise factor Q15 */ ) { - Word16 Lprot, LprotLog2Minus1, hamm_len2, Lprot2, Lprot2_1, m, n; - const Word16 *pFftTbl = NULL; - Word16 xfp[L_PROT48k]; - Word32 magSq[L_PROT48k / 2 + 1], *pMagSq; - Word16 *pXfp, *pXfp1, *pXsav, *pPlocs; - Word16 Xmax, Xmin, sel, man, expo, expoBy2; - Word16 sinTblOffset, rectLength, fraction, special; - Word32 *pPlocsi; + Word16 Xph_short; + Word32 corr_phase[MAX_PLOCS], Xph; + Word32 *pCorrPhase; + Word16 cos_F, sin_F, tmp; + Word16 Lprot, m, i, e, im_ind, delta_corr_up, delta_corr_dn, delta_tmp; + Word32 tmp1; + Word16 j, re, im, *pReX, *pImX, lastPeak, lprotBy2Minus1, segmentLen; + Word16 pkLocation_1, pkLocation, pkLocation1; + const Word16 *pPlocs; + const Word32 *pPlocsi; Word32 acc; - Word16 stop_band_start; - Word16 stop_band_length; + Word16 Lecu; + Word16 Lprot_inv; + Word16 k; + Word16 tmp2; + Word16 alpha_local; + Word16 beta_local; + Word16 expo; + Word16 one_peak_flag_mask; + Word16 mag_chg_local; /*for peak attenuation in burst */ - LprotLog2Minus1 = 0; - hamm_len2 = 0; - move16(); // LprotLog2Minus1 - move16(); // hamm_len2 - Lprot = 512; /* 1536=(2*output_frame)*1024/1280; */ + Lprot = 512; move16(); - - sinTblOffset = 0; + Lprot_inv = 8192; move16(); + Lecu = shl( output_frame, 1 ); IF( EQ_16( output_frame, L_FRAME48k ) ) { Lprot = L_PROT48k; /* 1536=(2*output_frame)*1024/1280; */ move16(); - hamm_len2 = L_PROT_HAMM_LEN2_48k; /* half Hamming window = 288 */ + Lprot_inv = 2731; /* Q22 */ move16(); } ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) { Lprot = L_PROT32k; /* 1024 */ move16(); - sinTblOffset = 4; - move16(); - hamm_len2 = L_PROT_HAMM_LEN2_32k; /* half Hamming window = 192 */ - move16(); - pFftTbl = FFT_W512; /* Table for 1024-point real input FFT */ - LprotLog2Minus1 = 9; /* FFT stages for complex input FFT */ + Lprot_inv = 4096; /* Q22 */ move16(); } ELSE { Lprot = 512; move16(); - sinTblOffset = 8; - move16(); - hamm_len2 = L_PROT_HAMM_LEN2_16k; /* half Hamming window = 96 */ - move16(); - pFftTbl = FFT_W256; /* Table for 512-point real input FFT */ - LprotLog2Minus1 = 8; /* FFT stages for complex input FFT */ + Lprot_inv = 8192; /* Q22 */ move16(); } - Lprot2 = shr( Lprot, 1 ); - Lprot2_1 = add( Lprot2, 1 ); - rectLength = sub( Lprot, shl( hamm_len2, 1 ) ); /* The length of the rectangular portion of the Hamming-Rectangular window. */ - - *Q = s_max( 0, sub( Exp16Array( Lprot, prevsynth ), 1 ) ); - move16(); - Copy_Scale_sig( prevsynth, xfp, Lprot, *Q ); - - IF( EQ_16( output_frame, L_FRAME48k ) ) - { - /* Apply hamming-rect window */ - { - windowing( xfp, xfp, w_hamm_sana48k_2_fx, rectLength, hamm_len2 ); - } - /* Spectrum */ - fft3_fx( xfp, xfp, Lprot ); - } - ELSE - { - { - /* Apply hamming-rect window */ - windowing_ROM_optimized( xfp, xfp, sinTblOffset, rectLength, hamm_len2 ); - } - /* Spectrum */ - r_fft_fx_lc( pFftTbl, Lprot, Lprot2, LprotLog2Minus1, xfp, xfp, 1 ); - } - - /* Apply zeroing of non-coded FFT spectrum */ - IF( GT_16( output_frame, inner_frame_tbl[bwidth_fx] ) ) - { - stop_band_start = shl( 128, bwidth_fx ); - stop_band_length = sub( Lprot, shl( stop_band_start, 1 ) ); - stop_band_start = add( stop_band_start, 1 ); - set16_fx( xfp + stop_band_start, 0, stop_band_length ); - } - - pXfp = xfp; - pXsav = X_sav; - FOR( m = 0; m < Lprot; m++ ) - { - *pXsav++ = *pXfp++; - move16(); - } - - /* Magnitude representation */ - fft_spec2_fx( xfp, magSq, Lprot ); - - /* Compute xfp[m] = sqrt(magSq[m]) */ - pXfp = xfp; - pMagSq = magSq; - FOR( m = 0; m < Lprot2_1; m++ ) - { - IF( *pMagSq == 0 ) - { - *pXfp++ = extract_l( *pMagSq++ ); /* magSq[] is zero */ - } - ELSE - { - expo = norm_l( *pMagSq ); /* exponent */ - man = extract_h( L_shl( *pMagSq++, expo ) ); /* mantissa */ - man = sqrt2ndOrder( man ); - expoBy2 = shr( expo, 1 ); /* Divided by 2-- square root operation. */ - IF( s_and( expo, 1 ) == 0 ) /* Check even or odd. */ - { - man = mult_r( man, FEC_HQ_ECU_ROOT2 ); /* FEC_HQ_ECU_ROOT2 is sqrt(2) in Q14 */ - expoBy2 = sub( expoBy2, 1 ); - } - *pXfp++ = shr_sat( man, expoBy2 ); - move16(); /* Denormalize the mantissa back to Q0. */ - } - } - - /* Find maximum and minimum. */ - maximum_fx( xfp, Lprot2_1, &Xmax ); - minimum_fx( xfp, Lprot2_1, &Xmin ); - { - sel = mult_r( sub( Xmax, Xmin ), CMPLMNT_PFIND_SENS_FX ); - } - - peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel ); - - { - /* Refine peaks */ - pPlocsi = plocsi; - pPlocs = plocs; - n = sub( *num_plocs, 1 ); /* -1 so as to exclude the very last peak. */ - /* Special case-- The very 1st peak if it is at 0 index position */ - IF( *pPlocs == 0 ) /* Only the very 1st peak is possible the peak at 0 index position. */ - { - fraction = imax_fx( xfp, -1 ); /* -1 signifies special left edge case. */ - acc = L_deposit_h( *pPlocs++ ); /* N.B., (*pPlocs) must be zero here. */ - *pPlocsi++ = L_mac( acc, fraction, 1 ); - move32(); /* in Q16 */ - n = sub( n, 1 ); /* This special case is taken care of-- one less to go */ - } - /* All peaks except the very last peak but including the very 1st one if it has not been taken care of. */ - pXfp1 = xfp - 1; - FOR( m = 0; m < n; m++ ) /* Loop through up to the last but one peak. (The last one is excluded.) */ - { - pXfp = pXfp1 + *pPlocs; - fraction = imax_fx( pXfp, 0 ); /* in Q15 */ - acc = L_deposit_h( *pPlocs++ ); - *pPlocsi++ = L_mac( acc, fraction, 1 ); - move32(); /* in Q16. Append the fractional part to the integral part. */ - } - IF( n >= 0 ) - { - /* Special case-- The very last peak */ - pXfp = pXfp1 + *pPlocs; - IF( EQ_16( *pPlocs, Lprot2 ) ) /* Only the very last peak is possible the peak at Lprot2 index position. */ - { - pXfp--; /* Special case needs extra decrement */ - special = 1; /* Signify special right edge case. */ - move16(); - } - ELSE - { - special = 0; - move16(); - } - fraction = imax_fx( pXfp, special ); /* in Q15 */ - acc = L_deposit_h( *pPlocs ); - *pPlocsi = L_mac( acc, fraction, 1 ); - move32(); /* in Q16. Append the fractional part to the integral part. */ - } - } -} -#endif - -/*-------------------------------------------------------------------* - * subst_spec_fx() - * - * Substitution spectrum calculation - *-------------------------------------------------------------------*/ - -#ifdef HARM_HQ_CORE -static void subst_spec_fx( -#else -static void ivas_subst_spec_fx( -#endif - const Word16 *plocs, /* i : The indices of the identified peaks Q0 */ - const Word32 *plocsi, /* i : Interpolated positions of the identified peaks Q16 */ - Word16 *num_plocs, /* i/o : Number of identified peaks Q0 */ - const Word16 time_offs, /* i : Time offset Q0 */ - Word16 *X, /* i/o : FFT spectrum */ - const Word16 *mag_chg, /* i : Magnitude modification Q15 */ - const Word16 ph_dith, /* i : Phase dither, 2*PI is not included. (Q15, i.e., between 0.0 and 1.0) */ - const Word16 *is_trans, /* i : Transient flags (either 0 or 1) */ - const Word16 output_frame, /* i : Frame length Q0 */ - Word16 *seed, /* i/o : Random seed */ - const Word16 *alpha, /* i : Magnitude modification factors for fade to average Q15 */ - const Word16 *beta, /* i : Magnitude modification factors for fade to average Q15 */ - Word16 beta_mute, /* i : Factor for long-term mute Q15 */ - const Word16 *Xavg, /* i : Frequency group averages to fade to Q0 */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 ph_ecu_lookahead, /* i : Phase ECU lookahead */ - const Word16 noise_fac /* i : noise factor Q15 */ -) -{ - Word16 Xph_short; - Word32 corr_phase[MAX_PLOCS], Xph; - Word32 *pCorrPhase; - Word16 cos_F, sin_F, tmp; - Word16 Lprot, m, i, e, im_ind, delta_corr_up, delta_corr_dn, delta_tmp; - Word32 tmp1; - Word16 j, re, im, *pReX, *pImX, lastPeak, lprotBy2Minus1, segmentLen; - Word16 pkLocation_1, pkLocation, pkLocation1; - const Word16 *pPlocs; - const Word32 *pPlocsi; - Word32 acc; - Word16 Lecu; - Word16 Lprot_inv; - Word16 k; - Word16 tmp2; - Word16 alpha_local; - Word16 beta_local; - Word16 expo; - Word16 one_peak_flag_mask; - Word16 mag_chg_local; /*for peak attenuation in burst */ - - Lprot = 512; - move16(); - Lprot_inv = 8192; - move16(); - Lecu = shl( output_frame, 1 ); - - IF( EQ_16( output_frame, L_FRAME48k ) ) - { - Lprot = L_PROT48k; /* 1536=(2*output_frame)*1024/1280; */ - move16(); - Lprot_inv = 2731; /* Q22 */ - move16(); - } - ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) - { - Lprot = L_PROT32k; /* 1024 */ - move16(); - Lprot_inv = 4096; /* Q22 */ - move16(); - } - ELSE - { - Lprot = 512; - move16(); - Lprot_inv = 8192; /* Q22 */ - move16(); - } - - /* Correction phase of the identified peaks */ - IF( s_or( is_trans[0], is_trans[1] ) != 0 ) + /* Correction phase of the identified peaks */ + IF( s_or( is_trans[0], is_trans[1] ) != 0 ) { *num_plocs = 0; move16(); } ELSE { -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { tmp = NS2SA_FX2( L_mult0( output_frame, 50 ), PH_ECU_ALDO_OLP2_NS - PH_ECU_LOOKAHEAD_NS ); @@ -1997,7 +1509,6 @@ static void ivas_subst_spec_fx( } } ELSE -#endif { // tmp = NS2SA(output_frame*50,PH_ECU_ALDO_OLP2_NS-PH_ECU_LOOKAHEAD_NS); tmp = NS2SA_FX2( L_mult0( output_frame, 50 ), PH_ECU_ALDO_OLP2_NS ); @@ -2323,421 +1834,53 @@ static void ivas_subst_spec_fx( return; } -#ifndef HARM_HQ_CORE -static void subst_spec_fx( - const Word16 *plocs, /* i : The indices of the identified peaks Q0 */ - const Word32 *plocsi, /* i : Interpolated positions of the identified peaks Q16 */ - Word16 *num_plocs, /* i/o : Number of identified peaks Q0 */ - const Word16 time_offs, /* i : Time offset Q0 */ - Word16 *X, /* i/o : FFT spectrum */ - const Word16 *mag_chg, /* i : Magnitude modification Q15 */ - const Word16 ph_dith, /* i : Phase dither, 2*PI is not included. (Q15, i.e., between 0.0 and 1.0) */ - const Word16 *is_trans, /* i : Transient flags (either 0 or 1) */ - const Word16 output_frame, /* i : Frame length Q0 */ - Word16 *seed, /* i/o : Random seed */ - const Word16 *alpha, /* i : Magnitude modification factors for fade to average Q15 */ - const Word16 *beta, /* i : Magnitude modification factors for fade to average Q15 */ - Word16 beta_mute, /* i : Factor for long-term mute Q15 */ - const Word16 *Xavg /* i : Frequency group averages to fade to Q0 */ + +/*-------------------------------------------------------------------------- + * rec_wtda() + * + * Windowing and TDA of reconstructed frame + *--------------------------------------------------------------------------*/ + +static void rec_wtda_fx( + Word16 *X, /* i : FFT spectrum */ + Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ + const Word16 output_frame, /* i : Frame length */ + const Word16 Lprot, /* i : Prototype frame length */ + const Word16 old_dec[270], /* i : end of last decoded for OLA before tda and itda */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 *num_p, /* i : Number of peaks Q0 */ + const Word16 *plocs /* i : Peak locations Q0 */ ) { - Word16 Xph_short; - Word32 corr_phase[MAX_PLOCS], Xph; - Word32 *pCorrPhase; - Word16 cos_F, sin_F, tmp; - Word16 Lprot, m, i, e, im_ind, delta_corr_up, delta_corr_dn, delta_tmp; - UWord16 lsb; - Word16 j, re, im, *pReX, *pImX, lastPeak, lprotBy2Minus1, segmentLen; - Word16 pkLocation_1, pkLocation, pkLocation1; - const Word16 *pPlocs; - const Word32 *pPlocsi; - Word32 acc; - Word16 Lecu; - Word16 Lprot_inv; - Word16 k; - Word16 tmp2; - Word16 alpha_local; - Word16 beta_local; - Word16 expo; - Word16 mag_chg_local; /*for peak attenuation in burst */ + Word16 timesh; + Word16 Qin; + Word16 xf_len; + Word16 i, idx; + Word16 *p_ecu; + Word16 g; + Word16 tbl_delta; + Word16 xsubst_[2 * L_FRAME48k]; + Word16 *out_ptr; + const Word16 *w_hamm; + Word16 *pX_start, *pX_end; + Word16 tmp, tmp_e; + Word16 hamm_len2; + Word16 *pNew; + const Word16 *pOldW, *pNewW; + Word16 xfwin[NS2SA( L_FRAME48k * FRAMES_PER_SEC, N_ZERO_MDCT_NS - ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 )]; + const Word16 *pOld; + Word16 copy_len; + Word16 ola_len; - Lprot = 512; + copy_len = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* prototype fill on each side of xsubst to fill MDCT Frame */ move16(); - Lprot_inv = 8192; + ola_len = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS - ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* remaining lengt of LA_ZEROS to overlap add decoded with xsubst */ move16(); - Lecu = shl( output_frame, 1 ); - IF( EQ_16( output_frame, L_FRAME48k ) ) - { - Lprot = L_PROT48k; /* 1536=(2*output_frame)*1024/1280; */ - move16(); - Lprot_inv = 2731; /* Q22 */ - move16(); - } - ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) - { - Lprot = L_PROT32k; /* 1024 */ - move16(); - Lprot_inv = 4096; /* Q22 */ - move16(); - } - ELSE - { - Lprot = 512; - move16(); - Lprot_inv = 8192; /* Q22 */ - move16(); - } - - /* Correction phase of the identified peaks */ - IF( s_or( is_trans[0], is_trans[1] ) != 0 ) - { - *num_plocs = 0; - move16(); - } - ELSE - { - tmp = NS2SA_FX2( L_mult0( output_frame, 50 ), PH_ECU_ALDO_OLP2_NS - PH_ECU_LOOKAHEAD_NS ); - move16(); - tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) ); - tmp = sub( tmp, shr( output_frame, 1 ) ); - tmp = add_sat( tmp, time_offs ); - tmp = round_fx( L_shl( L_mult0( tmp, Lprot_inv ), 4 ) ); /* 0+22+4-16=10 */ - - pPlocsi = plocsi; - pCorrPhase = corr_phase; - FOR( m = 0; m < *num_plocs; m++ ) - { - Mpy_32_16_ss( *pPlocsi++, tmp, &acc, &lsb ); /* plocsi[] in Q16, tmp in Q10 and tmp does not include 2*PI. */ - acc = L_add( L_shl( acc, 5 ), lshr( lsb, 11 ) ); - *pCorrPhase++ = acc; /* in Q16. 2*PI is not included. */ - move32(); - } - } - lprotBy2Minus1 = sub( shr( Lprot, 1 ), 1 ); - i = 1; - move16(); - k = 0; - move16(); - im_ind = sub( Lprot, 1 ); - move16(); - pReX = X + i; - pImX = X + im_ind; - pPlocs = plocs; - pCorrPhase = corr_phase; - pkLocation = *pPlocs; /* N.B. No post-increment */ - move16(); - pkLocation1 = *pPlocs++; - move16(); - lastPeak = sub( *num_plocs, 1 ); - FOR( m = 0; m < *num_plocs; m++ ) - { - delta_corr_dn = DELTA_CORR; - move16(); - delta_corr_up = DELTA_CORR; - move16(); - - pkLocation_1 = pkLocation; /* plocs[m - 1] */ - move16(); - pkLocation = pkLocation1; /* plocs[m] */ - move16(); - pkLocation1 = *pPlocs++; /* plocs[m + 1] */ - move16(); - IF( m > 0 ) - { - delta_tmp = shr( sub( sub( pkLocation, pkLocation_1 ), 1 ), 1 ); - if ( LT_16( delta_tmp, DELTA_CORR ) ) - { - delta_corr_dn = delta_tmp; - move16(); - } - } - - IF( LT_16( m, lastPeak ) ) - { - delta_tmp = shr( sub( sub( pkLocation1, pkLocation ), 1 ), 1 ); - if ( LT_16( delta_tmp, DELTA_CORR ) ) - { - delta_corr_up = delta_tmp; - move16(); - } - } - - /* Input Xph */ - segmentLen = sub( sub( pkLocation, delta_corr_dn ), i ); - /* i = add(i, segmentLen); */ - FOR( j = 0; j < segmentLen; j++ ) - { - *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); - - re = *pReX; - move16(); - im = *pImX; - move16(); - { - tmp = sub( mult_r( re, cos_F ), mult_r( im, sin_F ) ); - im = add( mult_r( re, sin_F ), mult_r( im, cos_F ) ); - } - IF( LT_16( alpha[k], 32766 ) ) - { - *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); - move16(); - tmp2 = mult_r( beta[k], Xavg[k] ); - *pReX++ = add( mult_r( alpha[k], tmp ), mult_r( tmp2, cos_F ) ); - move16(); - *pImX-- = add( mult_r( alpha[k], im ), mult_r( tmp2, sin_F ) ); - move16(); - } - ELSE - { - *pReX++ = mult_r( mag_chg[k], tmp ); - move16(); - *pImX-- = mult_r( mag_chg[k], im ); - move16(); - } - i = add( i, 1 ); - if ( GE_16( i, ivas_gwlpr[k + 1] ) ) - { - k = add( k, 1 ); - } - } - - e = add( pkLocation, delta_corr_up ); - if ( GT_16( e, lprotBy2Minus1 ) ) - { - e = lprotBy2Minus1; - move16(); - } - - Xph = *pCorrPhase; - move32(); - Xph_short = s_and( extract_l( L_shr( Xph, 16 - 10 ) ), 0x3ff ); /* 10 bits precision after radix point */ - IF( GE_16( Xph_short, 512 ) ) - { - sin_F = negate( sincos_t_ext_fx[Xph_short - 512] ); - IF( LT_16( Xph_short, 768 ) ) - { - cos_F = negate( sincos_t_ext_fx[Xph_short - ( 512 - 256 )] ); - } - ELSE - { - cos_F = sincos_t_ext_fx[-Xph_short + ( 1024 + 256 )]; - move16(); - } - } - ELSE - { - sin_F = sincos_t_ext_fx[Xph_short]; - move16(); - IF( LT_16( Xph_short, 256 ) ) - { - cos_F = sincos_t_ext_fx[Xph_short + 256]; - move16(); - } - ELSE - { - cos_F = negate( sincos_t_ext_fx[-Xph_short + ( 256 + 512 )] ); - } - } - - segmentLen = add( sub( e, i ), 1 ); - /* i = add(i, segmentLen); */ - FOR( j = 0; j < segmentLen; j++ ) - { - mag_chg_local = mag_chg[k]; - move16(); - IF( ph_dith != 0 ) - { - Xph = *pCorrPhase; /* in Q16. 2*PI is not included. */ - move32(); - Random( seed ); /* in Q0 */ - acc = L_mult( *seed, ph_dith ); /* N.B. ph_dith[i] is in Q15, i.e., in between 0 and 1.0 (2*PI not included) */ - acc = L_shr( acc, PHASE_DITH_SCALE_SHIFT ); - Xph = L_add( Xph, acc ); /* in Q16. */ - - IF( ph_dith > 0 ) /* up to 6 dB additional att of peaks in non_transient longer bursts, (when peak phase is randomized ) */ - { - /* mag_chg_local *= 0.5 + (1.0 - ph_dith[i])/2 where 0.5~= sqrt((float)pow(10.0,-6/10.0)) and ph_dith=0..1.0--> scale=1.0 ...5 */ - mag_chg_local = mult_r( mag_chg_local, sub( 32767, shr( ph_dith, 1 ) ) ); - } - Xph_short = s_and( extract_l( L_shr( Xph, 16 - 10 ) ), 0x3ff ); - IF( GE_16( Xph_short, 512 ) ) - { - sin_F = negate( sincos_t_ext_fx[Xph_short - 512] ); - IF( LT_16( Xph_short, 768 ) ) - { - cos_F = negate( sincos_t_ext_fx[Xph_short - ( 512 - 256 )] ); - } - ELSE - { - cos_F = sincos_t_ext_fx[-Xph_short + ( 1024 + 256 )]; - move16(); - } - } - ELSE - { - sin_F = sincos_t_ext_fx[Xph_short]; - move16(); - IF( LT_16( Xph_short, 256 ) ) - { - cos_F = sincos_t_ext_fx[Xph_short + 256]; - move16(); - } - ELSE - { - cos_F = negate( sincos_t_ext_fx[-Xph_short + ( 256 + 512 )] ); - } - } - } - - re = *pReX; - move16(); - im = *pImX; - move16(); - { - tmp = sub_sat( mult_r( re, cos_F ), mult_r( im, sin_F ) ); - im = add_sat( mult_r( re, sin_F ), mult_r( im, cos_F ) ); - } - IF( LT_16( alpha[k], 32766 ) ) - { - alpha_local = mag_chg_local; - move16(); - - acc = L_sub( 1073741824L, L_mult0( alpha_local, alpha_local ) ); - acc = Sqrt_l( acc, &expo ); - expo = add( 30, add( 31, expo ) ); - if ( EQ_16( s_and( expo, 1 ), 1 ) ) - { - acc = Mult_32_16( acc, 23170 ); /* 1/sqrt(2) in Q15 */ - } - expo = shr( expo, 1 ); - beta_local = mult_r( beta_mute, round_fx( L_shl( acc, sub( 31, expo ) ) ) ); - - IF( GE_16( k, LGW32K - 1 ) ) - { - beta_local = mult_r( beta_local, 3277 ); /* 0.1 in Q15 */ - } - ELSE IF( GE_16( k, LGW16K - 1 ) ) - { - beta_local = mult_r( beta_local, 16384 ); /* 0.5 in Q15 */ - } - - *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); - move16(); - tmp2 = mult_r( beta_local, Xavg[k] ); - *pReX++ = add( mult_r( alpha_local, tmp ), mult_r( tmp2, cos_F ) ); - move16(); - *pImX-- = add( mult_r( alpha_local, im ), mult_r( tmp2, sin_F ) ); - move16(); - } - ELSE - { - *pReX++ = mult_r( mag_chg_local, tmp ); - move16(); - *pImX-- = mult_r( mag_chg_local, im ); - move16(); - } - - i = add( i, 1 ); - if ( GE_16( i, ivas_gwlpr[k + 1] ) ) - { - k = add( k, 1 ); - } - } - pCorrPhase++; - } - - segmentLen = sub( shr( Lprot, 1 ), i ); - FOR( j = 0; j < segmentLen; j++ ) - { - *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); - move16(); - - re = *pReX; - move16(); - im = *pImX; - move16(); - tmp = sub( mult_r( re, cos_F ), mult_r( im, sin_F ) ); - im = add( mult_r( re, sin_F ), mult_r( im, cos_F ) ); - IF( LT_16( alpha[k], 32766 ) ) - { - *seed = rand_phase_fx( *seed, &sin_F, &cos_F ); - move16(); - tmp2 = mult_r( beta[k], Xavg[k] ); - *pReX++ = add( mult_r( alpha[k], tmp ), mult_r( tmp2, cos_F ) ); - move16(); - *pImX-- = add( mult_r( alpha[k], im ), mult_r( tmp2, sin_F ) ); - move16(); - } - ELSE - { - *pReX++ = mult_r( mag_chg[k], tmp ); - move16(); - *pImX-- = mult_r( mag_chg[k], im ); - move16(); - } - - i = add( i, 1 ); - if ( GE_16( i, ivas_gwlpr[k + 1] ) ) - { - k = add( k, 1 ); - } - } -} -#endif - -/*-------------------------------------------------------------------------- - * rec_wtda() - * - * Windowing and TDA of reconstructed frame - *--------------------------------------------------------------------------*/ - -#ifdef HARM_HQ_CORE -static void rec_wtda_fx( -#else -static void ivas_rec_wtda_fx( -#endif - Word16 *X, /* i : FFT spectrum */ - Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ - const Word16 output_frame, /* i : Frame length */ - const Word16 Lprot, /* i : Prototype frame length */ - const Word16 old_dec[270], /* i : end of last decoded for OLA before tda and itda */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 *num_p, /* i : Number of peaks Q0 */ - const Word16 *plocs /* i : Peak locations Q0 */ -) -{ - Word16 timesh; - Word16 Qin; - Word16 xf_len; - Word16 i, idx; - Word16 *p_ecu; - Word16 g; - Word16 tbl_delta; - Word16 xsubst_[2 * L_FRAME48k]; -#ifdef HARM_HQ_CORE - Word16 *out_ptr; -#endif - const Word16 *w_hamm; - Word16 *pX_start, *pX_end; - Word16 tmp, tmp_e; - Word16 hamm_len2; - Word16 *pNew; - const Word16 *pOldW, *pNewW; - Word16 xfwin[NS2SA( L_FRAME48k * FRAMES_PER_SEC, N_ZERO_MDCT_NS - ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 )]; - const Word16 *pOld; - Word16 copy_len; - Word16 ola_len; - - copy_len = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* prototype fill on each side of xsubst to fill MDCT Frame */ - move16(); - ola_len = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS - ( 2 * FRAME_SIZE_NS - L_PROT_NS ) / 2 ); /* remaining lengt of LA_ZEROS to overlap add decoded with xsubst */ - move16(); - - xf_len = 26; - move16(); - tbl_delta = 10082; /* Q12 */ - move16(); + xf_len = 26; + move16(); + tbl_delta = 10082; /* Q12 */ + move16(); IF( EQ_16( output_frame, L_FRAME48k ) ) { w_hamm = w_hamm_sana48k_2_fx; @@ -2788,18 +1931,8 @@ static void ivas_rec_wtda_fx( } } -#ifndef HARM_HQ_CORE - /* extract reconstructed frame with aldo window */ - timesh = sub( NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ), shr( sub( shl( output_frame, 1 ), Lprot ), 1 ) ); - - set16_fx( xsubst_, 0, add( sub( shl( output_frame, 1 ), Lprot ), timesh ) ); - Copy( X, xsubst_ + add( sub( shl( output_frame, 1 ), Lprot ), timesh ), sub( Lprot, timesh ) ); - - /* Copy and OLA look ahead zero part of MDCT window from decoded signal */ -#endif IF( element_mode != EVS_MONO ) { -#ifdef HARM_HQ_CORE /* extract reconstructed frame with aldo window */ timesh = sub( NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ), shr( sub( shl( output_frame, 1 ), Lprot ), 1 ) ); @@ -2807,7 +1940,6 @@ static void ivas_rec_wtda_fx( Copy( X, xsubst_ + add( sub( shl( output_frame, 1 ), Lprot ), timesh ), sub( Lprot, timesh ) ); /* Copy and OLA look ahead zero part of MDCT window from decoded signal */ -#endif Copy( old_dec, xsubst_ + NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ), copy_len ); /* also need to scale to Q0 ?? */ pOld = old_dec + copy_len; pNew = xsubst_ + add( copy_len, NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ) ); @@ -2827,13 +1959,10 @@ static void ivas_rec_wtda_fx( pNewW += 1; } -#ifdef HARM_HQ_CORE out_ptr = xsubst_ + output_frame; -#endif } ELSE { -#ifdef HARM_HQ_CORE Word16 l; Word16 Lprot2 = shr( Lprot, 1 ); @@ -2854,190 +1983,42 @@ static void ivas_rec_wtda_fx( *p_ecu = mult( g, ( *p_ecu ) ); move16(); p_ecu++; - } - - timesh = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), 10000000L - PH_ECU_ALDO_OLP2_NS ); - move16(); - - out_ptr = xsubst_ + sub( output_frame, timesh ); -#else - /* Smoothen onset of ECU frame */ - p_ecu = xsubst_ + add( sub( shl( output_frame, 1 ), Lprot ), timesh ); - FOR( i = 0; i < xf_len; ( i++, p_ecu++ ) ) - { - idx = extract_l( L_shr( L_mult0( i, tbl_delta ), 12 ) ); // Q0 - g = sincos_t_fx[idx]; // Q15 - move16(); - g = mult( g, g ); // Q15 - *p_ecu = mult( g, ( *p_ecu ) ); - move16(); - p_ecu++; - } -#endif - } - - /* Apply TDA and windowing to ECU frame */ - Qin = 0; - move16(); -#ifdef HARM_HQ_CORE - wtda_fx( out_ptr, &Qin, ecu_rec, NULL, 0, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame ); -#else - wtda_fx( xsubst_ + output_frame, &Qin, ecu_rec, NULL, 0, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame ); -#endif - - return; -} - -#ifndef HARM_HQ_CORE -static void rec_wtda_fx( - Word16 *X, /* i : FFT spectrum */ - Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ - const Word16 output_frame, /* i : Frame length */ - const Word16 Lprot, /* i : Prototype frame length */ - const Word32 fs ) -{ - Word16 l, Lprot2, timesh; - Word16 rec_buf[3 * L_FRAME48k]; - Word16 *xsubst_, *out_ptr; - Word16 Qin; - Word16 xf_len; - Word16 i, idx; - Word16 *p_ecu; - Word16 g; - Word16 tbl_delta; - - xsubst_ = rec_buf + output_frame; - Lprot2 = shr( Lprot, 1 ); - - /* Initialize to WB constants */ - xf_len = 26; - move16(); - tbl_delta = 10082; /* Q12 */ - move16(); - IF( EQ_16( output_frame, L_FRAME48k ) ) - { - xf_len = 78; - move16(); - tbl_delta = 3361; /* Q12 */ - move16(); - } - ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) - { - xf_len = 52; - move16(); - tbl_delta = 5041; /* Q12 */ - move16(); - } - - /* extract reconstructed frame with aldo window */ - l = sub( output_frame, Lprot2 ); - set16_fx( xsubst_, 0, l ); - Copy( X, xsubst_ + l, Lprot ); - set16_fx( xsubst_ + add( output_frame, Lprot2 ), 0, l ); - - /* Smoothen onset of ECU frame */ - p_ecu = xsubst_ + sub( output_frame, Lprot2 ); - FOR( i = 0; i < xf_len; i++ ) - { - idx = extract_l( L_shr( L_mult0( i, tbl_delta ), 12 ) ); - g = sincos_t_fx[idx]; - move16(); - g = mult( g, g ); - *p_ecu = mult( g, ( *p_ecu ) ); - move16(); - p_ecu++; - } - - timesh = NS2SA_FX2( fs, 10000000L - PH_ECU_ALDO_OLP2_NS ); - move16(); - - set16_fx( rec_buf, 0, output_frame ); - Qin = 0; - move16(); - out_ptr = rec_buf + sub( shl( output_frame, 1 ), timesh ); - wtda_fx( out_ptr, &Qin, ecu_rec, NULL, 0, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ - output_frame ); - return; -} -#endif - -/*-------------------------------------------------------------------------- - * rec_frame_fx() - * - * Frame reconstruction - *--------------------------------------------------------------------------*/ - -#ifdef HARM_HQ_CORE -static void rec_frame_fx( -#else -static void ivas_rec_frame_fx( -#endif - Word16 *X, /* i : FFT spectrum */ - Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ - const Word16 output_frame, /* i : Frame length */ - const Word16 Q, - const Word16 *old_dec, /* i : end of last decoded for OLA before tda and itda */ - const Word16 element_mode, /* i : IVAS element mode */ - const Word16 *num_p, /* i : Number of peaks */ - const Word16 *plocs /* i : Peak locations */ -) -{ - const Word16 *pFftTbl; - Word16 Lprot, lprotLog2Minus1; - - /* Initialize to WB constants */ - Lprot = 512; - move16(); - lprotLog2Minus1 = 9 - 1; - move16(); - pFftTbl = FFT_W256; /* Table for 512-point real input FFT */ - IF( EQ_16( output_frame, L_FRAME48k ) ) - { - Lprot = L_PROT48k; /* 1536 = (2*output_frame)*1024/1280 */ - move16(); - } - ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) - { - Lprot = L_PROT32k; /* 1024 */ - move16(); - lprotLog2Minus1 = 10 - 1; - move16(); - pFftTbl = FFT_W512; /* Table for 1024-point real input FFT */ - } - - /* extend spectrum and IDFT */ - IF( EQ_16( output_frame, L_FRAME48k ) ) - { - ifft3_fx( X, X, Lprot ); - } - ELSE - { - r_fft_fx_lc( pFftTbl, Lprot, shr( Lprot, 1 ), lprotLog2Minus1, X, X, 0 ); /* Inverse FFT */ + } + + timesh = NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), 10000000L - PH_ECU_ALDO_OLP2_NS ); + move16(); + + out_ptr = xsubst_ + sub( output_frame, timesh ); } - Scale_sig( X, Lprot, -Q ); -#ifdef HARM_HQ_CORE - rec_wtda_fx( X, ecu_rec, output_frame, Lprot, old_dec, element_mode, num_p, plocs ); -#else - ivas_rec_wtda_fx( X, ecu_rec, output_frame, Lprot, old_dec, element_mode, num_p, plocs ); -#endif + /* Apply TDA and windowing to ECU frame */ + Qin = 0; + move16(); + wtda_fx( out_ptr, &Qin, ecu_rec, NULL, 0, ALDO_WINDOW, ALDO_WINDOW, /* window overlap of current frame (0: full, 2: none, or 3: half) */ output_frame ); return; } -#ifndef HARM_HQ_CORE + +/*-------------------------------------------------------------------------- + * rec_frame_fx() + * + * Frame reconstruction + *--------------------------------------------------------------------------*/ + static void rec_frame_fx( Word16 *X, /* i : FFT spectrum */ Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ const Word16 output_frame, /* i : Frame length */ - const Word16 Q ) + const Word16 Q, + const Word16 *old_dec, /* i : end of last decoded for OLA before tda and itda */ + const Word16 element_mode, /* i : IVAS element mode */ + const Word16 *num_p, /* i : Number of peaks */ + const Word16 *plocs /* i : Peak locations */ +) { const Word16 *pFftTbl; Word16 Lprot, lprotLog2Minus1; - Word32 fs; - - fs = L_mult0( output_frame, 50 ); /* Initialize to WB constants */ Lprot = 512; @@ -3070,11 +2051,11 @@ static void rec_frame_fx( } Scale_sig( X, Lprot, -Q ); - rec_wtda_fx( X, ecu_rec, output_frame, Lprot, fs ); + rec_wtda_fx( X, ecu_rec, output_frame, Lprot, old_dec, element_mode, num_p, plocs ); return; } -#endif + static Word32 mult_32_32_q( const Word32 a, @@ -3167,12 +2148,8 @@ static void fir_dwn_fx( * Pitch/correlation analysis and adaptive analysis frame length calculation *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE static void fec_ecu_pitch_fx( const Word16 element_mode, -#else -static void fec_ecu_pitch_ivas_fx( -#endif const Word16 *prevsynth_fx, /*Q15 16 */ Word16 *prevsynth_LP_fx, /* Q15 16 */ const Word16 L, @@ -3353,238 +2330,17 @@ static void fec_ecu_pitch_ivas_fx( accBisqrt = Isqrt( accB ); /* Q31 - 3 + tmpQLP */ accCisqrt = Isqrt( accC ); /* Q31 - 3 + tmpQLP*/ -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { - Ryytmp = mult_32_32_q( accA, accCisqrt, sub( 16 + 3, tmpQLP ) ); /*Q 6 -2*tmpQLP + Q31 - 3 + tmpQLP -16 -3 +tmpQLP = Q15*/ - Ryytmp = mult_32_32_q( Ryytmp, accBisqrt, add( 15 - 3, tmpQLP ) ); /*Q15 + Q31 - 3 + tmpQLP -15 + 3- tmpQLP = Q31*/ - Ryy = extract_h( Ryytmp ); /* Q15 */ - } - ELSE -#endif - { - Ryytmp = L_shl_sat( Mult_32_32( accA, accCisqrt ), Q15 ); /*Q 6 -2*tmpQLP + Q31 - 3 + tmpQLP -16 -3 +tmpQLP = Q15*/ - Ryy = extract_h( L_shl_sat( Mult_32_32( Ryytmp, accBisqrt ), 16 ) ); /*Q15 + Q31 - 3 + tmpQLP -15 + 3- tmpQLP = Q31*/ - } - - IF( GT_16( Ryy, *min_corr_fx ) ) - { - *min_corr_fx = Ryy; - move16(); - delay_ind = i; - move16(); - } - - test(); - IF( HqVoicing == 0 && GT_16( *min_corr_fx, 31130 ) ) - { - BREAK; - } - } - - *N = sub( Lon20mul34, delay_ind ); - move16(); - - Scale_sig( prevsynth_LP_fx, 320, negate( sub( tmpQLP, 3 ) ) ); - - return; -} - -#ifndef HARM_HQ_CORE -static void fec_ecu_pitch_fx( - const Word16 *prevsynth_fx, /*Q15 16 */ - Word16 *prevsynth_LP_fx, /* Q15 16 */ - const Word16 L, - Word16 *N, - Word16 *min_corr_fx, /* Q15 16 */ - Word16 *decimatefator, - const Word16 HqVoicing ) -{ - - Word16 i, filt_size; - Word16 QAsr, Ryy, cb_start, tmpQLP; - Word32 Ryytmp; - Word32 accA, accB, accBisqrt, accC, accCisqrt; - Word16 delay_ind, k; - const Word16 *Asr_LP_fx; - Word16 *ptr_LP, *ptr_LP2, *ptr_LP3, *ptr_LP4; - Word16 cb_end; - Word16 Lmul2, Lon20mul6, Lon20mul28, Lon20mul33, Lon20mul34; - - - SWITCH( L ) - { - case L_FRAME48k: - *decimatefator = 6; - move16(); - filt_size = 60; - move16(); - Asr_LP_fx = Asr_LP48_fx; - QAsr = 17; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 1920; - move16(); - BREAK; - - case L_FRAME32k: - *decimatefator = 4; - move16(); - filt_size = 40; - move16(); - Asr_LP_fx = Asr_LP32_fx; - QAsr = 15; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 1280; - move16(); - BREAK; - - case L_FRAME16k: - *decimatefator = 2; - move16(); - filt_size = 20; - move16(); - Asr_LP_fx = Asr_LP16_fx; - QAsr = 15; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 640; - move16(); - BREAK; - - default: - *decimatefator = 2; - move16(); - filt_size = 40; - move16(); - Asr_LP_fx = Asr_LP16_fx; - QAsr = 15; - move16(); - Lon20mul6 = 48; - move16(); - Lon20mul28 = 224; - move16(); - Lon20mul33 = 264; - move16(); - Lon20mul34 = 272; - move16(); - Lmul2 = 320; - move16(); - BREAK; - } - - - /* Resampling to work at 8Khz */ - fir_dwn_fx( prevsynth_fx, Asr_LP_fx, QAsr, prevsynth_LP_fx, Lmul2, filt_size, *decimatefator ); /* resampling without delay */ - - - tmpQLP = Find_Max_Norm16( prevsynth_LP_fx, 320 ); - Scale_sig( prevsynth_LP_fx, 320, sub( tmpQLP, 3 ) ); /* to avoid over scaling */ - - - /* Correlation analysis */ - *min_corr_fx = 0; - move16(); - accC = L_deposit_l( 0 ); - - ptr_LP = prevsynth_LP_fx + Lon20mul34; - FOR( k = 0; k < Lon20mul6; k++ ) - { - accC = L_mac0( accC, *ptr_LP, *ptr_LP ); - ptr_LP++; - } - - - IF( EQ_16( HqVoicing, 1 ) ) - { - cb_start = 0; - move16(); - cb_end = Lon20mul33; - move16(); - } - ELSE - { - cb_start = 0; - move16(); - cb_end = Lon20mul28; - move16(); - } - - accB = 0; - move16(); - delay_ind = cb_start; - move16(); - - FOR( i = cb_start; i < cb_end; i++ ) /* cb_end = 35 let 6 ms min of loop size */ - { - accA = 0; - move16(); - IF( EQ_16( i, cb_start ) ) - { - accB = 0; - move16(); - ptr_LP = prevsynth_LP_fx; - ptr_LP2 = prevsynth_LP_fx + Lon20mul34; - FOR( k = 0; k < Lon20mul6; k++ ) - { - accA = L_mac0( accA, *ptr_LP, *ptr_LP2 ); - accB = L_mac0( accB, *ptr_LP, *ptr_LP ); - ptr_LP++; - ptr_LP2++; - } - } - ELSE - { - - - accB = L_mac0( L_msu0( accB, prevsynth_LP_fx[i - 1], prevsynth_LP_fx[i - 1] ), prevsynth_LP_fx[i + Lon20mul6 - 1], prevsynth_LP_fx[i + Lon20mul6 - 1] ); /* tmpQLP-5 */ - - - ptr_LP3 = prevsynth_LP_fx + i; - ptr_LP4 = prevsynth_LP_fx + Lon20mul34; - - FOR( k = 0; k < Lon20mul6; k++ ) - { - accA = L_mac0( accA, *ptr_LP3, *ptr_LP4 ); /*2* tmpQLP-5 */ - ptr_LP3++; - ptr_LP4++; - } - } - - /*accB*/ - /*accC*/ - /*accA Q 6-2*tmpQLP*/ - - accBisqrt = Isqrt( accB ); /* Q31 - 3 + tmpQLP */ - accCisqrt = Isqrt( accC ); /* Q31 - 3 + tmpQLP*/ - - - Ryytmp = mult_32_32_q( accA, accCisqrt, sub( 16 + 3, tmpQLP ) ); /*Q 6 -2*tmpQLP + Q31 - 3 + tmpQLP -16 -3 +tmpQLP = Q15*/ - Ryytmp = mult_32_32_q( Ryytmp, accBisqrt, add( 15 - 3, tmpQLP ) ); /*Q15 + Q31 - 3 + tmpQLP -15 + 3- tmpQLP = Q31*/ - Ryy = extract_h( Ryytmp ); /* Q15 */ - + Ryytmp = mult_32_32_q( accA, accCisqrt, sub( 16 + 3, tmpQLP ) ); /*Q 6 -2*tmpQLP + Q31 - 3 + tmpQLP -16 -3 +tmpQLP = Q15*/ + Ryytmp = mult_32_32_q( Ryytmp, accBisqrt, add( 15 - 3, tmpQLP ) ); /*Q15 + Q31 - 3 + tmpQLP -15 + 3- tmpQLP = Q31*/ + Ryy = extract_h( Ryytmp ); /* Q15 */ + } + ELSE + { + Ryytmp = L_shl_sat( Mult_32_32( accA, accCisqrt ), Q15 ); /*Q 6 -2*tmpQLP + Q31 - 3 + tmpQLP -16 -3 +tmpQLP = Q15*/ + Ryy = extract_h( L_shl_sat( Mult_32_32( Ryytmp, accBisqrt ), 16 ) ); /*Q15 + Q31 - 3 + tmpQLP -15 + 3- tmpQLP = Q31*/ + } IF( GT_16( Ryy, *min_corr_fx ) ) { @@ -3605,9 +2361,10 @@ static void fec_ecu_pitch_fx( move16(); Scale_sig( prevsynth_LP_fx, 320, negate( sub( tmpQLP, 3 ) ) ); + return; } -#endif + static void sin_cos_est_fx( Word32 phi, @@ -3715,11 +2472,7 @@ static Word16 abs_iter_fx( * next power of 2 using linear interpolation. *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE static void fec_ecu_dft_fx( -#else -static void ivas_fec_ecu_dft_fx( -#endif const Word16 *prevsynth_LP, /*Qin */ const Word16 N, Word16 *Tfr, /*Qout */ @@ -3790,7 +2543,6 @@ static void ivas_fec_ecu_dft_fx( tmp = Exp16Array( *Nfft, Tfr16 ); *exp = add( tmp, add( 2, norm_s( *Nfft ) ) ); move16(); -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { Word16 loctmp = *exp; @@ -3799,7 +2551,6 @@ static void ivas_fec_ecu_dft_fx( Copy_Scale_sig_16_32_DEPREC( Tfr16, Tfr32, *Nfft, loctmp ); /*Qin+exp; */ /*Even with limiting loctmp, if Copy_Scale_sig_16_32_no_sat() is used, can lead to 1 difference */ } ELSE -#endif { Copy_Scale_sig_16_32_no_sat( Tfr16, Tfr32, *Nfft, *exp ); /*Qin+exp; */ *exp = s_min( *exp, 15 ); @@ -3838,106 +2589,6 @@ static void ivas_fec_ecu_dft_fx( return; } -#ifndef HARM_HQ_CORE -static void fec_ecu_dft_fx( - const Word16 *prevsynth_LP, /*Qin */ - const Word16 N, - Word16 *Tfr, /*Qout */ - Word16 *Tfi, /*Qout */ - Word32 *sum_Tf_abs, /*Qout; */ - Word16 *Tf_abs, /*Qout */ - Word16 *Nfft, - Word16 *exp /*Qout = Qin+exp */ -) -{ - Word32 L_tmp, Tmp, Tfr32[512], Tfi32[512], fac, *Pt1, *Pt2; - Word16 i, tmp, tmp_short, N_LP, target[2 * L_FRAME48k], Tfr16[FEC_FFT_MAX_SIZE], *pt1, *pt2, *pt3; - Word16 tmp_loop; - tmp = sub( 296, N ); - Copy( &prevsynth_LP[tmp], target, N ); - - /* DFT */ - L_tmp = L_deposit_l( N ); - FOR( tmp = 0; L_tmp <= 16384; tmp++ ) - { - L_tmp = L_shl( L_tmp, 1 ); - } - *Nfft = shl( 1, sub( 15, tmp ) ); - move16(); - - set32_fx( Tfr32, 0, *Nfft ); - set32_fx( Tfi32, 0, *Nfft ); - Tfr16[0] = target[0]; - move16(); - Tfr16[*Nfft - 1] = target[N - 1]; - move16(); - - IF( EQ_16( *Nfft, N ) ) - { - Copy( &target[1], &Tfr16[1], sub( *Nfft, 2 ) ); - } - ELSE - { - tmp = div_s( sub( N, 1 ), sub( *Nfft, 1 ) ); - Tmp = L_deposit_l( tmp ); - fac = L_add( Tmp, 0 ); - tmp_loop = sub( *Nfft, 1 ); - FOR( i = 1; i < tmp_loop; i++ ) /* interpolation for FFT */ - { - tmp_short = extract_l( L_shr( Tmp, 15 ) ); - tmp = extract_l( L_msu( Tmp, tmp_short, 16384 ) ); - L_tmp = L_mult( sub_sat( target[tmp_short + 1], target[tmp_short] ), tmp ); /*Qin+16 */ - Tfr16[i] = add_sat( target[tmp_short], round_fx_sat( L_tmp ) ); - move16(); /*Qin */ - Tmp = L_add( Tmp, fac ); - } - } - - - /*to avoid overflow in DoRTFTn_fx() */ - tmp = Exp16Array( *Nfft, Tfr16 ); - *exp = add( tmp, add( 2, norm_s( *Nfft ) ) ); - move16(); - { - Word16 loctmp = *exp; - move16(); - loctmp = s_min( 15, loctmp ); - Copy_Scale_sig_16_32_DEPREC( Tfr16, Tfr32, *Nfft, loctmp ); /*Qin+exp; */ /*Even with limiting loctmp, if Copy_Scale_sig_16_32_no_sat() is used, can lead to 1 difference */ - } - - DoRTFTn_fx( Tfr32, Tfi32, *Nfft ); - N_LP = shr( *Nfft, 1 ); - - L_tmp = L_deposit_l( 0 ); - - pt1 = Tfr; - pt2 = Tfi; - pt3 = Tf_abs; - Pt1 = Tfr32; - Pt2 = Tfi32; - FOR( i = 0; i < N_LP; i++ ) - { - *pt1 = extract_h( *Pt1 ); /*Qin+exp-16 */ - move16(); - *pt2 = extract_h( *Pt2 ); /*Qin+exp-16 */ - move16(); - *pt3 = abs_iter_fx( Tfr[i], Tfi[i], 5 ); - move16(); /*Qin+exp-16 */ - L_tmp = L_mac0( L_tmp, *pt3, 1 ); /*Qin+exp-16 */ - pt1++; - pt2++; - pt3++; - Pt1++; - Pt2++; - } - *sum_Tf_abs = L_tmp; - move32(); - *exp = sub( *exp, 16 ); - move16(); - - return; -} -#endif static void singenerator_fx( const Word16 L, /* i : size of output */ const Word16 cosfreq, /* i : cosine of 1-sample dephasing at the given frequency Q15*/ @@ -4206,11 +2857,7 @@ static void sinusoidal_synthesis_fx( return; } -#ifdef HARM_HQ_CORE static void fec_noise_filling_fx( -#else -static void ivas_fec_noise_filling_fx( -#endif const Word16 *prevsynth_fx, /*Qsynth */ Word16 *synthesis_fx, /*Qsynth */ Word16 *ni_seed_forfec, @@ -4329,11 +2976,6 @@ static void ivas_fec_noise_filling_fx( IF( element_mode == EVS_MONO ) { -#ifndef HARM_HQ_CORE - kk = i_mult2( 7, L20 ); - tmp_fx = i_mult2( 37, L20 ); - p_mdct_ola = prevsynth_fx + tmp_fx; -#else q1 = i_mult2( 7, L20 ); q2 = i_mult2( 33, L20 ); @@ -4350,212 +2992,46 @@ static void ivas_fec_noise_filling_fx( { L_tmp = L_mult( *sinq_tab, *sinq_tab ); /*Q30 */ sinq_tab++; - q2 = round_fx( L_sub( 2147483647, L_tmp ) ); /*Q15 */ - q1 = round_fx( L_tmp ); /*Q15 */ - L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */ - L_tmp = L_mac( L_tmp, ( *pt6++ ), q2 ); /*Qsynth+16 */ - ( *pt1++ ) = round_fx( L_tmp ); /*Qsynth */ - move16(); - } -#endif - } - ELSE - { - kk = NS2SA_FX2( L_mult0( L, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ); - p_mdct_ola = old_out + kk; - -#ifdef HARM_HQ_CORE - /* overlappadd with the ms of valid mdct of the last frame */ - tmp_fx = i_mult2( 3, L20 ); - pt1 = &synthesis_fx[0]; - pt6 = &p_mdct_ola[0]; - FOR( k = 0; k < tmp_fx; k++ ) - { - L_tmp = L_mult( *sinq_tab, *sinq_tab ); /*Q31 */ - sinq_tab++; - q2 = round_fx( L_sub( 2147483647, L_tmp ) ); /*Q15 */ - q1 = round_fx( L_tmp ); /*Q15 */ - L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */ - L_tmp = L_add_sat( L_tmp, L_shr_sat( Mpy_32_16_1( L_deposit_h( *pt6++ ), q2 ), Q_old_out ) ); /*Qsynth+16 */ - ( *pt1++ ) = round_fx_sat( L_tmp ); /*Qsynth */ - move16(); - } - - Copy( synthesis_fx, synthesis_fx + kk, sub( 2 * L, kk ) ); - Copy( synthesis_fx + L, gapsynth_fx, L ); - Copy( prevsynth_fx + sub( alignment_point, kk ), synthesis_fx, kk ); -#endif - } - -#ifndef HARM_HQ_CORE - /* overlappadd with the ms of valid mdct of the last frame */ - tmp_fx = i_mult2( 3, L20 ); - pt1 = &synthesis_fx[0]; - pt6 = &p_mdct_ola[0]; - FOR( k = 0; k < tmp_fx; k++ ) - { - L_tmp = L_mult( *sinq_tab, *sinq_tab ); /*Q31 */ - sinq_tab++; - q2 = round_fx( L_sub( 2147483647, L_tmp ) ); /*Q15 */ - q1 = round_fx( L_tmp ); /*Q15 */ - L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */ - L_tmp = L_add_sat( L_tmp, L_shr_sat( Mpy_32_16_1( L_deposit_h( *pt6++ ), q2 ), Q_old_out ) ); /*Qsynth+16 */ - ( *pt1++ ) = round_fx_sat( L_tmp ); /*Qsynth */ - move16(); - } - - Copy( synthesis_fx, synthesis_fx + kk, sub( 2 * L, kk ) ); - Copy( synthesis_fx + L, gapsynth_fx, L ); - Copy( prevsynth_fx + sub( alignment_point, kk ), synthesis_fx, kk ); -#endif - - return; -} - -#ifndef HARM_HQ_CORE -static void fec_noise_filling_fx( - const Word16 *prevsynth_fx, /*Qsynth */ - Word16 *synthesis_fx, /*Qsynth */ - Word16 *ni_seed_forfec, - const Word16 L, - const Word16 N, - const Word16 HqVoicing, - Word16 *gapsynth_fx /*Qsynth */ -) -{ - Word16 Rnd_N_noise; - Word16 k, kk, i; - Word16 N_noise; - - Word16 tmp_fx, ind, q1, q2, L20, flag; - Word16 noisevect_fx[34 * L_FRAME48k / 20], SS_fx[L_FRAME48k / 2]; - Word16 *pt1, *pt2, *pt3, *pt4, *pt5; - const Word16 *pt6; - Word32 L_tmp; - const Word16 *sinq_tab; - - IF( EQ_16( L, L_FRAME32k ) ) - { - sinq_tab = sinq_32k; - } - ELSE IF( EQ_16( L, L_FRAME48k ) ) - { - sinq_tab = sinq_48k; - } - ELSE - { - sinq_tab = sinq_16k; - } - - L20 = extract_h( L_mult( 1639, L ) ); /*L/20 */ - - /*N=47*L/20-delay_ind*decimatefator-6*L/20; */ - - tmp_fx = sub( sub( shl( L, 1 ), i_mult2( 3, L20 ) ), N ); - Copy( prevsynth_fx + tmp_fx, noisevect_fx, N ); - - /* Noise addition on full band */ - /* residual */ - - tmp_fx = s_min( N, L ); - N_noise = shr( tmp_fx, 1 ); - ind = sub( N, tmp_fx ); - pt1 = noisevect_fx; - pt2 = pt1 + ind; - move16(); - pt3 = &synthesis_fx[ind]; - move16(); - FOR( k = 0; k < tmp_fx; k++ ) - { - ( *pt1++ ) = sub_sat( ( *pt2++ ), ( *pt3++ ) ); - move16(); - } - - IF( HqVoicing ) - { - Scale_sig( noisevect_fx, N, -2 ); - } - - kk = 0; - move16(); - k = 0; - move16(); - Rnd_N_noise = N_noise; - move16(); - - ind = shl( L, 1 ); - flag = ind; - move16(); - pt5 = synthesis_fx; - WHILE( flag > 0 ) - { - tmp_fx = Random( ni_seed_forfec ); - - L_tmp = L_mac( 1503264768, tmp_fx, 9830 ); - if ( kk == 0 ) - { - L_tmp = L_mac( 1073741824, tmp_fx, 6554 ); - } - - kk = sub( 1, kk ); - tmp_fx = round_fx( L_tmp ); - Rnd_N_noise = extract_h( L_mult( N_noise, tmp_fx ) ); /*Q0 */ - - - tmp_fx = div_s( 1, Rnd_N_noise ); /*Q15 */ - tmp_fx = round_fx_sat( L_shl_sat( L_mult( tmp_fx, 25736 ), 2 ) ); /*Q15 */ - - sinq_fx( shr( tmp_fx, 1 ), shr( tmp_fx, 2 ), Rnd_N_noise, SS_fx ); - - pt2 = &noisevect_fx[N_noise]; - pt1 = pt2 - Rnd_N_noise; - pt3 = SS_fx; - pt4 = pt3 + sub( Rnd_N_noise, 1 ); - tmp_fx = s_min( Rnd_N_noise, flag ); - FOR( i = 0; i < tmp_fx; i++ ) - { - L_tmp = L_mult( ( *pt1++ ), ( *pt3++ ) ); /*Qsynth+16 */ - L_tmp = L_mac_sat( L_tmp, ( *pt2++ ), ( *pt4-- ) ); /*Qsynth+16 */ - *pt5 = add_sat( *pt5, round_fx_sat( L_tmp ) ); - move16(); /*Qsynth */ - pt5++; + q2 = round_fx( L_sub( 2147483647, L_tmp ) ); /*Q15 */ + q1 = round_fx( L_tmp ); /*Q15 */ + L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */ + L_tmp = L_mac( L_tmp, ( *pt6++ ), q2 ); /*Qsynth+16 */ + ( *pt1++ ) = round_fx( L_tmp ); /*Qsynth */ + move16(); } - flag = sub( flag, tmp_fx ); } + ELSE + { + kk = NS2SA_FX2( L_mult0( L, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ); + p_mdct_ola = old_out + kk; - q1 = i_mult2( 7, L20 ); - q2 = i_mult2( 33, L20 ); - - Copy( synthesis_fx, synthesis_fx + q1, q2 ); - Copy( synthesis_fx + L, gapsynth_fx, L ); - Copy( prevsynth_fx + sub( i_mult2( 37, L20 ), q1 ), synthesis_fx, q1 ); - pt1 = &synthesis_fx[q1]; - q2 = i_mult2( 37, L20 ); - pt6 = &prevsynth_fx[q2]; - tmp_fx = i_mult2( 3, L20 ); + /* overlappadd with the ms of valid mdct of the last frame */ + tmp_fx = i_mult2( 3, L20 ); + pt1 = &synthesis_fx[0]; + pt6 = &p_mdct_ola[0]; + FOR( k = 0; k < tmp_fx; k++ ) + { + L_tmp = L_mult( *sinq_tab, *sinq_tab ); /*Q31 */ + sinq_tab++; + q2 = round_fx( L_sub( 2147483647, L_tmp ) ); /*Q15 */ + q1 = round_fx( L_tmp ); /*Q15 */ + L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */ + L_tmp = L_add_sat( L_tmp, L_shr_sat( Mpy_32_16_1( L_deposit_h( *pt6++ ), q2 ), Q_old_out ) ); /*Qsynth+16 */ + ( *pt1++ ) = round_fx_sat( L_tmp ); /*Qsynth */ + move16(); + } - /* overlappadd with the ms of valid mdct of the last frame */ - FOR( k = 0; k < tmp_fx; k++ ) - { - L_tmp = L_mult( *sinq_tab, *sinq_tab ); /*Q30 */ - sinq_tab++; - q2 = round_fx( L_sub( 2147483647, L_tmp ) ); /*Q15 */ - q1 = round_fx( L_tmp ); /*Q15 */ - L_tmp = L_mult( ( *pt1 ), q1 ); /*Qsynth+16 */ - L_tmp = L_mac( L_tmp, ( *pt6++ ), q2 ); /*Qsynth+16 */ - ( *pt1++ ) = round_fx( L_tmp ); /*Qsynth */ - move16(); + Copy( synthesis_fx, synthesis_fx + kk, sub( 2 * L, kk ) ); + Copy( synthesis_fx + L, gapsynth_fx, L ); + Copy( prevsynth_fx + sub( alignment_point, kk ), synthesis_fx, kk ); } + return; } -#endif -#ifdef HARM_HQ_CORE + static void fec_alg_fx( -#else -static void ivas_fec_alg_fx( -#endif const Word16 *prevsynth, /*Qin */ const Word16 *prevsynth_LP, /*Qin */ Word16 *ni_seed_forfec, @@ -4578,19 +3054,11 @@ static void ivas_fec_alg_fx( Word16 exp; Word16 n, Q; -#ifdef HARM_HQ_CORE fec_ecu_dft_fx( prevsynth_LP, N, Tfr, Tfi, &sum_Tf_abs, Tf_abs, &Nfft, &exp, element_mode ); -#else - ivas_fec_ecu_dft_fx( prevsynth_LP, N, Tfr, Tfi, &sum_Tf_abs, Tf_abs, &Nfft, &exp, element_mode ); -#endif sinusoidal_synthesis_fx( Tfr, Tfi, Tf_abs, N, output_frame, decimatefactor, Nfft, sum_Tf_abs, synthesis, HqVoicing, exp ); -#ifdef HARM_HQ_CORE fec_noise_filling_fx( prevsynth, synthesis, ni_seed_forfec, output_frame, i_mult2( N, decimatefactor ), HqVoicing, gapsynth, element_mode, old_out, Q_old_out ); -#else - ivas_fec_noise_filling_fx( prevsynth, synthesis, ni_seed_forfec, output_frame, i_mult2( N, decimatefactor ), HqVoicing, gapsynth, element_mode, old_out, Q_old_out ); -#endif n = R1_48 - R2_48; move16(); @@ -4614,56 +3082,6 @@ static void ivas_fec_alg_fx( return; } -#ifndef HARM_HQ_CORE -static void fec_alg_fx( - const Word16 *prevsynth, /*Qin */ - const Word16 *prevsynth_LP, /*Qin */ - Word16 *ni_seed_forfec, - Word32 *ecu_rec, /*Qin+16 (Qin+15 to be coherent witch other scaling) */ - const Word16 output_frame, - const Word16 N, - const Word16 decimatefactor, - const Word16 HqVoicing, - Word16 *gapsynth /*Qin */ -) -{ - Word16 Nfft; - Word32 sum_Tf_abs; - Word16 Tfr[FEC_FFT_MAX_SIZE]; - Word16 Tfi[FEC_FFT_MAX_SIZE]; - Word16 Tf_abs[FEC_FFT_MAX_SIZE / 2]; - Word16 synthesis[2 * L_FRAME48k]; - Word16 exp; - Word16 n, Q; - - fec_ecu_dft_fx( prevsynth_LP, N, Tfr, Tfi, &sum_Tf_abs, Tf_abs, &Nfft, &exp ); - - sinusoidal_synthesis_fx( Tfr, Tfi, Tf_abs, N, output_frame, decimatefactor, Nfft, sum_Tf_abs, synthesis, HqVoicing, exp ); - - fec_noise_filling_fx( prevsynth, synthesis, ni_seed_forfec, output_frame, i_mult2( N, decimatefactor ), HqVoicing, gapsynth ); - - n = R1_48 - R2_48; - move16(); - - test(); - IF( EQ_16( output_frame, L_FRAME32k ) || EQ_16( output_frame, L_FRAME16k ) ) - { - n = R1_16 - R2_16; - move16(); - - if ( EQ_16( output_frame, L_FRAME32k ) ) - { - n = 2 * N16_CORE_SW; - move16(); - } - } - Q = 0; - move16(); - wtda_fx( synthesis + sub( output_frame, n ), &Q, ecu_rec, NULL, NULL, ALDO_WINDOW, ALDO_WINDOW, output_frame ); /* return Q15 */ - - return; -} -#endif /*-------------------------------------------------------------------------- * hq_phase_ecu_fx() @@ -4671,11 +3089,7 @@ static void fec_alg_fx( * Main routine for HQ phase ECU *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE static void hq_phase_ecu_fx( -#else -static void ivas_hq_phase_ecu_fx( -#endif const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0*/ Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses Q0*/ @@ -4759,11 +3173,7 @@ static void ivas_hq_phase_ecu_fx( trans_ana_fx( prevsynth + offset, mag_chg, &ph_dith, mag_chg_1st, output_frame, *time_offs, env_stab, *last_fec, element_mode, alpha, beta, beta_mute, Xavg ); -#ifdef HARM_HQ_CORE spec_ana_fx( prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec, element_mode, &noise_fac, pcorr ); -#else - ivas_spec_ana_fx( prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec, element_mode, &noise_fac, pcorr ); -#endif test(); IF( prev_bfi != 0 && *last_fec != 0 ) @@ -4792,22 +3202,13 @@ static void ivas_hq_phase_ecu_fx( seed = extract_l( L_add( L_deposit_l( seed ), L_deposit_l( plocs[*num_p - 1] ) ) ); } -#ifdef HARM_HQ_CORE subst_spec_fx( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, alpha, beta, *beta_mute, Xavg, element_mode, ph_ecu_lookahead, noise_fac ); -#else - ivas_subst_spec_fx( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, - alpha, beta, *beta_mute, Xavg, element_mode, ph_ecu_lookahead, noise_fac ); -#endif /* reconstructed frame in tda domain */ old_dec = prevsynth + sub( shl( output_frame, 1 ), NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), N_ZERO_MDCT_NS ) ); -#ifdef HARM_HQ_CORE rec_frame_fx( X, ecu_rec, output_frame, *Q_spec, old_dec, element_mode, num_p, plocs ); -#else - ivas_rec_frame_fx( X, ecu_rec, output_frame, *Q_spec, old_dec, element_mode, num_p, plocs ); -#endif *last_fec = 0; move16(); @@ -4817,115 +3218,6 @@ static void ivas_hq_phase_ecu_fx( return; } -#ifndef HARM_HQ_CORE -static void hq_phase_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0*/ - Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses Q0*/ - Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ - Word16 *Q_spec, /* i/o: Q value of stored spectrum */ - Word16 *num_p, /* i/o: Number of identified peaks Q0 */ - Word16 *plocs, /* i/o: Peak locations Q0 */ - Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ - const Word16 env_stab, /* i : Envelope stability parameter */ - Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ - Word16 *ph_ecu_active, /* i : Phase ECU active flag */ - const Word16 prev_bfi, /* i : indicating burst frame error */ - const Word16 old_is_transient[2], /* i : flags indicating previous transient frames*/ - Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients*/ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to Q0*/ - Word16 *beta_mute, /* o : Factor for long-term mute Q15 */ - const Word16 bwidth_fx, /* i : Encoded bandwidth */ - const Word16 output_frame /* i : frame length */ -) -{ - Word16 lprot, offset; - Word16 mag_chg[LGW_MAX], ph_dith, X[L_PROT48k]; - Word16 seed; - Word16 alpha[LGW_MAX], beta[LGW_MAX]; - - IF( EQ_16( output_frame, L_FRAME48k ) ) - { - lprot = L_PROT48k; /* 1536 = (2*output_frame)*1024/1280 */ - move16(); - } - ELSE IF( EQ_16( output_frame, L_FRAME32k ) ) - { - lprot = L_PROT32k; /* 1024 */ - move16(); - } - ELSE IF( output_frame == L_FRAME16k ) - { - lprot = 512; - move16(); - } - ELSE - { - lprot = 256; - move16(); - } - - test(); - test(); - test(); - IF( prev_bfi == 0 || ( prev_bfi != 0 && *last_fec != 0 && ( EQ_16( *time_offs, output_frame ) ) ) ) - { - test(); - if ( !( prev_bfi != 0 && *last_fec != 0 ) ) - { - *time_offs = 0; - move16(); - } - - offset = sub( sub( shl( output_frame, 1 ), lprot ), *time_offs ); - - trans_ana_fx( prevsynth + offset, mag_chg, &ph_dith, mag_chg_1st, output_frame, *time_offs, env_stab, - *last_fec, EVS_MONO, alpha, beta, beta_mute, Xavg ); - - spec_ana_fx( prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec ); - - test(); - IF( prev_bfi != 0 && *last_fec != 0 ) - { - *time_offs = add_sat( *time_offs, output_frame ); - move16(); - } - } - ELSE - { - *time_offs = add_sat( *time_offs, output_frame ); - move16(); - - offset = sub( shl( output_frame, 1 ), lprot ); - - trans_ana_fx( prevsynth + offset, mag_chg, &ph_dith, mag_chg_1st, output_frame, *time_offs, env_stab, - 0, EVS_MONO, alpha, beta, beta_mute, Xavg ); - } - - Copy( X_sav, X, lprot ); - - /* seed for own_rand2 */ - seed = *time_offs; - move16(); - IF( *num_p > 0 ) - { - seed = add_sat( seed, plocs[*num_p - 1] ); - } - - subst_spec_fx( plocs, plocsi, num_p, *time_offs, X, mag_chg, ph_dith, old_is_transient, output_frame, &seed, - alpha, beta, *beta_mute, Xavg ); - - /* reconstructed frame in tda domain */ - rec_frame_fx( X, ecu_rec, output_frame, *Q_spec ); - - *last_fec = 0; - move16(); - *ph_ecu_active = 1; - move16(); - - return; -} -#endif /*-------------------------------------------------------------------------- * hq_ecu() @@ -4933,11 +3225,7 @@ static void hq_phase_ecu_fx( * Main routine for HQ ECU *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE void hq_ecu_fx( -#else -void ivas_hq_ecu_fx( -#endif const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses Q0 */ @@ -4987,11 +3275,7 @@ void ivas_hq_ecu_fx( IF( !( LT_16( output_frame, L_FRAME16k ) ) ) { -#ifdef HARM_HQ_CORE fec_ecu_pitch_fx( st_fx->element_mode, fec_alg_input, prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing ); -#else - fec_ecu_pitch_ivas_fx( fec_alg_input, prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing ); -#endif } ELSE { @@ -5055,11 +3339,7 @@ void ivas_hq_ecu_fx( IF( ( ( st_fx->element_mode == EVS_MONO ) && evs_mode_selection ) || ( ( st_fx->element_mode != EVS_MONO ) && evs_mode_selection && ivas_mode_selection ) ) { -#ifdef HARM_HQ_CORE fec_alg_fx( fec_alg_input, prevsynth_LP, &hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth, st_fx->element_mode, hHQ_core->old_out_fx, hHQ_core->Q_old_wtda ); -#else - ivas_fec_alg_fx( fec_alg_input, prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth, st_fx->element_mode, st_fx->hHQ_core->old_out_fx, st_fx->hHQ_core->Q_old_wtda ); -#endif *last_fec = 1; move16(); *ph_ecu_active = 0; @@ -5069,15 +3349,9 @@ void ivas_hq_ecu_fx( } ELSE { -#ifdef HARM_HQ_CORE hq_phase_ecu_fx( prevsynth - NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), PH_ECU_LOOKAHEAD_NS ), ecu_rec, time_offs, X_sav, Q_spec, num_p, plocs, plocsi, env_stab, last_fec, ph_ecu_active, prev_bfi, old_is_transient, mag_chg_1st, Xavg, beta_mute, st_fx->bwidth, output_frame, corr, st_fx->element_mode ); -#else - ivas_hq_phase_ecu_fx( prevsynth - NS2SA_FX2( L_mult0( output_frame, FRAMES_PER_SEC ), PH_ECU_LOOKAHEAD_NS ), ecu_rec, time_offs, X_sav, Q_spec, num_p, plocs, plocsi, - env_stab, last_fec, ph_ecu_active, prev_bfi, old_is_transient, - mag_chg_1st, Xavg, beta_mute, st_fx->bwidth, output_frame, corr, st_fx->element_mode ); -#endif *last_fec = 0; move16(); @@ -5087,87 +3361,6 @@ void ivas_hq_ecu_fx( return; } -#ifndef HARM_HQ_CORE -void hq_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ - Word32 *ecu_rec, /* o : reconstructed frame in tda domain */ - Word16 *time_offs, /* i/o: Sample offset for consecutive frame losses Q0 */ - Word16 *X_sav, /* i/o: Stored spectrum of prototype frame */ - Word16 *Q_spec, /* i/o: Q value of stored spectrum */ - Word16 *num_p, /* i/o: Number of identified peaks Q0 */ - Word16 *plocs, /* i/o: Peak locations Q0 */ - Word32 *plocsi, /* i/o: Interpolated peak locations Q16 */ - const Word16 env_stab, /* i : Envelope stability parameter */ - Word16 *last_fec, /* i/o: Flag for usage of pitch dependent ECU */ - const Word16 ph_ecu_HqVoicing, /* i : HQ Voicing flag */ - Word16 *ph_ecu_active, /* i : Phase ECU active flag */ - Word16 *gapsynth, /* o : Gap synthesis */ - const Word16 prev_bfi, /* i : indicating burst frame error */ - const Word16 old_is_transient[2], /* i : flags indicating previous transient frames */ - Word16 *mag_chg_1st, /* i/o: per band magnitude modifier for transients */ - Word16 *Xavg, /* i/o: Frequency group average gain to fade to Q0 */ - Word16 *beta_mute, /* o : Factor for long-term mute Q15 */ - const Word16 output_frame, /* i : frame length */ - Decoder_State *st_fx /* i/o: decoder state structure */ -) -{ - Word16 N; - Word16 decimatefactor; - Word16 corr; /*Q15 */ - Word16 prevsynth_LP[2 * L_FRAME8k]; - /* init (values ar changed after) */ - decimatefactor = 4; - move16(); - N = shr( output_frame, 2 ); - - /* find pitch and R value */ - IF( !( LT_16( output_frame, L_FRAME16k ) ) ) - { - fec_ecu_pitch_fx( prevsynth + NS2SA_FX2( L_mult0( output_frame, 50 ), ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing ); - } - ELSE - { - corr = 0; - move16(); /* just to avoid using uninitialized value in if statement below */ - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( GE_32( st_fx->total_brate, 48000 ) && - ( GE_16( output_frame, L_FRAME16k ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) && ( NE_16( ph_ecu_HqVoicing, 0 ) || ( ( ( NE_16( st_fx->hHQ_core->env_stab_plc_fx, 0 ) ) && ( LT_16( corr, 19661 ) ) ) || ( !( NE_16( st_fx->hHQ_core->env_stab_plc_fx, 0 ) ) && ( GT_16( corr, 27853 ) ) ) ) ) ) ) || - ( LT_32( st_fx->total_brate, 48000 ) && ( ( ph_ecu_HqVoicing || GT_16( corr, 27853 ) ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) ) ) ) - { - fec_alg_fx( prevsynth + NS2SA_FX2( L_mult0( output_frame, 50 ), ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth ); - *last_fec = 1; - move16(); - *ph_ecu_active = 0; - move16(); - *time_offs = output_frame; - move16(); - } - ELSE - { - hq_phase_ecu_fx( prevsynth, ecu_rec, time_offs, X_sav, Q_spec, num_p, plocs, plocsi, - env_stab, last_fec, ph_ecu_active, prev_bfi, old_is_transient, - mag_chg_1st, Xavg, beta_mute, st_fx->bwidth, output_frame ); - } - - return; -} -#endif /******************************************************************************* * The square root of x which MUST be 0.5 <= x < 1, i.e., x must be normalized. diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index c069ef068..780f7a2b5 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -343,11 +343,7 @@ ivas_error evs_dec_fx( } ELSE { -#ifdef HARM_HQ_CORE hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag, NULL ); -#else - hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag ); -#endif Qpostd = Q_synth; move16(); } diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index 5b5fe93f7..d00426514 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -12,12 +12,8 @@ * HQ mode selector (decision_matrix) *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE /* o : Consumed bits Q0 */ Word16 hq_classifier_dec_fx( -#else -Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits Q0 */ -#endif Decoder_State *st_fx, /* i/o: decoder state structure */ const Word32 core_brate, /* i : Core bit rate Q0 */ const Word16 length, /* i : Frame length Q0 */ @@ -85,75 +81,3 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits Q0 */ return bits; } -#ifndef HARM_HQ_CORE - -Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word32 core_brate, /* i : Core bit rate Q0 */ - const Word16 length, /* i : Frame length Q0 */ - Word16 *is_transient, /* o : Transient flag Q0 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ -) -{ - Word16 bits; - Word32 max_brate; - - max_brate = HQ_32k; /* Q0 */ - move32(); - if ( st_fx->element_mode > EVS_MONO ) - { - max_brate = HQ_48k; /* Q0 */ - move32(); - } - test(); - test(); - test(); - test(); - IF( ( EQ_16( length, L_SPEC32k ) || EQ_16( length, L_FRAME48k ) ) && LE_32( core_brate, max_brate ) ) - { - *hqswb_clas = get_next_indice_fx( st_fx, 2 ); /* Q0 */ - move16(); - bits = 2; - move16(); - } - ELSE IF( EQ_16( length, L_SPEC16k_EXT ) || EQ_16( length, L_SPEC48k_EXT ) ) - { - *hqswb_clas = HQ_NORMAL; /* Q0 */ - bits = 0; - move16(); - move16(); - } - ELSE - { - *hqswb_clas = get_next_indice_fx( st_fx, 1 ); /* Q0 */ - move16(); - bits = 1; - move16(); - } - - *is_transient = 0; - move16(); - if ( EQ_16( *hqswb_clas, HQ_TRANSIENT ) ) - { - *is_transient = 1; /* Q0 */ - move16(); - } - - test(); - IF( LE_32( st_fx->core_brate, HQ_32k ) && *hqswb_clas == HQ_NORMAL ) - { - IF( EQ_16( length, L_SPEC32k ) ) - { - *hqswb_clas = HQ_GEN_SWB; /* Q0 */ - move16(); - } - ELSE IF( EQ_16( length, L_FRAME48k ) ) - { - *hqswb_clas = HQ_GEN_FB; /* Q0 */ - move16(); - } - } - - return bits; -} -#endif diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index ee2633894..644b8b370 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -16,456 +16,6 @@ * HQ core decoder *--------------------------------------------------------------------------*/ void hq_core_dec_fx( -#ifndef HARM_HQ_CORE - Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis Q_synth*/ - Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length Q0*/ - const Word16 hq_core_type, /* i : HQ core type Q0*/ - const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ -) -{ - Word16 num_bits, is_transient, hqswb_clas, inner_frame; - Word16 i, j, flag_uv, num_Sb, nb_sfm; - Word16 ynrm[NB_SFM], num_bands_p[MAX_SB_NB]; - Word16 ener_match; /* Q13 */ - Word32 t_audio_q[L_FRAME48k_EXT]; /* Q12 */ - Word16 Q_audio; - Word32 wtda_audio[2 * L_FRAME48k]; - Word16 delay_comp; - Word32 normq_fx[NB_SFM]; - Word16 mean_en_high_fx; - Word16 SWB_fenv_fx[SWB_FENV + DIM_FB]; - const Word16 *sfmsize, *sfm_start, *sfm_end; - Word16 gapsynth_fx[L_FRAME48k]; - Word16 tmp, tmp_loop; - Word32 L_tmp; - UWord16 lsb; - Word16 L_spec; - HQ_NBFEC_HANDLE hHQ_nbfec; - HQ_DEC_HANDLE hHQ_core; - hHQ_nbfec = st_fx->hHQ_nbfec; - hHQ_core = st_fx->hHQ_core; - - /*-------------------------------------------------------------------------- - * Initializations - *--------------------------------------------------------------------------*/ - - set32_fx( t_audio_q, 0, L_FRAME48k_EXT ); - set16_fx( gapsynth_fx, 0, L_FRAME48k ); - set16_fx( num_bands_p, 0, MAX_SB_NB ); - set16_fx( ynrm, 39, NB_SFM ); /* Initialize to the smallest value */ - mean_en_high_fx = 0; - move16(); - Q_audio = 12; - move16(); - sfm_start = sfm_end = NULL; - num_Sb = nb_sfm = 0; - move16(); - move16(); - - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; /* Q0 */ - move16(); - if ( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) - { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; /* Q0 */ - move16(); - } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; /* Q0 */ - move16(); - /*-------------------------------------------------------------------------- - * Find the number of bits for transform-domain coding - *--------------------------------------------------------------------------*/ - - /* set the total bit-budget */ - /*num_bits = (short)(st->total_brate / 50); */ - Mpy_32_16_ss( st_fx->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l( L_shr( L_tmp, 3 ) ); /*Q0 */ - IF( !st_fx->bfi ) - { - IF( EQ_16( core_switching_flag, 1 ) ) - { - { - core_switching_hq_prepare_dec_fx( st_fx, &num_bits, output_frame ); - - /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ - if ( GT_16( num_bits, HQ_48k / 50 ) ) - { - num_bits = (Word16) ( HQ_48k / 50 ); - move16(); - } - } - } - /* subtract signalling bits */ - num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ - - /* set FEC parameters */ - flag_uv = sub( 1, hHQ_core->HqVoicing ); /* Q0 */ - - /* subtract the number of bits for pitch & gain at higher bitrates */ - test(); - IF( !( core_switching_flag ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) - { - hHQ_core->HqVoicing = get_next_indice_fx( st_fx, 1 ); /* Q0 */ - move16(); - num_bits = sub( num_bits, 1 ); /* Q0 */ - } - ELSE - { - hHQ_core->HqVoicing = 0; - move16(); - if ( GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) - { - hHQ_core->HqVoicing = 1; /* Q0 */ - move16(); - } - } - } - ELSE - { - flag_uv = 0; - move16(); - } - - /* set inner frame (== coded bandwidth) length */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ - move16(); - L_spec = inner_frame; /* Q0 */ - move16(); - - IF( st_fx->bfi == 0 ) - { - hHQ_core->ph_ecu_HqVoicing = 0; - move16(); - if ( GE_16( output_frame, L_FRAME16k ) ) - { - hHQ_core->ph_ecu_HqVoicing = hHQ_core->HqVoicing; - move16(); - } - } - - IF( EQ_16( output_frame, L_FRAME8k ) ) - { - hq_configure_bfi_fx( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end ); - } - - /*-------------------------------------------------------------------------- - * transform-domain decoding - *--------------------------------------------------------------------------*/ - - IF( EQ_16( st_fx->bfi, 1 ) ) - { - is_transient = hHQ_core->old_is_transient[0]; /* Q0 */ - move16(); - IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ - { - /* ecu_rec sent to OLA, env_stab passed in ph_ecu_st */ - hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p, hHQ_core->plocs, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, - &hHQ_core->last_fec, hHQ_core->ph_ecu_HqVoicing, &hHQ_core->ph_ecu_active, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient, hHQ_core->mag_chg_1st_fx, - hHQ_core->Xavg_fx, &hHQ_core->beta_mute_fx, output_frame, st_fx ); - } - ELSE - { - HQ_FEC_processing_fx( st_fx, t_audio_q, is_transient, hHQ_nbfec->ynrm_values_fx, hHQ_nbfec->r_p_values_fx, num_Sb, nb_sfm, num_bands_p, - output_frame, sfm_start, sfm_end ); - } - - hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ - move16(); - hHQ_core->old_is_transient[1] = hHQ_core->old_is_transient[0]; /* Q0 */ - move16(); - - IF( GE_16( output_frame, L_FRAME16k ) ) - { - /* keep st->previoussynth updated as in FEC_HQ_pitch_analysis but no LP analysis */ - delay_comp = NS2SA_FX2( st_fx->output_Fs, DELAY_CLDFB_NS ); /* Q0 */ - - Copy( st_fx->previoussynth_fx + delay_comp, st_fx->previoussynth_fx, sub( output_frame, delay_comp ) ); /* Q0 */ - Copy( st_fx->delay_buf_out_fx, st_fx->previoussynth_fx + output_frame - delay_comp, delay_comp ); /* Q0 */ - - flag_uv = 1; - move16(); /* disable costly pitch out synthesis in bfi frame */ - hHQ_core->HqVoicing = sub( 1, flag_uv ); /* safety setting for HQ->ACELP switch logic Q0*/ - set16_fx( hHQ_core->fer_samples_fx, 0, L_FRAME48k ); /* safety, create a known signal state for HQ->ACELP switch logic */ - } - } - ELSE - { - IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) - { - IF( EQ_16( st_fx->prev_bfi, 1 ) ) - { - set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); - set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); - hHQ_core->last_max_pos_pulse = 0; - move16(); - } - - /* HQ low rate decoder */ - hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); - hqswb_clas = is_transient; /* Q0 */ - move16(); - Q_audio = 12; - move16(); - } - ELSE - { - /* HQ high rate decoder */ - hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); - Q_audio = 12; - move16(); - } - - { - /* scaling (coefficients are in nominal level) */ - IF( NE_16( output_frame, NORM_MDCT_FACTOR ) ) - { - IF( EQ_16( output_frame, L_FRAME32k ) ) - { - Q_audio = sub( Q_audio, 1 ); /* Multiply by 2 */ - } - ELSE - { - tmp = mult_r( output_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling_inv[tmp]; /* Q13 */ - move16(); - FOR( i = 0; i < inner_frame; i++ ) - { - /*t_audio_q[i] *= ener_match;*/ - Mpy_32_16_ss( t_audio_q[i], ener_match, &L_tmp, &lsb ); /*12+13-15=10 */ - t_audio_q[i] = L_add_sat( L_shl_sat( L_tmp, 2 ), L_shr( lsb, 14 ) ); - move16(); /* Q12 */ - } - } - } - } - HQ_FEC_Mem_update_fx( st_fx, t_audio_q, normq_fx, ynrm, num_bands_p, is_transient, hqswb_clas, - core_switching_flag, nb_sfm, num_Sb, &mean_en_high_fx, hq_core_type, output_frame ); - } - /*-------------------------------------------------------------------------- - * Attenuate HFs in case of band-width switching (from higher BW to lower BW) - *--------------------------------------------------------------------------*/ - /* attenuate HFs in case of band-width switching */ - IF( st_fx->bws_cnt1 > 0 ) - { - IF( EQ_16( st_fx->bws_cnt1, N_NS2W_FRAMES ) ) - { - ener_match = 32767; - move16(); /* 1.0f in Q15 */ - } - ELSE - { - ener_match = div_s( st_fx->bws_cnt1, N_NS2W_FRAMES ); /*Q15*/ - } - - IF( is_transient ) - { - FOR( i = 0; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) - { - tmp_loop = mult( inner_frame, 8192 /* 0.25 in Q15 */ ); - FOR( j = mult( inner_frame_tbl[st_fx->bwidth - 1], 8192 ); j < tmp_loop; j++ ) - { - tmp = i_mult( i, inner_frame ); /*Q0*/ - tmp = mult( tmp, 8192 /* 0.25 in Q15 */ ); /*Q0*/ - tmp = add( tmp, j ); - t_audio_q[tmp] = Mult_32_16( t_audio_q[tmp], ener_match ); - move32(); /*Q12*/ - } - } - } - ELSE - { - FOR( i = inner_frame_tbl[st_fx->bwidth - 1]; i < inner_frame; i++ ) - { - t_audio_q[i] = Mult_32_16( t_audio_q[i], ener_match ); /*Q12*/ - move32(); - } - } - } - - /* WB/SWB bandwidth switching */ - IF( is_transient ) - { - Copy_Scale_sig_32_16( &t_audio_q[240], st_fx->t_audio_q_fx, 80, -13 ); /* -1Q */ - } - ELSE - { - Copy_Scale_sig_32_16( t_audio_q, st_fx->t_audio_q_fx, L_FRAME, -13 ); /* -1Q */ - } - - - /*-------------------------------------------------------------------------- - * Inverse transform - * Overlap-add - * Pre-echo reduction - *--------------------------------------------------------------------------*/ - { - test(); - IF( EQ_16( output_frame, L_FRAME8k ) || st_fx->bfi == 0 ) - { - test(); - IF( NE_16( inner_frame, output_frame ) && EQ_16( st_fx->bfi, 1 ) ) - { - Inverse_Transform( t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, output_frame, st_fx->element_mode ); - } - ELSE - { - Inverse_Transform( t_audio_q, &Q_audio, wtda_audio, is_transient, output_frame, inner_frame, st_fx->element_mode ); - } - *Q_synth = Q_audio; - move16(); - } - } - IF( EQ_16( output_frame, L_FRAME8k ) ) - { - test(); - IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) - { - Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 15 - exp_old_out - Q_old_wtda */ - } - ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) - { - set16_fx( hHQ_nbfec->prev_oldauOut_fx, 0, output_frame ); - } - - test(); - test(); - test(); - test(); - IF( ( EQ_16( st_fx->prev_bfi, 1 ) || EQ_16( st_fx->bfi, 1 ) ) && hHQ_core->old_is_transient[2] == 0 && EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) ) - { - time_domain_FEC_HQ_fx( st_fx, wtda_audio, synth, mean_en_high_fx, output_frame, Q_synth ); - } - ELSE - { - window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); - hHQ_nbfec->phase_mat_next = 0; - move16(); - } - - test(); - test(); - IF( ( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) || !( GE_16( output_frame, L_FRAME16k ) ) ) - { - preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, - &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); - } - } - ELSE - { - test(); - IF( EQ_16( st_fx->bfi, 1 ) && GE_16( output_frame, L_FRAME16k ) ) - { - /* PHASE_ECU active */ - Q_audio = 15; - move16(); - window_ola_fx( t_audio_q, synth, &Q_audio, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - ALDO_WINDOW, ALDO_WINDOW, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); - *Q_synth = Q_audio; - move16(); - } - ELSE - { - /* no BFI or baseline PLC active */ - window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi && !hHQ_core->ph_ecu_active, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); - } - test(); - test(); - IF( ( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) || !( GE_16( output_frame, L_FRAME16k ) ) ) - { - preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, - &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, - &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); - } - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( !st_fx->bfi && st_fx->prev_bfi && GE_32( st_fx->last_total_brate, HQ_48k ) && EQ_16( st_fx->last_codec_mode, MODE2 ) && ( EQ_16( st_fx->last_core_bfi, TCX_20_CORE ) || EQ_16( st_fx->last_core_bfi, TCX_10_CORE ) ) && st_fx->hPlcInfo->concealment_method == TCX_NONTONAL && LT_32( st_fx->hPlcInfo->nbLostCmpt, 4 ) ) - { - st_fx->hPlcInfo->recovery_gain = shl_sat( st_fx->hPlcInfo->recovery_gain, *Q_synth ); /* Q14 + Q_synth */ - move16(); - IF( st_fx->hTonalMDCTConc->q_lastPcmOut != 0 ) - { - Scale_sig( st_fx->hTonalMDCTConc->secondLastPcmOut, shr( st_fx->hPlcInfo->L_frameTCX, 1 ), negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) ); - Scale_sig( st_fx->hTonalMDCTConc->lastPcmOut, st_fx->hPlcInfo->L_frameTCX, negate( st_fx->hTonalMDCTConc->q_lastPcmOut ) ); - st_fx->hTonalMDCTConc->q_lastPcmOut = 0; - move16(); - } - waveform_adj2_fix( st_fx->hPlcInfo, st_fx->hTonalMDCTConc->secondLastPcmOut, synth, 0, add( extract_l( st_fx->hPlcInfo->nbLostCmpt ), 1 ), st_fx->bfi ); - } - - IF( GE_16( output_frame, L_FRAME16k ) ) - { - IF( EQ_16( hHQ_core->ph_ecu_HqVoicing, 1 ) ) - { - hHQ_core->oldHqVoicing = 1; - move16(); - Copy( gapsynth_fx, hHQ_core->oldgapsynth_fx, L_FRAME48k ); /* q_gapsynth */ - } - ELSE - { - hHQ_core->oldHqVoicing = 0; - move16(); - } - } - ELSE - { - hHQ_core->oldHqVoicing = 0; - move16(); - } - - if ( EQ_16( st_fx->nbLostCmpt, FRAMECTTOSTART_MDCT ) ) - { - hHQ_core->HqVoicing = 0; - move16(); - } - - IF( EQ_16( output_frame, L_FRAME8k ) ) - { - Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ - Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* q_old_auOut */ - Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ - } - - /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ - - { - Word16 nbsubfr; - /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; /* Q0 */ - move16(); - if ( EQ_16( st_fx->L_frame, 320 ) ) - { - nbsubfr = 5; /* Q0 */ - move16(); - } - - /* update buffer of old subframe pitch values */ - test(); - IF( EQ_16( st_fx->last_core, HQ_CORE ) && NE_16( st_fx->L_frame, st_fx->last_L_frame ) ) - { - set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - } - Copy32( &st_fx->old_pitch_buf_fx[nbsubfr], &st_fx->old_pitch_buf_fx[0], nbsubfr ); /* 15Q16 */ - set32_fx( &st_fx->old_pitch_buf_fx[nbsubfr], ( L_SUBFR << 16 ), nbsubfr ); - Copy( &st_fx->mem_pitch_gain[2], &st_fx->mem_pitch_gain[nbsubfr + 2], nbsubfr ); /* Q14 */ - set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); - } - return; -} - - -void ivas_hq_core_dec_fx( -#endif Decoder_State *st_fx, /* i/o: decoder state structure fx */ Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ @@ -493,10 +43,8 @@ void ivas_hq_core_dec_fx( Word32 L_tmp; UWord16 lsb; Word16 L_spec; -#ifdef HARM_HQ_CORE const Word16 *sfmsize, *sfm_start, *sfm_end; HQ_NBFEC_HANDLE hHQ_nbfec; -#endif HQ_DEC_HANDLE hHQ_core; TCX_DEC_HANDLE hTcxDec; TCX_CONFIG_HANDLE tcx_cfg; @@ -512,17 +60,13 @@ void ivas_hq_core_dec_fx( Word16 Q_output; hHQ_core = st_fx->hHQ_core; -#ifdef HARM_HQ_CORE hHQ_nbfec = st_fx->hHQ_nbfec; -#endif Q_output = 0; move16(); *Q_synth = 0; move16(); -#ifdef HARM_HQ_CORE if ( st_fx->element_mode > EVS_MONO ) -#endif { st_fx->Q_syn_factor = 0; move16(); @@ -585,7 +129,6 @@ void ivas_hq_core_dec_fx( } ELSE { -#ifdef HARM_HQ_CORE core_switching_hq_prepare_dec_fx( st_fx, &num_bits, output_frame ); /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ @@ -594,9 +137,6 @@ void ivas_hq_core_dec_fx( num_bits = (Word16) ( HQ_48k / 50 ); move16(); } -#else - /* this cannot happen in IVAS */ -#endif } } IF( hq_recovery_flag ) @@ -650,7 +190,6 @@ void ivas_hq_core_dec_fx( } } -#ifdef HARM_HQ_CORE IF( EQ_16( output_frame, L_FRAME8k ) ) { hq_configure_bfi_fx( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end ); @@ -662,7 +201,6 @@ void ivas_hq_core_dec_fx( sfm_end = NULL; } -#endif /*-------------------------------------------------------------------------- * transform-domain decoding *--------------------------------------------------------------------------*/ @@ -674,23 +212,15 @@ void ivas_hq_core_dec_fx( IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { /* ecu_rec sent to OLA, env_stab passed in ph_ecu_st */ -#ifdef HARM_HQ_CORE hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p, hHQ_core->plocs, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, &hHQ_core->last_fec, hHQ_core->ph_ecu_HqVoicing, &hHQ_core->ph_ecu_active, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient, hHQ_core->mag_chg_1st_fx, hHQ_core->Xavg_fx, &hHQ_core->beta_mute_fx, output_frame, st_fx ); -#else - ivas_hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p, hHQ_core->plocs, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, - &hHQ_core->last_fec, hHQ_core->ph_ecu_HqVoicing, &hHQ_core->ph_ecu_active, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient, hHQ_core->mag_chg_1st_fx, - hHQ_core->Xavg_fx, &hHQ_core->beta_mute_fx, output_frame, st_fx ); -#endif } -#ifdef HARM_HQ_CORE ELSE { HQ_FEC_processing_fx( st_fx, t_audio_q, is_transient, hHQ_nbfec->ynrm_values_fx, hHQ_nbfec->r_p_values_fx, num_Sb, nb_sfm, num_bands_p, output_frame, sfm_start, sfm_end ); } -#endif hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); @@ -716,7 +246,6 @@ void ivas_hq_core_dec_fx( { IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { -#ifdef HARM_HQ_CORE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); @@ -730,39 +259,17 @@ void ivas_hq_core_dec_fx( hqswb_clas = is_transient; /* Q0 */ move16(); -#else - /* this cannot happen in IVAS */ - - is_transient = 0; - move16(); - hqswb_clas = is_transient; /* Q0 */ - move16(); - Q_audio = 12; - move16(); - Q_G_audio = Q_audio; - move16(); -#endif } ELSE { /* HQ high rate decoder */ -#ifdef HARM_HQ_CORE hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); -#else - ivas_hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); - Q_audio = 12; - move16(); - Q_G_audio = Q_audio; - move16(); -#endif } -#ifdef HARM_HQ_CORE Q_audio = Q12; move16(); Q_G_audio = Q_audio; move16(); -#endif test(); test(); @@ -812,12 +319,10 @@ void ivas_hq_core_dec_fx( ELSE { ener_match = imult1616( st_fx->bws_cnt1, ONE_BY_N_NS2W_FRAMES_Q15 ); /*Q15*/ -#ifdef HARM_HQ_CORE if ( st_fx->element_mode == EVS_MONO ) { ener_match = div_s( st_fx->bws_cnt1, N_NS2W_FRAMES ); /*Q15*/ } -#endif } IF( is_transient ) @@ -981,7 +486,6 @@ void ivas_hq_core_dec_fx( move16(); } -#ifdef HARM_HQ_CORE IF( EQ_16( output_frame, L_FRAME8k ) ) { test(); @@ -1020,15 +524,12 @@ void ivas_hq_core_dec_fx( } } ELSE -#endif { test(); IF( EQ_16( st_fx->bfi, 1 ) && GE_16( output_frame, L_FRAME16k ) ) { /* PHASE_ECU active */ -#ifdef HARM_HQ_CORE IF( st_fx->element_mode > EVS_MONO ) -#endif { Scale_sig32( t_audio_q, L_FRAME48k_EXT, sub( Q15, Q_audio ) ); } @@ -1061,7 +562,6 @@ void ivas_hq_core_dec_fx( } } -#ifdef HARM_HQ_CORE IF( st_fx->element_mode == EVS_MONO ) { test(); @@ -1087,7 +587,6 @@ void ivas_hq_core_dec_fx( } } -#endif IF( GE_16( output_frame, L_FRAME16k ) ) { IF( EQ_16( hHQ_core->ph_ecu_HqVoicing, 1 ) ) @@ -1114,7 +613,6 @@ void ivas_hq_core_dec_fx( move16(); } -#ifdef HARM_HQ_CORE IF( EQ_16( output_frame, L_FRAME8k ) ) { Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ @@ -1122,7 +620,6 @@ void ivas_hq_core_dec_fx( Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ } -#endif /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ { Word16 nbsubfr; @@ -1146,9 +643,7 @@ void ivas_hq_core_dec_fx( set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } -#ifdef HARM_HQ_CORE IF( GT_16( st_fx->element_mode, EVS_MONO ) ) -#endif { /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ Copy_Scale_sig( output, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame, negate( Q_output ) ); /* Q0 */ diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 342a18bbc..0c9fb88d6 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -14,60 +14,6 @@ * * HQ core HB band-width switching handling *--------------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE -void ivas_hq_pred_hb_bws_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 *ynrm, /* i : norm quantization index vector Q0*/ - const Word16 length, /* i : frame length Q0*/ - const Word16 hqswb_clas, /* i : HQ SWB class Q0*/ - const Word16 *SWB_fenv /* i : SWB frequency envelopes Q1*/ -) -{ - Word16 i; - Word32 L_tmp; - - IF( GE_16( length, L_FRAME32k ) ) - { - /* calculate the switching parameters */ - test(); - test(); - IF( ( NE_16( hqswb_clas, HQ_GEN_SWB ) && LE_32( st_fx->core_brate, HQ_32k ) ) || GT_32( st_fx->core_brate, HQ_32k ) ) - { - st_fx->prev_ener_shb_fx = 0; - move16(); - L_tmp = L_deposit_l( 0 ); - FOR( i = 25; i < SFM_N_HARM; i++ ) - { - L_tmp = L_add( L_tmp, dicn_fx[ynrm[i]] ); /*Q14*/ - } - L_tmp = L_min( 8191, L_shr( L_tmp, 13 ) ); /* Q1 */ - st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ - st_fx->prev_ener_shb_fx = mult( st_fx->prev_ener_shb_fx, 5461 ); /*Q1*/ - move16(); - move16(); - } - ELSE - { - st_fx->prev_ener_shb_fx = 0; - move16(); - L_tmp = L_deposit_l( 0 ); - FOR( i = 0; i < SWB_FENV - 3; i++ ) - { - L_tmp = L_add( L_tmp, SWB_fenv[i] ); /*Q1*/ - } - L_tmp = Mpy_32_16_1( L_tmp, 2979 ); // Q1 - st_fx->prev_ener_shb_fx = extract_l( L_tmp ); /*Q1*/ - } - } - - IF( GE_16( st_fx->last_inner_frame, L_FRAME32k ) && st_fx->hBWE_FD != NULL ) - { - set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); - } - - return; -} -#endif void hq_pred_hb_bws_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -115,12 +61,8 @@ void hq_pred_hb_bws_fx( } } -#ifdef HARM_HQ_CORE test(); IF( GE_16( st_fx->last_inner_frame, L_FRAME32k ) && st_fx->hBWE_FD != NULL ) -#else - IF( GE_16( st_fx->last_inner_frame, L_FRAME32k ) ) -#endif { set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, st_fx->prev_ener_shb_fx, SWB_FENV ); } @@ -135,11 +77,7 @@ void hq_pred_hb_bws_fx( * HQ High rate decoding routine *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE void hq_hr_dec_fx( -#else -void ivas_hq_hr_dec_fx( -#endif Decoder_State *st_fx, /* i/o: decoder state structure fx */ Word32 *t_audio_q, /* o : transform-domain coefficients Q12 */ const Word16 length, /* i : frame length Q0 */ @@ -207,11 +145,7 @@ void ivas_hq_hr_dec_fx( * Decode classification *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ -#else - bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ -#endif bits_left = sub( num_bits, bits ); /* Q0 */ @@ -219,13 +153,8 @@ void ivas_hq_hr_dec_fx( * set quantization parameters *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE hq_configure_fx( length, *hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); -#else - ivas_hq_configure_fx( length, *hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, - &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); -#endif /*------------------------------------------------------------------* * Unpacking bitstream @@ -310,12 +239,7 @@ void ivas_hq_hr_dec_fx( * Bit allocation *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE hq_bit_allocation_fx( st_fx->core_brate, length, *hqswb_clas, &bits_left, normqlg2, nb_sfm, sfmsize, noise_level, R, Rsubband, &sum, &core_sfm, num_env_bands ); -#else - ivas_hq_bit_allocation_fx( st_fx->core_brate, length, *hqswb_clas, &bits_left, normqlg2, nb_sfm, sfmsize, noise_level, - R, Rsubband, &sum, &core_sfm, num_env_bands ); -#endif test(); test(); @@ -356,11 +280,7 @@ void ivas_hq_hr_dec_fx( } ELSE { -#ifdef HARM_HQ_CORE pvq_core_dec_fx( st_fx, sfm_start, sfm_end, sfmsize, t_audio_q_norm, &Q_audio, sum, nb_sfm, Rsubband, R, pulses, maxpulse, HQ_CORE ); -#else - ivas_pvq_core_dec_fx( st_fx, sfm_start, sfm_end, sfmsize, t_audio_q_norm, &Q_audio, sum, nb_sfm, Rsubband, R, pulses, maxpulse, HQ_CORE ); -#endif } test(); @@ -401,290 +321,6 @@ void ivas_hq_hr_dec_fx( * Spectral filling *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE - fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, - &hHQ_core->no_att_hangover, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed, hq_generic_exc_clas, - core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient[0], - hHQ_core->prev_normq_fx, hHQ_core->prev_env_fx, st_fx->prev_bfi, sfmsize, sfm_start, sfm_end, - &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas, num_sfm, hHQ_core->prev_env_Q, num_env_bands, st_fx->element_mode ); -#else - ivas_fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, - &hHQ_core->no_att_hangover, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed, hq_generic_exc_clas, - core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient[0], - hHQ_core->prev_normq_fx, hHQ_core->prev_env_fx, st_fx->prev_bfi, sfmsize, sfm_start, sfm_end, - &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas, num_sfm, hHQ_core->prev_env_Q, num_env_bands, st_fx->element_mode ); -#endif - - enforce_zero_for_min_envelope_fx( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); - - IF( EQ_16( *is_transient, 1 ) ) - { -#ifdef HARM_HQ_CORE - de_interleave_spectrum_fx( t_audio_q, length ); -#else - ivas_de_interleave_spectrum_fx( t_audio_q, length ); -#endif - } - - /*------------------------------------------------------------------* - * WB/SWB bandwidth switching - *------------------------------------------------------------------*/ - -#ifdef HARM_HQ_CORE - hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); -#else - ivas_hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); -#endif - - /* update */ - hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ - move16(); - - return; -} -#ifndef HARM_HQ_CORE - -void hq_hr_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word32 *t_audio_q, /* o : transform-domain coefficients Q12 */ - const Word16 length, /* i : frame length Q0 */ - Word16 num_bits, /* i : number of available bits Q0 */ - Word16 *ynrm, /* o : norm quantization index vector Q0 */ - Word16 *is_transient, /* o : transient flag Q0 */ - Word16 *hqswb_clas, /* o : HQ SWB class Q0 */ - Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ - const Word16 core_switching_flag /* i : Core switching flag Q0 */ -) -{ - Word16 nb_sfm; - Word16 sum, hcode_l; - Word16 sfmsize[NB_SFM], sfm_start[NB_SFM], sfm_end[NB_SFM]; - Word16 num_sfm, numnrmibits; - Word16 nf_idx; - Word16 normqlg2[NB_SFM], R[NB_SFM]; - Word16 pulses[NB_SFM], maxpulse[NB_SFM]; - Word16 env_stab; /*Q15*/ - Word16 Rsubband[NB_SFM]; /*Q3*/ - Word16 start_norm, Npeaks = 0; - Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /*Q15*/ - Word16 peak_idx[HVQ_MAX_PEAKS]; - Word16 hq_generic_offset; - Word16 num_env_bands; - Word16 hq_generic_exc_clas = 0; - Word16 core_sfm; - Word16 har_freq_est1, har_freq_est2; - Word16 flag_dis; - const Word16 *subband_search_offset; - Word16 wBands[2]; - Word16 bits, i; - Word16 t_audio_q_norm[L_FRAME48k]; - Word16 Q_audio; - Word16 b_delta_env; - Word16 tmp, n_band; - Word16 Q_shift; - Word16 bits_left; - Word16 csw_flag1, csw_flag2; - move16(); - move16(); - - HQ_DEC_HANDLE hHQ_core = st_fx->hHQ_core; - hq_generic_offset = 0; - move16(); - move16(); - - Q_audio = 0; /* to avoid compilation warnings */ - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - set16_fx( pulses, 0, NB_SFM ); - set16_fx( maxpulse, 0, NB_SFM ); - flag_dis = 1; - move16(); - har_freq_est1 = 0; - move16(); - har_freq_est2 = 0; - move16(); - set16_fx( peak_idx, 0, HVQ_MAX_PEAKS ); - - /*------------------------------------------------------------------* - * Decode classification - *------------------------------------------------------------------*/ - - bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); - bits_left = sub( num_bits, bits ); - - /*------------------------------------------------------------------* - * set quantization parameters - *------------------------------------------------------------------*/ - - hq_configure_evs_fx( length, *hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, - &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); - - /*------------------------------------------------------------------* - * Unpacking bitstream - *------------------------------------------------------------------*/ - - nf_idx = 0; - move16(); - test(); - test(); - test(); - IF( !*is_transient && NE_16( *hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) - { - nf_idx = get_next_indice_fx( st_fx, 2 ); /* Q0 */ - } - - /*------------------------------------------------------------------* - * Decode envelope - *------------------------------------------------------------------*/ - - hcode_l = decode_envelope_indices_fx( st_fx, start_norm, num_env_bands, numnrmibits, ynrm, NORMAL_HQ_CORE, *is_transient ); /* Q0 */ - bits_left = sub( bits_left, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ - - dequantize_norms_fx( st_fx, start_norm, num_env_bands, *is_transient, ynrm, normqlg2 ); - - test(); - IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) - { - hq_generic_exc_clas = swb_bwe_gain_deq_fx( st_fx, HQ_CORE, NULL, SWB_fenv, st_fx->core_brate >= HQ_32k, *hqswb_clas ); /* Use (st->core_brate >= HQ_32k) to be consistent with hq_configure Q0*/ - if ( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) - { - bits_left = add( bits_left, 1 ); /* conditional 1 bit saving for representing HQ GENERIC excitation class Q0*/ - } - map_hq_generic_fenv_norm_fx( *hqswb_clas, SWB_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); - } - - env_stab = 0; - move16(); - - csw_flag1 = s_and( core_switching_flag, (Word16) ( st_fx->element_mode != EVS_MONO ) ); /* Q0 */ - csw_flag2 = s_and( csw_flag1, (Word16) EQ_16( length, L_SPEC32k_EXT ) ); /* Q0 */ - test(); - IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) - { - hHQ_core->mem_env_delta = 0; - move16(); - } - ELSE IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) - { - env_stab = env_stability_fx( ynrm, SFM_N_ENV_STAB, hHQ_core->mem_norm, &hHQ_core->mem_env_delta, csw_flag1 ); /* Q0 */ - } - ELSE - { - hHQ_core->mem_norm[0] = 31; - move16(); - hHQ_core->mem_env_delta = 0; - move16(); - } - - IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) - { - hHQ_core->env_stab_fx = 32767; - move16(); /* 1 in Q15, stable by definition */ - } - ELSE - { - test(); - IF( EQ_16( length, L_FRAME32k ) || csw_flag2 ) - { - move16(); /* calculated stability */ - hHQ_core->env_stab_fx = env_stab; /* Q15 */ - } - ELSE - { - hHQ_core->env_stab_fx = env_stability_fx( ynrm, SFM_N_ENV_STAB_WB, hHQ_core->mem_norm_hqfec, &hHQ_core->mem_env_delta_hqfec, csw_flag1 ); /* Q15 */ - move16(); - } - } - hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ - - /*------------------------------------------------------------------* - * Bit allocation - *------------------------------------------------------------------*/ - - hq_bit_allocation_fx( st_fx->core_brate, length, *hqswb_clas, &bits_left, normqlg2, nb_sfm, sfmsize, noise_level, - R, Rsubband, &sum, &core_sfm, num_env_bands ); - - test(); - test(); - IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) && st_fx->bws_cnt1 > 0 && LT_32( st_fx->core_brate, HQ_32k ) ) - { - tmp = i_mult( st_fx->bws_cnt1, 1638 /* 1/20 in Q15 */ ); /* Q15 */ - move16(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) ) - { - FOR( n_band = 0; n_band < 4; n_band++ ) - { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ - move16(); - } - } - - FOR( n_band = 4; n_band < SWB_FENV; n_band++ ) - { - SWB_fenv[n_band] = mult_r( SWB_fenv[n_band], tmp ); /* Q1 */ - move16(); - } - } - - test(); - IF( EQ_16( *hqswb_clas, HQ_GEN_SWB ) || EQ_16( *hqswb_clas, HQ_GEN_FB ) ) - { - b_delta_env = get_nor_delta_hf_fx( st_fx, ynrm, Rsubband, num_env_bands, nb_sfm, core_sfm ); /* Q0 */ - sum = sub( sum, b_delta_env ); /* Q0 */ - } - - /*------------------------------------------------------------------* - * Decode spectral fine structure using HVQ/PVQ - *------------------------------------------------------------------*/ - - IF( EQ_16( *hqswb_clas, HQ_HVQ ) ) - { - hvq_dec_fx( st_fx, bits_left, st_fx->core_brate, ynrm, R, noise_level, peak_idx, &Npeaks, t_audio_q, st_fx->core ); - } - ELSE - { - pvq_core_dec_fx( st_fx, sfm_start, sfm_end, sfmsize, t_audio_q_norm, &Q_audio, sum, nb_sfm, Rsubband, R, pulses, maxpulse, HQ_CORE ); - } - - test(); - IF( EQ_16( *hqswb_clas, HQ_HVQ ) || EQ_16( *hqswb_clas, HQ_HARMONIC ) ) - { - subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ - move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ - move16(); - - IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) ) - { - Q_shift = sub( SWB_BWE_LR_Qs, Q_audio ); - FOR( i = 0; i < 300; i++ ) - { - t_audio_q[i] = L_shl( L_deposit_l( t_audio_q_norm[i] ), Q_shift ); /* Q12 */ - move32(); - } - } - - har_est_fx( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2 ); - - hHQ_core->prev_frm_hfe2 = har_freq_est2; - move16(); - } - - { - hHQ_core->prev_frm_hfe2 = 0; /*reset*/ - move16(); - hHQ_core->prev_stab_hfe2 = 0; /*reset*/ - move16(); - } - - /*------------------------------------------------------------------* - * Spectral filling - *------------------------------------------------------------------*/ - fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, &hHQ_core->no_att_hangover, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed, hq_generic_exc_clas, core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient[0], @@ -710,4 +346,3 @@ void hq_hr_dec_fx( return; } -#endif diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 87de0a937..2a11d25a7 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -613,11 +613,7 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ -#ifdef HARM_HQ_CORE hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_32_fx[n] ); -#else - ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_32_fx[n] ); -#endif Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor } diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index 81cd93e97..9c8460bcb 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -321,7 +321,6 @@ static void peak_vq_dec_fx( pvq_decode_frame_fx( st_fx, pvq_vector, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, Rk, pvq_bits, core ); -#ifdef HARM_HQ_CORE #ifdef HARM_HQ_CORE_KEEP_BE fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, pvq_maxpulse, NULL, pvq_bands, pvq_vector, pvq_inp_vector, fg_pred, EVS_MONO, core ); @@ -329,10 +328,6 @@ static void peak_vq_dec_fx( fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, pvq_maxpulse, NULL, pvq_bands, pvq_vector, pvq_inp_vector, fg_pred, st_fx->element_mode, core ); #endif -#else - fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, pvq_maxpulse, NULL, - pvq_bands, pvq_vector, pvq_inp_vector, fg_pred, core ); -#endif fine_gain_dec_fx( st_fx, k_sort, pvq_bands, gain_bits_array, fg_pred ); diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index ebc7b8905..80bc47135 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -215,11 +215,7 @@ void pvq_decode_frame_fx( * *-------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE Word16 pvq_core_dec_fx( -#else -Word16 ivas_pvq_core_dec_fx( -#endif Decoder_State *st_fx, const Word16 *sfm_start, const Word16 *sfm_end, @@ -249,11 +245,7 @@ Word16 ivas_pvq_core_dec_fx( } R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 -#ifdef HARM_HQ_CORE assign_gain_bits_fx( st_fx->element_mode, core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); -#else - ivas_assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); -#endif pvq_bits = shr( R_upd, 3 ); // Q3 -> Q0 @@ -285,13 +277,8 @@ Word16 ivas_pvq_core_dec_fx( get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); -#ifdef HARM_HQ_CORE fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, coefs_quant, pulse_vector, fg_pred, st_fx->element_mode, core ); -#else - ivas_fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, - nb_sfm, coefs_quant, pulse_vector, fg_pred, core ); -#endif fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred ); IF( st_fx->hHQ_core != NULL ) @@ -309,88 +296,6 @@ Word16 ivas_pvq_core_dec_fx( return bits_tot; } -#ifndef HARM_HQ_CORE -Word16 pvq_core_dec_fx( - Decoder_State *st_fx, - const Word16 *sfm_start, - const Word16 *sfm_end, - const Word16 *sfmsize, - Word16 coefs_quant[], /* o : output MDCT */ - Word16 *Q_coefs, - Word16 bits_tot, - Word16 nb_sfm, - Word16 *R, /* Q3 */ - Word16 *Rs, - Word16 *npulses, - Word16 *maxpulse, - const Word16 core ) -{ - Word16 i; - Word16 R_upd; - Word16 ord[NB_SFM_MAX]; - Word16 pulse_vector[L_FRAME48k]; - Word16 pvq_bits; - Word16 gain_bits_array[NB_SFM]; - Word16 fg_pred[NB_SFM_MAX]; - - if ( st_fx->hHQ_core != NULL ) - { - st_fx->hHQ_core->ber_occured_in_pvq = 0; - move16(); - } - - R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 - assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - - pvq_bits = shr( R_upd, 3 ); // Q3 -> Q0 - - pvq_decode_frame_fx( st_fx, coefs_quant, npulses, pulse_vector, sfm_start, - sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); - - IF( Rs != NULL ) - { - FOR( i = 0; i < nb_sfm; i++ ) - { - if ( npulses[i] <= 0 ) - { - Rs[i] = 0; - move16(); /* Update Rs in case no pulses were assigned */ - } - } - } - - FOR( i = 0; i < nb_sfm; i++ ) - { - ord[i] = i; - move16(); - if ( npulses[i] <= 0 ) - { - R[i] = 0; - move16(); /* Update in case no pulses were assigned */ - } - } - - get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); - - fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, - nb_sfm, coefs_quant, pulse_vector, fg_pred, core ); - - fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred ); - IF( st_fx->hHQ_core != NULL ) - { - IF( st_fx->hHQ_core->ber_occured_in_pvq != 0 ) - { - set16_fx( fg_pred, 1, nb_sfm ); /* low complex ECU action in case of detetected BER in PVQ decoding */ - } - } - - apply_gain_fx( ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant ); - *Q_coefs = 12; - move16(); - - return bits_tot; -} -#endif /*-------------------------------------------------------------------* diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 3c2878853..493e5e8f3 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -600,21 +600,12 @@ void gsc_enc_fx( { Q_concat = Q12; move16(); -#ifdef HARM_HQ_CORE bit = sub( bit, pvq_core_enc_fx( st_fx->element_mode, hBstr, concat_in, concat_out, &Q_concat, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ) ); -#else - bit = sub( bit, pvq_core_enc_ivas_fx( hBstr, concat_in, concat_out, &Q_concat, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ) ); -#endif } ELSE { -#ifdef HARM_HQ_CORE tmp = pvq_core_enc_fx( st_fx->element_mode, hBstr, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); -#else - tmp = pvq_core_enc_fx( hBstr, concat_in, concat_out, &Q_tmp, bit, nb_subbands, gsc_sfm_start, gsc_sfm_end, - gsc_sfm_size, bits_per_bands, NULL, inpulses_fx, imaxpulse_fx, ACELP_CORE ); -#endif Scale_sig( concat_out, gsc_sfm_end[nb_subbands - 1], sub( Q_concat, Q_tmp ) ); /* Q_PVQ_OUT */ bit = sub( bit, tmp ); diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index d674cc30e..a17b07876 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -184,113 +184,9 @@ static Word16 hf_spectrum_sparseness_fx( * * HQ mode selector (decision_matrix) *--------------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE -Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 length, /* i : Frame length Q0 */ - const Word32 *coefs, /* i : Spectral coefficients Q12 */ - const Word16 is_transient, /* i : Transient flag Q0 */ - Word16 *Npeaks, /* o : Number of identified peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - Word32 *pe_gains, /* o : Peak gains Q12 */ - Word32 *nf_gains, /* o : Noise-fill gains Q12 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ -) -{ - Word16 bits; - HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; - - *hqswb_clas = HQ_NORMAL; - IF( EQ_16( is_transient, 1 ) ) - { - *hqswb_clas = HQ_TRANSIENT; - move16(); - } - - /* classification and limit bandwidth for bit allocation */ - test(); - test(); - test(); - IF( EQ_16( length, L_FRAME32k ) && NE_16( is_transient, 1 ) && LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( st_fx->bwidth, st_fx->last_bwidth ) ) - { - /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); /* Q0 */ - move16(); - - /* Detect harmonic VQ mode HQ_HVQ */ - hvq_classifier_fx( coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, st_fx->core_brate, st_fx->last_core, - nf_gains, &hHQ_core->hvq_hangover, pe_gains ); - } - - test(); - test(); - test(); - IF( EQ_16( length, L_FRAME48k ) && NE_16( is_transient, 1 ) && LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( st_fx->bwidth, st_fx->last_bwidth ) ) - { - /* Detect HQ_HARMONIC mode */ - *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); /* Q0 */ - move16(); - - /* Detect harmonic VQ mode HQ_HVQ */ - hvq_classifier_fx( coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, - st_fx->core_brate, st_fx->last_core, nf_gains, &hHQ_core->hvq_hangover, pe_gains ); - } - - test(); - test(); - IF( EQ_16( length, L_FRAME48k ) && LE_32( st_fx->core_brate, HQ_32k ) && EQ_16( *hqswb_clas, HQ_NORMAL ) ) - { - *hqswb_clas = HQ_GEN_FB; /* Q0 */ - move16(); - } - test(); - IF( GE_16( length, L_FRAME32k ) && LE_32( st_fx->core_brate, HQ_32k ) ) - { - bits = 2; - move16(); - } - ELSE - { - bits = 1; - move16(); - } - - test(); - IF( EQ_16( length, L_FRAME48k ) && LE_32( st_fx->core_brate, HQ_32k ) ) - { - IF( GE_16( *hqswb_clas, HQ_GEN_SWB ) ) - { - push_indice( st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas - 5, bits ); - } - ELSE - { - push_indice( st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); - } - } - ELSE - { - push_indice( st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); - } - - test(); - test(); - IF( EQ_16( *hqswb_clas, HQ_NORMAL ) && EQ_16( length, L_FRAME32k ) && LE_32( st_fx->core_brate, HQ_32k ) ) - { - *hqswb_clas = HQ_GEN_SWB; /* Q0 */ - move16(); - } - - return bits; -} -#endif - -#ifdef HARM_HQ_CORE /* o : Consumed bits Q0 */ Word16 hq_classifier_enc_fx( -#else -Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bits Q0 */ -#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 length, /* i : Frame length Q0 */ const Word32 *coefs, /* i : Spectral coefficients Q12 */ @@ -335,11 +231,7 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bits Q0 */ IF( !is_transient && EQ_16( st_fx->bwidth, st_fx->last_bwidth ) ) { /* Detect HQ_HARMONIC mode */ -#ifdef HARM_HQ_CORE *hqswb_clas = peak_avrg_ratio_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); /* Q0 */ -#else - *hqswb_clas = peak_avrg_ratio_ivas_fx( st_fx->total_brate, coefs, NUMC_N + 96, &hHQ_core->mode_count, &hHQ_core->mode_count1, 12 ); /* Q0 */ -#endif harmonic_decision = hf_spectrum_sparseness_fx( st_fx, coefs ); @@ -352,11 +244,7 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bits Q0 */ ELSE { /* Detect harmonic VQ mode HQ_HVQ */ -#ifdef HARM_HQ_CORE hvq_classifier_fx( coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, st_fx->core_brate, st_fx->last_core, nf_gains, &hHQ_core->hvq_hangover, pe_gains ); -#else - hvq_classifier_ivas_fx( coefs, &hHQ_core->prev_Npeaks, hHQ_core->prev_peaks, hqswb_clas, Npeaks, peaks, st_fx->core_brate, st_fx->last_core, nf_gains, &hHQ_core->hvq_hangover, pe_gains ); -#endif } } bits = 2; @@ -396,11 +284,7 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bits Q0 */ * Classify the input signal and decide if it has a harmonic structure *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE Word16 peak_avrg_ratio_fx( -#else -Word16 peak_avrg_ratio_ivas_fx( -#endif const Word32 total_brate, /* i : total bitrate Q0*/ const Word32 *input_hi_fx, /* i : input signal Q_coeff */ const Word16 length, /* i : number of coefficients Q0*/ @@ -512,124 +396,6 @@ Word16 peak_avrg_ratio_ivas_fx( return hqswb_clas; /* Q0 */ } -#ifndef HARM_HQ_CORE -/*--------------------------------------------------------------------------* - * peak_avrg_ratio() - * - * Classify the input signal and decide if it has a harmonic structure - *--------------------------------------------------------------------------*/ -Word16 peak_avrg_ratio_fx( - const Word32 total_brate, /* i : total bitrate Q0*/ - const Word32 *input_hi_fx, /* i : input signal Q_coeff*/ - const Word16 length, /* i : number of coefficients Q0*/ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count Q0*/ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count Q0*/ - Word16 Q_coeff ) -{ - Word16 i, j, q, k, k1, hqswb_clas; - Word32 mean_fx, peak_fx; - Word32 input_abs_fx[L_FRAME32k]; - Word32 peak_th_fx; - - FOR( i = 96; i < length; i++ ) - { - input_abs_fx[i] = L_abs( input_hi_fx[i] ); /* Q_coeff */ - } - - hqswb_clas = HQ_NORMAL; - move16(); - peak_th_fx = L_shl( 10L, sub( Q_coeff, 5 ) ); /* 5 is safe shift */ - - k = 0; - move16(); - k1 = 0; - move16(); - q = 96; /* q used for indexing */ - move16(); - - FOR( i = 3; i < 17; i++ ) - { - peak_fx = L_deposit_l( 0 ); - mean_fx = L_deposit_l( 1 ); - - /*for(j = 0; j < 32; j ++, q ++) */ - FOR( j = 0; j < 32; j++ ) - { - input_abs_fx[q] = L_shr( input_abs_fx[q], 5 ); /*Q_coeff-5 */ - move32(); - mean_fx = L_add( mean_fx, input_abs_fx[q] ); /*Q_coeff-5 */ - if ( GT_32( input_abs_fx[q], peak_fx ) ) - { - peak_fx = input_abs_fx[q]; /*Q_coeff-5 */ - move32(); - } - q += 1; - } - - IF( LT_16( i, 8 ) ) - { - if ( GT_32( peak_fx, Mult_32_16( mean_fx, 4608 ) ) ) /* Q15 0.140625 */ - { - k = add( k, 1 ); - } - } - ELSE - { - test(); - if ( GT_32( peak_fx, Mult_32_16( mean_fx, 3686 ) ) /*Q15 0.1125 */ - && GT_32( peak_fx, peak_th_fx ) ) /*Q27 10 */ - { - k1 = add( k1, 1 ); - } - } - } - - test(); - IF( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) - { - IF( LT_16( *mode_count, 8 ) ) - { - *mode_count = add( *mode_count, 1 ); - move16(); - } - - IF( *mode_count1 > 0 ) - { - *mode_count1 = sub( *mode_count1, 1 ); - move16(); - } - } - ELSE - { - IF( LT_16( *mode_count1, 8 ) ) - { - *mode_count1 = add( *mode_count1, 1 ); - move16(); - } - - IF( *mode_count > 0 ) - { - *mode_count = sub( *mode_count, 1 ); - move16(); - } - } - - test(); - test(); - test(); - test(); - test(); - test(); - - IF( ( GE_16( add( k, k1 ), 5 ) && GT_16( k1, 2 ) && EQ_32( total_brate, HQ_24k40 ) ) || ( ( ( GE_16( add( k, k1 ), 10 ) && GT_16( k1, 5 ) ) || GE_16( *mode_count, 5 ) ) && LT_16( *mode_count1, 5 ) ) ) - { - hqswb_clas = HQ_HARMONIC; - move16(); - } - - return hqswb_clas; /* Q0 */ -} -#endif /*--------------------------------------------------------------------------* * hvq_classifier() @@ -637,11 +403,7 @@ Word16 peak_avrg_ratio_fx( * Classification of harmonic low band content for Harmonic VQ *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE static void hvq_classifier_fx( -#else -void hvq_classifier_ivas_fx( -#endif const Word32 *input, /* i : input signal Q12 */ Word16 *prev_Npeaks, /* i/o: Peak number memory Q0 */ Word16 *prev_peaks, /* i/o: Peak indices memory Q0 */ @@ -1070,443 +832,3 @@ void hvq_classifier_ivas_fx( return; } -#ifndef HARM_HQ_CORE -void hvq_classifier_fx( - const Word32 *input, /* i : input signal Q12 */ - Word16 *prev_Npeaks, /* i/o: Peak number memory Q0 */ - Word16 *prev_peaks, /* i/o: Peak indices memory Q0 */ - Word16 *hqswb_clas, /* i/o: HQ class Q0 */ - Word16 *Npeaks, /* o : Number of peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - const Word32 L_core_brate, /* i : Core bit-rate Q0 */ - const Word16 last_core, /* i : Last core used Q0 */ - Word32 *L_nf_gains, /* o : Noisefloor gains Q12 */ - Word16 *hvq_hangover, /* i/o: Mode-switch hangover Q0 */ - Word32 *L_pe_gains /* o : peak gains Q12 */ -) -{ - const Word16 *p_adj; - UWord16 lsb; - - Word32 L_input_abs[L_FRAME32k]; - Word32 L_input_max; - Word32 L_thr[L_FRAME16k]; - Word32 L_thr_tmp; - Word32 L_m; - Word32 L_tmp; - Word32 L_d; - Word32 L_peak; - Word32 L_nf, L_pe; - Word32 L_pe_mean[HVQ_NSUB_32k], L_nf_mean[HVQ_NSUB_32k]; - - Word16 inv_nsub; - Word16 sharp_dist; - Word16 exp1, exp2; - Word16 tmp; - Word16 shift; - Word16 idx; - Word16 frac; - Word16 inv_nf_mean; - Word16 inv_gains_nsub; - Word16 nf_mean_norm; - Word16 num_sharp_bands, i, j, k, q, peak_th, nsub, pindx, N, offset; - Word16 num_peak_cands, high, low; - Word16 sharp[HVQ_NSUB_32k]; - Word16 peak_cand_idx[HVQ_THRES_BIN_32k], avail_peaks[HVQ_NSUB_32k]; - - L_input_max = L_deposit_l( 0 ); - set32_fx( L_thr, 0, L_FRAME16k ); - - IF( EQ_32( L_core_brate, HQ_24k40 ) ) - { - nsub = HVQ_NSUB_24k; - move16(); - inv_nsub = 4681; /* 1/7 in Q15 */ - move16(); - inv_gains_nsub = 10923; /* 1/3 in Q15 */ - move16(); - } - ELSE - { - nsub = HVQ_NSUB_32k; - move16(); - inv_nsub = 3277; /* 1/10 in Q15 */ - move16(); - inv_gains_nsub = 6554; /* 1/5 in Q15 */ - move16(); - } - - N = shl( nsub, 5 ); /* Mult by 32 (HVQ_BW) */ - - test(); - test(); - IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) && last_core != ACELP_CORE && NE_16( last_core, AMR_WB_CORE ) ) - { - FOR( i = 0; i < N; i++ ) - { - L_input_abs[i] = L_abs( input[i] ); /* Q12 */ - IF( GT_32( L_input_abs[i], L_input_max ) ) - { - L_input_max = L_input_abs[i]; /* Q12 */ - move16(); - } - } - - exp1 = norm_l( L_input_max ); - - *Npeaks = 0; - move16(); - L_nf = 3276800; /* 800 in Q12 */ - move32(); - L_pe = 3276800; /* 800 in Q12 */ - move32(); - num_sharp_bands = 0; - move16(); - k = 0; - move16(); - q = 0; - move16(); - sharp_dist = 0; - move16(); - - /* Find peak threshold */ - FOR( i = 0; i < nsub; i++ ) - { - L_peak = 0; - L_nf_mean[i] = 0; - L_pe_mean[i] = 0; - move32(); - move32(); - move32(); - FOR( j = 0; j < HVQ_BW; j++ ) - { - L_d = L_input_abs[q]; /* Q12 */ - move32(); - IF( GT_32( L_d, L_nf ) ) - { - /*nf = HVQ_NF_WEIGHT1 * nf + (1 - HVQ_NF_WEIGHT1) * d; */ - Mpy_32_16_ss( L_d, HVQ_NF_WEIGHT1B, &L_tmp, &lsb ); /* 12+15-15=12 */ - Mpy_32_16_ss( L_nf, HVQ_NF_WEIGHT1_FX, &L_nf, &lsb ); /* 12+15-15=12 */ - L_nf = L_add( L_nf, L_tmp ); /*Q12 */ - } - ELSE - { - /*nf = HVQ_NF_WEIGHT2 * nf + (1 - HVQ_NF_WEIGHT2) * d; */ - Mpy_32_16_ss( L_d, HVQ_NF_WEIGHT2B, &L_tmp, &lsb ); /* 12+15-15=12 */ - Mpy_32_16_ss( L_nf, HVQ_NF_WEIGHT2_FX, &L_nf, &lsb ); /* 12+15-15=12 */ - L_nf = L_add( L_nf, L_tmp ); /*Q12 */ - } - - IF( GT_32( L_d, L_pe ) ) - { - /*pe = HVQ_PE_WEIGHT1 * pe + (1 - HVQ_PE_WEIGHT1) * d; */ - Mpy_32_16_ss( L_d, HVQ_PE_WEIGHT1B, &L_tmp, &lsb ); /* 12+15-15=12 */ - Mpy_32_16_ss( L_pe, HVQ_PE_WEIGHT1_FX, &L_pe, &lsb ); /* 12+15-15=12 */ - L_pe = L_add( L_pe, L_tmp ); /*Q12 */ - } - ELSE - { - /*pe = HVQ_PE_WEIGHT2 * pe + (1 - HVQ_PE_WEIGHT2) * d; */ - Mpy_32_16_ss( L_d, HVQ_PE_WEIGHT2B, &L_tmp, &lsb ); /* 12+15-15=12 */ - Mpy_32_16_ss( L_pe, HVQ_PE_WEIGHT2_FX, &L_pe, &lsb ); /* 12+15-15=12 */ - L_pe = L_add( L_pe, L_tmp ); /*Q12 */ - } - - L_nf_mean[i] = L_add_sat( L_nf_mean[i], L_nf ); /*Q12 */ - L_pe_mean[i] = L_add_sat( L_pe_mean[i], L_pe ); /*Q12 */ - move32(); - move32(); - IF( GT_32( L_d, L_peak ) ) - { - L_peak = L_add( L_d, 0 ); - } - - q += 1; - } - L_nf_mean[i] = L_shr( L_nf_mean[i], 5 ); /* Divide by 5 (HVQ_BW) */ - L_pe_mean[i] = L_shr( L_pe_mean[i], 5 ); /* Divide by 5 (HVQ_BW) */ - move32(); - move32(); - - /*thr_tmp = (float)pow( pe_mean[i]/nf_mean[i], HVQ_THR_POW ) * nf_mean[i]; */ - exp1 = norm_l( L_nf_mean[i] ); - nf_mean_norm = extract_h( L_shl( L_nf_mean[i], exp1 ) ); /* 12+s-16=s-4 */ - IF( nf_mean_norm == 0 ) - { - inv_nf_mean = 0; - } - ELSE - { - inv_nf_mean = div_s( 1 << 14, nf_mean_norm ); /* 15+14-s+4=33-s */ - } - Mpy_32_16_ss( L_pe_mean[i], inv_nf_mean, &L_tmp, &lsb ); /*12+33-s-15=30-s */ - - exp2 = norm_l( L_tmp ); - tmp = Log2_norm_lc( L_shl( L_tmp, exp2 ) ); /* Q15 */ - exp2 = exp1 - exp2; /* Q0 */ - L_tmp = Mpy_32_16( exp2, tmp, 32767 ); /* 1 in Q15. Q16 */ - Mpy_32_16_ss( L_tmp, 28836, &L_tmp, &lsb ); /* 16+15-15=16 */ - frac = L_Extract_lc( L_tmp, &tmp ); /* Q15 and Q0 */ - L_tmp = Pow2( 14, frac ); /* Q14 */ - L_tmp = L_shl( L_tmp, tmp ); /* Q14 */ - - Mpy_32_16_ss( L_tmp, nf_mean_norm, &L_tmp, &lsb ); /*14+s-4-15=s-5 */ - shift = sub( 17, exp1 ); /* 16-(s-5)=17-s */ - L_thr_tmp = L_shl( L_tmp, shift ); /* Q16 */ - L_thr_tmp = L_add( L_thr_tmp, lshr( lsb, sub( 16, shift ) ) ); /*Q16 */ - - set32_fx( &L_thr[k], L_thr_tmp, HVQ_BW ); - k = add( k, HVQ_BW ); - - /*sharp[i] = peak/nf_mean[i]; */ - Mpy_32_16_ss( L_peak, inv_nf_mean, &L_tmp, &lsb ); /* 12+33-s-15=30-s */ - shift = sub( exp1, 8 ); - sharp[i] = extract_h( L_shl( L_tmp, shift ) ); /* 30-s+s-8-16 -> Q6 */ - move16(); - - /*sharp_dist += (sharp[i]-HVQ_SHARP_THRES); */ - sharp_dist = add_sat( sharp_dist, sub( sharp[i], HVQ_SHARP_THRES_FX ) ); - IF( GT_16( sharp[i], HVQ_SHARP_THRES_FX ) ) - { - num_sharp_bands = add( num_sharp_bands, 1 ); - } - } - - /* Estimate noise floor gains */ - offset = s_and( nsub, 1 ); - FOR( i = 0; i < ( nsub & (Word16) 0xFFFE ); i++ ) - { - /*(2*i+1)/nsub */ - idx = mult( add( shl( i, 1 ), 1 ), add( inv_nsub, 1 ) ); /*0+15-15 = 0 */ - L_nf_gains[idx] = L_add( L_nf_gains[idx], L_nf_mean[i + offset] ); - L_pe_gains[idx] = L_add( L_pe_gains[idx], L_pe_mean[i + offset] ); - move32(); - move32(); - } - - FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) - { - Mpy_32_16_ss( L_nf_gains[i], inv_gains_nsub, &L_nf_gains[i], &lsb ); /*12+15-15=12 */ - Mpy_32_16_ss( L_pe_gains[i], inv_gains_nsub, &L_pe_gains[i], &lsb ); /*12+15-15=12 */ - } - - /* Allocate available peaks */ - FOR( i = 0; i < nsub; i++ ) - { - avail_peaks[i] = HVQ_PA_PEAKS_SHARP1; - move16(); - idx = mult( add( shl( i, 1 ), 1 ), add( inv_nsub, 1 ) ); /*0+15-15 = 0 */ - Mpy_32_16_ss( L_nf_gains[idx], HVQ_PA_FAC_FX, &L_tmp, &lsb ); /* 12+15-15 -> Q12 */ - IF( LT_32( L_nf_mean[i], L_tmp ) ) - { - IF( LT_16( sharp[i], HVQ_PA_SHARP_THRES3_FX ) ) - { - avail_peaks[i] = HVQ_PA_PEAKS_SHARP3; - move16(); - } - ELSE IF( LT_16( sharp[i], HVQ_PA_SHARP_THRES2_FX ) ) - { - avail_peaks[i] = HVQ_PA_PEAKS_SHARP2; - move16(); - } - } - } - - - /* Adjust threshold around previous peaks */ - FOR( i = 0; i < *prev_Npeaks; i++ ) - { - j = sub( prev_peaks[i], 2 ); /* Q0 */ - k = add( prev_peaks[i], 2 ); /* Q0 */ - p_adj = hvq_thr_adj_fx; /* Q15 */ - move16(); - - FOR( q = j; q < k; q++ ) - { - Mpy_32_16_ss( L_thr[q], *p_adj++, &L_thr[q], &lsb ); /* 12+15-15=12 */ - move32(); - } - } - - num_peak_cands = 0; - move16(); - - /* Remove everything below threshold for peak search */ - L_input_abs[0] = L_deposit_l( 0 ); - L_input_abs[1] = L_deposit_l( 0 ); - L_input_abs[N - 2] = L_deposit_l( 0 ); - L_input_abs[N - 1] = L_deposit_l( 0 ); - move32(); - move32(); - move32(); - move32(); - FOR( i = 0; i < N - 2; i++ ) - { - IF( LT_32( L_input_abs[i], L_thr[i] ) ) - { - L_input_abs[i] = L_deposit_l( 0 ); - move32(); - } - ELSE - { - L_input_abs[num_peak_cands] = L_input_abs[i]; /* Q12 */ - move32(); - peak_cand_idx[num_peak_cands] = i; /* Q0 */ - move16(); - num_peak_cands = add( num_peak_cands, 1 ); - } - } - IF( EQ_32( L_core_brate, HQ_24k40 ) ) - { - peak_th = HVQ_MAX_PEAKS_24k_CLAS; - move16(); - } - ELSE - { - peak_th = HVQ_MAX_PEAKS_32k; - move16(); - } - /* Find peaks */ - pindx = maximum_32_fx( L_input_abs, num_peak_cands, &L_m ); - i = 0; - move16(); - - WHILE( L_m > 0 && LT_16( i, peak_th + 1 ) ) - { - idx = mult( peak_cand_idx[pindx], INV_HVQ_BW ); /* 0+15-15=0 */ - IF( avail_peaks[idx] > 0 ) - { - peaks[i++] = peak_cand_idx[pindx]; /* Q0 */ - move16(); - avail_peaks[idx]--; - } - - j = sub( pindx, 2 ); - k = add( pindx, 2 ); - - if ( j < 0 ) - { - j = 0; - move16(); - } - - tmp = sub( num_peak_cands, 1 ); - if ( GT_16( k, tmp ) ) - { - k = tmp; - move16(); - } - - low = sub( peak_cand_idx[pindx], 2 ); - high = add( peak_cand_idx[pindx], 2 ); - - if ( low < 0 ) - { - low = 0; - move16(); - } - - tmp = sub( N, 1 ); - IF( GT_16( high, tmp ) ) - { - high = tmp; - move16(); - } - - FOR( q = j; q <= pindx; q++ ) - { - IF( GE_16( peak_cand_idx[q], low ) ) - { - peak_cand_idx[q] = 0; - move16(); - L_input_abs[q] = 0; - move16(); - } - } - - FOR( q = pindx + 1; q <= k; q++ ) - { - IF( LE_16( peak_cand_idx[q], high ) ) - { - peak_cand_idx[q] = 0; - move16(); - L_input_abs[q] = 0; - move16(); - } - } - - pindx = maximum_32_fx( L_input_abs, num_peak_cands, &L_m ); /* Q0 */ - } - - *Npeaks = i; - move16(); - IF( GT_16( *Npeaks, HVQ_MIN_PEAKS ) ) - { - test(); - IF( GT_16( num_sharp_bands, sub( nsub, 3 ) ) && LE_16( *Npeaks, peak_th ) ) - { - sharp_dist = mult( sharp_dist, inv_nsub ); /*x+15-15=x */ - test(); - IF( LE_16( sharp_dist, SHARP_DIST_THRES_FX ) && *hvq_hangover < 0 ) - { - *hvq_hangover = add( *hvq_hangover, 1 ); - } - ELSE - { - *hqswb_clas = HQ_HVQ; /* Q0 */ - move16(); - *hvq_hangover = 2; /* Q0 */ - move16(); - } - - /* update memory */ - *prev_Npeaks = *Npeaks; /* Q0 */ - move16(); - Copy( peaks, prev_peaks, *Npeaks ); /* Q0 */ - } - ELSE - { - IF( *hvq_hangover > 0 ) - { - *hqswb_clas = HQ_HVQ; /* Q0 */ - move16(); - *hvq_hangover = sub( *hvq_hangover, 1 ); /* Q0 */ - move16(); - } - ELSE - { - *hvq_hangover = -1; - move16(); - } - } - } - ELSE - { - /* Zero peaks, likely silence input. */ - *hvq_hangover = -1; - move16(); - } - - IF( EQ_32( L_core_brate, HQ_24k40 ) ) - { - *Npeaks = s_min( HVQ_MAX_PEAKS_24k, *Npeaks ); /* Q0 */ - move16(); - } - ELSE - { - *Npeaks = s_min( HVQ_MAX_PEAKS_32k, *Npeaks ); /* Q0 */ - move16(); - } - } - ELSE - { - *prev_Npeaks = 0; - move16(); - *hvq_hangover = 0; - move16(); - } - - - return; -} -#endif diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 98552f5e3..074035d8d 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -9,215 +9,6 @@ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -#ifndef HARM_HQ_CORE -/*-------------------------------------------------------------------------- - * hq_core_enc() - * - * HQ core encoder - *--------------------------------------------------------------------------*/ - -void hq_core_enc_fx( - Encoder_State *st_fx, - const Word16 *audio, /* i : input audio signal Q0*/ - const Word16 input_frame_orig, /* i : frame length Q0*/ - const Word16 hq_core_type, /* i : HQ core type Q0*/ - const Word16 Voicing_flag, /* i : Voicing flag for FER method selection Q0*/ - const Word16 vad_hover_flag /* i : VAD hangover flag Q0*/ -) -{ - Word16 i, is_transient, num_bits, extra_unused; - Word32 wtda_audio[2 * L_FRAME48k]; - Word32 t_audio[L_FRAME48k_EXT]; /* Q12 */ - Word16 Q_audio = 0; - Word16 inner_frame, input_frame; - Word16 ener_match; /* Q13/Q15 */ - move16(); - - Word16 tmp; - Word32 L_tmp; - UWord16 lsb; - Word16 two_frames_buffer[2 * L_FRAME48k]; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - - set32_fx( t_audio, 0, L_FRAME48k ); - st_fx->Nb_ACELP_frames = 0; - move16(); - - /* set input_frame length */ - input_frame = input_frame_orig; /* Q0 */ - move16(); - /* Sanity check, it should never happen at the encoder side (no BFI) */ - IF( EQ_16( st_fx->hTcxCfg->tcx_curr_overlap_mode, FULL_OVERLAP ) ) - { - st_fx->hTcxCfg->tcx_last_overlap_mode = ALDO_WINDOW; - ; - move16(); - } - ELSE - { - st_fx->hTcxCfg->tcx_last_overlap_mode = st_fx->hTcxCfg->tcx_curr_overlap_mode; - move16(); - } - st_fx->hTcxCfg->tcx_curr_overlap_mode = ALDO_WINDOW; - move16(); - - /*-------------------------------------------------------------------------- - * Preprocessing in the first HQ frame after ACELP frame - * Find the number of bits for PVQ coding - * Write signalling information - *--------------------------------------------------------------------------*/ - - /*num_bits = (short)(st->total_brate / 50); */ - Mpy_32_16_ss( st_fx->total_brate, 5243, &L_tmp, &lsb ); /* 5243 is 1/50 in Q18. (0+18-15=3) */ - num_bits = extract_l( L_shr( L_tmp, 3 ) ); /*Q0 */ - extra_unused = 0; - move16(); - - /*-------------------------------------------------------------------------- - * Detect signal transition - *--------------------------------------------------------------------------*/ - - is_transient = detect_transient_fx( audio, input_frame, 0, st_fx ); /* Q0 */ - - { - /*-------------------------------------------------------------------------- - * Windowing and time-domain aliasing - * DCT transform - *--------------------------------------------------------------------------*/ - - Copy( st_fx->old_input_signal_fx, two_frames_buffer, input_frame ); /* st_fx->q_old_inp */ - Copy( audio, two_frames_buffer + input_frame, input_frame ); /* Q0 */ - - wtda_fx( two_frames_buffer + input_frame, &Q_audio, wtda_audio, NULL, 0, - st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, input_frame ); - - test(); - IF( st_fx->last_core == ACELP_CORE || EQ_16( st_fx->last_core, AMR_WB_CORE ) ) - { - /* Preprocessing in the first HQ frame after ACELP frame */ - core_switching_hq_prepare_enc_fx( st_fx, &num_bits, input_frame, wtda_audio, two_frames_buffer + input_frame ); - - /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ - IF( GT_16( num_bits, ACELP_48k_BITS ) ) - { - extra_unused = sub( num_bits, ACELP_48k_BITS ); - num_bits = ACELP_48k_BITS; - move16(); - } - } - /* subtract signalling bits */ - num_bits = sub( num_bits, hBstr->nb_bits_tot ); /* Q0 */ - direct_transform_fx( wtda_audio, t_audio, is_transient, input_frame, &Q_audio, st_fx->element_mode ); - - /* scale coefficients to their nominal level (8kHz) */ - IF( NE_16( input_frame, NORM_MDCT_FACTOR ) ) - { - IF( EQ_16( input_frame, L_FRAME32k ) ) - { - Q_audio = add( Q_audio, 1 ); /* Divide by 2 */ - } - ELSE - { - tmp = mult_r( input_frame, 410 / 2 ); /* 1/8000 in Q15 */ - ener_match = hq_nominal_scaling[tmp]; - move16(); - FOR( i = 0; i < input_frame; i++ ) - { - /*t_audio_q[i] *= ener_match; */ - Mpy_32_16_ss( t_audio[i], ener_match, &t_audio[i], &lsb ); /* Q12 */ - move16(); - } - } - } - - /* limit encoded band-width according to the command-line OR BWD limitation */ - inner_frame = inner_frame_tbl[st_fx->bwidth]; /* Q0 */ - move16(); - IF( GT_16( input_frame, inner_frame ) ) - { - IF( EQ_16( is_transient, 1 ) ) - { - FOR( i = 1; i < NUM_TIME_SWITCHING_BLOCKS; i++ ) - { - tmp = i_mult2( i, shr( input_frame, 2 ) ); - tmp = shr( inner_frame, 2 ); - Copy32( t_audio + i_mult2( i, shr( input_frame, 2 ) ), t_audio + i_mult2( i, tmp ), tmp ); /* Q12 */ - } - } - - set32_fx( t_audio + inner_frame, 0, sub( input_frame, inner_frame ) ); - } - } - /*-------------------------------------------------------------------------- - * High-band gain control in case of BWS - *--------------------------------------------------------------------------*/ - - /*-------------------------------------------------------------------------- - * Classify whether to put extra bits for FER mitigation - *--------------------------------------------------------------------------*/ - - test(); - test(); - test(); - IF( ( EQ_16( st_fx->last_core, TCX_20_CORE ) || EQ_16( st_fx->last_core, TCX_10_CORE ) || EQ_16( st_fx->last_core, HQ_CORE ) ) && GT_32( st_fx->core_brate, MINIMUM_RATE_TO_ENCODE_VOICING_FLAG ) ) - { - IF( Voicing_flag > 0 ) - { - push_indice( hBstr, IND_HQ_VOICING_FLAG, 1, 1 ); - num_bits = sub( num_bits, 1 ); - } - ELSE - { - push_indice( hBstr, IND_HQ_VOICING_FLAG, 0, 1 ); - num_bits = sub( num_bits, 1 ); - } - } - - /*-------------------------------------------------------------------------- - * Transform-domain encoding - *--------------------------------------------------------------------------*/ - - IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) - { - /* HQ low rate encoder */ - FOR( i = 0; i < inner_frame; i++ ) - { - t_audio[i] = L_shr( t_audio[i], sub( Q_audio, 12 ) ); /* Q12 */ - move32(); - } - hq_lr_enc_fx( st_fx, t_audio, inner_frame, &num_bits, is_transient ); - Q_audio = 12; - move16(); - } - ELSE - { - /* HQ high rate encoder */ - FOR( i = 0; i < inner_frame; i++ ) - { - t_audio[i] = L_shr( t_audio[i], sub( Q_audio, 12 ) ); /* Q12 */ - move32(); - } - hq_hr_enc_fx( st_fx, t_audio, inner_frame, &num_bits, is_transient, vad_hover_flag ); - Q_audio = 12; - move16(); - } - - /* write all unused bits to the bitstream */ - num_bits = add( num_bits, extra_unused ); - - WHILE( num_bits >= 16 ) - { - push_indice( hBstr, IND_UNUSED, 0, 16 ); - num_bits = sub( num_bits, 16 ); - } - - IF( num_bits != 0 ) - { - push_indice( hBstr, IND_UNUSED, 0, num_bits ); - } - return; -} -#endif /*-------------------------------------------------------------------* * hq_core_enc_init() @@ -272,7 +63,6 @@ void HQ_core_enc_init_fx( } -#ifdef HARM_HQ_CORE /*-------------------------------------------------------------------------- * hq_core_enc() * @@ -280,9 +70,6 @@ void HQ_core_enc_init_fx( *--------------------------------------------------------------------------*/ void hq_core_enc_fx( -#else -void hq_core_enc_ivas_fx( -#endif Encoder_State *st, /* i/o: encoder state structure */ const Word16 *audio_fx, /* i : input audio signal Q0*/ const Word16 input_frame_orig, /* i : frame length Q0*/ @@ -392,14 +179,12 @@ void hq_core_enc_ivas_fx( Q_audio = 0; move16(); -#ifdef HARM_HQ_CORE IF( st->element_mode == EVS_MONO ) { Copy( st->old_input_signal_fx, two_frames_buffer, input_frame ); /* st_fx->q_old_inp */ Copy( audio_fx, two_frames_buffer + input_frame, input_frame ); /* Q0 */ } ELSE -#endif { Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); /* Q0 */ Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) ); /* Q0 */ @@ -433,9 +218,7 @@ void hq_core_enc_ivas_fx( move16(); direct_transform_fx( wtda_audio_fx32, t_audio_fx, is_transient, input_frame, &Q_audio, st->element_mode ); -#ifdef HARM_HQ_CORE IF( st->element_mode > EVS_MONO ) -#endif { scale_sig32( wtda_audio_fx32, L_FRAME48k_EXT, sub( Q_audio, tmp_q ) ); /* Q_audio */ } @@ -443,14 +226,12 @@ void hq_core_enc_ivas_fx( /* scale coefficients to their nominal level (8kHz) */ IF( NE_16( input_frame, NORM_MDCT_FACTOR ) ) { -#ifdef HARM_HQ_CORE test(); IF( st->element_mode == EVS_MONO && EQ_16( input_frame, L_FRAME32k ) ) { Q_audio = add( Q_audio, 1 ); /* Divide by 2 */ } ELSE -#endif { UWord16 lsb; tmp = mult_r( input_frame, 410 / 2 ); /* 1/8000 in Q15 */ @@ -493,12 +274,8 @@ void hq_core_enc_ivas_fx( * High-band gain control in case of BWS *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE test(); IF( st->element_mode > EVS_MONO && st->bwidth_sw_cnt > 0 ) -#else - IF( st->bwidth_sw_cnt > 0 ) -#endif { Word32 L_tmp; tmp = BASOP_Util_Divide1616_Scale( 3, BWS_TRAN_PERIOD, &exp ); /* Q15-exp */ @@ -542,13 +319,11 @@ void hq_core_enc_ivas_fx( * Transform-domain encoding *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE IF( st->element_mode == EVS_MONO ) { scale_sig32( t_audio_fx, inner_frame, sub( Q12, Q_audio ) ); /* Q12 */ } ELSE -#endif { scale_sig32( t_audio_fx, L_FRAME48k_EXT, sub( Q12, Q_audio ) ); scale_sig32( wtda_audio_fx32, 2 * L_FRAME48k, sub( Q12, Q_audio ) ); @@ -558,21 +333,13 @@ void hq_core_enc_ivas_fx( IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { -#ifdef HARM_HQ_CORE /* HQ low rate encoder */ hq_lr_enc_fx( st, t_audio_fx, inner_frame, &num_bits, is_transient ); -#else - /* this cannot happen in IVAS */ -#endif } ELSE { /* HQ high rate encoder */ -#ifdef HARM_HQ_CORE hq_hr_enc_fx( st, t_audio_fx, L_spec, &num_bits, is_transient, vad_hover_flag ); -#else - hq_hr_enc_ivas_fx( st, t_audio_fx, L_spec, &num_bits, is_transient, vad_hover_flag ); -#endif } /* write all unused bits to the bitstream */ @@ -641,11 +408,7 @@ void hq_core_enc_ivas_fx( Copy( wtda_audio_fx16 + sub( shr( overlap, 1 ), tcx_offset ), output_fx, st->L_frame ); /* Q0 */ } -#ifdef HARM_HQ_CORE ELSE IF( st->element_mode > EVS_MONO ) -#else - ELSE -#endif { Word16 tmp_q = Q_audio; move16(); diff --git a/lib_enc/hq_env_enc_fx.c b/lib_enc/hq_env_enc_fx.c index 98c94cc2f..6374a89e8 100644 --- a/lib_enc/hq_env_enc_fx.c +++ b/lib_enc/hq_env_enc_fx.c @@ -552,542 +552,6 @@ Word16 encode_envelope_indices_fx( return hcode_l; } -#ifndef HARM_HQ_CORE -Word16 encode_envelope_indices_ivas_fx( /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream Q0 */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ - Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ - Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ - const Word16 flag_HQ2, /* i : indicator of HQ2 core Q0 */ - const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ -) -{ - Word16 bits; - Word16 prevj; - Word16 hcode_l; - Word16 i, j; - Word16 difidx_flag; - Word16 index_max, index_min, index_rad; - Word16 difidx_org[NB_SFM]; /* length of this buffer is max(BANDS_MAX,NB_SFM) */ - Word16 m, r; - Word16 v, k; - - - set16_fx( difidx_org, 0, NB_SFM ); - difidx_flag = 0; - move16(); - - /*------------------------------------------------------------------* - * Check Huffman encoding for QNorm indices - *------------------------------------------------------------------*/ - - /* LC mode index is changed to synchronize LR_MDCT signaling */ - /* LC mode 0 = Context based coding */ - /* LC mode 1 = resized huffman coding */ - /* LC mode 2 = normal Huffman Coding */ - /* LC mode 3 = bit packing */ - IF( flag_pack == 0 ) - { - test(); - IF( is_transient && EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) - { - bits = 0; - move16(); - index_max = 0; - move16(); - index_min = 31; - move16(); - FOR( i = 0; i < num_sfm; i++ ) - { - IF( GT_16( difidx[i], index_max ) ) - { - index_max = difidx[i]; /* Q0 */ - move16(); - } - IF( LT_16( difidx[i], index_min ) ) - { - index_min = difidx[i]; /* Q0 */ - move16(); - } - } - test(); - IF( GT_16( index_min, 10 ) && LT_16( index_max, 22 ) ) - { - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - bits = add( bits, huffsizn_tran[j] ); - } - } - hcode_l = 0; - move16(); - *LCmode = 0; - move16(); - prevj = add( difidx[0], OFFSET_NORM ); - /* LC mode 0 = Context based coding */ - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - IF( GT_16( prevj, HTH_NORM ) ) - { - /* above */ - hcode_l = add( hcode_l, huffsizn_n[31 - j] ); /* Q0 */ - } - ELSE - { - IF( LT_16( prevj, LTH_NORM ) ) - { - /* less */ - hcode_l = add( hcode_l, huffsizn_n[j] ); /* Q0 */ - } - ELSE - { - /* equal */ - hcode_l = add( hcode_l, huffsizn_e[j] ); /* Q0 */ - } - } - prevj = j; - move16(); - } - test(); - IF( GE_16( hcode_l, bits ) && bits != 0 ) - { - /* LC mode 1 Transient Huffman Coding */ - *LCmode = 1; - move16(); - hcode_l = bits; - move16(); - } - } - ELSE - { - /* Check bits if LC mode == 3 -> Check bits if LC mode == 0 */ - hcode_l = 0; - move16(); - prevj = add( difidx[0], OFFSET_NORM ); - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - IF( GT_16( prevj, HTH_NORM ) ) - { - /* above */ - hcode_l = add( hcode_l, huffsizn_n[( 31 - j )] ); /* Q0 */ - } - ELSE - { - IF( LT_16( prevj, LTH_NORM ) ) - { - /* less */ - hcode_l = add( hcode_l, huffsizn_n[j] ); /* Q0 */ - } - ELSE - { - /* equal */ - hcode_l = add( hcode_l, huffsizn_e[j] ); /* Q0 */ - } - } - prevj = j; - move16(); - } - - *LCmode = 0; - move16(); - - /* LR-MDCT core doesn't have coding mode 2 and 3 */ - IF( flag_HQ2 == NORMAL_HQ_CORE ) - { - /* Check bits if LC mode == 1 -> Check bits if LC mode == 2 */ - bits = 0; - move16(); - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - bits = add( bits, huffsizn[j] ); - } - - /*------------------------------------------------------------------------------* - * comparing bit expenses of coding mode 2 with that of the optimal coding mode - *------------------------------------------------------------------------------*/ - - IF( GT_16( hcode_l, bits ) ) - { - *LCmode = 2; - move16(); - } - hcode_l = s_min( hcode_l, bits ); - } - - /* Check bits if LC mode == 2 -> Check bits if LC mode == 1 */ - bits = 0; - move16(); - index_max = 0; - move16(); - index_min = 31; - move16(); - FOR( i = 1; i < num_sfm; i++ ) - { - difidx_org[i] = difidx[i]; /* Q0 */ - move16(); - } - - difidx_flag = 0; - move16(); - FOR( i = 2; i < num_sfm; i++ ) - { - IF( GT_16( difidx_org[i - 1], 17 ) ) - { - difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); /* Q0 */ - move16(); - IF( GT_16( difidx[i], 31 ) ) - { - difidx_flag = 1; - move16(); - BREAK; - } - } - - IF( LT_16( difidx_org[i - 1], 13 ) ) - { - difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); /* Q0 */ - move16(); - IF( difidx[i] < 0 ) - { - difidx_flag = 1; - move16(); - BREAK; - } - } - } - - index_rad = 0; - move16(); - IF( difidx_flag == 0 ) - { - FOR( i = 1; i < num_sfm; i++ ) - { - index_max = s_max( index_max, difidx[i] ); - index_min = s_min( index_min, difidx[i] ); - } - - index_rad = s_max( sub( 15, index_min ), sub( index_max, 15 ) ); - - IF( LE_16( index_rad, HUFF_THR ) ) - { - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - bits = add( bits, resize_huffsizn[j] ); - } - - /*------------------------------------------------------------------* - * comparing bit expenses of coding mode 1 with that of coding mode 0 - *------------------------------------------------------------------*/ - - IF( GT_16( hcode_l, bits ) ) - { - *LCmode = 1; - move16(); - } - hcode_l = s_min( hcode_l, bits ); - } - } - - /* LR-MDCT core doesn't have coding mode 2 and 3 */ - IF( flag_HQ2 == NORMAL_HQ_CORE ) - { - /*------------------------------------------------------------------------------* - * comparing bit expenses of coding mode 3 with that of the optimal coding mode - *------------------------------------------------------------------------------*/ - - IF( GE_16( hcode_l, numnrmibits ) ) - { - *LCmode = 3; - move16(); - } - hcode_l = s_min( hcode_l, numnrmibits ); - } - - test(); - test(); - IF( ( NE_16( *LCmode, 1 ) && flag_HQ2 == NORMAL_HQ_CORE ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) ) - { - FOR( i = 2; i < num_sfm; i++ ) - { - difidx[i] = difidx_org[i]; /* Q0 */ - move16(); - } - } - } - } - ELSE - { - test(); - IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) || EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) ) - { - push_indice( hBstr, IND_HQ2_DENG_HMODE, *LCmode, BITS_DE_HMODE ); - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, difidx[0], BITS_DE_FCOMP ); - } - ELSE - { - push_indice( hBstr, IND_LC_MODE, *LCmode, 2 ); - push_indice( hBstr, IND_YNRM, difidx[0], NORM0_BITS ); - } - - test(); - IF( is_transient && EQ_16( flag_HQ2, LOW_RATE_HQ_CORE_TRAN ) ) - { - hcode_l = 0; - move16(); - IF( EQ_16( *LCmode, 1 ) ) - { - /* LC mode 0 Transient Huffman Coding */ - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - m = huffnorm_tran[j]; /* Q0 */ - move16(); - r = huffsizn_tran[j]; /* Q0 */ - move16(); - v = 0; - move16(); - - /* Bit reverse */ - FOR( k = 0; k < r; k++ ) - { - v = lshl( v, 1 ); /* Q0 */ - v = s_or( v, s_and( m, 1 ) ); /* Q0 */ - m = lshr( m, 1 ); /* Q0 */ - } - - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, v, r ); - } - } - ELSE - { - /* LC mode 1 context based Coding */ - prevj = add( difidx[0], OFFSET_NORM ); - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - - IF( GT_16( prevj, HTH_NORM ) ) - { - /* above */ - r = huffsizn_n[( 31 - j )]; /* Q0 */ - move16(); - m = huffnorm_n[( 31 - j )]; /* Q0 */ - move16(); - } - ELSE - { - IF( LT_16( prevj, LTH_NORM ) ) - { - /* less */ - r = huffsizn_n[j]; /* Q0 */ - move16(); - m = huffnorm_n[j]; /* Q0 */ - move16(); - } - ELSE - { - /* equal */ - r = huffsizn_e[j]; /* Q0 */ - move16(); - m = huffnorm_e[j]; /* Q0 */ - move16(); - } - } - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, m, r ); - prevj = j; - move16(); - } - } - } - ELSE - { - hcode_l = 0; - move16(); - IF( *LCmode == 0 ) - { - /* LC mode 3 -> LC mode 0 */ - prevj = add( difidx[0], OFFSET_NORM ); - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - - IF( GT_16( prevj, HTH_NORM ) ) - { - /* above */ - r = huffsizn_n[( 31 - j )]; /* Q0 */ - move16(); - m = huffnorm_n[( 31 - j )]; /* Q0 */ - move16(); - } - ELSE - { - IF( LT_16( prevj, LTH_NORM ) ) - { - /* less */ - r = huffsizn_n[j]; /* Q0 */ - move16(); - m = huffnorm_n[j]; /* Q0 */ - move16(); - } - ELSE - { - /* equal */ - r = huffsizn_e[j]; /* Q0 */ - move16(); - m = huffnorm_e[j]; /* Q0 */ - move16(); - } - } - - IF( EQ_16( flag_HQ2, LOW_RATE_HQ_CORE ) ) - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, m, r ); - } - ELSE - { - push_indice( hBstr, IND_YNRM, m, r ); - } - - prevj = j; - move16(); - } - } - ELSE IF( EQ_16( *LCmode, 1 ) ) - { - IF( EQ_16( flag_HQ2, 1 ) ) - { - index_max = 0; - move16(); - index_min = 31; - move16(); - FOR( i = 1; i < num_sfm; i++ ) - { - difidx_org[i] = difidx[i]; /* Q0 */ - move16(); - } - - FOR( i = 2; i < num_sfm; i++ ) - { - IF( GT_16( difidx_org[i - 1], 17 ) ) - { - difidx[i] = add( difidx_org[i], s_min( sub( difidx_org[i - 1], 17 ), 3 ) ); /* Q0 */ - move16(); - IF( GT_16( difidx[i], 31 ) ) - { - difidx_flag = 1; - move16(); - BREAK; - } - } - - IF( LT_16( difidx_org[i - 1], 13 ) ) - { - difidx[i] = add( difidx_org[i], s_max( sub( difidx_org[i - 1], 13 ), -3 ) ); /* Q0 */ - move16(); - IF( difidx[i] < 0 ) - { - difidx_flag = 1; - move16(); - BREAK; - } - } - } - - IF( difidx_flag == 0 ) - { - FOR( i = 1; i < num_sfm; i++ ) - { - index_max = s_max( index_max, difidx[i] ); - index_min = s_min( index_min, difidx[i] ); - } - - index_rad = s_max( sub( 15, index_min ), sub( index_max, 15 ) ); - - IF( LE_16( index_rad, HUFF_THR ) ) - { - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - } - } - } - } - - /* LC mode 2 -> LC mode 1 */ - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - - m = resize_huffnorm[j]; /* Q0 */ - move16(); - r = resize_huffsizn[j]; /* Q0 */ - move16(); - v = 0; - move16(); - - /* Bit reverse */ - FOR( k = 0; k < r; k++ ) - { - v = lshl( v, 1 ); /* Q0 */ - v = s_or( v, s_and( m, 1 ) ); /* Q0 */ - m = lshr( m, 1 ); /* Q0 */ - } - - IF( flag_HQ2 == 0 ) - { - push_indice( hBstr, IND_YNRM, v, r ); - } - ELSE - { - push_indice( hBstr, IND_HQ2_DIFF_ENERGY, v, r ); - } - } - } - ELSE IF( EQ_16( *LCmode, 2 ) ) - { - /* LC mode 1 -> LC mode 2 */ - FOR( i = 1; i < num_sfm; i++ ) - { - j = difidx[i]; /* Q0 */ - move16(); - - m = huffnorm[j]; /* Q0 */ - move16(); - r = huffsizn[j]; /* Q0 */ - move16(); - - push_indice( hBstr, IND_YNRM, m, r ); - } - } - ELSE - { - FOR( i = 1; i < num_sfm; i++ ) - { - push_indice( hBstr, IND_YNRM, difidx[i], NORMI_BITS ); - } - } - } - } - - return hcode_l; -} -#endif /*--------------------------------------------------------------------------* * diff_envelope_coding_fx() diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index b2d7b4175..5d2a3cce4 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -18,247 +18,6 @@ *--------------------------------------------------------------------------*/ void hq_hr_enc_fx( -#ifndef HARM_HQ_CORE - Encoder_State *st_fx, /* i/o: encoder state structure fx */ - Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ - const Word16 length, /* i : length of spectrum Q0 */ - Word16 *num_bits, /* i : number of available bits Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - const Word16 vad_hover_flag /* i : VAD hangover flag Q0 */ -) -{ - Word16 nb_sfm; /* Q0 */ - Word16 sum, hcode_l; /* Q0 */ - Word16 difidx[NB_SFM]; /* Q0 */ - Word16 normqlg2[NB_SFM], ynrm[NB_SFM]; /* Q0 */ - Word16 nf_idx; /* Q0 */ - Word16 bits; /* */ - Word16 LCmode; /* Q0 */ - Word16 shape_bits, num_sfm, numnrmibits; /* Q0 */ - Word16 hqswb_clas; /* Q0 */ - Word16 num_env_bands; /* Q0 */ - Word16 Npeaks, start_norm; /* Q0 */ - Word16 difidx_org[NB_SFM]; /* Q0 */ - Word16 R[NB_SFM]; /* Q0 */ - Word16 peaks[HVQ_MAX_PEAKS]; /* Q0 */ - Word16 sfmsize[NB_SFM], sfm_start[NB_SFM], sfm_end[NB_SFM]; /* Q0 */ - Word16 npulses[NB_SFM], maxpulse[NB_SFM]; /* Q0 */ - Word16 Rsubband[NB_SFM]; /* Q3 */ - Word32 t_audio_q[L_SPEC48k_EXT]; /* Q12 */ - Word32 nf_gains[HVQ_NF_GROUPS]; /* Q12 */ - Word32 pe_gains[HVQ_NF_GROUPS]; /* Q12 */ - Word16 noise_level[HVQ_BWE_NOISE_BANDS]; /* Q15 */ - Word16 hq_generic_offset; /* Q0 */ - Word16 hq_generic_fenv[HQ_FB_FENV]; /* Q1 */ - Word16 hq_generic_exc_clas = 0; /* Q0 */ - move16(); - Word16 core_sfm; /* Q0 */ - Word16 har_freq_est1, har_freq_est2; - Word16 flag_dis; - const Word16 *subband_search_offset; - Word16 wBands[2]; - - Word16 t_audio_norm[L_FRAME48k]; - Word16 t_audio_q_norm[L_FRAME48k]; - Word16 Q_audio; - Word16 i; - Word16 b_delta_env; - Word16 Q_shift; - Word16 att; - HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; - - /*------------------------------------------------------------------* - * Initializations - *------------------------------------------------------------------*/ - - Npeaks = 0; - Q_audio = 0; /* to avoid compilation warnings */ - move16(); - move16(); - - set16_fx( npulses, 0, NB_SFM ); - set16_fx( maxpulse, 0, NB_SFM ); - set16_fx( difidx_org, 0, NB_SFM ); - set32_fx( t_audio_q, 0, L_FRAME48k ); - set32_fx( nf_gains, 0, HVQ_NF_GROUPS ); - set32_fx( pe_gains, 0, HVQ_NF_GROUPS ); - flag_dis = 1; - move16(); - har_freq_est1 = 0; - move16(); - har_freq_est2 = 0; - move16(); - - /*------------------------------------------------------------------* - * Classification - *------------------------------------------------------------------*/ - - bits = hq_classifier_enc_fx( st_fx, length, t_audio, is_transient, &Npeaks, peaks, pe_gains, nf_gains, &hqswb_clas ); /* Q0 */ - - *num_bits = sub( *num_bits, bits ); /* Q0 */ - move16(); - - /*------------------------------------------------------------------* - * set quantization parameters - *------------------------------------------------------------------*/ - - hq_configure_evs_fx( length, hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, - sfmsize, sfm_start, sfm_end ); - - /*------------------------------------------------------------------* - * Transient frame handling - *------------------------------------------------------------------*/ - - /* Interleave MLT coefficients of 4 sub-vectors in case of transient */ - IF( EQ_16( is_transient, 1 ) ) - { - interleave_spectrum_fx( t_audio, length ); - } - - test(); - IF( EQ_16( st_fx->element_mode, IVAS_CPE_DFT ) || EQ_16( st_fx->element_mode, IVAS_CPE_TD ) ) - { - calculate_hangover_attenuation_gain_fx( st_fx, &att, vad_hover_flag ); - v_multc_att32( t_audio, att, t_audio, sfm_end[( num_sfm - 1 )] ); /* Q12 */ - } - - /*------------------------------------------------------------------* - * Scalar quantization of norms - * Encode norm indices - *------------------------------------------------------------------*/ - - /* calculate and quantize norms */ - calc_norm_fx( t_audio, Q12, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); - - /* create differential code of quantized norm indices */ - diff_envelope_coding_fx( is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx ); - - /* Find coding mode and calculate bit rate */ - hcode_l = encode_envelope_indices_fx( st_fx->hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); /* Q0 */ - *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Q0 */ - move16(); - - /* Encode norm indices */ - encode_envelope_indices_fx( st_fx->hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); - - /*------------------------------------------------------------------* - * HQ Generic HF encoding - *------------------------------------------------------------------*/ - - test(); - IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) - { - hq_generic_encoding_fx( t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas /*, length*/ ); - IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) - { - *num_bits = add( *num_bits, 1 ); /* conditional 1 bit saving for representing FD3 BWE excitation class Q0*/ - move16(); - } - map_hq_generic_fenv_norm_fx( hqswb_clas, hq_generic_fenv, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); - } - - /*------------------------------------------------------------------* - * Bit allocation - *------------------------------------------------------------------*/ - - hq_bit_allocation_fx( st_fx->core_brate, length, hqswb_clas, num_bits, normqlg2, nb_sfm, sfmsize, noise_level, - R, Rsubband, &sum, &core_sfm, num_env_bands ); - - /*------------------------------------------------------------------* - * Normalize coefficients with quantized norms - *------------------------------------------------------------------*/ - IF( hqswb_clas != HQ_HVQ ) - { - test(); - IF( hqswb_clas == HQ_GEN_SWB || hqswb_clas == HQ_GEN_FB ) - { - b_delta_env = calc_nor_delta_hf_fx( st_fx->hBstr, t_audio, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); /* Q0 */ - sum = sub( sum, b_delta_env ); - } - normalizecoefs_fx( t_audio, ynrm, nb_sfm, sfm_start, sfm_end, t_audio_norm ); - Q_audio = 12; - move16(); - } - - /*------------------------------------------------------------------* - * Quantize/code spectral fine structure using PVQ or HVQ - *------------------------------------------------------------------*/ - - IF( EQ_16( hqswb_clas, HQ_HVQ ) ) - { - sum = hvq_enc_fx( st_fx, st_fx->core_brate, *num_bits, Npeaks, ynrm, R, peaks, nf_gains, noise_level, pe_gains, t_audio, t_audio_q ); - *num_bits = sub( *num_bits, sum ); /* Q0 */ - move16(); - } - ELSE - { - shape_bits = pvq_core_enc_fx( st_fx->hBstr, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, - npulses, maxpulse, HQ_CORE ); - *num_bits = add( *num_bits, sub( sum, shape_bits ) ); /* Q0 */ - move16(); - } - - test(); - IF( EQ_16( hqswb_clas, HQ_HVQ ) || EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - subband_search_offset = subband_search_offsets_13p2kbps_Har; /* Q0 */ - wBands[0] = SWB_SB_BW_LEN0_16KBPS_HAR; /* Q0 */ - move16(); - wBands[1] = SWB_SB_BW_LEN1_16KBPS_HAR; /* Q0 */ - move16(); - - IF( EQ_16( hqswb_clas, HQ_HARMONIC ) ) - { - Q_shift = sub( SWB_BWE_LR_Qs, Q_audio ); - FOR( i = 0; i < 300; i++ ) - { - t_audio_q[i] = L_shl( L_deposit_l( t_audio_q_norm[i] ), Q_shift ); /* Q12 */ - move32(); - } - } - - har_est_fx( t_audio_q, 300, &har_freq_est1, &har_freq_est2, &flag_dis, &hHQ_core->prev_frm_hfe2, subband_search_offset, wBands, &hHQ_core->prev_stab_hfe2 ); - - hHQ_core->prev_frm_hfe2 = har_freq_est2; /* Q0 */ - move16(); - } - - test(); - test(); - hHQ_core->prev_frm_hfe2 = 0; /*reset*/ - move16(); - hHQ_core->prev_stab_hfe2 = 0; /*reset*/ - move16(); - - nf_idx = 0; - move16(); - test(); - test(); - test(); - IF( NE_16( is_transient, 1 ) && NE_16( hqswb_clas, HQ_HVQ ) && !( EQ_16( length, L_FRAME16k ) && LE_32( st_fx->core_brate, HQ_32k ) ) ) - { - test(); - IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) - { - nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, s_max( core_sfm, sub( num_env_bands, 1 ) ) ); /* Q0 */ - push_indice( st_fx->hBstr, IND_NF_IDX, nf_idx, 2 ); - } - ELSE - { - nf_idx = noise_adjust_fx( t_audio_norm, 12, R, sfm_start, sfm_end, core_sfm ); /* Q0 */ - push_indice( st_fx->hBstr, IND_NF_IDX, nf_idx, 2 ); - } - } - /* updates */ - hHQ_core->prev_hqswb_clas = hqswb_clas; /* Q0 */ - move16(); - - /* Prepare synthesis for LB generation in case of switch to ACELP */ - return; -} - -void hq_hr_enc_ivas_fx( -#endif Encoder_State *st, /* i/o: encoder state structure */ Word32 *t_audio_fx, /* i/o: transform-domain coefficients Q12*/ const Word16 length, /* i : length of spectrum Q0*/ @@ -323,11 +82,7 @@ void hq_hr_enc_ivas_fx( * Classification *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE bits = hq_classifier_enc_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ -#else - bits = hq_classifier_enc_ivas_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ -#endif *num_bits = sub( *num_bits, bits ); @@ -344,11 +99,7 @@ void hq_hr_enc_ivas_fx( /* Interleave MLT coefficients of 4 sub-vectors in case of transient frame */ IF( is_transient ) { -#ifdef HARM_HQ_CORE interleave_spectrum_fx( t_audio_fx, length ); -#else - interleave_spectrum_ivas_fx( t_audio_fx, length ); -#endif } test(); @@ -364,13 +115,11 @@ void hq_hr_enc_ivas_fx( *------------------------------------------------------------------*/ /* calculate and quantize norms */ -#ifdef HARM_HQ_CORE IF( st->element_mode == EVS_MONO ) { calc_norm_fx( t_audio_fx, 12, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); } ELSE -#endif { calc_norm_ivas_fx( t_audio_fx, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); } @@ -379,20 +128,12 @@ void hq_hr_enc_ivas_fx( diff_envelope_coding_fx( is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx ); /* Find norm coding mode and calculate number of bits */ -#ifdef HARM_HQ_CORE hcode_l = encode_envelope_indices_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); /* Q0 */ -#else - hcode_l = encode_envelope_indices_ivas_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); /* Q0 */ -#endif *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); /* Encode norm indices */ -#ifdef HARM_HQ_CORE encode_envelope_indices_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); -#else - encode_envelope_indices_ivas_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); -#endif /*------------------------------------------------------------------* * HQ Generic BWE encoding @@ -401,11 +142,7 @@ void hq_hr_enc_ivas_fx( test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { -#ifdef HARM_HQ_CORE hq_generic_hf_encoding_fx( st->element_mode, t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, length ); -#else - hq_generic_hf_encoding_fx( t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, length ); -#endif IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { @@ -419,11 +156,7 @@ void hq_hr_enc_ivas_fx( * Bit allocation *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE hq_bit_allocation_fx( st->core_brate, length, hqswb_clas, num_bits, normqlg2, nb_sfm, sfmsize, noise_level_fx, R, Rsubband, &sum, &core_sfm, num_env_bands ); -#else - ivas_hq_bit_allocation_fx( st->core_brate, length, hqswb_clas, num_bits, normqlg2, nb_sfm, sfmsize, noise_level_fx, R, Rsubband, &sum, &core_sfm, num_env_bands ); -#endif /*------------------------------------------------------------------* * Normalize coefficients with quantized norms @@ -434,11 +167,7 @@ void hq_hr_enc_ivas_fx( test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { -#ifdef HARM_HQ_CORE b_delta_env = calc_nor_delta_hf_fx( hBstr, t_audio_fx, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); /* Q0 */ -#else - b_delta_env = calc_nor_delta_hf_ivas_fx( hBstr, t_audio_fx, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); /* Q0 */ -#endif sum = sub( sum, b_delta_env ); } normalizecoefs_fx( t_audio_fx, ynrm, nb_sfm, sfm_start, sfm_end, t_audio_norm ); @@ -452,21 +181,13 @@ void hq_hr_enc_ivas_fx( IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { -#ifdef HARM_HQ_CORE sum = hvq_enc_fx( st, st->core_brate, *num_bits, Npeaks, ynrm, R, peaks, nf_gains_fx, noise_level_fx, pe_gains_fx, t_audio_fx, t_audio_q_fx ); -#else - sum = hvq_enc_ivas_fx( st, st->core_brate, *num_bits, Npeaks, ynrm, R, peaks, nf_gains_fx, noise_level_fx, pe_gains_fx, t_audio_fx, t_audio_q_fx ); -#endif *num_bits = sub( *num_bits, sum ); } ELSE { -#ifdef HARM_HQ_CORE shape_bits = pvq_core_enc_fx( st->element_mode, hBstr, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, npulses, maxpulse, HQ_CORE ); /* Q0 */ -#else - shape_bits = pvq_core_enc_ivas_fx( hBstr, t_audio_norm, t_audio_q_norm, &Q_audio, sum, nb_sfm, sfm_start, sfm_end, sfmsize, Rsubband, R, npulses, maxpulse, HQ_CORE ); /* Q0 */ -#endif *num_bits = add( *num_bits, sub( sum, shape_bits ) ); } @@ -524,9 +245,7 @@ void hq_hr_enc_ivas_fx( move16(); /* Prepare synthesis for LB generation in case of switch to ACELP */ -#ifdef HARM_HQ_CORE IF( st->element_mode > EVS_MONO ) -#endif { IF( NE_16( hqswb_clas, HQ_HVQ ) ) { @@ -540,11 +259,7 @@ void hq_hr_enc_ivas_fx( IF( is_transient ) { -#ifdef HARM_HQ_CORE de_interleave_spectrum_fx( t_audio_q_fx, length ); -#else - ivas_de_interleave_spectrum_fx( t_audio_q_fx, length ); -#endif } Copy32( t_audio_q_fx, t_audio_fx, length ); diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index 4111ff1bc..c570a6e49 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -30,12 +30,8 @@ static Word16 quant_lc_fx( const Word16, Word16 * ); * Harmonic VQ encoder *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE /* o : Consumed bits */ Word16 hvq_enc_fx( -#else -Word16 hvq_enc_ivas_fx( /*o : Consumed bits */ -#endif Encoder_State *st_fx, /* i/o: encoder state structure */ const Word32 core_brate, /* i : Total bit rate */ const Word16 hvq_bits, /* i : HVQ bit budget */ @@ -204,195 +200,14 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits */ } } -#ifdef HARM_HQ_CORE nBits = peak_vq_enc_fx( st_fx->element_mode, st_fx->hBstr, st_fx->bwidth, coefs, coefs_out, core_brate, sub( hvq_bits, bits_used ), Npeaks, ynrm, R, peaks, &nf_gains[0] ); -#else - nBits = peak_vq_enc_ivas_fx( st_fx->hBstr, st_fx->bwidth, coefs, coefs_out, core_brate, sub( hvq_bits, bits_used ), - Npeaks, ynrm, R, peaks, &nf_gains[0] ); -#endif bits_used = add( bits_used, nBits ); return bits_used; } -#ifndef HARM_HQ_CORE -Word16 hvq_enc_fx( /* o : Consumed bits */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word32 core_brate, /* i : Total bit rate */ - const Word16 hvq_bits, /* i : HVQ bit budget */ - const Word16 Npeaks, /* i : Number of peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ - Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains */ - Word16 *noise_level, /* o : Quantized noise level */ - const Word32 *pe_gains, /* i : Peak gains */ - const Word32 *coefs, /* i : spectrum coefficients in Q12 */ - Word32 *coefs_out /* o : encoded spectrum coefficients in Q12 */ -) -{ - const Word32 *pCoefs; - Word16 bin_th, j, i, n; - Word16 nf_cnt; - Word16 q_noise_level_idx[HVQ_BWE_NOISE_BANDS]; - Word16 q_noise_level[HVQ_BWE_NOISE_BANDS]; - Word32 d, nf_mean; - Word32 nf, pe, pe_mean; - Word16 bits_used, nBits; - Word16 lb_nfpe; - UWord16 dontCare; - Word32 acc, numerator, denominator; - Word16 expPeMean, expNfMean, expNfpe, expNfpe3, expo, expo3; - Word16 manPeMean, manNfMean, manNfpe, man; - Word16 tmp16, adjust; - - bits_used = 0; - move16(); - - IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) - { - bin_th = HVQ_THRES_BIN_24k; - move16(); - n = ( L_FRAME32k - HVQ_THRES_BIN_24k ) / HVQ_BWE_NOISE_BANDS; - move16(); - } - ELSE - { - bin_th = HVQ_THRES_BIN_32k; - move16(); - n = ( L_FRAME32k - HVQ_THRES_BIN_32k ) / HVQ_BWE_NOISE_BANDS; - move16(); - } - - nf = 800 * 4096L; /* Q12 */ - move32(); - pe = 800 * 4096L; /* Q12 */ - move32(); - pCoefs = &coefs[bin_th]; - - /* Find HB noise level */ - FOR( i = 0; i < HVQ_BWE_NOISE_BANDS; i++ ) - { - nf_cnt = 0; - move16(); - nf_mean = L_deposit_l( 0 ); - pe_mean = L_deposit_l( 0 ); - FOR( j = 0; j < n; j++ ) - { - d = L_abs( *pCoefs++ ); /* Q12 */ - - IF( GT_32( d, pe ) ) - { - /* W*pe + (1 - W)*d = (pe - d)*W + d */ - acc = L_sub( pe, d ); - Mpy_32_16_ss( acc, HVQ_BWE_WEIGHT2_FX, &acc, &dontCare ); - pe = L_add( acc, d ); /* in Q12 and always positive */ - } - ELSE - { - /* W*pe + (1 - W)*d = (pe - d)*W + d */ - acc = L_sub( pe, d ); - Mpy_32_16_ss( acc, HVQ_BWE_WEIGHT1_FX, &acc, &dontCare ); - pe = L_add( acc, d ); /* in Q12 and always positive */ - - IF( GT_32( d, nf ) ) - { - acc = L_sub( nf, d ); - Mpy_32_16_ss( acc, HVQ_BWE_WEIGHT1_FX, &acc, &dontCare ); - nf = L_add( acc, d ); /* in Q12 and always positive */ - } - ELSE - { - acc = L_sub( nf, d ); - Mpy_32_16_ss( acc, HVQ_BWE_WEIGHT2_FX, &acc, &dontCare ); - nf = L_add( acc, d ); /* in Q12 always positive */ - } - nf_mean = L_add( nf_mean, nf ); /* in Q12 and always positive */ - nf_cnt = add( nf_cnt, 1 ); /* Q0 */ - } - - pe_mean = L_add_sat( pe_mean, pe ); /* in Q12 and always positive */ - } - - IF( pe_mean > 0 ) - { - expPeMean = norm_l( pe_mean ); /* exponent */ - manPeMean = extract_h( L_shl( pe_mean, expPeMean ) ); /* mantissa */ - expNfMean = norm_l( nf_mean ); /* exponent */ - manNfMean = extract_h( L_shl( nf_mean, expNfMean ) ); /* mantissa */ - - numerator = L_mult0( manNfMean, n ); - IF( nf_cnt > 0 ) - { - denominator = L_mult0( manPeMean, nf_cnt ); /* in Q15 */ - } - ELSE - { - denominator = L_mult0( manPeMean, 1 ); /* in Q15 */ - } - manNfpe = ratio( numerator, denominator, &expo ); /* manNfpe in Q14 */ - expNfpe = add( sub( expNfMean, expPeMean ), expo ); - - tmp16 = mult_r( manNfpe, manNfpe ); /* in Q(14+14+1-16) = Q13 */ - tmp16 = mult_r( tmp16, manNfpe ); /* in Q(13+14+1-16) = Q12 */ - acc = L_mult( tmp16, HVQ_NFPE_FACTOR_CUBE_FX ); /* in Q(12+6+1) = Q19 */ - expNfpe3 = extract_l( L_mult0( expNfpe, 3 ) ); /* Cube operation */ - /* Number of bits required to adjust to Q15 */ - adjust = add( 19 - ( 15 + 16 ), expNfpe3 ); /* +16 is due to the following extract_h(). */ - noise_level[i] = extract_h( L_shr_sat( acc, adjust ) ); /* noise_level[] in Q15 */ - move16(); - q_noise_level_idx[i] = quant_lc_fx( noise_level[i], &q_noise_level[i] ); - move16(); - } - ELSE - { - q_noise_level_idx[i] = 0; - move16(); - q_noise_level[i] = 0; - move16(); - } - push_indice( st_fx->hBstr, IND_HVQ_BWE_NL, q_noise_level_idx[i], 2 ); - bits_used = add( bits_used, 2 ); - - noise_level[i] = q_noise_level[i]; /* in Q15 */ - move16(); - } - - FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) - { - IF( pe_gains[i] != 0 ) - { - /* Neither pe_gains[] nor nf_gains[] is zero. */ - man = ratio( nf_gains[i], pe_gains[i], &expo ); /* man in Q14 */ - tmp16 = mult_r( man, man ); /* in Q(14+14+1-16) = Q13 */ - tmp16 = mult_r( tmp16, man ); /* in Q(13+14+1-16) = Q12 */ - acc = L_mult( tmp16, HVQ_LB_NFPE_FACTOR_CUBE_FX ); /* in Q(12+9+1) = Q22 */ - expo3 = extract_l( L_mult0( expo, 3 ) ); /* Cube operation. */ - /* Number of bits required to adjust to Q15 */ - adjust = add( 22 - ( 15 + 16 ), expo3 ); /* +16 is due to the following extract_h(). */ - lb_nfpe = extract_h( L_shr_sat( acc, adjust ) ); /* noise_level[] in Q15 */ - IF( lb_nfpe > 16384 ) /* in Q15 */ - { - lb_nfpe = 16384; - move16(); - } - Mpy_32_16_ss( nf_gains[i], shl_sat( lb_nfpe, 1 ), &nf_gains[i], &dontCare ); /* nf_gains[] in Q12 */ - } - ELSE - { - nf_gains[i] = 0; - move16(); - } - } - nBits = peak_vq_enc_fx( st_fx->hBstr, st_fx->bwidth, coefs, coefs_out, core_brate, sub( hvq_bits, bits_used ), - Npeaks, ynrm, R, peaks, &nf_gains[0] ); - move16(); - bits_used = add( bits_used, nBits ); - return bits_used; -} -#endif /*----------------------------------------------------------------------------- * quant() diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index d65772bdc..40ec5df20 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -376,11 +376,7 @@ ivas_error ivas_core_enc_fx( Scale_sig( st->hTcxEnc->Txnq, L_FRAME32k / 2 + 64, sub( 0, st->hTcxEnc->q_Txnq ) ); // Q0 st->hTcxEnc->q_Txnq = 0; move16(); -#ifdef HARM_HQ_CORE hq_core_enc_fx( st, st->input_fx, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] ); -#else - hq_core_enc_ivas_fx( st, st->input_fx, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] ); -#endif } /*---------------------------------------------------------------------* diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 89d9a5681..8c0d7321c 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -19,22 +19,8 @@ static void quant_peaks_fx( BSTR_ENC_HANDLE hBstr, const Word32 *, Word32 *, const Word32 *, Word16 *, const Word16, const Word32, const Word16 ); static Word16 hvq_code_pos_fx( BSTR_ENC_HANDLE hBstr, const Word16 *inp, const Word16 length, const Word16 num_peaks ); static Word16 sparse_code_pos_fx( const Word16 *inp, const Word16 length, Word16 *result ); -#ifdef HARM_HQ_CORE static Word16 hvq_code_pos_fx( BSTR_ENC_HANDLE hBstr, const Word16 *inp, const Word16 length, const Word16 num_peaks ); static void quant_peaks_fx( BSTR_ENC_HANDLE hBstr, const Word32 *vect_in, Word32 *vect_out, const Word32 *peak_gain, Word16 *vq_idx, const Word16 overlap, const Word32 core_brate, const Word16 Npeaks ); -#else -static Word16 hvq_code_pos_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word16 *inp, const Word16 length, const Word16 num_peaks ); -static void quant_peaks_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle*/ - const Word32 *vect_in, /* i : Target vector in Q12 */ - Word32 *vect_out, /* i/o: Quantized vector in Q12 */ - const Word32 *peak_gain, /* i : Peak gain vector in Q12 */ - Word16 *vq_idx, /* o : Codebook index */ - const Word16 overlap, /* i : Overlap indicator */ - const Word32 core_brate, /* i : Core bitrate */ - const Word16 Npeaks /* i : Number of peaks */ -); -#endif /*-------------------------------------------------------------------------- @@ -43,14 +29,8 @@ static void quant_peaks_ivas_fx( * Vector Quantization of MDCT peaks *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE Word16 peak_vq_enc_fx( -#else -Word16 peak_vq_enc_ivas_fx( -#endif -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 bwidth, /* i : audio bandwidth */ const Word32 *coefs, /* i : Input coefficient vector Q12 */ @@ -141,13 +121,11 @@ Word16 peak_vq_enc_ivas_fx( /* Quantize noise floor gains */ FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) { -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { logqnorm_fx( &nf_gains[i], 12, &indx, 32, 1, 0 ); } ELSE -#endif { logqnorm_ivas_fx( &nf_gains[i], 12, &indx, 32, 1, &thren_HQ_fx[0] ); } @@ -218,26 +196,22 @@ Word16 peak_vq_enc_ivas_fx( /* Quantize peak gains */ pPeakGains = &peak_gains[0]; pPgainCbIdx = &pgain_cb_idx[0]; -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 32, 1, 1 ); } ELSE -#endif { logqnorm_ivas_fx( pPeakGains++, 14, pPgainCbIdx++, 32, 1, &thren_pg_fx[0] ); } vqPeaksMinus1 = sub( vq_peaks, 1 ); FOR( i = 0; i < vqPeaksMinus1; i++ ) { -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 45, 1, 1 ); } ELSE -#endif { logqnorm_ivas_fx( pPeakGains++, 14, pPgainCbIdx++, 45, 1, &thren_pg_fx[0] ); } @@ -345,30 +319,18 @@ Word16 peak_vq_enc_ivas_fx( { num_overlap_bins = sub( 5, sub( vq_peak_idx[i + 1], vq_peak_idx[i] ) ); indx = sub( vq_peak_idx[i], 2 ); -#ifdef HARM_HQ_CORE quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks ); -#else - quant_peaks_ivas_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks ); -#endif push_indice( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); bits = add( bits, 9 ); } indx = sub( vq_peak_idx[i], 2 ); -#ifdef HARM_HQ_CORE quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks ); -#else - quant_peaks_ivas_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks ); -#endif push_indice( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); bits = add( bits, 9 ); /* Quantize peak positions and sign with HVQ */ -#ifdef HARM_HQ_CORE pos_bits = hvq_code_pos_fx( hBstr, pos_vec, bin_th, vq_peaks ); -#else - pos_bits = hvq_code_pos_ivas_fx( hBstr, pos_vec, bin_th, vq_peaks ); -#endif bits = add( bits, pos_bits ); bit_budget = sub( num_bits, bits ); @@ -411,13 +373,11 @@ Word16 peak_vq_enc_ivas_fx( pCoefs++; } -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { logqnorm_fx( pPvqVectorBandStart, 12, &pvq_norm[k], 40, hvq_band_width[k], 0 ); } ELSE -#endif { logqnorm_ivas_fx( pPvqVectorBandStart, 12, &pvq_norm[k], 40, hvq_band_width[k], &thren_HQ_fx[0] ); } @@ -434,12 +394,7 @@ Word16 peak_vq_enc_ivas_fx( move16(); set16_fx( npulses, 0, MAX_PVQ_BANDS ); -#ifdef HARM_HQ_CORE pvq_encode_frame_fx( hBstr, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, Rk, pvq_bits, HQ_CORE ); -#else - pvq_encode_frame_ivas_fx( hBstr, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, - Rk, pvq_bits, HQ_CORE ); -#endif FOR( i = 0; i < pvq_bands; i++ ) { @@ -447,7 +402,6 @@ Word16 peak_vq_enc_ivas_fx( move16(); } -#ifdef HARM_HQ_CORE #ifdef HARM_HQ_CORE_KEEP_BE (void) element_mode; fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, NULL, NULL, pvq_bands, coefs_pvq, @@ -456,10 +410,6 @@ Word16 peak_vq_enc_ivas_fx( fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, NULL, NULL, pvq_bands, coefs_pvq, pvq_inp_vector, fg_pred, element_mode, HQ_CORE ); #endif -#else - fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, NULL, NULL, pvq_bands, coefs_pvq, - pvq_inp_vector, fg_pred, HQ_CORE ); -#endif pCoefsOut = &coefs_out[0]; pSelBnds = &sel_bnds[0]; @@ -531,700 +481,123 @@ Word16 peak_vq_enc_ivas_fx( return bits; } -#ifndef HARM_HQ_CORE -Word16 peak_vq_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 *coefs, /* i : Input coefficient vector Q12 */ - Word32 *coefs_out, /* o : Quantized output vector Q12 */ - const Word32 core_brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* i : Peak index vector */ - Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ -) -{ - Word16 pos_bits; - Word32 normq; - Word32 pgain_q[HVQ_MAX_PEAKS]; - Word32 peak_gains[HVQ_MAX_PEAKS]; - Word16 coefs_pvq[HVQ_PVQ_BUF_LEN], *pCoefsPvq; /* Q12 */ - Word32 pvq_vector[HVQ_PVQ_BUF_LEN], *pPvqVector; - Word32 *pPvqVectorBandStart; - Word16 pvq_vector_norm[HVQ_PVQ_BUF_LEN]; - Word16 fg_pred[NB_SFM_MAX]; - Word16 i, j, k, m, r, pvq_bands, num_overlap_bins; - Word16 hcode_l, FlagN, low_peak_bin, vq_cb_idx, max_peaks, bin_th, bin_th2; - Word16 bits; - Word16 nf_seed; - Word16 pgain_cb_idx[HVQ_MAX_PEAKS], pgain_difidx[HVQ_MAX_PEAKS]; /* Q0 */ - Word16 pvq_norm[MAX_PVQ_BANDS]; - Word16 pvq_bits, bit_budget; - Word16 pos_vec[HVQ_THRES_BIN_32k]; - Word16 npulses[MAX_PVQ_BANDS]; - Word16 pvq_inp_vector[HVQ_PVQ_BUF_LEN]; - Word16 k_sort[MAX_PVQ_BANDS]; - Word16 Rk[MAX_PVQ_BANDS]; - Word16 gopt[NB_SFM]; - Word16 tmp1, exp1; - Word16 Q_coefs; - - Word16 indx, vqPeaksMinus1, tmp16, whiteNoise; - Word16 *pPgainDifIdx, *pPgainCbIdx, *pVqPeakIdx, *pPosVec; - Word32 *pPeakGains, *pCoefsOut; - const Word32 *pCoefs; - Word32 acc; - UWord16 dontCare16; - Word32 manE_peak, manPeakGains, manPkEnrg; /* Due to very wide dynamic range, use floating point format, i.e., (man, exp) */ - Word16 expE_peak, expPeakGains, expPkEnrg; - Word16 *pSelBnds; - Word16 sel_bnds[HVQ_NUM_SFM_24k]; - Word16 hvq_band_end[MAX_PVQ_BANDS]; - Word16 hvq_band_start[MAX_PVQ_BANDS]; - Word16 hvq_band_width[MAX_PVQ_BANDS]; - Word16 n_sel_bnds; - UWord32 lsb; - - assert( ( core_brate > HQ_16k40 && core_brate <= HQ_48k ) && "HVQ rate not supported" ); - /* max_peaks equation needs to be converted */ - max_peaks = (Word16) ( ( core_brate * HVQ_PEAKS_PER_DELTA + HVQ_PEAKS_PER_DELTA_OFFS ) / HVQ_PEAKS_BPS_DELTA ); +/*-------------------------------------------------------------------------- + * quant_peaks_fx() + * + * Applies VQ on input vector + *--------------------------------------------------------------------------*/ - bits = 0; - move16(); - nf_seed = RANDOM_INITSEED; +static void quant_peaks_fx( + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle*/ + const Word32 *vect_in, /* i : Target vector in Q12 */ + Word32 *vect_out, /* i/o: Quantized vector in Q12 */ + const Word32 *peak_gain, /* i : Peak gain vector in Q12 */ + Word16 *vq_idx, /* o : Codebook index */ + const Word16 overlap, /* i : Overlap indicator */ + const Word32 core_brate, /* i : Core bitrate */ + const Word16 Npeaks /* i : Number of peaks */ +) +{ + Word16 x[4]; /* Qx */ + Word16 xq[4]; /* Q15 */ + Word16 weights[4]; /* Q0 */ + Word16 *pWeights; + Word16 i, cb_class, search_overlap, indx, cbSize; + Word16 expPeakGain, manPeakGain, expIn, manIn; + Word32 vectIn, absPeakGain1, absPeakGain; + UWord16 dontCare; + Word16 Qx_vec[4]; + Word16 Qx = 15; move16(); + set16_fx( weights, 1, 4 ); - set16_fx( coefs_pvq, 0, HVQ_PVQ_BUF_LEN ); - set32_fx( pvq_vector, 0, HVQ_PVQ_BUF_LEN ); - set16_fx( pvq_vector_norm, 0, HVQ_PVQ_BUF_LEN ); - set16_fx( npulses, 0, MAX_PVQ_BANDS ); - - bin_th = HVQ_THRES_BIN_32k; - move16(); - bin_th2 = HVQ_THRES_BIN_32k / HVQ_NF_GROUPS; - move16(); - /* Set bit-rate dependent variables */ - IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) + /* Divide vect_in[] by peak_gain to yield x[]. */ + expPeakGain = norm_l( *peak_gain ); /* exponent */ + manPeakGain = extract_h( L_shl( *peak_gain, expPeakGain ) ); /* mantissa */ + manPeakGain = abs_s( manPeakGain ); /* Prepare for div_s() only accepting +ve. */ + FOR( i = 0; i < 4; i++ ) { - bin_th = HVQ_THRES_BIN_24k; - move16(); - bin_th2 = HVQ_THRES_BIN_24k / HVQ_NF_GROUPS; + indx = hvq_index_mapping_fx[i]; move16(); - } + vectIn = L_add( vect_in[indx], 0 ); + expIn = norm_l( vectIn ); /* exponent */ + expIn = sub( expIn, 1 ); + expIn = s_min( expIn, expPeakGain ); /* highest Q is Q15 */ + manIn = extract_h( L_shl( vectIn, expIn ) ); /* mantissa */ + manIn = abs_s( manIn ); /* Prepare for div_s() only accepting +ve. */ - FOR( i = 0; i < bin_th; i++ ) - { - pos_vec[i] = 0; + x[i] = div_s( manIn, manPeakGain ); /* in Q(15+expIn-expPeakGain) */ move16(); - } - - /* Quantize noise floor gains */ - FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) - { - logqnorm_fx( &nf_gains[i], 12, &indx, 32, 1, 0 ); - - /* De-quantization */ - acc = dicn_fx[indx]; /* Q14 */ - move32(); - nf_gains[i] = L_shr( acc, 1 + 2 ); /* nf_gains in Q12. dicn_fx is in Q14. Need extra shift +2. */ - move32(); - push_indice( hBstr, IND_HVQ_NF_GAIN, indx, 5 ); - bits = add( bits, 5 ); - } - - /* Signal number of peaks */ - i = sub( max_peaks, vq_peaks ); - push_indice( hBstr, IND_NUM_PEAKS, i, 5 ); - bits = add( bits, 5 ); - - /* Identify position of first peak and arrange peak gains by position */ - pVqPeakIdx = &vq_peak_idx[0]; - low_peak_bin = bin_th; - FOR( i = 0; i < vq_peaks; i++ ) - { - indx = *pVqPeakIdx++; + Qx_vec[i] = add( 15, sub( expIn, expPeakGain ) ); move16(); - IF( LT_16( indx, low_peak_bin ) ) + Qx = s_min( Qx, Qx_vec[i] ); + + /* Restore the sign destroyed by abs operations. */ + IF( L_xor( vectIn, *peak_gain ) < 0 ) /* Check the sign bits (MSB). */ { - low_peak_bin = indx; + x[i] = negate( x[i] ); move16(); } - /* Store the sign information. */ - IF( coefs[indx] < 0 ) + } + FOR( i = 0; i < 4; i++ ) + { + IF( NE_16( Qx_vec[i], Qx ) ) { - pos_vec[indx] = -1; /* Negative. */ + x[i] = shr( x[i], sub( Qx_vec[i], Qx ) ); /* Qx */ move16(); } - ELSE + } + absPeakGain = L_abs( peak_gain[0] ); + IF( vect_out[0] != 0 ) + { + absPeakGain1 = L_abs( peak_gain[-1] ); + IF( GT_32( absPeakGain1, absPeakGain ) ) { - pos_vec[indx] = 1; /* Positive */ + weights[0] = 0; move16(); + if ( vect_out[1] != 0 ) + { + weights[1] = 0; + move16(); + } } } - - pPeakGains = &peak_gains[0]; - pVqPeakIdx = &vq_peak_idx[0]; - pPosVec = &pos_vec[0]; - pCoefs = &coefs[0]; - FOR( i = 0; i < bin_th; i++ ) + IF( overlap > 0 ) { - acc = *pCoefs++; - IF( *pPosVec++ != 0 ) + absPeakGain1 = L_abs( peak_gain[1] ); + IF( GT_32( absPeakGain1, absPeakGain ) ) { - *pPeakGains++ = L_abs( acc ); /* in Q12 */ - move32(); - *pVqPeakIdx++ = i; - move16(); + indx = sub( 4, overlap ); + pWeights = &weights[indx]; + FOR( i = 0; i < overlap; i++ ) + { + *pWeights++ = 0; + move16(); + } } } - /* Scale down peak gains */ - /* Divided by 4 is equivalent to consider peak_gains to be in Q14 from Q12. - * No physical bit shift is actually required. - */ - - /* Quantize peak gains */ - pPeakGains = &peak_gains[0]; - pPgainCbIdx = &pgain_cb_idx[0]; - logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 32, 1, 1 ); - vqPeaksMinus1 = sub( vq_peaks, 1 ); - FOR( i = 0; i < vqPeaksMinus1; i++ ) + /* Classify */ + cb_class = w_vquant_fx( x, Qx, weights, 0, hvq_class_c_fx, HVQ_NUM_CLASS, 0 ); + IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) + { + indx = s_max( 0, sub( HVQ_MAX_PEAKS_24k, Npeaks ) ); + search_overlap = hvq_cb_search_overlap24k[indx]; + move16(); + } + ELSE { - logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 45, 1, 1 ); + indx = s_max( 0, sub( HVQ_MAX_PEAKS_32k, Npeaks ) ); + search_overlap = hvq_cb_search_overlap32k[indx]; + move16(); } - /* Code quantized peak gain indices - * and also scale up peak gains. */ - diffcod_fx( vq_peaks, pgain_cb_idx, &pgain_difidx[1] ); - /* Accumulate peak energy. */ - manE_peak = L_deposit_l( 0 ); - expE_peak = 32; - move16(); - FOR( i = 0; i < vq_peaks; i++ ) + /* Quantize */ + cbSize = add( HVQ_CB_SIZE / 2, search_overlap ); + IF( cb_class == 0 ) { - indx = pgain_cb_idx[i]; - move16(); - /* Scale up peak gains */ - pgain_q[i] = L_shl( dicn_pg_fx[indx], 2 ); /* pgain_q in Q12 */ - move32(); - /* Use floating point operation to deal with wide dynamic range.l - * 32-bit mantissa is used here. It should be even more accurate than - * the floating-point reference code with 24-bit mantissa! */ - expPeakGains = norm_l( pgain_q[i] ); - manPeakGains = L_shl( pgain_q[i], expPeakGains ); - Mpy_32_32_ss( manPeakGains, manPeakGains, &manPkEnrg, &lsb ); /* peak_gains square */ - expPkEnrg = shl( expPeakGains, 1 ); /* Multiply by 2 due to squaring. */ - /* True floating value = manPkEng x 2^(32 - 1 - expPkEnrg - 2*12). - * In this context, the 32-bit manPkEng is in Q0. - * 32 is due to Mpy_32_32() only providing the 32 MSBs of the 64 bits product. - * -1 is due fractional mode Multiply. 2*12 is due to square of Q12. */ - floating_point_add( &manE_peak, &expE_peak, manPkEnrg, expPkEnrg ); - } - pgain_difidx[0] = pgain_cb_idx[0]; - move16(); - - /* Huffman coding */ - hcode_l = 0; - move16(); - pPgainDifIdx = &pgain_difidx[1]; - FOR( i = 0; i < vqPeaksMinus1; i++ ) - { - indx = *pPgainDifIdx++; - move16(); - hcode_l = add( hcode_l, pgain_huffsizn[indx] ); - } - - FlagN = HUFCODE; - move16(); - - tmp16 = extract_l( L_mult0( GAINI_BITS, vqPeaksMinus1 ) ); - IF( GE_16( hcode_l, tmp16 ) ) - { - hcode_l = tmp16; - move16(); - FlagN = NOHUFCODE; - move16(); - } - - push_indice( hBstr, IND_FLAGN, FlagN, 1 ); - push_indice( hBstr, IND_PG_IDX, pgain_difidx[0], GAIN0_BITS ); - - IF( FlagN ) - { - pPgainDifIdx = &pgain_difidx[1]; - FOR( i = 0; i < vqPeaksMinus1; i++ ) - { - j = *pPgainDifIdx++; - move16(); - m = pgain_huffnorm[j]; - move16(); - r = pgain_huffsizn[j]; - move16(); - - push_indice( hBstr, IND_PG_IDX, m, r ); - } - } - ELSE - { - pPgainDifIdx = &pgain_difidx[1]; - FOR( i = 0; i < vqPeaksMinus1; i++ ) - { - push_indice( hBstr, IND_PG_IDX, ( *pPgainDifIdx++ ), GAINI_BITS ); - } - } - - /* Number of bits used for peak gain quantization */ - bits = add( bits, add( FLAGN_BITS + GAIN0_BITS, hcode_l ) ); - - /* Add sign for peak shape normalization */ - FOR( i = 0; i < vq_peaks; i++ ) - { - indx = vq_peak_idx[i]; - move16(); - peak_gains[i] = pgain_q[i]; /* Q12 */ - move32(); - IF( pos_vec[indx] < 0 ) - { - peak_gains[i] = L_negate( peak_gains[i] ); /* Q12 */ - move32(); - } - } - - /* Quantize peak shapes */ - FOR( i = 0; i < vqPeaksMinus1; i++ ) - { - num_overlap_bins = sub( 5, sub( vq_peak_idx[i + 1], vq_peak_idx[i] ) ); - indx = sub( vq_peak_idx[i], 2 ); - quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks ); - push_indice( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); - bits = add( bits, 9 ); - } - - indx = sub( vq_peak_idx[i], 2 ); - quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks ); - push_indice( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); - bits = add( bits, 9 ); - - /* Quantize peak positions and sign with HVQ */ - pos_bits = hvq_code_pos_fx( hBstr, pos_vec, bin_th, vq_peaks ); - - bits = add( bits, pos_bits ); - bit_budget = sub( num_bits, bits ); - - /* Calculate number of PVQ bands to code and assign bits */ - pvq_bands = hvq_pvq_bitalloc_fx( bit_budget, core_brate, bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, &n_sel_bnds ); - - /* Get band limits for concatenated PVQ target */ - hvq_concat_bands_fx( pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, hvq_band_width, hvq_band_end ); - - /* Quantize PVQ bands */ - pCoefsOut = coefs_out; - pCoefs = coefs; - pPvqVector = pvq_vector; - pSelBnds = sel_bnds; - m = bin_th; - move16(); - FOR( k = 0; k < pvq_bands; k++ ) - { - IF( GE_16( k, sub( pvq_bands, n_sel_bnds ) ) ) - { - i = band_start_harm[*pSelBnds++]; - move16(); - pCoefs = coefs + i; - pCoefsOut = coefs_out + i; - } - k_sort[k] = k; - move16(); - j = 0; - move16(); - pPvqVectorBandStart = pPvqVector; - WHILE( LT_16( j, hvq_band_width[k] ) ) - { - IF( *pCoefsOut++ == 0 ) - { - *pPvqVector++ = *pCoefs; /* Q12 */ - move32(); - j = add( j, 1 ); - } - pCoefs++; - } - logqnorm_fx( pPvqVectorBandStart, 12, &pvq_norm[k], 40, hvq_band_width[k], 0 ); - } - - /* Normalize coefficients */ - normalizecoefs_fx( pvq_vector, pvq_norm, pvq_bands, hvq_band_start, hvq_band_end, pvq_vector_norm ); - Q_coefs = 12; - move16(); - - bit_budget = sub( bit_budget, i_mult2( HVQ_PVQ_GAIN_BITS, pvq_bands ) ); - - pvq_bits = bit_budget; - move16(); - set16_fx( npulses, 0, MAX_PVQ_BANDS ); - - pvq_encode_frame_fx( hBstr, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, - Rk, pvq_bits, HQ_CORE ); - - FOR( i = 0; i < pvq_bands; i++ ) - { - k_sort[i] = i; - move16(); - } - - fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, NULL, NULL, pvq_bands, coefs_pvq, - pvq_inp_vector, fg_pred, HQ_CORE ); - - pCoefsOut = &coefs_out[0]; - pSelBnds = &sel_bnds[0]; - pCoefsPvq = &coefs_pvq[0]; - FOR( k = 0; k < pvq_bands; k++ ) - { - indx = pvq_norm[k]; - move16(); - tmp1 = ratio( gopt[k], fg_pred[k], &exp1 ); - tmp1 = shr( tmp1, sub( 1, exp1 ) ); /* Q13 */ - Mpy_32_16_ss( dicn_fx[indx], tmp1, &normq, &dontCare16 ); /* dicn_fx in Q14, sorted_pvq_gain_pred_err_fx in Q13. */ - - logqnorm_fx( &normq, 12, &pvq_norm[k], 40, 1, 0 ); /* normq in Q(14+(16+13)+1-32)=Q12 */ - pvq_norm[k] = sub( pvq_norm[k], 8 ); - move16(); - IF( pvq_norm[k] < 0 ) - { - pvq_norm[k] = 0; - move16(); - } - - push_indice( hBstr, IND_HVQ_PVQ_GAIN, pvq_norm[k], HVQ_PVQ_GAIN_BITS ); - pvq_bits = add( pvq_bits, HVQ_PVQ_GAIN_BITS ); - - pvq_norm[k] = add( pvq_norm[k], 8 ); - move16(); - indx = pvq_norm[k]; - move16(); - normq = L_add( dicn_fx[indx], 0 ); /* in Q14 */ - j = 0; - move16(); - IF( GE_16( k, sub( pvq_bands, n_sel_bnds ) ) ) - { - i = band_start_harm[*pSelBnds++]; - move16(); - pCoefsOut = coefs_out + i; - } - WHILE( LT_16( j, hvq_band_width[k] ) ) - { - IF( EQ_32( *pCoefsOut, 0 ) ) - { - acc = L_mult( *pCoefsPvq++, fg_pred[k] ); /* in Q(15 + 1 + 12 = 28) */ - tmp16 = extract_h( acc ); /* in Q(28 - 16 = 12) */ - Mpy_32_16_ss( normq, tmp16, &acc, &dontCare16 ); /* acc(Q11), normq(Q14), tmp16(Q12) */ - *pCoefsOut = L_shl( acc, 12 - 11 ); /* Q12 */ - move32(); - j = add( j, 1 ); - } - pCoefsOut++; - } - } - bits = add( bits, pvq_bits ); - - /* Noise fill unqantized coeffs with one gain per group */ - pCoefsOut = &coefs_out[-1]; - FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) - { - FOR( j = 0; j < bin_th2; j++ ) - { - IF( *( ++pCoefsOut ) == 0 ) - { - whiteNoise = Random( &nf_seed ); /* Q15 */ - Mpy_32_16_ss( nf_gains[i], whiteNoise, pCoefsOut, &dontCare16 ); /* nf_gains in Q12. *pCoefsOut in Q12 */ - } - } - } - - return bits; -} -#endif - -/*-------------------------------------------------------------------------- - * quant_peaks_fx() - * - * Applies VQ on input vector - *--------------------------------------------------------------------------*/ - -#ifdef HARM_HQ_CORE -static void quant_peaks_fx( -#else -static void quant_peaks_ivas_fx( -#endif - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle*/ - const Word32 *vect_in, /* i : Target vector in Q12 */ - Word32 *vect_out, /* i/o: Quantized vector in Q12 */ - const Word32 *peak_gain, /* i : Peak gain vector in Q12 */ - Word16 *vq_idx, /* o : Codebook index */ - const Word16 overlap, /* i : Overlap indicator */ - const Word32 core_brate, /* i : Core bitrate */ - const Word16 Npeaks /* i : Number of peaks */ -) -{ - Word16 x[4]; /* Qx */ - Word16 xq[4]; /* Q15 */ - Word16 weights[4]; /* Q0 */ - Word16 *pWeights; - Word16 i, cb_class, search_overlap, indx, cbSize; - Word16 expPeakGain, manPeakGain, expIn, manIn; - Word32 vectIn, absPeakGain1, absPeakGain; - UWord16 dontCare; - Word16 Qx_vec[4]; - Word16 Qx = 15; - move16(); - set16_fx( weights, 1, 4 ); - - /* Divide vect_in[] by peak_gain to yield x[]. */ - expPeakGain = norm_l( *peak_gain ); /* exponent */ - manPeakGain = extract_h( L_shl( *peak_gain, expPeakGain ) ); /* mantissa */ - manPeakGain = abs_s( manPeakGain ); /* Prepare for div_s() only accepting +ve. */ - FOR( i = 0; i < 4; i++ ) - { - indx = hvq_index_mapping_fx[i]; - move16(); - vectIn = L_add( vect_in[indx], 0 ); - expIn = norm_l( vectIn ); /* exponent */ - expIn = sub( expIn, 1 ); - expIn = s_min( expIn, expPeakGain ); /* highest Q is Q15 */ - manIn = extract_h( L_shl( vectIn, expIn ) ); /* mantissa */ - manIn = abs_s( manIn ); /* Prepare for div_s() only accepting +ve. */ - - x[i] = div_s( manIn, manPeakGain ); /* in Q(15+expIn-expPeakGain) */ - move16(); - Qx_vec[i] = add( 15, sub( expIn, expPeakGain ) ); - move16(); - Qx = s_min( Qx, Qx_vec[i] ); - - /* Restore the sign destroyed by abs operations. */ - IF( L_xor( vectIn, *peak_gain ) < 0 ) /* Check the sign bits (MSB). */ - { - x[i] = negate( x[i] ); - move16(); - } - } - FOR( i = 0; i < 4; i++ ) - { - IF( NE_16( Qx_vec[i], Qx ) ) - { - x[i] = shr( x[i], sub( Qx_vec[i], Qx ) ); /* Qx */ - move16(); - } - } - absPeakGain = L_abs( peak_gain[0] ); - IF( vect_out[0] != 0 ) - { - absPeakGain1 = L_abs( peak_gain[-1] ); - IF( GT_32( absPeakGain1, absPeakGain ) ) - { - weights[0] = 0; - move16(); - if ( vect_out[1] != 0 ) - { - weights[1] = 0; - move16(); - } - } - } - IF( overlap > 0 ) - { - absPeakGain1 = L_abs( peak_gain[1] ); - IF( GT_32( absPeakGain1, absPeakGain ) ) - { - indx = sub( 4, overlap ); - pWeights = &weights[indx]; - FOR( i = 0; i < overlap; i++ ) - { - *pWeights++ = 0; - move16(); - } - } - } - - /* Classify */ - cb_class = w_vquant_fx( x, Qx, weights, 0, hvq_class_c_fx, HVQ_NUM_CLASS, 0 ); - IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) - { - indx = s_max( 0, sub( HVQ_MAX_PEAKS_24k, Npeaks ) ); - search_overlap = hvq_cb_search_overlap24k[indx]; - move16(); - } - ELSE - { - indx = s_max( 0, sub( HVQ_MAX_PEAKS_32k, Npeaks ) ); - search_overlap = hvq_cb_search_overlap32k[indx]; - move16(); - } - - /* Quantize */ - cbSize = add( HVQ_CB_SIZE / 2, search_overlap ); - IF( cb_class == 0 ) - { - *vq_idx = w_vquant_fx( x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 0 ); - move16(); - push_indice( hBstr, IND_HVQ_PEAKS, 0, 1 ); - } - ELSE IF( EQ_16( cb_class, 1 ) ) - { - indx = sub( HVQ_CB_SIZE * 2, shl( search_overlap, 2 ) ); - *vq_idx = w_vquant_fx( x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 0 ); - move16(); - *vq_idx = add( *vq_idx, sub( HVQ_CB_SIZE / 2, search_overlap ) ); - move16(); - push_indice( hBstr, IND_HVQ_PEAKS, 0, 1 ); - } - ELSE IF( EQ_16( cb_class, 2 ) ) - { - indx = sub( HVQ_CB_SIZE * 2, shl( search_overlap, 2 ) ); - *vq_idx = w_vquant_fx( x, Qx, weights, xq, &hvq_peak_cb_fx[indx], cbSize, 1 ); - move16(); - *vq_idx = add( *vq_idx, sub( HVQ_CB_SIZE / 2, search_overlap ) ); - move16(); - push_indice( hBstr, IND_HVQ_PEAKS, 1, 1 ); - } - ELSE - { - *vq_idx = w_vquant_fx( x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 1 ); - move16(); - push_indice( hBstr, IND_HVQ_PEAKS, 1, 1 ); - } - - FOR( i = 0; i < 4; i++ ) - { - indx = hvq_index_mapping_fx[i]; - move16(); - IF( weights[i] != 0 ) - { - Mpy_32_16_ss( *peak_gain, xq[i], &vect_out[indx], &dontCare ); /* peak_gains in Q12, xq in Q15 -> Q12. */ - move32(); - } - } - vect_out[2] = *peak_gain; - move32(); /* vect_out in Q12 */ - - return; -} - -#ifndef HARM_HQ_CORE -static void quant_peaks_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word32 *vect_in, /* i : Target vector in Q12 */ - Word32 *vect_out, /* i/o: Quantized vector in Q12 */ - const Word32 *peak_gain, /* i : Peak gain vector in Q12 */ - Word16 *vq_idx, /* o : Codebook index */ - const Word16 overlap, /* i : Overlap indicator */ - const Word32 core_brate, /* i : Core bitrate */ - const Word16 Npeaks /* i : Number of peaks */ -) -{ - Word16 x[4]; /* Qx */ - Word16 xq[4]; /* Q15 */ - Word16 weights[4]; /* Q0 */ - Word16 *pWeights; - Word16 i, cb_class, search_overlap, indx, cbSize; - Word16 expPeakGain, manPeakGain, expIn, manIn; - Word32 vectIn, absPeakGain1, absPeakGain; - UWord16 dontCare; - Word16 Qx_vec[4]; - Word16 Qx = 15; - - set16_fx( weights, 1, 4 ); - - /* Divide vect_in[] by peak_gain to yield x[]. */ - expPeakGain = norm_l( *peak_gain ); /* exponent */ - manPeakGain = extract_h( L_shl( *peak_gain, expPeakGain ) ); /* mantissa */ - manPeakGain = abs_s( manPeakGain ); /* Prepare for div_s() only accepting +ve. */ - FOR( i = 0; i < 4; i++ ) - { - indx = hvq_index_mapping_fx[i]; - move16(); - vectIn = L_add( vect_in[indx], 0 ); - expIn = norm_l( vectIn ); /* exponent */ - expIn = sub( expIn, 1 ); - expIn = s_min( expIn, expPeakGain ); /* highest Q is Q15 */ - manIn = extract_h( L_shl( vectIn, expIn ) ); /* mantissa */ - manIn = abs_s( manIn ); /* Prepare for div_s() only accepting +ve. */ - - x[i] = div_s( manIn, manPeakGain ); /* in Q(15+expIn-expPeakGain) */ - - Qx_vec[i] = add( 15, sub( expIn, expPeakGain ) ); - move16(); - Qx = s_min( Qx, Qx_vec[i] ); - - /* Restore the sign destroyed by abs operations. */ - if ( L_xor( vectIn, *peak_gain ) < 0 ) /* Check the sign bits (MSB). */ - { - x[i] = negate( x[i] ); - move16(); - } - } - FOR( i = 0; i < 4; i++ ) - { - IF( NE_16( Qx_vec[i], Qx ) ) - { - x[i] = shr( x[i], sub( Qx_vec[i], Qx ) ); /* Qx */ - move16(); - } - } - absPeakGain = L_abs( peak_gain[0] ); - IF( vect_out[0] != 0 ) - { - absPeakGain1 = L_abs( peak_gain[-1] ); - IF( GT_32( absPeakGain1, absPeakGain ) ) - { - weights[0] = 0; - move16(); - if ( vect_out[1] != 0 ) - { - weights[1] = 0; - move16(); - } - } - } - IF( overlap > 0 ) - { - absPeakGain1 = L_abs( peak_gain[1] ); - IF( GT_32( absPeakGain1, absPeakGain ) ) - { - indx = sub( 4, overlap ); - pWeights = &weights[indx]; - FOR( i = 0; i < overlap; i++ ) - { - *pWeights++ = 0; - move16(); - } - } - } - - /* Classify */ -#if HVQ_VQ_DIM != 5 -#error w_vquant_fx() is hard-wired to dim = 4 = (HVQ_VQ_DIM - 1). -#endif - cb_class = w_vquant_fx( x, Qx, weights, 0, hvq_class_c_fx, HVQ_NUM_CLASS, 0 ); - IF( LT_32( core_brate, HQ_BWE_CROSSOVER_BRATE ) ) - { - indx = sub( HVQ_MAX_PEAKS_24k, Npeaks ); - search_overlap = hvq_cb_search_overlap24k[indx]; - move16(); - } - ELSE - { - indx = sub( HVQ_MAX_PEAKS_32k, Npeaks ); - search_overlap = hvq_cb_search_overlap32k[indx]; - move16(); - } - - /* Quantize */ - cbSize = add( HVQ_CB_SIZE / 2, search_overlap ); - IF( cb_class == 0 ) - { - *vq_idx = w_vquant_fx( x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 0 ); + *vq_idx = w_vquant_fx( x, Qx, weights, xq, hvq_peak_cb_fx, cbSize, 0 ); move16(); push_indice( hBstr, IND_HVQ_PEAKS, 0, 1 ); } @@ -1268,7 +641,7 @@ static void quant_peaks_fx( return; } -#endif + /*-------------------------------------------------------------------------- * code_pos() @@ -1352,119 +725,6 @@ static Word16 sparse_code_pos_fx( * * Code pulse positions *--------------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE -static Word16 hvq_code_pos_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *inp, - const Word16 length, - const Word16 num_peaks ) -{ - Word16 sparse_result[4 * HVQ_THRES_BIN_32k / HVQ_CP_L1_LEN]; - Word16 delta[HVQ_MAX_PEAKS]; - Word16 peak_idx[HVQ_MAX_PEAKS]; - Word16 inp_abs[HVQ_THRES_BIN_32k]; - Word16 inp_sign[HVQ_MAX_PEAKS]; - - Word16 i, j; - Word16 bits; - Word16 delta_max; - Word16 delta_bits, sparse_bits; - Word16 tmp; - - bits = 0; - move16(); - - /* Extract sorted peak index vector and sign vector */ - j = 0; - move16(); - FOR( i = 0; i < length; i++ ) - { - inp_abs[i] = abs_s( inp[i] ); - move16(); - IF( inp[i] != 0 ) - { - peak_idx[j] = i; - move16(); - inp_sign[j] = inp[i]; - move16(); - j = add( j, 1 ); - } - } - - /* Calculate delta */ - delta[0] = add( peak_idx[0], HVQ_CP_HUFF_OFFSET ); - move16(); - delta_max = delta[0]; - move16(); - FOR( i = 1; i < num_peaks; i++ ) - { - delta[i] = sub( sub( peak_idx[i], peak_idx[i - 1] ), HVQ_CP_HUFF_OFFSET ); - move16(); - if ( LT_16( delta_max, delta[i] ) ) - { - delta_max = delta[i]; - move16(); - } - } - - /* Calculate bits needed for huffman coding of deltas */ - delta_bits = -1; - move16(); - IF( LE_16( delta_max, HVQ_CP_HUFF_MAX ) ) - { - delta_bits = 0; - move16(); - FOR( i = 0; i < num_peaks; i++ ) - { - delta_bits = add( delta_bits, hvq_cp_huff_len[delta[i]] ); - } - } - - /* Calculate bits neeed for sparse coding */ - sparse_bits = sparse_code_pos_fx( inp_abs, length, sparse_result ); - - /* Decide which coding mode to use */ - test(); - IF( GT_16( delta_bits, sparse_bits ) || delta_bits < 0 ) - { - push_indice( hBstr, IND_POS_IDX, HVQ_CP_SPARSE, 1 ); - - FOR( i = 0; i < sparse_bits; i++ ) - { - push_indice( hBstr, IND_POS_IDX, sparse_result[i], 1 ); - } - bits = add( add( bits, sparse_bits ), 1 ); - } - ELSE - { - push_indice( hBstr, IND_POS_IDX, HVQ_CP_DELTA, 1 ); - - FOR( i = 0; i < num_peaks; i++ ) - { - j = delta[i]; - move16(); - push_indice( hBstr, IND_POS_IDX, hvq_cp_huff_val[j], hvq_cp_huff_len[j] ); - } - bits = add( add( bits, delta_bits ), 1 ); - } - - /* Send sign */ - FOR( i = 0; i < num_peaks; i++ ) - { - tmp = 1; - move16(); - if ( inp_sign[i] < 0 ) - { - tmp = 0; - move16(); - } - push_indice( hBstr, IND_POS_IDX, tmp, 1 ); - } - bits = add( bits, num_peaks ); - - return bits; -} -#endif static Word16 hvq_code_pos_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 3f68ddb54..cdddb769c 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -819,29 +819,6 @@ Word16 peak_avrg_ratio_fx( Word16 *mode_count1, /* i/o: HQ_NORMAL mode count Q0*/ Word16 Q_coeff ); -#ifndef HARM_HQ_CORE -Word16 peak_avrg_ratio_ivas_fx( - const Word32 total_brate, /* Q0 */ - const Word32 *input_hi_fx, /* i : i signal Q_coeff*/ - const Word16 length, /* i : number of coefficients Q0*/ - Word16 *mode_count, /* i/o: HQ_HARMONIC mode count Q0*/ - Word16 *mode_count1, /* i/o: HQ_NORMAL mode count Q0*/ - Word16 Q_coeff ); - -void hvq_classifier_ivas_fx( - const Word32 *input, /* i : input signal Q12 */ - Word16 *prev_Npeaks, /* i/o: Peak number memory Q0 */ - Word16 *prev_peaks, /* i/o: Peak indices memory Q0 */ - Word16 *hqswb_clas, /* i/o: HQ class Q0 */ - Word16 *Npeaks, /* o : Number of peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - const Word32 L_core_brate, /* i : Core bit-rate Q0 */ - const Word16 last_core, /* i : Last core used Q0 */ - Word32 *L_nf_gains, /* o : Noisefloor gains Q12 */ - Word16 *hvq_hangover, /* i/o: Mode-switch hangover Q0 */ - Word32 *L_pe_gains /* o : peak gains Q12 */ -); -#endif void pit16k_Q_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 nBits, /* i : # of Q bits */ @@ -3603,9 +3580,7 @@ Word16 Pit_exc_contribution_len_fx( Word16 Qnew ); Word16 pvq_core_enc_fx( -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ Word16 coefs_quant[], /* o : quantized coefficients */ @@ -3622,24 +3597,6 @@ Word16 pvq_core_enc_fx( const Word16 core /* i : number of bands */ ); -#ifndef HARM_HQ_CORE -Word16 pvq_core_enc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ - Word16 coefs_quant[], /* o : quantized coefficients */ - Word16 *Q_coefs, - const Word16 bits_tot, /* i : total number of bits */ - const Word16 nb_sfm, /* i : number of bands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : subband width */ - Word16 *R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *Rs, /* i/o: Integer bit allocation */ - Word16 *npulses, /* o : number of pulses */ - Word16 *maxpulse, /* i : maximum pulse per band */ - const Word16 core /* i : number of bands */ -); -#endif void core_switching_hq_prepare_enc_fx( Encoder_State *st_fx, /* i/o: encoder state structure */ Word16 *num_bits, /* i/o: bit budget update Q0*/ @@ -3656,17 +3613,6 @@ void hq_lr_enc_fx( ); void hq_hr_enc_fx( -#ifndef HARM_HQ_CORE - Encoder_State *st_fx, /* i/o: encoder state structure fx */ - Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ - const Word16 length, /* i : length of spectrum Q0 */ - Word16 *num_bits, /* i : number of available bits Q0 */ - const Word16 is_transient, /* i : transient flag Q0 */ - const Word16 vad_hover_flag /* i : VAD hangover flag Q0 */ -); - -void hq_hr_enc_ivas_fx( -#endif Encoder_State *st_fx, /* i/o: encoder state structure fx */ Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ const Word16 length, /* i : length of spectrum Q0 */ @@ -3702,20 +3648,6 @@ Word16 hq_classifier_enc_fx( Word16 *hqswb_clas /* o : HQ class Q0 */ ); -#ifndef HARM_HQ_CORE -/* o : Consumed bits Q0 */ -Word16 hq_classifier_enc_ivas_fx( - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 length, /* i : Frame length Q0 */ - const Word32 *coefs, /* i : Spectral coefficients Q12 */ - const Word16 is_transient, /* i : Transient flag Q0 */ - Word16 *Npeaks, /* o : Number of identified peaks Q0 */ - Word16 *peaks, /* o : Peak indices Q0 */ - Word32 *pe_gains, /* o : Peak gains Q12 */ - Word32 *nf_gains, /* o : Noise-fill gains Q12 */ - Word16 *hqswb_clas /* o : HQ class Q0 */ -); -#endif void diff_envelope_coding_fx( const Word16 is_transient, /* i : transient indicator Q0 */ const Word16 num_env_bands, /* i : number of envelope bands to code Q0 */ @@ -3725,27 +3657,6 @@ void diff_envelope_coding_fx( Word16 *difidx /* o : differential code Q0 */ ); -#ifndef HARM_HQ_CORE -/* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ -Word16 encode_envelope_indices_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream Q0 */ - const Word16 num_sfm, /* i : Number of subbands Q0 */ - const Word16 numnrmibits, /* i : Bitrate of fall-back coding mode Q0 */ - Word16 *difidx, /* i/o: Diff indices/encoded diff indices Q0 */ - Word16 *LCmode, /* o : Coding mode if flag_pack=0, i : if flag_pack=1 Q0 */ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0 */ - const Word16 flag_HQ2, /* i : indicator of HQ2 core Q0 */ - const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ -); - -void hq_generic_encoding_fx( - const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ - Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope */ - const Word16 hq_generic_offset, /* i : frequency offset for extracting energy */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *hq_generic_exc_clas /* o : bwe excitation class */ -); -#endif void normalizecoefs_fx( Word32 *coefs, /* i : Input vector (Q12) */ const Word16 *ynrm, /* i : quantization indices for norms */ @@ -3771,40 +3682,6 @@ Word16 hvq_enc_fx( Word32 *coefs_out /* o : encoded spectrum coefficients in Q14 */ ); -#ifndef HARM_HQ_CORE -/* o : Consumed bits */ -Word16 hvq_enc_ivas_fx( - Encoder_State *st_fx, /*i/o: encoder state structure */ - const Word32 core_brate, /*i : Total bit rate */ - const Word16 hvq_bits, /*i : HVQ bit budget */ - const Word16 Npeaks, /*i : Number of peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *peaks, /* i : Peak pos. / Encoded peak pos. */ - Word32 *nf_gains, /* i/o: Noise fill gains / Quant. nf gains Q12 */ - Word16 *noise_level, /* o : Quantized noise level Q15 */ - const Word32 *pe_gains, /* i : Peak gains */ - const Word32 *coefs, /* i : spectrum coefficients in Q12 */ - Word32 *coefs_out /* o : encoded spectrum coefficients in Q12 */ -); - -Word16 pvq_core_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ - Word16 coefs_quant[], /* o : quantized coefficients */ - Word16 *Q_coefs, - const Word16 bits_tot, /* i : total number of bits */ - const Word16 nb_sfm, /* i : number of bands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : subband width */ - Word16 *R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *Rs, /* i/o: Integer bit allocation */ - Word16 *npulses, /* o : number of pulses */ - Word16 *maxpulse, /* i : maximum pulse per band */ - const Word16 core /* i : number of bands */ -); -#endif /* o : index of noise attenuation Q0 */ Word16 noise_adjust_fx( const Word16 *coeffs_norm, /* i : normalized coefficients Qx */ @@ -3855,25 +3732,8 @@ void diffcod_lrmdct_fx( const Word16 is_transient /* i : transient flag Q0*/ ); -#ifndef HARM_HQ_CORE -Word16 peak_vq_enc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 *coefs, /* i : Input coefficient vector Q12 */ - Word32 *coefs_out, /* o : Quantized output vector Q12 */ - const Word32 core_brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* i : Peak index vector */ - Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ -); -#endif Word16 peak_vq_enc_fx( -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 bwidth, /* i : audio bandwidth */ const Word32 *coefs, /* i : Input coefficient vector Q12 */ @@ -4062,24 +3922,6 @@ void pvq_encode_frame_fx( const Word16 core /* i : core */ ); -#ifndef HARM_HQ_CORE -void pvq_encode_frame_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *coefs_norm, /* i : normalized coefficients to encode */ - Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *gopt, /* o : optimal shape gains */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band Q3 */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ -); -#endif /*Qx o : interpolated value */ Word16 Interpol_4( Word16 *x, /*Qx i : i vector */ @@ -4111,19 +3953,6 @@ void pvq_encode_fx( const Word16 neg_gain /* i : Gain use - negative gain in Q15 0 ..1 */ ); -#ifndef HARM_HQ_CORE -void pvq_encode_ivas_fx( - BSTR_ENC_HANDLE hBstr, - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 *x, /* i : vector to quantize Q15-3=>Q12 */ - Word16 *y, /* o : raw pulses (non-scaled short) Q0 */ - Word16 *xq, /* o : quantized vector Q15 */ - Word32 *L_xq, /* o : quantized vector Q31 */ - const Word16 pulses, /* i : number of allocated pulses */ - const Word16 dim, /* i : Length of vector */ - const Word16 neg_gain /* i : Gain use - negative gain in Q15 0 ..1 */ -); -#endif void rc_enc_init_fx( PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ Word16 tot_bits /* i : Total bit budget Q0*/ diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index c75798e5d..da8247321 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -16,23 +16,8 @@ *--------------------------------------------------------------------*/ static Word16 calc_pvq_splits_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 band_bits, const Word16 sfmsize, const Word16 *y, const Word16 Q_y, Word16 *bits ); -#ifndef HARM_HQ_CORE -static Word16 calc_pvq_splits_ivas_fx( /* o : Number of segments */ - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 band_bits, /* i : Band bit rate */ - const Word16 sfmsize, /* i : Band width */ - const Word16 *y, /* i : Target vector */ - const Word16 Q_y, /* i : Q point of y */ - Word16 *bits /* o : Consumed bits */ -); -static void densityIndexSymbolEncode_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 density, const Word16 r_dim, const Word16 l_dim, const Word16 index_phi ); -#endif static void densityIndexSymbolEncode_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 density, const Word16 r_dim, const Word16 l_dim, const Word16 index_phi ); static void encode_energies_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 *coefs, const Word16 Q_coefs, Word16 Np, Word16 *dim_part, Word32 *E_part, Word16 *bits_part, Word16 *g_part, Word16 qband, Word16 *bits_left, Word32 enr, Word16 dim, const Word16 strict_bits ); -#ifndef HARM_HQ_CORE -static void encode_energies_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, const Word16 *coefs, const Word16 Q_coefs, Word16 Np, Word16 *dim_part, Word32 *E_part, Word16 *bits_part, Word16 *g_part, Word16 qband, Word16 *bits_left, Word32 enr, Word16 dim, const Word16 strict_bits ); -#endif /*-------------------------------------------------------------------* @@ -41,111 +26,6 @@ static void encode_energies_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, * Encode band with PVQ *--------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE -/* Encode band with PVQ */ -static void pvq_encode_band_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 *coefs_norm, /* i : normalized vector to encode */ - const Word16 Q_coefs, - Word16 *pulse_vector, /* o : quantized vector, integer */ - Word16 *npulses, /* o : number of pulses */ - Word16 *coefs_quant, /* o : quantized vector Q=12*/ - const Word16 sfmsize, /* i : length of vector */ - const Word16 band_bits, /* i : assigned bits */ - Word16 *bits_left, /* o : bits remaining */ - const Word16 strict_bits /* i : conservative rounding flag */ -) -{ - Word16 K_val; - Word16 j, Np; - Word32 enr, E_part[MAX_SPLITS + 1]; - Word16 part_start[MAX_SPLITS + 1], dim_part[MAX_SPLITS + 1], bits_part[MAX_SPLITS + 1]; - Word16 pool_tot, pool_part, dim_parts; - Word16 g_part[MAX_SPLITS]; - Word16 g_part_neg[MAX_SPLITS]; - Word16 sg_part[MAX_SPLITS + 1]; - Word16 idx_sort[MAX_SPLITS + 1]; - Word16 js, band_bits_tot, split_bit; - Word16 tmp; - Word32 L_coefs_quant_fx[PVQ_MAX_BAND_SIZE]; - - Np = calc_pvq_splits_ivas_fx( hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit ); - band_bits_tot = sub( band_bits, split_bit ); - - enr = L_deposit_l( 0 ); - FOR( j = 0; j < sfmsize; j++ ) - { - /* This is of paramount importance that the number of bits down-shift here - * MUST BE IDENTICAL to that used to compute "l_enr" in encode_energies_fx(). - * If the number of bits down-shift is changed here, that in encode_energies_fx() - * must be changed to the same amount as well! - */ - tmp = shr( coefs_norm[j], 2 ); - enr = L_mac0( enr, tmp, tmp ); - } - - dim_parts = extract_h( L_mult( negate( sfmsize ), lim_neg_inv_tbl_fx[Np] ) ); - set16_fx( dim_part, dim_parts, sub( Np, 1 ) ); - dim_part[Np - 1] = sub( sfmsize, i_mult2( dim_parts, sub( Np, 1 ) ) ); - move16(); - - part_start[0] = 0; - move16(); - FOR( j = 1; j < Np; j++ ) - { - part_start[j] = add( part_start[j - 1], dim_part[j - 1] ); - move16(); - } - - /* Encode energies */ - set16_fx( g_part_neg, -32768, Np ); /* -1.0 in Q15 */ - IF( GT_16( Np, 1 ) ) - { - encode_energies_ivas_fx( hBstr, hPVQ, coefs_norm, Q_coefs, Np, dim_part, E_part, bits_part, g_part_neg, band_bits_tot, bits_left, enr, sfmsize, strict_bits ); - } - ELSE - { - bits_part[0] = band_bits_tot; - move16(); - } - - pool_tot = 0; /* Word16 */ - move16(); - pool_part = 0; /* Word16 */ - move16(); - - FOR( j = 0; j < Np; j++ ) - { - g_part[j] = negate( g_part_neg[j] ); - move16(); - } - srt_vec_ind16_fx( g_part, sg_part, idx_sort, Np ); - FOR( j = 0; j < Np; j++ ) - { - js = idx_sort[Np - 1 - j]; - move16(); - pool_part = shrtCDivSignedApprox( pool_tot, sub( Np, j ) ); - bits_part[js] = s_max( 0, s_min( add( bits_part[js], pool_part ), 256 ) ); - move16(); - conservativeL1Norm_fx( dim_part[js], bits_part[js], strict_bits, *bits_left, pool_tot, *npulses, /* inputs */ - &K_val, bits_left, &pool_tot, npulses ); /* outputs */ - - IF( K_val > 0 ) - { - pvq_encode_ivas_fx( hBstr, hPVQ, coefs_norm + part_start[js], pulse_vector + part_start[js], - coefs_quant + part_start[js], L_coefs_quant_fx, K_val, dim_part[js], g_part_neg[js] ); - } - ELSE - { - set16_fx( coefs_quant + part_start[js], 0, dim_part[js] ); - set16_fx( pulse_vector + part_start[js], 0, dim_part[js] ); - } - } - - return; -} -#endif static void pvq_encode_band_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -256,11 +136,7 @@ static void pvq_encode_band_fx( * *--------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE void pvq_encode_frame_fx( -#else -void pvq_encode_frame_ivas_fx( -#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *coefs_norm, /* i : normalized coefficients to encode */ Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ @@ -335,21 +211,12 @@ void pvq_encode_frame_ivas_fx( bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, sub( bands_to_code, coded_bands ), sfmsize[is], R[is], bit_pool, /* inputs */ &band_bits, &bits_left, &bit_pool ); -#ifdef HARM_HQ_CORE pvq_encode_band_fx( hBstr, hPVQ, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, &bits_left, strict_bits ); -#else - pvq_encode_band_ivas_fx( hBstr, hPVQ, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], - &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, &bits_left, strict_bits ); -#endif xy_corr = L_deposit_l( 0 ); yy_corr = L_deposit_l( 1 ); -#ifdef HARM_HQ_CORE shift = band_len_ener_shift[band_len_idx[shr( sfmsize[is], 3 )]]; -#else - shift = ivas_band_len_ener_shift[ivas_band_len_idx[shr( sfmsize[is], 3 )]]; -#endif move16(); FOR( j = 0; j < sfmsize[i]; j++ ) { @@ -388,126 +255,6 @@ void pvq_encode_frame_ivas_fx( return; } -#ifndef HARM_HQ_CORE -void pvq_encode_frame_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 *coefs_norm, /* i : normalized coefficients to encode */ - Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ - Word16 *coefs_quant, /* o : quantized coefficients */ - Word16 *gopt, /* o : optimal shape gains */ - Word16 *npulses, /* o : number of pulses per band */ - Word16 *pulse_vector, /* o : non-normalized pulse shapes */ - const Word16 *sfm_start, /* i : indices of first coefficients in the bands */ - const Word16 *sfm_end, /* i : indices of last coefficients in the bands */ - const Word16 *sfmsize, /* i : band sizes */ - const Word16 nb_sfm, /* i : total number of bands */ - const Word16 *R, /* i : bitallocation per band Q3 */ - const Word16 pvq_bits, /* i : number of bits avaiable */ - const Word16 core /* i : core */ -) -{ - Word16 i, j; - Word16 band_bits, bits_left; - - Word16 bit_pool = 0; - move16(); - Word16 coded_bands, bands_to_code; - Word16 bits; - Word16 R_sort[NB_SFM]; - Word16 is, i_sort[NB_SFM]; - Word16 strict_bits; - Word16 exp, tmp, shift; - Word32 xy_corr, yy_corr; - PVQ_ENC_DATA pvq_enc; - PVQ_ENC_HANDLE hPVQ = &pvq_enc; - - rc_enc_init_fx( hPVQ, pvq_bits ); - - bits = shl( sub( pvq_bits, RC_BITS_RESERVED ), 3 ); - - bands_to_code = 0; - move16(); - FOR( i = 0; i < nb_sfm; i++ ) - { - if ( R[i] > 0 ) - { - bands_to_code = add( bands_to_code, 1 ); - } - } - - IF( core == ACELP_CORE ) - { - strict_bits = 1; - move16(); - srt_vec_ind16_fx( R, R_sort, i_sort, nb_sfm ); - } - ELSE - { - strict_bits = 0; - move16(); - FOR( i = 0; i < nb_sfm; i++ ) - { - i_sort[i] = i; - move16(); - } - } - - coded_bands = 0; - move16(); - FOR( i = 0; i < nb_sfm; i++ ) - { - is = i_sort[i]; - move16(); - gopt[is] = 0; - move16(); - IF( R[is] > 0 ) - { - bandBitsAdjustment_fx( hPVQ->rc_num_bits, hPVQ->rc_range, bits, bands_to_code, sub( bands_to_code, coded_bands ), sfmsize[is], R[is], bit_pool, /* inputs */ - &band_bits, &bits_left, &bit_pool ); - /* outputs */ - pvq_encode_band_fx( hBstr, hPVQ, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], - &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, &bits_left, strict_bits ); - - xy_corr = L_deposit_l( 0 ); - yy_corr = L_deposit_l( 1 ); - shift = band_len_ener_shift[band_len_idx[sfmsize[is] >> 3]]; - move16(); - FOR( j = 0; j < sfmsize[i]; j++ ) - { - tmp = shr( coefs_quant[sfm_start[is] + j], shift ); - xy_corr = L_mac0( xy_corr, shr( coefs_norm[sfm_start[is] + j], 1 ), tmp ); /* Q_coefs-1+15-shift */ - yy_corr = L_mac0( yy_corr, tmp, tmp ); /* 2*(15-shift) */ - } - - tmp = ratio( xy_corr, yy_corr, &exp ); - gopt[is] = shl_sat( tmp, sub( sub( sub( 14, Q_coefs ), shift ), exp ) ); - move16(); - if ( gopt[is] == 0 ) - { - gopt[is] = 1; - move16(); - } - - /* Updates */ - coded_bands = add( coded_bands, 1 ); - } - ELSE - { - FOR( j = sfm_start[is]; j < sfm_end[is]; j++ ) - { - coefs_quant[j] = 0; - move16(); - pulse_vector[j] = 0; - move16(); - } - } - } - - rc_enc_finish_fx( hBstr, hPVQ ); - - return; -} -#endif /*---------------------------------------------------------------------* * pvq_core_enc() @@ -515,12 +262,8 @@ void pvq_encode_frame_fx( * Main Generic Audio Encoder Routine *---------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE Word16 pvq_core_enc_fx( const Word16 element_mode, -#else -Word16 pvq_core_enc_ivas_fx( -#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ Word16 coefs_quant[], /* o : quantized coefficients */ @@ -532,299 +275,69 @@ Word16 pvq_core_enc_ivas_fx( const Word16 *sfmsize, /* i : subband width */ Word16 *R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ Word16 *Rs, /* i/o: Integer bit allocation */ - Word16 *npulses, /* o : number of pulses */ - Word16 *maxpulse, /* i : maximum pulse per band */ - const Word16 core /* i : number of bands */ -) -{ - Word16 i; - Word16 R_upd; /* Q3 */ - Word16 ord[NB_SFM_MAX]; - Word16 fg_pred[NB_SFM_MAX]; - Word16 pvq_bits; - - Word16 pulse_vector[L_SPEC48k_EXT]; - Word16 gopt[NB_SFM]; - Word16 gain_bits_array[NB_SFM]; - Word16 gain_bits_tot; - - R_upd = shl( bits_tot, 3 ); -#ifdef HARM_HQ_CORE - gain_bits_tot = assign_gain_bits_fx( element_mode, core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); -#else - gain_bits_tot = ivas_assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); -#endif - pvq_bits = shr( R_upd, 3 ); - -#ifdef HARM_HQ_CORE - pvq_encode_frame_fx( hBstr, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); -#else - pvq_encode_frame_ivas_fx( hBstr, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); -#endif - - IF( Rs != NULL ) - { - FOR( i = 0; i < nb_sfm; i++ ) - { - if ( npulses[i] <= 0 ) - { - Rs[i] = 0; - move16(); /* Update Rs in case no pulses were assigned */ - } - } - } - - FOR( i = 0; i < nb_sfm; i++ ) - { - ord[i] = i; - move16(); - if ( npulses[i] <= 0 ) - { - R[i] = 0; - move16(); /* Update in case no pulses were assigned */ - } - } - - get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); - - /* Fine gain prediction */ -#ifdef HARM_HQ_CORE - fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, - coefs_quant, pulse_vector, fg_pred, element_mode, core ); -#else - ivas_fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, - coefs_quant, pulse_vector, fg_pred, core ); -#endif - - fine_gain_quant_fx( hBstr, ord, nb_sfm, gain_bits_array, fg_pred, gopt ); - - apply_gain_fx( ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant ); - - *Q_coefs = Q12; - move16(); - - return add( pvq_bits, gain_bits_tot ); -} - -#ifndef HARM_HQ_CORE -Word16 pvq_core_enc_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ - Word16 coefs_quant[], /* o : quantized coefficients */ - Word16 *Q_coefs, - const Word16 bits_tot, /* i : total number of bits */ - const Word16 nb_sfm, /* i : number of bands */ - const Word16 *sfm_start, /* i : Subband start coefficient */ - const Word16 *sfm_end, /* i : Subband end coefficient */ - const Word16 *sfmsize, /* i : subband width */ - Word16 *R, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *Rs, /* i/o: Integer bit allocation */ - Word16 *npulses, /* o : number of pulses */ - Word16 *maxpulse, /* i : maximum pulse per band */ - const Word16 core /* i : number of bands */ -) -{ - Word16 i; - Word16 R_upd; /* Q3 */ - Word16 ord[NB_SFM_MAX]; - Word16 fg_pred[NB_SFM_MAX]; - Word16 pvq_bits; - - Word16 pulse_vector[L_SPEC48k_EXT]; - Word16 gopt[NB_SFM]; - Word16 gain_bits_array[NB_SFM]; - Word16 gain_bits_tot; - - - R_upd = shl( bits_tot, 3 ); - gain_bits_tot = assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); - pvq_bits = shr( R_upd, 3 ); - - pvq_encode_frame_fx( hBstr, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); - - - IF( Rs != NULL ) - { - FOR( i = 0; i < nb_sfm; i++ ) - { - if ( npulses[i] <= 0 ) - { - Rs[i] = 0; - move16(); /* Update Rs in case no pulses were assigned */ - } - } - } - - FOR( i = 0; i < nb_sfm; i++ ) - { - ord[i] = i; - move16(); - if ( npulses[i] <= 0 ) - { - R[i] = 0; - move16(); /* Update in case no pulses were assigned */ - } - } - - get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); - - /* Fine gain prediction */ - fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, - coefs_quant, pulse_vector, fg_pred, core ); - - fine_gain_quant_fx( hBstr, ord, nb_sfm, gain_bits_array, fg_pred, gopt ); - - apply_gain_fx( ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant ); - *Q_coefs = 12; - move16(); - return add( pvq_bits, gain_bits_tot ); - ; -} -#endif - -static void encode_energies_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 *coefs, /* In block-floating point format with a common block-exponent - not used in this function. Hence, the block-exponent is - not in the parameter list. */ - const Word16 Q_coefs, - Word16 Np, /* i : number of parts */ - Word16 *dim_part, /* o : sizes of parts */ - Word32 *E_part, /* o : energies of parts 32-bit Q15 */ - Word16 *bits_part, /* o : assigned bits per part */ - Word16 *g_part, /* o : gains Q15 */ - Word16 qband, /* i : assigned quanta per band */ - Word16 *bits_left, /* o : remaining bits */ - Word32 enr, /* i : energy of vector */ - Word16 dim, /* i : size of vector */ - const Word16 strict_bits /* i : conservative rounding flag */ -) -{ - Word16 i, j, l_Np, r_Np; - Word16 l_bits, r_bits, l_dim, r_dim; - Word32 l_enr, r_enr; - Word16 l_gain, r_gain; - Word16 il, ir; - Word16 density; - Word16 phi; - Word16 index_phi = -1; - move16(); - Word16 oppRQ3, qzero; - Word16 angle; - Word32 sqrt_r_enr, sqrt_l_enr; - Word16 exp1, exp2, tmp; - l_Np = shr( Np, 1 ); - r_Np = sub( Np, l_Np ); - - l_enr = L_deposit_l( 0 ); - l_bits = 0; - move16(); - l_dim = 0; - move16(); - FOR( i = 0; i < l_Np; i++ ) - { - l_dim = add( l_dim, dim_part[i] ); - } - FOR( j = 0; j < l_dim; j++ ) - { - /* This is of paramount importance that the number of bits down-shift - * must be identical to that used to compute "enr" in pvq_encode_band_fx(). - * Otherwise, the subsequent "r_enr" will be computed incorrectly. - */ - tmp = shr( coefs[j], 2 ); - l_enr = L_mac0( l_enr, tmp, tmp ); - } - r_enr = L_sub( enr, l_enr ); - r_dim = sub( dim, l_dim ); - - obtainEnergyQuantizerDensity_fx( dim, qband, &density ); - sqrt_r_enr = Sqrt_l( r_enr, &exp1 ); - sqrt_l_enr = Sqrt_l( l_enr, &exp2 ); - - IF( LT_16( exp1, exp2 ) ) - { - sqrt_l_enr = L_shr( sqrt_l_enr, shr( sub( exp2, exp1 ), 1 ) ); - } - ELSE IF( LT_16( exp2, exp1 ) ) - { - sqrt_r_enr = L_shr( sqrt_r_enr, shr( sub( exp1, exp2 ), 1 ) ); - exp1 = exp2; - move16(); - } - - exp1 = add( shl( sub( Q_coefs, 2 ), 1 ), add( 31, exp1 ) ); /* 2x exponent */ - IF( EQ_16( s_and( exp1, 1 ), 1 ) ) - { - sqrt_r_enr = Mult_32_16( sqrt_r_enr, 23170 ); /* Q(exp1/2) */ - sqrt_l_enr = Mult_32_16( sqrt_l_enr, 23170 ); /* Q(exp1/2) */ - } - - IF( sqrt_r_enr != 0 ) - { - angle = atan2_fx( sqrt_r_enr, sqrt_l_enr ); /* Q14 */ - } - ELSE - { - angle = 0; - move16(); - } + Word16 *npulses, /* o : number of pulses */ + Word16 *maxpulse, /* i : maximum pulse per band */ + const Word16 core /* i : number of bands */ +) +{ + Word16 i; + Word16 R_upd; /* Q3 */ + Word16 ord[NB_SFM_MAX]; + Word16 fg_pred[NB_SFM_MAX]; + Word16 pvq_bits; - phi = mult_r( angle, 20861 ); + Word16 pulse_vector[L_SPEC48k_EXT]; + Word16 gopt[NB_SFM]; + Word16 gain_bits_array[NB_SFM]; + Word16 gain_bits_tot; - rangeCoderFinalizationFBits_fx( hPVQ->rc_num_bits, (UWord32) hPVQ->rc_range, &qzero ); - densityAngle2RmsProjEnc_fx( density, phi, &index_phi, &ir, &il, &oppRQ3 ); - densityIndexSymbolEncode_fx( hBstr, hPVQ, density, r_dim, l_dim, index_phi ); + R_upd = shl( bits_tot, 3 ); + gain_bits_tot = assign_gain_bits_fx( element_mode, core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); + pvq_bits = shr( R_upd, 3 ); - l_gain = il; /* Q15 */ - move16(); - r_gain = ir; /* Q15 */ - move16(); + pvq_encode_frame_fx( hBstr, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); - FOR( i = 0; i < l_Np; i++ ) + IF( Rs != NULL ) { - g_part[i] = mult_r( l_gain, g_part[i] ); - move16(); + FOR( i = 0; i < nb_sfm; i++ ) + { + if ( npulses[i] <= 0 ) + { + Rs[i] = 0; + move16(); /* Update Rs in case no pulses were assigned */ + } + } } - FOR( i = l_Np; i < Np; i++ ) + FOR( i = 0; i < nb_sfm; i++ ) { - g_part[i] = mult_r( r_gain, g_part[i] ); + ord[i] = i; move16(); + if ( npulses[i] <= 0 ) + { + R[i] = 0; + move16(); /* Update in case no pulses were assigned */ + } } - NearOppSplitAdjustment_fx( qband, qzero, hPVQ->rc_num_bits, hPVQ->rc_range, *bits_left, - strict_bits, Np, dim_part[0], dim_part[Np - 1], - l_dim, r_dim, oppRQ3, &l_bits, &r_bits, bits_left ); + get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); - IF( GT_16( l_Np, 1 ) ) - { - encode_energies_fx( hBstr, hPVQ, coefs, Q_coefs, l_Np, dim_part, E_part, bits_part, g_part, l_bits, bits_left, l_enr, l_dim, strict_bits ); - } - ELSE - { - E_part[0] = l_enr; - move32(); - bits_part[0] = l_bits; - move16(); - } - IF( GT_16( r_Np, 1 ) ) - { - encode_energies_fx( hBstr, hPVQ, &coefs[l_dim], Q_coefs, r_Np, &dim_part[l_Np], &E_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_enr, r_dim, strict_bits ); - } - ELSE - { - E_part[1] = r_enr; - move32(); - bits_part[1] = r_bits; - move16(); - } + /* Fine gain prediction */ + fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, + coefs_quant, pulse_vector, fg_pred, element_mode, core ); - return; + fine_gain_quant_fx( hBstr, ord, nb_sfm, gain_bits_array, fg_pred, gopt ); + + apply_gain_fx( ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant ); + + *Q_coefs = Q12; + move16(); + + return add( pvq_bits, gain_bits_tot ); } -#ifndef HARM_HQ_CORE -static void encode_energies_ivas_fx( + +static void encode_energies_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ const Word16 *coefs, /* In block-floating point format with a common block-exponent @@ -916,8 +429,7 @@ static void encode_energies_ivas_fx( rangeCoderFinalizationFBits_fx( hPVQ->rc_num_bits, (UWord32) hPVQ->rc_range, &qzero ); densityAngle2RmsProjEnc_fx( density, phi, &index_phi, &ir, &il, &oppRQ3 ); - densityIndexSymbolEncode_ivas_fx( hBstr, hPVQ, density, r_dim, l_dim, index_phi ); - + densityIndexSymbolEncode_fx( hBstr, hPVQ, density, r_dim, l_dim, index_phi ); l_gain = il; /* Q15 */ move16(); @@ -938,12 +450,11 @@ static void encode_energies_ivas_fx( NearOppSplitAdjustment_fx( qband, qzero, hPVQ->rc_num_bits, hPVQ->rc_range, *bits_left, strict_bits, Np, dim_part[0], dim_part[Np - 1], - l_dim, r_dim, oppRQ3, - &l_bits, &r_bits, bits_left ); + l_dim, r_dim, oppRQ3, &l_bits, &r_bits, bits_left ); IF( GT_16( l_Np, 1 ) ) { - encode_energies_ivas_fx( hBstr, hPVQ, coefs, Q_coefs, l_Np, dim_part, E_part, bits_part, g_part, l_bits, bits_left, l_enr, l_dim, strict_bits ); + encode_energies_fx( hBstr, hPVQ, coefs, Q_coefs, l_Np, dim_part, E_part, bits_part, g_part, l_bits, bits_left, l_enr, l_dim, strict_bits ); } ELSE { @@ -954,7 +465,7 @@ static void encode_energies_ivas_fx( } IF( GT_16( r_Np, 1 ) ) { - encode_energies_ivas_fx( hBstr, hPVQ, &coefs[l_dim], Q_coefs, r_Np, &dim_part[l_Np], &E_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_enr, r_dim, strict_bits ); + encode_energies_fx( hBstr, hPVQ, &coefs[l_dim], Q_coefs, r_Np, &dim_part[l_Np], &E_part[l_Np], &bits_part[l_Np], &g_part[l_Np], r_bits, bits_left, r_enr, r_dim, strict_bits ); } ELSE { @@ -967,79 +478,6 @@ static void encode_energies_ivas_fx( return; } -static void densityIndexSymbolEncode_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 density, /* i : Current density */ - const Word16 r_dim, /* i : Opposite size */ - const Word16 l_dim, /* i : Near size */ - const Word16 index_phi /* i : Index */ -) -{ - Word16 angle, c, densitySubIndex, densitySubC; - Word32 sym_freq, cum_freq, tot; - Word32 acc; - UWord16 lsb; - - sym_freq = L_deposit_l( 1 ); - - IF( s_and( (Word16) 0xFFFE, density ) != 0 ) /* even */ - { - angle = atan2_fx( SQRT_DIM_fx[r_dim], SQRT_DIM_fx[l_dim] ); - angle = shl_sat( angle, 1 ); - angle = mult_r( angle, 20861 ); - c = mult_r( density, angle ); - - densitySubIndex = sub( density, index_phi ); - densitySubC = sub( density, c ); - - IF( c == 0 ) - { - tot = L_mac0( 1L, density, add( density, 1 ) ); - sym_freq = L_deposit_l( add( shl( sub( density, index_phi ), 1 ), 1 ) ); - cum_freq = L_mac0( L_mult( index_phi, density ), index_phi, 1 ); - } - ELSE IF( EQ_16( c, density ) ) - { - tot = L_mac0( 1L, density, add( density, 1 ) ); - sym_freq = L_deposit_l( add( shl( index_phi, 1 ), 1 ) ); - cum_freq = L_mult0( index_phi, index_phi ); - } - ELSE - { - acc = L_mult0( density, c ); /* density*c */ - Mpy_32_16_ss( acc, densitySubC, &acc, &lsb ); /* density*c*(density - c) */ - acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); /* Concatenate acc and lsb forming 48-bit; upshift 16 bits; keep 32 MSB. */ - acc = L_shr( acc, 1 ); /* Compensate fractional mode multiply (Mpy_32_16_ss) */ - tot = L_add( L_add( acc, (Word32) density ), 1L ); /* density*c*(density - c) + density + 1 */ - IF( LE_16( index_phi, c ) ) - { - sym_freq = L_mac( 1L, index_phi, densitySubC ); - acc = L_mult0( densitySubC, sub( index_phi, 1 ) ); - acc = L_add( acc, 1 ); - Mpy_32_16_ss( acc, index_phi, &acc, &lsb ); - acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); - cum_freq = L_shr( acc, 1 ); - } - ELSE - { - sym_freq = L_mac( 1L, densitySubIndex, c ); - acc = L_mult0( densitySubIndex, add( densitySubIndex, 1 ) ); - Mpy_32_16_ss( acc, c, &acc, &lsb ); - acc = L_or( L_shl( acc, 16 ), L_and( lsb, 0xffffL ) ); - acc = L_shr( acc, 1 ); - acc = L_sub( acc, (Word32) index_phi ); - acc = L_add( add( density, 1 ), acc ); - cum_freq = L_sub( tot, acc ); - } - } - - rc_encode_fx( hBstr, hPVQ, cum_freq, sym_freq, tot ); - } - - return; -} -#endif static void densityIndexSymbolEncode_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -1121,12 +559,8 @@ static void densityIndexSymbolEncode_fx( * Calculate the number of segments needed *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE /* o : Number of segments */ static Word16 calc_pvq_splits_fx( -#else -static Word16 calc_pvq_splits_ivas_fx( /* o : Number of segments */ -#endif BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ const Word16 band_bits, /* i : Band bit rate */ @@ -1230,109 +664,3 @@ static Word16 calc_pvq_splits_ivas_fx( /* o : Number of segments */ return Np; } -#ifndef HARM_HQ_CORE - -static Word16 calc_pvq_splits_fx( /* o : Number of segments */ - BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 band_bits, /* i : Band bit rate */ - const Word16 sfmsize, /* i : Band width */ - const Word16 *y, /* i : Target vector */ - const Word16 Q_y, /* i : Q point of y */ - Word16 *bits /* o : Consumed bits */ -) -{ - Word16 Np; - Word16 Npart; - Word16 i, j; - Word16 E[MAX_SPLITS]; - Word16 Emean, eTotal; - Word16 tmp, expo; - const Word16 *pY; - Word16 max_dev, qPoint; - Word32 acc, acc1; - - IF( band_bits == 0 ) - { - Np = 1; - move16(); - } - ELSE - { - acc = L_mult0( band_bits, 0x7a44 ); - Np = extract_l( L_shr( acc, 23 ) ); /* Get integer part. */ - if ( L_and( acc, 0x7fffffL ) != 0 ) /* If fractional part != 0, add 1. */ - { - Np = add( Np, 1 ); /* ceiling operation */ - } - } - *bits = 0; - move16(); - - IF( LT_16( Np, MAX_SPLITS ) ) - { - acc = L_mult0( 8 * THR_ADD_SPLIT, sfmsize ); - IF( GT_32( band_bits, acc ) ) - { - Npart = extract_l( (Word32) intLimCDivPos_fx( UL_deposit_l( (UWord16) sfmsize ), Np ) ); - *bits = 8; - move16(); - eTotal = 0; - move16(); - pY = y; - qPoint = shl( Q_y, 1 ); /* acc in 2*Q_y */ - FOR( i = 0; i < Np; i++ ) - { - acc = L_deposit_l( 0 ); - FOR( j = 0; j < Npart; j++ ) - { - acc = L_mac0( acc, *pY, *pY ); - pY++; - } - acc = L_shr( acc, qPoint ); - - E[i] = sub( 30, norm_l( L_max( 1L, acc ) ) ); /* L_max needed to handle low subvector levels */ - move16(); - eTotal = add( eTotal, E[i] ); - } - - Emean = ratio( eTotal, Np, &expo ); - Emean = shr( Emean, add( 14 - 8, expo ) ); /* Emean in Q8 */ - - max_dev = -1; - move16(); - FOR( i = 0; i < Np; i++ ) - { - tmp = abs_s( sub( shl( E[i], 8 ), Emean ) ); /* in Q8 */ - max_dev = s_max( tmp, max_dev ); - } - - acc = L_sub( L_shl( Np, 5 + 3 + 8 ), L_shl( band_bits, 8 ) ); /* NB: max_dev in Q8 */ - acc1 = L_shl( L_mult0( Np, max_dev ), 3 ); - - tmp = 0; - move16(); - if ( GT_32( acc1, acc ) ) - { - tmp = 1; - move16(); - } - rc_enc_bits_fx( hBstr, hPVQ, tmp, 1 ); - Np = add( Np, tmp ); - } - } - - /* Check constraints for number of splits */ - /* The following code assumes that PVQ_MAX_BAND_SIZE is 64 */ - i = shr( sfmsize, 6 ); /* 6 = log2(64) = log2(PVQ_MAX_BAND_SIZE) */ - if ( s_and( sfmsize, 0x3f ) != 0 ) - { - i = add( i, 1 ); /* ceiling operation */ - } - - Np = s_max( i, Np ); - Np = s_min( MAX_SPLITS, Np ); - Np = s_min( sfmsize, Np ); /* The code line assumes that MIN_BAND_SIZE is 1 */ - return Np; -} -#endif diff --git a/lib_enc/pvq_encode_fx.c b/lib_enc/pvq_encode_fx.c index d1b392ac2..f858e1dd6 100644 --- a/lib_enc/pvq_encode_fx.c +++ b/lib_enc/pvq_encode_fx.c @@ -174,212 +174,6 @@ static Word16 one_pulse_search( * * *-----------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE -void pvq_encode_ivas_fx( - BSTR_ENC_HANDLE hBstr, - PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ - const Word16 *x, /* i : vector to quantize Q15-3=>Q12 */ - Word16 *y, /* o : raw pulses (non-scaled short) Q0 */ - Word16 *xq, /* o : quantized vector Q15 */ - Word32 *L_xq, /* o : quantized vector Q31 fot eval */ - const Word16 pulses, /* i : number of allocated pulses */ - const Word16 dim, /* i : Length of vector */ - const Word16 neg_gain /* i : Gain use - negative gain in Q15 0..1 */ -) -{ - Word16 i; - Word16 pulse_tot; - Word16 xabs[PVQ_MAX_BAND_SIZE]; - Word16 max_xabs; - Word32 L_xsum; - Word32 L_proj_fac; - Word32 L_yy, L_xy; - Word16 max_amp_y, imax; - Word16 k, en_margin, en_dn_shift, high_prec_active; - - Word32 L_num, L_tmp; - Word16 proj_fac, tmp, shift_den, shift_num, shift_delta, num, den; - - UWord16 u16_tmp; - Word16 dim_m1; - Word32 L_isqrt; - Word16 neg_gain_norm, shift_tot; - Word16 high_pulse_density_flag; - PvqEntry entry; - - L_proj_fac = 4096; - move32(); - L_xsum = L_deposit_h( 0 ); - max_xabs = -1; - move16(); - - FOR( i = 0; i < dim; i++ ) - { - xabs[i] = abs_s( x[i] ); - move16(); /* Q12 */ - max_xabs = s_max( max_xabs, xabs[i] ); /* for efficient search correlation scaling */ - L_xsum = L_mac0( L_xsum, 1, xabs[i] ); /* stay in Q12 */ - y[i] = 0; - move16(); /* init, later only non-zero values need to be normalized */ - } - - test(); - IF( L_xsum == 0 || neg_gain == 0 ) - { - pulse_tot = pulses; - move16(); - dim_m1 = sub( dim, 1 ); - y[dim_m1] = 0; - move16(); - y[0] = shr( pulses, 1 ); - move16(); - y[dim_m1] = add( y[dim_m1], sub( pulses, y[0] ) ); - move16(); - L_yy = L_mult( y[0], y[0] ); /* L_yy needed for normalization */ - IF( dim_m1 != 0 ) - { - L_yy = L_mac( L_yy, y[dim_m1], y[dim_m1] ); /* (single basop) */ - } - } - ELSE - { - - num = sub( pulses, PYR_OFFSET ); - high_pulse_density_flag = pyramidSearchProjInit_fx( dim, pulses ); - - test(); - IF( ( num > 0 ) && ( high_pulse_density_flag != 0 ) ) - { - shift_den = norm_l( L_xsum ); /* x_sum input Q12 */ - den = extract_h( L_shl( L_xsum, shift_den ) ); /* now in Q12+shift_den */ - - L_num = L_deposit_l( num ); - shift_num = sub( norm_l( L_num ), 1 ); - L_num = L_shl( L_num, shift_num ); /* now in Q0 +shift_num -1 */ - proj_fac = div_l( L_num, den ); /* L_num always has to be less than den<<16 */ - - shift_delta = sub( shift_num, shift_den ); - L_proj_fac = L_shl_sat( L_deposit_l( proj_fac ), sub( 9, shift_delta ) ); /* bring to a fixed Q12 */ - } - - pulse_tot = 0; - move16(); - L_yy = L_deposit_l( 0 ); - L_xy = L_deposit_l( 0 ); - test(); - IF( ( num > 0 ) && ( high_pulse_density_flag != 0 ) ) - { - FOR( i = 0; i < dim; i++ ) /* max 64 */ - { - Mpy_32_16_ss( L_proj_fac, xabs[i], &L_tmp, &u16_tmp ); /*Q12 *Q12 +1 */ - y[i] = extract_l( L_shr( L_tmp, 12 + 12 - 16 + 1 ) ); - move16(); /* Q12 *Q12 -> Q0 */ - - pulse_tot = add( pulse_tot, y[i] ); /* Q0 */ - L_yy = L_mac( L_yy, y[i], y[i] ); /* Energy, result will scale up by 2 by L_mac */ - L_xy = L_mac( L_xy, xabs[i], y[i] ); /* Corr, Q0*Q12 +1 --> Q13 */ - } - } - - - L_yy = L_shr( L_yy, 1 ); - IF( LE_16( pulses, 127 ) ) - { - /* LC inner loop, enters here always for dimensions 6 and higher, and also sometimes for dimensions 1 .. 5 */ - /* ( if high energy precision is inactive, max_amp_y is not needed , no max_amp_y(k-1) update ) */ - FOR( k = pulse_tot; k < pulses; k++ ) - { - L_yy = L_add( L_yy, 1 ); - imax = one_pulse_search( dim, xabs, y, &pulse_tot, &L_xy, &L_yy, 0, 0, max_xabs ); - } - } - ELSE - { /* HC or LC+HC inner loops */ - max_amp_y = max_val_fx( y, dim ); /* this loops over max 5 values (as pulses are dimension restricted) */ - /* max_amp_y from projected y is needed when pulses_sum exceeds 127 */ - - /* First section with 32 bit energy inactive, max_amp_y kept updated though */ - FOR( k = pulse_tot; k < 128; k++ ) - { - L_yy = L_add( L_yy, 1 ); - imax = one_pulse_search( dim, xabs, y, &pulse_tot, &L_xy, &L_yy, 0, 0, max_xabs ); - max_amp_y = s_max( max_amp_y, y[imax] ); - } - - /* Second section with higher number of pulses, 32 bit energy precission adaptively selected, max_amp_y kept updated */ - FOR( k = pulse_tot; k < pulses; k++ ) - { - L_yy = L_add( L_yy, 1 ); - en_margin = norm_l( L_mac( L_yy, 1, max_amp_y ) ); /* find max current energy "addition", margin, ~ 2 ops */ - en_dn_shift = sub( 16, en_margin ); /* calc. shift to lower byte for fixed use of extract_l */ - - high_prec_active = 1; - move16(); - if ( en_dn_shift <= 0 ) - { - /* only use 32 bit energy if actually needed */ - high_prec_active = 0; - move16(); - } - /* 32 bit energy and corr adaptively active, max_amp_y kept updated */ - imax = one_pulse_search( dim, xabs, y, &pulse_tot, &L_xy, &L_yy, high_prec_active, en_dn_shift, max_xabs ); - max_amp_y = s_max( max_amp_y, y[imax] ); - } - } - L_yy = L_shl( L_yy, 1 ); /* compensate search loop analysis energy downshift by 1, - to make energy right for unit/inverse gain calculation */ - } - - /* Apply unit energy normalization scaling, always at least one pulse so no div-by-zero check is needed */ - L_isqrt = L_deposit_l( 0 ); - IF( neg_gain != 0 ) - { - L_isqrt = Isqrt( L_shr( L_yy, 1 ) ); /* Note: one single gain factor as not computed */ - } - - shift_num = norm_s( pulse_tot ); /* account for max possible pulse amplitude in y, - can be used even when max_amp_y is not avail. */ - shift_den = norm_s( neg_gain ); /* account for gain downscaling shift */ - neg_gain_norm = shl( neg_gain, shift_den ); /* up to 10 dB loss without this norm */ - shift_tot = sub( add( shift_num, shift_den ), 15 ); - - L_isqrt = L_negate( L_isqrt ); - FOR( i = 0; i < dim; i++ ) - { - tmp = shl( y[i], shift_num ); /* upshifted abs(y[i]) used in scaling */ - if ( x[i] < 0 ) - { - tmp = negate( tmp ); /* apply sign */ - } - - IF( y[i] != 0 ) - { - y[i] = shr( tmp, shift_num ); - move16(); /* updates sign of y[i} , ~range -512 + 512), array move */ - } - Mpy_32_16_ss( L_isqrt, tmp, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) +1 */ - Mpy_32_16_ss( L_tmp, neg_gain_norm, &L_tmp, &u16_tmp ); /* Q31*Q(0+x) *Q15 +1 */ - L_tmp = L_shr_sat( L_tmp, shift_tot ); /* Q31+x */ - xq[i] = round_fx_sat( L_tmp ); /* Q15, array move */ - move16(); - L_xq[i] = L_tmp; /* Q31 currently unused */ - move32(); - } - - /* index the found PVQ vector into short codewords */ - entry = mpvq_encode_vec_fx( y, dim, pulses ); - - /* send the short codeword(s) to the range encoder */ - rc_enc_bits_fx( hBstr, hPVQ, UL_deposit_l( entry.lead_sign_ind ), 1 ); /* 0 or 1 */ - - IF( NE_16( dim, 1 ) ) - { - rc_enc_uniform_fx( hBstr, hPVQ, entry.index, entry.size ); - } - - return; -} -#endif void pvq_encode_fx( BSTR_ENC_HANDLE hBstr, diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index c19985a1b..12037d2a0 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -3012,227 +3012,6 @@ static Word16 decision_hq_generic_class_fx_32( } } -#ifndef HARM_HQ_CORE -/*-------------------------------------------------------------------* - * hq_generic_encoding_fx() - * - *-------------------------------------------------------------------*/ - -void hq_generic_encoding_fx( - const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ - Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope : Q3 */ - const Word16 hq_generic_offset, /* i : frequency offset for extracting energy : Q0 */ - Encoder_State *st_fx, /* i/o: encoder state structure */ - Word16 *hq_generic_exc_clas /* o : bwe excitation class : Q0 */ -) -{ - Word16 n_coeff, n_band; - Word16 indice[HQ_GENERIC_NVQIDX]; - Word16 nenv; - - Word16 energy_factor_fx[SWB_FENV]; - Word16 cs, exp, tmp, tmp2; - Word32 energy_fx; - Word32 L_tmp, max_coefs_fx; - Word16 w_env_fx[SWB_FENV]; - HQ_ENC_HANDLE hHQ_core = st_fx->hHQ_core; - BSTR_ENC_HANDLE hBstr = st_fx->hBstr; - - set16_fx( energy_factor_fx, 0, SWB_FENV ); - - IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) - { - nenv = SWB_FENV; - move16(); - } - ELSE - { - nenv = SWB_FENV - 2; - move16(); - } - - energy_control_fx_32( st_fx, HQ_CORE, -1, -1, coefs_fx, hq_generic_offset, energy_factor_fx ); - - IF( EQ_16( hHQ_core->hq_generic_speech_class, 1 ) ) - { - push_indice( hBstr, IND_HQ_SWB_EXC_SP_CLAS, 1, 1 ); - *hq_generic_exc_clas = HQ_GENERIC_SP_EXC; - move16(); - } - ELSE - { - *hq_generic_exc_clas = decision_hq_generic_class_fx_32( coefs_fx, hq_generic_offset ); - move16(); - push_indice( hBstr, IND_HQ_SWB_EXC_SP_CLAS, 0, 1 ); - push_indice( hBstr, IND_HQ_SWB_EXC_CLAS, *hq_generic_exc_clas, 1 ); - } - - FOR( n_band = 0; n_band < nenv; n_band++ ) - { - energy_fx = L_deposit_l( 0 ); - max_coefs_fx = L_deposit_l( 0 ); - tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); - FOR( n_coeff = swb_bwe_subband[n_band] + hq_generic_offset; n_coeff < tmp2; n_coeff++ ) - { - IF( LT_32( max_coefs_fx, L_abs( coefs_fx[n_coeff] ) ) ) - { - max_coefs_fx = L_abs( coefs_fx[n_coeff] ); - } - } - cs = norm_l( max_coefs_fx ); - tmp2 = add( swb_bwe_subband[n_band + 1], hq_generic_offset ); - FOR( n_coeff = swb_bwe_subband[n_band] + hq_generic_offset; n_coeff < tmp2; n_coeff++ ) - { - tmp = extract_h( L_shl( coefs_fx[n_coeff], cs ) ); /*12 + cs - 16 */ - L_tmp = L_mult0( tmp, tmp ); /*2*cs - 8 */ - energy_fx = L_add( energy_fx, L_shr( L_tmp, 5 ) ); - } - - IF( energy_fx != 0 ) - { - L_tmp = Mult_32_16( energy_fx, energy_factor_fx[n_band] ); /*2*cs - 13 */ - L_tmp = Mult_32_16( L_tmp, swb_inv_bwe_subband_width_fx[n_band] ); /*2*cs - 13 + 15 - 15 */ - - exp = norm_l( L_tmp ); - tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( 30, add( exp, 2 * cs - 13 ) ); - - L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ - hq_generic_fenv_fx[n_band] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ - move16(); - } - ELSE - { - hq_generic_fenv_fx[n_band] = -24576; - move16(); - } - } - - IF( EQ_16( st_fx->bwidth, FB ) ) - { - FOR( n_band = 0; n_band < DIM_FB; n_band++ ) - { - energy_fx = L_deposit_l( 0 ); - max_coefs_fx = L_deposit_l( 0 ); - tmp2 = fb_bwe_subband[add( n_band, 1 )]; - FOR( n_coeff = fb_bwe_subband[n_band]; n_coeff < tmp2; n_coeff++ ) - { - IF( LT_32( max_coefs_fx, L_abs( coefs_fx[n_coeff] ) ) ) - { - max_coefs_fx = L_abs( coefs_fx[n_coeff] ); - } - } - cs = norm_l( max_coefs_fx ); - tmp2 = fb_bwe_subband[n_band + 1]; - FOR( n_coeff = fb_bwe_subband[n_band]; n_coeff < tmp2; n_coeff++ ) - { - tmp = extract_h( L_shl( coefs_fx[n_coeff], cs ) ); /*12 + cs - 16 */ - L_tmp = L_mult0( tmp, tmp ); /*2*cs - 8 */ - energy_fx = L_add( energy_fx, L_shr( L_tmp, 5 ) ); - } - - IF( energy_fx != 0 ) - { - L_tmp = Mult_32_16( energy_fx, fb_inv_bwe_subband_width_fx[n_band] ); /*2*cs - 13 + 18 - 15 */ - - exp = norm_l( L_tmp ); - tmp = Log2_norm_lc( L_shl( L_tmp, exp ) ); - exp = sub( 30, add( exp, 2 * cs - 13 ) ); - - L_tmp = Mpy_32_16( exp, tmp, 24660 ); /* Q14 */ /*10log10(2) in Q13 */ - hq_generic_fenv_fx[n_band + nenv] = round_fx( L_shl( L_tmp, 10 ) ); /*Q8 */ - move16(); - } - ELSE - { - hq_generic_fenv_fx[n_band + nenv] = -24576; - move16(); - } - } - } - - freq_weights_fx( hq_generic_fenv_fx, w_NOR_fx, w_env_fx, nenv ); - - FOR( n_band = 0; n_band < nenv; n_band++ ) - { - hq_generic_fenv_fx[n_band] = sub( hq_generic_fenv_fx[n_band], Mean_env_fx[n_band] ); - move16(); - } - - IF( st_fx->bwidth == FB ) - { - FOR( n_band = 0; n_band < DIM_FB; n_band++ ) - { - hq_generic_fenv_fx[n_band + nenv] = sub( shr( hq_generic_fenv_fx[n_band + nenv], 1 ), Mean_env_fb_fx[n_band] ); - move16(); - } - } - - /* Energy VQ */ - IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) - { - msvq_interpol_fx( hq_generic_fenv_fx, w_env_fx, indice ); - } - ELSE - { - msvq_interpol_2_fx( hq_generic_fenv_fx, w_env_fx, indice, nenv ); - } - - IF( EQ_16( st_fx->bwidth, FB ) ) - { - indice[5] = vqSimple_w_fx( hq_generic_fenv_fx + nenv, hq_generic_fenv_fx + nenv, EnvCdbkFB_fx, NULL, DIM_FB, N_CB_FB, 0 ); - move16(); - } - - push_indice( hBstr, IND_SWB_FENV_HQ, indice[0], 5 ); - push_indice( hBstr, IND_SWB_FENV_HQ, indice[1], 7 ); - push_indice( hBstr, IND_SWB_FENV_HQ, indice[2], 6 ); - push_indice( hBstr, IND_SWB_FENV_HQ, indice[3], 5 ); - - IF( LE_16( hq_generic_offset, HQ_GENERIC_FOFFSET_24K4 ) ) - { - push_indice( hBstr, IND_SWB_FENV_HQ, indice[4], 6 ); - } - ELSE - { - push_indice( hBstr, IND_SWB_FENV_HQ, indice[4], 5 ); - } - - IF( EQ_16( st_fx->bwidth, FB ) ) - { - push_indice( hBstr, IND_FB_FENV_HQ, indice[5], 5 ); - } - - FOR( n_band = 0; n_band < nenv; n_band++ ) - { - tmp = add( hq_generic_fenv_fx[n_band], Mean_env_fx[n_band] ); /*8 */ - L_tmp = L_mult( tmp, 21771 ); /*26 */ - L_tmp = L_shr( L_tmp, 10 ); /*16 */ - L_Extract( L_tmp, &exp, &tmp ); /* */ - tmp = extract_l( Pow2( 13, tmp ) ); - exp = sub( exp, 13 ); - hq_generic_fenv_fx[n_band] = shl_sat( tmp, add( exp, 1 ) ); /*1 */ - move16(); - } - - IF( EQ_16( st_fx->bwidth, FB ) ) - { - FOR( n_band = 0; n_band < DIM_FB; n_band++ ) - { - tmp = add( hq_generic_fenv_fx[n_band + nenv], Mean_env_fb_fx[n_band] ); /*7 */ - L_tmp = L_mult( tmp, 21771 ); /*25 */ - L_tmp = L_shr( L_tmp, 9 ); /*16 */ - L_Extract( L_tmp, &exp, &tmp ); - tmp = extract_l( Pow2( 13, tmp ) ); - exp = sub( exp, 13 ); - hq_generic_fenv_fx[n_band + nenv] = shl( tmp, add( exp, 1 ) ); /*2 */ - move16(); - } - } - - return; -} -#endif /*-------------------------------------------------------------------* * fd_bwe_enc_init_fx() @@ -3287,9 +3066,7 @@ void fd_bwe_enc_init_fx( *-------------------------------------------------------------------*/ void hq_generic_hf_encoding_fx( -#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ -#endif const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope : Q1 */ const Word16 hq_generic_offset, /* i : frequency offset for extracting energy : Q0 */ @@ -3452,14 +3229,12 @@ void hq_generic_hf_encoding_fx( IF( EQ_16( length, L_SPEC48k ) ) { -#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { indice[5] = vqSimple_w_fx( hq_generic_fenv_fx + nenv, hq_generic_fenv_fx + nenv, EnvCdbkFB_fx, NULL, DIM_FB, N_CB_FB, 0 ); move16(); } ELSE -#endif { Word16 sf = getScaleFactor16( hq_generic_fenv_fx, add( DIM_FB, nenv ) ); Scale_sig( hq_generic_fenv_fx, add( DIM_FB, nenv ), negate( sf ) ); -- GitLab From 01461af2224607653204c531024065b09f180acd Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 19:59:55 +0100 Subject: [PATCH 02/11] [cleanup] accept HARMONIZE_TBE3 --- lib_com/options.h | 1 - lib_com/prot_fx.h | 56 -- lib_com/swb_tbe_com_fx.c | 251 ----- lib_dec/dec_post_fx.c | 4 - lib_dec/evs_dec_fx.c | 10 - lib_dec/ivas_core_dec_fx.c | 16 - lib_dec/swb_tbe_dec_fx.c | 1781 ------------------------------------ lib_enc/evs_enc_fx.c | 4 - lib_enc/ivas_core_enc_fx.c | 4 - lib_enc/prot_fx_enc.h | 16 - lib_enc/swb_tbe_enc_fx.c | 973 -------------------- 11 files changed, 3116 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 89dee9b69..8628e13c3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,7 +84,6 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ -#define HARMONIZE_TBE3 /* VA: basop issue 2399: Remove duplicated code: TBE, step 3 */ #define FIX_2459_USAN_AMR_SIDSTART /* FhG: basop issue 2459: fix msan complaint */ #define FIX_2458_USAN_NULLPTR_WITH_ZERO_OFFSET /* FhG: basop issue 2458: avoid indexing into null pointer */ #define HARM_2456_APPLY_SCALE /* FhG basop issue 2456: Harmonize apply_scale_ind(), apply_scale_ivas_fx() */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index fb8805407..128b232f3 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -2589,31 +2589,15 @@ void flip_and_downmix_generic_fx( ); void Calc_rc0_h( -#ifdef HARMONIZE_TBE3 const Word16 element_mode, /* i : element mode */ const Word16 enc_dec, /* i : encoder/decoder flag */ -#endif Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ); void PostShortTerm_fx( -#ifdef HARMONIZE_TBE3 const Word16 element_mode, /* i : element mode */ const Word16 enc_dec, /* i : encoder/decoder flag */ -#endif - Word16 *sig_in, /* i : i signal (pointer to current subframe */ - Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 *mem_stp, /* i/o: postfilter memory*/ - Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ - Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ - Word16 *mem_zero, /* i/o: null memory to compute h_st*/ - const Word16 formant_fac_fx /* i : Strength of post-filter*/ -); - -#ifndef HARMONIZE_TBE3 -void PostShortTerm_ivas_enc_fx( Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -2624,17 +2608,6 @@ void PostShortTerm_ivas_enc_fx( const Word16 formant_fac_fx /* i : Strength of post-filter*/ ); -void PostShortTerm_ivas_dec_fx( - Word16 *sig_in, /* i : i signal (pointer to current subframe */ - Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 *mem_stp, /* i/o: postfilter memory*/ - Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ - Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ - Word16 *mem_zero, /* i/o: null memory to compute h_st*/ - const Word16 formant_fac_fx /* i : Strength of post-filter*/ -); -#endif void flip_spectrum_and_decimby4_fx( const Word16 i[], /* i : i spectrum */ Word16 output[], /* o : output spectrum */ @@ -5386,7 +5359,6 @@ void wb_tbe_dec_fx( Word16 *synth, /* i/o: ACELP core synthesis/final synthesis */ Word16 *Q_synth ); -#ifdef HARMONIZE_TBE3 void swb_tbe_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ @@ -5400,20 +5372,6 @@ void swb_tbe_dec_fx( Word16 *Q_synth, /* o : Q-factor of synth_fx16[]/synth_fx[] */ Word16 *pitch_buf_fx /* i : Q6 */ ); -#else -void swb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_exc*/ - Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 old_syn_12k8_16k[], /* i : low band synthesis*/ - Word16 *White_exc16k, /* o : shaped white excitation for the FB TBE */ - Word16 *Q_white_exc, - Word16 *synth, /* o : SHB synthesis/final synthesis */ - Word16 *Q_synth, - Word16 *pitch_buf ); -#endif void fb_tbe_dec_fx( Decoder_State *st, /* i/o: encoder state structure */ @@ -9706,20 +9664,6 @@ void v_sub32_fx( const Word16 N /* i : Vector length */ ); -#ifndef HARMONIZE_TBE3 -void swb_tbe_dec_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ - Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ - const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ - Word16 *pitch_buf_fx, /* i : Q6 */ - Word16 *Q_white_exc /* o : Q-factor of White_exc16k_fx */ -); -#endif Word16 swb_bwe_dec_fx32( Decoder_State *st_fx, /* i/o: decoder state structure */ Word32 output_fx[], /* i : synthesis @internal Fs : Q11 */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 504b83759..845f5c080 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -26,11 +26,7 @@ static void create_random_vector_fx( Word16 output[], const Word16 length, Word16 seed[], Word16 element_mode ); static void flip_spectrum_fx( const Word16 input[], Word16 output[], const Word16 length ); -#ifdef HARMONIZE_TBE3 static void Calc_st_filt_tbe_fx( const Word16 element_mode, const Word16 enc_dec, Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); -#else -static void Calc_st_filt_tbe_fx( Word16 *apond2, Word16 *apond1, Word16 *parcor0, Word16 *sig_ltp_ptr, Word16 *mem_zero ); -#endif static void Hilbert_transform_fx( Word32 tmp_R[], Word32 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); static void Hilbert_transform_sp_fx( Word16 tmp_R[], Word16 tmp_I[], Word32 *tmpi_R, Word32 *tmpi_I, const Word16 length, const Word16 HB_stage_id ); static void Estimate_mix_factors_fx( const Word16 *shb_res, const Word16 Q_shb, const Word16 *exc16kWhtnd, const Word16 Q_bwe_exc, const Word16 *White_exc16k_frac, const Word16 Q_frac, const Word32 pow1, const Word16 Q_pow1, const Word32 pow22, const Word16 Q_pow22, Word16 *vf_modified, Word16 *vf_ind ); @@ -636,10 +632,8 @@ void flip_spectrum_fx( *---------------------------------------------------------------------------*/ void Calc_rc0_h( -#ifdef HARMONIZE_TBE3 const Word16 element_mode, /* i : element mode */ const Word16 enc_dec, /* i : encoder/decoder flag */ -#endif Word16 *h, /* i : impulse response of composed filter */ Word16 *rc0 /* o : 1st parcor */ ) @@ -647,14 +641,11 @@ void Calc_rc0_h( Word32 L_acc; Word16 *ptrs; Word16 acf0, acf1; -#ifdef HARMONIZE_TBE3 Word16 tmp2; -#endif Word16 temp, sh_acf; Word16 i; /* computation of the autocorrelation function acf */ -#ifdef HARMONIZE_TBE3 IF( element_mode != EVS_MONO && enc_dec == ENC ) { #ifdef FIX_2462_PARCOR_FIX @@ -691,7 +682,6 @@ void Calc_rc0_h( } } ELSE -#endif { L_acc = L_mult( h[0], h[0] ); FOR( i = 1; i < LONG_H_ST; i++ ) @@ -746,72 +736,10 @@ void Calc_rc0_h( return; } -#ifndef HARMONIZE_TBE3 -static void Calc_rc0_h_ivas_enc_fx( - Word16 *h, /* i : impulse response of composed filter */ - Word16 *rc0 /* o : 1st parcor */ -) -{ - Word32 L_acc; - Word16 *ptrs; - Word16 acf0, acf1; - Word16 temp, sh_acf, tmp2; - Word16 i; - - /* computation of the autocorrelation function acf */ - L_acc = L_mult( h[0], h[0] ); - FOR( i = 1; i < LONG_H_ST; i++ ) - { - tmp2 = shr( h[i], 2 ); - L_acc = L_mac( L_acc, tmp2, tmp2 ); - } - sh_acf = norm_l( L_acc ); - L_acc = L_shl( L_acc, sh_acf ); - acf0 = extract_h( L_acc ); - - ptrs = h; - - temp = *ptrs++; - move16(); - L_acc = L_mult( temp, *ptrs ); - FOR( i = 1; i < LONG_H_ST - 1; i++ ) - { - temp = shr( *ptrs++, 2 ); - move16(); - L_acc = L_mac( L_acc, temp, shr( *ptrs, 2 ) ); - } - L_acc = L_shl( L_acc, sh_acf ); - acf1 = extract_h( L_acc ); - - /* Compute 1st parcor */ - IF( acf0 == 0 ) - { - *rc0 = 0; - move16(); - return; - } - - IF( LT_16( acf0, abs_s( acf1 ) ) ) - { - *rc0 = 0; - move16(); - return; - } - *rc0 = div_s( abs_s( acf1 ), acf0 ); - move16(); - IF( acf1 > 0 ) - { - *rc0 = negate( *rc0 ); - move16(); - } -} -#endif static void Calc_st_filt_tbe_fx( -#ifdef HARMONIZE_TBE3 const Word16 element_mode, /* i : element mode */ const Word16 enc_dec, /* i : encoder/decoder flag */ -#endif Word16 *apond2, /* i : coefficients of numerator */ Word16 *apond1, /* i : coefficients of denominator */ Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ @@ -827,25 +755,19 @@ static void Calc_st_filt_tbe_fx( Word16 i; temp = sub( 2, norm_s( apond2[0] ) ); -#ifdef HARMONIZE_TBE3 IF( element_mode != EVS_MONO && enc_dec == ENC ) { /* compute i.r. of composed filter apond2 / apond1 */ syn_filt_fx( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); } ELSE -#endif { /* compute i.r. of composed filter apond2 / apond1 */ Syn_filt_s( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); } /* compute 1st parcor */ -#ifdef HARMONIZE_TBE3 Calc_rc0_h( element_mode, enc_dec, h, parcor0 ); -#else - Calc_rc0_h( h, parcor0 ); -#endif /* compute g0 */ @@ -870,49 +792,6 @@ static void Calc_st_filt_tbe_fx( return; } -#ifndef HARMONIZE_TBE3 -static void Calc_st_filt_tbe_ivas_enc_fx( - Word16 *apond2, /* i : coefficients of numerator */ - Word16 *apond1, /* i : coefficients of denominator */ - Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ - Word16 *mem_zero /* i : All zero memory */ -) -{ - Word32 L_g0; - - Word16 h[LONG_H_ST]; - - Word16 g0, temp; - Word16 i; - temp = sub( 2, norm_s( apond2[0] ) ); - /* compute i.r. of composed filter apond2 / apond1 */ - syn_filt_fx( temp, apond1, LPC_SHB_ORDER, apond2, h, LONG_H_ST, mem_zero, 0 ); - /* compute 1st parcor */ - Calc_rc0_h_ivas_enc_fx( h, parcor0 ); - - /* compute g0 */ - L_g0 = L_mult0( 1, abs_s( h[0] ) ); - FOR( i = 1; i < LONG_H_ST; i++ ) - { - L_g0 = L_mac0( L_g0, 1, abs_s( h[i] ) ); - } - g0 = extract_h( L_shl( L_g0, 14 ) ); - - /* Scale signal i of 1/A(gamma1) */ - IF( GT_16( g0, 1024 ) ) - { - temp = div_s( 1024, g0 ); /* temp = 2**15 / gain0 */ - FOR( i = 0; i < L_SUBFR16k; i++ ) - { - sig_ltp_ptr[i] = mult_r( sig_ltp_ptr[i], temp ); - move16(); - } - } - - return; -} -#endif static void filt_mu_fx( const Word16 *sig_in, /* i : signal (beginning at sample -1) */ @@ -1079,10 +958,8 @@ static void scale_st_swb( *-------------------------------------------------------------------*/ void PostShortTerm_fx( -#ifdef HARMONIZE_TBE3 const Word16 element_mode, /* i : element mode */ const Word16 enc_dec, /* i : encoder/decoder flag */ -#endif Word16 *sig_in, /* i : input signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -1122,21 +999,14 @@ void PostShortTerm_fx( move16(); /* Control short term pst filter gain and compute parcor0 */ -#ifdef HARMONIZE_TBE3 Calc_st_filt_tbe_fx( element_mode, enc_dec, apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); /* parcor0 in Q15, sig_ltp_fx in Q_bwe_exc */ -#else - Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); - /* i: parcor0 in Q15, o: sig_ltp_fx in Q_bwe_exc */ -#endif /* 1/A(gamma1) filtering, mem_stp is updated */ -#ifdef HARMONIZE_TBE3 IF( element_mode != EVS_MONO && enc_dec == ENC ) { syn_filt_fx( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); } ELSE -#endif { Syn_filt_s( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); } @@ -1150,127 +1020,6 @@ void PostShortTerm_fx( return; } -#ifndef HARMONIZE_TBE3 -void PostShortTerm_ivas_enc_fx( - Word16 *sig_in, /* i : input signal (pointer to current subframe */ - Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 *mem_stp, /* i/o: postfilter memory*/ - Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ - Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ - Word16 *mem_zero, /* i/o: null memory to compute h_st*/ - const Word16 formant_fac_fx /* i : Strength of post-filter*/ -) -{ - Word16 apond1_fx[LPC_SHB_ORDER + 1]; /* denominator coeff.*/ - Word16 apond2_fx[LONG_H_ST]; /* numerator coeff. */ - Word16 sig_ltp_fx[L_SUBFR16k + 1]; /* residual signal */ - /*Word16 lpccoeff_fx[LPC_SHB_ORDER+1];//Q12 */ - Word16 g1_fx, g2_fx, parcor0_fx; /*Q15 */ - Word16 tmp; - - parcor0_fx = 0; - move16(); - set16_fx( apond1_fx, 0, LPC_SHB_ORDER + 1 ); - set16_fx( apond2_fx, 0, LONG_H_ST ); - set16_fx( sig_ltp_fx, 0, L_SUBFR16k + 1 ); - - /* Obtain post-filter weights */ - tmp = extract_h( L_mult( GAMMA_SHARP_FX, formant_fac_fx ) ); /*Q15 */ - g1_fx = add( GAMMA0_FX, tmp ); /*Q15 */ - g2_fx = sub( GAMMA0_FX, tmp ); /*Q15 */ - - /* Compute weighted LPC coefficients */ - weight_a_fx( lpccoeff, apond1_fx, g1_fx, LPC_SHB_ORDER ); - weight_a_fx( lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER ); - /* o: apond1_fx, apond2_fx in Q12 */ - - /* Compute A(gamma2) residual */ - Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx + 1, L_SUBFR16k, 0 ); - /* o: sig_ltp_fx in Q_bwe_exc */ - - /* Save last output of 1/A(gamma1) */ - sig_ltp_fx[0] = *ptr_mem_stp; - move16(); - - /* Control short term pst filter gain and compute parcor0 */ - Calc_st_filt_tbe_ivas_enc_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); - /* o: parcor0 in Q15 */ - /* i/o: sig_ltp_fx in Q_bwe_exc */ - - /* 1/A(gamma1) filtering, mem_stp is updated */ - syn_filt_fx( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); - - /* (1 + mu z-1) tilt filtering */ - filt_mu_fx( sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k ); - /* o: sig_out in Q_bwe_exc */ - - /* gain control */ - scale_st_swb( sig_in, sig_out, ptr_gain_prec, L_SUBFR16k ); - - return; -} - -void PostShortTerm_ivas_dec_fx( - Word16 *sig_in, /* i : input signal (pointer to current subframe */ - Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ - Word16 *sig_out, /* o : postfiltered output */ - Word16 *mem_stp, /* i/o: postfilter memory*/ - Word16 *ptr_mem_stp, /* i/o: pointer to postfilter memory*/ - Word16 *ptr_gain_prec, /* i/o: for gain adjustment*/ - Word16 *mem_zero, /* i/o: null memory to compute h_st*/ - const Word16 formant_fac_fx /* i : Strength of post-filter*/ -) -{ - Word16 apond1_fx[LPC_SHB_ORDER + 1]; /* denominator coeff.*/ - Word16 apond2_fx[LONG_H_ST]; /* numerator coeff. */ - Word16 sig_ltp_fx[L_SUBFR16k + 1]; /* residual signal */ - /*Word16 lpccoeff_fx[LPC_SHB_ORDER+1];//Q12 */ - Word16 g1_fx, g2_fx, parcor0_fx; /*Q15 */ - Word16 tmp; - - parcor0_fx = 0; - move16(); - set16_fx( apond1_fx, 0, LPC_SHB_ORDER + 1 ); - set16_fx( apond2_fx, 0, LONG_H_ST ); - set16_fx( sig_ltp_fx, 0, L_SUBFR16k + 1 ); - - /* Obtain post-filter weights */ - tmp = extract_h( L_mult( GAMMA_SHARP_FX, formant_fac_fx ) ); /*Q15 */ - g1_fx = add( GAMMA0_FX, tmp ); /*Q15 */ - g2_fx = sub( GAMMA0_FX, tmp ); /*Q15 */ - - /* Compute weighted LPC coefficients */ - weight_a_fx( lpccoeff, apond1_fx, g1_fx, LPC_SHB_ORDER ); - weight_a_fx( lpccoeff, apond2_fx, g2_fx, LPC_SHB_ORDER ); - /* o: apond1_fx, apond2_fx in Q12 */ - - /* Compute A(gamma2) residual */ - Residu3_10_fx( apond2_fx, sig_in, sig_ltp_fx + 1, L_SUBFR16k, 0 ); - /* o: sig_ltp_fx in Q_bwe_exc */ - - /* Save last output of 1/A(gamma1) */ - sig_ltp_fx[0] = *ptr_mem_stp; - move16(); - - /* Control short term pst filter gain and compute parcor0 */ - Calc_st_filt_tbe_fx( apond2_fx, apond1_fx, &parcor0_fx, sig_ltp_fx + 1, mem_zero ); - /* o: parcor0 in Q15 */ - /* i/o: sig_ltp_fx in Q_bwe_exc */ - - /* 1/A(gamma1) filtering, mem_stp is updated */ - Syn_filt_s( 0, apond1_fx, LPC_SHB_ORDER, sig_ltp_fx + 1, sig_ltp_fx + 1, L_SUBFR16k, mem_stp, 1 ); - - /* (1 + mu z-1) tilt filtering */ - filt_mu_fx( sig_ltp_fx, sig_out, parcor0_fx, L_SUBFR16k ); - /* o: sig_out in Q_bwe_exc */ - - /* gain control */ - scale_st_swb( sig_in, sig_out, ptr_gain_prec, L_SUBFR16k ); - - return; -} -#endif /*-------------------------------------------------------------------* * flip_spectrum_and_decimby4() diff --git a/lib_dec/dec_post_fx.c b/lib_dec/dec_post_fx.c index e19fc5f94..829005b0a 100644 --- a/lib_dec/dec_post_fx.c +++ b/lib_dec/dec_post_fx.c @@ -1309,11 +1309,7 @@ static void calc_st_filt_local_fx( E_UTIL_synthesis( temp, apond1, apond2, h, LONG_H_ST, mem_zero, 0, M ); /* compute 1st parcor */ -#ifdef HARMONIZE_TBE3 Calc_rc0_h( EVS_MONO, DEC, h, parcor0 ); -#else - Calc_rc0_h( h, parcor0 ); -#endif /* compute g0 */ L_g0 = L_mult0( 1, abs_s( h[0] ) ); // Q12 diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 780f7a2b5..22abfd683 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -407,12 +407,7 @@ ivas_error evs_dec_fx( IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) || ( NE_16( st_fx->coder_type, AUDIO ) && NE_16( st_fx->coder_type, INACTIVE ) && GT_32( st_fx->core_brate, SID_2k40 ) && EQ_16( st_fx->core, ACELP_CORE ) && GE_32( st_fx->output_Fs, 32000 ) && GT_16( st_fx->bwidth, NB ) && st_fx->bws_cnt > 0 && !st_fx->ppp_mode_dec && !( EQ_16( st_fx->nelp_mode_dec, 1 ) && EQ_16( st_fx->bfi, 1 ) ) ) ) { /* SWB TBE decoder */ -#ifdef HARMONIZE_TBE3 swb_tbe_dec_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); -#else - swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, - old_syn_12k8_16k_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); -#endif /* FB TBE decoder */ test(); @@ -848,12 +843,7 @@ ivas_error evs_dec_fx( ELSE IF( EQ_16( st_fx->extl, SWB_TBE ) || EQ_16( st_fx->extl, FB_TBE ) ) { /* SWB TBE decoder */ -#ifdef HARMONIZE_TBE3 swb_tbe_dec_fx( st_fx, NULL, bwe_exc_extended_fx, voice_factors_fx, hBWE_TD->old_core_synth_fx, fb_exc_fx, &Q_fb_exc, hb_synth_fx, NULL, &hb_synth_fx_exp, pitch_buf_fx ); -#else - swb_tbe_dec_fx( st_fx, st_fx->coder_type, bwe_exc_extended_fx, st_fx->Q_exc, voice_factors_fx, hBWE_TD->old_core_synth_fx, - fb_exc_fx, &Q_fb_exc, hb_synth_fx, &hb_synth_fx_exp, pitch_buf_fx ); -#endif test(); IF( EQ_16( st_fx->extl, FB_TBE ) && EQ_16( output_frame, L_FRAME48k ) ) diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 2a11d25a7..164bbc3f1 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -1016,29 +1016,15 @@ ivas_error ivas_core_dec_fx( IF( flag_swb_tbe ) { /* SWB TBE decoder */ -#ifdef HARMONIZE_TBE3 swb_tbe_dec_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, &Q_white_exc, NULL, hb_synth_32_fx[n], NULL, pitch_buf_fx[n] ); -#else - swb_tbe_dec_ivas_fx( st, hStereoICBWE, bwe_exc_extended_fx[n], st->Q_exc, voice_factors_fx[n], old_syn_12k8_16k_fx[n], tmp_buffer_fx /*fb_exc*/, hb_synth_32_fx[n], pitch_buf_fx[n], &Q_white_exc ); -#endif Copy_Scale_sig_16_32_no_sat( hBWE_TD->syn_overlap_fx, hBWE_TD->syn_overlap_fx_32, L_SHB_LAHEAD, sub( Q11, hBWE_TD->prev_Q_bwe_syn2 ) ); // Q11 Copy_Scale_sig_32_16( hBWE_TD->old_tbe_synth_fx_32, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH, sub( hBWE_TD->prev_Qx, Q11 ) ); // prev_Qx -#ifndef HARMONIZE_TBE3 - IF( GT_16( Q_white_exc, 31 ) ) - { - Scale_sig( tmp_buffer_fx, L_FRAME48k, sub( 31, Q_white_exc ) ); // Q31 - Q_white_exc = 31; - move16(); - } -#endif /* FB TBE decoder */ IF( EQ_16( st->extl, FB_TBE ) ) { -#ifdef HARMONIZE_TBE3 // TODO: check why 'Q_synth' is not used instead of 'Q_white_exc' as the second but last paremeter in the following function call -#endif fb_tbe_dec_fx( st, tmp_buffer_fx /*fb_exc*/, Q_white_exc, NULL, hb_synth_32_fx[n], 0, tmp_buffer_fx /*fb_synth_ref*/, Q_white_exc, output_frame ); } } @@ -1129,9 +1115,7 @@ ivas_error ivas_core_dec_fx( q = Q11; move16(); -#ifdef HARMONIZE_TBE3 // TODO: check whether 'Q_synth' is not used instead of 'Q_white_exc' as the last paremeter in the following function call -#endif stereo_icBWE_dec_fx( hCPE, hb_synth_32_fx[0], hb_synth_32_fx[1], tmp_buffer_fx /*fb_synth_ref*/, voice_factors_fx[0], output_frame, &q, Q_white_exc ); test(); diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 827949d68..9adfdcf52 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -1317,1695 +1317,6 @@ void wb_tbe_dec_fx( return; } -#ifndef HARMONIZE_TBE3 -/*======================================================================================*/ -/* FUNCTION : void swb_tbe_dec_fx () */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) coder_type : coding type */ -/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ -/* _(Word16[]) voice_factors :voicing factors Q15 */ -/* _(Word16*) Q_white_exc :Q Format of White Exc */ -/* _(Word16*) Q_synth :Q Format of Synthesis */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16*)synth : SHB synthesis/final synthesis Q_white_exc */ -/* _(Word16*)White_exc16k : shaped white excitation for the FB TBE Q_synth */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Decoder_State *st_fx: : Decoder state structure */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* CALLED FROM : RX */ -/*======================================================================================*/ - -void swb_tbe_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word32 *bwe_exc_extended, /* i : bandwidth extended excitation 2*Q_exc */ - Word16 Q_exc, - const Word16 voice_factors[], /* i : voicing factors */ - const Word16 old_syn_12k8_16k[], /* i : low band synthesis */ - Word16 *White_exc16k, /* o : shaped white excitation for the FB TBE */ - Word16 *Q_white_exc, - Word16 *synth, /* o : SHB synthesis/final synthesis */ - Word16 *Q_synth, - Word16 *pitch_buf /* i : pitch buffer Q6 */ -) -{ - Word16 i; - Word16 shaped_shb_excitation[L_FRAME16k + L_SHB_LAHEAD]; - Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - Word16 lsf_shb[LPC_SHB_ORDER], lpc_shb[LPC_SHB_ORDER + 1], GainShape[NUM_SHB_SUBFR]; - Word32 GainFrame; - Word16 error[L_FRAME32k]; - Word32 L_ener; - Word16 ener; - Word16 is_fractive; - Word32 prev_pow, curr_pow, Lscale; - Word16 scale; - Word16 exp, tmp; - Word16 j, cnt; - Word16 n_mem, n_mem2, Qx, sc; - Word16 n_mem3; - Word32 Lmax, L_tmp; - Word16 frac; - - Word32 L_tmp1, L_tmp2; - Word16 expa, expb; - Word16 fraca, fracb; - Word16 GainShape_tmp[NUM_SHB_SUBGAINS]; - Word16 Q_bwe_exc; - Word16 Q_shb; - Word16 vf_modified[NB_SUBFR16k]; - Word16 stemp; - - Word16 tilt_swb_fec; - Word16 Q_bwe_exc_fb; - - Word16 lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER]; - Word16 lpc_shb_sf[4 * ( LPC_SHB_ORDER + 1 )]; - const Word16 *ptr_lsp_interp_coef; - Word32 shb_ener_sf_32; - Word16 shb_res_gshape[NB_SUBFR16k]; - Word16 mixFactors; - Word16 vind; - Word16 shb_res_dummy[L_FRAME16k]; - Word16 shaped_shb_excitationTemp[L_FRAME16k]; - Word32 ener_tmp[NUM_SHB_SUBGAINS]; - Word16 pitch_fx; - Word16 l_subframe_fx; - Word16 formant_fac; - Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; - Word16 refl[M]; - Word16 tilt_para; - Word16 tmp1, tmp2; - Word16 f_fx, inc_fx; - Word32 GainFrame_prevfrm_fx; - - Word16 synth_scale_fx; - Word16 mean_vf; - Word16 exp_ener, inv_ener; - Word32 prev_ener_ratio_fx = 0; /* initialize just to avoid compiler warning */ - move32(); - Word16 max, n, temp, shaped_shb_excitation_frac[L_FRAME16k + L_SHB_LAHEAD]; - Word32 curr_frame_pow; - Word16 curr_frame_pow_exp; - Word32 L_prev_ener_shb; - TD_BWE_DEC_HANDLE hBWE_TD; - hBWE_TD = st_fx->hBWE_TD; - - /* initializations */ - GainFrame = L_deposit_l( 0 ); - mixFactors = 0; - move16(); - shb_ener_sf_32 = L_deposit_l( 0 ); - set16_fx( shaped_shb_excitationTemp, 0, L_FRAME16k ); - st_fx->hTdCngDec->shb_dtx_count_fx = 0; - move16(); - is_fractive = 0; - move16(); - set16_fx( shb_res_gshape, 1638 /*0.1f Q14*/, NB_SUBFR16k ); /* Q14 */ - Q_shb = 0; /* high band target Q factor set to zero */ - move16(); - L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k, st_fx->Q_syn2, st_fx->L_frame ); - tilt_swb_fec = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); - /* i: old_syn_12k8_16k in st_fx->Q_syn2 */ - /* o: tilt_swb_fec in Q11 */ - test(); - if ( st_fx->bfi && st_fx->clas_dec != UNVOICED_CLAS ) - { - tilt_swb_fec = hBWE_TD->tilt_swb_fec_fx; - move16(); - } - - /* WB/SWB bandwidth switching */ - test(); - test(); - IF( ( GT_16( st_fx->tilt_wb_fx, 10240 ) && ( st_fx->clas_dec == UNVOICED_CLAS ) ) || GT_16( st_fx->tilt_wb_fx, 20480 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( st_fx->prev_fractive == 0 ) && - ( LT_32( st_fx->prev_enerLH_fx, L_shl( st_fx->enerLH_fx, 1 ) ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) && LT_32( st_fx->prev_enerLL_fx, L_shl( st_fx->enerLL_fx, 1 ) ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) ) || - ( EQ_16( st_fx->prev_fractive, 1 ) && - GT_32( L_shr( st_fx->prev_enerLH_fx, 2 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) ) /* 24576 in Q13*/ - || ( GT_32( L_shr( st_fx->enerLL_fx, 1 ), Mult_32_16( st_fx->enerLH_fx, 24576 ) ) && /*24576 = 1.5 in Q14*/ - LT_16( st_fx->tilt_wb_fx, 20480 ) ) /* 20480 = 10 in Q11*/ - ) - { - is_fractive = 0; - move16(); - } - ELSE - { - is_fractive = 1; - move16(); - } - } - - /* WB/SWB bandwidth switching */ - IF( st_fx->bws_cnt > 0 ) - { - f_fx = 1489; /*Q15*/ - move16(); - inc_fx = 1489; /*Q15*/ - move16(); - IF( EQ_16( is_fractive, 1 ) ) - { - Copy( lsf_tab_fx, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); - } - ELSE - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add( f_fx, inc_fx ); - } - } - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) && - !( ( L_sub( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) < 0 ) && L_sub( st_fx->prev_enerLH_fx, ( L_shr( st_fx->enerLH_fx, 1 ) > 0 ) ) ) ) || - ( sub( st_fx->last_core, ACELP_CORE ) != 0 ) || ( ( sub( st_fx->last_core, ACELP_CORE ) == 0 ) && ( L_sub( L_abs( L_sub( st_fx->last_core_brate, st_fx->core_brate ) ), 3600 ) > 0 ) ) || ( sub( s_xor( is_fractive, st_fx->prev_fractive ), 1 ) == 0 ) ) - { - set16_fx( GainShape, 11587, NUM_SHB_SUBFR ); - } - ELSE - { - if ( GT_16( hBWE_TD->prev_GainShape_fx, 11587 ) ) - { - hBWE_TD->prev_GainShape_fx = 11587; - move16(); - } - set16_fx( GainShape, hBWE_TD->prev_GainShape_fx, NUM_SHB_SUBFR ); - } - - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, NB_SUBFR16k ); /* Q14 */ - } - ELSE /* No bandwidth switching */ - { - test(); - IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) - { - f_fx = 1489; /*Q15*/ - move16(); - inc_fx = 1489; /*Q15*/ - move16(); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add( f_fx, inc_fx ); - } - } - - IF( !st_fx->bfi ) - { - IF( st_fx->use_partial_copy ) - { - IF( NE_16( st_fx->last_extl, SWB_TBE ) ) - { - hBWE_TD->GainFrame_prevfrm_fx = 0; - move16(); - f_fx = 1489 /*0.045454f Q15*/; - move16(); - inc_fx = 1489 /*0.045454f Q15*/; - move16(); - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->lsp_prevfrm_fx[i] = f_fx; - move16(); - f_fx = add( f_fx, inc_fx ); - } - } - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - set16_fx( GainShape, RECIP_ROOT_EIGHT_FX, NUM_SHB_SUBFR ); - - IF( EQ_16( st_fx->rf_frame_type, RF_NELP ) ) - { - /* Frame gain */ - GainFrame = L_mac( SHB_GAIN_QLOW_FX, st_fx->rf_indx_tbeGainFr, SHB_GAIN_QDELTA_FX ); - move32(); /*Q18*/ - L_tmp = Mult_32_16( GainFrame, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ - - frac = L_Extract_lc( L_tmp, &exp ); - L_tmp = Pow2( 30, frac ); - GainFrame = L_shl( L_tmp, sub( exp, 12 ) ); /*Q18*/ - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) && !st_fx->prev_use_partial_copy && EQ_16( st_fx->prev_coder_type, UNVOICED ) && NE_32( GainFrame, hBWE_TD->GainFrame_prevfrm_fx ) && NE_16( st_fx->next_coder_type, GENERIC ) && EQ_16( st_fx->last_extl, SWB_TBE ) ) - { - /*GainFrame = 0.2f*GainFrame + 0.8f*st_fx->GainFrame_prevfrm_fx;*/ - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6553 ) ); - } - } - ELSE - { - temp = 0; - move16(); - /* Frame gain */ - SWITCH( st_fx->rf_indx_tbeGainFr ) - { - case 0: - GainFrame = 131072; /* 0.5f in Q18 */ - move32(); - if ( LE_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - case 1: - GainFrame = 524288; /* 2.0f in Q18 */ - move32(); - test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 327680l /*1.25 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - case 2: - GainFrame = 1048576; /* 4.0f in Q18 */ - move32(); - test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 786432l /*3 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - case 3: - GainFrame = 2097152; /* 8.0f in Q18 */ - move32(); - test(); - if ( GT_32( hBWE_TD->GainFrame_prevfrm_fx, 1572864l /*6 Q18*/ ) && LE_32( hBWE_TD->GainFrame_prevfrm_fx, 4194304l /*16Q18*/ ) ) - { - temp = 26214 /*0.8 Q15*/; - move16(); - } - BREAK; - default: - fprintf( stderr, "RF SWB-TBE gain bits not supported." ); - } - IF( EQ_16( st_fx->last_extl, SWB_TBE ) ) - { - GainFrame = L_add( Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, temp ), Mult_32_16( GainFrame, sub( 32767, temp ) ) ); - } - test(); - IF( ( st_fx->core == ACELP_CORE ) && ( st_fx->last_core == ACELP_CORE ) ) - { - test(); - test(); - test(); - test(); - if ( !st_fx->prev_use_partial_copy && EQ_16( st_fx->last_coder_type, VOICED ) && EQ_16( st_fx->rf_frame_type, RF_GENPRED ) && GT_32( GainFrame, 2097152 ) && LT_32( GainFrame, 3059606 ) ) - { - GainFrame = Mult_32_16( GainFrame, 9830 ); - } - } - } - } - ELSE - { - /* de-quantization */ - dequantizeSHBparams_fx( st_fx, st_fx->extl, st_fx->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, - &shb_ener_sf_32, shb_res_gshape, &mixFactors, &j /*temp*/ ); - Q_shb = 0; - move16(); - /* o: shb_ener_sf_32 in (2*Q_shb) */ - /* o: shb_res_gshape in Q14 */ - /* o: GainShape Q15 */ - /* o: GainFrame Q18 */ - } - } - ELSE /* FER concealment of TBE parameters */ - { - Copy( hBWE_TD->lsp_prevfrm_fx, lsf_shb, LPC_SHB_ORDER ); - - /* Gain shape concealment */ - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - /* Gradient based GS estimation */ - gradientGainShape( st_fx, GainShape, &GainFrame ); - /* o: GainShape[16] in Q15 */ - /* o: GainFrame in Q18 */ - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - FOR( j = 0; j < 4; j++ ) - { - GainShape[add( i * 4, j )] = mult_r( st_fx->cummulative_damping, hBWE_TD->GainShape_Delay_fx[4 + i] ); - move16(); - } - } - IF( GT_16( tilt_swb_fec, ( 8 << 11 ) ) ) /* tilt_swb_fec in Q11 */ - { - IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) - { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 19661 /*0.6f Q15*/ ); - } - ELSE IF( EQ_16( st_fx->nbLostCmpt, 2 ) ) - { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 11469 /*0.35f Q15*/ ); - } - ELSE - { - GainFrame = Mult_32_16( hBWE_TD->GainFrame_prevfrm_fx, 6554 /*0.2f Q15*/ ); - } - GainFrame = Mult_32_16( GainFrame, st_fx->cummulative_damping ); - } - ELSE - { - GainFrame = hBWE_TD->GainFrame_prevfrm_fx; - move16(); /* gain locking */ - } - } - - /* FER concealment for 24.4kbps and 32kbps */ - test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - /*scale = st->prev1_shb_ener_sf/root_a(st->prev2_shb_ener_sf * st->prev3_shb_ener_sf); */ - L_tmp = L_mult( extract_l( hBWE_TD->prev2_shb_ener_sf_fx ), extract_l( hBWE_TD->prev3_shb_ener_sf_fx ) ); /*Q1*/ - tmp = round_fx( root_a_fx( L_tmp, 1, &exp ) ); /* Q = 15-exp */ - tmp1 = extract_l( hBWE_TD->prev1_shb_ener_sf_fx ); /*Q0*/ - i = sub( norm_s( tmp1 ), 1 ); - tmp1 = shl( tmp1, i ); /* Qi */ - IF( tmp == 0 ) - { - tmp = 32767 /*1.0f Q15*/; - move16(); /*Q15*/ - } - ELSE - { - scale = div_s( tmp1, tmp ); /* Q15 - Q(15-exp) + Qi = Qexp+i */ - scale = s_max( scale, 0 ); - /*scale = st->prev_res_shb_gshape * min(scale, 1.0f); */ - tmp = shl_sat( scale, sub( sub( 15, exp ), i ) ); /*Q15*/ - } - scale = mult_r( hBWE_TD->prev_res_shb_gshape_fx, tmp ); /* Q14 */ - - test(); - IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || - GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) - { - /* shb_ener_sf_32 = 0.5f * scale * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, scale ); - - if ( GT_16( st_fx->nbLostCmpt, 1 ) ) - { - /* shb_ener_sf_32 *= 0.5f; */ - shb_ener_sf_32 = L_shr( shb_ener_sf_32, 1 ); - } - } - ELSE - { - /* shb_ener_sf = scale * scale * st_fx->prev1_shb_ener_sf_fx; */ - L_tmp = L_mult( scale, scale ); /* Q29 */ - shb_ener_sf_32 = L_shl( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, round_fx( L_tmp ) ), 2 ); - } - } - ELSE - { - test(); - IF( GT_32( L_shr( hBWE_TD->prev2_shb_ener_sf_fx, 1 ), hBWE_TD->prev1_shb_ener_sf_fx ) || - GT_32( L_shr( hBWE_TD->prev3_shb_ener_sf_fx, 1 ), hBWE_TD->prev2_shb_ener_sf_fx ) ) - { - /* shb_ener_sf_32 = 0.5f * st->cummulative_damping * st_fx->prev1_shb_ener_sf_fx; */ - shb_ener_sf_32 = L_shr( Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ), 1 ); - } - ELSE - { - shb_ener_sf_32 = Mult_32_16( hBWE_TD->prev1_shb_ener_sf_fx, st_fx->cummulative_damping ); - } - } - } - - shb_ener_sf_32 = L_max( shb_ener_sf_32, 1l /*1.0f Q0*/ ); - mixFactors = hBWE_TD->prev_mixFactors_fx; - move16(); - - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - set16_fx( shb_res_gshape, 3277 /*0.2f Q14*/, 5 ); /* Q14 */ - } - ELSE - { - set16_fx( shb_res_gshape, 16384 /*1.0f Q14*/, 5 ); /* Q14 */ - } - } - } - - /* get the gainshape delay */ - Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); - test(); - IF( ( st_fx->rf_flag != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - hBWE_TD->GainShape_Delay_fx[i + 4] = s_min( s_max( GainShape[i * 4], 3277 /*0.1f Q15*/ ), 16384 /*0.5f Q15*/ ); - move16(); - } - } - ELSE - { - FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) - { - hBWE_TD->GainShape_Delay_fx[i + 4] = GainShape[i * 4]; - move16(); - } - } - - /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ - /* mean(voice_factors[i], 4); */ - L_tmp = L_mult( voice_factors[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors[2], 8192 ); - mean_vf = mac_r( L_tmp, voice_factors[3], 8192 ); - - Copy( voice_factors, vf_modified, NB_SUBFR16k ); - - test(); - IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mult( voice_factors[i], 26214 /*0.8f Q15*/ ); - vf_modified[i] = mac_r( L_tmp, voice_factors[i - 1], 6554 /*0.2f Q15*/ ); - move16(); - } - IF( NE_16( st_fx->L_frame, L_FRAME ) ) - { - L_tmp = L_mult( voice_factors[4], 26214 /*0.8f Q15*/ ); - vf_modified[4] = mac_r( L_tmp, voice_factors[3], 6554 /*0.2f Q15*/ ); - move16(); - } - } - - /* convert quantized LSFs to LSPs for interpolation */ - E_LPC_lsf_lsp_conversion( lsf_shb, lsp_shb_2, LPC_SHB_ORDER ); - - test(); - IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) - { - /* SHB LSP values from prev. frame for interpolation */ - Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1, LPC_SHB_ORDER ); - } - ELSE - { - /* Use current frame's LSPs; in effect no interpolation */ - Copy( lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER ); - } - - test(); - test(); - test(); - IF( ( st_fx->bws_cnt == 0 ) && ( st_fx->bws_cnt1 == 0 ) && ( st_fx->prev_use_partial_copy == 0 ) && ( st_fx->use_partial_copy == 0 ) ) - { - lsf_diff[0] = 16384; - move16(); /*Q15*/ - lsf_diff[LPC_SHB_ORDER - 1] = 16384; - move16(); /*Q15*/ - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - lsf_diff[i] = sub( lsf_shb[i], lsf_shb[i - 1] ); - move16(); - } - - a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); - tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ - tmp1 = mult( 27425, tmp ); - tmp1 = mult( tmp1, tmp ); /*Q10*/ - tmp2 = shr( mult( 31715, tmp ), 2 ); /*Q10*/ - tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ - - test(); - IF( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) - { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - hBWE_TD->prev_lsf_diff_fx[i - 1] = shr( lsf_diff[i], 1 ); - move16(); - } - } - - IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) - { - test(); - test(); - test(); - test(); - test(); - IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && - !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( st_fx->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) - { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) - { - tmp = mult( 26214, lsf_diff[i] ); - - test(); - IF( ( hBWE_TD->prev_lsf_diff_fx[i - 1] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ - { - st_fx->BER_detect = 1; - move16(); - tmp = 0; - move16(); - } - ELSE - { - tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - } - - tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); - move16(); - } - ELSE - { - tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - - test(); - IF( ( lsf_diff[i] <= 0 ) || ( tmp < 0 ) ) /* safety check in case of bit errors */ - { - st_fx->BER_detect = 1; - move16(); - tmp = 0; - move16(); - } - ELSE - { - tmp = div_s( tmp, lsf_diff[i] ); - } - - tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); - move16(); - } - } - w[0] = w[1]; - move16(); - w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; - move16(); - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tmp1 = mult( lsp_shb_1[i], sub( 32767, w[i] ) ); - tmp2 = mult( lsp_shb_2[i], w[i] ); - lsp_temp[i] = add( tmp1, tmp2 ); - move16(); - } - } - ELSE - { - Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); - } - } - - Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = tilt_para; - move16(); - } - ELSE - { - Copy( lsp_shb_2, lsp_temp, LPC_SHB_ORDER ); - } - - test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) - { - /* ---------- SHB LSP interpolation ---------- */ - ptr_lsp_interp_coef = interpol_frac_shb; /*Q15*/ - FOR( j = 0; j < 4; j++ ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ - /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1));*/ - L_tmp = L_mult( lsp_shb_1[i], ( *ptr_lsp_interp_coef ) ); - lsp_temp[i] = mac_r( L_tmp, lsp_shb_2[i], ( *( ptr_lsp_interp_coef + 1 ) ) ); - move16(); - } - ptr_lsp_interp_coef += 2; - - /* convert from lsp to lsf */ - /*old code: lsp2lsf_fx(lsp_temp, lsp_temp, LPC_SHB_ORDER, INT_FS_FX); */ /* input lsp_temp_fx in Q15*/ - - tmp = i_mult( j, LPC_SHB_ORDER + 1 ); - /* convert LSPs to LP coefficients */ - E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb_sf + tmp, LPC_SHB_ORDER ); - /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf + tmp, lpc_shb_sf + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf[tmp] ), 2 ) ); - } - } - /*ELSE*/ - { - /* for 13.2 and 16.4kbps */ - E_LPC_f_lsp_a_conversion( lsp_temp, lpc_shb, LPC_SHB_ORDER ); - Copy_Scale_sig( lpc_shb, lpc_shb, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb[0] ), 2 ) ); /* Q12 */ - } - - /* Save the SWB LSP values from current frame for interpolation */ - Copy( lsp_shb_2, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); - /* lsp_shb_2_fx in Q15 */ - - /* save the shb_ener Q18, prev_resgainshape Q14, and mixFactor Q15 values */ - hBWE_TD->prev3_shb_ener_sf_fx = hBWE_TD->prev2_shb_ener_sf_fx; - move32(); - hBWE_TD->prev2_shb_ener_sf_fx = hBWE_TD->prev1_shb_ener_sf_fx; - move32(); - hBWE_TD->prev1_shb_ener_sf_fx = shb_ener_sf_32; - move32(); - hBWE_TD->prev_res_shb_gshape_fx = shb_res_gshape[4]; - move16(); - hBWE_TD->prev_mixFactors_fx = mixFactors; - move16(); - - /* SWB CNG/DTX - update memories */ - if ( st_fx->hTdCngDec != NULL ) - { - Copy( st_fx->hTdCngDec->lsp_shb_prev_fx, st_fx->hTdCngDec->lsp_shb_prev_prev_fx, LPC_SHB_ORDER ); /* Q15 */ - Copy( lsf_shb, st_fx->hTdCngDec->lsp_shb_prev_fx, LPC_SHB_ORDER ); /* Q15 */ - } - - /* vind = (short)(mixFactors*8.0f); */ - vind = shl( mixFactors, 3 - 15 ); /* 3 for mpy by 8.0f, -15 to bring it to Q0 */ - /* i: mixFactors in Q15 */ - /* o: vind in Q0 */ - - /* Determine formant PF strength */ - formant_fac = swb_formant_fac_fx( lpc_shb[1], &hBWE_TD->tilt_mem_fx ); - /* o: formant_fac in Q15 */ - - /* -------- start of memory rescaling -------- */ - /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ - Lmax = 0; - move32(); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - Q_bwe_exc = norm_l( Lmax ); - if ( Lmax == 0 ) - { - Q_bwe_exc = 31; - move16(); - } - Q_bwe_exc = add( Q_bwe_exc, add( Q_exc, Q_exc ) ); - - /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ - find_max_mem_dec( st_fx, &n_mem, &n_mem2, &n_mem3 ); /* for >=24.4, use n_mem2 lpc_syn, shb_20sample, and mem_stp_swb_fx memory */ - - tmp = add( st_fx->prev_Q_bwe_exc, n_mem ); - if ( GT_16( Q_bwe_exc, tmp ) ) - { - Q_bwe_exc = tmp; - move16(); - } - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, st_fx->prev_Q_bwe_exc ); - IF( sc != 0 ) - { - rescale_genSHB_mem_dec( st_fx, sc ); - } - - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); - - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); - } - Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - - /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation, L_SHB_LAHEAD ); - - /* save the previous Q factor (32-bit) of the buffer */ - st_fx->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - - Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - - /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; - move16(); - - IF( GT_32( st_fx->total_brate, ACELP_32k ) ) - { - FOR( j = 0; j < 4; j++ ) - { - Copy( lpc_shb, &lpc_shb_sf[i_mult( j, LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 ); - } - } - - /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the low band ACELP core excitation */ - GenShapedSHBExcitation_fx( shaped_shb_excitation + L_SHB_LAHEAD, lpc_shb, White_exc16k, - hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - coder_type, st_fx->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified, st_fx->extl, - &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf, shb_ener_sf_32, - shb_res_gshape, shb_res_dummy, &vind, formant_fac, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, st_fx->prev_bfi ); - - *Q_white_exc = Q_bwe_exc_fb; - move16(); - IF( EQ_16( st_fx->extl, FB_TBE ) ) - { - hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; - move16(); - } - ELSE - { - /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. - 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - hBWE_TD->prev_Q_bwe_exc_fb = 51; - move16(); - } - /* rescale the TBE post proc memory */ - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) - { - /* TD BWE post-processing */ - PostShortTerm_fx( &shaped_shb_excitation[L_SHB_LAHEAD + i], lpc_shb, &shaped_shb_excitationTemp[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac ); - } - Copy( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ - - tmp = sub( shl( Q_bwe_exc, 1 ), 31 + 16 ); - prev_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ - curr_pow = L_shl_sat( 1407374848l /*0.00001f Q47*/, tmp ); /* 2*(Q_bwe_exc) */ - FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) - { - prev_pow = L_mac0_sat( prev_pow, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /*2*Q_bwe_exc*/ - curr_pow = L_mac0_sat( curr_pow, shaped_shb_excitation[i + L_SHB_LAHEAD + 10], shaped_shb_excitation[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ - } - - if ( GT_16( voice_factors[0], 24576 /*0.75f Q15*/ ) ) - { - curr_pow = L_shr( curr_pow, 2 ); /* Q(2*Q_bwe_exc) */ - } - - Lscale = root_a_over_b_fx( curr_pow, shl( Q_bwe_exc, 1 ), prev_pow, shl( Q_bwe_exc, 1 ), &exp ); - - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - IF( exp < 0 ) - { - Lscale = L_shl( Lscale, exp ); - exp = 0; - move16(); - } - /* - code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues - thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations - */ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - temp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ - temp = sub( 32767 /*1.0f Q15*/, temp ); - Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - ELSE - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - temp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), temp ); /* Q31-exp */ - temp = sub( 32767 /*1.0f Q15*/, temp ); - Lscale = L_add( Mult_32_16( Lscale, temp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - - /* Update SHB excitation */ - Copy( shaped_shb_excitation + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - - l_subframe_fx = L_FRAME16k / NUM_SHB_SUBGAINS; - L_ener = 0; - move32(); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - L_tmp = 0; - move32(); - ener_tmp[i] = 0; - move32(); - { - Word64 tmp64 = 0; - move64(); - FOR( j = 0; j < l_subframe_fx; j++ ) - { - tmp64 = W_mac0_16_16( tmp64, shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )], shaped_shb_excitation[add( i_mult( i, l_subframe_fx ), j )] ); /* 2*Q_bwe_exc */ - } - L_tmp = W_sat_l( tmp64 ); - } - - L_tmp = Mult_32_16( L_tmp, 410 /*0.0125 Q15*/ ); /* 2*Q_bwe_exc: ener_tmp_fx in (2*Q_bwe_exc) */ - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, sub( 30, i_mult( 2, Q_bwe_exc ) ) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - ener_tmp[i] = L_shl_sat( L_tmp, sub( add( exp, shl( Q_bwe_exc, 1 ) ), 31 ) ); /*2 * Q_bwe_exc: Q31 -exp +exp +2 * Q_bwe_exc -31 */ - move32(); - L_ener = L_add_sat( L_ener, L_shr( ener_tmp[i], 2 ) ); /* 2*Q_bwe_exc */ - } - } - ener = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ - /* WB/SWB bandwidth switching */ - IF( st_fx->bws_cnt > 0 ) - { - ener = mult( ener, 11587 ); - /*bandwidth switching should be updated*/ - if ( GT_16( st_fx->tilt_swb_fx, 16384 ) ) - { - st_fx->prev_fractive = 1; - move16(); - } - - IF( is_fractive == 0 ) - { - IF( GT_16( st_fx->tilt_wb_fx, 2048 ) ) /*assuming st_fx->tilt_wb_fx in Q11*/ - { - st_fx->tilt_wb_fx = 2048; - move16(); - } - ELSE IF( LT_16( st_fx->tilt_wb_fx, 1024 ) ) - { - st_fx->tilt_wb_fx = 1024; - move16(); - } - test(); - if ( EQ_16( st_fx->prev_fractive, 1 ) && GT_16( st_fx->tilt_wb_fx, 1024 ) ) - { - st_fx->tilt_wb_fx = 1024; - move16(); - } - } - ELSE - { - IF( GT_16( st_fx->tilt_wb_fx, 8192 ) ) - { - IF( st_fx->prev_fractive == 0 ) - { - st_fx->tilt_wb_fx = 8192; - move16(); - } - ELSE - { - st_fx->tilt_wb_fx = 16384; - move16(); - } - } - ELSE - { - st_fx->tilt_wb_fx = shl( st_fx->tilt_wb_fx, 2 ); - move16(); - } - } - - IF( ener != 0 ) - { - L_tmp = L_shl( L_mult0( ener, st_fx->tilt_wb_fx ), sub( st_fx->Q_syn2, 14 ) ); /* 3+11 +st_fx->Q_syn2 -14 = st_fx->Q_syn2*/ - exp_ener = norm_s( ener ); - tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ - inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp) = 26- exp*/ - - test(); - IF( GT_32( L_tmp, st_fx->enerLH_fx ) ) /*st_fx->Q_syn2*/ - { - st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 16 ) ) ); /*Q11*/ - move16(); - /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -16 ) -16 +1 -1 = (11) *0.5*/ - } - ELSE IF( LT_32( L_tmp, Mult_32_16( st_fx->enerLH_fx, 1638 ) ) && EQ_16( is_fractive, 1 ) ) - { - st_fx->tilt_wb_fx = extract_h( L_shr_sat( Mult_32_16( st_fx->enerLH_fx, inv_ener ), sub( sub( st_fx->Q_syn2, exp_ener ), 15 ) ) ); /*Q11*/ - move16(); - /*st_fx->Q_syn2 -1 + 26- exp_ener -15 -(st_fx->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ - } - L_tmp = L_mult0( st_fx->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ - GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ - } - ELSE - { - GainFrame_prevfrm_fx = 0; - move32(); - } - - IF( EQ_16( is_fractive, 1 ) ) - { - GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 10 ); - } - ELSE - { - GainFrame = L_shl( L_deposit_l( st_fx->tilt_wb_fx ), 8 ); - } - - test(); - IF( EQ_16( s_and( is_fractive, st_fx->prev_fractive ), 1 ) && GT_32( GainFrame, GainFrame_prevfrm_fx ) ) - { - GainFrame = L_add( Mult_32_16( GainFrame_prevfrm_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); /* 18 +15 -15 = 18*/ - } - ELSE - { - test(); - test(); - test(); - test(); - IF( ( LT_32( L_shr( st_fx->prev_enerLH_fx, 1 ), st_fx->enerLH_fx ) && GT_32( st_fx->prev_enerLH_fx, L_shr( st_fx->enerLH_fx, 1 ) ) ) && ( LT_32( L_shr( st_fx->prev_enerLL_fx, 1 ), st_fx->enerLL_fx ) && GT_32( st_fx->prev_enerLL_fx, L_shr( st_fx->enerLL_fx, 1 ) ) ) && ( s_xor( is_fractive, st_fx->prev_fractive ) == 0 ) ) - { - GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( GainFrame_prevfrm_fx, 1 ) ); - } - ELSE - { - test(); - IF( ( is_fractive == 0 ) && EQ_16( st_fx->prev_fractive, 1 ) ) - { - L_tmp1 = L_shl( Mult_32_16( GainFrame, 3277 ), 13 ); /* 31 */ - L_tmp = L_sub( 2147483647, L_tmp1 ); /* 31 */ - GainFrame = L_add( Mult_32_32( GainFrame, L_tmp ), Mult_32_32( GainFrame_prevfrm_fx, L_tmp1 ) ); /* 18 */ - } - ELSE - { - GainFrame = L_add( L_shr( GainFrame, 1 ), L_shr( L_min( GainFrame_prevfrm_fx, GainFrame ), 1 ) ); /* 18 */ - } - } - } - - GainFrame = Mult_32_16( GainFrame, i_mult( sub( N_WS2N_FRAMES, st_fx->bws_cnt ), 819 ) ); /*Q18*/ - } - ELSE - { - if ( st_fx->bws_cnt1 > 0 ) - { - GainFrame = Mult_32_16( GainFrame, i_mult( st_fx->bws_cnt1, 819 ) ); /*Q18*/ - } - IF( GE_16( st_fx->nbLostCmpt, 1 ) ) - { - ener = s_max( 1, ener ); - exp_ener = norm_s( ener ); - tmp = shl( ener, exp_ener ); /*Q(3+exp)*/ - inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp)*/ - prev_ener_ratio_fx = L_shr_sat( L_mult0( st_fx->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ - } - - IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( st_fx->clas_dec != UNVOICED_CLAS ) && NE_16( st_fx->clas_dec, UNVOICED_TRANSITION ) && LT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) && - ( ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLL_fx, 1 ), st_fx->prev_enerLL_fx ) ) || ( GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) && LT_32( L_shr( st_fx->enerLH_fx, 1 ), st_fx->prev_enerLH_fx ) ) ) ) - { - IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) ) /*18*/ - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 13107 ), Mult_32_16( GainFrame, 19661 ) ); /*18*/ - } - ELSE IF( GT_32( L_shr( prev_ener_ratio_fx, 1 ), GainFrame ) ) - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ); - } - ELSE - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); - } - - test(); - IF( GT_16( tilt_swb_fec, hBWE_TD->tilt_swb_fec_fx ) && ( hBWE_TD->tilt_swb_fec_fx > 0 ) ) - { - exp = norm_s( hBWE_TD->tilt_swb_fec_fx ); - tmp = shl( hBWE_TD->tilt_swb_fec_fx, exp ); /*Q(11+exp)*/ - tmp = div_s( 16384, tmp ); /*Q(15+14-11-exp)*/ - tmp = extract_h( L_shl( L_mult0( tmp, st_fx->tilt_wb_fx ), sub( exp, 1 ) ) ); /*18 -exp +11 + exp -1 -16 =12; */ - GainFrame = L_shl( Mult_32_16( GainFrame, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ - } - } - ELSE IF( ( ( st_fx->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 16384 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && - ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) ) - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); - } - } - ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) - { - test(); - IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) - { - GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 26214 ), Mult_32_16( GainFrame, 6554 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ - } - ELSE - { - GainFrame = L_min( L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ), L_shl( Mult_32_16( GainFrame, 16384 ), 3 ) ); /*Q18*/ - } - } - ELSE IF( GT_32( prev_ener_ratio_fx, GainFrame ) && ( ( EQ_16( st_fx->codec_mode, MODE1 ) && GT_32( st_fx->enerLL_fx, st_fx->prev_enerLL_fx ) && GT_32( st_fx->enerLH_fx, st_fx->prev_enerLH_fx ) ) || EQ_16( st_fx->codec_mode, MODE2 ) ) ) - { - test(); - IF( GT_16( tilt_swb_fec, 20480 ) && GT_16( hBWE_TD->tilt_swb_fec_fx, 20480 ) ) - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 16384 ), Mult_32_16( GainFrame, 16384 ) ); - } - ELSE - { - GainFrame = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame, 26214 ) ); - } - } - } - } - st_fx->prev_fractive = is_fractive; - move16(); - - /* Adjust the subframe and frame gain of the synthesized shb signal */ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - /* pitch = 0.25f*sum_s(pitch_buf, 4); */ - L_tmp = L_mult( pitch_buf[0], 8192 ); - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mac( L_tmp, pitch_buf[i], 8192 ); /* pitch_buf in Q6 x 0.25 in Q15 */ - } - pitch_fx = round_fx( L_tmp ); /* Q6 */ - } - ELSE - { - /* pitch_fx = 0.2f*sum_s(pitch_buf, 5); */ - L_tmp = L_mult( pitch_buf[0], 6554 ); - FOR( i = 1; i < NB_SUBFR16k; i++ ) - { - L_tmp = L_mac( L_tmp, pitch_buf[i], 6554 ); /* pitch_buf in Q6 x 0.2 in Q15 */ - } - pitch_fx = round_fx( L_tmp ); /* Q6 */ - } - - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( ( ( GE_32( st_fx->total_brate, ACELP_24k40 ) && EQ_16( st_fx->prev_coder_type, coder_type ) && NE_16( coder_type, UNVOICED ) ) || ( LE_32( st_fx->total_brate, ACELP_16k40 ) && ( EQ_16( st_fx->prev_coder_type, coder_type ) || ( EQ_16( st_fx->prev_coder_type, VOICED ) && EQ_16( coder_type, GENERIC ) ) || ( EQ_16( st_fx->prev_coder_type, GENERIC ) && EQ_16( coder_type, VOICED ) ) ) ) ) && GT_16( pitch_fx, 4480 /*70 in Q6*/ ) && LT_16( st_fx->extl, FB_TBE ) ) - { - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - GainShape_tmp[i] = GainShape[i * 4]; /* Q15 */ - move16(); - } - - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /* if( ener_tmp_fx[i]*GainShape_tmp_fx[i] > st_fx->prev_ener_fx*st_fx->prev_GainShape_fx ) */ - L_tmp1 = Mult_32_16( ener_tmp[i], GainShape_tmp[i] ); /* (2*Q_bwe_exc) */ - L_tmp2 = Mult_32_16( hBWE_TD->prev_ener_fx, hBWE_TD->prev_GainShape_fx ); /* (2*st_fx->prev_ener_fx_Q) */ - tmp = sub( shl( Q_bwe_exc, 1 ), shl( hBWE_TD->prev_ener_fx_Q, 1 ) ); - L_tmp2 = L_shl_sat( L_tmp2, tmp ); /* new Q = (2*Q_bwe_exc) */ - IF( GT_32( L_tmp1, L_tmp2 ) ) - { - /*GainShape_tmp_fx[i] = 0.5f*(L_tmp2/ener_tmp_fx[i] + GainShape_tmp_fx[i]);*/ - /* tmp = L_tmp2/ener_tmp_fx[i]*/ - L_tmp = L_tmp2; - move32(); - if ( L_tmp2 < 0 ) - { - L_tmp = L_negate( L_tmp2 ); - } - - expb = norm_l( L_tmp ); - fracb = round_fx_sat( L_shl_sat( L_tmp, expb ) ); - expb = sub( 30, expb ); /* - (2*Q_bwe_exc_ext); */ - - expa = norm_l( ener_tmp[i] ); - fraca = extract_h( L_shl( ener_tmp[i], expa ) ); - expa = sub( 30, expa ); - - scale = shr( sub( fraca, fracb ), 15 ); - fracb = shl( fracb, scale ); - expb = sub( expb, scale ); - - tmp = div_s( fracb, fraca ); - exp = sub( sub( expb, expa ), 1 ); - tmp = shl( tmp, exp ); - GainShape_tmp[i] = add( tmp, shr( GainShape_tmp[i], 1 ) ); /* Q15 */ - move16(); - } - - hBWE_TD->prev_ener_fx = ener_tmp[i]; - move32(); - hBWE_TD->prev_GainShape_fx = GainShape_tmp[i]; - move16(); - hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; - move16(); - } - FOR( i = 0; i < NUM_SHB_SUBFR; i++ ) - { - Word16 idx = 0; - move16(); - IF( i != 0 ) - { - idx = idiv1616( i_mult( i, NUM_SHB_SUBGAINS ), NUM_SHB_SUBFR ); - } - GainShape[i] = GainShape_tmp[idx]; - move16(); - } - } - ELSE - { - hBWE_TD->prev_ener_fx_Q = Q_bwe_exc; - move16(); - } - - - /* Back up the Q_bwe_exc associated with shaped_shb_excitation for the next frame*/ - hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; - move16(); - - /* Scale the shaped excitation */ - ScaleShapedSHB_fx( SHB_OVERLAP_LEN, - shaped_shb_excitation, /* i/o: Q_bwe_exc */ - hBWE_TD->syn_overlap_fx, - GainShape, /* Q15 */ - GainFrame, /* Q18 */ - window_shb_fx, - subwin_shb_fx, - &Q_bwe_exc, &Qx, n_mem3, hBWE_TD->prev_Q_bwe_syn2 ); - - max = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - max = s_max( max, shaped_shb_excitation[i] ); /* Q0 */ - } - - IF( max == 0 ) - { - curr_frame_pow = 0; - move16(); - n = 0; - move16(); - } - ELSE - { - n = norm_s( max ); - max = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - shaped_shb_excitation_frac[i] = shl_sat( shaped_shb_excitation[i], n ); /*Q_bwe_exc+n*/ - move16(); - } - - curr_frame_pow = 0; - move32(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp = L_mult0( shaped_shb_excitation_frac[i], shaped_shb_excitation_frac[i] ); /*2*(Q_bwe_exc+n)*/ - curr_frame_pow = L_add( curr_frame_pow, L_shr( L_tmp, 9 ) ); /*2*(Q_bwe_exc+n)-9*/ - } - } - curr_frame_pow_exp = sub( shl( add( Q_bwe_exc, n ), 1 ), 9 ); - - - tmp = sub( hBWE_TD->prev_frame_pow_exp, curr_frame_pow_exp ); - IF( tmp > 0 ) /* shifting prev */ - { - IF( GT_16( tmp, 32 ) ) - { - hBWE_TD->prev_frame_pow_exp = add( curr_frame_pow_exp, 32 ); - move16(); - tmp = 32; - move16(); - } - hBWE_TD->prev_swb_bwe_frame_pow_fx = L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, tmp ); - move32(); - hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); - } - ELSE /* shifting curr */ - { - IF( LT_16( tmp, -32 ) ) - { - curr_frame_pow_exp = sub( hBWE_TD->prev_frame_pow_exp, 32 ); - tmp = -32; - move16(); - } - curr_frame_pow = L_shr( curr_frame_pow, -tmp ); - curr_frame_pow_exp = hBWE_TD->prev_frame_pow_exp; - move16(); - } - test(); - IF( !st_fx->bfi && st_fx->prev_bfi ) - { - L_tmp = L_shr( curr_frame_pow, 4 ); - L_tmp = Mult_32_16( L_tmp, 17476 ); - - test(); - test(); - IF( ( GT_32( L_shr( curr_frame_pow, 1 ), hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) && - ( GT_32( hBWE_TD->prev_swb_bwe_frame_pow_fx, L_tmp ) ) && EQ_16( st_fx->prev_coder_type, UNVOICED ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, exp ) ); /*Q15*/ - } - ELSE - { - scale = temp = 32767; - move16(); /*Q15*/ - } - FOR( j = 0; j < 8; j++ ) - { - GainShape[2 * j] = mult_r( GainShape[2 * j], scale ); - move16(); - GainShape[add( 2 * j, 1 )] = mult_r( GainShape[add( 2 * j, 1 )], scale ); - move16(); - FOR( i = 0; i < L_FRAME16k / 8; i++ ) - { - shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )] = mult_r( shaped_shb_excitation[add( i, j * ( L_FRAME16k / 8 ) )], scale ); - move16(); - } - - IF( temp > 0 ) - { - /* scale <= temp, due to scale = sqrt( st->prev_swb_bwe_frame_pow_fx/curr_frame_pow ), temp = sqrt( scale, 1.f/8.f ) - and curr_frame_pow > st->prev_swb_bwe_frame_pow_fx -> scale <= 1.0, sqrt(scale, 1.f/8.f) >= scale */ - IF( LT_16( scale, temp ) ) - { - scale = div_s( scale, temp ); - } - ELSE - { - scale = 32767; - move16(); - } - } - ELSE - { - scale = 0; - move16(); - } - } - } - - /* adjust the FEC frame energy */ - IF( st_fx->bfi ) - { - scale = temp = 4096; - move16(); /*Q12*/ - - IF( EQ_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - test(); - test(); - test(); - IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) && - NE_16( st_fx->prev_coder_type, UNVOICED ) && - ( st_fx->last_good != UNVOICED_CLAS ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); /*31 - exp*/ - scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } - ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && EQ_16( st_fx->nbLostCmpt, 1 ) && - ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && - ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } - } - ELSE IF( GT_16( st_fx->nbLostCmpt, 1 ) ) - { - test(); - test(); - test(); - test(); - test(); - IF( GT_32( curr_frame_pow, hBWE_TD->prev_swb_bwe_frame_pow_fx ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } - ELSE IF( LT_32( curr_frame_pow, L_shr( hBWE_TD->prev_swb_bwe_frame_pow_fx, 1 ) ) && - ( GT_32( st_fx->enerLL_fx, L_shr( st_fx->prev_enerLL_fx, 1 ) ) || GT_32( st_fx->enerLH_fx, L_shr( st_fx->prev_enerLH_fx, 1 ) ) ) && - ( EQ_16( st_fx->prev_coder_type, UNVOICED ) || ( st_fx->last_good == UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 10240 ) ) ) - { - L_tmp = root_a_over_b_fx( hBWE_TD->prev_swb_bwe_frame_pow_fx, curr_frame_pow_exp, curr_frame_pow, curr_frame_pow_exp, &exp ); - L_tmp = L_min( L_tmp, L_shl_sat( 2, sub( 31, exp ) ) ); /*31 - exp*/ - scale = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - L_tmp = root_a_fx( L_tmp, sub( 31, exp ), &exp ); - temp = round_fx( L_shl( L_tmp, sub( exp, 3 ) ) ); /*Q12*/ - } - } - FOR( j = 0; j < 8; j++ ) - { - GainShape[2 * j] = shl_sat( mult_r( GainShape[2 * j], scale ), 3 ); - move16(); /* 15 +12 +3-15 =15*/ - GainShape[add( 2 * j, 1 )] = shl_sat( mult_r( GainShape[add( 2 * j, 1 )], scale ), 3 ); - move16(); - FOR( i = 0; i < 40; i++ ) - { - shaped_shb_excitation[add( i, j * 40 )] = shl_sat( mult_r( shaped_shb_excitation[add( i, j * 40 )], scale ), 3 ); - move16(); /* Q_bwe_exc +12+3 -15 =Q_bwe_exc*/ - } - - IF( temp > 0 ) - { - IF( LT_16( scale, temp ) ) - { - scale = shr( div_s( scale, temp ), 3 ); - } - ELSE - { - tmp1 = sub( norm_s( scale ), 1 ); - tmp2 = norm_s( temp ); - scale = div_s( shl( scale, tmp1 ), shl( temp, tmp2 ) ); - scale = shr( scale, add( sub( tmp1, tmp2 ), 3 ) ); - } - } - ELSE - { - scale = 0; - move16(); - } - } - } - - hBWE_TD->prev_swb_bwe_frame_pow_fx = curr_frame_pow; - move32(); - hBWE_TD->prev_frame_pow_exp = curr_frame_pow_exp; - move16(); - - { - Word64 prev_ener_shb64 = 0; - move64(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - prev_ener_shb64 = W_mac0_16_16( prev_ener_shb64, shaped_shb_excitation[i], shaped_shb_excitation[i] ); /* Q0 */ - } - L_prev_ener_shb = W_sat_l( prev_ener_shb64 ); - } - - /* st->prev_ener_shb = sqrt(st->prev_ener_shb/L_FRAME16k) */ - L_prev_ener_shb = Mult_32_16( L_prev_ener_shb, 26214 ); /* 2*Q_bwe_exc_mod+8; 26214=(1/L_FRAME16k) in Q23 */ - st_fx->prev_ener_shb_fx = 0; - move16(); - - IF( L_prev_ener_shb != 0 ) - { - exp = norm_l( L_prev_ener_shb ); - tmp = extract_h( L_shl( L_prev_ener_shb, exp ) ); - exp = sub( exp, sub( 30, ( add( i_mult( 2, Q_bwe_exc ), 8 ) ) ) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - st_fx->prev_ener_shb_fx = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ - move16(); - } - /* st->prev_SWB_fenv[i] = sqrt(curr_frame_pow/L_FRAME16k); */ - L_tmp = Mult_32_16( curr_frame_pow, 26214 ); /* curr_frame_pow_exp+8; 26214=(1/L_FRAME16k) in Q23 */ - tmp = 0; - move16(); - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( exp, sub( 30, add( curr_frame_pow_exp, 8 ) ) ); - - tmp = div_s( 16384, tmp ); - L_tmp = L_deposit_h( tmp ); - L_tmp = Isqrt_lc( L_tmp, &exp ); - tmp = round_fx_sat( L_shl_sat( L_tmp, sub( exp, 14 ) ) ); /* Q1 */ - } - set16_fx( st_fx->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn2 ); - IF( sc != 0 ) - { - FOR( i = 0; i < 2 * ALLPASSSECTIONS_STEEP; i++ ) - { - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i] = shl( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx[i], sc ); - move16(); - } - - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - FOR( i = 0; i < HILBERT_MEM_SIZE; i++ ) - { - hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i] = L_shl( hBWE_TD->genSHBsynth_Hilbert_Mem_fx[i], sc ); - move32(); - } - } - IF( EQ_32( st_fx->output_Fs, 48000 ) ) - { - Scale_sig( hBWE_TD->int_3_over_2_tbemem_dec_fx, INTERP_3_2_MEM_LEN, sc ); - } - IF( EQ_32( st_fx->output_Fs, 16000 ) ) - { - Scale_sig( hBWE_TD->mem_resamp_HB_32k_fx, 2 * ALLPASSSECTIONS_STEEP + 1, sc ); - } - } - /* i: shaped_shb_excitation[320] in (Q_bwe_exc) */ - /* i/o: st_fx->genSHBsynth_Hilbert_Mem_fx in (Q_bwe_exc) */ - /* i/o: st_fx->genSHBsynth_state_lsyn_filt_shb_local_fx in (Q_bwe_exc) */ - /* o: error in (Qx) */ - GenSHBSynth_fx( shaped_shb_excitation, error, hBWE_TD->genSHBsynth_Hilbert_Mem_fx, - hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local_fx, st_fx->L_frame, &( hBWE_TD->syn_dm_phase ) ); - - Copy( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); - - /* resample SHB synthesis (if needed) and scale down */ - synth_scale_fx = 32767; - move16(); /* 1.0 in Q15 */ - if ( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - synth_scale_fx = 29491; - move16(); /* 0.9 in Q15 */ - } - - IF( EQ_32( st_fx->output_Fs, 48000 ) ) - { - IF( EQ_32( st_fx->extl, FB_TBE ) ) - { - tmp = norm_l( GainFrame ); - if ( GainFrame == 0 ) - { - tmp = 31; - move16(); - } - L_tmp = L_shl( GainFrame, tmp ); /* 18 + tmp */ - - tmp1 = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - Word16 idx = 0; - IF( i != 0 ) - { - idx = idiv1616( i_mult( NUM_SHB_SUBFR, i ), L_FRAME16k ); - } - L_tmp1 = Mult_32_16( L_tmp, GainShape[idx] ); /* Q : 18 + tmp +15 -15*/ - White_exc16k[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ - move16(); - tmp1 = s_max( tmp1, abs_s( White_exc16k[i] ) ); - } - - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ - move16(); - tmp = norm_s( tmp1 ); - if ( tmp1 == 0 ) - { - tmp = 15; - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i++ ) - { - White_exc16k[i] = shl( White_exc16k[i], sub( tmp, 1 ) ); - move16(); - } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); - move16(); - } - - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ - { - FOR( i = 0; i < L_FRAME32k; i++ ) - { - error[i] = mult_r( error[i], synth_scale_fx ); - move16(); - } - } - - interpolate_3_over_2_allpass_fx( error, L_FRAME32k, synth, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); - } - ELSE IF( EQ_32( st_fx->output_Fs, 32000 ) ) - { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ - { - FOR( i = 0; i < L_FRAME32k; i++ ) - { - synth[i] = mult_r( synth_scale_fx, error[i] ); - move16(); /*Qx*/ - } - } - ELSE - { - Copy( error, synth, L_FRAME32k ); - } - } - ELSE IF( EQ_32( st_fx->output_Fs, 16000 ) ) - { - IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ - { - FOR( i = 0; i < L_FRAME32k; i++ ) - { - error[i] = mult_r( error[i], synth_scale_fx ); - move16(); - } - } - - Decimate_allpass_steep_fx( error, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, synth ); - } - - /* Update previous frame parameters for FEC */ - Copy( lsf_shb, hBWE_TD->lsp_prevfrm_fx, LPC_SHB_ORDER ); - IF( EQ_16( st_fx->codec_mode, MODE1 ) ) - { - hBWE_TD->GainFrame_prevfrm_fx = GainFrame; - move16(); /*Q18*/ - hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; - move16(); - - if ( !st_fx->bfi ) - { - hBWE_TD->GainAttn_fx = 32767; /*Q15*/ - move16(); - } - } - ELSE - { - IF( !st_fx->bfi ) - { - hBWE_TD->GainFrame_prevfrm_fx = GainFrame; - move16(); /*Q18*/ - hBWE_TD->tilt_swb_fec_fx = tilt_swb_fec; - move16(); - hBWE_TD->GainAttn_fx = 32767; /*Q15*/ - move16(); - } - } - - hBWE_TD->prev_ener_fx = ener_tmp[NUM_SHB_SUBGAINS - 1]; - move32(); - hBWE_TD->prev_GainShape_fx = GainShape[NUM_SHB_SUBFR - 1]; - move32(); - *Q_synth = Q_bwe_exc; - move16(); - hBWE_TD->prev_Q_bwe_syn2 = Q_bwe_exc; - move16(); - hBWE_TD->prev_Qx = Q_bwe_exc; - move16(); - - return; -} - -#endif /*-------------------------------------------------------------------* * gradientGainShape() @@ -4519,7 +2830,6 @@ static void find_max_mem_dec_m3( * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module *-------------------------------------------------------------------*/ -#ifdef HARMONIZE_TBE3 void swb_tbe_dec_fx( Decoder_State *st, /* i/o: decoder state structure */ STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ @@ -4533,20 +2843,6 @@ void swb_tbe_dec_fx( Word16 *Q_synth, /* o : Q-factor of synth_fx16[]/synth_fx[] */ Word16 *pitch_buf_fx /* i : Q6 */ ) -#else -void swb_tbe_dec_ivas_fx( - Decoder_State *st, /* i/o: decoder state structure */ - STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ - const Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation : Q_exc */ - Word16 Q_exc, - const Word16 voice_factors_fx[], /* i : voicing factors : Q15 */ - const Word16 old_syn_12k8_16k_fx16[], /* i : low band synthesis : old_syn_fx */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE : Q_white_exc*/ - Word32 *synth_fx, /* o : SHB synthesis/final synthesis 32-bit : Qx */ - Word16 *pitch_buf_fx, /* i : Q6 */ - Word16 *Q_white_exc /* o : Q-factor of White_exc16k_fx */ -) -#endif { Word16 i, j, cnt, n; Word16 stemp; @@ -4556,9 +2852,7 @@ void swb_tbe_dec_ivas_fx( Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; Word16 lsf_shb_fx[LPC_SHB_ORDER], lpc_shb_fx[LPC_SHB_ORDER + 1], GainShape_fx[NUM_SHB_SUBFR]; // Q12,Q12,Q15 Word32 GainFrame_fx; // Q18 -#ifdef HARMONIZE_TBE3 Word16 error_fx16[L_FRAME32k]; -#endif Word32 error_fx[L_FRAME32k]; Word16 ener_fx; Word32 L_ener; @@ -4613,17 +2907,11 @@ void swb_tbe_dec_ivas_fx( Word16 expa, expb; Word16 fraca, fracb; Word16 exp_ener, inv_ener; -#ifdef HARMONIZE_TBE3 Word16 Q_exc = st->Q_exc; move16(); -#endif hBWE_TD = st->hBWE_TD; -#ifndef HARMONIZE_TBE3 - Word32 old_syn_12k8_16k_fx[L_FRAME16k]; - Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx16, old_syn_12k8_16k_fx, st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) -#endif /* initializations */ GainFrame_fx = 0; move32(); @@ -4656,19 +2944,15 @@ void swb_tbe_dec_ivas_fx( } /* find tilt */ -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { L_tmp = calc_tilt_bwe_fx( old_syn_12k8_16k_fx16, st->Q_syn2, st->L_frame ); tilt_swb_fec_fx = round_fx_sat( L_shl_sat( L_tmp, 3 ) ); } ELSE -#endif { -#ifdef HARMONIZE_TBE3 Word32 old_syn_12k8_16k_fx[L_FRAME16k]; Copy_Scale_sig_16_32_DEPREC( old_syn_12k8_16k_fx16, old_syn_12k8_16k_fx, st->L_frame, Q11 - ( -Q1 ) ); // Q(11 - (-1)) -#endif calc_tilt_bwe_fx_loc( old_syn_12k8_16k_fx, &tilt_swb_fec_32_fx, &tilt_swb_fec_fx_q, L_FRAME ); tilt_swb_fec_fx = round_fx_sat( L_shl_sat( tilt_swb_fec_32_fx, sub( 11 + 16, tilt_swb_fec_fx_q ) ) ); } @@ -5007,7 +3291,6 @@ void swb_tbe_dec_ivas_fx( /* get the gainshape delay */ Copy( &hBWE_TD->GainShape_Delay_fx[4], &hBWE_TD->GainShape_Delay_fx[0], NUM_SHB_SUBFR / 4 ); -#ifdef HARMONIZE_TBE3 test(); test(); IF( st->element_mode == EVS_MONO && ( ( st->rf_flag != 0 ) || EQ_32( st->total_brate, ACELP_9k60 ) ) ) @@ -5019,7 +3302,6 @@ void swb_tbe_dec_ivas_fx( } } ELSE -#endif { FOR( i = 0; i < NUM_SHB_SUBFR / 4; i++ ) { @@ -5181,9 +3463,7 @@ void swb_tbe_dec_ivas_fx( Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER ); } -#ifdef HARMONIZE_TBE3 IF( st->element_mode != EVS_MONO ) -#endif { /* convert from lsp to lsf */ lsp2lsf_fx( lsp_temp_fx, lsf_shb_fx, LPC_SHB_ORDER, 1 ); @@ -5218,13 +3498,11 @@ void swb_tbe_dec_ivas_fx( /* convert LSPs to LP coefficients */ E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { /* Bring the LPCs to Q12 */ Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); } -#endif } } @@ -5284,7 +3562,6 @@ void swb_tbe_dec_ivas_fx( /* -------- start of memory rescaling -------- */ /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ -#ifdef HARMONIZE_TBE3 Word16 sig_len = L_FRAME32k + NL_BUFF_OFFSET; move16(); IF( st->element_mode == EVS_MONO ) @@ -5299,11 +3576,6 @@ void swb_tbe_dec_ivas_fx( FOR( cnt = 0; cnt < sig_len; cnt++ ) #else FOR( cnt = 0; cnt < sig_len; cnt++ ) // note: this differs from the encoder where the length is always L_FRAME32k -#endif -#else - Lmax = 0; - move32(); - FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) #endif { Lmax = L_max( Lmax, L_abs( bwe_exc_extended_fx[cnt] ) ); @@ -5336,7 +3608,6 @@ void swb_tbe_dec_ivas_fx( /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ sc = sub( Q_bwe_exc, add( Q_exc, Q_exc ) ); -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); @@ -5351,7 +3622,6 @@ void swb_tbe_dec_ivas_fx( Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); } ELSE -#endif { FOR( cnt = 0; cnt < L_FRAME32k + NL_BUFF_OFFSET; cnt++ ) { @@ -5373,7 +3643,6 @@ void swb_tbe_dec_ivas_fx( Q_shb = 0; move16(); -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { IF( GT_32( st->total_brate, ACELP_32k ) ) @@ -5393,7 +3662,6 @@ void swb_tbe_dec_ivas_fx( &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st->total_brate, st->prev_bfi ); } ELSE -#endif { Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); @@ -5449,13 +3717,8 @@ void swb_tbe_dec_ivas_fx( FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { /* TD BWE post-processing */ -#ifdef HARMONIZE_TBE3 PostShortTerm_fx( st->element_mode, DEC, &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); -#else - PostShortTerm_ivas_dec_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); -#endif } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); /* Q_bwe_exc */ @@ -5531,13 +3794,11 @@ void swb_tbe_dec_ivas_fx( move16(); L_ener = EPSILON_FX_SMALL; move32(); -#ifdef HARMONIZE_TBE3 if ( st->element_mode == EVS_MONO ) { L_ener = 0; move32(); } -#endif FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) { @@ -5569,13 +3830,11 @@ void swb_tbe_dec_ivas_fx( L_ener = L_add_sat( L_ener, L_shr( ener_tmp_fx[i], 2 ) ); /* 2*Q_bwe_exc */ } } -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 19, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q3: 2*Q_bwe_exc+19-2*Q_bwe_exc-16 */ } ELSE -#endif { ener_fx = s_max( 1, round_fx_sat( L_shl_sat( L_ener, sub( 18, shl( Q_bwe_exc, 1 ) ) ) ) ); /* Q2: 2*Q_bwe_exc+18-2*Q_bwe_exc-16 */ } @@ -5583,7 +3842,6 @@ void swb_tbe_dec_ivas_fx( /* WB/SWB bandwidth switching */ IF( st->bws_cnt > 0 ) { -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { ener_fx = mult( ener_fx, 11587 ); @@ -5594,7 +3852,6 @@ void swb_tbe_dec_ivas_fx( } } -#endif IF( is_fractive == 0 ) { IF( GT_16( st->tilt_wb_fx, 2048 ) ) /*assuming st->tilt_wb_fx in Q11*/ @@ -5638,7 +3895,6 @@ void swb_tbe_dec_ivas_fx( IF( ener_fx != 0 ) { -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 14 ) ); /* 3+11 +st->Q_syn2 -14 = st->Q_syn2*/ @@ -5647,7 +3903,6 @@ void swb_tbe_dec_ivas_fx( inv_ener = div_s( 16384, tmp ); /*Q(15+14-3-exp) = 26- exp*/ } ELSE -#endif { L_tmp = L_shl( L_mult0( ener_fx, st->tilt_wb_fx ), sub( st->Q_syn2, 13 ) ); /* 2+11 +st->Q_syn2 -13 = st->Q_syn2*/ exp_ener = norm_s( ener_fx ); @@ -5669,13 +3924,11 @@ void swb_tbe_dec_ivas_fx( /*st->Q_syn2 -1 + 26- exp_ener -15 -(st->Q_syn2 -exp_ener -15 ) -16 = (11) 0.25*/ } L_tmp = L_mult0( st->prev_ener_shb_fx, inv_ener ); /*Q(1+15+14-3-exp_ener) = 27 -exp_ener*/ -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { GainFrame_prevfrm_fx = L_shr_sat( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ } ELSE -#endif { GainFrame_prevfrm_fx = L_shr( L_tmp, sub( 9, exp_ener ) ); /*27 -exp_ener -(9-exp_ener )= Q18*/ } @@ -5738,7 +3991,6 @@ void swb_tbe_dec_ivas_fx( { ener_fx = s_max( 1, ener_fx ); exp_ener = norm_s( ener_fx ); -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { tmp = shl( ener_fx, exp_ener ); /*Q(3+exp)*/ @@ -5746,7 +3998,6 @@ void swb_tbe_dec_ivas_fx( prev_ener_ratio_fx = L_shr_sat( L_mult0( st->prev_ener_shb_fx, inv_ener ), sub( 9, exp_ener ) ); /*Q: 1+26-exp-9+exp = 18 */ } ELSE -#endif { tmp = shl( ener_fx, exp_ener ); /*Q(2+exp)*/ inv_ener = div_s( 16384, tmp ); /*Q(15+14-2-exp)*/ @@ -5756,7 +4007,6 @@ void swb_tbe_dec_ivas_fx( IF( EQ_16( st->nbLostCmpt, 1 ) ) { -#ifdef HARMONIZE_TBE3 Word16 thr_tilt_swb = 4096; move16(); if ( st->element_mode == EVS_MONO ) @@ -5764,7 +4014,6 @@ void swb_tbe_dec_ivas_fx( thr_tilt_swb = 16384; move16(); } -#endif test(); test(); @@ -5802,13 +4051,8 @@ void swb_tbe_dec_ivas_fx( GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, s_min( tmp, 20480 ) ), 3 ); /*Q18 = 18 +12 -15 +3 */ } } -#ifdef HARMONIZE_TBE3 ELSE IF( ( ( st->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, thr_tilt_swb ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) ) -#else - ELSE IF( ( ( st->clas_dec != UNVOICED_CLAS ) || GT_16( hBWE_TD->tilt_swb_fec_fx, 4096 ) ) && GT_32( L_shr( prev_ener_ratio_fx, 2 ), GainFrame_fx ) && - ( GT_32( st->enerLL_fx, L_shr( st->prev_enerLL_fx, 1 ) ) || GT_32( st->enerLH_fx, L_shr( st->prev_enerLH_fx, 1 ) ) ) ) -#endif { GainFrame_fx = L_add( Mult_32_16( prev_ener_ratio_fx, 6554 ), Mult_32_16( GainFrame_fx, 26214 ) ); } @@ -6009,14 +4253,12 @@ void swb_tbe_dec_ivas_fx( Word16 n_mem3_new = 0; move16(); -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { n_mem3_new = n_mem3; move16(); } ELSE -#endif { find_max_mem_dec_m3( st, &n_mem3_new ); } @@ -6042,7 +4284,6 @@ void swb_tbe_dec_ivas_fx( max_val = 0; move16(); -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { FOR( i = 0; i < L_FRAME16k; i++ ) @@ -6051,7 +4292,6 @@ void swb_tbe_dec_ivas_fx( } } ELSE -#endif { FOR( i = 0; i < L_FRAME16k; i++ ) { @@ -6115,20 +4355,13 @@ void swb_tbe_dec_ivas_fx( } test(); -#ifdef HARMONIZE_TBE3 IF( !st->bfi && st->prev_bfi ) // note: this is likely a bug in EVS -#else - test(); - IF( !st->bfi && ( st->prev_bfi || st->prev_use_partial_copy ) ) -#endif { -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { L_tmp = L_shr( curr_frame_pow_fx, 4 ); L_tmp = Mult_32_16( L_tmp, 17476 ); } -#endif test(); test(); @@ -6335,7 +4568,6 @@ void swb_tbe_dec_ivas_fx( set16_fx( st->hBWE_FD->prev_SWB_fenv_fx, tmp, SWB_FENV ); /* Q1 */ } -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { /* rescale the memories if Q_bwe_exc is different from previous frame */ @@ -6372,7 +4604,6 @@ void swb_tbe_dec_ivas_fx( Copy( error_fx16 + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth_fx, L_SHB_TRANSITION_LENGTH ); } ELSE -#endif { FOR( i = 0; i < L_FRAME16k; i++ ) { @@ -6411,7 +4642,6 @@ void swb_tbe_dec_ivas_fx( tmp1 = 0; move16(); -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { FOR( i = 0; i < L_FRAME16k; i++ ) @@ -6428,7 +4658,6 @@ void swb_tbe_dec_ivas_fx( } } ELSE -#endif { Word32 idx32 = L_shr_r( 0x00333333, 10 ); FOR( i = 0; i < L_FRAME16k; i++ ) @@ -6459,7 +4688,6 @@ void swb_tbe_dec_ivas_fx( *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); move16(); -#ifdef HARMONIZE_TBE3 test(); IF( st->element_mode != EVS_MONO && GT_16( *Q_white_exc, Q31 ) ) { @@ -6467,10 +4695,8 @@ void swb_tbe_dec_ivas_fx( *Q_white_exc = Q31; move16(); } -#endif } -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ @@ -6486,7 +4712,6 @@ void swb_tbe_dec_ivas_fx( interpolate_3_over_2_allpass_fx( error_fx16, L_FRAME32k, synth_fx16, hBWE_TD->int_3_over_2_tbemem_dec_fx, allpass_poles_3_ov_2 ); } ELSE -#endif { IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { @@ -6503,7 +4728,6 @@ void swb_tbe_dec_ivas_fx( } ELSE IF( EQ_32( st->output_Fs, 32000 ) ) { -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ @@ -6520,7 +4744,6 @@ void swb_tbe_dec_ivas_fx( } } ELSE -#endif { IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { @@ -6538,7 +4761,6 @@ void swb_tbe_dec_ivas_fx( } ELSE IF( EQ_32( st->output_Fs, 16000 ) ) { -#ifdef HARMONIZE_TBE3 IF( st->element_mode == EVS_MONO ) { IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ @@ -6553,7 +4775,6 @@ void swb_tbe_dec_ivas_fx( Decimate_allpass_steep_fx( error_fx16, hBWE_TD->mem_resamp_HB_32k_fx, L_FRAME32k, synth_fx16 ); } ELSE -#endif { IF( NE_16( synth_scale_fx, 32767 ) ) /* 1.0 in Q15 */ { @@ -6605,13 +4826,11 @@ void swb_tbe_dec_ivas_fx( hBWE_TD->prev_Qx = Q_bwe_exc; move16(); -#ifdef HARMONIZE_TBE3 if ( Q_synth != NULL ) { *Q_synth = Q_bwe_exc; move16(); } -#endif return; } diff --git a/lib_enc/evs_enc_fx.c b/lib_enc/evs_enc_fx.c index 5e94dcfdc..9dbe3e914 100644 --- a/lib_enc/evs_enc_fx.c +++ b/lib_enc/evs_enc_fx.c @@ -463,11 +463,7 @@ ivas_error evs_enc_fx( test(); IF( NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) ) { -#ifdef HARMONIZE_TBE3 swb_tbe_enc_fx( st, NULL, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, st->voicing_fx, pitch_buf ); -#else - swb_tbe_enc_fx( st, st->coder_type, shb_speech, bwe_exc_extended, voice_factors, fb_exc, &Q_fb_exc, Q_new, Q_shb_spch, st->voicing_fx, pitch_buf ); -#endif IF( EQ_16( st->extl, FB_TBE ) ) { diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 40ec5df20..21a9da678 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -696,11 +696,7 @@ ivas_error ivas_core_enc_fx( Word16 Q_fb_exc; Word16 fb_exc_fx[L_FRAME16k]; -#ifdef HARMONIZE_TBE3 swb_tbe_enc_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], 0, st->voicing_fx, pitch_buf_fx[n] ); -#else - swb_tbe_enc_ivas_fx( st, hStereoICBWE, shb_speech_fx, bwe_exc_extended_fx[n], voice_factors_fx[n], fb_exc_fx, &Q_fb_exc, Q_new[n], 0, st->voicing_fx, pitch_buf_fx[n] ); -#endif IF( EQ_16( st->extl, FB_TBE ) ) { diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index cdddb769c..64ab8f2d6 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -563,22 +563,6 @@ void InitSWBencBufferStates_fx( ); void swb_tbe_enc_fx( -#ifndef HARMONIZE_TBE3 - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word16 *new_speech_fx, /* i : original i signal */ - Word32 *bwe_exc_extended_fx, /* i : bandwidth extended excitation */ - const Word16 voice_factors_fx[], /* i : voicing factors */ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE */ - Word16 *Q_white_exc, /* o : generated white noise for FB Q factor */ - Word16 Q_bwe_exc, /* i : bandwidth extended excitation Q factor */ - Word16 Q_shb, /* i : SHB target Q factor */ - Word16 *voicing_fx, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : pitch for each subframe */ -); - -void swb_tbe_enc_ivas_fx( -#endif Encoder_State *st_fx, /* i/o: encoder state structure */ STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index fe14e4860..0408ba504 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -1351,925 +1351,6 @@ void fb_tbe_reset_enc_fx( /*======================================================================================*/ void swb_tbe_enc_fx( -#ifndef HARMONIZE_TBE3 - Encoder_State *st_fx, /* i/o: encoder state structure */ - const Word16 coder_type, /* i : coding type */ - Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q_shb*/ - Word32 *bwe_exc_extended, /* i : bandwidth extended exciatation 2*Q_new*/ - const Word16 voice_factors_fx[], /* i : voicing factors Q15*/ - Word16 *White_exc16k_fx, /* o : shaped white excitation for the FB TBE Q_white_exc*/ - Word16 *Q_white_exc, - Word16 Q_new, - Word16 Q_shb, - Word16 *voicing, /* i : OL maximum normalized correlation */ - const Word16 pitch_buf[] /* i : subframe pitch Q6*/ -) -{ - Word16 i, j; - - Word16 shb_old_speech_fx[L_LOOK_16k + L_SUBFR16k + L_FRAME16k]; - Word16 bwe_exc_extended_16[L_FRAME32k + NL_BUFF_OFFSET]; - - Word16 shaped_shb_excitation_fx[L_FRAME16k + L_SHB_LAHEAD]; - Word32 GainFrame_fx; - Word16 GainShape_fx[NUM_SHB_SUBFR]; - Word16 lpc_shb_fx[LPC_SHB_ORDER + 1], lsp_shb_fx[LPC_SHB_ORDER], lsf_shb_fx[LPC_SHB_ORDER]; - Word16 weights_lsp[LPC_SHB_ORDER]; - Word16 Q_out; - Word16 *shb_frame_fx, *shb_new_speech_fx; - Word16 R_h[LPC_SHB_ORDER + 2]; /* Autocorrelations of windowed speech MSB */ - Word16 R_l[LPC_SHB_ORDER + 2]; /* Autocorrelations of windowed speech LSB */ - Word16 Q_R; - Word32 LepsP[LPC_SHB_ORDER + 1]; - - Word16 ana_align_delay[2] = { -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ), -L_SHB_LAHEAD - ( NL_BUFF_OFFSET / 2 ) }; - move16(); - move16(); - Word32 prev_pow_fx, curr_pow_fx, Lscale; - Word32 p2m_in_fx, p2m_out_fx; - - Word16 exp_out, exp, exp1, frac; - Word16 cnt, n_mem, n_mem2; - Word32 L_tmp, L_tmp1; - Word16 Q_bwe_exc; - - Word16 frGainAttenuate, frGainSmoothEn; - Word16 MA_lsp_shb_spacing; - Word16 temp_swb_fac, feedback; - Word32 L_feedback; - Word16 tmp, tmp1, tmp2; - Word32 Lmax; - Word16 sc; - Word16 lsf_shb_orig_fx[LPC_SHB_ORDER]; - Word16 sd_uq_q_fx; - Word16 vf_modified_fx[NB_SUBFR16k]; - Word16 pitBufAvg_fx; - Word16 voicingBufAvg_fx; - Word16 sum1, sum2; - Word16 recip, Q_recip; - const Word16 *ptr_lsp_interp_coef_fx; - - Word16 lsp_shb_1_fx[LPC_SHB_ORDER], lsp_shb_2_fx[LPC_SHB_ORDER], lsp_temp_fx[LPC_SHB_ORDER]; - Word16 lpc_shb_sf_fx[4 * ( LPC_SHB_ORDER + 1 )]; - - /*Word32 shb_ener_sf_fx_32[4];*/ - Word32 shb_ener_sf_Q31; - Word16 shb_res_fx[L_FRAME16k]; - Word16 shb_res_gshape_fx[NB_SUBFR16k]; - Word32 shb_res_gshape_fx_32[NB_SUBFR16k]; - Word16 vf_ind_fx; - - Word16 formant_fac_fx; - Word16 shaped_shb_excitationTemp_fx[L_FRAME16k]; - - Word16 mean_vf; - Word16 lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER]; - Word16 refl[M]; - Word16 tilt_para; - Word16 Q_bwe_exc_fb; - Word16 n_subfr_saturation; - TD_BWE_ENC_HANDLE hBWE_TD = st_fx->hBWE_TD; - RF_ENC_HANDLE hRF = st_fx->hRF; - - /* init and buffers set up */ - exp1 = 0; /* to avoid compilation warnings */ - set16_fx( shaped_shb_excitationTemp_fx, 0, L_FRAME16k ); - - /* compensate for the delay in target generation and subframe LA */ - shb_frame_fx = shb_old_speech_fx + L_SUBFR16k + ana_align_delay[0]; - move16(); - - /* set up the speech buffers for TBE processing*/ - shb_new_speech_fx = shb_old_speech_fx + ( L_LOOK_16k + L_SUBFR16k ); - move16(); - Copy( hBWE_TD->old_speech_shb_fx, shb_old_speech_fx, ( L_LOOK_16k + L_SUBFR16k ) ); - Copy( shb_speech_fx, shb_new_speech_fx, L_FRAME16k ); - Copy( shb_old_speech_fx + L_FRAME16k, hBWE_TD->old_speech_shb_fx, ( L_LOOK_16k + L_SUBFR16k ) ); - - /* autocorrelation of SHB speech for 10-th order LP analysis */ - autocorr_fx( shb_old_speech_fx, - LPC_SHB_ORDER + 1, - R_h, /* autocorr (msb) Q15 */ - R_l, /* autocorr (lsb) */ - &Q_R, - NS2SA( INT_FS_16k, ACELP_LOOK_NS ) + L_SUBFR16k + L_FRAME16k, - win_lpc_shb_fx, - 0, - 1 ); - - - /* Spectral smoothing of autocorrelation coefficients */ - test(); - IF( ( st_fx->rf_mode != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) - { - FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) - { - L_tmp = Mpy_32( R_h[i], R_l[i], wac_swb_h[i - 1], wac_swb_l[i - 1] ); - L_Extract( L_tmp, &R_h[i], &R_l[i] ); - } - } - - /* Set the autocorr[0] element to a non-negative value */ - R_l[0] = s_max( R_l[0], 1 ); - move16(); - - E_LPC_lev_dur_fx( R_h, R_l, lpc_shb_fx, LepsP, LPC_SHB_ORDER, NULL ); /* LPC in Q14 */ - { - Word16 enerG, lpc_shb1[M + 1]; - - /* extend the lpc_shb to a 16th order gain calc */ - set16_fx( lpc_shb1, 0, M + 1 ); - Copy( lpc_shb_fx, lpc_shb1, LPC_SHB_ORDER + 1 ); - - /* estimate the LP gain */ - enerG = Enr_1_Az_fx( lpc_shb1, 2 * L_SUBFR ); /* Q3 */ - - /* if the LP gain is greater than a threshold, avoid saturation */ - IF( GT_16( enerG, 256 /*32 Q3*/ ) ) - { - set16_fx( lpc_shb_fx, 0, LPC_SHB_ORDER + 1 ); - E_LPC_lev_dur_fx( R_h, R_l, lpc_shb_fx, LepsP, 2, NULL ); /* LPC in Q14 */ - } - } - - /* this is needed as the E_LPC_lev_dur function outputs lpc in Q14 */ - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); - - /* Expand bandwidth of the LP coeffs */ - test(); - IF( ( st_fx->rf_mode != 0 ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) - { - FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) - { - lpc_shb_fx[i] = mult_r( lpc_shb_fx[i], lpc_weights_fx[i] ); - move16(); - } - } - - /* LPC to LSP conversion */ - /* LPC: Q12, LSP: Q15 */ - E_LPC_a_lsp_conversion( lpc_shb_fx, lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); - - /* LSP to LSF conversion */ - /* LSP: Q15, LSF: Q15 */ - E_LPC_lsp_lsf_conversion( lsp_shb_fx, lsf_shb_fx, LPC_SHB_ORDER ); - - /* Input signal filtering in case of tonal sounds in the high band - gain Frame smoothing and attenuation control */ - gainFrSmooth_En_fx( st_fx, shb_frame_fx, lpc_shb_fx, lsf_shb_fx, &MA_lsp_shb_spacing, &frGainAttenuate, &frGainSmoothEn ); - - Copy( lsp_shb_fx, hBWE_TD->prev_lsp_shb_fx, LPC_SHB_ORDER ); - Copy( lsf_shb_fx, lsf_shb_orig_fx, LPC_SHB_ORDER ); - - test(); - IF( ( EQ_16( st_fx->rf_mode, 1 ) ) || EQ_32( st_fx->total_brate, ACELP_9k60 ) ) - { - lsp_weights_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); - - /* to compensate for the 1.1* weighting done inside the function lsp_weights */ - /*weights_lsp[3]*=0.909091f; weights_lsp[4]*=0.909091f; */ - weights_lsp[3] = mult_r( weights_lsp[3], 29789 /*0.909091f Q15*/ ); - move16(); - weights_lsp[4] = mult_r( weights_lsp[4], 29789 /*0.909091f Q15*/ ); - move16(); - - /* 8-bit VQ, 10 dimension */ - i = closest_centroid_fx( lsf_shb_fx, weights_lsp, swb_tbe_lsfvq_cbook_8b, 256, LPC_SHB_ORDER ); - Copy( swb_tbe_lsfvq_cbook_8b + i * LPC_SHB_ORDER, lsf_shb_fx, LPC_SHB_ORDER ); - - set16_fx( hBWE_TD->lsf_idx, 0, NUM_Q_LSF ); - hBWE_TD->lsf_idx[0] = i; - move16(); - } - ELSE - { - /* LSF quantization (21 bits) */ - Quant_BWE_LSF_fx( st_fx->hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); - } - - /* space the lsfs to assert a minimum distance */ - space_lsfs_fx( lsf_shb_fx, LPC_SHB_ORDER ); - - /* voice factor adjustment and gainframe attenuation factor */ - tmp = sub( lsf_shb_fx[0], lsf_shb_orig_fx[0] ); - L_tmp = L_mult( tmp, tmp ); - FOR( i = 1; i < LPC_SHB_ORDER; i++ ) - { - /* Estimate the QD in lsfs between UQ and Q */ - tmp = sub( lsf_shb_fx[i], lsf_shb_orig_fx[i] ); - L_tmp = L_mac( L_tmp, tmp, tmp ); - } - sd_uq_q_fx = round_fx( L_tmp ); /* sd_uq_q_fx in Q15 */ - /* voice factor modification to limit any spurious jumps in the middle of voiced subframes*/ - /* mean(voice_factors_fx[i], 4); */ - - L_tmp = L_mult( voice_factors_fx[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); - mean_vf = mac_r( L_tmp, voice_factors_fx[3], 8192 ); - - Copy( voice_factors_fx, vf_modified_fx, NB_SUBFR16k ); - - test(); - IF( EQ_16( coder_type, VOICED ) || GT_16( mean_vf, 13107 /*0.4f Q15*/ ) ) - { - FOR( i = 1; i < NB_SUBFR; i++ ) - { - L_tmp = L_mult( voice_factors_fx[i], 26214 ); - vf_modified_fx[i] = mac_r( L_tmp, voice_factors_fx[i - 1], 6554 ); - move16(); - } - IF( NE_16( st_fx->L_frame, L_FRAME ) ) - { - L_tmp = L_mult( voice_factors_fx[4], 26214 ); - vf_modified_fx[4] = mac_r( L_tmp, voice_factors_fx[3], 6554 ); - move16(); - } - } - - /* convert quantized LSFs to LSPs for interpolation */ - E_LPC_lsf_lsp_conversion( lsf_shb_fx, lsp_shb_2_fx, LPC_SHB_ORDER ); - - test(); - IF( EQ_16( st_fx->last_extl, SWB_TBE ) || EQ_16( st_fx->last_extl, FB_TBE ) ) - { - /* SHB LSP values from prev. frame for interpolation */ - Copy( hBWE_TD->swb_lsp_prev_interp_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); - } - ELSE - { - /* Use current frame's LSPs; in effect no interpolation */ - Copy( lsp_shb_2_fx, lsp_shb_1_fx, LPC_SHB_ORDER ); - } - - lsf_diff[0] = lsf_diff[LPC_SHB_ORDER - 1] = 16384; /*Q15*/ - move16(); - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - lsf_diff[i] = sub( lsf_shb_fx[i], lsf_shb_fx[i - 1] ); - move16(); - } - a2rc_fx( hBWE_TD->cur_sub_Aq_fx + 1, refl, M ); - - /* LSP interpolation for 13.2 kbps and 16.4 kbps */ - /* tilt_para = 6.6956f * (1.0f + refl[0]) * (1.0f + refl[0]) - - 3.8714f * (1.0f + refl[0]) - + 1.3041f; */ - tmp = add( 16384, shr( refl[0], 1 ) ); /*Q14*/ - tmp1 = mult( 27425 /*Q12*/, tmp ); /*Q11*/ - tmp1 = mult( tmp1, tmp ); - tmp2 = shr( mult( 31715, tmp ), 2 ); /* Q11 */ - tilt_para = add( sub( tmp1, tmp2 ), 1335 ); /*Q10*/ - - IF( NE_16( st_fx->last_extl, SWB_TBE ) ) - { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - hBWE_TD->prev_lsf_diff_fx[i - 1] = mult( lsf_diff[i], 16384 ); /*Q15*/ - move16(); - } - } - - IF( LE_32( st_fx->total_brate, ACELP_16k40 ) ) - { - test(); - test(); - test(); - test(); - test(); - IF( !( GT_16( hBWE_TD->prev_tilt_para_fx, 5120 ) && ( EQ_16( coder_type, TRANSITION ) || LT_16( tilt_para, 1024 ) ) ) && - !( ( ( LT_16( hBWE_TD->prev_tilt_para_fx, 3072 ) && GE_16( hBWE_TD->prev_coder_type, VOICED ) ) ) && GT_16( tilt_para, 5120 ) ) ) - { - FOR( i = 1; i < LPC_SHB_ORDER - 1; i++ ) - { - IF( LT_16( lsf_diff[i], hBWE_TD->prev_lsf_diff_fx[i - 1] ) ) - { - tmp = mult( 26214, lsf_diff[i] ); - tmp = div_s( tmp, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); - move16(); - } - ELSE - { - tmp = mult( 26214, hBWE_TD->prev_lsf_diff_fx[i - 1] ); - tmp = div_s( tmp, lsf_diff[i] ); - tmp = s_max( tmp, 16384 ); - w[i] = s_min( tmp, 32767 ); - move16(); - } - } - w[0] = w[1]; - move16(); - w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2]; - move16(); - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - tmp1 = mult( lsp_shb_1_fx[i], sub( 32767, w[i] ) ); - tmp2 = mult( lsp_shb_2_fx[i], w[i] ); - lsp_temp_fx[i] = add( tmp1, tmp2 ); - move16(); - } - } - ELSE - { - Copy( lsp_shb_2_fx, lsp_temp_fx, LPC_SHB_ORDER ); - } - } - - Copy( lsf_diff + 1, hBWE_TD->prev_lsf_diff_fx, LPC_SHB_ORDER - 2 ); - hBWE_TD->prev_tilt_para_fx = tilt_para; - move16(); - - shb_ener_sf_Q31 = 0; - move16(); - test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) - { - /* ---------- SHB LSP interpolation ---------- */ - ptr_lsp_interp_coef_fx = interpol_frac_shb; /* Q15 */ - FOR( j = 0; j < 4; j++ ) - { - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - /*lsp_temp_fx[i] = lsp_shb_1_fx[i]*(*ptr_lsp_interp_coef_fx) */ - /* + lsp_shb_2_fx[i]*(*(ptr_lsp_interp_coef_fx+1)); */ - L_tmp = L_mult( lsp_shb_1_fx[i], ( *ptr_lsp_interp_coef_fx ) ); - lsp_temp_fx[i] = mac_r( L_tmp, lsp_shb_2_fx[i], ( *( ptr_lsp_interp_coef_fx + 1 ) ) ); - move16(); - } - ptr_lsp_interp_coef_fx += 2; - - tmp = i_mult2( j, ( LPC_SHB_ORDER + 1 ) ); - /* convert LSPs to LPC coefficients for SHB synthesis*/ - E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER ); - /* Bring the LPCs to Q12 */ - Copy_Scale_sig( lpc_shb_sf_fx + tmp, lpc_shb_sf_fx + tmp, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_sf_fx[tmp] ), 2 ) ); - } - - /* -------- Calculate the SHB Energy -------- */ - /*shb_ener_sf[0] = 0.003125f * sum2_f( shb_frame + L_SHB_LAHEAD, 320 );*/ - FOR( i = L_SHB_LAHEAD; i < L_FRAME16k + L_SHB_LAHEAD; i++ ) - { - /* shbEner = shbEner + in[i] * in[i] */ - shb_ener_sf_Q31 = L_mac0_sat( shb_ener_sf_Q31, shb_frame_fx[i], shb_frame_fx[i] ); - /* o: shb_ener_sf_Q31 in (2*Q_shb) */ - } - shb_ener_sf_Q31 = Mult_32_16( shb_ener_sf_Q31, 102 /*0.003125f Q15*/ ); - shb_ener_sf_Q31 = L_add( 1l /*1 Q0*/, shb_ener_sf_Q31 ); - Quant_shb_ener_sf_fx( st_fx, &shb_ener_sf_Q31, ( 2 * Q_shb ) ); - - /* -------- calculate the residuals using the FOUR subframe LPCs -------- */ - set16_fx( shb_res_fx, 0, L_FRAME16k ); - Residu3_10_fx( lpc_shb_sf_fx, shb_frame_fx + L_SHB_LAHEAD, shb_res_fx, 80, 0 ); - Residu3_10_fx( lpc_shb_sf_fx + ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 80, shb_res_fx + 80, 80, 0 ); - Residu3_10_fx( lpc_shb_sf_fx + 2 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 160, shb_res_fx + 160, 80, 0 ); - Residu3_10_fx( lpc_shb_sf_fx + 3 * ( LPC_SHB_ORDER + 1 ), shb_frame_fx + L_SHB_LAHEAD + 240, shb_res_fx + 240, 80, 0 ); - /* i: shb_frame_fx in Q_shb */ - /* o: shb_res_fx in Q_shb */ - - set32_fx( shb_res_gshape_fx_32, 0, NB_SUBFR16k ); - FOR( i = 0; i < NB_SUBFR16k; i++ ) - { - shb_res_gshape_fx_32[i] = sum2_fx( shb_res_fx + i * 64, 64 ); - move32(); - } - /* o: shb_res_gshape_fx_32 in (2*Q_shb+1) */ - - maximum_32_fx( shb_res_gshape_fx_32, NB_SUBFR16k, &L_tmp ); - - /* root_a_over_b_fx(shb_res_gshape_fx_32[i], (2*Q_shb+1), L_tmp, (2*Q_shb+1), &exp);*/ - /* First, find 1/L_tmp, L_tmp in QA = (2*Q_shb+1) */ - - /* case when den = 0 */ - recip = 0; /*instead of 32767 to be compatible with previous root_a_over_b_fx() output */ - Q_recip = 0; - - IF( L_tmp ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - recip = div_s( 16384, tmp ); - // Q_recip = 31 - ( exp - 14 ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ - Q_recip = sub( 31 + 14, exp ); /* = 31-(exp+2*Q_shb+1-14), but adjusted by (2*Q_shb+1) for use at Mult_32_16 below */ - move16(); - } - - FOR( i = 0; i < NB_SUBFR16k; i++ ) - { - L_tmp1 = Mult_32_16( shb_res_gshape_fx_32[i], recip ); /*Q = Q_recip+1-16*/ - L_tmp = root_a_fx( L_tmp1, add( Q_recip, 1 - 16 ), &exp ); - shb_res_gshape_fx[i] = round_fx( L_shl( L_tmp, sub( exp, 1 ) ) ); /* Q14 */ - move16(); - } - - Quant_shb_res_gshape_fx( st_fx, shb_res_gshape_fx ); - } - - /* for 13.2 and 16.4kbps */ - E_LPC_f_lsp_a_conversion( lsp_temp_fx, lpc_shb_fx, LPC_SHB_ORDER ); - Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); /* Q12 */ - - /* Save the SWB LSP values from current frame for interpolation */ - Copy( lsp_shb_2_fx, hBWE_TD->swb_lsp_prev_interp_fx, LPC_SHB_ORDER ); /* lsp_shb_2_fx in Q15 */ - - /* -------- start of memory rescaling -------- */ - /* ----- calculate optimum Q_bwe_exc and rescale memories accordingly ----- */ - Lmax = L_deposit_l( 0 ); - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - Lmax = L_max( Lmax, L_abs( bwe_exc_extended[cnt] ) ); - } - Q_bwe_exc = norm_l( Lmax ); - if ( Lmax == 0 ) - { - Q_bwe_exc = 31; - move16(); - } - Q_bwe_exc = add( Q_bwe_exc, add( Q_new, Q_new ) ); - - /* Account for any outliers in the memories from previous frame for rescaling to avoid saturation */ - find_max_mem_enc( st_fx, &n_mem, &n_mem2 ); - - tmp2 = add( hBWE_TD->prev_Q_bwe_exc, n_mem ); - if ( GT_16( Q_bwe_exc, tmp2 ) ) - { - Q_bwe_exc = tmp2; - move16(); - } - - /* rescale the memories if Q_bwe_exc is different from previous frame */ - sc = sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_exc ); - IF( sc != 0 ) - { - rescale_genSHB_mem_enc( st_fx, sc ); - } - - /* rescale the bwe_exc_extended and bring it to 16-bit single precision with dynamic norm */ - Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); - sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); - - FOR( cnt = 0; cnt < L_FRAME32k; cnt++ ) - { - bwe_exc_extended_16[cnt + NL_BUFF_OFFSET] = round_fx_sat( L_shl_sat( bwe_exc_extended[cnt], sc ) ); - move16(); - } - Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); - - /* state_syn_shbexc_fx is kept at (st_fx->prev_Q_bwe_syn) for 24.4/32kbps or is kept at Q_bwe_exc for 13.2/16.4kbps */ - Copy( hBWE_TD->state_syn_shbexc_fx, shaped_shb_excitation_fx, L_SHB_LAHEAD ); - - /* save the previous Q factor of the buffer */ - hBWE_TD->prev_Q_bwe_exc = Q_bwe_exc; - move16(); - - Q_bwe_exc = sub( Q_bwe_exc, 16 ); /* Q_bwe_exc reflecting the single precision dynamic norm-ed buffers from here */ - - /* -------- end of rescaling memories -------- */ - Q_bwe_exc_fb = hBWE_TD->prev_Q_bwe_exc_fb; - move16(); - /* Determine formant PF strength */ - formant_fac_fx = swb_formant_fac_fx( lpc_shb_fx[1], &hBWE_TD->tilt_mem_fx ); - /* i:lpc_shb_fx Q12, o:formant_fac_fx Q15 */ - - /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ - vf_ind_fx = 20; - move16(); - - GenShapedSHBExcitation_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, - hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, - coder_type, st_fx->element_mode, bwe_exc_extended_16, hBWE_TD->bwe_seed, vf_modified_fx, st_fx->extl, - &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), lpc_shb_sf_fx, shb_ener_sf_Q31, - shb_res_gshape_fx, shb_res_fx, &vf_ind_fx, formant_fac_fx, hBWE_TD->fb_state_lpc_syn_fx, - &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0 ); - - *Q_white_exc = Q_bwe_exc_fb; - move16(); - IF( EQ_16( st_fx->extl, FB_TBE ) ) - { - hBWE_TD->prev_Q_bwe_exc_fb = Q_bwe_exc_fb; - move16(); - } - ELSE - { - /*Indirectly a memory reset of FB memories for next frame such that rescaling of memories would lead to 0 due to such high prev. Q value. - 51 because of 31 + 20(shift of Q_bwe_exc_fb before de-emphasis)*/ - hBWE_TD->prev_Q_bwe_exc_fb = 51; - move16(); - } - - test(); - IF( EQ_32( st_fx->total_brate, ACELP_24k40 ) || EQ_32( st_fx->total_brate, ACELP_32k ) ) - { - IF( EQ_16( st_fx->codec_mode, MODE2 ) ) - { - hBWE_TD->idx_mixFac = vf_ind_fx; - move16(); - } - ELSE - { - push_indice( st_fx->hBstr, IND_SHB_VF, vf_ind_fx, NUM_BITS_SHB_VF ); - } - } - - FOR( i = 0; i < LPC_SHB_ORDER; i++ ) - { - hBWE_TD->mem_stp_swb_fx[i] = shl( hBWE_TD->mem_stp_swb_fx[i], sub( Q_bwe_exc, hBWE_TD->prev_Q_bwe_syn ) ); - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) - { - PostShortTerm_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); - } - Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); - - tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); - prev_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - curr_pow_fx = L_shl( 21475l /*0.00001f Q31*/, tmp ); /* 2*(Q_bwe_exc) */ - FOR( i = 0; i < L_SHB_LAHEAD + 10; i++ ) - { - prev_pow_fx = L_mac0_sat( prev_pow_fx, shaped_shb_excitation_fx[i], shaped_shb_excitation_fx[i] ); /* 2*Q_bwe_exc */ - curr_pow_fx = L_mac0_sat( curr_pow_fx, shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10], shaped_shb_excitation_fx[i + L_SHB_LAHEAD + 10] ); /* 2*Q_bwe_exc */ - } - - if ( GT_16( voice_factors_fx[0], 24576 /*0.75f Q15*/ ) ) - { - /*curr_pow_fx = Mult_32_16( curr_pow_fx, 8192);*/ /* Q(2*Q_bwe_exc) */ - curr_pow_fx = L_shr( curr_pow_fx, 2 ); /* scale by 0.25 */ - } - - Lscale = root_a_over_b_fx( curr_pow_fx, - shl( Q_bwe_exc, 1 ), - prev_pow_fx, - shl( Q_bwe_exc, 1 ), - &exp ); - FOR( i = 0; i < L_SHB_LAHEAD; i++ ) - { - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q(16-exp+Q_bwe_exc) */ - shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - IF( exp < 0 ) - { - Lscale = L_shl( Lscale, exp ); - exp = 0; - move16(); - } - /* - code for EVS and IVAS are basically identical with the exception of i_mult_sat() which has precision issues - thus is was replaced for IVAS and kept for EVS, in order to keep EVS BE to test sequences and legacy implementations - */ - IF( EQ_16( st_fx->element_mode, EVS_MONO ) ) - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ - tmp = sub( 32767 /*1.0f Q15*/, tmp ); - Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - ELSE - { - FOR( ; i < L_SHB_LAHEAD + 10; i++ ) - { - tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); - L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ - tmp = sub( 32767 /*1.0f Q15*/, tmp ); - Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ - shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ - move16(); - } - } - - /* Update SHB excitation */ - Copy( shaped_shb_excitation_fx + L_FRAME16k, hBWE_TD->state_syn_shbexc_fx, L_SHB_LAHEAD ); /* Q_bwe_exc */ - - /* Estimate the gain-shape parameter */ - n_subfr_saturation = 0; - move16(); - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, - Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 1 ); - - /* Gain shape BWS/high band low energy fix */ - IF( LT_16( hBWE_TD->cldfbHBLT, 8192 /*1.0f Q13*/ ) ) /* cldfbHBLT in Q13 */ - { - /* There is not much HB past 10kHz; the temporal resolution is quite coarse, so reduce the dynamic range */ - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /* 0.35f +/- delta variation; delta = 0.1*(GS-0.35)*/ - /* GainShape[i] = 0.315f + 0.1f * GainShape[i]; */ - GainShape_fx[i] = mac_r( 676457349l /*0.315 Q31*/, 3277 /*0.1 Q15*/, GainShape_fx[i] ); - move16(); - } - } - - /* Gain frame adjustment factor */ - /* log( (GainShape[0]) / (st->prev_wb_GainShape) )*/ - test(); - IF( GainShape_fx[0] && hBWE_TD->prev_swb_GainShape_fx ) - { - exp = norm_s( hBWE_TD->prev_swb_GainShape_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), hBWE_TD->prev_swb_GainShape_fx ); - L_tmp = L_mult( GainShape_fx[0], tmp ); /*Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); /*move16(); */ - exp1 = sub( exp, exp1 ); /*move16(); */ - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - } - ELSE - { - temp_swb_fac = 0; - move16(); - } - L_feedback = L_mult0( temp_swb_fac, temp_swb_fac ); - - - FOR( i = 1; i < NUM_SHB_SUBGAINS; i++ ) - { - test(); - IF( GainShape_fx[i] && GainShape_fx[i - 1] ) - { - exp = norm_s( GainShape_fx[i - 1] ); - tmp = div_s( shl( 1, sub( 14, exp ) ), GainShape_fx[i - 1] ); - L_tmp = L_mult( GainShape_fx[i], tmp ); /* Q(30 - exp) */ - - exp1 = norm_l( L_tmp ); - frac = Log2_norm_lc( L_shl( L_tmp, exp1 ) ); - exp1 = sub( exp, exp1 ); - L_tmp = Mpy_32_16( exp1, frac, 22713 ); - temp_swb_fac = round_fx( L_shl( L_tmp, 10 ) ); - } - ELSE - { - temp_swb_fac = 0; - move16(); - } - - L_feedback = L_mac( L_feedback, temp_swb_fac, temp_swb_fac ); - } - - /* feedback = 0.4f / (1 + 0.5f * feedback) */ - L_tmp = L_add( L_shr( L_feedback, 1 ), L_shl( 1, 21 ) ); /* Q21 */ - IF( L_tmp != 0 ) - { - exp = norm_l( L_tmp ); - tmp = extract_h( L_shl( L_tmp, exp ) ); - exp = sub( sub( 30, exp ), 21 ); - tmp = div_s( 16384, tmp ); /*Q(15+exp) */ - L_tmp = L_shr( L_mult( 13107, tmp ), exp ); /*Q31 */ - feedback = round_fx( L_tmp ); /*Q15 */ - } - ELSE - { - feedback = 8738; - move16(); /*Q15 */ - } - - /* voicing in Q15 */ - L_tmp = L_mult( voicing[0], 8192 ); - L_tmp = L_mac( L_tmp, voicing[1], 8192 ); - L_tmp = L_mac( L_tmp, voicing[2], 8192 ); - tmp = sum1 = round_fx( L_tmp ); /* sum1 used again below - Q13 */ - tmp = add( tmp, 1 ); /* To ensure change is BE */ - - /* voice_factors_fx in Q15 */ - L_tmp = L_mult( voice_factors_fx[0], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[1], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[2], 8192 ); - L_tmp = L_mac( L_tmp, voice_factors_fx[3], 8192 ); - tmp1 = sum2 = round_fx( L_tmp ); /* sum2 used again below - Q13 */ - - - test(); - test(); - IF( EQ_16( frGainAttenuate, 1 ) || ( GT_16( tmp, 19661 ) && GT_16( tmp1, 6554 ) ) ) - - { - temp_swb_fac = hBWE_TD->prev_swb_GainShape_fx; - move16(); - FOR( i = 0; i < NUM_SHB_SUBGAINS; i++ ) - { - /*GainShape_fx[i] = (1 - feedback) * GainShape[i] + feedback * temp_swb_fac; */ - GainShape_fx[i] = round_fx( L_mac( L_mult( sub( 32767, feedback ), GainShape_fx[i] ), feedback, temp_swb_fac ) ); - move16(); - temp_swb_fac = GainShape_fx[i]; - move16(); - } - } - hBWE_TD->prev_swb_GainShape_fx = GainShape_fx[3]; - move16(); - - /* Compute the power of gains away from the peak gain prior to quantization */ - p2m_in_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBGAINS, 1 ); - - /* Quantization of the gain shape parameter */ - - QuantizeSHBsubgains_fx( st_fx, GainShape_fx, st_fx->extl ); - /* o: GainShape_fx in Q15 */ - /* Compute the power of gains away from the peak gain after quantization */ - p2m_out_fx = pow_off_pk_fx( GainShape_fx, NUM_SHB_SUBFR, 4 ); - - /* Estimate the gain parameter */ - EstimateSHBFrameGain_fx( st_fx->element_mode, SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, - GainShape_fx, &GainFrame_fx, window_shb_fx, subwin_shb_fx, n_subfr_saturation ); - - IF( EQ_16( st_fx->tec_tfa, 1 ) ) - { - tfaCalcEnv_fx( shb_frame_fx, st_fx->tfa_enr ); - } - - /* If there's a big difference in the power of gains away from the peak gain */ - /* due to poor quantization then suppress energy of the high band. */ - IF( GT_32( p2m_out_fx, L_shl( p2m_in_fx, 1 ) ) ) - { - L_tmp = root_a_over_b_fx( p2m_in_fx, 28, p2m_out_fx, 29, &exp_out ); - GainFrame_fx = L_shl( Mult_32_32( GainFrame_fx, L_tmp ), exp_out ); /* Q18 */ - } - test(); - IF( EQ_16( frGainSmoothEn, 1 ) && LT_32( hBWE_TD->prev_gainFr_SHB_fx, GainFrame_fx ) ) - { - GainFrame_fx = L_add( L_shr( hBWE_TD->prev_gainFr_SHB_fx, 1 ), L_shr( GainFrame_fx, 1 ) ); /* Q18 */ - } - - test(); - test(); - IF( EQ_16( frGainAttenuate, 1 ) && LE_16( MA_lsp_shb_spacing, 79 /*0.0024f Q15*/ ) ) - { - exp1 = norm_l( GainFrame_fx ); - frac = Log2_norm_lc( L_shl( GainFrame_fx, exp1 ) ); - exp = sub( 30, add( exp1, 21 ) ); - L_tmp = Mpy_32_16( exp, frac, 26214 ); /* Q16 */ - frac = L_Extract_lc( L_tmp, &exp ); - GainFrame_fx = Pow2( 30, frac ); - exp = sub( exp, 30 ); - GainFrame_fx = L_shl( GainFrame_fx, add( exp, 18 ) ); /* Q18 */ - } - ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) - { - /*GainFrame *= (0.8f + 0.5f*feedback); */ - tmp = add( 26214, mult_r( feedback, 16384 ) ); - GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 */ - } - hBWE_TD->prev_frGainAtten = frGainAttenuate; - move16(); - hBWE_TD->prev_gainFr_SHB_fx = GainFrame_fx; - move16(); /* Q18 */ - - - /* Gain attenuation when the SWB LSF quantization error is larger than a threshold */ - tmp = mult_r( 25600 /*400 Q6*/, sd_uq_q_fx ); /* Q6 * Q15 => Q6 */ - IF( EQ_16( st_fx->L_frame, L_FRAME ) ) - { - tmp1 = mult_r( 6554 /*0.2f Q15*/, tmp ); /* Q15, Q6 => Q6 */ - L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ - } - ELSE - { - tmp1 = mult_r( 3277 /*0.1f Q15*/, tmp ); /* Q15, Q6 => Q6 */ - L_tmp = L_msu( 8192l /*1.0f Q13*/, tmp1, tmp ); /* Q13 */ - } - /* sd_uq_q = max(min(sd_uq_q, 1.0f), 0.5f); */ - L_tmp = L_min( L_tmp, 8192l /*1.0f Q13*/ ); - L_tmp = L_max( L_tmp, 4096l /*0.5f Q13*/ ); /* Q13 */ - /* keep the L_tmp; dont overwrite */ - - /* pitBufAvg = 0.0025f * sum_f(pitch_buf, 4); */ - /* pitch_buf: Q6 */ - pitBufAvg_fx = mult_r( pitch_buf[0], 1311 ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[1], 1311 ) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[2], 1311 ) ); - pitBufAvg_fx = add( pitBufAvg_fx, mult_r( pitch_buf[3], 1311 ) ); /* Q10 */ - - /* voicingBufAvg = (sum_f(voice_factors, 4)=sum2 > 0.6f) ? 0.333f : 0.1667f; */ - tmp2 = 5462 /*0.1667f Q15*/; - move16(); - if ( GT_16( sum2, 4915 /*0.6f Q13*/ ) ) - { - tmp2 = 10912 /*0.333f Q15*/; /* Q15 */ - move16(); - } - voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ - - - /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ - /* sd_uq_q: Q13, pitBufAvg_fx: Q6, voicingBufAvg_fx: Q15 */ - - /* 1/voicingBufAvg_fx */ - tmp = 32767; - move16(); - IF( voicingBufAvg_fx > 0 ) - { - exp = norm_s( voicingBufAvg_fx ); - tmp = div_s( shl( 1, sub( 14, exp ) ), voicingBufAvg_fx ); /* (14-exp) */ - - /* sd_uq_q*pitBufAvg */ - L_tmp = Mult_32_16( L_tmp, pitBufAvg_fx ); /* Q13 * Q10 + 1 -16 => Q8 */ - L_tmp = Mult_32_16( L_tmp, tmp ); /* Q8 + (14 - exp) - 15 => Q7 - exp */ - tmp = round_fx_sat( L_shl_sat( L_tmp, 31 - ( 7 - exp ) ) ); /* Q15 */ - } - - tmp = s_min( tmp, 32767 /*1.0f Q15*/ ); - tmp = s_max( tmp, 19661 /*0.6f Q15*/ ); - GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 + Q15 + 1 - 16 : Q18 */ - - test(); - IF( EQ_16( st_fx->L_frame, L_FRAME16k ) || EQ_16( st_fx->rf_mode, 1 ) ) - { - /* Compensate for energy increase mismatch due to memory-less synthesis*/ - GainFrame_fx = Mult_32_16( GainFrame_fx, 27853 /*0.85f Q15*/ ); /* Q18 */ - } - - /* Quantization of the frame gain parameter */ - QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &hRF->RF_bwe_gainFr_ind, 0 ); - - /* Adjust the subframe and frame gain of the synthesized SHB signal */ - /* Scale the shaped excitation */ - IF( EQ_32( st_fx->extl, FB_TBE ) ) - { - tmp = norm_l( GainFrame_fx ); - if ( GainFrame_fx == 0 ) - { - tmp = 31; - move16(); - } - L_tmp = L_shl( GainFrame_fx, tmp ); /* 18 + tmp */ - - tmp1 = 0; - move16(); - FOR( i = 0; i < L_FRAME16k; i++ ) - { - L_tmp1 = Mult_32_16( L_tmp, GainShape_fx[NUM_SHB_SUBFR * i / L_FRAME16k] ); /* Q : 18 + tmp +15 -15*/ - /*White_exc16k_fx[i] = round_fx( L_shl(Mult_32_16( L_tmp1, White_exc16k_fx[i]),(23 - tmp -*Q_white_exc)) );*/ - /*18 + tmp +*Q_white_exc -15 + 23 - tmp -*Q_white_exc -16 = 10*/ - White_exc16k_fx[i] = round_fx( Mult_32_16( L_tmp1, White_exc16k_fx[i] ) ); /* 18 + tmp +*Q_white_exc -15 -16 */ - move16(); - /*Lmax = L_max(Lmax,White_exc16k_fx[i]);*/ - tmp1 = s_max( tmp1, abs_s( White_exc16k_fx[i] ) ); - /*White_exc16k_fx[i] =32767;*/ - /*White_exc16k_fx[i] = shr(White_exc16k_fx[i],5);*/ - } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 13 ); /* *Q_white_exc + 18 + tmp -15 -16 */ - tmp = norm_s( tmp1 ); - if ( tmp1 == 0 ) - { - tmp = 15; - move16(); - } - - FOR( i = 0; i < L_FRAME16k; i++ ) - { - White_exc16k_fx[i] = shl( White_exc16k_fx[i], sub( tmp, 1 ) ); - move16(); - } - *Q_white_exc = sub( add( *Q_white_exc, tmp ), 1 ); - move16(); - } - - /* *Q_white_exc = Q_bwe_exc_mod; move16(); output Qwhiteexc_FB from the GenShapedSHB function*/ - hBWE_TD->prev_Q_bwe_syn = Q_bwe_exc; - move16(); - - return; -} - - -/*======================================================================================*/ -/* FUNCTION : void swb_tbe_enc_ivas_fx () */ -/*--------------------------------------------------------------------------------------*/ -/* PURPOSE : SWB TBE encoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band encoding module */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT ARGUMENTS : */ -/* _(Word16) coder_type : coding type */ -/* _(Word16*) shb_speech_fx : SHB target signal (6-14kHz) at 16kHz Q0 */ -/* _(Word16*) bwe_exc_extended :bandwidth extended exciatation Q0 */ -/* _(Word16[]) voice_factors :voicing factors Q15 */ -/* _(Word16*) Q_white_exc :Q Format of White Exc */ -/*--------------------------------------------------------------------------------------*/ -/* OUTPUT ARGUMENTS : */ -/* _(Word16[])White_exc16k_fx : shaped white excitation for the FB TBE Q_white_exc */ -/* _(Word16*)fb_slope_fx : slope +ve (high freq > low freq), -ve or neutral Q12 */ -/*--------------------------------------------------------------------------------------*/ -/* INPUT/OUTPUT ARGUMENTS : */ -/* _ Encoder_State *st_fx: : Encoder state structure */ -/*--------------------------------------------------------------------------------------*/ -/* RETURN ARGUMENTS : */ -/* _ None */ -/*--------------------------------------------------------------------------------------*/ -/* CALLED FROM : TX */ -/*======================================================================================*/ - -void swb_tbe_enc_ivas_fx( -#endif Encoder_State *st_fx, /* i/o: encoder state structure */ STEREO_ICBWE_ENC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */ Word16 *shb_speech_fx, /* i : SHB target signal (6-14kHz) at 16kHz Q0 */ @@ -2450,7 +1531,6 @@ void swb_tbe_enc_ivas_fx( 1 ); /* Spectral smoothing of autocorrelation coefficients */ -#ifdef HARMONIZE_TBE3 const Word16 *p_wac_swb_h, *p_wac_swb_l; IF( st_fx->element_mode == EVS_MONO ) { @@ -2462,18 +1542,13 @@ void swb_tbe_enc_ivas_fx( p_wac_swb_h = wac_swb_ivas_h; p_wac_swb_l = wac_swb_ivas_l; } -#endif test(); test(); IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) { FOR( i = 1; i <= LPC_SHB_ORDER; i++ ) { -#ifdef HARMONIZE_TBE3 L_tmp = Mpy_32( R_h[i], R_l[i], p_wac_swb_h[i - 1], p_wac_swb_l[i - 1] ); -#else - L_tmp = Mpy_32( R_h[i], R_l[i], wac_swb_ivas_h[i - 1], wac_swb_ivas_l[i - 1] ); -#endif L_Extract( L_tmp, &R_h[i], &R_l[i] ); } } @@ -2495,9 +1570,7 @@ void swb_tbe_enc_ivas_fx( /* if the LP gain is greater than a threshold, avoid saturation */ Word16 flag_sat = 0; -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode != EVS_MONO ) -#endif { Word16 lpc_shb_fx0_req_shift = sub( norm_s( lpc_shb_fx[0] ), 2 ); IF( GT_16( lpc_shb_fx0_req_shift, 0 ) ) @@ -2520,13 +1593,11 @@ void swb_tbe_enc_ivas_fx( } /* this is needed as the E_LPC_lev_dur function outputs lpc in Q14 */ -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { Copy_Scale_sig( lpc_shb_fx, lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); } ELSE -#endif { scale_sig( lpc_shb_fx, LPC_SHB_ORDER + 1, sub( norm_s( lpc_shb_fx[0] ), 2 ) ); } @@ -2553,12 +1624,8 @@ void swb_tbe_enc_ivas_fx( test(); test(); -#ifdef HARMONIZE_TBE3 test(); IF( st_fx->element_mode != EVS_MONO && ( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || st_fx->ini_frame == 0 ) ) -#else - IF( ( NE_16( st_fx->last_extl, SWB_TBE ) && NE_16( st_fx->last_extl, FB_TBE ) ) || st_fx->ini_frame == 0 ) -#endif { FOR( i = 0; i < LPC_SHB_ORDER; i++ ) { @@ -2579,13 +1646,11 @@ void swb_tbe_enc_ivas_fx( test(); IF( st_fx->rf_mode || EQ_32( st_fx->extl_brate, SWB_TBE_0k95 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) ) { -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { lsp_weights_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); } ELSE -#endif { lsp_weights_ivas_fx( lsf_shb_fx, weights_lsp, LPC_SHB_ORDER, &Q_out ); } @@ -2616,13 +1681,11 @@ void swb_tbe_enc_ivas_fx( ELSE { /* LSF quantization (21 bits) */ -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { Quant_BWE_LSF_fx( hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl ); // this is likely a bug in EVS } ELSE -#endif { Quant_BWE_LSF_fx( hBstr, hBWE_TD, st_fx->codec_mode, lsf_shb_fx, lsf_shb_fx, st_fx->extl_brate ); } @@ -3123,7 +2186,6 @@ void swb_tbe_enc_ivas_fx( rescale_genSHB_mem_enc( st_fx, sc ); } -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { Copy( hBWE_TD->old_bwe_exc_extended_fx, bwe_exc_extended_16, NL_BUFF_OFFSET ); @@ -3137,7 +2199,6 @@ void swb_tbe_enc_ivas_fx( Copy( bwe_exc_extended_16 + L_FRAME32k, hBWE_TD->old_bwe_exc_extended_fx, NL_BUFF_OFFSET ); } ELSE -#endif { sc = sub( Q_bwe_exc, add( Q_new, Q_new ) ); @@ -3163,7 +2224,6 @@ void swb_tbe_enc_ivas_fx( move16(); /* Calculate the 6 to 14 kHz (or 7.5 - 15.5 kHz) SHB excitation signal from the ACELP core excitation */ -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { GenShapedSHBExcitation_fx( shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, @@ -3174,7 +2234,6 @@ void swb_tbe_enc_ivas_fx( &( hBWE_TD->fb_tbe_demph_fx ), &Q_bwe_exc, &Q_bwe_exc_fb, Q_shb, n_mem2, hBWE_TD->prev_Q_bwe_syn, st_fx->total_brate, 0 ); } ELSE -#endif { GenShapedSHBExcitation_ivas_fx( ENC, shaped_shb_excitation_fx + L_SHB_LAHEAD, lpc_shb_fx, White_exc16k_fx, hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx, st_fx->coder_type, bwe_exc_extended_16, hBWE_TD->bwe_seed, @@ -3242,18 +2301,12 @@ void swb_tbe_enc_ivas_fx( { FOR( i = 0; i < L_FRAME16k; i += L_SUBFR16k ) { -#ifdef HARMONIZE_TBE3 PostShortTerm_fx( st_fx->element_mode, ENC, &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); -#else - PostShortTerm_ivas_enc_fx( &shaped_shb_excitation_fx[L_SHB_LAHEAD + i], lpc_shb_fx, &shaped_shb_excitationTemp_fx[i], hBWE_TD->mem_stp_swb_fx, - hBWE_TD->ptr_mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ), hBWE_TD->mem_zero_swb_fx, formant_fac_fx ); /* shaped_shb_excitation_fx in Q_bwe_exc, lpc_shb_fx in Q12 */ -#endif } Copy( shaped_shb_excitationTemp_fx, &shaped_shb_excitation_fx[L_SHB_LAHEAD], L_FRAME16k ); -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { tmp = sub( shl( Q_bwe_exc, 1 ), 31 ); @@ -3274,7 +2327,6 @@ void swb_tbe_enc_ivas_fx( Lscale = root_a_over_b_fx( curr_pow_fx, shl( Q_bwe_exc, 1 ), prev_pow_fx, shl( Q_bwe_exc, 1 ), &exp ); } ELSE -#endif { Word16 max_val; maximum_abs_16_fx( shaped_shb_excitation_fx, L_FRAME16k + L_SHB_LAHEAD, &max_val ); @@ -3338,13 +2390,8 @@ void swb_tbe_enc_ivas_fx( tmp = i_mult_sat( sub( i, 19 ), 3277 /*0.1f Q15*/ ); /* Q15 */ L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ tmp = sub( 32767 /*1.0f Q15*/, tmp ); -#ifdef HARMONIZE_TBE3 Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ -#else - L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ -#endif shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } @@ -3356,11 +2403,9 @@ void swb_tbe_enc_ivas_fx( tmp = round_fx_sat( L_shl( L_mult( 0x6666 /* 0.1 in Q12 */, shl( sub( i, 19 ), 11 ) ), 1 ) ); L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ tmp = sub( 32767 /*1.0f Q15*/, tmp ); -#ifdef HARMONIZE_TBE3 // TODO: to be verified, at the decoder there is // Lscale = L_add( Mult_32_16( Lscale, temp_fx ), L_tmp1 ); // L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ -#endif L_tmp = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); L_tmp = Mult_32_16( L_tmp, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ @@ -3383,7 +2428,6 @@ void swb_tbe_enc_ivas_fx( /* Estimate the gain-shape parameter */ n_subfr_saturation = 0; move16(); -#ifdef HARMONIZE_TBE3 Word16 limit_min_gain = 0; move16(); IF( st_fx->element_mode == EVS_MONO ) @@ -3393,9 +2437,6 @@ void swb_tbe_enc_ivas_fx( } EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, limit_min_gain ); -#else - EstimateSHBGainShape_fx( SHB_OVERLAP_LEN, shb_frame_fx, Q_shb, shaped_shb_excitation_fx, Q_bwe_exc, GainShape_fx, subwin_shb_fx, &n_subfr_saturation, 0 ); -#endif test(); IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) @@ -3446,7 +2487,6 @@ void swb_tbe_enc_ivas_fx( } /* Gain frame adjustment factor */ -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { test(); @@ -3495,7 +2535,6 @@ void swb_tbe_enc_ivas_fx( } } ELSE -#endif { IF( hBWE_TD->prev_swb_GainShape_fx == 0 ) { @@ -3560,14 +2599,12 @@ void swb_tbe_enc_ivas_fx( move16(); /*Q15 */ } -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { GainShape_tilt_fx = 0; // just to avoid compilation warnings move16(); } ELSE -#endif { /* calculate tilt in all sub-frame gains */ Copy( GainShape_fx, GainShape_Interp_fx, NUM_SHB_SUBGAINS ); @@ -3794,14 +2831,12 @@ void swb_tbe_enc_ivas_fx( ELSE IF( EQ_16( hBWE_TD->prev_frGainAtten, 1 ) && GT_32( Mult_32_16( GainFrame_fx, 10923 ), hBWE_TD->prev_gainFr_SHB_fx ) ) { /*GainFrame *= (0.8f + 0.5f*feedback); */ -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { tmp = add( 26214, mult_r( feedback, 16384 ) ); GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 */ } ELSE -#endif { tmp = add( 13107 /* 0.8 in Q14 */, shr( feedback, 2 ) ); GainFrame_fx = L_shl( Mult_32_16( GainFrame_fx, tmp ), 1 ); /* Q18 */ @@ -3868,7 +2903,6 @@ void swb_tbe_enc_ivas_fx( } voicingBufAvg_fx = shl( mult( tmp2, sum1 ), 2 ); /* Q15 */ -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { /* max(min((float)(sd_uq_q*pitBufAvg/voicingBufAvg), 1.0f), 0.6f) */ @@ -3889,7 +2923,6 @@ void swb_tbe_enc_ivas_fx( } } ELSE -#endif { test(); IF( voicingBufAvg_fx <= 0 && Mpy_32_16_1( L_tmp, pitBufAvg_fx ) != 0 ) @@ -3921,7 +2954,6 @@ void swb_tbe_enc_ivas_fx( /* Controlled gain evolution in SWB for stronger voiced segments */ test(); -#ifdef HARMONIZE_TBE3 test(); IF( st_fx->element_mode == EVS_MONO ) { @@ -3930,9 +2962,6 @@ void swb_tbe_enc_ivas_fx( GainFrame_fx = Mult_32_16( GainFrame_fx, tmp ); /* Q18 + Q15 + 1 - 16 : Q18 */ } ELSE IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#else - IF( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) -#endif { GainFrame_fx = Mpy_32_16_1( GainFrame_fx, extract_l( L_shl( L_tmp, 2 ) ) ); } @@ -3978,13 +3007,11 @@ void swb_tbe_enc_ivas_fx( } /* Quantization of the frame gain parameter */ -#ifdef HARMONIZE_TBE3 IF( st_fx->element_mode == EVS_MONO ) { QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, &st_fx->hRF->RF_bwe_gainFr_ind, 0 ); } ELSE -#endif { QuantizeSHBframegain_fx( st_fx, &GainFrame_fx, st_fx->extl, 0, NULL, ( EQ_32( st_fx->extl_brate, SWB_TBE_1k10 ) || EQ_32( st_fx->extl_brate, SWB_TBE_1k75 ) ) ? 1 : 0 ); } -- GitLab From ce0de70b4012c0c6fcd49a714a9f58eadb39a18e Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 20:00:54 +0100 Subject: [PATCH 03/11] [cleanup] accept FIX_2459_USAN_AMR_SIDSTART --- lib_com/options.h | 1 - lib_dec/hf_synth_fx.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 8628e13c3..4e6b73922 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,7 +84,6 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ -#define FIX_2459_USAN_AMR_SIDSTART /* FhG: basop issue 2459: fix msan complaint */ #define FIX_2458_USAN_NULLPTR_WITH_ZERO_OFFSET /* FhG: basop issue 2458: avoid indexing into null pointer */ #define HARM_2456_APPLY_SCALE /* FhG basop issue 2456: Harmonize apply_scale_ind(), apply_scale_ivas_fx() */ #define HARM_2454_TCX_RES_Q_SPEC /* FhG: harmonization of tcx_res_Q_spec_fx() and tcx_res_Q_spec_ivas_fx() */ diff --git a/lib_dec/hf_synth_fx.c b/lib_dec/hf_synth_fx.c index 99656ace0..9c4807835 100644 --- a/lib_dec/hf_synth_fx.c +++ b/lib_dec/hf_synth_fx.c @@ -994,14 +994,12 @@ void hf_synth_amr_wb_fx( move16(); /* qdct */ pt1++; } -#ifdef FIX_2459_USAN_AMR_SIDSTART /* initialize to fix MSAN complaint - array is never actually accessed in this case */ FOR( i = 0; i < NB_SUBFR; i++ ) { HF_corr_gain[i] = 32767; /* one in Q15 */ } -#endif } q_tmp = Exp16Array( L_FRAME16k, dct_hb ); -- GitLab From cf21d21e701f0efca4c6c1384963a57333ec0792 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 20:01:53 +0100 Subject: [PATCH 04/11] [cleanup] accept FIX_2458_USAN_NULLPTR_WITH_ZERO_OFFSET --- lib_com/options.h | 1 - lib_rend/ivas_objectRenderer_fx.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 4e6b73922..573601c37 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,7 +84,6 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ -#define FIX_2458_USAN_NULLPTR_WITH_ZERO_OFFSET /* FhG: basop issue 2458: avoid indexing into null pointer */ #define HARM_2456_APPLY_SCALE /* FhG basop issue 2456: Harmonize apply_scale_ind(), apply_scale_ivas_fx() */ #define HARM_2454_TCX_RES_Q_SPEC /* FhG: harmonization of tcx_res_Q_spec_fx() and tcx_res_Q_spec_ivas_fx() */ #define FIX_FLOAT_1535_ARI_RES_Q_CLEANUP /* FhG: remove dead code from tcx_ari_res_Q_spec() */ diff --git a/lib_rend/ivas_objectRenderer_fx.c b/lib_rend/ivas_objectRenderer_fx.c index a447eeaf1..02e280949 100644 --- a/lib_rend/ivas_objectRenderer_fx.c +++ b/lib_rend/ivas_objectRenderer_fx.c @@ -446,11 +446,7 @@ ivas_error ivas_td_binaural_renderer_unwrap_fx( move16(); } -#ifdef FIX_2458_USAN_NULLPTR_WITH_ZERO_OFFSET IF( NE_32( ( error = TDREND_Update_listener_orientation_fx( hBinRendererTd, tmp_headRotEnabled, ( Quaternions != NULL ) ? &Quaternions[tmp_CombinedOrient_subframe_idx] : NULL, ( Pos != NULL ) ? &Pos[tmp_CombinedOrient_subframe_idx] : NULL ) ), IVAS_ERR_OK ) ) -#else -IF( NE_32( ( error = TDREND_Update_listener_orientation_fx( hBinRendererTd, tmp_headRotEnabled, &Quaternions[tmp_CombinedOrient_subframe_idx], &Pos[tmp_CombinedOrient_subframe_idx] ) ), IVAS_ERR_OK ) ) -#endif { return error; } -- GitLab From 0e798db48bc885676e3bcd43b7321cdc7bc4631a Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 20:02:41 +0100 Subject: [PATCH 05/11] [cleanup] accept HARM_2456_APPLY_SCALE --- lib_com/cng_exc_fx.c | 4 ---- lib_com/fd_cng_com_fx.c | 28 ---------------------------- lib_com/options.h | 1 - lib_com/prot_fx.h | 9 --------- lib_enc/cng_enc_fx.c | 6 ------ 5 files changed, 48 deletions(-) diff --git a/lib_com/cng_exc_fx.c b/lib_com/cng_exc_fx.c index 084f28796..5ba48494e 100644 --- a/lib_com/cng_exc_fx.c +++ b/lib_com/cng_exc_fx.c @@ -872,11 +872,7 @@ void cng_params_upd_fx( Word16 index = 0; move32(); move16(); -#ifdef HARM_2456_APPLY_SCALE index = apply_scale_ind( &att_fx, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO ); -#else - apply_scale_ivas_fx( &att_fx, bwidth, last_active_brate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO, &index ); -#endif att_fx = pow_10_q23[index]; // Q23 move32(); tmp = extract_h( att_fx ); // Q7 diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index 8f3cf09e3..b6eeab177 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -1759,34 +1759,6 @@ Word16 apply_scale_ind( return i; } -#ifndef HARM_2456_APPLY_SCALE -void apply_scale_ivas_fx( - Word32 *scale, /* o : scalefactor */ - const Word16 bwmode, /* i : audio bandwidth */ - const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP *scaleTable, /* i : Scale table Q7 */ - const Word16 scaleTableSize, /* i : Size of scale table */ - Word16 *index ) -{ - Word16 i; - FOR( i = 0; i < scaleTableSize; i++ ) - { - cast16(); - IF( s_and( (Word16) EQ_16( bwmode, (Word16) scaleTable[i].bwmode ), - s_and( L_sub( bitrate, scaleTable[i].bitrateFrom ) >= 0, - L_sub( bitrate, scaleTable[i].bitrateTo ) < 0 ) ) ) - { - BREAK; - } - } - assert( i < scaleTableSize ); - - *scale = L_add( *scale, L_deposit_h( scaleTable[i].scale ) ); - move32(); - *index = i; - move16(); -} -#endif /*------------------------------------------------------------------- * bandcombinepow() * diff --git a/lib_com/options.h b/lib_com/options.h index 573601c37..490afe9e8 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,7 +84,6 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ -#define HARM_2456_APPLY_SCALE /* FhG basop issue 2456: Harmonize apply_scale_ind(), apply_scale_ivas_fx() */ #define HARM_2454_TCX_RES_Q_SPEC /* FhG: harmonization of tcx_res_Q_spec_fx() and tcx_res_Q_spec_ivas_fx() */ #define FIX_FLOAT_1535_ARI_RES_Q_CLEANUP /* FhG: remove dead code from tcx_ari_res_Q_spec() */ #define HQ_ALIGN_DUPLICATED_CODE /* Eri: Align duplicated code */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 128b232f3..fe805323e 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4708,15 +4708,6 @@ Word16 apply_scale_ind( const SCALE_SETUP *scaleTable, /* i : Scale table */ const Word16 scaleTableSize /* i : Size of scale table */ ); -#ifndef HARM_2456_APPLY_SCALE -void apply_scale_ivas_fx( - Word32 *scale, /* o : scalefactor */ - const Word16 bwmode, /* i : audio bandwidth */ - const Word32 bitrate, /* i : Bit rate */ - const SCALE_SETUP *scaleTable, /* i : Scale table */ - const Word16 scaleTableSize, /* i : Size of scale table */ - Word16 *index ); -#endif /* Compute the power for each partition */ void bandcombinepow( diff --git a/lib_enc/cng_enc_fx.c b/lib_enc/cng_enc_fx.c index 0d6de1ed5..9ca7edab8 100644 --- a/lib_enc/cng_enc_fx.c +++ b/lib_enc/cng_enc_fx.c @@ -1679,14 +1679,8 @@ static Word16 shb_DTX_fx( { Word32 att_fx32 = 0; move32(); -#ifdef HARM_2456_APPLY_SCALE apply_scale( &att_fx32, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO ); // Q23; -#else - Word16 index; - - apply_scale_ivas_fx( &att_fx32, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO, &index ); // Q23; -#endif att_fx = extract_l( L_shr( att_fx32, 15 ) ); // Q8 } -- GitLab From 0ee6276d2f13cd06bd32293205c15c9badfbc703 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 20:03:30 +0100 Subject: [PATCH 06/11] [cleanup] accept HARM_2454_TCX_RES_Q_SPEC --- lib_com/options.h | 1 - lib_enc/cod_tcx_fx.c | 8 -- lib_enc/prot_fx_enc.h | 15 --- lib_enc/tcx_utils_enc_fx.c | 183 ------------------------------------- 4 files changed, 207 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 490afe9e8..9cdfe7e29 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,7 +84,6 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ -#define HARM_2454_TCX_RES_Q_SPEC /* FhG: harmonization of tcx_res_Q_spec_fx() and tcx_res_Q_spec_ivas_fx() */ #define FIX_FLOAT_1535_ARI_RES_Q_CLEANUP /* FhG: remove dead code from tcx_ari_res_Q_spec() */ #define HQ_ALIGN_DUPLICATED_CODE /* Eri: Align duplicated code */ #define FIX_2467_RENAME_GSC_FUNCTION /* VA: basop issue 2467: Removal of unused function/table and renaming of _ivas_fx versions to default ones. */ diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index 960d9d832..d2260c190 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3589,19 +3589,11 @@ void QuantizeTCXSpectrum_fx( resQBits = tcx_res_Q_gain_fx( gain_tcx_opt_fx, gain_tcx_opt_e, gain_tcx_fx, gain_tcx_e, sqQ + L_spec, resQTargetBits ); IF( st->tcxonly ) { -#ifdef HARM_2454_TCX_RES_Q_SPEC resQBits = tcx_res_Q_spec_fx( x_orig_fx, x_orig_e, spectrum_fx, *spectrum_e, L_spec, *gain_tcx_fx, *gain_tcx_e, sqQ + L_spec, resQTargetBits, resQBits, st->hTcxCfg->sq_rounding, NULL ); -#else - resQBits = tcx_res_Q_spec_ivas_fx( x_orig_fx, x_orig_e, spectrum_fx, *spectrum_e, L_spec, *gain_tcx_fx, *gain_tcx_e, sqQ + L_spec, resQTargetBits, resQBits, st->hTcxCfg->sq_rounding, NULL ); -#endif } ELSE { -#ifdef HARM_2454_TCX_RES_Q_SPEC resQBits = tcx_res_Q_spec_fx( x_orig_fx, x_orig_e, spectrum_fx, *spectrum_e, L_spec, *gain_tcx_fx, *gain_tcx_e, sqQ + L_spec, resQTargetBits, resQBits, st->hTcxCfg->sq_rounding, lf_deemph_fact_fx ); -#else - resQBits = tcx_res_Q_spec_ivas_fx( x_orig_fx, x_orig_e, spectrum_fx, *spectrum_e, L_spec, *gain_tcx_fx, *gain_tcx_e, sqQ + L_spec, resQTargetBits, resQBits, st->hTcxCfg->sq_rounding, lf_deemph_fact_fx ); -#endif } } } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 64ab8f2d6..0bb6cac18 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1296,21 +1296,6 @@ Word16 tcx_res_Q_spec_fx( Word16 sq_round, const Word16 lf_deemph_factors[] ); -#ifndef HARM_2454_TCX_RES_Q_SPEC -Word16 tcx_res_Q_spec_ivas_fx( - Word32 *x_orig, - Word16 x_orig_e, - Word32 *x_Q, - Word16 x_Q_e, - Word16 L_frame, - Word16 sqGain, - Word16 sqGain_e, - Word16 *prm, - Word16 sqTargetBits, - Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] ); -#endif /* compute noise-measure flags for spectrum filling and quantization (0: tonal, 1: noise-like) */ void ComputeSpectrumNoiseMeasure_fx( const Word32 *powerSpec, diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index eb6cfd187..097e09dd6 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -3392,7 +3392,6 @@ Word16 tcx_res_Q_gain_fx( return bits; } -#ifndef HARM_2454_TCX_RES_Q_SPEC Word16 tcx_res_Q_spec_fx( Word32 *x_orig, Word16 x_orig_e, @@ -3407,188 +3406,6 @@ Word16 tcx_res_Q_spec_fx( Word16 sq_round, const Word16 lf_deemph_factors[] /* 1Q14 */ ) -{ - Word16 i; - Word16 fac_m, fac_p; - Word32 tmp1, tmp2; - Word16 s, s2, lf_deemph_factor; - Word16 c; - Word32 thres; - - /* Limit the number of residual bits */ - sqTargetBits = s_min( sqTargetBits, NPRM_RESQ ); - - /* Requantize the spectrum line-by-line */ - fac_m = shr( sq_round, 1 ); - fac_p = sub( 0x4000, fac_m ); - - /* exponent difference of x_orig and x_Q * sqGain */ - s = sub( x_orig_e, add( x_Q_e, sqGain_e ) ); - - lf_deemph_factor = 0x4000; - move16(); - s2 = sub( x_Q_e, 1 ); - - FOR( i = 0; i < L_frame; i++ ) - { - IF( GE_16( bits, sub( sqTargetBits, kMaxEstimatorUndershoot ) ) ) - { - fac_m = 0; - move16(); - fac_p = 0; - move16(); - - IF( GE_16( bits, s_min( NPRM_RESQ, add( sqTargetBits, kMaxEstimatorOvershoot ) ) ) ) - { - BREAK; - } - } - - test(); - test(); - IF( ( x_Q[i] != 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) - { - tmp1 = L_add( x_orig[i], 0 ); - tmp2 = Mpy_32_16_1( x_Q[i], sqGain ); - IF( s > 0 ) - { - tmp2 = L_shr( tmp2, s ); - } - IF( s < 0 ) - { - tmp1 = L_shl( tmp1, s ); - } - - if ( lf_deemph_factors != NULL ) - { - lf_deemph_factor = lf_deemph_factors[i]; - move16(); - } - - IF( LT_32( tmp1, tmp2 ) ) - { - prm[bits] = 0; - move16(); - bits = add( bits, 1 ); - - IF( x_Q[i] > 0 ) - { - tmp1 = L_mult( fac_m, lf_deemph_factor ); - } - IF( x_Q[i] < 0 ) - { - tmp1 = L_mult( fac_p, lf_deemph_factor ); - } - x_Q[i] = L_sub( x_Q[i], L_shr( tmp1, s2 ) ); - move32(); - } - ELSE - { - prm[bits] = 1; - move16(); - bits = add( bits, 1 ); - - IF( x_Q[i] > 0 ) - { - tmp1 = L_mult( fac_p, lf_deemph_factor ); - } - IF( x_Q[i] < 0 ) - { - tmp1 = L_mult( fac_m, lf_deemph_factor ); - } - x_Q[i] = L_add( x_Q[i], L_shr( tmp1, s2 ) ); - move32(); - } - } - } - - /*Quantize zeroed-line of the spectrum*/ - c = sub( 21627 /*0.66f Q15*/, mult_r( sq_round, 21627 /*0.66f Q15*/ ) ); - - FOR( i = 0; i < L_frame; i++ ) - { - IF( GE_16( bits, sub( sqTargetBits, 2 ) ) ) - { - BREAK; - } - - test(); - test(); - IF( ( x_Q[i] == 0 ) && ( ( lf_deemph_factors == NULL ) || ( GT_16( lf_deemph_factors[i], 0x2000 ) ) ) ) - { - if ( lf_deemph_factors != NULL ) - { - lf_deemph_factor = lf_deemph_factors[i]; - move16(); - } - - thres = L_mult( c, lf_deemph_factor ); - tmp1 = L_shl( Mpy_32_16_1( thres, sqGain ), sub( sqGain_e, x_orig_e ) ); - - IF( GT_32( x_orig[i], tmp1 ) ) - { - prm[bits] = 1; - move16(); - bits = add( bits, 1 ); - - prm[bits] = 1; - move16(); - bits = add( bits, 1 ); - - x_Q[i] = L_shl( thres, sub( 1, x_Q_e ) ); - move32(); - } - ELSE IF( L_add( x_orig[i], tmp1 ) < 0 ) - { - prm[bits] = 1; - move16(); - bits = add( bits, 1 ); - - prm[bits] = 0; - move16(); - bits = add( bits, 1 ); - - x_Q[i] = L_shl( L_negate( thres ), sub( 1, x_Q_e ) ); - move32(); - } - ELSE - { - prm[bits] = 0; - move16(); - bits = add( bits, 1 ); - } - } - } - - /*Be sure that every possible bits are initialized*/ - FOR( i = bits; i < NPRM_RESQ; i++ ) - { - prm[i] = 0; - move16(); - } - - - return bits; -} - - -Word16 tcx_res_Q_spec_ivas_fx( -#else -Word16 tcx_res_Q_spec_fx( -#endif - Word32 *x_orig, - Word16 x_orig_e, - Word32 *x_Q, - Word16 x_Q_e, - Word16 L_frame, - Word16 sqGain, - Word16 sqGain_e, - Word16 *prm, - Word16 sqTargetBits, - Word16 bits, - Word16 sq_round, - const Word16 lf_deemph_factors[] /* 1Q14 */ -) { Word16 i; Word16 fac_m, fac_p; -- GitLab From 28982fee7dd433df3b1a33ac379af60f07b692a6 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 20:04:28 +0100 Subject: [PATCH 07/11] [cleanup] accept FIX_FLOAT_1535_ARI_RES_Q_CLEANUP --- lib_com/options.h | 1 - lib_enc/cod_tcx_fx.c | 4 - lib_enc/prot_fx_enc.h | 17 --- lib_enc/tcx_utils_enc_fx.c | 234 ------------------------------------- 4 files changed, 256 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 9cdfe7e29..2a5e164c6 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -84,7 +84,6 @@ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ #define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ -#define FIX_FLOAT_1535_ARI_RES_Q_CLEANUP /* FhG: remove dead code from tcx_ari_res_Q_spec() */ #define HQ_ALIGN_DUPLICATED_CODE /* Eri: Align duplicated code */ #define FIX_2467_RENAME_GSC_FUNCTION /* VA: basop issue 2467: Removal of unused function/table and renaming of _ivas_fx versions to default ones. */ #define HARMONIZE_FUNC /* VA: basop issue 2460: Remove duplicated code: various functions */ diff --git a/lib_enc/cod_tcx_fx.c b/lib_enc/cod_tcx_fx.c index d2260c190..aff171740 100644 --- a/lib_enc/cod_tcx_fx.c +++ b/lib_enc/cod_tcx_fx.c @@ -3570,11 +3570,7 @@ void QuantizeTCXSpectrum_fx( prm_resq = sqQ + sub( sqTargetBits, resQTargetBits ); -#ifdef FIX_FLOAT_1535_ARI_RES_Q_CLEANUP resQBits = tcx_ari_res_Q_spec_fx( x_orig_fx, x_orig_e, hm_cfg->indexBuffer, spectrum_fx, *spectrum_e, L_spec, *gain_tcx_fx, *gain_tcx_e, prm_resq, resQTargetBits, resQBits, st->hTcxCfg->sq_rounding, lf_deemph_fact_fx ); -#else - resQBits = tcx_ari_res_Q_spec_ivas_fx( x_orig_fx, x_orig_e, hm_cfg->indexBuffer, spectrum_fx, *spectrum_e, L_spec, *gain_tcx_fx, *gain_tcx_e, prm_resq, resQTargetBits, resQBits, st->hTcxCfg->sq_rounding, lf_deemph_fact_fx ); -#endif /* Transmit zeros when there bits remain after RESQ */ FOR( i = resQBits; i < resQTargetBits; ++i ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 0bb6cac18..fbe9c0f01 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -1257,23 +1257,6 @@ Word16 tcx_ari_res_Q_spec_fx( const Word16 x_fac[] /* i : spectrum post-quantization factors Q14 */ ); -#ifndef FIX_FLOAT_1535_ARI_RES_Q_CLEANUP -Word16 tcx_ari_res_Q_spec_ivas_fx( - const Word32 x_orig[], /* i : original spectrum Q31-e */ - Word16 x_orig_e, /* i : original spectrum exponent Q0 */ - const Word16 signs[], /* i : signs (x_orig[.]<0) Q0 */ - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i : quantized spectrum exponent Q0 */ - Word16 L_frame, /* i : number of lines Q0 */ - Word16 gain, /* i : TCX gain Q15-e */ - Word16 gain_e, /* i : TCX gain exponent Q0 */ - Word16 prm[], /* o : bit-stream Q0 */ - Word16 target_bits, /* i : number of bits available Q0 */ - Word16 bits, /* i : number of bits used so far Q0 */ - Word16 deadzone, /* i : quantizer deadzone Q15 */ - const Word16 x_fac[] /* i : spectrum post-quantization factors Q14 */ -); -#endif Word16 tcx_res_Q_gain_fx( Word16 sqGain, Word16 sqGain_e, diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 097e09dd6..d38d2efd4 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -2996,9 +2996,7 @@ Word16 tcx_ari_res_Q_spec_fx( num_zeros = 0; move16(); -#ifdef FIX_FLOAT_1535_ARI_RES_Q_CLEANUP assert( x_fac != NULL ); -#endif s = sub( add( gain_e, x_Q_e ), x_orig_e ); FOR( i = 0; i < L_frame; i++ ) @@ -3101,238 +3099,6 @@ Word16 tcx_ari_res_Q_spec_fx( return bits; } -#ifndef FIX_FLOAT_1535_ARI_RES_Q_CLEANUP -Word16 tcx_ari_res_Q_spec_ivas_fx( - const Word32 x_orig[], /* i : original spectrum Q31-e */ - Word16 x_orig_e, /* i : original spectrum exponent Q0 */ - const Word16 signs[], /* i : signs (x_orig[.]<0) Q0 */ - Word32 x_Q[], /* i/o: quantized spectrum Q31-e */ - Word16 x_Q_e, /* i : quantized spectrum exponent Q0 */ - Word16 L_frame, /* i : number of lines Q0 */ - Word16 gain, /* i : TCX gain Q15-e */ - Word16 gain_e, /* i : TCX gain exponent Q0 */ - Word16 prm[], /* o : bit-stream Q0 */ - Word16 target_bits, /* i : number of bits available Q0 */ - Word16 bits, /* i : number of bits used so far Q0 */ - Word16 deadzone, /* i : quantizer deadzone Q15 */ - const Word16 x_fac[] /* i : spectrum post-quantization factors Q14 */ -) -{ - Word16 i, j, num_zeros; - Word16 zeros[L_FRAME_PLUS]; - Word16 fac_p, sign; - Word32 thres, x_Q_m, x_Q_p; - Word32 L_tmp, L_tmp2; - Word16 s, s2; - - /* Limit the number of residual bits */ - target_bits = s_min( target_bits, NPRM_RESQ ); - - /* Requantize the spectrum line-by-line */ - /* fac_m = deadzone * 0.5f; - fac_p = 0.5f - fac_m; */ - num_zeros = 0; - move16(); - s = sub( add( gain_e, x_Q_e ), x_orig_e ); - IF( x_fac == NULL ) - { - FOR( i = 0; i < L_frame; ++i ) - { - IF( GE_16( bits, target_bits ) ) /* no bits left */ - { - BREAK; - } - - IF( x_Q[i] != 0 ) - { - sign = shl( sub( 1, shl( signs[i], 1 ) ), Q14 ); - move16(); - - /* x_Q_m = x_Q[i] - sign*fac_m; - x_Q_p = x_Q[i] + sign*fac_p; */ - - L_tmp = L_mult( sign, deadzone ); /* sign*deadzone/2 in Q31 */ - x_Q_m = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) ); - - L_tmp = L_mac( L_tmp, sign, (Word16) 0x8000 ); /* sign*(deadzone-1)/2 in Q31 */ - x_Q_p = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) ); - - /* if (fabs(x_orig[i] - gain * x_Q_m) < fabs(x_orig[i] - gain * x_Q_p)) */ - L_tmp = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_m, gain ), s ) ) ); - L_tmp2 = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_p, gain ), s ) ) ); - - IF( LT_32( L_tmp, L_tmp2 ) ) /* Decrease magnitude */ - { - x_Q[i] = x_Q_m; - move32(); - prm[bits] = 0; - move16(); - } - ELSE /* Increase magnitude */ - { - x_Q[i] = x_Q_p; - move32(); - prm[bits] = 1; - move16(); - } - bits = add( bits, 1 ); - } - ELSE - { - zeros[num_zeros] = i; - move16(); - num_zeros = add( num_zeros, 1 ); - } - } - - /* Requantize zeroed-lines of the spectrum */ - fac_p = msu_r( 1417339264l /*2*0.33f Q31*/, deadzone, 21627 /*2*0.33f Q15*/ ); /* Q16 */ - target_bits = sub( target_bits, 1 ); /* reserve 1 bit for the check below */ - - s = sub( gain_e, x_orig_e ); - s2 = sub( x_Q_e, 1 ); - FOR( j = 0; j < num_zeros; j++ ) - { - IF( GE_16( bits, target_bits ) ) /* 1 or 0 bits left */ - { - BREAK; - } - - i = zeros[j]; - move16(); - - thres = L_shl( fac_p, Q15 ); /* Q31 */ - - IF( GT_32( L_abs( x_orig[i] ), L_shl( Mpy_32_16_1( thres, gain ), s ) ) ) - { - prm[bits] = 1; - move16(); - bits = add( bits, 1 ); - - prm[bits] = sub( 1, signs[i] ); - move16(); - bits = add( bits, 1 ); - - L_tmp = L_shr( thres, s2 ); - IF( signs[i] ) - { - L_tmp = L_negate( L_tmp ); - } - x_Q[i] = L_tmp; - move32(); - } - ELSE - { - prm[bits] = 0; - move16(); - bits = add( bits, 1 ); - } - } - - return bits; - } - - s = sub( add( gain_e, x_Q_e ), x_orig_e ); - FOR( i = 0; i < L_frame; i++ ) - { - IF( GE_16( bits, target_bits ) ) /* no bits left */ - { - BREAK; - } - - IF( x_Q[i] != 0 ) - { - sign = x_fac[i]; - move16(); - IF( signs[i] != 0 ) - { - sign = negate( sign ); - } - - /* x_Q_m = x_Q[i] - sign*fac_m; - x_Q_p = x_Q[i] + sign*fac_p; */ - - L_tmp = L_mult( sign, deadzone ); /* sign*deadzone/2 in Q31 */ - x_Q_m = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) ); - - L_tmp = L_mac( L_tmp, sign, (Word16) 0x8000 ); /* sign*(deadzone-1)/2 in Q31 */ - x_Q_p = L_sub( x_Q[i], L_shr( L_tmp, x_Q_e ) ); - - /* if (fabs(x_orig[i] - gain * x_Q_m) < fabs(x_orig[i] - gain * x_Q_p)) */ - L_tmp = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_m, gain ), s ) ) ); - L_tmp2 = L_abs( L_sub( x_orig[i], L_shl( Mpy_32_16_1( x_Q_p, gain ), s ) ) ); - - IF( LT_32( L_tmp, L_tmp2 ) ) /* Decrease magnitude */ - { - x_Q[i] = x_Q_m; - move32(); - prm[bits] = 0; - move16(); - } - ELSE /* Increase magnitude */ - { - x_Q[i] = x_Q_p; - move32(); - prm[bits] = 1; - move16(); - } - bits = add( bits, 1 ); - } - ELSE - { - zeros[num_zeros] = i; - move16(); - num_zeros = add( num_zeros, 1 ); - } - } - - /* Requantize zeroed-lines of the spectrum */ - fac_p = msu_r( 1417339264l /*2*0.33f Q31*/, deadzone, 21627 /*2*0.33f Q15*/ ); /* Q16 */ - target_bits = sub( target_bits, 1 ); /* reserve 1 bit for the check below */ - - s = sub( gain_e, x_orig_e ); - s2 = sub( x_Q_e, 1 ); - FOR( j = 0; j < num_zeros; j++ ) - { - IF( GE_16( bits, target_bits ) ) /* 1 or 0 bits left */ - { - BREAK; - } - - i = zeros[j]; - move16(); - - thres = L_mult( fac_p, x_fac[i] ); /* Q31 */ - - IF( GT_32( L_abs( x_orig[i] ), L_shl( Mpy_32_16_1( thres, gain ), s ) ) ) - { - prm[bits] = 1; - move16(); - bits = add( bits, 1 ); - - prm[bits] = sub( 1, signs[i] ); - move16(); - bits = add( bits, 1 ); - - L_tmp = L_shr( thres, s2 ); - IF( signs[i] ) - { - L_tmp = L_negate( L_tmp ); - } - x_Q[i] = L_tmp; - move32(); - } - ELSE - { - prm[bits] = 0; - move16(); - bits = add( bits, 1 ); - } - } - - return bits; -} -#endif #define kMaxEstimatorOvershoot 5 #define kMaxEstimatorUndershoot 0 -- GitLab From 511afb40fb5a76572f4d0128d0aca89bf8a180ae Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 20:05:13 +0100 Subject: [PATCH 08/11] [cleanup] accept FIX_2283_ISM_MD_DELAY --- lib_com/options.h | 1 - lib_rend/lib_rend_fx.c | 5 ----- 2 files changed, 6 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2a5e164c6..a64b81aa4 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -102,7 +102,6 @@ /* any switch which is non-be wrt. TS 26.251 V3.0 */ #define FIX_2448_RENDERER_MSAN_ERROR /* FhG: basop issue 2448: fix MSAN error with MSA rendering */ -#define FIX_2283_ISM_MD_DELAY /* Dolby: Fix ISM metadata delay round-off */ #define FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING /* FhG: basop issue 2262: correct buffer update for FD-CNG buffer in case of BR switching */ #define FIX_2440_AGC_PRESCALING /* FhG: basop issue 2440: Fix loop bounds when scaling p_output_fx before ivas_spar_dec_agc_pca_fx() */ #define FIX_2471_REMOVE_POSSIBLE_OVRF /* VA: basop issue 2471: correcting undesired overflow */ diff --git a/lib_rend/lib_rend_fx.c b/lib_rend/lib_rend_fx.c index 28e23d187..d312c8f10 100644 --- a/lib_rend/lib_rend_fx.c +++ b/lib_rend/lib_rend_fx.c @@ -1817,13 +1817,8 @@ static ivas_error alignInputDelay( Word64 tmp; inputIsm = (input_ism *) inputBase; -#ifdef FIX_2283_ISM_MD_DELAY tmp = W_mult0_32_32( L_add( maxGlobalDelayNs, 500000 /* + 0.5ms for rounding */ ) /* Q0 */, 4295 /* (1 / 1e6f) in Q32 */ ); // Q32 inputIsm->ism_metadata_delay_ms_fx = add( inputIsm->ism_metadata_delay_ms_fx, extract_l( W_extract_h( tmp ) ) ); -#else - tmp = W_mult0_32_32( L_add( maxGlobalDelayNs, 500000 /* + 0.5ms for rounding */ ) /* Q0 */, 2147 /* (1 / 1e6f) in Q31 */ ); // Q31 - inputIsm->ism_metadata_delay_ms_fx = add( inputIsm->ism_metadata_delay_ms_fx, extract_h( W_extract_h( tmp ) ) ); -#endif } } } -- GitLab From a2f20d294513f7734259e701ef86e709e58454a9 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 20:06:10 +0100 Subject: [PATCH 09/11] [cleanup] accept FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING --- lib_com/fd_cng_com_fx.c | 3 --- lib_com/options.h | 1 - lib_com/prot_fx.h | 11 ++--------- lib_com/stat_com.h | 3 --- lib_dec/amr_wb_dec_fx.c | 6 ++---- lib_dec/core_switching_dec_fx.c | 25 +------------------------ lib_dec/evs_dec_fx.c | 6 ++---- lib_dec/ivas_core_dec_fx.c | 20 -------------------- 8 files changed, 7 insertions(+), 68 deletions(-) diff --git a/lib_com/fd_cng_com_fx.c b/lib_com/fd_cng_com_fx.c index b6eeab177..4677016f8 100644 --- a/lib_com/fd_cng_com_fx.c +++ b/lib_com/fd_cng_com_fx.c @@ -166,9 +166,6 @@ void initFdCngCom( set16_fx( hFdCngCom->coherence_fx, 16384 /* 0.5 in Q15 */, MDCT_ST_DTX_NUM_COHERENCE_BANDS ); -#ifndef FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING - set32_fx( hFdCngCom->olapBufferSynth_fx, 0, FFTLEN ); -#endif #ifndef FIX_BASOP_REMOVE_SYNTH2_FX set32_fx( hFdCngCom->olapBufferSynth2_fx, 0, FFTLEN ); #endif diff --git a/lib_com/options.h b/lib_com/options.h index a64b81aa4..2e2667cda 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -102,7 +102,6 @@ /* any switch which is non-be wrt. TS 26.251 V3.0 */ #define FIX_2448_RENDERER_MSAN_ERROR /* FhG: basop issue 2448: fix MSAN error with MSA rendering */ -#define FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING /* FhG: basop issue 2262: correct buffer update for FD-CNG buffer in case of BR switching */ #define FIX_2440_AGC_PRESCALING /* FhG: basop issue 2440: Fix loop bounds when scaling p_output_fx before ivas_spar_dec_agc_pca_fx() */ #define FIX_2471_REMOVE_POSSIBLE_OVRF /* VA: basop issue 2471: correcting undesired overflow */ #define FIX_2465_Q_BWE_EXC /* VA: basop issue 2465: fix calculation of Q_bwe_exc in SWB TBE encoder */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index fe805323e..828007025 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7091,18 +7091,11 @@ ivas_error core_switching_pre_dec_fx( const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ const Word32 last_element_brate, /* i : last element bitrate */ -#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) && defined( FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING ) +#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) const Word16 Q_old_synthFB ); -#elif defined( FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING ) +#else const Word16 Q_old_synthFB, Word16 *Q_olapBufferSynth2 ); -#elif defined( FIX_BASOP_REMOVE_SYNTH2_FX ) - const Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth ); -#else - const Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth, - Word16 *Q_olapBufferSynth2 ); #endif ivas_error core_switching_post_dec_fx( diff --git a/lib_com/stat_com.h b/lib_com/stat_com.h index d952b6a78..148c75873 100644 --- a/lib_com/stat_com.h +++ b/lib_com/stat_com.h @@ -367,9 +367,6 @@ typedef struct Word16 fftlenFac; // Q0 Word16 timeDomainBuffer[L_FRAME16k]; /*Q15*/ -#ifndef FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING - Word32 olapBufferSynth_fx[FFTLEN]; /*Q_olapBufferSynth*/ -#endif #ifndef FIX_BASOP_REMOVE_SYNTH2_FX Word32 olapBufferSynth2_fx[FFTLEN]; #endif diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index bc04b021d..26b5d26d3 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -173,12 +173,10 @@ ivas_error amr_wb_dec_fx( } /* Updates in case of EVS -> AMR-WB IO switching */ -#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) && defined( FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING ) +#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1 ) ), IVAS_ERR_OK ) ) -#elif defined( FIX_BASOP_REMOVE_SYNTH2_FX ) || defined( FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING ) - IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16 ) ), IVAS_ERR_OK ) ) #else - IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16 ) ), IVAS_ERR_OK ) ) + IF( NE_32( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16 ) ), IVAS_ERR_OK ) ) #endif { return error; diff --git a/lib_dec/core_switching_dec_fx.c b/lib_dec/core_switching_dec_fx.c index 07b991ee9..001cfa975 100644 --- a/lib_dec/core_switching_dec_fx.c +++ b/lib_dec/core_switching_dec_fx.c @@ -1157,17 +1157,10 @@ ivas_error core_switching_pre_dec_fx( const Word16 nchan_out, /* i : number of output channels */ const Word16 last_element_mode, /* i : last_element_mode */ const Word32 last_element_brate, /* i : last element bitrate */ -#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) && defined( FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING ) +#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) const Word16 Q_old_synthFB ) -#elif defined( FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING ) - const Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth2 ) -#elif defined( FIX_BASOP_REMOVE_SYNTH2_FX ) - const Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth ) #else const Word16 Q_old_synthFB, - Word16 *Q_olapBufferSynth, Word16 *Q_olapBufferSynth2 ) #endif { @@ -1969,40 +1962,24 @@ ivas_error core_switching_pre_dec_fx( test(); IF( LE_32( st->total_brate, SID_2k40 ) && LE_32( st->last_total_brate, SID_2k40 ) ) { -#ifdef FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING lerp( st->hFdCngDec->hFdCngCom->olapBufferSynth, st->hFdCngDec->hFdCngCom->olapBufferSynth, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ) ); -#else - L_lerp_fx( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, st->hFdCngDec->hFdCngCom->olapBufferSynth_fx, shl( st->L_frame, 1 ), shl( st->last_L_frame, 1 ), Q_olapBufferSynth ); -#endif IF( EQ_16( st->L_frame, L_FRAME ) ) { FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) { -#ifdef FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING st->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[i], 20480 /* Q15*/ ); /* (Q15 - olapBufferSynth_exp) */ move16(); -#else - st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], (Word16) 20480 /* 0.6250f in Q15 */ ); - move32(); -#endif } } ELSE { FOR( i = 0; i < shl( st->L_frame, 1 ); i++ ) { -#ifdef FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING st->hFdCngDec->hFdCngCom->olapBufferSynth[i] = mult_r( st->hFdCngDec->hFdCngCom->olapBufferSynth[i], 26214 /* Q14*/ ); /* (Q15 - olapBufferSynth_exp) + 1 */ move16(); -#else - st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i] = Mult_32_16( L_shl( st->hFdCngDec->hFdCngCom->olapBufferSynth_fx[i], 1 ), (Word16) 26214 /* 1.6f in Q14 */ ); - move32(); -#endif } -#ifdef FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING st->hFdCngDec->hFdCngCom->olapBufferSynth_exp = add( st->hFdCngDec->hFdCngCom->olapBufferSynth_exp, 1 ); -#endif } } } diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 22abfd683..9e22ad6af 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -315,12 +315,10 @@ ivas_error evs_dec_fx( /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ -#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) && defined( FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING ) +#if defined( FIX_BASOP_REMOVE_SYNTH2_FX ) IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1 ) ) != IVAS_ERR_OK ) -#elif defined( FIX_BASOP_REMOVE_SYNTH2_FX ) || defined( FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING ) - IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16 ) ) != IVAS_ERR_OK ) #else - IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16, &tmp16 ) ) != IVAS_ERR_OK ) + IF( ( error = core_switching_pre_dec_fx( st_fx, output_frame, -1, 1, EVS_MONO, EVS_MONO, -1, &tmp16 ) ) != IVAS_ERR_OK ) #endif { return error; diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 164bbc3f1..e558413a2 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -438,7 +438,6 @@ ivas_error ivas_core_dec_fx( /*---------------------------------------------------------------------* * Preprocessing (preparing) for ACELP/HQ core switching *---------------------------------------------------------------------*/ -#ifdef FIX_BASOP_2262_OLAP_BUFFER_SYNTH_SWITCHING #ifdef FIX_BASOP_REMOVE_SYNTH2_FX IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn ) ), IVAS_ERR_OK ) ) #else @@ -447,25 +446,6 @@ ivas_error ivas_core_dec_fx( move16(); IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) -#endif -#else -#ifdef FIX_BASOP_REMOVE_SYNTH2_FX - Word16 Q_olapBufferSynth; - - Q_olapBufferSynth = Q15; /*Initializing with max values to avoid warnings*/ - move16(); - - IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth ) ), IVAS_ERR_OK ) ) -#else - Word16 Q_olapBufferSynth, Q_olapBufferSynth2; - - Q_olapBufferSynth = Q15; /*Initializing with max values to avoid warnings*/ - Q_olapBufferSynth2 = Q15; /*Initializing with max values to avoid warnings*/ - move16(); - move16(); - - IF( NE_32( ( error = core_switching_pre_dec_fx( st, output_frame, sts[0]->last_core_brate, nchan_out, last_element_mode, last_element_brate, st->Q_syn, &Q_olapBufferSynth, &Q_olapBufferSynth2 ) ), IVAS_ERR_OK ) ) -#endif #endif { return error; -- GitLab From a628d9be6a588dd359f294d33b7d486d79c60445 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 20:07:11 +0100 Subject: [PATCH 10/11] [cleanup] accept FIX_2440_AGC_PRESCALING --- lib_com/options.h | 1 - lib_dec/ivas_dec_fx.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 2e2667cda..b63ee327f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -102,7 +102,6 @@ /* any switch which is non-be wrt. TS 26.251 V3.0 */ #define FIX_2448_RENDERER_MSAN_ERROR /* FhG: basop issue 2448: fix MSAN error with MSA rendering */ -#define FIX_2440_AGC_PRESCALING /* FhG: basop issue 2440: Fix loop bounds when scaling p_output_fx before ivas_spar_dec_agc_pca_fx() */ #define FIX_2471_REMOVE_POSSIBLE_OVRF /* VA: basop issue 2471: correcting undesired overflow */ #define FIX_2465_Q_BWE_EXC /* VA: basop issue 2465: fix calculation of Q_bwe_exc in SWB TBE encoder */ #define FIX_2436_CLDFBANAHANDLE_ADRESS /* FhG: cldfb handle pointer were handed over in faulty manner*/ diff --git a/lib_dec/ivas_dec_fx.c b/lib_dec/ivas_dec_fx.c index 525caf8e2..19cedd9ef 100644 --- a/lib_dec/ivas_dec_fx.c +++ b/lib_dec/ivas_dec_fx.c @@ -629,13 +629,9 @@ ivas_error ivas_dec_fx( ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->sba_dirac_stereo_flag == 0 ) { Word16 size = add( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, sba_ch_idx ); -#ifdef FIX_2440_AGC_PRESCALING // For nchan_transport = 3, the fourth input audio channel in ivas_spar_dec_agc_pca_fx() is also used, // so one additional channel must be aligned to Q14. if ( EQ_16( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, 3 ) ) -#else - if ( EQ_16( size, 3 ) ) -#endif { size = add( size, 1 ); } -- GitLab From f4a350fea31f0546675abf3d21da8fce7418d063 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Fri, 13 Mar 2026 20:09:21 +0100 Subject: [PATCH 11/11] formatting --- lib_com/fine_gain_bits_fx.c | 20 ++++++------ lib_com/hq_tools_fx.c | 2 +- lib_com/low_rate_band_att_fx.c | 24 +++++++------- lib_com/prot_fx.h | 60 +++++++++++++++++----------------- lib_com/rom_com.h | 14 ++++---- lib_com/swb_bwe_com_fx.c | 2 +- lib_com/swb_tbe_com_fx.c | 18 +++++----- lib_dec/pvq_core_dec_fx.c | 1 - lib_enc/peak_vq_enc_fx.c | 22 ++++++------- lib_enc/prot_fx_enc.h | 28 ++++++++-------- lib_enc/swb_bwe_enc_fx.c | 2 +- lib_enc/swb_tbe_enc_fx.c | 2 +- 12 files changed, 97 insertions(+), 98 deletions(-) diff --git a/lib_com/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index 1d4ad2a7d..d211a8a67 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -17,10 +17,10 @@ static void subband_gain_bits_fx( const Word16 element_mode, /* i : element mode */ - const Word16 *Rk, /* i : bit allocation per band Q3 */ - const Word16 N, /* i : number of bands */ - Word16 *bits, /* o : gain bits per band */ - const Word16 *sfmsize /* i : Size of bands */ + const Word16 *Rk, /* i : bit allocation per band Q3 */ + const Word16 N, /* i : number of bands */ + Word16 *bits, /* o : gain bits per band */ + const Word16 *sfmsize /* i : Size of bands */ ) { Word16 i, b, tot; @@ -73,12 +73,12 @@ static void subband_gain_bits_fx( /* o : Number of assigned gain bits */ Word16 assign_gain_bits_fx( const Word16 element_mode, /* i : element mode */ - const Word16 core, /* i : HQ core */ - const Word16 BANDS, /* i : Number of bands */ - const Word16 *band_width, /* i : Sub band bandwidth */ - Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *gain_bits_array, /* o : Assigned gain bits */ - Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ + const Word16 core, /* i : HQ core */ + const Word16 BANDS, /* i : Number of bands */ + const Word16 *band_width, /* i : Sub band bandwidth */ + Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ + Word16 *gain_bits_array, /* o : Assigned gain bits */ + Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ ) { Word16 gain_bits_tot; diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index bdd99ac97..2c2f5a6c3 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -1835,7 +1835,7 @@ Word16 calc_nor_delta_hf_fx( *--------------------------------------------------------------------------*/ void hq_bwe_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ const Word16 HQ_mode, /* i : HQ mode Q0*/ Word32 *coeff_out1, /* i/o: BWE input & temporary buffer Q12*/ const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes Q1*/ diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 9ec3ff357..aeb46f87c 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -16,19 +16,19 @@ *--------------------------------------------------------------------------*/ void fine_gain_pred_fx( - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - const Word16 *sfm_size, /* i : Sub band bandwidths */ - const Word16 *i_sort, /* i : Energy sorting indices */ - const Word16 *K, /* i : Number of pulses per band */ - const Word16 *maxpulse, /* i : Maximum pulse per band */ - const Word16 *R, /* i : Bits per sub band Q3 */ - const Word16 num_sfm, /* i : Number of sub bands */ - Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) Q0 */ - Word16 *fg_pred, /* o : Predicted fine gains Q12 */ + const Word16 *sfm_start, /* i : Sub band start indices */ + const Word16 *sfm_end, /* i : Sub band end indices */ + const Word16 *sfm_size, /* i : Sub band bandwidths */ + const Word16 *i_sort, /* i : Energy sorting indices */ + const Word16 *K, /* i : Number of pulses per band */ + const Word16 *maxpulse, /* i : Maximum pulse per band */ + const Word16 *R, /* i : Bits per sub band Q3 */ + const Word16 num_sfm, /* i : Number of sub bands */ + Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ + Word16 *y, /* i/o: Quantized vector (int) Q0 */ + Word16 *fg_pred, /* o : Predicted fine gains Q12 */ const Word16 element_mode, /* i : element mode */ - const Word16 core /* i : Core */ + const Word16 core /* i : Core */ ) { Word16 i, band; diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 828007025..a40fba659 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -373,7 +373,7 @@ void time_reduce_pre_echo_fx( Word16 Q_synth ); void hq_generic_decoding_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ const Word16 HQ_mode, /* i : HQ mode */ Word32 *coeff_out1_fx, /* i/o: BWE i & temporary buffer */ const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes */ @@ -626,7 +626,7 @@ Word16 calc_nor_delta_hf_fx( ); void hq_bwe_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ const Word16 HQ_mode, /* i : HQ mode */ Word32 *coeff_out1, /* i/o: BWE i & temporary buffer */ const Word16 *hq_generic_fenv, /* i : SWB frequency envelopes */ @@ -2591,13 +2591,13 @@ void flip_and_downmix_generic_fx( void Calc_rc0_h( const Word16 element_mode, /* i : element mode */ const Word16 enc_dec, /* i : encoder/decoder flag */ - Word16 *h, /* i : impulse response of composed filter */ - Word16 *rc0 /* o : 1st parcor */ + Word16 *h, /* i : impulse response of composed filter */ + Word16 *rc0 /* o : 1st parcor */ ); void PostShortTerm_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 enc_dec, /* i : encoder/decoder flag */ + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ Word16 *sig_in, /* i : i signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ @@ -4466,19 +4466,19 @@ void bands_and_bit_alloc_fx( ); #endif void fine_gain_pred_fx( - const Word16 *sfm_start, /* i : Sub band start indices */ - const Word16 *sfm_end, /* i : Sub band end indices */ - const Word16 *sfm_size, /* i : Sub band bandwidths */ - const Word16 *i_sort, /* i : Energy sorting indices */ - const Word16 *K, /* i : Number of pulses per band */ - const Word16 *maxpulse, /* i : Maximum pulse per band */ - const Word16 *R, /* i : Bits per sub band Q3 */ - const Word16 num_sfm, /* i : Number of sub bands */ - Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ - Word16 *y, /* i/o: Quantized vector (int) */ - Word16 *fg_pred, /* o : Predicted fine gains Q12 */ + const Word16 *sfm_start, /* i : Sub band start indices */ + const Word16 *sfm_end, /* i : Sub band end indices */ + const Word16 *sfm_size, /* i : Sub band bandwidths */ + const Word16 *i_sort, /* i : Energy sorting indices */ + const Word16 *K, /* i : Number of pulses per band */ + const Word16 *maxpulse, /* i : Maximum pulse per band */ + const Word16 *R, /* i : Bits per sub band Q3 */ + const Word16 num_sfm, /* i : Number of sub bands */ + Word16 *xq, /* i/o: Quantized vector /quantized vector with finegain adj Q15*/ + Word16 *y, /* i/o: Quantized vector (int) */ + Word16 *fg_pred, /* o : Predicted fine gains Q12 */ const Word16 element_mode, /* i : element mode */ - const Word16 core /* i : Core */ + const Word16 core /* i : Core */ ); void fine_gain_quant_fx( @@ -4511,12 +4511,12 @@ void fine_gain_dec_fx( /* o : Number of assigned gain bits */ Word16 assign_gain_bits_fx( const Word16 element_mode, /* i : element mode */ - const Word16 core, /* i : HQ core */ - const Word16 BANDS, /* i : Number of bands */ - const Word16 *band_width, /* i : Sub band bandwidth */ - Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ - Word16 *gain_bits_array, /* o : Assigned gain bits */ - Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ + const Word16 core, /* i : HQ core */ + const Word16 BANDS, /* i : Number of bands */ + const Word16 *band_width, /* i : Sub band bandwidth */ + Word16 *Rk, /* i/o: Bit allocation/Adjusted bit alloc. Q3 */ + Word16 *gain_bits_array, /* o : Assigned gain bits */ + Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ ); void freq_dnw_scaling_fx( @@ -6847,11 +6847,11 @@ void fd_bwe_dec_init( ); void hq_core_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure fx */ - Word16 synth[], /* o : output synthesis Q_synth*/ - Word16 *Q_synth, /* o : Q value of synth */ - const Word16 output_frame, /* i : output frame length Q0*/ - const Word16 hq_core_type, /* i : HQ core type Q0*/ + Decoder_State *st_fx, /* i/o: decoder state structure fx */ + Word16 synth[], /* o : output synthesis Q_synth*/ + Word16 *Q_synth, /* o : Q value of synth */ + const Word16 output_frame, /* i : output frame length Q0*/ + const Word16 hq_core_type, /* i : HQ core type Q0*/ const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ ); @@ -9925,7 +9925,7 @@ void IGFEncConcatenateBitstream( ); void hq_generic_hf_encoding_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope */ const Word16 hq_generic_offset, /* i : frequency offset for extracting energy */ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index aeea3f8b2..2843d1d6b 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1488,15 +1488,15 @@ extern const Word16 tab_hup_l_fx[]; // Q15 extern const Word16 mfreq_loc_Q2fx[]; // Q0 extern const Word16 mfreq_loc_div_25[]; // Q0 -extern const Word16 band_len_idx[]; // Q0 -extern const Word16 band_len_ener_shift[]; // Q0 -extern const Word16 fine_gain_pred_sqrt_bw[]; // Q11 +extern const Word16 band_len_idx[]; // Q0 +extern const Word16 band_len_ener_shift[]; // Q0 +extern const Word16 fine_gain_pred_sqrt_bw[]; // Q11 extern const Word16 fine_gain_pred_sqrt_bw_ext[]; // Q11 extern const Word16 band_len_idx_ext[1 + ( MAX_SFM_LEN_FX * 5 / 4 / 8 )]; // Q11 -extern const Word16 Mean_isf_wb[]; // Q2.56 -extern const Word16 lsp_shb_prev_tbl_fx[]; // Q15 -extern const Word16 lsp_shb_prev_tbl_swb_tbe_enc_fx[]; // Q15 -extern const Word16 ivas_lsp_shb_prev_tbl_fx[]; // Q15 +extern const Word16 Mean_isf_wb[]; // Q2.56 +extern const Word16 lsp_shb_prev_tbl_fx[]; // Q15 +extern const Word16 lsp_shb_prev_tbl_swb_tbe_enc_fx[]; // Q15 +extern const Word16 ivas_lsp_shb_prev_tbl_fx[]; // Q15 extern const Word16 tab_ari_qnew[4][4]; // enhancer.c diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index b455267be..bd1c35e3e 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -2413,7 +2413,7 @@ void calc_norm_envelop_fx_32( *-------------------------------------------------------------------*/ void hq_generic_decoding_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ const Word16 HQ_mode, /* i : HQ mode : Q0 */ Word32 *coeff_out1_fx, /* i/o: BWE input & temporary buffer : Q12 */ const Word16 *hq_generic_fenv_fx, /* i : SWB frequency envelopes : Q1 */ diff --git a/lib_com/swb_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 845f5c080..01a549755 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -634,8 +634,8 @@ void flip_spectrum_fx( void Calc_rc0_h( const Word16 element_mode, /* i : element mode */ const Word16 enc_dec, /* i : encoder/decoder flag */ - Word16 *h, /* i : impulse response of composed filter */ - Word16 *rc0 /* o : 1st parcor */ + Word16 *h, /* i : impulse response of composed filter */ + Word16 *rc0 /* o : 1st parcor */ ) { Word32 L_acc; @@ -740,11 +740,11 @@ void Calc_rc0_h( static void Calc_st_filt_tbe_fx( const Word16 element_mode, /* i : element mode */ const Word16 enc_dec, /* i : encoder/decoder flag */ - Word16 *apond2, /* i : coefficients of numerator */ - Word16 *apond1, /* i : coefficients of denominator */ - Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ - Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ - Word16 *mem_zero /* i : All zero memory */ + Word16 *apond2, /* i : coefficients of numerator */ + Word16 *apond1, /* i : coefficients of denominator */ + Word16 *parcor0, /* o : 1st parcor calcul. on composed filter */ + Word16 *sig_ltp_ptr, /* i/o: i of 1/A(gamma1) : scaled by 1/g0 */ + Word16 *mem_zero /* i : All zero memory */ ) { Word32 L_g0; @@ -958,8 +958,8 @@ static void scale_st_swb( *-------------------------------------------------------------------*/ void PostShortTerm_fx( - const Word16 element_mode, /* i : element mode */ - const Word16 enc_dec, /* i : encoder/decoder flag */ + const Word16 element_mode, /* i : element mode */ + const Word16 enc_dec, /* i : encoder/decoder flag */ Word16 *sig_in, /* i : input signal (pointer to current subframe */ Word16 *lpccoeff, /* i : LPC coefficients for current subframe */ Word16 *sig_out, /* o : postfiltered output */ diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 80bc47135..a787b376d 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -297,7 +297,6 @@ Word16 pvq_core_dec_fx( } - /*-------------------------------------------------------------------* * decode_energies() * diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 8c0d7321c..ff27de8c3 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -31,17 +31,17 @@ static void quant_peaks_fx( BSTR_ENC_HANDLE hBstr, const Word32 *vect_in, Word32 Word16 peak_vq_enc_fx( const Word16 element_mode, /* i : element mode */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 *coefs, /* i : Input coefficient vector Q12 */ - Word32 *coefs_out, /* o : Quantized output vector Q12 */ - const Word32 core_brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* i : Peak index vector */ - Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word32 *coefs, /* i : Input coefficient vector Q12 */ + Word32 *coefs_out, /* o : Quantized output vector Q12 */ + const Word32 core_brate, /* i : Core bitrate */ + const Word16 num_bits, /* i : Number of bits for HVQ */ + const Word16 vq_peaks, /* i : Number of identified peaks */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *vq_peak_idx, /* i : Peak index vector */ + Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ ) { Word16 pos_bits; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index fbe9c0f01..a1dba490e 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3533,9 +3533,9 @@ Word16 Pit_exc_contribution_len_fx( Word16 pvq_core_enc_fx( const Word16 element_mode, /* i : element mode */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ - Word16 coefs_quant[], /* o : quantized coefficients */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ + Word16 coefs_quant[], /* o : quantized coefficients */ Word16 *Q_coefs, const Word16 bits_tot, /* i : total number of bits */ const Word16 nb_sfm, /* i : number of bands */ @@ -3686,17 +3686,17 @@ void diffcod_lrmdct_fx( Word16 peak_vq_enc_fx( const Word16 element_mode, /* i : element mode */ - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bwidth, /* i : audio bandwidth */ - const Word32 *coefs, /* i : Input coefficient vector Q12 */ - Word32 *coefs_out, /* o : Quantized output vector Q12 */ - const Word32 brate, /* i : Core bitrate */ - const Word16 num_bits, /* i : Number of bits for HVQ */ - const Word16 vq_peaks, /* i : Number of identified peaks */ - const Word16 *ynrm, /* i : Envelope coefficients */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *vq_peak_idx, /* i : Peak index vector */ - Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bwidth, /* i : audio bandwidth */ + const Word32 *coefs, /* i : Input coefficient vector Q12 */ + Word32 *coefs_out, /* o : Quantized output vector Q12 */ + const Word32 brate, /* i : Core bitrate */ + const Word16 num_bits, /* i : Number of bits for HVQ */ + const Word16 vq_peaks, /* i : Number of identified peaks */ + const Word16 *ynrm, /* i : Envelope coefficients */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *vq_peak_idx, /* i : Peak index vector */ + Word32 *nf_gains /* i : Estimated noise floor gains Q12 */ ); void wb_vad_init_fx( diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 12037d2a0..3c099f6aa 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -3066,7 +3066,7 @@ void fd_bwe_enc_init_fx( *-------------------------------------------------------------------*/ void hq_generic_hf_encoding_fx( - const Word16 element_mode, /* i : element mode */ + const Word16 element_mode, /* i : element mode */ const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope : Q1 */ const Word16 hq_generic_offset, /* i : frequency offset for extracting energy : Q0 */ diff --git a/lib_enc/swb_tbe_enc_fx.c b/lib_enc/swb_tbe_enc_fx.c index 0408ba504..6cb93e941 100644 --- a/lib_enc/swb_tbe_enc_fx.c +++ b/lib_enc/swb_tbe_enc_fx.c @@ -2391,7 +2391,7 @@ void swb_tbe_enc_fx( L_tmp1 = Mult_32_16( L_shl_sat( 1, sub( 31, exp ) ), tmp ); /* Q31-exp */ tmp = sub( 32767 /*1.0f Q15*/, tmp ); Lscale = L_add( Mult_32_16( Lscale, tmp ), L_tmp1 ); - L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ + L_tmp = Mult_32_16( Lscale, shaped_shb_excitation_fx[i] ); /* Q_bwe_exc + (31-exp) - 15 */ shaped_shb_excitation_fx[i] = round_fx_sat( L_shl_sat( L_tmp, exp ) ); /* Q_bwe_exc */ move16(); } -- GitLab