Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : /*====================================================================================
34 : EVS Codec 3GPP TS26.443 Nov 04, 2021. Version 12.14.0 / 13.10.0 / 14.6.0 / 15.4.0 / 16.3.0
35 : ====================================================================================*/
36 :
37 : #include <stdint.h>
38 : #include "options.h"
39 : #ifdef DEBUGGING
40 : #include "debug.h"
41 : #endif
42 : #include <math.h>
43 : #include "cnst.h"
44 : #include "prot.h"
45 : #include "rom_com.h"
46 : #include "rom_dec.h"
47 : #include "wmc_auto.h"
48 : #include "ivas_prot.h"
49 :
50 : /*-----------------------------------------------------------------*
51 : * Local function prototypes
52 : *-----------------------------------------------------------------*/
53 :
54 : static void dequantizeSHBparams( Decoder_State *st, const int16_t extl, int32_t extl_brate, float *Q_lsf, float *Q_subgain, float *Q_framegrain, int16_t *uv_flag, float *Q_shb_ener_sf, float *Q_shb_res_gshape, float *Q_mixFactors, int16_t *MSFlag );
55 : static void Dequant_lower_LSF( const int16_t lsf_idx[], float lsf_q[] );
56 : static void Map_higher_LSF( float lsf_q[], const float m, const float grid_in[] );
57 : static void Dequant_mirror_point( const float lsf_q[], const int16_t m_idx, float *m );
58 :
59 :
60 : /*-------------------------------------------------------------------*
61 : * ResetSHBbuffer_Dec()
62 : *
63 : *
64 : *-------------------------------------------------------------------*/
65 :
66 125200 : void ResetSHBbuffer_Dec(
67 : TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
68 : const int16_t extl /* i : BWE extension layer */
69 : )
70 : {
71 : int16_t i;
72 : float f;
73 : float inc;
74 :
75 125200 : if ( extl != WB_TBE )
76 : {
77 125200 : f = 1.0f / 22.0f;
78 125200 : inc = 1.0f / 22.0f;
79 : }
80 : else
81 : {
82 0 : f = 1.0f / 6.0f;
83 0 : inc = 1.0f / 6.0f;
84 : }
85 :
86 : /* states for the filters used in generating SHB excitation from WB excitation*/
87 125200 : set_f( hBWE_TD->mem_csfilt, 0, 2 );
88 :
89 : /* states for the filters used in generating SHB signal from SHB excitation*/
90 125200 : set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD );
91 125200 : set_f( hBWE_TD->state_lpc_syn, 0, LPC_SHB_ORDER );
92 :
93 125200 : if ( extl == FB_TBE )
94 : {
95 0 : set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER );
96 0 : hBWE_TD->fb_tbe_demph = 0;
97 0 : fb_tbe_reset_synth( hBWE_TD->fbbwe_hpf_mem, &hBWE_TD->prev_fbbwe_ratio );
98 : }
99 :
100 : /* states for the filters used in generating SHB signal from SHB excitation in wideband*/
101 125200 : set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
102 125200 : set_f( hBWE_TD->mem_genSHBexc_filt_down_wb2, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
103 125200 : set_f( hBWE_TD->mem_genSHBexc_filt_down_wb3, 0.0f, ( 2 * ALLPASSSECTIONS_STEEP + 1 ) );
104 :
105 125200 : set_f( hBWE_TD->state_lsyn_filt_shb, 0, 2 * ALLPASSSECTIONS_STEEP );
106 125200 : set_f( hBWE_TD->state_lsyn_filt_dwn_shb, 0, 2 * ALLPASSSECTIONS_STEEP );
107 125200 : set_f( hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN );
108 :
109 : /* States for the local synthesis filters */
110 125200 : set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD );
111 :
112 : /* States for FEC */
113 125200 : if ( extl != WB_TBE )
114 : {
115 1377200 : for ( i = 0; i < LPC_SHB_ORDER; i++ )
116 : {
117 1252000 : hBWE_TD->lsp_prevfrm[i] = f;
118 1252000 : f += inc;
119 : }
120 : }
121 : else
122 : {
123 0 : for ( i = 0; i < LPC_SHB_ORDER_WB; i++ )
124 : {
125 0 : hBWE_TD->lsp_prevfrm[i] = f;
126 0 : f += inc;
127 : }
128 0 : for ( ; i < LPC_SHB_ORDER; i++ )
129 : {
130 0 : hBWE_TD->lsp_prevfrm[i] = 0.0f;
131 : }
132 : }
133 :
134 125200 : hBWE_TD->GainFrame_prevfrm = 0.0f;
135 125200 : hBWE_TD->GainAttn = 1.0;
136 125200 : hBWE_TD->tbe_demph = 0.0f;
137 125200 : hBWE_TD->tbe_premph = 0.0f;
138 125200 : set_f( hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER );
139 125200 : hBWE_TD->gain_prec_swb = 1.0f;
140 125200 : set_f( hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 );
141 125200 : hBWE_TD->prev_pow_exc16kWhtnd = 1.0f;
142 125200 : hBWE_TD->prev_mix_factor = 1.0f;
143 :
144 125200 : set_f( hBWE_TD->old_core_synth, 0, L_FRAME16k );
145 125200 : set_f( hBWE_TD->old_tbe_synth, 0, L_SHB_TRANSITION_LENGTH );
146 125200 : hBWE_TD->tilt_swb_fec = 0.0f;
147 :
148 125200 : return;
149 : }
150 :
151 : /*-------------------------------------------------------------------*
152 : * wb_tbe_dec()
153 : *
154 : * WB TBE decoder, 6 - 8 kHz band decoding module
155 : *-------------------------------------------------------------------*/
156 :
157 277071 : void wb_tbe_dec(
158 : Decoder_State *st, /* i/o: decoder state structure */
159 : const float *bwe_exc_extended, /* i : bandwidth extended excitation */
160 : const float voice_factors[], /* i : voicing factors */
161 : float *synth /* o : WB synthesis/final synthesis */
162 : )
163 : {
164 : int16_t i;
165 : TD_BWE_DEC_HANDLE hBWE_TD;
166 : float shaped_wb_excitation[( L_FRAME16k + L_SHB_LAHEAD ) / 4];
167 : float exc4kWhtnd[L_FRAME16k / 4];
168 : float lsf_wb[LPC_SHB_ORDER_WB], lpc_wb[LPC_SHB_ORDER_WB + 1], GainShape[NUM_SHB_SUBFR], GainFrame;
169 : float error[L_FRAME16k];
170 : float upsampled_synth[L_FRAME48k];
171 : float prev_pow, curr_pow, scale;
172 : float temp, curr_frame_pow;
173 : int16_t j;
174 : float vf_modified[NB_SUBFR16k];
175 277071 : int16_t uv_flag = 0;
176 :
177 277071 : hBWE_TD = st->hBWE_TD;
178 :
179 277071 : if ( st->bws_cnt == 0 )
180 : {
181 :
182 276507 : if ( !st->bfi )
183 : {
184 252545 : if ( st->use_partial_copy )
185 : {
186 92 : if ( st->last_extl != WB_TBE )
187 : {
188 0 : hBWE_TD->GainFrame_prevfrm = 0;
189 0 : hBWE_TD->lsp_prevfrm[0] = 0.1f;
190 0 : for ( i = 1; i < LPC_SHB_ORDER_LBR_WB; i++ )
191 : {
192 0 : hBWE_TD->lsp_prevfrm[i] = hBWE_TD->lsp_prevfrm[i - i] + 0.1f;
193 : }
194 : }
195 :
196 92 : mvr2r( hBWE_TD->lsp_prevfrm, lsf_wb, LPC_SHB_ORDER_LBR_WB );
197 92 : set_f( GainShape, RECIP_ROOT_EIGHT, NUM_SHB_SUBFR / 2 );
198 :
199 92 : if ( st->rf_frame_type == RF_NELP )
200 : {
201 : /* Frame gain */
202 : /* only four LSBs are valid */
203 0 : st->rf_indx_tbeGainFr &= 0xF;
204 0 : mvr2r( SHBCB_FrameGain16 + st->rf_indx_tbeGainFr, &GainFrame, 1 );
205 0 : if ( st->core == ACELP_CORE && st->last_core == ACELP_CORE && !st->prev_use_partial_copy && st->prev_coder_type == UNVOICED && GainFrame != hBWE_TD->GainFrame_prevfrm && st->last_extl == WB_TBE )
206 : {
207 0 : GainFrame = 0.2f * GainFrame + 0.8f * hBWE_TD->GainFrame_prevfrm;
208 : }
209 : }
210 : else
211 : {
212 : /* Frame gain */
213 92 : temp = 0.0f;
214 92 : switch ( st->rf_indx_tbeGainFr )
215 : {
216 52 : case 0:
217 52 : GainFrame = 0.5f;
218 52 : if ( hBWE_TD->GainFrame_prevfrm <= 1.25 )
219 : {
220 40 : temp = 0.8f;
221 : }
222 52 : break;
223 40 : case 1:
224 40 : GainFrame = 2.0f;
225 40 : if ( hBWE_TD->GainFrame_prevfrm > 1.25 && hBWE_TD->GainFrame_prevfrm <= 3 )
226 : {
227 14 : temp = 0.8f;
228 : }
229 40 : break;
230 0 : case 2:
231 0 : GainFrame = 4.0f;
232 0 : if ( hBWE_TD->GainFrame_prevfrm > 3 && hBWE_TD->GainFrame_prevfrm <= 6 )
233 : {
234 0 : temp = 0.8f;
235 : }
236 0 : break;
237 0 : case 3:
238 0 : GainFrame = 8.0f;
239 0 : if ( hBWE_TD->GainFrame_prevfrm > 6 && hBWE_TD->GainFrame_prevfrm <= 16 )
240 : {
241 0 : temp = 0.8f;
242 : }
243 0 : break;
244 0 : default:
245 0 : GainFrame = 1.0f;
246 0 : IVAS_ERROR( IVAS_ERR_INTERNAL, "RF WB-TBE gain bits not supported." );
247 0 : break;
248 : }
249 :
250 92 : if ( st->last_extl == WB_TBE )
251 : {
252 92 : GainFrame = ( 1 - temp ) * GainFrame + temp * ( hBWE_TD->GainFrame_prevfrm );
253 : }
254 :
255 92 : if ( st->core == ACELP_CORE && st->last_core == ACELP_CORE )
256 : {
257 92 : if ( !st->prev_use_partial_copy && st->last_coder_type == VOICED && st->rf_frame_type == RF_GENPRED && st->prev_tilt_code_dec < 0.046f && st->prev_tilt_code_dec > 0.006f )
258 : {
259 0 : GainFrame *= 0.3f;
260 : }
261 : }
262 : }
263 : }
264 : else
265 : {
266 : /* de-quantization */
267 252453 : dequantizeSHBparams( st, st->extl, st->extl_brate, lsf_wb, GainShape, &GainFrame, &uv_flag, 0, 0, 0, &j /*temp*/ );
268 : }
269 : }
270 : else
271 : {
272 23962 : if ( st->extl_brate == WB_TBE_0k35 )
273 : {
274 4443 : mvr2r( hBWE_TD->lsp_prevfrm, lsf_wb, LPC_SHB_ORDER_LBR_WB );
275 : }
276 : else
277 : {
278 19519 : mvr2r( hBWE_TD->lsp_prevfrm, lsf_wb, LPC_SHB_ORDER_WB );
279 : }
280 23962 : set_f( GainShape, RECIP_ROOT_EIGHT, NUM_SHB_SUBFR / 2 );
281 23962 : hBWE_TD->GainAttn *= 0.85f;
282 23962 : if ( st->codec_mode == MODE1 )
283 : {
284 23691 : GainFrame = hBWE_TD->GainAttn * hBWE_TD->GainFrame_prevfrm;
285 : }
286 : else
287 : {
288 271 : GainFrame = hBWE_TD->GainFrame_prevfrm;
289 : }
290 : }
291 :
292 276507 : if ( st->extl_brate == WB_TBE_0k35 )
293 : {
294 : /* convert LSPs back into LP coeffs */
295 64740 : lsp2a( lpc_wb, lsf_wb, LPC_SHB_ORDER_LBR_WB );
296 64740 : set_f( lpc_wb + LPC_SHB_ORDER_LBR_WB + 1, 0.0f, ( LPC_SHB_ORDER_WB - LPC_SHB_ORDER_LBR_WB ) );
297 : }
298 : else
299 : {
300 : /* convert LSPs back into LP coeffs */
301 211767 : lsp2a( lpc_wb, lsf_wb, LPC_SHB_ORDER_WB );
302 : }
303 276507 : lpc_wb[0] = 1.0f;
304 276507 : mvr2r( voice_factors, vf_modified, NB_SUBFR16k );
305 276507 : if ( st->coder_type == VOICED )
306 : {
307 127108 : for ( i = 1; i < NB_SUBFR; i++ )
308 : {
309 95331 : vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i - 1];
310 : }
311 :
312 31777 : if ( st->L_frame != L_FRAME )
313 : {
314 0 : vf_modified[4] = 0.8f * voice_factors[4] + 0.2f * voice_factors[3];
315 : }
316 : }
317 :
318 276507 : if ( st->use_partial_copy && st->nelp_mode_dec )
319 : {
320 0 : set_f( vf_modified, 0.0f, NB_SUBFR16k );
321 : }
322 :
323 : /* From low band excitation, generate highband excitation */
324 276507 : mvr2r( hBWE_TD->state_syn_shbexc, shaped_wb_excitation, L_SHB_LAHEAD / 4 );
325 :
326 : #ifdef FIX_1465_SWB_TBE_RANDOM_VECTOR_CREATION
327 276507 : GenShapedWBExcitation( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->state_lpc_syn, st->coder_type, st->element_mode, bwe_exc_extended, hBWE_TD->bwe_seed, vf_modified, uv_flag, st->igf );
328 : #else
329 : GenShapedWBExcitation( shaped_wb_excitation + L_SHB_LAHEAD / 4, lpc_wb, exc4kWhtnd, hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3, hBWE_TD->state_lpc_syn, st->coder_type, bwe_exc_extended, hBWE_TD->bwe_seed, vf_modified, uv_flag, st->igf );
330 : #endif
331 :
332 276507 : prev_pow = sum2_f( shaped_wb_excitation, L_SHB_LAHEAD / 4 );
333 276507 : curr_pow = sum2_f( shaped_wb_excitation + L_SHB_LAHEAD / 4, L_SHB_LAHEAD / 4 );
334 :
335 276507 : if ( st->element_mode > EVS_MONO )
336 : {
337 : /* prevent too low values of energy */
338 271471 : prev_pow = max( 0.00001f, prev_pow );
339 271471 : curr_pow = max( 0.00001f, curr_pow );
340 : }
341 :
342 276507 : if ( voice_factors[0] > 0.75f )
343 : {
344 3596 : curr_pow *= 0.25;
345 : }
346 :
347 276507 : if ( prev_pow == 0 )
348 : {
349 250 : scale = 0;
350 : }
351 : else
352 : {
353 276257 : scale = (float) sqrt( curr_pow / prev_pow );
354 : }
355 :
356 1382535 : for ( i = 0; i < L_SHB_LAHEAD / 4 - 1; i++ )
357 : {
358 1106028 : shaped_wb_excitation[i] *= scale;
359 : }
360 276507 : scale = (float) sqrt( scale );
361 :
362 276507 : shaped_wb_excitation[L_SHB_LAHEAD / 4 - 1] *= scale;
363 :
364 : /* Update SHB excitation */
365 276507 : mvr2r( shaped_wb_excitation + L_FRAME16k / 4, hBWE_TD->state_syn_shbexc, L_SHB_LAHEAD / 4 );
366 :
367 : /* Adjust the subframe and frame gain of the synthesized shb signal */
368 : /* Scale the shaped excitation */
369 276507 : ScaleShapedSHB( SHB_OVERLAP_LEN / 2, shaped_wb_excitation, hBWE_TD->syn_overlap, GainShape, GainFrame, window_wb, subwin_wb );
370 :
371 276507 : curr_frame_pow = sum2_f( shaped_wb_excitation, L_FRAME16k / 4 ) + 0.001f;
372 276507 : curr_frame_pow = min( curr_frame_pow, FLT_MAX );
373 :
374 276507 : if ( !st->bfi && ( st->prev_bfi || st->prev_use_partial_copy ) )
375 : {
376 9523 : if ( curr_frame_pow > 2.0f * hBWE_TD->prev_wb_bwe_frame_pow )
377 : {
378 7636 : scale = root_a_over_b( hBWE_TD->prev_wb_bwe_frame_pow, curr_frame_pow );
379 7636 : temp = (float) pow( scale, 0.125f );
380 : }
381 : else
382 : {
383 1887 : scale = 1.0f;
384 1887 : temp = 1.0f;
385 : }
386 :
387 85707 : for ( j = 0; j < 8; j++ )
388 : {
389 76184 : GainShape[2 * j] *= scale;
390 76184 : GainShape[2 * j + 1] *= scale;
391 838024 : for ( i = 0; i < L_FRAME16k / ( 4 * 8 ); i++ )
392 : {
393 761840 : shaped_wb_excitation[i + j * L_FRAME16k / ( 4 * 8 )] *= scale;
394 : }
395 76184 : scale /= temp;
396 : }
397 : }
398 :
399 276507 : hBWE_TD->prev_wb_bwe_frame_pow = curr_frame_pow;
400 :
401 : /* generate 16kHz SHB signal (6 - 8 kHz) from 2kHz signal */
402 276507 : GenWBSynth( shaped_wb_excitation, error, hBWE_TD->state_lsyn_filt_shb, hBWE_TD->state_lsyn_filt_dwn_shb );
403 :
404 276507 : mvr2r( error + L_FRAME16k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth, L_SHB_TRANSITION_LENGTH );
405 :
406 88758747 : for ( i = 0; i < L_FRAME16k; i++ )
407 : {
408 88482240 : synth[i] = 0.65f * error[i];
409 : }
410 :
411 276507 : if ( st->hBWE_FD != NULL )
412 : {
413 276507 : st->hBWE_FD->last_wb_bwe_ener = 0.0f;
414 88758747 : for ( i = 0; i < L_FRAME16k; i++ )
415 : {
416 88482240 : st->hBWE_FD->last_wb_bwe_ener += synth[i] * synth[i];
417 : }
418 276507 : st->hBWE_FD->last_wb_bwe_ener = (float) sqrt( st->hBWE_FD->last_wb_bwe_ener / L_FRAME16k );
419 : }
420 :
421 276507 : if ( st->output_Fs == 32000 ) /* 32kHz sampling rate, but only WB output - interpolate */
422 : {
423 7499 : Interpolate_allpass_steep( synth, hBWE_TD->mem_resamp_HB, L_FRAME16k, upsampled_synth );
424 7499 : mvr2r( upsampled_synth, synth, L_FRAME32k );
425 : }
426 269008 : else if ( st->output_Fs == 48000 )
427 : {
428 10525 : interpolate_3_over_1_allpass( synth, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB );
429 10525 : mvr2r( upsampled_synth, synth, L_FRAME48k );
430 : }
431 : }
432 : else
433 : {
434 3948 : for ( i = 0; i < LPC_SHB_ORDER_WB; i++ )
435 : {
436 3384 : lsf_wb[i] = ( i + 1 ) / 6.f;
437 : }
438 564 : GainFrame = 0;
439 :
440 564 : hBWE_TD->prev_wb_bwe_frame_pow = 0.001f;
441 : }
442 :
443 : /* Update previous frame parameters for FEC */
444 277071 : if ( st->extl_brate == WB_TBE_0k35 )
445 : {
446 65304 : mvr2r( lsf_wb, hBWE_TD->lsp_prevfrm, LPC_SHB_ORDER_LBR_WB );
447 : }
448 : else
449 : {
450 211767 : mvr2r( lsf_wb, hBWE_TD->lsp_prevfrm, LPC_SHB_ORDER_WB );
451 : }
452 277071 : hBWE_TD->GainFrame_prevfrm = GainFrame;
453 :
454 277071 : if ( !st->bfi )
455 : {
456 253109 : hBWE_TD->GainAttn = 1.0f;
457 : }
458 :
459 277071 : return;
460 : }
461 :
462 : /*-------------------------------------------------------------------*
463 : * swb_tbe_dec()
464 : *
465 : * SWB TBE decoder, 6 - 14 kHz (or 7.5 - 15.5 kHz) band decoding module
466 : *-------------------------------------------------------------------*/
467 :
468 1072787 : void swb_tbe_dec(
469 : Decoder_State *st, /* i/o: decoder state structure */
470 : STEREO_ICBWE_DEC_HANDLE hStereoICBWE, /* i/o: IC-BWE state structure */
471 : const float *bwe_exc_extended, /* i : bandwidth extended excitation */
472 : const float voice_factors[], /* i : voicing factors */
473 : const float old_syn_12k8_16k[], /* i : low band synthesis */
474 : float *White_exc16k, /* o : shaped white excitation for the FB TBE */
475 : float *synth, /* o : SHB synthesis/final synthesis */
476 : float *pitch_buf )
477 : {
478 : int16_t i, j;
479 : int16_t stemp;
480 : TD_BWE_DEC_HANDLE hBWE_TD;
481 : float shaped_shb_excitation[L_FRAME16k + L_SHB_LAHEAD];
482 : float lsf_shb[LPC_SHB_ORDER], lpc_shb[LPC_SHB_ORDER + 1], GainShape[NUM_SHB_SUBFR], GainFrame;
483 : float error[L_FRAME32k];
484 : float ener;
485 : int16_t is_fractive;
486 : float prev_pow, curr_pow, scale;
487 : float curr_frame_pow, temp;
488 : float GainShapeTemp[NUM_SHB_SUBFR / 4], GainGrad0[3], GainGrad1[3], GainGradFEC[4];
489 : float vf_modified[NB_SUBFR16k];
490 : float f, inc;
491 : float GainFrame_prevfrm;
492 : float tilt_swb_fec;
493 : float prev_ener_ratio;
494 : float lsp_shb_1[LPC_SHB_ORDER], lsp_shb_2[LPC_SHB_ORDER], lsp_temp[LPC_SHB_ORDER];
495 : float lpc_shb_sf[4 * ( LPC_SHB_ORDER + 1 )];
496 : const float *ptr_lsp_interp_coef;
497 : float shb_ener_sf;
498 : float shb_res_gshape[NB_SUBFR16k];
499 : float mixFactors;
500 : int16_t vind;
501 : float shb_res_dummy[L_FRAME16k];
502 : float shaped_shb_excitationTemp[L_FRAME16k];
503 : float ener_tmp[NUM_SHB_SUBGAINS];
504 : float GainShape_tmp[NUM_SHB_SUBGAINS];
505 : float pitch;
506 : int16_t l_subframe;
507 : float formant_fac;
508 : float synth_scale;
509 : float lsf_diff[LPC_SHB_ORDER], w[LPC_SHB_ORDER];
510 : float refl[M];
511 : float tilt_para;
512 : float *nlExc16k, *mixExc16k;
513 : int16_t MSFlag;
514 : float feedback;
515 : float GainShape_tilt;
516 :
517 1072787 : hBWE_TD = st->hBWE_TD;
518 :
519 : /* initializations */
520 1072787 : GainFrame = 0.0f;
521 1072787 : mixFactors = 0.0f;
522 1072787 : shb_ener_sf = 0.0f;
523 1072787 : set_f( shaped_shb_excitationTemp, 0.0f, L_FRAME16k );
524 1072787 : if ( st->hTdCngDec != NULL )
525 : {
526 855161 : st->hTdCngDec->shb_dtx_count = 0;
527 : }
528 1072787 : is_fractive = 0;
529 :
530 1072787 : if ( hStereoICBWE != NULL )
531 : {
532 107658 : nlExc16k = hStereoICBWE->nlExc16k;
533 107658 : mixExc16k = hStereoICBWE->mixExc16k;
534 107658 : MSFlag = hStereoICBWE->MSFlag;
535 : }
536 : else
537 : {
538 965129 : nlExc16k = NULL;
539 965129 : mixExc16k = NULL;
540 965129 : MSFlag = 0;
541 : }
542 :
543 : /* find tilt */
544 1072787 : calc_tilt_bwe( old_syn_12k8_16k, &tilt_swb_fec, L_FRAME );
545 :
546 1072787 : if ( st->bfi && st->clas_dec != UNVOICED_CLAS )
547 : {
548 41346 : tilt_swb_fec = hBWE_TD->tilt_swb_fec;
549 : }
550 :
551 : /* WB/SWB bandwidth switching */
552 1072787 : if ( ( st->tilt_wb > 5 && st->clas_dec == UNVOICED_CLAS ) || st->tilt_wb > 10 )
553 : {
554 87804 : if ( ( st->prev_fractive == 0 && st->prev_enerLH < 2.0f * st->enerLH && st->prev_enerLH > 0.5f * st->enerLH && st->prev_enerLL < 2.0f * st->enerLL && st->prev_enerLL > 0.5f * st->enerLL ) || ( st->prev_fractive == 1 && st->prev_enerLH > 3.0f * st->enerLH ) || ( st->enerLL > 1.5f * st->enerLH && st->tilt_wb < 10.0f ) )
555 : {
556 589 : is_fractive = 0;
557 : }
558 : else
559 : {
560 87215 : is_fractive = 1;
561 : }
562 : }
563 :
564 : /* WB/SWB bandwidth switching */
565 1072787 : if ( st->bws_cnt > 0 )
566 : {
567 741 : f = 1.0f / 22.0f;
568 741 : inc = 1.0f / 22.0f;
569 :
570 741 : if ( is_fractive == 1 )
571 : {
572 0 : mvr2r( lsf_tab, hBWE_TD->lsp_prevfrm, LPC_SHB_ORDER );
573 : }
574 : else
575 : {
576 8151 : for ( i = 0; i < LPC_SHB_ORDER; i++ )
577 : {
578 7410 : hBWE_TD->lsp_prevfrm[i] = f;
579 7410 : f += inc;
580 : }
581 : }
582 741 : if ( ( st->last_extl != SWB_TBE && st->last_extl != FB_TBE && !( st->prev_enerLH < 2.0f * st->enerLH && st->prev_enerLH > 0.5f * st->enerLH ) ) || st->last_core != ACELP_CORE || ( st->last_core == ACELP_CORE && labs( st->last_core_brate - st->core_brate ) > 3600 ) || ( is_fractive ^ st->prev_fractive ) == 1 )
583 : {
584 713 : set_f( GainShape, 0.3536f, NUM_SHB_SUBFR );
585 : }
586 : else
587 : {
588 28 : hBWE_TD->prev_GainShape = ( hBWE_TD->prev_GainShape > 0.3536f ) ? 0.353f : hBWE_TD->prev_GainShape;
589 28 : set_f( GainShape, hBWE_TD->prev_GainShape, NUM_SHB_SUBFR );
590 : }
591 :
592 741 : mvr2r( hBWE_TD->lsp_prevfrm, lsf_shb, LPC_SHB_ORDER );
593 741 : set_f( shb_res_gshape, 0.2f, NB_SUBFR16k );
594 : }
595 : else
596 : {
597 1072046 : if ( st->last_extl != SWB_TBE && st->last_extl != FB_TBE )
598 : {
599 77189 : f = 1.0f / 22.0f;
600 77189 : inc = 1.0f / 22.0f;
601 849079 : for ( i = 0; i < LPC_SHB_ORDER; i++ )
602 : {
603 771890 : hBWE_TD->lsp_prevfrm[i] = f;
604 771890 : f += inc;
605 : }
606 : }
607 :
608 1072046 : if ( !st->bfi )
609 : {
610 1016630 : if ( st->use_partial_copy )
611 : {
612 80 : if ( st->last_extl != SWB_TBE )
613 : {
614 8 : hBWE_TD->GainFrame_prevfrm = 0;
615 8 : f = 1.0f / 22.0f;
616 8 : inc = 1.0f / 22.0f;
617 88 : for ( i = 0; i < LPC_SHB_ORDER; i++ )
618 : {
619 80 : hBWE_TD->lsp_prevfrm[i] = f;
620 80 : f += inc;
621 : }
622 : }
623 80 : mvr2r( hBWE_TD->lsp_prevfrm, lsf_shb, LPC_SHB_ORDER );
624 80 : set_f( GainShape, RECIP_ROOT_EIGHT, NUM_SHB_SUBFR );
625 :
626 80 : if ( st->rf_frame_type == RF_NELP )
627 : {
628 : /* Frame gain */
629 0 : GainFrame = usdequant( st->rf_indx_tbeGainFr, SHB_GAIN_QLOW, SHB_GAIN_QDELTA );
630 0 : GainFrame = (float) pow( 10.0, GainFrame );
631 :
632 0 : if ( st->core == ACELP_CORE && st->last_core == ACELP_CORE && !st->prev_use_partial_copy && st->prev_coder_type == UNVOICED && GainFrame != hBWE_TD->GainFrame_prevfrm && st->next_coder_type != GENERIC && st->last_extl == SWB_TBE )
633 : {
634 0 : GainFrame = 0.2f * GainFrame + 0.8f * hBWE_TD->GainFrame_prevfrm;
635 : }
636 : }
637 : else
638 : {
639 80 : temp = 0.0f;
640 : /* Frame gain */
641 80 : switch ( st->rf_indx_tbeGainFr )
642 : {
643 0 : case 0:
644 0 : GainFrame = 0.5f;
645 0 : if ( hBWE_TD->GainFrame_prevfrm <= 1.25 )
646 : {
647 0 : temp = 0.8f;
648 : }
649 0 : break;
650 50 : case 1:
651 50 : GainFrame = 2.0f;
652 50 : if ( hBWE_TD->GainFrame_prevfrm > 1.25 && hBWE_TD->GainFrame_prevfrm <= 3 )
653 : {
654 38 : temp = 0.8f;
655 : }
656 50 : break;
657 24 : case 2:
658 24 : GainFrame = 4.0f;
659 24 : if ( hBWE_TD->GainFrame_prevfrm > 3 && hBWE_TD->GainFrame_prevfrm <= 6 )
660 : {
661 12 : temp = 0.8f;
662 : }
663 24 : break;
664 6 : case 3:
665 6 : GainFrame = 8.0f;
666 6 : if ( hBWE_TD->GainFrame_prevfrm > 6 && hBWE_TD->GainFrame_prevfrm <= 16 )
667 : {
668 0 : temp = 0.8f;
669 : }
670 6 : break;
671 0 : default:
672 0 : IVAS_ERROR( IVAS_ERR_INTERNAL, "RF SWB-TBE gain bits not supported." );
673 : }
674 :
675 80 : if ( st->last_extl == SWB_TBE )
676 : {
677 72 : GainFrame = ( 1 - temp ) * GainFrame + temp * ( hBWE_TD->GainFrame_prevfrm );
678 : }
679 :
680 80 : if ( st->core == ACELP_CORE && st->last_core == ACELP_CORE )
681 : {
682 72 : if ( !st->prev_use_partial_copy && st->last_coder_type == VOICED && st->rf_frame_type == RF_GENPRED && GainFrame > 8.0f && GainFrame < 11.67f )
683 : {
684 0 : GainFrame *= 0.3f;
685 : }
686 : }
687 : }
688 : }
689 : else
690 : {
691 : /* de-quantization */
692 1016550 : dequantizeSHBparams( st, st->extl, st->extl_brate, lsf_shb, GainShape, &GainFrame, &stemp, &shb_ener_sf, shb_res_gshape, &mixFactors, &MSFlag );
693 1016550 : if ( hStereoICBWE != NULL )
694 : {
695 104246 : hStereoICBWE->MSFlag = MSFlag;
696 : }
697 : }
698 : }
699 : else
700 : {
701 55416 : mvr2r( hBWE_TD->lsp_prevfrm, lsf_shb, LPC_SHB_ORDER );
702 :
703 55416 : if ( st->codec_mode == MODE1 && st->element_mode == EVS_MONO )
704 : {
705 : /* the previous frame gainshape gradient and the gainshape gradient pattern for the current frame */
706 2532 : for ( j = 0; j < 3; j++ )
707 : {
708 1899 : GainGrad0[j] = hBWE_TD->GainShape_Delay[j + 1] - hBWE_TD->GainShape_Delay[j];
709 1899 : GainGrad1[j] = hBWE_TD->GainShape_Delay[j + 5] - hBWE_TD->GainShape_Delay[j + 4];
710 1899 : GainGradFEC[j + 1] = GainGrad0[j] * 0.4f + GainGrad1[j] * 0.6f;
711 : }
712 :
713 : /* gradient for the first gainshape */
714 633 : if ( ( GainGrad1[2] > 2 * GainGrad1[1] && GainGrad1[1] > 2 * GainGrad1[0] ) ||
715 584 : ( GainGrad1[2] < 2 * GainGrad1[1] && GainGrad1[1] < 2 * GainGrad1[0] ) )
716 : {
717 255 : GainGradFEC[0] = GainGrad1[1] * 0.1f + GainGrad1[2] * 0.9f;
718 : }
719 : else
720 : {
721 378 : GainGradFEC[0] = GainGrad1[0] * 0.2f + GainGrad1[1] * 0.3f + GainGrad1[2] * 0.5f;
722 : }
723 :
724 : /* get the first gainshape template */
725 633 : if ( ( st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS ) && GainGradFEC[0] > 0 )
726 : {
727 32 : GainShapeTemp[0] = hBWE_TD->GainShape_Delay[7] + GainGradFEC[0];
728 : }
729 601 : else if ( GainGradFEC[0] > 0 )
730 : {
731 242 : GainShapeTemp[0] = hBWE_TD->GainShape_Delay[7] + GainGradFEC[0] * 0.5f;
732 : }
733 : else
734 : {
735 359 : GainShapeTemp[0] = hBWE_TD->GainShape_Delay[7];
736 : }
737 :
738 : /*Get the second the third and the fourth gainshape template*/
739 633 : if ( ( GainGrad1[2] > 10.0f * GainGrad1[1] ) && GainGrad1[1] > 0 )
740 : {
741 0 : for ( i = 1; i < NUM_SHB_SUBFR / 4; i++ )
742 : {
743 0 : GainShapeTemp[i] = GainShapeTemp[i - 1] + GainGradFEC[i] * 0.8f;
744 0 : GainShapeTemp[i] = max( GainShapeTemp[i], 0.01f );
745 : }
746 : }
747 633 : else if ( ( GainGrad1[2] > 10.0f * GainGrad1[1] ) && GainGrad1[1] < 0 )
748 : {
749 404 : for ( i = 1; i < NUM_SHB_SUBFR / 4; i++ )
750 : {
751 303 : GainShapeTemp[i] = GainShapeTemp[i - 1] + GainGradFEC[i] * 0.2f;
752 303 : GainShapeTemp[i] = max( GainShapeTemp[i], 0.01f );
753 : }
754 : }
755 : else
756 : {
757 2128 : for ( i = 1; i < NUM_SHB_SUBFR / 4; i++ )
758 : {
759 1596 : GainShapeTemp[i] = GainShapeTemp[i - 1] + GainGradFEC[i];
760 1596 : GainShapeTemp[i] = max( GainShapeTemp[i], 0.01f );
761 : }
762 : }
763 :
764 : /* Get the gainshape and gain frame for the current frame*/
765 633 : if ( ( st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS ) && st->nbLostCmpt == 1 )
766 : {
767 170 : for ( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
768 : {
769 680 : for ( j = 0; j < 4; j++ )
770 : {
771 544 : GainShape[i * 4 + j] = GainShapeTemp[i] * 1.2f;
772 : }
773 : }
774 34 : hBWE_TD->GainAttn *= 0.95f;
775 : }
776 599 : else if ( st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS )
777 : {
778 0 : for ( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
779 : {
780 0 : for ( j = 0; j < 4; j++ )
781 : {
782 0 : GainShape[i * 4 + j] = GainShapeTemp[i];
783 : }
784 : }
785 0 : hBWE_TD->GainAttn *= 0.95f;
786 : }
787 599 : else if ( st->nbLostCmpt > 1 )
788 : {
789 2065 : for ( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
790 : {
791 8260 : for ( j = 0; j < 4; j++ )
792 : {
793 6608 : GainShape[i * 4 + j] = GainShapeTemp[i] * 0.5f;
794 : }
795 : }
796 413 : hBWE_TD->GainAttn *= 0.5f;
797 : }
798 : else
799 : {
800 930 : for ( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
801 : {
802 3720 : for ( j = 0; j < 4; j++ )
803 : {
804 2976 : GainShape[i * 4 + j] = GainShapeTemp[i];
805 : }
806 : }
807 186 : hBWE_TD->GainAttn *= 0.85f;
808 : }
809 :
810 633 : GainFrame = hBWE_TD->GainAttn * hBWE_TD->GainFrame_prevfrm;
811 : }
812 : else
813 : {
814 273915 : for ( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
815 : {
816 1095660 : for ( j = 0; j < 4; j++ )
817 : {
818 876528 : GainShape[i * 4 + j] = st->cummulative_damping * hBWE_TD->GainShape_Delay[4 + i];
819 : }
820 : }
821 :
822 54783 : if ( tilt_swb_fec > 8 )
823 : {
824 797 : if ( st->nbLostCmpt == 1 )
825 : {
826 674 : GainFrame = (float) ( 0.6 * st->cummulative_damping * hBWE_TD->GainFrame_prevfrm );
827 : }
828 123 : else if ( st->nbLostCmpt == 2 )
829 : {
830 117 : GainFrame = (float) ( 0.35 * st->cummulative_damping * hBWE_TD->GainFrame_prevfrm );
831 : }
832 : else
833 : {
834 6 : GainFrame = (float) ( 0.2 * st->cummulative_damping * hBWE_TD->GainFrame_prevfrm );
835 : }
836 : }
837 : else
838 : {
839 53986 : GainFrame = hBWE_TD->GainFrame_prevfrm; /* gain locking */
840 : }
841 : }
842 :
843 55416 : if ( st->extl_brate >= SWB_TBE_2k8 )
844 : {
845 11962 : if ( st->codec_mode == MODE1 && st->element_mode == EVS_MONO )
846 : {
847 438 : scale = (float) ( hBWE_TD->prev1_shb_ener_sf / sqrt( ( hBWE_TD->prev2_shb_ener_sf * hBWE_TD->prev3_shb_ener_sf ) + 0.0001 ) );
848 438 : scale = hBWE_TD->prev_res_shb_gshape * min( scale, 1.0f );
849 :
850 438 : if ( hBWE_TD->prev2_shb_ener_sf > 2.0f * hBWE_TD->prev1_shb_ener_sf || hBWE_TD->prev3_shb_ener_sf > 2.0f * hBWE_TD->prev2_shb_ener_sf )
851 : {
852 164 : shb_ener_sf = 0.5f * scale * hBWE_TD->prev1_shb_ener_sf;
853 164 : if ( st->nbLostCmpt > 1 )
854 : {
855 126 : shb_ener_sf *= 0.5f;
856 : }
857 : }
858 : else
859 : {
860 274 : shb_ener_sf = scale * scale * hBWE_TD->prev1_shb_ener_sf;
861 : }
862 : }
863 : else
864 : {
865 11524 : if ( hBWE_TD->prev2_shb_ener_sf > 2.0f * hBWE_TD->prev1_shb_ener_sf || hBWE_TD->prev3_shb_ener_sf > 2.0f * hBWE_TD->prev2_shb_ener_sf )
866 : {
867 755 : shb_ener_sf = 0.5f * st->cummulative_damping * hBWE_TD->prev1_shb_ener_sf;
868 : }
869 : else
870 : {
871 10769 : shb_ener_sf = st->cummulative_damping * hBWE_TD->prev1_shb_ener_sf;
872 : }
873 : }
874 : }
875 :
876 55416 : shb_ener_sf = max( shb_ener_sf, 1.0f );
877 55416 : mixFactors = hBWE_TD->prev_mixFactors;
878 :
879 55416 : if ( st->codec_mode == MODE2 )
880 : {
881 770 : set_f( shb_res_gshape, 1.0f, NB_SUBFR16k );
882 : }
883 : else
884 : {
885 54646 : set_f( shb_res_gshape, 0.2f, NB_SUBFR16k );
886 : }
887 : }
888 : }
889 :
890 : /* get the gainshape delay */
891 1072787 : mvr2r( &hBWE_TD->GainShape_Delay[4], &hBWE_TD->GainShape_Delay[0], NUM_SHB_SUBFR / 4 );
892 5363935 : for ( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
893 : {
894 4291148 : hBWE_TD->GainShape_Delay[i + 4] = GainShape[i * 4];
895 : }
896 :
897 1072787 : mvr2r( voice_factors, vf_modified, NB_SUBFR16k );
898 1072787 : if ( st->coder_type == VOICED || mean( voice_factors, 4 ) > 0.4f )
899 : {
900 842340 : for ( i = 1; i < NB_SUBFR; i++ )
901 : {
902 631755 : vf_modified[i] = 0.8f * voice_factors[i] + 0.2f * voice_factors[i - 1];
903 : }
904 :
905 210585 : if ( st->L_frame != L_FRAME )
906 : {
907 101960 : vf_modified[4] = 0.8f * voice_factors[4] + 0.2f * voice_factors[3];
908 : }
909 : }
910 :
911 1072787 : if ( st->use_partial_copy && st->nelp_mode_dec )
912 : {
913 0 : set_f( vf_modified, 0.0f, NB_SUBFR16k );
914 : }
915 :
916 : /* SHB LSF from current frame; and convert to LSP for interpolation */
917 1072787 : lsf2lsp( lsf_shb, lsp_shb_2, LPC_SHB_ORDER, 1 );
918 :
919 1072787 : if ( st->last_extl == SWB_TBE || st->last_extl == FB_TBE )
920 : {
921 : /* SHB LSP values from prev. frame for interpolation */
922 994857 : mvr2r( hBWE_TD->swb_lsp_prev_interp, lsp_shb_1, LPC_SHB_ORDER );
923 : }
924 : else
925 : {
926 : /* Use current frame's LSPs; in effect no interpolation */
927 77930 : mvr2r( lsp_shb_2, lsp_shb_1, LPC_SHB_ORDER );
928 : }
929 :
930 1072787 : if ( st->bws_cnt == 0 && st->bws_cnt1 == 0 && st->prev_use_partial_copy == 0 && st->use_partial_copy == 0 )
931 : {
932 1070508 : lsf_diff[0] = lsf_diff[LPC_SHB_ORDER - 1] = 0.5f;
933 9634572 : for ( i = 1; i < ( LPC_SHB_ORDER - 1 ); i++ )
934 : {
935 8564064 : lsf_diff[i] = lsf_shb[i] - lsf_shb[i - 1];
936 : }
937 :
938 1070508 : a2rc( hBWE_TD->cur_sub_Aq + 1, refl, M );
939 :
940 1070508 : tilt_para = 6.6956f * ( 1.0f + refl[0] ) * ( 1.0f + refl[0] ) - 3.8714f * ( 1.0f + refl[0] ) + 1.3041f;
941 1070508 : if ( st->last_extl != SWB_TBE && st->last_extl != FB_TBE )
942 : {
943 686808 : for ( i = 1; i < LPC_SHB_ORDER - 1; i++ )
944 : {
945 610496 : hBWE_TD->prev_lsf_diff[i - 1] = 0.5f * lsf_diff[i];
946 : }
947 : }
948 :
949 1070508 : if ( st->extl_brate <= FB_TBE_1k8 )
950 : {
951 835852 : if ( !( hBWE_TD->prev_tilt_para > 5.0f && ( st->coder_type == TRANSITION || tilt_para < 1.0f ) ) && !( ( hBWE_TD->prev_tilt_para < 3.0f && st->prev_coder_type >= VOICED ) && tilt_para > 5.0f ) )
952 : {
953 7280424 : for ( i = 1; i < ( LPC_SHB_ORDER - 1 ); i++ )
954 : {
955 6471488 : if ( lsf_diff[i] < 0 || hBWE_TD->prev_lsf_diff[i - 1] <= 0 ) /* safety check in case of bit errors */
956 : {
957 0 : w[i] = 0;
958 0 : st->BER_detect = 1;
959 : }
960 : else
961 : {
962 6471488 : w[i] = ( lsf_diff[i] < hBWE_TD->prev_lsf_diff[i - 1] ) ? min( max( 0.8f * lsf_diff[i] / hBWE_TD->prev_lsf_diff[i - 1], 0.5f ), 1.0f ) : min( max( 0.8f * hBWE_TD->prev_lsf_diff[i - 1] / lsf_diff[i], 0.5f ), 1.0f );
963 : }
964 : }
965 808936 : w[0] = w[1];
966 808936 : w[LPC_SHB_ORDER - 1] = w[LPC_SHB_ORDER - 2];
967 :
968 8898296 : for ( i = 0; i < LPC_SHB_ORDER; i++ )
969 : {
970 8089360 : lsp_temp[i] = lsp_shb_1[i] * ( 1.0f - w[i] ) + lsp_shb_2[i] * w[i];
971 : }
972 : }
973 : else
974 : {
975 26916 : mvr2r( lsp_shb_2, lsp_temp, LPC_SHB_ORDER );
976 : }
977 :
978 : /* convert from lsp to lsf */
979 835852 : lsp2lsf( lsp_temp, lsf_shb, LPC_SHB_ORDER, 1 );
980 : }
981 :
982 1070508 : mvr2r( lsf_diff + 1, hBWE_TD->prev_lsf_diff, LPC_SHB_ORDER - 2 );
983 1070508 : hBWE_TD->prev_tilt_para = tilt_para;
984 : }
985 : else
986 : {
987 2279 : mvr2r( lsp_shb_2, lsp_temp, LPC_SHB_ORDER );
988 : }
989 :
990 1072787 : if ( st->extl_brate >= SWB_TBE_2k8 )
991 : {
992 : /* SHB LSP interpolation */
993 235245 : ptr_lsp_interp_coef = interpol_frac_shb;
994 1176225 : for ( j = 0; j < 4; j++ )
995 : {
996 10350780 : for ( i = 0; i < LPC_SHB_ORDER; i++ )
997 : {
998 9409800 : lsp_temp[i] = lsp_shb_1[i] * ( *ptr_lsp_interp_coef ) + lsp_shb_2[i] * ( *( ptr_lsp_interp_coef + 1 ) );
999 : }
1000 940980 : ptr_lsp_interp_coef += 2;
1001 :
1002 : /* convert from lsp to lsf */
1003 940980 : lsp2lsf( lsp_temp, lsp_temp, LPC_SHB_ORDER, 1 );
1004 :
1005 : /* convert lsf to lpc for SHB synthesis */
1006 940980 : lsp2a( lpc_shb_sf + j * ( LPC_SHB_ORDER + 1 ), lsp_temp, LPC_SHB_ORDER );
1007 940980 : lpc_shb_sf[j * ( LPC_SHB_ORDER + 1 )] = 1.0f;
1008 : }
1009 : }
1010 :
1011 : /* Save the SWB LSP values from current frame for interpolation */
1012 1072787 : mvr2r( lsp_shb_2, hBWE_TD->swb_lsp_prev_interp, LPC_SHB_ORDER );
1013 :
1014 : /* save the shb_ener and mixFactor values */
1015 1072787 : hBWE_TD->prev3_shb_ener_sf = hBWE_TD->prev2_shb_ener_sf;
1016 1072787 : hBWE_TD->prev2_shb_ener_sf = hBWE_TD->prev1_shb_ener_sf;
1017 1072787 : hBWE_TD->prev1_shb_ener_sf = shb_ener_sf;
1018 1072787 : hBWE_TD->prev_res_shb_gshape = shb_res_gshape[4];
1019 1072787 : hBWE_TD->prev_mixFactors = mixFactors;
1020 :
1021 : /* SWB CNG/DTX - update memories */
1022 1072787 : if ( st->hTdCngDec != NULL )
1023 : {
1024 855161 : mvr2r( st->hTdCngDec->lsp_shb_prev, st->hTdCngDec->lsp_shb_prev_prev, LPC_SHB_ORDER );
1025 855161 : mvr2r( lsf_shb, st->hTdCngDec->lsp_shb_prev, LPC_SHB_ORDER );
1026 : }
1027 :
1028 : /* convert LSPs back into LP coeffs */
1029 1072787 : lsp2a( lpc_shb, lsf_shb, LPC_SHB_ORDER );
1030 1072787 : lpc_shb[0] = 1.0;
1031 1072787 : if ( st->extl_brate == SWB_TBE_1k10 || st->extl_brate == SWB_TBE_1k75 )
1032 : {
1033 15483 : vind = (int16_t) ( mixFactors * ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) );
1034 : }
1035 : else
1036 : {
1037 1057304 : vind = (int16_t) ( mixFactors * ( 1 << NUM_BITS_SHB_VF ) );
1038 : }
1039 :
1040 : /* Determine formant PF strength */
1041 1072787 : formant_fac = swb_formant_fac( lpc_shb[1], &hBWE_TD->tilt_mem );
1042 1072787 : if ( st->total_brate > ACELP_32k )
1043 : {
1044 483160 : for ( j = 0; j < 4; j++ )
1045 : {
1046 386528 : mvr2r( lpc_shb, &lpc_shb_sf[j * ( LPC_SHB_ORDER + 1 )], LPC_SHB_ORDER + 1 );
1047 : }
1048 : }
1049 :
1050 : /* From low band excitation, generate highband excitation */
1051 1072787 : mvr2r( hBWE_TD->state_syn_shbexc, shaped_shb_excitation, L_SHB_LAHEAD );
1052 1072787 : GenShapedSHBExcitation( shaped_shb_excitation + L_SHB_LAHEAD, lpc_shb, White_exc16k, hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->state_lpc_syn, st->coder_type, bwe_exc_extended, hBWE_TD->bwe_seed, vf_modified, st->extl, &( hBWE_TD->tbe_demph ), &( hBWE_TD->tbe_premph ), lpc_shb_sf, &shb_ener_sf, shb_res_gshape, shb_res_dummy, &vind, formant_fac, hBWE_TD->fb_state_lpc_syn, &( hBWE_TD->fb_tbe_demph ), st->total_brate, st->prev_bfi, st->element_mode, st->flag_ACELP16k, nlExc16k, mixExc16k, st->extl_brate, MSFlag,
1053 : NULL, &( hBWE_TD->prev_pow_exc16kWhtnd ), &( hBWE_TD->prev_mix_factor ), NULL, NULL );
1054 :
1055 : /* fill-in missing SHB excitation */
1056 1072787 : if ( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && st->last_core_brate <= SID_2k40 )
1057 : {
1058 559 : mvr2r( shaped_shb_excitation + L_SHB_LAHEAD, shaped_shb_excitation, L_SHB_LAHEAD );
1059 : }
1060 :
1061 1072787 : if ( hStereoICBWE != NULL )
1062 : {
1063 107658 : mvr2r( shaped_shb_excitation + L_SHB_LAHEAD, hStereoICBWE->shbSynthRef, L_FRAME16k );
1064 : }
1065 :
1066 1072787 : if ( st->extl_brate != SWB_TBE_1k10 && st->extl_brate != SWB_TBE_1k75 )
1067 : {
1068 5286520 : for ( i = 0; i < L_FRAME16k; i += L_SUBFR16k )
1069 : {
1070 : /* TD BWE post-processing */
1071 4229216 : PostShortTerm( &shaped_shb_excitation[L_SHB_LAHEAD + i], lpc_shb, &shaped_shb_excitationTemp[i], hBWE_TD->mem_stp_swb, hBWE_TD->ptr_mem_stp_swb, &( hBWE_TD->gain_prec_swb ), hBWE_TD->mem_zero_swb, formant_fac );
1072 : }
1073 :
1074 1057304 : mvr2r( shaped_shb_excitationTemp, &shaped_shb_excitation[L_SHB_LAHEAD], L_FRAME16k );
1075 :
1076 1057304 : prev_pow = sum2_f( shaped_shb_excitation, L_SHB_LAHEAD + 10 );
1077 1057304 : curr_pow = sum2_f( shaped_shb_excitation + L_SHB_LAHEAD + 10, L_SHB_LAHEAD + 10 );
1078 :
1079 1057304 : if ( st->element_mode > EVS_MONO )
1080 : {
1081 : /* prevent too low values of energy */
1082 1036808 : prev_pow = max( 0.00001f, prev_pow );
1083 1036808 : curr_pow = max( 0.00001f, curr_pow );
1084 : }
1085 :
1086 1057304 : if ( voice_factors[0] > 0.75f )
1087 : {
1088 31532 : curr_pow *= 0.25;
1089 : }
1090 :
1091 1057304 : if ( prev_pow == 0 )
1092 : {
1093 0 : scale = 0;
1094 : }
1095 : else
1096 : {
1097 1057304 : scale = (float) sqrt( curr_pow / prev_pow );
1098 : }
1099 :
1100 22203384 : for ( i = 0; i < L_SHB_LAHEAD; i++ )
1101 : {
1102 21146080 : shaped_shb_excitation[i] *= scale;
1103 : }
1104 11630344 : for ( ; i < L_SHB_LAHEAD + 10; i++ )
1105 : {
1106 10573040 : temp = ( i - 19 ) / 10.0f;
1107 10573040 : shaped_shb_excitation[i] *= ( temp * 1.0f + ( 1.0f - temp ) * scale );
1108 : }
1109 : }
1110 : else
1111 : {
1112 : /* reset the PF memories if the PF is not running */
1113 15483 : set_f( hBWE_TD->mem_stp_swb, 0, LPC_SHB_ORDER );
1114 15483 : hBWE_TD->gain_prec_swb = 1.0f;
1115 15483 : set_f( hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER );
1116 : }
1117 :
1118 : /* Update SHB excitation */
1119 1072787 : mvr2r( shaped_shb_excitation + L_FRAME16k, hBWE_TD->state_syn_shbexc, L_SHB_LAHEAD );
1120 1072787 : l_subframe = L_FRAME16k / NUM_SHB_SUBGAINS;
1121 1072787 : ener = EPSILON;
1122 5363935 : for ( i = 0; i < NUM_SHB_SUBGAINS; i++ )
1123 : {
1124 4291148 : ener_tmp[i] = EPSILON;
1125 347582988 : for ( j = 0; j < l_subframe; j++ )
1126 : {
1127 343291840 : ener_tmp[i] += shaped_shb_excitation[i * l_subframe + j] * shaped_shb_excitation[i * l_subframe + j] * 0.0125f;
1128 : }
1129 4291148 : ener_tmp[i] = (float) sqrt( ener_tmp[i] );
1130 4291148 : ener += ener_tmp[i];
1131 : }
1132 1072787 : ener /= NUM_SHB_SUBGAINS;
1133 :
1134 : /* WB/SWB bandwidth switching */
1135 1072787 : if ( st->bws_cnt > 0 )
1136 : {
1137 741 : ener *= 0.35f;
1138 :
1139 741 : if ( st->tilt_swb > 8 )
1140 : {
1141 0 : st->prev_fractive = 1;
1142 : }
1143 :
1144 741 : if ( is_fractive == 0 )
1145 : {
1146 741 : if ( st->tilt_wb > 1.0 )
1147 : {
1148 143 : st->tilt_wb = 1.0f;
1149 : }
1150 598 : else if ( st->tilt_wb < 0.5 )
1151 : {
1152 576 : st->tilt_wb = 0.5f;
1153 : }
1154 :
1155 741 : if ( st->prev_fractive == 1 && st->tilt_wb > 0.5 )
1156 : {
1157 57 : st->tilt_wb = 0.5f;
1158 : }
1159 : }
1160 : else
1161 : {
1162 0 : if ( st->tilt_wb > 4 )
1163 : {
1164 0 : if ( st->prev_fractive == 0 )
1165 : {
1166 0 : st->tilt_wb = 4;
1167 : }
1168 : else
1169 : {
1170 0 : st->tilt_wb = 8;
1171 : }
1172 : }
1173 : else
1174 : {
1175 0 : st->tilt_wb *= 2;
1176 : }
1177 : }
1178 :
1179 741 : if ( ener != 0 )
1180 : {
1181 741 : if ( ener * st->tilt_wb > st->enerLH )
1182 : {
1183 687 : st->tilt_wb = 0.5f * st->enerLH / ener;
1184 : }
1185 54 : else if ( ener * st->tilt_wb < 0.05f * st->enerLH && is_fractive == 1 )
1186 : {
1187 0 : st->tilt_wb = 0.25f * st->enerLH / ener;
1188 : }
1189 :
1190 741 : GainFrame_prevfrm = st->prev_ener_shb / ener;
1191 : }
1192 : else
1193 : {
1194 0 : GainFrame_prevfrm = 0;
1195 : }
1196 :
1197 741 : if ( is_fractive == 1 )
1198 : {
1199 0 : GainFrame = 8.0f * st->tilt_wb;
1200 : }
1201 : else
1202 : {
1203 741 : GainFrame = 2.0f * st->tilt_wb;
1204 : }
1205 :
1206 741 : if ( ( is_fractive & st->prev_fractive ) == 1 && GainFrame > GainFrame_prevfrm )
1207 : {
1208 0 : GainFrame = 0.2f * GainFrame + 0.8f * GainFrame_prevfrm;
1209 : }
1210 : else
1211 : {
1212 741 : if ( ( st->prev_enerLH < 2.0f * st->enerLH && st->prev_enerLH > 0.5f * st->enerLH ) && ( st->prev_enerLL < 2.0f * st->enerLL && st->prev_enerLL > 0.5f * st->enerLL ) && ( is_fractive ^ st->prev_fractive ) == 0 )
1213 : {
1214 38 : GainFrame = 0.5f * GainFrame + 0.5f * GainFrame_prevfrm;
1215 : }
1216 : else
1217 : {
1218 703 : if ( is_fractive == 0 && st->prev_fractive == 1 )
1219 : {
1220 57 : GainFrame = ( 1.0f - 0.1f * GainFrame ) * GainFrame + 0.1f * GainFrame * GainFrame_prevfrm;
1221 : }
1222 : else
1223 : {
1224 646 : GainFrame = 0.5f * GainFrame + 0.5f * GainFrame_prevfrm;
1225 : }
1226 : }
1227 : }
1228 :
1229 741 : GainFrame *= ( (float) N_WS2N_FRAMES - (float) st->bws_cnt ) / (float) N_WS2N_FRAMES;
1230 : }
1231 : else
1232 : {
1233 1072046 : if ( st->bws_cnt1 > 0 )
1234 : {
1235 1418 : GainFrame *= (float) st->bws_cnt1 / (float) N_WS2N_FRAMES;
1236 : }
1237 :
1238 1072046 : if ( st->nbLostCmpt == 1 )
1239 : {
1240 23858 : prev_ener_ratio = st->prev_ener_shb / ener;
1241 :
1242 23858 : if ( st->clas_dec != UNVOICED_CLAS && st->clas_dec != UNVOICED_TRANSITION && hBWE_TD->tilt_swb_fec < 8.0 &&
1243 18283 : ( ( st->enerLL > 0.5f * st->prev_enerLL && st->enerLL < 2.0f * st->prev_enerLL ) || ( st->enerLH > 0.5f * st->prev_enerLH && st->enerLH < 2.0f * st->prev_enerLH ) ) )
1244 : {
1245 222 : if ( prev_ener_ratio > 4.0f * GainFrame )
1246 : {
1247 2 : GainFrame = 0.4f * prev_ener_ratio + 0.6f * GainFrame;
1248 : }
1249 220 : else if ( prev_ener_ratio > 2.0f * GainFrame )
1250 : {
1251 66 : GainFrame = 0.8f * prev_ener_ratio + 0.2f * GainFrame;
1252 : }
1253 : else
1254 : {
1255 154 : GainFrame = 0.2f * prev_ener_ratio + 0.8f * GainFrame;
1256 : }
1257 :
1258 222 : if ( tilt_swb_fec > hBWE_TD->tilt_swb_fec )
1259 : {
1260 0 : GainFrame *= hBWE_TD->tilt_swb_fec > 0 ? ( min( 5.0f, tilt_swb_fec / hBWE_TD->tilt_swb_fec ) ) : 1.0f;
1261 : }
1262 : }
1263 23636 : else if ( ( st->clas_dec != UNVOICED_CLAS || hBWE_TD->tilt_swb_fec > 8.0 ) && prev_ener_ratio > 4.0f * GainFrame && ( st->enerLL > 0.5f * st->prev_enerLL || st->enerLH > 0.5f * st->prev_enerLH ) )
1264 : {
1265 0 : GainFrame = 0.2f * prev_ener_ratio + 0.8f * GainFrame;
1266 : }
1267 : }
1268 1048188 : else if ( st->nbLostCmpt > 1 )
1269 : {
1270 31558 : prev_ener_ratio = st->prev_ener_shb / ener;
1271 31558 : if ( ( prev_ener_ratio > 4.0 * GainFrame ) && ( ( st->codec_mode == MODE1 && st->enerLL > st->prev_enerLL && st->enerLH > st->prev_enerLH ) || st->codec_mode == MODE2 ) )
1272 : {
1273 0 : if ( tilt_swb_fec > 10.0f && hBWE_TD->tilt_swb_fec > 10.0f )
1274 : {
1275 0 : GainFrame = min( ( prev_ener_ratio * 0.8f + GainFrame * 0.2f ), 4.0f * GainFrame );
1276 : }
1277 : else
1278 : {
1279 0 : GainFrame = min( ( prev_ener_ratio * 0.5f + GainFrame * 0.5f ), 4.0f * GainFrame );
1280 : }
1281 : }
1282 31558 : else if ( ( prev_ener_ratio > GainFrame ) && ( ( st->codec_mode == MODE1 && st->enerLL > st->prev_enerLL && st->enerLH > st->prev_enerLH ) || st->codec_mode == MODE2 ) )
1283 : {
1284 0 : if ( tilt_swb_fec > 10.0f && hBWE_TD->tilt_swb_fec > 10.0f )
1285 : {
1286 0 : GainFrame = 0.5f * prev_ener_ratio + 0.5f * GainFrame;
1287 : }
1288 : else
1289 : {
1290 0 : GainFrame = 0.2f * prev_ener_ratio + 0.8f * GainFrame;
1291 : }
1292 : }
1293 : }
1294 : }
1295 :
1296 1072787 : st->prev_fractive = is_fractive;
1297 :
1298 : /* Adjust the subframe and frame gain of the synthesized shb signal */
1299 : /* Scale the shaped excitation */
1300 1072787 : if ( st->L_frame == L_FRAME )
1301 : {
1302 597027 : pitch = 0.25f * sum_f( pitch_buf, 4 );
1303 : }
1304 : else
1305 : {
1306 475760 : pitch = 0.2f * sum_f( pitch_buf, 5 );
1307 : }
1308 :
1309 1072787 : if ( ( ( st->extl_brate >= SWB_TBE_2k8 && st->prev_coder_type == st->coder_type && st->coder_type != UNVOICED ) || ( st->extl_brate < SWB_TBE_2k8 && ( st->prev_coder_type == st->coder_type || ( st->prev_coder_type == VOICED && st->coder_type == GENERIC ) || ( st->prev_coder_type == GENERIC && st->coder_type == VOICED ) ) ) ) && pitch > 70 && st->extl < FB_TBE && st->extl_brate != SWB_TBE_1k10 && st->extl_brate != SWB_TBE_1k75 )
1310 : {
1311 2163955 : for ( i = 0; i < NUM_SHB_SUBGAINS; i++ )
1312 : {
1313 1731164 : GainShape_tmp[i] = GainShape[i * 4];
1314 : }
1315 :
1316 2163955 : for ( i = 0; i < NUM_SHB_SUBGAINS; i++ )
1317 : {
1318 1731164 : if ( ener_tmp[i] * GainShape_tmp[i] > hBWE_TD->prev_ener * hBWE_TD->prev_GainShape )
1319 : {
1320 1022183 : GainShape_tmp[i] = 0.5f * ( hBWE_TD->prev_ener * hBWE_TD->prev_GainShape / ener_tmp[i] + GainShape_tmp[i] );
1321 : }
1322 1731164 : hBWE_TD->prev_ener = ener_tmp[i];
1323 1731164 : hBWE_TD->prev_GainShape = GainShape_tmp[i];
1324 : }
1325 :
1326 7357447 : for ( i = 0; i < NUM_SHB_SUBFR; i++ )
1327 : {
1328 6924656 : GainShape[i] = GainShape_tmp[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR];
1329 : }
1330 : }
1331 :
1332 : /* Gain shape smoothing after quantization */
1333 1072787 : if ( st->extl_brate == SWB_TBE_1k10 || st->extl_brate == SWB_TBE_1k75 )
1334 : {
1335 77415 : for ( i = 0; i < NUM_SHB_SUBGAINS; i++ )
1336 : {
1337 61932 : GainShape_tmp[i] = GainShape[i * NUM_SHB_SUBGAINS];
1338 : }
1339 :
1340 15483 : lls_interp_n( GainShape_tmp, NUM_SHB_SUBGAINS, &GainShape_tilt, &temp, 1 );
1341 :
1342 15483 : if ( vind >= 6 && fabs( GainShape_tilt ) < 0.12f )
1343 : {
1344 9761 : feedback = 0.3f;
1345 48805 : for ( i = 0; i < NUM_SHB_SUBGAINS; i++ )
1346 : {
1347 39044 : GainShape[i] = ( 1 - feedback ) * GainShape[i * NUM_SHB_SUBGAINS] + feedback * GainShape_tmp[i];
1348 : }
1349 :
1350 156176 : for ( i = NUM_SHB_SUBFR - 1; i > 0; i-- )
1351 : {
1352 146415 : GainShape[i] = GainShape[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR];
1353 : }
1354 : }
1355 : }
1356 :
1357 : /* fil-in missing memory */
1358 1072787 : if ( ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT ) && st->last_core_brate <= SID_2k40 )
1359 : {
1360 11739 : for ( i = 0; i < L_SHB_LAHEAD; i++ )
1361 : {
1362 11180 : hBWE_TD->syn_overlap[i] = shaped_shb_excitation[i] * subwin_shb[L_SHB_LAHEAD - i];
1363 11180 : hBWE_TD->syn_overlap[i] *= window_shb[L_SHB_LAHEAD - 1 - i] * GainFrame;
1364 : }
1365 : }
1366 :
1367 1072787 : ScaleShapedSHB( SHB_OVERLAP_LEN, shaped_shb_excitation, hBWE_TD->syn_overlap, GainShape, GainFrame, window_shb, subwin_shb );
1368 :
1369 1072787 : if ( hStereoICBWE != NULL )
1370 : {
1371 107658 : mvr2r( lpc_shb, hStereoICBWE->lpSHBRef, LPC_SHB_ORDER + 1 );
1372 107658 : mvr2r( GainShape, hStereoICBWE->gshapeRef, NUM_SHB_SUBFR );
1373 107658 : hStereoICBWE->gFrameRef = GainFrame;
1374 :
1375 107658 : mvr2r( shaped_shb_excitation, hStereoICBWE->shbSynthRef, L_FRAME16k );
1376 : }
1377 :
1378 1072787 : curr_frame_pow = sum2_f( shaped_shb_excitation, L_FRAME16k ) + 0.001f;
1379 1072787 : curr_frame_pow = min( curr_frame_pow, FLT_MAX );
1380 :
1381 1072787 : if ( !st->bfi && ( st->prev_bfi || st->prev_use_partial_copy ) )
1382 : {
1383 25541 : if ( ( curr_frame_pow > 2.0f * hBWE_TD->prev_swb_bwe_frame_pow ) &&
1384 17257 : ( curr_frame_pow < 30.0f * hBWE_TD->prev_swb_bwe_frame_pow ) &&
1385 11049 : st->prev_coder_type == UNVOICED )
1386 : {
1387 640 : scale = (float) sqrt( hBWE_TD->prev_swb_bwe_frame_pow / curr_frame_pow );
1388 640 : if ( curr_frame_pow == 0 )
1389 : {
1390 0 : scale = 0;
1391 : }
1392 640 : temp = (float) pow( scale, 0.125f );
1393 : }
1394 : else
1395 : {
1396 24901 : scale = 1.0f;
1397 24901 : temp = 1.0f;
1398 : }
1399 :
1400 229869 : for ( j = 0; j < 8; j++ )
1401 : {
1402 204328 : GainShape[2 * j] *= scale;
1403 204328 : GainShape[2 * j + 1] *= scale;
1404 8377448 : for ( i = 0; i < L_FRAME16k / 8; i++ )
1405 : {
1406 8173120 : shaped_shb_excitation[i + j * L_FRAME16k / 8] *= scale;
1407 : }
1408 :
1409 204328 : scale /= temp;
1410 : }
1411 : }
1412 :
1413 : /* adjust the FEC frame energy */
1414 1072787 : if ( st->bfi )
1415 : {
1416 55539 : scale = 1.0f;
1417 55539 : temp = 1.0f;
1418 55539 : if ( st->nbLostCmpt == 1 )
1419 : {
1420 23963 : if ( curr_frame_pow > hBWE_TD->prev_swb_bwe_frame_pow && st->prev_coder_type != UNVOICED && st->last_good != UNVOICED_CLAS )
1421 : {
1422 1739 : scale = (float) sqrt( hBWE_TD->prev_swb_bwe_frame_pow / curr_frame_pow );
1423 1739 : if ( curr_frame_pow == 0 )
1424 : {
1425 0 : scale = 0;
1426 : }
1427 1739 : temp = (float) pow( scale, 0.125f );
1428 : }
1429 22224 : else if ( curr_frame_pow < 0.5f * hBWE_TD->prev_swb_bwe_frame_pow && st->nbLostCmpt == 1 && ( st->enerLL > 0.5 * st->prev_enerLL || st->enerLH > 0.5 * st->prev_enerLH ) && ( st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS || hBWE_TD->tilt_swb_fec > 5.0f ) )
1430 : {
1431 4 : scale = (float) sqrt( hBWE_TD->prev_swb_bwe_frame_pow / curr_frame_pow );
1432 4 : if ( curr_frame_pow == 0 )
1433 : {
1434 0 : scale = 0;
1435 : }
1436 4 : temp = (float) pow( scale, 0.125f );
1437 : }
1438 : }
1439 31576 : else if ( st->nbLostCmpt > 1 )
1440 : {
1441 31576 : if ( curr_frame_pow > hBWE_TD->prev_swb_bwe_frame_pow )
1442 : {
1443 5073 : scale = (float) sqrt( hBWE_TD->prev_swb_bwe_frame_pow / curr_frame_pow );
1444 5073 : if ( curr_frame_pow == 0 )
1445 : {
1446 0 : scale = 0;
1447 : }
1448 5073 : temp = (float) pow( scale, 0.125f );
1449 : }
1450 26503 : else if ( curr_frame_pow < 0.5f * hBWE_TD->prev_swb_bwe_frame_pow && ( st->enerLL > 0.5 * st->prev_enerLL || st->enerLH > 0.5 * st->prev_enerLH ) && ( st->prev_coder_type == UNVOICED || st->last_good == UNVOICED_CLAS || hBWE_TD->tilt_swb_fec > 5.0f ) )
1451 : {
1452 0 : scale = (float) min( 2.0f, sqrt( hBWE_TD->prev_swb_bwe_frame_pow / curr_frame_pow ) );
1453 0 : if ( curr_frame_pow == 0 )
1454 : {
1455 0 : scale = 0;
1456 : }
1457 0 : temp = (float) pow( scale, 0.125f );
1458 : }
1459 : }
1460 :
1461 499851 : for ( j = 0; j < 8; j++ )
1462 : {
1463 444312 : GainShape[2 * j] *= scale;
1464 444312 : GainShape[2 * j + 1] *= scale;
1465 18216792 : for ( i = 0; i < L_FRAME16k / 8; i++ )
1466 : {
1467 17772480 : shaped_shb_excitation[i + j * L_FRAME16k / 8] *= scale;
1468 : }
1469 :
1470 444312 : scale /= temp;
1471 : }
1472 : }
1473 :
1474 1072787 : hBWE_TD->prev_swb_bwe_frame_pow = curr_frame_pow;
1475 :
1476 1072787 : st->prev_ener_shb = EPSILON;
1477 344364627 : for ( i = 0; i < L_FRAME16k; i++ )
1478 : {
1479 343291840 : st->prev_ener_shb += shaped_shb_excitation[i] * shaped_shb_excitation[i];
1480 : }
1481 1072787 : st->prev_ener_shb = (float) sqrt( st->prev_ener_shb / L_FRAME16k );
1482 :
1483 1072787 : if ( st->hBWE_FD != NULL )
1484 : {
1485 16091805 : for ( i = 0; i < SWB_FENV; i++ )
1486 : {
1487 15019018 : st->hBWE_FD->prev_SWB_fenv[i] = (float) sqrt( curr_frame_pow / L_FRAME16k );
1488 : }
1489 : }
1490 :
1491 : /* generate 32kHz SHB synthesis from 12.8(16)kHz signal */
1492 1072787 : GenSHBSynth( shaped_shb_excitation, error, hBWE_TD->genSHBsynth_Hilbert_Mem, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, st->L_frame, &( hBWE_TD->syn_dm_phase ) );
1493 :
1494 1072787 : mvr2r( error + L_FRAME32k - L_SHB_TRANSITION_LENGTH, hBWE_TD->old_tbe_synth, L_SHB_TRANSITION_LENGTH );
1495 :
1496 : /* resample SHB synthesis (if needed) and scale down */
1497 1072787 : synth_scale = ( st->codec_mode == MODE1 ) ? 0.9f : 1.f;
1498 :
1499 1072787 : if ( st->output_Fs == 48000 )
1500 : {
1501 628698 : if ( st->extl == FB_TBE )
1502 : {
1503 87763005 : for ( i = 0; i < L_FRAME16k; i++ )
1504 : {
1505 87489600 : White_exc16k[i] *= GainFrame * GainShape[NUM_SHB_SUBFR * i / L_FRAME16k];
1506 : }
1507 : }
1508 :
1509 402995418 : for ( i = 0; i < L_FRAME32k; i++ )
1510 : {
1511 402366720 : error[i] *= synth_scale;
1512 : }
1513 :
1514 628698 : interpolate_3_over_2_allpass( error, L_FRAME32k, synth, hBWE_TD->int_3_over_2_tbemem_dec );
1515 : }
1516 444089 : else if ( st->output_Fs == 32000 )
1517 : {
1518 274296079 : for ( i = 0; i < L_FRAME32k; i++ )
1519 : {
1520 273868160 : synth[i] = synth_scale * error[i];
1521 : }
1522 : }
1523 16170 : else if ( st->output_Fs == 16000 )
1524 : {
1525 10364970 : for ( i = 0; i < L_FRAME32k; i++ )
1526 : {
1527 10348800 : error[i] *= synth_scale;
1528 : }
1529 :
1530 16170 : Decimate_allpass_steep( error, hBWE_TD->mem_resamp_HB_32k, L_FRAME32k, synth );
1531 : }
1532 :
1533 : /* Update previous frame parameters for FEC */
1534 1072787 : mvr2r( lsf_shb, hBWE_TD->lsp_prevfrm, LPC_SHB_ORDER );
1535 1072787 : if ( st->codec_mode == MODE1 )
1536 : {
1537 1062155 : hBWE_TD->GainFrame_prevfrm = GainFrame;
1538 1062155 : hBWE_TD->tilt_swb_fec = tilt_swb_fec;
1539 :
1540 1062155 : if ( !st->bfi )
1541 : {
1542 1007386 : hBWE_TD->GainAttn = 1.0f;
1543 : }
1544 : }
1545 : else
1546 : {
1547 10632 : if ( !st->bfi )
1548 : {
1549 9862 : hBWE_TD->tilt_swb_fec = tilt_swb_fec;
1550 9862 : hBWE_TD->GainFrame_prevfrm = GainFrame; /* gain locking on lost frame */
1551 9862 : hBWE_TD->GainAttn = 1.0f;
1552 : }
1553 : }
1554 1072787 : hBWE_TD->prev_ener = ener_tmp[NUM_SHB_SUBGAINS - 1];
1555 1072787 : hBWE_TD->prev_GainShape = GainShape[NUM_SHB_SUBFR - 1];
1556 :
1557 1072787 : return;
1558 : }
1559 :
1560 : /*-------------------------------------------------------------------*
1561 : * Dequant_lower_LSF()
1562 : *
1563 : * Dequantized the lower LSFs
1564 : *-------------------------------------------------------------------*/
1565 :
1566 659673 : static void Dequant_lower_LSF(
1567 : const int16_t lsf_idx[], /* i : LSF indices */
1568 : float lsf_q[] /* o : Quantized LSFs */
1569 : )
1570 : {
1571 : int16_t i;
1572 :
1573 659673 : lsf_q[0] = lsf_q_cb[0][lsf_idx[0]];
1574 3298365 : for ( i = 1; i < NUM_Q_LSF; i++ )
1575 : {
1576 2638692 : lsf_q[i] = lsf_q_cb[i][lsf_idx[i]] + lsf_q[i - 1];
1577 : }
1578 :
1579 659673 : return;
1580 : }
1581 :
1582 : /*-------------------------------------------------------------------*
1583 : * Map_higher_LSF()
1584 : *
1585 : * Map the higher LSFs from the lower LSFs
1586 : *-------------------------------------------------------------------*/
1587 :
1588 659673 : static void Map_higher_LSF(
1589 : float lsf_q[], /* i/o: Quantized lower LSFs */
1590 : const float m, /* i : Mirroring point */
1591 : const float grid_in[] /* i : Input LSF smoohthing grid */
1592 : )
1593 : {
1594 : float lsf_map[NUM_MAP_LSF];
1595 : float grid[NUM_MAP_LSF];
1596 : float last_q_lsf;
1597 : float lsf_smooth[NUM_MAP_LSF];
1598 : float offset;
1599 : int16_t i;
1600 : float scale;
1601 :
1602 3958038 : for ( i = 0; i < NUM_MAP_LSF; i++ )
1603 : {
1604 3298365 : lsf_map[i] = 2 * m - lsf_q[NUM_MAP_LSF - 1 - i];
1605 : }
1606 :
1607 659673 : if ( m > MAX_LSF / 2 )
1608 : {
1609 190585 : offset = lsf_map[0];
1610 190585 : scale = ( MAX_LSF - m ) / m;
1611 1143510 : for ( i = 0; i < NUM_MAP_LSF; i++ )
1612 : {
1613 952925 : lsf_map[i] = ( lsf_map[i] - offset ) * scale + offset;
1614 : }
1615 : }
1616 :
1617 659673 : last_q_lsf = lsf_q[NUM_Q_LSF - 1];
1618 659673 : scale = MAX_LSF - last_q_lsf;
1619 :
1620 3958038 : for ( i = 0; i < NUM_MAP_LSF; i++ )
1621 : {
1622 3298365 : grid[i] = grid_in[i] * scale + last_q_lsf;
1623 : }
1624 :
1625 3958038 : for ( i = 0; i < NUM_MAP_LSF; i++ )
1626 : {
1627 3298365 : lsf_smooth[i] = ( 1 - grid_smoothing[i] ) * lsf_map[i] + grid_smoothing[i] * grid[i];
1628 : }
1629 :
1630 3958038 : for ( i = 0; i < NUM_MAP_LSF; i++ )
1631 : {
1632 3298365 : lsf_q[NUM_Q_LSF + i] = lsf_smooth[i];
1633 : }
1634 :
1635 659673 : return;
1636 : }
1637 :
1638 : /*-------------------------------------------------------------------*
1639 : * Map_higher_LSF()
1640 : *
1641 : * Map the higher LSFs from the lower LSFs
1642 : *-------------------------------------------------------------------*/
1643 :
1644 659673 : static void Dequant_mirror_point(
1645 : const float lsf_q[], /* i/o: Quantized lower LSFs */
1646 : const int16_t m_idx, /* i : Mirror point index */
1647 : float *m /* i : Mirroring point */
1648 : )
1649 : {
1650 659673 : *m = mirror_point_q_cb[m_idx] + lsf_q[NUM_Q_LSF - 1];
1651 :
1652 659673 : return;
1653 : }
1654 :
1655 : /*-------------------------------------------------------------------*
1656 : * dequantizeSHBparams()
1657 : *
1658 : * Dequantize super highband spectral envolope, temporal gains and frame gain
1659 : *-------------------------------------------------------------------*/
1660 :
1661 1269003 : static void dequantizeSHBparams(
1662 : Decoder_State *st, /* i/o: decoder state structure */
1663 : const int16_t extl, /* i : extension layer */
1664 : int32_t extl_brate, /* i : extensiuon layer bitrate */
1665 : float *Q_lsf, /* o : SHB LSF from de-quantization */
1666 : float *Q_subgain, /* o : SHB subframe gains from de-quantization */
1667 : float *Q_framegrain, /* o : SHB frame gain from de-quantization */
1668 : int16_t *uv_flag, /* o : unvoiced flag */
1669 : float *Q_shb_ener_sf,
1670 : float *Q_shb_res_gshape,
1671 : float *Q_mixFactors,
1672 : int16_t *MSFlag )
1673 : {
1674 : int16_t i, j, idxLSF, idxSubGain, idxFrameGain;
1675 : TD_BWE_DEC_HANDLE hBWE_TD;
1676 : float Q_combined_gains[NUM_SHB_SUBFR / 4];
1677 : float lsf_q[LPC_SHB_ORDER];
1678 : int16_t lsf_idx[NUM_Q_LSF];
1679 : int16_t m_idx, grid_idx;
1680 : float m;
1681 : int16_t idx_shb_fr_gain, idx_res_gs[5], idx_mixFac;
1682 :
1683 : UWord32 Idx_lvq;
1684 : int16_t Idx, Idx_pred;
1685 : int16_t num_bits_lvq;
1686 : float out[LATTICE_DIM];
1687 : const float *cb_stage;
1688 : int16_t predictor_bits;
1689 1269003 : int16_t nbits = NUM_BITS_SHB_MSLVQ;
1690 :
1691 1269003 : hBWE_TD = st->hBWE_TD;
1692 :
1693 : /* LSFs */
1694 1269003 : if ( extl == WB_TBE )
1695 : {
1696 252453 : if ( extl_brate == WB_TBE_0k35 )
1697 : {
1698 60205 : if ( st->codec_mode == MODE2 )
1699 : {
1700 2696 : idxFrameGain = hBWE_TD->gFrame_WB;
1701 2696 : idxLSF = hBWE_TD->lsf_WB;
1702 : }
1703 : else
1704 : {
1705 57509 : idxFrameGain = get_next_indice( st, NUM_BITS_SHB_FrameGain_LBR_WB );
1706 57509 : idxLSF = get_next_indice( st, NUM_BITS_LBR_WB_LSF );
1707 : }
1708 :
1709 60205 : mvr2r( lbr_wb_bwe_lsfvq_cbook_2bit + idxLSF * LPC_SHB_ORDER_LBR_WB, Q_lsf, LPC_SHB_ORDER_LBR_WB );
1710 60205 : set_f( Q_subgain, RECIP_ROOT_EIGHT, NUM_SHB_SUBFR / 2 );
1711 60205 : mvr2r( SHBCB_FrameGain16 + idxFrameGain, Q_framegrain, 1 );
1712 : }
1713 : else
1714 : {
1715 : /* read the information about UNVOICED frame */
1716 192248 : *uv_flag = get_next_indice( st, 1 );
1717 :
1718 192248 : idxSubGain = get_next_indice( st, NUM_BITS_SHB_SUBGAINS );
1719 192248 : idxFrameGain = get_next_indice( st, NUM_BITS_SHB_FrameGain );
1720 192248 : idxLSF = get_next_indice( st, NUM_BITS_WB_LSF );
1721 :
1722 192248 : mvr2r( wb_bwe_lsfvq_cbook_8bit + idxLSF * LPC_SHB_ORDER_WB, Q_lsf, LPC_SHB_ORDER_WB );
1723 192248 : mvr2r( HBCB_SubGain5bit + idxSubGain * NUM_SHB_SUBFR / 4, Q_combined_gains, NUM_SHB_SUBFR / 4 );
1724 :
1725 961240 : for ( i = 0; i < NUM_SHB_SUBFR / 4; i++ )
1726 : {
1727 768992 : Q_combined_gains[i] = (float) pow( 10.0f, Q_combined_gains[i] / 20.0f );
1728 : }
1729 :
1730 961240 : for ( i = 0; i < NUM_SHB_SUBFR / 2; i += 2 )
1731 : {
1732 768992 : Q_subgain[i] = Q_combined_gains[i / 2];
1733 768992 : Q_subgain[i + 1] = Q_combined_gains[i / 2];
1734 : }
1735 :
1736 : /* frame gain */
1737 192248 : mvr2r( SHBCB_FrameGain64 + idxFrameGain, Q_framegrain, 1 );
1738 : }
1739 : }
1740 : else
1741 : {
1742 1016550 : if ( st->codec_mode == MODE2 )
1743 : {
1744 9782 : idxSubGain = hBWE_TD->idxSubGains;
1745 9782 : idxFrameGain = hBWE_TD->idxFrameGain;
1746 : }
1747 : else
1748 : {
1749 1006768 : idxSubGain = get_next_indice( st, NUM_BITS_SHB_SUBGAINS );
1750 1006768 : if ( st->extl_brate == SWB_TBE_1k75 )
1751 : {
1752 11712 : idxFrameGain = get_next_indice( st, NUM_BITS_SHB_FRAMEGAIN_1k75 );
1753 : }
1754 : else
1755 : {
1756 995056 : idxFrameGain = get_next_indice( st, NUM_BITS_SHB_FRAMEGAIN );
1757 : }
1758 : }
1759 :
1760 : /* Multi Source Flag */
1761 1016550 : if ( st->element_mode >= IVAS_CPE_DFT && !( st->element_mode == IVAS_CPE_TD && st->tdm_LRTD_flag ) )
1762 : {
1763 201517 : *MSFlag = get_next_indice( st, STEREO_ICBWE_MSFLAG_BITS );
1764 : }
1765 : else
1766 : {
1767 815033 : *MSFlag = 0;
1768 : }
1769 :
1770 1016550 : if ( st->extl_brate >= SWB_TBE_2k8 )
1771 : {
1772 223283 : if ( st->codec_mode == MODE2 )
1773 : {
1774 5602 : idx_shb_fr_gain = hBWE_TD->idx_shb_fr_gain;
1775 : }
1776 : else
1777 : {
1778 217681 : idx_shb_fr_gain = get_next_indice( st, NUM_BITS_SHB_ENER_SF );
1779 : }
1780 223283 : *Q_shb_ener_sf = usdequant( idx_shb_fr_gain, 0, 0.042f );
1781 223283 : *Q_shb_ener_sf = (float) pow( 10.0, *Q_shb_ener_sf );
1782 :
1783 1339698 : for ( i = 0; i < 5; i++ )
1784 : {
1785 1116415 : if ( st->codec_mode == MODE2 )
1786 : {
1787 28010 : idx_res_gs[i] = hBWE_TD->idx_res_gs[i];
1788 : }
1789 : else
1790 : {
1791 1088405 : idx_res_gs[i] = get_next_indice( st, NUM_BITS_SHB_RES_GS );
1792 : }
1793 1116415 : Q_shb_res_gshape[i] = usdequant( idx_res_gs[i], 0.125f, 0.125f );
1794 : }
1795 :
1796 223283 : if ( st->codec_mode == MODE2 )
1797 : {
1798 5602 : idx_mixFac = hBWE_TD->idx_mixFac;
1799 : }
1800 : else
1801 : {
1802 217681 : idx_mixFac = get_next_indice( st, NUM_BITS_SHB_VF );
1803 : }
1804 223283 : *Q_mixFactors = usdequant( idx_mixFac, 0.125f, 0.125f );
1805 : }
1806 : else
1807 : {
1808 793267 : *Q_shb_ener_sf = 0;
1809 793267 : if ( st->extl_brate == SWB_TBE_1k10 || st->extl_brate == SWB_TBE_1k75 )
1810 : {
1811 14322 : idx_mixFac = get_next_indice( st, NUM_BITS_SHB_VF );
1812 14322 : *Q_mixFactors = usdequant( idx_mixFac, 0.0f, 1.0f / ( ( 1 << NUM_BITS_SHB_VF ) - 1 ) );
1813 : }
1814 : else
1815 : {
1816 778945 : *Q_mixFactors = 0;
1817 : }
1818 793267 : set_f( Q_shb_res_gshape, 0, 5 );
1819 : }
1820 :
1821 1016550 : if ( ( st->extl_brate == SWB_TBE_0k95 || st->extl_brate == SWB_TBE_1k10 ) && st->codec_mode == MODE1 )
1822 : {
1823 342951 : set_s( lsf_idx, 0, 5 );
1824 342951 : lsf_idx[0] = get_next_indice( st, 8 );
1825 342951 : grid_idx = 0;
1826 342951 : m_idx = 0;
1827 :
1828 342951 : mvr2r( swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER );
1829 : }
1830 673599 : else if ( st->rf_flag == 0 && !( ( st->element_mode == EVS_MONO && st->total_brate == ACELP_9k60 ) || ( st->element_mode == EVS_MONO && ( st->total_brate == 0 ) && ( ( st->last_total_brate == ACELP_9k60 ) || ( st->last_total_brate == ACELP_13k20 && st->rf_flag_last ) ) ) ) )
1831 : {
1832 : /* LSFs */
1833 671385 : if ( st->extl_brate == SWB_TBE_1k75 )
1834 : {
1835 : /* read multi-stage LVQ quantizer */
1836 11712 : if ( nbits >= 19 )
1837 : {
1838 11712 : cb_stage = cb_LSF_BWE[0];
1839 : }
1840 : else
1841 : {
1842 0 : cb_stage = cb_LSF_BWE[1];
1843 : }
1844 :
1845 11712 : set_zero( lsf_q, LPC_SHB_ORDER );
1846 :
1847 : /* VQ part */
1848 11712 : num_bits_lvq = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3];
1849 11712 : Idx = get_next_indice( st, num_bits_lvq );
1850 11712 : v_add( lsf_q, cb_stage + Idx * 6, lsf_q, 6 );
1851 :
1852 : /* MSLVQ part */
1853 11712 : num_bits_lvq = nbits - num_bits_lvq - config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2];
1854 11712 : predictor_bits = config_LSF_BWE[( NUM_BITS_SHB_MSLVQ - nbits ) * 3 + 2];
1855 11712 : Idx_pred = 0;
1856 :
1857 11712 : if ( num_bits_lvq == 16 )
1858 : {
1859 : /* MSLVQ part */
1860 0 : Idx_lvq = get_next_indice( st, num_bits_lvq - 1 ) + ( ( get_next_indice( st, 1 ) ) << 15 );
1861 0 : deindex_lvq_SHB( Idx_lvq, out, num_bits_lvq, 0 );
1862 : }
1863 : else
1864 : {
1865 : /* MSLVQ part */
1866 11712 : Idx_lvq = get_next_indice( st, num_bits_lvq );
1867 11712 : deindex_lvq_SHB( Idx_lvq, out, num_bits_lvq, ( nbits < 19 ) );
1868 : }
1869 :
1870 : /* mvr2r( mean_lsf, Q_lsfs, LPC_SHB_ORDER ); */
1871 11712 : v_add( lsf_q, out, lsf_q, LATTICE_DIM ); /* quantized mean removed data for first 8 dim*/
1872 :
1873 : /* predict last 2 components */
1874 11712 : if ( predictor_bits == 0 )
1875 : {
1876 0 : lsf_q[LATTICE_DIM] = dotp( lsf_q, LastCoefPred_0bit, LATTICE_DIM );
1877 0 : lsf_q[LATTICE_DIM + 1] = dotp( lsf_q, &LastCoefPred_0bit[LATTICE_DIM + 1], LATTICE_DIM );
1878 : }
1879 : else
1880 : {
1881 11712 : Idx_pred = get_next_indice( st, 1 );
1882 :
1883 11712 : lsf_q[LATTICE_DIM] = dotp( lsf_q, &LastCoefPred_1bit[2 * ( LATTICE_DIM + 1 ) * Idx_pred], LATTICE_DIM );
1884 11712 : lsf_q[LATTICE_DIM + 1] = dotp( lsf_q, &LastCoefPred_1bit[2 * ( LATTICE_DIM + 1 ) * Idx_pred + LATTICE_DIM + 1], LATTICE_DIM );
1885 : }
1886 :
1887 11712 : if ( nbits < NUM_BITS_SHB_MSLVQ )
1888 : {
1889 0 : Idx_pred = get_next_indice( st, NUM_BITS_SHB_MSLVQ - nbits );
1890 : }
1891 :
1892 11712 : v_add( SHB_LSF_mean, lsf_q, lsf_q, LPC_SHB_ORDER );
1893 11712 : v_sort( lsf_q, 0, LPC_SHB_ORDER - 1 );
1894 : }
1895 : else
1896 : {
1897 659673 : if ( extl_brate == SWB_TBE_1k6 || extl_brate == FB_TBE_1k8 || extl_brate == SWB_TBE_2k8 || extl_brate == FB_TBE_3k0 )
1898 : {
1899 3958038 : for ( i = 0; i < NUM_Q_LSF; i++ )
1900 : {
1901 3298365 : if ( st->codec_mode == MODE2 )
1902 : {
1903 37840 : lsf_idx[i] = hBWE_TD->lsf_idx[i];
1904 : }
1905 : else
1906 : {
1907 3260525 : lsf_idx[i] = get_next_indice( st, lsf_q_num_bits[i] );
1908 : }
1909 : }
1910 : }
1911 :
1912 659673 : Dequant_lower_LSF( lsf_idx, lsf_q );
1913 :
1914 659673 : if ( st->codec_mode == MODE2 )
1915 : {
1916 7568 : m_idx = hBWE_TD->m_idx;
1917 7568 : grid_idx = hBWE_TD->grid_idx;
1918 : }
1919 : else
1920 : {
1921 652105 : m_idx = get_next_indice( st, MIRROR_POINT_BITS );
1922 652105 : grid_idx = get_next_indice( st, NUM_LSF_GRID_BITS );
1923 : }
1924 :
1925 659673 : Dequant_mirror_point( lsf_q, m_idx, &m );
1926 :
1927 : /* safety check in case of bit errors */
1928 659673 : if ( m > MAX_LSF )
1929 : {
1930 0 : st->BER_detect = 1;
1931 0 : m = MAX_LSF;
1932 : }
1933 :
1934 659673 : Map_higher_LSF( lsf_q, m, lsf_grid[grid_idx] );
1935 : }
1936 7385235 : for ( i = 0; i < LPC_SHB_ORDER; i++ )
1937 : {
1938 : /* safety check in case of bit errors */
1939 6713850 : if ( lsf_q[LPC_SHB_ORDER - 1 - i] > MAX_LSF )
1940 : {
1941 0 : st->BER_detect = 1;
1942 0 : lsf_q[LPC_SHB_ORDER - 1 - i] = MAX_LSF;
1943 : }
1944 6713850 : Q_lsf[i] = 0.5f - lsf_q[LPC_SHB_ORDER - 1 - i];
1945 : }
1946 : }
1947 : else
1948 : {
1949 2214 : set_s( lsf_idx, 0, 5 );
1950 2214 : mvs2s( hBWE_TD->lsf_idx, lsf_idx, 5 );
1951 2214 : grid_idx = 0;
1952 2214 : m_idx = 0;
1953 2214 : mvr2r( swb_tbe_lsfvq_cbook_8b + lsf_idx[0] * LPC_SHB_ORDER, Q_lsf, LPC_SHB_ORDER );
1954 : }
1955 :
1956 1016550 : space_lsfs( Q_lsf, LPC_SHB_ORDER );
1957 :
1958 : /* Dequantize subgain indices */
1959 1016550 : j = idxSubGain * NUM_SHB_SUBGAINS;
1960 :
1961 5082750 : for ( i = 0; i < NUM_SHB_SUBGAINS; i++ )
1962 : {
1963 4066200 : Q_subgain[i] = (float) pow( 10.0, SHBCB_SubGain5bit[j++] );
1964 : }
1965 :
1966 17281350 : for ( i = NUM_SHB_SUBFR - 1; i >= 0; i-- )
1967 : {
1968 16264800 : Q_subgain[i] = Q_subgain[i * NUM_SHB_SUBGAINS / NUM_SHB_SUBFR];
1969 : }
1970 :
1971 : /* Frame gain */
1972 1016550 : if ( st->extl_brate == SWB_TBE_1k75 )
1973 : {
1974 11712 : *Q_framegrain = usdequant( idxFrameGain, SHB_GAIN_QLOW_1k75, SHB_GAIN_QDELTA_1k75 );
1975 : }
1976 : else
1977 : {
1978 1004838 : *Q_framegrain = usdequant( idxFrameGain, SHB_GAIN_QLOW, SHB_GAIN_QDELTA );
1979 : }
1980 :
1981 1016550 : *Q_framegrain = (float) pow( 10.0, *Q_framegrain );
1982 : }
1983 :
1984 1269003 : return;
1985 : }
1986 :
1987 :
1988 : /*-------------------------------------------------------------------*
1989 : * fb_tbe_dec()
1990 : *
1991 : * FB TBE decoder, 14(resp. 15.5) - 20 kHz band decoding module
1992 : *-------------------------------------------------------------------*/
1993 :
1994 292113 : void fb_tbe_dec(
1995 : Decoder_State *st, /* i/o: decoder state structure */
1996 : const float fb_exc[], /* i : FB excitation from the SWB part */
1997 : float *hb_synth, /* o : high-band synthesis */
1998 : float *fb_synth_ref, /* o : high-band synthesis 16-20 kHz */
1999 : const int16_t output_frame /* i : output frame length */
2000 : )
2001 : {
2002 : int16_t i;
2003 : TD_BWE_DEC_HANDLE hBWE_TD;
2004 292113 : float ratio = 0, fb_exc_energy = 0;
2005 : float fb_synth[L_FRAME48k];
2006 :
2007 292113 : hBWE_TD = st->hBWE_TD;
2008 :
2009 292113 : if ( output_frame == L_FRAME48k )
2010 : {
2011 : /* decode FB slope information */
2012 273405 : if ( st->extl == FB_TBE && !st->bfi )
2013 : {
2014 266277 : if ( st->codec_mode == MODE2 )
2015 : {
2016 1908 : i = hBWE_TD->idxGain;
2017 : }
2018 : else
2019 : {
2020 264369 : i = get_next_indice( st, NUM_BITS_FB_FRAMEGAIN_TBE );
2021 : }
2022 266277 : ratio = (float) ( 1 << i );
2023 : }
2024 7128 : else if ( st->extl == FB_TBE && st->bfi )
2025 : {
2026 7128 : ratio = hBWE_TD->prev_fbbwe_ratio;
2027 : }
2028 : }
2029 : else
2030 : {
2031 : /* update the position in the bitstream - needed in IVAS */
2032 18708 : if ( !st->bfi )
2033 : {
2034 18093 : st->next_bit_pos += NUM_BITS_FB_FRAMEGAIN;
2035 : }
2036 :
2037 18708 : return;
2038 : }
2039 :
2040 273405 : fb_exc_energy = sum2_f( fb_exc, L_FRAME16k );
2041 :
2042 : /* FB TBE synthesis */
2043 273405 : synthesise_fb_high_band( fb_exc, fb_synth, fb_exc_energy, ratio, st->L_frame, st->bfi, &( hBWE_TD->prev_fbbwe_ratio ), hBWE_TD->fbbwe_hpf_mem );
2044 :
2045 273405 : if ( st->element_mode >= IVAS_CPE_DFT && st->idchan == 0 )
2046 : {
2047 30694 : mvr2r( fb_synth, fb_synth_ref, L_FRAME48k );
2048 : }
2049 :
2050 : /* add the fb_synth component to the hb_synth component */
2051 273405 : v_add( hb_synth, fb_synth, hb_synth, L_FRAME48k );
2052 :
2053 273405 : return;
2054 : }
2055 :
2056 :
2057 : /*---------------------------------------------------------------------*
2058 : * tbe_read_bitstream()
2059 : *
2060 : * Read TBE bitstream and populate the parameters for TD-BWE decoder.
2061 : *---------------------------------------------------------------------*/
2062 :
2063 15537 : void tbe_read_bitstream(
2064 : Decoder_State *st /* i/o: decoder state structure */
2065 : )
2066 : {
2067 : int16_t i;
2068 : TD_BWE_DEC_HANDLE hBWE_TD;
2069 :
2070 15537 : hBWE_TD = st->hBWE_TD;
2071 :
2072 15537 : if ( ( st->rf_flag || st->total_brate == ACELP_9k60 ) && st->bwidth == WB )
2073 : {
2074 : /* WB LSF */
2075 2788 : hBWE_TD->lsf_WB = get_next_indice( st, NUM_BITS_LBR_WB_LSF );
2076 :
2077 : /* WB frame gain */
2078 2788 : hBWE_TD->gFrame_WB = get_next_indice( st, NUM_BITS_SHB_FrameGain_LBR_WB );
2079 : }
2080 12749 : else if ( st->total_brate >= ACELP_9k60 && st->total_brate <= ACELP_32k && ( st->bwidth == SWB || st->bwidth == FB ) )
2081 : {
2082 9862 : if ( st->rf_flag == 0 && st->total_brate > ACELP_9k60 )
2083 : {
2084 45408 : for ( i = 0; i < NUM_Q_LSF; i++ )
2085 : {
2086 37840 : hBWE_TD->lsf_idx[i] = get_next_indice( st, lsf_q_num_bits[i] );
2087 : }
2088 7568 : hBWE_TD->m_idx = get_next_indice( st, MIRROR_POINT_BITS );
2089 7568 : hBWE_TD->grid_idx = get_next_indice( st, NUM_LSF_GRID_BITS );
2090 : }
2091 : else
2092 : {
2093 2294 : hBWE_TD->lsf_idx[0] = get_next_indice( st, 8 );
2094 2294 : hBWE_TD->m_idx = 0;
2095 2294 : hBWE_TD->grid_idx = 0;
2096 : }
2097 :
2098 : /* shape gains */
2099 9862 : hBWE_TD->idxSubGains = get_next_indice( st, NUM_BITS_SHB_SUBGAINS );
2100 :
2101 : /* frame gain */
2102 9862 : hBWE_TD->idxFrameGain = get_next_indice( st, NUM_BITS_SHB_FRAMEGAIN );
2103 :
2104 9862 : if ( st->total_brate >= ACELP_24k40 )
2105 : {
2106 : /* sub frame energy*/
2107 5602 : hBWE_TD->idx_shb_fr_gain = get_next_indice( st, NUM_BITS_SHB_ENER_SF );
2108 :
2109 : /* gain shapes residual */
2110 33612 : for ( i = 0; i < NB_SUBFR16k; i++ )
2111 : {
2112 28010 : hBWE_TD->idx_res_gs[i] = get_next_indice( st, NUM_BITS_SHB_RES_GS );
2113 : }
2114 :
2115 : /* voicing factor */
2116 5602 : hBWE_TD->idx_mixFac = get_next_indice( st, NUM_BITS_SHB_VF );
2117 : }
2118 :
2119 9862 : if ( st->tec_tfa == 1 )
2120 : {
2121 5660 : st->tec_flag = get_next_indice( st, BITS_TEC );
2122 5660 : st->tfa_flag = get_next_indice( st, BITS_TFA );
2123 :
2124 5660 : if ( st->tfa_flag && st->tec_flag )
2125 : {
2126 100 : st->tec_flag = 2;
2127 100 : st->tfa_flag = 0;
2128 : }
2129 : }
2130 : else
2131 : {
2132 4202 : st->tec_flag = 0;
2133 4202 : st->tfa_flag = 0;
2134 : }
2135 : }
2136 :
2137 15537 : if ( st->bwidth == FB )
2138 : {
2139 1908 : hBWE_TD->idxGain = get_next_indice( st, 4 );
2140 : }
2141 :
2142 15537 : return;
2143 : }
2144 :
2145 :
2146 : /*---------------------------------------------------------------------*
2147 : * GenTransition()
2148 : *
2149 : * Generate a highband transition signal from the gain shape overlap
2150 : * buffer to fill the gap caused by the delay alignment buffer when
2151 : * switching from TBE to IGF
2152 : *---------------------------------------------------------------------*/
2153 :
2154 81762 : void GenTransition(
2155 : TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
2156 : float *outputHB, /* o : synthesized HB transitions signal */
2157 : const int32_t output_Fs, /* i : output sampling rate */
2158 : const int16_t element_mode, /* i : element mode */
2159 : const int16_t L_frame, /* i : ACELP frame length */
2160 : const int16_t rf_flag, /* i : RF flag */
2161 : const int32_t total_brate /* i : total bitrate */
2162 : )
2163 : {
2164 : int16_t i, length;
2165 : float syn_overlap_32k[2 * SHB_OVERLAP_LEN];
2166 :
2167 : /* set targeted length of transition signal */
2168 81762 : length = 2 * NS2SA( output_Fs, DELAY_BWE_TOTAL_NS );
2169 :
2170 : /* upsample overlap snippet */
2171 81762 : Interpolate_allpass_steep( hBWE_TD->syn_overlap, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, SHB_OVERLAP_LEN, syn_overlap_32k );
2172 :
2173 : /* perform spectral flip and downmix with overlap snippet to match HB synth */
2174 81762 : if ( ( element_mode == EVS_MONO && ( rf_flag || total_brate == ACELP_9k60 ) ) || ( element_mode > EVS_MONO && L_frame == L_FRAME ) )
2175 : {
2176 28518 : flip_and_downmix_generic( syn_overlap_32k, syn_overlap_32k, 2 * SHB_OVERLAP_LEN, hBWE_TD->genSHBsynth_Hilbert_Mem, hBWE_TD->genSHBsynth_Hilbert_Mem + HILBERT_ORDER1, hBWE_TD->genSHBsynth_Hilbert_Mem + ( HILBERT_ORDER1 + 2 * HILBERT_ORDER2 ), &( hBWE_TD->syn_dm_phase ) );
2177 : }
2178 : else
2179 : {
2180 2183004 : for ( i = 0; i < 2 * SHB_OVERLAP_LEN; i++ )
2181 : {
2182 2129760 : syn_overlap_32k[i] = ( ( i % 2 ) == 0 ) ? ( -syn_overlap_32k[i] ) : ( syn_overlap_32k[i] );
2183 : }
2184 : }
2185 :
2186 : /* cross fade of overlap snippet and mirrored HB synth from previous frame */
2187 3352242 : for ( i = 0; i < 2 * L_SHB_LAHEAD; i++ )
2188 : {
2189 3270480 : outputHB[i] = window_shb_32k[i] * hBWE_TD->old_tbe_synth[L_SHB_TRANSITION_LENGTH - 1 - i] + window_shb_32k[2 * L_SHB_LAHEAD - 1 - i] * syn_overlap_32k[i];
2190 : }
2191 :
2192 : /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */
2193 12592744 : for ( ; i < length; i++ )
2194 : {
2195 12510982 : outputHB[i] = hBWE_TD->old_tbe_synth[L_SHB_TRANSITION_LENGTH - 1 - i];
2196 : }
2197 :
2198 81762 : if ( output_Fs == 48000 )
2199 : {
2200 50465 : interpolate_3_over_2_allpass( outputHB, length, outputHB, hBWE_TD->int_3_over_2_tbemem_dec );
2201 : }
2202 31297 : else if ( output_Fs == 16000 )
2203 : {
2204 726 : Decimate_allpass_steep( outputHB, hBWE_TD->mem_resamp_HB_32k, L_FRAME32k, outputHB );
2205 : }
2206 :
2207 81762 : return;
2208 : }
2209 :
2210 : /*---------------------------------------------------------------------*
2211 : * GenTransition_WB()
2212 : *
2213 : *
2214 : *---------------------------------------------------------------------*/
2215 :
2216 10506 : void GenTransition_WB(
2217 : TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
2218 : float *outputHB, /* o : synthesized HB transitions signal */
2219 : const int32_t output_Fs /* i : output sampling rate */
2220 : )
2221 : {
2222 : int16_t i, length;
2223 : float speech_buf_16k1[SHB_OVERLAP_LEN], speech_buf_16k2[2 * SHB_OVERLAP_LEN];
2224 : float upsampled_synth[L_FRAME48k];
2225 :
2226 : /* set targeted length of transition signal */
2227 10506 : length = 2 * NS2SA( output_Fs, DELAY_BWE_TOTAL_NS );
2228 :
2229 : /* upsample overlap snippet */
2230 10506 : Interpolate_allpass_steep( hBWE_TD->syn_overlap, hBWE_TD->state_lsyn_filt_shb, SHB_OVERLAP_LEN / 2, speech_buf_16k1 );
2231 10506 : Interpolate_allpass_steep( speech_buf_16k1, hBWE_TD->state_lsyn_filt_dwn_shb, SHB_OVERLAP_LEN, speech_buf_16k2 );
2232 :
2233 : /* perform spectral flip and downmix with overlap snippet to match HB synth */
2234 220626 : for ( i = 0; i < SHB_OVERLAP_LEN; i++ )
2235 : {
2236 210120 : speech_buf_16k2[i] = ( ( i % 2 ) == 0 ) ? ( -speech_buf_16k2[i] ) : ( speech_buf_16k2[i] );
2237 : }
2238 :
2239 : /* cross fade of overlap snippet and mirrored HB synth from previous frame */
2240 220626 : for ( i = 0; i < L_SHB_LAHEAD; i++ )
2241 : {
2242 210120 : outputHB[i] = window_shb[i] * hBWE_TD->old_tbe_synth[L_SHB_TRANSITION_LENGTH - 1 - i] + window_shb[L_SHB_LAHEAD - 1 - i] * speech_buf_16k2[i];
2243 210120 : outputHB[i] *= 0.65f;
2244 : }
2245 :
2246 : /* fill transition signal with mirrored HB synth from previous frame to fully fill delay alignment buffer gap */
2247 604174 : for ( ; i < length; i++ )
2248 : {
2249 593668 : outputHB[i] = hBWE_TD->old_tbe_synth[L_SHB_TRANSITION_LENGTH - 1 - i];
2250 593668 : outputHB[i] *= 0.65f;
2251 : }
2252 :
2253 : /* upsampling if necessary */
2254 10506 : if ( output_Fs == 32000 )
2255 : {
2256 24 : Interpolate_allpass_steep( outputHB, hBWE_TD->mem_resamp_HB, L_FRAME16k, upsampled_synth );
2257 24 : mvr2r( upsampled_synth, outputHB, L_FRAME32k );
2258 : }
2259 10482 : else if ( output_Fs == 48000 )
2260 : {
2261 166 : interpolate_3_over_1_allpass( outputHB, L_FRAME16k, upsampled_synth, hBWE_TD->mem_resamp_HB );
2262 166 : mvr2r( upsampled_synth, outputHB, L_FRAME48k );
2263 : }
2264 :
2265 10506 : return;
2266 : }
2267 :
2268 :
2269 : /*---------------------------------------------------------------------*
2270 : * void TBEreset_dec()
2271 : *
2272 : *
2273 : *---------------------------------------------------------------------*/
2274 :
2275 4012140 : void TBEreset_dec(
2276 : Decoder_State *st /* i/o: decoder state structure */
2277 : )
2278 : {
2279 : TD_BWE_DEC_HANDLE hBWE_TD;
2280 :
2281 4012140 : hBWE_TD = st->hBWE_TD;
2282 :
2283 4012140 : if ( st->last_core != ACELP_CORE )
2284 : {
2285 3994319 : set_f( hBWE_TD->old_bwe_exc, 0.0f, PIT16k_MAX * 2 );
2286 3994319 : hBWE_TD->bwe_non_lin_prev_scale = 0.f;
2287 : }
2288 4012140 : if ( st->bwidth == WB )
2289 : {
2290 926702 : wb_tbe_extras_reset( hBWE_TD->mem_genSHBexc_filt_down_wb2, hBWE_TD->mem_genSHBexc_filt_down_wb3 );
2291 926702 : wb_tbe_extras_reset_synth( hBWE_TD->state_lsyn_filt_shb, hBWE_TD->state_lsyn_filt_dwn_shb, hBWE_TD->mem_resamp_HB );
2292 926702 : set_f( hBWE_TD->mem_genSHBexc_filt_down_shb, 0, 7 );
2293 926702 : set_f( hBWE_TD->state_lpc_syn, 0, 10 );
2294 926702 : set_f( hBWE_TD->state_syn_shbexc, 0, L_SHB_LAHEAD / 4 );
2295 926702 : set_f( hBWE_TD->syn_overlap, 0, L_SHB_LAHEAD );
2296 926702 : set_f( hBWE_TD->mem_csfilt, 0, 2 );
2297 : }
2298 3085438 : else if ( st->bwidth == SWB || st->bwidth == FB )
2299 : {
2300 3085438 : swb_tbe_reset( hBWE_TD->mem_csfilt, hBWE_TD->mem_genSHBexc_filt_down_shb, hBWE_TD->state_lpc_syn, hBWE_TD->syn_overlap, hBWE_TD->state_syn_shbexc, &( hBWE_TD->tbe_demph ), &( hBWE_TD->tbe_premph ), hBWE_TD->mem_stp_swb, &( hBWE_TD->gain_prec_swb ) );
2301 :
2302 3085438 : set_f( hBWE_TD->GainShape_Delay, 0, NUM_SHB_SUBFR / 2 );
2303 3085438 : set_f( hBWE_TD->int_3_over_2_tbemem_dec, 0.f, INTERP_3_2_MEM_LEN );
2304 3085438 : set_f( hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 );
2305 3085438 : hBWE_TD->prev_pow_exc16kWhtnd = 1.0f;
2306 3085438 : hBWE_TD->prev_mix_factor = 1.0f;
2307 :
2308 3085438 : swb_tbe_reset_synth( hBWE_TD->genSHBsynth_Hilbert_Mem, hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local );
2309 :
2310 3085438 : if ( st->bwidth == FB )
2311 : {
2312 1634903 : if ( st->hBWE_FD != NULL )
2313 : {
2314 1634903 : st->hBWE_FD->prev_fb_ener_adjust = 0.0f;
2315 : }
2316 1634903 : set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER );
2317 1634903 : hBWE_TD->fb_tbe_demph = 0;
2318 1634903 : fb_tbe_reset_synth( hBWE_TD->fbbwe_hpf_mem, &hBWE_TD->prev_fbbwe_ratio );
2319 : }
2320 : }
2321 :
2322 4012140 : return;
2323 : }
2324 :
2325 : /*-------------------------------------------------------------------*
2326 : * td_bwe_dec_init()
2327 : *
2328 : * Initialize TD BWE state structure at the decoder
2329 : *-------------------------------------------------------------------*/
2330 :
2331 119503 : void td_bwe_dec_init(
2332 : TD_BWE_DEC_HANDLE hBWE_TD, /* i/o: TD BWE data handle */
2333 : const int16_t extl, /* i : BWE extension layer */
2334 : const int32_t output_Fs /* i : output sampling rate */
2335 : )
2336 : {
2337 : int16_t i;
2338 :
2339 : /* init. SHB buffers */;
2340 119503 : set_f( hBWE_TD->old_bwe_exc, 0.0f, ( PIT16k_MAX * 2 ) );
2341 119503 : hBWE_TD->bwe_seed[0] = 23; /* 1; */
2342 119503 : hBWE_TD->bwe_seed[1] = 59; /* 10000; */
2343 119503 : set_f( hBWE_TD->old_bwe_exc_extended, 0.0f, NL_BUFF_OFFSET );
2344 119503 : hBWE_TD->bwe_non_lin_prev_scale = 0;
2345 :
2346 119503 : set_f( hBWE_TD->genSHBsynth_Hilbert_Mem, 0.0f, HILBERT_MEM_SIZE );
2347 119503 : set_f( hBWE_TD->genSHBsynth_state_lsyn_filt_shb_local, 0.0f, 2 * ALLPASSSECTIONS_STEEP );
2348 :
2349 119503 : hBWE_TD->syn_dm_phase = 0;
2350 119503 : hBWE_TD->prev_fbbwe_ratio = 1.0f;
2351 119503 : hBWE_TD->prev_wb_bwe_frame_pow = 0.001f;
2352 119503 : hBWE_TD->prev_swb_bwe_frame_pow = 0.001f;
2353 :
2354 : /* reset SHB buffers */
2355 119503 : ResetSHBbuffer_Dec( hBWE_TD, extl );
2356 :
2357 119503 : if ( output_Fs == 48000 )
2358 : {
2359 52585 : set_f( hBWE_TD->fbbwe_hpf_mem[0], 0, 4 );
2360 52585 : set_f( hBWE_TD->fbbwe_hpf_mem[1], 0, 4 );
2361 52585 : set_f( hBWE_TD->fbbwe_hpf_mem[2], 0, 4 );
2362 52585 : set_f( hBWE_TD->fbbwe_hpf_mem[3], 0, 4 );
2363 : }
2364 :
2365 119503 : set_f( hBWE_TD->mem_resamp_HB, 0, INTERP_3_1_MEM_LEN );
2366 119503 : set_f( hBWE_TD->mem_resamp_HB_32k, 0, 2 * ALLPASSSECTIONS_STEEP + 1 );
2367 :
2368 119503 : hBWE_TD->tilt_mem = 0.0f;
2369 119503 : set_f( hBWE_TD->prev_lsf_diff, 0.5f, LPC_SHB_ORDER - 2 );
2370 119503 : hBWE_TD->prev_tilt_para = 0.0f;
2371 119503 : set_f( hBWE_TD->cur_sub_Aq, 0.0f, M + 1 );
2372 119503 : set_f( hBWE_TD->int_3_over_2_tbemem_dec, 0.0f, INTERP_3_2_MEM_LEN );
2373 :
2374 : /* TD BWE post-processing */
2375 119503 : hBWE_TD->ptr_mem_stp_swb = hBWE_TD->mem_stp_swb + LPC_SHB_ORDER - 1;
2376 119503 : set_f( hBWE_TD->mem_zero_swb, 0, LPC_SHB_ORDER );
2377 :
2378 1314533 : for ( i = 0; i < LPC_SHB_ORDER; i++ )
2379 : {
2380 1195030 : hBWE_TD->swb_lsp_prev_interp[i] = (float) cos( (float) i * EVS_PI / (float) 10.0f );
2381 : }
2382 :
2383 119503 : hBWE_TD->prev1_shb_ener_sf = 1.0f;
2384 119503 : hBWE_TD->prev2_shb_ener_sf = 1.0f;
2385 119503 : hBWE_TD->prev3_shb_ener_sf = 1.0f;
2386 119503 : hBWE_TD->prev_res_shb_gshape = 0.125f;
2387 119503 : hBWE_TD->prev_mixFactors = 0.5f;
2388 119503 : hBWE_TD->prev_GainShape = 0.0f;
2389 119503 : set_f( hBWE_TD->fb_state_lpc_syn, 0, LPC_SHB_ORDER );
2390 119503 : hBWE_TD->fb_tbe_demph = 0.0f;
2391 :
2392 119503 : set_f( hBWE_TD->old_hb_synth, 0, L_FRAME48k );
2393 :
2394 119503 : hBWE_TD->GainFrame_prevfrm = 0.0f;
2395 :
2396 119503 : hBWE_TD->prev_ener = 0.0f;
2397 :
2398 119503 : return;
2399 : }
|