Line data Source code
1 : /*==================================================================================== 2 : EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 3 : ====================================================================================*/ 4 : #include <stdint.h> 5 : #include "options.h" /* Compilation switches */ 6 : #include "cnst.h" /* Common constants */ 7 : #include "rom_com_fx.h" /* Static table prototypes */ 8 : //#include "prot_fx.h" /* Function prototypes */ 9 : #include "prot_fx.h" /* Function prototypes */ 10 : #include "prot_fx_enc.h" /* Function prototypes */ 11 : 12 : /*--------------------------------------------------------------------------* 13 : * noise_adjust_fx() 14 : * 15 : * Calculate attenuation 16 : *--------------------------------------------------------------------------*/ 17 : 18 5867 : Word16 noise_adjust_fx( /* o : index of noise attenuation Q0 */ 19 : const Word16 *coeffs_norm, /* i : normalized coefficients Qx */ 20 : const Word16 qx, /* i : Q value of coeffs_norm */ 21 : const Word16 *bitalloc, /* i : bit allocation Q0 */ 22 : const Word16 *sfm_start, /* i : band start Q0 */ 23 : const Word16 *sfm_end, /* i : band end Q0 */ 24 : const Word16 core_sfm /* i : index of the end band for core Q0 */ 25 : ) 26 : { 27 : Word16 nf_idx, sfm, bin, num_coeffs; 28 : Word16 E, diff, inv_num_coeffs; 29 : 30 5867 : E = 0; 31 5867 : move16(); 32 5867 : num_coeffs = 0; 33 5867 : move16(); 34 : 35 171353 : FOR( sfm = 0; sfm <= core_sfm; sfm++ ) 36 : { 37 165486 : IF( bitalloc[sfm] == 0 ) 38 : { 39 554798 : FOR( bin = sfm_start[sfm]; bin < sfm_end[sfm]; bin++ ) 40 : { 41 518116 : IF( coeffs_norm[bin] == 0 ) 42 : { 43 1019 : E = sub( E, 1 ); 44 : } 45 : ELSE 46 : { 47 517097 : E = add( E, sub( 15 + 8, add( qx, norm_s( coeffs_norm[bin] ) ) ) ); 48 : } 49 518116 : num_coeffs = add( num_coeffs, 1 ); 50 : } 51 : } 52 : } 53 : 54 5867 : IF( num_coeffs != 0 ) 55 : { 56 4864 : inv_num_coeffs = div_s( 1, num_coeffs ); /* Q15 */ 57 4864 : E = mult( E, inv_num_coeffs ); /* Q0 (0+15-15) */ 58 : } 59 : ELSE 60 : { 61 1003 : E = 0; 62 1003 : move16(); 63 : } 64 : 65 5867 : diff = sub( 7, E ); 66 5867 : nf_idx = s_min( s_max( diff, 0 ), 3 ); 67 : 68 5867 : return nf_idx; 69 : }