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"
7 : #include "cnst.h"
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 : /* FUNCTION : stat_noise_uv_enc_fx */
15 : /*----------------------------------------------------------------------*/
16 : /* PURPOSE : Modifies excitation signal in UC mode */
17 : /* when the noise is stationary */
18 : /*----------------------------------------------------------------------*/
19 : /* INPUT ARGUMENTS : */
20 : /* _ (Encoder_State) st_fx : Encoder state Structure */
21 : /* _ (Word16*) epsP : LP prediction errors */
22 : /* _ (Word16*) isp_new : immittance spectral pairs at 4th sfr Q15 */
23 : /* _ (Word16*) isp_mid : immittance spectral pairs at 2nd sfr Q15 */
24 : /* _ (Word16*) Aq : A(z) quantized for the 4 subframes Q12 */
25 : /* _ (Word16 ) uc_two_stage_flag flag undicating two-stage UC */
26 : /*-----------------------------------------------------------------------*/
27 : /* INPUT/OUTPUT ARGUMENTS : */
28 : /* _ (Word16*) exc2 : excitation buffer Q_exc */
29 : /*-----------------------------------------------------------------------*/
30 : /* OUTPUT ARGUMENTS : */
31 : /*-----------------------------------------------------------------------*/
32 :
33 : /* _ None */
34 : /*-----------------------------------------------------------------------*/
35 : /* RETURN ARGUMENTS : */
36 : /* _ None */
37 : /*=======================================================================*/
38 :
39 1423 : void stat_noise_uv_enc_fx(
40 : Encoder_State *st_fx, /* i/o: state structure */
41 : const Word32 *LepsP, /* i : LP prediction errors */
42 : const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr */
43 : const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr */
44 : Word16 *Aq, /* i : A(z) quantized for the 4 subframes */
45 : Word16 *exc2, /* i/o: excitation buffer */
46 : const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */
47 : Word16 Q_new )
48 : {
49 1423 : Word16 noisiness = 0;
50 1423 : move16();
51 : Word16 num, den, expn, expd;
52 :
53 1423 : test();
54 1423 : test();
55 1423 : test();
56 1423 : IF( ( EQ_16( st_fx->coder_type, UNVOICED ) && uc_two_stage_flag == 0 ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) )
57 : {
58 : /*-----------------------------------------------------------------*
59 : * Calculate and write the noisiness parameter
60 : *-----------------------------------------------------------------*/
61 :
62 : /* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */
63 0 : expn = sub( norm_l( LepsP[0] ), 1 );
64 0 : num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/
65 0 : expd = norm_l( LepsP[1] );
66 0 : den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/
67 0 : num = div_s( num, den ); /*expn-expd+15*/
68 0 : num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/
69 0 : num = sub( num, 1024 ); /*num - 1*/
70 :
71 0 : test();
72 0 : IF( NE_16( st_fx->bwidth, NB ) )
73 : {
74 : /* WB case */
75 : /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*2 * 32);*/
76 0 : noisiness = shr( num, 4 ); /*Q10 x64 -> Q0 */
77 : }
78 0 : ELSE IF( EQ_16( st_fx->coder_type, INACTIVE ) && EQ_16( st_fx->bwidth, NB ) )
79 : {
80 : /* NB GSC case */
81 : /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*.25f * 32);*/
82 0 : noisiness = shr( num, 4 + 3 ); /*Q10 x8 -> Q0 */
83 : }
84 : ELSE
85 : {
86 : /* NB case */
87 0 : noisiness = shr( num, 4 + 2 ); /*Q16 x16 -> Q0 */
88 : }
89 :
90 0 : noisiness = s_max( noisiness, 0 );
91 0 : noisiness = s_min( noisiness, 31 );
92 :
93 0 : push_indice( st_fx->hBstr, IND_NOISINESS, noisiness, 5 );
94 : }
95 :
96 : /*-----------------------------------------------------------------*
97 : * Modify the stationary noise excitation signal
98 : *-----------------------------------------------------------------*/
99 :
100 1423 : stat_noise_uv_mod_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count,
101 1423 : st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx,
102 1423 : st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge );
103 :
104 :
105 1423 : return;
106 : }
107 :
108 :
109 145349 : void stat_noise_uv_enc_ivas_fx(
110 : Encoder_State *st_fx, /* i/o: state structure */
111 : const Word32 *LepsP, /* i : LP prediction errors Q=Qx*/
112 : const Word16 *isp_new, /* i : immittance spectral pairs at 4th sfr Q=15*/
113 : const Word16 *isp_mid, /* i : immittance spectral pairs at 2nd sfr Q=15*/
114 : Word16 *Aq, /* i : A(z) quantized for the 4 subframes Q=12 */
115 : Word16 *exc2, /* i/o: excitation buffer Q=Q_stat_noise */
116 : const Word16 uc_two_stage_flag, /* o : flag undicating two-stage UC */
117 : Word16 *Q_new )
118 : {
119 145349 : Word16 noisiness = 0;
120 145349 : move16();
121 : Word16 num, den, expn, expd;
122 :
123 145349 : test();
124 145349 : test();
125 145349 : test();
126 145349 : IF( ( EQ_16( st_fx->coder_type, UNVOICED ) && uc_two_stage_flag == 0 ) || ( EQ_16( st_fx->coder_type, INACTIVE ) && LE_32( st_fx->core_brate, ACELP_9k60 ) ) )
127 : {
128 : /*-----------------------------------------------------------------*
129 : * Calculate and write the noisiness parameter
130 : *-----------------------------------------------------------------*/
131 :
132 : /* epsP[2] is located in LepsP[0] and epsP[16] in LepsP[1] */
133 327 : expn = sub( norm_l( LepsP[0] ), 1 );
134 327 : num = extract_h( L_shl( LepsP[0], expn ) ); /*expn-16*/
135 327 : expd = norm_l( LepsP[1] );
136 327 : den = extract_h( L_shl( LepsP[1], expd ) ); /*expd-16*/
137 327 : num = div_s( num, den ); /*expn-expd+15*/
138 327 : num = shr_sat( num, add( sub( expn, expd ), 5 ) ); /*Q10*/
139 327 : num = sub( num, 1024 ); /*num - 1*/
140 :
141 327 : test();
142 327 : IF( NE_16( st_fx->bwidth, NB ) )
143 : {
144 : /* WB case */
145 : /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*2 * 32);*/
146 327 : noisiness = shr( num, 4 ); /*Q10 x64 -> Q0 */
147 : }
148 0 : ELSE IF( EQ_16( st_fx->coder_type, INACTIVE ) && EQ_16( st_fx->bwidth, NB ) )
149 : {
150 : /* NB GSC case */
151 : /* noisiness = (Word16)(((epsP[2] / epsP[16]) - 1)*.25f * 32);*/
152 0 : noisiness = shr( num, 4 + 3 ); /*Q10 x8 -> Q0 */
153 : }
154 : ELSE
155 : {
156 : /* NB case */
157 0 : noisiness = shr( num, 4 + 2 ); /*Q16 x16 -> Q0 */
158 : }
159 :
160 327 : noisiness = s_max( noisiness, 0 );
161 327 : noisiness = s_min( noisiness, 31 );
162 :
163 327 : push_indice( st_fx->hBstr, IND_NOISINESS, noisiness, 5 );
164 : }
165 :
166 : /*-----------------------------------------------------------------*
167 : * Modify the stationary noise excitation signal
168 : *-----------------------------------------------------------------*/
169 :
170 145349 : stat_noise_uv_mod_ivas_fx( st_fx->coder_type, noisiness, st_fx->lsp_old_fx, isp_new, isp_mid, Aq, exc2, Q_new, 0, &st_fx->ge_sm_fx, &st_fx->uv_count, &st_fx->act_count,
171 145349 : st_fx->lspold_s_fx, &st_fx->noimix_seed, &st_fx->min_alpha_fx, &st_fx->exc_pe_fx,
172 145349 : st_fx->core_brate, st_fx->bwidth, &st_fx->Q_stat_noise, &st_fx->Q_stat_noise_ge );
173 :
174 :
175 145349 : return;
176 : }
|