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