/*==================================================================================== EVS Codec 3GPP TS26.443 Jun 30, 2015. Version CR 26.443-0006 ====================================================================================*/ #include #include #include #include #include "options.h" #include "prot.h" #include "rom_com.h" /*---------------------------------------------------------------------* * bass_pf_enc() * * Low-frequency postfiltering, decoder parammeter estimation *---------------------------------------------------------------------*/ float bass_pf_enc( const float *orig, /* (i) : 12.8kHz original signal */ const float *syn, /* (i) : 12.8kHz synthesis to postfilter */ const float pitch_buf[], /* (i) : Pitch gain for all subframes (gainT_sf[16]) */ const float gainT_sf[], /* (i) : Pitch gain for all subframes (gainT_sf[16]) */ const short l_frame, /* (i) : frame length (should be multiple of l_subfr)*/ const short l_subfr_in, /* (i) : sub-frame length (80/64) */ float mem_bpf[], /* i/o : memory state [2*L_FILT16k] */ float mem_error_bpf[], /* i/o : memory state [2*L_FILT16k] */ int *gain_factor_param, /* (o) : quantized gain factor */ const short mode, /* (i) : coding mode of adapt bpf */ float *mem_deemph_err, /* o : Error deemphasis memory */ float *lp_ener /* o : long_term error signal energy */ ) { int i, j, sf, i_subfr, T, lg, l_subfr, l_filt; float d,n, snr, nrg1,nrg2, gain,nrg,tmp; float noise_buf[L_FILT16k+(2*L_SUBFR)], *noise, *noise_in; float error_buf[L_FILT16k+(2*L_SUBFR)], *error, *error_in; float cross_n_d, nrg_n; const float *pFilt; float ener2; if ( l_frame!=L_FRAME16k ) { pFilt = filt_lp; l_filt = L_FILT; } else { pFilt = filt_lp_16kHz; l_filt = L_FILT16k; } noise = noise_buf + l_filt; noise_in = noise_buf + 2*l_filt; error = error_buf + l_filt; error_in = error_buf + 2*l_filt; sf = 0; snr=0.f; nrg_n=1e-6f; cross_n_d = 0.f; l_subfr = l_subfr_in; for (i_subfr=0; i_subfr 1.0f) gain = 1.0f; if (gain < 0.0f) gain = 0.0f; lg = l_frame - T - i_subfr; if (lg < 0) lg = 0; if (lg > l_subfr) lg = l_subfr; if (gain > 0) { tmp = 0.01f; nrg=0.01f; for (i=0; i1.0f) { gain=1.0f; } else if(gain<0.f) { gain=0.f; } ener2=0.01f; for (i=0; i0.5f) { tmp=0.5f; } else if(tmp<0.f) { tmp=0.0f; } for (i=0; i/ */ if(mode==2) { *gain_factor_param = (int)(-2.f*(cross_n_d/nrg_n)+0.5f); if(*gain_factor_param>3) { *gain_factor_param=3; } else if(*gain_factor_param<0) { *gain_factor_param=0; } /*If optimal gain negatif or zero but snr still positif->gain=0.5f*/ if(snr>0.f && *gain_factor_param==0) { *gain_factor_param=1; } } else { *gain_factor_param=2; } return(snr); }