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