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 "options.h" /* Compilation switches */
6 : #include "cnst.h" /* Common constants */
7 : #include "rom_com_fx.h" /* Static table prototypes */
8 : //#include "prot_fx.h" /* Function prototypes */
9 : #include "rom_com.h" /* Common constants */
10 : #include "prot_fx.h" /* Function prototypes */
11 : #include "prot_fx_enc.h" /* Function prototypes */
12 : #include "basop_util.h" /* Function prototypes */
13 : #include "ivas_prot_fx.h"
14 :
15 : /*-------------------------------------------------------------------*
16 : * updt_enc()
17 : *
18 : * Common updates (all frame types)
19 : *-------------------------------------------------------------------*/
20 :
21 172382 : void updt_enc_fx(
22 : Encoder_State *st, /* i/o: state structure */
23 : const Word16 *old_exc, /* i : buffer of excitation */
24 : const Word16 *pitch_buf, /* i : floating pitch for each subframe */
25 : const Word16 Es_pred, /* i : predicited scaled innovation energy */
26 : const Word16 *Aq, /* i : A(z) quantized for all subframes */
27 : const Word16 *lsf_new, /* i : current frame LSF vector */
28 : const Word16 *lsp_new, /* i : current frame LSP vector */
29 : const Word16 *old_bwe_exc /* i : buffer of excitation */
30 : )
31 : {
32 : Word16 i, tmp;
33 172382 : SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR;
34 172382 : LPD_state_HANDLE hLPDmem = st->hLPDmem;
35 172382 : GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc;
36 172382 : TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD;
37 :
38 : /* update old excitation buffer */
39 172382 : Copy( &old_exc[st->L_frame], hLPDmem->old_exc, L_EXC_MEM );
40 172382 : test();
41 172382 : test();
42 172382 : IF( !st->Opt_AMR_WB && st->hBWE_TD != NULL )
43 : {
44 172253 : Copy( &old_bwe_exc[L_FRAME32k], hBWE_TD->old_bwe_exc_fx, PIT16k_MAX * 2 );
45 : }
46 :
47 : /* update old LSP and LSF vector */
48 172382 : Copy( lsp_new, st->lsp_old_fx, M );
49 172382 : Copy( lsf_new, st->lsf_old_fx, M );
50 :
51 : /* update last coder type */
52 172382 : st->last_coder_type = st->coder_type;
53 172382 : move16();
54 172382 : test();
55 172382 : test();
56 172382 : test();
57 172382 : if ( EQ_16( st->coder_type, INACTIVE ) || ( EQ_16( st->bpf_off, 1 ) && NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, TRANSITION ) ) )
58 : {
59 20498 : st->last_coder_type = UNVOICED;
60 20498 : move16();
61 : }
62 :
63 : /* this ensures that st->last_coder_type is never set to INACTIVE in case of AVQ inactive because the FEC does not distinguish between GSC inactive and AVQ inactive */
64 172382 : test();
65 172382 : if ( EQ_16( st->coder_type, INACTIVE ) && GT_32( st->total_brate, ACELP_24k40 ) )
66 : {
67 3905 : st->last_coder_type = GENERIC;
68 3905 : move16();
69 : }
70 :
71 172382 : test();
72 172382 : test();
73 172382 : test();
74 172382 : IF( st->Opt_AMR_WB && EQ_16( st->coder_type, INACTIVE ) && st->core_brate != SID_1k75 && st->core_brate != FRAME_NO_DATA )
75 : {
76 : /* overwrite previous coding type to help FEC */
77 0 : st->last_coder_type = UNVOICED;
78 0 : move16();
79 : }
80 :
81 : /* AC mode (GSC) - in speech we can consider that the last pitch band reached the max */
82 172382 : test();
83 172382 : test();
84 172382 : IF( st->hGSCEnc != NULL && NE_16( st->coder_type, AUDIO ) && NE_16( st->coder_type, INACTIVE ) )
85 : {
86 143995 : hGSCEnc->mem_last_pit_band = 10 + BAND1k2;
87 143995 : move16();
88 143995 : hGSCEnc->past_dyn_dec = NOISE_LEVEL_SP0 - 1;
89 143995 : move16(); /* tends to speech */
90 143995 : hGSCEnc->noise_lev = NOISE_LEVEL_SP0 - 1;
91 143995 : move16(); /* tends to speech */
92 : /*st->mid_dyn_fx = 40.0f * 0.5f + st->mid_dyn * 0.5f;*/
93 143995 : hGSCEnc->mid_dyn_fx = add( 20 * 128, mult_r( hGSCEnc->mid_dyn_fx, 16384 ) ); /*Q7*/
94 143995 : move16();
95 : }
96 :
97 : /* convert old LSP vector from 12kHz domain to 16kHz domain (needed in case of ACELP@12k8 <-> ACELP@16kHz switching) */
98 172382 : IF( EQ_16( st->L_frame, L_FRAME ) )
99 : {
100 90831 : Copy( st->lsp_old_fx, st->lsp_old16k_fx, M );
101 90831 : st->rate_switching_reset_16kHz = lsp_convert_poly_fx( st->lsp_old16k_fx, L_FRAME16k, st->Opt_AMR_WB );
102 90831 : move16();
103 : }
104 :
105 : /* update buffer of old subframe pitch values */
106 172382 : IF( NE_16( st->last_L_frame, st->L_frame ) )
107 : {
108 1720 : IF( EQ_16( st->L_frame, L_FRAME ) )
109 : {
110 5845 : FOR( i = 0; i < NB_SUBFR; i++ )
111 : {
112 4676 : st->old_pitch_buf_fx[NB_SUBFR + i] = mult_r( 26214, st->old_pitch_buf_fx[NB_SUBFR + i + 1] );
113 4676 : move16();
114 : }
115 : }
116 : ELSE
117 : {
118 2755 : FOR( i = NB_SUBFR; i > 0; i-- )
119 : {
120 2204 : st->old_pitch_buf_fx[NB_SUBFR + i] = add( mult_r( 8192, st->old_pitch_buf_fx[NB_SUBFR + i - 1] ), st->old_pitch_buf_fx[NB_SUBFR + i - 1] );
121 2204 : move16();
122 : }
123 551 : st->old_pitch_buf_fx[2 * NB_SUBFR16k - 1] = st->old_pitch_buf_fx[2 * NB_SUBFR16k - 2];
124 551 : move16();
125 : }
126 : }
127 172382 : tmp = shr( st->L_frame, 6 );
128 172382 : Copy( &st->old_pitch_buf_fx[tmp], st->old_pitch_buf_fx, tmp );
129 172382 : Copy( pitch_buf, &st->old_pitch_buf_fx[tmp], tmp );
130 :
131 : /* SC-VBR */
132 172382 : st->last_Opt_SC_VBR = st->Opt_SC_VBR;
133 172382 : move16();
134 172382 : IF( st->hSC_VBR != NULL )
135 : {
136 1427 : hSC_VBR->last_last_ppp_mode = hSC_VBR->last_ppp_mode;
137 1427 : move16();
138 1427 : hSC_VBR->last_ppp_mode = hSC_VBR->ppp_mode;
139 1427 : move16();
140 1427 : hSC_VBR->last_nelp_mode = hSC_VBR->nelp_mode;
141 1427 : move16();
142 : }
143 : /* core switching updates */
144 172382 : Copy( &Aq[( st->L_frame / L_SUBFR - 1 ) * ( M + 1 )], st->old_Aq_12_8_fx, M + 1 );
145 172382 : st->old_Es_pred_fx = Es_pred;
146 172382 : move16();
147 :
148 172382 : return;
149 : }
150 :
151 : /*-------------------------------------------------------------------*
152 : * updt_IO_switch()
153 : *
154 : * Common updates for AMR-WB IO mode and EVS primary mode switching
155 : *-------------------------------------------------------------------*/
156 :
157 0 : void updt_IO_switch_enc_fx(
158 : Encoder_State *st, /* i/o: state structure */
159 : const Word16 input_frame /* i : input frame length */
160 : )
161 : {
162 : Word16 xsp_tmp[M];
163 0 : SC_VBR_ENC_HANDLE hSC_VBR = st->hSC_VBR;
164 0 : DTX_ENC_HANDLE hDtxEnc = st->hDtxEnc;
165 0 : TD_CNG_ENC_HANDLE hTdCngEnc = st->hTdCngEnc;
166 0 : GSC_ENC_HANDLE hGSCEnc = st->hGSCEnc;
167 0 : AMRWB_IO_ENC_HANDLE hAmrwb_IO = st->hAmrwb_IO;
168 0 : TD_BWE_ENC_HANDLE hBWE_TD = st->hBWE_TD;
169 0 : FD_BWE_ENC_HANDLE hBWE_FD = st->hBWE_FD;
170 :
171 0 : IF( EQ_16( st->last_core, AMR_WB_CORE ) ) /* switching to EVS primary mode */
172 : {
173 : /* reset onset detection counter */
174 0 : st->tc_cnt = -1;
175 0 : move16();
176 :
177 : /* force safety-net LSFQ in the first frames after the switching */
178 0 : st->Nb_ACELP_frames = 0;
179 0 : move16();
180 :
181 : /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
182 0 : Copy( stable_LSP_fx, xsp_tmp, M );
183 0 : isf2lsf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp );
184 0 : Copy( stable_LSP_fx, xsp_tmp, M );
185 0 : isp2lsp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M );
186 0 : isp2lsp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M );
187 :
188 0 : Copy( stable_LSP_fx, xsp_tmp, M );
189 0 : isp2lsp_fx( hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M );
190 : /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_AMR_WB_SID * STEP_SID), 127 );*/
191 0 : IF( hTdCngEnc->old_enr_index >= 0 )
192 : {
193 : /* old index is initialized to -1, and may only be updated after it has been calculated properly at least once once */
194 0 : hTdCngEnc->old_enr_index = s_min( mult( shl( hTdCngEnc->old_enr_index, 1 ), 32459 ), 127 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/
195 0 : move16();
196 : }
197 : /* Perform preemphasis of the old input signal @16kHz */
198 0 : st->mem_preemph16k_fx = 0;
199 0 : move16();
200 0 : PREEMPH_FX( st->old_inp_16k_fx, PREEMPH_FAC_16k, L_INP_MEM, &( st->mem_preemph16k_fx ) );
201 0 : Scale_sig( st->old_inp_16k_fx, L_INP_MEM, st->prev_Q_new );
202 : /* reset TD BWE buffers */
203 0 : set16_fx( hBWE_TD->old_speech_shb_fx, 0, L_LOOK_16k + L_SUBFR16k );
204 0 : set16_fx( hBWE_TD->old_speech_wb_fx, 0, ( L_LOOK_12k8 + L_SUBFR ) * 5 / 16 );
205 0 : set16_fx( hBWE_TD->old_bwe_exc_fx, 0, PIT16k_MAX * 2 );
206 0 : set16_fx( hBWE_TD->old_bwe_exc_extended_fx, 0, NL_BUFF_OFFSET );
207 0 : hBWE_TD->bwe_non_lin_prev_scale_fx = 0;
208 0 : move16();
209 0 : set16_fx( hBWE_TD->decim_state1_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
210 0 : set16_fx( hBWE_TD->decim_state2_fx, 0, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
211 0 : set16_fx( hBWE_FD->L_old_wtda_swb_fx, 0, L_FRAME16k );
212 0 : set16_fx( hBWE_FD->old_input_wb_fx, 0, NS2SA( 16000, DELAY_FD_BWE_ENC_NS ) );
213 :
214 0 : wb_tbe_extras_reset_fx( hBWE_TD->mem_genSHBexc_filt_down_wb2_fx, hBWE_TD->mem_genSHBexc_filt_down_wb3_fx );
215 :
216 0 : IF( GE_16( input_frame, L_FRAME32k ) )
217 : {
218 0 : swb_tbe_reset_fx( hBWE_TD->mem_csfilt_fx, hBWE_TD->mem_genSHBexc_filt_down_shb_fx, hBWE_TD->state_lpc_syn_fx,
219 0 : hBWE_TD->syn_overlap_fx, hBWE_TD->state_syn_shbexc_fx, &( hBWE_TD->tbe_demph_fx ), &( hBWE_TD->tbe_premph_fx ), hBWE_TD->mem_stp_swb_fx, &( hBWE_TD->gain_prec_swb_fx ) );
220 : }
221 :
222 0 : IF( EQ_16( input_frame, L_FRAME48k ) )
223 : {
224 0 : set16_fx( hBWE_TD->fb_state_lpc_syn_fx, 0, LPC_SHB_ORDER );
225 0 : hBWE_TD->fb_tbe_demph_fx = 0;
226 0 : move16();
227 0 : fb_tbe_reset_enc_fx( hBWE_TD->elliptic_bpf_2_48k_mem_fx, &hBWE_TD->prev_fb_energy_fx, hBWE_TD->elliptic_bpf_2_48k_mem_fx_Q, &hBWE_TD->prev_fb_energy_fx_Q );
228 : }
229 :
230 : /* reset FD BWE buffers */
231 0 : hBWE_FD->prev_mode = NORMAL;
232 0 : move16();
233 :
234 : /* reset the unvoiced/audio signal improvement memories */
235 0 : hGSCEnc->seed_tcx = 15687;
236 0 : move16();
237 :
238 0 : st->use_acelp_preq = 0;
239 0 : move16();
240 : }
241 : ELSE /* switching to AMR-WB IO mode */
242 : {
243 0 : set16_fx( st->mem_MA_fx, 0, M );
244 :
245 : /* AMR-WB IO mode uses ISF(ISP), but EVS primary mode LSF(LSP) */
246 0 : Copy( stable_ISP_fx, xsp_tmp, M );
247 0 : lsf2isf_fx( st->lsf_old_fx, st->lsf_old_fx, xsp_tmp, M );
248 0 : Copy( stable_ISP_fx, xsp_tmp, M );
249 0 : lsp2isp_fx( st->lsp_old_fx, st->lsp_old_fx, xsp_tmp, M );
250 0 : lsp2isp_fx( st->lsp_old1_fx, st->lsp_old1_fx, xsp_tmp, M );
251 0 : Copy( stable_ISP_fx, xsp_tmp, M );
252 0 : lsp2isp_fx( hDtxEnc->lspCNG_fx, hDtxEnc->lspCNG_fx, xsp_tmp, M );
253 :
254 0 : IF( hTdCngEnc->old_enr_index >= 0 )
255 : {
256 : /* old_enr__index is initialized to -1, and may only be updated this way after it has been calculated properly at least once once */
257 : /*st->old_enr_index = min( (short)((float)st->old_enr_index / STEP_SID * STEP_AMR_WB_SID), 63 );*/
258 0 : hTdCngEnc->old_enr_index = s_max( s_min( mult( hTdCngEnc->old_enr_index, 16384 ), 63 ), 0 ); /*32459 = 2/(STEP_SID/STEP_AMR_WB_SID)*/
259 : }
260 : /* gain quantization memory */
261 0 : set16_fx( hAmrwb_IO->past_qua_en_fx, ( -14 * 1024 ), GAIN_PRED_ORDER );
262 : /* reset VBR signalling */
263 0 : IF( st->Opt_SC_VBR )
264 : {
265 0 : hSC_VBR->ppp_mode = 0;
266 0 : move16();
267 0 : hSC_VBR->nelp_mode = 0;
268 0 : move16();
269 : }
270 0 : st->hGSCEnc->seed_tcx = 15687; /* the re-init here was present only in float _DIFF_FLOAT_FIX_*/
271 0 : move16();
272 : }
273 :
274 : /* Force SID in case of AMR-WB IO/EVS primary mode switching */
275 0 : IF( hTdCngEnc != NULL )
276 : {
277 0 : hDtxEnc->cnt_SID = 0;
278 0 : move16();
279 :
280 : /* CNG - reset */
281 0 : hDtxEnc->cng_cnt = 0;
282 0 : move16();
283 0 : hTdCngEnc->ho_hist_size = 0;
284 0 : move16();
285 0 : hTdCngEnc->burst_ho_cnt = 0;
286 0 : move16();
287 : }
288 : /* LP memories */
289 0 : Copy( UVWB_Ave_fx, st->mem_AR_fx, M );
290 :
291 : /* FEC - update adaptive LSF mean vector */
292 0 : Copy( st->lsf_old_fx, st->lsfoldbfi0_fx, M );
293 0 : Copy( st->lsf_old_fx, st->lsfoldbfi1_fx, M );
294 0 : Copy( st->lsf_old_fx, st->lsf_adaptive_mean_fx, M );
295 :
296 0 : return;
297 : }
298 :
299 : /*-------------------------------------------------------------------*
300 : * updt_enc_common_fx()
301 : *
302 : * Common updates for MODE1 and MODE2
303 : *-------------------------------------------------------------------*/
304 :
305 3100 : void updt_enc_common_fx(
306 : Encoder_State *st, /* i/o: encoder state structure */
307 : const Word16 Etot, /* i : total energy */
308 : const Word16 Q_new /* i : CUrrent frame scaling */
309 : )
310 : {
311 : /*---------------------------------------------------------------------*
312 : * Updates - main main codec parameters
313 : *---------------------------------------------------------------------*/
314 :
315 3100 : st->last_sr_core = st->sr_core;
316 3100 : move32();
317 3100 : st->last_codec_mode = st->codec_mode;
318 3100 : move16();
319 3100 : st->last_L_frame = st->L_frame;
320 3100 : move16();
321 3100 : st->last_core = st->core;
322 3100 : move16();
323 :
324 3100 : st->last_core_brate = st->core_brate;
325 3100 : move32();
326 3100 : st->last_total_brate = st->total_brate;
327 3100 : move32();
328 3100 : st->last_extl = st->extl;
329 3100 : move16();
330 3100 : st->last_input_bwidth = st->input_bwidth;
331 3100 : move16();
332 3100 : st->last_bwidth = st->bwidth;
333 3100 : move16();
334 3100 : IF( GT_16( st->element_mode, EVS_MONO ) )
335 : {
336 0 : st->hNoiseEst->Etot_last_32fx = L_deposit_h( Etot );
337 : }
338 : ELSE
339 : {
340 3100 : st->hNoiseEst->Etot_last_fx = Etot;
341 : }
342 3100 : move16();
343 3100 : st->last_coder_type_raw = st->coder_type_raw;
344 3100 : move16();
345 :
346 3100 : st->prev_Q_new = Q_new;
347 3100 : move16();
348 :
349 3100 : test();
350 3100 : IF( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL )
351 : {
352 3100 : st->hDtxEnc->last_active_brate = st->total_brate;
353 3100 : move32();
354 : }
355 :
356 3100 : IF( st->hBWE_TD != NULL )
357 : {
358 3100 : st->hBWE_TD->prev_coder_type = st->coder_type;
359 3100 : move16();
360 3100 : IF( EQ_16( st->core, HQ_CORE ) )
361 : {
362 : /* in the HQ core, coder_type is not used so it could have been set to anything */
363 407 : st->hBWE_TD->prev_coder_type = GENERIC;
364 407 : move16();
365 : }
366 : }
367 :
368 3100 : test();
369 3100 : IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL )
370 : {
371 0 : IF( GT_32( st->core_brate, SID_2k40 ) )
372 : {
373 0 : IF( EQ_16( st->hDtxEnc->first_CNG, 1 ) )
374 : {
375 0 : IF( GE_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) )
376 : {
377 0 : st->hTdCngEnc->act_cnt = 0;
378 0 : move16();
379 : }
380 0 : st->hTdCngEnc->act_cnt = add( st->hTdCngEnc->act_cnt, 1 );
381 0 : move16();
382 :
383 0 : test();
384 0 : IF( EQ_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) && st->hTdCngEnc->ho_hist_size > 0 )
385 : {
386 0 : st->hTdCngEnc->ho_hist_size = sub( st->hTdCngEnc->ho_hist_size, 1 );
387 0 : move16();
388 : }
389 : }
390 :
391 0 : test();
392 0 : test();
393 0 : test();
394 0 : IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) )
395 : {
396 0 : st->hTdCngEnc->act_cnt2 = add( st->hTdCngEnc->act_cnt2, 1 );
397 0 : st->hTdCngEnc->act_cnt2 = s_min( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD );
398 0 : move16();
399 0 : move16();
400 :
401 0 : test();
402 0 : test();
403 0 : test();
404 0 : IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) )
405 : {
406 : }
407 : }
408 : }
409 :
410 0 : test();
411 0 : test();
412 0 : test();
413 0 : IF( ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->hDtxEnc->first_CNG == 0 && EQ_16( st->cng_type, LP_CNG ) )
414 : {
415 0 : st->hDtxEnc->first_CNG = 1;
416 0 : move16();
417 : }
418 : }
419 :
420 : /*-----------------------------------------------------------------*
421 : * Increase the counter of initialization frames
422 : * Limit the max number of init. frames
423 : *-----------------------------------------------------------------*/
424 :
425 3100 : if ( LT_16( st->ini_frame, MAX_FRAME_COUNTER ) )
426 : {
427 600 : st->ini_frame = add( st->ini_frame, 1 );
428 600 : move16();
429 : }
430 :
431 : /* synchronisation of CNG seeds */
432 3100 : test();
433 3100 : test();
434 3100 : test();
435 3100 : IF( st->hTdCngEnc != NULL && NE_32( st->core_brate, FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) && NE_16( st->core, AMR_WB_CORE ) )
436 : {
437 3100 : Random( &( st->hTdCngEnc->cng_seed ) );
438 3100 : Random( &( st->hTdCngEnc->cng_ener_seed ) );
439 : }
440 :
441 : /*---------------------------------------------------------------------*
442 : * Updates - MODE2
443 : *---------------------------------------------------------------------*/
444 :
445 3100 : IF( EQ_16( st->element_mode, EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) )
446 : {
447 44 : st->codec_mode = MODE2;
448 44 : move16();
449 :
450 44 : st->sr_core = getCoreSamplerateMode2( EVS_MONO, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 );
451 44 : move32();
452 :
453 : // st->L_frame = extract_l(Mult_32_16(st->sr_core, 0x0290)); /*(int16_t)(st->sr_core / FRAMES_PER_SEC);*/
454 :
455 44 : IF( EQ_32( st->sr_core, INT_FS_12k8 ) )
456 : {
457 0 : st->preemph_fac = PREEMPH_FAC;
458 0 : st->gamma = GAMMA1;
459 0 : st->L_frame = L_FRAME;
460 0 : move16();
461 0 : move16();
462 0 : move16();
463 : }
464 : ELSE
465 : {
466 44 : st->preemph_fac = PREEMPH_FAC_16k;
467 44 : st->gamma = GAMMA16k;
468 44 : st->L_frame = L_FRAME16k;
469 44 : move16();
470 44 : move16();
471 44 : move16();
472 : }
473 :
474 44 : st->igf = getIgfPresent_fx( EVS_MONO, st->total_brate, st->bwidth, st->rf_mode );
475 44 : move16();
476 : }
477 :
478 : /* update FER clas */
479 3100 : IF( NE_16( st->core, AMR_WB_CORE ) )
480 : {
481 3100 : st->last_clas = st->clas;
482 3100 : move16();
483 : }
484 :
485 : /* Update Core */
486 3100 : core_encode_update_fx( st );
487 :
488 : /*---------------------------------------------------------------------*
489 : * RF mode updates
490 : *---------------------------------------------------------------------*/
491 :
492 3100 : IF( st->rf_mode )
493 : {
494 0 : IF( st->hSC_VBR != NULL )
495 : {
496 0 : st->hSC_VBR->last_nelp_mode = 0;
497 0 : move16();
498 0 : IF( EQ_16( st->hRF->rf_frame_type, RF_NELP ) )
499 : {
500 0 : st->hSC_VBR->last_nelp_mode = 1;
501 0 : move16();
502 : }
503 : }
504 : }
505 :
506 3100 : st->rf_mode_last = st->rf_mode;
507 3100 : move16();
508 :
509 3100 : IF( st->Opt_RF_ON )
510 : {
511 0 : st->L_frame = L_FRAME;
512 0 : st->rf_mode = 1;
513 0 : move16();
514 0 : move16();
515 : }
516 :
517 : /*---------------------------------------------------------------------*
518 : * Other updates
519 : *---------------------------------------------------------------------*/
520 :
521 3100 : test();
522 3100 : IF( GT_16( st->element_mode, EVS_MONO ) && st->hTcxEnc != NULL )
523 : {
524 : }
525 3100 : return;
526 : }
527 :
528 :
529 1108119 : void updt_enc_common_ivas_fx(
530 : Encoder_State *st, /* i/o: encoder state structure */
531 : const Word16 Q_new /* i : CUrrent frame scaling */
532 : )
533 : {
534 : /*---------------------------------------------------------------------*
535 : * Updates - main main codec parameters
536 : *---------------------------------------------------------------------*/
537 1108119 : st->last_sr_core = st->sr_core;
538 1108119 : move32();
539 1108119 : st->last_codec_mode = st->codec_mode;
540 1108119 : move16();
541 1108119 : st->last_L_frame = st->L_frame;
542 1108119 : move16();
543 1108119 : st->last_core = st->core;
544 1108119 : move16();
545 :
546 1108119 : st->last_total_brate = st->total_brate;
547 1108119 : move32();
548 1108119 : st->last_bits_frame_nominal = st->bits_frame_nominal;
549 1108119 : move16();
550 1108119 : st->last_core_brate = st->core_brate;
551 1108119 : move32();
552 1108119 : st->last_extl = st->extl;
553 1108119 : move16();
554 1108119 : st->last_input_bwidth = st->input_bwidth;
555 1108119 : move16();
556 1108119 : st->last_bwidth = st->bwidth;
557 1108119 : move16();
558 1108119 : st->last_coder_type_raw = st->coder_type_raw;
559 1108119 : move16();
560 1108119 : st->prev_Q_new = Q_new;
561 1108119 : move16();
562 :
563 1108119 : test();
564 1108119 : if ( GT_32( st->core_brate, SID_2k40 ) && st->hDtxEnc != NULL )
565 : {
566 95560 : st->hDtxEnc->last_active_brate = st->total_brate;
567 95560 : move32();
568 : }
569 :
570 1108119 : IF( st->hBWE_TD != NULL )
571 : {
572 414420 : IF( EQ_16( st->core, HQ_CORE ) )
573 : {
574 : /* in the HQ core, coder_type is not used so it could have been set to anything */
575 7815 : st->hBWE_TD->prev_coder_type = GENERIC;
576 7815 : move16();
577 : }
578 : ELSE
579 : {
580 406605 : st->hBWE_TD->prev_coder_type = st->coder_type;
581 406605 : move16();
582 : }
583 : }
584 :
585 1108119 : test();
586 1108119 : IF( st->Opt_DTX_ON && st->hTdCngEnc != NULL )
587 : {
588 46560 : IF( GT_32( st->core_brate, SID_2k40 ) )
589 : {
590 33636 : IF( EQ_16( st->hDtxEnc->first_CNG, 1 ) )
591 : {
592 17646 : if ( GE_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) )
593 : {
594 674 : st->hTdCngEnc->act_cnt = 0;
595 674 : move16();
596 : }
597 17646 : st->hTdCngEnc->act_cnt = add( st->hTdCngEnc->act_cnt, 1 );
598 17646 : move16();
599 :
600 17646 : test();
601 17646 : IF( EQ_16( st->hTdCngEnc->act_cnt, BUF_DEC_RATE ) && st->hTdCngEnc->ho_hist_size > 0 )
602 : {
603 244 : st->hTdCngEnc->ho_hist_size = sub( st->hTdCngEnc->ho_hist_size, 1 );
604 244 : move16();
605 : }
606 : }
607 :
608 33636 : test();
609 33636 : test();
610 33636 : test();
611 33636 : IF( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) || EQ_16( st->hDtxEnc->first_CNG, 1 ) )
612 : {
613 33636 : if ( GE_16( ++( st->hTdCngEnc->act_cnt2 ), MIN_ACT_CNG_UPD ) )
614 : {
615 27199 : st->hTdCngEnc->act_cnt2 = MIN_ACT_CNG_UPD;
616 27199 : move16();
617 : }
618 :
619 33636 : test();
620 33636 : test();
621 33636 : test();
622 33636 : IF( ( EQ_16( st->element_mode, IVAS_SCE ) || EQ_16( st->element_mode, IVAS_CPE_DFT ) || EQ_16( st->element_mode, IVAS_CPE_TD ) ) && GE_16( st->hTdCngEnc->act_cnt2, MIN_ACT_CNG_UPD ) )
623 : {
624 27199 : Word32 cng_att_fx32 = 0;
625 27199 : move32();
626 :
627 27199 : apply_scale( &cng_att_fx32, st->hFdCngEnc->hFdCngCom->CngBandwidth, st->hFdCngEnc->hFdCngCom->CngBitrate, scaleTableStereo, SIZE_SCALE_TABLE_STEREO );
628 :
629 27199 : st->hTdCngEnc->CNG_att_fx = extract_l( L_shr( cng_att_fx32, Q16 ) ); // Q23
630 27199 : move16();
631 : }
632 : }
633 : }
634 :
635 46560 : test();
636 46560 : test();
637 46560 : test();
638 46560 : if ( ( EQ_32( st->core_brate, SID_2k40 ) || EQ_32( st->core_brate, FRAME_NO_DATA ) ) && st->hDtxEnc->first_CNG == 0 && EQ_16( st->cng_type, LP_CNG ) )
639 : {
640 29 : st->hDtxEnc->first_CNG = 1;
641 29 : move16();
642 : }
643 : }
644 :
645 : /*-----------------------------------------------------------------*
646 : * Increase the counter of initialization frames
647 : * Limit the max number of init. frames
648 : *-----------------------------------------------------------------*/
649 :
650 1108119 : IF( LT_16( st->ini_frame, MAX_FRAME_COUNTER ) )
651 : {
652 394260 : st->ini_frame = add( st->ini_frame, 1 );
653 : }
654 :
655 : /* synchronisation of CNG seeds */
656 1108119 : test();
657 1108119 : test();
658 1108119 : test();
659 1108119 : IF( st->hTdCngEnc != NULL && ( st->core_brate != FRAME_NO_DATA ) && NE_32( st->core_brate, SID_2k40 ) && NE_16( st->core, AMR_WB_CORE ) )
660 : {
661 33636 : Random( &( st->hTdCngEnc->cng_seed ) );
662 33636 : Random( &( st->hTdCngEnc->cng_ener_seed ) );
663 : }
664 :
665 : /*---------------------------------------------------------------------*
666 : * Updates - MODE2
667 : *---------------------------------------------------------------------*/
668 :
669 1108119 : test();
670 1108119 : IF( ( st->element_mode == EVS_MONO ) && EQ_16( st->mdct_sw, MODE2 ) )
671 : {
672 0 : st->codec_mode = MODE2;
673 0 : move16();
674 :
675 0 : st->sr_core = getCoreSamplerateMode2( EVS_MONO, st->total_brate, st->bwidth, st->flag_ACELP16k, st->rf_mode, 0 );
676 0 : move16();
677 :
678 : Word16 exp;
679 0 : st->L_frame = BASOP_Util_Divide3232_Scale( st->sr_core, FRAMES_PER_SEC, &exp );
680 0 : move16();
681 0 : st->L_frame = shr( st->L_frame, sub( 15, exp ) );
682 0 : move16();
683 :
684 0 : IF( EQ_32( st->sr_core, INT_FS_12k8 ) )
685 : {
686 0 : st->preemph_fac = PREEMPH_FAC;
687 0 : st->gamma = GAMMA1;
688 : }
689 : ELSE
690 : {
691 :
692 0 : st->preemph_fac = PREEMPH_FAC_16k;
693 0 : st->gamma = GAMMA16k;
694 : }
695 0 : move16();
696 0 : move16();
697 :
698 0 : st->igf = getIgfPresent_fx( EVS_MONO, st->total_brate, st->bwidth, st->rf_mode );
699 0 : move16();
700 : }
701 :
702 : /* update FER clas */
703 1108119 : if ( NE_16( st->core, AMR_WB_CORE ) )
704 : {
705 1108119 : st->last_clas = st->clas;
706 1108119 : move16();
707 : }
708 :
709 : /* Update Core */
710 1108119 : core_encode_update_ivas_fx( st );
711 :
712 : /*---------------------------------------------------------------------*
713 : * RF mode updates
714 : *---------------------------------------------------------------------*/
715 :
716 1108119 : IF( st->rf_mode )
717 : {
718 0 : IF( st->hSC_VBR != NULL )
719 : {
720 0 : IF( EQ_16( st->hRF->rf_frame_type, RF_NELP ) )
721 : {
722 0 : st->hSC_VBR->last_nelp_mode = 1;
723 0 : move16();
724 : }
725 : ELSE
726 : {
727 0 : st->hSC_VBR->last_nelp_mode = 0;
728 0 : move16();
729 : }
730 : }
731 : }
732 :
733 1108119 : st->rf_mode_last = st->rf_mode;
734 1108119 : move16();
735 :
736 1108119 : IF( st->Opt_RF_ON )
737 : {
738 0 : st->L_frame = L_FRAME;
739 0 : st->rf_mode = 1;
740 0 : move16();
741 0 : move16();
742 : }
743 :
744 : /*---------------------------------------------------------------------*
745 : * Other updates
746 : *---------------------------------------------------------------------*/
747 :
748 1108119 : test();
749 1108119 : if ( st->element_mode > EVS_MONO && st->hTcxEnc != NULL )
750 : {
751 1104292 : st->hTcxEnc->tcxltp_norm_corr_mem = st->hTcxEnc->tcxltp_norm_corr_past;
752 1104292 : move16();
753 : }
754 :
755 1108119 : return;
756 : }
|