From 76c4eb6abbe0d9ea72fc10d5609746a60b47d506 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Feb 2026 19:03:55 +0100 Subject: [PATCH 01/31] HARM_HQ_CORE --- lib_com/fine_gain_bits_fx.c | 4 +- lib_com/hq_conf_fx.c | 3 +- lib_com/ivas_prot_fx.h | 9 +- lib_com/options.h | 1 + lib_com/prot_fx.h | 5 +- lib_dec/FEC_HQ_phase_ecu_fx.c | 514 +++++++++++++++++++++++-------- lib_dec/hq_core_dec_fx.c | 16 + lib_dec/hq_hr_dec_fx.c | 17 + lib_dec/ivas_stereo_dft_plc_fx.c | 1 + lib_dec/pvq_core_dec_fx.c | 4 + lib_enc/gs_enc_fx.c | 9 + lib_enc/hq_classifier_enc_fx.c | 68 +++- lib_enc/hq_hr_enc_fx.c | 30 +- lib_enc/hvq_enc_fx.c | 63 ++-- lib_enc/prot_fx_enc.h | 17 +- lib_enc/pvq_core_enc_fx.c | 45 ++- 16 files changed, 625 insertions(+), 181 deletions(-) diff --git a/lib_com/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index b6846372c..172e51833 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -14,6 +14,7 @@ * * HQ core encoder *--------------------------------------------------------------------------*/ + static void subband_gain_bits_fx( const Word16 *Rk, /* i : bit allocation per band Q3 */ const Word16 N, /* i : number of bands */ @@ -101,7 +102,7 @@ Word16 assign_gain_bits_fx( /* o : Number of assigned 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 */ @@ -183,3 +184,4 @@ Word16 ivas_assign_gain_bits_fx( /* o : Number of ass return gain_bits_tot; } +#endif diff --git a/lib_com/hq_conf_fx.c b/lib_com/hq_conf_fx.c index b114745b5..9450e6314 100644 --- a/lib_com/hq_conf_fx.c +++ b/lib_com/hq_conf_fx.c @@ -15,7 +15,7 @@ * * 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 */ @@ -539,6 +539,7 @@ void hq_configure_evs_fx( return; } +#endif void hq_configure_fx( const Word16 length, /* i : Frame length Q0 */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index ff41c4ae0..d5c4c8bc3 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1611,6 +1611,7 @@ void ivas_hq_hr_dec_fx( const Word16 core_switching_flag /* i : Core switching flag */ ); +#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 */ @@ -1625,7 +1626,7 @@ void ivas_hq_configure_fx( Word16 *sfm_start, /* o : Subband start coefficients Q0 */ Word16 *sfm_end /* o : Subband end coefficients Q0 */ ); - +#endif void ivas_hq_bit_allocation_fx( const Word32 core_brate, /* i : Core bit-rate Q0 */ const Word16 length, /* i : Frame length Q0 */ @@ -1642,6 +1643,7 @@ void ivas_hq_bit_allocation_fx( const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_GEN Q0 */ ); +#ifndef HARM_HQ_CORE /* o : Number of assigned gain bits */ Word16 ivas_assign_gain_bits_fx( const Word16 core, /* i : HQ core */ @@ -1651,7 +1653,7 @@ Word16 ivas_assign_gain_bits_fx( Word16 *gain_bits_array, /* o : Assigned gain bits */ Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ ); - +#endif void ivas_fine_gain_pred_fx( const Word16 *sfm_start, /* i : Sub band start indices */ const Word16 *sfm_end, /* i : Sub band end indices */ @@ -1683,6 +1685,7 @@ 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 */ @@ -1705,7 +1708,7 @@ void ivas_hq_ecu_fx( const Word16 output_frame, /* i : frame length */ Decoder_State *st_fx /* i/o: decoder state structure */ ); - +#endif 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 */ diff --git a/lib_com/options.h b/lib_com/options.h index 439a9e508..40276a07b 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -96,6 +96,7 @@ #define HARM_2336_DOTP /* VA: basop 2336; Harmonisation of some dot_product function + some BE optimisation */ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ +#define HARM_HQ_CORE /* harmonize HQ core functions */ /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index a4a32366e..890561117 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1383,7 +1383,6 @@ Word16 rescale_mem( Word16 i_subfr /* i : subframe number */ ); -// hq_conf.c void hq_configure_fx( const Word16 length, /* i : Frame length Q0 */ const Word16 hqswb_clas, /* i : HQ SWB class Q0 */ @@ -1399,6 +1398,7 @@ 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 */ @@ -1413,8 +1413,7 @@ void hq_configure_evs_fx( Word16 *sfm_start, /* o : Subband start coefficients Q0 */ Word16 *sfm_end /* o : Subband end coefficients Q0 */ ); - -// hp50.c +#endif void hp20( Word16 signal[], /* i/o: signal to filter any */ const Word16 stride, /* i : stride to be applied accessing signal */ diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 497e76ec8..48b95ff92 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -58,24 +58,37 @@ #define FEC_HQ_WIN_A0 FEC_HQ_HAMM_A0 #define FEC_HQ_WIN_A1 FEC_HQ_HAMM_A1 -static Word16 sqrt2ndOrder( const Word16 ); +/*---------------------------------------------------------------------* + * Local functions declarations + *---------------------------------------------------------------------*/ + +static Word16 sqrt2ndOrder( const Word16 ); static void windowing( const Word16 *, Word16 *, const Word16 *, const Word16, const Word16 ); 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 * ); +#ifndef HARM_HQ_CORE static void peakfinder_fx( const Word16 *, const Word16, Word16 *, Word16 *, const Word16 ); +#endif static Word16 imax_fx( const Word16 *, const Word16 ); +#ifndef 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 ); 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 ); + /*------------------------------------------------------------------* * rand_phase() * * randomized phase in form of sin and cos components *------------------------------------------------------------------*/ -static Word16 rand_phase_fx( const Word16 seed, Word16 *sin_F /*Q15*/, Word16 *cos_F /*Q15*/ ) + +static Word16 rand_phase_fx( + const Word16 seed, + Word16 *sin_F /*Q15*/, + Word16 *cos_F /*Q15*/ ) { const Word16 *sincos = sincos_t_ext_fx + 128; // Q15 Word16 seed2 = own_random2_fx( seed ); @@ -175,11 +188,13 @@ static Word16 ivas_imax2_jacobsen_mag_fx( return posi; } + /*----------------------------------------------------------------------------- * fft_spec2_fx() * * Square magnitude of fft spectrum *----------------------------------------------------------------------------*/ + static void fft_spec2_fx( const Word16 x[], /* i : Input vector: complex spectrum Q0*/ Word32 xMagSq[], /* o : Magnitude square spectrum Q0*/ @@ -213,14 +228,17 @@ static void fft_spec2_fx( /* The magnitude square at N/2 */ *pMagSq = L_mult0( *pRe, *pRe ); move32(); + return; } + /*----------------------------------------------------------------------------- * trans_ana_fx() * * Transient analysis *----------------------------------------------------------------------------*/ + static void trans_ana_fx( const Word16 *xfp, /* i : Input signal Q0 */ Word16 *mag_chg, /* o : Magnitude modification Q15 */ @@ -230,7 +248,7 @@ static void trans_ana_fx( const Word16 time_offs, /* i : Time offset (integral multiple of output_frame) */ const Word16 est_mus_content, /* i : 0.0=speech_like ... 1.0=Music (==st->env_stab ) */ const Word16 last_fec, /* i : signal that previous frame was concealed with fec_alg */ - const Word16 element_mode, /* i : element_mode req to handle EVS_MONO specific BE path */ + const Word16 element_mode, /* i : element_mode req to handle EVS_MONO specific BE path */ Word16 *alpha, /* o : Magnitude modification factors for fade to average */ Word16 *beta, /* o : Magnitude modification factors for fade to average */ Word16 *beta_mute, /* o : Factor for long-term mute Q15 */ @@ -605,18 +623,24 @@ static void trans_ana_fx( return; } + /*----------------------------------------------------------------------------- * peakfinder_fx() * * Peak-picking algorithm *----------------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE +static void peakfinder_fx( +#else static void ivas_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 */ - const Word16 endpoints /* i : Flag to include endpoints in peak search */ +#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 */ + Word16 *cInd, /* o : number of identified peaks Q0 */ + const Word16 sel, /* i : The amount above surrounding data for a peak to be identified */ + const Word16 endpoints /* i : Flag to include endpoints in peak search */ ) { const Word16 *pX0; @@ -898,8 +922,11 @@ static void ivas_peakfinder_fx( move16(); } } + + 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 */ @@ -1161,15 +1188,18 @@ static void peakfinder_fx( } } } +#endif /*----------------------------------------------------------------------------- * imax_fx() * * Get interpolated maximum position *-----------------------------------------------------------------------------*/ -static Word16 imax_fx( /* o: The location, relative to the middle of the 3 given data point, of the maximum. (Q15) */ - 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 */ + +/* 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; @@ -1258,16 +1288,22 @@ static Word16 imax_fx( /* o: The location, relative to the } } } + return posi; /* Q15. The position either left or right relative to the index of the middle of the 3 given data points. */ } + /*----------------------------------------------------------------------------- * spec_ana_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 */ @@ -1276,8 +1312,8 @@ static void ivas_spec_ana_fx( 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 */ - const Word16 element_mode, /* i : IVAS element mode */ - Word16 *noise_fac, /* o : for few peaks zeroing valleys decision making Q15*/ + const Word16 element_mode, /* i : IVAS element mode */ + Word16 *noise_fac, /* o : for few peaks zeroing valleys decision making Q15 */ const Word16 pcorr ) { Word16 Lprot, LprotLog2Minus1 = 0, hamm_len2 = 0, Lprot2, Lprot2_1, m, n; @@ -1394,6 +1430,7 @@ static void ivas_spec_ana_fx( window_corr = sub( window_corr, window_corr_step ); } } + /* Spectrum */ r_fft_fx_lc( pFftTbl, Lprot, Lprot2, LprotLog2Minus1, xfp, xfp, 1 ); } @@ -1456,8 +1493,12 @@ static void ivas_spec_ana_fx( { sel = mult_r( sub( Xmax, Xmin ), CMPLMNT_ST_PFIND_SENS_FX ); } - ivas_peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel, TRUE ); +#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 */ ) @@ -1468,7 +1509,6 @@ static void ivas_spec_ana_fx( IF( element_mode == EVS_MONO ) { - /* Refine peaks */ pPlocsi = plocsi; pPlocs = plocs; @@ -1638,8 +1678,11 @@ 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 */ @@ -1783,11 +1826,14 @@ static void spec_ana_fx( { sel = mult_r( sub( Xmax, Xmin ), CMPLMNT_PFIND_SENS_FX ); } - peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel ); +#ifdef HARM_HQ_CORE + peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel, TRUE ); +#else + peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel ); +#endif { - /* Refine peaks */ pPlocsi = plocsi; pPlocs = plocs; @@ -1833,6 +1879,7 @@ static void spec_ana_fx( } } } +#endif /*-------------------------------------------------------------------* * subst_spec_fx() @@ -1840,7 +1887,11 @@ static void spec_ana_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 */ @@ -1855,9 +1906,9 @@ static void ivas_subst_spec_fx( 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 */ + 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; @@ -1920,18 +1971,41 @@ static void ivas_subst_spec_fx( // 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 ); move16(); - tmp = sub( tmp, ph_ecu_lookahead ); - tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) ); - tmp = sub( tmp, shr( output_frame, 1 ) ); - tmp1 = L_mac0( L_mult0( tmp, Lprot_inv ), time_offs, Lprot_inv ); /* Q22 */ - - pPlocsi = plocsi; - pCorrPhase = corr_phase; - FOR( m = 0; m < *num_plocs; m++ ) +#ifdef HARM_HQ_CORE + IF( element_mode == EVS_MONO ) { - acc = L_shl( Mpy_32_32( *pPlocsi++, tmp1 ), 9 ); /* 16+22+9-31 = 16*/ - *pCorrPhase++ = acc; /* in Q16. 2*PI is not included. */ - move32(); + 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; + UWord16 lsb; + 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(); + } + } + ELSE +#endif + { + tmp = sub( tmp, ph_ecu_lookahead ); + tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) ); + tmp = sub( tmp, shr( output_frame, 1 ) ); + tmp1 = L_mac0( L_mult0( tmp, Lprot_inv ), time_offs, Lprot_inv ); /* Q22 */ + + pPlocsi = plocsi; + pCorrPhase = corr_phase; + FOR( m = 0; m < *num_plocs; m++ ) + { + acc = L_shl( Mpy_32_32( *pPlocsi++, tmp1 ), 9 ); /* 16+22+9-31 = 16*/ + *pCorrPhase++ = acc; /* in Q16. 2*PI is not included. */ + move32(); + } } } one_peak_flag_mask = 32767 /* 1.0f in Q15 */; /* all ones mask -> keep */ @@ -2236,8 +2310,11 @@ static void ivas_subst_spec_fx( k = add( k, 1 ); } } + + 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 */ @@ -2598,6 +2675,7 @@ static void subst_spec_fx( } } } +#endif /*-------------------------------------------------------------------------- * rec_wtda() @@ -2605,15 +2683,19 @@ static void subst_spec_fx( * 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 */ + 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; @@ -2747,6 +2829,7 @@ static void ivas_rec_wtda_fx( return; } +#ifndef HARM_HQ_CORE static void rec_wtda_fx( Word16 *X, /* i : FFT spectrum */ Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ @@ -2817,6 +2900,7 @@ static void rec_wtda_fx( output_frame ); return; } +#endif /*-------------------------------------------------------------------------- * rec_frame_fx() @@ -2824,7 +2908,11 @@ static void rec_wtda_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 */ @@ -2869,11 +2957,16 @@ static void ivas_rec_frame_fx( } 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 return; } +#ifndef HARM_HQ_CORE static void rec_frame_fx( Word16 *X, /* i : FFT spectrum */ Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ @@ -2917,12 +3010,20 @@ static void rec_frame_fx( } Scale_sig( X, Lprot, -Q ); +#ifdef HARM_HQ_CORE + rec_wtda_fx( X, ecu_rec, output_frame, Lprot, fs, EVS_MONO, NULL, NULL ); +#else rec_wtda_fx( X, ecu_rec, output_frame, Lprot, fs ); +#endif return; } +#endif -static Word32 mult_32_32_q( const Word32 a, const Word32 b, const Word16 q ) +static Word32 mult_32_32_q( + const Word32 a, + const Word32 b, + const Word16 q ) { Word32 hi; UWord32 lo; @@ -3010,7 +3111,12 @@ 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, @@ -3030,7 +3136,6 @@ static void fec_ecu_pitch_ivas_fx( Word16 cb_end; Word16 Lmul2, Lon20mul6, Lon20mul28, Lon20mul33, Lon20mul34; - SWITCH( L ) { case L_FRAME48k: @@ -3114,15 +3219,12 @@ static void fec_ecu_pitch_ivas_fx( 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(); @@ -3176,11 +3278,8 @@ static void fec_ecu_pitch_ivas_fx( } 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; @@ -3195,13 +3294,22 @@ static void fec_ecu_pitch_ivas_fx( /*accB*/ /*accC*/ /*accA Q 6-2*tmpQLP*/ - accBisqrt = Isqrt( accB ); /* Q31 - 3 + tmpQLP */ accCisqrt = Isqrt( accC ); /* Q31 - 3 + tmpQLP*/ - - 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*/ +#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 ) ) { @@ -3222,9 +3330,11 @@ static void fec_ecu_pitch_ivas_fx( 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 */ @@ -3441,11 +3551,13 @@ static void fec_ecu_pitch_fx( Scale_sig( prevsynth_LP_fx, 320, negate( sub( tmpQLP, 3 ) ) ); return; } +#endif -static void sin_cos_est_fx( Word32 phi, Word16 *cosfreq, Word16 *sinfreq ) +static void sin_cos_est_fx( + Word32 phi, + Word16 *cosfreq, + Word16 *sinfreq ) { - - /* i phi : normalized frequency beteween 0 and Pi (nyquist) in Q30 */ /* o cosfreq & sinfreq : cos(phi) and sin (phi) in Q15 */ @@ -3483,7 +3595,11 @@ static void sin_cos_est_fx( Word32 phi, Word16 *cosfreq, Word16 *sinfreq ) return; } -static Word16 abs_iter_fx( Word16 re /*Qx*/, Word16 im /*Qx*/, Word16 N ) + +static Word16 abs_iter_fx( + Word16 re /*Qx*/, + Word16 im /*Qx*/, + Word16 N ) { Word16 A, tmp, L_tmp1, L_tmp2; Word16 i, exp; @@ -3497,7 +3613,6 @@ static Word16 abs_iter_fx( Word16 re /*Qx*/, Word16 im /*Qx*/, Word16 N ) re = shl( re, exp ); im = shl( im, exp ); - IF( im < 0 ) { im = negate( im ); @@ -3513,7 +3628,6 @@ static Word16 abs_iter_fx( Word16 re /*Qx*/, Word16 im /*Qx*/, Word16 N ) im = tmp; move16(); - FOR( i = 0; i < N; i++ ) { L_tmp1 = shr( im, i ); @@ -3533,8 +3647,11 @@ static Word16 abs_iter_fx( Word16 re /*Qx*/, Word16 im /*Qx*/, Word16 N ) tmp = abs_s( re ); /*A = round_fx(L_shr(L_mult(tmp, cor[i]), exp)); //this can be ommited, if we don't need the exact abs value */ A = shr_sat( tmp, exp ); + return A; } + + /*-------------------------------------------------------------------------- * fec_ecu_dft() * @@ -3542,7 +3659,11 @@ static Word16 abs_iter_fx( Word16 re /*Qx*/, Word16 im /*Qx*/, Word16 N ) * 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 */ @@ -3573,7 +3694,6 @@ static void ivas_fec_ecu_dft_fx( Copy( &prevsynth_LP[tmp], target, N ); /* DFT */ - L_tmp = L_deposit_l( N ); FOR( tmp = 0; L_tmp <= 16384; tmp++ ) { @@ -3595,7 +3715,6 @@ static void ivas_fec_ecu_dft_fx( } ELSE { - tmp = div_s( sub( N, 1 ), sub( *Nfft, 1 ) ); Tmp = L_deposit_l( tmp ); fac = L_add( Tmp, 0 ); @@ -3611,18 +3730,28 @@ static void ivas_fec_ecu_dft_fx( } } - /*to avoid overflow in DoRTFTn_fx() */ tmp = Exp16Array( *Nfft, Tfr16 ); *exp = add( tmp, add( 2, norm_s( *Nfft ) ) ); move16(); - Copy_Scale_sig_16_32_no_sat( Tfr16, Tfr32, *Nfft, *exp ); /*Qin+exp; */ - *exp = s_min( *exp, 15 ); +#ifdef HARM_HQ_CORE + IF( element_mode == EVS_MONO ) + { + 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 */ + } + ELSE +#endif + { + Copy_Scale_sig_16_32_no_sat( Tfr16, Tfr32, *Nfft, *exp ); /*Qin+exp; */ + *exp = s_min( *exp, 15 ); + } DoRTFTn_fx( Tfr32, Tfi32, *Nfft ); N_LP = shr( *Nfft, 1 ); - L_tmp = L_deposit_l( 0 ); pt1 = Tfr; @@ -3649,9 +3778,11 @@ static void ivas_fec_ecu_dft_fx( move32(); *exp = sub( *exp, 16 ); move16(); + return; } +#ifndef HARM_HQ_CORE static void fec_ecu_dft_fx( const Word16 *prevsynth_LP, /*Qin */ const Word16 N, @@ -3669,9 +3800,7 @@ static void fec_ecu_dft_fx( tmp = sub( 296, N ); Copy( &prevsynth_LP[tmp], target, N ); - /* DFT */ - L_tmp = L_deposit_l( N ); FOR( tmp = 0; L_tmp <= 16384; tmp++ ) { @@ -3680,7 +3809,6 @@ static void fec_ecu_dft_fx( *Nfft = shl( 1, sub( 15, tmp ) ); move16(); - set32_fx( Tfr32, 0, *Nfft ); set32_fx( Tfi32, 0, *Nfft ); Tfr16[0] = target[0]; @@ -3694,7 +3822,6 @@ static void fec_ecu_dft_fx( } ELSE { - tmp = div_s( sub( N, 1 ), sub( *Nfft, 1 ) ); Tmp = L_deposit_l( tmp ); fac = L_add( Tmp, 0 ); @@ -3725,7 +3852,6 @@ static void fec_ecu_dft_fx( DoRTFTn_fx( Tfr32, Tfi32, *Nfft ); N_LP = shr( *Nfft, 1 ); - L_tmp = L_deposit_l( 0 ); pt1 = Tfr; @@ -3752,21 +3878,19 @@ static void fec_ecu_dft_fx( 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*/ const Word16 sinfreq, /* i : sine of 1-sample dephasing at the given frequency Q15*/ - const Word16 a_re, - /* i : real part of complex spectral coefficient at the given frequency */ /*Qin */ - const Word16 a_im, - /* i : imag part of complex spectral coefficient at the given frequency */ /*Qin */ - Word32 xx[] /* o : output vector */ /*Qin+16 */ + const Word16 a_re, /* i : real part of complex spectral coefficient at the given frequency Qin */ + const Word16 a_im, /* i : imag part of complex spectral coefficient at the given frequency Qin */ + Word32 xx[] /* o : output vector Qin+16 */ ) { - Word32 *ptr, L_C0, L_S0, L_C1, L_S1; Word16 C0, S0, C1, S1; Word16 i; @@ -3849,7 +3973,6 @@ static void sinusoidal_synthesis_fx( move16(); /*flag corresponds to condition sub(N, Lon20_10)>0 || HqVoicing */ } - pt4 = pulses; nb_pulses = 0; move16(); @@ -3908,7 +4031,6 @@ static void sinusoidal_synthesis_fx( } } - nb_pulses_final = 0; move16(); @@ -3916,7 +4038,6 @@ static void sinusoidal_synthesis_fx( cumsum = L_deposit_l( 0 ); - L_tmp = Mult_32_16( sum_Tf_abs, 22938 ); // Qin pt1 = a_re; @@ -3995,15 +4116,10 @@ static void sinusoidal_synthesis_fx( move16(); } - /* sinusoidal synthesis */ - - set32_fx( synthesis_fx, 0, Len ); - exp = add( exp, sN ); - pt1 = a_re; pt2 = a_im; pt3 = freqi; @@ -4016,8 +4132,6 @@ static void sinusoidal_synthesis_fx( inv_den = i_mult2( N, decimate_factor ); /*Q0 */ /*tmp = div_s(12868,inv_den);*/ /*Q15 */ - - FOR( i = 0; i < nb_pulses_final; i++ ) { @@ -4030,13 +4144,17 @@ static void sinusoidal_synthesis_fx( pt2++; pt3++; } - Copy_Scale_sig_32_16( synthesis_fx, synthesis, Len, negate( add( exp, 16 ) ) ); /*Qin */ + Copy_Scale_sig_32_16( synthesis_fx, synthesis, Len, negate( add( exp, 16 ) ) ); /*Qin */ 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, @@ -4048,7 +4166,6 @@ static void ivas_fec_noise_filling_fx( const Word16 *old_out, const Word16 Q_old_out ) { - Word16 Rnd_N_noise; Word16 k, kk, i; Word16 N_noise; @@ -4059,9 +4176,9 @@ static void ivas_fec_noise_filling_fx( const Word16 *pt6; Word32 L_tmp; const Word16 *sinq_tab; - const Word16 *p_mdct_ola; Word16 alignment_point; + L20 = extract_h( L_mult( 1639, L ) ); /*L/20 */ IF( element_mode == EVS_MONO ) { @@ -4089,7 +4206,6 @@ static void ivas_fec_noise_filling_fx( /* Noise addition on full band */ /* residual */ - tmp_fx = s_min( N, L ); N_noise = shr( tmp_fx, 1 ); ind = sub( N, tmp_fx ); @@ -4134,7 +4250,6 @@ static void ivas_fec_noise_filling_fx( 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( L_shl( L_mult( tmp_fx, 25736 ), 2 ) ); /*Q15 */ @@ -4158,16 +4273,65 @@ 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 ); + + 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 */ + 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(); + } +#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]; @@ -4187,8 +4351,12 @@ static void ivas_fec_noise_filling_fx( 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 */ @@ -4199,7 +4367,6 @@ static void fec_noise_filling_fx( Word16 *gapsynth_fx /*Qsynth */ ) { - Word16 Rnd_N_noise; Word16 k, kk, i; Word16 N_noise; @@ -4323,9 +4490,16 @@ static void fec_noise_filling_fx( ( *pt1++ ) = round_fx( L_tmp ); /*Qsynth */ move16(); } + + 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, @@ -4348,11 +4522,19 @@ 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(); @@ -4371,13 +4553,12 @@ static void ivas_fec_alg_fx( } Q = 0; move16(); - wtda_fx( synthesis + sub( output_frame, n ), &Q, ecu_rec, - NULL, - NULL, ALDO_WINDOW, ALDO_WINDOW, output_frame ); /* return Q15 */ + wtda_fx( synthesis + sub( output_frame, n ), &Q, ecu_rec, NULL, NULL, ALDO_WINDOW, ALDO_WINDOW, output_frame ); /* return Q15 */ return; } +#ifndef HARM_HQ_CORE static void fec_alg_fx( const Word16 *prevsynth, /*Qin */ const Word16 *prevsynth_LP, /*Qin */ @@ -4399,7 +4580,11 @@ static void 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, EVS_MONO ); +#else fec_ecu_dft_fx( prevsynth_LP, N, Tfr, Tfi, &sum_Tf_abs, Tf_abs, &Nfft, &exp ); +#endif sinusoidal_synthesis_fx( Tfr, Tfi, Tf_abs, N, output_frame, decimatefactor, Nfft, sum_Tf_abs, synthesis, HqVoicing, exp ); @@ -4422,12 +4607,11 @@ static void fec_alg_fx( } Q = 0; move16(); - wtda_fx( synthesis + sub( output_frame, n ), &Q, ecu_rec, - NULL, - NULL, ALDO_WINDOW, ALDO_WINDOW, output_frame ); /* return Q15 */ + 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() @@ -4435,24 +4619,28 @@ 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( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ +#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*/ 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 */ + 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 */ + 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 */ + 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 */ const Word16 pcorr, const Word16 element_mode /* i : IVAS element mode */ @@ -4519,7 +4707,11 @@ 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 ) @@ -4548,38 +4740,51 @@ 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(); *ph_ecu_active = 1; move16(); + + return; } +#ifndef HARM_HQ_CORE static void hq_phase_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ + 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 */ + 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 */ + 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 */ + 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 */ + const Word16 output_frame /* i : frame length */ ) { Word16 lprot, offset; @@ -4625,7 +4830,11 @@ static void hq_phase_ecu_fx( 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 ); +#ifdef HARM_HQ_CORE + spec_ana_fx( prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec, EVS_MONO, &seed /*temp*/, -1 ); +#else spec_ana_fx( prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec ); +#endif test(); IF( prev_bfi != 0 && *last_fec != 0 ) @@ -4655,18 +4864,29 @@ static void hq_phase_ecu_fx( seed = add_sat( seed, 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, EVS_MONO, -1, -1 ); +#else 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 ); +#endif /* reconstructed frame in tda domain */ +#ifdef HARM_HQ_CORE + rec_frame_fx( X, ecu_rec, output_frame, *Q_spec, NULL, EVS_MONO, NULL, NULL ); +#else rec_frame_fx( X, ecu_rec, output_frame, *Q_spec ); +#endif *last_fec = 0; move16(); *ph_ecu_active = 1; move16(); -} + return; +} +#endif /*-------------------------------------------------------------------------- * hq_ecu() @@ -4674,14 +4894,18 @@ 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( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ +#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 */ 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 */ + 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 */ @@ -4691,9 +4915,9 @@ void ivas_hq_ecu_fx( 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 */ + 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 */ ) { @@ -4724,7 +4948,11 @@ 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 { @@ -4757,6 +4985,7 @@ void ivas_hq_ecu_fx( test(); ivas_mode_selection = ( LT_16( N, PH_ECU_N_LIMIT ) ) || ( LT_16( corr, PH_ECU_CORR_LIMIT_Q15 ) ); + test(); test(); test(); @@ -4764,7 +4993,11 @@ 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, &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 ); +#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; @@ -4774,9 +5007,15 @@ 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(); @@ -4786,14 +5025,15 @@ void ivas_hq_ecu_fx( return; } +#ifndef HARM_HQ_CORE void hq_ecu_fx( - const Word16 *prevsynth, /* i : buffer of previously synthesized signal Q0 */ + 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 */ + 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 */ @@ -4803,8 +5043,8 @@ void hq_ecu_fx( 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 */ + 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 */ ) @@ -4818,12 +5058,14 @@ void hq_ecu_fx( move16(); N = shr( output_frame, 2 ); - /* find pitch and R value */ - IF( !( LT_16( output_frame, L_FRAME16k ) ) ) { +#ifdef HARM_HQ_CORE + fec_ecu_pitch_fx( st_fx->element_mode, 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 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 ); +#endif } ELSE { @@ -4850,8 +5092,11 @@ void hq_ecu_fx( ( 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] ) ) ) ) { - +#ifdef HARM_HQ_CORE + 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, EVS_MONO, NULL, 0 ); +#else 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 ); +#endif *last_fec = 1; move16(); *ph_ecu_active = 0; @@ -4861,12 +5106,20 @@ void hq_ecu_fx( } ELSE { +#ifdef HARM_HQ_CORE + 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, -1, EVS_MONO ); +#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 ); +#endif } + return; } +#endif /******************************************************************************* * The square root of x which MUST be 0.5 <= x < 1, i.e., x must be normalized. @@ -4887,8 +5140,9 @@ void hq_ecu_fx( * plot(err); ******************************************************************************/ -static Word16 sqrt2ndOrder( /* o: in Q15 (2nd order least square approx.) */ - const Word16 x /* i: x must be in between 0.5 and 1.0 (Q15). */ +/* o: in Q15 (2nd order least square approx.) */ +static Word16 sqrt2ndOrder( + const Word16 x /* i: x must be in between 0.5 and 1.0 (Q15). */ ) { Word32 acc; @@ -4900,6 +5154,7 @@ static Word16 sqrt2ndOrder( /* o: in Q15 (2nd order least square acc = 682030261L; /* 0.317595089462249 in Q31 */ move32(); z = mac_r( acc, z, x ); /* in Q15 */ + return z; } @@ -4911,6 +5166,7 @@ static Word16 sqrt2ndOrder( /* o: in Q15 (2nd order least square * rectLength signifies the length of the rectangular part of the Hamming-Rectangular * window. *--------------------------------------------------------------------------- */ + static void windowing( const Word16 *x, /* i: Input signal Qx*/ Word16 *y, /* o: Windowed output Qx*/ @@ -4922,6 +5178,7 @@ static void windowing( Word16 i; Word16 *pY; const Word16 *pX, *pW; + pX = x; pW = win; pY = y; @@ -4940,6 +5197,8 @@ static void windowing( *pY++ = mult_r( *pX++, *( --pW ) ); move16(); } + + return; } /*----------------------------------------------------------------------------- @@ -4954,6 +5213,7 @@ static void windowing( * 4. 1st half of the right half of the Hamming window * 5. 2nd half of the right half of the Hamming window *----------------------------------------------------------------------------*/ + static void windowing_ROM_optimized( const Word16 *x, /* i: Input signal Qin*/ Word16 *y, /* o: Windowed output Qin*/ @@ -5019,4 +5279,6 @@ static void windowing_ROM_optimized( move16(); pSine += downSamples; /* Increment address counter */ } + + return; } diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 8a8ee0236..987b1f9d3 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1,12 +1,15 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ + #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Static table prototypes */ #include "ivas_prot_fx.h" + + /*-------------------------------------------------------------------------- * hq_core_dec() * @@ -157,9 +160,15 @@ void 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 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 } ELSE { @@ -547,6 +556,7 @@ void ivas_hq_core_dec_fx( test(); test(); hq_recovery_flag = ( EQ_16( st_fx->last_core, ACELP_CORE ) ) && st_fx->prev_bfi && ( GT_16( st_fx->element_mode, EVS_MONO ) ); /* ACELP -> HQtrans -> HQ; with HQtrans lost */ + /*-------------------------------------------------------------------------- * Find the number of bits for transform-domain coding *--------------------------------------------------------------------------*/ @@ -634,9 +644,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 } hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 30a7d4f4a..68d22349b 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -119,11 +119,14 @@ void hq_pred_hb_bws_fx( return; } + + /*--------------------------------------------------------------------------* * hq_hr_dec_fx() * * HQ High rate decoding routine *--------------------------------------------------------------------------*/ + 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 */ @@ -198,8 +201,14 @@ 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 @@ -365,6 +374,7 @@ void ivas_hq_hr_dec_fx( /*------------------------------------------------------------------* * Spectral filling *------------------------------------------------------------------*/ + 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], @@ -382,6 +392,7 @@ void ivas_hq_hr_dec_fx( /*------------------------------------------------------------------* * WB/SWB bandwidth switching *------------------------------------------------------------------*/ + ivas_hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ @@ -465,8 +476,14 @@ void 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 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 ); +#endif /*------------------------------------------------------------------* * Unpacking bitstream diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index 4ded8044f..670b19e36 100644 --- a/lib_dec/ivas_stereo_dft_plc_fx.c +++ b/lib_dec/ivas_stereo_dft_plc_fx.c @@ -598,6 +598,7 @@ void stereo_dft_res_subst_spec_fx( sel = Mpy_32_16_1( L_sub( Xmax, Xmin ), (Word16) ( 0x03D7 ) /* Q15 */ ); /* 2 * q_res - 31 */ ivas_peakfinder_fx( abs_res, L_res, plocs, num_plocs, sel, FALSE ); + /* Refine peaks */ FOR( i = 0; i < *num_plocs; i++ ) { diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 96595be9a..80a8d2f03 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -234,7 +234,11 @@ Word16 ivas_pvq_core_dec_fx( } R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 +#ifdef HARM_HQ_CORE + assign_gain_bits_fx( 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 diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 9f140f843..7b3eefc95 100644 --- a/lib_enc/gs_enc_fx.c +++ b/lib_enc/gs_enc_fx.c @@ -595,12 +595,21 @@ 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 07152c842..3a6e2f971 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -27,7 +27,7 @@ * Local functions *-----------------------------------------------------------------*/ -void hvq_classifier_fx( const Word32 *input /*Q12*/, Word16 *prev_Npeaks, Word16 *prev_peaks, Word16 *hqswb_clas, Word16 *Npeaks, Word16 *peaks, const Word32 L_core_brate, const Word16 last_core, Word32 *L_nf_gains /*Q12*/, Word16 *hvq_hangover, Word32 *L_pe_gains /*Q12*/ ); +static void hvq_classifier_fx( const Word32 *input /*Q12*/, Word16 *prev_Npeaks, Word16 *prev_peaks, Word16 *hqswb_clas, Word16 *Npeaks, Word16 *peaks, const Word32 L_core_brate, const Word16 last_core, Word32 *L_nf_gains /*Q12*/, Word16 *hvq_hangover, Word32 *L_pe_gains /*Q12*/ ); static Word16 hf_spectrum_sparseness_fx( Encoder_State *st, const Word32 *coefs_fx ); @@ -177,21 +177,25 @@ static Word16 hf_spectrum_sparseness_fx( return result; /* Q0 */ } + + /*--------------------------------------------------------------------------* * hq_classifier_enc_fx() * * HQ mode selector (decision_matrix) *--------------------------------------------------------------------------*/ -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 */ + +/* o : Consumed bits Q0 */ +Word16 hq_classifier_enc_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 */ ) { Word16 bits; @@ -215,8 +219,13 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits move16(); /* 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_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 } test(); @@ -227,9 +236,15 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits /* 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 */ +#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_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 } test(); @@ -327,11 +342,14 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bi 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 ); - test(); IF( EQ_16( *hqswb_clas, HQ_HARMONIC ) && !harmonic_decision ) { @@ -341,7 +359,11 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bi 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; @@ -372,14 +394,21 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bi return bits; /* Q0 */ } + + /*--------------------------------------------------------------------------* * peak_avrg_ratio() * * 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 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*/ @@ -480,14 +509,16 @@ Word16 peak_avrg_ratio_ivas_fx( test(); test(); test(); - IF( ( GE_16( add( k, k1 ), 5 ) && GT_16( k1, 2 ) && LT_32( total_brate, HQ_BWE_CROSSOVER_BRATE ) ) || ( ( ( 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 */ } + +#ifndef HARM_HQ_CORE /*--------------------------------------------------------------------------* * peak_avrg_ratio() * @@ -604,13 +635,19 @@ Word16 peak_avrg_ratio_fx( return hqswb_clas; /* Q0 */ } +#endif /*--------------------------------------------------------------------------* * hvq_classifier() * * 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 */ @@ -1039,7 +1076,7 @@ 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 */ @@ -1478,3 +1515,4 @@ void hvq_classifier_fx( return; } +#endif diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index 7c5a7884c..a5f3c7314 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -101,8 +101,13 @@ void hq_hr_enc_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 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 ); +#endif /*------------------------------------------------------------------* * Transient frame handling @@ -120,6 +125,7 @@ void hq_hr_enc_fx( 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 @@ -181,16 +187,25 @@ void hq_hr_enc_fx( /*------------------------------------------------------------------* * Quantize/code spectral fine structure using PVQ or HVQ *------------------------------------------------------------------*/ + IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { +#ifdef HARM_HQ_CORE + 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 ); +#else 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 ); +#endif *num_bits = sub( *num_bits, sum ); /* Q0 */ move16(); } ELSE { +#ifdef HARM_HQ_CORE + shape_bits = pvq_core_enc_fx( st_fx->element_mode, 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 ); +#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 ); +#endif *num_bits = add( *num_bits, sub( sum, shape_bits ) ); /* Q0 */ move16(); } @@ -301,6 +316,7 @@ void hq_hr_enc_ivas_fx( Word16 t_audio_q_norm[L_FRAME48k_EXT]; Word32 nf_gains_fx[HVQ_NF_GROUPS], pe_gains_fx[HVQ_NF_GROUPS]; Word16 hq_generic_fenv_fx[HQ_FB_FENV]; + /*------------------------------------------------------------------* * Initializations *------------------------------------------------------------------*/ @@ -313,9 +329,11 @@ void hq_hr_enc_ivas_fx( set32_fx( t_audio_q_fx, 0, L_FRAME48k ); set32_fx( nf_gains_fx, 0, HVQ_NF_GROUPS ); set32_fx( pe_gains_fx, 0, HVQ_NF_GROUPS ); + /*------------------------------------------------------------------* * Classification *------------------------------------------------------------------*/ + bits = hq_classifier_enc_ivas_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ *num_bits = sub( *num_bits, bits ); move16(); @@ -385,6 +403,7 @@ void hq_hr_enc_ivas_fx( /*------------------------------------------------------------------* * Normalize coefficients with quantized norms *------------------------------------------------------------------*/ + IF( NE_16( hqswb_clas, HQ_HVQ ) ) { test(); @@ -397,18 +416,28 @@ void hq_hr_enc_ivas_fx( } Word16 Q_audio = 12, Q_shift; move16(); + /*------------------------------------------------------------------* * Quantize/code spectral fine structure using PVQ or HVQ *------------------------------------------------------------------*/ + 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 ); move16(); } 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 ) ); move16(); } @@ -461,7 +490,6 @@ void hq_hr_enc_ivas_fx( } } - /* updates */ hHQ_core->prev_hqswb_clas = hqswb_clas; /* Q0 */ move16(); diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index 57692bbef..e362dd60d 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -5,11 +5,11 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" -//#include "prot_fx.h" #include "rom_com.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ + #define HVQ_ENC_NOISE_DELTA ( (Word16) 3277 ) /* 0.1 in Q15 */ static Word16 quant_lc_fx( const Word16, Word16 * ); @@ -20,19 +20,25 @@ static Word16 quant_lc_fx( const Word16, Word16 * ); * * Harmonic VQ encoder *--------------------------------------------------------------------------*/ -Word16 hvq_enc_ivas_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 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 */ + +#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 */ + 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 */ ) { const Word32 *pCoefs; @@ -188,17 +194,31 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits move16(); } } - 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] ); + +#ifdef HARM_HQ_CORE + IF( st_fx->element_mode == EVS_MONO ) + { + 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] ); + } + ELSE +#endif + { + 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] ); + } + bits_used = add( bits_used, nBits ); + return bits_used; } -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 */ +#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. */ @@ -368,6 +388,7 @@ Word16 hvq_enc_fx( /*o : Consumed bits bits_used = add( bits_used, nBits ); return bits_used; } +#endif /*----------------------------------------------------------------------------- * quant() diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 619068099..9bff7a0e4 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -850,6 +850,7 @@ 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*/ @@ -857,7 +858,8 @@ Word16 peak_avrg_ratio_ivas_fx( Word16 *mode_count, /* i/o: HQ_HARMONIC mode count Q0*/ Word16 *mode_count1, /* i/o: HQ_NORMAL mode count Q0*/ Word16 Q_coeff ); - +#endif +#ifndef HARM_HQ_CORE void hvq_classifier_ivas_fx( const Word32 *input, /* i : input signal Q12 */ Word16 *prev_Npeaks, /* i/o: Peak number memory Q0 */ @@ -871,7 +873,7 @@ void hvq_classifier_ivas_fx( 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 */ @@ -3583,6 +3585,9 @@ Word16 Pit_exc_contribution_len_fx( Word16 Qnew ); Word16 pvq_core_enc_fx( +#ifdef HARM_HQ_CORE + const Word16 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 */ @@ -3599,6 +3604,7 @@ 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 */ @@ -3615,6 +3621,7 @@ Word16 pvq_core_enc_ivas_fx( 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*/ @@ -3742,6 +3749,7 @@ 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 */ @@ -3757,7 +3765,8 @@ Word16 hvq_enc_ivas_fx( const Word32 *coefs, /* i : spectrum coefficients in Q12 */ Word32 *coefs_out /* o : encoded spectrum coefficients in Q12 */ ); - +#endif +#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 */ @@ -3774,7 +3783,7 @@ Word16 pvq_core_enc_fx( 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 */ diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 5ce698f46..4ee0f7429 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -475,12 +475,19 @@ void pvq_encode_frame_fx( return; } + /*---------------------------------------------------------------------* * pvq_core_enc() * * 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 */ @@ -508,13 +515,24 @@ Word16 pvq_core_enc_ivas_fx( 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( 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 ); - 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 ); - +#ifdef HARM_HQ_CORE + IF( element_mode == EVS_MONO ) + { + 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 +#endif + { + 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 ); + } IF( Rs != NULL ) { @@ -542,16 +560,30 @@ Word16 pvq_core_enc_ivas_fx( get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); /* Fine gain prediction */ - ivas_fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, - coefs_quant, pulse_vector, fg_pred, core ); +#ifdef HARM_HQ_CORE + IF( element_mode == EVS_MONO ) + { + fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, + coefs_quant, pulse_vector, fg_pred, core ); + } + ELSE +#endif + { + ivas_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; + + *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 */ @@ -625,6 +657,7 @@ Word16 pvq_core_enc_fx( return add( pvq_bits, gain_bits_tot ); ; } +#endif static void encode_energies_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ -- GitLab From 558ffd6700492e1aace98b27480a4b562bf18e3e Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Feb 2026 19:24:30 +0100 Subject: [PATCH 02/31] fix --- lib_dec/hq_hr_dec_fx.c | 10 ++++++++-- lib_enc/hq_hr_enc_fx.c | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 68d22349b..0205594dd 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -136,7 +136,7 @@ void ivas_hq_hr_dec_fx( 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 */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -478,7 +478,13 @@ void hq_hr_dec_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE - hq_configure_fx( length, *hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, + Word16 tmp_length = length; + if( length == 960 ) + { + tmp_length = L_SPEC48k; + } + + hq_configure_fx( tmp_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 hq_configure_evs_fx( length, *hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index a5f3c7314..7690f3316 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -347,6 +347,7 @@ void hq_hr_enc_ivas_fx( /*------------------------------------------------------------------* * Transient frame handling *------------------------------------------------------------------*/ + /* Interleave MLT coefficients of 4 sub-vectors in case of transient frame */ IF( is_transient ) { @@ -366,6 +367,7 @@ void hq_hr_enc_ivas_fx( /* calculate and quantize norms */ calc_norm_ivas_fx( t_audio_fx, 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 ); @@ -374,6 +376,7 @@ void hq_hr_enc_ivas_fx( *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); move16(); + /* Encode norm indices */ encode_envelope_indices_ivas_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); @@ -493,6 +496,7 @@ void hq_hr_enc_ivas_fx( /* updates */ hHQ_core->prev_hqswb_clas = hqswb_clas; /* Q0 */ move16(); + /* Prepare synthesis for LB generation in case of switch to ACELP */ IF( NE_16( hqswb_clas, HQ_HVQ ) ) { -- GitLab From 0b782e03265787bd0d68d9b8a602e1106a03853a Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Feb 2026 20:45:28 +0100 Subject: [PATCH 03/31] more HARM_HQ_CORE --- lib_com/fill_spectrum_fx.c | 26 +++++++++++++-- lib_com/hq_tools_fx.c | 34 +++++++++++++++++++- lib_com/ivas_prot_fx.h | 10 +++--- lib_com/prot_fx.h | 17 ++++++++-- lib_com/swb_bwe_com_fx.c | 32 ++++++++++++++++--- lib_dec/FEC_HQ_phase_ecu_fx.c | 59 +++++++++++++++++++++++++++++++++-- lib_dec/hq_hr_dec_fx.c | 31 +++++++++++++++--- 7 files changed, 186 insertions(+), 23 deletions(-) diff --git a/lib_com/fill_spectrum_fx.c b/lib_com/fill_spectrum_fx.c index e41eca0af..7353485a6 100644 --- a/lib_com/fill_spectrum_fx.c +++ b/lib_com/fill_spectrum_fx.c @@ -43,7 +43,19 @@ #include "ivas_prot_fx.h" +#ifdef HARM_HQ_CORE +/*--------------------------------------------------------------------------* + * fill_spectrum() + * + * Apply spectral filling by + * - filling zero-bit bands below BWE region + * - applying BWE above transition frequency + *--------------------------------------------------------------------------*/ + +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 */ @@ -173,7 +185,6 @@ void ivas_fill_spectrum_fx( move16(); } - /*----------------------------------------------------------------* * Build noise-fill codebook *----------------------------------------------------------------*/ @@ -250,10 +261,15 @@ void ivas_fill_spectrum_fx( /*----------------------------------------------------------------* * Harmonic BWE, HVQ BWE and HQ SWB BWE *----------------------------------------------------------------*/ + 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 ) ) { @@ -262,12 +278,17 @@ 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 } /*----------------------------------------------------------------* * HQ WB BWE refinements *----------------------------------------------------------------*/ + test(); IF( EQ_16( length, L_FRAME16k ) && LE_32( L_core_brate, HQ_32k ) ) { @@ -304,7 +325,7 @@ 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 */ @@ -564,3 +585,4 @@ void fill_spectrum_fx( return; } +#endif diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index cc5f483ea..65e4e5cf4 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -808,7 +808,11 @@ 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*/ @@ -968,9 +972,11 @@ void ivas_harm_bwe_fx( { set32_fx( &coeff_out[800], 0, 160 ); } + 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*/ @@ -1133,6 +1139,7 @@ void harm_bwe_fx( } return; } +#endif /*--------------------------------------------------------------------------* * HVQ_bwe_fx() @@ -1486,11 +1493,13 @@ void hvq_bwe_fx( return; } + /*-------------------------------------------------------------------* * hvq_concat_bands_fx() * * Compute the band limits for concatenated bands for PVQ target signal in HVQ *--------------------------------------------------------------------------*/ + void hvq_concat_bands_fx( const Word16 pvq_bands, /* i : Number of bands in concatenated PVQ target Q0*/ const Word16 *sel_bnds, /* i : Array of selected high bands Q0*/ @@ -1582,6 +1591,8 @@ void noise_mix_fx( move32(); } } + + return; } @@ -1590,6 +1601,7 @@ void noise_mix_fx( * * Prepare HQ GENERIC HF fine structure *--------------------------------------------------------------------------*/ + void hq_generic_fine_fx( Word16 *coeff, /* i : coded/noisefilled normalized spectrum Q12*/ const Word16 last_sfm, /* i : Last coded band Q0*/ @@ -1627,11 +1639,13 @@ void hq_generic_fine_fx( return; } + /*--------------------------------------------------------------------------* * overlap_hq_bwe_fx() * * Overlapping at the boundary between HQ core and BWE *--------------------------------------------------------------------------*/ + static void overlap_hq_bwe_fx( const Word32 *hq_swb_overlap_buf, /* i : spectrum from HQ core Q12*/ Word32 *coeff_out, /* i/o: spectrum from BWE, overlapped output Q12*/ @@ -1679,14 +1693,17 @@ static void overlap_hq_bwe_fx( } } } + return; } + /*--------------------------------------------------------------------------* * map_hq_generic_fenv_norm() * * mapping high frequency envelope to high band norm *--------------------------------------------------------------------------*/ + void map_hq_generic_fenv_norm_fx( const Word16 hqswb_clas, /*Q0*/ const Word16 *hq_generic_fenv, /* Q1, frequency-domain BWE envelope */ @@ -2050,6 +2067,7 @@ Word16 calc_nor_delta_hf_fx( /* updating bit allocation */ update_rsubband_fx( nb_sfm, Rsubband, add_bits_denv ); } + return add_bits_denv; } @@ -2059,6 +2077,7 @@ 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*/ @@ -2082,14 +2101,24 @@ void hq_bwe_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( EVS_MONO, 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_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 ); 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*/ @@ -2109,10 +2138,13 @@ void hq_bwe_ivas_fx( 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*/ +#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/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index d5c4c8bc3..f01a74df4 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1708,7 +1708,7 @@ void ivas_hq_ecu_fx( const Word16 output_frame, /* i : frame length */ Decoder_State *st_fx /* i/o: decoder state structure */ ); -#endif + 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 */ @@ -1748,12 +1748,13 @@ void ivas_fill_spectrum_fx( const Word16 num_env_bands, const Word16 element_mode ); - +#endif void ivas_de_interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ ); +#ifndef HARM_HQ_CORE void ivas_harm_bwe_fx( const Word16 *coeff_fine, /* i : fine structure for BWE */ const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ @@ -1770,7 +1771,8 @@ void ivas_harm_bwe_fx( Word32 *coeff_out, /* o : coded/noisefilled spectrum */ const Word16 element_mode /* i : IVAS element mode */ ); - +#endif +#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 */ @@ -1778,7 +1780,7 @@ void ivas_hq_pred_hb_bws_fx( 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/prot_fx.h b/lib_com/prot_fx.h index 890561117..19a99bbcf 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -286,6 +286,7 @@ 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 */ @@ -295,7 +296,7 @@ void hq_generic_decoding_fx( 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 */ @@ -397,6 +398,9 @@ 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 */ @@ -406,6 +410,7 @@ 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 */ @@ -415,7 +420,7 @@ void hq_generic_decoding_ivas_fx( 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 */ @@ -682,6 +687,7 @@ Word16 calc_nor_delta_hf_ivas_fx( const Word16 core_sfm /* i : index of the end band for core */ ); +#ifndef HARM_HQ_CORE void hq_bwe_fx( const Word16 HQ_mode, /* i : HQ mode */ Word32 *coeff_out1, /* i/o: BWE i & temporary buffer */ @@ -694,8 +700,13 @@ void hq_bwe_fx( 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 */ diff --git a/lib_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index 525a1db85..2e25c9afc 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -2146,6 +2146,7 @@ void time_envelop_shaping_ivas_fx( /* RETURN ARGUMENTS : */ /* _ None */ /*--------------------------------------------------------------------------*/ + void time_reduce_pre_echo_fx( const Word16 *synth, /* i : ACELP core synthesis Q_syn*/ Word16 *error, /* i/o: SHB BWE synthesis Q0*/ @@ -2435,6 +2436,7 @@ void calc_normal_length_fx_32( * calc_norm_envelop_fx_32() * *-------------------------------------------------------------------*/ + void calc_norm_envelop_fx_32( const Word32 SWB_signal_fx[], /* i : SWB spectrum : Q12 */ Word32 *envelope_fx, /* o : normalized envelope : Q16 */ @@ -2488,11 +2490,16 @@ void calc_norm_envelop_fx_32( return; } + /*-------------------------------------------------------------------* * hq_generic_decoding_fx() * *-------------------------------------------------------------------*/ + 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 */ @@ -2800,14 +2807,28 @@ void hq_generic_decoding_fx( } } - L_tmp1 = L_deposit_l( 0 ); L_tmp2 = L_deposit_l( 0 ); - FOR( i = 0; i < 5; ++i ) +#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 { - 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] ) ); + 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 + } } +#endif pit1_fx = &coeff_out_fx[HQ_GENERIC_HIGH1 + hq_generic_offset]; L_tmp1 = L_max( L_tmp1, 1 ); @@ -3040,6 +3061,7 @@ 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 */ @@ -3587,7 +3609,7 @@ void hq_generic_decoding_ivas_fx( 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 48b95ff92..6d11a397b 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -1968,12 +1968,11 @@ static void ivas_subst_spec_fx( } ELSE { - // 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 ); - move16(); #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 ); + move16(); tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) ); tmp = sub( tmp, shr( output_frame, 1 ) ); tmp = add_sat( tmp, time_offs ); @@ -1993,6 +1992,9 @@ 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 ); + move16(); tmp = sub( tmp, ph_ecu_lookahead ); tmp = add( tmp, sub( Lecu, shr( sub( Lecu, Lprot ), 1 ) ) ); tmp = sub( tmp, shr( output_frame, 1 ) ); @@ -2706,6 +2708,9 @@ static void ivas_rec_wtda_fx( 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; @@ -2776,6 +2781,7 @@ 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 ) ); @@ -2783,8 +2789,18 @@ 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 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 ) ); + + 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 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 ) ); @@ -2803,9 +2819,41 @@ static void ivas_rec_wtda_fx( pOldW -= 1; pNewW += 1; } + +#ifdef HARM_HQ_CORE + out_ptr = xsubst_ + output_frame; +#endif } ELSE { +#ifdef HARM_HQ_CORE + Word16 l; + Word16 Lprot2 = shr( Lprot, 1 ); + + /* 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( 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++ ) ) @@ -2818,13 +2866,18 @@ static void ivas_rec_wtda_fx( 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; } diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 0205594dd..7aa920257 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -1,18 +1,20 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ + #include #include "options.h" /* Compilation switches */ -#include "prot_fx.h" /* Function prototypes */ +#include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Static table prototypes */ #include "ivas_prot_fx.h" + /*--------------------------------------------------------------------------* * hq_pred_hb_bws() * * 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*/ @@ -65,6 +67,7 @@ void ivas_hq_pred_hb_bws_fx( return; } +#endif void hq_pred_hb_bws_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -112,7 +115,12 @@ 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 ); } @@ -375,11 +383,19 @@ 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 ); @@ -393,7 +409,11 @@ void ivas_hq_hr_dec_fx( * 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 */ @@ -411,7 +431,7 @@ void hq_hr_dec_fx( 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 */ + const Word16 core_switching_flag /* i : Core switching flag Q0 */ ) { Word16 nb_sfm; @@ -479,9 +499,9 @@ void hq_hr_dec_fx( #ifdef HARM_HQ_CORE Word16 tmp_length = length; - if( length == 960 ) + if ( length == 960 ) { - tmp_length = L_SPEC48k; + tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE } hq_configure_fx( tmp_length, *hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, @@ -653,6 +673,7 @@ void hq_hr_dec_fx( /*------------------------------------------------------------------* * 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], -- GitLab From fb569235e3d164d404f6ba6dad5c2c4b6e43fdd5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Feb 2026 21:45:03 +0100 Subject: [PATCH 04/31] HARM_HQ_CORE2 --- lib_com/ivas_prot_fx.h | 3 ++- lib_com/low_rate_band_att_fx.c | 33 +++++++++++++++++++++++++++------ lib_com/options.h | 1 + lib_com/prot_fx.h | 5 ++++- lib_dec/FEC_HQ_phase_ecu_fx.c | 9 +++++++++ lib_dec/peak_vq_dec_fx.c | 6 +++++- lib_dec/pvq_core_dec_fx.c | 11 +++++++++++ lib_enc/hq_hr_enc_fx.c | 12 +++++++++--- lib_enc/hvq_enc_fx.c | 5 +++++ lib_enc/peak_vq_enc_fx.c | 19 +++++++++++++++---- lib_enc/prot_fx_enc.h | 3 +++ lib_enc/pvq_core_enc_fx.c | 5 +++++ 12 files changed, 96 insertions(+), 16 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f01a74df4..b8cf37e6d 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1654,6 +1654,7 @@ Word16 ivas_assign_gain_bits_fx( Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ ); #endif +#ifdef HARM_HQ_CORE2 void ivas_fine_gain_pred_fx( const Word16 *sfm_start, /* i : Sub band start indices */ const Word16 *sfm_end, /* i : Sub band end indices */ @@ -1668,7 +1669,7 @@ void ivas_fine_gain_pred_fx( 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, diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 8e7cef9d1..7e94d236a 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -14,7 +14,12 @@ * * Fine gain prediction *--------------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE2 +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 */ @@ -26,7 +31,10 @@ 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 */ - const Word16 core /* i : Core */ +#ifdef HARM_HQ_CORE2 + const Word16 element_mode, /* i : element mode */ +#endif + const Word16 core /* i : Core */ ) { Word16 i, band; @@ -71,11 +79,22 @@ void ivas_fine_gain_pred_fx( 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 */ - 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 ) ); - Mpy_32_16_ss( L_tmp, tmp1, &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ + +#ifdef HARM_HQ_CORE2 + IF( element_mode == EVS_MONO ) + { + 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 */ + } + ELSE +#endif + { + 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 ) ); + 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(); @@ -125,6 +144,7 @@ void ivas_fine_gain_pred_fx( return; } +#ifndef HARM_HQ_CORE2 void fine_gain_pred_fx( const Word16 *sfm_start, /* i : Sub band start indices */ const Word16 *sfm_end, /* i : Sub band end indices */ @@ -228,6 +248,7 @@ void fine_gain_pred_fx( return; } +#endif /*--------------------------------------------------------------------------* * get_max_pulses() diff --git a/lib_com/options.h b/lib_com/options.h index 40276a07b..56e96b95f 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -97,6 +97,7 @@ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define HARM_HQ_CORE /* harmonize HQ core functions */ +#define HARM_HQ_CORE2 /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 19a99bbcf..1067d7daa 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4674,7 +4674,10 @@ 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 */ - const Word16 core /* i : Core */ +#ifdef HARM_HQ_CORE2 + const Word16 element_mode, /* i : element mode */ +#endif + const Word16 core /* i : Core */ ); void fine_gain_quant_fx( diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 6d11a397b..69f60e686 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -5036,6 +5036,15 @@ void ivas_hq_ecu_fx( ( ph_ecu_HqVoicing || ( ( ( GT_16( hHQ_core->env_stab_plc_fx, 16384 ) /* 0.5 in Q15 */ ) && ( LT_16( corr, 19661 ) /* 0.6 in Q15 */ ) ) || ( LT_16( hHQ_core->env_stab_plc_fx, 16384 ) /* 0.5 in Q15 */ && ( GT_16( corr, 27853 ) /* 0.85 in Q15 */ ) ) ) ) ) ) || ( LT_32( st_fx->total_brate, 48000 ) && ( ( ph_ecu_HqVoicing || GT_16( corr, 27853 ) /* 0.85 in Q15 */ ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) ) ); +#ifdef HARM_HQ_CORE + // temp. hack to keep EVS BE + IF( st_fx->element_mode == EVS_MONO ) + { + evs_mode_selection = ( 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] ) ) ); + } +#endif + test(); ivas_mode_selection = ( LT_16( N, PH_ECU_N_LIMIT ) ) || ( LT_16( corr, PH_ECU_CORR_LIMIT_Q15 ) ); diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index 80fa60560..83023b888 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -312,9 +312,13 @@ 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_CORE2 + 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 ); +#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 80a8d2f03..85358adc9 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -270,8 +270,13 @@ Word16 ivas_pvq_core_dec_fx( get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); +#ifdef HARM_HQ_CORE2 + 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 ) @@ -350,8 +355,13 @@ Word16 pvq_core_dec_fx( get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); +#ifdef HARM_HQ_CORE2 + 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 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 ) @@ -361,6 +371,7 @@ Word16 pvq_core_dec_fx( 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(); diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index 7690f3316..aac8a8161 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -102,7 +102,13 @@ void hq_hr_enc_fx( *------------------------------------------------------------------*/ #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, + Word16 tmp_length = length; + if ( length == 960 ) + { + tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE + } + + hq_configure_fx( tmp_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 hq_configure_evs_fx( length, hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, @@ -367,7 +373,7 @@ void hq_hr_enc_ivas_fx( /* calculate and quantize norms */ calc_norm_ivas_fx( t_audio_fx, 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 ); @@ -376,7 +382,7 @@ void hq_hr_enc_ivas_fx( *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); move16(); - + /* Encode norm indices */ encode_envelope_indices_ivas_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index e362dd60d..6ddeefa6a 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -204,8 +204,13 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits */ ELSE #endif { +#ifdef HARM_HQ_CORE2 + nBits = peak_vq_enc_ivas_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 ); diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 56b591ea5..6e60b33c4 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -40,8 +40,11 @@ static void quant_peaks_ivas_fx( *--------------------------------------------------------------------------*/ Word16 peak_vq_enc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bwidth, /* i : audio bandwidth */ +#ifdef HARM_HQ_CORE2 + 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 */ Word32 *coefs_out, /* o : Quantized output vector Q12 */ const Word32 core_brate, /* i : Core bitrate */ @@ -386,9 +389,13 @@ Word16 peak_vq_enc_ivas_fx( move16(); } - +#ifdef HARM_HQ_CORE2 + 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 ); +#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]; @@ -804,9 +811,13 @@ Word16 peak_vq_enc_fx( move16(); } - +#ifdef HARM_HQ_CORE2 + 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, EVS_MONO, HQ_CORE ); +#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]; diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 9bff7a0e4..1ba8cf57c 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3835,6 +3835,9 @@ void diffcod_lrmdct_fx( ); Word16 peak_vq_enc_ivas_fx( +#ifdef HARM_HQ_CORE2 + 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 */ diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 4ee0f7429..9b77dd79d 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -560,6 +560,10 @@ Word16 pvq_core_enc_ivas_fx( get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); /* Fine gain prediction */ +#ifdef HARM_HQ_CORE2 + 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 #ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { @@ -572,6 +576,7 @@ Word16 pvq_core_enc_ivas_fx( 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 ); -- GitLab From 73a38884009cd01f96a0cd2968a82d62feb60003 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Feb 2026 22:31:11 +0100 Subject: [PATCH 05/31] fix --- lib_com/low_rate_band_att_fx.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 7e94d236a..1cff52ee2 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -83,8 +83,7 @@ void ivas_fine_gain_pred_fx( #ifdef HARM_HQ_CORE2 IF( element_mode == EVS_MONO ) { - 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 */ + Mpy_32_16_ss( L_tmp, ivas_fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ } ELSE #endif -- GitLab From 0686cbf6202cdad908c0842b9431bcc25e0cd848 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Feb 2026 23:17:05 +0100 Subject: [PATCH 06/31] fix --- lib_com/low_rate_band_att_fx.c | 4 ++-- lib_com/rom_com_fx.c | 13 ++++++++----- lib_dec/hq_core_dec_fx.c | 8 ++++---- lib_dec/hq_hr_dec_fx.c | 3 +-- lib_enc/hq_lr_enc_fx.c | 4 ++++ lib_enc/pvq_core_enc_fx.c | 16 ++++++++++------ 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 1cff52ee2..dee013bb5 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -29,7 +29,7 @@ void ivas_fine_gain_pred_fx( 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 *y, /* i/o: Quantized vector (int) Q0 */ Word16 *fg_pred, /* o : Predicted fine gains Q12 */ #ifdef HARM_HQ_CORE2 const Word16 element_mode, /* i : element mode */ @@ -295,6 +295,7 @@ void get_max_pulses_fx( return; } + /*--------------------------------------------------------------------------* * fine_gain_dec() * @@ -316,7 +317,6 @@ void fine_gain_dec_fx( Word16 gain_dbq; Word32 L_tmp; - FOR( band = 0; band < num_sfm; band++ ) { gbits = gain_bits[ord[band]]; diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index eff398b33..9346aca6e 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -25791,14 +25791,17 @@ const Word16 ivas_band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { 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 */ const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ /*% sfms=[8,16,24,32,40,48,64,80,96], round(sqrt(sfms)*2^11) */ + + /*----------------------------------------------------------------------------------* * means of ISFs for WB active speech *----------------------------------------------------------------------------------*/ -const Word16 Mean_isf_wb[M] = /* G722.2 active speech ISF's means Q2.56*/ - { - 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, - 8750, 9753, 10705, 11728, 12833, 13971, 15043, 4037 - }; + +/* G722.2 active speech ISF's means Q2.56*/ +const Word16 Mean_isf_wb[M] = { + 738, 1326, 2336, 3578, 4596, 5662, 6711, 7730, + 8750, 9753, 10705, 11728, 12833, 13971, 15043, 4037 +}; const Word16 lsp_shb_prev_tbl_fx[LPC_SHB_ORDER] = { /*Q15 */ diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 987b1f9d3..1127dd5ce 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -736,6 +736,7 @@ void ivas_hq_core_dec_fx( /*-------------------------------------------------------------------------- * Attenuate HFs in case of band-width switching (from higher BW to lower BW) *--------------------------------------------------------------------------*/ + /* attenuate HFs in case of band-width switching */ IF( GT_16( st_fx->bws_cnt1, 0 ) ) { @@ -784,12 +785,12 @@ void ivas_hq_core_dec_fx( 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(); test(); IF( st_fx->element_mode > EVS_MONO && ( core_switching_flag || hq_recovery_flag ) ) @@ -838,7 +839,6 @@ void ivas_hq_core_dec_fx( index = tcx_cfg->tcx_last_overlap_mode; /* Q0 */ move16(); - /* LB synthesis */ E_audio = sub( 31, Q_audio ); IMDCT_fx( t_audio_q, E_audio, hTcxDec->syn_Overl, hTcxDec->syn_Overl_TDAC, wtda_audio_16, tcx_cfg->tcx_aldo_window_1, tcx_cfg->tcx_aldo_window_1_trunc, tcx_cfg->tcx_aldo_window_2, tcx_cfg->tcx_mdct_window_half, tcx_cfg->tcx_mdct_window_minimum, tcx_cfg->tcx_mdct_window_trans, tcx_cfg->tcx_mdct_window_half_length, tcx_cfg->tcx_mdct_window_min_length, index, @@ -1079,10 +1079,10 @@ void HQ_core_dec_init_fx( move16(); set16_fx( hHQ_core->prev_En_sb_fx, 0, NB_SWB_SUBBANDS ); - /*----------------------------------------------------------------------------------* * HQ FEC *----------------------------------------------------------------------------------*/ + hHQ_core->time_offs = 0; move16(); set16_fx( hHQ_core->X_sav_fx, 0, PH_ECU_SPEC_SIZE ); @@ -1121,10 +1121,10 @@ void HQ_core_dec_init_fx( move16(); move16(); - return; } + /*-------------------------------------------------------------------* * HQ_nbfec_init_fx() * diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 7aa920257..b8df02550 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -399,7 +399,6 @@ void ivas_hq_hr_dec_fx( enforce_zero_for_min_envelope_fx( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); - IF( EQ_16( *is_transient, 1 ) ) { ivas_de_interleave_spectrum_fx( t_audio_q, length ); @@ -682,7 +681,6 @@ void hq_hr_dec_fx( enforce_zero_for_min_envelope_fx( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); - IF( EQ_16( *is_transient, 1 ) ) { de_interleave_spectrum_fx( t_audio_q, length ); @@ -691,6 +689,7 @@ void hq_hr_dec_fx( /*------------------------------------------------------------------* * WB/SWB bandwidth switching *------------------------------------------------------------------*/ + hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 74a3a15df..9c1388813 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -206,7 +206,11 @@ void hq_lr_enc_fx( } ELSE { +#ifdef HARM_HQ_CORE + hqswb_clas_fx = peak_avrg_ratio_fx( HQ_BWE_CROSSOVER_BRATE /* st_fx->total_brate - temp. hack to keep EVS BE*/, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ +#else hqswb_clas_fx = peak_avrg_ratio_fx( st_fx->total_brate, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ +#endif } /* write the classification information into the bitstream */ diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 9b77dd79d..51ddf27be 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -310,10 +310,10 @@ void pvq_encode_frame_ivas_fx( 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 */ + &band_bits, &bits_left, &bit_pool ); + 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 ); + &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 ); @@ -430,14 +430,18 @@ void pvq_encode_frame_fx( 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 */ + &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 ); + &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 ); +#ifdef HARM_HQ_CORE2aa + shift = ivas_band_len_ener_shift[ivas_band_len_idx[sfmsize[is] >> 3]]; +#else shift = band_len_ener_shift[band_len_idx[sfmsize[is] >> 3]]; +#endif move16(); FOR( j = 0; j < sfmsize[i]; j++ ) { -- GitLab From 2eaeb027ac8259b8a6a9e8e6238ba45c05eb1b39 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Feb 2026 23:34:32 +0100 Subject: [PATCH 07/31] merge HARM_HQ_CORE2 into HARM_HQ_CORE --- lib_com/ivas_prot_fx.h | 2 +- lib_com/low_rate_band_att_fx.c | 8 +++--- lib_com/prot_fx.h | 5 ++-- lib_dec/hq_hr_dec_fx.c | 4 +++ lib_dec/peak_vq_dec_fx.c | 2 +- lib_dec/pvq_core_dec_fx.c | 46 ++++++++++++++++++++++++++-------- lib_enc/hq_lr_enc_fx.c | 23 ++++++++--------- lib_enc/hvq_enc_fx.c | 2 +- lib_enc/peak_vq_enc_fx.c | 6 ++--- lib_enc/prot_fx_enc.h | 2 +- lib_enc/pvq_core_enc_fx.c | 2 +- 11 files changed, 65 insertions(+), 37 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index b8cf37e6d..d532fd312 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1654,7 +1654,7 @@ Word16 ivas_assign_gain_bits_fx( Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ ); #endif -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE void ivas_fine_gain_pred_fx( const Word16 *sfm_start, /* i : Sub band start indices */ const Word16 *sfm_end, /* i : Sub band end indices */ diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index dee013bb5..7e1fcd5eb 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -15,7 +15,7 @@ * Fine gain prediction *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE void fine_gain_pred_fx( #else void ivas_fine_gain_pred_fx( @@ -31,7 +31,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_CORE2 +#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ #endif const Word16 core /* i : Core */ @@ -80,7 +80,7 @@ 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_CORE2 +#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { Mpy_32_16_ss( L_tmp, ivas_fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ @@ -143,7 +143,7 @@ void ivas_fine_gain_pred_fx( return; } -#ifndef HARM_HQ_CORE2 +#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 */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 1067d7daa..694284e6d 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -4674,7 +4674,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_CORE2 +#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ #endif const Word16 core /* i : Core */ @@ -6760,6 +6760,7 @@ 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, @@ -6774,7 +6775,7 @@ Word16 ivas_pvq_core_dec_fx( 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 */ diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index b8df02550..d8d3798da 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -342,7 +342,11 @@ 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(); diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index 83023b888..8e539eba8 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -312,7 +312,7 @@ 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_CORE2 +#ifdef HARM_HQ_CORE 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 ); #else diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 85358adc9..740e3be4a 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -9,19 +9,24 @@ #include "prot_fx.h" /* Function prototypes */ #include "ivas_prot_fx.h" + /*-------------------------------------------------------------------* * Local prototypes * *-------------------------------------------------------------------*/ + static Word16 get_pvq_splits_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ, const Word16 band_bits, const Word16 sfmsize, Word16 *bits ); static void densitySymbolIndexDecode_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ, const Word16 density, const Word16 opp_sz, const Word16 near_sz, Word16 *index_phi ); + + /*-------------------------------------------------------------------* * pvq_decode_band() * *-------------------------------------------------------------------*/ + static void pvq_decode_band_fx( Decoder_State *st_fx, /* i/o: Decoder state */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ Word16 *pulse_vector, /* i/o: decoded integer shape vector */ Word16 *npulses, /* i/o: number of pulses */ Word16 *coefs_quant, /* i/o: decoded coefficients buffer Qx */ @@ -31,9 +36,7 @@ static void pvq_decode_band_fx( const Word16 strict_bits /* i : Conservative rounding flag */ ) { - Word16 K_val; - Word16 j, Np; Word16 part_start[MAX_SPLITS + 1], dim_part[MAX_SPLITS + 1], bits_part[MAX_SPLITS + 1]; Word16 pool_tot, pool_part, dim_parts; @@ -109,6 +112,12 @@ static void pvq_decode_band_fx( return; } + +/*-------------------------------------------------------------------* + * pvq_decode_frame() + * + *-------------------------------------------------------------------*/ + void pvq_decode_frame_fx( Decoder_State *st_fx, Word16 *coefs_quant, /* o : quantized coefficients Qx */ @@ -197,6 +206,8 @@ void pvq_decode_frame_fx( } rc_dec_finish_fx( st_fx, hPVQ ); + + return; } /*-------------------------------------------------------------------* @@ -204,7 +215,11 @@ 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, @@ -270,7 +285,7 @@ Word16 ivas_pvq_core_dec_fx( get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); -#ifdef HARM_HQ_CORE2 +#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 @@ -286,6 +301,7 @@ Word16 ivas_pvq_core_dec_fx( 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(); @@ -293,6 +309,7 @@ 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, @@ -355,7 +372,7 @@ Word16 pvq_core_dec_fx( get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); -#ifdef HARM_HQ_CORE2 +#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 @@ -378,11 +395,14 @@ Word16 pvq_core_dec_fx( return bits_tot; } +#endif + /*-------------------------------------------------------------------* * decode_energies() * *-------------------------------------------------------------------*/ + void decode_energies_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ @@ -474,6 +494,7 @@ void decode_energies_fx( * densitySymbolIndexDecode() * *-------------------------------------------------------------------*/ + static void densitySymbolIndexDecode_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ @@ -611,6 +632,7 @@ static void densitySymbolIndexDecode_fx( rc_dec_update_fx( st_fx, hPVQ, cum_freq, sym_freq ); *index_phi = alpha; move16(); + return; } @@ -621,12 +643,13 @@ static void densitySymbolIndexDecode_fx( * Retrieve the number of segments *--------------------------------------------------------------------------*/ -static Word16 get_pvq_splits_fx( /* o : Number of segments */ - Decoder_State *st_fx, /* i/o: Decoder state */ - PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ - const Word16 band_bits, /* i : Band bit budget */ - const Word16 sfmsize, /* i : Band width */ - Word16 *bits /* o : Used bits */ +/* o : Number of segments */ +static Word16 get_pvq_splits_fx( + Decoder_State *st_fx, /* i/o: Decoder state */ + PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ + const Word16 band_bits, /* i : Band bit budget */ + const Word16 sfmsize, /* i : Band width */ + Word16 *bits /* o : Used bits */ ) { Word16 Np, i; @@ -673,5 +696,6 @@ static Word16 get_pvq_splits_fx( /* o : Number of segme 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; } diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 9c1388813..0b5044598 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -306,7 +306,6 @@ void hq_lr_enc_fx( bit_budget_fx = sub( sub( *num_bits_fx, ebits_fx ), round_fx( L_shl( L_mult( Ngq_fx, gqbits_fx ), 15 ) ) ); /* (*num_bits) - (short) ceil (ebits) - Ngq * gqbits; Q0*/ - pbits_fx = 0; move16(); @@ -1013,13 +1012,14 @@ void hq_lr_enc_fx( * if flag_pack = 0, estimatng else packing bits *--------------------------------------------------------------------------*/ -static Word16 small_symbol_enc_tran_fx( /* o : bits */ - BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ - const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ - const Word16 BANDS, /* i : number of bands Q0*/ - Word16 *hLCmode, /* i/o: LC mode info Q0*/ - const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ - const Word16 is_transient /* Q0 */ ) +/* o : bits */ +static Word16 small_symbol_enc_tran_fx( + BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream */ + const Word16 *qbidx, /* i : input of dequantized differential energy Q0*/ + const Word16 BANDS, /* i : number of bands Q0*/ + Word16 *hLCmode, /* i/o: LC mode info Q0*/ + const Word16 flag_pack, /* i : indicator of packing or estimating bits Q0*/ + const Word16 is_transient /* Q0 */ ) { Word16 i, bits; Word16 difidx[BANDS_MAX]; @@ -1481,7 +1481,7 @@ static Word16 large_symbol_enc_fx( *-------------------------------------------------------------------*/ static Word16 band_energy_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word32 *L_t_audio, /* i : Q12 : input MDCT signal (Qs) */ const Word16 band_start[], /* i : Q0 : band start table */ const Word16 band_end[], /* i : Q0 : band end table */ @@ -1558,7 +1558,6 @@ static Word16 band_energy_quant_fx( reverse_transient_frame_energies_fx( L_band_energy, bands_fx ); } - /* Quantize the reference and band energies */ exp_normd = norm_l( L_qint ); rev_qint_fx = div_s( 0x4000, round_fx( L_shl( L_qint, exp_normd ) ) ); /* Q14-(29+exp_normd-16)+15 */ @@ -1682,8 +1681,8 @@ static Word16 band_energy_quant_fx( *-------------------------------------------------------------------*/ static Word16 p2a_threshold_quant_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: : bit stream */ - const Word32 *L_t_audio, /* i : Q12 : input spectrum */ + BSTR_ENC_HANDLE hBstr, /* i/o: : bit stream */ + const Word32 *L_t_audio, /* i : Q12 : input spectrum */ const Word16 band_start[], /* i : Q0 : table of start freq for every subband */ const Word16 band_end[], /* i : Q0 : table of end freq for every subband */ const Word16 band_width[], /* i : Q0 : table of bandwidth for every subband */ diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index 6ddeefa6a..433c78e04 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -204,7 +204,7 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits */ ELSE #endif { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE nBits = peak_vq_enc_ivas_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 diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 6e60b33c4..2f9fe2208 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -40,7 +40,7 @@ static void quant_peaks_ivas_fx( *--------------------------------------------------------------------------*/ Word16 peak_vq_enc_ivas_fx( -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ #endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -389,7 +389,7 @@ Word16 peak_vq_enc_ivas_fx( move16(); } -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE 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 ); #else @@ -811,7 +811,7 @@ Word16 peak_vq_enc_fx( move16(); } -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE 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, EVS_MONO, HQ_CORE ); #else diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 1ba8cf57c..146d9473f 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3835,7 +3835,7 @@ void diffcod_lrmdct_fx( ); Word16 peak_vq_enc_ivas_fx( -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ #endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 51ddf27be..5c6c34014 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -564,7 +564,7 @@ Word16 pvq_core_enc_ivas_fx( get_max_pulses_fx( sfm_start, sfm_end, ord, npulses, nb_sfm, pulse_vector, maxpulse ); /* Fine gain prediction */ -#ifdef HARM_HQ_CORE2 +#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 -- GitLab From 25e294bdb6cb8fb4b9bdf2992e5955c9e6a69797 Mon Sep 17 00:00:00 2001 From: vaclav Date: Mon, 23 Feb 2026 23:50:01 +0100 Subject: [PATCH 08/31] HARM_HQ_CORE2 --- lib_com/interleave_spectrum_fx.c | 20 ++++++++++++++++++++ lib_com/ivas_prot_fx.h | 3 ++- lib_com/prot_fx.h | 3 ++- lib_dec/hq_hr_dec_fx.c | 4 ++++ lib_enc/hq_hr_enc_fx.c | 9 +++++++++ lib_enc/peak_vq_enc_fx.c | 30 +++++++++++++++++++++++++++--- 6 files changed, 64 insertions(+), 5 deletions(-) diff --git a/lib_com/interleave_spectrum_fx.c b/lib_com/interleave_spectrum_fx.c index 8847b9f5b..cf2288a22 100644 --- a/lib_com/interleave_spectrum_fx.c +++ b/lib_com/interleave_spectrum_fx.c @@ -43,10 +43,17 @@ #include "ivas_prot_fx.h" +/*--------------------------------------------------------------------------* + * interleave_spectrum() + * + * Interleave the spectrum + *--------------------------------------------------------------------------*/ + void interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ ) +#ifndef HARM_HQ_CORE2 { Word16 i, j, k; Word32 *p1, *p2, *p3, *p4; @@ -131,6 +138,7 @@ 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; @@ -213,7 +221,17 @@ void interleave_spectrum_ivas_fx( } +/*--------------------------------------------------------------------------* + * de_interleave_spectrum() + * + * Deinterleave the spectrum + *--------------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE2 +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 */ ) @@ -307,6 +325,7 @@ void ivas_de_interleave_spectrum_fx( return; } +#ifndef HARM_HQ_CORE2 void de_interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ @@ -400,3 +419,4 @@ void de_interleave_spectrum_fx( return; } +#endif diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index d532fd312..fc996224c 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1750,11 +1750,12 @@ void ivas_fill_spectrum_fx( const Word16 element_mode ); #endif +#ifndef HARM_HQ_CORE2 void ivas_de_interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ ); - +#endif #ifndef HARM_HQ_CORE void ivas_harm_bwe_fx( const Word16 *coeff_fine, /* i : fine structure for BWE */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 694284e6d..5a81ffed8 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1610,11 +1610,12 @@ void interleave_spectrum_fx( const Word16 length /* i : length of spectrum Q0 */ ); +#ifndef HARM_HQ_CORE2 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 */ diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index d8d3798da..6f99f3f2e 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -405,7 +405,11 @@ void ivas_hq_hr_dec_fx( IF( EQ_16( *is_transient, 1 ) ) { +#ifdef HARM_HQ_CORE2 + de_interleave_spectrum_fx( t_audio_q, length ); +#else ivas_de_interleave_spectrum_fx( t_audio_q, length ); +#endif } /*------------------------------------------------------------------* diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index aac8a8161..735268568 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -357,8 +357,13 @@ void hq_hr_enc_ivas_fx( /* Interleave MLT coefficients of 4 sub-vectors in case of transient frame */ IF( is_transient ) { +#ifdef HARM_HQ_CORE2 + interleave_spectrum_fx( t_audio_fx, length ); +#else interleave_spectrum_ivas_fx( t_audio_fx, length ); +#endif } + test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { @@ -512,7 +517,11 @@ void hq_hr_enc_ivas_fx( IF( is_transient ) { +#ifdef HARM_HQ_CORE2 + 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/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 2f9fe2208..9b0780bea 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -19,8 +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 ); +#ifndef HARM_HQ_CORE2 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 */ @@ -31,6 +31,7 @@ static void quant_peaks_ivas_fx( const Word32 core_brate, /* i : Core bitrate */ const Word16 Npeaks /* i : Number of peaks */ ); +#endif /*-------------------------------------------------------------------------- @@ -100,7 +101,6 @@ Word16 peak_vq_enc_ivas_fx( assert( ( core_brate > HQ_16k40 && core_brate <= HQ_48k ) && "HVQ rate not supported" ); - max_peaks = extract_l( Mpy_32_32( L_add( imult3216( core_brate, HVQ_PEAKS_PER_DELTA ), HVQ_PEAKS_PER_DELTA_OFFS ), 282564 ) ); /* 1/HVQ_PEAKS_BPS_DELTA in Q31 */ bits = 0; @@ -313,18 +313,30 @@ 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_CORE2 + 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_CORE2 + 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_CORE2 + 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 ); @@ -466,6 +478,8 @@ Word16 peak_vq_enc_ivas_fx( return bits; } + + Word16 peak_vq_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 bwidth, /* i : audio bandwidth */ @@ -888,13 +902,19 @@ Word16 peak_vq_enc_fx( return bits; } + /*-------------------------------------------------------------------------- * quant_peaks_fx() * * Applies VQ on input vector *--------------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE2 +static void quant_peaks_fx( +#else static void quant_peaks_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ +#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 */ @@ -1047,6 +1067,7 @@ static void quant_peaks_ivas_fx( return; } +#ifndef HARM_HQ_CORE2 static void quant_peaks_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word32 *vect_in, /* i : Target vector in Q12 */ @@ -1203,6 +1224,7 @@ static void quant_peaks_fx( return; } +#endif /*-------------------------------------------------------------------------- * code_pos() @@ -1286,6 +1308,7 @@ static Word16 sparse_code_pos_fx( * * Code pulse positions *--------------------------------------------------------------------------*/ +#ifndef HARM_HQ_CORE2 static Word16 hvq_code_pos_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *inp, @@ -1397,6 +1420,7 @@ static Word16 hvq_code_pos_ivas_fx( return bits; } +#endif static Word16 hvq_code_pos_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ -- GitLab From 95e954687be22b60def842ec7e1436ea6cca9c62 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 07:03:06 +0100 Subject: [PATCH 09/31] fix --- lib_dec/hq_hr_dec_fx.c | 10 ++++++++++ lib_enc/hq_hr_enc_fx.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 6f99f3f2e..ec5947042 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -691,7 +691,17 @@ void hq_hr_dec_fx( IF( EQ_16( *is_transient, 1 ) ) { +#ifdef HARM_HQ_CORE2 + tmp_length = length; + if ( length == 960 ) + { + tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE + } + + de_interleave_spectrum_fx( t_audio_q, tmp_length ); +#else de_interleave_spectrum_fx( t_audio_q, length ); +#endif } /*------------------------------------------------------------------* diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index 735268568..de7bce073 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -122,7 +122,17 @@ void hq_hr_enc_fx( /* Interleave MLT coefficients of 4 sub-vectors in case of transient */ IF( EQ_16( is_transient, 1 ) ) { +#ifdef HARM_HQ_CORE2 + Word16 tmp_length = length; + if ( length == 960 ) + { + tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE + } + + interleave_spectrum_fx( t_audio, tmp_length ); +#else interleave_spectrum_fx( t_audio, length ); +#endif } test(); -- GitLab From ba0ecb0357adae5897fcff0a302f620444e2ecf5 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 07:08:55 +0100 Subject: [PATCH 10/31] HARM_HQ_CORE2 --- lib_enc/prot_fx_enc.h | 3 +- lib_enc/pvq_core_enc_fx.c | 62 +++++++++++++++++++++++++++++++++------ lib_enc/pvq_encode_fx.c | 5 ++++ 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 146d9473f..34ecb0001 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4088,6 +4088,7 @@ void pvq_encode_fx( const Word16 neg_gain /* i : Gain use - negative gain in Q15 0 ..1 */ ); +#ifndef HARM_HQ_CORE2 void pvq_encode_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -4099,7 +4100,7 @@ void pvq_encode_ivas_fx( 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 5c6c34014..a61025226 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -16,6 +16,7 @@ *--------------------------------------------------------------------*/ 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_CORE2 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 */ @@ -26,10 +27,21 @@ static Word16 calc_pvq_splits_ivas_fx( /* o : Number of 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_CORE2 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 + + +/*-------------------------------------------------------------------* + * pvq_encode_band() + * + * Encode band with PVQ + *--------------------------------------------------------------------*/ +#ifndef HARM_HQ_CORE2 /* Encode band with PVQ */ static void pvq_encode_band_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ @@ -58,7 +70,11 @@ static void pvq_encode_band_ivas_fx( Word16 tmp; Word32 L_coefs_quant_fx[PVQ_MAX_BAND_SIZE]; +#ifdef HARM_HQ_CORE2 + Np = calc_pvq_splits_fx( hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit ); +#else Np = calc_pvq_splits_ivas_fx( hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit ); +#endif band_bits_tot = sub( band_bits, split_bit ); enr = L_deposit_l( 0 ); @@ -90,7 +106,11 @@ static void pvq_encode_band_ivas_fx( set16_fx( g_part_neg, -32768, Np ); /* -1.0 in Q15 */ IF( GT_16( Np, 1 ) ) { +#ifdef HARM_HQ_CORE2 + encode_energies_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 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 ); +#endif } ELSE { @@ -121,8 +141,13 @@ static void pvq_encode_band_ivas_fx( IF( K_val > 0 ) { +#ifdef HARM_HQ_CORE2 + pvq_encode_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 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] ); +#endif } ELSE { @@ -133,6 +158,7 @@ static void pvq_encode_band_ivas_fx( 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 */ @@ -147,7 +173,6 @@ static void pvq_encode_band_fx( const Word16 strict_bits /* i : conservative rounding flag */ ) { - Word16 K_val; Word16 j, Np; Word32 enr, E_part[MAX_SPLITS + 1]; @@ -312,8 +337,13 @@ 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_CORE2 + 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 ); @@ -810,6 +840,8 @@ static void encode_energies_fx( return; } + +#ifndef HARM_HQ_CORE2 static void encode_energies_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -952,6 +984,7 @@ 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 */ @@ -1024,6 +1057,7 @@ static void densityIndexSymbolEncode_ivas_fx( return; } +#endif static void densityIndexSymbolEncode_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -1098,19 +1132,26 @@ static void densityIndexSymbolEncode_fx( return; } + /*--------------------------------------------------------------------------* * calc_pvq_splits() * * Calculate the number of segments needed *--------------------------------------------------------------------------*/ -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 */ + +#ifdef HARM_HQ_CORE2 +/* 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 */ + 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; @@ -1206,6 +1247,8 @@ static Word16 calc_pvq_splits_ivas_fx( /* o : Number of Np = s_min( sfmsize, Np ); /* The code line assumes that MIN_BAND_SIZE is 1 */ return Np; } +#ifndef HARM_HQ_CORE2 + 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 */ @@ -1309,3 +1352,4 @@ static Word16 calc_pvq_splits_fx( /* o : Number of segm 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 8db3fc5b4..eeab6b0a3 100644 --- a/lib_enc/pvq_encode_fx.c +++ b/lib_enc/pvq_encode_fx.c @@ -166,10 +166,14 @@ static Word16 one_pulse_search( return imax; } + + /*-----------------------------------------------------------------------* * Function pvq_encode_fx() * * * *-----------------------------------------------------------------------*/ + +#ifndef HARM_HQ_CORE2 void pvq_encode_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -374,6 +378,7 @@ void pvq_encode_ivas_fx( return; } +#endif void pvq_encode_fx( BSTR_ENC_HANDLE hBstr, -- GitLab From 9c9d91e2b95c8320ab8a1b93d8751d8711865205 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 07:27:19 +0100 Subject: [PATCH 11/31] HARM_HQ_CORE2 --- lib_com/interleave_spectrum_fx.c | 6 +++--- lib_com/ivas_prot_fx.h | 2 +- lib_com/prot_fx.h | 2 +- lib_com/rom_com.h | 8 ++++--- lib_com/rom_com_fx.c | 2 ++ lib_dec/hq_hr_dec_fx.c | 4 ++-- lib_enc/hq_hr_enc_fx.c | 8 +++---- lib_enc/peak_vq_enc_fx.c | 18 +++++++++------- lib_enc/prot_fx_enc.h | 5 +++-- lib_enc/pvq_core_enc_fx.c | 36 ++++++++++++++++++++------------ lib_enc/pvq_encode_fx.c | 5 +++-- 11 files changed, 58 insertions(+), 38 deletions(-) diff --git a/lib_com/interleave_spectrum_fx.c b/lib_com/interleave_spectrum_fx.c index cf2288a22..1ad331a5b 100644 --- a/lib_com/interleave_spectrum_fx.c +++ b/lib_com/interleave_spectrum_fx.c @@ -53,7 +53,7 @@ void interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ ) -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE { Word16 i, j, k; Word32 *p1, *p2, *p3, *p4; @@ -227,7 +227,7 @@ void interleave_spectrum_ivas_fx( * Deinterleave the spectrum *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE void de_interleave_spectrum_fx( #else void ivas_de_interleave_spectrum_fx( @@ -325,7 +325,7 @@ void ivas_de_interleave_spectrum_fx( return; } -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE void de_interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index fc996224c..f60352128 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1750,7 +1750,7 @@ void ivas_fill_spectrum_fx( const Word16 element_mode ); #endif -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE void ivas_de_interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 5a81ffed8..c1e828531 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -1610,7 +1610,7 @@ void interleave_spectrum_fx( const Word16 length /* i : length of spectrum Q0 */ ); -#ifndef HARM_HQ_CORE2 +#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 */ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index a61ee76af..355cd3c62 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1486,9 +1486,11 @@ 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 +#ifndef HARM_HQ_CORE2 +extern const Word16 band_len_idx[]; // Q0 +extern const Word16 band_len_ener_shift[]; // Q0 +extern const Word16 fine_gain_pred_sqrt_bw[]; // Q11 +#endif 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 diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index 9346aca6e..9ce3d9bd0 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -25776,6 +25776,7 @@ 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] */ +#ifndef HARM_HQ_CORE2 const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { // Q0 /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ @@ -25784,6 +25785,7 @@ const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { 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) */ +#endif 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*/ diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index ec5947042..4c043c288 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -405,7 +405,7 @@ void ivas_hq_hr_dec_fx( IF( EQ_16( *is_transient, 1 ) ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE de_interleave_spectrum_fx( t_audio_q, length ); #else ivas_de_interleave_spectrum_fx( t_audio_q, length ); @@ -691,7 +691,7 @@ void hq_hr_dec_fx( IF( EQ_16( *is_transient, 1 ) ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE tmp_length = length; if ( length == 960 ) { diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index de7bce073..b0fb53716 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -122,8 +122,8 @@ void hq_hr_enc_fx( /* Interleave MLT coefficients of 4 sub-vectors in case of transient */ IF( EQ_16( is_transient, 1 ) ) { -#ifdef HARM_HQ_CORE2 - Word16 tmp_length = length; +#ifdef HARM_HQ_CORE + tmp_length = length; if ( length == 960 ) { tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE @@ -367,7 +367,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_CORE2 +#ifdef HARM_HQ_CORE interleave_spectrum_fx( t_audio_fx, length ); #else interleave_spectrum_ivas_fx( t_audio_fx, length ); @@ -527,7 +527,7 @@ void hq_hr_enc_ivas_fx( IF( is_transient ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE de_interleave_spectrum_fx( t_audio_q_fx, length ); #else ivas_de_interleave_spectrum_fx( t_audio_q_fx, length ); diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 9b0780bea..2bb89c9ee 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -19,7 +19,7 @@ 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 ); -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE 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*/ @@ -313,7 +313,7 @@ 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_CORE2 +#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 ); @@ -323,7 +323,7 @@ Word16 peak_vq_enc_ivas_fx( } indx = sub( vq_peak_idx[i], 2 ); -#ifdef HARM_HQ_CORE2 +#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 ); @@ -332,7 +332,7 @@ Word16 peak_vq_enc_ivas_fx( bits = add( bits, 9 ); /* Quantize peak positions and sign with HVQ */ -#ifdef HARM_HQ_CORE2 +#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 ); @@ -392,8 +392,12 @@ Word16 peak_vq_enc_ivas_fx( move16(); set16_fx( npulses, 0, MAX_PVQ_BANDS ); +#ifdef HARM_HQ_CORE2 + 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++ ) { @@ -909,7 +913,7 @@ Word16 peak_vq_enc_fx( * Applies VQ on input vector *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE static void quant_peaks_fx( #else static void quant_peaks_ivas_fx( @@ -1067,7 +1071,7 @@ static void quant_peaks_ivas_fx( return; } -#ifndef HARM_HQ_CORE2 +#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 */ @@ -1308,7 +1312,7 @@ static Word16 sparse_code_pos_fx( * * Code pulse positions *--------------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE static Word16 hvq_code_pos_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *inp, diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 34ecb0001..98f2fce0b 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -4040,6 +4040,7 @@ void pvq_encode_frame_fx( const Word16 core /* i : core */ ); +#ifndef HARM_HQ_CORE2 void pvq_encode_frame_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *coefs_norm, /* i : normalized coefficients to encode */ @@ -4056,7 +4057,7 @@ void pvq_encode_frame_ivas_fx( 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 */ @@ -4088,7 +4089,7 @@ void pvq_encode_fx( const Word16 neg_gain /* i : Gain use - negative gain in Q15 0 ..1 */ ); -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE void pvq_encode_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index a61025226..d915c80b4 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -16,7 +16,7 @@ *--------------------------------------------------------------------*/ 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_CORE2 +#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 */ @@ -30,7 +30,7 @@ static void densityIndexSymbolEncode_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HAN #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_CORE2 +#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,7 +41,7 @@ static void encode_energies_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, * Encode band with PVQ *--------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE /* Encode band with PVQ */ static void pvq_encode_band_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ @@ -70,7 +70,7 @@ static void pvq_encode_band_ivas_fx( Word16 tmp; Word32 L_coefs_quant_fx[PVQ_MAX_BAND_SIZE]; -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE Np = calc_pvq_splits_fx( hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit ); #else Np = calc_pvq_splits_ivas_fx( hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit ); @@ -106,7 +106,7 @@ static void pvq_encode_band_ivas_fx( set16_fx( g_part_neg, -32768, Np ); /* -1.0 in Q15 */ IF( GT_16( Np, 1 ) ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE encode_energies_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 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 ); @@ -141,7 +141,7 @@ static void pvq_encode_band_ivas_fx( IF( K_val > 0 ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE pvq_encode_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 @@ -261,7 +261,12 @@ static void pvq_encode_band_fx( return; } + +#ifdef HARM_HQ_CORE2 +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[] */ @@ -337,7 +342,7 @@ 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_CORE2 +#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 @@ -386,6 +391,7 @@ void pvq_encode_frame_ivas_fx( return; } +#ifndef HARM_HQ_CORE2 void pvq_encode_frame_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *coefs_norm, /* i : normalized coefficients to encode */ @@ -467,8 +473,8 @@ void pvq_encode_frame_fx( xy_corr = L_deposit_l( 0 ); yy_corr = L_deposit_l( 1 ); -#ifdef HARM_HQ_CORE2aa - shift = ivas_band_len_ener_shift[ivas_band_len_idx[sfmsize[is] >> 3]]; +#ifdef HARM_HQ_CORE2 + shift = ivas_band_len_ener_shift[ivas_band_len_idx[shr( sfmsize[is], 3 )]]; #else shift = band_len_ener_shift[band_len_idx[sfmsize[is] >> 3]]; #endif @@ -508,7 +514,7 @@ void pvq_encode_frame_fx( return; } - +#endif /*---------------------------------------------------------------------* * pvq_core_enc() @@ -557,6 +563,9 @@ Word16 pvq_core_enc_ivas_fx( #endif pvq_bits = shr( R_upd, 3 ); +#ifdef HARM_HQ_CORE2 + 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 #ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { @@ -567,6 +576,7 @@ Word16 pvq_core_enc_ivas_fx( { 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 ) { @@ -841,7 +851,7 @@ static void encode_energies_fx( return; } -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE static void encode_energies_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -1139,7 +1149,7 @@ static void densityIndexSymbolEncode_fx( * Calculate the number of segments needed *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE /* o : Number of segments */ static Word16 calc_pvq_splits_fx( #else @@ -1247,7 +1257,7 @@ static Word16 calc_pvq_splits_ivas_fx( /* o : Number of segments */ Np = s_min( sfmsize, Np ); /* The code line assumes that MIN_BAND_SIZE is 1 */ return Np; } -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE static Word16 calc_pvq_splits_fx( /* o : Number of segments */ BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ diff --git a/lib_enc/pvq_encode_fx.c b/lib_enc/pvq_encode_fx.c index eeab6b0a3..a7c99a1fb 100644 --- a/lib_enc/pvq_encode_fx.c +++ b/lib_enc/pvq_encode_fx.c @@ -1,6 +1,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ + #include #include "options.h" /* Compilation switches */ #include "cnst.h" @@ -15,7 +16,7 @@ active if k>=128 and accumulated energy is high enough, comes at a controlled complexity cost, as dimensions decrease for high k's*/ -/* o : maximum value in the input vector */ +/* o : maximum value in the input vector */ static Word16 max_val_fx( const Word16 *vec, /* i : input vector */ const Word16 lvec /* i : length of input vector */ @@ -173,7 +174,7 @@ static Word16 one_pulse_search( * * *-----------------------------------------------------------------------*/ -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE void pvq_encode_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ -- GitLab From f915b16ebfaabc82c157337cecd88c5f52a3327a Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 07:53:11 +0100 Subject: [PATCH 12/31] HARM_HQ_CORE2 --- lib_com/hq_tools_fx.c | 36 ++++++++++++++++++++++++++++++---- lib_com/low_rate_band_att_fx.c | 10 +++++++++- lib_com/prot_fx.h | 6 ++++-- lib_com/rom_com.h | 8 ++++---- lib_com/rom_com_fx.c | 11 +++++++++-- lib_enc/hq_env_enc_fx.c | 24 ++++++++++++----------- lib_enc/hq_hr_enc_fx.c | 15 +++++++++++++- lib_enc/peak_vq_enc_fx.c | 2 +- lib_enc/prot_fx_enc.h | 5 +++-- lib_enc/pvq_core_enc_fx.c | 20 ++++++++++++++----- 10 files changed, 104 insertions(+), 33 deletions(-) diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 65e4e5cf4..11fd94320 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -33,6 +33,7 @@ /*==================================================================================== EVS Codec 3GPP TS26.452 Nov 04, 2021. Version 16.4.0 ====================================================================================*/ + #include #include #include "options.h" /* Compilation switches */ @@ -41,11 +42,15 @@ #include "prot_fx.h" #include "ivas_prot_fx.h" + /*--------------------------------------------------------------------------* * Local function prototypes *--------------------------------------------------------------------------*/ 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 /*--------------------------------------------------------------------------* @@ -61,7 +66,6 @@ void hq_swb_harmonic_calc_norm_envelop_fx( const Word16 SWB_flength /* i : length of input signal Q0*/ ) { - Word16 lookback; Word16 env_index; Word16 n_freq; @@ -1540,11 +1544,19 @@ void hvq_concat_bands_fx( return; } + + /*--------------------------------------------------------------------------* * noise_mix_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 */ @@ -1804,12 +1816,15 @@ void map_hq_generic_fenv_norm_fx( normqlg2[i] = dicnlg2[s_min( add( ynrm[i], 10 ), 39 )]; /*Q0*/ move16(); } + return; } -static void update_rsubband_fx( const Word16 nb_sfm, /*Q0*/ - Word16 *Rsubband, /* Q3 */ - Word16 b_add_bits_denv /*Q0*/ ) + +static void update_rsubband_fx( + const Word16 nb_sfm, /*Q0*/ + Word16 *Rsubband, /* Q3 */ + Word16 b_add_bits_denv /*Q0*/ ) { Word16 i; @@ -1833,6 +1848,14 @@ static void update_rsubband_fx( const Word16 nb_sfm, /*Q0*/ return; } + +/*-------------------------------------------------------------------* + * get_nor_delta_hf() + * + * + *--------------------------------------------------------------------------*/ + +/*! r: Number of bits consumed for the delta coding */ Word16 get_nor_delta_hf_fx( Decoder_State *st, Word16 *ynrm, /*Q0*/ @@ -1877,6 +1900,8 @@ Word16 get_nor_delta_hf_fx( } return add_bits_denv; } + +#ifndef HARM_HQ_CORE2 /*-------------------------------------------------------------------* * calc_nor_delta_hf() * @@ -1973,11 +1998,14 @@ Word16 calc_nor_delta_hf_ivas_fx( } return add_bits_denv; } +#endif + /*-------------------------------------------------------------------* * calc_nor_delta_hf() * * *--------------------------------------------------------------------------*/ + Word16 calc_nor_delta_hf_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word32 *t_audio, /* i : transform-domain coefficients Qx*/ diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 7e1fcd5eb..68b995784 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -59,10 +59,18 @@ 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++ ) { @@ -83,7 +91,7 @@ void ivas_fine_gain_pred_fx( #ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { - Mpy_32_16_ss( L_tmp, ivas_fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ + Mpy_32_16_ss( L_tmp, fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ } ELSE #endif diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c1e828531..e8db9d285 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -625,6 +625,7 @@ 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 */ @@ -636,7 +637,7 @@ void noise_mix_fx( 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 */ @@ -675,6 +676,7 @@ Word16 calc_nor_delta_hf_fx( const Word16 core_sfm /* i : index of the end band for core */ ); +#ifndef HARM_HQ_CORE2 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*/ @@ -686,7 +688,7 @@ Word16 calc_nor_delta_hf_ivas_fx( const Word16 *sfm_start, /* i : Start index of bands */ const Word16 core_sfm /* i : index of the end band for core */ ); - +#endif #ifndef HARM_HQ_CORE void hq_bwe_fx( const Word16 HQ_mode, /* i : HQ mode */ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 355cd3c62..272f8a8df 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1486,14 +1486,14 @@ extern const Word16 tab_hup_l_fx[]; // Q15 extern const Word16 mfreq_loc_Q2fx[]; // Q0 extern const Word16 mfreq_loc_div_25[]; // Q0 -#ifndef HARM_HQ_CORE2 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 #endif -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 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 9ce3d9bd0..ef143324c 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -25776,7 +25776,14 @@ 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] */ -#ifndef HARM_HQ_CORE2 +#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*/ +}; // Q0 +const Word16 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 */ +const Word16 fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ +#else const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { // Q0 /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ @@ -25785,13 +25792,13 @@ const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { 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) */ -#endif 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 */ const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ +#endif /*% sfms=[8,16,24,32,40,48,64,80,96], round(sqrt(sfms)*2^11) */ diff --git a/lib_enc/hq_env_enc_fx.c b/lib_enc/hq_env_enc_fx.c index bcf0e3945..e59f6a1ca 100644 --- a/lib_enc/hq_env_enc_fx.c +++ b/lib_enc/hq_env_enc_fx.c @@ -4,28 +4,29 @@ #include #include "options.h" /* Compilation switches */ -// #include "prot_fx.h" /* Function prototypes */ #include "rom_enc.h" #include "rom_com.h" #include "stl.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ + /*--------------------------------------------------------------------------------------* * encode_envelope_indices_fx() * * Encode envelope indices *--------------------------------------------------------------------------------------*/ -Word16 encode_envelope_indices_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 */ +/* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ +Word16 encode_envelope_indices_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 */ ) { Word16 bits; @@ -38,7 +39,6 @@ Word16 encode_envelope_indices_fx( /* o : Number of b Word16 m, r; Word16 v, k; - set16_fx( difidx_org, 0, NB_SFM ); difidx_flag = 0; move16(); @@ -552,6 +552,7 @@ Word16 encode_envelope_indices_fx( /* o : Number of b return hcode_l; } +#ifndef HARM_HQ_CORE2 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 */ @@ -1086,6 +1087,7 @@ Word16 encode_envelope_indices_ivas_fx( /* o : Number 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 b0fb53716..4265e71ab 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -393,13 +393,21 @@ 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_CORE2 + 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 ) ); move16(); /* Encode norm indices */ +#ifdef HARM_HQ_CORE2 + 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 @@ -415,6 +423,7 @@ void hq_hr_enc_ivas_fx( *num_bits = add( *num_bits, 1 ); /* conditional 1 bit saving for representing FD3 BWE excitation class */ move16(); } + map_hq_generic_fenv_norm_fx( hqswb_clas, hq_generic_fenv_fx, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); } @@ -433,12 +442,16 @@ 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_CORE2 + 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 ); } - Word16 Q_audio = 12, Q_shift; + Word16 Q_audio = Q12, Q_shift; move16(); /*------------------------------------------------------------------* diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 2bb89c9ee..b7d9a7402 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -392,7 +392,7 @@ Word16 peak_vq_enc_ivas_fx( move16(); set16_fx( npulses, 0, MAX_PVQ_BANDS ); -#ifdef HARM_HQ_CORE2 +#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, diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 98f2fce0b..2029961e1 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3704,6 +3704,7 @@ void diff_envelope_coding_fx( Word16 *difidx /* o : differential code Q0 */ ); +#ifndef HARM_HQ_CORE2 /* 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 */ @@ -3715,7 +3716,7 @@ Word16 encode_envelope_indices_ivas_fx( const Word16 flag_HQ2, /* i : indicator of HQ2 core Q0 */ const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ ); - +#endif 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 */ @@ -4040,7 +4041,7 @@ void pvq_encode_frame_fx( const Word16 core /* i : core */ ); -#ifndef HARM_HQ_CORE2 +#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 */ diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index d915c80b4..80be8df84 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -262,7 +262,14 @@ static void pvq_encode_band_fx( return; } -#ifdef HARM_HQ_CORE2 + +/*-------------------------------------------------------------------* + * pvq_encode_frame() + * + * + *--------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE void pvq_encode_frame_fx( #else void pvq_encode_frame_ivas_fx( @@ -285,7 +292,6 @@ void pvq_encode_frame_ivas_fx( { Word16 i, j; Word16 band_bits, bits_left; - Word16 bit_pool = 0; move16(); Word16 coded_bands, bands_to_code; @@ -352,7 +358,11 @@ void pvq_encode_frame_ivas_fx( 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++ ) { @@ -391,7 +401,7 @@ void pvq_encode_frame_ivas_fx( return; } -#ifndef HARM_HQ_CORE2 +#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 */ @@ -473,7 +483,7 @@ void pvq_encode_frame_fx( xy_corr = L_deposit_l( 0 ); yy_corr = L_deposit_l( 1 ); -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE shift = ivas_band_len_ener_shift[ivas_band_len_idx[shr( sfmsize[is], 3 )]]; #else shift = band_len_ener_shift[band_len_idx[sfmsize[is] >> 3]]; @@ -563,7 +573,7 @@ Word16 pvq_core_enc_ivas_fx( #endif pvq_bits = shr( R_upd, 3 ); -#ifdef HARM_HQ_CORE2 +#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 #ifdef HARM_HQ_CORE -- GitLab From 4ab212b39f10bd5034c86a161dbed3cda94521fd Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 08:19:04 +0100 Subject: [PATCH 13/31] HARM_HQ_CORE2 --- lib_com/hq_tools_fx.c | 9 ++++--- lib_com/low_rate_band_att_fx.c | 12 ++++++--- lib_com/prot_fx.h | 5 +++- lib_enc/hq_env_enc_fx.c | 2 +- lib_enc/hq_hr_enc_fx.c | 47 ++++++++++++++++++++++++---------- lib_enc/prot_fx_enc.h | 6 +++-- lib_enc/swb_bwe_enc_fx.c | 30 ++++++++++++++++------ 7 files changed, 79 insertions(+), 32 deletions(-) diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 11fd94320..44317785f 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -1901,7 +1901,7 @@ Word16 get_nor_delta_hf_fx( return add_bits_denv; } -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE /*-------------------------------------------------------------------* * calc_nor_delta_hf() * @@ -2179,6 +2179,7 @@ void hq_bwe_ivas_fx( return; } + /*--------------------------------------------------------------------------* * hq_wb_nf_bwe() * @@ -2597,6 +2598,7 @@ void hq_wb_nf_bwe_fx( return; } + /*--------------------------------------------------------------------------* * enforce_zero_for_min_envelope_fx() * @@ -2641,6 +2643,8 @@ void enforce_zero_for_min_envelope_fx( return; } + + /*--------------------------------------------------------------------------* * apply_envelope() * @@ -2676,10 +2680,10 @@ void apply_envelope_enc_ivas_fx( } } - return; } + /*--------------------------------------------------------------------------* * apply_envelope() * @@ -2776,6 +2780,5 @@ void apply_envelope_fx( } } - return; } diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 68b995784..b2c138207 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -42,7 +42,9 @@ 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; @@ -91,18 +93,22 @@ void ivas_fine_gain_pred_fx( #ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { - Mpy_32_16_ss( L_tmp, fine_gain_pred_sqrt_bw[bw_idx], &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ + tmp1 = fine_gain_pred_sqrt_bw[bw_idx]; } ELSE #endif { Word16 norm = norm_s( bw ); +#ifdef HARM_HQ_CORE + Word16 tmp_exp = sub( 15, norm ); +#else Word16 tmp1, tmp_exp = sub( 15, norm ); +#endif tmp1 = Sqrt16( shl( bw, norm ), &tmp_exp ); tmp1 = shr( tmp1, sub( sub( 15, tmp_exp ), Q11 ) ); Mpy_32_16_ss( L_tmp, tmp1, &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ } - + 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(); test(); diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index e8db9d285..84516152c 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -676,7 +676,7 @@ Word16 calc_nor_delta_hf_fx( const Word16 core_sfm /* i : index of the end band for core */ ); -#ifndef HARM_HQ_CORE2 +#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*/ @@ -10130,6 +10130,9 @@ void IGFEncConcatenateBitstream( ); void hq_generic_hf_encoding_fx( +#ifdef HARM_HQ_CORE2 + 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_enc/hq_env_enc_fx.c b/lib_enc/hq_env_enc_fx.c index e59f6a1ca..98c94cc2f 100644 --- a/lib_enc/hq_env_enc_fx.c +++ b/lib_enc/hq_env_enc_fx.c @@ -552,7 +552,7 @@ Word16 encode_envelope_indices_fx( return hcode_l; } -#ifndef HARM_HQ_CORE2 +#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 */ diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index 4265e71ab..efe376ea7 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -168,7 +168,17 @@ void hq_hr_enc_fx( test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { +#ifdef HARM_HQ_CORE2 + tmp_length = length; + if ( st_fx->bwidth == FB ) + { + tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE + } + + hq_generic_hf_encoding_fx( st_fx->element_mode, t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas, tmp_length ); +#else hq_generic_encoding_fx( t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas /*, length*/ ); +#endif 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*/ @@ -393,7 +403,7 @@ 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_CORE2 +#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 */ @@ -403,7 +413,7 @@ void hq_hr_enc_ivas_fx( move16(); /* Encode norm indices */ -#ifdef HARM_HQ_CORE2 +#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 ); @@ -416,7 +426,11 @@ 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_CORE2 + 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 ) ) { @@ -442,7 +456,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_CORE2 +#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 */ @@ -532,22 +546,27 @@ void hq_hr_enc_ivas_fx( move16(); /* Prepare synthesis for LB generation in case of switch to ACELP */ - IF( NE_16( hqswb_clas, HQ_HVQ ) ) - { - apply_envelope_enc_ivas_fx( t_audio_q_norm, ynrm, num_sfm, sfm_start, sfm_end, t_audio_q_fx ); - scale_sig32( t_audio_q_fx, length, sub( Q12, Q_audio ) ); // Q12 - } +#ifdef HARM_HQ_CORE2 + IF( st->element_mode > EVS_MONO ) +#endif + { + IF( NE_16( hqswb_clas, HQ_HVQ ) ) + { + apply_envelope_enc_ivas_fx( t_audio_q_norm, ynrm, num_sfm, sfm_start, sfm_end, t_audio_q_fx ); + scale_sig32( t_audio_q_fx, length, sub( Q12, Q_audio ) ); // Q12 + } - IF( is_transient ) - { + IF( is_transient ) + { #ifdef HARM_HQ_CORE - de_interleave_spectrum_fx( t_audio_q_fx, length ); + de_interleave_spectrum_fx( t_audio_q_fx, length ); #else - ivas_de_interleave_spectrum_fx( t_audio_q_fx, length ); + ivas_de_interleave_spectrum_fx( t_audio_q_fx, length ); #endif - } + } - Copy32( t_audio_q_fx, t_audio_fx, length ); + Copy32( t_audio_q_fx, t_audio_fx, length ); + } return; } diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 2029961e1..933b9d67f 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3704,7 +3704,7 @@ void diff_envelope_coding_fx( Word16 *difidx /* o : differential code Q0 */ ); -#ifndef HARM_HQ_CORE2 +#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 */ @@ -3717,6 +3717,8 @@ Word16 encode_envelope_indices_ivas_fx( const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ ); #endif +#ifndef HARM_HQ_CORE2 + 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 */ @@ -3724,7 +3726,7 @@ void hq_generic_encoding_fx( 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 */ diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index 05802bf45..b88e5745d 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -4267,6 +4267,7 @@ static Word16 decision_hq_generic_class_fx_32( } } +#ifndef HARM_HQ_CORE2 /*-------------------------------------------------------------------* * hq_generic_encoding_fx() * @@ -4486,7 +4487,7 @@ void hq_generic_encoding_fx( return; } - +#endif /*-------------------------------------------------------------------* * fd_bwe_enc_init_fx() @@ -4541,6 +4542,9 @@ void fd_bwe_enc_init_fx( *-------------------------------------------------------------------*/ void hq_generic_hf_encoding_fx( +#ifdef HARM_HQ_CORE2 + 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 */ @@ -4703,15 +4707,25 @@ void hq_generic_hf_encoding_fx( IF( EQ_16( length, L_SPEC48k ) ) { - Word16 sf = getScaleFactor16( hq_generic_fenv_fx, add( DIM_FB, nenv ) ); - Scale_sig( hq_generic_fenv_fx, add( DIM_FB, nenv ), negate( sf ) ); - Copy_Scale_sig( EnvCdbkFB_fx, EnvCdbkFB_fx_loc, N_CB_FB * DIM_FB, negate( sf ) ); - // Scaling done to handel overflow inside vqSimple_w_fx +#ifdef HARM_HQ_CORE2 + 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 ) ); + Copy_Scale_sig( EnvCdbkFB_fx, EnvCdbkFB_fx_loc, N_CB_FB * DIM_FB, negate( sf ) ); + // Scaling done to handel overflow inside vqSimple_w_fx - indice[5] = vqSimple_w_fx( hq_generic_fenv_fx + nenv, hq_generic_fenv_fx + nenv, EnvCdbkFB_fx_loc, NULL, DIM_FB, N_CB_FB, 0 ); - move16(); + indice[5] = vqSimple_w_fx( hq_generic_fenv_fx + nenv, hq_generic_fenv_fx + nenv, EnvCdbkFB_fx_loc, NULL, DIM_FB, N_CB_FB, 0 ); + move16(); - Scale_sig( hq_generic_fenv_fx, add( DIM_FB, nenv ), sf ); + Scale_sig( hq_generic_fenv_fx, add( DIM_FB, nenv ), sf ); + } } push_indice( hBstr, IND_SWB_FENV_HQ, indice[0], 5 ); -- GitLab From c8e34f38c350dcd9b123aaa1cdb4a01645ac61c9 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 08:32:21 +0100 Subject: [PATCH 14/31] HARM_HQ_CORE2 --- lib_com/options.h | 2 +- lib_com/prot_fx.h | 2 +- lib_dec/FEC_HQ_phase_ecu_fx.c | 4 +--- lib_dec/hq_hr_dec_fx.c | 11 ++++++++--- lib_enc/hq_hr_enc_fx.c | 25 +++++++++++++++++-------- lib_enc/hq_lr_enc_fx.c | 4 ++-- lib_enc/prot_fx_enc.h | 2 -- lib_enc/pvq_core_enc_fx.c | 9 ++++----- lib_enc/swb_bwe_enc_fx.c | 6 +++--- 9 files changed, 37 insertions(+), 28 deletions(-) diff --git a/lib_com/options.h b/lib_com/options.h index 56e96b95f..b85e1418d 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -97,7 +97,7 @@ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define HARM_HQ_CORE /* harmonize HQ core functions */ -#define HARM_HQ_CORE2 +#define HARM_HQ_CORE_EVS_TO_BE_CHECKED // hack to keep EVS BE /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 84516152c..c84620e05 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -10130,7 +10130,7 @@ void IGFEncConcatenateBitstream( ); void hq_generic_hf_encoding_fx( -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ #endif const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 69f60e686..5e55ccfcb 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -5031,13 +5031,11 @@ void ivas_hq_ecu_fx( test(); test(); test(); - evs_mode_selection = ( GE_32( st_fx->total_brate, 48000 ) && ( GE_16( output_frame, L_FRAME16k ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) && ( ph_ecu_HqVoicing || ( ( ( GT_16( hHQ_core->env_stab_plc_fx, 16384 ) /* 0.5 in Q15 */ ) && ( LT_16( corr, 19661 ) /* 0.6 in Q15 */ ) ) || ( LT_16( hHQ_core->env_stab_plc_fx, 16384 ) /* 0.5 in Q15 */ && ( GT_16( corr, 27853 ) /* 0.85 in Q15 */ ) ) ) ) ) ) || ( LT_32( st_fx->total_brate, 48000 ) && ( ( ph_ecu_HqVoicing || GT_16( corr, 27853 ) /* 0.85 in Q15 */ ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) ) ); -#ifdef HARM_HQ_CORE - // temp. hack to keep EVS BE +#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED IF( st_fx->element_mode == EVS_MONO ) { evs_mode_selection = ( 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 ) ) ) ) ) ) ) || diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 4c043c288..4848d8b43 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -505,14 +505,19 @@ void hq_hr_dec_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED Word16 tmp_length = length; if ( length == 960 ) { - tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE + tmp_length = L_SPEC48k; } hq_configure_fx( tmp_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 + 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 #else 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 ); @@ -691,11 +696,11 @@ void hq_hr_dec_fx( IF( EQ_16( *is_transient, 1 ) ) { -#ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED tmp_length = length; if ( length == 960 ) { - tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE + tmp_length = L_SPEC48k; } de_interleave_spectrum_fx( t_audio_q, tmp_length ); diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index efe376ea7..d017ccd4f 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -102,14 +102,19 @@ void hq_hr_enc_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED Word16 tmp_length = length; if ( length == 960 ) { - tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE + tmp_length = L_SPEC48k; } hq_configure_fx( tmp_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 + 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 #else 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 ); @@ -122,11 +127,11 @@ void hq_hr_enc_fx( /* Interleave MLT coefficients of 4 sub-vectors in case of transient */ IF( EQ_16( is_transient, 1 ) ) { -#ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED tmp_length = length; if ( length == 960 ) { - tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE + tmp_length = L_SPEC48k; } interleave_spectrum_fx( t_audio, tmp_length ); @@ -168,14 +173,18 @@ void hq_hr_enc_fx( test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED tmp_length = length; if ( st_fx->bwidth == FB ) { - tmp_length = L_SPEC48k; // this is temp. hack to keep EVS BE + tmp_length = L_SPEC48k; } hq_generic_hf_encoding_fx( st_fx->element_mode, t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas, tmp_length ); +#else + hq_generic_hf_encoding_fx( st_fx->element_mode, t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas, length ); +#endif #else hq_generic_encoding_fx( t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas /*, length*/ ); #endif @@ -426,7 +435,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_CORE2 +#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 ); @@ -546,10 +555,10 @@ void hq_hr_enc_ivas_fx( move16(); /* Prepare synthesis for LB generation in case of switch to ACELP */ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( st->element_mode > EVS_MONO ) #endif - { + { IF( NE_16( hqswb_clas, HQ_HVQ ) ) { apply_envelope_enc_ivas_fx( t_audio_q_norm, ynrm, num_sfm, sfm_start, sfm_end, t_audio_q_fx ); diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 0b5044598..2f16ba019 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -206,8 +206,8 @@ void hq_lr_enc_fx( } ELSE { -#ifdef HARM_HQ_CORE - hqswb_clas_fx = peak_avrg_ratio_fx( HQ_BWE_CROSSOVER_BRATE /* st_fx->total_brate - temp. hack to keep EVS BE*/, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ +#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED + hqswb_clas_fx = peak_avrg_ratio_fx( HQ_BWE_CROSSOVER_BRATE /* temp. hack to keep EVS BE */, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ #else hqswb_clas_fx = peak_avrg_ratio_fx( st_fx->total_brate, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ #endif diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 933b9d67f..8ff9cdccb 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3716,8 +3716,6 @@ Word16 encode_envelope_indices_ivas_fx( const Word16 flag_HQ2, /* i : indicator of HQ2 core Q0 */ const Word16 is_transient /* i : indicator of HQ_TRANSIENT Q0 */ ); -#endif -#ifndef HARM_HQ_CORE2 void hq_generic_encoding_fx( const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 80be8df84..85185aa3f 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -812,7 +812,6 @@ static void encode_energies_fx( densityAngle2RmsProjEnc_fx( density, phi, &index_phi, &ir, &il, &oppRQ3 ); densityIndexSymbolEncode_fx( hBstr, hPVQ, density, r_dim, l_dim, index_phi ); - l_gain = il; /* Q15 */ move16(); r_gain = ir; /* Q15 */ @@ -832,8 +831,7 @@ static void encode_energies_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 ) ) { @@ -1160,13 +1158,13 @@ static void densityIndexSymbolEncode_fx( *--------------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE -/* o : Number of segments */ +/* 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 */ + 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 */ @@ -1265,6 +1263,7 @@ static Word16 calc_pvq_splits_ivas_fx( /* o : Number of segments */ 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; } #ifndef HARM_HQ_CORE diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index b88e5745d..4d245c9c2 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -4267,7 +4267,7 @@ static Word16 decision_hq_generic_class_fx_32( } } -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE /*-------------------------------------------------------------------* * hq_generic_encoding_fx() * @@ -4542,7 +4542,7 @@ void fd_bwe_enc_init_fx( *-------------------------------------------------------------------*/ void hq_generic_hf_encoding_fx( -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ #endif const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ @@ -4707,7 +4707,7 @@ void hq_generic_hf_encoding_fx( IF( EQ_16( length, L_SPEC48k ) ) { -#ifdef HARM_HQ_CORE2 +#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 ); -- GitLab From 0cb7ff36aabb25f447e7f2fea99ebee41f1283e0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 08:46:15 +0100 Subject: [PATCH 15/31] formal improvements --- lib_com/low_rate_band_att_fx.c | 6 ++++-- lib_com/options.h | 2 +- lib_dec/FEC_HQ_phase_ecu_fx.c | 2 +- lib_dec/hq_hr_dec_fx.c | 12 ++++++++---- lib_enc/hq_hr_enc_fx.c | 18 ++++++++++++------ lib_enc/hq_lr_enc_fx.c | 4 ++-- lib_enc/pvq_core_enc_fx.c | 2 +- 7 files changed, 29 insertions(+), 17 deletions(-) diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index b2c138207..7710c5958 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -96,18 +96,20 @@ void ivas_fine_gain_pred_fx( tmp1 = fine_gain_pred_sqrt_bw[bw_idx]; } ELSE -#endif { +#endif Word16 norm = norm_s( bw ); #ifdef HARM_HQ_CORE Word16 tmp_exp = sub( 15, norm ); #else - Word16 tmp1, tmp_exp = sub( 15, norm ); + Word16 tmp1, tmp_exp = sub( 15, norm ); #endif tmp1 = Sqrt16( shl( bw, norm ), &tmp_exp ); tmp1 = shr( tmp1, sub( sub( 15, tmp_exp ), Q11 ) ); Mpy_32_16_ss( L_tmp, tmp1, &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ +#ifdef HARM_HQ_CORE } +#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(); diff --git a/lib_com/options.h b/lib_com/options.h index b85e1418d..35a8fe0ca 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -97,7 +97,7 @@ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define HARM_HQ_CORE /* harmonize HQ core functions */ -#define HARM_HQ_CORE_EVS_TO_BE_CHECKED // hack to keep EVS BE +#define HARM_HQ_CORE_KEEP_EVS_BE // hack to keep EVS BE /* #################### End BE switches ################################## */ diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 5e55ccfcb..fa5709638 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -5035,7 +5035,7 @@ void ivas_hq_ecu_fx( ( ph_ecu_HqVoicing || ( ( ( GT_16( hHQ_core->env_stab_plc_fx, 16384 ) /* 0.5 in Q15 */ ) && ( LT_16( corr, 19661 ) /* 0.6 in Q15 */ ) ) || ( LT_16( hHQ_core->env_stab_plc_fx, 16384 ) /* 0.5 in Q15 */ && ( GT_16( corr, 27853 ) /* 0.85 in Q15 */ ) ) ) ) ) ) || ( LT_32( st_fx->total_brate, 48000 ) && ( ( ph_ecu_HqVoicing || GT_16( corr, 27853 ) /* 0.85 in Q15 */ ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) ) ); -#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED +#ifdef HARM_HQ_CORE_KEEP_EVS_BE IF( st_fx->element_mode == EVS_MONO ) { evs_mode_selection = ( 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 ) ) ) ) ) ) ) || diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 4848d8b43..a7d496288 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -505,11 +505,13 @@ void hq_hr_dec_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED +#ifdef HARM_HQ_CORE_KEEP_EVS_BE Word16 tmp_length = length; - if ( length == 960 ) + move16(); + if ( EQ_16( length, L_FRAME48k ) ) { tmp_length = L_SPEC48k; + move16(); } hq_configure_fx( tmp_length, *hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, @@ -696,11 +698,13 @@ void hq_hr_dec_fx( IF( EQ_16( *is_transient, 1 ) ) { -#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED +#ifdef HARM_HQ_CORE_KEEP_EVS_BE tmp_length = length; - if ( length == 960 ) + move16(); + if ( EQ_16( length, L_FRAME48k ) ) { tmp_length = L_SPEC48k; + move16(); } de_interleave_spectrum_fx( t_audio_q, tmp_length ); diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index d017ccd4f..cb086fd2b 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -102,11 +102,13 @@ void hq_hr_enc_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED +#ifdef HARM_HQ_CORE_KEEP_EVS_BE Word16 tmp_length = length; - if ( length == 960 ) + move16(); + if ( EQ_16( length, L_FRAME48k ) ) { tmp_length = L_SPEC48k; + move16(); } hq_configure_fx( tmp_length, hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, @@ -127,11 +129,13 @@ void hq_hr_enc_fx( /* Interleave MLT coefficients of 4 sub-vectors in case of transient */ IF( EQ_16( is_transient, 1 ) ) { -#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED +#ifdef HARM_HQ_CORE_KEEP_EVS_BE tmp_length = length; - if ( length == 960 ) + move16(); + if ( EQ_16( length, L_FRAME48k ) ) { tmp_length = L_SPEC48k; + move16(); } interleave_spectrum_fx( t_audio, tmp_length ); @@ -174,11 +178,13 @@ void hq_hr_enc_fx( IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED +#ifdef HARM_HQ_CORE_KEEP_EVS_BE tmp_length = length; - if ( st_fx->bwidth == FB ) + move16(); + if ( EQ_16( length, L_FRAME48k ) ) { tmp_length = L_SPEC48k; + move16(); } hq_generic_hf_encoding_fx( st_fx->element_mode, t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas, tmp_length ); diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 2f16ba019..730e277dd 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -206,8 +206,8 @@ void hq_lr_enc_fx( } ELSE { -#ifdef HARM_HQ_CORE_EVS_TO_BE_CHECKED - hqswb_clas_fx = peak_avrg_ratio_fx( HQ_BWE_CROSSOVER_BRATE /* temp. hack to keep EVS BE */, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ +#ifdef HARM_HQ_CORE_KEEP_EVS_BE + hqswb_clas_fx = peak_avrg_ratio_fx( HQ_BWE_CROSSOVER_BRATE, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ #else hqswb_clas_fx = peak_avrg_ratio_fx( st_fx->total_brate, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ #endif diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index 85185aa3f..ea4013789 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -831,7 +831,7 @@ static void encode_energies_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 ) ) { -- GitLab From 9ee14699b1e06d1b45da4e5a5debd4e5d1ae4968 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 11:09:58 +0100 Subject: [PATCH 16/31] fix --- lib_com/fine_gain_bits_fx.c | 37 ++++++++++++++++++++++------- lib_com/hq_tools_fx.c | 4 ---- lib_com/ivas_prot_fx.h | 9 +++---- lib_com/prot_fx.h | 8 ++++--- lib_dec/FEC_HQ_phase_ecu_fx.c | 23 +++++++++++------- lib_dec/pvq_core_dec_fx.c | 7 +----- lib_enc/prot_fx_enc.h | 6 ++--- lib_enc/pvq_core_enc_fx.c | 44 ++++------------------------------- 8 files changed, 59 insertions(+), 79 deletions(-) diff --git a/lib_com/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index 172e51833..f0327907c 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -16,6 +16,9 @@ *--------------------------------------------------------------------------*/ 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 */ @@ -31,7 +34,17 @@ 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. */ - bps = extract_l( L_shr( L_mult0( Rk[i], inv_tbl_fx[sfmsize[i]] ), 18 ) ); /* 3+15 */ +#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 */ + } + if ( EQ_32( L_shl( L_mult0( sfmsize[i], add( bps, 1 ) ), 3 ), Rk[i] ) ) { bps = add( bps, 1 ); @@ -61,13 +74,17 @@ static void subband_gain_bits_fx( * Assign gain adjustment bits and update bit budget *--------------------------------------------------------------------------*/ -Word16 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 */ +/* 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 */ + 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; @@ -76,7 +93,11 @@ Word16 assign_gain_bits_fx( /* o : Number of assigned /* 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 { diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 44317785f..0874f8391 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -2129,11 +2129,7 @@ void hq_bwe_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( EVS_MONO, 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_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/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f60352128..9d240345b 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1749,14 +1749,12 @@ void ivas_fill_spectrum_fx( const Word16 num_env_bands, const Word16 element_mode ); -#endif -#ifndef HARM_HQ_CORE + void ivas_de_interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ ); -#endif -#ifndef HARM_HQ_CORE + void ivas_harm_bwe_fx( const Word16 *coeff_fine, /* i : fine structure for BWE */ const Word16 *coeff, /* i : coded/noisefilled normalized spectrum */ @@ -1773,8 +1771,7 @@ void ivas_harm_bwe_fx( Word32 *coeff_out, /* o : coded/noisefilled spectrum */ const Word16 element_mode /* i : IVAS element mode */ ); -#endif -#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 */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index c84620e05..6395304e1 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -688,8 +688,7 @@ Word16 calc_nor_delta_hf_ivas_fx( const Word16 *sfm_start, /* i : Start index of bands */ const Word16 core_sfm /* i : index of the end band for core */ ); -#endif -#ifndef HARM_HQ_CORE + void hq_bwe_fx( const Word16 HQ_mode, /* i : HQ mode */ Word32 *coeff_out1, /* i/o: BWE i & temporary buffer */ @@ -4710,8 +4709,11 @@ void fine_gain_dec_fx( Word16 *fg_pred /* i/o: Predicted gains / Corrected gains Q12*/ ); -/* o : Number of assigned gain bits */ +/* 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 */ diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index fa5709638..beeae550d 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -1827,11 +1827,7 @@ static void spec_ana_fx( sel = mult_r( sub( Xmax, Xmin ), CMPLMNT_PFIND_SENS_FX ); } -#ifdef HARM_HQ_CORE - peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel, TRUE ); -#else peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel ); -#endif { /* Refine peaks */ @@ -3063,11 +3059,7 @@ static void rec_frame_fx( } Scale_sig( X, Lprot, -Q ); -#ifdef HARM_HQ_CORE - rec_wtda_fx( X, ecu_rec, output_frame, Lprot, fs, EVS_MONO, NULL, NULL ); -#else rec_wtda_fx( X, ecu_rec, output_frame, Lprot, fs ); -#endif return; } @@ -5038,6 +5030,21 @@ void ivas_hq_ecu_fx( #ifdef HARM_HQ_CORE_KEEP_EVS_BE IF( st_fx->element_mode == EVS_MONO ) { + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); evs_mode_selection = ( 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] ) ) ); } diff --git a/lib_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 740e3be4a..ebc7b8905 100644 --- a/lib_dec/pvq_core_dec_fx.c +++ b/lib_dec/pvq_core_dec_fx.c @@ -250,7 +250,7 @@ Word16 ivas_pvq_core_dec_fx( R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 #ifdef HARM_HQ_CORE - assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); + 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 @@ -372,13 +372,8 @@ Word16 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 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 ) diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 8ff9cdccb..5ba320ed4 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -858,8 +858,7 @@ Word16 peak_avrg_ratio_ivas_fx( Word16 *mode_count, /* i/o: HQ_HARMONIC mode count Q0*/ Word16 *mode_count1, /* i/o: HQ_NORMAL mode count Q0*/ Word16 Q_coeff ); -#endif -#ifndef HARM_HQ_CORE + void hvq_classifier_ivas_fx( const Word32 *input, /* i : input signal Q12 */ Word16 *prev_Npeaks, /* i/o: Peak number memory Q0 */ @@ -3766,8 +3765,7 @@ Word16 hvq_enc_ivas_fx( const Word32 *coefs, /* i : spectrum coefficients in Q12 */ Word32 *coefs_out /* o : encoded spectrum coefficients in Q12 */ ); -#endif -#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 */ diff --git a/lib_enc/pvq_core_enc_fx.c b/lib_enc/pvq_core_enc_fx.c index ea4013789..c75798e5d 100644 --- a/lib_enc/pvq_core_enc_fx.c +++ b/lib_enc/pvq_core_enc_fx.c @@ -70,11 +70,7 @@ static void pvq_encode_band_ivas_fx( Word16 tmp; Word32 L_coefs_quant_fx[PVQ_MAX_BAND_SIZE]; -#ifdef HARM_HQ_CORE - Np = calc_pvq_splits_fx( hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit ); -#else Np = calc_pvq_splits_ivas_fx( hBstr, hPVQ, band_bits, sfmsize, coefs_norm, Q_coefs, &split_bit ); -#endif band_bits_tot = sub( band_bits, split_bit ); enr = L_deposit_l( 0 ); @@ -106,11 +102,7 @@ static void pvq_encode_band_ivas_fx( set16_fx( g_part_neg, -32768, Np ); /* -1.0 in Q15 */ IF( GT_16( Np, 1 ) ) { -#ifdef HARM_HQ_CORE - encode_energies_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 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 ); -#endif } ELSE { @@ -141,13 +133,8 @@ static void pvq_encode_band_ivas_fx( IF( K_val > 0 ) { -#ifdef HARM_HQ_CORE - pvq_encode_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 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] ); -#endif } ELSE { @@ -483,11 +470,7 @@ void pvq_encode_frame_fx( xy_corr = L_deposit_l( 0 ); yy_corr = L_deposit_l( 1 ); -#ifdef HARM_HQ_CORE - shift = ivas_band_len_ener_shift[ivas_band_len_idx[shr( sfmsize[is], 3 )]]; -#else shift = band_len_ener_shift[band_len_idx[sfmsize[is] >> 3]]; -#endif move16(); FOR( j = 0; j < sfmsize[i]; j++ ) { @@ -567,7 +550,7 @@ Word16 pvq_core_enc_ivas_fx( R_upd = shl( bits_tot, 3 ); #ifdef HARM_HQ_CORE - gain_bits_tot = assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); + 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 @@ -576,16 +559,7 @@ Word16 pvq_core_enc_ivas_fx( #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 -#ifdef HARM_HQ_CORE - IF( element_mode == EVS_MONO ) - { - 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 -#endif - { - 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 ); - } + 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 ) @@ -618,18 +592,8 @@ Word16 pvq_core_enc_ivas_fx( 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 -#ifdef HARM_HQ_CORE - IF( element_mode == EVS_MONO ) - { - fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, - coefs_quant, pulse_vector, fg_pred, core ); - } - ELSE -#endif - { - ivas_fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, - coefs_quant, pulse_vector, fg_pred, core ); - } + 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 ); -- GitLab From 41a1c182f1d343f2795b3c84f34d7e517c96fe0a Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 12:01:27 +0100 Subject: [PATCH 17/31] fix --- lib_com/fine_gain_bits_fx.c | 2 +- lib_com/ivas_prot_fx.h | 3 +- lib_com/options.h | 1 + lib_com/rom_com_fx.c | 1 - lib_dec/hq_core_dec_fx.c | 4 ++ lib_dec/hq_hr_dec_fx.c | 60 ++++++++++++++++++++++++++++-- lib_dec/peak_vq_dec_fx.c | 54 +++++++++++++++++---------- lib_enc/hq_core_enc_fx.c | 4 ++ lib_enc/hq_hr_enc_fx.c | 74 +++++++++++++++++++++++++++++++++++-- lib_enc/peak_vq_enc_fx.c | 6 +++ lib_enc/prot_fx_enc.h | 2 + 11 files changed, 181 insertions(+), 30 deletions(-) diff --git a/lib_com/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index f0327907c..d982b94e2 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -77,7 +77,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 */ + const Word16 element_mode, /* i : element mode */ #endif const Word16 core, /* i : HQ core */ const Word16 BANDS, /* i : Number of bands */ diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 9d240345b..fcd846c3a 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1599,6 +1599,7 @@ Word16 ivas_hq_classifier_dec_fx( Word16 *hqswb_clas /* o : HQ class Q0 */ ); +#ifndef HARM_HQ_CORE2 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 */ @@ -1610,7 +1611,7 @@ void ivas_hq_hr_dec_fx( Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ const Word16 core_switching_flag /* i : Core switching flag */ ); - +#endif #ifndef HARM_HQ_CORE void ivas_hq_configure_fx( const Word16 length, /* i : Frame length Q0 */ diff --git a/lib_com/options.h b/lib_com/options.h index 2598f9f31..28ad2aae9 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,6 +98,7 @@ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define HARM_HQ_CORE /* harmonize HQ core functions */ #define HARM_HQ_CORE_KEEP_EVS_BE // hack to keep EVS BE +//#define HARM_HQ_CORE2 /* #################### End BE switches ################################## */ diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index ef143324c..8202ccdb5 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -17099,7 +17099,6 @@ const Word16 fg_inv_tbl_fx [HQ_MAX_BAND_LEN/8 + 1 ] = 586, 512, 456, 410, 373, 342 }; - const UWord32 exactdivodd[ODD_DIV_SIZE] = { /* exactdivodd[0]=1/1, exactdivodd[1]=1/3, exactdivodd[n]=1/(2*n+1), exactdivodd[47]=1/95 ) */ diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 1127dd5ce..5dfe1f20f 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -693,7 +693,11 @@ void ivas_hq_core_dec_fx( ELSE { /* HQ high rate decoder */ +#ifdef HARM_HQ_CORE2 + 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 ); +#endif Q_audio = 12; move16(); Q_G_audio = Q_audio; diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index a7d496288..06d8a6757 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -135,7 +135,11 @@ void hq_pred_hb_bws_fx( * HQ High rate decoding routine *--------------------------------------------------------------------------*/ +#ifdef HARM_HQ_CORE2 +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 */ @@ -203,16 +207,39 @@ void ivas_hq_hr_dec_fx( * Decode classification *------------------------------------------------------------------*/ - bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ - bits_left = sub( num_bits, bits ); /* Q0 */ +#ifdef HARM_HQ_CORE2 + IF( st_fx->element_mode == EVS_MONO ) + { + bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); + } + ELSE +#endif + { + bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ + } + bits_left = sub( num_bits, bits ); /* Q0 */ /*------------------------------------------------------------------* * set quantization parameters *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_KEEP_EVS_BE + Word16 tmp_length = length; + move16(); + test(); + if ( st_fx->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) + { + tmp_length = L_SPEC48k; + move16(); + } + + hq_configure_fx( tmp_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 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 #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 ); @@ -300,8 +327,18 @@ void ivas_hq_hr_dec_fx( * Bit allocation *------------------------------------------------------------------*/ - 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 ); +#ifdef HARM_HQ_CORE2 + IF( st_fx->element_mode == EVS_MONO ) + { + 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 +#endif + { + 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 ); + } test(); test(); @@ -406,7 +443,20 @@ void ivas_hq_hr_dec_fx( IF( EQ_16( *is_transient, 1 ) ) { #ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_KEEP_EVS_BE + tmp_length = length; + move16(); + test(); + if ( st_fx->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) + { + tmp_length = L_SPEC48k; + move16(); + } + + de_interleave_spectrum_fx( t_audio_q, tmp_length ); +#else de_interleave_spectrum_fx( t_audio_q, length ); +#endif #else ivas_de_interleave_spectrum_fx( t_audio_q, length ); #endif @@ -428,6 +478,7 @@ void ivas_hq_hr_dec_fx( return; } +#ifndef HARM_HQ_CORE2 void hq_hr_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ @@ -725,3 +776,4 @@ void hq_hr_dec_fx( return; } +#endif diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index 8e539eba8..122e97e6c 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -6,17 +6,25 @@ #include "options.h" /* Compilation switches */ #include "prot_fx.h" #include "rom_com.h" -#include "enh64.h" + + +/*------------------------------------------------------------------------* + * Local constants + *------------------------------------------------------------------------*/ #define PK_VQ_NOISE_DELTA ( (Word16) 3277 ) /* 0.1 in Q15 */ + /*------------------------------------------------------------------------* * Local function prototypes *------------------------------------------------------------------------*/ + static void dequant_peaks_fx( Decoder_State *st_fx, Word32 *vect_out, const Word32 *peak_gain ); static Word16 hvq_dec_pos_fx( Decoder_State *st_fx, Word16 *pos_vec, const Word16 length, const Word16 num_peaks ); static Word16 sparse_dec_pos_fx( Decoder_State *st_fx, Word16 *out, const Word16 length ); static void peak_vq_dec_fx( Decoder_State *st_fx, Word32 *coefs_out, const Word32 brate, const Word16 num_bits, const Word16 *ynrm, Word16 *R, Word16 *vq_peak_idx, Word16 *Npeaks, const Word16 core ); + + /*-------------------------------------------------------------------------- * hvq_dec_fx() * @@ -24,16 +32,16 @@ static void peak_vq_dec_fx( Decoder_State *st_fx, Word32 *coefs_out, const Word3 *--------------------------------------------------------------------------*/ void hvq_dec_fx( - Decoder_State *st_fx, /* i/o: decoder state structure */ - const Word16 num_bits, /* i : Number of available bits */ - const Word32 core_brate, /* i : Core bit-rate */ - const Word16 *ynrm, /* i : Envelope coefficients Q0 */ - Word16 *R, /* i/o: Bit allocation/updated bit allocation */ - Word16 *noise_level, /* o : Noise level in Q15 */ - Word16 *peak_idx, /* o : Peak position vector */ - Word16 *Npeaks, /* o : Total number of peaks */ - Word32 *coefsq_norm, /* o : Output vector in Q12 */ - const Word16 core /* i : Core */ + Decoder_State *st_fx, /* i/o: decoder state structure */ + const Word16 num_bits, /* i : Number of available bits */ + const Word32 core_brate, /* i : Core bit-rate */ + const Word16 *ynrm, /* i : Envelope coefficients Q0 */ + Word16 *R, /* i/o: Bit allocation/updated bit allocation */ + Word16 *noise_level, /* o : Noise level in Q15 */ + Word16 *peak_idx, /* o : Peak position vector */ + Word16 *Npeaks, /* o : Total number of peaks */ + Word32 *coefsq_norm, /* o : Output vector in Q12 */ + const Word16 core /* i : Core */ ) { Word16 i; @@ -52,10 +60,12 @@ void hvq_dec_fx( bits = sub( bits, 2 ); } - peak_vq_dec_fx( st_fx, coefsq_norm, core_brate, bits, ynrm, R, peak_idx, - Npeaks, core ); + peak_vq_dec_fx( st_fx, coefsq_norm, core_brate, bits, ynrm, R, peak_idx, Npeaks, core ); + + return; } + /*-------------------------------------------------------------------------- * peak_vq_dec() * @@ -288,8 +298,7 @@ static void peak_vq_dec_fx( pvq_bits = sub( num_bits, diff ); /* Calculate number of PVQ bands to code and assign bits */ - pvq_bands = hvq_pvq_bitalloc_fx( pvq_bits, core_brate, st_fx->bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, - &n_sel_bnds ); + pvq_bands = hvq_pvq_bitalloc_fx( pvq_bits, core_brate, st_fx->bwidth, ynrm, manE_peak, expE_peak, Rk, R, sel_bnds, &n_sel_bnds ); /* safety check in case of bit errors */ test(); @@ -300,9 +309,9 @@ static void peak_vq_dec_fx( } pvq_bits = sub( pvq_bits, i_mult2( HVQ_PVQ_GAIN_BITS, pvq_bands ) ); + /* 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 ); + hvq_concat_bands_fx( pvq_bands, sel_bnds, n_sel_bnds, hvq_band_start, hvq_band_width, hvq_band_end ); FOR( k = 0; k < pvq_bands; k++ ) { @@ -313,8 +322,13 @@ 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_EVS_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 ); +#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, 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 ); @@ -460,9 +474,9 @@ static void dequant_peaks_fx( static Word16 hvq_dec_pos_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ - Word16 *pos_vec, /* o : decoded peak positions */ - const Word16 length, /* i : length */ - const Word16 num_peaks /* i : number of peaks */ + Word16 *pos_vec, /* o : decoded peak positions */ + const Word16 length, /* i : length */ + const Word16 num_peaks /* i : number of peaks */ ) { Word16 peak_idx[HVQ_MAX_PEAKS]; diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 6c4aa6bf4..2722ac054 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -510,7 +510,11 @@ void hq_core_enc_ivas_fx( ELSE { /* HQ high rate encoder */ +#ifdef HARM_HQ_CORE2 + 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 */ diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index cb086fd2b..de3470d34 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -18,6 +18,7 @@ *--------------------------------------------------------------------------*/ void hq_hr_enc_fx( +#ifndef HARM_HQ_CORE2 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 */ @@ -311,6 +312,7 @@ void hq_hr_enc_fx( } 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*/ @@ -375,7 +377,16 @@ void hq_hr_enc_ivas_fx( * Classification *------------------------------------------------------------------*/ - bits = hq_classifier_enc_ivas_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ +#ifdef HARM_HQ_CORE2 + IF( st->element_mode == EVS_MONO ) + { + bits = hq_classifier_enc_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ + } + ELSE +#endif + { + bits = hq_classifier_enc_ivas_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ + } *num_bits = sub( *num_bits, bits ); move16(); @@ -383,7 +394,20 @@ void hq_hr_enc_ivas_fx( * Set quantization parameters *------------------------------------------------------------------*/ +#ifdef HARM_HQ_CORE_KEEP_EVS_BE + Word16 tmp_length = length; + move16(); + test(); + if ( st->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) + { + tmp_length = L_SPEC48k; + move16(); + } + + hq_configure_fx( tmp_length, hqswb_clas, st->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); +#else hq_configure_fx( length, hqswb_clas, st->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); +#endif /*------------------------------------------------------------------* * Transient frame handling @@ -393,7 +417,20 @@ void hq_hr_enc_ivas_fx( IF( is_transient ) { #ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_KEEP_EVS_BE + tmp_length = length; + move16(); + test(); + if ( st->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) + { + tmp_length = L_SPEC48k; + move16(); + } + + interleave_spectrum_fx( t_audio_fx, tmp_length ); +#else interleave_spectrum_fx( t_audio_fx, length ); +#endif #else interleave_spectrum_ivas_fx( t_audio_fx, length ); #endif @@ -412,7 +449,16 @@ void hq_hr_enc_ivas_fx( *------------------------------------------------------------------*/ /* calculate and quantize norms */ - calc_norm_ivas_fx( t_audio_fx, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); +#ifdef HARM_HQ_CORE2 + 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 ); + } /* create differential code of quantized norm indices */ diff_envelope_coding_fx( is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx ); @@ -442,7 +488,20 @@ void hq_hr_enc_ivas_fx( IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { #ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_KEEP_EVS_BE + tmp_length = length; + move16(); + test(); + if ( st->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) + { + tmp_length = L_SPEC48k; + move16(); + } + + hq_generic_hf_encoding_fx( st->element_mode, t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, tmp_length ); +#else hq_generic_hf_encoding_fx( st->element_mode, t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, length ); +#endif #else hq_generic_hf_encoding_fx( t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, length ); #endif @@ -460,7 +519,16 @@ void hq_hr_enc_ivas_fx( * Bit allocation *------------------------------------------------------------------*/ - 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 ); +#ifdef HARM_HQ_CORE2 + IF( st->element_mode == EVS_MONO ) + { + 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 +#endif + { + 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 ); + } /*------------------------------------------------------------------* * Normalize coefficients with quantized norms diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index b7d9a7402..f5ee73977 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -406,8 +406,14 @@ Word16 peak_vq_enc_ivas_fx( } #ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_KEEP_EVS_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, + pvq_inp_vector, fg_pred, EVS_MONO, HQ_CORE ); +#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, 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 ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 5ba320ed4..4e07606ec 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3637,6 +3637,7 @@ void hq_lr_enc_fx( ); void hq_hr_enc_fx( +#ifndef HARM_HQ_CORE2 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 */ @@ -3646,6 +3647,7 @@ void hq_hr_enc_fx( ); 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 */ -- GitLab From 04d20b458e2ce3d49425eaa50c93d482189f1944 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 14:47:44 +0100 Subject: [PATCH 18/31] fix --- lib_com/low_rate_band_att_fx.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 7710c5958..7a5a4d883 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -106,7 +106,6 @@ void ivas_fine_gain_pred_fx( #endif tmp1 = Sqrt16( shl( bw, norm ), &tmp_exp ); tmp1 = shr( tmp1, sub( sub( 15, tmp_exp ), Q11 ) ); - Mpy_32_16_ss( L_tmp, tmp1, &L_tmp, &lsb ); /*31-exp+11-15=27-exp */ #ifdef HARM_HQ_CORE } #endif -- GitLab From 376de564dad6422fa2db9c19be162d889ac41810 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 15:02:31 +0100 Subject: [PATCH 19/31] formal improvements --- lib_com/hq_tools_fx.c | 2 +- lib_com/logqnorm_fx.c | 11 ++++++++--- lib_enc/hq_hr_enc_fx.c | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib_com/hq_tools_fx.c b/lib_com/hq_tools_fx.c index 0874f8391..c93c6a20e 100644 --- a/lib_com/hq_tools_fx.c +++ b/lib_com/hq_tools_fx.c @@ -2024,7 +2024,7 @@ Word16 calc_nor_delta_hf_fx( max_delta = -100; move16(); - calc_norm_fx( t_audio, 12, ynrm_t, normqlg2_t, 0, nb_sfm, sfmsize, sfm_start ); + calc_norm_fx( t_audio, Q12, ynrm_t, normqlg2_t, 0, nb_sfm, sfmsize, sfm_start ); add_bits_denv = 0; move16(); FOR( i = num_env_bands; i < nb_sfm; ++i ) diff --git a/lib_com/logqnorm_fx.c b/lib_com/logqnorm_fx.c index 4b096ac35..20e76f497 100644 --- a/lib_com/logqnorm_fx.c +++ b/lib_com/logqnorm_fx.c @@ -47,6 +47,7 @@ * * Log quantization for norms of sub-vectors *--------------------------------------------------------------------------*/ + void logqnorm_ivas_fx( const Word32 *x_fx, /* i : coefficient vector Qq*/ const Word16 q, /* i : q of coefficient vector */ @@ -129,8 +130,11 @@ void logqnorm_ivas_fx( *k_fx = j2; move16(); } + return; } + + void logqnorm_fx( const Word32 *L_x, /* i : coefficient vector Qx */ const Word16 qx, /* i : Q value of input */ @@ -276,10 +280,11 @@ void logqnorm_2_fx( * * Calculate the norms for the spectral envelope *--------------------------------------------------------------------------*/ + void calc_norm_ivas_fx( - const Word32 *x_fx, /* i : Input vector.(Qin) */ - Word16 *norm, /* o : Quantization indices for norms Q0 */ - Word16 *normlg, /* o : Quantized norms in log2 Q0 */ + const Word32 *x_fx, /* i : Input vector.(Qin) */ + Word16 *norm, /* o : Quantization indices for norms Q0 */ + Word16 *normlg, /* o : Quantized norms in log2 Q0 */ const Word16 start_band, /* i : Indice of band to start coding */ const Word16 num_bands, /* i : Number of bands */ const Word16 *band_len, /* i : Length of bands */ diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index de3470d34..c4f1d70d2 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -158,7 +158,7 @@ void hq_hr_enc_fx( *------------------------------------------------------------------*/ /* calculate and quantize norms */ - calc_norm_fx( t_audio, 12, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); + 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 ); -- GitLab From 13b77d96d073756eddb6df435197ee72b181d2d7 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 17:52:04 +0100 Subject: [PATCH 20/31] HARM_HQ_CORE2 --- lib_com/ivas_prot_fx.h | 3 +- lib_com/options.h | 2 +- lib_com/prot_fx.h | 22 +++-- lib_dec/evs_dec_fx.c | 4 + lib_dec/hq_core_dec_fx.c | 167 ++++++++++++++++++++++++++++++++----- lib_dec/ivas_core_dec_fx.c | 4 + lib_enc/hq_core_enc_fx.c | 123 ++++++++++++++++++++------- lib_enc/hvq_enc_fx.c | 24 +++++- lib_enc/ivas_core_enc_fx.c | 4 + lib_enc/peak_vq_enc_fx.c | 58 ++++++++++--- lib_enc/prot_fx_enc.h | 6 +- 11 files changed, 345 insertions(+), 72 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index fcd846c3a..9939503e8 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1580,6 +1580,7 @@ ivas_error ivas_osba_render_sf_fx( Word32 *p_output[] /* o : rendered time signal */ ); +#ifndef HARM_HQ_CORE2 void ivas_hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ Word16 synth[], /* o : output synthesis */ @@ -1589,7 +1590,7 @@ void ivas_hq_core_dec_fx( const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ ); - +#endif /* o : Consumed bits Q0 */ Word16 ivas_hq_classifier_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ diff --git a/lib_com/options.h b/lib_com/options.h index 0e162fda0..c77e68954 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,7 @@ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define HARM_HQ_CORE /* harmonize HQ core functions */ #define HARM_HQ_CORE_KEEP_EVS_BE // hack to keep EVS BE -//#define HARM_HQ_CORE2 +#define HARM_HQ_CORE2 /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 6395304e1..333cd561b 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7071,6 +7071,7 @@ void fd_bwe_dec_init( FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ ); +#ifndef HARM_HQ_CORE2 void hq_core_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *audio_fx, /* i : input audio signal Q0 */ @@ -7079,14 +7080,19 @@ void hq_core_enc_ivas_fx( 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*/ + 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_CORE2 + 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( @@ -7354,8 +7360,8 @@ ivas_error amr_wb_dec_fx( Word16 output_sp[], /* o : synthesis output */ Word32 *mem_hp20_in_fx /* i/o: hp20 filter memory Qx*/ #else - Word16 output_sp[], /* o : synthesis output */ - Decoder_State *st_fx /* o : Decoder static variables structure */ + Word16 output_sp[], /* o : synthesis output */ + Decoder_State *st_fx /* o : Decoder static variables structure */ #endif ); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 20f6e7f70..5fec7f552 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -348,7 +348,11 @@ ivas_error evs_dec_fx( } ELSE { +#ifdef HARM_HQ_CORE2 + 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_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 5dfe1f20f..0d8f8e9bb 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -15,8 +15,8 @@ * * HQ core decoder *--------------------------------------------------------------------------*/ - void hq_core_dec_fx( +#ifndef HARM_HQ_CORE2 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 */ @@ -471,6 +471,7 @@ void hq_core_dec_fx( 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 */ @@ -499,16 +500,15 @@ void ivas_hq_core_dec_fx( UWord16 lsb; Word16 L_spec; HQ_DEC_HANDLE hHQ_core; - - hHQ_core = st_fx->hHQ_core; - +#ifdef HARM_HQ_CORE2 + const Word16 *sfmsize, *sfm_start, *sfm_end; +#endif TCX_DEC_HANDLE hTcxDec; TCX_CONFIG_HANDLE tcx_cfg; Word16 index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX; Word16 tcx_offset, overlap, L_frame; Word16 L_frameTCX_glob, L_frame_glob; Word16 acelp_zir[L_FRAME_MAX / 2]; - // Word16 encoderLookahead, encoderLookaheadFB; Word16 hq_recovery_flag; Word16 mdctWindowLength; Word16 mdctWindowLengthFB; @@ -516,6 +516,8 @@ void ivas_hq_core_dec_fx( Word16 output[L_FRAME16k]; Word16 Q_output; + hHQ_core = st_fx->hHQ_core; + Q_output = 0; move16(); *Q_synth = 0; @@ -580,13 +582,25 @@ void ivas_hq_core_dec_fx( } ELSE { +#ifdef HARM_HQ_CORE2 + 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(); + } +#else /* this cannot happen in IVAS */ +#endif } } IF( hq_recovery_flag ) { acelp_plc_mdct_transition_fx( st_fx ); } + /* subtract signalling bits */ num_bits = sub( num_bits, st_fx->next_bit_pos ); /* Q0 */ @@ -633,6 +647,13 @@ void ivas_hq_core_dec_fx( } } +#ifdef HARM_HQ_CORE2 + IF( EQ_16( output_frame, L_FRAME8k ) ) + { + hq_configure_bfi_fx( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end ); + } + +#endif /*-------------------------------------------------------------------------- * transform-domain decoding *--------------------------------------------------------------------------*/ @@ -679,13 +700,27 @@ void ivas_hq_core_dec_fx( { IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { +#ifdef HARM_HQ_CORE2 + 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 ); + +#else /* this cannot happen in IVAS */ is_transient = 0; move16(); +#endif hqswb_clas = is_transient; /* Q0 */ move16(); - Q_audio = 12; + Q_audio = Q12; move16(); Q_G_audio = Q_audio; move16(); @@ -694,7 +729,16 @@ void ivas_hq_core_dec_fx( { /* HQ high rate decoder */ #ifdef HARM_HQ_CORE2 - hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); +#ifdef HARM_HQ_CORE_KEEP_EVS_BE + IF( st_fx->element_mode == EVS_MONO ) + { + hq_hr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); + } + ELSE +#endif + { + 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 ); #endif @@ -808,9 +852,6 @@ void ivas_hq_core_dec_fx( L_spec = hTcxDec->L_frameTCX; /* Q0 */ move16(); st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Q0 */ - // fscaleFB = sr2fscale( st_fx->output_Fs ); - // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; - // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; mdctWindowLength = getMdctWindowLength_fx( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); @@ -918,13 +959,57 @@ void ivas_hq_core_dec_fx( move16(); } +#ifdef HARM_HQ_CORE2 + IF( EQ_16( output_frame, L_FRAME8k ) ) + { + test(); + IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) + { + Copy_Scale_sig( st_fx->hHQ_core->old_out_fx + N_ZERO_NB, st_fx->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( st_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 ); + st_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 +#endif { test(); IF( EQ_16( st_fx->bfi, 1 ) && GE_16( output_frame, L_FRAME16k ) ) { /* PHASE_ECU active */ - Scale_sig32( t_audio_q, L_FRAME48k_EXT, sub( Q15, Q_audio ) ); - Q_audio = 15; +#ifdef HARM_HQ_CORE2 + IF( st_fx->element_mode > EVS_MONO ) +#endif + { + Scale_sig32( t_audio_q, L_FRAME48k_EXT, sub( Q15, Q_audio ) ); + } + Q_audio = Q15; 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 ); @@ -953,6 +1038,33 @@ void ivas_hq_core_dec_fx( } } +#ifdef HARM_HQ_CORE2 + IF( st_fx->element_mode == EVS_MONO ) + { + 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 ); + } + } + +#endif IF( GE_16( output_frame, L_FRAME16k ) ) { IF( EQ_16( hHQ_core->ph_ecu_HqVoicing, 1 ) ) @@ -979,15 +1091,23 @@ void ivas_hq_core_dec_fx( move16(); } - /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ +#ifdef HARM_HQ_CORE2 + IF( EQ_16( output_frame, L_FRAME8k ) ) + { + Copy32( wtda_audio, st_fx->hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &st_fx->hHQ_nbfec->old_auOut_2fr_fx[output_frame], st_fx->hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* q_old_auOut */ + Copy_Scale_sig( synth, &st_fx->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; - /*nbsubfr = extract_l(L_mult0(st_fx->L_frame,FL2WORD16(1/L_SUBFR)));*/ - nbsubfr = 4; /* Q0 */ - if ( EQ_16( st_fx->L_frame, 320 ) ) + nbsubfr = NB_SUBFR; /* Q0 */ + move16(); + if ( EQ_16( st_fx->L_frame, L_FRAME16k ) ) { - nbsubfr = 5; /* Q0 */ + nbsubfr = NB_SUBFR16k; /* Q0 */ move16(); } @@ -1003,11 +1123,16 @@ void ivas_hq_core_dec_fx( set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } - /* 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 */ +#ifdef HARM_HQ_CORE2 + IF( output_32_fx != NULL ) +#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 */ - Copy_Scale_sig_16_32_DEPREC( output, output_32_fx, L_FRAME16k, sub( Q11, Q_output ) ); // Q11 - st_fx->Q_syn_factor = s_min( 0, s_min( *Q_synth, Q_output ) ); + Copy_Scale_sig_16_32_DEPREC( output, output_32_fx, L_FRAME16k, sub( Q11, Q_output ) ); // Q11 + st_fx->Q_syn_factor = s_min( 0, s_min( *Q_synth, Q_output ) ); + } return; } diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index c44b34c17..276142838 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -593,7 +593,11 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ +#ifdef HARM_HQ_CORE2 + 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_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 2722ac054..beff58403 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -9,7 +9,7 @@ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ - +#ifndef HARM_HQ_CORE2 /*-------------------------------------------------------------------------- * hq_core_enc() * @@ -217,6 +217,7 @@ void hq_core_enc_fx( } return; } +#endif /*-------------------------------------------------------------------* * hq_core_enc_init() @@ -270,17 +271,27 @@ void HQ_core_enc_init_fx( return; } + +#ifdef HARM_HQ_CORE2 +/*-------------------------------------------------------------------------- + * hq_core_enc() + * + * HQ core encoder + *--------------------------------------------------------------------------*/ + +void hq_core_enc_fx( +#else 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_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*/ +#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*/ + 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 t_audio_fx[L_FRAME48k_EXT]; Word16 wtda_audio_fx16[2 * L_FRAME48k]; Word32 wtda_audio_fx32[2 * L_FRAME48k]; @@ -378,16 +389,27 @@ void hq_core_enc_ivas_fx( * Windowing and time-domain aliasing * DCT transform *--------------------------------------------------------------------------*/ + Q_audio = 0; move16(); - 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 */ - st->q_old_inp = 0; - move16(); - st->q_inp = 0; - move16(); - Copy( st->old_input_signal_fx, two_frames_buffer, input_frame ); /* Q0 */ - Copy( audio_fx, two_frames_buffer + input_frame, input_frame ); /* Q0 */ +#ifdef HARM_HQ_CORE2 + 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 */ + st->q_old_inp = 0; + move16(); + st->q_inp = 0; + move16(); + Copy( st->old_input_signal_fx, two_frames_buffer, input_frame ); /* Q0 */ + Copy( audio_fx, two_frames_buffer + input_frame, input_frame ); /* Q0 */ + } wtda_fx( two_frames_buffer + input_frame, &Q_audio, wtda_audio_fx32, NULL, 0, st->hTcxCfg->tcx_last_overlap_mode, st->hTcxCfg->tcx_curr_overlap_mode, input_frame ); @@ -410,20 +432,36 @@ void hq_core_enc_ivas_fx( Word16 tmp_q = Q_audio; move16(); direct_transform_fx( wtda_audio_fx32, t_audio_fx, is_transient, input_frame, &Q_audio, st->element_mode ); - scale_sig32( wtda_audio_fx32, L_FRAME48k_EXT, sub( Q_audio, tmp_q ) ); /* Q_audio */ + +#ifdef HARM_HQ_CORE2 + IF( st->element_mode > EVS_MONO ) +#endif + { + scale_sig32( wtda_audio_fx32, L_FRAME48k_EXT, sub( Q_audio, tmp_q ) ); /* Q_audio */ + } /* scale coefficients to their nominal level (8kHz) */ IF( NE_16( input_frame, NORM_MDCT_FACTOR ) ) { - UWord16 lsb; - tmp = mult_r( input_frame, 410 / 2 ); /* 1/8000 in Q15 */ - Word16 ener_match_fx = hq_nominal_scaling[tmp]; - move16(); - FOR( i = 0; i < input_frame; i++ ) +#ifdef HARM_HQ_CORE2 + test(); + IF( st->element_mode == EVS_MONO && EQ_16( input_frame, L_FRAME32k ) ) { - /*t_audio_q[i] *= ener_match; */ - Mpy_32_16_ss( t_audio_fx[i], ener_match_fx, &t_audio_fx[i], &lsb ); /* Q12 */ + Q_audio = add( Q_audio, 1 ); /* Divide by 2 */ + } + ELSE +#endif + { + UWord16 lsb; + tmp = mult_r( input_frame, 410 / 2 ); /* 1/8000 in Q15 */ + Word16 ener_match_fx = hq_nominal_scaling[tmp]; move16(); + FOR( i = 0; i < input_frame; i++ ) + { + /*t_audio_q[i] *= ener_match; */ + Mpy_32_16_ss( t_audio_fx[i], ener_match_fx, &t_audio_fx[i], &lsb ); /* Q12 */ + move16(); + } } } @@ -455,7 +493,12 @@ void hq_core_enc_ivas_fx( * High-band gain control in case of BWS *--------------------------------------------------------------------------*/ +#ifdef HARM_HQ_CORE2 + 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 */ @@ -499,19 +542,43 @@ void hq_core_enc_ivas_fx( * Transform-domain encoding *--------------------------------------------------------------------------*/ - scale_sig32( t_audio_fx, L_FRAME48k_EXT, sub( Q12, Q_audio ) ); - scale_sig32( wtda_audio_fx32, 2 * L_FRAME48k, sub( Q12, Q_audio ) ); - Q_audio = 12; +#ifdef HARM_HQ_CORE2 + 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 ) ); + } + Q_audio = Q12; move16(); + IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { +#ifdef HARM_HQ_CORE2 + /* 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_CORE2 - hq_hr_enc_fx( st, t_audio_fx, L_spec, &num_bits, is_transient, vad_hover_flag ); +#ifdef HARM_HQ_CORE_KEEP_EVS_BE + IF( st->element_mode == EVS_MONO ) + { + hq_hr_enc_fx( st, t_audio_fx, inner_frame, &num_bits, is_transient, vad_hover_flag ); + } + ELSE +#endif + { + 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 diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index 433c78e04..c5419270a 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -10,8 +10,17 @@ #include "prot_fx_enc.h" /* Function prototypes */ +/*-------------------------------------------------------------------------- + * Local constants + *--------------------------------------------------------------------------*/ + #define HVQ_ENC_NOISE_DELTA ( (Word16) 3277 ) /* 0.1 in Q15 */ + +/*-------------------------------------------------------------------------- + * Local function prototypes + *--------------------------------------------------------------------------*/ + static Word16 quant_lc_fx( const Word16, Word16 * ); @@ -198,15 +207,25 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits */ #ifdef HARM_HQ_CORE IF( st_fx->element_mode == EVS_MONO ) { +#ifdef HARM_HQ_CORE2 + 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_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 } ELSE #endif { #ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE2 + 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->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] ); +#endif #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] ); @@ -400,7 +419,10 @@ Word16 hvq_enc_fx( /* o : Consumed bits * * Quantize the noise to one of the levels in {0, 0.1, 0.2, 0.3} *----------------------------------------------------------------------------*/ -static Word16 quant_lc_fx( const Word16 x, Word16 *qx ) + +static Word16 quant_lc_fx( + const Word16 x, + Word16 *qx ) { Word16 indx; diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 55956600d..791955244 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -376,7 +376,11 @@ 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_CORE2 + 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 f5ee73977..7a2316e5f 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -40,7 +40,11 @@ static void quant_peaks_ivas_fx( * Vector Quantization of MDCT peaks *--------------------------------------------------------------------------*/ +#ifdef HARM_HQ_CORE2 +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 @@ -82,7 +86,6 @@ Word16 peak_vq_enc_ivas_fx( Word16 tmp1, exp1; Word16 Q_coefs; - Word16 indx, vqPeaksMinus1, tmp16, whiteNoise; Word16 *pPgainDifIdx, *pPgainCbIdx, *pVqPeakIdx, *pPosVec; Word32 *pPeakGains, *pCoefsOut; @@ -108,7 +111,6 @@ Word16 peak_vq_enc_ivas_fx( nf_seed = RANDOM_INITSEED; move16(); - 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 ); @@ -136,7 +138,16 @@ Word16 peak_vq_enc_ivas_fx( /* Quantize noise floor gains */ FOR( i = 0; i < HVQ_NF_GROUPS; i++ ) { - logqnorm_ivas_fx( &nf_gains[i], 12, &indx, 32, 1, &thren_HQ_fx[0] ); +#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] ); + } /* De-quantization */ acc = dicn_fx[indx]; /* Q14 */ @@ -204,11 +215,29 @@ Word16 peak_vq_enc_ivas_fx( /* Quantize peak gains */ pPeakGains = &peak_gains[0]; pPgainCbIdx = &pgain_cb_idx[0]; - logqnorm_ivas_fx( pPeakGains++, 14, pPgainCbIdx++, 32, 1, &thren_pg_fx[0] ); +#ifdef HARM_HQ_CORE2 + 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++ ) { - logqnorm_ivas_fx( pPeakGains++, 14, pPgainCbIdx++, 45, 1, &thren_pg_fx[0] ); +#ifdef HARM_HQ_CORE2 + 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] ); + } } /* Code quantized peak gain indices @@ -378,7 +407,17 @@ Word16 peak_vq_enc_ivas_fx( } pCoefs++; } - logqnorm_ivas_fx( pPvqVectorBandStart, 12, &pvq_norm[k], 40, hvq_band_width[k], &thren_HQ_fx[0] ); + +#ifdef HARM_HQ_CORE2 + 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] ); + } } /* Normalize coefficients */ @@ -489,7 +528,7 @@ Word16 peak_vq_enc_ivas_fx( return bits; } - +#ifndef HARM_HQ_CORE2 Word16 peak_vq_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 bwidth, /* i : audio bandwidth */ @@ -529,7 +568,6 @@ Word16 peak_vq_enc_fx( Word16 tmp1, exp1; Word16 Q_coefs; - Word16 indx, vqPeaksMinus1, tmp16, whiteNoise; Word16 *pPgainDifIdx, *pPgainCbIdx, *pVqPeakIdx, *pPosVec; Word32 *pPeakGains, *pCoefsOut; @@ -551,13 +589,11 @@ Word16 peak_vq_enc_fx( /* 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 ); - bits = 0; move16(); nf_seed = RANDOM_INITSEED; move16(); - 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 ); @@ -911,7 +947,7 @@ Word16 peak_vq_enc_fx( return bits; } - +#endif /*-------------------------------------------------------------------------- * quant_peaks_fx() diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 4e07606ec..4b94537dd 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3835,6 +3835,7 @@ void diffcod_lrmdct_fx( const Word16 is_transient /* i : transient flag Q0*/ ); +#ifndef HARM_HQ_CORE2 Word16 peak_vq_enc_ivas_fx( #ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ @@ -3851,8 +3852,11 @@ Word16 peak_vq_enc_ivas_fx( 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_CORE2 + 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 */ -- GitLab From 0c5f484c46f928c1cf3a88df2b8ea2e879a03c58 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 18:27:52 +0100 Subject: [PATCH 21/31] merge HARM_HQ_CORE2 into HARM_HQ_CORE --- lib_com/ivas_prot_fx.h | 7 +++---- lib_com/options.h | 2 +- lib_com/prot_fx.h | 4 ++-- lib_dec/evs_dec_fx.c | 2 +- lib_dec/hq_core_dec_fx.c | 24 ++++++++++++------------ lib_dec/hq_hr_dec_fx.c | 8 ++++---- lib_dec/ivas_core_dec_fx.c | 2 +- lib_enc/hq_core_enc_fx.c | 18 +++++++++--------- lib_enc/hq_hr_enc_fx.c | 8 ++++---- lib_enc/hvq_enc_fx.c | 7 +------ lib_enc/ivas_core_enc_fx.c | 2 +- lib_enc/peak_vq_enc_fx.c | 10 +++++----- lib_enc/prot_fx_enc.h | 9 +++------ 13 files changed, 47 insertions(+), 56 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index 9939503e8..af586e383 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1580,7 +1580,7 @@ ivas_error ivas_osba_render_sf_fx( Word32 *p_output[] /* o : rendered time signal */ ); -#ifndef HARM_HQ_CORE2 +#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 */ @@ -1600,7 +1600,7 @@ Word16 ivas_hq_classifier_dec_fx( Word16 *hqswb_clas /* o : HQ class Q0 */ ); -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE 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 */ @@ -1612,8 +1612,7 @@ void ivas_hq_hr_dec_fx( Word16 *SWB_fenv, /* o : SWB frequency envelopes Q1 */ const Word16 core_switching_flag /* i : Core switching flag */ ); -#endif -#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 */ diff --git a/lib_com/options.h b/lib_com/options.h index c77e68954..0bcb8d510 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -98,7 +98,7 @@ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define HARM_HQ_CORE /* harmonize HQ core functions */ #define HARM_HQ_CORE_KEEP_EVS_BE // hack to keep EVS BE -#define HARM_HQ_CORE2 + /* #################### End BE switches ################################## */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index 333cd561b..cd535be63 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7071,7 +7071,7 @@ void fd_bwe_dec_init( FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ ); -#ifndef HARM_HQ_CORE2 +#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 */ @@ -7087,7 +7087,7 @@ void hq_core_dec_fx( 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_CORE2 +#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 diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 5fec7f552..421fc2652 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -348,7 +348,7 @@ ivas_error evs_dec_fx( } ELSE { -#ifdef HARM_HQ_CORE2 +#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 ); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 0d8f8e9bb..7a9288159 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -16,7 +16,7 @@ * HQ core decoder *--------------------------------------------------------------------------*/ void hq_core_dec_fx( -#ifndef HARM_HQ_CORE2 +#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 */ @@ -500,7 +500,7 @@ void ivas_hq_core_dec_fx( UWord16 lsb; Word16 L_spec; HQ_DEC_HANDLE hHQ_core; -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE const Word16 *sfmsize, *sfm_start, *sfm_end; #endif TCX_DEC_HANDLE hTcxDec; @@ -582,7 +582,7 @@ void ivas_hq_core_dec_fx( } ELSE { -#ifdef HARM_HQ_CORE2 +#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 */ @@ -647,7 +647,7 @@ void ivas_hq_core_dec_fx( } } -#ifdef HARM_HQ_CORE2 +#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 ); @@ -700,7 +700,7 @@ void ivas_hq_core_dec_fx( { IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( EQ_16( st_fx->prev_bfi, 1 ) ) { set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); @@ -728,7 +728,7 @@ void ivas_hq_core_dec_fx( ELSE { /* HQ high rate decoder */ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE #ifdef HARM_HQ_CORE_KEEP_EVS_BE IF( st_fx->element_mode == EVS_MONO ) { @@ -851,7 +851,7 @@ void ivas_hq_core_dec_fx( move16(); L_spec = hTcxDec->L_frameTCX; /* Q0 */ move16(); - st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Q0 */ + st_fx->fscale = sr2fscale_fx( st_fx->sr_core ); /* Q0 */ mdctWindowLength = getMdctWindowLength_fx( st_fx->fscale ); /* Q0 */ Word16 temp, temp_e; temp = BASOP_Util_Divide3232_Scale( st_fx->output_Fs, st_fx->sr_core, &temp_e ); @@ -959,7 +959,7 @@ void ivas_hq_core_dec_fx( move16(); } -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( EQ_16( output_frame, L_FRAME8k ) ) { test(); @@ -1003,7 +1003,7 @@ void ivas_hq_core_dec_fx( IF( EQ_16( st_fx->bfi, 1 ) && GE_16( output_frame, L_FRAME16k ) ) { /* PHASE_ECU active */ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( st_fx->element_mode > EVS_MONO ) #endif { @@ -1038,7 +1038,7 @@ void ivas_hq_core_dec_fx( } } -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( st_fx->element_mode == EVS_MONO ) { test(); @@ -1091,7 +1091,7 @@ void ivas_hq_core_dec_fx( move16(); } -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( EQ_16( output_frame, L_FRAME8k ) ) { Copy32( wtda_audio, st_fx->hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ @@ -1123,7 +1123,7 @@ void ivas_hq_core_dec_fx( set16_fx( &st_fx->mem_pitch_gain[2], 0, nbsubfr ); } -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( output_32_fx != NULL ) #endif { diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 06d8a6757..5846db54e 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -135,7 +135,7 @@ void hq_pred_hb_bws_fx( * HQ High rate decoding routine *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE void hq_hr_dec_fx( #else void ivas_hq_hr_dec_fx( @@ -207,7 +207,7 @@ void ivas_hq_hr_dec_fx( * Decode classification *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( st_fx->element_mode == EVS_MONO ) { bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); @@ -327,7 +327,7 @@ void ivas_hq_hr_dec_fx( * Bit allocation *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( st_fx->element_mode == EVS_MONO ) { hq_bit_allocation_fx( st_fx->core_brate, length, *hqswb_clas, &bits_left, normqlg2, nb_sfm, sfmsize, noise_level, @@ -478,7 +478,7 @@ void ivas_hq_hr_dec_fx( return; } -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE void hq_hr_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index 276142838..d1bb90aec 100644 --- a/lib_dec/ivas_core_dec_fx.c +++ b/lib_dec/ivas_core_dec_fx.c @@ -593,7 +593,7 @@ ivas_error ivas_core_dec_fx( IF( EQ_16( st->core, HQ_CORE ) ) { /* HQ core decoder */ -#ifdef HARM_HQ_CORE2 +#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] ); diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index beff58403..d1cdfc353 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -9,7 +9,7 @@ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE /*-------------------------------------------------------------------------- * hq_core_enc() * @@ -272,7 +272,7 @@ void HQ_core_enc_init_fx( } -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE /*-------------------------------------------------------------------------- * hq_core_enc() * @@ -392,7 +392,7 @@ void hq_core_enc_ivas_fx( Q_audio = 0; move16(); -#ifdef HARM_HQ_CORE2 +#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 */ @@ -433,7 +433,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_CORE2 +#ifdef HARM_HQ_CORE IF( st->element_mode > EVS_MONO ) #endif { @@ -443,7 +443,7 @@ void hq_core_enc_ivas_fx( /* scale coefficients to their nominal level (8kHz) */ IF( NE_16( input_frame, NORM_MDCT_FACTOR ) ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE test(); IF( st->element_mode == EVS_MONO && EQ_16( input_frame, L_FRAME32k ) ) { @@ -493,7 +493,7 @@ void hq_core_enc_ivas_fx( * High-band gain control in case of BWS *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE test(); IF( st->element_mode > EVS_MONO && st->bwidth_sw_cnt > 0 ) #else @@ -542,7 +542,7 @@ void hq_core_enc_ivas_fx( * Transform-domain encoding *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( st->element_mode == EVS_MONO ) { scale_sig32( t_audio_fx, inner_frame, sub( Q12, Q_audio ) ); /* Q12 */ @@ -558,7 +558,7 @@ void hq_core_enc_ivas_fx( IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE /* HQ low rate encoder */ hq_lr_enc_fx( st, t_audio_fx, inner_frame, &num_bits, is_transient ); #else @@ -568,7 +568,7 @@ void hq_core_enc_ivas_fx( ELSE { /* HQ high rate encoder */ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE #ifdef HARM_HQ_CORE_KEEP_EVS_BE IF( st->element_mode == EVS_MONO ) { diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index c4f1d70d2..ce162abf7 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -18,7 +18,7 @@ *--------------------------------------------------------------------------*/ void hq_hr_enc_fx( -#ifndef HARM_HQ_CORE2 +#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 */ @@ -377,7 +377,7 @@ void hq_hr_enc_ivas_fx( * Classification *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( st->element_mode == EVS_MONO ) { bits = hq_classifier_enc_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ @@ -449,7 +449,7 @@ void hq_hr_enc_ivas_fx( *------------------------------------------------------------------*/ /* calculate and quantize norms */ -#ifdef HARM_HQ_CORE2 +#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 ); @@ -519,7 +519,7 @@ void hq_hr_enc_ivas_fx( * Bit allocation *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( st->element_mode == EVS_MONO ) { 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 ); diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index c5419270a..cb3cbde0c 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -207,7 +207,7 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits */ #ifdef HARM_HQ_CORE IF( st_fx->element_mode == EVS_MONO ) { -#ifdef HARM_HQ_CORE2 +#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 @@ -219,13 +219,8 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits */ #endif { #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE2 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->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] ); -#endif #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] ); diff --git a/lib_enc/ivas_core_enc_fx.c b/lib_enc/ivas_core_enc_fx.c index 791955244..3261bfb05 100644 --- a/lib_enc/ivas_core_enc_fx.c +++ b/lib_enc/ivas_core_enc_fx.c @@ -376,7 +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_CORE2 +#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] ); diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 7a2316e5f..0b9fe15c0 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -40,7 +40,7 @@ static void quant_peaks_ivas_fx( * Vector Quantization of MDCT peaks *--------------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE Word16 peak_vq_enc_fx( #else Word16 peak_vq_enc_ivas_fx( @@ -215,7 +215,7 @@ Word16 peak_vq_enc_ivas_fx( /* Quantize peak gains */ pPeakGains = &peak_gains[0]; pPgainCbIdx = &pgain_cb_idx[0]; -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 32, 1, 1 ); @@ -228,7 +228,7 @@ Word16 peak_vq_enc_ivas_fx( vqPeaksMinus1 = sub( vq_peaks, 1 ); FOR( i = 0; i < vqPeaksMinus1; i++ ) { -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 45, 1, 1 ); @@ -408,7 +408,7 @@ Word16 peak_vq_enc_ivas_fx( pCoefs++; } -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE IF( element_mode == EVS_MONO ) { logqnorm_fx( pPvqVectorBandStart, 12, &pvq_norm[k], 40, hvq_band_width[k], 0 ); @@ -528,7 +528,7 @@ Word16 peak_vq_enc_ivas_fx( return bits; } -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE Word16 peak_vq_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 bwidth, /* i : audio bandwidth */ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index 4b94537dd..c2d6c48ca 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3637,7 +3637,7 @@ void hq_lr_enc_fx( ); void hq_hr_enc_fx( -#ifndef HARM_HQ_CORE2 +#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 */ @@ -3835,11 +3835,8 @@ void diffcod_lrmdct_fx( const Word16 is_transient /* i : transient flag Q0*/ ); -#ifndef HARM_HQ_CORE2 +#ifndef HARM_HQ_CORE Word16 peak_vq_enc_ivas_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 */ @@ -3854,7 +3851,7 @@ Word16 peak_vq_enc_ivas_fx( ); #endif Word16 peak_vq_enc_fx( -#ifdef HARM_HQ_CORE2 +#ifdef HARM_HQ_CORE const Word16 element_mode, /* i : element mode */ #endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ -- GitLab From d664e502a2d5fe54a356b674a7d49de2cbe24a12 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 19:00:21 +0100 Subject: [PATCH 22/31] cleaning --- lib_dec/FEC_HQ_phase_ecu_fx.c | 31 -------------------- lib_dec/hq_core_dec_fx.c | 6 ---- lib_dec/hq_hr_dec_fx.c | 30 ------------------- lib_enc/hq_hr_enc_fx.c | 54 ----------------------------------- lib_enc/hvq_enc_fx.c | 23 +++------------ lib_enc/peak_vq_enc_fx.c | 5 ---- 6 files changed, 4 insertions(+), 145 deletions(-) diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index beeae550d..a34b57e28 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -4625,11 +4625,7 @@ static void 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, EVS_MONO ); -#else fec_ecu_dft_fx( prevsynth_LP, N, Tfr, Tfi, &sum_Tf_abs, Tf_abs, &Nfft, &exp ); -#endif sinusoidal_synthesis_fx( Tfr, Tfi, Tf_abs, N, output_frame, decimatefactor, Nfft, sum_Tf_abs, synthesis, HqVoicing, exp ); @@ -4875,11 +4871,7 @@ static void hq_phase_ecu_fx( 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 ); -#ifdef HARM_HQ_CORE - spec_ana_fx( prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec, EVS_MONO, &seed /*temp*/, -1 ); -#else spec_ana_fx( prevsynth + offset, plocs, plocsi, num_p, X_sav, output_frame, bwidth_fx, Q_spec ); -#endif test(); IF( prev_bfi != 0 && *last_fec != 0 ) @@ -4909,20 +4901,11 @@ static void hq_phase_ecu_fx( seed = add_sat( seed, 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, EVS_MONO, -1, -1 ); -#else 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 ); -#endif /* reconstructed frame in tda domain */ -#ifdef HARM_HQ_CORE - rec_frame_fx( X, ecu_rec, output_frame, *Q_spec, NULL, EVS_MONO, NULL, NULL ); -#else rec_frame_fx( X, ecu_rec, output_frame, *Q_spec ); -#endif *last_fec = 0; move16(); @@ -5128,11 +5111,7 @@ void hq_ecu_fx( /* find pitch and R value */ IF( !( LT_16( output_frame, L_FRAME16k ) ) ) { -#ifdef HARM_HQ_CORE - fec_ecu_pitch_fx( st_fx->element_mode, 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 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 ); -#endif } ELSE { @@ -5159,11 +5138,7 @@ void hq_ecu_fx( ( 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] ) ) ) ) { -#ifdef HARM_HQ_CORE - 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, EVS_MONO, NULL, 0 ); -#else 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 ); -#endif *last_fec = 1; move16(); *ph_ecu_active = 0; @@ -5173,15 +5148,9 @@ void hq_ecu_fx( } ELSE { -#ifdef HARM_HQ_CORE - 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, -1, EVS_MONO ); -#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 ); -#endif } return; diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 7a9288159..fc523dd45 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -160,15 +160,9 @@ void 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 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 } ELSE { diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 5846db54e..242144246 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -555,26 +555,8 @@ void hq_hr_dec_fx( * set quantization parameters *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - Word16 tmp_length = length; - move16(); - if ( EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - hq_configure_fx( tmp_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 - 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 -#else 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 ); -#endif /*------------------------------------------------------------------* * Unpacking bitstream @@ -749,19 +731,7 @@ void hq_hr_dec_fx( IF( EQ_16( *is_transient, 1 ) ) { -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - tmp_length = length; - move16(); - if ( EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - de_interleave_spectrum_fx( t_audio_q, tmp_length ); -#else de_interleave_spectrum_fx( t_audio_q, length ); -#endif } /*------------------------------------------------------------------* diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index ce162abf7..4b1cff6a1 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -102,26 +102,8 @@ void hq_hr_enc_fx( * set quantization parameters *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - Word16 tmp_length = length; - move16(); - if ( EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - hq_configure_fx( tmp_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 - 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 -#else 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 ); -#endif /*------------------------------------------------------------------* * Transient frame handling @@ -130,19 +112,7 @@ void hq_hr_enc_fx( /* Interleave MLT coefficients of 4 sub-vectors in case of transient */ IF( EQ_16( is_transient, 1 ) ) { -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - tmp_length = length; - move16(); - if ( EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - interleave_spectrum_fx( t_audio, tmp_length ); -#else interleave_spectrum_fx( t_audio, length ); -#endif } test(); @@ -178,23 +148,7 @@ void hq_hr_enc_fx( test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { -#ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - tmp_length = length; - move16(); - if ( EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - hq_generic_hf_encoding_fx( st_fx->element_mode, t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas, tmp_length ); -#else - hq_generic_hf_encoding_fx( st_fx->element_mode, t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas, length ); -#endif -#else hq_generic_encoding_fx( t_audio, hq_generic_fenv, hq_generic_offset, st_fx, &hq_generic_exc_clas /*, length*/ ); -#endif 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*/ @@ -232,22 +186,14 @@ void hq_hr_enc_fx( IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { -#ifdef HARM_HQ_CORE - 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 ); -#else 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 ); -#endif *num_bits = sub( *num_bits, sum ); /* Q0 */ move16(); } ELSE { -#ifdef HARM_HQ_CORE - shape_bits = pvq_core_enc_fx( st_fx->element_mode, 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 ); -#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 ); -#endif *num_bits = add( *num_bits, sub( sum, shape_bits ) ); /* Q0 */ move16(); } diff --git a/lib_enc/hvq_enc_fx.c b/lib_enc/hvq_enc_fx.c index cb3cbde0c..4111ff1bc 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -205,27 +205,12 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits */ } #ifdef HARM_HQ_CORE - IF( st_fx->element_mode == EVS_MONO ) - { -#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_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 - } - ELSE -#endif - { -#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] ); + 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] ); + 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 ); diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 0b9fe15c0..92aee40f9 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -871,13 +871,8 @@ Word16 peak_vq_enc_fx( move16(); } -#ifdef HARM_HQ_CORE - 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, EVS_MONO, HQ_CORE ); -#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]; -- GitLab From 474f18b3cca73568296f94837dd50f438992e860 Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 24 Feb 2026 20:23:35 +0100 Subject: [PATCH 23/31] fix --- lib_dec/hq_core_dec_fx.c | 22 ++++++++++++++++++++-- lib_enc/hq_core_enc_fx.c | 4 ++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index fc523dd45..77e651254 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -516,8 +516,13 @@ void ivas_hq_core_dec_fx( move16(); *Q_synth = 0; move16(); - st_fx->Q_syn_factor = 0; - move16(); +#ifdef HARM_HQ_CORE_KEEP_EVS_BE + if ( st_fx->element_mode > EVS_MONO ) +#endif + { + st_fx->Q_syn_factor = 0; + move16(); + } /*-------------------------------------------------------------------------- * Initializations @@ -646,6 +651,12 @@ void ivas_hq_core_dec_fx( { hq_configure_bfi_fx( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end ); } + ELSE + { + sfmsize = NULL; + sfm_start = NULL; + sfm_end = NULL; + } #endif /*-------------------------------------------------------------------------- @@ -669,6 +680,13 @@ void ivas_hq_core_dec_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, st_fx->hHQ_nbfec->ynrm_values_fx, st_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(); diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index d1cdfc353..ebb01a5cf 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -650,7 +650,11 @@ 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(); -- GitLab From 93e3d619211cccca639286e74f391843391b7b9b Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 25 Feb 2026 08:23:13 +0100 Subject: [PATCH 24/31] fix EVS BE in BWS --- lib_dec/hq_core_dec_fx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 77e651254..a7e99d336 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -808,6 +808,12 @@ 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_KEEP_EVS_BE + if ( st_fx->element_mode == EVS_MONO ) + { + ener_match = div_s( st_fx->bws_cnt1, N_NS2W_FRAMES ); /*Q15*/ + } +#endif } IF( is_transient ) -- GitLab From 0fb25f154aedf7585c30817002f8624cd050a4f0 Mon Sep 17 00:00:00 2001 From: vaclav Date: Wed, 25 Feb 2026 10:01:38 +0100 Subject: [PATCH 25/31] harmonize classification functions + simplifications --- lib_com/hq_bit_allocation_fx.c | 105 ++++++++++++++++++--------------- lib_com/ivas_prot_fx.h | 6 +- lib_com/options.h | 2 +- lib_dec/FEC_HQ_phase_ecu_fx.c | 7 ++- lib_dec/hq_classifier_dec_fx.c | 19 ++++-- lib_dec/hq_core_dec_fx.c | 51 ++++++++-------- lib_dec/hq_hr_dec_fx.c | 54 +++-------------- lib_dec/peak_vq_dec_fx.c | 2 +- lib_enc/hq_classifier_enc_fx.c | 64 +++++++++----------- lib_enc/hq_core_enc_fx.c | 11 +--- lib_enc/hq_hr_enc_fx.c | 71 ++++------------------ lib_enc/hq_lr_enc_fx.c | 2 +- lib_enc/peak_vq_enc_fx.c | 2 +- lib_enc/prot_fx_enc.h | 3 +- 14 files changed, 158 insertions(+), 241 deletions(-) diff --git a/lib_com/hq_bit_allocation_fx.c b/lib_com/hq_bit_allocation_fx.c index c1efb9def..29d281cfd 100644 --- a/lib_com/hq_bit_allocation_fx.c +++ b/lib_com/hq_bit_allocation_fx.c @@ -14,7 +14,11 @@ * 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 */ @@ -39,8 +43,6 @@ void ivas_hq_bit_allocation_fx( Word16 E_hb_mean; Word16 E_max; Word16 i_max; - /* Temp */ - Word16 sfm_limit = nb_sfm; move16(); @@ -164,69 +166,73 @@ void ivas_hq_bit_allocation_fx( } avrg_wnorm = shr( avrg_wnorm, 3 ); - FOR( i = 0; i < 4; i++ ){ - IF( LT_16( wnorm[i], avrg_wnorm ) ){ + 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 ); + } } - - /* 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 ) ) + ELSE { - tmp = shr( sfm_limit, 1 ); - tmp2 = sub( tmp, 1 ); - FOR( i = tmp; i < sfm_limit; i++ ) + 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 ) ) { - wnorm[i] = wnorm[tmp2]; - move16(); + 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 ); } - 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 ); + /* Find last coded core band */ + *core_sfm = sub( nb_sfm, 1 ); move16(); - IF( LT_16( *core_sfm, num_env_bands ) ) + test(); + test(); + IF( hqswb_clas == HQ_NORMAL || EQ_16( hqswb_clas, HQ_HARMONIC ) ) { - *core_sfm = sub( num_env_bands, 1 ); + *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(); + *num_bits = sub( *num_bits, *sum ); + move16(); -return; + 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 */ @@ -441,3 +447,4 @@ void hq_bit_allocation_fx( return; } +#endif diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index af586e383..f60b6c837 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1590,7 +1590,7 @@ void ivas_hq_core_dec_fx( const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ ); -#endif + /* o : Consumed bits Q0 */ Word16 ivas_hq_classifier_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -1600,7 +1600,6 @@ Word16 ivas_hq_classifier_dec_fx( Word16 *hqswb_clas /* o : HQ class Q0 */ ); -#ifndef HARM_HQ_CORE 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 */ @@ -1627,7 +1626,7 @@ void ivas_hq_configure_fx( Word16 *sfm_start, /* o : Subband start coefficients Q0 */ Word16 *sfm_end /* o : Subband end coefficients Q0 */ ); -#endif + void ivas_hq_bit_allocation_fx( const Word32 core_brate, /* i : Core bit-rate Q0 */ const Word16 length, /* i : Frame length Q0 */ @@ -1644,7 +1643,6 @@ void ivas_hq_bit_allocation_fx( const Word16 num_env_bands /* i : Number sub bands to be encoded for HQ_GEN Q0 */ ); -#ifndef HARM_HQ_CORE /* o : Number of assigned gain bits */ Word16 ivas_assign_gain_bits_fx( const Word16 core, /* i : HQ core */ diff --git a/lib_com/options.h b/lib_com/options.h index 0bcb8d510..794993b65 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -97,7 +97,7 @@ #define FIX_2431_AVOID_CALLOC /* VA: basp issue 2431: avoid use of calloc() */ #define FIX_2424_REMOVE_GAUSS_L2_ENC /* VA: basop issue 2424: Remove duplicated code in gauss_L2_ivas_fx() */ #define HARM_HQ_CORE /* harmonize HQ core functions */ -#define HARM_HQ_CORE_KEEP_EVS_BE // hack to keep EVS BE +#define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ /* #################### End BE switches ################################## */ diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index a34b57e28..4bb105f5e 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -5010,7 +5010,7 @@ void ivas_hq_ecu_fx( ( ph_ecu_HqVoicing || ( ( ( GT_16( hHQ_core->env_stab_plc_fx, 16384 ) /* 0.5 in Q15 */ ) && ( LT_16( corr, 19661 ) /* 0.6 in Q15 */ ) ) || ( LT_16( hHQ_core->env_stab_plc_fx, 16384 ) /* 0.5 in Q15 */ && ( GT_16( corr, 27853 ) /* 0.85 in Q15 */ ) ) ) ) ) ) || ( LT_32( st_fx->total_brate, 48000 ) && ( ( ph_ecu_HqVoicing || GT_16( corr, 27853 ) /* 0.85 in Q15 */ ) && !prev_bfi && ( !old_is_transient[0] || old_is_transient[1] ) ) ); -#ifdef HARM_HQ_CORE_KEEP_EVS_BE +#ifdef HARM_HQ_CORE_KEEP_BE IF( st_fx->element_mode == EVS_MONO ) { test(); @@ -5028,7 +5028,8 @@ void ivas_hq_ecu_fx( test(); test(); test(); - evs_mode_selection = ( 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 ) ) ) ) ) ) ) || + evs_mode_selection = ( 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( hHQ_core->env_stab_plc_fx, 0 ) ) && ( LT_16( corr, 19661 ) ) ) || ( !( NE_16( 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] ) ) ); } #endif @@ -5044,7 +5045,7 @@ void ivas_hq_ecu_fx( ( ( st_fx->element_mode != EVS_MONO ) && evs_mode_selection && ivas_mode_selection ) ) { #ifdef HARM_HQ_CORE - 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 ); + 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 diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index d6df6e4f5..5b5fe93f7 100644 --- a/lib_dec/hq_classifier_dec_fx.c +++ b/lib_dec/hq_classifier_dec_fx.c @@ -12,12 +12,17 @@ * HQ mode selector (decision_matrix) *--------------------------------------------------------------------------*/ -Word16 ivas_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 */ +#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 */ + Word16 *is_transient, /* o : Transient flag Q0 */ + Word16 *hqswb_clas /* o : HQ class Q0 */ ) { Word16 bits; @@ -80,6 +85,7 @@ Word16 ivas_hq_classifier_dec_fx( /* o : Consumed bits return bits; } +#ifndef HARM_HQ_CORE Word16 hq_classifier_dec_fx( /* o : Consumed bits Q0 */ Decoder_State *st_fx, /* i/o: decoder state structure */ @@ -150,3 +156,4 @@ Word16 hq_classifier_dec_fx( /* o : Consumed bits return bits; } +#endif diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index a7e99d336..183987900 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -493,10 +493,11 @@ void ivas_hq_core_dec_fx( Word32 L_tmp; UWord16 lsb; Word16 L_spec; - HQ_DEC_HANDLE hHQ_core; #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; Word16 index, left_rect, tcx_offsetFB, overlapFB, L_frameTCX; @@ -511,12 +512,15 @@ 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_KEEP_EVS_BE +#ifdef HARM_HQ_CORE if ( st_fx->element_mode > EVS_MONO ) #endif { @@ -683,7 +687,7 @@ void ivas_hq_core_dec_fx( #ifdef HARM_HQ_CORE ELSE { - HQ_FEC_processing_fx( st_fx, t_audio_q, is_transient, st_fx->hHQ_nbfec->ynrm_values_fx, st_fx->hHQ_nbfec->r_p_values_fx, num_Sb, nb_sfm, num_bands_p, + 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 @@ -724,42 +728,42 @@ void ivas_hq_core_dec_fx( /* 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(); #else /* this cannot happen in IVAS */ is_transient = 0; move16(); -#endif hqswb_clas = is_transient; /* Q0 */ move16(); - Q_audio = Q12; + Q_audio = 12; move16(); Q_G_audio = Q_audio; move16(); +#endif } ELSE { /* HQ high rate decoder */ #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - IF( st_fx->element_mode == EVS_MONO ) - { - hq_hr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); - } - ELSE -#endif - { - hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); - } + 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 ); -#endif 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(); test(); @@ -808,7 +812,7 @@ 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_KEEP_EVS_BE +#ifdef HARM_HQ_CORE if ( st_fx->element_mode == EVS_MONO ) { ener_match = div_s( st_fx->bws_cnt1, N_NS2W_FRAMES ); /*Q15*/ @@ -983,11 +987,11 @@ void ivas_hq_core_dec_fx( test(); IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) { - Copy_Scale_sig( st_fx->hHQ_core->old_out_fx + N_ZERO_NB, st_fx->hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 15 - exp_old_out - Q_old_wtda */ + 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( st_fx->hHQ_nbfec->prev_oldauOut_fx, 0, output_frame ); + set16_fx( hHQ_nbfec->prev_oldauOut_fx, 0, output_frame ); } test(); @@ -1002,7 +1006,8 @@ void ivas_hq_core_dec_fx( { 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 ); - st_fx->hHQ_nbfec->phase_mat_next = 0; + + hHQ_nbfec->phase_mat_next = 0; move16(); } @@ -1112,9 +1117,9 @@ void ivas_hq_core_dec_fx( #ifdef HARM_HQ_CORE IF( EQ_16( output_frame, L_FRAME8k ) ) { - Copy32( wtda_audio, st_fx->hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ - Copy( &st_fx->hHQ_nbfec->old_auOut_2fr_fx[output_frame], st_fx->hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* q_old_auOut */ - Copy_Scale_sig( synth, &st_fx->hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ + 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 */ } #endif diff --git a/lib_dec/hq_hr_dec_fx.c b/lib_dec/hq_hr_dec_fx.c index 242144246..342a18bbc 100644 --- a/lib_dec/hq_hr_dec_fx.c +++ b/lib_dec/hq_hr_dec_fx.c @@ -208,15 +208,11 @@ void ivas_hq_hr_dec_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE - IF( st_fx->element_mode == EVS_MONO ) - { - bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); - } - ELSE + 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 = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ - } + bits_left = sub( num_bits, bits ); /* Q0 */ /*------------------------------------------------------------------* @@ -224,22 +220,8 @@ void ivas_hq_hr_dec_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - Word16 tmp_length = length; - move16(); - test(); - if ( st_fx->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - hq_configure_fx( tmp_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 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 #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 ); @@ -320,6 +302,7 @@ void ivas_hq_hr_dec_fx( move16(); } } + hHQ_core->env_stab_plc_fx = env_stab_smo_fx( s_min( hHQ_core->env_stab_fx, sub( 32767 /* 1.0f in Q15 */, stab_trans_fx[L_STAB_TBL - 1] ) ), hHQ_core->env_stab_state_p_fx, &hHQ_core->envstabplc_hocnt ); /* Q0 */ move16(); @@ -328,17 +311,11 @@ void ivas_hq_hr_dec_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE - IF( st_fx->element_mode == EVS_MONO ) - { - 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 + 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 - { - 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 ); - } test(); test(); @@ -443,20 +420,7 @@ void ivas_hq_hr_dec_fx( IF( EQ_16( *is_transient, 1 ) ) { #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - tmp_length = length; - move16(); - test(); - if ( st_fx->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - de_interleave_spectrum_fx( t_audio_q, tmp_length ); -#else de_interleave_spectrum_fx( t_audio_q, length ); -#endif #else ivas_de_interleave_spectrum_fx( t_audio_q, length ); #endif diff --git a/lib_dec/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index 122e97e6c..81cd93e97 100644 --- a/lib_dec/peak_vq_dec_fx.c +++ b/lib_dec/peak_vq_dec_fx.c @@ -322,7 +322,7 @@ 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_EVS_BE +#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 ); #else diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index 3a6e2f971..d682402cc 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -184,18 +184,17 @@ static Word16 hf_spectrum_sparseness_fx( * * HQ mode selector (decision_matrix) *--------------------------------------------------------------------------*/ - -/* o : Consumed bits Q0 */ -Word16 hq_classifier_enc_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 */ +#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; @@ -219,13 +218,8 @@ Word16 hq_classifier_enc_fx( move16(); /* 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_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 } test(); @@ -238,13 +232,8 @@ Word16 hq_classifier_enc_fx( move16(); /* 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_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 } test(); @@ -294,26 +283,30 @@ Word16 hq_classifier_enc_fx( return bits; } -Word16 hq_classifier_enc_ivas_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 */ +#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 */ + 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; Word32 max_brate; Word16 harmonic_decision; - max_brate = HQ_32k; move32(); @@ -375,6 +368,7 @@ Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bi bits = 0; /* HQ_NORMAL only -- no signalling needed */ move16(); } + /* write signalling info to the bitstream */ push_indice( st_fx->hBstr, IND_HQ_SWB_CLAS, *hqswb_clas, bits ); diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index ebb01a5cf..98552f5e3 100644 --- a/lib_enc/hq_core_enc_fx.c +++ b/lib_enc/hq_core_enc_fx.c @@ -569,16 +569,7 @@ void hq_core_enc_ivas_fx( { /* HQ high rate encoder */ #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - IF( st->element_mode == EVS_MONO ) - { - hq_hr_enc_fx( st, t_audio_fx, inner_frame, &num_bits, is_transient, vad_hover_flag ); - } - ELSE -#endif - { - hq_hr_enc_fx( st, t_audio_fx, L_spec, &num_bits, is_transient, vad_hover_flag ); - } + 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 diff --git a/lib_enc/hq_hr_enc_fx.c b/lib_enc/hq_hr_enc_fx.c index 4b1cff6a1..5c290fe7c 100644 --- a/lib_enc/hq_hr_enc_fx.c +++ b/lib_enc/hq_hr_enc_fx.c @@ -324,36 +324,18 @@ void hq_hr_enc_ivas_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE - IF( st->element_mode == EVS_MONO ) - { - 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_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 - { - bits = hq_classifier_enc_ivas_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ - } + *num_bits = sub( *num_bits, bits ); - move16(); /*------------------------------------------------------------------* * Set quantization parameters *------------------------------------------------------------------*/ -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - Word16 tmp_length = length; - move16(); - test(); - if ( st->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - hq_configure_fx( tmp_length, hqswb_clas, st->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); -#else hq_configure_fx( length, hqswb_clas, st->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); -#endif /*------------------------------------------------------------------* * Transient frame handling @@ -363,20 +345,7 @@ void hq_hr_enc_ivas_fx( IF( is_transient ) { #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - tmp_length = length; - move16(); - test(); - if ( st->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - interleave_spectrum_fx( t_audio_fx, tmp_length ); -#else interleave_spectrum_fx( t_audio_fx, length ); -#endif #else interleave_spectrum_ivas_fx( t_audio_fx, length ); #endif @@ -417,7 +386,6 @@ void hq_hr_enc_ivas_fx( #endif *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); - move16(); /* Encode norm indices */ #ifdef HARM_HQ_CORE @@ -427,27 +395,14 @@ void hq_hr_enc_ivas_fx( #endif /*------------------------------------------------------------------* - * HQ GENERIC BWE encoding + * HQ Generic BWE encoding *------------------------------------------------------------------*/ test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE - tmp_length = length; - move16(); - test(); - if ( st->element_mode == EVS_MONO && EQ_16( length, L_FRAME48k ) ) - { - tmp_length = L_SPEC48k; - move16(); - } - - hq_generic_hf_encoding_fx( st->element_mode, t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, tmp_length ); -#else hq_generic_hf_encoding_fx( st->element_mode, t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, length ); -#endif #else hq_generic_hf_encoding_fx( t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, length ); #endif @@ -455,7 +410,6 @@ void hq_hr_enc_ivas_fx( 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 */ - move16(); } map_hq_generic_fenv_norm_fx( hqswb_clas, hq_generic_fenv_fx, ynrm, normqlg2, num_env_bands, nb_sfm, hq_generic_offset ); @@ -466,15 +420,10 @@ void hq_hr_enc_ivas_fx( *------------------------------------------------------------------*/ #ifdef HARM_HQ_CORE - IF( st->element_mode == EVS_MONO ) - { - 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 + 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 - { - 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 ); - } /*------------------------------------------------------------------* * Normalize coefficients with quantized norms @@ -508,8 +457,8 @@ void hq_hr_enc_ivas_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 ); - move16(); } ELSE { @@ -518,8 +467,8 @@ void hq_hr_enc_ivas_fx( #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 ) ); - move16(); } test(); diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 730e277dd..a09ee38f9 100644 --- a/lib_enc/hq_lr_enc_fx.c +++ b/lib_enc/hq_lr_enc_fx.c @@ -206,7 +206,7 @@ void hq_lr_enc_fx( } ELSE { -#ifdef HARM_HQ_CORE_KEEP_EVS_BE +#ifdef HARM_HQ_CORE_KEEP_BE hqswb_clas_fx = peak_avrg_ratio_fx( HQ_BWE_CROSSOVER_BRATE, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ #else hqswb_clas_fx = peak_avrg_ratio_fx( st_fx->total_brate, L_t_audio, NUMC_N, &hHQ_core->mode_count, &hHQ_core->mode_count1, SWB_BWE_LR_Qs ); /* Q0 */ diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 92aee40f9..743e30218 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -445,7 +445,7 @@ Word16 peak_vq_enc_ivas_fx( } #ifdef HARM_HQ_CORE -#ifdef HARM_HQ_CORE_KEEP_EVS_BE +#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, pvq_inp_vector, fg_pred, EVS_MONO, HQ_CORE ); diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index c2d6c48ca..edf5a1f1b 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3683,6 +3683,7 @@ 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 */ @@ -3695,7 +3696,7 @@ Word16 hq_classifier_enc_ivas_fx( 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 */ -- GitLab From 8dd404af62a35dfa7f7d169a64d845f0e2ac3167 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 3 Mar 2026 08:33:20 +0100 Subject: [PATCH 26/31] Few fixes within HARM_HQ_CORE --- lib_dec/FEC_HQ_phase_ecu_fx.c | 4 ---- lib_dec/hq_core_dec_fx.c | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 4bb105f5e..e2ec9b45a 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -68,14 +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 * ); -#ifndef HARM_HQ_CORE static void peakfinder_fx( const Word16 *, const Word16, Word16 *, Word16 *, const Word16 ); -#endif static Word16 imax_fx( const Word16 *, const Word16 ); -#ifndef 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 ); 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 ); diff --git a/lib_dec/hq_core_dec_fx.c b/lib_dec/hq_core_dec_fx.c index 183987900..ee2633894 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1147,7 +1147,7 @@ void ivas_hq_core_dec_fx( } #ifdef HARM_HQ_CORE - IF( output_32_fx != NULL ) + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) #endif { /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ -- GitLab From 6d1c889b04e7d68bbb5f1bd56e7262996bf8ebd1 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 3 Mar 2026 08:57:33 +0100 Subject: [PATCH 27/31] Fixes to declarations --- lib_dec/FEC_HQ_phase_ecu_fx.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index e2ec9b45a..635b1f27e 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -68,10 +68,23 @@ 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 ); -- GitLab From 78a10bb80a6099cf71f25644cc9925ad62d0bacd Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 3 Mar 2026 16:03:51 +0100 Subject: [PATCH 28/31] Minor fixes under HARM_HQ_CORE --- lib_com/low_rate_band_att_fx.c | 14 +++++--------- lib_com/rom_com.h | 6 +++--- lib_com/rom_com_fx.c | 21 +++++++++++---------- lib_enc/peak_vq_enc_fx.c | 5 ++++- lib_enc/prot_fx_enc.h | 2 +- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 7a5a4d883..26cc9de5a 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -97,17 +97,13 @@ void ivas_fine_gain_pred_fx( } ELSE { -#endif - Word16 norm = norm_s( bw ); -#ifdef HARM_HQ_CORE - Word16 tmp_exp = sub( 15, norm ); + tmp1 = ivas_fine_gain_pred_sqrt_bw[bw_idx]; + } #else + Word16 norm = norm_s( bw ); Word16 tmp1, tmp_exp = sub( 15, norm ); -#endif - tmp1 = Sqrt16( shl( bw, norm ), &tmp_exp ); - tmp1 = shr( tmp1, sub( sub( 15, tmp_exp ), Q11 ) ); -#ifdef HARM_HQ_CORE - } + 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 */ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 272f8a8df..910d3b519 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1490,10 +1490,10 @@ 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 +extern const Word16 ivas_band_len_idx[]; // Q0 +extern const Word16 ivas_band_len_ener_shift[]; // Q0 #endif +extern const Word16 ivas_fine_gain_pred_sqrt_bw[]; // 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 diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index 8202ccdb5..4b0ff2594 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -25777,11 +25777,12 @@ const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 15 /* 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*/ -}; // Q0 -const Word16 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 */ -const Word16 fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ + /*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 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 */ +const Word16 fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ +const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5792, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ #else const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { // Q0 @@ -25792,11 +25793,11 @@ const Word16 band_len_ener_shift[8] = { 1, 2, 2, 2, 3, 3, 4 /*sfm==80*/, 4 /*sfm /*% 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 */ -const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ + /*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_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 743e30218..89d9a5681 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -19,7 +19,10 @@ 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 ); -#ifndef HARM_HQ_CORE +#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*/ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index edf5a1f1b..36bdc1f39 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -3585,7 +3585,7 @@ Word16 Pit_exc_contribution_len_fx( Word16 pvq_core_enc_fx( #ifdef HARM_HQ_CORE - const Word16 element_mode, + 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 */ -- GitLab From 6fca072f1221b7a3b3f1cb43a6fa293adb4c88d4 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Wed, 4 Mar 2026 15:34:10 +0100 Subject: [PATCH 29/31] Fixes for extended ACELP->HQ switching frame --- lib_com/low_rate_band_att_fx.c | 16 +++++++++++++++- lib_com/rom_com.h | 9 ++++++--- lib_com/rom_com_fx.c | 14 ++++++++------ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 26cc9de5a..c77f9d051 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -97,7 +97,21 @@ void ivas_fine_gain_pred_fx( } ELSE { - tmp1 = ivas_fine_gain_pred_sqrt_bw[bw_idx]; + IF( EQ_16( sfm_size[0], 10 ) ) + { + bw_idx = band_len_idx_ext[shr( bw, 3 )]; + tmp1 = fine_gain_pred_sqrt_bw_ext[bw_idx]; + } + ELSE + { + tmp1 = fine_gain_pred_sqrt_bw[bw_idx]; +#ifdef HARM_HQ_CORE_KEEP_BE + if ( EQ_16( bw_idx, 0 ) ) + { + tmp1--; /* Lookup table uses rounding while calculations use truncation */ + } +#endif + } } #else Word16 norm = norm_s( bw ); diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index 910d3b519..e247196a1 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1490,10 +1490,13 @@ 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_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 ivas_fine_gain_pred_sqrt_bw[]; // 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 diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index 4b0ff2594..1a8ce9fa2 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -25777,12 +25777,14 @@ const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 15 /* 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*/ -}; // Q0 -const Word16 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 */ -const Word16 fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ -const Word16 ivas_fine_gain_pred_sqrt_bw[9] = { 5792, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ + /*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 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 */ +const Word16 fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ +/* 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 -- GitLab From 83ecd58d794d23dc06810a4a283ae3141d1e4608 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 5 Mar 2026 08:21:13 +0100 Subject: [PATCH 30/31] Further fixes within HARM_HQ_CORE --- lib_com/ivas_prot_fx.h | 3 +-- lib_com/low_rate_band_att_fx.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib_com/ivas_prot_fx.h b/lib_com/ivas_prot_fx.h index f60b6c837..ca50a2082 100644 --- a/lib_com/ivas_prot_fx.h +++ b/lib_com/ivas_prot_fx.h @@ -1652,8 +1652,7 @@ Word16 ivas_assign_gain_bits_fx( Word16 *gain_bits_array, /* o : Assigned gain bits */ Word16 *Rcalc /* o : Bit budget for shape quantizer Q3 */ ); -#endif -#ifdef HARM_HQ_CORE + void ivas_fine_gain_pred_fx( const Word16 *sfm_start, /* i : Sub band start indices */ const Word16 *sfm_end, /* i : Sub band end indices */ diff --git a/lib_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index c77f9d051..350b6fad9 100644 --- a/lib_com/low_rate_band_att_fx.c +++ b/lib_com/low_rate_band_att_fx.c @@ -97,7 +97,7 @@ void ivas_fine_gain_pred_fx( } ELSE { - IF( EQ_16( sfm_size[0], 10 ) ) + IF( EQ_16( sfm_size[0], 10 ) ) /* If sfm_size[0] is 10, it means the extended ACELP->HQ transition frame is used. See hq_configure_fx(). */ { bw_idx = band_len_idx_ext[shr( bw, 3 )]; tmp1 = fine_gain_pred_sqrt_bw_ext[bw_idx]; -- GitLab From 80d8d7f9c58b4ed8fbb5d56737e9045463309114 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Thu, 5 Mar 2026 09:31:11 +0100 Subject: [PATCH 31/31] Clang format --- apps/encoder.c | 4 ++-- apps/encoder_fmtsw.c | 4 ++-- lib_com/basop_settings.h | 4 ++-- lib_com/lsf_tools_fx.c | 12 ++++++------ lib_com/prot_fx.h | 6 +++--- lib_com/pvq_com_fx.c | 2 +- lib_com/rom_com_fx.c | 10 +++++----- lib_com/swb_tbe_com_fx.c | 2 +- lib_com/tcq_position_arith_fx.c | 2 +- lib_dec/FEC_HQ_phase_ecu_fx.c | 2 +- lib_dec/FEC_clas_estim_fx.c | 2 +- lib_dec/amr_wb_dec_fx.c | 4 ++-- lib_dec/dec_tcx_fx.c | 2 +- lib_dec/evs_dec_fx.c | 2 +- lib_dec/ivas_dirac_dec_fx.c | 4 ++-- lib_dec/swb_tbe_dec_fx.c | 2 +- lib_dec/vlpc_2st_dec_fx.c | 8 ++++---- lib_enc/ACcontextMapping_enc_fx.c | 4 ++-- lib_enc/ari_enc_fx.c | 4 ++-- lib_enc/cod_ace_fx.c | 2 +- lib_enc/comvad_decision_fx.c | 2 +- lib_enc/cor_shif_fx.c | 2 +- lib_enc/core_enc_2div_fx.c | 2 +- lib_enc/corr_xh_fx.c | 2 +- lib_enc/enc_acelp_tcx_main_fx.c | 2 +- lib_enc/enc_nelp_fx.c | 2 +- lib_enc/enc_prm_fx.c | 2 +- lib_enc/energy_fx.c | 2 +- lib_enc/find_tilt_fx.c | 2 +- lib_enc/frame_spec_dif_cor_rate_fx.c | 2 +- lib_enc/hq_classifier_enc_fx.c | 2 +- lib_enc/igf_scf_enc_fx.c | 2 +- lib_enc/ivas_masa_enc_fx.c | 2 +- lib_enc/lsf_msvq_ma_enc_fx.c | 22 +++++++++++----------- lib_enc/ltd_stable_fx.c | 2 +- lib_enc/mdct_classifier_fx.c | 2 +- lib_enc/mdct_selector_fx.c | 2 +- lib_enc/nois_est_fx.c | 2 +- lib_enc/normalizecoefs_fx.c | 4 ++-- lib_enc/pitch_ol_fx.c | 6 +++--- lib_enc/plc_enc_ext_fx.c | 2 +- lib_enc/qlpc_avq_fx.c | 2 +- lib_enc/spec_center_fx.c | 2 +- lib_enc/spec_flatness_fx.c | 2 +- lib_enc/subband_fft_fx.c | 2 +- lib_enc/swb_bwe_enc_lr_fx.c | 2 +- lib_enc/tcx_utils_enc_fx.c | 2 +- lib_enc/tfa_enc_fx.c | 2 +- lib_enc/tns_base_enc_fx.c | 2 +- lib_enc/update_decision_fx.c | 2 +- lib_enc/updt_tar_fx.c | 2 +- lib_enc/vad_basop_fx.c | 2 +- lib_enc/vad_fx.c | 4 ++-- lib_enc/vad_proc_fx.c | 2 +- lib_enc/vlpc_2st_cod_fx.c | 2 +- lib_isar/isar_lc3plus_dec.h | 2 +- lib_isar/isar_lc3plus_enc.h | 2 +- lib_isar/isar_lcld_encoder.c | 6 +++--- lib_isar/isar_splitRend_lcld_dec.c | 2 +- lib_rend/ivas_objectRenderer_hrFilt_fx.c | 4 ++-- 60 files changed, 98 insertions(+), 98 deletions(-) diff --git a/apps/encoder.c b/apps/encoder.c index 9e10a9c5c..31d9b448c 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -55,10 +55,10 @@ rather than just defining _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does. */ #include #if !defined( S_ISREG ) && defined( S_IFMT ) && defined( S_IFREG ) -#define S_ISREG( m ) ( ( (m) &S_IFMT ) == S_IFREG ) +#define S_ISREG( m ) ( ( ( m ) & S_IFMT ) == S_IFREG ) #endif #if !defined( S_ISDIR ) && defined( S_IFMT ) && defined( S_IFDIR ) -#define S_ISDIR( m ) ( ( (m) &S_IFMT ) == S_IFDIR ) +#define S_ISDIR( m ) ( ( ( m ) & S_IFMT ) == S_IFDIR ) #endif #endif diff --git a/apps/encoder_fmtsw.c b/apps/encoder_fmtsw.c index 12cc57349..036144175 100644 --- a/apps/encoder_fmtsw.c +++ b/apps/encoder_fmtsw.c @@ -55,10 +55,10 @@ rather than just defining _S_IFMT, _S_IFREG, and _S_IFDIR as it normally does. */ #include #if !defined( S_ISREG ) && defined( S_IFMT ) && defined( S_IFREG ) -#define S_ISREG( m ) ( ( (m) &S_IFMT ) == S_IFREG ) +#define S_ISREG( m ) ( ( ( m ) & S_IFMT ) == S_IFREG ) #endif #if !defined( S_ISDIR ) && defined( S_IFMT ) && defined( S_IFDIR ) -#define S_ISDIR( m ) ( ( (m) &S_IFMT ) == S_IFDIR ) +#define S_ISDIR( m ) ( ( ( m ) & S_IFMT ) == S_IFDIR ) #endif #endif diff --git a/lib_com/basop_settings.h b/lib_com/basop_settings.h index 79544c078..6d1d513a2 100644 --- a/lib_com/basop_settings.h +++ b/lib_com/basop_settings.h @@ -59,13 +59,13 @@ \def Macro converts a float < 1 to Word32 fixed point with saturation and rounding */ #define FL2WORD32( val ) \ - ( Word32 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD32 ) ) ? (int32_t) ( MAXVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * (WORD32_FIX_SCALE) -0.5 ) <= (double) ( MINVAL_WORD32 ) ) ? (int32_t) ( MINVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) (WORD32_FIX_SCALE) -0.5 ) ) ) + ( Word32 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD32 ) ) ? (int32_t) ( MAXVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * ( WORD32_FIX_SCALE ) - 0.5 ) <= (double) ( MINVAL_WORD32 ) ) ? (int32_t) ( MINVAL_WORD32 ) : (int32_t) ( (double) ( val ) * (double) ( WORD32_FIX_SCALE ) - 0.5 ) ) ) /*! \def Macro converts a float < 1 to Word16 fixed point with saturation and rounding */ #define FL2WORD16( val ) \ - ( Word16 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD16 ) ) ? (int32_t) ( MAXVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * (WORD16_FIX_SCALE) -0.5 ) <= (double) ( MINVAL_WORD16 ) ) ? (int32_t) ( MINVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) (WORD16_FIX_SCALE) -0.5 ) ) ) + ( Word16 )( ( ( val ) >= 0 ) ? ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) + 0.5 ) >= (double) ( MAXVAL_WORD16 ) ) ? (int32_t) ( MAXVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) + 0.5 ) ) : ( ( ( (double) ( val ) * ( WORD16_FIX_SCALE ) - 0.5 ) <= (double) ( MINVAL_WORD16 ) ) ? (int32_t) ( MINVAL_WORD16 ) : (int32_t) ( (double) ( val ) * (double) ( WORD16_FIX_SCALE ) - 0.5 ) ) ) /*! \def Macro converts a Word32 fixed point to Word16 fixed point <1 with saturation diff --git a/lib_com/lsf_tools_fx.c b/lib_com/lsf_tools_fx.c index c1638a269..2882080ba 100644 --- a/lib_com/lsf_tools_fx.c +++ b/lib_com/lsf_tools_fx.c @@ -584,8 +584,8 @@ Word16 lpc2lsp_fx( tfreq[rc] = rt; rc = add( rc, 2 ); } /* end else, find Q root */ - } /* end for */ - } /* end else */ + } /* end for */ + } /* end else */ FOR( i = 0; i < order; i++ ) { @@ -729,8 +729,8 @@ Word16 lpc2lsp_ivas_fx( tfreq[rc] = rt; rc = add( rc, 2 ); } /* end else, find Q root */ - } /* end for */ - } /* end else */ + } /* end for */ + } /* end else */ FOR( i = 0; i < order; i++ ) { @@ -3547,7 +3547,7 @@ Word32 poscos_fx( Word16 w ) Lacc = L_sub( Lacc, L_shl( Ltemp, 1 ) ); /* Lacc=cos( w) in Q30 */ return L_negate( Lacc ); /* return -cos( w), Q30 */ - } /* end else */ + } /* end else */ } /*===================================================================*/ /* FUNCTION : root_search_fx ( ) */ @@ -3660,7 +3660,7 @@ Word16 root_search_fx( Word16 low, move16(); return ( add( round_fx( Ltemp ), shl( low, 6 ) ) ); } /* end else ( root in interval) */ - } /* end else ( exact root at high) */ + } /* end else ( exact root at high) */ /* find the exact root */ *v_low = v_high; diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index cd535be63..cf809cdeb 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -7360,8 +7360,8 @@ ivas_error amr_wb_dec_fx( Word16 output_sp[], /* o : synthesis output */ Word32 *mem_hp20_in_fx /* i/o: hp20 filter memory Qx*/ #else - Word16 output_sp[], /* o : synthesis output */ - Decoder_State *st_fx /* o : Decoder static variables structure */ + Word16 output_sp[], /* o : synthesis output */ + Decoder_State *st_fx /* o : Decoder static variables structure */ #endif ); @@ -10737,7 +10737,7 @@ void UnmapIndex_fx( Word32 *Lag /* Q0 */ ); -//#define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) +// #define GET_ADJ2( T, L, F ) ( ( ( L ) << ( F ) ) - ( T ) ) #define GET_ADJ2( T, L, F ) ( sub( shl( L, F ), T ) ) Word32 tcx_hm_render_fx( diff --git a/lib_com/pvq_com_fx.c b/lib_com/pvq_com_fx.c index 49a83bc7b..f86e66f60 100644 --- a/lib_com/pvq_com_fx.c +++ b/lib_com/pvq_com_fx.c @@ -440,7 +440,7 @@ void NearOppSplitAdjustment_fx( QuantaPerDsDirac_fx( Nhead, Midx, hBitsN, &qmin ); qskew = sub( qavg, qmin ); /* Q0 */ qskew = s_max( 0, qskew ); /* Q0 */ - } /* end of skew calc code*/ + } /* end of skew calc code*/ QIa = add( extract_l( intLimCDivPos_fx( (UWord32) L_deposit_l( Nopp ), Nnear ) ), 1 ); /* always positive Word16 out Q0*/ L_qnum = L_sub( L_deposit_l( sub( sub( add( qband, qzero ), qac ), qskew ) ), L_mult0( Nopp, oppRQ3 ) ); /* Q0 */ diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index 1a8ce9fa2..a5d801e00 100644 --- a/lib_com/rom_com_fx.c +++ b/lib_com/rom_com_fx.c @@ -25777,9 +25777,9 @@ const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 15 /* 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*/ -}; // Q0 + /*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 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 */ const Word16 fine_gain_pred_sqrt_bw[9] = { 5793, 8192, 10033, 11585, 12953, 14189, 16384, 18318, 20066 }; /* (Q11) */ /* 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: */ @@ -25797,8 +25797,8 @@ const Word16 fine_gain_pred_sqrt_bw[8] = { 5793, 8192, 10033, 11585, 14189, 1638 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 */ +}; // 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_tbe_com_fx.c b/lib_com/swb_tbe_com_fx.c index 8a9aad1a6..5e6c8c4ac 100644 --- a/lib_com/swb_tbe_com_fx.c +++ b/lib_com/swb_tbe_com_fx.c @@ -1493,7 +1493,7 @@ void GenShapedWBExcitation_ivas_fx( #ifdef HARMONIZE_TBE2 pow22 = L_add( pow22, L_shr( L_tmp, Q_pow ) ); /* Q22 */ #else - pow22 = L_add( pow22, L_shr( L_tmp, 10 ) ); /* Q22 */ + pow22 = L_add( pow22, L_shr( L_tmp, 10 ) ); /* Q22 */ #endif } } diff --git a/lib_com/tcq_position_arith_fx.c b/lib_com/tcq_position_arith_fx.c index f74aea076..431a509b1 100644 --- a/lib_com/tcq_position_arith_fx.c +++ b/lib_com/tcq_position_arith_fx.c @@ -1237,7 +1237,7 @@ Word32 GetISCScale_fx( *nzpout = nzposcurr; move16(); } /*magnitude coding */ - } /*TCQ */ + } /*TCQ */ IF( actualt_fx == 0 ) { diff --git a/lib_dec/FEC_HQ_phase_ecu_fx.c b/lib_dec/FEC_HQ_phase_ecu_fx.c index 635b1f27e..484e3ca2f 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -80,7 +80,7 @@ static void spec_ana_fx( const Word16 *prevsynth, Word16 *plocs, Word32 *plocsi, 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 ); +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 diff --git a/lib_dec/FEC_clas_estim_fx.c b/lib_dec/FEC_clas_estim_fx.c index f968ccb90..946f770e8 100644 --- a/lib_dec/FEC_clas_estim_fx.c +++ b/lib_dec/FEC_clas_estim_fx.c @@ -731,7 +731,7 @@ void FEC_clas_estim_fx( } } } /*if (Opt_AMR_WB)*/ - } /*if (codec_mode==MODE1)*/ + } /*if (codec_mode==MODE1)*/ } /* Do the classification only diff --git a/lib_dec/amr_wb_dec_fx.c b/lib_dec/amr_wb_dec_fx.c index 0eb145603..00347cac7 100644 --- a/lib_dec/amr_wb_dec_fx.c +++ b/lib_dec/amr_wb_dec_fx.c @@ -21,8 +21,8 @@ ivas_error amr_wb_dec_fx( Word16 output_sp[], /* o : synthesis output */ Word32 *mem_hp20_in_fx /* i/o: hp20 filter memory Qx*/ #else - Word16 output_sp[], /* o : synthesis output Q_syn2*/ - Decoder_State *st_fx /* o : Decoder static variables structure */ + Word16 output_sp[], /* o : synthesis output Q_syn2*/ + Decoder_State *st_fx /* o : Decoder static variables structure */ #endif ) { diff --git a/lib_dec/dec_tcx_fx.c b/lib_dec/dec_tcx_fx.c index 339826d53..0f5f1ec57 100644 --- a/lib_dec/dec_tcx_fx.c +++ b/lib_dec/dec_tcx_fx.c @@ -2267,7 +2267,7 @@ void IMDCT_fx( Word32 *x, Word16 x_e, Word16 *old_syn_overl, Word16 *syn_Overl_T tmp8, fullbandScale ); } /* TRANSITION_OVERLAP */ - } /* TCX-20 and TCX-only */ + } /* TCX-20 and TCX-only */ /* Window and overlap-add past frame if past frame is TCX */ test(); diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 421fc2652..84b5debb5 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -1356,7 +1356,7 @@ ivas_error evs_dec_fx( Scale_sig32( mem_hp20_in_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ hp20( synth_fx, 1 /*stride*/, output_frame, mem_hp20_in_fx, st_fx->output_Fs ); #else - Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ + Scale_sig32( st_fx->L_mem_hp_out_fx, 4, sub( Qpostd, Qpostd_prev ) ); /*Qpostd*/ hp20( synth_fx, 1 /*stride*/, output_frame, st_fx->L_mem_hp_out_fx, L_mult0( output_frame, 50 ) ); #endif diff --git a/lib_dec/ivas_dirac_dec_fx.c b/lib_dec/ivas_dirac_dec_fx.c index d61e3ff4b..f76354881 100644 --- a/lib_dec/ivas_dirac_dec_fx.c +++ b/lib_dec/ivas_dirac_dec_fx.c @@ -1895,8 +1895,8 @@ void ivas_qmetadata_to_dirac_fx( } /* for ( block =...) */ - } /* for ( band = ...) */ - } /* for ( idx_sec = ...)*/ + } /* for ( band = ...) */ + } /* for ( idx_sec = ...)*/ /* Bands not transmitted -> zeroed*/ FOR( b = band_grouping[band]; b < hSpatParamRendCom->num_freq_bands; b++ ) diff --git a/lib_dec/swb_tbe_dec_fx.c b/lib_dec/swb_tbe_dec_fx.c index 60f22396e..7a6ba9ac4 100644 --- a/lib_dec/swb_tbe_dec_fx.c +++ b/lib_dec/swb_tbe_dec_fx.c @@ -3763,7 +3763,7 @@ static void dequantizeSHBparams_fx( { *Q_framegrain = L_mac( SHB_GAIN_QLOW_FX, idxFrameGain, SHB_GAIN_QDELTA_FX ); move32(); - } /*Q18*/ + } /*Q18*/ L_tmp = Mult_32_16( *Q_framegrain, 27213 ); /*Q16*/ /* 3.321928 in Q13 */ frac = L_Extract_lc( L_tmp, &exp ); L_tmp = Pow2( 30, frac ); diff --git a/lib_dec/vlpc_2st_dec_fx.c b/lib_dec/vlpc_2st_dec_fx.c index 562cce4cf..cb654c4ff 100644 --- a/lib_dec/vlpc_2st_dec_fx.c +++ b/lib_dec/vlpc_2st_dec_fx.c @@ -6,9 +6,9 @@ #include #include "options.h" #include "prot_fx.h" -//#ifdef DEBUGGING to be removed +// #ifdef DEBUGGING to be removed #include -//#endif +// #endif void vlpc_2st_dec( Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage 14Q1*1.28*/ @@ -33,9 +33,9 @@ void vlpc_2st_dec( FOR( i = 0; i < M; i++ ) { - //#ifdef DEBUGGING to be removed + // #ifdef DEBUGGING to be removed assert( abs_s( xq[i] ) <= 32 ); /* If xq > 32 for IVAS, we might need a different loop implementation */ - //#endif + // #endif lsfq[i] = add( lsfq[i], shl( mult_r( w[i], shl_sat( xq[i], 10 ) ), 2 ) ); /*14Q1*1.28*/ move16(); } diff --git a/lib_enc/ACcontextMapping_enc_fx.c b/lib_enc/ACcontextMapping_enc_fx.c index f9e2d919c..eca622dd0 100644 --- a/lib_enc/ACcontextMapping_enc_fx.c +++ b/lib_enc/ACcontextMapping_enc_fx.c @@ -1419,7 +1419,7 @@ Word16 RCcontextMapping_encode2_estimate_no_mem_s17_LCS_fx( } } - } /*end of the 2-tuples loop*/ + } /*end of the 2-tuples loop*/ total_output_bits = round_fx( W_shl_sat_l( bit_estimate_fx, -Q7 ) ); /* Q23 -> Q16 -> Q0 */ IF( *stop ) { @@ -1794,7 +1794,7 @@ Word16 RCcontextMapping_encode2_estimate_bandWise_fx( hContextMem->ctx = add( i_mult( s_and( hContextMem->ctx, 0xf ), 16 ), t ); /* Q0 */ move16(); - } /*end of the 2-tuples loop*/ + } /*end of the 2-tuples loop*/ total_output_bits = round_fx( W_shl_sat_l( hContextMem->bit_estimate_fx, -Q7 ) ); /* Q0 */ // total_output_bits = (Word16) ( hContextMem->bit_estimate + 0.5f ); diff --git a/lib_enc/ari_enc_fx.c b/lib_enc/ari_enc_fx.c index 0c44f113e..45e03cb64 100644 --- a/lib_enc/ari_enc_fx.c +++ b/lib_enc/ari_enc_fx.c @@ -5,10 +5,10 @@ #include #include "assert.h" #include "options.h" -//#include "basop_mpy.h" +// #include "basop_mpy.h" #include "cnst.h" #include "rom_com.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/cod_ace_fx.c b/lib_enc/cod_ace_fx.c index 92b08554e..7b32f789e 100644 --- a/lib_enc/cod_ace_fx.c +++ b/lib_enc/cod_ace_fx.c @@ -6,7 +6,7 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "basop_util.h" #include "options.h" #include "rom_basop_util.h" diff --git a/lib_enc/comvad_decision_fx.c b/lib_enc/comvad_decision_fx.c index 479781d27..dafa4561c 100644 --- a/lib_enc/comvad_decision_fx.c +++ b/lib_enc/comvad_decision_fx.c @@ -8,7 +8,7 @@ #include "cnst.h" /* Common constants */ #include "basop_util.h" #include "vad_basop.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_enc.h" /* Encoder static table prototypes */ #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ diff --git a/lib_enc/cor_shif_fx.c b/lib_enc/cor_shif_fx.c index 5e4214552..c98afa1ee 100644 --- a/lib_enc/cor_shif_fx.c +++ b/lib_enc/cor_shif_fx.c @@ -4,7 +4,7 @@ #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +// #include "prot_fx.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/core_enc_2div_fx.c b/lib_enc/core_enc_2div_fx.c index 45aba6a05..dbc7d44ec 100644 --- a/lib_enc/core_enc_2div_fx.c +++ b/lib_enc/core_enc_2div_fx.c @@ -8,7 +8,7 @@ #include "options.h" #include "cnst.h" /* Common constants */ #include "ivas_cnst.h" /* Common constants */ -//#include "prot_fx.h" +// #include "prot_fx.h" #include "basop_util.h" #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ diff --git a/lib_enc/corr_xh_fx.c b/lib_enc/corr_xh_fx.c index 4f0614fba..14bd84b79 100644 --- a/lib_enc/corr_xh_fx.c +++ b/lib_enc/corr_xh_fx.c @@ -4,7 +4,7 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/enc_acelp_tcx_main_fx.c b/lib_enc/enc_acelp_tcx_main_fx.c index b3bd7d112..44108f56c 100644 --- a/lib_enc/enc_acelp_tcx_main_fx.c +++ b/lib_enc/enc_acelp_tcx_main_fx.c @@ -4,7 +4,7 @@ #include #include "options.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "cnst.h" /* Common constants */ #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ diff --git a/lib_enc/enc_nelp_fx.c b/lib_enc/enc_nelp_fx.c index 5181a08ff..7eaccfcea 100644 --- a/lib_enc/enc_nelp_fx.c +++ b/lib_enc/enc_nelp_fx.c @@ -5,7 +5,7 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +// #include "prot_fx.h" /* Function prototypes */ #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/enc_prm_fx.c b/lib_enc/enc_prm_fx.c index f72a955a8..c138f0e21 100644 --- a/lib_enc/enc_prm_fx.c +++ b/lib_enc/enc_prm_fx.c @@ -686,7 +686,7 @@ void enc_prm_fx( n = ACELP_GAINS_BITS[st->acelp_cfg.gains_mode[sfr]]; push_next_indice( hBstr, prm[j++], n ); } /*end of for(sfr)*/ - } /*end of mode[0]==0*/ + } /*end of mode[0]==0*/ /*--------------------------------------------------------------------------------* diff --git a/lib_enc/energy_fx.c b/lib_enc/energy_fx.c index 53cda71c1..b81412ead 100644 --- a/lib_enc/energy_fx.c +++ b/lib_enc/energy_fx.c @@ -8,7 +8,7 @@ #include "basop_util.h" #include "rom_enc.h" #include "vad_basop.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/find_tilt_fx.c b/lib_enc/find_tilt_fx.c index 56ea1e9dd..ef0f639a9 100644 --- a/lib_enc/find_tilt_fx.c +++ b/lib_enc/find_tilt_fx.c @@ -4,7 +4,7 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -//#include "prot_fx.h" /* Function prototypes */ +// #include "prot_fx.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" diff --git a/lib_enc/frame_spec_dif_cor_rate_fx.c b/lib_enc/frame_spec_dif_cor_rate_fx.c index 54e6148af..ea810ab67 100644 --- a/lib_enc/frame_spec_dif_cor_rate_fx.c +++ b/lib_enc/frame_spec_dif_cor_rate_fx.c @@ -8,7 +8,7 @@ #include "cnst.h" #include "basop_util.h" #include "vad_basop.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/hq_classifier_enc_fx.c b/lib_enc/hq_classifier_enc_fx.c index d682402cc..d674cc30e 100644 --- a/lib_enc/hq_classifier_enc_fx.c +++ b/lib_enc/hq_classifier_enc_fx.c @@ -289,7 +289,7 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits /* o : Consumed bits Q0 */ Word16 hq_classifier_enc_fx( #else -Word16 hq_classifier_enc_ivas_fx( /* o : Consumed bits Q0 */ +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 */ diff --git a/lib_enc/igf_scf_enc_fx.c b/lib_enc/igf_scf_enc_fx.c index d1341a98a..909381fbb 100644 --- a/lib_enc/igf_scf_enc_fx.c +++ b/lib_enc/igf_scf_enc_fx.c @@ -5,7 +5,7 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "stat_enc.h" #include "stat_com.h" #include "basop_util.h" diff --git a/lib_enc/ivas_masa_enc_fx.c b/lib_enc/ivas_masa_enc_fx.c index 3b30558be..cc4a3bf5a 100644 --- a/lib_enc/ivas_masa_enc_fx.c +++ b/lib_enc/ivas_masa_enc_fx.c @@ -3792,7 +3792,7 @@ static void masa_metadata_direction_alignment_fx( move16(); } } /* sf */ - } /* band */ + } /* band */ return; } diff --git a/lib_enc/lsf_msvq_ma_enc_fx.c b/lib_enc/lsf_msvq_ma_enc_fx.c index 2f9f2b7c7..640f1eccd 100644 --- a/lib_enc/lsf_msvq_ma_enc_fx.c +++ b/lib_enc/lsf_msvq_ma_enc_fx.c @@ -860,8 +860,8 @@ void msvq_enc_fx( p_max = ( *func_ptr )( dist[1] ); } /*IF (L_sub(tmp,dist[1][p_max]) < 0) */ - } /* FOR (c=0; c #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_com.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/mdct_selector_fx.c b/lib_enc/mdct_selector_fx.c index bc502d49f..b6de7a5d2 100644 --- a/lib_enc/mdct_selector_fx.c +++ b/lib_enc/mdct_selector_fx.c @@ -5,7 +5,7 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_com.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/nois_est_fx.c b/lib_enc/nois_est_fx.c index ff6784c4e..f3373dc01 100644 --- a/lib_enc/nois_est_fx.c +++ b/lib_enc/nois_est_fx.c @@ -7,7 +7,7 @@ #include "options.h" #include "cnst.h" #include "rom_com.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" diff --git a/lib_enc/normalizecoefs_fx.c b/lib_enc/normalizecoefs_fx.c index 89bfadac5..4b126e2dc 100644 --- a/lib_enc/normalizecoefs_fx.c +++ b/lib_enc/normalizecoefs_fx.c @@ -4,8 +4,8 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" /* Common constants */ -//#include "basop_mpy.h" -//#include "prot_fx.h" +// #include "basop_mpy.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/pitch_ol_fx.c b/lib_enc/pitch_ol_fx.c index 571b73500..99603eb93 100644 --- a/lib_enc/pitch_ol_fx.c +++ b/lib_enc/pitch_ol_fx.c @@ -774,7 +774,7 @@ void pitch_ol_fx( exp_sect1[j] = ind1; move16(); } /* IF (k >= 0) */ - } /* FOR (j = subsect0; ... */ + } /* FOR (j = subsect0; ... */ } ELSE /* 3rd half-frame (look-ahead) */ { @@ -1118,7 +1118,7 @@ void pitch_ol_fx( offset1 = add( offset1, sec_length1[j] ); } /* FOR j < NSECT */ - } /* FOR i < NHFR */ + } /* FOR i < NHFR */ pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, EVS_MONO, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); @@ -1832,7 +1832,7 @@ void pitch_ol_ivas_fx( offset1 = add( offset1, sec_length1[j] ); } /* FOR j < NSECT */ - } /* FOR i < NHFR */ + } /* FOR i < NHFR */ pitch_ol_resolve_fx( pitch, voicing, old_pitch, old_corr, old_thres, delta_pit, IVAS_SCE, corr_shift, relE, Opt_SC_VBR, pitchX, corX, scaledX, sect0, pit_max, pit_min_coding ); /* any element mode other than EVS_MONO is OK here */ return; diff --git a/lib_enc/plc_enc_ext_fx.c b/lib_enc/plc_enc_ext_fx.c index 6e9571442..fa5f85f8c 100644 --- a/lib_enc/plc_enc_ext_fx.c +++ b/lib_enc/plc_enc_ext_fx.c @@ -7,7 +7,7 @@ #include "options.h" #include "cnst.h" #include "stat_enc.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_com.h" /* Common constants */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/qlpc_avq_fx.c b/lib_enc/qlpc_avq_fx.c index 5d4d93fdf..ab6d62658 100644 --- a/lib_enc/qlpc_avq_fx.c +++ b/lib_enc/qlpc_avq_fx.c @@ -7,7 +7,7 @@ #include #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_com.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/spec_center_fx.c b/lib_enc/spec_center_fx.c index 78af3cda3..b628ea0f5 100644 --- a/lib_enc/spec_center_fx.c +++ b/lib_enc/spec_center_fx.c @@ -6,7 +6,7 @@ #include "options.h" #include "basop_util.h" #include "vad_basop.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_enc.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/spec_flatness_fx.c b/lib_enc/spec_flatness_fx.c index ba8838e05..89102d926 100644 --- a/lib_enc/spec_flatness_fx.c +++ b/lib_enc/spec_flatness_fx.c @@ -8,7 +8,7 @@ #include "options.h" #include "basop_util.h" #include "vad_basop.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/subband_fft_fx.c b/lib_enc/subband_fft_fx.c index daf9048a4..7026f2603 100644 --- a/lib_enc/subband_fft_fx.c +++ b/lib_enc/subband_fft_fx.c @@ -7,7 +7,7 @@ #include "options.h" #include "basop_util.h" #include "vad_basop.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_enc.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/swb_bwe_enc_lr_fx.c b/lib_enc/swb_bwe_enc_lr_fx.c index 843efcf49..794d0b4b2 100644 --- a/lib_enc/swb_bwe_enc_lr_fx.c +++ b/lib_enc/swb_bwe_enc_lr_fx.c @@ -863,7 +863,7 @@ static void EncodeSWBSubbands_fx( Word16 ss_min_fx; /* Qss */ Word32 L_th_g[NB_SWB_SUBBANDS]; Word16 QbeL; - GainItem_fx pk_sf_fx[(NB_SWB_SUBBANDS) *8]; + GainItem_fx pk_sf_fx[( NB_SWB_SUBBANDS ) * 8]; Word16 pul_res_fx[NB_SWB_SUBBANDS]; GainItem_fx Nbiggest_fx[NB_SWB_SUBBANDS * N_NBIGGEST_PULSEARCH]; diff --git a/lib_enc/tcx_utils_enc_fx.c b/lib_enc/tcx_utils_enc_fx.c index 9765655ba..c751ebc65 100644 --- a/lib_enc/tcx_utils_enc_fx.c +++ b/lib_enc/tcx_utils_enc_fx.c @@ -9,7 +9,7 @@ #include "stl.h" #include "options.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "rom_basop_util.h" #include "basop_util.h" #include "rom_com.h" diff --git a/lib_enc/tfa_enc_fx.c b/lib_enc/tfa_enc_fx.c index 60427f792..baea8b4f9 100644 --- a/lib_enc/tfa_enc_fx.c +++ b/lib_enc/tfa_enc_fx.c @@ -6,7 +6,7 @@ #include "options.h" #include "basop_util.h" #include "cnst.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/tns_base_enc_fx.c b/lib_enc/tns_base_enc_fx.c index 36880d3d5..6bc31dd0a 100644 --- a/lib_enc/tns_base_enc_fx.c +++ b/lib_enc/tns_base_enc_fx.c @@ -5,7 +5,7 @@ #include "options.h" #include "cnst.h" #include "stl.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "basop_util.h" #include "stl.h" #include diff --git a/lib_enc/update_decision_fx.c b/lib_enc/update_decision_fx.c index 67476f993..e25e4d50c 100644 --- a/lib_enc/update_decision_fx.c +++ b/lib_enc/update_decision_fx.c @@ -7,7 +7,7 @@ #include "options.h" #include "basop_util.h" #include "vad_basop.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ /*-------------------------------------------------------------------* diff --git a/lib_enc/updt_tar_fx.c b/lib_enc/updt_tar_fx.c index b379f24ef..b875a7ee4 100644 --- a/lib_enc/updt_tar_fx.c +++ b/lib_enc/updt_tar_fx.c @@ -4,7 +4,7 @@ #include #include "options.h" /* Compilation switches */ #include "cnst.h" -//#include "prot_fx.h" /* Function prototypes */ +// #include "prot_fx.h" /* Function prototypes */ #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ diff --git a/lib_enc/vad_basop_fx.c b/lib_enc/vad_basop_fx.c index 3436a1d68..c4a5705c2 100644 --- a/lib_enc/vad_basop_fx.c +++ b/lib_enc/vad_basop_fx.c @@ -4,7 +4,7 @@ #include #include "options.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "vad_basop.h" diff --git a/lib_enc/vad_fx.c b/lib_enc/vad_fx.c index 7c5414780..63c8bfeb0 100644 --- a/lib_enc/vad_fx.c +++ b/lib_enc/vad_fx.c @@ -1534,7 +1534,7 @@ Word16 wb_vad_fx( } thr1 = thr1_nb_mod; move16(); /* needed for st_fx->vadnoise_fx update below */ - } /* end of NB */ + } /* end of NB */ /* *flag_noisy_speech_snr is a Word8 parameter */ @@ -2809,7 +2809,7 @@ Word16 wb_vad_ivas_fx( } thr1 = thr1_nb_mod; move16(); /* needed for st_fx->vadnoise_fx update below */ - } /* end of NB */ + } /* end of NB */ /* *flag_noisy_speech_snr is a Word8 parameter */ diff --git a/lib_enc/vad_proc_fx.c b/lib_enc/vad_proc_fx.c index 62469f3a7..b3aac988c 100644 --- a/lib_enc/vad_proc_fx.c +++ b/lib_enc/vad_proc_fx.c @@ -8,7 +8,7 @@ #include "cnst.h" #include "basop_util.h" #include "vad_basop.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "stat_enc.h" #include "rom_enc.h" #include "rom_com.h" /* Common constants */ diff --git a/lib_enc/vlpc_2st_cod_fx.c b/lib_enc/vlpc_2st_cod_fx.c index 32ab21877..780e0e89e 100644 --- a/lib_enc/vlpc_2st_cod_fx.c +++ b/lib_enc/vlpc_2st_cod_fx.c @@ -6,7 +6,7 @@ #include "options.h" #include "cnst.h" #include "options.h" -//#include "prot_fx.h" +// #include "prot_fx.h" #include "prot_fx.h" /* Function prototypes */ #include "prot_fx_enc.h" /* Function prototypes */ #include "basop_util.h" diff --git a/lib_isar/isar_lc3plus_dec.h b/lib_isar/isar_lc3plus_dec.h index 461e15dc8..6f469f48b 100644 --- a/lib_isar/isar_lc3plus_dec.h +++ b/lib_isar/isar_lc3plus_dec.h @@ -76,7 +76,7 @@ typedef struct ISAR_LC3PLUS_DEC_HANDLE int16_t *pcm_conversion_buffer; uint8_t *scratch; LC3PLUS_CONFIG config; -} * ISAR_LC3PLUS_DEC_HANDLE; +} *ISAR_LC3PLUS_DEC_HANDLE; ivas_error ISAR_LC3PLUS_DEC_Open( const LC3PLUS_CONFIG config, /* i : decoder configuration */ diff --git a/lib_isar/isar_lc3plus_enc.h b/lib_isar/isar_lc3plus_enc.h index 793da7b9f..5ce87a91f 100644 --- a/lib_isar/isar_lc3plus_enc.h +++ b/lib_isar/isar_lc3plus_enc.h @@ -51,7 +51,7 @@ typedef struct ISAR_LC3PLUS_ENC_HANDLE int32_t num_ftds; LC3PLUS_RTP_FDL fdl_request; uint8_t *scratch; -} * ISAR_LC3PLUS_ENC_HANDLE; +} *ISAR_LC3PLUS_ENC_HANDLE; ivas_error ISAR_LC3PLUS_ENC_Open( const LC3PLUS_CONFIG config, /* i : encoder configuration */ diff --git a/lib_isar/isar_lcld_encoder.c b/lib_isar/isar_lcld_encoder.c index 9b33cc653..5b34a4ff3 100644 --- a/lib_isar/isar_lcld_encoder.c +++ b/lib_isar/isar_lcld_encoder.c @@ -1431,7 +1431,7 @@ static void QuantizeSpectrumDPCM_Opt( fImag_fx ); iBlockOffset++; } /* group length */ - } /* groups */ + } /* groups */ pfPredStateReal_fx[iFBOffset] = fPrevReal_fx; move32(); pfPredStateImag_fx[iFBOffset] = fPrevImag_fx; @@ -1466,8 +1466,8 @@ static void QuantizeSpectrumDPCM_Opt( iBlockOffset++; } /* group length */ - } /* groups */ - } /* predEnable */ + } /* groups */ + } /* predEnable */ iFBOffset++; } /* bandwidth */ } diff --git a/lib_isar/isar_splitRend_lcld_dec.c b/lib_isar/isar_splitRend_lcld_dec.c index b4047a750..8fb28c90b 100644 --- a/lib_isar/isar_splitRend_lcld_dec.c +++ b/lib_isar/isar_splitRend_lcld_dec.c @@ -36,7 +36,7 @@ #include "ivas_prot_fx.h" #include "prot_fx.h" #include "prot_fx.h" -//#include "control.h" +// #include "control.h" #ifdef DEBUGGING #include "debug.h" #endif diff --git a/lib_rend/ivas_objectRenderer_hrFilt_fx.c b/lib_rend/ivas_objectRenderer_hrFilt_fx.c index 7426c3688..2a81e28a8 100644 --- a/lib_rend/ivas_objectRenderer_hrFilt_fx.c +++ b/lib_rend/ivas_objectRenderer_hrFilt_fx.c @@ -663,7 +663,7 @@ static void getPeriodicBSplineSampVec_fx( #ifdef FIX_2235_TD_RENDERER_WORD16 const Word16 *azimBsShape_fx, /* i : Basis shape Q15 */ #else - const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ + const Word32 *azimBsShape_fx, /* i : Basis shape Q30 */ #endif const Word16 subSampFactor /* i : Subsampling factor */ ) @@ -755,7 +755,7 @@ static void getStandardBSplineSampVec_fx( const Word16 *KSeq_fx, /* i : knot sequence including multiplicities Q KSeq_Q_fx */ const Word16 KSeq_Q_fx, /* i : Q-value of knot sequence */ #else - const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ + const Word32 *KSeq_fx, /* i : knot sequence including multiplicities Q22 */ #endif const Word16 SegSamples, /* i : samples per segment */ const Word16 *BsLen, /* i : lengths of basis shapes */ -- GitLab