Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #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 5924 : 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 5924 : push_wmops( "mc_paramupmix_read_bs" );
104 5924 : *nb_bits = 0;
105 :
106 5924 : if ( st0->bfi )
107 : {
108 850 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
109 : {
110 8840 : for ( k = 0; k < IVAS_MAX_NUM_BANDS; k++ )
111 : {
112 8160 : hMCParamUpmix->alphas[i][k] = hMCParamUpmix->alpha_prev[i][k];
113 8160 : hMCParamUpmix->betas[i][k] = hMCParamUpmix->beta_prev[i][k];
114 : }
115 : }
116 :
117 850 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
118 : {
119 680 : mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
120 680 : mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
121 : }
122 :
123 170 : hMCParamUpmix->first_frame = 1;
124 : }
125 : else /* if (!st->bfi) */
126 : {
127 5754 : bit_stream_orig = st0->bit_stream;
128 5754 : next_bit_pos_orig = st0->next_bit_pos;
129 5754 : last_bit_pos = (int16_t) ( ( st_ivas->hDecoderConfig->ivas_total_brate / FRAMES_PER_SEC ) - 1 );
130 5754 : nb_bits_read_orig = 0;
131 5754 : last_bit_pos -= nb_bits_read_orig; /* reverse the bitstream for easier reading of indices */
132 14390754 : for ( i = 0; i < min( MAX_BITS_METADATA, last_bit_pos ); i++ )
133 : {
134 14385000 : bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
135 : }
136 5754 : st0->bit_stream = bstr_meta;
137 5754 : st0->next_bit_pos = 0;
138 5754 : st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 );
139 5754 : st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */
140 :
141 5754 : if ( hMCParamUpmix->first_frame == 0 )
142 : {
143 27690 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
144 : {
145 22152 : mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
146 22152 : mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
147 : }
148 : }
149 :
150 28770 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
151 : {
152 23016 : get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas[i] );
153 :
154 23016 : get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas[i] );
155 : }
156 5754 : *nb_bits += st0->next_bit_pos;
157 5754 : st0->bit_stream = bit_stream_orig;
158 5754 : st0->next_bit_pos = next_bit_pos_orig;
159 :
160 5754 : if ( hMCParamUpmix->first_frame )
161 : {
162 1080 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
163 : {
164 864 : mvr2r( hMCParamUpmix->alphas[i], hMCParamUpmix->alpha_prev[i], IVAS_MAX_NUM_BANDS );
165 864 : mvr2r( hMCParamUpmix->betas[i], hMCParamUpmix->beta_prev[i], IVAS_MAX_NUM_BANDS );
166 : }
167 216 : hMCParamUpmix->first_frame = 0;
168 : }
169 :
170 28770 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
171 : {
172 23016 : mvr2r( hMCParamUpmix->alpha_prev[i], hMCParamUpmix->alpha_sf[i], IVAS_MAX_NUM_BANDS );
173 23016 : mvr2r( hMCParamUpmix->beta_prev[i], hMCParamUpmix->beta_sf[i], IVAS_MAX_NUM_BANDS );
174 : }
175 : }
176 :
177 5924 : pop_wmops();
178 5924 : return;
179 : }
180 :
181 :
182 : /*-------------------------------------------------------------------------
183 : * ivas_mc_paramupmix_dec_digest_tc()
184 : *
185 : *
186 : *------------------------------------------------------------------------*/
187 :
188 5914 : 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 5914 : hMCParamUpmix = st_ivas->hMCParamUpmix;
196 5914 : assert( hMCParamUpmix );
197 5914 : push_wmops( "ivas_mc_paramupmix_dec_digest_tc" );
198 :
199 5914 : ivas_param_upmix_dec_decorr_subframes( st_ivas, nSamplesForRendering );
200 :
201 : /* adapt subframes */
202 5914 : ivas_dec_td_renderers_adapt_subframes( st_ivas );
203 :
204 5914 : ivas_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator );
205 :
206 5914 : pop_wmops();
207 5914 : return;
208 : }
209 :
210 :
211 : /*-------------------------------------------------------------------------
212 : * ivas_mc_paramupmix_dec_render()
213 : *
214 : *
215 : *------------------------------------------------------------------------*/
216 :
217 7954 : 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 7954 : hMCParamUpmix = st_ivas->hMCParamUpmix;
232 7954 : assert( hMCParamUpmix );
233 :
234 7954 : push_wmops( "ivas_mc_paramupmix_dec_render" );
235 :
236 135218 : for ( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
237 : {
238 127264 : output_f_local[ch] = output_f[ch];
239 : }
240 :
241 7954 : 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 7954 : slots_to_render = min( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered, nSamplesAsked / slot_size );
245 7954 : *nSamplesRendered = slots_to_render * slot_size;
246 7954 : first_sf = st_ivas->hTcBuffer->subframes_rendered;
247 7954 : last_sf = first_sf;
248 :
249 103402 : for ( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ )
250 : {
251 95448 : mvr2r( input_f[ch], output_f_local[ch], *nSamplesRendered );
252 : }
253 :
254 33633 : while ( slots_to_render > 0 )
255 : {
256 25679 : slots_to_render -= st_ivas->hTcBuffer->subframe_nbslots[last_sf];
257 25679 : last_sf++;
258 : }
259 : #ifdef DEBUGGING
260 : assert( slots_to_render == 0 );
261 : #endif
262 : {
263 33633 : for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
264 : {
265 25679 : int16_t n_samples_sf = slot_size * st_ivas->hTcBuffer->subframe_nbslots[subframe_idx];
266 25679 : ivas_mc_paramupmix_dec_sf( st_ivas, output_f_local );
267 :
268 431423 : for ( ch = 0; ch < min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, -1, -1 ) ); ch++ )
269 : {
270 405744 : output_f_local[ch] += n_samples_sf;
271 : }
272 :
273 : /* update combined orientation access index */
274 25679 : ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
275 : }
276 : }
277 :
278 7954 : *nSamplesAvailable = ( st_ivas->hTcBuffer->num_slots - st_ivas->hTcBuffer->slots_rendered ) * slot_size;
279 :
280 7954 : pop_wmops();
281 7954 : return;
282 : }
283 :
284 :
285 : /*-------------------------------------------------------------------------
286 : * ivas_mc_paramupmix_dec_open()
287 : *
288 : * Open Parametric MC decoder handle
289 : *-------------------------------------------------------------------------*/
290 :
291 46 : 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 46 : error = IVAS_ERR_OK;
302 :
303 : /*-----------------------------------------------------------------*
304 : * prepare library opening
305 : *-----------------------------------------------------------------*/
306 :
307 46 : 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 46 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
312 46 : hMCParamUpmix->first_frame = 1;
313 46 : st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
314 46 : nchan_transport = st_ivas->nchan_transport;
315 :
316 46 : switch ( nchan_transport )
317 : {
318 46 : case 8:
319 46 : st_ivas->nCPE = 4;
320 46 : st_ivas->nSCE = 0;
321 46 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
322 46 : break;
323 : #ifdef DEBUGGING
324 : default:
325 : assert( 0 && "Number of TC not supported for MC ParamUpmix!" );
326 : #endif
327 : }
328 :
329 46 : hMCParamUpmix->hoa_encoder = NULL;
330 :
331 : /*-----------------------------------------------------------------*
332 : * set input parameters
333 : *-----------------------------------------------------------------*/
334 :
335 46 : hMCParamUpmix->num_freq_bands = (int16_t) ( output_Fs * INV_CLDFB_BANDWIDTH + 0.5f );
336 :
337 230 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
338 : {
339 184 : ivas_td_decorr_dec_open( &( hMCParamUpmix->hTdDecorr[i] ), output_Fs, 2, 1 );
340 : }
341 :
342 414 : for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
343 : {
344 368 : 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 368 : set_zero( hMCParamUpmix->pcm_delay[i], NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ) );
349 : }
350 :
351 : /* Head or external rotation */
352 46 : 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 || st_ivas->hCombinedOrientationData ) )
353 : {
354 37 : 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 37 : 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 46 : hMCParamUpmix->free_param_interpolator = 0;
363 46 : hMCParamUpmix->param_interpolator = NULL;
364 :
365 46 : 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 46 : hMCParamUpmix->free_param_interpolator = 1;
370 :
371 46 : ivas_dec_get_adapted_linear_interpolator( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator );
372 :
373 46 : 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 39 : buffer_mode = TC_BUFFER_MODE_RENDERER;
381 39 : nchan_tc = ivas_dec_get_num_tc_channels( st_ivas );
382 39 : nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
383 :
384 39 : if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_STEREO || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_MONO )
385 : {
386 0 : buffer_mode = TC_BUFFER_MODE_BUFFER;
387 0 : nchan_tc = st_ivas->hDecoderConfig->nchan_out;
388 0 : nchan_to_allocate = nchan_tc;
389 : }
390 39 : 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 38 : nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
393 : }
394 :
395 39 : granularity = ivas_dec_get_render_granularity( st_ivas->renderer_type, RENDERER_DISABLE, output_Fs );
396 :
397 39 : if ( ( error = ivas_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 46 : st_ivas->hMCParamUpmix = hMCParamUpmix;
404 :
405 46 : return error;
406 : }
407 :
408 :
409 : /*-------------------------------------------------------------------------
410 : * ivas_mc_paramupmix_dec_close()
411 : *
412 : * Close ParamUpmix MC memories
413 : *------------------------------------------------------------------------*/
414 :
415 1986 : 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 1986 : if ( hMCParamUpmix == NULL || *hMCParamUpmix == NULL )
422 : {
423 1940 : return;
424 : }
425 230 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
426 : {
427 184 : ivas_td_decorr_dec_close( &( ( *hMCParamUpmix )->hTdDecorr[i] ) );
428 : }
429 414 : for ( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
430 : {
431 368 : if ( ( *hMCParamUpmix )->pcm_delay[i] != NULL )
432 : {
433 368 : free( ( *hMCParamUpmix )->pcm_delay[i] );
434 : }
435 : }
436 46 : if ( ( *hMCParamUpmix )->param_interpolator != NULL )
437 : {
438 46 : if ( ( *hMCParamUpmix )->free_param_interpolator == 1 )
439 : {
440 46 : free( ( *hMCParamUpmix )->param_interpolator );
441 : }
442 : }
443 46 : if ( ( *hMCParamUpmix )->hoa_encoder != NULL )
444 : {
445 37 : free( ( *hMCParamUpmix )->hoa_encoder );
446 37 : ( *hMCParamUpmix )->hoa_encoder = NULL;
447 : }
448 46 : free( *hMCParamUpmix );
449 :
450 46 : *hMCParamUpmix = NULL;
451 :
452 46 : return;
453 : }
454 :
455 :
456 : /*-------------------------------------------------------------------------
457 : * paramupmix_td_decorr_process()
458 : *
459 : *
460 : *------------------------------------------------------------------------*/
461 :
462 5982 : static void paramupmix_td_decorr_process(
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 5982 : offset = (int16_t) ( output_frame * FRAMES_PER_SEC * IVAS_DECORR_PARM_LOOKAHEAD_TAU );
474 :
475 : /* Look-ahead delay */
476 29910 : for ( k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++ )
477 : {
478 23928 : mvr2r( pcm_in[k], pp_out_pcm[k], output_frame );
479 23928 : delay_signal( pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset );
480 :
481 : /* In ducking gains */
482 23928 : if ( hTdDecorr[k]->ducking_flag )
483 : {
484 23928 : ivas_td_decorr_get_ducking_gains( hTdDecorr[k]->pTrans_det, pcm_in[k], in_duck_gain, out_duck_gain, output_frame, 0 );
485 :
486 22419048 : for ( j = 0; j < output_frame; j++ )
487 : {
488 22395120 : pp_out_pcm[k][j] = pp_out_pcm[k][j] * in_duck_gain[j];
489 : }
490 : }
491 :
492 : /* All pass delay section */
493 23928 : 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 23928 : if ( hTdDecorr[k]->ducking_flag )
497 : {
498 22419048 : for ( j = 0; j < output_frame; j++ )
499 : {
500 22395120 : pp_out_pcm[k][j] = pp_out_pcm[k][j] * out_duck_gain[j];
501 : }
502 : }
503 : }
504 :
505 5982 : return;
506 : }
507 :
508 :
509 : /*-------------------------------------------------------------------------
510 : * ivas_param_upmix_dec_decorr_subframes()
511 : *
512 : *
513 : *------------------------------------------------------------------------*/
514 :
515 5914 : static void ivas_param_upmix_dec_decorr_subframes(
516 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
517 : const int16_t nSamplesForRendering /* i : number of samples provided */
518 : )
519 : {
520 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
521 : float *pPcm_tmp[MC_PARAMUPMIX_COMBINATIONS];
522 : float *p_tc[MC_PARAMUPMIX_COMBINATIONS];
523 : int16_t nchan_internal, ch;
524 : int16_t nSamplesLeftForTD, default_frame;
525 :
526 5914 : hMCParamUpmix = st_ivas->hMCParamUpmix;
527 5914 : assert( hMCParamUpmix );
528 :
529 5914 : push_wmops( "ivas_param_upmix_dec_decorr_subframes" );
530 :
531 : /* TD decorrelator */
532 5914 : default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC );
533 5914 : nSamplesLeftForTD = nSamplesForRendering;
534 5914 : nchan_internal = MC_PARAMUPMIX_COMBINATIONS;
535 :
536 29570 : for ( ch = 0; ch < nchan_internal; ch++ )
537 : {
538 23656 : pPcm_tmp[ch] = st_ivas->hTcBuffer->tc[ch + 8];
539 23656 : p_tc[ch] = st_ivas->hTcBuffer->tc[ch + 4];
540 : }
541 :
542 11896 : while ( nSamplesLeftForTD )
543 : {
544 5982 : int16_t nSamplesToDecorr = min( nSamplesLeftForTD, default_frame );
545 :
546 5982 : paramupmix_td_decorr_process( hMCParamUpmix->hTdDecorr, p_tc, pPcm_tmp, nSamplesToDecorr );
547 :
548 29910 : for ( ch = 0; ch < nchan_internal; ch++ )
549 : {
550 23928 : p_tc[ch] += nSamplesToDecorr;
551 : }
552 :
553 5982 : nSamplesLeftForTD -= nSamplesToDecorr;
554 : }
555 :
556 5914 : pop_wmops();
557 5914 : return;
558 : }
559 :
560 :
561 : /*****************************************************************************************/
562 : /* local functions */
563 : /*****************************************************************************************/
564 :
565 102716 : static void ps_pred_process_sf(
566 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix,
567 : DECODER_TC_BUFFER_HANDLE hTcBuffer,
568 : float qmf_mod_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */
569 : float qmf_mod_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
570 : float qmf_side_re[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* in/out */
571 : float qmf_side_im[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
572 : float *param_interpol,
573 : const int16_t ch,
574 : const int16_t slots_rendered )
575 : {
576 : float vmre, vmim, vsre, vsim;
577 : int16_t iqmf, ipar, ismp, iismp;
578 : float alpha_smp, beta_smp;
579 : float *alpha1, *alpha2;
580 : float *beta1, *beta2;
581 102716 : float *alpha_prev = hMCParamUpmix->alpha_prev[ch];
582 102716 : float *beta_prev = hMCParamUpmix->beta_prev[ch];
583 102716 : float *alpha_sf = hMCParamUpmix->alpha_sf[ch];
584 102716 : float *beta_sf = hMCParamUpmix->beta_sf[ch];
585 : float dalpha, dbeta, ifac;
586 : float alpha_start[IVAS_MAX_NUM_BANDS], beta_start[IVAS_MAX_NUM_BANDS];
587 :
588 102716 : const int16_t qmf_to_par_band[] = {
589 : 0, 1, 2, 3, 4, 5, 5, 6, 6, 7,
590 : 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
591 : 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
592 : 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
593 : 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
594 : 11, 11, 11, 11, 11, 11, 11, 11, 11, 11
595 : };
596 :
597 102716 : mvr2r( alpha_sf, alpha_start, IVAS_MAX_NUM_BANDS );
598 102716 : mvr2r( beta_sf, beta_start, IVAS_MAX_NUM_BANDS );
599 6265676 : for ( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ )
600 : {
601 6162960 : ipar = qmf_to_par_band[iqmf];
602 6162960 : alpha1 = alpha_prev;
603 6162960 : beta1 = beta_prev;
604 :
605 6162960 : ismp = 0;
606 6162960 : alpha2 = hMCParamUpmix->alphas[ch];
607 6162960 : beta2 = hMCParamUpmix->betas[ch];
608 6162960 : alpha_smp = alpha_start[ipar];
609 6162960 : beta_smp = beta_start[ipar];
610 :
611 28942080 : for ( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ )
612 : {
613 22779120 : if ( ( slots_rendered == 0 ) && ( iismp == 0 ) )
614 : {
615 1419360 : ifac = param_interpol[iismp];
616 : }
617 : else
618 : {
619 21359760 : ifac = param_interpol[iismp] - param_interpol[iismp - 1];
620 : }
621 22779120 : dalpha = ( alpha2[ipar] - alpha1[ipar] ) * ifac;
622 22779120 : dbeta = ( beta2[ipar] - beta1[ipar] ) * ifac;
623 :
624 22779120 : alpha_smp += dalpha;
625 22779120 : beta_smp += dbeta;
626 :
627 22779120 : vmre = qmf_mod_re[ismp][iqmf];
628 22779120 : vmim = qmf_mod_im[ismp][iqmf];
629 22779120 : vsre = qmf_side_re[ismp][iqmf];
630 22779120 : vsim = qmf_side_im[ismp][iqmf];
631 :
632 22779120 : qmf_side_re[ismp][iqmf] = alpha_smp * vmre + beta_smp * vsre;
633 22779120 : qmf_side_im[ismp][iqmf] = alpha_smp * vmim + beta_smp * vsim;
634 :
635 22779120 : ismp++;
636 : }
637 6162960 : alpha_sf[ipar] = alpha_smp;
638 6162960 : beta_sf[ipar] = beta_smp;
639 : }
640 :
641 102716 : return;
642 : }
643 :
644 25679 : static void ivas_mc_paramupmix_dec_sf(
645 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
646 : float *output_f[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels */
647 : )
648 : {
649 : int16_t i, ch, slot_idx, k;
650 : float *pPcm_temp[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/
651 : /*CLDFB*/
652 : float Cldfb_RealBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
653 : float Cldfb_ImagBuffer[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX];
654 : int16_t noparamupmix_delay, n_samples_rendered;
655 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
656 : int16_t subframeIdx, idx_in, maxBand;
657 : float Cldfb_RealBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
658 : float Cldfb_ImagBuffer_subfr[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
659 : float Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
660 : float Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
661 : int16_t slot_index_start;
662 :
663 25679 : hMCParamUpmix = st_ivas->hMCParamUpmix;
664 25679 : assert( hMCParamUpmix );
665 25679 : push_wmops( "ivas_mc_paramupmix_dec_sf" );
666 :
667 25679 : slot_index_start = st_ivas->hTcBuffer->slots_rendered;
668 128395 : for ( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
669 : {
670 102716 : pPcm_temp[2 * i] = output_f[i + 4]; /* un-decorrelated */
671 102716 : pPcm_temp[2 * i + 1] = output_f[i + 8]; /* decorrelated */
672 : }
673 :
674 : /* CLDFB Analysis*/
675 231111 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
676 : {
677 : /* slot loop for gathering the input data */
678 964736 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
679 : {
680 759304 : 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] );
681 : }
682 : }
683 :
684 128395 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
685 : {
686 102716 : ps_pred_process_sf( hMCParamUpmix,
687 : st_ivas->hTcBuffer,
688 102716 : Cldfb_RealBuffer[2 * ch], /* in/out */
689 102716 : Cldfb_ImagBuffer[2 * ch],
690 102716 : Cldfb_RealBuffer[2 * ch + 1], /* in/out decorr */
691 102716 : Cldfb_ImagBuffer[2 * ch + 1],
692 102716 : &hMCParamUpmix->param_interpolator[st_ivas->hTcBuffer->slots_rendered],
693 : ch,
694 102716 : st_ivas->hTcBuffer->slots_rendered );
695 :
696 : /*-- m, s -> l, r ----------------------------*/
697 482368 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
698 : {
699 23158772 : for ( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
700 : {
701 22779120 : float qlre = Cldfb_RealBuffer[2 * ch][slot_idx][k];
702 22779120 : float qlim = Cldfb_ImagBuffer[2 * ch][slot_idx][k];
703 22779120 : float qrre = Cldfb_RealBuffer[2 * ch + 1][slot_idx][k];
704 22779120 : float qrim = Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k];
705 :
706 22779120 : Cldfb_RealBuffer[2 * ch][slot_idx][k] = qlre + qrre;
707 22779120 : Cldfb_ImagBuffer[2 * ch][slot_idx][k] = qlim + qrim;
708 22779120 : Cldfb_RealBuffer[2 * ch + 1][slot_idx][k] = qlre - qrre;
709 22779120 : Cldfb_ImagBuffer[2 * ch + 1][slot_idx][k] = qlim - qrim;
710 : }
711 : }
712 : }
713 :
714 25679 : if ( st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV || st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV_ROOM )
715 : {
716 24999 : maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * st_ivas->hDecoderConfig->output_Fs ) / 48000 );
717 24999 : subframeIdx = st_ivas->hTcBuffer->subframes_rendered;
718 : /* fastconv binaural rendering and CLDFB synthesis */
719 : /* cldfb analysis of non-coupled, non-LFE channels */
720 24999 : idx_in = 0;
721 124995 : for ( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ )
722 : {
723 99996 : if ( st_ivas->hIntSetup.index_lfe[0] != ch )
724 : {
725 99356 : pPcm_temp[ch] = output_f[ch];
726 : /* slot loop for gathering the input data */
727 465568 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
728 : {
729 366212 : cldfbAnalysis_ts( &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
730 366212 : Cldfb_RealBuffer_subfr[idx_in][slot_idx],
731 366212 : Cldfb_ImagBuffer_subfr[idx_in][slot_idx],
732 366212 : maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in] );
733 : }
734 99356 : idx_in++;
735 : }
736 : }
737 :
738 : /* copy and reorder cldfb analysis of coupled channels */
739 124995 : for ( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ )
740 : {
741 499980 : for ( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
742 : {
743 399984 : mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
744 399984 : mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX );
745 399984 : mvr2r( Cldfb_RealBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
746 399984 : mvr2r( Cldfb_ImagBuffer[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX );
747 : }
748 99996 : idx_in += 2;
749 : }
750 :
751 24999 : if ( st_ivas->hCombinedOrientationData && st_ivas->renderer_type == RENDERER_BINAURAL_FASTCONV )
752 : {
753 113992 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
754 : {
755 89633 : ivas_param_mc_mc2sba_cldfb( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder, slot_idx, Cldfb_RealBuffer_subfr, Cldfb_ImagBuffer_subfr, maxBand, GAIN_LFE );
756 : }
757 : }
758 :
759 : /*LFE handling for split rendering cases*/
760 24999 : if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
761 : {
762 22559 : if ( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
763 : {
764 30880 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
765 : {
766 412165 : for ( ch = 0; ch < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ); ch++ )
767 : {
768 387920 : mvr2r( Cldfb_RealBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer[ch][slot_index_start + slot_idx], maxBand );
769 387920 : mvr2r( Cldfb_ImagBuffer_subfr[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer[ch][slot_index_start + slot_idx], maxBand );
770 : }
771 : }
772 :
773 6635 : st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
774 : }
775 : }
776 :
777 : /* Implement binaural rendering */
778 24999 : ivas_binRenderer( st_ivas->hBinRenderer,
779 22559 : ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
780 : st_ivas->hCombinedOrientationData,
781 24999 : st_ivas->hTcBuffer->subframe_nbslots[subframeIdx],
782 : Cldfb_RealBuffer_Binaural, Cldfb_ImagBuffer_Binaural,
783 : Cldfb_RealBuffer_subfr,
784 : Cldfb_ImagBuffer_subfr );
785 :
786 24999 : if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
787 : {
788 : int16_t pos_idx;
789 114122 : for ( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
790 : {
791 426144 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
792 : {
793 1003743 : for ( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
794 : {
795 669162 : ivas_CLDFB_RINGBUF_Push(
796 669162 : st_ivas->hSplitBinRend->hMultiBinCldfbData[pos_idx * BINAURAL_CHANNELS + ch],
797 669162 : Cldfb_RealBuffer_Binaural[pos_idx][ch][slot_idx],
798 669162 : Cldfb_ImagBuffer_Binaural[pos_idx][ch][slot_idx],
799 : maxBand );
800 : }
801 : }
802 : }
803 : }
804 :
805 : /* Implement CLDFB synthesis */
806 74997 : for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
807 : {
808 : float *RealBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
809 : float *ImagBuffer[MAX_PARAM_SPATIAL_SUBFRAMES];
810 :
811 234384 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
812 : {
813 184386 : RealBuffer[slot_idx] = Cldfb_RealBuffer_Binaural[0][ch][slot_idx];
814 184386 : ImagBuffer[slot_idx] = Cldfb_ImagBuffer_Binaural[0][ch][slot_idx];
815 : }
816 :
817 49998 : cldfbSynthesis( RealBuffer, ImagBuffer, &( output_f[ch][0] ), maxBand * st_ivas->hTcBuffer->subframe_nbslots[subframeIdx], st_ivas->cldfbSynDec[ch] );
818 : }
819 : }
820 : else
821 : {
822 : /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
823 680 : pPcm_temp[0] = output_f[4];
824 680 : pPcm_temp[1] = output_f[6];
825 680 : pPcm_temp[2] = output_f[5];
826 680 : pPcm_temp[3] = output_f[7];
827 680 : pPcm_temp[4] = output_f[8];
828 680 : pPcm_temp[5] = output_f[10];
829 680 : pPcm_temp[6] = output_f[9];
830 680 : pPcm_temp[7] = output_f[11];
831 :
832 : /* CLDFB synthesis */
833 6120 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
834 : {
835 27200 : for ( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
836 : {
837 : float *ptr_im[1], *ptr_re[1];
838 21760 : ptr_re[0] = Cldfb_RealBuffer[ch][slot_idx];
839 21760 : ptr_im[0] = Cldfb_ImagBuffer[ch][slot_idx];
840 :
841 21760 : cldfbSynthesis( ptr_re, ptr_im, &( pPcm_temp[ch][hMCParamUpmix->num_freq_bands * slot_idx] ),
842 21760 : hMCParamUpmix->num_freq_bands, st_ivas->cldfbSynDec[ch] );
843 : }
844 : }
845 :
846 : /* adjust delay of other channels */
847 680 : noparamupmix_delay = NS2SA( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS );
848 680 : n_samples_rendered = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] * hMCParamUpmix->num_freq_bands;
849 680 : if ( n_samples_rendered > noparamupmix_delay )
850 : {
851 0 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
852 : {
853 : /*delay is handled within LFE decoder*/
854 0 : if ( st_ivas->hIntSetup.index_lfe[0] != ch )
855 : {
856 : float tmp_buf[L_SUBFRAME5MS_48k];
857 0 : mvr2r( &output_f[ch][n_samples_rendered - noparamupmix_delay], tmp_buf, noparamupmix_delay );
858 0 : mvr2r( output_f[ch], &output_f[ch][noparamupmix_delay], n_samples_rendered - noparamupmix_delay );
859 0 : mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], noparamupmix_delay );
860 0 : mvr2r( tmp_buf, hMCParamUpmix->pcm_delay[ch], noparamupmix_delay );
861 : }
862 : }
863 : }
864 : else
865 : {
866 3400 : for ( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
867 : {
868 2720 : if ( st_ivas->hIntSetup.index_lfe[0] != ch )
869 : {
870 : float tmp_buf[L_SUBFRAME5MS_48k];
871 2040 : mvr2r( &output_f[ch][0], tmp_buf, n_samples_rendered );
872 2040 : mvr2r( hMCParamUpmix->pcm_delay[ch], output_f[ch], n_samples_rendered );
873 2040 : mvr2r( &hMCParamUpmix->pcm_delay[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay[ch][0], noparamupmix_delay - n_samples_rendered );
874 2040 : mvr2r( tmp_buf, &hMCParamUpmix->pcm_delay[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered );
875 : }
876 : }
877 : }
878 : }
879 :
880 25679 : st_ivas->hTcBuffer->slots_rendered += st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered];
881 25679 : st_ivas->hTcBuffer->subframes_rendered++;
882 :
883 25679 : pop_wmops();
884 25679 : return;
885 : }
886 :
887 :
888 552384 : static int16_t huff_read(
889 : Decoder_State *st,
890 : const int16_t ( *ht )[2] )
891 : {
892 552384 : int16_t node = 0;
893 552384 : uint16_t next_bit = 0;
894 :
895 : do
896 : {
897 1162123 : next_bit = st->bit_stream[st->next_bit_pos];
898 1162123 : st->next_bit_pos++;
899 1162123 : node = ht[node][next_bit];
900 1162123 : } while ( node > 0 );
901 :
902 552384 : return -( node + 1 );
903 : }
904 :
905 :
906 46032 : static void huffman_decode(
907 : Decoder_State *st,
908 : const PAR_TYPE parType,
909 : int32_t *vq )
910 : {
911 : const int16_t( *huff_node_table )[2];
912 : int16_t iv, nquant, offset;
913 :
914 46032 : nquant = 0;
915 46032 : switch ( parType )
916 : {
917 23016 : case ALPHA:
918 23016 : nquant = ivas_mc_paramupmix_alpha_quant_table.nquant;
919 23016 : break;
920 23016 : case BETA:
921 23016 : nquant = ivas_mc_paramupmix_beta_quant_table[0].nquant;
922 23016 : break;
923 0 : default:
924 0 : assert( 0 );
925 : }
926 :
927 46032 : offset = nquant - 1; /* range of df [-(nquant - 1), nquant - 1] */
928 :
929 46032 : st->next_bit_pos++;
930 46032 : switch ( parType )
931 : {
932 23016 : case ALPHA:
933 23016 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha;
934 23016 : break;
935 23016 : case BETA:
936 23016 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta;
937 23016 : break;
938 0 : default:
939 0 : huff_node_table = NULL;
940 0 : assert( 0 );
941 : }
942 46032 : vq[0] = huff_read( st, huff_node_table );
943 :
944 46032 : switch ( parType )
945 : {
946 23016 : case ALPHA:
947 23016 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha;
948 23016 : break;
949 23016 : case BETA:
950 23016 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta;
951 23016 : break;
952 0 : default:
953 0 : assert( 0 );
954 : }
955 :
956 552384 : for ( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ )
957 : {
958 506352 : vq[iv] = huff_read( st, huff_node_table ) + vq[iv - 1] - offset;
959 : }
960 :
961 46032 : return;
962 : }
963 :
964 :
965 23016 : static void dequant_alpha(
966 : int32_t *vq,
967 : float *v )
968 : {
969 : int16_t iv;
970 23016 : const ACPL_QUANT_TABLE *quant_table = &ivas_mc_paramupmix_alpha_quant_table;
971 :
972 299208 : for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
973 : {
974 276192 : v[iv] = quant_table->data[vq[iv]];
975 : }
976 :
977 23016 : return;
978 : }
979 :
980 :
981 23016 : static void dequant_beta(
982 : int32_t *aq,
983 : int32_t *bq,
984 : float *beta )
985 : {
986 : int16_t iv;
987 : const ACPL_QUANT_TABLE *quant_table;
988 :
989 299208 : for ( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
990 : {
991 276192 : quant_table = &ivas_mc_paramupmix_beta_quant_table[ivas_param_upmx_mx_qmap[aq[iv]]];
992 276192 : beta[iv] = quant_table->data[bq[iv]];
993 : }
994 :
995 23016 : return;
996 : }
997 :
998 :
999 46032 : static void get_ec_data(
1000 : Decoder_State *st,
1001 : const PAR_TYPE parType,
1002 : int32_t *parQ,
1003 : int32_t *alphaQEnv,
1004 : float ab[IVAS_MAX_NUM_BANDS] )
1005 : {
1006 46032 : huffman_decode( st, parType, parQ );
1007 :
1008 46032 : if ( parType == ALPHA )
1009 : {
1010 23016 : dequant_alpha( parQ, ab );
1011 23016 : mvl2l( parQ, alphaQEnv, (int16_t) IVAS_MAX_NUM_BANDS );
1012 : }
1013 : else
1014 : {
1015 23016 : dequant_beta( alphaQEnv, parQ, ab );
1016 : }
1017 :
1018 46032 : return;
1019 : }
|