Loading lib_com/bits_alloc_fx.c +1 −2 Original line number Diff line number Diff line Loading @@ -408,7 +408,7 @@ static Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( return bitsused; } /*#ifdef IVAS_CODE Below basop operators are missing */ /*-------------------------------------------------------------------* * fcb_table() * Loading Loading @@ -3271,4 +3271,3 @@ Word16 set_ACELP_flag_IVAS( return 0; } } /*#endif IVAS_CODE*/ lib_com/est_tilt_fx.c +13 −22 Original line number Diff line number Diff line Loading @@ -40,18 +40,12 @@ Word16 est_tilt_fx( /* o : tilt of the code const Word32 gain_code, /* i : algebraic code gain Q16 */ Word16 *voice_fac, /* o : voicing factor Q15 */ const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ #ifdef ADD_LRTD , const Word16 L_subfr /* i : Sub frame length */ #endif ) { Word16 i, tmp, exp, ener1, exp1, ener2, exp2; Word32 L_tmp; Word16 tilt_code; #ifdef ADD_LRTD PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " ) #endif ener1 = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp1 ) ); exp1 = sub( exp1, add( Q_exc, Q_exc ) ); L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */ Loading Loading @@ -117,26 +111,23 @@ Word16 est_tilt_fx( /* o : tilt of the code /* RETURN ARGUMENTS : */ /* _ (Word16) tolt_code : tilt of the code Q15 */ /*=======================================================================*/ Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 */ /* o : tilt of the code Q15 */ Word16 est_tilt_ivas_fx( const Word16 *exc, /* i : adaptive excitation vector Qx */ const Word16 gain_pit, /* i : adaptive gain Q14 */ const Word16 *code, /* i : algebraic excitation vector Q9 */ const Word32 gain_code, /* i : algebraic code gain Q16 */ Word16 *voice_fac, /* o : voicing factor Q15 */ const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ #if 1 // def ADD_LRTD , const Word16 Q_exc, /* i : Scaling factor of excitation Q0 */ const Word16 L_subfr, /* i : Sub frame length */ const Word16 flag_tilt /* i : flag for special tilt */ #endif ) { Word16 i, tmp, exp, ener1, exp1, ener2, exp2; Word32 L_tmp; Word16 tilt_code; #ifdef ADD_LRTD PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " ) #endif ener1 = extract_h( Dot_product12( exc, exc, L_subfr, &exp1 ) ); exp1 = sub( exp1, add( Q_exc, Q_exc ) ); L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */ Loading lib_com/fd_cng_com_fx.c +0 −5 Original line number Diff line number Diff line Loading @@ -566,11 +566,6 @@ void minimum_statistics( Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ Word16 *msPeriodogBufPtr, /* i/o: Counter */ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ #ifdef IVAS_CODE_CNG , const Word16 enc_dec, /* i : encoder/decoder indicator */ const Word16 element_mode /* i : IVAS element mode type */ #endif ) { Word16 i, j, k, s, s1, s2, s3; Loading lib_com/frame_ener.cdeleted 100644 → 0 +0 −333 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository. All Rights Reserved. This software is protected by copyright law and by international treaties. The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository retain full ownership rights in their respective contributions in the software. This notice grants no license of any kind, including but not limited to patent license, nor is any license granted by implication, estoppel or otherwise. Contributors are required to enter into the IVAS codec Public Collaboration agreement before making contributions. This software is provided "AS IS", without any express or implied warranties. The software is in the development stage. It is intended exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. Any dispute, controversy or claim arising under or in relation to providing this software shall be submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ /*==================================================================================== EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 ====================================================================================*/ #include <stdint.h> #include "options.h" #include <math.h> #include "cnst.h" #include "prot.h" #include "wmc_auto.h" #include "prot_fx.h" /*----------------------------------------------------------------------------------* * fer_energy() * * Estimation of pitch-synchronous (voiced sounds) or half-frame energy *----------------------------------------------------------------------------------*/ #ifndef IVAS_FLOAT_FIXED void fer_energy( const int16_t L_frame, /* i : frame length */ const int16_t clas, /* i : frame classification */ const float *synth, /* i : synthesized speech at Fs = 12k8 Hz */ const float pitch, /* i : pitch period */ float *enr, /* o : pitch-synchronous or half_frame energy */ const int16_t offset /* i : speech pointer offset (0 or L_frame) */ ) { int16_t len; const float *pt_synth; if ( clas == VOICED_CLAS || clas == ONSET || clas == SIN_ONSET ) /* Voiced or Onset current frame */ { len = (int16_t) ( pitch + 0.5f ); /* pitch value */ pt_synth = synth; if ( offset != 0 ) { pt_synth = synth + L_frame - len; } emaximum( pt_synth, len, enr ); /* pitch synchronous E */ } else { pt_synth = synth; if ( offset != 0 ) { pt_synth = synth + L_frame / 2; } *enr = dotp( pt_synth, pt_synth, L_frame / 2 ); *enr /= (float) ( L_frame / 2 ); } return; } #endif void fer_energy_fx( const Word16 L_frame, /* i : frame length */ const Word16 clas, /* i : frame classification */ const Word32 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q(q_synth) */ const Word16 q_synth, /* i : synthesized speech at Fs = 12k8 Hz */ const Word16 pitch, /* i : pitch period Q0 */ Word32 *enr, /* o : pitch-synchronous or half_frame energy Q0 */ const Word16 offset /* i : speech pointer offset (0 or L_frame) */ ) { Word16 len, shift, exp; const Word32 *pt_synth; Word16 enr_tmp, i; Word64 W_tmp; test(); test(); IF( EQ_16( clas, VOICED_CLAS ) || EQ_16( clas, ONSET ) || EQ_16( clas, SIN_ONSET ) ) /* Voiced or Onset current frame */ { len = ( pitch ); /* pitch value */ move16(); pt_synth = synth; IF( offset != 0 ) { pt_synth = synth + sub( L_frame, len ); } emaximum_32fx( q_synth, pt_synth, len, enr ); /* pitch synchronous E */ } ELSE { pt_synth = synth; IF( offset != 0 ) { pt_synth = synth + shr( L_frame, 1 ); } W_tmp = 0; move64(); FOR( i = 0; i < L_frame / 2; i++ ) { W_tmp = W_add( W_tmp, W_mult0_32_32( pt_synth[i], pt_synth[i] ) ); // Q = q_synth * 2 } shift = W_norm( W_tmp ); W_tmp = W_shl( W_tmp, shift ); // Q = q_synth * 2 + shift *enr = W_extract_h( W_tmp ); // Q = q_synth * 2 + shift - 32 move32(); enr_tmp = BASOP_Util_Divide3216_Scale( *enr, shr( L_frame, 1 ) /*Q0*/, &exp ); *enr = L_shr( L_deposit_l( enr_tmp ), sub( sub( sub( shift, 32 ), exp ), 1 ) ); /*Q0*/ move32(); } return; } /*----------------------------------------------------------------------------------* * frame_ener() * * Estimation of pitch-synchronous (voiced) or mean half-frame (unvoiced) energy *----------------------------------------------------------------------------------*/ Word16 frame_ener_fx( const Word16 L_frame, /* i : length of the frame */ const Word16 clas, /* i : frame classification */ const Word16 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q_new */ const Word16 pitch, /* i : pitch period Q0 */ Word32 *enr_q, /* o : pitch-synchronous or half_frame energy Q0 */ const Word16 offset, /* i : speech pointer offset (0 or L_FRAME) */ const Word16 Q_new, /* i : Scaling factor */ Word16 shift, /* i : Shift need to obtain 12 bits vectors */ const Word16 enc /* i : Encoder/decoder */ ) { Word16 len, exp_enrq, exp_tmp, pos; Word16 i; const Word16 *pt_synth; Word32 Ltmp; exp_enrq = 0; move16(); test(); test(); IF( ( EQ_16( clas, VOICED_CLAS ) ) || ( EQ_16( clas, ONSET ) ) || ( EQ_16( clas, SIN_ONSET ) ) ) /* current frame is voiced */ { /* current frame is voiced */ len = pitch; move16(); /* pitch value at the end of frame */ pt_synth = synth; if ( offset != 0 ) { pt_synth = synth + sub( L_frame, len ); } emaximum_fx( Q_new, pt_synth, len, enr_q ); IF( enc != 0 ) { exp_enrq = norm_l( *enr_q ); *enr_q = L_shl( *enr_q, exp_enrq ); move32(); exp_enrq = sub( exp_enrq, 2 ); } } ELSE { /* current frame is unvoiced */ Word16 L_frame2, exp2, enr_q_tmp; L_frame2 = shr( L_frame, 1 ); pos = 0; move16(); if ( offset != 0 ) { pos = sub( L_frame, L_frame2 ); } Ltmp = L_mult_sat( synth[pos], synth[pos] ); /*2 * Qnew + 1*/ FOR( i = 1; i < L_frame2; i++ ) { Ltmp = L_mac_sat( Ltmp, synth[pos + i], synth[pos + i] ); /*2 * Qnew + 1*/ } test(); IF( EQ_32( Ltmp, MAX_32 ) || enc != 0 ) { /* scale down when overflow occurs */ *enr_q = Energy_scale( synth + pos, L_frame2, shift, &exp_enrq ); move32(); } ELSE { shift = 0; move16(); /* Normalize acc in Q31 (energy already calculated) */ pos = norm_l( Ltmp ); Ltmp = L_shl( Ltmp, pos ); exp_enrq = sub( 30, pos ); /* exponent = 0..30 */ *enr_q = Ltmp; move32(); } /* enr2 = 1.0f/L_FRAME2 * dot_product(synth, synth, L_FRAME2) */ exp_enrq = sub( exp_enrq, shl( shift, 1 ) ); IF( enc != 0 ) { assert( L_frame == 256 || L_frame == 320 ); exp_tmp = add( shl( Q_new, 1 ), -2 + 7 ); /* L_subfr == L_SUBFR */ exp_enrq = sub( exp_enrq, exp_tmp ); exp_enrq = sub( 31, exp_enrq ); IF( EQ_16( L_frame, 320 ) ) { *enr_q = Mult_32_16( *enr_q, 26214 ); /*x 0.8 to get /160*/ move32(); i = norm_l( *enr_q ); *enr_q = L_shl( *enr_q, i ); move32(); exp_enrq = add( i, exp_enrq ); } } ELSE { exp_enrq = sub( exp_enrq, add( Q_new, Q_new ) ); enr_q_tmp /*Q30 exp2+exp_enrq*/ = BASOP_Util_Divide3216_Scale( *enr_q /*Q31*/, L_frame2 /*Q0*/, &exp2 ); *enr_q = L_shr( L_deposit_l( enr_q_tmp ), sub( 30, add( exp2, exp_enrq ) ) ); /*Q0*/ move32(); *enr_q = L_add( *enr_q, 1 ); move32(); exp_enrq = 0; move16(); } } return exp_enrq; } /*------------------------------------------------------------------------* * frame_energy() * * Compute pitch-synchronous energy at the frame end *------------------------------------------------------------------------*/ Word16 frame_energy_fx( /* o : Frame energy in Q8 */ Word16 L_frame, const Word16 *pitch, /* i : pitch values for each subframe Q6 */ const Word16 *speech, /* i : pointer to speech signal for E computation Q_syn*/ const Word16 lp_speech, /* i : long term active speech energy average Q8 */ Word16 *frame_ener, /* o : pitch-synchronous energy at frame end Q8 */ const Word16 Q_syn /* i : Synthesis scaling */ ) { Word32 Ltmp; const Word16 *pt1; Word16 tmp16, exp1, exp2, tmp1, tmp2; Word16 len, enern; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif /* len = (0.5f * (pitch[2]/64.0 + pitch[3]/64.0) + 0.5f) */ len = mult_r( add_o( pitch[2], pitch[3], &Overflow ), 256 ); if ( LT_16( len, L_SUBFR ) ) { len = shl( len, 1 ); } pt1 = speech + sub( L_frame, len ); /* *frame_ener = 10.0f * log10(dot_product(pt1, pt1, len) / (float)len) */ tmp1 = norm_s( len ); tmp2 = shl( len, tmp1 ); tmp1 = sub( 15, tmp1 ); Ltmp = Dot_productSq16HQ( 0, pt1, len, &exp1 ); exp1 = sub( exp1, shl( Q_syn, 1 ) ); exp1 = sub( exp1, 1 ); /* compensation of leftshift caused by mac operation in dot_productSq16HQ */ tmp16 = BASOP_Util_Divide3216_Scale( Ltmp, len, &exp2 ); exp1 = add( exp1, exp2 ); exp1 = add( exp1, 1 ); /* compensate result of division Q-1 */ tmp2 = norm_s( tmp16 ); Ltmp = L_shl( L_deposit_h( tmp16 ), tmp2 ); /*Q16, (exp1-tmp2) = Q31, exp1-tmp2+15*/ Ltmp = BASOP_Util_Log2( Ltmp ); /*Q(31-6) = Q25*/ exp1 = sub( 15 + exp1, tmp2 ); /*add ld(2^exp1)=exp1 but check format, first*/ tmp16 = sub( sub( 15, norm_s( exp1 ) ), 5 ); /*factor to shift Ltmp and exp1 with (shr) to avoid overflows when adding*/ Ltmp = L_shr_o( Ltmp, tmp16, &Overflow ); /*Q25, tmp16*/ exp2 = shr( exp1, tmp16 ); /*Q0 , tmp16*/ Ltmp = L_add_o( Ltmp, L_shl( L_deposit_l( exp2 ), 25 ), &Overflow ); /*Q25, tmp16, normalized*/ /*make 10*log10 out of log2*/ Ltmp = Mpy_32_16_1( Ltmp, LG10 ); /*Q25,tmp16 * Q13 = Q23, tmp16*/ *frame_ener = extract_h( L_shl_o( Ltmp, add( tmp16, 1 ), &Overflow ) ); /*Q8*/ move16(); enern = sub_o( *frame_ener, lp_speech, &Overflow ); /*Q8*/ return enern; } lib_com/get_gain.cdeleted 100644 → 0 +0 −170 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository. All Rights Reserved. This software is protected by copyright law and by international treaties. The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository retain full ownership rights in their respective contributions in the software. This notice grants no license of any kind, including but not limited to patent license, nor is any license granted by implication, estoppel or otherwise. Contributors are required to enter into the IVAS codec Public Collaboration agreement before making contributions. This software is provided "AS IS", without any express or implied warranties. The software is in the development stage. It is intended exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. Any dispute, controversy or claim arising under or in relation to providing this software shall be submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ /*==================================================================================== EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 ====================================================================================*/ #include <stdint.h> #include "options.h" #include "prot.h" #include "wmc_auto.h" #include "prot_fx.h" /*----------------------------------------------------------------------------------* * get_gain() * * *----------------------------------------------------------------------------------*/ #ifndef IVAS_FLOAT_FIXED /*! r: codebook gain (adaptive or fixed) */ float get_gain_flt( const float x[], /* i : target signal */ const float y[], /* i : filtered codebook excitation */ const int16_t n, /* i : segment length */ float *en_y /* o : energy of y (sum of y[]^2, optional) */ ) { float corr = 0.0f, ener = 1e-6f; int16_t i; for ( i = 0; i < n; i++ ) { corr += x[i] * y[i]; ener += y[i] * y[i]; } if ( en_y ) { *en_y = ener; } return ( corr / ener ); } #endif Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */ const Word16 x[], /* input : target signal Qx */ const Word16 y[], /* input : filtered codebook excitation Qx */ const Word16 n /* input : segment length */ ) { Word32 tcorr, tener, Lgain; Word16 exp_c, exp_e, exp, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif tcorr = L_deposit_l( 0 ); tener = L_deposit_l( 0 ); /*----------------------------------------------------------------* * Find gain based on inter-correlation product *----------------------------------------------------------------*/ tcorr = Dot_product16HQ( 0, x, y, n, &exp_c ); tener = Dot_productSq16HQ( 0, y, n, &exp_e ); BASOP_Util_Divide_MantExp( round_fx_o( tcorr, &Overflow ), exp_c, s_max( round_fx_o( tener, &Overflow ), 1 ), exp_e, &tmp, &exp ); Lgain = L_shl_o( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ), &Overflow ) /*Q16*/; return Lgain; } Word32 get_gain2( /* output: codebook gain (adaptive or fixed) Q16 */ const Word16 x[], /* input : target signal */ const Word16 y[], /* input : filtered codebook excitation */ const Word16 n /* input : segment length */ ) { Word32 tcorr, tener, Lgain; Word16 m_corr, m_ener, negative, Q_corr, Q_ener; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif negative = 0; move16(); /*----------------------------------------------------------------* * Find gain based on inter-correlation product *----------------------------------------------------------------*/ tcorr = Dot_product16HQ( 0, x, y, n, &Q_corr ); tener = Dot_productSq16HQ( 0, y, n, &Q_ener ); tener = L_max( tener, 1 ); if ( tcorr <= 0 ) { negative = 1; move16(); } BASOP_SATURATE_WARNING_OFF_EVS /*tcorr max be negative maxvall - not critical*/ tcorr = L_abs( tcorr ); BASOP_SATURATE_WARNING_ON_EVS m_corr = extract_h( tcorr ); m_ener = extract_h( tener ); IF( GT_16( m_corr, m_ener ) ) { m_corr = shr( m_corr, 1 ); Q_corr = add( Q_corr, 1 ); } if ( m_ener == 0 ) { move16(); m_corr = 0x7FFF; } IF( m_ener != 0 ) { m_corr = div_s( m_corr, m_ener ); } Q_corr = sub( Q_corr, Q_ener ); Lgain = L_shl_o( L_deposit_l( m_corr ), add( Q_corr, 1 ), &Overflow ); /* Lgain in Q16 */ if ( negative != 0 ) { Lgain = L_negate( Lgain ); /* Lgain in Q16 */ } return Lgain; } Loading
lib_com/bits_alloc_fx.c +1 −2 Original line number Diff line number Diff line Loading @@ -408,7 +408,7 @@ static Word16 BITS_ALLOC_adjust_acelp_fixed_cdk( return bitsused; } /*#ifdef IVAS_CODE Below basop operators are missing */ /*-------------------------------------------------------------------* * fcb_table() * Loading Loading @@ -3271,4 +3271,3 @@ Word16 set_ACELP_flag_IVAS( return 0; } } /*#endif IVAS_CODE*/
lib_com/est_tilt_fx.c +13 −22 Original line number Diff line number Diff line Loading @@ -40,18 +40,12 @@ Word16 est_tilt_fx( /* o : tilt of the code const Word32 gain_code, /* i : algebraic code gain Q16 */ Word16 *voice_fac, /* o : voicing factor Q15 */ const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ #ifdef ADD_LRTD , const Word16 L_subfr /* i : Sub frame length */ #endif ) { Word16 i, tmp, exp, ener1, exp1, ener2, exp2; Word32 L_tmp; Word16 tilt_code; #ifdef ADD_LRTD PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " ) #endif ener1 = extract_h( Dot_product12( exc, exc, L_SUBFR, &exp1 ) ); exp1 = sub( exp1, add( Q_exc, Q_exc ) ); L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */ Loading Loading @@ -117,26 +111,23 @@ Word16 est_tilt_fx( /* o : tilt of the code /* RETURN ARGUMENTS : */ /* _ (Word16) tolt_code : tilt of the code Q15 */ /*=======================================================================*/ Word16 est_tilt_ivas_fx( /* o : tilt of the code Q15 */ /* o : tilt of the code Q15 */ Word16 est_tilt_ivas_fx( const Word16 *exc, /* i : adaptive excitation vector Qx */ const Word16 gain_pit, /* i : adaptive gain Q14 */ const Word16 *code, /* i : algebraic excitation vector Q9 */ const Word32 gain_code, /* i : algebraic code gain Q16 */ Word16 *voice_fac, /* o : voicing factor Q15 */ const Word16 Q_exc /* i : Scaling factor of excitation Q0 */ #if 1 // def ADD_LRTD , const Word16 Q_exc, /* i : Scaling factor of excitation Q0 */ const Word16 L_subfr, /* i : Sub frame length */ const Word16 flag_tilt /* i : flag for special tilt */ #endif ) { Word16 i, tmp, exp, ener1, exp1, ener2, exp2; Word32 L_tmp; Word16 tilt_code; #ifdef ADD_LRTD PMT( "FIX POINT NEED to be adapted for 16 kHz frame length " ) #endif ener1 = extract_h( Dot_product12( exc, exc, L_subfr, &exp1 ) ); exp1 = sub( exp1, add( Q_exc, Q_exc ) ); L_tmp = L_mult( gain_pit, gain_pit ); /* energy of pitch excitation */ Loading
lib_com/fd_cng_com_fx.c +0 −5 Original line number Diff line number Diff line Loading @@ -566,11 +566,6 @@ void minimum_statistics( Word16 *msPeriodogBuf, /* i/o: Buffer of periodograms (energies) */ Word16 *msPeriodogBufPtr, /* i/o: Counter */ HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */ #ifdef IVAS_CODE_CNG , const Word16 enc_dec, /* i : encoder/decoder indicator */ const Word16 element_mode /* i : IVAS element mode type */ #endif ) { Word16 i, j, k, s, s1, s2, s3; Loading
lib_com/frame_ener.cdeleted 100644 → 0 +0 −333 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository. All Rights Reserved. This software is protected by copyright law and by international treaties. The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository retain full ownership rights in their respective contributions in the software. This notice grants no license of any kind, including but not limited to patent license, nor is any license granted by implication, estoppel or otherwise. Contributors are required to enter into the IVAS codec Public Collaboration agreement before making contributions. This software is provided "AS IS", without any express or implied warranties. The software is in the development stage. It is intended exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. Any dispute, controversy or claim arising under or in relation to providing this software shall be submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ /*==================================================================================== EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 ====================================================================================*/ #include <stdint.h> #include "options.h" #include <math.h> #include "cnst.h" #include "prot.h" #include "wmc_auto.h" #include "prot_fx.h" /*----------------------------------------------------------------------------------* * fer_energy() * * Estimation of pitch-synchronous (voiced sounds) or half-frame energy *----------------------------------------------------------------------------------*/ #ifndef IVAS_FLOAT_FIXED void fer_energy( const int16_t L_frame, /* i : frame length */ const int16_t clas, /* i : frame classification */ const float *synth, /* i : synthesized speech at Fs = 12k8 Hz */ const float pitch, /* i : pitch period */ float *enr, /* o : pitch-synchronous or half_frame energy */ const int16_t offset /* i : speech pointer offset (0 or L_frame) */ ) { int16_t len; const float *pt_synth; if ( clas == VOICED_CLAS || clas == ONSET || clas == SIN_ONSET ) /* Voiced or Onset current frame */ { len = (int16_t) ( pitch + 0.5f ); /* pitch value */ pt_synth = synth; if ( offset != 0 ) { pt_synth = synth + L_frame - len; } emaximum( pt_synth, len, enr ); /* pitch synchronous E */ } else { pt_synth = synth; if ( offset != 0 ) { pt_synth = synth + L_frame / 2; } *enr = dotp( pt_synth, pt_synth, L_frame / 2 ); *enr /= (float) ( L_frame / 2 ); } return; } #endif void fer_energy_fx( const Word16 L_frame, /* i : frame length */ const Word16 clas, /* i : frame classification */ const Word32 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q(q_synth) */ const Word16 q_synth, /* i : synthesized speech at Fs = 12k8 Hz */ const Word16 pitch, /* i : pitch period Q0 */ Word32 *enr, /* o : pitch-synchronous or half_frame energy Q0 */ const Word16 offset /* i : speech pointer offset (0 or L_frame) */ ) { Word16 len, shift, exp; const Word32 *pt_synth; Word16 enr_tmp, i; Word64 W_tmp; test(); test(); IF( EQ_16( clas, VOICED_CLAS ) || EQ_16( clas, ONSET ) || EQ_16( clas, SIN_ONSET ) ) /* Voiced or Onset current frame */ { len = ( pitch ); /* pitch value */ move16(); pt_synth = synth; IF( offset != 0 ) { pt_synth = synth + sub( L_frame, len ); } emaximum_32fx( q_synth, pt_synth, len, enr ); /* pitch synchronous E */ } ELSE { pt_synth = synth; IF( offset != 0 ) { pt_synth = synth + shr( L_frame, 1 ); } W_tmp = 0; move64(); FOR( i = 0; i < L_frame / 2; i++ ) { W_tmp = W_add( W_tmp, W_mult0_32_32( pt_synth[i], pt_synth[i] ) ); // Q = q_synth * 2 } shift = W_norm( W_tmp ); W_tmp = W_shl( W_tmp, shift ); // Q = q_synth * 2 + shift *enr = W_extract_h( W_tmp ); // Q = q_synth * 2 + shift - 32 move32(); enr_tmp = BASOP_Util_Divide3216_Scale( *enr, shr( L_frame, 1 ) /*Q0*/, &exp ); *enr = L_shr( L_deposit_l( enr_tmp ), sub( sub( sub( shift, 32 ), exp ), 1 ) ); /*Q0*/ move32(); } return; } /*----------------------------------------------------------------------------------* * frame_ener() * * Estimation of pitch-synchronous (voiced) or mean half-frame (unvoiced) energy *----------------------------------------------------------------------------------*/ Word16 frame_ener_fx( const Word16 L_frame, /* i : length of the frame */ const Word16 clas, /* i : frame classification */ const Word16 *synth, /* i : synthesized speech at Fs = 12k8 Hz Q_new */ const Word16 pitch, /* i : pitch period Q0 */ Word32 *enr_q, /* o : pitch-synchronous or half_frame energy Q0 */ const Word16 offset, /* i : speech pointer offset (0 or L_FRAME) */ const Word16 Q_new, /* i : Scaling factor */ Word16 shift, /* i : Shift need to obtain 12 bits vectors */ const Word16 enc /* i : Encoder/decoder */ ) { Word16 len, exp_enrq, exp_tmp, pos; Word16 i; const Word16 *pt_synth; Word32 Ltmp; exp_enrq = 0; move16(); test(); test(); IF( ( EQ_16( clas, VOICED_CLAS ) ) || ( EQ_16( clas, ONSET ) ) || ( EQ_16( clas, SIN_ONSET ) ) ) /* current frame is voiced */ { /* current frame is voiced */ len = pitch; move16(); /* pitch value at the end of frame */ pt_synth = synth; if ( offset != 0 ) { pt_synth = synth + sub( L_frame, len ); } emaximum_fx( Q_new, pt_synth, len, enr_q ); IF( enc != 0 ) { exp_enrq = norm_l( *enr_q ); *enr_q = L_shl( *enr_q, exp_enrq ); move32(); exp_enrq = sub( exp_enrq, 2 ); } } ELSE { /* current frame is unvoiced */ Word16 L_frame2, exp2, enr_q_tmp; L_frame2 = shr( L_frame, 1 ); pos = 0; move16(); if ( offset != 0 ) { pos = sub( L_frame, L_frame2 ); } Ltmp = L_mult_sat( synth[pos], synth[pos] ); /*2 * Qnew + 1*/ FOR( i = 1; i < L_frame2; i++ ) { Ltmp = L_mac_sat( Ltmp, synth[pos + i], synth[pos + i] ); /*2 * Qnew + 1*/ } test(); IF( EQ_32( Ltmp, MAX_32 ) || enc != 0 ) { /* scale down when overflow occurs */ *enr_q = Energy_scale( synth + pos, L_frame2, shift, &exp_enrq ); move32(); } ELSE { shift = 0; move16(); /* Normalize acc in Q31 (energy already calculated) */ pos = norm_l( Ltmp ); Ltmp = L_shl( Ltmp, pos ); exp_enrq = sub( 30, pos ); /* exponent = 0..30 */ *enr_q = Ltmp; move32(); } /* enr2 = 1.0f/L_FRAME2 * dot_product(synth, synth, L_FRAME2) */ exp_enrq = sub( exp_enrq, shl( shift, 1 ) ); IF( enc != 0 ) { assert( L_frame == 256 || L_frame == 320 ); exp_tmp = add( shl( Q_new, 1 ), -2 + 7 ); /* L_subfr == L_SUBFR */ exp_enrq = sub( exp_enrq, exp_tmp ); exp_enrq = sub( 31, exp_enrq ); IF( EQ_16( L_frame, 320 ) ) { *enr_q = Mult_32_16( *enr_q, 26214 ); /*x 0.8 to get /160*/ move32(); i = norm_l( *enr_q ); *enr_q = L_shl( *enr_q, i ); move32(); exp_enrq = add( i, exp_enrq ); } } ELSE { exp_enrq = sub( exp_enrq, add( Q_new, Q_new ) ); enr_q_tmp /*Q30 exp2+exp_enrq*/ = BASOP_Util_Divide3216_Scale( *enr_q /*Q31*/, L_frame2 /*Q0*/, &exp2 ); *enr_q = L_shr( L_deposit_l( enr_q_tmp ), sub( 30, add( exp2, exp_enrq ) ) ); /*Q0*/ move32(); *enr_q = L_add( *enr_q, 1 ); move32(); exp_enrq = 0; move16(); } } return exp_enrq; } /*------------------------------------------------------------------------* * frame_energy() * * Compute pitch-synchronous energy at the frame end *------------------------------------------------------------------------*/ Word16 frame_energy_fx( /* o : Frame energy in Q8 */ Word16 L_frame, const Word16 *pitch, /* i : pitch values for each subframe Q6 */ const Word16 *speech, /* i : pointer to speech signal for E computation Q_syn*/ const Word16 lp_speech, /* i : long term active speech energy average Q8 */ Word16 *frame_ener, /* o : pitch-synchronous energy at frame end Q8 */ const Word16 Q_syn /* i : Synthesis scaling */ ) { Word32 Ltmp; const Word16 *pt1; Word16 tmp16, exp1, exp2, tmp1, tmp2; Word16 len, enern; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif /* len = (0.5f * (pitch[2]/64.0 + pitch[3]/64.0) + 0.5f) */ len = mult_r( add_o( pitch[2], pitch[3], &Overflow ), 256 ); if ( LT_16( len, L_SUBFR ) ) { len = shl( len, 1 ); } pt1 = speech + sub( L_frame, len ); /* *frame_ener = 10.0f * log10(dot_product(pt1, pt1, len) / (float)len) */ tmp1 = norm_s( len ); tmp2 = shl( len, tmp1 ); tmp1 = sub( 15, tmp1 ); Ltmp = Dot_productSq16HQ( 0, pt1, len, &exp1 ); exp1 = sub( exp1, shl( Q_syn, 1 ) ); exp1 = sub( exp1, 1 ); /* compensation of leftshift caused by mac operation in dot_productSq16HQ */ tmp16 = BASOP_Util_Divide3216_Scale( Ltmp, len, &exp2 ); exp1 = add( exp1, exp2 ); exp1 = add( exp1, 1 ); /* compensate result of division Q-1 */ tmp2 = norm_s( tmp16 ); Ltmp = L_shl( L_deposit_h( tmp16 ), tmp2 ); /*Q16, (exp1-tmp2) = Q31, exp1-tmp2+15*/ Ltmp = BASOP_Util_Log2( Ltmp ); /*Q(31-6) = Q25*/ exp1 = sub( 15 + exp1, tmp2 ); /*add ld(2^exp1)=exp1 but check format, first*/ tmp16 = sub( sub( 15, norm_s( exp1 ) ), 5 ); /*factor to shift Ltmp and exp1 with (shr) to avoid overflows when adding*/ Ltmp = L_shr_o( Ltmp, tmp16, &Overflow ); /*Q25, tmp16*/ exp2 = shr( exp1, tmp16 ); /*Q0 , tmp16*/ Ltmp = L_add_o( Ltmp, L_shl( L_deposit_l( exp2 ), 25 ), &Overflow ); /*Q25, tmp16, normalized*/ /*make 10*log10 out of log2*/ Ltmp = Mpy_32_16_1( Ltmp, LG10 ); /*Q25,tmp16 * Q13 = Q23, tmp16*/ *frame_ener = extract_h( L_shl_o( Ltmp, add( tmp16, 1 ), &Overflow ) ); /*Q8*/ move16(); enern = sub_o( *frame_ener, lp_speech, &Overflow ); /*Q8*/ return enern; }
lib_com/get_gain.cdeleted 100644 → 0 +0 −170 Original line number Diff line number Diff line /****************************************************************************************************** (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository. All Rights Reserved. This software is protected by copyright law and by international treaties. The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other contributors to this repository retain full ownership rights in their respective contributions in the software. This notice grants no license of any kind, including but not limited to patent license, nor is any license granted by implication, estoppel or otherwise. Contributors are required to enter into the IVAS codec Public Collaboration agreement before making contributions. This software is provided "AS IS", without any express or implied warranties. The software is in the development stage. It is intended exclusively for experts who have experience with such software and solely for the purpose of inspection. All implied warranties of non-infringement, merchantability and fitness for a particular purpose are hereby disclaimed and excluded. Any dispute, controversy or claim arising under or in relation to providing this software shall be submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and the United Nations Convention on Contracts on the International Sales of Goods. *******************************************************************************************************/ /*==================================================================================== EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0 ====================================================================================*/ #include <stdint.h> #include "options.h" #include "prot.h" #include "wmc_auto.h" #include "prot_fx.h" /*----------------------------------------------------------------------------------* * get_gain() * * *----------------------------------------------------------------------------------*/ #ifndef IVAS_FLOAT_FIXED /*! r: codebook gain (adaptive or fixed) */ float get_gain_flt( const float x[], /* i : target signal */ const float y[], /* i : filtered codebook excitation */ const int16_t n, /* i : segment length */ float *en_y /* o : energy of y (sum of y[]^2, optional) */ ) { float corr = 0.0f, ener = 1e-6f; int16_t i; for ( i = 0; i < n; i++ ) { corr += x[i] * y[i]; ener += y[i] * y[i]; } if ( en_y ) { *en_y = ener; } return ( corr / ener ); } #endif Word32 get_gain( /* output: codebook gain (adaptive or fixed) Q16 */ const Word16 x[], /* input : target signal Qx */ const Word16 y[], /* input : filtered codebook excitation Qx */ const Word16 n /* input : segment length */ ) { Word32 tcorr, tener, Lgain; Word16 exp_c, exp_e, exp, tmp; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif tcorr = L_deposit_l( 0 ); tener = L_deposit_l( 0 ); /*----------------------------------------------------------------* * Find gain based on inter-correlation product *----------------------------------------------------------------*/ tcorr = Dot_product16HQ( 0, x, y, n, &exp_c ); tener = Dot_productSq16HQ( 0, y, n, &exp_e ); BASOP_Util_Divide_MantExp( round_fx_o( tcorr, &Overflow ), exp_c, s_max( round_fx_o( tener, &Overflow ), 1 ), exp_e, &tmp, &exp ); Lgain = L_shl_o( L_deposit_l( tmp ) /*Q15*/, add( 1, exp ), &Overflow ) /*Q16*/; return Lgain; } Word32 get_gain2( /* output: codebook gain (adaptive or fixed) Q16 */ const Word16 x[], /* input : target signal */ const Word16 y[], /* input : filtered codebook excitation */ const Word16 n /* input : segment length */ ) { Word32 tcorr, tener, Lgain; Word16 m_corr, m_ener, negative, Q_corr, Q_ener; #ifdef BASOP_NOGLOB_DECLARE_LOCAL Flag Overflow = 0; move32(); #endif negative = 0; move16(); /*----------------------------------------------------------------* * Find gain based on inter-correlation product *----------------------------------------------------------------*/ tcorr = Dot_product16HQ( 0, x, y, n, &Q_corr ); tener = Dot_productSq16HQ( 0, y, n, &Q_ener ); tener = L_max( tener, 1 ); if ( tcorr <= 0 ) { negative = 1; move16(); } BASOP_SATURATE_WARNING_OFF_EVS /*tcorr max be negative maxvall - not critical*/ tcorr = L_abs( tcorr ); BASOP_SATURATE_WARNING_ON_EVS m_corr = extract_h( tcorr ); m_ener = extract_h( tener ); IF( GT_16( m_corr, m_ener ) ) { m_corr = shr( m_corr, 1 ); Q_corr = add( Q_corr, 1 ); } if ( m_ener == 0 ) { move16(); m_corr = 0x7FFF; } IF( m_ener != 0 ) { m_corr = div_s( m_corr, m_ener ); } Q_corr = sub( Q_corr, Q_ener ); Lgain = L_shl_o( L_deposit_l( m_corr ), add( Q_corr, 1 ), &Overflow ); /* Lgain in Q16 */ if ( negative != 0 ) { Lgain = L_negate( Lgain ); /* Lgain in Q16 */ } return Lgain; }