Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 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 "ivas_cnst.h"
38 : #include "ivas_rom_com.h"
39 : #include <assert.h>
40 : #include <stdint.h>
41 : #include "options.h"
42 : #ifdef DEBUGGING
43 : #include "debug.h"
44 : #endif
45 : #include <math.h>
46 : #include "prot.h"
47 : #include "ivas_prot.h"
48 : #include "rom_com.h"
49 : #include "wmc_auto.h"
50 : #include "ivas_prot.h"
51 : #include "ivas_rom_dec.h"
52 :
53 : /*-------------------------------------------------------------------
54 : * Local constants
55 : *-------------------------------------------------------------------*/
56 :
57 : #define DELTA_MASKING_NOISE 1e-20f
58 : #define CNA_ACT_DN_LARGE_PARTITION 50 /* index of the first larger partition */
59 : #define ST_PERIODOG_FACT 0.9 /* short-term filter factor for periodogram */
60 : #define CNA_ACT_DN_FACT 0.7 /* downward updating factor for CNA during active frames */
61 : #define FIRST_CNA_NOISE_UPD_FRAMES 5 /* minimum number of CN initialization frames */
62 :
63 :
64 : /*-------------------------------------------------------------------
65 : * Local fucntions declarations
66 : *-------------------------------------------------------------------*/
67 :
68 : static void perform_noise_estimation_dec( const float *timeDomainInput, float *power_spectrum, HANDLE_FD_CNG_DEC hFdCngDec, const int16_t element_mode, const int16_t bwidth, const int16_t L_frame, const int16_t last_L_frame, const int32_t last_core_brate, const int16_t VAD );
69 :
70 :
71 : /*-------------------------------------------------------------------
72 : * createFdCngDec()
73 : *
74 : * Create an instance of type FD_CNG
75 : *-------------------------------------------------------------------*/
76 :
77 18029 : ivas_error createFdCngDec(
78 : HANDLE_FD_CNG_DEC *hFdCngDec )
79 : {
80 : HANDLE_FD_CNG_DEC hs;
81 : ivas_error error;
82 18029 : error = IVAS_ERR_OK;
83 :
84 : /* Set output to NULL in case of errors and early return */
85 18029 : *hFdCngDec = NULL;
86 :
87 : /* Allocate memory */
88 18029 : if ( ( hs = (HANDLE_FD_CNG_DEC) malloc( sizeof( FD_CNG_DEC ) ) ) == NULL )
89 : {
90 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for FD CNG DEC structure" );
91 : }
92 :
93 18029 : if ( ( error = createFdCngCom( &( hs->hFdCngCom ) ) ) != IVAS_ERR_OK )
94 : {
95 0 : return error;
96 : }
97 :
98 18029 : *hFdCngDec = hs;
99 :
100 18029 : return error;
101 : }
102 :
103 :
104 : /*-------------------------------------------------------------------
105 : * initFdCngDec()
106 : *
107 : * Initialize an instance of type FD_CNG
108 : *-------------------------------------------------------------------*/
109 :
110 18029 : void initFdCngDec(
111 : DEC_CORE_HANDLE st /* i/o: decoder state structure */
112 : )
113 : {
114 : HANDLE_FD_CNG_DEC hFdCngDec;
115 :
116 18029 : hFdCngDec = st->hFdCngDec;
117 :
118 : /* Initialize common */
119 18029 : initFdCngCom( hFdCngDec->hFdCngCom, st->cldfbSyn->scale );
120 :
121 : /* Set some counters and flags */
122 18029 : hFdCngDec->flag_dtx_mode = 0;
123 18029 : hFdCngDec->lp_noise = -20.f;
124 18029 : hFdCngDec->lp_speech = 25.f;
125 :
126 : /* Initialize noise estimation algorithm */
127 18029 : set_f( hFdCngDec->bandNoiseShape, 0.0f, FFTLEN2 );
128 18029 : set_f( hFdCngDec->partNoiseShape, 0.0f, NPART );
129 18029 : set_f( hFdCngDec->msPeriodog, 0.0f, NPART_SHAPING );
130 18029 : set_f( hFdCngDec->msAlpha, 0.0f, NPART_SHAPING );
131 18029 : set_f( hFdCngDec->msBminWin, 0.0f, NPART_SHAPING );
132 18029 : set_f( hFdCngDec->msBminSubWin, 0.0f, NPART_SHAPING );
133 18029 : set_f( hFdCngDec->msPsd, 0.0f, NPART_SHAPING );
134 18029 : set_f( hFdCngDec->msNoiseFloor, 0.0f, NPART_SHAPING );
135 18029 : set_f( hFdCngDec->msNoiseEst, 0.0f, NPART_SHAPING );
136 18029 : set_f( hFdCngDec->msMinBuf, FLT_MAX, MSNUMSUBFR * NPART_SHAPING );
137 18029 : set_f( hFdCngDec->msCurrentMin, FLT_MAX, NPART_SHAPING );
138 18029 : set_f( hFdCngDec->msCurrentMinOut, FLT_MAX, NPART_SHAPING );
139 18029 : set_f( hFdCngDec->msCurrentMinSubWindow, FLT_MAX, NPART_SHAPING );
140 18029 : set_s( hFdCngDec->msLocalMinFlag, 0, NPART_SHAPING );
141 18029 : set_s( hFdCngDec->msNewMinFlag, 0, NPART_SHAPING );
142 18029 : set_f( hFdCngDec->msPsdFirstMoment, 0.0f, NPART_SHAPING );
143 18029 : set_f( hFdCngDec->msPsdSecondMoment, 0.0f, NPART_SHAPING );
144 18029 : hFdCngDec->msPeriodogBufPtr = 0;
145 18029 : set_f( hFdCngDec->msPeriodogBuf, 0.0f, MSBUFLEN * NPART_SHAPING );
146 18029 : set_f( hFdCngDec->msLogPeriodog, 0.0f, NPART_SHAPING );
147 18029 : set_f( hFdCngDec->msLogNoiseEst, 0.0f, NPART_SHAPING );
148 18029 : set_f( hFdCngDec->psize_shaping, 0.0f, NPART_SHAPING );
149 18029 : hFdCngDec->nFFTpart_shaping = 0;
150 :
151 18029 : set_f( hFdCngDec->hFdCngCom->sidNoiseEstLp, 0.0f, NPART );
152 :
153 18029 : set_f( hFdCngDec->smoothed_psd, 0.0f, L_FRAME16k );
154 18029 : set_f( hFdCngDec->msPeriodog_ST, 0.0f, NPART_SHAPING );
155 :
156 18029 : hFdCngDec->ms_last_inactive_bwidth = NB;
157 18029 : hFdCngDec->ms_cnt_bw_up = 0;
158 :
159 18029 : hFdCngDec->cna_LR_LT = 0.5f;
160 18029 : hFdCngDec->cna_ILD_LT = 0.0f;
161 18029 : hFdCngDec->first_cna_noise_updated = 0;
162 18029 : hFdCngDec->first_cna_noise_update_cnt = 0;
163 18029 : hFdCngDec->cna_nbands = CNA_INIT_NBANDS;
164 18029 : mvs2s( cna_init_bands, hFdCngDec->cna_band_limits, CNA_INIT_NBANDS + 1 );
165 18029 : hFdCngDec->cna_act_fact = 1.0f;
166 18029 : hFdCngDec->cna_rescale_fact = 0.0f;
167 18029 : hFdCngDec->cna_seed = 5687;
168 18029 : set_zero( hFdCngDec->cna_cm, STEREO_DFT_BAND_MAX );
169 18029 : set_zero( hFdCngDec->cna_g_state, STEREO_DFT_BAND_MAX );
170 :
171 18029 : st->CNG_mode = -1;
172 18029 : mvr2r( st->lsp_old, st->lspCNG, M );
173 :
174 18029 : return;
175 : }
176 :
177 :
178 : /*-------------------------------------------------------------------
179 : * configureFdCngDec()
180 : *
181 : * Configure an instance of type FD_CNG
182 : *-------------------------------------------------------------------*/
183 :
184 1193613 : void configureFdCngDec(
185 : HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: Contains the variables related to the FD-based CNG process */
186 : const int16_t bwidth,
187 : const int32_t total_brate,
188 : const int16_t L_frame,
189 : const int16_t last_L_frame,
190 : const int16_t element_mode )
191 : {
192 : int16_t j, stopBandFR;
193 1193613 : HANDLE_FD_CNG_COM hsCom = hFdCngDec->hFdCngCom;
194 :
195 1193613 : hsCom->CngBandwidth = bwidth;
196 1193613 : if ( hsCom->CngBandwidth == FB )
197 : {
198 1001350 : hsCom->CngBandwidth = SWB;
199 : }
200 1193613 : if ( total_brate != FRAME_NO_DATA && total_brate != SID_2k40 )
201 : {
202 1193332 : hsCom->CngBitrate = total_brate;
203 : }
204 281 : else if ( hsCom->CngBitrate == -1 )
205 : {
206 : /* set minimum active CBR bitrate if CngBitrate is uninitialized */
207 0 : if ( element_mode > EVS_MONO )
208 : {
209 0 : hsCom->CngBitrate = IVAS_13k2;
210 : }
211 : else
212 : {
213 0 : hsCom->CngBitrate = ACELP_7k20;
214 : }
215 : }
216 :
217 : /* FD-CNG config for MDCT-Stereo is always the same (since for > 48 kbps only) */
218 : /* This may need adjustment in the future if 2TC DTX for some mode uses MDCT-Stereo DTX for lower bitrates too */
219 1193613 : if ( element_mode == IVAS_CPE_MDCT )
220 : {
221 1013805 : hsCom->CngBitrate = IVAS_48k;
222 : }
223 1193613 : hsCom->numSlots = 16;
224 :
225 : /* NB configuration */
226 1193613 : if ( bwidth == NB )
227 : {
228 0 : hsCom->FdCngSetup = FdCngSetup_nb;
229 0 : hsCom->numCoreBands = 16;
230 0 : hsCom->regularStopBand = 16;
231 : }
232 :
233 : /* WB configuration */
234 1193613 : else if ( bwidth == WB )
235 : {
236 : /* FFT 6.4kHz, no CLDFB */
237 3141 : if ( hsCom->CngBitrate <= ACELP_8k00 && L_frame == L_FRAME )
238 : {
239 466 : hsCom->FdCngSetup = FdCngSetup_wb1;
240 466 : hsCom->numCoreBands = 16;
241 466 : hsCom->regularStopBand = 16;
242 : }
243 : /* FFT 6.4kHz, CLDFB 8.0kHz */
244 2675 : else if ( hsCom->CngBitrate <= ACELP_13k20 || L_frame == L_FRAME )
245 : {
246 875 : hsCom->FdCngSetup = FdCngSetup_wb2;
247 875 : hsCom->numCoreBands = 16;
248 875 : hsCom->regularStopBand = 20;
249 875 : if ( L_frame == L_FRAME16k )
250 : {
251 8 : hsCom->FdCngSetup = FdCngSetup_wb2;
252 8 : hsCom->numCoreBands = 20;
253 8 : hsCom->regularStopBand = 20;
254 8 : hsCom->FdCngSetup.fftlen = 640;
255 8 : hsCom->FdCngSetup.stopFFTbin = 256;
256 : }
257 : }
258 : /* FFT 8.0kHz, no CLDFB */
259 : else
260 : {
261 1800 : hsCom->FdCngSetup = FdCngSetup_wb3;
262 1800 : hsCom->numCoreBands = 20;
263 1800 : hsCom->regularStopBand = 20;
264 : }
265 : }
266 :
267 : /* SWB/FB configuration */
268 : else
269 : {
270 : /* FFT 6.4kHz, CLDFB 14kHz */
271 1190472 : if ( L_frame == L_FRAME )
272 : {
273 9112 : hsCom->FdCngSetup = FdCngSetup_swb1;
274 9112 : hsCom->numCoreBands = 16;
275 9112 : hsCom->regularStopBand = 35;
276 : }
277 : /* FFT 8.0kHz, CLDFB 16kHz */
278 : else
279 : {
280 1181360 : hsCom->FdCngSetup = FdCngSetup_swb2;
281 1181360 : hsCom->numCoreBands = 20;
282 1181360 : hsCom->regularStopBand = 40;
283 1181360 : if ( last_L_frame == L_FRAME && element_mode == IVAS_CPE_DFT )
284 : {
285 587 : hsCom->regularStopBand = 35;
286 : }
287 : }
288 : }
289 :
290 :
291 1193613 : hsCom->fftlen = hsCom->FdCngSetup.fftlen;
292 1193613 : hsCom->stopFFTbin = hsCom->FdCngSetup.stopFFTbin;
293 :
294 : /* Configure the SID quantizer and the Comfort Noise Generator */
295 :
296 1193613 : hsCom->startBand = 2;
297 1193613 : hsCom->stopBand = hsCom->FdCngSetup.sidPartitions[hsCom->FdCngSetup.numPartitions - 1] + 1;
298 1193613 : initPartitions( hsCom->FdCngSetup.sidPartitions, hsCom->FdCngSetup.numPartitions, hsCom->startBand, hsCom->stopBand, hsCom->part, &hsCom->npart, hsCom->midband, hsCom->psize, hsCom->psize_inv, 0 );
299 1193613 : if ( hsCom->stopFFTbin == 160 )
300 : {
301 0 : hsCom->nFFTpart = 17;
302 : }
303 1193613 : else if ( hsCom->stopFFTbin == 256 )
304 : {
305 10453 : hsCom->nFFTpart = 20;
306 : }
307 : else
308 : {
309 1183160 : hsCom->nFFTpart = 21;
310 : }
311 1193613 : hsCom->nCLDFBpart = hsCom->npart - hsCom->nFFTpart;
312 4775016 : for ( j = 0; j < hsCom->nCLDFBpart; j++ )
313 : {
314 3581403 : hsCom->CLDFBpart[j] = hsCom->part[j + hsCom->nFFTpart] - ( hsCom->stopFFTbin - hsCom->startBand );
315 3581403 : hsCom->CLDFBpsize_inv[j] = hsCom->psize_inv[j + hsCom->nFFTpart];
316 : }
317 :
318 1193613 : stopBandFR = (int16_t) floor( 1000.f /*Hz*/ / 25.f /*Hz/Bin*/ );
319 1193613 : if ( stopBandFR > hsCom->stopFFTbin )
320 : {
321 0 : stopBandFR = hsCom->stopFFTbin;
322 : }
323 1193613 : initPartitions( hsCom->FdCngSetup.shapingPartitions, hsCom->FdCngSetup.numShapingPartitions, hsCom->startBand, hsCom->stopFFTbin, hFdCngDec->part_shaping, &hFdCngDec->npart_shaping, hFdCngDec->midband_shaping, hFdCngDec->psize_shaping, hFdCngDec->psize_inv_shaping, stopBandFR );
324 :
325 1193613 : hFdCngDec->nFFTpart_shaping = hFdCngDec->npart_shaping;
326 :
327 1193613 : switch ( hsCom->fftlen )
328 : {
329 10445 : case 512:
330 10445 : hsCom->fftSineTab = NULL;
331 10445 : hsCom->olapWinAna = olapWinAna512;
332 10445 : hsCom->olapWinSyn = olapWinSyn256;
333 10445 : break;
334 1183168 : case 640:
335 1183168 : hsCom->fftSineTab = fftSineTab640;
336 1183168 : hsCom->olapWinAna = olapWinAna640;
337 1183168 : hsCom->olapWinSyn = olapWinSyn320;
338 1183168 : break;
339 0 : default:
340 0 : assert( !"Unsupported FFT length for FD-based CNG" );
341 : break;
342 : }
343 1193613 : hsCom->frameSize = hsCom->fftlen >> 1;
344 :
345 1193613 : return;
346 : }
347 :
348 :
349 : /*-------------------------------------------------------------------
350 : * deleteFdCngDec()
351 : *
352 : * Delete the instance of type FD_CNG
353 : *-------------------------------------------------------------------*/
354 :
355 539005 : void deleteFdCngDec(
356 : HANDLE_FD_CNG_DEC *hFdCngDec )
357 : {
358 539005 : HANDLE_FD_CNG_DEC hsDec = *hFdCngDec;
359 :
360 539005 : if ( hsDec != NULL )
361 : {
362 18029 : deleteFdCngCom( &( hsDec->hFdCngCom ) );
363 18029 : free( hsDec );
364 18029 : *hFdCngDec = NULL;
365 : }
366 :
367 539005 : return;
368 : }
369 :
370 :
371 : /*-------------------------------------------------------------------
372 : * ApplyFdCng()
373 : *
374 : * Apply the CLDFB-based CNG at the decoder
375 : *-------------------------------------------------------------------*/
376 :
377 419851 : void ApplyFdCng(
378 : float *timeDomainInput,
379 : float *powerSpectrum,
380 : float **realBuffer, /* i/o: Real part of the buffer */
381 : float **imagBuffer, /* i/o: Imaginary part of the buffer */
382 : Decoder_State *st,
383 : const int16_t concealWholeFrame,
384 : const int16_t is_music )
385 : {
386 419851 : HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec;
387 419851 : HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom;
388 419851 : float *cngNoiseLevel = hFdCngCom->cngNoiseLevel;
389 419851 : float *sidNoiseEst = hFdCngCom->sidNoiseEst;
390 : int16_t j, k;
391 : float factor;
392 : float lsp_cng[M];
393 : int16_t L_frame, last_L_frame;
394 : int32_t sr_core;
395 :
396 419851 : push_wmops( "ApplyFdCng" );
397 :
398 : /* limit L_frame and core Fs values for MDCT-Stereo modes which can have higher core sampling than 16kHz, but use a downsampled buffer */
399 419851 : L_frame = min( st->L_frame, L_FRAME16k );
400 419851 : last_L_frame = min( st->last_L_frame, L_FRAME16k );
401 419851 : sr_core = min( st->sr_core, INT_FS_16k );
402 :
403 419851 : if ( hFdCngCom->frame_type_previous == ACTIVE_FRAME )
404 : {
405 404064 : hFdCngCom->inactive_frame_counter = 0;
406 : }
407 :
408 419851 : if ( st->element_mode == IVAS_CPE_TD )
409 : {
410 4254 : hFdCngDec->flag_dtx_mode = hFdCngDec->flag_dtx_mode || st->first_CNG;
411 : }
412 :
413 419851 : switch ( st->m_frame_type )
414 : {
415 :
416 405427 : case ACTIVE_FRAME:
417 : /**************************
418 : * ACTIVE_FRAME at DECODER *
419 : **************************/
420 :
421 405427 : hFdCngCom->inactive_frame_counter = 0;
422 405427 : hFdCngCom->sid_frame_counter = 0;
423 : /* set noise estimation inactive during concealment, as no update with noise generated by concealment should be performed. */
424 : /* set noise estimation inactive when we have bit errors, as no update with noise generated by corrupt frame (biterror) should be performed. */
425 405427 : if ( concealWholeFrame == 0 &&
426 386253 : ( timeDomainInput == NULL ||
427 386253 : ( *timeDomainInput<FLT_MAX && * timeDomainInput>( -FLT_MAX ) &&
428 386253 : *( timeDomainInput + hFdCngCom->frameSize - 1 ) < FLT_MAX &&
429 386253 : *( timeDomainInput + hFdCngCom->frameSize - 1 ) > ( -FLT_MAX ) ) ) &&
430 391723 : ( ( ( ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT && hFdCngDec->flag_dtx_mode ) || !st->VAD || ( st->ini_frame < 100 && st->is_ism_format ) ) &&
431 92800 : !( st->cng_type == LP_CNG && hFdCngDec->flag_dtx_mode ) && ( is_music == 0 ) ) ||
432 300787 : ( st->element_mode == IVAS_CPE_TD ) ) &&
433 95087 : ( !st->BER_detect ) )
434 : {
435 : /* Perform noise estimation at the decoder */
436 95087 : perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD );
437 :
438 95087 : if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT )
439 : {
440 : /* Update the shaping parameters */
441 88296 : scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape, 1 );
442 : }
443 :
444 : /* Update CNG levels */
445 95087 : if ( hFdCngDec->flag_dtx_mode && st->cng_type == FD_CNG )
446 : {
447 4239 : bandcombinepow( hFdCngDec->bandNoiseShape, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv, hFdCngDec->partNoiseShape ); /* This needs to be done only once per inactive phase */
448 :
449 4239 : j = 0;
450 91357 : for ( k = 0; k < hFdCngCom->nFFTpart; k++ )
451 : {
452 87118 : factor = ( hFdCngCom->sidNoiseEst[k] + DELTA ) / ( hFdCngDec->partNoiseShape[k] + DELTA );
453 1313456 : for ( ; j <= hFdCngCom->part[k]; j++ )
454 : {
455 1226338 : cngNoiseLevel[j] = hFdCngDec->bandNoiseShape[j] * factor;
456 : }
457 : }
458 : }
459 : else
460 : {
461 : /* This sets the new CNG levels until a SID update overwrites it */
462 90848 : if ( !( st->element_mode == IVAS_CPE_TD ) || ( st->element_mode == IVAS_CPE_TD && !hFdCngDec->flag_dtx_mode && !st->VAD ) )
463 : {
464 88251 : mvr2r( hFdCngDec->bandNoiseShape, cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */
465 : }
466 : }
467 :
468 95087 : if ( st->element_mode == IVAS_CPE_MDCT && timeDomainInput == NULL )
469 : {
470 5470 : st->hTcxDec->CngLevelBackgroundTrace_bfi = sqrtf( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / NORM_MDCT_FACTOR );
471 : }
472 : else
473 : {
474 89617 : st->hTcxDec->CngLevelBackgroundTrace_bfi = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame );
475 : }
476 95087 : st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / st->L_frame );
477 : }
478 310340 : else if ( st->element_mode == IVAS_CPE_TD || st->element_mode == IVAS_CPE_DFT )
479 : {
480 95367 : if ( hFdCngCom->active_frame_counter > 0 )
481 : {
482 : /* Perform noise estimation in active frames in the decoder for downward updates */
483 94813 : perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD );
484 : }
485 : }
486 :
487 405427 : if ( ( concealWholeFrame == 1 ) && ( st->nbLostCmpt == 1 ) )
488 : {
489 : /* update lsf cng estimate for concealment. Do that during concealment, in order to avoid addition clean channel complexity*/
490 :
491 : /* always set psychParameters for MDCT-Stereo ... */
492 9684 : if ( st->element_mode == IVAS_CPE_MDCT && st->hTonalMDCTConc != NULL )
493 : {
494 6410 : st->hTonalMDCTConc->psychParams = ( st->core == TCX_20_CORE ) ? &st->hTonalMDCTConc->psychParamsTCX20 : &st->hTonalMDCTConc->psychParamsTCX10;
495 : }
496 :
497 : /* ... but do actual computations only if sufficient energy in noise shape */
498 9684 : if ( sum_f( cngNoiseLevel + hFdCngCom->startBand, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) > 0.01f )
499 : {
500 3807 : if ( st->element_mode == IVAS_CPE_MDCT && st->core != ACELP_CORE )
501 : {
502 1007 : TonalMdctConceal_whiten_noise_shape( st, L_frame, ON_FIRST_LOST_FRAME );
503 : }
504 2800 : else if ( st->element_mode != IVAS_CPE_MDCT || st->core == ACELP_CORE )
505 : {
506 2800 : lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, 0.f );
507 2800 : a2lsp_stab( hFdCngCom->A_cng, lsp_cng, st->lspold_cng );
508 2800 : mvr2r( lsp_cng, st->lspold_cng, M );
509 2800 : lsp2lsf( lsp_cng, st->lsf_cng, M, sr_core );
510 : }
511 3807 : st->plcBackgroundNoiseUpdated = 1;
512 : }
513 : }
514 405427 : break;
515 :
516 1910 : case SID_FRAME:
517 1910 : hFdCngDec->flag_dtx_mode = 1;
518 : /* FALLTHRU */
519 :
520 14424 : case ZERO_FRAME:
521 :
522 14424 : if ( st != NULL && st->cng_type == LP_CNG )
523 : {
524 : /* Perform noise estimation on inactive phase at the decoder */
525 1150 : perform_noise_estimation_dec( timeDomainInput, powerSpectrum, hFdCngDec, st->element_mode, st->bwidth, L_frame, last_L_frame, st->last_core_brate, st->VAD );
526 :
527 1150 : if ( st->element_mode != IVAS_CPE_TD && st->element_mode != IVAS_CPE_DFT )
528 : {
529 : /* Update the shaping parameters */
530 0 : scalebands( hFdCngDec->msNoiseEst, hFdCngDec->part_shaping, hFdCngDec->nFFTpart_shaping, hFdCngDec->midband_shaping, hFdCngDec->nFFTpart_shaping, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngDec->bandNoiseShape, 1 );
531 : }
532 :
533 : /* This sets the new CNG levels until a SID update overwrites it */
534 1150 : mvr2r( hFdCngDec->bandNoiseShape, cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ); /* This sets the new CNG levels until a SID update overwrites it */
535 :
536 1150 : st->cngTDLevel = (float) sqrt( ( sum_f( cngNoiseLevel, hFdCngCom->stopFFTbin - hFdCngCom->startBand ) / 2 * hFdCngCom->fftlen ) / L_frame );
537 1150 : break;
538 : }
539 :
540 13274 : hFdCngCom->inactive_frame_counter++;
541 :
542 : /*************************************
543 : * SID_FRAME or ZERO_FRAME at DECODER *
544 : *************************************/
545 :
546 : /* Detect first non-active frame */
547 13274 : if ( hFdCngCom->inactive_frame_counter == 1 )
548 : {
549 : /* Compute the fine spectral structure of the comfort noise shape using the decoder-side noise estimates */
550 356 : bandcombinepow( hFdCngDec->bandNoiseShape, hFdCngCom->stopFFTbin - hFdCngCom->startBand, hFdCngCom->part, hFdCngCom->nFFTpart, hFdCngCom->psize_inv, hFdCngDec->partNoiseShape );
551 :
552 356 : if ( st->element_mode == IVAS_CPE_DFT )
553 : {
554 284 : mvr2r( st->hFdCngDec->hFdCngCom->sidNoiseEst, st->hFdCngDec->hFdCngCom->sidNoiseEstLp, NPART );
555 : }
556 : }
557 :
558 13274 : if ( st->m_frame_type == SID_FRAME )
559 : {
560 1695 : if ( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh )
561 : {
562 : /* At initialization, interpolate the bin/band-wise levels from the partition levels */
563 31 : scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel, 1 );
564 : }
565 : else
566 : {
567 1664 : if ( st->element_mode == IVAS_CPE_DFT )
568 : {
569 1451 : sidNoiseEst = hFdCngCom->sidNoiseEstLp;
570 : }
571 :
572 : /* Interpolate the CLDFB band levels from the SID (partition) levels */
573 1664 : if ( hFdCngCom->regularStopBand > hFdCngCom->numCoreBands )
574 : {
575 1436 : scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, cngNoiseLevel, 0 );
576 : }
577 :
578 :
579 : /* Shape the SID noise levels in each FFT bin */
580 1664 : j = 0;
581 35942 : for ( k = 0; k < hFdCngCom->nFFTpart; k++ )
582 : {
583 34278 : factor = ( sidNoiseEst[k] + DELTA ) / ( hFdCngDec->partNoiseShape[k] + DELTA );
584 520806 : for ( ; j <= hFdCngCom->part[k]; j++ )
585 : {
586 486528 : cngNoiseLevel[j] = hFdCngDec->bandNoiseShape[j] * factor;
587 : }
588 : }
589 : }
590 : }
591 11579 : else if ( st->element_mode == IVAS_CPE_DFT )
592 : {
593 10110 : if ( !( hFdCngCom->msFrCnt_init_counter < hFdCngCom->msFrCnt_init_thresh ) )
594 : {
595 10110 : sidNoiseEst = hFdCngCom->sidNoiseEstLp;
596 10110 : j = 0;
597 218395 : for ( k = 0; k < hFdCngCom->nFFTpart; k++ )
598 : {
599 208285 : factor = ( sidNoiseEst[k] + DELTA ) / ( hFdCngDec->partNoiseShape[k] + DELTA );
600 3165665 : for ( ; j <= hFdCngCom->part[k]; j++ )
601 : {
602 2957380 : cngNoiseLevel[j] = hFdCngDec->bandNoiseShape[j] * factor;
603 : }
604 : }
605 : }
606 : }
607 13274 : if ( st->codec_mode == MODE2 )
608 : {
609 : /* Generate comfort noise during SID or zero frames */
610 0 : generate_comfort_noise_dec( realBuffer, imagBuffer, st, -1 );
611 : }
612 :
613 13274 : break;
614 :
615 0 : default:
616 0 : break;
617 : }
618 :
619 419851 : pop_wmops();
620 :
621 419851 : return;
622 : }
623 :
624 :
625 : /*-------------------------------------------------------------------
626 : * perform_noise_estimation_dec()
627 : *
628 : * Perform noise estimation at the decoder
629 : *-------------------------------------------------------------------*/
630 :
631 191050 : static void perform_noise_estimation_dec(
632 : const float *timeDomainInput,
633 : float *power_spectrum,
634 : HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure containing all buffers and variables */
635 : const int16_t element_mode, /* i : element mode */
636 : const int16_t bwidth, /* i : audio bandwidth */
637 : const int16_t L_frame, /* i : frame length at internal Fs */
638 : const int16_t last_L_frame, /* i : frame length of the last frame at internal Fs */
639 : const int32_t last_core_brate, /* i : previous frame core bitrate */
640 : const int16_t VAD /* i : VAD flag in the decoder */
641 : )
642 : {
643 : float *ptr_r;
644 : float *ptr_i;
645 191050 : int16_t startBand = hFdCngDec->hFdCngCom->startBand;
646 191050 : int16_t stopFFTbin = hFdCngDec->hFdCngCom->stopFFTbin;
647 191050 : float *fftBuffer = hFdCngDec->hFdCngCom->fftBuffer;
648 191050 : float *periodog = hFdCngDec->hFdCngCom->periodog;
649 191050 : float *ptr_per = periodog;
650 191050 : float *msPeriodog = hFdCngDec->msPeriodog;
651 191050 : float *msNoiseEst = hFdCngDec->msNoiseEst;
652 :
653 191050 : int16_t *part = hFdCngDec->part_shaping;
654 191050 : int16_t npart = hFdCngDec->npart_shaping;
655 191050 : int16_t nFFTpart = hFdCngDec->nFFTpart_shaping;
656 191050 : float *psize_inv = hFdCngDec->psize_inv_shaping;
657 191050 : float *psize = hFdCngDec->psize_shaping;
658 191050 : float *msLogPeriodog = hFdCngDec->msLogPeriodog;
659 191050 : float *msLogNoiseEst = hFdCngDec->msLogNoiseEst;
660 : int16_t i;
661 : float enr, enr_tot, enr_tot0, enr_ratio, alpha;
662 : int16_t p;
663 : float temp, ftemp, delta;
664 : float wght;
665 :
666 191050 : if ( !( element_mode == IVAS_CPE_MDCT && power_spectrum != NULL ) )
667 : {
668 : /* Perform STFT analysis */
669 185580 : AnalysisSTFT( timeDomainInput, fftBuffer, hFdCngDec->hFdCngCom );
670 : }
671 :
672 191050 : if ( element_mode == IVAS_CPE_TD || element_mode == IVAS_CPE_DFT )
673 : {
674 : /* Calculate periodogram (squared magnitude in each FFT bin) */
675 102754 : if ( startBand == 0 )
676 : {
677 0 : ( *ptr_per ) = fftBuffer[0] * fftBuffer[0];
678 0 : ptr_per++;
679 0 : ptr_r = fftBuffer + 2;
680 : }
681 : else
682 : {
683 102754 : ptr_r = fftBuffer + 2 * startBand;
684 : }
685 :
686 102754 : ptr_i = ptr_r + 1;
687 :
688 29179230 : for ( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ )
689 : {
690 29076476 : ( *ptr_per ) = ( *ptr_r ) * ( *ptr_r ) + ( *ptr_i ) * ( *ptr_i );
691 29076476 : ptr_r += 2;
692 29076476 : ptr_i += 2;
693 : }
694 :
695 : /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/
696 102754 : v_multc( periodog, 4.f / (float) ( hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen ), periodog, stopFFTbin - startBand );
697 :
698 : /* Combine bins of power spectrum into partitions */
699 102754 : i = 0;
700 6426987 : for ( p = 0; p < npart; p++ )
701 : {
702 :
703 : /* calculate mean over all bins in power partition */
704 6324233 : temp = 0;
705 35400709 : for ( ; i <= part[p]; i++ )
706 : {
707 29076476 : temp += periodog[i];
708 : }
709 6324233 : msPeriodog[p] = temp * psize_inv[p];
710 : }
711 :
712 : /* compensate for the loss of variance - don't do when first noise update is not completed yet due to risk of msPeriodog[p] < 0 */
713 102754 : if ( hFdCngDec->first_cna_noise_updated )
714 : {
715 32981 : i = 0;
716 2056472 : for ( p = 0; p < npart; p++ )
717 : {
718 : /* calculate variance over all bins in power partition */
719 2023491 : temp = 0;
720 11765849 : for ( ; i <= part[p]; i++ )
721 : {
722 9742358 : delta = periodog[i] - msPeriodog[p];
723 9742358 : temp += delta * delta;
724 : }
725 2023491 : temp *= psize_inv[p];
726 :
727 : /* compensate for the loss of variance */
728 2023491 : msPeriodog[p] = (float) ( msPeriodog[p] + sqrt( temp ) * rand_gauss( &ftemp, &hFdCngDec->cna_seed ) );
729 :
730 2023491 : if ( msPeriodog[p] < 1e-5f )
731 : {
732 103930 : msPeriodog[p] = 1e-5f;
733 : }
734 : }
735 : }
736 :
737 : /* calculate total energy (short-term and long-term) */
738 102754 : enr_tot = sum_f( msPeriodog, npart ) + EPSILON;
739 102754 : enr_tot0 = sum_f( msNoiseEst, npart ) + EPSILON;
740 :
741 : /* update short-term periodogram on larger partitions */
742 1289287 : for ( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ )
743 : {
744 1186533 : if ( L_frame != last_L_frame || last_core_brate <= SID_2k40 )
745 : {
746 : /* core Fs has changed or last frame was SID/NO_DATA -> re-initialize short-term periodogram */
747 45900 : hFdCngDec->msPeriodog_ST[p] = msPeriodog[p];
748 : }
749 : else
750 : {
751 1140633 : hFdCngDec->msPeriodog_ST[p] = (float) ( ST_PERIODOG_FACT * hFdCngDec->msPeriodog_ST[p] + ( 1 - ST_PERIODOG_FACT ) * msPeriodog[p] );
752 : }
753 : }
754 :
755 : /* core Fs has changed -> partitions have changed -> re-calculate long-term periodogram */
756 : /* part L_FRAME16k L_FRAME */
757 : /* ... */
758 : /* [55] 146 146 */
759 : /* [56] 174 160 */
760 : /* [57] 210 174 */
761 : /* [58] 254 190 */
762 : /* [59] 306 210 */
763 : /* [60] 317 230 */
764 : /* [61] 253 */
765 :
766 102754 : if ( last_L_frame == L_FRAME16k && L_frame == L_FRAME )
767 : {
768 2269 : msNoiseEst[61] = msNoiseEst[58];
769 2269 : msNoiseEst[60] = min( msNoiseEst[58], msNoiseEst[57] );
770 2269 : msNoiseEst[59] = msNoiseEst[57];
771 2269 : msNoiseEst[58] = msNoiseEst[56];
772 2269 : msNoiseEst[57] = msNoiseEst[56];
773 2269 : msNoiseEst[56] = min( msNoiseEst[56], msNoiseEst[55] );
774 : }
775 100485 : else if ( last_L_frame == L_FRAME && L_frame == L_FRAME16k )
776 : {
777 539 : msNoiseEst[56] = min( msNoiseEst[56], msNoiseEst[57] );
778 539 : msNoiseEst[57] = min( msNoiseEst[58], msNoiseEst[59] );
779 539 : msNoiseEst[58] = min( msNoiseEst[60], msNoiseEst[61] );
780 539 : msNoiseEst[59] = 0.0f;
781 539 : msNoiseEst[60] = 0.0f;
782 539 : msNoiseEst[61] = 0.0f;
783 :
784 539 : hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES;
785 : }
786 :
787 : /* Smooth with IIR filter */
788 102754 : if ( !hFdCngDec->first_cna_noise_updated )
789 : {
790 69773 : if ( !VAD )
791 : {
792 : /* background noise update with moving average */
793 837 : alpha = 1.0f / ( hFdCngDec->first_cna_noise_update_cnt + 1 );
794 52227 : for ( p = 0; p < npart; p++ )
795 : {
796 51390 : msNoiseEst[p] = ( 1 - alpha ) * msNoiseEst[p] + alpha * msPeriodog[p];
797 : }
798 :
799 : /* check, if we reached the required number of first CNA noise update frames */
800 837 : if ( hFdCngDec->first_cna_noise_update_cnt < FIRST_CNA_NOISE_UPD_FRAMES - 1 )
801 : {
802 754 : hFdCngDec->first_cna_noise_update_cnt++;
803 : }
804 : else
805 : {
806 83 : hFdCngDec->first_cna_noise_updated = 1;
807 83 : if ( hFdCngDec->hFdCngCom->msFrCnt_init_counter == 0 )
808 : {
809 59 : hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1;
810 : }
811 : }
812 : }
813 : else
814 : {
815 68936 : hFdCngDec->first_cna_noise_update_cnt = 0;
816 : }
817 : }
818 : else
819 : {
820 32981 : hFdCngDec->hFdCngCom->msFrCnt_init_counter = 1;
821 32981 : if ( VAD )
822 : {
823 : /* no updates during active frames except for significant energy drops */
824 29698 : enr_ratio = enr_tot / enr_tot0;
825 29698 : if ( enr_ratio < 0.5f )
826 : {
827 : /* total energy significantly decreases during active frames -> downward update */
828 813 : wght = lin_interp( enr_ratio, 0.0f, 0.8f, 0.5f, 0.95f, 1 );
829 50784 : for ( p = 0; p < npart; p++ )
830 : {
831 49971 : if ( msPeriodog[p] < msNoiseEst[p] )
832 : {
833 37009 : msNoiseEst[p] = wght * msNoiseEst[p] + ( 1 - wght ) * msPeriodog[p];
834 : }
835 : }
836 : }
837 : else
838 : {
839 : /* energy significantly decreases in one of the larger partitions during active frames -> downward update */
840 356570 : for ( p = CNA_ACT_DN_LARGE_PARTITION; p < npart; p++ )
841 : {
842 327685 : if ( hFdCngDec->msPeriodog_ST[p] < msNoiseEst[p] )
843 : {
844 13400 : msNoiseEst[p] = (float) ( CNA_ACT_DN_FACT * msNoiseEst[p] + ( 1 - CNA_ACT_DN_FACT ) * hFdCngDec->msPeriodog_ST[p] );
845 : }
846 : }
847 : }
848 : }
849 : else
850 : {
851 :
852 3283 : if ( bwidth >= WB && hFdCngDec->ms_last_inactive_bwidth == NB )
853 : {
854 : /* bandwidth increased -> set counter for fast initilization */
855 57 : hFdCngDec->ms_cnt_bw_up = FIRST_CNA_NOISE_UPD_FRAMES;
856 : }
857 3283 : hFdCngDec->ms_last_inactive_bwidth = bwidth;
858 : /* update background noise during inactive frames */
859 3283 : ptr_per = msNoiseEst;
860 204868 : for ( p = 0; p < npart; p++ )
861 : {
862 201585 : enr = msPeriodog[p];
863 201585 : alpha = 0.95f;
864 : /* bandwidth increased -> do fast re-initilization */
865 201585 : if ( hFdCngDec->ms_cnt_bw_up > 0 && p > 55 )
866 : {
867 1934 : alpha = 1.0f / ( hFdCngDec->ms_cnt_bw_up + 1 );
868 : }
869 199651 : else if ( enr < *ptr_per && part[p] == 1 )
870 : {
871 : /* faster downward update for single-bin partitions */
872 1131 : alpha = 0.8f;
873 : }
874 198520 : else if ( enr > 2.0f * ( *ptr_per ) )
875 : {
876 : /* prevent abrupt upward updates */
877 62716 : enr = 2.0f * ( *ptr_per );
878 : }
879 :
880 : /* IIR smoothing */
881 201585 : *ptr_per *= alpha;
882 201585 : *ptr_per += ( 1 - alpha ) * enr;
883 201585 : ptr_per++;
884 : }
885 :
886 3283 : if ( hFdCngDec->ms_cnt_bw_up > 0 )
887 : {
888 364 : hFdCngDec->ms_cnt_bw_up--;
889 : }
890 : }
891 : }
892 :
893 102754 : mvr2r( msNoiseEst, hFdCngDec->msPsd, npart );
894 :
895 : /* Expand partitions into bins of power spectrum */
896 102754 : scalebands( msNoiseEst, part, nFFTpart, hFdCngDec->midband_shaping, nFFTpart, stopFFTbin - startBand, hFdCngDec->bandNoiseShape, 1 );
897 :
898 102754 : mvr2r( hFdCngDec->bandNoiseShape, &hFdCngDec->smoothed_psd[startBand], stopFFTbin - startBand );
899 102754 : set_zero( &hFdCngDec->smoothed_psd[stopFFTbin], L_FRAME16k - stopFFTbin );
900 : }
901 : else
902 : {
903 88296 : if ( element_mode == IVAS_CPE_MDCT && power_spectrum != NULL )
904 : {
905 : /* use power spectrum calculated in the MDCT-domain instead of calculating new power spectrum */
906 5470 : periodog = power_spectrum;
907 : }
908 : else
909 : {
910 : /* Compute the squared magnitude in each FFT bin */
911 82826 : if ( startBand == 0 )
912 : {
913 0 : ( *ptr_per ) = fftBuffer[0] * fftBuffer[0]; /* DC component */
914 0 : ptr_per++;
915 0 : ptr_r = fftBuffer + 2;
916 : }
917 : else
918 : {
919 82826 : ptr_r = fftBuffer + 2 * startBand;
920 : }
921 :
922 82826 : ptr_i = ptr_r + 1;
923 :
924 24274934 : for ( ; ptr_per < periodog + stopFFTbin - startBand; ptr_per++ )
925 : {
926 24192108 : ( *ptr_per ) = ( *ptr_r ) * ( *ptr_r ) + ( *ptr_i ) * ( *ptr_i );
927 24192108 : ptr_r += 2;
928 24192108 : ptr_i += 2;
929 : }
930 : /* Nyquist frequency is discarded */
931 :
932 : /* Rescale to get energy/sample: it should be 2*(1/N)*(2/N), parseval relation with 1/N,*2 for nrg computed till Nyquist only, 2/N as windowed samples correspond to half a frame*/
933 82826 : v_multc( periodog, 4.f / (float) ( hFdCngDec->hFdCngCom->fftlen * hFdCngDec->hFdCngCom->fftlen ), periodog, stopFFTbin - startBand );
934 : }
935 :
936 : /* Adjust to the desired frequency resolution by averaging over spectral partitions for SID transmission */
937 88296 : bandcombinepow( periodog, stopFFTbin - startBand, part, npart, psize_inv, msPeriodog );
938 :
939 : /* Compress MS inputs */
940 88296 : compress_range( msPeriodog, msLogPeriodog, npart );
941 :
942 : /* Call the minimum statistics routine for noise estimation */
943 88296 : minimum_statistics( npart, nFFTpart, psize, msLogPeriodog, hFdCngDec->msNoiseFloor, msLogNoiseEst, hFdCngDec->msAlpha, hFdCngDec->msPsd, hFdCngDec->msPsdFirstMoment, hFdCngDec->msPsdSecondMoment, hFdCngDec->msMinBuf, hFdCngDec->msBminWin, hFdCngDec->msBminSubWin, hFdCngDec->msCurrentMin, hFdCngDec->msCurrentMinOut, hFdCngDec->msCurrentMinSubWindow, hFdCngDec->msLocalMinFlag, hFdCngDec->msNewMinFlag, hFdCngDec->msPeriodogBuf, &( hFdCngDec->msPeriodogBufPtr ), hFdCngDec->hFdCngCom,
944 : DEC, element_mode );
945 :
946 : /* Expand MS outputs */
947 88296 : expand_range( msLogNoiseEst, msNoiseEst, npart );
948 : }
949 :
950 191050 : return;
951 : }
952 :
953 :
954 : /*-------------------------------------------------------------------
955 : * FdCng_decodeSID()
956 : *
957 : * Decode the FD-CNG bitstream
958 : *-------------------------------------------------------------------*/
959 :
960 1782 : void FdCng_decodeSID(
961 : Decoder_State *st /* i/o: decoder state structure */
962 : )
963 : {
964 : int16_t N;
965 : float *sidNoiseEst;
966 : float gain;
967 : int16_t i, index;
968 : float v[32];
969 : int16_t indices[32];
970 : HANDLE_FD_CNG_COM hFdCngCom;
971 : float *invTrfMatrix;
972 : float tmpRAM[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
973 :
974 1782 : const float gain_q_offset = ( st->element_mode == EVS_MONO ) ? GAIN_Q_OFFSET_EVS : GAIN_Q_OFFSET_IVAS;
975 :
976 1782 : invTrfMatrix = (float *) tmpRAM;
977 :
978 1782 : hFdCngCom = ( st->hFdCngDec )->hFdCngCom;
979 :
980 1782 : sidNoiseEst = hFdCngCom->sidNoiseEst;
981 :
982 1782 : N = hFdCngCom->npart;
983 1782 : gain = 0.0f;
984 1782 : hFdCngCom->sid_frame_counter++;
985 :
986 : /* Read bitstream */
987 12474 : for ( i = 0; i < FD_CNG_stages_37bits; i++ )
988 : {
989 10692 : indices[i] = get_next_indice( st, bits_37bits[i] );
990 : }
991 :
992 1782 : index = get_next_indice( st, 7 );
993 :
994 : /* MSVQ decoder */
995 :
996 1782 : if ( st->element_mode != EVS_MONO )
997 : {
998 1782 : create_IDCT_N_Matrix( invTrfMatrix, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM ) / ( sizeof( float ) ) );
999 1782 : msvq_dec( cdk_37bits_ivas, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix, v, NULL );
1000 : }
1001 : else
1002 : { /* Legacy EVS_MONO MSVQ tables */
1003 0 : msvq_dec( cdk_37bits, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 0, NULL, v, NULL );
1004 : }
1005 :
1006 :
1007 : /* Decode gain */
1008 1782 : gain = ( (float) index - gain_q_offset ) / 1.5f;
1009 :
1010 : /* Apply gain and undo log */
1011 43540 : for ( i = 0; i < N; i++ )
1012 : {
1013 41758 : sidNoiseEst[i] = (float) pow( 10.f, ( v[i] + gain ) / 10.f );
1014 : }
1015 :
1016 : /* NB last band energy compensation */
1017 :
1018 1782 : if ( hFdCngCom->CngBandwidth == NB )
1019 : {
1020 0 : sidNoiseEst[N - 1] *= NB_LAST_BAND_SCALE;
1021 : }
1022 :
1023 1782 : if ( hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20 )
1024 : {
1025 463 : sidNoiseEst[N - 1] *= SWB_13k2_LAST_BAND_SCALE;
1026 : }
1027 :
1028 1782 : scalebands( sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 );
1029 :
1030 1782 : lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, st->preemph_fac );
1031 :
1032 1782 : return;
1033 : }
1034 :
1035 :
1036 : /*-------------------------------------------------------------------
1037 : * noisy_speech_detection()
1038 : *
1039 : *
1040 : *-------------------------------------------------------------------*/
1041 :
1042 713328 : void noisy_speech_detection(
1043 : HANDLE_FD_CNG_DEC hFdCngDec, /* i/o: FD_CNG structure */
1044 : const int16_t vad, /* i : VAD flag */
1045 : const float syn[] /* i : input time-domain frame */
1046 : )
1047 : {
1048 : float tmp;
1049 :
1050 713328 : if ( vad == 0 )
1051 : {
1052 52287 : tmp = dotp( hFdCngDec->msNoiseEst, hFdCngDec->psize_shaping, hFdCngDec->nFFTpart_shaping );
1053 52287 : hFdCngDec->lp_noise = 0.995f * hFdCngDec->lp_noise + 0.005f * 10.f * (float) log10( tmp + DELTA );
1054 : }
1055 : else
1056 : {
1057 661041 : tmp = dotp( syn, syn, hFdCngDec->hFdCngCom->frameSize ) * 2.f / hFdCngDec->hFdCngCom->frameSize;
1058 661041 : hFdCngDec->lp_speech = 0.995f * hFdCngDec->lp_speech + 0.005f * 10.f * (float) log10( tmp + DELTA );
1059 : }
1060 :
1061 713328 : tmp = hFdCngDec->lp_speech - 45.f;
1062 713328 : if ( hFdCngDec->lp_noise < tmp )
1063 : {
1064 406896 : hFdCngDec->lp_noise = tmp;
1065 : }
1066 :
1067 713328 : hFdCngDec->hFdCngCom->flag_noisy_speech = ( hFdCngDec->lp_speech - hFdCngDec->lp_noise ) < 28.f;
1068 :
1069 713328 : return;
1070 : }
1071 :
1072 :
1073 : /*-------------------------------------------------------------------
1074 : * generate_comfort_noise_dec()
1075 : *
1076 : * Generate the comfort noise based on the target noise level
1077 : *-------------------------------------------------------------------*/
1078 :
1079 16790 : void generate_comfort_noise_dec(
1080 : float **bufferReal, /* o : Real part of input bands */
1081 : float **bufferImag, /* o : Imaginary part of input bands */
1082 : Decoder_State *st, /* i/o: decoder state structure */
1083 : const int16_t nchan_out /* i : number of output channels */
1084 : )
1085 : {
1086 : int16_t i, j;
1087 : float *ptr_r, *ptr_i;
1088 16790 : HANDLE_FD_CNG_DEC hFdCngDec = st->hFdCngDec;
1089 16790 : HANDLE_FD_CNG_COM hFdCngCom = hFdCngDec->hFdCngCom;
1090 16790 : float *cngNoiseLevel = hFdCngCom->cngNoiseLevel;
1091 16790 : float *ptr_level = cngNoiseLevel;
1092 16790 : int16_t *seed = &( hFdCngCom->seed );
1093 : int16_t *seed2;
1094 : float c1, c2;
1095 : float tmp1, tmp2;
1096 : float scale, scaleCldfb;
1097 16790 : float *fftBuffer = hFdCngCom->fftBuffer;
1098 16790 : float *timeDomainOutput = hFdCngCom->timeDomainBuffer;
1099 : int16_t tcx_transition;
1100 : float enr, att;
1101 :
1102 16790 : scale = 1.f;
1103 16790 : scaleCldfb = CLDFB_SCALING / hFdCngCom->scalingFactor;
1104 :
1105 16790 : c1 = (float) sqrt( hFdCngCom->coherence[0] );
1106 16790 : c2 = (float) sqrt( 1 - hFdCngCom->coherence[0] );
1107 :
1108 16790 : seed2 = &( hFdCngCom->seed2 );
1109 16790 : if ( st->element_mode == IVAS_CPE_MDCT && st->idchan == 1 )
1110 : {
1111 2526 : seed2 = &( hFdCngCom->seed3 );
1112 : }
1113 :
1114 : /* Generate Gaussian random noise in real and imaginary parts of the FFT bins
1115 : Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */
1116 :
1117 16790 : if ( hFdCngCom->startBand == 0 )
1118 : {
1119 0 : if ( ( st->element_mode == IVAS_CPE_MDCT && nchan_out != 1 ) || ( st->element_mode == IVAS_SCE && st->cng_ism_flag ) )
1120 : {
1121 0 : rand_gauss( &tmp1, seed );
1122 0 : rand_gauss( &tmp2, seed2 );
1123 0 : fftBuffer[0] = tmp1 * c1 + tmp2 * c2;
1124 : }
1125 : else
1126 : {
1127 0 : rand_gauss( &fftBuffer[0], seed );
1128 : }
1129 0 : fftBuffer[0] *= (float) sqrt( scale * *ptr_level ); /* DC component in FFT */
1130 0 : ptr_level++;
1131 0 : ptr_r = fftBuffer + 2;
1132 : }
1133 : else
1134 : {
1135 16790 : fftBuffer[0] = 0.f;
1136 16790 : set_f( fftBuffer + 2, 0.0f, 2 * ( hFdCngCom->startBand - 1 ) );
1137 16790 : ptr_r = fftBuffer + 2 * hFdCngCom->startBand;
1138 : }
1139 :
1140 16790 : ptr_i = ptr_r + 1;
1141 16790 : if ( st->element_mode == IVAS_CPE_MDCT && nchan_out != 1 )
1142 4974 : {
1143 : int16_t band_len_accu;
1144 :
1145 4974 : band_len_accu = 0;
1146 4974 : i = 0;
1147 29844 : for ( int16_t b = 0; b < MDCT_ST_DTX_NUM_COHERENCE_BANDS; b++ )
1148 : {
1149 24870 : band_len_accu += mdct_stereo_dtx_coherence_bandlengths[b];
1150 :
1151 : /* First band needs to be shortened. The offset from encoder-side estimation is already in, so add it back here */
1152 24870 : if ( b == 0 )
1153 : {
1154 4974 : band_len_accu += MDCT_ST_DTX_FIRST_BAND_OFFSET - hFdCngCom->startBand;
1155 : }
1156 :
1157 : /*
1158 : * for last band, we need to keep going until the end of the fft section - if there is still any
1159 : * this way, the coherence value of the last band is used for eveyrthing above as well
1160 : */
1161 24870 : if ( b == MDCT_ST_DTX_NUM_COHERENCE_BANDS - 1 )
1162 : {
1163 4974 : band_len_accu = max( band_len_accu, hFdCngCom->stopFFTbin - hFdCngCom->startBand );
1164 : }
1165 :
1166 : /* mixing values for coherence is now frequency-dependent */
1167 24870 : c1 = (float) sqrt( hFdCngCom->coherence[b] );
1168 24870 : c2 = (float) sqrt( 1 - hFdCngCom->coherence[b] );
1169 :
1170 1606602 : for ( ; i < band_len_accu; i++ )
1171 : {
1172 : float val_level;
1173 1581732 : val_level = (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1174 :
1175 : /* Real part in FFT bins */
1176 1581732 : rand_gauss( &tmp1, seed );
1177 1581732 : rand_gauss( &tmp2, seed2 );
1178 1581732 : *ptr_r = tmp1 * c1 + tmp2 * c2;
1179 1581732 : ( *ptr_r ) *= val_level;
1180 :
1181 : /* Imaginary part in FFT bins */
1182 1581732 : rand_gauss( &tmp1, seed );
1183 1581732 : rand_gauss( &tmp2, seed2 );
1184 1581732 : *ptr_i = tmp1 * c1 + tmp2 * c2;
1185 1581732 : ( *ptr_i ) *= val_level;
1186 :
1187 : /* advance all pointers together here */
1188 1581732 : ptr_r += 2;
1189 1581732 : ptr_i += 2;
1190 1581732 : ptr_level++;
1191 : }
1192 : }
1193 : }
1194 : else
1195 : {
1196 3338584 : for ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++ )
1197 : {
1198 : /* Real part in FFT bins */
1199 3326768 : if ( st->element_mode == IVAS_SCE && st->cng_ism_flag )
1200 : {
1201 1364580 : rand_gauss( &tmp1, seed );
1202 1364580 : rand_gauss( &tmp2, seed2 );
1203 1364580 : *ptr_r = tmp1 * c1 + tmp2 * c2;
1204 : }
1205 : else
1206 : {
1207 1962188 : rand_gauss( ptr_r, seed );
1208 : }
1209 3326768 : ( *ptr_r ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1210 3326768 : ptr_r += 2;
1211 :
1212 : /* Imaginary part in FFT bins */
1213 3326768 : if ( st->element_mode == IVAS_SCE && st->cng_ism_flag )
1214 : {
1215 1364580 : rand_gauss( &tmp1, seed );
1216 1364580 : rand_gauss( &tmp2, seed2 );
1217 1364580 : *ptr_i = tmp1 * c1 + tmp2 * c2;
1218 : }
1219 : else
1220 : {
1221 1962188 : rand_gauss( ptr_i, seed );
1222 : }
1223 3326768 : ( *ptr_i ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1224 3326768 : ptr_i += 2;
1225 : }
1226 : }
1227 :
1228 : /* Remaining FFT bins are set to zero */
1229 16790 : set_f( fftBuffer + 2 * hFdCngCom->stopFFTbin, 0.0f, hFdCngCom->fftlen - 2 * hFdCngCom->stopFFTbin );
1230 :
1231 : /* Nyquist frequency is discarded */
1232 16790 : fftBuffer[1] = 0.f;
1233 :
1234 : /* If previous frame is active, reset the overlap-add buffer */
1235 16790 : tcx_transition = 0;
1236 16790 : if ( hFdCngCom->frame_type_previous == ACTIVE_FRAME )
1237 : {
1238 1762 : set_f( hFdCngCom->olapBufferSynth, 0.0f, hFdCngCom->fftlen );
1239 1762 : if ( ( st->core > ACELP_CORE && st->codec_mode == MODE2 ) || st->codec_mode == MODE1 )
1240 : {
1241 1762 : tcx_transition = 1;
1242 : }
1243 : }
1244 :
1245 : /* Perform STFT synthesis */
1246 16790 : SynthesisSTFT( fftBuffer, timeDomainOutput, hFdCngCom->olapBufferSynth, hFdCngCom->olapWinSyn, tcx_transition, hFdCngCom, st->element_mode, nchan_out );
1247 :
1248 : /* update CNG excitation energy for LP_CNG */
1249 :
1250 : /* calculate the residual signal energy */
1251 16790 : enr = dotp( hFdCngCom->exc_cng, hFdCngCom->exc_cng, hFdCngCom->frameSize ) / hFdCngCom->frameSize;
1252 :
1253 : /* convert log2 of residual signal energy */
1254 16790 : enr = (float) log10( enr + 0.1f ) / (float) log10( 2.0f );
1255 :
1256 : /* decrease the energy in case of WB input */
1257 16790 : if ( st->bwidth != NB )
1258 : {
1259 16790 : if ( st->bwidth == WB )
1260 : {
1261 3753 : if ( st->CNG_mode >= 0 )
1262 : {
1263 : /* Bitrate adapted attenuation */
1264 1 : att = ENR_ATT[st->CNG_mode];
1265 : }
1266 : else
1267 : {
1268 : /* Use least attenuation for higher bitrates */
1269 3752 : att = ENR_ATT[4];
1270 : }
1271 : }
1272 : else
1273 : {
1274 13037 : att = 1.5f;
1275 : }
1276 :
1277 16790 : enr -= att;
1278 : }
1279 :
1280 16790 : st->lp_ener = (float) ( 0.8f * st->lp_ener + 0.2f * pow( 2.0f, enr ) );
1281 :
1282 : /* Generate Gaussian random noise in real and imaginary parts of the CLDFB bands
1283 : Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each band */
1284 :
1285 : /*
1286 : * Note: for the stereo DTX noise mixing, c1 and c2 at this point are set to the value calculated for the last band
1287 : * as all the coherence bands are in the FFT region, we do not need the special handling here
1288 : */
1289 :
1290 16790 : if ( bufferReal != NULL && hFdCngCom->numCoreBands < hFdCngCom->regularStopBand )
1291 : {
1292 0 : for ( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ )
1293 : {
1294 0 : for ( i = 0; i < hFdCngCom->numSlots; i++ )
1295 : {
1296 : /* Real part in CLDFB band */
1297 0 : if ( ( st->element_mode == IVAS_CPE_MDCT && nchan_out != 1 ) || ( st->element_mode == IVAS_SCE && st->cng_ism_flag ) )
1298 : {
1299 0 : rand_gauss( &tmp1, seed );
1300 0 : rand_gauss( &tmp2, seed2 );
1301 0 : bufferReal[i][j] = tmp1 * c1 + tmp2 * c2;
1302 : }
1303 : else
1304 : {
1305 0 : rand_gauss( &bufferReal[i][j], seed );
1306 : }
1307 0 : bufferReal[i][j] *= (float) sqrt( ( scaleCldfb * *ptr_level ) * 0.5f );
1308 :
1309 : /* Imaginary part in CLDFB band */
1310 0 : if ( ( st->element_mode == IVAS_CPE_MDCT && nchan_out != 1 ) || ( st->element_mode == IVAS_SCE && st->cng_ism_flag ) )
1311 : {
1312 0 : rand_gauss( &tmp1, seed );
1313 0 : rand_gauss( &tmp2, seed2 );
1314 0 : bufferImag[i][j] = tmp1 * c1 + tmp2 * c2;
1315 : }
1316 : else
1317 : {
1318 0 : rand_gauss( &bufferImag[i][j], seed );
1319 : }
1320 0 : bufferImag[i][j] *= (float) sqrt( ( scaleCldfb * *ptr_level ) * 0.5f );
1321 : }
1322 0 : ptr_level++;
1323 : }
1324 : }
1325 :
1326 : /* Overlap-add when previous frame is active */
1327 16790 : if ( hFdCngCom->frame_type_previous == ACTIVE_FRAME && st->codec_mode == MODE2 )
1328 : {
1329 0 : float noise[2048], old_exc_ener = 0.f, gain = 0.f, tmp;
1330 0 : int16_t N = hFdCngCom->frameSize;
1331 0 : int16_t seed_loc = hFdCngCom->seed;
1332 : float *old_exc, old_Aq[M + 1], *old_syn_pe, old_syn;
1333 :
1334 0 : if ( st->core > ACELP_CORE )
1335 : {
1336 0 : tcx_windowing_synthesis_current_frame( timeDomainOutput, st->hTcxCfg->tcx_mdct_window, /*Keep sine windows for limiting Time modulation*/
1337 0 : st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, 0, st->hTcxCfg->tcx_last_overlap_mode == ALDO_WINDOW ? FULL_OVERLAP : st->hTcxCfg->tcx_last_overlap_mode, NULL, NULL, NULL, NULL, NULL, N / 2, st->hTcxCfg->tcx_offset < 0 ? -st->hTcxCfg->tcx_offset : 0, 1, 0, 0 );
1338 :
1339 0 : if ( st->hTcxCfg->last_aldo )
1340 : {
1341 0 : for ( i = 0; i < ( hFdCngCom->frameSize - NS2SA( st->sr_core, N_ZERO_MDCT_NS ) ); i++ )
1342 : {
1343 0 : timeDomainOutput[i] += st->hHQ_core->old_outLB[i + NS2SA( st->sr_core, N_ZERO_MDCT_NS )];
1344 : }
1345 : }
1346 : else
1347 : {
1348 0 : tcx_windowing_synthesis_past_frame( st->hTcxDec->syn_Overl, st->hTcxCfg->tcx_mdct_window, st->hTcxCfg->tcx_mdct_window_half, st->hTcxCfg->tcx_mdct_window_minimum, st->hTcxCfg->tcx_mdct_window_length, st->hTcxCfg->tcx_mdct_window_half_length, st->hTcxCfg->tcx_mdct_window_min_length, st->hTcxCfg->tcx_last_overlap_mode );
1349 :
1350 0 : for ( i = 0; i < st->hTcxCfg->tcx_mdct_window_length; i++ )
1351 : {
1352 0 : timeDomainOutput[i] += st->hTcxDec->syn_Overl[i];
1353 : }
1354 : }
1355 : }
1356 : else
1357 : {
1358 0 : mvr2r( st->old_Aq_12_8, old_Aq, M + 1 );
1359 0 : old_exc = st->old_exc + L_EXC_MEM_DEC - ( N / 2 );
1360 0 : old_syn_pe = st->mem_syn2;
1361 0 : old_syn = st->syn[M];
1362 :
1363 0 : for ( i = 0; i < N / 2; i++ )
1364 : {
1365 0 : old_exc_ener += old_exc[i] * old_exc[i];
1366 : }
1367 :
1368 0 : old_exc_ener = (float) sqrt( old_exc_ener / (float) ( N / 2 ) );
1369 :
1370 0 : for ( i = 0; i < N; i++ )
1371 : {
1372 0 : rand_gauss( &( noise[i] ), &( seed_loc ) );
1373 0 : gain += noise[i] * noise[i];
1374 : }
1375 :
1376 0 : gain = old_exc_ener / (float) sqrt( gain / (float) N );
1377 :
1378 0 : for ( i = 0; i < N; i++ )
1379 : {
1380 0 : noise[i] *= gain;
1381 : }
1382 :
1383 0 : syn_filt( old_Aq, M, noise, noise, N, old_syn_pe, 0 );
1384 :
1385 0 : tmp = old_syn;
1386 :
1387 0 : deemph( noise, st->preemph_fac, N, &tmp );
1388 :
1389 0 : for ( i = 0; i < N / 2; i++ )
1390 : {
1391 0 : timeDomainOutput[i] += noise[i] * hFdCngCom->olapWinSyn[N / 2 + i];
1392 : }
1393 : }
1394 : }
1395 :
1396 16790 : return;
1397 : }
1398 :
1399 :
1400 : /*-------------------------------------------------------------------
1401 : * generate_comfort_noise_dec_hf()
1402 : *
1403 : * Generate the comfort noise based on the target noise level for the CLDFB part
1404 : *-------------------------------------------------------------------*/
1405 :
1406 13484 : void generate_comfort_noise_dec_hf(
1407 : float **bufferReal, /* o : Real part of input bands */
1408 : float **bufferImag, /* o : Imaginary part of input bands */
1409 : HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
1410 : const int16_t cng_coh_flag /* i : CNG Flag for coherence handling */
1411 : )
1412 : {
1413 : int16_t i, j;
1414 : float *ptr_level;
1415 :
1416 13484 : int16_t *seed = &( hFdCngCom->seed );
1417 13484 : float scale = CLDFB_SCALING / hFdCngCom->scalingFactor;
1418 :
1419 13484 : int16_t *seed2 = &( hFdCngCom->seed );
1420 :
1421 13484 : float tmp1, tmp2, c1 = 0.f, c2 = 0.f;
1422 :
1423 13484 : if ( cng_coh_flag )
1424 : {
1425 5262 : seed2 = &( hFdCngCom->seed2 );
1426 :
1427 : /* alwas use the value for the last band - frequency-wise we are here always above */
1428 5262 : c1 = (float) sqrt( hFdCngCom->coherence[MDCT_ST_DTX_NUM_COHERENCE_BANDS - 1] );
1429 5262 : c2 = (float) sqrt( 1 - hFdCngCom->coherence[MDCT_ST_DTX_NUM_COHERENCE_BANDS - 1] );
1430 : }
1431 :
1432 13484 : ptr_level = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand;
1433 : /*
1434 : Generate Gaussian random noise in real and imaginary parts of the CLDFB bands
1435 : Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each band
1436 : */
1437 13484 : if ( hFdCngCom->numCoreBands < hFdCngCom->regularStopBand )
1438 : {
1439 243533 : for ( j = hFdCngCom->numCoreBands; j < hFdCngCom->regularStopBand; j++ )
1440 : {
1441 3933936 : for ( i = 0; i < hFdCngCom->numSlots; i++ )
1442 : {
1443 3702528 : if ( cng_coh_flag )
1444 : {
1445 : /* Real part in CLDFB band */
1446 1535216 : rand_gauss( &tmp1, seed );
1447 1535216 : rand_gauss( &tmp2, seed2 );
1448 1535216 : bufferReal[i][j] = tmp1 * c1 + tmp2 * c2;
1449 1535216 : bufferReal[i][j] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1450 :
1451 : /* Imaginary part in CLDFB band */
1452 1535216 : rand_gauss( &tmp1, seed );
1453 1535216 : rand_gauss( &tmp2, seed2 );
1454 1535216 : bufferImag[i][j] = tmp1 * c1 + tmp2 * c2;
1455 1535216 : bufferImag[i][j] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1456 : }
1457 : else
1458 : {
1459 : /* Real part in CLDFB band */
1460 2167312 : rand_gauss( &bufferReal[i][j], seed );
1461 2167312 : bufferReal[i][j] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1462 : /* Imaginary part in CLDFB band */
1463 2167312 : rand_gauss( &bufferImag[i][j], seed );
1464 2167312 : bufferImag[i][j] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1465 : }
1466 : }
1467 231408 : ptr_level++;
1468 : }
1469 : }
1470 :
1471 13484 : return;
1472 : }
1473 :
1474 :
1475 : /*-------------------------------------------------------------------
1476 : * generate_masking_noise()
1477 : *
1478 : * Generate additional comfort noise (kind of noise filling)
1479 : *-------------------------------------------------------------------*/
1480 :
1481 88048 : void generate_masking_noise(
1482 : float *timeDomainBuffer, /* i/o: time-domain signal */
1483 : HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
1484 : const int16_t length, /* i : frame size */
1485 : const int16_t core, /* i : core */
1486 : const int16_t return_noise, /* i : noise is returned instead of added */
1487 : const int16_t secondary, /* i : flag to indicate secondary noise generation */
1488 : const int16_t element_mode, /* i : element mode */
1489 : STEREO_CNG_DEC_HANDLE hStereoCng, /* i : stereo CNG handle */
1490 : const int16_t nchan_out /* i : number of output channels */
1491 : )
1492 : {
1493 88048 : float *cngNoiseLevel = hFdCngCom->cngNoiseLevel;
1494 88048 : float *ptr_level = cngNoiseLevel;
1495 88048 : float *fftBuffer = hFdCngCom->fftBuffer;
1496 : int16_t i;
1497 : float maskingNoise[L_FRAME16k];
1498 : float *ptr_r;
1499 : float *ptr_i;
1500 88048 : int16_t startBand = hFdCngCom->startBand;
1501 88048 : int16_t *seed = &( hFdCngCom->seed );
1502 88048 : float scale = 1.f;
1503 :
1504 : /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
1505 88048 : if ( hFdCngCom->likelihood_noisy_speech > DELTA_MASKING_NOISE )
1506 : {
1507 4654 : if ( core != AMR_WB_CORE )
1508 : {
1509 : /* Compute additional CN level */
1510 62961 : for ( i = 0; i < SIZE_SCALE_TABLE_CN; i++ )
1511 : {
1512 62961 : if ( ( hFdCngCom->CngBandwidth == scaleTable_cn_only[i].bwmode ) &&
1513 18727 : ( hFdCngCom->CngBitrate >= scaleTable_cn_only[i].bitrateFrom ) &&
1514 18727 : ( hFdCngCom->CngBitrate < scaleTable_cn_only[i].bitrateTo ) )
1515 : {
1516 4654 : break;
1517 : }
1518 : }
1519 :
1520 4654 : scale *= (float) pow( 10.f, -scaleTable_cn_only[i].scale / 10.f ) - 1.f;
1521 : }
1522 : else
1523 : {
1524 : /* Compute additional CN level */
1525 0 : for ( i = 0; i < SIZE_SCALE_TABLE_CN_AMRWB; i++ )
1526 : {
1527 0 : if ( hFdCngCom->CngBitrate >= scaleTable_cn_only_amrwbio[i][0] )
1528 : {
1529 0 : break;
1530 : }
1531 : }
1532 :
1533 0 : if ( i < SIZE_SCALE_TABLE_CN_AMRWB )
1534 : {
1535 0 : scale *= (float) pow( 10.f, -scaleTable_cn_only_amrwbio[i][1] / 10.f ) - 1.f;
1536 : }
1537 : else
1538 : {
1539 0 : scale = 0.f;
1540 : }
1541 : }
1542 :
1543 : /* Exclude clean speech */
1544 4654 : scale *= hFdCngCom->likelihood_noisy_speech;
1545 :
1546 : /* Generate Gaussian random noise in real and imaginary parts of the FFT bins
1547 : Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */
1548 4654 : if ( startBand == 0 )
1549 : {
1550 0 : rand_gauss( &fftBuffer[0], seed );
1551 0 : ptr_r = fftBuffer + 2;
1552 0 : fftBuffer[0] *= (float) sqrt( scale * *ptr_level ); /* DC component in FFT */
1553 0 : ptr_level++;
1554 : }
1555 : else
1556 : {
1557 4654 : fftBuffer[0] = 0.f;
1558 4654 : set_f( fftBuffer + 2, 0.0f, 2 * ( startBand - 1 ) );
1559 4654 : ptr_r = fftBuffer + 2 * startBand;
1560 : }
1561 4654 : ptr_i = ptr_r + 1;
1562 1335122 : for ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - startBand; ptr_level++ )
1563 : {
1564 : /* Real part in FFT bins */
1565 1330468 : rand_gauss( ptr_r, seed );
1566 1330468 : ( *ptr_r ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1567 1330468 : ptr_r += 2;
1568 : /* Imaginary part in FFT bins */
1569 1330468 : rand_gauss( ptr_i, seed );
1570 1330468 : ( *ptr_i ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1571 1330468 : ptr_i += 2;
1572 : }
1573 :
1574 : /* Remaining FFT bins are set to zero */
1575 4654 : set_f( fftBuffer + 2 * hFdCngCom->stopFFTbin, 0.0f, hFdCngCom->fftlen - 2 * hFdCngCom->stopFFTbin );
1576 : /* Nyquist frequency is discarded */
1577 4654 : fftBuffer[1] = 0.f;
1578 : }
1579 : else
1580 : {
1581 : /* very low level case - update random seeds and reset FFT buffer; don't fully skip SynthesisSTFT(), because of the buffer updates done there... */
1582 83394 : generate_masking_noise_update_seed( hFdCngCom );
1583 :
1584 83394 : set_f( fftBuffer, 0.f, hFdCngCom->fftlen );
1585 : }
1586 :
1587 : /* Perform STFT synthesis */
1588 88048 : if ( secondary )
1589 : {
1590 458 : SynthesisSTFT( fftBuffer, maskingNoise, hStereoCng->olapBufferSynth22, hFdCngCom->olapWinSyn, 0, hFdCngCom, element_mode, nchan_out );
1591 : }
1592 : else
1593 : {
1594 87590 : SynthesisSTFT( fftBuffer, maskingNoise, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, 0, hFdCngCom, element_mode, nchan_out );
1595 : }
1596 :
1597 : /* Add some comfort noise on top of decoded signal */
1598 88048 : if ( return_noise )
1599 : {
1600 916 : mvr2r( maskingNoise, timeDomainBuffer, min( hFdCngCom->frameSize, length ) );
1601 : }
1602 : else
1603 : {
1604 87132 : v_add( maskingNoise, timeDomainBuffer, timeDomainBuffer, min( hFdCngCom->frameSize, length ) );
1605 : }
1606 :
1607 88048 : return;
1608 : }
1609 :
1610 :
1611 : /*-------------------------------------------------------------------
1612 : * generate_masking_noise_update_seed()
1613 : *
1614 : * Update seed for scenarios where generate_masking_noise() is
1615 : * not called based on signal statistics
1616 : *-------------------------------------------------------------------*/
1617 :
1618 96782 : void generate_masking_noise_update_seed(
1619 : HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
1620 : )
1621 : {
1622 96782 : float *cngNoiseLevel = hFdCngCom->cngNoiseLevel;
1623 96782 : float *ptr_level = cngNoiseLevel;
1624 96782 : int16_t startBand = hFdCngCom->startBand;
1625 96782 : int16_t *seed = &( hFdCngCom->seed );
1626 96782 : float tmp = 0;
1627 :
1628 : /*
1629 : Generate Gaussian random noise in real and imaginary parts of the FFT bins
1630 : Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin
1631 : */
1632 96782 : if ( startBand == 0 )
1633 : {
1634 0 : rand_gauss( &tmp, seed );
1635 0 : ptr_level++;
1636 : }
1637 :
1638 27036018 : for ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - startBand; ptr_level++ )
1639 : {
1640 : /* Real part in FFT bins */
1641 26939236 : rand_gauss( &tmp, seed );
1642 26939236 : rand_gauss( &tmp, seed );
1643 : }
1644 :
1645 96782 : return;
1646 : }
1647 :
1648 :
1649 : /*-------------------------------------------------------------------
1650 : * generate_masking_noise_mdct()
1651 : *
1652 : * Generate additional comfort noise (kind of noise filling)
1653 : *-------------------------------------------------------------------*/
1654 :
1655 30328 : void generate_masking_noise_mdct(
1656 : float *mdctBuffer, /* i/o: time-domain signal */
1657 : HANDLE_FD_CNG_COM hFdCngCom /* i/o: FD_CNG structure containing all buffers and variables */
1658 : )
1659 : {
1660 30328 : float *cngNoiseLevel = hFdCngCom->cngNoiseLevel;
1661 : int16_t i;
1662 : float maskingNoise[2 * L_FRAME16k];
1663 : float *ptr_r;
1664 30328 : float *ptr_level = cngNoiseLevel;
1665 30328 : int16_t startBand = hFdCngCom->startBand;
1666 30328 : int16_t *seed = &( hFdCngCom->seed );
1667 30328 : float scale = 1.f;
1668 :
1669 : /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
1670 30328 : if ( hFdCngCom->likelihood_noisy_speech > DELTA_MASKING_NOISE )
1671 : {
1672 13971 : for ( i = 0; i < SIZE_SCALE_TABLE_CN; i++ )
1673 : {
1674 13971 : if ( ( hFdCngCom->CngBandwidth == scaleTable_cn_only[i].bwmode ) &&
1675 4430 : ( hFdCngCom->CngBitrate >= scaleTable_cn_only[i].bitrateFrom ) &&
1676 4430 : ( hFdCngCom->CngBitrate < scaleTable_cn_only[i].bitrateTo ) )
1677 : {
1678 1037 : break;
1679 : }
1680 : }
1681 :
1682 1037 : scale *= (float) pow( 10.f, -scaleTable_cn_only[i].scale / 10.f ) - 1.f;
1683 :
1684 : /* Exclude clean speech */
1685 1037 : scale *= hFdCngCom->likelihood_noisy_speech;
1686 :
1687 : /*
1688 : Generate Gaussian random noise in real and imaginary parts of the FFT bins
1689 : Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin
1690 : */
1691 1037 : if ( startBand == 0 )
1692 : {
1693 0 : rand_gauss( &maskingNoise[0], seed );
1694 0 : maskingNoise[0] *= (float) sqrt( scale * *ptr_level * 0.5f ); /* DC component in FFT */
1695 0 : ptr_level++;
1696 0 : ptr_r = maskingNoise + 1;
1697 : }
1698 : else
1699 : {
1700 1037 : maskingNoise[0] = 0.f;
1701 1037 : set_f( maskingNoise + 1, 0.0f, ( startBand - 1 ) );
1702 1037 : ptr_r = maskingNoise + startBand;
1703 : }
1704 :
1705 299955 : for ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - startBand; ptr_level++ )
1706 : {
1707 : /* MDCT bins */
1708 298918 : rand_gauss( ptr_r, seed );
1709 298918 : ( *ptr_r ) *= (float) sqrt( scale * *ptr_level * 0.5f );
1710 298918 : ptr_r += 1;
1711 : }
1712 :
1713 : /*re-normalization of energy level: M/sqrt(2)*/
1714 1037 : v_multc( maskingNoise, (float) sqrt( NORM_MDCT_FACTOR ), maskingNoise, hFdCngCom->stopFFTbin );
1715 :
1716 : /* Add some comfort noise on top of decoded signal */
1717 1037 : v_add( maskingNoise, mdctBuffer, mdctBuffer, hFdCngCom->stopFFTbin );
1718 : }
1719 : else
1720 : {
1721 : /* very low level case - just update random seeds */
1722 29291 : if ( startBand == 0 )
1723 : {
1724 0 : rand_gauss( &maskingNoise[0], seed );
1725 0 : ptr_level++;
1726 : }
1727 :
1728 8196117 : for ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - startBand; ptr_level++ )
1729 : {
1730 8166826 : rand_gauss( &maskingNoise[0], seed );
1731 : }
1732 : }
1733 :
1734 30328 : return;
1735 : }
1736 :
1737 : /*-------------------------------------------------------------------
1738 : * generate_stereo_masking_noise()
1739 : *
1740 : * Generate additional comfort noise (kind of noise filling)
1741 : *-------------------------------------------------------------------*/
1742 :
1743 928 : void generate_stereo_masking_noise(
1744 : float *syn, /* i/o: time-domain signal */
1745 : Decoder_State *st, /* i/o: decoder state structure */
1746 : STEREO_TD_DEC_DATA_HANDLE hStereoTD, /* i : TD stereo structure */
1747 : const int16_t flag_sec_CNA, /* i : CNA flag for secondary channel */
1748 : const int16_t fadeOut, /* i : only fade out of previous state */
1749 : STEREO_CNG_DEC_HANDLE hStereoCng, /* i : Stereo CNG handle */
1750 : const int16_t nchan_out /* i : number of output channels */
1751 : )
1752 : {
1753 : HANDLE_FD_CNG_COM hFdCngCom;
1754 : float gamma, scale, SP_ratio;
1755 : float Np[L_FRAME16k];
1756 : float Ns[L_FRAME16k];
1757 : float N1[L_FRAME16k];
1758 : float N2[L_FRAME16k];
1759 : int16_t i;
1760 :
1761 928 : if ( st->idchan == 0 )
1762 : {
1763 458 : hFdCngCom = st->hFdCngDec->hFdCngCom;
1764 458 : mvr2r( hFdCngCom->olapBufferSynth2, Np, hFdCngCom->frameSize / 2 );
1765 458 : mvr2r( hStereoCng->olapBufferSynth22, Ns, hFdCngCom->frameSize / 2 );
1766 458 : set_f( &Np[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2 );
1767 458 : set_f( &Ns[hFdCngCom->frameSize / 2], 0.0f, hFdCngCom->frameSize / 2 );
1768 :
1769 458 : if ( !fadeOut )
1770 : {
1771 458 : generate_masking_noise( N1, hFdCngCom, hFdCngCom->frameSize, 0, 1, 0, st->element_mode, hStereoCng, nchan_out );
1772 : /* Generate masking noise for secondary channel */
1773 458 : if ( flag_sec_CNA )
1774 : {
1775 458 : generate_masking_noise( N2, hFdCngCom, hFdCngCom->frameSize, 0, 1, 1, st->element_mode, hStereoCng, nchan_out );
1776 458 : gamma = hStereoCng->c_PS_LT * hStereoCng->c_PS_LT;
1777 458 : scale = 1.0f;
1778 458 : if ( gamma < 0.9f )
1779 : {
1780 458 : gamma = gamma / ( 1 - gamma );
1781 458 : gamma = (float) sqrt( gamma + 1 ) - (float) sqrt( gamma );
1782 458 : scale = 1.0f / (float) sqrt( 1 + gamma * gamma );
1783 : }
1784 : else
1785 : {
1786 0 : gamma = 0.0f;
1787 : }
1788 :
1789 59082 : for ( i = 0; i < 2 * hFdCngCom->frameSize / 4; i++ )
1790 : {
1791 58624 : Np[i] += scale * ( N1[i] + gamma * N2[i] );
1792 58624 : Ns[i] += scale * sign( hStereoCng->c_PS_LT ) * ( N1[i] - gamma * N2[i] );
1793 : }
1794 59082 : for ( ; i < hFdCngCom->frameSize; i++ )
1795 : {
1796 58624 : Np[i] = scale * ( N1[i] + gamma * N2[i] );
1797 58624 : Ns[i] = scale * sign( hStereoCng->c_PS_LT ) * ( N1[i] - gamma * N2[i] );
1798 : }
1799 458 : scale *= (float) ( hFdCngCom->fftlen / 2 );
1800 59082 : for ( i = 0; i < hFdCngCom->frameSize / 2; i++ )
1801 : {
1802 58624 : hFdCngCom->olapBufferSynth2[i] = scale * ( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] + gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4] );
1803 58624 : hStereoCng->olapBufferSynth22[i] = sign( hStereoCng->c_PS_LT ) * scale * ( hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4] - gamma * hStereoCng->olapBufferSynth22[i + 5 * hFdCngCom->frameSize / 4] );
1804 : }
1805 : }
1806 : else
1807 : {
1808 0 : for ( i = 0; i < hFdCngCom->frameSize / 2; i++ )
1809 : {
1810 0 : Np[i] += N1[i];
1811 : }
1812 0 : mvr2r( &N1[hFdCngCom->frameSize / 2], &Np[hFdCngCom->frameSize / 2], hFdCngCom->frameSize / 2 );
1813 0 : scale = (float) ( hFdCngCom->fftlen / 2 );
1814 0 : for ( i = 0; i < hFdCngCom->frameSize; i++ )
1815 : {
1816 0 : hFdCngCom->olapBufferSynth2[i] = scale * hFdCngCom->olapBufferSynth2[i + 5 * hFdCngCom->frameSize / 4];
1817 : }
1818 : }
1819 : }
1820 : else
1821 : {
1822 0 : set_f( hFdCngCom->olapBufferSynth2, 0.0f, hFdCngCom->frameSize / 2 );
1823 0 : set_f( hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize / 2 );
1824 : }
1825 458 : if ( flag_sec_CNA )
1826 : {
1827 458 : mvr2r( Ns, hStereoCng->maskingNoiseS, hFdCngCom->frameSize );
1828 458 : hStereoCng->enableSecCNA = 1;
1829 : }
1830 : else
1831 : {
1832 0 : set_f( hStereoCng->olapBufferSynth22, 0.0f, hFdCngCom->frameSize );
1833 : }
1834 :
1835 : /* add masking noise */
1836 458 : v_add( Np, syn, syn, hFdCngCom->frameSize );
1837 : }
1838 470 : else if ( hStereoCng->enableSecCNA )
1839 : {
1840 458 : SP_ratio = hStereoTD->SP_ratio_LT; /* Use long-term SP ratio based on L/R synthesis */
1841 : /* scale and add masking noise */
1842 29770 : for ( i = 0; i < *hStereoCng->frameSize / 4; i++ )
1843 : {
1844 29312 : scale = ( ( hStereoTD->prevSP_ratio * ( *hStereoCng->frameSize / 4 - (float) i ) + SP_ratio * (float) i ) / ( *hStereoCng->frameSize / 4 ) );
1845 29312 : syn[i] += scale * hStereoCng->maskingNoiseS[i];
1846 : }
1847 29770 : for ( ; i < *hStereoCng->frameSize / 2; i++ )
1848 : {
1849 29312 : syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i];
1850 : }
1851 59082 : for ( ; i < *hStereoCng->frameSize; i++ )
1852 : {
1853 58624 : syn[i] += SP_ratio * hStereoCng->maskingNoiseS[i];
1854 : }
1855 458 : hStereoTD->prevSP_ratio = SP_ratio;
1856 : }
1857 :
1858 928 : return;
1859 : }
1860 :
1861 :
1862 : /*-------------------------------------------------------------------
1863 : * generate_masking_noise_hf_cldfb()
1864 : *
1865 : * Generate additional comfort noise (kind of noise filling)
1866 : *-------------------------------------------------------------------*/
1867 :
1868 41995 : void generate_masking_noise_lb_dirac(
1869 : HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
1870 : float *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */
1871 : const int16_t nCldfbTs, /* i : number of CLDFB slots that will be rendered */
1872 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom, /* i : common spatial rendering parameters handle */
1873 : const int16_t cna_flag /* i : CNA flag for LB and HB */
1874 : )
1875 : {
1876 : int16_t i;
1877 41995 : float *cngNoiseLevel = hFdCngCom->cngNoiseLevel;
1878 41995 : float *fftBuffer = hFdCngCom->fftBuffer;
1879 : float *ptr_r;
1880 : float *ptr_i;
1881 : float *ptr_level;
1882 41995 : int16_t *seed = &( hFdCngCom->seed );
1883 : float scale;
1884 : int16_t n_samples_out, n_samples_start, n_samples_out_loop;
1885 :
1886 41995 : push_wmops( "fd_cng_dirac" );
1887 :
1888 : /* Init */
1889 41995 : scale = 0.f;
1890 41995 : n_samples_out = hFdCngCom->frameSize / DEFAULT_JBM_CLDFB_TIMESLOTS * nCldfbTs;
1891 41995 : n_samples_start = 0;
1892 :
1893 : /*LB CLDFB - CNA from STFT*/
1894 : #ifdef DEBUG_MODE_DIRAC
1895 : {
1896 : int16_t tmp_s;
1897 : tmp_s = (int16_t) ( 32768.f * 0.5f * hFdCngCom->likelihood_noisy_speech * cna_flag + 0.5f );
1898 : dbgwrite( &tmp_s, sizeof( int16_t ), 1, hFdCngCom->frameSize / 16, "./res/ivas_dirac_likelihood_noisy.pcm" );
1899 : }
1900 : #endif
1901 41995 : if ( cna_flag )
1902 : {
1903 : /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
1904 13977 : if ( hFdCngCom->likelihood_noisy_speech > DELTA_MASKING_NOISE )
1905 : {
1906 : /* Compute additional CN level */
1907 7657 : for ( i = 0; i < 15; i++ )
1908 : {
1909 7657 : if ( ( hFdCngCom->CngBandwidth == scaleTable_cn_dirac[i].bwmode ) &&
1910 1767 : ( hFdCngCom->CngBitrate >= scaleTable_cn_dirac[i].bitrateFrom ) &&
1911 1767 : ( hFdCngCom->CngBitrate < scaleTable_cn_dirac[i].bitrateTo ) )
1912 : {
1913 589 : break;
1914 : }
1915 : }
1916 :
1917 589 : scale = (float) pow( 10.f, -scaleTable_cn_dirac[i].scale / 10.f ) - 1.f;
1918 589 : scale *= hFdCngCom->likelihood_noisy_speech;
1919 : }
1920 : }
1921 :
1922 : /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/
1923 41995 : if ( cna_flag && tdBuffer != NULL )
1924 : {
1925 : int16_t cur_subframe;
1926 : int16_t cur_subframe_start_outfs;
1927 : int16_t cur_subframe_start_cngfs;
1928 : int16_t slot_size_cng;
1929 :
1930 27954 : while ( n_samples_out > 0 )
1931 : {
1932 13977 : n_samples_out_loop = min( hFdCngCom->frameSize, n_samples_out );
1933 13977 : if ( scale != 0 )
1934 : {
1935 : /*Generate LF comfort noise only at first slot, for the whole frame*/
1936 589 : ptr_level = cngNoiseLevel;
1937 :
1938 : /* Generate Gaussian random noise in real and imaginary parts of the FFT bins
1939 : Amplitudes are adjusted to the estimated noise level cngNoiseLevel in each bin */
1940 589 : if ( hFdCngCom->startBand == 0 )
1941 : {
1942 0 : rand_gauss( &fftBuffer[0], seed );
1943 0 : ptr_r = fftBuffer + 2;
1944 0 : fftBuffer[0] *= (float) sqrt( scale * *ptr_level ); /* DC component in FFT */
1945 0 : ptr_level++;
1946 : }
1947 : else
1948 : {
1949 589 : fftBuffer[0] = 0.f;
1950 589 : set_f( fftBuffer + 2, 0.0f, 2 * ( hFdCngCom->startBand - 1 ) );
1951 589 : ptr_r = fftBuffer + 2 * hFdCngCom->startBand;
1952 : }
1953 589 : ptr_i = ptr_r + 1;
1954 :
1955 187891 : for ( ; ptr_level < cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand; ptr_level++ )
1956 : {
1957 : /* Real part in FFT bins */
1958 187302 : rand_gauss( ptr_r, seed );
1959 187302 : ( *ptr_r ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1960 187302 : ptr_r += 2;
1961 : /* Imaginary part in FFT bins */
1962 187302 : rand_gauss( ptr_i, seed );
1963 187302 : ( *ptr_i ) *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
1964 187302 : ptr_i += 2;
1965 : }
1966 :
1967 : /* Remaining FFT bins are set to zero */
1968 589 : set_f( fftBuffer + 2 * hFdCngCom->stopFFTbin, 0.0f, hFdCngCom->fftlen - 2 * hFdCngCom->stopFFTbin );
1969 : /* Nyquist frequency is discarded */
1970 589 : fftBuffer[1] = 0.f;
1971 :
1972 : /* Perform STFT synthesis */
1973 589 : SynthesisSTFT_dirac( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, n_samples_out_loop, hFdCngCom );
1974 :
1975 : #ifdef DEBUG_MODE_DIRAC
1976 : {
1977 : int16_t tmp[1000];
1978 :
1979 : for ( i = 0; i < hFdCngCom->frameSize; i++ )
1980 : {
1981 : tmp[i] = (int16_t) ( tdBuffer[i] + 0.5f );
1982 : }
1983 : dbgwrite( tmp, sizeof( int16_t ), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm" );
1984 : }
1985 : #endif
1986 : }
1987 :
1988 : else
1989 : {
1990 : /* very low level case - update random seeds */
1991 13388 : generate_masking_noise_update_seed( hFdCngCom );
1992 :
1993 13388 : set_f( fftBuffer, 0.f, hFdCngCom->fftlen );
1994 :
1995 : /* Perform STFT synthesis */
1996 13388 : SynthesisSTFT_dirac( fftBuffer, tdBuffer + n_samples_start, hFdCngCom->olapBufferSynth2, hFdCngCom->olapWinSyn, n_samples_out_loop, hFdCngCom );
1997 :
1998 : #ifdef DEBUG_MODE_DIRAC
1999 : {
2000 : int16_t tmp[1000];
2001 :
2002 : for ( i = 0; i < hFdCngCom->frameSize; i++ )
2003 : {
2004 : tmp[i] = (int16_t) ( tdBuffer[i] + 0.5f );
2005 : }
2006 : dbgwrite( tmp, sizeof( int16_t ), hFdCngCom->frameSize, 1, "./res/ivas_dirac_cna_fft.pcm" );
2007 : }
2008 : #endif
2009 : }
2010 13977 : n_samples_out -= hFdCngCom->frameSize;
2011 13977 : n_samples_start += hFdCngCom->frameSize;
2012 : }
2013 :
2014 : /* move generated noise to the 5ms subframe starts in the tc buffer according to the output sampling frequency to avoid
2015 : overwriting it with the synthesis in case of shared tc and synth channel memory, i.e. non-TSM mode */
2016 13977 : slot_size_cng = hFdCngCom->frameSize / DEFAULT_JBM_CLDFB_TIMESLOTS;
2017 : /* move start indices forward to the end of the last subframe */
2018 13977 : cur_subframe_start_outfs = nCldfbTs * hSpatParamRendCom->slot_size;
2019 13977 : cur_subframe_start_cngfs = nCldfbTs * slot_size_cng;
2020 :
2021 : /* go from the last subframe back and move the LB noise */
2022 69885 : for ( cur_subframe = hSpatParamRendCom->nb_subframes - 1; cur_subframe >= 0; cur_subframe-- )
2023 : {
2024 : int16_t move_size, subframe_size_outfs;
2025 55908 : move_size = slot_size_cng * hSpatParamRendCom->subframe_nbslots[cur_subframe];
2026 55908 : subframe_size_outfs = hSpatParamRendCom->subframe_nbslots[cur_subframe] * hSpatParamRendCom->slot_size;
2027 55908 : cur_subframe_start_outfs -= hSpatParamRendCom->subframe_nbslots[cur_subframe] * hSpatParamRendCom->slot_size;
2028 55908 : cur_subframe_start_cngfs -= hSpatParamRendCom->subframe_nbslots[cur_subframe] * slot_size_cng;
2029 : /* move cna */
2030 55908 : mvr2r( tdBuffer + cur_subframe_start_cngfs, tdBuffer + cur_subframe_start_outfs, move_size );
2031 : /* set everything else to zero */
2032 55908 : set_zero( tdBuffer + cur_subframe_start_outfs + move_size, subframe_size_outfs - move_size );
2033 : }
2034 : }
2035 :
2036 :
2037 41995 : pop_wmops();
2038 :
2039 41995 : return;
2040 : }
2041 :
2042 :
2043 : /*-------------------------------------------------------------------
2044 : * generate_masking_noise_hf_cldfb()
2045 : *
2046 : * Generate additional comfort noise (kind of noise filling)
2047 : *-------------------------------------------------------------------*/
2048 :
2049 1295840 : void generate_masking_noise_dirac(
2050 : HANDLE_FD_CNG_COM hFdCngCom, /* i/o: FD_CNG structure containing all buffers and variables */
2051 : HANDLE_CLDFB_FILTER_BANK h_cldfb, /* i : filterbank state */
2052 : float *tdBuffer, /* i/o: time-domain signal, if NULL no LB-CNA */
2053 : float *Cldfb_RealBuffer, /* o : CLDFD real buffer */
2054 : float *Cldfb_ImagBuffer, /* o : CLDFD imaginary buffer */
2055 : const int16_t slot_index, /* i : CLDFB slot index */
2056 : const int16_t cna_flag, /* i : CNA flag for LB and HB */
2057 : const int16_t fd_cng_flag /* i : FD-CNG flag for HB */
2058 : )
2059 : {
2060 : int16_t i;
2061 : float *ptr_level;
2062 1295840 : int16_t *seed = &( hFdCngCom->seed );
2063 : float scale;
2064 :
2065 1295840 : push_wmops( "fd_cng_dirac" );
2066 :
2067 : /* Init */
2068 1295840 : scale = 0.f;
2069 :
2070 : /* Resample CLDFB memories if necessary*/
2071 1295840 : if ( ( h_cldfb->no_channels * h_cldfb->no_col ) != hFdCngCom->frameSize )
2072 : {
2073 775 : resampleCldfb( h_cldfb, hFdCngCom->frameSize * FRAMES_PER_SEC );
2074 : }
2075 :
2076 1295840 : set_zero( Cldfb_RealBuffer, CLDFB_NO_CHANNELS_MAX );
2077 1295840 : set_zero( Cldfb_ImagBuffer, CLDFB_NO_CHANNELS_MAX );
2078 :
2079 : /*LB CLDFB - CNA from STFT*/
2080 : #ifdef DEBUG_MODE_DIRAC
2081 : {
2082 : int16_t tmp_s;
2083 : tmp_s = (int16_t) ( 32768.f * 0.5f * hFdCngCom->likelihood_noisy_speech * cna_flag + 0.5f );
2084 : dbgwrite( &tmp_s, sizeof( int16_t ), 1, hFdCngCom->frameSize / 16, "./res/ivas_dirac_likelihood_noisy.pcm" );
2085 : }
2086 : #endif
2087 1295840 : if ( cna_flag )
2088 : {
2089 : /* skip noise generating if level is very low, to avoid problems with possibly running into denormals */
2090 416528 : if ( hFdCngCom->likelihood_noisy_speech > DELTA_MASKING_NOISE )
2091 : {
2092 : /* Compute additional CN level */
2093 245024 : for ( i = 0; i < 15; i++ )
2094 : {
2095 245024 : if ( ( hFdCngCom->CngBandwidth == scaleTable_cn_dirac[i].bwmode ) &&
2096 56544 : ( hFdCngCom->CngBitrate >= scaleTable_cn_dirac[i].bitrateFrom ) &&
2097 56544 : ( hFdCngCom->CngBitrate < scaleTable_cn_dirac[i].bitrateTo ) )
2098 : {
2099 18848 : break;
2100 : }
2101 : }
2102 :
2103 18848 : scale = (float) pow( 10.f, -scaleTable_cn_dirac[i].scale / 10.f ) - 1.f;
2104 18848 : scale *= hFdCngCom->likelihood_noisy_speech;
2105 : }
2106 : }
2107 : /* LB CLDFB - CNA from STFT: CNA applied only in channel 0*/
2108 1295840 : if ( cna_flag && tdBuffer != NULL )
2109 : {
2110 223632 : if ( scale != 0 )
2111 : {
2112 : /* LF CLDFB*/
2113 9424 : cldfbAnalysis_ts( &( tdBuffer[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb );
2114 : }
2115 : else
2116 : {
2117 : /* LB ana CLDFB*/
2118 214208 : cldfbAnalysis_ts( &( tdBuffer[hFdCngCom->numCoreBands * slot_index] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, hFdCngCom->numCoreBands, h_cldfb );
2119 : }
2120 : }
2121 :
2122 : /*HF CLDFB - CNA and/or FD-CNG*/
2123 1295840 : if ( fd_cng_flag )
2124 : {
2125 9696 : scale += 1.f;
2126 : }
2127 1295840 : if ( scale != 0 )
2128 : {
2129 21888 : scale *= CLDFB_SCALING * ( h_cldfb->scale * h_cldfb->scale * 8.f );
2130 21888 : ptr_level = hFdCngCom->cngNoiseLevel + hFdCngCom->stopFFTbin - hFdCngCom->startBand;
2131 :
2132 459648 : for ( i = hFdCngCom->numCoreBands; i < hFdCngCom->regularStopBand; i++ )
2133 : {
2134 : /* Real part in CLDFB band */
2135 437760 : rand_gauss( &Cldfb_RealBuffer[i], seed );
2136 437760 : Cldfb_RealBuffer[i] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
2137 : /* Imaginary part in CLDFB band */
2138 437760 : rand_gauss( &Cldfb_ImagBuffer[i], seed );
2139 437760 : Cldfb_ImagBuffer[i] *= (float) sqrt( ( scale * *ptr_level ) * 0.5f );
2140 :
2141 437760 : ptr_level++;
2142 : }
2143 : }
2144 :
2145 1295840 : pop_wmops();
2146 :
2147 1295840 : return;
2148 : }
2149 :
2150 :
2151 : /*-------------------------------------------------------------------
2152 : * FdCngDecodeMDCTStereoSID()
2153 : *
2154 : * Decode FD-Cng parameters for CNG in MDCT-Stereo mode from the bitstream
2155 : *
2156 : *-------------------------------------------------------------------*/
2157 :
2158 401 : void FdCngDecodeMDCTStereoSID(
2159 : CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
2160 : )
2161 : {
2162 : DEC_CORE_HANDLE sts[CPE_CHANNELS];
2163 : HANDLE_FD_CNG_COM hFdCngCom;
2164 : float *ms_ptr[CPE_CHANNELS];
2165 : float *lr_ptr[CPE_CHANNELS];
2166 : float logNoiseEst[CPE_CHANNELS][NPART];
2167 : float gain[CPE_CHANNELS];
2168 : int16_t indices[FD_CNG_stages_37bits];
2169 : int16_t N, i, ch, p, stages;
2170 : int16_t is_out_ms;
2171 : float *invTrfMatrix;
2172 : float tmpRAM[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
2173 : int32_t tmp;
2174 :
2175 401 : invTrfMatrix = (float *) tmpRAM;
2176 401 : create_IDCT_N_Matrix( invTrfMatrix, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM ) / ( sizeof( float ) ) );
2177 :
2178 401 : is_out_ms = 0;
2179 401 : if ( hCPE->hCoreCoder[0]->cng_sba_flag )
2180 : {
2181 0 : is_out_ms = 1;
2182 : }
2183 :
2184 401 : N = 0; /* to avoid compilation warning */
2185 :
2186 1203 : for ( ch = 0; ch < CPE_CHANNELS; ch++ )
2187 : {
2188 802 : sts[ch] = hCPE->hCoreCoder[ch];
2189 802 : ms_ptr[ch] = &logNoiseEst[ch][0];
2190 802 : lr_ptr[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0];
2191 : }
2192 :
2193 : /* decode noise shapes and gains */
2194 1203 : for ( ch = 0; ch < CPE_CHANNELS; ch++ )
2195 : {
2196 802 : sts[ch] = hCPE->hCoreCoder[ch];
2197 802 : hFdCngCom = ( sts[ch]->hFdCngDec )->hFdCngCom;
2198 802 : N = hFdCngCom->npart;
2199 802 : hFdCngCom->sid_frame_counter++;
2200 :
2201 802 : if ( ch )
2202 : {
2203 401 : stages = FD_CNG_JOINT_stages_25bits;
2204 : }
2205 : else
2206 : {
2207 401 : stages = FD_CNG_stages_37bits;
2208 : }
2209 :
2210 : /* read bitstream */
2211 4812 : for ( i = 0; i < stages; i++ )
2212 : {
2213 4010 : indices[i] = get_next_indice( sts[ch], bits_37bits[i] );
2214 : }
2215 : {
2216 802 : gain[ch] = ( (float) get_next_indice( sts[ch], 7 ) - GAIN_Q_OFFSET_IVAS ) / 1.5f;
2217 : }
2218 :
2219 : /* MSVQ decoder */
2220 802 : msvq_dec( cdk_37bits_ivas, NULL, NULL, stages, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix, ms_ptr[ch], NULL );
2221 : }
2222 :
2223 401 : tmp = sts[1]->total_brate;
2224 401 : sts[1]->total_brate = sts[1]->total_brate + 16 * FRAMES_PER_SEC;
2225 : /* read the four additional coherence values */
2226 2005 : for ( int16_t b = 1; b < MDCT_ST_DTX_NUM_COHERENCE_BANDS; b++ )
2227 : {
2228 : uint16_t tmp_bit;
2229 :
2230 1604 : tmp_bit = get_next_indice( sts[1], 4 );
2231 1604 : sts[0]->hFdCngDec->hFdCngCom->coherence[b] = (float) tmp_bit / 15.f;
2232 1604 : sts[1]->hFdCngDec->hFdCngCom->coherence[b] = sts[0]->hFdCngDec->hFdCngCom->coherence[b];
2233 : }
2234 401 : sts[1]->total_brate = tmp;
2235 :
2236 401 : if ( sts[0]->hFdCngDec->hFdCngCom->no_side_flag )
2237 : {
2238 11 : set_zero( ms_ptr[1], NPART );
2239 : }
2240 :
2241 401 : if ( is_out_ms == 0 )
2242 : {
2243 401 : inverseMS( N, ms_ptr[0], ms_ptr[1], 1.f );
2244 : }
2245 :
2246 1203 : for ( ch = 0; ch < CPE_CHANNELS; ch++ )
2247 : {
2248 802 : hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom;
2249 19018 : for ( p = 0; p < N; p++ )
2250 : {
2251 18216 : lr_ptr[ch][p] = powf( 10.f, ( ms_ptr[ch][p] + gain[ch] ) / 10.f );
2252 : }
2253 :
2254 802 : scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 );
2255 :
2256 802 : lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac );
2257 : }
2258 :
2259 401 : if ( hCPE->nchan_out == 1 && hCPE->last_element_brate <= IVAS_SID_5k2 )
2260 : {
2261 : /* create proper M noise shape in channel zero after gains have been applied */
2262 2648 : for ( p = 0; p < N; p++ )
2263 : {
2264 2538 : sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * ( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p] );
2265 : }
2266 : }
2267 :
2268 401 : return;
2269 : }
2270 :
2271 :
2272 : /*-------------------------------------------------------------------
2273 : * FdCngDecodeDiracMDCTStereoSID()
2274 : *
2275 : * Decode FD-CNG parameters for CNG in 2TC DirAC mode from the bitstream
2276 : *-------------------------------------------------------------------*/
2277 :
2278 101 : void FdCngDecodeDiracMDCTStereoSID(
2279 : CPE_DEC_HANDLE hCPE /* i/o: CPE decoder state structure */
2280 : )
2281 : {
2282 : DEC_CORE_HANDLE sts[CPE_CHANNELS];
2283 : HANDLE_FD_CNG_COM hFdCngCom;
2284 : float *ms_ptr[CPE_CHANNELS];
2285 : float *lr_ptr[CPE_CHANNELS];
2286 : float logNoiseEst[CPE_CHANNELS][NPART];
2287 : float gain[CPE_CHANNELS];
2288 : int16_t indices[FD_CNG_stages_37bits];
2289 : int16_t N, i, ch, p;
2290 : float *invTrfMatrix;
2291 : float tmpRAM[FDCNG_VQ_MAX_LEN][FDCNG_VQ_DCT_MAXTRUNC];
2292 :
2293 :
2294 101 : invTrfMatrix = (float *) tmpRAM; /* dynamically filled */
2295 101 : create_IDCT_N_Matrix( invTrfMatrix, FDCNG_VQ_MAX_LEN, FDCNG_VQ_DCT_MAXTRUNC, sizeof( tmpRAM ) / ( sizeof( float ) ) );
2296 :
2297 303 : for ( ch = 0; ch < CPE_CHANNELS; ch++ )
2298 : {
2299 202 : sts[ch] = hCPE->hCoreCoder[ch];
2300 202 : ms_ptr[ch] = &logNoiseEst[ch][0];
2301 202 : lr_ptr[ch] = &sts[ch]->hFdCngDec->hFdCngCom->sidNoiseEst[0];
2302 202 : ( sts[ch]->hFdCngDec )->hFdCngCom->sid_frame_counter++;
2303 : }
2304 :
2305 : /* decode noise shapes and gains */
2306 101 : hFdCngCom = ( sts[0]->hFdCngDec )->hFdCngCom;
2307 101 : N = hFdCngCom->npart;
2308 :
2309 : /* read bitstream */
2310 707 : for ( i = 0; i < FD_CNG_stages_37bits; i++ )
2311 : {
2312 606 : indices[i] = get_next_indice( sts[0], bits_37bits[i] );
2313 : }
2314 101 : gain[0] = ( (float) get_next_indice( sts[0], 7 ) - GAIN_Q_OFFSET_IVAS ) / 1.5f;
2315 101 : gain[1] = gain[0];
2316 :
2317 : /* MSVQ decoder */
2318 101 : msvq_dec( cdk_37bits_ivas, NULL, NULL, FD_CNG_stages_37bits, N, FD_CNG_maxN_37bits, indices, 1, invTrfMatrix, ms_ptr[0], NULL );
2319 101 : mvr2r( ms_ptr[0], ms_ptr[1], N );
2320 :
2321 : /*inverseMS( N, ms_ptr[0], ms_ptr[1], 1.f );*/
2322 :
2323 303 : for ( ch = 0; ch < CPE_CHANNELS; ch++ )
2324 : {
2325 202 : hFdCngCom = sts[ch]->hFdCngDec->hFdCngCom;
2326 5050 : for ( p = 0; p < N; p++ )
2327 : {
2328 4848 : lr_ptr[ch][p] = powf( 10.f, ( ms_ptr[ch][p] + gain[ch] ) / 10.f );
2329 : }
2330 :
2331 : /* NB last band energy compensation */
2332 202 : if ( hFdCngCom->CngBandwidth == NB )
2333 : {
2334 0 : lr_ptr[ch][N - 1] *= NB_LAST_BAND_SCALE;
2335 : }
2336 202 : else if ( hFdCngCom->CngBandwidth == SWB && hFdCngCom->CngBitrate <= ACELP_13k20 )
2337 : {
2338 0 : lr_ptr[ch][N - 1] *= SWB_13k2_LAST_BAND_SCALE;
2339 : }
2340 :
2341 202 : scalebands( hFdCngCom->sidNoiseEst, hFdCngCom->part, hFdCngCom->npart, hFdCngCom->midband, hFdCngCom->nFFTpart, hFdCngCom->stopBand - hFdCngCom->startBand, hFdCngCom->cngNoiseLevel, 1 );
2342 :
2343 202 : lpc_from_spectrum( hFdCngCom, hFdCngCom->startBand, hFdCngCom->stopFFTbin, sts[ch]->preemph_fac );
2344 : }
2345 :
2346 606 : for ( i = 0; i < MDCT_ST_DTX_NUM_COHERENCE_BANDS; i++ )
2347 : {
2348 505 : sts[0]->hFdCngDec->hFdCngCom->coherence[i] = 0.0f;
2349 505 : sts[1]->hFdCngDec->hFdCngCom->coherence[i] = 0.0f;
2350 : }
2351 :
2352 101 : if ( hCPE->nchan_out == 1 )
2353 : {
2354 : /* create proper M noise shape in channel zero after gains have been applied */
2355 0 : for ( p = 0; p < N; p++ )
2356 : {
2357 0 : sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] = 0.5f * ( sts[0]->hFdCngDec->hFdCngCom->sidNoiseEst[p] + sts[1]->hFdCngDec->hFdCngCom->sidNoiseEst[p] );
2358 : }
2359 : }
2360 :
2361 101 : return;
2362 : }
|