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 : #include <stdint.h>
34 : #include "options.h"
35 : #include <math.h>
36 : #include "ivas_prot.h"
37 : #include "prot.h"
38 : #include "ivas_cnst.h"
39 : #include "isar_prot.h"
40 : #ifdef DEBUGGING
41 : #include "debug.h"
42 : #endif
43 : #include "wmc_auto.h"
44 :
45 :
46 : /*-------------------------------------------------------------------------
47 : * Local constants
48 : *------------------------------------------------------------------------*/
49 :
50 : #define START_VAL_AVG_LEN 2
51 : #define SR_PLC_FADE_START 10 /* start fading at this number of bad frames in row */
52 : #define SR_PLC_MUTE 30 /* Total mute at this number of bad frames in row */
53 : #define SR_PLC_FADE_DEGREE -3 /* fading degree per frame in dB */
54 : #define SRHO_THRESH ( 2.f / 3.f * 0.1f )
55 : #define STH_THRESH ( 2.f / 3.f * PI2 / 12 )
56 :
57 :
58 : /*-------------------------------------------------------------------------
59 : * Function adaptive_polar_ext_plc()
60 : *
61 : *
62 : *------------------------------------------------------------------------*/
63 :
64 30720 : static void adaptive_polar_ext_plc(
65 : const float *prev_real,
66 : const float *prev_imag,
67 : float *rec_real,
68 : float *rec_imag,
69 : float xf_alp[CLDFB_PLC_XF],
70 : float xf_bet[CLDFB_PLC_XF],
71 : const int16_t iNumCols )
72 : {
73 : float uth[CLDFB_NO_COL_MAX], uthu[CLDFB_NO_COL_MAX], urh[CLDFB_NO_COL_MAX];
74 : float ph_adj, ph_diff, ph_adj_t, quot, drho, srho, diff, dth, sth, fac_real, fac_imag;
75 : float Ruu_real[2], Ruu_imag[2];
76 : float start_real, start_imag, abs_fac, abs_fac_powj, comp_fac, fac_powj_real, fac_powj_imag, temp, abs2inv;
77 : float fac_ph_real, fac_ph_imag, rat_real, rat_imag, abs_temp;
78 : int32_t k, j;
79 :
80 : /* reset of accumulators */
81 30720 : ph_adj = 0.0f;
82 30720 : drho = 0.0f;
83 30720 : srho = 0.0f;
84 30720 : dth = 0.0f;
85 30720 : sth = 0.0f;
86 :
87 : /* calculate per-sample phase and magnitude evolution in preceding frame */
88 284766 : for ( k = 0; k < iNumCols; k++ )
89 : {
90 273410 : urh[k] = sqrtf( prev_imag[k] * prev_imag[k] + prev_real[k] * prev_real[k] );
91 273410 : if ( urh[k] < EPSILON )
92 : {
93 : /* zero encountered */
94 19364 : break;
95 : }
96 254046 : uth[k] = atan2f( prev_imag[k], prev_real[k] );
97 :
98 : /* phase unwrap */
99 254046 : if ( k == 0 )
100 : {
101 22814 : uthu[0] = uth[0];
102 : }
103 : else
104 : {
105 : /* phase unwrap */
106 231232 : ph_diff = uth[k] - uth[k - 1];
107 231232 : uthu[k] = uth[k];
108 231232 : if ( fabsf( ph_diff ) >= PI2 / 2 )
109 : {
110 60171 : ph_adj_t = ph_diff / PI2;
111 60171 : if ( fabsf( ph_adj_t - truncf( ph_adj_t ) ) == 0.5f )
112 : {
113 4475 : ph_adj_t = truncf( ph_adj_t );
114 : }
115 60171 : ph_adj = -PI2 * roundf( ph_adj_t ) + ph_adj;
116 : }
117 231232 : uthu[k] += ph_adj;
118 : /* unwrapped phase in uthu */
119 :
120 : /* mean and stdev of per-sample magnitude ratios */
121 231232 : quot = urh[k] / urh[k - 1];
122 231232 : drho += quot;
123 231232 : srho += SQR( quot );
124 : /* mean and stdev of per-sample phase differences */
125 231232 : diff = uthu[k] - uthu[k - 1]; /* the mean value calculation could be optimized */
126 231232 : dth += diff;
127 231232 : sth += SQR( diff );
128 : }
129 : }
130 :
131 30720 : if ( k == iNumCols )
132 : {
133 : /* mean and stdev of per-sample magnitude ratios */
134 11356 : drho *= 1.0f / ( iNumCols - 1 );
135 11356 : temp = srho - ( iNumCols - 1 ) * SQR( drho );
136 11356 : if ( temp > 0 )
137 : {
138 11237 : srho = sqrtf( temp * ( 1.0f / ( iNumCols - 2 ) ) );
139 : }
140 : else
141 : {
142 119 : srho = 0.0f;
143 : }
144 :
145 : /* mean and stdev of per-sample phase differences */
146 11356 : dth *= 1.0f / ( iNumCols - 1 );
147 11356 : temp = sth - ( iNumCols - 1 ) * SQR( dth );
148 11356 : if ( temp > 0 )
149 : {
150 11356 : sth = sqrtf( temp * ( 1.0f / ( iNumCols - 2 ) ) );
151 : }
152 : else
153 : {
154 0 : sth = 0.0f;
155 : }
156 :
157 : /* do phase extension only if the std deviations are small */
158 11356 : if ( ( srho < SRHO_THRESH ) || ( sth < STH_THRESH ) )
159 : {
160 : /* calculate complex evolution factor */
161 255 : fac_ph_real = cosf( dth );
162 255 : fac_ph_imag = sinf( dth );
163 255 : fac_real = min( 1, drho ) * fac_ph_real;
164 255 : fac_imag = min( 1, drho ) * fac_ph_imag;
165 :
166 : /* Calculate start value for evolution from last samples of previous frame */
167 255 : fac_powj_real = fac_real;
168 255 : fac_powj_imag = fac_imag;
169 255 : start_real = prev_real[iNumCols - 1];
170 255 : start_imag = prev_imag[iNumCols - 1];
171 510 : for ( j = 1; j < START_VAL_AVG_LEN; j++ )
172 : {
173 255 : start_real += fac_powj_real * prev_real[iNumCols - j - 1] - fac_powj_imag * prev_imag[iNumCols - j - 1];
174 255 : start_imag += fac_powj_imag * prev_real[iNumCols - j - 1] + fac_powj_real * prev_imag[iNumCols - j - 1];
175 255 : temp = fac_powj_real * fac_real - fac_powj_imag * fac_imag;
176 255 : fac_powj_imag = fac_powj_imag * fac_real + fac_powj_real * fac_imag;
177 255 : fac_powj_real = temp;
178 : }
179 255 : start_real *= 1.0f / START_VAL_AVG_LEN;
180 255 : start_imag *= 1.0f / START_VAL_AVG_LEN;
181 :
182 : /* make evolution less static: apply per samples differences as in preceding frame */
183 255 : rat_real = ( prev_real[1] * prev_real[0] + prev_imag[1] * prev_imag[0] );
184 255 : rat_imag = ( -prev_real[1] * prev_imag[0] + prev_imag[1] * prev_real[0] );
185 :
186 : /* only phase perturbation */
187 255 : abs_temp = sqrtf( SQR( rat_real ) + SQR( rat_imag ) );
188 255 : abs2inv = min( 1, drho ) / max( EPSILON, abs_temp );
189 255 : rat_real *= abs2inv;
190 255 : rat_imag *= abs2inv;
191 :
192 : /* apply complex evolution for first substitution sample */
193 255 : rec_real[0] = rat_real * start_real - rat_imag * start_imag;
194 255 : rec_imag[0] = rat_imag * start_real + rat_real * start_imag;
195 3825 : for ( j = 2; j < iNumCols; j++ )
196 : {
197 : /* make evolution less static: apply per samples differences as in preceding frame */
198 3570 : rat_real = ( prev_real[j] * prev_real[j - 1] + prev_imag[j] * prev_imag[j - 1] );
199 3570 : rat_imag = ( -prev_real[j] * prev_imag[j - 1] + prev_imag[j] * prev_real[j - 1] );
200 :
201 : /* only phase perturbation */
202 3570 : abs_temp = sqrtf( SQR( rat_real ) + SQR( rat_imag ) );
203 3570 : abs2inv = min( 1, drho ) / max( EPSILON, abs_temp );
204 :
205 3570 : rat_real *= abs2inv;
206 3570 : rat_imag *= abs2inv;
207 : /* apply complex evolution for further substitution samples */
208 3570 : rec_real[j - 1] = rat_real * rec_real[j - 2] - rat_imag * rec_imag[j - 2];
209 3570 : rec_imag[j - 1] = rat_imag * rec_real[j - 2] + rat_real * rec_imag[j - 2];
210 : }
211 :
212 : /* do the same for samples of crossfade region */
213 1020 : for ( j = 1; j < CLDFB_PLC_XF + 2; j++ )
214 : {
215 765 : rat_real = ( prev_real[j] * prev_real[j - 1] + prev_imag[j] * prev_imag[j - 1] );
216 765 : rat_imag = ( -prev_real[j] * prev_imag[j - 1] + prev_imag[j] * prev_real[j - 1] );
217 :
218 765 : abs_temp = sqrtf( SQR( rat_real ) + SQR( rat_imag ) );
219 765 : abs2inv = min( 1, drho ) / max( EPSILON, abs_temp );
220 :
221 765 : rat_real *= abs2inv;
222 765 : rat_imag *= abs2inv;
223 765 : rec_real[j + iNumCols - 2] = rat_real * rec_real[j + iNumCols - 3] - rat_imag * rec_imag[j + iNumCols - 3];
224 765 : rec_imag[j + iNumCols - 2] = rat_imag * rec_real[j + iNumCols - 3] + rat_real * rec_imag[j + iNumCols - 3];
225 : }
226 :
227 :
228 : /* apply crossfade */
229 765 : for ( j = 0; j < CLDFB_PLC_XF; j++ )
230 : {
231 510 : rec_real[iNumCols + j] *= xf_alp[j];
232 510 : rec_imag[iNumCols + j] *= xf_alp[j];
233 510 : xf_bet[j] = 1 - xf_alp[j];
234 : }
235 : }
236 : else
237 : {
238 : /* do complex lpc combined with frame repetition */
239 11101 : Ruu_real[0] = SQR( prev_real[0] ) + SQR( prev_imag[0] );
240 11101 : Ruu_real[1] = 0;
241 11101 : Ruu_imag[1] = 0;
242 177616 : for ( j = 1; j < iNumCols; j++ )
243 : {
244 166515 : Ruu_real[0] += SQR( prev_real[j] ) + SQR( prev_imag[j] );
245 166515 : Ruu_real[1] += prev_real[j] * prev_real[j - 1] + prev_imag[j] * prev_imag[j - 1];
246 166515 : Ruu_imag[1] += prev_imag[j] * prev_real[j - 1] - prev_real[j] * prev_imag[j - 1];
247 : }
248 11101 : if ( Ruu_real[0] > EPSILON )
249 : {
250 : /* prediction coefficient */
251 11101 : fac_real = Ruu_real[1] / Ruu_real[0];
252 11101 : fac_imag = Ruu_imag[1] / Ruu_real[0];
253 : }
254 : else
255 : {
256 0 : fac_real = 0;
257 0 : fac_imag = 0;
258 : }
259 :
260 : /* apply prediction using last sample of preceding frame as start value and combine with previous frame samples */
261 11101 : fac_powj_real = fac_real;
262 11101 : fac_powj_imag = fac_imag;
263 11101 : abs_fac = sqrtf( SQR( fac_real ) + SQR( fac_imag ) );
264 11101 : abs_fac_powj = abs_fac;
265 188717 : for ( j = 0; j < iNumCols; j++ )
266 : {
267 177616 : comp_fac = 1 - abs_fac_powj;
268 177616 : rec_real[j] = prev_real[iNumCols - 1] * fac_powj_real - prev_imag[iNumCols - 1] * fac_powj_imag +
269 177616 : prev_real[j] * comp_fac;
270 177616 : rec_imag[j] = prev_real[iNumCols - 1] * fac_powj_imag + prev_imag[iNumCols - 1] * fac_powj_real +
271 177616 : prev_imag[j] * comp_fac;
272 177616 : abs_fac_powj = abs_fac_powj * abs_fac;
273 177616 : temp = fac_powj_real * fac_real - fac_powj_imag * fac_imag;
274 177616 : fac_powj_imag = fac_powj_real * fac_imag + fac_powj_imag * fac_real;
275 177616 : fac_powj_real = temp;
276 : }
277 :
278 : /* prepare XF to next frame using prediction */
279 11101 : fac_powj_real = fac_real;
280 11101 : fac_powj_imag = fac_imag;
281 11101 : abs_fac_powj = abs_fac;
282 33303 : for ( j = 0; j < CLDFB_PLC_XF; j++ )
283 : {
284 22202 : xf_bet[j] = 1 - abs_fac_powj;
285 22202 : rec_real[j + iNumCols] = rec_real[iNumCols - 1] * fac_powj_real - rec_imag[iNumCols - 1] * fac_powj_imag;
286 22202 : rec_imag[j + iNumCols] = rec_real[iNumCols - 1] * fac_powj_imag + rec_imag[iNumCols - 1] * fac_powj_real;
287 22202 : abs_fac_powj = abs_fac_powj * abs_fac;
288 22202 : temp = fac_powj_real * fac_real - fac_powj_imag * fac_imag;
289 22202 : fac_powj_imag = fac_powj_real * fac_imag + fac_powj_imag * fac_real;
290 22202 : fac_powj_real = temp;
291 : }
292 : }
293 : }
294 : else
295 : {
296 329188 : for ( j = 0; j < iNumCols; j++ )
297 : {
298 309824 : rec_real[j] = prev_real[j];
299 309824 : rec_imag[j] = prev_imag[j];
300 : }
301 58092 : for ( j = 0; j < CLDFB_PLC_XF; j++ )
302 : {
303 38728 : xf_bet[j] = 1;
304 38728 : rec_real[j + iNumCols] = 0;
305 38728 : rec_imag[j + iNumCols] = 0;
306 : }
307 : }
308 :
309 30720 : return;
310 : }
311 :
312 :
313 : /*-------------------------------------------------------------------------
314 : * Function isar_splitBinRendPLCOpen()
315 : *
316 : *
317 : *------------------------------------------------------------------------*/
318 :
319 2098 : ivas_error isar_splitBinRendPLCOpen(
320 : ISAR_SPLIT_REND_PLC_HANDLE *phSplitRendPLC, /* i/o: ISAR PLC handle */
321 : const int16_t iNumSubSets )
322 : {
323 : ivas_error error;
324 : ISAR_SPLIT_REND_PLC_HANDLE hSplitRendPLC;
325 :
326 2098 : error = IVAS_ERR_OK;
327 2098 : if ( ( hSplitRendPLC = (ISAR_SPLIT_REND_PLC_HANDLE) malloc( sizeof( SPLIT_REND_PLC_STRUCT ) ) ) == NULL )
328 : {
329 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for bin split renderer PLC Module \n" ) );
330 : }
331 :
332 2098 : hSplitRendPLC->prev_bfi = 0;
333 2098 : hSplitRendPLC->bf_count = 0;
334 2098 : hSplitRendPLC->iNumSubSets = iNumSubSets;
335 2098 : set_zero( &hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinReal[0][0][0], 2 * ( CLDFB_NO_COL_MAX + CLDFB_PLC_XF ) * CLDFB_NO_CHANNELS_MAX );
336 2098 : set_zero( &hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinImag[0][0][0], 2 * ( CLDFB_NO_COL_MAX + CLDFB_PLC_XF ) * CLDFB_NO_CHANNELS_MAX );
337 2098 : *phSplitRendPLC = hSplitRendPLC;
338 :
339 2098 : return error;
340 : }
341 :
342 :
343 : /*-------------------------------------------------------------------------
344 : * Function isar_splitBinRendPLCClose()
345 : *
346 : *
347 : *------------------------------------------------------------------------*/
348 :
349 2098 : void isar_splitBinRendPLCClose(
350 : ISAR_SPLIT_REND_PLC_HANDLE *phSplitRendPLC /* i/o: ISAR PLC handle */
351 : )
352 : {
353 2098 : if ( ( *phSplitRendPLC ) != NULL )
354 : {
355 2098 : free( ( *phSplitRendPLC ) );
356 2098 : ( *phSplitRendPLC ) = NULL;
357 : }
358 :
359 2098 : return;
360 : }
361 :
362 :
363 : /*-------------------------------------------------------------------------
364 : * Function isar_splitBinRendPLCsaveState()
365 : *
366 : *
367 : *------------------------------------------------------------------------*/
368 :
369 324905 : void isar_splitBinRendPLCsaveState(
370 : ISAR_SPLIT_REND_PLC_HANDLE hSplitRendPLC,
371 : float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
372 : float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
373 : const int16_t num_chs,
374 : const int16_t iNumBlocks,
375 : const int16_t iNumIterations )
376 : {
377 : int16_t k, n;
378 :
379 : /* Save Cldfb frame */
380 5318161 : for ( k = 0; k < ( iNumBlocks * iNumIterations ); k++ )
381 : {
382 14979768 : for ( n = 0; n < num_chs; n++ )
383 : {
384 9986512 : mvr2r( &Cldfb_RealBuffer_Binaural[n][k][0], &hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinReal[n][k][0], CLDFB_NO_CHANNELS_MAX );
385 9986512 : mvr2r( &Cldfb_ImagBuffer_Binaural[n][k][0], &hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinImag[n][k][0], CLDFB_NO_CHANNELS_MAX );
386 : }
387 : }
388 :
389 324905 : return;
390 : }
391 :
392 :
393 : /*-------------------------------------------------------------------------
394 : * Function isar_splitBinRendPLC_xf()
395 : *
396 : * Cross-fade of preceding bad frame into good frame
397 : *------------------------------------------------------------------------*/
398 :
399 149 : void isar_splitBinRendPLC_xf(
400 : ISAR_SPLIT_REND_PLC_HANDLE hSplitRendPLC,
401 : float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
402 : float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
403 : const int16_t num_chs,
404 : const int16_t iNumBlocks,
405 : const int16_t iNumIterations,
406 : int32_t **ppiDecodingFailed,
407 : int32_t **ppiDecodingFailedPrev )
408 : {
409 : int16_t n, i, k;
410 :
411 : /* Indicate that next transition will be from a good frame */
412 149 : hSplitRendPLC->prev_bfi = 0;
413 :
414 : /* Reset bf conter */
415 149 : hSplitRendPLC->bf_count = 0;
416 :
417 :
418 : /* Do the cross fade */
419 447 : for ( n = 0; n < num_chs; n++ )
420 : {
421 18178 : for ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ )
422 : {
423 17880 : int16_t iSubSet = i % hSplitRendPLC->iNumSubSets;
424 17880 : if ( ppiDecodingFailedPrev[n][iSubSet] == 1 && ppiDecodingFailed[n][iSubSet] == 0 )
425 : {
426 53640 : for ( k = 0; k < CLDFB_PLC_XF; k++ )
427 : {
428 35760 : Cldfb_RealBuffer_Binaural[n][k][i] = hSplitRendPLC->CldfbPLC_state.xf_bet[n][i][k] * Cldfb_RealBuffer_Binaural[n][k][i] + hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinReal[n][k + ( iNumBlocks * iNumIterations )][i];
429 35760 : Cldfb_ImagBuffer_Binaural[n][k][i] = hSplitRendPLC->CldfbPLC_state.xf_bet[n][i][k] * Cldfb_ImagBuffer_Binaural[n][k][i] + hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinImag[n][k + ( iNumBlocks * iNumIterations )][i];
430 : }
431 : }
432 : }
433 : }
434 :
435 149 : return;
436 : }
437 :
438 :
439 : /*-------------------------------------------------------------------------
440 : * Function isar_splitBinRendPLC()
441 : *
442 : * Conceal bad frame
443 : *------------------------------------------------------------------------*/
444 :
445 256 : void isar_splitBinRendPLC(
446 : ISAR_SPLIT_REND_PLC_HANDLE hSplitRendPLC,
447 : float Cldfb_RealBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
448 : float Cldfb_ImagBuffer_Binaural[BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX],
449 : const int16_t num_chs,
450 : const int16_t iNumBlocks,
451 : const int16_t iNumIterations,
452 : int32_t **ppiDecodingFailed )
453 : {
454 : int32_t i, n, k;
455 : float fade_fac;
456 : float prev_real[CLDFB_NO_COL_MAX], prev_imag[CLDFB_NO_COL_MAX], rec_real[CLDFB_NO_COL_MAX + CLDFB_PLC_XF], rec_imag[CLDFB_NO_COL_MAX + CLDFB_PLC_XF];
457 : float xf_alp[CLDFB_PLC_XF];
458 : int16_t iNumCols, fade_start_cntr, mute_cntr, fade_val;
459 :
460 256 : iNumCols = iNumBlocks * iNumIterations;
461 :
462 : /* Indicate that next transition will be from a bad frame */
463 256 : hSplitRendPLC->prev_bfi = 1;
464 :
465 768 : for ( i = 0; i < CLDFB_PLC_XF; i++ )
466 : {
467 512 : xf_alp[i] = 1.0f - ( i + 1.0f ) / ( CLDFB_PLC_XF + 1.0f );
468 : }
469 :
470 768 : for ( n = 0; n < num_chs; n++ )
471 : {
472 31232 : for ( i = 0; i < CLDFB_NO_CHANNELS_MAX; i++ )
473 : {
474 30720 : int32_t iSubSet = i % hSplitRendPLC->iNumSubSets;
475 522240 : for ( k = 0; k < iNumCols; k++ )
476 : {
477 491520 : prev_real[k] = hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinReal[n][k][i];
478 491520 : prev_imag[k] = hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinImag[n][k][i];
479 : }
480 :
481 30720 : adaptive_polar_ext_plc( prev_real, prev_imag, rec_real, rec_imag,
482 30720 : xf_alp, hSplitRendPLC->CldfbPLC_state.xf_bet[n][i],
483 : iNumCols );
484 :
485 522240 : for ( k = 0; k < iNumCols; k++ )
486 : {
487 491520 : hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinReal[n][k][i] = rec_real[k];
488 491520 : hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinImag[n][k][i] = rec_imag[k];
489 :
490 491520 : if ( ppiDecodingFailed[n][iSubSet] == 1 )
491 : { /* only then copy to output */
492 491520 : Cldfb_RealBuffer_Binaural[n][k][i] = rec_real[k];
493 491520 : Cldfb_ImagBuffer_Binaural[n][k][i] = rec_imag[k];
494 : }
495 : }
496 :
497 92160 : for ( k = iNumCols; k < iNumCols + CLDFB_PLC_XF; k++ )
498 : {
499 61440 : hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinReal[n][k][i] = rec_real[k];
500 61440 : hSplitRendPLC->CldfbPLC_state.Cldfb_Prev_BinImag[n][k][i] = rec_imag[k];
501 : }
502 : }
503 : }
504 :
505 : /* Check bf counter */
506 256 : fade_start_cntr = SR_PLC_FADE_START * CLDFB_NO_COL_MAX / iNumCols;
507 256 : mute_cntr = SR_PLC_MUTE * CLDFB_NO_COL_MAX / iNumCols;
508 :
509 256 : if ( hSplitRendPLC->bf_count++ >= fade_start_cntr )
510 : {
511 0 : if ( hSplitRendPLC->bf_count < mute_cntr )
512 : {
513 0 : fade_val = ( ( hSplitRendPLC->bf_count - fade_start_cntr ) * iNumCols ) / CLDFB_NO_COL_MAX;
514 0 : fade_fac = powf( 10, fade_val * SR_PLC_FADE_DEGREE / 20.0f );
515 :
516 0 : for ( n = 0; n < num_chs; n++ )
517 : {
518 0 : for ( k = 0; k < iNumCols; k++ )
519 : {
520 0 : v_multc( &Cldfb_RealBuffer_Binaural[n][k][0], fade_fac, &Cldfb_RealBuffer_Binaural[n][k][0], (int16_t) CLDFB_NO_CHANNELS_MAX );
521 0 : v_multc( &Cldfb_ImagBuffer_Binaural[n][k][0], fade_fac, &Cldfb_ImagBuffer_Binaural[n][k][0], (int16_t) CLDFB_NO_CHANNELS_MAX );
522 : }
523 : }
524 : }
525 : else
526 : {
527 0 : for ( n = 0; n < num_chs; n++ )
528 : {
529 0 : for ( k = 0; k < iNumCols; k++ )
530 : {
531 0 : set_zero( &Cldfb_RealBuffer_Binaural[n][k][0], (int16_t) CLDFB_NO_CHANNELS_MAX );
532 0 : set_zero( &Cldfb_ImagBuffer_Binaural[n][k][0], (int16_t) CLDFB_NO_CHANNELS_MAX );
533 : }
534 : }
535 0 : hSplitRendPLC->bf_count = mute_cntr;
536 : }
537 : }
538 :
539 256 : return;
540 : }
|