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 <stdlib.h>
6 : #include "options.h" /* Compilation switches */
7 : #include "cnst.h" /* Common constants */
8 : //#include "prot_fx.h" /* Function prototypes */
9 : #include "ivas_stat_enc.h" /* Function prototypes */
10 : #include "prot_fx.h" /* Function prototypes */
11 : #include "prot_fx_enc.h" /* Function prototypes */
12 :
13 : /*-------------------------------------------------------------------*
14 : * vad_param_updt()
15 : *
16 : * Update parameters used by VAD
17 : *--------------------------------------------------------------------*/
18 :
19 1185822 : void vad_param_updt_fx(
20 : Encoder_State *st_fx, /* i/o: state structure */
21 : const Word16 old_pitch1, /* i : OL pitch value from last frame Q0 */
22 : const Word16 corr_shift, /* i : correlation shift Q15*/
23 : const Word16 corr_shiftR, /* i : correlation shift Q15 */
24 : const Word16 Az[], /* i: a coeffs Q12 */
25 : FRONT_VAD_ENC_HANDLE hFrontVad[], /* i/o: front-VAD handles */
26 : const Word16 n_channels /* i : number of channels */
27 : )
28 : {
29 : Word16 voice_tmp, pitch_tmp;
30 : Word32 L_tmp;
31 : Word16 refl[M + 1];
32 : Word16 tmp1, tmp2;
33 : Word16 tmp_active_flag;
34 : Word16 i, ini_frame, corr_shift_temp[2];
35 : VAD_HANDLE hVAD;
36 1185822 : DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc;
37 : #ifndef ISSUE_1867_replace_overflow_libenc
38 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
39 : Flag Overflow = 0;
40 : move32();
41 : #endif
42 : #endif
43 :
44 1185822 : corr_shift_temp[0] = corr_shift; /*Q15*/
45 1185822 : corr_shift_temp[1] = corr_shiftR; /*Q15*/
46 1185822 : move16();
47 1185822 : move16();
48 :
49 1185822 : hVAD = st_fx->hVAD;
50 1185822 : ini_frame = st_fx->ini_frame;
51 1185822 : move16();
52 :
53 1185822 : IF( hFrontVad != NULL )
54 : {
55 49758 : hVAD = hFrontVad[0]->hVAD;
56 49758 : ini_frame = hFrontVad[0]->ini_frame;
57 49758 : move16();
58 : }
59 2403612 : FOR( i = 0; i < n_channels; i++ )
60 : {
61 1217790 : if ( EQ_16( i, 1 ) )
62 : {
63 31968 : hVAD = hFrontVad[1]->hVAD;
64 : }
65 1217790 : IF( !st_fx->Opt_AMR_WB )
66 : {
67 : /* fix explanation
68 : , after function dtx_fx, the "vad_flag" parameter can not be used for SID scheduling purposes any longer
69 : as dtx_fx can schedules active frames even if the initial analyzed vad_flag is 0 )
70 : in the worst case without the fix an active frame could be classified as SID frame, quite/very unlikley though
71 : */
72 1217790 : tmp_active_flag = 0;
73 1217790 : move16();
74 1217790 : test();
75 1217790 : if ( ( NE_32( st_fx->core_brate, (Word32) SID_2k40 ) ) && ( st_fx->core_brate != 0 ) ) /* Note, core_brate_fx can be -1 */
76 : {
77 1166467 : tmp_active_flag = 1;
78 1166467 : move16(); /* reqires active coding according to dtx_fx logic */
79 : }
80 1217790 : test();
81 1217790 : test();
82 1217790 : IF( ( st_fx->Opt_DTX_ON != 0 ) && ( tmp_active_flag == 0 ) && ( GT_16( ini_frame, 3 ) ) )
83 :
84 :
85 : {
86 : /* update the counter of consecutive inactive frames in DTX */
87 51217 : hVAD->consec_inactive = add( hVAD->consec_inactive, 1 );
88 51217 : move16();
89 51217 : if ( GT_16( hVAD->consec_inactive, 5 ) )
90 : {
91 43242 : hVAD->consec_inactive = 5;
92 43242 : move16();
93 : }
94 :
95 51217 : IF( EQ_16( hVAD->consec_inactive, 5 ) )
96 : {
97 : /* compute spectral tilt parameter */
98 44544 : a2rc_fx( &Az[1], refl, M ); /* cast to kill MSVC warning */
99 : /* i: Az in Q12 */
100 : /* o: refl in Q15 */
101 :
102 44544 : IF( EQ_16( hVAD->spectral_tilt_reset, 1 ) )
103 : {
104 552 : hVAD->spectral_tilt_reset = 0;
105 552 : move16();
106 552 : hVAD->running_avg_fx = refl[0];
107 552 : move16(); /*Q15*/
108 552 : hVAD->ra_deltasum_fx = 0;
109 552 : move16(); /*Q15*/
110 : }
111 :
112 : /* st_fx->ra_deltasum_fx += (0.80f * st_fx->running_avg_fx + 0.20f * refl[0]) - st_fx->running_avg_fx;
113 : st_fx->running_avg_fx = 0.80f * st_fx->running_avg_fx + 0.20f * refl[0]; */
114 44544 : tmp1 = mult( 6553, hVAD->running_avg_fx ); /* = -0.80f * st_fx->running_avg_fx + st_fx->running_avg_fx*/
115 44544 : tmp2 = mult( 6553, refl[0] );
116 44544 : hVAD->ra_deltasum_fx = add( hVAD->ra_deltasum_fx, sub( tmp2, tmp1 ) );
117 44544 : move16();
118 :
119 44544 : tmp1 = mult( 26214, hVAD->running_avg_fx ); /* (0.8 in Q15 * Q15) = Q(30 - 15)*/
120 44544 : hVAD->running_avg_fx = add( tmp1, tmp2 );
121 44544 : move16();
122 :
123 44544 : IF( GT_16( abs_s( hVAD->ra_deltasum_fx ), 6553 ) ) /*0.2 in Q15*/
124 : {
125 241 : hVAD->spectral_tilt_reset = 1;
126 241 : move16();
127 241 : hVAD->running_avg_fx = 0;
128 241 : move16();
129 241 : hVAD->ra_deltasum_fx = 0;
130 241 : move16();
131 241 : hVAD->trigger_SID = 1;
132 241 : move16();
133 : }
134 : }
135 : }
136 : ELSE
137 : {
138 1166573 : hVAD->trigger_SID = 0;
139 1166573 : move16();
140 1166573 : hVAD->consec_inactive = 0;
141 1166573 : move16();
142 : }
143 :
144 1217790 : IF( EQ_16( hVAD->trigger_SID, 1 ) )
145 : {
146 845 : IF( GE_16( hDtxEnc->cng_cnt, 8 ) )
147 : {
148 : /* Declare SID frame due to spectral tilt changes */
149 0 : hDtxEnc->cnt_SID = 1;
150 0 : move16();
151 0 : st_fx->core_brate = SID_2k40;
152 0 : move32();
153 0 : hVAD->trigger_SID = 0;
154 0 : move16();
155 : }
156 845 : ELSE IF( EQ_32( st_fx->core_brate, SID_2k40 ) )
157 : {
158 : /* SID fame has already been declared before */
159 221 : hVAD->trigger_SID = 0;
160 221 : move16();
161 : }
162 : }
163 : }
164 :
165 :
166 : /* (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift */
167 1217790 : L_tmp = L_mult( st_fx->voicing_fx[0], 10923 );
168 1217790 : L_tmp = L_mac( L_tmp, st_fx->voicing_fx[1], 10923 );
169 1217790 : L_tmp = L_mac( L_tmp, st_fx->voicing_fx[2], 10923 ); /*Q15 */
170 : #ifdef ISSUE_1867_replace_overflow_libenc
171 1217790 : L_tmp = L_mac_sat( L_tmp, corr_shift_temp[i], 32767 ); /*Q15 */
172 1217790 : voice_tmp = round_fx_sat( L_tmp ); /*Q15 */
173 : #else
174 : L_tmp = L_mac_o( L_tmp, corr_shift_temp[i], 32767, &Overflow ); /*Q15 */
175 : voice_tmp = round_fx_o( L_tmp, &Overflow ); /*Q15 */
176 : #endif
177 :
178 : /* abs(pitch[0] - *pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1]) */
179 1217790 : pitch_tmp = abs_s( sub( st_fx->pitch[0], old_pitch1 ) ); /*Q0 */
180 1217790 : pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch[1], st_fx->pitch[0] ) ) ); /*Q0 */
181 1217790 : pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch[2], st_fx->pitch[1] ) ) ); /*Q0 */
182 :
183 :
184 : /* if( (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift > 0.65 &&
185 : (short)(abs(pitch[0] - st->pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1])) / 3 < 14 )
186 : {
187 : (st->voiced_burst)++;
188 : } else {
189 : st->voiced_burst = 0;
190 : } */
191 :
192 1217790 : hVAD->voiced_burst = add( hVAD->voiced_burst, 1 );
193 1217790 : move16();
194 1217790 : test();
195 1217790 : if ( ( LE_16( voice_tmp, 21299 ) ) /* 0.65 in Q15 */
196 679797 : || ( GE_16( pitch_tmp, 42 ) ) ) /*3*14 = 42 Q0 */
197 : {
198 672430 : hVAD->voiced_burst = 0;
199 672430 : move16();
200 : }
201 : }
202 :
203 :
204 1185822 : return;
205 : }
|