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 1164068 : 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 1164068 : DTX_ENC_HANDLE hDtxEnc = st_fx->hDtxEnc;
37 : #ifdef BASOP_NOGLOB_DECLARE_LOCAL
38 1164068 : Flag Overflow = 0;
39 1164068 : move32();
40 : #endif
41 :
42 1164068 : corr_shift_temp[0] = corr_shift; /*Q15*/
43 1164068 : corr_shift_temp[1] = corr_shiftR; /*Q15*/
44 1164068 : move16();
45 1164068 : move16();
46 :
47 1164068 : hVAD = st_fx->hVAD;
48 1164068 : ini_frame = st_fx->ini_frame;
49 1164068 : move16();
50 :
51 1164068 : IF( hFrontVad != NULL )
52 : {
53 49758 : hVAD = hFrontVad[0]->hVAD;
54 49758 : ini_frame = hFrontVad[0]->ini_frame;
55 49758 : move16();
56 : }
57 2360104 : FOR( i = 0; i < n_channels; i++ )
58 : {
59 1196036 : if ( EQ_16( i, 1 ) )
60 : {
61 31968 : hVAD = hFrontVad[1]->hVAD;
62 : }
63 1196036 : IF( !st_fx->Opt_AMR_WB )
64 : {
65 : /* fix explanation
66 : , after function dtx_fx, the "vad_flag" parameter can not be used for SID scheduling purposes any longer
67 : as dtx_fx can schedules active frames even if the initial analyzed vad_flag is 0 )
68 : in the worst case without the fix an active frame could be classified as SID frame, quite/very unlikley though
69 : */
70 1196036 : tmp_active_flag = 0;
71 1196036 : move16();
72 1196036 : test();
73 1196036 : if ( ( NE_32( st_fx->core_brate, (Word32) SID_2k40 ) ) && ( st_fx->core_brate != 0 ) ) /* Note, core_brate_fx can be -1 */
74 : {
75 1141158 : tmp_active_flag = 1;
76 1141158 : move16(); /* reqires active coding according to dtx_fx logic */
77 : }
78 1196036 : test();
79 1196036 : test();
80 1196036 : IF( ( st_fx->Opt_DTX_ON != 0 ) && ( tmp_active_flag == 0 ) && ( GT_16( ini_frame, 3 ) ) )
81 :
82 :
83 : {
84 : /* update the counter of consecutive inactive frames in DTX */
85 54776 : hVAD->consec_inactive = add( hVAD->consec_inactive, 1 );
86 54776 : move16();
87 54776 : if ( GT_16( hVAD->consec_inactive, 5 ) )
88 : {
89 46530 : hVAD->consec_inactive = 5;
90 46530 : move16();
91 : }
92 :
93 54776 : IF( EQ_16( hVAD->consec_inactive, 5 ) )
94 : {
95 : /* compute spectral tilt parameter */
96 47872 : a2rc_fx( &Az[1], refl, M ); /* cast to kill MSVC warning */
97 : /* i: Az in Q12 */
98 : /* o: refl in Q15 */
99 :
100 47872 : IF( EQ_16( hVAD->spectral_tilt_reset, 1 ) )
101 : {
102 733 : hVAD->spectral_tilt_reset = 0;
103 733 : move16();
104 733 : hVAD->running_avg_fx = refl[0];
105 733 : move16(); /*Q15*/
106 733 : hVAD->ra_deltasum_fx = 0;
107 733 : move16(); /*Q15*/
108 : }
109 :
110 : /* st_fx->ra_deltasum_fx += (0.80f * st_fx->running_avg_fx + 0.20f * refl[0]) - st_fx->running_avg_fx;
111 : st_fx->running_avg_fx = 0.80f * st_fx->running_avg_fx + 0.20f * refl[0]; */
112 47872 : tmp1 = mult( 6553, hVAD->running_avg_fx ); /* = -0.80f * st_fx->running_avg_fx + st_fx->running_avg_fx*/
113 47872 : tmp2 = mult( 6553, refl[0] );
114 47872 : hVAD->ra_deltasum_fx = add( hVAD->ra_deltasum_fx, sub( tmp2, tmp1 ) );
115 47872 : move16();
116 :
117 47872 : tmp1 = mult( 26214, hVAD->running_avg_fx ); /* (0.8 in Q15 * Q15) = Q(30 - 15)*/
118 47872 : hVAD->running_avg_fx = add( tmp1, tmp2 );
119 47872 : move16();
120 :
121 47872 : IF( GT_16( abs_s( hVAD->ra_deltasum_fx ), 6553 ) ) /*0.2 in Q15*/
122 : {
123 439 : hVAD->spectral_tilt_reset = 1;
124 439 : move16();
125 439 : hVAD->running_avg_fx = 0;
126 439 : move16();
127 439 : hVAD->ra_deltasum_fx = 0;
128 439 : move16();
129 439 : hVAD->trigger_SID = 1;
130 439 : move16();
131 : }
132 : }
133 : }
134 : ELSE
135 : {
136 1141260 : hVAD->trigger_SID = 0;
137 1141260 : move16();
138 1141260 : hVAD->consec_inactive = 0;
139 1141260 : move16();
140 : }
141 :
142 1196036 : IF( EQ_16( hVAD->trigger_SID, 1 ) )
143 : {
144 1570 : IF( GE_16( hDtxEnc->cng_cnt, 8 ) )
145 : {
146 : /* Declare SID frame due to spectral tilt changes */
147 0 : hDtxEnc->cnt_SID = 1;
148 0 : move16();
149 0 : st_fx->core_brate = SID_2k40;
150 0 : move32();
151 0 : hVAD->trigger_SID = 0;
152 0 : move16();
153 : }
154 1570 : ELSE IF( EQ_32( st_fx->core_brate, SID_2k40 ) )
155 : {
156 : /* SID fame has already been declared before */
157 349 : hVAD->trigger_SID = 0;
158 349 : move16();
159 : }
160 : }
161 : }
162 :
163 :
164 : /* (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift */
165 1196036 : L_tmp = L_mult( st_fx->voicing_fx[0], 10923 );
166 1196036 : L_tmp = L_mac( L_tmp, st_fx->voicing_fx[1], 10923 );
167 1196036 : L_tmp = L_mac( L_tmp, st_fx->voicing_fx[2], 10923 ); /*Q15 */
168 1196036 : L_tmp = L_mac_o( L_tmp, corr_shift_temp[i], 32767, &Overflow ); /*Q15 */
169 1196036 : voice_tmp = round_fx_o( L_tmp, &Overflow ); /*Q15 */
170 :
171 : /* abs(pitch[0] - *pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1]) */
172 1196036 : pitch_tmp = abs_s( sub( st_fx->pitch[0], old_pitch1 ) ); /*Q0 */
173 1196036 : pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch[1], st_fx->pitch[0] ) ) ); /*Q0 */
174 1196036 : pitch_tmp = add( pitch_tmp, abs_s( sub( st_fx->pitch[2], st_fx->pitch[1] ) ) ); /*Q0 */
175 :
176 :
177 : /* if( (voicing[0] + voicing[1] + voicing[2]) / 3 + corr_shift > 0.65 &&
178 : (short)(abs(pitch[0] - st->pitO) + abs(pitch[1] - pitch[0]) + abs(pitch[2] - pitch[1])) / 3 < 14 )
179 : {
180 : (st->voiced_burst)++;
181 : } else {
182 : st->voiced_burst = 0;
183 : } */
184 :
185 1196036 : hVAD->voiced_burst = add( hVAD->voiced_burst, 1 );
186 1196036 : move16();
187 1196036 : test();
188 1196036 : if ( ( LE_16( voice_tmp, 21299 ) ) /* 0.65 in Q15 */
189 657651 : || ( GE_16( pitch_tmp, 42 ) ) ) /*3*14 = 42 Q0 */
190 : {
191 669271 : hVAD->voiced_burst = 0;
192 669271 : move16();
193 : }
194 : }
195 :
196 :
197 1164068 : return;
198 : }
|