diff --git a/lib_com/fill_spectrum_fx.c b/lib_com/fill_spectrum_fx.c index e41eca0af2046898dae1c160b152c3d5e6850b3f..7353485a60939631c22b9c9f08b18948e290e351 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/fine_gain_bits_fx.c b/lib_com/fine_gain_bits_fx.c index b6846372c6ee1434a1222e798335f46eb24439ca..d982b94e2cdd13859b5f3fc13339d09b79ddfcb7 100644 --- a/lib_com/fine_gain_bits_fx.c +++ b/lib_com/fine_gain_bits_fx.c @@ -14,7 +14,11 @@ * * HQ core encoder *--------------------------------------------------------------------------*/ + 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 */ @@ -30,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 ); @@ -60,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; @@ -75,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 { @@ -101,7 +123,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 +205,4 @@ Word16 ivas_assign_gain_bits_fx( /* o : Number of ass return gain_bits_tot; } +#endif diff --git a/lib_com/hq_bit_allocation_fx.c b/lib_com/hq_bit_allocation_fx.c index c1efb9def8e6cd00471c788298241b93679727aa..29d281cfd7d7ef761f006fbc4a63a927d9a92da3 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/hq_conf_fx.c b/lib_com/hq_conf_fx.c index b114745b591caa955966d47245c24eaccfac0a75..9450e6314c9f613f663f0ac349ad268484f0800a 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/hq_tools_fx.c b/lib_com/hq_tools_fx.c index cc5f483eadb9af737c0a99fb6d02eb3111bfb0c8..c93c6a20e7b0b50854347a7dfc8567579a0c5bb1 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; @@ -808,7 +812,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 +976,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 +1143,7 @@ void harm_bwe_fx( } return; } +#endif /*--------------------------------------------------------------------------* * HVQ_bwe_fx() @@ -1486,11 +1497,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*/ @@ -1531,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 */ @@ -1582,6 +1603,8 @@ void noise_mix_fx( move32(); } } + + return; } @@ -1590,6 +1613,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 +1651,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 +1705,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 */ @@ -1787,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; @@ -1816,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*/ @@ -1860,6 +1900,8 @@ Word16 get_nor_delta_hf_fx( } return add_bits_denv; } + +#ifndef HARM_HQ_CORE /*-------------------------------------------------------------------* * calc_nor_delta_hf() * @@ -1956,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*/ @@ -1979,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 ) @@ -2050,6 +2095,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 +2105,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*/ @@ -2088,8 +2135,14 @@ void hq_bwe_fx( 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,16 +2162,20 @@ 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 ); return; } + /*--------------------------------------------------------------------------* * hq_wb_nf_bwe() * @@ -2537,6 +2594,7 @@ void hq_wb_nf_bwe_fx( return; } + /*--------------------------------------------------------------------------* * enforce_zero_for_min_envelope_fx() * @@ -2581,6 +2639,8 @@ void enforce_zero_for_min_envelope_fx( return; } + + /*--------------------------------------------------------------------------* * apply_envelope() * @@ -2616,10 +2676,10 @@ void apply_envelope_enc_ivas_fx( } } - return; } + /*--------------------------------------------------------------------------* * apply_envelope() * @@ -2716,6 +2776,5 @@ void apply_envelope_fx( } } - return; } diff --git a/lib_com/interleave_spectrum_fx.c b/lib_com/interleave_spectrum_fx.c index 8847b9f5b2cf36b5a39aa2f690132efe209f9b34..1ad331a5bf67d9c9b7437d5f5e298b298dffac59 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_CORE { 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_CORE +void de_interleave_spectrum_fx( +#else void ivas_de_interleave_spectrum_fx( +#endif Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ ) @@ -307,6 +325,7 @@ void ivas_de_interleave_spectrum_fx( return; } +#ifndef HARM_HQ_CORE void de_interleave_spectrum_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ @@ -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 b8feba23dae54fb3a21c8b3742838a6257903736..8b8f12f43140553fb220cffa3ef13942d1a4b57d 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_CORE void ivas_hq_core_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ Word16 synth[], /* o : output synthesis */ @@ -1666,7 +1667,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, @@ -1683,6 +1684,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 */ @@ -1775,7 +1777,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/logqnorm_fx.c b/lib_com/logqnorm_fx.c index 4b096ac35a52c814559eca58cea6e97a66976fe3..20e76f4974a5a3310bc888e83d7b860ae54cafa5 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_com/low_rate_band_att_fx.c b/lib_com/low_rate_band_att_fx.c index 8e7cef9d13cd272662af48fb8ae20b4ab37eb8b8..350b6fad951c1596fd7a0cf0ad547ada59304f8a 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_CORE +void fine_gain_pred_fx( +#else void ivas_fine_gain_pred_fx( +#endif const Word16 *sfm_start, /* i : Sub band start indices */ const Word16 *sfm_end, /* i : Sub band end indices */ const Word16 *sfm_size, /* i : Sub band bandwidths */ @@ -24,9 +29,12 @@ 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 */ - const Word16 core /* i : Core */ +#ifdef HARM_HQ_CORE + const Word16 element_mode, /* i : element mode */ +#endif + const Word16 core /* i : Core */ ) { Word16 i, band; @@ -34,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; @@ -51,10 +61,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++ ) { @@ -71,12 +89,37 @@ 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 */ + +#ifdef HARM_HQ_CORE + IF( element_mode == EVS_MONO ) + { + tmp1 = fine_gain_pred_sqrt_bw[bw_idx]; + } + ELSE + { + 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]; + } + 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 ); 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 */ - +#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(); test(); @@ -125,6 +168,7 @@ void ivas_fine_gain_pred_fx( return; } +#ifndef HARM_HQ_CORE void fine_gain_pred_fx( const Word16 *sfm_start, /* i : Sub band start indices */ const Word16 *sfm_end, /* i : Sub band end indices */ @@ -228,6 +272,7 @@ void fine_gain_pred_fx( return; } +#endif /*--------------------------------------------------------------------------* * get_max_pulses() @@ -275,6 +320,7 @@ void get_max_pulses_fx( return; } + /*--------------------------------------------------------------------------* * fine_gain_dec() * @@ -296,7 +342,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/options.h b/lib_com/options.h index b2727be5ac198886445ef794e1411432b5daf421..dd5034c929face931c707a25699bef0a9952a1e2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -83,6 +83,8 @@ #define FIX_1990_SANITIZER_IN_REVERB_LOAD /* Nokia: Fix issue part of issue 1990 by introducing missing free of structure - keep until #2059 is addressed */ #define TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR /* FhG: Temporary workaround for incorrect implementation of decoder flush with split rendering */ #define NONBE_1122_KEEP_EVS_MODE_UNCHANGED /* FhG: Disables fix for issue 1122 in EVS mode to keep BE tests green. This switch should be removed once the 1122 fix is added to EVS via a CR. */ +#define HARM_HQ_CORE /* harmonize HQ core functions */ +#define HARM_HQ_CORE_KEEP_BE /* hack to keep all BE after HQ core functions harmonization; pending resolving issues #2450, #2451, #2452 */ #define HARMONIZE_TBE3 /* VA: basop issue 2399: Remove duplicated code: TBE, step 3 */ #define FIX_2459_USAN_AMR_SIDSTART /* FhG: basop issue 2459: fix msan complaint */ #define FIX_2458_USAN_NULLPTR_WITH_ZERO_OFFSET /* FhG: basop issue 2458: avoid indexing into null pointer */ diff --git a/lib_com/prot_fx.h b/lib_com/prot_fx.h index b7f81c48411f88811e36cff386700ef007686f62..f678394227320346ea2bcf74b2dc12bcb9fdde8f 100644 --- a/lib_com/prot_fx.h +++ b/lib_com/prot_fx.h @@ -274,6 +274,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 */ @@ -283,7 +284,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 */ @@ -383,6 +384,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 */ @@ -392,6 +396,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 */ @@ -401,7 +406,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 */ @@ -606,6 +611,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 */ @@ -617,7 +623,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 */ @@ -656,6 +662,7 @@ Word16 calc_nor_delta_hf_fx( const Word16 core_sfm /* i : index of the end band for core */ ); +#ifndef HARM_HQ_CORE Word16 calc_nor_delta_hf_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word32 *t_audio, /* i : transform-domain coefficients Qx*/ @@ -680,8 +687,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 */ @@ -1369,7 +1381,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 */ @@ -1385,6 +1396,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 */ @@ -1399,8 +1411,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 */ @@ -1586,11 +1597,12 @@ void interleave_spectrum_fx( const Word16 length /* i : length of spectrum Q0 */ ); +#ifndef HARM_HQ_CORE void interleave_spectrum_ivas_fx( Word32 *coefs, /* i/o: input and output coefficients Q12 */ const Word16 length /* i : length of spectrum Q0 */ ); - +#endif /* o : impulse response energy Q3 */ Word16 findpulse_fx( const Word16 L_frame, /* i : length of the frame */ @@ -4564,7 +4576,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_CORE + const Word16 element_mode, /* i : element mode */ +#endif + const Word16 core /* i : Core */ ); void fine_gain_quant_fx( @@ -4594,8 +4609,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 */ @@ -6640,6 +6658,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, @@ -6654,7 +6673,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 */ @@ -6935,6 +6954,7 @@ void fd_bwe_dec_init( FD_BWE_DEC_HANDLE hBWE_FD /* i/o: FD BWE data handle */ ); +#ifndef HARM_HQ_CORE void hq_core_enc_ivas_fx( Encoder_State *st, /* i/o: encoder state structure */ const Word16 *audio_fx, /* i : input audio signal Q0 */ @@ -6943,14 +6963,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_CORE + const Word16 core_switching_flag, /* i : ACELP->HQ switching frame flag */ + Word32 *output_32_fx /* o : synthesis @internal_Fs, Q11 */ +#else const Word16 core_switching_flag /* i : ACELP->HQ switching frame flag Q0*/ +#endif ); void HQ_core_dec_init_fx( @@ -9975,6 +10000,9 @@ void IGFEncConcatenateBitstream( ); void hq_generic_hf_encoding_fx( +#ifdef HARM_HQ_CORE + const Word16 element_mode, /* i : element mode */ +#endif const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original */ Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope */ const Word16 hq_generic_offset, /* i : frequency offset for extracting energy */ diff --git a/lib_com/rom_com.h b/lib_com/rom_com.h index a61ee76afeba95bcb1b93347b81311a7e45e897f..e247196a164906eb127a49f69b4c971d1bc936f1 100644 --- a/lib_com/rom_com.h +++ b/lib_com/rom_com.h @@ -1486,12 +1486,17 @@ extern const Word16 tab_hup_l_fx[]; // Q15 extern const Word16 mfreq_loc_Q2fx[]; // Q0 extern const Word16 mfreq_loc_div_25[]; // Q0 -extern const Word16 band_len_idx[]; // Q0 -extern const Word16 band_len_ener_shift[]; // Q0 -extern const Word16 fine_gain_pred_sqrt_bw[]; // Q11 -extern const Word16 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 band_len_idx[]; // Q0 +extern const Word16 band_len_ener_shift[]; // Q0 +extern const Word16 fine_gain_pred_sqrt_bw[]; // Q11 +#ifndef HARM_HQ_CORE +extern const Word16 ivas_band_len_idx[]; // Q0 +extern const Word16 ivas_band_len_ener_shift[]; // Q0 +extern const Word16 ivas_fine_gain_pred_sqrt_bw[]; // Q11 +#else +extern const Word16 fine_gain_pred_sqrt_bw_ext[]; // Q11 +extern const Word16 band_len_idx_ext[1 + ( MAX_SFM_LEN_FX * 5 / 4 / 8 )]; // Q11 +#endif extern const Word16 Mean_isf_wb[]; // Q2.56 extern const Word16 lsp_shb_prev_tbl_fx[]; // Q15 extern const Word16 lsp_shb_prev_tbl_swb_tbe_enc_fx[]; // Q15 diff --git a/lib_com/rom_com_fx.c b/lib_com/rom_com_fx.c index ef6d2d354aa8225a7d0cab9ff8f50563cccd17c2..3e86de9a6691d2880c8d942cf99e997f06422ad9 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 ) */ @@ -25776,6 +25775,17 @@ const Word16 mfreq_loc_div_25[] = { 7, 15, 31, 47, 63, 79, 95, 111, 127, 143, 15 /* sfm/8= [ 1 2 3 4 6 8 10 12]; */ /* % idx= 0 1 2 3 4 5 6 7; */ /* call with band_len_idx[sfm_size>>3] */ +#ifdef HARM_HQ_CORE +const Word16 band_len_idx[1 + ( MAX_SFM_LEN_FX / 8 )] = { + /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ + -1, 0 /*8*/, 1 /*16*/, 2 /*24*/, 3 /*32*/, 4 /*40*/, 5 /*48 */, -1, 6 /*64 */, -1, 7 /*80*/, -1, 8 /*96*/ +}; // 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 /*sfm/8*/ /*1*/ /*2 */ /*3 */ /*4 */ /*6 */ /*8 */ /*10*/ /*12*/ @@ -25788,17 +25798,21 @@ 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) */ +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) */ + + /*----------------------------------------------------------------------------------* * 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_com/swb_bwe_com_fx.c b/lib_com/swb_bwe_com_fx.c index f7fcbca9b3ee4b162b9225e43792ea41041d945c..9b7c2424f764ab21a6257106dd1d3e327f7fa0cd 100644 --- a/lib_com/swb_bwe_com_fx.c +++ b/lib_com/swb_bwe_com_fx.c @@ -2062,6 +2062,7 @@ void time_envelop_shaping_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*/ @@ -2351,6 +2352,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 */ @@ -2404,11 +2406,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 */ @@ -2716,14 +2723,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 ); @@ -2956,6 +2977,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 */ @@ -3503,7 +3525,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 8b9710af9f4f2bd06e21c8c13cda6a70d333186c..1593244610500339bb650295ab1d7801dd4acf36 100644 --- a/lib_dec/FEC_HQ_phase_ecu_fx.c +++ b/lib_dec/FEC_HQ_phase_ecu_fx.c @@ -58,24 +58,46 @@ #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 * ); +#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 ); + /*------------------------------------------------------------------* * 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 +197,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 +237,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 +257,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 +632,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 +931,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 */ @@ -1163,6 +1199,7 @@ static void peakfinder_fx( return; } +#endif /*----------------------------------------------------------------------------- * imax_fx() @@ -1262,16 +1299,22 @@ static Word16 imax_fx( } } } + 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 */ @@ -1280,8 +1323,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; @@ -1398,6 +1441,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 ); } @@ -1460,8 +1504,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 */ ) @@ -1472,7 +1520,6 @@ static void ivas_spec_ana_fx( IF( element_mode == EVS_MONO ) { - /* Refine peaks */ pPlocsi = plocsi; pPlocs = plocs; @@ -1642,8 +1689,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 */ @@ -1787,11 +1837,10 @@ static void spec_ana_fx( { sel = mult_r( sub( Xmax, Xmin ), CMPLMNT_PFIND_SENS_FX ); } - peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel ); + peakfinder_fx( xfp, Lprot2_1, plocs, num_plocs, sel ); { - /* Refine peaks */ pPlocsi = plocsi; pPlocs = plocs; @@ -1837,6 +1886,7 @@ static void spec_ana_fx( } } } +#endif /*-------------------------------------------------------------------* * subst_spec_fx() @@ -1844,7 +1894,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 */ @@ -1859,9 +1913,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; @@ -1921,21 +1975,46 @@ 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(); - 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 */ +#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 ); + tmp = round_fx( L_shl( L_mult0( tmp, Lprot_inv ), 4 ) ); /* 0+22+4-16=10 */ - pPlocsi = plocsi; - pCorrPhase = corr_phase; - FOR( m = 0; m < *num_plocs; m++ ) + 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 { - 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 = 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++ ) + { + 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 */ @@ -2240,8 +2319,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 */ @@ -2602,6 +2684,7 @@ static void subst_spec_fx( } } } +#endif /*-------------------------------------------------------------------------- * rec_wtda() @@ -2609,15 +2692,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; @@ -2628,6 +2715,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; @@ -2698,6 +2788,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 ) ); @@ -2705,8 +2796,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 ) ); @@ -2725,9 +2826,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++ ) ) @@ -2740,17 +2873,23 @@ 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; } +#ifndef HARM_HQ_CORE static void rec_wtda_fx( Word16 *X, /* i : FFT spectrum */ Word32 *ecu_rec, /* o : Reconstructed frame in tda domain */ @@ -2821,6 +2960,7 @@ static void rec_wtda_fx( output_frame ); return; } +#endif /*-------------------------------------------------------------------------- * rec_frame_fx() @@ -2828,7 +2968,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 */ @@ -2873,11 +3017,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 */ @@ -2925,8 +3074,12 @@ static void rec_frame_fx( 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; @@ -3014,7 +3167,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, @@ -3034,7 +3192,6 @@ static void fec_ecu_pitch_ivas_fx( Word16 cb_end; Word16 Lmul2, Lon20mul6, Lon20mul28, Lon20mul33, Lon20mul34; - SWITCH( L ) { case L_FRAME48k: @@ -3118,15 +3275,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(); @@ -3180,11 +3334,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; @@ -3199,13 +3350,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 ) ) { @@ -3226,9 +3386,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 */ @@ -3445,11 +3607,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 */ @@ -3487,7 +3651,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; @@ -3501,7 +3669,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 ); @@ -3517,7 +3684,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 ); @@ -3537,8 +3703,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() * @@ -3546,7 +3715,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 */ @@ -3577,7 +3750,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++ ) { @@ -3599,7 +3771,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 ); @@ -3615,18 +3786,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; @@ -3653,9 +3834,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, @@ -3673,9 +3856,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++ ) { @@ -3684,7 +3865,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]; @@ -3698,7 +3878,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 ); @@ -3729,7 +3908,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; @@ -3756,21 +3934,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; @@ -3853,7 +4029,6 @@ static void sinusoidal_synthesis_fx( move16(); /*flag corresponds to condition sub(N, Lon20_10)>0 || HqVoicing */ } - pt4 = pulses; nb_pulses = 0; move16(); @@ -3912,7 +4087,6 @@ static void sinusoidal_synthesis_fx( } } - nb_pulses_final = 0; move16(); @@ -3920,7 +4094,6 @@ static void sinusoidal_synthesis_fx( cumsum = L_deposit_l( 0 ); - L_tmp = Mult_32_16( sum_Tf_abs, 22938 ); // Qin pt1 = a_re; @@ -3999,15 +4172,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; @@ -4020,8 +4188,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++ ) { @@ -4034,13 +4200,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, @@ -4052,7 +4222,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; @@ -4063,9 +4232,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 ) { @@ -4093,7 +4262,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 ); @@ -4138,7 +4306,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 */ @@ -4162,16 +4329,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]; @@ -4191,8 +4407,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 */ @@ -4203,7 +4423,6 @@ static void fec_noise_filling_fx( Word16 *gapsynth_fx /*Qsynth */ ) { - Word16 Rnd_N_noise; Word16 k, kk, i; Word16 N_noise; @@ -4327,9 +4546,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, @@ -4352,11 +4578,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(); @@ -4375,13 +4609,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 */ @@ -4426,12 +4659,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() @@ -4439,24 +4671,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 */ @@ -4523,7 +4759,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 ) @@ -4552,38 +4792,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; @@ -4669,8 +4922,10 @@ static void hq_phase_ecu_fx( move16(); *ph_ecu_active = 1; move16(); -} + return; +} +#endif /*-------------------------------------------------------------------------- * hq_ecu() @@ -4678,14 +4933,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 */ @@ -4695,9 +4954,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 */ ) { @@ -4728,7 +4987,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 { @@ -4754,13 +5017,37 @@ 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_KEEP_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( 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 + test(); ivas_mode_selection = ( LT_16( N, PH_ECU_N_LIMIT ) ) || ( LT_16( corr, PH_ECU_CORR_LIMIT_Q15 ) ); + test(); test(); test(); @@ -4768,7 +5055,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, &hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth, st_fx->element_mode, hHQ_core->old_out_fx, hHQ_core->Q_old_wtda ); +#else ivas_fec_alg_fx( fec_alg_input, prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth, st_fx->element_mode, st_fx->hHQ_core->old_out_fx, st_fx->hHQ_core->Q_old_wtda ); +#endif *last_fec = 1; move16(); *ph_ecu_active = 0; @@ -4778,9 +5069,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(); @@ -4790,14 +5087,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 */ @@ -4807,8 +5105,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 */ ) @@ -4822,9 +5120,7 @@ void hq_ecu_fx( move16(); N = shr( output_frame, 2 ); - /* find pitch and R value */ - IF( !( LT_16( output_frame, L_FRAME16k ) ) ) { fec_ecu_pitch_fx( prevsynth + NS2SA_FX2( L_mult0( output_frame, 50 ), ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, output_frame, &N, &corr, &decimatefactor, ph_ecu_HqVoicing ); @@ -4854,7 +5150,6 @@ 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] ) ) ) ) { - fec_alg_fx( prevsynth + NS2SA_FX2( L_mult0( output_frame, 50 ), ACELP_LOOK_NS / 2 - PH_ECU_LOOKAHEAD_NS ), prevsynth_LP, &st_fx->hHQ_core->ni_seed_forfec, ecu_rec, output_frame, N, decimatefactor, ph_ecu_HqVoicing, gapsynth ); *last_fec = 1; move16(); @@ -4869,8 +5164,10 @@ void hq_ecu_fx( env_stab, last_fec, ph_ecu_active, prev_bfi, old_is_transient, mag_chg_1st, Xavg, beta_mute, st_fx->bwidth, output_frame ); } + return; } +#endif /******************************************************************************* * The square root of x which MUST be 0.5 <= x < 1, i.e., x must be normalized. @@ -4893,7 +5190,7 @@ void hq_ecu_fx( /* 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). */ + const Word16 x /* i: x must be in between 0.5 and 1.0 (Q15). */ ) { Word32 acc; @@ -4930,6 +5227,7 @@ static void windowing( Word16 i; Word16 *pY; const Word16 *pX, *pW; + pX = x; pW = win; pY = y; @@ -4948,6 +5246,8 @@ static void windowing( *pY++ = mult_r( *pX++, *( --pW ) ); move16(); } + + return; } /*----------------------------------------------------------------------------- diff --git a/lib_dec/evs_dec_fx.c b/lib_dec/evs_dec_fx.c index 95345a4440771020d6599272acd7f3a5dbda06ea..e9673e0caf79d40d1b80babad186e3c2874ae703 100644 --- a/lib_dec/evs_dec_fx.c +++ b/lib_dec/evs_dec_fx.c @@ -338,7 +338,11 @@ ivas_error evs_dec_fx( } ELSE { +#ifdef HARM_HQ_CORE + hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag, NULL ); +#else hq_core_dec_fx( st_fx, synth_fx, &Q_synth, output_frame, hq_core_type, core_switching_flag ); +#endif Qpostd = Q_synth; move16(); } diff --git a/lib_dec/hq_classifier_dec_fx.c b/lib_dec/hq_classifier_dec_fx.c index d6df6e4f50103475295230f4c8012e7dabdc61ec..5b5fe93f7759a32533aac123007abe8142b362c7 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 8a8ee02361ab42ab4bf7b2fb0643df8a910beade..ee2633894722d660768e88e67f20f674cef5a487 100644 --- a/lib_dec/hq_core_dec_fx.c +++ b/lib_dec/hq_core_dec_fx.c @@ -1,19 +1,22 @@ /*==================================================================================== 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() * * HQ core decoder *--------------------------------------------------------------------------*/ - void hq_core_dec_fx( +#ifndef HARM_HQ_CORE Decoder_State *st_fx, /* i/o: decoder state structure fx */ Word16 synth[], /* o : output synthesis Q_synth*/ Word16 *Q_synth, /* o : Q value of synth */ @@ -462,6 +465,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 */ @@ -489,17 +493,17 @@ void ivas_hq_core_dec_fx( Word32 L_tmp; UWord16 lsb; Word16 L_spec; +#ifdef HARM_HQ_CORE + const Word16 *sfmsize, *sfm_start, *sfm_end; + HQ_NBFEC_HANDLE hHQ_nbfec; +#endif HQ_DEC_HANDLE hHQ_core; - - hHQ_core = st_fx->hHQ_core; - 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; @@ -507,12 +511,22 @@ void ivas_hq_core_dec_fx( Word16 output[L_FRAME16k]; 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(); - st_fx->Q_syn_factor = 0; - move16(); +#ifdef HARM_HQ_CORE + if ( st_fx->element_mode > EVS_MONO ) +#endif + { + st_fx->Q_syn_factor = 0; + move16(); + } /*-------------------------------------------------------------------------- * Initializations @@ -547,6 +561,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 *--------------------------------------------------------------------------*/ @@ -570,13 +585,25 @@ void ivas_hq_core_dec_fx( } ELSE { +#ifdef HARM_HQ_CORE + core_switching_hq_prepare_dec_fx( st_fx, &num_bits, output_frame ); + + /* During ACELP->HQ core switching, limit the HQ core bitrate to 48kbps */ + 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 */ @@ -623,6 +650,19 @@ void ivas_hq_core_dec_fx( } } +#ifdef HARM_HQ_CORE + IF( EQ_16( output_frame, L_FRAME8k ) ) + { + hq_configure_bfi_fx( &nb_sfm, &num_Sb, num_bands_p, &sfmsize, &sfm_start, &sfm_end ); + } + ELSE + { + sfmsize = NULL; + sfm_start = NULL; + sfm_end = NULL; + } + +#endif /*-------------------------------------------------------------------------- * transform-domain decoding *--------------------------------------------------------------------------*/ @@ -634,10 +674,23 @@ void ivas_hq_core_dec_fx( IF( GE_16( output_frame, L_FRAME16k ) ) /* Apply phase ecu for WB, SWB and FB */ { /* ecu_rec sent to OLA, env_stab passed in ph_ecu_st */ +#ifdef HARM_HQ_CORE + hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p, hHQ_core->plocs, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, + &hHQ_core->last_fec, hHQ_core->ph_ecu_HqVoicing, &hHQ_core->ph_ecu_active, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient, hHQ_core->mag_chg_1st_fx, + hHQ_core->Xavg_fx, &hHQ_core->beta_mute_fx, output_frame, st_fx ); +#else ivas_hq_ecu_fx( st_fx->hTcxDec->prev_good_synth_fx, t_audio_q, &hHQ_core->time_offs, hHQ_core->X_sav_fx, &hHQ_core->Q_X_sav, &hHQ_core->num_p, hHQ_core->plocs, hHQ_core->plocsi_fx, hHQ_core->env_stab_fx, &hHQ_core->last_fec, hHQ_core->ph_ecu_HqVoicing, &hHQ_core->ph_ecu_active, gapsynth_fx, st_fx->prev_bfi, hHQ_core->old_is_transient, hHQ_core->mag_chg_1st_fx, hHQ_core->Xavg_fx, &hHQ_core->beta_mute_fx, output_frame, st_fx ); +#endif + } +#ifdef HARM_HQ_CORE + ELSE + { + HQ_FEC_processing_fx( st_fx, t_audio_q, is_transient, hHQ_nbfec->ynrm_values_fx, hHQ_nbfec->r_p_values_fx, num_Sb, nb_sfm, num_bands_p, + output_frame, sfm_start, sfm_end ); } +#endif hHQ_core->old_is_transient[2] = hHQ_core->old_is_transient[1]; /* Q0 */ move16(); @@ -663,6 +716,21 @@ void ivas_hq_core_dec_fx( { IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { +#ifdef HARM_HQ_CORE + IF( EQ_16( st_fx->prev_bfi, 1 ) ) + { + set32_fx( hHQ_core->last_ni_gain_fx, 0, BANDS_MAX ); + set16_fx( hHQ_core->last_env_fx, 0, BANDS_MAX ); + hHQ_core->last_max_pos_pulse = 0; + move16(); + } + + /* HQ low rate decoder */ + hq_lr_dec_fx( st_fx, t_audio_q, inner_frame, num_bits, &is_transient ); + + hqswb_clas = is_transient; /* Q0 */ + move16(); +#else /* this cannot happen in IVAS */ is_transient = 0; @@ -673,17 +741,29 @@ void ivas_hq_core_dec_fx( move16(); Q_G_audio = Q_audio; move16(); +#endif } ELSE { /* HQ high rate decoder */ +#ifdef HARM_HQ_CORE + hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); +#else ivas_hq_hr_dec_fx( st_fx, t_audio_q, L_spec, num_bits, ynrm, &is_transient, &hqswb_clas, SWB_fenv_fx, core_switching_flag ); Q_audio = 12; move16(); Q_G_audio = Q_audio; move16(); +#endif } +#ifdef HARM_HQ_CORE + Q_audio = Q12; + move16(); + Q_G_audio = Q_audio; + move16(); +#endif + test(); test(); test(); @@ -720,6 +800,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 ) ) { @@ -731,6 +812,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 + if ( st_fx->element_mode == EVS_MONO ) + { + ener_match = div_s( st_fx->bws_cnt1, N_NS2W_FRAMES ); /*Q15*/ + } +#endif } IF( is_transient ) @@ -768,12 +855,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 ) ) @@ -786,10 +873,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 */ - // fscaleFB = sr2fscale( st_fx->output_Fs ); - // encoderLookahead = ( L_LOOK_12k8 * st_fx->fscale ) / FSCALE_DENOM; - // encoderLookaheadFB = ( L_LOOK_12k8 * fscaleFB ) / FSCALE_DENOM; + 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 ); @@ -822,7 +906,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, @@ -898,13 +981,58 @@ void ivas_hq_core_dec_fx( move16(); } +#ifdef HARM_HQ_CORE + IF( EQ_16( output_frame, L_FRAME8k ) ) + { + test(); + IF( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) + { + Copy_Scale_sig( hHQ_core->old_out_fx + N_ZERO_NB, hHQ_nbfec->prev_oldauOut_fx, output_frame - N_ZERO_NB, negate( hHQ_core->Q_old_wtda ) ); /* 15 - exp_old_out - Q_old_wtda */ + } + ELSE IF( EQ_16( st_fx->prev_bfi, 1 ) ) + { + set16_fx( hHQ_nbfec->prev_oldauOut_fx, 0, output_frame ); + } + + test(); + test(); + test(); + test(); + IF( ( EQ_16( st_fx->prev_bfi, 1 ) || EQ_16( st_fx->bfi, 1 ) ) && hHQ_core->old_is_transient[2] == 0 && EQ_16( st_fx->last_core, HQ_CORE ) && EQ_16( st_fx->last_codec_mode, MODE1 ) ) + { + time_domain_FEC_HQ_fx( st_fx, wtda_audio, synth, mean_en_high_fx, output_frame, Q_synth ); + } + ELSE + { + window_ola_fx( wtda_audio, synth, Q_synth, hHQ_core->old_out_fx, &hHQ_core->Q_old_wtda, output_frame, + st_fx->hTcxCfg->tcx_last_overlap_mode, st_fx->hTcxCfg->tcx_curr_overlap_mode, st_fx->prev_bfi, hHQ_core->oldHqVoicing, hHQ_core->oldgapsynth_fx ); + + hHQ_nbfec->phase_mat_next = 0; + move16(); + } + + test(); + test(); + IF( ( st_fx->bfi == 0 && st_fx->prev_bfi == 0 ) || !( GE_16( output_frame, L_FRAME16k ) ) ) + { + preecho_sb_fx( st_fx->core_brate, wtda_audio, Q_audio, synth, *Q_synth, output_frame, &hHQ_core->memfilt_lb_fx, + &hHQ_core->mean_prev_hb_fx, &hHQ_core->smoothmem_fx, &hHQ_core->mean_prev_fx, &hHQ_core->mean_prev_nc_fx, &hHQ_core->wmold_hb_fx, &hHQ_core->prevflag, &hHQ_core->pastpre, st_fx->bwidth ); + } + } + ELSE +#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_CORE + 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 ); @@ -933,6 +1061,33 @@ void ivas_hq_core_dec_fx( } } +#ifdef HARM_HQ_CORE + 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 ) ) @@ -959,15 +1114,23 @@ void ivas_hq_core_dec_fx( move16(); } - /* prepare synthesis output buffer (as recent as possible) for HQ FEC */ +#ifdef HARM_HQ_CORE + IF( EQ_16( output_frame, L_FRAME8k ) ) + { + Copy32( wtda_audio, hHQ_nbfec->oldIMDCTout_fx, L_FRAME8k / 2 ); /* q_wtda */ + Copy( &hHQ_nbfec->old_auOut_2fr_fx[output_frame], hHQ_nbfec->old_auOut_2fr_fx, output_frame ); /* q_old_auOut */ + Copy_Scale_sig( synth, &hHQ_nbfec->old_auOut_2fr_fx[output_frame], output_frame, negate( *Q_synth ) ); /* Q0 */ + } +#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(); } @@ -983,11 +1146,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_CORE + IF( GT_16( st_fx->element_mode, EVS_MONO ) ) +#endif + { + /* Move LB excitation to old_exc memory in case of switch HQ->ACELP */ + Copy_Scale_sig( output, st_fx->old_exc_fx + sub( L_EXC_MEM_DEC, st_fx->L_frame ), st_fx->L_frame, negate( Q_output ) ); /* Q0 */ - 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; } @@ -1063,10 +1231,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 ); @@ -1105,10 +1273,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 30a7d4f4ae9ca4fc66f9917ef120cb2bf155e698..342a18bbc245d88660c7c663b82cb0307bf350a7 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,19 +115,31 @@ 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 ); } return; } + + /*--------------------------------------------------------------------------* * hq_hr_dec_fx() * * HQ High rate decoding routine *--------------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE +void hq_hr_dec_fx( +#else void ivas_hq_hr_dec_fx( +#endif Decoder_State *st_fx, /* i/o: decoder state structure fx */ Word32 *t_audio_q, /* o : transform-domain coefficients Q12 */ const Word16 length, /* i : frame length Q0 */ @@ -133,7 +148,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; @@ -192,14 +207,25 @@ void ivas_hq_hr_dec_fx( * Decode classification *------------------------------------------------------------------*/ +#ifdef HARM_HQ_CORE + bits = hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ +#else bits = ivas_hq_classifier_dec_fx( st_fx, st_fx->core_brate, length, is_transient, hqswb_clas ); /* Q0 */ - bits_left = sub( num_bits, bits ); /* Q0 */ +#endif + + bits_left = sub( num_bits, bits ); /* Q0 */ /*------------------------------------------------------------------* * 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 @@ -276,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(); @@ -283,8 +310,12 @@ void ivas_hq_hr_dec_fx( * Bit allocation *------------------------------------------------------------------*/ +#ifdef HARM_HQ_CORE + hq_bit_allocation_fx( st_fx->core_brate, length, *hqswb_clas, &bits_left, normqlg2, nb_sfm, sfmsize, noise_level, R, Rsubband, &sum, &core_sfm, num_env_bands ); +#else ivas_hq_bit_allocation_fx( st_fx->core_brate, length, *hqswb_clas, &bits_left, normqlg2, nb_sfm, sfmsize, noise_level, R, Rsubband, &sum, &core_sfm, num_env_bands ); +#endif test(); test(); @@ -325,7 +356,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(); @@ -365,24 +400,41 @@ void ivas_hq_hr_dec_fx( /*------------------------------------------------------------------* * Spectral filling *------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE + fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, + &hHQ_core->no_att_hangover, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed, hq_generic_exc_clas, + core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient[0], + hHQ_core->prev_normq_fx, hHQ_core->prev_env_fx, st_fx->prev_bfi, sfmsize, sfm_start, sfm_end, + &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas, num_sfm, hHQ_core->prev_env_Q, num_env_bands, st_fx->element_mode ); +#else ivas_fill_spectrum_fx( t_audio_q_norm, t_audio_q, R, *is_transient, ynrm, SWB_fenv, hq_generic_offset, nf_idx, length, env_stab, &hHQ_core->no_att_hangover, &hHQ_core->energy_lt_fx, &hHQ_core->hq_generic_seed, hq_generic_exc_clas, core_sfm, *hqswb_clas, noise_level, st_fx->core_brate, hHQ_core->prev_noise_level_fx, &hHQ_core->prev_R, hHQ_core->prev_coeff_out_fx, peak_idx, Npeaks, pulses, hHQ_core->old_is_transient[0], hHQ_core->prev_normq_fx, hHQ_core->prev_env_fx, st_fx->prev_bfi, sfmsize, sfm_start, sfm_end, &st_fx->hBWE_FD->prev_L_swb_norm, hHQ_core->prev_hqswb_clas, num_sfm, hHQ_core->prev_env_Q, num_env_bands, st_fx->element_mode ); +#endif enforce_zero_for_min_envelope_fx( *hqswb_clas, ynrm, t_audio_q, nb_sfm, sfm_start, sfm_end ); - IF( EQ_16( *is_transient, 1 ) ) { +#ifdef HARM_HQ_CORE + de_interleave_spectrum_fx( t_audio_q, length ); +#else ivas_de_interleave_spectrum_fx( t_audio_q, length ); +#endif } /*------------------------------------------------------------------* * WB/SWB bandwidth switching *------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE + hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); +#else ivas_hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); +#endif /* update */ hHQ_core->prev_hqswb_clas = *hqswb_clas; /* Q0 */ @@ -390,6 +442,7 @@ void ivas_hq_hr_dec_fx( return; } +#ifndef HARM_HQ_CORE void hq_hr_dec_fx( Decoder_State *st_fx, /* i/o: decoder state structure fx */ @@ -400,7 +453,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; @@ -465,6 +518,7 @@ void hq_hr_dec_fx( /*------------------------------------------------------------------* * set quantization parameters *------------------------------------------------------------------*/ + hq_configure_evs_fx( length, *hqswb_clas, st_fx->core_brate, &num_sfm, &nb_sfm, &start_norm, &num_env_bands, &numnrmibits, &hq_generic_offset, sfmsize, sfm_start, sfm_end ); @@ -630,6 +684,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], @@ -638,7 +693,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 ); @@ -647,6 +701,7 @@ void hq_hr_dec_fx( /*------------------------------------------------------------------* * WB/SWB bandwidth switching *------------------------------------------------------------------*/ + hq_pred_hb_bws_fx( st_fx, ynrm, length, *hqswb_clas, SWB_fenv ); /* update */ @@ -655,3 +710,4 @@ void hq_hr_dec_fx( return; } +#endif diff --git a/lib_dec/ivas_core_dec_fx.c b/lib_dec/ivas_core_dec_fx.c index fbb69eb639a999840768c50baa35b98d0ffe138e..425ceb05b1e3e5a38eebaa06e447c70dcfe4e2f1 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_CORE + hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_32_fx[n] ); +#else ivas_hq_core_dec_fx( st, synth_16_fx[n], &Q_synth, output_frame, NORMAL_HQ_CORE, core_switching_flag[n], output_32_fx[n] ); +#endif Scale_sig( synth_16_fx[n], output_frame, sub( st->Q_syn_factor, Q_synth ) ); // st->Q_syn_factor } diff --git a/lib_dec/ivas_stereo_dft_plc_fx.c b/lib_dec/ivas_stereo_dft_plc_fx.c index 4ded8044f211e566a7ab650d2a8753b034ae9fff..670b19e36cae2a55d2206cc238b62a8c489dd66c 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/peak_vq_dec_fx.c b/lib_dec/peak_vq_dec_fx.c index 80fa60560198ea9f2cda772a64713847c1d1ec66..81cd93e97ae725725a168924994a07b35d5cb1ab 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++ ) { @@ -312,9 +321,18 @@ static void peak_vq_dec_fx( pvq_decode_frame_fx( st_fx, pvq_vector, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, Rk, pvq_bits, core ); - +#ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_KEEP_BE + fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, pvq_maxpulse, NULL, + pvq_bands, pvq_vector, pvq_inp_vector, fg_pred, EVS_MONO, core ); +#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 ); +#endif fine_gain_dec_fx( st_fx, k_sort, pvq_bands, gain_bits_array, fg_pred ); @@ -456,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_dec/pvq_core_dec_fx.c b/lib_dec/pvq_core_dec_fx.c index 96595be9abd67706f1504eb4e1e25cd311236a9d..ebc7b8905e49915a271beeae493a48478f9caf2b 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, @@ -234,7 +249,11 @@ Word16 ivas_pvq_core_dec_fx( } R_upd = shl( bits_tot, 3 ); // Q0 -> Q3 +#ifdef HARM_HQ_CORE + assign_gain_bits_fx( st_fx->element_mode, core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); +#else ivas_assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); +#endif pvq_bits = shr( R_upd, 3 ); // Q3 -> Q0 @@ -266,8 +285,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_CORE + fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, + nb_sfm, coefs_quant, pulse_vector, fg_pred, st_fx->element_mode, core ); +#else ivas_fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, coefs_quant, pulse_vector, fg_pred, core ); +#endif fine_gain_dec_fx( st_fx, ord, nb_sfm, gain_bits_array, fg_pred ); IF( st_fx->hHQ_core != NULL ) @@ -277,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(); @@ -284,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, @@ -357,17 +383,21 @@ 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(); return bits_tot; } +#endif + /*-------------------------------------------------------------------* * decode_energies() * *-------------------------------------------------------------------*/ + void decode_energies_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ @@ -459,6 +489,7 @@ void decode_energies_fx( * densitySymbolIndexDecode() * *-------------------------------------------------------------------*/ + static void densitySymbolIndexDecode_fx( Decoder_State *st_fx, PVQ_DEC_HANDLE hPVQ, /* i/o: PVQ decoder handle */ @@ -596,6 +627,7 @@ static void densitySymbolIndexDecode_fx( rc_dec_update_fx( st_fx, hPVQ, cum_freq, sym_freq ); *index_phi = alpha; move16(); + return; } @@ -606,12 +638,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; @@ -658,5 +691,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_dec/vlpc_2st_dec_fx.c b/lib_dec/vlpc_2st_dec_fx.c index f3414dc71815a5517a0e6e449d484d7bf7c32eb5..a4c1c9e7e5412c79e5b22886fdfb19711736ab07 100644 --- a/lib_dec/vlpc_2st_dec_fx.c +++ b/lib_dec/vlpc_2st_dec_fx.c @@ -8,7 +8,6 @@ #include "prot_fx.h" #include - void vlpc_2st_dec( Word16 *lsfq, /* i/o: i:1st stage o:1st+2nd stage 14Q1*1.28*/ Word16 *indx, /* i : index[] (4 bits per words) */ diff --git a/lib_enc/gs_enc_fx.c b/lib_enc/gs_enc_fx.c index 9f140f84342a4107a9c2f6665e9faeb704081784..7b3eefc951d3355c83bb43c07a41e1b22b300232 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 07152c84267d8270bb762b7dab56c7f91772ad2f..d674cc30e68fade347709b80d0a4a57aa6d45e2a 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,11 +177,14 @@ static Word16 hf_spectrum_sparseness_fx( return result; /* Q0 */ } + + /*--------------------------------------------------------------------------* * hq_classifier_enc_fx() * * HQ mode selector (decision_matrix) *--------------------------------------------------------------------------*/ +#ifndef HARM_HQ_CORE Word16 hq_classifier_enc_fx( /* o : Consumed bits Q0 */ Encoder_State *st_fx, /* i/o: encoder state structure */ const Word16 length, /* i : Frame length Q0 */ @@ -227,6 +230,7 @@ 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 */ 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 ); @@ -279,26 +283,30 @@ Word16 hq_classifier_enc_fx( /* o : Consumed bits 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(); @@ -327,11 +335,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 +352,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; @@ -353,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 ); @@ -372,14 +388,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 +503,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 +629,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 +1070,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 +1509,4 @@ void hvq_classifier_fx( return; } +#endif diff --git a/lib_enc/hq_core_enc_fx.c b/lib_enc/hq_core_enc_fx.c index 6c4aa6bf4ab9bd8f7398d3d8e6d7807be77d7bf3..98552f5e30f76c96ca64bd1676bf1c1d1376c03c 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_CORE /*-------------------------------------------------------------------------- * 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_CORE +/*-------------------------------------------------------------------------- + * 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_CORE + IF( st->element_mode == EVS_MONO ) + { + Copy( st->old_input_signal_fx, two_frames_buffer, input_frame ); /* st_fx->q_old_inp */ + Copy( audio_fx, two_frames_buffer + input_frame, input_frame ); /* Q0 */ + } + ELSE +#endif + { + Scale_sig( st->old_input_signal_fx, input_frame, negate( st->q_old_inp ) ); /* Q0 */ + Scale_sig( st->input_fx, add( input_frame, NS2SA( 48000, DELAY_FIR_RESAMPL_NS ) ), negate( st->q_inp ) ); /* Q0 */ + 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_CORE + 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_CORE + test(); + IF( st->element_mode == EVS_MONO && EQ_16( input_frame, L_FRAME32k ) ) + { + Q_audio = add( Q_audio, 1 ); /* Divide by 2 */ + } + ELSE +#endif { - /*t_audio_q[i] *= ener_match; */ - Mpy_32_16_ss( t_audio_fx[i], ener_match_fx, &t_audio_fx[i], &lsb ); /* Q12 */ + 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_CORE + test(); + IF( st->element_mode > EVS_MONO && st->bwidth_sw_cnt > 0 ) +#else IF( st->bwidth_sw_cnt > 0 ) +#endif { Word32 L_tmp; tmp = BASOP_Util_Divide1616_Scale( 3, BWS_TRAN_PERIOD, &exp ); /* Q15-exp */ @@ -499,18 +542,37 @@ 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_CORE + IF( st->element_mode == EVS_MONO ) + { + scale_sig32( t_audio_fx, inner_frame, sub( Q12, Q_audio ) ); /* Q12 */ + } + ELSE +#endif + { + scale_sig32( t_audio_fx, L_FRAME48k_EXT, sub( Q12, Q_audio ) ); + scale_sig32( wtda_audio_fx32, 2 * L_FRAME48k, sub( Q12, Q_audio ) ); + } + Q_audio = Q12; move16(); + IF( EQ_16( hq_core_type, LOW_RATE_HQ_CORE ) ) { +#ifdef HARM_HQ_CORE + /* HQ low rate encoder */ + hq_lr_enc_fx( st, t_audio_fx, inner_frame, &num_bits, is_transient ); +#else /* this cannot happen in IVAS */ +#endif } ELSE { /* HQ high rate encoder */ +#ifdef HARM_HQ_CORE + hq_hr_enc_fx( st, t_audio_fx, L_spec, &num_bits, is_transient, vad_hover_flag ); +#else hq_hr_enc_ivas_fx( st, t_audio_fx, L_spec, &num_bits, is_transient, vad_hover_flag ); +#endif } /* write all unused bits to the bitstream */ @@ -579,7 +641,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(); diff --git a/lib_enc/hq_env_enc_fx.c b/lib_enc/hq_env_enc_fx.c index bcf0e3945c690e037de9bcebcf7440dc42322468..98c94cc2f4b1ed9061a04e79884c549a9094f43d 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_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 */ @@ -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 7c5a7884c757ea1d20486bd3448ccba0261f3a83..5c290fe7c9fb27dfda1bcd5e4398381d57437608 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_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 */ @@ -120,13 +121,14 @@ 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 *------------------------------------------------------------------*/ /* 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 ); @@ -181,6 +183,7 @@ void hq_hr_enc_fx( /*------------------------------------------------------------------* * Quantize/code spectral fine structure using PVQ or HVQ *------------------------------------------------------------------*/ + IF( EQ_16( hqswb_clas, HQ_HVQ ) ) { sum = hvq_enc_fx( st_fx, st_fx->core_brate, *num_bits, Npeaks, ynrm, R, peaks, nf_gains, noise_level, pe_gains, t_audio, t_audio_q ); @@ -255,6 +258,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*/ @@ -301,6 +305,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,12 +318,18 @@ 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 *------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE + bits = hq_classifier_enc_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ +#else bits = hq_classifier_enc_ivas_fx( st, length, t_audio_fx, is_transient, &Npeaks, peaks, pe_gains_fx, nf_gains_fx, &hqswb_clas ); /* Q0 */ +#endif + *num_bits = sub( *num_bits, bits ); - move16(); /*------------------------------------------------------------------* * Set quantization parameters @@ -329,11 +340,17 @@ void hq_hr_enc_ivas_fx( /*------------------------------------------------------------------* * Transient frame handling *------------------------------------------------------------------*/ + /* Interleave MLT coefficients of 4 sub-vectors in case of transient frame */ IF( is_transient ) { +#ifdef HARM_HQ_CORE + interleave_spectrum_fx( t_audio_fx, length ); +#else interleave_spectrum_ivas_fx( t_audio_fx, length ); +#endif } + test(); IF( EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) { @@ -347,32 +364,54 @@ 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_CORE + IF( st->element_mode == EVS_MONO ) + { + calc_norm_fx( t_audio_fx, 12, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); + } + ELSE +#endif + { + calc_norm_ivas_fx( t_audio_fx, ynrm, normqlg2, start_norm, num_env_bands, sfmsize, sfm_start ); + } + /* create differential code of quantized norm indices */ diff_envelope_coding_fx( is_transient, num_env_bands, start_norm, ynrm, normqlg2, difidx ); /* Find norm coding mode and calculate number of bits */ +#ifdef HARM_HQ_CORE + hcode_l = encode_envelope_indices_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); /* Q0 */ +#else hcode_l = encode_envelope_indices_ivas_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 0, NORMAL_HQ_CORE, is_transient ); /* Q0 */ +#endif *num_bits = sub( *num_bits, add( hcode_l, NORM0_BITS + FLAGS_BITS ) ); - move16(); + /* Encode norm indices */ +#ifdef HARM_HQ_CORE + encode_envelope_indices_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); +#else encode_envelope_indices_ivas_fx( hBstr, num_env_bands, numnrmibits, difidx, &LCmode, 1, NORMAL_HQ_CORE, is_transient ); +#endif /*------------------------------------------------------------------* - * HQ GENERIC BWE encoding + * HQ Generic BWE encoding *------------------------------------------------------------------*/ test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { +#ifdef HARM_HQ_CORE + hq_generic_hf_encoding_fx( st->element_mode, t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, length ); +#else hq_generic_hf_encoding_fx( t_audio_fx, hq_generic_fenv_fx, hq_generic_offset, st, &hq_generic_exc_clas, length ); +#endif IF( EQ_16( hq_generic_exc_clas, HQ_GENERIC_SP_EXC ) ) { *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 ); } @@ -380,37 +419,56 @@ void hq_hr_enc_ivas_fx( * Bit allocation *------------------------------------------------------------------*/ +#ifdef HARM_HQ_CORE + hq_bit_allocation_fx( st->core_brate, length, hqswb_clas, num_bits, normqlg2, nb_sfm, sfmsize, noise_level_fx, R, Rsubband, &sum, &core_sfm, num_env_bands ); +#else ivas_hq_bit_allocation_fx( st->core_brate, length, hqswb_clas, num_bits, normqlg2, nb_sfm, sfmsize, noise_level_fx, R, Rsubband, &sum, &core_sfm, num_env_bands ); +#endif /*------------------------------------------------------------------* * Normalize coefficients with quantized norms *------------------------------------------------------------------*/ + IF( NE_16( hqswb_clas, HQ_HVQ ) ) { test(); IF( EQ_16( hqswb_clas, HQ_GEN_SWB ) || EQ_16( hqswb_clas, HQ_GEN_FB ) ) { +#ifdef HARM_HQ_CORE + b_delta_env = calc_nor_delta_hf_fx( hBstr, t_audio_fx, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); /* Q0 */ +#else b_delta_env = calc_nor_delta_hf_ivas_fx( hBstr, t_audio_fx, ynrm, Rsubband, num_env_bands, nb_sfm, sfmsize, sfm_start, core_sfm ); /* Q0 */ +#endif sum = sub( sum, b_delta_env ); } normalizecoefs_fx( t_audio_fx, ynrm, nb_sfm, sfm_start, sfm_end, t_audio_norm ); } - Word16 Q_audio = 12, Q_shift; + Word16 Q_audio = Q12, 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(); } test(); @@ -461,23 +519,32 @@ 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 ) ) +#ifdef HARM_HQ_CORE + IF( st->element_mode > EVS_MONO ) +#endif { - 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( 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 ) - { - ivas_de_interleave_spectrum_fx( t_audio_q_fx, length ); - } + IF( is_transient ) + { +#ifdef HARM_HQ_CORE + de_interleave_spectrum_fx( t_audio_q_fx, length ); +#else + ivas_de_interleave_spectrum_fx( t_audio_q_fx, length ); +#endif + } - Copy32( t_audio_q_fx, t_audio_fx, length ); + Copy32( t_audio_q_fx, t_audio_fx, length ); + } return; } diff --git a/lib_enc/hq_lr_enc_fx.c b/lib_enc/hq_lr_enc_fx.c index 7da3d34158db7fdc5f847c9e783b9573567833c6..663cee4b9be46a1d4f80bdbfeff0e304aaeed92c 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_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 */ +#endif } /* write the classification information into the bitstream */ @@ -302,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(); @@ -1479,7 +1482,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 */ @@ -1556,7 +1559,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 */ @@ -1680,8 +1682,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 e7a339af6fe5cd564088301a64658ffd9cc2f864..4111ff1bc2a271ca6f3c70a396736bca68b7959c 100644 --- a/lib_enc/hvq_enc_fx.c +++ b/lib_enc/hvq_enc_fx.c @@ -5,13 +5,22 @@ #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 */ + +/*-------------------------------------------------------------------------- + * Local constants + *--------------------------------------------------------------------------*/ + #define HVQ_ENC_NOISE_DELTA ( (Word16) 3277 ) /* 0.1 in Q15 */ + +/*-------------------------------------------------------------------------- + * Local function prototypes + *--------------------------------------------------------------------------*/ + static Word16 quant_lc_fx( const Word16, Word16 * ); @@ -20,19 +29,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 +203,26 @@ Word16 hvq_enc_ivas_fx( /*o : Consumed bits move16(); } } + +#ifdef HARM_HQ_CORE + nBits = peak_vq_enc_fx( st_fx->element_mode, st_fx->hBstr, st_fx->bwidth, coefs, coefs_out, core_brate, sub( hvq_bits, bits_used ), + Npeaks, ynrm, R, peaks, &nf_gains[0] ); +#else nBits = peak_vq_enc_ivas_fx( st_fx->hBstr, st_fx->bwidth, coefs, coefs_out, core_brate, sub( hvq_bits, bits_used ), Npeaks, ynrm, R, peaks, &nf_gains[0] ); +#endif + bits_used = add( bits_used, nBits ); + return bits_used; } -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,13 +392,17 @@ Word16 hvq_enc_fx( /*o : Consumed bits bits_used = add( bits_used, nBits ); return bits_used; } +#endif /*----------------------------------------------------------------------------- * quant() * * 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 84433de1a9ec779245e4a8cb9afce74340bb6a47..d65772bdcadf29238ce9506f05d17ab044b0e534 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_CORE + hq_core_enc_fx( st, st->input_fx, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] ); +#else hq_core_enc_ivas_fx( st, st->input_fx, input_frame, NORMAL_HQ_CORE, Voicing_flag[n], vad_hover_flag[0] ); +#endif } /*---------------------------------------------------------------------* diff --git a/lib_enc/peak_vq_enc_fx.c b/lib_enc/peak_vq_enc_fx.c index 56b591ea56f522acc54e43440906d4a87ed454e4..89d9a56816767cff15884ddb126688e91e1c2fe0 100644 --- a/lib_enc/peak_vq_enc_fx.c +++ b/lib_enc/peak_vq_enc_fx.c @@ -19,8 +19,11 @@ static void quant_peaks_fx( BSTR_ENC_HANDLE hBstr, const Word32 *, Word32 *, const Word32 *, Word16 *, const Word16, const Word32, const Word16 ); static Word16 hvq_code_pos_fx( BSTR_ENC_HANDLE hBstr, const Word16 *inp, const Word16 length, const Word16 num_peaks ); static Word16 sparse_code_pos_fx( const Word16 *inp, const Word16 length, Word16 *result ); +#ifdef HARM_HQ_CORE +static Word16 hvq_code_pos_fx( BSTR_ENC_HANDLE hBstr, const Word16 *inp, const Word16 length, const Word16 num_peaks ); +static void quant_peaks_fx( BSTR_ENC_HANDLE hBstr, const Word32 *vect_in, Word32 *vect_out, const Word32 *peak_gain, Word16 *vq_idx, const Word16 overlap, const Word32 core_brate, const Word16 Npeaks ); +#else static Word16 hvq_code_pos_ivas_fx( BSTR_ENC_HANDLE hBstr, const Word16 *inp, const Word16 length, const Word16 num_peaks ); - static void quant_peaks_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle*/ const Word32 *vect_in, /* i : Target vector in Q12 */ @@ -31,6 +34,7 @@ static void quant_peaks_ivas_fx( const Word32 core_brate, /* i : Core bitrate */ const Word16 Npeaks /* i : Number of peaks */ ); +#endif /*-------------------------------------------------------------------------- @@ -39,9 +43,16 @@ static void quant_peaks_ivas_fx( * Vector Quantization of MDCT peaks *--------------------------------------------------------------------------*/ +#ifdef HARM_HQ_CORE +Word16 peak_vq_enc_fx( +#else Word16 peak_vq_enc_ivas_fx( - BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ - const Word16 bwidth, /* i : audio bandwidth */ +#endif +#ifdef HARM_HQ_CORE + const Word16 element_mode, /* i : element mode */ +#endif + BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ + const Word16 bwidth, /* i : audio bandwidth */ const Word32 *coefs, /* i : Input coefficient vector Q12 */ Word32 *coefs_out, /* o : Quantized output vector Q12 */ const Word32 core_brate, /* i : Core bitrate */ @@ -78,7 +89,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; @@ -97,7 +107,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; @@ -105,7 +114,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 ); @@ -133,7 +141,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 */ @@ -201,11 +218,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_CORE + IF( element_mode == EVS_MONO ) + { + logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 32, 1, 1 ); + } + ELSE +#endif + { + logqnorm_ivas_fx( pPeakGains++, 14, pPgainCbIdx++, 32, 1, &thren_pg_fx[0] ); + } vqPeaksMinus1 = sub( vq_peaks, 1 ); FOR( i = 0; i < vqPeaksMinus1; i++ ) { - logqnorm_ivas_fx( pPeakGains++, 14, pPgainCbIdx++, 45, 1, &thren_pg_fx[0] ); +#ifdef HARM_HQ_CORE + IF( element_mode == EVS_MONO ) + { + logqnorm_fx( pPeakGains++, 14, pPgainCbIdx++, 45, 1, 1 ); + } + ELSE +#endif + { + logqnorm_ivas_fx( pPeakGains++, 14, pPgainCbIdx++, 45, 1, &thren_pg_fx[0] ); + } } /* Code quantized peak gain indices @@ -310,18 +345,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_CORE + quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks ); +#else quant_peaks_ivas_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, num_overlap_bins, core_brate, vq_peaks ); +#endif push_indice( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); bits = add( bits, 9 ); } indx = sub( vq_peak_idx[i], 2 ); +#ifdef HARM_HQ_CORE + quant_peaks_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks ); +#else quant_peaks_ivas_fx( hBstr, &coefs[indx], &coefs_out[indx], &peak_gains[i], &vq_cb_idx, 0, core_brate, vq_peaks ); +#endif push_indice( hBstr, IND_HVQ_PEAKS, vq_cb_idx, 8 ); bits = add( bits, 9 ); /* Quantize peak positions and sign with HVQ */ +#ifdef HARM_HQ_CORE + pos_bits = hvq_code_pos_fx( hBstr, pos_vec, bin_th, vq_peaks ); +#else pos_bits = hvq_code_pos_ivas_fx( hBstr, pos_vec, bin_th, vq_peaks ); +#endif bits = add( bits, pos_bits ); bit_budget = sub( num_bits, bits ); @@ -363,7 +410,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_CORE + IF( element_mode == EVS_MONO ) + { + logqnorm_fx( pPvqVectorBandStart, 12, &pvq_norm[k], 40, hvq_band_width[k], 0 ); + } + ELSE +#endif + { + logqnorm_ivas_fx( pPvqVectorBandStart, 12, &pvq_norm[k], 40, hvq_band_width[k], &thren_HQ_fx[0] ); + } } /* Normalize coefficients */ @@ -377,8 +434,12 @@ Word16 peak_vq_enc_ivas_fx( move16(); set16_fx( npulses, 0, MAX_PVQ_BANDS ); +#ifdef HARM_HQ_CORE + pvq_encode_frame_fx( hBstr, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, Rk, pvq_bits, HQ_CORE ); +#else pvq_encode_frame_ivas_fx( hBstr, pvq_vector_norm, Q_coefs, coefs_pvq, gopt, npulses, pvq_inp_vector, hvq_band_start, hvq_band_end, hvq_band_width, pvq_bands, Rk, pvq_bits, HQ_CORE ); +#endif FOR( i = 0; i < pvq_bands; i++ ) { @@ -386,9 +447,19 @@ Word16 peak_vq_enc_ivas_fx( move16(); } - +#ifdef HARM_HQ_CORE +#ifdef HARM_HQ_CORE_KEEP_BE + (void) element_mode; + fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, NULL, NULL, pvq_bands, coefs_pvq, + 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 ); +#endif pCoefsOut = &coefs_out[0]; pSelBnds = &sel_bnds[0]; @@ -459,6 +530,8 @@ Word16 peak_vq_enc_ivas_fx( return bits; } + +#ifndef HARM_HQ_CORE Word16 peak_vq_enc_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 bwidth, /* i : audio bandwidth */ @@ -498,7 +571,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; @@ -520,13 +592,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 ); @@ -804,7 +874,6 @@ Word16 peak_vq_enc_fx( move16(); } - fine_gain_pred_fx( hvq_band_start, hvq_band_end, hvq_band_width, k_sort, npulses, NULL, NULL, pvq_bands, coefs_pvq, pvq_inp_vector, fg_pred, HQ_CORE ); @@ -876,14 +945,20 @@ Word16 peak_vq_enc_fx( return bits; } +#endif /*-------------------------------------------------------------------------- * quant_peaks_fx() * * Applies VQ on input vector *--------------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE +static void quant_peaks_fx( +#else static void quant_peaks_ivas_fx( - 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 */ @@ -1036,6 +1111,7 @@ static void quant_peaks_ivas_fx( return; } +#ifndef HARM_HQ_CORE static void quant_peaks_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word32 *vect_in, /* i : Target vector in Q12 */ @@ -1192,6 +1268,7 @@ static void quant_peaks_fx( return; } +#endif /*-------------------------------------------------------------------------- * code_pos() @@ -1275,6 +1352,7 @@ static Word16 sparse_code_pos_fx( * * Code pulse positions *--------------------------------------------------------------------------*/ +#ifndef HARM_HQ_CORE static Word16 hvq_code_pos_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *inp, @@ -1386,6 +1464,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 */ diff --git a/lib_enc/prot_fx_enc.h b/lib_enc/prot_fx_enc.h index abcb704e15984765394e9f00712d725b286f4be0..ab96335fcdccbc2f54a83cacc8ad3d3892c195c0 100644 --- a/lib_enc/prot_fx_enc.h +++ b/lib_enc/prot_fx_enc.h @@ -808,6 +808,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*/ @@ -829,7 +830,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 */ @@ -3504,6 +3505,9 @@ Word16 Pit_exc_contribution_len_fx( Word16 Qnew ); Word16 pvq_core_enc_fx( +#ifdef HARM_HQ_CORE + const Word16 element_mode, /* i : element mode */ +#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ Word16 coefs_norm[], /* i/o: normalized coefficients to encode */ Word16 coefs_quant[], /* o : quantized coefficients */ @@ -3520,6 +3524,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 */ @@ -3536,6 +3541,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*/ @@ -3552,6 +3558,7 @@ void hq_lr_enc_fx( ); void hq_hr_enc_fx( +#ifndef HARM_HQ_CORE Encoder_State *st_fx, /* i/o: encoder state structure fx */ Word32 *t_audio, /* i/o: transform-domain coefficients Q12 */ const Word16 length, /* i : length of spectrum Q0 */ @@ -3561,6 +3568,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 */ @@ -3596,6 +3604,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 */ @@ -3608,7 +3617,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 */ @@ -3618,6 +3627,7 @@ void diff_envelope_coding_fx( Word16 *difidx /* o : differential code Q0 */ ); +#ifndef HARM_HQ_CORE /* o : Number of bits if flag_pack=0,0 if flag_pack=1 Q0 */ Word16 encode_envelope_indices_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i : handle to the bitstream Q0 */ @@ -3637,7 +3647,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 */ @@ -3663,6 +3673,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 */ @@ -3695,7 +3706,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 */ @@ -3746,6 +3757,7 @@ void diffcod_lrmdct_fx( const Word16 is_transient /* i : transient flag Q0*/ ); +#ifndef HARM_HQ_CORE Word16 peak_vq_enc_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 bwidth, /* i : audio bandwidth */ @@ -3759,8 +3771,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_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 */ @@ -3949,6 +3964,7 @@ void pvq_encode_frame_fx( const Word16 core /* i : core */ ); +#ifndef HARM_HQ_CORE void pvq_encode_frame_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *coefs_norm, /* i : normalized coefficients to encode */ @@ -3965,7 +3981,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 */ @@ -3997,6 +4013,7 @@ void pvq_encode_fx( const Word16 neg_gain /* i : Gain use - negative gain in Q15 0 ..1 */ ); +#ifndef HARM_HQ_CORE void pvq_encode_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -4008,7 +4025,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 5ce698f464879f0e0dbd48765f24adae089c2207..c75798e5d666305a13a65354c499af92d108e927 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_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 */ @@ -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_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 + +/*-------------------------------------------------------------------* + * pvq_encode_band() + * + * Encode band with PVQ + *--------------------------------------------------------------------*/ + +#ifndef HARM_HQ_CORE /* Encode band with PVQ */ static void pvq_encode_band_ivas_fx( BSTR_ENC_HANDLE hBstr, /* i/o: Encoder bitstream handle */ @@ -133,6 +145,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 +160,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]; @@ -236,7 +248,19 @@ static void pvq_encode_band_fx( return; } + + +/*-------------------------------------------------------------------* + * pvq_encode_frame() + * + * + *--------------------------------------------------------------------*/ + +#ifdef HARM_HQ_CORE +void pvq_encode_frame_fx( +#else void pvq_encode_frame_ivas_fx( +#endif BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *coefs_norm, /* i : normalized coefficients to encode */ Word16 Q_coefs, /* i : Q-point of coefs_norm[] */ @@ -255,7 +279,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; @@ -310,14 +333,23 @@ 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 ); + +#ifdef HARM_HQ_CORE + pvq_encode_band_fx( hBstr, hPVQ, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], + &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, &bits_left, strict_bits ); +#else pvq_encode_band_ivas_fx( hBstr, hPVQ, &coefs_norm[sfm_start[is]], Q_coefs, &pulse_vector[sfm_start[is]], - &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, - &bits_left, strict_bits ); + &npulses[is], &coefs_quant[sfm_start[is]], sfmsize[is], band_bits, &bits_left, strict_bits ); +#endif xy_corr = L_deposit_l( 0 ); yy_corr = L_deposit_l( 1 ); +#ifdef HARM_HQ_CORE + shift = band_len_ener_shift[band_len_idx[shr( sfmsize[is], 3 )]]; +#else shift = ivas_band_len_ener_shift[ivas_band_len_idx[shr( sfmsize[is], 3 )]]; +#endif move16(); FOR( j = 0; j < sfmsize[i]; j++ ) { @@ -356,6 +388,7 @@ void pvq_encode_frame_ivas_fx( return; } +#ifndef HARM_HQ_CORE void pvq_encode_frame_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ const Word16 *coefs_norm, /* i : normalized coefficients to encode */ @@ -430,10 +463,10 @@ 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 ); @@ -474,13 +507,20 @@ void pvq_encode_frame_fx( return; } +#endif /*---------------------------------------------------------------------* * 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 +548,19 @@ 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( element_mode, core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); +#else gain_bits_tot = ivas_assign_gain_bits_fx( core, nb_sfm, sfmsize, R, gain_bits_array, &R_upd ); +#endif pvq_bits = shr( R_upd, 3 ); +#ifdef HARM_HQ_CORE + pvq_encode_frame_fx( hBstr, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); +#else pvq_encode_frame_ivas_fx( hBstr, coefs_norm, *Q_coefs, coefs_quant, gopt, npulses, pulse_vector, sfm_start, sfm_end, sfmsize, nb_sfm, R, pvq_bits, core ); - +#endif IF( Rs != NULL ) { @@ -542,16 +588,25 @@ 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_CORE + fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, + coefs_quant, pulse_vector, fg_pred, element_mode, core ); +#else ivas_fine_gain_pred_fx( sfm_start, sfm_end, sfmsize, ord, npulses, maxpulse, R, nb_sfm, coefs_quant, pulse_vector, fg_pred, core ); +#endif fine_gain_quant_fx( hBstr, ord, nb_sfm, gain_bits_array, fg_pred, gopt ); apply_gain_fx( ord, sfm_start, sfm_end, nb_sfm, fg_pred, coefs_quant ); - *Q_coefs = 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 +680,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 */ @@ -720,7 +776,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 */ @@ -740,8 +795,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 ) ) { @@ -768,6 +822,8 @@ static void encode_energies_fx( return; } + +#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 */ @@ -910,6 +966,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 */ @@ -982,6 +1039,7 @@ static void densityIndexSymbolEncode_ivas_fx( return; } +#endif static void densityIndexSymbolEncode_fx( BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */ @@ -1056,19 +1114,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_CORE +/* o : Number of segments */ +static Word16 calc_pvq_splits_fx( +#else +static Word16 calc_pvq_splits_ivas_fx( /* o : Number of segments */ +#endif + BSTR_ENC_HANDLE hBstr, /* i/o: Encoder state */ + PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ + const Word16 band_bits, /* i : Band bit rate */ + 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; @@ -1162,8 +1227,11 @@ static Word16 calc_pvq_splits_ivas_fx( /* o : Number of 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 + 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 */ @@ -1267,3 +1335,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 53c18e3abb7238e0f018dc63c70211d311c0c452..d1b392ac2f1e5b212bd66cac143c75ef82e9ee70 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,6 +174,7 @@ static Word16 one_pulse_search( * * *-----------------------------------------------------------------------*/ +#ifndef HARM_HQ_CORE void pvq_encode_ivas_fx( BSTR_ENC_HANDLE hBstr, PVQ_ENC_HANDLE hPVQ, /* i/o: PVQ encoder handle */ @@ -377,6 +379,7 @@ void pvq_encode_ivas_fx( return; } +#endif void pvq_encode_fx( BSTR_ENC_HANDLE hBstr, diff --git a/lib_enc/swb_bwe_enc_fx.c b/lib_enc/swb_bwe_enc_fx.c index b6749e80a144138a2001d900203ebc39d75b7441..c19985a1bf3e45430bc4174dd6cab535f505f67b 100644 --- a/lib_enc/swb_bwe_enc_fx.c +++ b/lib_enc/swb_bwe_enc_fx.c @@ -3012,6 +3012,7 @@ static Word16 decision_hq_generic_class_fx_32( } } +#ifndef HARM_HQ_CORE /*-------------------------------------------------------------------* * hq_generic_encoding_fx() * @@ -3231,7 +3232,7 @@ void hq_generic_encoding_fx( return; } - +#endif /*-------------------------------------------------------------------* * fd_bwe_enc_init_fx() @@ -3286,6 +3287,9 @@ void fd_bwe_enc_init_fx( *-------------------------------------------------------------------*/ void hq_generic_hf_encoding_fx( +#ifdef HARM_HQ_CORE + const Word16 element_mode, /* i : element mode */ +#endif const Word32 *coefs_fx, /* i : MDCT coefficients of weighted original : Q12 */ Word16 *hq_generic_fenv_fx, /* i/o: energy of SWB envelope : Q1 */ const Word16 hq_generic_offset, /* i : frequency offset for extracting energy : Q0 */ @@ -3448,15 +3452,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_CORE + IF( element_mode == EVS_MONO ) + { + indice[5] = vqSimple_w_fx( hq_generic_fenv_fx + nenv, hq_generic_fenv_fx + nenv, EnvCdbkFB_fx, NULL, DIM_FB, N_CB_FB, 0 ); + move16(); + } + ELSE +#endif + { + Word16 sf = getScaleFactor16( hq_generic_fenv_fx, add( DIM_FB, nenv ) ); + Scale_sig( hq_generic_fenv_fx, add( DIM_FB, nenv ), negate( sf ) ); + 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 );