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 <stdint.h>
35 : #include "options.h"
36 : #include "cnst.h"
37 : #include "prot_fx.h"
38 : #include "ivas_prot_fx.h"
39 : #include "ivas_prot_rend_fx.h"
40 : #include "ivas_cnst.h"
41 : #include "rom_com.h"
42 : #include "ivas_rom_com.h"
43 : #include "ivas_rom_dec.h"
44 : #include "math.h"
45 : #include "wmc_auto.h"
46 : #include "rom_dec.h"
47 : #include "ivas_rom_com_fx.h"
48 :
49 : /*-----------------------------------------------------------------------*
50 : * Local arrays
51 : *-----------------------------------------------------------------------*/
52 :
53 : /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
54 : const Word16 MC_PARAMUPMIX_CHIDX1[MC_PARAMUPMIX_COMBINATIONS] = { 0, 1, 4, 5 };
55 : const Word16 MC_PARAMUPMIX_CHIDX2[MC_PARAMUPMIX_COMBINATIONS] = { 2, 3, 6, 7 };
56 : const Word16 qmf_to_par_band[] = {
57 : 0, 1, 2, 3, 4, 5, 5, 6, 6, 7,
58 : 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
59 : 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
60 : 10, 10, 11, 11, 11, 11, 11, 11, 11, 11,
61 : 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
62 : 11, 11, 11, 11, 11, 11, 11, 11, 11, 11
63 : };
64 :
65 : /*-----------------------------------------------------------------------*
66 : * Local function prototypes
67 : *-----------------------------------------------------------------------*/
68 :
69 : static void ps_pred_process_sf( MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, DECODER_TC_BUFFER_HANDLE hTcBuffer, Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], Word16 *param_interpol_fx, const Word16 ch, const Word16 slots_rendered );
70 :
71 : static void ivas_mc_paramupmix_dec_sf( Decoder_Struct *st_ivas, Word32 *output_fx[MAX_OUTPUT_CHANNELS] );
72 :
73 : static void ivas_param_upmix_dec_decorr_subframes( Decoder_Struct *st_ivas, const Word16 nSamplesForRendering );
74 :
75 : static Word16 huff_read( Decoder_State *st, const Word16 ( *ht )[2] );
76 :
77 : static void huffman_decode( Decoder_State *st, const PAR_TYPE parType, Word32 *vq );
78 :
79 : static void dequant_alpha( Word32 *vq, Word32 *v );
80 :
81 : static void dequant_beta( Word32 *aq, Word32 *bq, Word32 *beta );
82 :
83 : static void get_ec_data( Decoder_State *st, const PAR_TYPE parType, Word32 *parQ, Word32 *alphaQEnv, Word32 ab[IVAS_MAX_NUM_BANDS] );
84 :
85 :
86 : /*-------------------------------------------------------------------------
87 : * ivas_mc_paramupmix_dec_read_BS()
88 : *
89 : * Read the ParamUpmix MC metadata
90 : *------------------------------------------------------------------------*/
91 :
92 790 : void ivas_mc_paramupmix_dec_read_BS(
93 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
94 : Decoder_State *st0, /* i/o: decoder state structure */
95 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix, /* i/o: decoder MC Param-Upmix handle */
96 : Word16 *nb_bits /* o : number of bits written */
97 : )
98 : {
99 : Word16 i, k;
100 : Word32 alpha_quant[IVAS_MAX_NUM_BANDS];
101 : Word16 nb_bits_read_orig;
102 : Word16 next_bit_pos_orig, last_bit_pos;
103 : UWord16 bstr_meta[MAX_BITS_METADATA], *bit_stream_orig;
104 :
105 790 : push_wmops( "mc_paramupmix_read_bs" );
106 790 : *nb_bits = 0;
107 790 : move16();
108 :
109 790 : IF( st0->bfi )
110 : {
111 0 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
112 : {
113 0 : FOR( k = 0; k < IVAS_MAX_NUM_BANDS; k++ )
114 : {
115 0 : hMCParamUpmix->alphas_fx[i][k] = hMCParamUpmix->alpha_prev_fx[i][k]; // Q28
116 0 : hMCParamUpmix->betas_fx[i][k] = hMCParamUpmix->beta_prev_fx[i][k]; // Q28
117 0 : move32();
118 0 : move32();
119 : }
120 : }
121 :
122 0 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
123 : {
124 0 : Copy32( hMCParamUpmix->alpha_prev_fx[i], hMCParamUpmix->alpha_sf_fx[i], IVAS_MAX_NUM_BANDS );
125 0 : Copy32( hMCParamUpmix->beta_prev_fx[i], hMCParamUpmix->beta_sf_fx[i], IVAS_MAX_NUM_BANDS );
126 : }
127 :
128 0 : hMCParamUpmix->first_frame = 1;
129 0 : move16();
130 : }
131 : ELSE /* IF (!st->bfi) */
132 : {
133 790 : bit_stream_orig = st0->bit_stream;
134 790 : next_bit_pos_orig = st0->next_bit_pos;
135 790 : move16();
136 790 : Word32 L_temp = Mpy_32_32( st_ivas->hDecoderConfig->ivas_total_brate, ONE_BY_FRAMES_PER_SEC_Q31 );
137 790 : last_bit_pos = extract_l( L_sub( L_temp, 1 ) );
138 790 : nb_bits_read_orig = 0;
139 790 : move16();
140 790 : last_bit_pos = sub( last_bit_pos, nb_bits_read_orig ); /* reverse the bitstream for easier reading of indices */
141 790 : Word16 len = s_min( MAX_BITS_METADATA, last_bit_pos );
142 1975790 : FOR( i = 0; i < len; i++ )
143 : {
144 1975000 : bstr_meta[i] = st_ivas->bit_stream[last_bit_pos - i];
145 1975000 : move16();
146 : }
147 790 : st0->bit_stream = bstr_meta;
148 790 : st0->next_bit_pos = 0;
149 790 : move16();
150 790 : st0->bits_frame = s_min( MAX_BITS_METADATA, add( last_bit_pos, 1 ) );
151 790 : move16();
152 790 : st0->total_brate = st_ivas->hDecoderConfig->ivas_total_brate; /* to avoid BER detect */
153 790 : move32();
154 :
155 :
156 790 : IF( EQ_16( hMCParamUpmix->first_frame, 0 ) )
157 : {
158 3890 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
159 : {
160 3112 : Copy32( hMCParamUpmix->alphas_fx[i], hMCParamUpmix->alpha_prev_fx[i], IVAS_MAX_NUM_BANDS );
161 3112 : Copy32( hMCParamUpmix->betas_fx[i], hMCParamUpmix->beta_prev_fx[i], IVAS_MAX_NUM_BANDS );
162 : }
163 : }
164 :
165 3950 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
166 : {
167 3160 : get_ec_data( st0, ALPHA, hMCParamUpmix->alpha_quant[i], alpha_quant, hMCParamUpmix->alphas_fx[i] );
168 :
169 3160 : get_ec_data( st0, BETA, hMCParamUpmix->beta_quant[i], alpha_quant, hMCParamUpmix->betas_fx[i] );
170 : }
171 790 : *nb_bits = add( *nb_bits, st0->next_bit_pos );
172 790 : move16();
173 790 : st0->bit_stream = bit_stream_orig;
174 790 : st0->next_bit_pos = next_bit_pos_orig;
175 790 : move16();
176 :
177 790 : IF( hMCParamUpmix->first_frame )
178 : {
179 60 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
180 : {
181 48 : Copy32( hMCParamUpmix->alphas_fx[i], hMCParamUpmix->alpha_prev_fx[i], IVAS_MAX_NUM_BANDS );
182 48 : Copy32( hMCParamUpmix->betas_fx[i], hMCParamUpmix->beta_prev_fx[i], IVAS_MAX_NUM_BANDS );
183 : }
184 12 : hMCParamUpmix->first_frame = 0;
185 12 : move16();
186 : }
187 :
188 3950 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
189 : {
190 3160 : Copy32( hMCParamUpmix->alpha_prev_fx[i], hMCParamUpmix->alpha_sf_fx[i], IVAS_MAX_NUM_BANDS );
191 3160 : Copy32( hMCParamUpmix->beta_prev_fx[i], hMCParamUpmix->beta_sf_fx[i], IVAS_MAX_NUM_BANDS );
192 : }
193 : }
194 :
195 790 : pop_wmops();
196 790 : return;
197 : }
198 :
199 :
200 : /*-------------------------------------------------------------------------
201 : * ivas_mc_paramupmix_dec_digest_tc()
202 : *
203 : *
204 : *------------------------------------------------------------------------*/
205 :
206 780 : void ivas_mc_paramupmix_dec_digest_tc(
207 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
208 : const UWord8 nCldfbSlots, /* i : number of CLFBS slots in the transport channels*/
209 : const Word16 nSamplesForRendering /* i : number of samples provided */
210 : )
211 : {
212 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
213 780 : hMCParamUpmix = st_ivas->hMCParamUpmix;
214 780 : assert( hMCParamUpmix );
215 780 : push_wmops( "ivas_mc_paramupmix_dec_digest_tc" );
216 :
217 780 : ivas_param_upmix_dec_decorr_subframes( st_ivas, nSamplesForRendering );
218 :
219 : /* adapt subframes */
220 780 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
221 :
222 780 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, nCldfbSlots, hMCParamUpmix->param_interpolator_fx );
223 :
224 780 : pop_wmops();
225 780 : return;
226 : }
227 :
228 :
229 : /*-------------------------------------------------------------------------
230 : * ivas_mc_paramupmix_dec_render()
231 : *
232 : *
233 : *------------------------------------------------------------------------*/
234 :
235 780 : void ivas_mc_paramupmix_dec_render(
236 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
237 : const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested */
238 : UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered */
239 : UWord16 *nSamplesAvailable, /* o : number of CLDFB slots still to render */
240 : Word32 *input_fx[], /* i : core-coder transport channels Qx*/
241 : Word32 *output_fx[] /* i/o: synthesized core-coder transport channels Qx*/
242 : )
243 : {
244 : Word16 slots_to_render, first_sf, last_sf, subframe_idx;
245 : UWord16 slot_size, ch;
246 : Word32 *output_local_fx[MAX_OUTPUT_CHANNELS];
247 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
248 :
249 780 : hMCParamUpmix = st_ivas->hMCParamUpmix;
250 780 : assert( hMCParamUpmix );
251 :
252 780 : push_wmops( "ivas_mc_paramupmix_dec_render" );
253 :
254 13260 : FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS; ch++ )
255 : {
256 12480 : output_local_fx[ch] = output_fx[ch];
257 : }
258 :
259 780 : slot_size = st_ivas->hTcBuffer->n_samples_granularity;
260 780 : move16();
261 :
262 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
263 780 : slots_to_render = s_min( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) );
264 780 : *nSamplesRendered = imult1616( slots_to_render, (Word16) slot_size );
265 780 : move16();
266 780 : first_sf = st_ivas->hTcBuffer->subframes_rendered;
267 780 : move16();
268 780 : last_sf = first_sf;
269 780 : move16();
270 :
271 10140 : FOR( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ )
272 : {
273 9360 : Copy32( input_fx[ch], output_local_fx[ch], *nSamplesRendered );
274 : }
275 :
276 3900 : WHILE( slots_to_render > 0 )
277 : {
278 3120 : slots_to_render = sub( slots_to_render, st_ivas->hTcBuffer->subframe_nbslots[last_sf] );
279 3120 : last_sf = add( last_sf, 1 );
280 : }
281 : {
282 :
283 :
284 3900 : FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
285 : {
286 3120 : Word16 n_samples_sf = imult1616( (Word16) slot_size, st_ivas->hTcBuffer->subframe_nbslots[subframe_idx] );
287 :
288 3120 : ivas_mc_paramupmix_dec_sf( st_ivas, output_local_fx );
289 :
290 3120 : Word16 num_ch = s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec_fx( st_ivas, -1, -1 ) );
291 47920 : FOR( ch = 0; ch < num_ch; ch++ )
292 : {
293 44800 : output_local_fx[ch] += n_samples_sf;
294 : }
295 :
296 : /* update combined orientation access index */
297 3120 : ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
298 : }
299 : }
300 :
301 780 : *nSamplesAvailable = imult1616( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), (Word16) slot_size );
302 780 : move16();
303 :
304 780 : pop_wmops();
305 780 : return;
306 : }
307 :
308 :
309 : /*-------------------------------------------------------------------------
310 : * ivas_mc_paramupmix_dec_open()
311 : *
312 : * Open Parametric MC decoder handle
313 : *-------------------------------------------------------------------------*/
314 :
315 12 : ivas_error ivas_mc_paramupmix_dec_open(
316 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
317 : )
318 : {
319 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
320 : Word32 output_Fs;
321 : Word16 nchan_transport;
322 : UWord16 i;
323 : ivas_error error;
324 :
325 12 : error = IVAS_ERR_OK;
326 12 : move32();
327 :
328 : /*-----------------------------------------------------------------*
329 : * prepare library opening
330 : *-----------------------------------------------------------------*/
331 :
332 12 : IF( ( hMCParamUpmix = (MC_PARAMUPMIX_DEC_HANDLE) malloc( sizeof( MC_PARAMUPMIX_DEC_DATA ) ) ) == NULL )
333 : {
334 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Param-Upmix MC\n" ) );
335 : }
336 12 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
337 12 : move32();
338 12 : hMCParamUpmix->first_frame = 1;
339 12 : move16();
340 12 : st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
341 12 : move16();
342 12 : nchan_transport = st_ivas->nchan_transport;
343 12 : move16();
344 :
345 12 : SWITCH( nchan_transport )
346 : {
347 12 : case 8:
348 12 : st_ivas->nCPE = 4;
349 12 : move16();
350 12 : st_ivas->nSCE = 0;
351 12 : move16();
352 12 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
353 12 : move16();
354 12 : BREAK;
355 : }
356 :
357 12 : hMCParamUpmix->hoa_encoder_fx = NULL;
358 :
359 : /*-----------------------------------------------------------------*
360 : * set input parameters
361 : *-----------------------------------------------------------------*/
362 :
363 12 : hMCParamUpmix->num_freq_bands = (Word16) Mpy_32_32_r( output_Fs, INV_CLDFB_BANDWIDTH_Q31 );
364 12 : move16();
365 :
366 60 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
367 : {
368 48 : ivas_td_decorr_dec_open_fx( &( hMCParamUpmix->hTdDecorr[i] ), output_Fs, 2, 1 );
369 : }
370 :
371 108 : FOR( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
372 : {
373 96 : IF( ( hMCParamUpmix->pcm_delay_fx[i] = (Word32 *) malloc( NS2SA_FX2( output_Fs, IVAS_FB_DEC_DELAY_NS ) * sizeof( Word32 ) ) ) == NULL )
374 : {
375 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for delay buffer\n" ) );
376 : }
377 96 : set32_fx( hMCParamUpmix->pcm_delay_fx[i], 0, NS2SA_FX2( output_Fs, IVAS_FB_DEC_DELAY_NS ) );
378 : }
379 :
380 : /* Head or external rotation */
381 12 : IF( ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) && ( st_ivas->hDecoderConfig->Opt_Headrotation || st_ivas->hDecoderConfig->Opt_ExternalOrientation ) )
382 : {
383 :
384 3 : IF( ( hMCParamUpmix->hoa_encoder_fx = (Word32 *) malloc( st_ivas->hTransSetup.nchan_out_woLFE * MAX_INTERN_CHANNELS * sizeof( Word32 ) ) ) == NULL )
385 : {
386 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Parametric MC\n" ) );
387 : }
388 3 : compute_hoa_encoder_mtx_fx( st_ivas->hTransSetup.ls_azimuth_fx, st_ivas->hTransSetup.ls_elevation_fx, hMCParamUpmix->hoa_encoder_fx, st_ivas->hTransSetup.nchan_out_woLFE, HEAD_ROTATION_HOA_ORDER );
389 : }
390 :
391 : /* allocate transport channels*/
392 12 : hMCParamUpmix->free_param_interpolator = 0;
393 12 : move16();
394 :
395 12 : IF( ( hMCParamUpmix->param_interpolator_fx = (Word16 *) malloc( MAX_JBM_CLDFB_TIMESLOTS * sizeof( Word16 ) ) ) == NULL )
396 : {
397 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for interpolator\n" ) );
398 : }
399 12 : hMCParamUpmix->free_param_interpolator = 1;
400 12 : move16();
401 :
402 12 : ivas_jbm_dec_get_adapted_linear_interpolator_fx( DEFAULT_JBM_CLDFB_TIMESLOTS, DEFAULT_JBM_CLDFB_TIMESLOTS, hMCParamUpmix->param_interpolator_fx );
403 :
404 12 : IF( st_ivas->hTcBuffer == NULL )
405 : {
406 : Word16 nchan_to_allocate;
407 : Word16 nchan_tc;
408 : TC_BUFFER_MODE buffer_mode;
409 :
410 5 : buffer_mode = TC_BUFFER_MODE_RENDERER;
411 5 : nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas );
412 5 : nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
413 5 : move16();
414 5 : move16();
415 :
416 5 : test();
417 5 : test();
418 5 : test();
419 5 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
420 : {
421 0 : buffer_mode = TC_BUFFER_MODE_BUFFER;
422 0 : move32();
423 0 : nchan_tc = st_ivas->hDecoderConfig->nchan_out;
424 0 : move16();
425 0 : nchan_to_allocate = nchan_tc;
426 0 : move16();
427 : }
428 5 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
429 : {
430 4 : nchan_to_allocate = MC_PARAMUPMIX_MAX_INPUT_CHANS;
431 4 : move16();
432 : }
433 :
434 5 : IF( NE_32( ( error = ivas_jbm_dec_tc_buffer_open_fx( st_ivas, buffer_mode, nchan_tc, nchan_to_allocate, nchan_to_allocate, NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ) ) ), IVAS_ERR_OK ) )
435 : {
436 0 : return error;
437 : }
438 : }
439 12 : st_ivas->hMCParamUpmix = hMCParamUpmix;
440 :
441 12 : return error;
442 : }
443 :
444 :
445 : /*-------------------------------------------------------------------------
446 : * ivas_mc_paramupmix_dec_close()
447 : *
448 : * Close ParamUpmix MC memories
449 : *------------------------------------------------------------------------*/
450 :
451 875 : void ivas_mc_paramupmix_dec_close(
452 : MC_PARAMUPMIX_DEC_HANDLE *hMCParamUpmix /* i/o: Parametric MC decoder handle */
453 : )
454 : {
455 : Word16 i;
456 :
457 875 : IF( hMCParamUpmix == NULL || *hMCParamUpmix == NULL )
458 : {
459 863 : return;
460 : }
461 60 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
462 : {
463 48 : ivas_td_decorr_dec_close( &( ( *hMCParamUpmix )->hTdDecorr[i] ) );
464 : }
465 108 : FOR( i = 0; i < MC_PARAMUPMIX_MAX_TRANSPORT_CHANS; i++ )
466 : {
467 96 : IF( ( *hMCParamUpmix )->pcm_delay_fx[i] != NULL )
468 : {
469 96 : free( ( *hMCParamUpmix )->pcm_delay_fx[i] );
470 : }
471 : }
472 12 : IF( ( *hMCParamUpmix )->param_interpolator_fx != NULL )
473 : {
474 12 : IF( EQ_16( ( *hMCParamUpmix )->free_param_interpolator, 1 ) )
475 : {
476 12 : free( ( *hMCParamUpmix )->param_interpolator_fx );
477 : }
478 : }
479 12 : IF( ( *hMCParamUpmix )->hoa_encoder_fx != NULL )
480 : {
481 3 : free( ( *hMCParamUpmix )->hoa_encoder_fx );
482 3 : ( *hMCParamUpmix )->hoa_encoder_fx = NULL;
483 : }
484 12 : free( *hMCParamUpmix );
485 :
486 12 : *hMCParamUpmix = NULL;
487 :
488 12 : return;
489 : }
490 :
491 :
492 : /*-------------------------------------------------------------------------
493 : * paramupmix_td_decorr_process_jbm_fx()
494 : *
495 : *
496 : *------------------------------------------------------------------------*/
497 :
498 780 : static void paramupmix_td_decorr_process_jbm_fx(
499 : ivas_td_decorr_state_t *hTdDecorr[], /* i/o: SPAR Covar. decoder handle */
500 : Word32 *pcm_in[], /* i : input audio channels */
501 : Word32 **pp_out_pcm, /* o : output audio channels */
502 : const Word16 output_frame, /* i : output frame length */
503 : Word16 *q_format )
504 : {
505 : Word16 j, k;
506 : Word16 offset;
507 : Word32 in_duck_gain[L_FRAME48k], out_duck_gain[L_FRAME48k]; // Q30
508 :
509 780 : offset = idiv1616( output_frame, 10 );
510 :
511 : /* Look-ahead delay */
512 3900 : FOR( k = 0; k < MC_PARAMUPMIX_COMBINATIONS; k++ )
513 : {
514 3120 : Copy32( pcm_in[k], pp_out_pcm[k], output_frame );
515 3120 : delay_signal32_fx( pp_out_pcm[k], output_frame, hTdDecorr[k]->look_ahead_buf, offset );
516 :
517 : /* In ducking gains */
518 3120 : IF( hTdDecorr[k]->ducking_flag )
519 : {
520 3120 : ivas_td_decorr_get_ducking_gains_fx( hTdDecorr[k]->pTrans_det, pcm_in[k], in_duck_gain, out_duck_gain, output_frame, 0 );
521 :
522 2614320 : FOR( j = 0; j < output_frame; j++ )
523 : {
524 2611200 : pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], in_duck_gain[j] );
525 2611200 : move16();
526 : }
527 3120 : q_format[k] = sub( q_format[k], Q1 ); // q_format--
528 3120 : move16();
529 : }
530 :
531 : /* All pass delay section */
532 3120 : ivas_td_decorr_APD_iir_filter_fx( &hTdDecorr[k]->APD_filt_state[0], pp_out_pcm[k], hTdDecorr[k]->num_apd_sections, output_frame );
533 :
534 : /* Out ducking gains */
535 3120 : IF( hTdDecorr[k]->ducking_flag )
536 : {
537 2614320 : FOR( j = 0; j < output_frame; j++ )
538 : {
539 2611200 : pp_out_pcm[k][j] = Mpy_32_32( pp_out_pcm[k][j], out_duck_gain[j] );
540 2611200 : move32();
541 : }
542 3120 : q_format[k] = sub( q_format[k], Q1 ); // q_format--
543 3120 : move16();
544 : }
545 : }
546 :
547 780 : return;
548 : }
549 :
550 :
551 : /*-------------------------------------------------------------------------
552 : * ivas_param_upmix_dec_decorr_subframes()
553 : *
554 : *
555 : *------------------------------------------------------------------------*/
556 :
557 780 : static void ivas_param_upmix_dec_decorr_subframes(
558 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
559 : const Word16 nSamplesForRendering )
560 : {
561 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
562 : Word32 *pPcm_tmp_fx[MC_PARAMUPMIX_COMBINATIONS];
563 : Word32 *p_tc_fx[MC_PARAMUPMIX_COMBINATIONS];
564 : Word16 nchan_internal, ch;
565 : Word16 nSamplesLeftForTD, default_frame;
566 :
567 780 : hMCParamUpmix = st_ivas->hMCParamUpmix;
568 780 : assert( hMCParamUpmix );
569 :
570 780 : push_wmops( "ivas_param_upmix_dec_decorr_subframes" );
571 :
572 : /* TD decorrelator */
573 780 : default_frame = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) );
574 780 : nSamplesLeftForTD = nSamplesForRendering;
575 780 : move16();
576 780 : nchan_internal = MC_PARAMUPMIX_COMBINATIONS;
577 780 : move16();
578 :
579 3900 : FOR( ch = 0; ch < nchan_internal; ch++ )
580 : {
581 3120 : pPcm_tmp_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 8]; // Q11
582 3120 : p_tc_fx[ch] = st_ivas->hTcBuffer->tc_fx[ch + 4]; // Q11
583 : }
584 :
585 1560 : WHILE( nSamplesLeftForTD )
586 : {
587 780 : Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame );
588 :
589 : {
590 : Word16 i, q_format[MC_PARAMUPMIX_COMBINATIONS];
591 :
592 3900 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
593 : {
594 3120 : q_format[i] = Q11;
595 3120 : move16();
596 : }
597 :
598 780 : paramupmix_td_decorr_process_jbm_fx( hMCParamUpmix->hTdDecorr, p_tc_fx, pPcm_tmp_fx, nSamplesToDecorr, q_format );
599 :
600 3900 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
601 : {
602 3120 : Scale_sig32( pPcm_tmp_fx[i], nSamplesToDecorr, sub( Q11, q_format[i] ) ); // Setting Q to changed q in q_format
603 : }
604 : }
605 3900 : FOR( ch = 0; ch < nchan_internal; ch++ )
606 : {
607 3120 : p_tc_fx[ch] += nSamplesToDecorr;
608 : }
609 :
610 780 : nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr );
611 : }
612 :
613 780 : pop_wmops();
614 780 : return;
615 : }
616 :
617 :
618 : /*****************************************************************************************/
619 : /* local functions */
620 : /*****************************************************************************************/
621 :
622 12480 : static void ps_pred_process_sf(
623 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix,
624 : DECODER_TC_BUFFER_HANDLE hTcBuffer,
625 : Word32 qmf_mod_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
626 : /* in/out */ // Q6
627 : Word32 qmf_mod_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], // Q6
628 : Word32 qmf_side_re_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX],
629 : /* in/out */ // Q6
630 : Word32 qmf_side_im_fx[JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX], // Q6
631 : Word16 *param_interpol_fx, // Q15
632 : const Word16 ch,
633 : const Word16 slots_rendered )
634 : {
635 : Word32 vmre_fx, vmim_fx, vsre_fx, vsim_fx;
636 : Word16 iqmf, ipar, ismp, iismp;
637 : Word32 alpha_smp_fx, beta_smp_fx;
638 : Word32 *alpha1_fx, *alpha2_fx;
639 : Word32 *beta1_fx, *beta2_fx;
640 12480 : Word32 *alpha_prev_fx = hMCParamUpmix->alpha_prev_fx[ch]; // Q28
641 12480 : Word32 *beta_prev_fx = hMCParamUpmix->beta_prev_fx[ch]; // Q28
642 12480 : Word32 *alpha_sf_fx = hMCParamUpmix->alpha_sf_fx[ch]; // Q28
643 12480 : Word32 *beta_sf_fx = hMCParamUpmix->beta_sf_fx[ch]; // Q28
644 : Word32 dalpha_fx, dbeta_fx;
645 : Word16 ifac_fx;
646 : Word32 alpha_start_fx[IVAS_MAX_NUM_BANDS], beta_start_fx[IVAS_MAX_NUM_BANDS];
647 : Word32 res_a, res_b;
648 :
649 :
650 12480 : Copy32( alpha_sf_fx, alpha_start_fx, IVAS_MAX_NUM_BANDS ); // Q28
651 12480 : Copy32( beta_sf_fx, beta_start_fx, IVAS_MAX_NUM_BANDS ); // Q28
652 761280 : FOR( iqmf = 0; iqmf < CLDFB_NO_CHANNELS_MAX; iqmf++ )
653 : {
654 748800 : ipar = qmf_to_par_band[iqmf];
655 748800 : move16();
656 748800 : alpha1_fx = alpha_prev_fx; // Q28
657 748800 : move16();
658 748800 : beta1_fx = beta_prev_fx; // Q28
659 748800 : move16();
660 :
661 748800 : ismp = 0;
662 748800 : move16();
663 748800 : alpha2_fx = hMCParamUpmix->alphas_fx[ch];
664 748800 : beta2_fx = hMCParamUpmix->betas_fx[ch];
665 748800 : alpha_smp_fx = alpha_start_fx[ipar]; // Q28
666 748800 : move32();
667 748800 : beta_smp_fx = beta_start_fx[ipar]; // Q28
668 748800 : move32();
669 :
670 3744000 : FOR( iismp = 0; iismp < hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered]; iismp++ )
671 : {
672 2995200 : IF( ( slots_rendered == 0 ) && ( iismp == 0 ) )
673 : {
674 187200 : ifac_fx = param_interpol_fx[iismp]; // Q15
675 187200 : move16();
676 : }
677 : ELSE
678 : {
679 2808000 : ifac_fx = sub( param_interpol_fx[iismp], param_interpol_fx[iismp - 1] ); // Q15
680 : }
681 2995200 : dalpha_fx = Mpy_32_16_1( L_sub( alpha2_fx[ipar], alpha1_fx[ipar] ), ifac_fx ); // Q28
682 2995200 : dbeta_fx = Mpy_32_16_1( L_sub( beta2_fx[ipar], beta1_fx[ipar] ), ifac_fx );
683 :
684 2995200 : alpha_smp_fx = L_add( alpha_smp_fx, dalpha_fx );
685 2995200 : beta_smp_fx = L_add( dbeta_fx, beta_smp_fx );
686 :
687 2995200 : vmre_fx = qmf_mod_re_fx[ismp][iqmf]; // Q6
688 2995200 : move32();
689 2995200 : vmim_fx = qmf_mod_im_fx[ismp][iqmf]; // Q6
690 2995200 : move32();
691 2995200 : vsre_fx = qmf_side_re_fx[ismp][iqmf]; // Q6
692 2995200 : move32();
693 2995200 : vsim_fx = qmf_side_im_fx[ismp][iqmf]; // Q6
694 2995200 : move32();
695 :
696 2995200 : res_a = L_shl( Mpy_32_32( alpha_smp_fx, vmre_fx ), Q31 - Q28 ); // Q6
697 2995200 : res_b = L_shl( Mpy_32_32( beta_smp_fx, vsre_fx ), Q31 - Q28 ); // Q6
698 2995200 : qmf_side_re_fx[ismp][iqmf] = L_add( res_a, res_b ); // Q6
699 2995200 : move32();
700 :
701 2995200 : res_a = L_shl( Mpy_32_32( alpha_smp_fx, vmim_fx ), Q31 - Q28 ); // Q6
702 2995200 : res_b = L_shl( Mpy_32_32( beta_smp_fx, vsim_fx ), Q31 - Q28 ); // Q6
703 2995200 : qmf_side_im_fx[ismp][iqmf] = L_add( res_a, res_b );
704 2995200 : move32();
705 :
706 2995200 : ismp = add( ismp, 1 );
707 : }
708 748800 : alpha_sf_fx[ipar] = alpha_smp_fx;
709 748800 : move32();
710 748800 : beta_sf_fx[ipar] = beta_smp_fx;
711 748800 : move32();
712 : }
713 :
714 12480 : return;
715 : }
716 :
717 :
718 3120 : static void ivas_mc_paramupmix_dec_sf(
719 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
720 : Word32 *output_fx[MAX_OUTPUT_CHANNELS] /* i/o: synthesized core-coder transport channels Q11*/
721 : )
722 : {
723 : Word16 i, ch, slot_idx, k;
724 : Word32 *pPcm_temp_fx[MC_PARAMUPMIX_COMBINATIONS * 2]; /* decorrelated and undecorrelated*/
725 : /*CLDFB*/
726 3120 : Word32 Cldfb_RealBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; // Q6
727 3120 : Word32 Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_MAX_TRANSPORT_CHANS][JBM_CLDFB_SLOTS_IN_SUBFRAME][CLDFB_NO_CHANNELS_MAX] = { 0 }; // Q6
728 :
729 : Word16 noparamupmix_delay, n_samples_rendered;
730 : MC_PARAMUPMIX_DEC_HANDLE hMCParamUpmix;
731 : Word16 subframeIdx, idx_in, maxBand;
732 3120 : Word32 Cldfb_RealBuffer_subfr_fx[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] = { 0 };
733 3120 : Word32 Cldfb_ImagBuffer_subfr_fx[MAX_INTERN_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX] = { 0 };
734 :
735 : Word32 Cldfb_RealBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
736 : Word32 Cldfb_ImagBuffer_Binaural_fx[MAX_HEAD_ROT_POSES][BINAURAL_CHANNELS][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX];
737 : int16_t slot_index_start;
738 :
739 3120 : hMCParamUpmix = st_ivas->hMCParamUpmix;
740 3120 : assert( hMCParamUpmix );
741 3120 : push_wmops( "ivas_mc_paramupmix_dec_sf" );
742 :
743 3120 : slot_index_start = st_ivas->hTcBuffer->slots_rendered;
744 :
745 15600 : FOR( i = 0; i < MC_PARAMUPMIX_COMBINATIONS; i++ )
746 : {
747 12480 : pPcm_temp_fx[2 * i] = output_fx[i + 4]; /* un-decorrelated Q11*/
748 12480 : pPcm_temp_fx[2 * i + 1] = output_fx[i + 8]; /* decorrelated Q11*/
749 : }
750 :
751 : /* CLDFB Analysis*/
752 28080 : FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
753 : {
754 : /* slot loop for gathering the input data */
755 124800 : FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
756 : {
757 99840 : Word16 q_cldfb = 11;
758 99840 : move16();
759 99840 : cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][hMCParamUpmix->num_freq_bands * slot_idx] ), Cldfb_RealBuffer_fx[ch][slot_idx], Cldfb_ImagBuffer_fx[ch][slot_idx], hMCParamUpmix->num_freq_bands, st_ivas->cldfbAnaDec[ch], &q_cldfb );
760 : }
761 : }
762 :
763 15600 : FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
764 : {
765 12480 : ps_pred_process_sf( hMCParamUpmix,
766 : st_ivas->hTcBuffer,
767 12480 : Cldfb_RealBuffer_fx[2 * ch], /* in/out */
768 12480 : Cldfb_ImagBuffer_fx[2 * ch],
769 12480 : Cldfb_RealBuffer_fx[2 * ch + 1], /* in/out decorr */
770 12480 : Cldfb_ImagBuffer_fx[2 * ch + 1],
771 12480 : &hMCParamUpmix->param_interpolator_fx[st_ivas->hTcBuffer->slots_rendered],
772 : ch,
773 12480 : st_ivas->hTcBuffer->slots_rendered );
774 :
775 : /*-- m, s -> l, r ----------------------------*/
776 62400 : FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
777 : {
778 3045120 : FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
779 : {
780 2995200 : Word32 qlre_fx = Cldfb_RealBuffer_fx[2 * ch][slot_idx][k]; // Q6
781 2995200 : Word32 qlim_fx = Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k]; // Q6
782 2995200 : Word32 qrre_fx = Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k]; // Q6
783 2995200 : Word32 qrim_fx = Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k]; // Q6
784 2995200 : move32();
785 2995200 : move32();
786 2995200 : move32();
787 2995200 : move32();
788 :
789 2995200 : Cldfb_RealBuffer_fx[2 * ch][slot_idx][k] = L_add( qlre_fx, qrre_fx );
790 2995200 : Cldfb_ImagBuffer_fx[2 * ch][slot_idx][k] = L_add( qlim_fx, qrim_fx );
791 2995200 : Cldfb_RealBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub( qlre_fx, qrre_fx );
792 2995200 : Cldfb_ImagBuffer_fx[2 * ch + 1][slot_idx][k] = L_sub( qlim_fx, qrim_fx );
793 2995200 : move32();
794 2995200 : move32();
795 2995200 : move32();
796 2995200 : move32();
797 : }
798 : }
799 : }
800 :
801 3120 : test();
802 3120 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
803 2440 : {
804 : Word16 temp_e;
805 2440 : maxBand = BASOP_Util_Divide3232_Scale( (Word32) W_mult0_32_32( CLDFB_NO_CHANNELS_MAX, st_ivas->hDecoderConfig->output_Fs ), 48000, &temp_e );
806 2440 : maxBand = shr( maxBand, sub( 15, temp_e ) );
807 2440 : subframeIdx = st_ivas->hTcBuffer->subframes_rendered;
808 2440 : move16();
809 : /* fastconv binaural rendering and CLDFB synthesis */
810 : /* cldfb analysis of non-coupled, non-LFE channels */
811 2440 : idx_in = 0;
812 2440 : move16();
813 12200 : FOR( ch = 0; ch < MC_PARAMUPMIX_MAX_INPUT_CHANS - 2 * MC_PARAMUPMIX_COMBINATIONS; ch++ )
814 : {
815 9760 : IF( st_ivas->hIntSetup.index_lfe[0] != ch )
816 : {
817 9120 : pPcm_temp_fx[ch] = output_fx[ch];
818 : /* slot loop for gathering the input data */
819 45600 : FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
820 : {
821 36480 : Word16 q_cldfb = 11;
822 36480 : move16();
823 :
824 36480 : cldfbAnalysis_ts_fx_fixed_q( &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ),
825 36480 : Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx],
826 36480 : Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx],
827 36480 : maxBand, st_ivas->cldfbAnaDec[2 * MC_PARAMUPMIX_COMBINATIONS + idx_in], &q_cldfb );
828 : }
829 9120 : idx_in = add( idx_in, 1 );
830 : }
831 : }
832 :
833 :
834 : /* copy and reorder cldfb analysis of coupled channels */
835 12200 : FOR( ch = 0; ch < MAX_PARAM_SPATIAL_SUBFRAMES; ch++ )
836 : {
837 48800 : FOR( slot_idx = 0; slot_idx < MAX_PARAM_SPATIAL_SUBFRAMES; slot_idx++ )
838 : {
839 39040 : Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6
840 39040 : Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX1[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6
841 39040 : Copy32( Cldfb_RealBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_RealBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6
842 39040 : Copy32( Cldfb_ImagBuffer_fx[MC_PARAMUPMIX_CHIDX2[ch]][slot_idx], Cldfb_ImagBuffer_subfr_fx[idx_in + 1][slot_idx], CLDFB_NO_CHANNELS_MAX ); // Q6
843 : }
844 9760 : idx_in = add( idx_in, 2 );
845 : }
846 :
847 2440 : IF( st_ivas->hCombinedOrientationData && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
848 : {
849 9000 : FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
850 : {
851 7200 : ivas_param_mc_mc2sba_cldfb_fx( st_ivas->hTransSetup, hMCParamUpmix->hoa_encoder_fx, slot_idx, Cldfb_RealBuffer_subfr_fx, Cldfb_ImagBuffer_subfr_fx, maxBand, GAIN_LFE_FX );
852 : }
853 : }
854 :
855 : /* Implement binaural rendering */
856 :
857 2440 : Word16 input_q = 6;
858 2440 : move16();
859 :
860 : /*LFE handling for split rendering cases*/
861 2440 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
862 : {
863 0 : IF( st_ivas->hSplitBinRend->hCldfbDataOut != NULL )
864 : {
865 0 : FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
866 : {
867 0 : FOR( ch = 0; ch < ( st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe ); ch++ )
868 : {
869 0 : Copy32( Cldfb_RealBuffer_subfr_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][add( slot_index_start, slot_idx )], maxBand );
870 0 : Copy32( Cldfb_ImagBuffer_subfr_fx[ch][slot_idx], st_ivas->hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][add( slot_index_start, slot_idx )], maxBand );
871 : }
872 : }
873 :
874 0 : st_ivas->hSplitBinRend->hCldfbDataOut->config = st_ivas->hIntSetup.output_config;
875 0 : move16();
876 : }
877 : }
878 :
879 : /* Implement binaural rendering */
880 : /*Binaural output in Q6 format*/
881 2440 : ivas_binRenderer_fx( st_ivas->hBinRenderer,
882 0 : ( st_ivas->hSplitBinRend == NULL ) ? NULL : &st_ivas->hSplitBinRend->splitrend.multiBinPoseData,
883 : st_ivas->hCombinedOrientationData,
884 2440 : st_ivas->hTcBuffer->subframe_nbslots[subframeIdx],
885 : Cldfb_RealBuffer_Binaural_fx, Cldfb_ImagBuffer_Binaural_fx,
886 : Cldfb_RealBuffer_subfr_fx,
887 : Cldfb_ImagBuffer_subfr_fx, &input_q );
888 :
889 : Word16 pos_idx;
890 2440 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
891 : {
892 0 : FOR( pos_idx = 0; pos_idx < st_ivas->hBinRenderer->numPoses; pos_idx++ )
893 : {
894 0 : FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
895 : {
896 0 : FOR( ch = 0; ch < st_ivas->hDecoderConfig->nchan_out; ch++ )
897 : {
898 0 : Copy32( Cldfb_RealBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_index_start, slot_idx )], maxBand );
899 0 : Copy32( Cldfb_ImagBuffer_Binaural_fx[pos_idx][ch][slot_idx], st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[add( i_mult( pos_idx, BINAURAL_CHANNELS ), ch )][add( slot_index_start, slot_idx )], maxBand );
900 : }
901 : }
902 : }
903 : }
904 :
905 :
906 : /* Implement CLDFB synthesis */
907 7320 : FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
908 : {
909 : Word32 *RealBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
910 : Word32 *ImagBuffer_fx[MAX_PARAM_SPATIAL_SUBFRAMES];
911 :
912 24400 : FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[subframeIdx]; slot_idx++ )
913 : {
914 19520 : RealBuffer_fx[slot_idx] = Cldfb_RealBuffer_Binaural_fx[0][ch][slot_idx]; // Q6
915 19520 : ImagBuffer_fx[slot_idx] = Cldfb_ImagBuffer_Binaural_fx[0][ch][slot_idx]; // Q6
916 : }
917 4880 : cldfbSynthesis_ivas_fx( RealBuffer_fx, ImagBuffer_fx, &( output_fx[ch][0] ), imult1616( maxBand, st_ivas->hTcBuffer->subframe_nbslots[subframeIdx] ), 6, 0, st_ivas->cldfbSynDec[ch] ); // output_fx returned in Q11
918 : }
919 : }
920 : ELSE
921 : {
922 : /* boxes = { 0 1 2 3 [4 6] [5 7] [8 10] [9 11] }; */
923 680 : pPcm_temp_fx[0] = output_fx[4];
924 680 : pPcm_temp_fx[1] = output_fx[6];
925 680 : pPcm_temp_fx[2] = output_fx[5];
926 680 : pPcm_temp_fx[3] = output_fx[7];
927 680 : pPcm_temp_fx[4] = output_fx[8];
928 680 : pPcm_temp_fx[5] = output_fx[10];
929 680 : pPcm_temp_fx[6] = output_fx[9];
930 680 : pPcm_temp_fx[7] = output_fx[11];
931 :
932 : /* CLDFB synthesis */
933 6120 : FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS * 2; ch++ )
934 : {
935 5440 : scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q5, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q11 -> Q5
936 5440 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5;
937 5440 : move16();
938 27200 : FOR( slot_idx = 0; slot_idx < st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered]; slot_idx++ )
939 : {
940 : Word32 *ptr_im_fx[1], *ptr_re_fx[1];
941 :
942 21760 : ptr_re_fx[0] = Cldfb_RealBuffer_fx[ch][slot_idx]; // Q6
943 21760 : ptr_im_fx[0] = Cldfb_ImagBuffer_fx[ch][slot_idx]; // Q6
944 21760 : cldfbSynthesis_ivas_fx( ptr_re_fx, ptr_im_fx, &( pPcm_temp_fx[ch][L_mult0( hMCParamUpmix->num_freq_bands, slot_idx )] ),
945 21760 : hMCParamUpmix->num_freq_bands, 0, 0, st_ivas->cldfbSynDec[ch] );
946 : }
947 5440 : scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, sub( Q11, st_ivas->cldfbSynDec[ch]->Q_cldfb_state ) ); // Q6 -> Q11
948 5440 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
949 5440 : move16();
950 : }
951 : // Done to keep entire buffer in q11
952 6120 : FOR( ch = 4; ch < 12; ch++ )
953 : {
954 5440 : Scale_sig32( output_fx[ch], imult1616( hMCParamUpmix->num_freq_bands, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] ), 6 ); // Q11
955 : }
956 : /* adjust delay of other channels */
957 680 : noparamupmix_delay = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_FB_DEC_DELAY_NS );
958 680 : n_samples_rendered = imult1616( st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered], hMCParamUpmix->num_freq_bands );
959 680 : IF( n_samples_rendered > noparamupmix_delay )
960 : {
961 0 : FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
962 : {
963 : #ifdef NONBE_1360_LFE_DELAY
964 : /*delay is handled within LFE decoder*/
965 0 : IF( NE_16( st_ivas->hIntSetup.index_lfe[0], ch ) )
966 : {
967 : #endif
968 : Word32 tmp_buf_fx[L_SUBFRAME5MS_48k];
969 0 : Copy32( &output_fx[ch][n_samples_rendered - noparamupmix_delay], tmp_buf_fx, noparamupmix_delay );
970 0 : Copy32( output_fx[ch], &output_fx[ch][noparamupmix_delay], sub( n_samples_rendered, noparamupmix_delay ) );
971 0 : Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], noparamupmix_delay );
972 0 : Copy32( tmp_buf_fx, hMCParamUpmix->pcm_delay_fx[ch], noparamupmix_delay );
973 : #ifdef NONBE_1360_LFE_DELAY
974 : }
975 : #endif
976 : }
977 : }
978 : ELSE
979 : {
980 3400 : FOR( ch = 0; ch < MC_PARAMUPMIX_COMBINATIONS; ch++ )
981 : {
982 : #ifdef NONBE_1360_LFE_DELAY
983 : /*delay is handled within LFE decoder*/
984 2720 : IF( NE_16( st_ivas->hIntSetup.index_lfe[0], ch ) )
985 : {
986 : #endif
987 : Word32 tmp_buf_fx[L_SUBFRAME5MS_48k];
988 2040 : Copy32( &output_fx[ch][0], tmp_buf_fx, n_samples_rendered );
989 2040 : Copy32( hMCParamUpmix->pcm_delay_fx[ch], output_fx[ch], n_samples_rendered );
990 2040 : Copy32( &hMCParamUpmix->pcm_delay_fx[ch][n_samples_rendered], &hMCParamUpmix->pcm_delay_fx[ch][0], sub( noparamupmix_delay, n_samples_rendered ) );
991 2040 : Copy32( tmp_buf_fx, &hMCParamUpmix->pcm_delay_fx[ch][noparamupmix_delay - n_samples_rendered], n_samples_rendered );
992 : #ifdef NONBE_1360_LFE_DELAY
993 : }
994 : #endif
995 : }
996 : }
997 : }
998 :
999 3120 : st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->subframes_rendered] );
1000 3120 : st_ivas->hTcBuffer->subframes_rendered = add( st_ivas->hTcBuffer->subframes_rendered, 1 );
1001 3120 : move16();
1002 3120 : move16();
1003 :
1004 3120 : pop_wmops();
1005 3120 : return;
1006 : }
1007 :
1008 :
1009 75840 : static Word16 huff_read(
1010 : Decoder_State *st,
1011 : const Word16 ( *ht )[2] )
1012 : {
1013 75840 : Word16 node = 0;
1014 75840 : UWord16 next_bit = 0;
1015 75840 : move16();
1016 75840 : move16();
1017 :
1018 : DO
1019 : {
1020 159463 : next_bit = st->bit_stream[st->next_bit_pos];
1021 159463 : move16();
1022 159463 : st->next_bit_pos = add( st->next_bit_pos, 1 );
1023 159463 : move16();
1024 159463 : node = ht[node][next_bit];
1025 159463 : move16();
1026 : }
1027 159463 : WHILE( node > 0 );
1028 :
1029 75840 : return negate( add( node, 1 ) );
1030 : }
1031 :
1032 :
1033 6320 : static void huffman_decode(
1034 : Decoder_State *st,
1035 : const PAR_TYPE parType,
1036 : Word32 *vq )
1037 : {
1038 : const Word16( *huff_node_table )[2];
1039 : Word16 iv, nquant, offset;
1040 :
1041 6320 : nquant = 0;
1042 6320 : move16();
1043 6320 : SWITCH( parType )
1044 : {
1045 3160 : case ALPHA:
1046 3160 : nquant = ivas_mc_paramupmix_alpha_quant_table_fx.nquant;
1047 3160 : move16();
1048 3160 : BREAK;
1049 3160 : case BETA:
1050 3160 : nquant = ivas_mc_paramupmix_beta_quant_table_fx[0].nquant;
1051 3160 : move16();
1052 3160 : BREAK;
1053 0 : default:
1054 0 : assert( 0 );
1055 : }
1056 :
1057 6320 : offset = sub( nquant, 1 ); /* range of df [-(nquant - 1), nquant - 1] */
1058 :
1059 6320 : st->next_bit_pos++;
1060 6320 : SWITCH( parType )
1061 : {
1062 3160 : case ALPHA:
1063 3160 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.alpha;
1064 3160 : BREAK;
1065 3160 : case BETA:
1066 3160 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df0.beta;
1067 3160 : BREAK;
1068 0 : default:
1069 0 : huff_node_table = NULL;
1070 0 : assert( 0 );
1071 : }
1072 6320 : vq[0] = huff_read( st, huff_node_table );
1073 6320 : move32();
1074 :
1075 6320 : SWITCH( parType )
1076 : {
1077 3160 : case ALPHA:
1078 3160 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df.alpha;
1079 3160 : BREAK;
1080 3160 : case BETA:
1081 3160 : huff_node_table = ivas_mc_paramupmix_huff_nodes_df.beta;
1082 3160 : BREAK;
1083 0 : default:
1084 0 : assert( 0 );
1085 : }
1086 :
1087 75840 : FOR( iv = 1; iv < IVAS_MAX_NUM_BANDS; iv++ )
1088 : {
1089 69520 : vq[iv] = L_sub( L_add( huff_read( st, huff_node_table ), vq[iv - 1] ), offset );
1090 69520 : move32();
1091 : }
1092 :
1093 6320 : return;
1094 : }
1095 :
1096 :
1097 3160 : static void dequant_alpha(
1098 : Word32 *vq,
1099 : Word32 *v )
1100 : {
1101 : Word16 iv;
1102 3160 : const ACPL_QUANT_TABLE_FX *quant_table = &ivas_mc_paramupmix_alpha_quant_table_fx; // Q28
1103 :
1104 41080 : FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
1105 : {
1106 37920 : v[iv] = quant_table->data[vq[iv]]; // Q28
1107 37920 : move32();
1108 : }
1109 :
1110 3160 : return;
1111 : }
1112 :
1113 :
1114 3160 : static void dequant_beta(
1115 : Word32 *aq,
1116 : Word32 *bq,
1117 : Word32 *beta )
1118 : {
1119 : Word16 iv;
1120 : const ACPL_QUANT_TABLE_FX *quant_table;
1121 :
1122 41080 : FOR( iv = 0; iv < IVAS_MAX_NUM_BANDS; iv++ )
1123 : {
1124 37920 : quant_table = &ivas_mc_paramupmix_beta_quant_table_fx[ivas_param_upmx_mx_qmap[aq[iv]]]; // Q28
1125 37920 : beta[iv] = quant_table->data[bq[iv]]; // Q28
1126 37920 : move32();
1127 : }
1128 :
1129 3160 : return;
1130 : }
1131 :
1132 :
1133 6320 : static void get_ec_data(
1134 : Decoder_State *st,
1135 : const PAR_TYPE parType,
1136 : Word32 *parQ,
1137 : Word32 *alphaQEnv,
1138 : Word32 ab[IVAS_MAX_NUM_BANDS] )
1139 : {
1140 6320 : huffman_decode( st, parType, parQ );
1141 :
1142 6320 : IF( EQ_32( parType, ALPHA ) )
1143 : {
1144 3160 : dequant_alpha( parQ, ab ); // Qab = Q28
1145 3160 : Copy32( parQ, alphaQEnv, (Word16) IVAS_MAX_NUM_BANDS );
1146 : }
1147 : ELSE
1148 : {
1149 3160 : dequant_beta( alphaQEnv, parQ, ab ); // Qab = Q28
1150 : }
1151 :
1152 6320 : return;
1153 : }
|