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 <assert.h>
34 : #include "options.h"
35 : #include <stdint.h>
36 : #include "cnst.h"
37 : #include "prot.h"
38 : #include "ivas_prot.h"
39 : #include "ivas_prot_rend.h"
40 : #include "ivas_cnst.h"
41 : #include "ivas_rom_com.h"
42 : #include "ivas_rom_dec.h"
43 : #include "math.h"
44 : #ifdef DEBUGGING
45 : #include "debug.h"
46 : #endif
47 : #ifdef DEBUG_PLOT
48 : #include "deb_out.h"
49 : #endif
50 : #include "wmc_auto.h"
51 : #include "rom_dec.h"
52 :
53 :
54 : /*-----------------------------------------------------------------------*
55 : * Local arrays
56 : *-----------------------------------------------------------------------*/
57 :
58 : /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
59 : const int16_t MC_PARAMUPMIX_CHIDX1[MC_PARAMUPMIX_COMBINATIONS] = { 0, 1, 4, 5 };
60 : const int16_t MC_PARAMUPMIX_CHIDX2[MC_PARAMUPMIX_COMBINATIONS] = { 2, 3, 6, 7 };
61 :
62 :
63 : /*-----------------------------------------------------------------------*
64 : * Local function prototypes
65 : *-----------------------------------------------------------------------*/
66 :
67 : static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], float *param_interpol, const int16_t ch, const int16_t slots_rendered );
68 :
69 : static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, float *output_f[MAX_OUTPUT_CHANNELS] );
70 :
71 : static void ivas_param_upmix_dec_decorr_subframes( Decoder_Struct *st_ivas, const int16_t nSamplesForRendering );
72 :
73 : static int16_t huff_read( Decoder_State *st, const int16_t ( *ht )[2] );
74 :
75 : static void huffman_decode( Decoder_State *st, const PAR_TYPE parType, int32_t *vq );
76 :
77 : static void dequant_alpha( int32_t *vq, float *v );
78 :
79 : static void dequant_beta( int32_t *aq, int32_t *bq, float *beta );
80 :
81 : static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, int32_t *parQ, int32_t *alphaQEnv, float ab[IVAS_MAX_NUM_BANDS] );
82 :
83 :
84 : /*-------------------------------------------------------------------------
85 : * ivas_mc_paramupmix_dec_read_BS()
86 : *
87 : * Read the ParamUpmix MC metadata
88 : *------------------------------------------------------------------------*/
89 :
90 14569 : void ivas_mc_paramupmix_dec_read_BS(
91 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
92 : Decoder_State *st0, /* i/o: decoder state structure */
93 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */
94 : int16_t *nb_bits /* o : number of bits written */
95 : )
96 : {
97 : int16_t i, k;
98 : int32_t alpha_quant[IVAS_MAX_NUM_BANDS];
99 : int16_t nb_bits_read_orig;
100 : int16_t next_bit_pos_orig, last_bit_pos;
101 : uint16_t bstr_meta[MAX_BITS_METADATA], *bit_stream_orig;
102 :
103 14569 : push_wmops( "mc_paramupmix_read_bs" );
104 14569 : *nb_bits = 0;
105 :
106 14569 : if ( st0->bfi )
107 : {
108 3415 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
109 : {
110 35516 : for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ )
111 : {
112 32784 : hMCParamUpmix->alphas[i][k] = hMCParamUpmix->alpha_prev[i][k];
113 32784 : hMCParamUpmix->betas[i][k] = hMCParamUpmix->beta_prev[i][k];
114 : }
115 : }
116 :
117 3415 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
118 : {
119 2732 : mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
120 2732 : mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
121 : }
122 :
123 683 : hMCParamUpmix->first_frame = 1;
124 : }
125 : else /* if (!st->bfi) */
126 : {
127 13886 : bit_stream_orig = st0->bit_stream;
128 13886 : next_bit_pos_orig = st0->next_bit_pos;
129 13886 : last_bit_pos = (int16_t) ( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 );
130 13886 : nb_bits_read_orig = 0;
131 13886 : last_bit_pos -= nb_bits_read_orig; /* reverse the bitstream for easier reading of indices */
132 34728886 : for ( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ )
133 : {
134 34715000 : bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
135 : }
136 13886 : st0->bit_stream = bstr_meta;
137 13886 : st0->next_bit_pos = 0;
138 13886 : st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 );
139 13886 : st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */
140 :
141 13886 : if ( hMCParamUpmix->first_frame == 0 )
142 : {
143 66480 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
144 : {
145 53184 : mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
146 53184 : mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
147 : }
148 : }
149 :
150 69430 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
151 : {
152 55544 : get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] );
153 :
154 55544 : get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] );
155 : }
156 13886 : *nb_bits += st0->next_bit_pos;
157 13886 : st0->bit_stream = bit_stream_orig;
158 13886 : st0->next_bit_pos = next_bit_pos_orig;
159 :
160 13886 : if ( hMCParamUpmix->first_frame )
161 : {
162 2950 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
163 : {
164 2360 : mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
165 2360 : mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
166 : }
167 590 : hMCParamUpmix->first_frame = 0;
168 : }
169 :
170 69430 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
171 : {
172 55544 : mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
173 55544 : mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
174 : }
175 : }
176 :
177 14569 : pop_wmops();
178 14569 : return;
179 : }
180 :
181 :
182 : /*-------------------------------------------------------------------------
183 : * ivas_mc_paramupmix_dec_digest_tc()
184 : *
185 : *
186 : *------------------------------------------------------------------------*/
187 :
188 13645 : void ivas_mc_paramupmix_dec_digest_tc(
189 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
190 : const uint8_t nCldfbSlots, /* i : number of CLDFB slots in transport channels */
191 : const int16_t nSamplesForRendering /* i : number of samples provided */
192 : )
193 : {
194 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
195 13645 : hMCParamUpmix = st_ivas->hMCParamUpmix;
196 13645 : assert( hMCParamUpmix );
197 13645 : push_wmops( "ivas_mc_paramupmix_dec_digest_tc" );
198 :
199 13645 : ivas_param_upmix_dec_decorr_subframes( st_ivas, nSamplesForRendering );
200 :
201 : /* adapt subframes */
202 13645 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
203 :
204 13645 : ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator );
205 :
206 13645 : pop_wmops();
207 13645 : return;
208 : }
209 :
210 :
211 : /*-------------------------------------------------------------------------
212 : * ivas_mc_paramupmix_dec_render()
213 : *
214 : *
215 : *------------------------------------------------------------------------*/
216 :
217 19122 : void ivas_mc_paramupmix_dec_render(
218 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
219 : const uint16_t nSamplesAsked, /* i : number of CLDFB slots requested */
220 : uint16_t *nSamplesRendered, /* o : number of CLDFB slots rendered */
221 : uint16_t *nSamplesAvailable, /* o : number of CLDFB slots still to render */
222 : float *input_f[], /* i : core-coder transport channels */
223 : float *output_f[] /* i/o: synthesized core-coder transport channels */
224 : )
225 : {
226 : int16_t slots_to_render, first_sf, last_sf, subframe_idx;
227 : uint16_t slot_size, ch;
228 : float *output_f_local[MAX_OUTPUT_CHANNELS];
229 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
230 :
231 19122 : hMCParamUpmix = st_ivas->hMCParamUpmix;
232 19122 : assert( hMCParamUpmix );
233 :
234 19122 : push_wmops( "ivas_mc_paramupmix_dec_render" );
235 :
236 325074 : for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
237 : {
238 305952 : output_f_local[ch] = output_f[ch];
239 : }
240 :
241 19122 : slot_size = st_ivas->hTcBuffer->n_samples_granularity;
242 :
243 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
244 19122 : slots_to_render = min( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered, nSamplesAsked / slot_size );
245 19122 : *nSamplesRendered = slots_to_render * slot_size;
246 19122 : first_sf = st_ivas->hTcBuffer->subframes_rendered;
247 19122 : last_sf = first_sf;
248 :
249 248586 : for ( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ )
250 : {
251 229464 : mvr2r( input_f[ch], output_f_local[ch], *nSamplesRendered );
252 : }
253 :
254 75946 : while ( slots_to_render > 0 )
255 : {
256 56824 : slots_to_render -= st_ivas->hTcBuffer->subframe_nbslots[last_sf];
257 56824 : last_sf++;
258 : }
259 : #ifdef DEBUGGING
260 : assert( slots_to_render == 0 );
261 : #endif
262 : {
263 75946 : for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
264 : {
265 56824 : int16_t n_samples_sf = slot_size * st_ivas->hTcBuffer->subframe_nbslots[subframe_idx];
266 56824 : ivas_mc_paramupmix_dec_sf( st_ivas, output_f_local );
267 :
268 889576 : for ( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ )
269 : {
270 832752 : output_f_local[ch] += n_samples_sf;
271 : }
272 :
273 : /* update combined orientation access index */
274 56824 : ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
275 : }
276 : }
277 :
278 19122 : *nSamplesAvailable = ( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered ) * slot_size;
279 :
280 19122 : pop_wmops();
281 19122 : return;
282 : }
283 :
284 :
285 : /*-------------------------------------------------------------------------
286 : * ivas_mc_paramupmix_dec_open()
287 : *
288 : * Open Parametric MC decoder handle
289 : *-------------------------------------------------------------------------*/
290 :
291 201 : ivas_error ivas_mc_paramupmix_dec_open(
292 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
293 : )
294 : {
295 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
296 : int32_t output_Fs;
297 : int16_t nchan_transport;
298 : uint16_t i;
299 : ivas_error error;
300 :
301 201 : error = IVAS_ERR_OK;
302 :
303 : /*-----------------------------------------------------------------*
304 : * prepare library opening
305 : *-----------------------------------------------------------------*/
306 :
307 201 : if ( ( hMCParamUpmix = (MC_PARAMUPMIX_DEC_HANDLE) malloc( sizeof( MC_PARAMUPMIX_DEC_DATA ) ) ) == NULL )
308 : {
309 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param-Upmix MC\n" ) );
310 : }
311 201 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
312 201 : hMCParamUpmix->first_frame = 1;
313 201 : st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
314 201 : nchan_transport = st_ivas->nchan_transport;
315 :
316 201 : switch ( nchan_transport )
317 : {
318 201 : case 8:
319 201 : st_ivas->nCPE = 4;
320 201 : st_ivas->nSCE = 0;
321 201 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
322 201 : break;
323 : #ifdef DEBUGGING
324 : default:
325 : assert( 0 && "Number of TC not supported for MC ParamUpmix!" );
326 : #endif
327 : }
328 :
329 201 : hMCParamUpmix->hoa_encoder = NULL;
330 :
331 : /*-----------------------------------------------------------------*
332 : * set input parameters
333 : *-----------------------------------------------------------------*/
334 :
335 201 : hMCParamUpmix->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
336 :
337 1005 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
338 : {
339 804 : ivas_td_decorr_dec_open( &( hMCParamUpmix->hTdDecorr[i] ), output_Fs, 2, 1 );
340 : }
341 :
342 1809 : for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
343 : {
344 1608 : if ( ( hMCParamUpmix->pcm_delay[i] = (float *) malloc( NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) * sizeof( float ) ) ) == NULL )
345 : {
346 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for delay buffer\n" ) );
347 : }
348 1608 : set_zero( hMCParamUpmix->pcm_delay[i], NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) );
349 : }
350 :
351 : /* Head or external rotation */
352 201 : if ( ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
353 : {
354 77 : if ( ( hMCParamUpmix->hoa_encoder = (float *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( float ) ) ) == NULL )
355 : {
356 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
357 : }
358 77 : compute_hoa_encoder_mtx( st_ivas->hTransSetup.ls_azimuth, st_ivas->hTransSetup.ls_elevation, hMCParamUpmix->hoa_encoder, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER );
359 : }
360 :
361 : /* allocate transport channels*/
362 201 : hMCParamUpmix->free_param_interpolator = 0;
363 201 : hMCParamUpmix->param_interpolator = NULL;
364 :
365 201 : if ( ( hMCParamUpmix->param_interpolator = (float *) malloc( MAX_JBM_CLDFB_TIMESLOTS * sizeof( float ) ) ) == NULL )
366 : {
367 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) );
368 : }
369 201 : hMCParamUpmix->free_param_interpolator = 1;
370 :
371 201 : ivas_jbm_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator );
372 :
373 201 : if ( st_ivas->hTcBuffer == NULL )
374 : {
375 : int16_t nchan_to_allocate;
376 : int16_t nchan_tc;
377 : int16_t granularity;
378 : TC_BUFFER_MODE buffer_mode;
379 :
380 180 : buffer_mode = TC_BUFFER_MODE_RENDERER;
381 180 : nchan_tc = ivas_jbm_dec_get_num_tc_channels( st_ivas );
382 180 : nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
383 :
384 180 : if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO )
385 : {
386 14 : buffer_mode = TC_BUFFER_MODE_BUFFER;
387 14 : nchan_tc = st_ivas->hDecoderConfig->nchan_out;
388 14 : nchan_to_allocate = nchan_tc;
389 : }
390 166 : else if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM || st_ivas->renderer_type == RENDERER_STEREO_PARAMETRIC )
391 : {
392 107 : nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
393 : }
394 :
395 180 : granularity = ivas_jbm_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs );
396 :
397 180 : if ( ( error = ivas_jbm_dec_tc_buffer_open( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, granularity ) ) != IVAS_ERR_OK )
398 : {
399 0 : return error;
400 : }
401 : }
402 :
403 201 : st_ivas->hMCParamUpmix = hMCParamUpmix;
404 :
405 201 : return error;
406 : }
407 :
408 :
409 : /*-------------------------------------------------------------------------
410 : * ivas_mc_paramupmix_dec_close()
411 : *
412 : * Close ParamUpmix MC memories
413 : *------------------------------------------------------------------------*/
414 :
415 87416 : void ivas_mc_paramupmix_dec_close(
416 : MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix /* i/o: Parametric MC decoder handle */
417 : )
418 : {
419 : int16_t i;
420 :
421 87416 : if ( hMCParamUpmix == NULL || *hMCParamUpmix == NULL )
422 : {
423 87215 : return;
424 : }
425 1005 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
426 : {
427 804 : ivas_td_decorr_dec_close( &( ( *hMCParamUpmix )->hTdDecorr[i] ) );
428 : }
429 1809 : for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
430 : {
431 1608 : if ( ( *hMCParamUpmix )->pcm_delay[i] != NULL )
432 : {
433 1608 : free( ( *hMCParamUpmix )->pcm_delay[i] );
434 : }
435 : }
436 201 : if ( ( *hMCParamUpmix )->param_interpolator != NULL )
437 : {
438 201 : if ( ( *hMCParamUpmix )->free_param_interpolator == 1 )
439 : {
440 201 : free( ( *hMCParamUpmix )->param_interpolator );
441 : }
442 : }
443 201 : if ( ( *hMCParamUpmix )->hoa_encoder != NULL )
444 : {
445 77 : free( ( *hMCParamUpmix )->hoa_encoder );
446 77 : ( *hMCParamUpmix )->hoa_encoder = NULL;
447 : }
448 201 : free( *hMCParamUpmix );
449 :
450 201 : *hMCParamUpmix = NULL;
451 :
452 201 : return;
453 : }
454 :
455 :
456 : /*-------------------------------------------------------------------------
457 : * paramupmix_td_decorr_process_jbm()
458 : *
459 : *
460 : *------------------------------------------------------------------------*/
461 :
462 13764 : static void paramupmix_td_decorr_process_jbm(
463 : ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle */
464 : float *pcm_in[], /* i : input audio channels */
465 : float **pp_out_pcm, /* o : output audio channels */
466 : const int16_t output_frame /* i : output frame length */
467 : )
468 : {
469 : int16_t j, k;
470 : int16_t offset;
471 : float in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k];
472 :
473 13764 : offset = (int16_t) ( output_frame * FRAMES_PER_SEC * IVAS_DECORR_PARM_LOOKAHEAD_TAU );
474 :
475 : /* Look-ahead delay */
476 68820 : for ( k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++ )
477 : {
478 55056 : mvr2r( pcm_in[k], pp_out_pcm[k], output_frame );
479 55056 : delay_signal( pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset );
480 :
481 : /* In ducking gains */
482 55056 : if ( hTdDecorr[k]->ducking_flag )
483 : {
484 55056 : ivas_td_decorr_get_ducking_gains( hTdDecorr[k]->pTrans_det, pcm_in[k], in_duck_gain, out_duck_gain, output_frame, 0 );
485 :
486 46312896 : for ( j = 0; j < output_frame; j++ )
487 : {
488 46257840 : pp_out_pcm[k][j] = pp_out_pcm[k][j] * in_duck_gain[j];
489 : }
490 : }
491 :
492 : /* All pass delay section */
493 55056 : ivas_td_decorr_APD_iir_filter( &hTdDecorr[k]->APD_filt_state[0], pp_out_pcm[k], hTdDecorr[k]->num_apd_sections, output_frame );
494 :
495 : /* Out ducking gains */
496 55056 : if ( hTdDecorr[k]->ducking_flag )
497 : {
498 46312896 : for ( j = 0; j < output_frame; j++ )
499 : {
500 46257840 : pp_out_pcm[k][j] = pp_out_pcm[k][j] * out_duck_gain[j];
501 : }
502 : }
503 : }
504 :
505 13764 : return;
506 : }
507 :
508 :
509 : /*-------------------------------------------------------------------------
510 : * ivas_param_upmix_dec_decorr_subframes()
511 : *
512 : *
513 : *------------------------------------------------------------------------*/
514 :
515 13645 : static void ivas_param_upmix_dec_decorr_subframes(
516 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
517 : const int16_t nSamplesForRendering )
518 : {
519 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
520 : float *pPcm_tmp[MC_PARAMUPMIX_COMBINATIONS];
521 : float *p_tc[MC_PARAMUPMIX_COMBINATIONS];
522 : int16_t nchan_internal, ch;
523 : int16_t nSamplesLeftForTD, default_frame;
524 :
525 13645 : hMCParamUpmix = st_ivas->hMCParamUpmix;
526 13645 : assert( hMCParamUpmix );
527 :
528 13645 : push_wmops( "ivas_param_upmix_dec_decorr_subframes" );
529 :
530 : /* TD decorrelator */
531 13645 : default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
532 13645 : nSamplesLeftForTD = nSamplesForRendering;
533 13645 : nchan_internal = MC_PARAMUPMIX_COMBINATIONS;
534 :
535 68225 : for ( ch = 0; ch < nchan_internal; ch++ )
536 : {
537 54580 : pPcm_tmp[ch] = st_ivas->hTcBuffer->tc[ch + 8];
538 54580 : p_tc[ch] = st_ivas->hTcBuffer->tc[ch + 4];
539 : }
540 :
541 27409 : while ( nSamplesLeftForTD )
542 : {
543 13764 : int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame );
544 :
545 13764 : paramupmix_td_decorr_process_jbm( hMCParamUpmix->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr );
546 :
547 68820 : for ( ch = 0; ch < nchan_internal; ch++ )
548 : {
549 55056 : p_tc[ch] += nSamplesToDecorr;
550 : }
551 :
552 13764 : nSamplesLeftForTD -= nSamplesToDecorr;
553 : }
554 :
555 13645 : pop_wmops();
556 13645 : return;
557 : }
558 :
559 :
560 : /*****************************************************************************************/
561 : /* local functions */
562 : /*****************************************************************************************/
563 :
564 227296 : static void ps_pred_process_sf(
565 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix,
566 : DECODER_TC_BUFFER_HANDLE hTcBuffer,
567 : float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */
568 : float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
569 : float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */
570 : float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
571 : float *param_interpol,
572 : const int16_t ch,
573 : const int16_t slots_rendered )
574 : {
575 : float vmre, vmim, vsre, vsim;
576 : int16_t iqmf, ipar, ismp, iismp;
577 : float alpha_smp, beta_smp;
578 : float *alpha1, *alpha2;
579 : float *beta1, *beta2;
580 227296 : float *alpha_prev = hMCParamUpmix->alpha_prev[ch];
581 227296 : float *beta_prev = hMCParamUpmix->beta_prev[ch];
582 227296 : float *alpha_sf = hMCParamUpmix->alpha_sf[ch];
583 227296 : float *beta_sf = hMCParamUpmix->beta_sf[ch];
584 : float dalpha, dbeta, ifac;
585 : float alpha_start[IVAS_MAX_NUM_BANDS], beta_start[IVAS_MAX_NUM_BANDS];
586 :
587 227296 : const int16_t qmf_to_par_band[] = {
588 : 0, 1, 2, 3, 4, 5, 5, 6, 6, 7,
589 : 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
590 : 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
591 : 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
592 : 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
593 : 11, 11, 11, 11, 11, 11, 11, 11, 11, 11
594 : };
595 :
596 227296 : mvr2r( alpha_sf, alpha_start, IVAS_MAX_NUM_BANDS );
597 227296 : mvr2r( beta_sf, beta_start, IVAS_MAX_NUM_BANDS );
598 13865056 : for ( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ )
599 : {
600 13637760 : ipar = qmf_to_par_band[iqmf];
601 13637760 : alpha1 = alpha_prev;
602 13637760 : beta1 = beta_prev;
603 :
604 13637760 : ismp = 0;
605 13637760 : alpha2 = hMCParamUpmix->alphas[ch];
606 13637760 : beta2 = hMCParamUpmix->betas[ch];
607 13637760 : alpha_smp = alpha_start[ipar];
608 13637760 : beta_smp = beta_start[ipar];
609 :
610 66185520 : for ( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ )
611 : {
612 52547760 : if ( ( slots_rendered == 0 ) && ( iismp == 0 ) )
613 : {
614 3274800 : ifac = param_interpol[iismp];
615 : }
616 : else
617 : {
618 49272960 : ifac = param_interpol[iismp] - param_interpol[iismp - 1];
619 : }
620 52547760 : dalpha = ( alpha2[ipar] - alpha1[ipar] ) * ifac;
621 52547760 : dbeta = ( beta2[ipar] - beta1[ipar] ) * ifac;
622 :
623 52547760 : alpha_smp += dalpha;
624 52547760 : beta_smp += dbeta;
625 :
626 52547760 : vmre = qmf_mod_re[ismp][iqmf];
627 52547760 : vmim = qmf_mod_im[ismp][iqmf];
628 52547760 : vsre = qmf_side_re[ismp][iqmf];
629 52547760 : vsim = qmf_side_im[ismp][iqmf];
630 :
631 52547760 : qmf_side_re[ismp][iqmf] = alpha_smp * vmre + beta_smp * vsre;
632 52547760 : qmf_side_im[ismp][iqmf] = alpha_smp * vmim + beta_smp * vsim;
633 :
634 52547760 : ismp++;
635 : }
636 13637760 : alpha_sf[ipar] = alpha_smp;
637 13637760 : beta_sf[ipar] = beta_smp;
638 : }
639 :
640 227296 : return;
641 : }
642 :
643 56824 : static void ivas_mc_paramupmix_dec_sf(
644 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
645 : float *output_f[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels */
646 : )
647 : {
648 : int16_t i, ch, slot_idx, k;
649 : float *pPcm_temp[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/
650 : /*CLDFB*/
651 : float Cldfb_RealBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
652 : float Cldfb_ImagBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
653 : int16_t noparamupmix_delay, n_samples_rendered;
654 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
655 : int16_t subframeIdx, idx_in, maxBand;
656 : float Cldfb_RealBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
657 : float Cldfb_ImagBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
658 : float Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
659 : float Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
660 : int16_t slot_index_start;
661 :
662 56824 : hMCParamUpmix = st_ivas->hMCParamUpmix;
663 56824 : assert( hMCParamUpmix );
664 56824 : push_wmops( "ivas_mc_paramupmix_dec_sf" );
665 :
666 56824 : slot_index_start = st_ivas->hTcBuffer->slots_rendered;
667 284120 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
668 : {
669 227296 : pPcm_temp[2 * i] = output_f[i + 4]; /* un-decorrelated */
670 227296 : pPcm_temp[2 * i + 1] = output_f[i + 8]; /* decorrelated */
671 : }
672 :
673 : /* CLDFB Analysis*/
674 511416 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
675 : {
676 : /* slot loop for gathering the input data */
677 2206184 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
678 : {
679 1751592 : cldfbAnalysis_ts( &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer[ch][slot_idx], Cldfb_ImagBuffer[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch] );
680 : }
681 : }
682 :
683 284120 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
684 : {
685 227296 : ps_pred_process_sf( hMCParamUpmix,
686 : st_ivas->hTcBuffer,
687 227296 : Cldfb_RealBuffer[2 * ch], /* in/out */
688 227296 : Cldfb_ImagBuffer[2 * ch],
689 227296 : Cldfb_RealBuffer[2 * ch + 1], /* in/out decorr */
690 227296 : Cldfb_ImagBuffer[2 * ch + 1],
691 227296 : &hMCParamUpmix->param_interpolator[st_ivas->hTcBuffer->slots_rendered],
692 : ch,
693 227296 : st_ivas->hTcBuffer->slots_rendered );
694 :
695 : /*-- m, s -> l, r ----------------------------*/
696 1103092 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
697 : {
698 53423556 : for ( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
699 : {
700 52547760 : float qlre = Cldfb_RealBuffer[2 * ch][slot_idx][k];
701 52547760 : float qlim = Cldfb_ImagBuffer[2 * ch][slot_idx][k];
702 52547760 : float qrre = Cldfb_RealBuffer[2 * ch + 1][slot_idx][k];
703 52547760 : float qrim = Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k];
704 :
705 52547760 : Cldfb_RealBuffer[2 * ch][slot_idx][k] = qlre + qrre;
706 52547760 : Cldfb_ImagBuffer[2 * ch][slot_idx][k] = qlim + qrim;
707 52547760 : Cldfb_RealBuffer[2 * ch + 1][slot_idx][k] = qlre - qrre;
708 52547760 : Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k] = qlim - qrim;
709 : }
710 : }
711 : }
712 :
713 56824 : if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
714 : {
715 43692 : maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * st_ivas->hDecoderConfig->output_Fs ) / 48000 );
716 43692 : subframeIdx = st_ivas->hTcBuffer->subframes_rendered;
717 : /* fastconv binaural rendering and CLDFB synthesis */
718 : /* cldfb analysis of non-coupled, non-LFE channels */
719 43692 : idx_in = 0;
720 218460 : for ( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ )
721 : {
722 174768 : if ( st_ivas->hIntSetup.index_lfe[0] != ch )
723 : {
724 167484 : pPcm_temp[ch] = output_f[ch];
725 : /* slot loop for gathering the input data */
726 804032 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
727 : {
728 636548 : cldfbAnalysis_ts( &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
729 636548 : Cldfb_RealBuffer_subfr[idx_in][slot_idx],
730 636548 : Cldfb_ImagBuffer_subfr[idx_in][slot_idx],
731 636548 : maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in] );
732 : }
733 167484 : idx_in++;
734 : }
735 : }
736 :
737 : /* copy and reorder cldfb analysis of coupled channels */
738 218460 : for ( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ )
739 : {
740 873840 : for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
741 : {
742 699072 : mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
743 699072 : mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
744 699072 : mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
745 699072 : mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
746 : }
747 174768 : idx_in += 2;
748 : }
749 :
750 43692 : if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
751 : {
752 173693 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
753 : {
754 137285 : ivas_param_mc_mc2sba_cldfb( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder, slot_idx, Cldfb_RealBuffer_subfr, Cldfb_ImagBuffer_subfr, maxBand, GAIN_LFE );
755 : }
756 : }
757 :
758 : /*LFE handling for split rendering cases*/
759 43692 : if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
760 : {
761 31008 : if ( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
762 : {
763 43145 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
764 : {
765 578425 : for ( ch = 0; ch < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ); ch++ )
766 : {
767 544400 : mvr2r( Cldfb_RealBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer[ch][slot_index_start + slot_idx], maxBand );
768 544400 : mvr2r( Cldfb_ImagBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer[ch][slot_index_start + slot_idx], maxBand );
769 : }
770 : }
771 :
772 9120 : st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
773 : }
774 : }
775 :
776 : /* Implement binaural rendering */
777 43692 : ivas_binRenderer( st_ivas->hBinRenderer,
778 31008 : ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
779 : st_ivas->hCombinedOrientationData,
780 43692 : st_ivas->hTcBuffer->subframe_nbslots[subframeIdx],
781 : Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural,
782 : Cldfb_RealBuffer_subfr,
783 : Cldfb_ImagBuffer_subfr );
784 :
785 43692 : if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
786 : {
787 : int16_t pos_idx;
788 156864 : for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
789 : {
790 595401 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
791 : {
792 1408635 : for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
793 : {
794 : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
795 939090 : ivas_CLDFB_RINGBUF_Push(
796 939090 : st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch],
797 939090 : Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx],
798 939090 : Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx],
799 : maxBand );
800 : #else
801 : mvr2r( Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_index_start + slot_idx], maxBand );
802 : mvr2r( Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[( pos_idx * BINAURAL_CHANNELS ) + ch][slot_index_start + slot_idx], maxBand );
803 : #endif
804 : }
805 : }
806 : }
807 : }
808 :
809 : /* Implement CLDFB synthesis */
810 131076 : for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
811 : {
812 : float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
813 : float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
814 :
815 420226 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
816 : {
817 332842 : RealBuffer[slot_idx] = Cldfb_RealBuffer_Binaural[0][ch][slot_idx];
818 332842 : ImagBuffer[slot_idx] = Cldfb_ImagBuffer_Binaural[0][ch][slot_idx];
819 : }
820 :
821 87384 : cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] );
822 : }
823 : }
824 : else
825 : {
826 : /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
827 13132 : pPcm_temp[0] = output_f[4];
828 13132 : pPcm_temp[1] = output_f[6];
829 13132 : pPcm_temp[2] = output_f[5];
830 13132 : pPcm_temp[3] = output_f[7];
831 13132 : pPcm_temp[4] = output_f[8];
832 13132 : pPcm_temp[5] = output_f[10];
833 13132 : pPcm_temp[6] = output_f[9];
834 13132 : pPcm_temp[7] = output_f[11];
835 :
836 : /* CLDFB synthesis */
837 118188 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
838 : {
839 525280 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
840 : {
841 : float *ptr_im[1], *ptr_re[1];
842 420224 : ptr_re[0] = Cldfb_RealBuffer[ch][slot_idx];
843 420224 : ptr_im[0] = Cldfb_ImagBuffer[ch][slot_idx];
844 :
845 420224 : cldfbSynthesis( ptr_re, ptr_im, &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
846 420224 : hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] );
847 : }
848 : }
849 :
850 : /* adjust delay of other channels */
851 13132 : noparamupmix_delay = NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS );
852 13132 : n_samples_rendered = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] * hMCParamUpmix->num_freq_bands;
853 13132 : if ( n_samples_rendered > noparamupmix_delay )
854 : {
855 0 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
856 : {
857 : /*delay is handled within LFE decoder*/
858 0 : if ( st_ivas->hIntSetup.index_lfe[0] != ch )
859 : {
860 : float tmp_buf[L_SUBFRAME5MS_48k];
861 0 : mvr2r( &output_f[ch][n_samples_rendered - noparamupmix_delay], tmp_buf, noparamupmix_delay );
862 0 : mvr2r( output_f[ch], &output_f[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay );
863 0 : mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], noparamupmix_delay );
864 0 : mvr2r( tmp_buf, hMCParamUpmix->pcm_delay[ch], noparamupmix_delay );
865 : }
866 : }
867 : }
868 : else
869 : {
870 65660 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
871 : {
872 52528 : if ( st_ivas->hIntSetup.index_lfe[0] != ch )
873 : {
874 : float tmp_buf[L_SUBFRAME5MS_48k];
875 39396 : mvr2r( &output_f[ch][0], tmp_buf, n_samples_rendered );
876 39396 : mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], n_samples_rendered );
877 39396 : mvr2r( &hMCParamUpmix->pcm_delay[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay[ch][0], noparamupmix_delay - n_samples_rendered );
878 39396 : mvr2r( tmp_buf, &hMCParamUpmix->pcm_delay[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered );
879 : }
880 : }
881 : }
882 : }
883 :
884 56824 : st_ivas->hTcBuffer->slots_rendered += st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered];
885 56824 : st_ivas->hTcBuffer->subframes_rendered++;
886 :
887 56824 : pop_wmops();
888 56824 : return;
889 : }
890 :
891 :
892 1333056 : static int16_t huff_read(
893 : Decoder_State *st,
894 : const int16_t ( *ht )[2] )
895 : {
896 1333056 : int16_t node = 0;
897 1333056 : uint16_t next_bit = 0;
898 :
899 : do
900 : {
901 2758310 : next_bit = st->bit_stream[st->next_bit_pos];
902 2758310 : st->next_bit_pos++;
903 2758310 : node = ht[node][next_bit];
904 2758310 : } while ( node > 0 );
905 :
906 1333056 : return -( node + 1 );
907 : }
908 :
909 :
910 111088 : static void huffman_decode(
911 : Decoder_State *st,
912 : const PAR_TYPE parType,
913 : int32_t *vq )
914 : {
915 : const int16_t( *huff_node_table )[2];
916 : int16_t iv, nquant, offset;
917 :
918 111088 : nquant = 0;
919 111088 : switch ( parType )
920 : {
921 55544 : case ALPHA:
922 55544 : nquant = ivas_mc_paramupmix_alpha_quant_table.nquant;
923 55544 : break;
924 55544 : case BETA:
925 55544 : nquant = ivas_mc_paramupmix_beta_quant_table[0].nquant;
926 55544 : break;
927 0 : default:
928 0 : assert( 0 );
929 : }
930 :
931 111088 : offset = nquant - 1; /* range of df [-(nquant - 1), nquant - 1] */
932 :
933 111088 : st->next_bit_pos++;
934 111088 : switch ( parType )
935 : {
936 55544 : case ALPHA:
937 55544 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha;
938 55544 : break;
939 55544 : case BETA:
940 55544 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta;
941 55544 : break;
942 0 : default:
943 0 : huff_node_table = NULL;
944 0 : assert( 0 );
945 : }
946 111088 : vq[0] = huff_read( st, huff_node_table );
947 :
948 111088 : switch ( parType )
949 : {
950 55544 : case ALPHA:
951 55544 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha;
952 55544 : break;
953 55544 : case BETA:
954 55544 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta;
955 55544 : break;
956 0 : default:
957 0 : assert( 0 );
958 : }
959 :
960 1333056 : for ( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ )
961 : {
962 1221968 : vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset;
963 : }
964 :
965 111088 : return;
966 : }
967 :
968 :
969 55544 : static void dequant_alpha(
970 : int32_t *vq,
971 : float *v )
972 : {
973 : int16_t iv;
974 55544 : const ACPL_QUANT_TABLE *quant_table = &ivas_mc_paramupmix_alpha_quant_table;
975 :
976 722072 : for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
977 : {
978 666528 : v[iv] = quant_table->data[vq[iv]];
979 : }
980 :
981 55544 : return;
982 : }
983 :
984 :
985 55544 : static void dequant_beta(
986 : int32_t *aq,
987 : int32_t *bq,
988 : float *beta )
989 : {
990 : int16_t iv;
991 : const ACPL_QUANT_TABLE *quant_table;
992 :
993 722072 : for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
994 : {
995 666528 : quant_table = &ivas_mc_paramupmix_beta_quant_table[ivas_param_upmx_mx_qmap[aq[iv]]];
996 666528 : beta[iv] = quant_table->data[bq[iv]];
997 : }
998 :
999 55544 : return;
1000 : }
1001 :
1002 :
1003 111088 : static void get_ec_data(
1004 : Decoder_State *st,
1005 : const PAR_TYPE parType,
1006 : int32_t *parQ,
1007 : int32_t *alphaQEnv,
1008 : float ab[IVAS_MAX_NUM_BANDS] )
1009 : {
1010 111088 : huffman_decode( st, parType, parQ );
1011 :
1012 111088 : if ( parType == ALPHA )
1013 : {
1014 55544 : dequant_alpha( parQ, ab );
1015 55544 : mvl2l( parQ, alphaQEnv, (int16_t) IVAS_MAX_NUM_BANDS );
1016 : }
1017 : else
1018 : {
1019 55544 : dequant_beta( alphaQEnv, parQ, ab );
1020 : }
1021 :
1022 111088 : return;
1023 : }
|