Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #include <stdint.h>
34 : #include "options.h"
35 : #include "cnst.h"
36 : #include "ivas_cnst.h"
37 : #include "rom_com.h"
38 : #include "prot_fx.h"
39 : #include "ivas_prot_fx.h"
40 : #include "ivas_prot_rend_fx.h"
41 : #include "ivas_rom_com.h"
42 : #include <math.h>
43 : #include "wmc_auto.h"
44 : #include "ivas_prot_fx.h"
45 : #ifdef DEBUGGING
46 : #include "debug.h"
47 : #endif
48 :
49 :
50 : /*-----------------------------------------------------------------------*
51 : * Local function prototypes
52 : *-----------------------------------------------------------------------*/
53 :
54 : static void ivas_jbm_dec_copy_tc( Decoder_Struct *st_ivas, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *data, Word32 *tc_digest_f[], Word16 data_q );
55 :
56 : static void ivas_jbm_dec_tc_buffer_playout_fx( Decoder_Struct *st_ivas, const UWord16 nSamplesAsked, UWord16 *nSamplesRendered, Word32 *output_fx[] );
57 :
58 : static void ivas_jbm_dec_copy_masa_meta_to_buffer( Decoder_Struct *st_ivas );
59 :
60 : static void ivas_jbm_masa_sf_to_slot_map( Decoder_Struct *st_ivas, const Word16 nCldfbTs );
61 :
62 :
63 : static Word16 ceil_fx16( Word16 inp, Word16 Q );
64 230248 : static Word16 ceil_fx16( Word16 inp, Word16 Q )
65 : {
66 230248 : Word16 ret = shr( inp, Q );
67 230248 : IF( ( s_and( inp, sub( shl( 1, Q ), 1 ) ) ) > 0 )
68 : {
69 2955 : ret = add( ret, 1 );
70 : }
71 230248 : return ret;
72 : }
73 :
74 : /*--------------------------------------------------------------------------*
75 : * ivas_jbm_dec_tc()
76 : *
77 : * Principal IVAS JBM decoder routine, decoding of metadata and transport channels
78 : *--------------------------------------------------------------------------*/
79 :
80 396879 : ivas_error ivas_jbm_dec_tc_fx(
81 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
82 : Word32 *data_fx /*Q11*/
83 : )
84 : {
85 : Word16 n, output_frame, nchan_out, i, ii;
86 : Decoder_State *st; /* used for bitstream handling */
87 : Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS]; /* buffer for output synthesis */
88 : Word16 nchan_remapped;
89 : Word16 nb_bits_metadata[MAX_SCE + 1];
90 : Word32 output_Fs, ivas_total_brate;
91 : AUDIO_CONFIG output_config;
92 : ivas_error error;
93 : Word16 num_md_sub_frames;
94 : Word32 ism_total_brate;
95 : Word16 s;
96 :
97 : CPE_DEC_HANDLE hCPE;
98 : SCE_DEC_HANDLE hSCE;
99 396879 : push_wmops( "ivas_jbm_dec_tc" );
100 :
101 : /*----------------------------------------------------------------*
102 : * Initialization of local vars after struct has been set
103 : *----------------------------------------------------------------*/
104 :
105 396879 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
106 396879 : move32();
107 396879 : nchan_out = st_ivas->hTcBuffer->nchan_transport_jbm;
108 396879 : move16();
109 396879 : output_config = st_ivas->hDecoderConfig->output_config;
110 396879 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
111 396879 : move32();
112 :
113 396879 : output_frame = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) ) /* output_Fs / FRAMES_PER_SEC */;
114 :
115 5159427 : FOR( n = 0; n < MAX_TRANSPORT_CHANNELS; n++ )
116 : {
117 4762548 : p_output_fx[n] = st_ivas->p_output_fx[n];
118 :
119 4762548 : IF( p_output_fx[n] != NULL )
120 : {
121 2230243 : set32_fx( p_output_fx[n], 0, L_FRAME48k );
122 : }
123 : }
124 :
125 396879 : IF( st_ivas->hDecoderConfig->Opt_tsm == 0 )
126 : {
127 2735838 : FOR( n = 0; n < ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ )
128 : {
129 2358364 : set_zero_fx( st_ivas->p_output_fx[n], L_FRAME48k );
130 2358364 : st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n];
131 : }
132 377474 : st_ivas->hTcBuffer->no_channels = ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
133 377474 : move16();
134 : }
135 :
136 : Word16 ch;
137 :
138 :
139 : /*----------------------------------------------------------------*
140 : * Decoding + pre-rendering
141 : *----------------------------------------------------------------*/
142 :
143 396879 : test();
144 396879 : test();
145 396879 : IF( st_ivas->bfi != 0 && st_ivas->ini_frame == 0 )
146 : {
147 : /* zero output when first frame(s) is lost */
148 0 : FOR( n = 0; n < nchan_out; n++ )
149 : {
150 0 : set32_fx( p_output_fx[n], 0, output_frame );
151 : }
152 : }
153 396879 : ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
154 : {
155 71432 : st_ivas->hCPE[0]->element_brate = ivas_total_brate;
156 71432 : move32();
157 71432 : Word16 q_output = 11;
158 71432 : move16();
159 71432 : set32_fx( &p_output_fx[0][0], 0, L_FRAME48k );
160 71432 : set32_fx( &p_output_fx[1][0], 0, L_FRAME48k );
161 :
162 71432 : IF( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, 0 ) ) != IVAS_ERR_OK )
163 : {
164 0 : return error;
165 : }
166 :
167 71432 : IF( NE_16( q_output, Q11 ) )
168 : {
169 0 : Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11
170 0 : Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11
171 : }
172 :
173 : /* HP filtering */
174 190396 : FOR( n = 0; n < s_min( nchan_out, st_ivas->nchan_transport ); n++ )
175 : {
176 118964 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
177 : }
178 :
179 71432 : test();
180 71432 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) )
181 : {
182 0 : s = Q16 - Q11;
183 0 : move16();
184 0 : s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) );
185 0 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i )
186 : {
187 0 : Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s)
188 : }
189 0 : ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx );
190 0 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i )
191 : {
192 0 : Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11
193 : }
194 : }
195 : }
196 325447 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
197 : {
198 : /* Metadata decoding and configuration */
199 93837 : test();
200 93837 : IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) )
201 2151 : {
202 2151 : ivas_ism_dtx_dec_fx( st_ivas, nb_bits_metadata );
203 :
204 2151 : set32_fx( p_output_fx[st_ivas->hISMDTX.sce_id_dtx], 0, L_FRAME48k );
205 :
206 2151 : IF( ( error = ivas_sce_dec_fx( st_ivas, st_ivas->hISMDTX.sce_id_dtx, &p_output_fx[st_ivas->hISMDTX.sce_id_dtx], output_frame, nb_bits_metadata[st_ivas->hISMDTX.sce_id_dtx] ) ) != IVAS_ERR_OK )
207 : {
208 0 : return error;
209 : }
210 : Word16 Q_cngNoiseLevel[MAX_SCE];
211 10755 : FOR( ch = 0; ch < 4; ch++ )
212 : {
213 8604 : IF( st_ivas->hSCE[ch] != NULL )
214 : {
215 5310 : Word16 shift = getScaleFactor32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
216 5310 : if ( LT_16( sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
217 : {
218 1938 : shift = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
219 : }
220 5310 : scale_sig32( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-(cngNoiseLevelExp -shift) )
221 5310 : st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
222 5310 : Q_cngNoiseLevel[ch] = sub( 31, st_ivas->hSCE[ch]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp );
223 5310 : move16();
224 5310 : move16();
225 : }
226 : }
227 2151 : ivas_ism_dtx_limit_noise_energy_for_near_silence_fx( st_ivas->hSCE, st_ivas->hISMDTX.sce_id_dtx, st_ivas->nchan_transport, Q_cngNoiseLevel );
228 : }
229 91686 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
230 : {
231 15884 : IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, st_ivas->hParamIsmDec->hParamIsm, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ), IVAS_ERR_OK ) )
232 : {
233 0 : return error;
234 : }
235 : }
236 : ELSE /* ISM_MODE_DISC */
237 : {
238 75802 : IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ivas_total_brate, st_ivas->nchan_ism, &( st_ivas->nchan_transport ), st_ivas->hIsmMetaData, st_ivas->hSCE, st_ivas->bfi, nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hSCE[0]->hCoreCoder[0] ) ), IVAS_ERR_OK ) )
239 : {
240 0 : return error;
241 : }
242 : }
243 :
244 333337 : FOR( n = 0; n < st_ivas->nchan_transport; n++ )
245 : {
246 : /* for DTX frames, dominant object has already been decoded before */
247 239500 : test();
248 239500 : test();
249 239500 : IF( !( ( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) || EQ_32( ivas_total_brate, FRAME_NO_DATA ) ) && EQ_16( n, st_ivas->hISMDTX.sce_id_dtx ) ) )
250 : {
251 237349 : set32_fx( p_output_fx[n], 0, L_FRAME48k );
252 :
253 237349 : IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, n, &p_output_fx[n], output_frame, nb_bits_metadata[n] ) ), IVAS_ERR_OK ) )
254 : {
255 0 : return error;
256 : }
257 : }
258 :
259 : /* HP filtering */
260 239500 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
261 : }
262 :
263 93837 : test();
264 93837 : test();
265 93837 : test();
266 93837 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
267 : {
268 3970 : ivas_mono_downmix_render_passive_fx( st_ivas, p_output_fx, output_frame );
269 :
270 3970 : Scale_sig32( p_output_fx[0], L_FRAME48k, 3 );
271 : }
272 89867 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) && ( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) ) )
273 : {
274 : /* loudness correction */
275 7955 : ivas_dirac_dec_binaural_sba_gain_fx( p_output_fx, st_ivas->nchan_transport, output_frame ); /*returns Q-1*/
276 :
277 23865 : FOR( i = 0; i < st_ivas->nchan_transport; i++ )
278 : {
279 15910 : Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q
280 : }
281 : }
282 : }
283 231610 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
284 151232 : {
285 151232 : set16_fx( nb_bits_metadata, 0, MAX_SCE );
286 :
287 :
288 : /* read parameters from the bitstream */
289 151232 : test();
290 151232 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && st_ivas->hQMetaData != NULL )
291 : {
292 : // st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
293 :
294 32208 : IF( st_ivas->nSCE > 0 )
295 : {
296 13800 : st = st_ivas->hSCE[0]->hCoreCoder[0];
297 : }
298 : ELSE
299 : {
300 18408 : st = st_ivas->hCPE[0]->hCoreCoder[0];
301 : }
302 :
303 32208 : IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
304 : {
305 0 : return error;
306 : }
307 :
308 32208 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
309 : {
310 4859 : ivas_jbm_dec_copy_masa_meta_to_buffer( st_ivas );
311 : }
312 : }
313 119024 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
314 : {
315 119024 : IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) )
316 : {
317 0 : return error;
318 : }
319 : }
320 :
321 151232 : test();
322 151232 : IF( EQ_16( st_ivas->nchan_transport, CPE_CHANNELS ) && GE_16( st_ivas->nCPE, 1 ) )
323 : {
324 52895 : st_ivas->hCPE[0]->brate_surplus = 0;
325 52895 : move32();
326 52895 : st_ivas->hCPE[0]->element_brate = ivas_total_brate;
327 52895 : move32();
328 : }
329 :
330 : /* core-decoding of transport channels */
331 151232 : Word16 q_output = Q11;
332 151232 : move16();
333 151232 : IF( EQ_16( st_ivas->nSCE, 1 ) )
334 : {
335 49099 : set32_fx( p_output_fx[0], 0, L_FRAME48k );
336 :
337 49099 : IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
338 : {
339 0 : return error;
340 : }
341 : }
342 102133 : ELSE IF( EQ_16( st_ivas->nCPE, 1 ) )
343 : {
344 52895 : set32_fx( &p_output_fx[0][0], 0, L_FRAME48k );
345 52895 : set32_fx( &p_output_fx[1][0], 0, L_FRAME48k );
346 :
347 52895 : IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
348 : {
349 0 : return error;
350 : }
351 :
352 52895 : IF( NE_16( q_output, Q11 ) )
353 : {
354 0 : Scale_sig32( p_output_fx[0], L_FRAME48k, sub( Q11, q_output ) ); // Q11
355 0 : Scale_sig32( p_output_fx[1], L_FRAME48k, sub( Q11, q_output ) ); // Q11
356 : }
357 : }
358 49238 : ELSE IF( GT_16( st_ivas->nCPE, 1 ) )
359 : {
360 49238 : IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
361 : {
362 0 : return error;
363 : }
364 : }
365 :
366 : /* TCs remapping */
367 151232 : nchan_remapped = st_ivas->nchan_transport;
368 151232 : move16();
369 :
370 151232 : test();
371 151232 : test();
372 151232 : test();
373 151232 : test();
374 151232 : test();
375 151232 : IF( st_ivas->sba_dirac_stereo_flag )
376 : {
377 6610 : nchan_remapped = nchan_out;
378 6610 : move16();
379 :
380 6610 : IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) )
381 : {
382 20540 : FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ )
383 : {
384 13930 : Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14
385 : }
386 6610 : SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
387 : Word16 nchan_transport;
388 6610 : nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
389 6610 : move16();
390 6610 : nchan_out = nchan_transport;
391 6610 : move16();
392 6610 : ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx ), ( p_output_fx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );
393 :
394 6610 : IF( st_ivas->hSpar->hPCA != NULL )
395 : {
396 0 : ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, p_output_fx );
397 : }
398 :
399 6610 : ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate ) );
400 : }
401 : {
402 : Word16 q;
403 6610 : hCPE = st_ivas->hCPE[0];
404 6610 : hSCE = st_ivas->hSCE[0];
405 :
406 6610 : s = 0;
407 6610 : move16();
408 19830 : FOR( i = 0; i < 2; i++ )
409 : {
410 13220 : s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 ) /* Guard bits */; // L_frame should be used instead of L_FRAME48k */
411 : }
412 19830 : FOR( i = 0; i < 2; i++ )
413 : {
414 13220 : Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s)
415 : }
416 6610 : hCPE->hStereoDft->q_dft = add( Q11, s );
417 6610 : move16();
418 6610 : IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
419 : {
420 61 : hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft;
421 61 : move16();
422 61 : hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft;
423 61 : move16();
424 : }
425 6610 : q = hCPE->hStereoDft->q_dft;
426 6610 : move16();
427 6610 : scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
428 19830 : FOR( i = 0; i < CPE_CHANNELS; ++i )
429 : {
430 13220 : scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
431 13220 : scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
432 : }
433 6610 : IF( hCPE->hCoreCoder[0] != NULL )
434 : {
435 6610 : Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q
436 6610 : Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q
437 6610 : hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q;
438 6610 : move16();
439 : }
440 6610 : IF( hCPE->hStereoDft != NULL )
441 : {
442 6610 : IF( LE_16( st_ivas->nchan_transport, 1 ) )
443 : {
444 2970 : st = hCPE->hCoreCoder[0];
445 2970 : test();
446 2970 : test();
447 2970 : test();
448 2970 : test();
449 2970 : test();
450 2970 : IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && EQ_16( st->core, ACELP_CORE ) && EQ_16( st->con_tcx, 1 ) ) )
451 : {
452 1349 : test();
453 1349 : test();
454 1349 : test();
455 1349 : test();
456 1349 : test();
457 1349 : test();
458 1349 : test();
459 1349 : test();
460 1349 : IF( ( ( ( st->last_core != ACELP_CORE ) || ( EQ_16( st->prev_bfi, 1 ) && ( st->last_core == ACELP_CORE ) && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */
461 : {
462 1251 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
463 : }
464 98 : ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */
465 : {
466 98 : IF( !st->tcxonly )
467 : {
468 98 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
469 : }
470 : }
471 : }
472 : ELSE /* ACELP core */
473 : {
474 1621 : test();
475 1621 : test();
476 1621 : IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */
477 : {
478 82 : test();
479 82 : test();
480 82 : test();
481 82 : test();
482 82 : IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) )
483 : {
484 82 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
485 : }
486 : }
487 : }
488 : }
489 6610 : scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft
490 6610 : hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft;
491 6610 : move16();
492 : }
493 :
494 6610 : IF( hSCE != NULL )
495 : {
496 2970 : Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_hb_synth_fx ) ); // q_dft
497 2970 : hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft;
498 2970 : move16();
499 2970 : Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mult_32_16( hCPE->hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ), sub( hCPE->hStereoDft->q_dft, hSCE->q_save_synth_fx ) ); // q_dft
500 2970 : hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft;
501 2970 : move16();
502 : }
503 19830 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
504 : {
505 13220 : scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
506 13220 : hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft;
507 13220 : move16();
508 : }
509 19830 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
510 : {
511 13220 : Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx
512 : }
513 :
514 6610 : ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame, st_ivas->ivas_format == MC_FORMAT );
515 :
516 19830 : FOR( i = 0; i < 2; i++ )
517 : {
518 13220 : Scale_sig32( p_output_fx[i], L_FRAME48k, negate( s ) );
519 : }
520 19830 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
521 : {
522 13220 : Scale_sig32( &hCPE->prev_synth_fx[ii][0], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->q_prev_synth_fx ) ); // Q11
523 : }
524 :
525 6610 : scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) );
526 19830 : FOR( i = 0; i < CPE_CHANNELS; ++i )
527 : {
528 13220 : scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
529 13220 : scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
530 : }
531 :
532 6610 : IF( hCPE->hCoreCoder[0] != NULL )
533 : {
534 6610 : Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB - q ); // Q_old_wtda_LB
535 6610 : Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda - q ); // Q_old_wtda_LB
536 : }
537 6610 : IF( hCPE->hStereoDft != NULL )
538 : {
539 6610 : IF( LE_16( st_ivas->nchan_transport, 1 ) )
540 : {
541 2970 : st = hCPE->hCoreCoder[0];
542 2970 : test();
543 2970 : test();
544 2970 : test();
545 2970 : test();
546 2970 : test();
547 2970 : IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) || ( EQ_16( st->bfi, 1 ) && st->core == ACELP_CORE && EQ_16( st->con_tcx, 1 ) ) )
548 : {
549 1349 : test();
550 1349 : test();
551 1349 : test();
552 1349 : test();
553 1349 : test();
554 1349 : test();
555 1349 : test();
556 1349 : test();
557 1349 : IF( ( ( st->last_core != ACELP_CORE || ( EQ_16( st->prev_bfi, 1 ) && st->last_core == ACELP_CORE && EQ_16( st->last_con_tcx, 1 ) ) ) && NE_16( st->last_core, AMR_WB_CORE ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_16( st->cng_type, FD_CNG ) ) ) /* TCX / HQ-CORE -> TCX / HQ-CORE */
558 : {
559 1349 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
560 : }
561 0 : ELSE IF( EQ_16( st->core, TCX_20_CORE ) || EQ_16( st->core, TCX_10_CORE ) || EQ_16( st->core, HQ_CORE ) ) /* ACELP -> TCX/HQ */
562 : {
563 0 : IF( !st->tcxonly )
564 : {
565 0 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
566 : }
567 : }
568 : }
569 : ELSE /* ACELP core */
570 : {
571 1621 : test();
572 1621 : test();
573 1621 : IF( EQ_16( st->last_core, TCX_20_CORE ) || EQ_16( st->last_core, TCX_10_CORE ) || EQ_16( st->last_core, HQ_CORE ) ) /* TCX/HQ -> ACELP */
574 : {
575 0 : test();
576 0 : test();
577 0 : test();
578 0 : test();
579 0 : IF( ( LE_16( st->last_L_frame, L_FRAME16k ) && LE_16( st->L_frame, L_FRAME16k ) ) || ( st_ivas->sba_dirac_stereo_flag && EQ_32( st->core_brate, SID_2k40 ) && EQ_16( st->cng_type, FD_CNG ) ) )
580 : {
581 0 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( L_mult0( s_max( hCPE->hCoreCoder[0]->L_frame, hCPE->hCoreCoder[0]->last_L_frame ), FRAMES_PER_SEC ), STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
582 : }
583 : }
584 : }
585 : }
586 6610 : scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11
587 6610 : hCPE->hStereoDft->q_ap_fade_mem_fx = Q11;
588 6610 : test();
589 : }
590 :
591 6610 : st_ivas->hSpar->hMdDec->Q_mixer_mat = 30;
592 6610 : move16();
593 19830 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
594 : {
595 13220 : scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
596 13220 : hCPE->q_output_mem_fx[ii] = Q11;
597 13220 : move16();
598 : }
599 : }
600 : }
601 144622 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && st_ivas->nCPE > 0 && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) )
602 : {
603 7960 : nchan_remapped = 1; /* Only one channel transported */
604 7960 : move16();
605 : }
606 :
607 : /* HP filtering */
608 472685 : FOR( n = 0; n < nchan_remapped; n++ )
609 : {
610 321453 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
611 : }
612 :
613 151232 : IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) )
614 : {
615 119024 : nchan_remapped = ivas_sba_remapTCs_fx( p_output_fx, st_ivas, output_frame );
616 :
617 119024 : test();
618 119024 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
619 29841 : {
620 29841 : num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, ivas_total_brate, st_ivas->last_active_ivas_total_brate );
621 :
622 29841 : SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
623 29841 : Word16 Q_p_output = MAX_16, temp_min;
624 29841 : move16();
625 : Word16 nchan_transport;
626 :
627 29841 : nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
628 29841 : move16();
629 29841 : nchan_out = nchan_transport;
630 29841 : move16();
631 77252 : FOR( ch = 0; ch < nchan_transport; ch++ )
632 : {
633 47411 : temp_min = getScaleFactor32( p_output_fx[ch], output_frame );
634 47411 : Q_p_output = s_min( Q_p_output, temp_min );
635 : }
636 29841 : Q_p_output = sub( Q_p_output, 2 );
637 29841 : if ( GT_16( Q_p_output, 20 ) )
638 : {
639 0 : Q_p_output = 20;
640 0 : move16();
641 : }
642 77252 : FOR( ch = 0; ch < nchan_transport; ch++ )
643 : {
644 47411 : Scale_sig32( p_output_fx[ch], output_frame, Q_p_output ); // Q(11+Q_p_output)
645 : }
646 :
647 29841 : ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, p_output_fx, st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, Q_p_output );
648 77252 : FOR( Word16 c = 0; c < nchan_transport; c++ )
649 : {
650 47411 : Scale_sig32( p_output_fx[c], output_frame, 11 ); // Q11
651 : }
652 : }
653 89183 : ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) )
654 : {
655 80933 : Word16 size = st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport;
656 80933 : move16();
657 80933 : if ( EQ_16( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, 3 ) )
658 23069 : size = add( size, 1 );
659 :
660 315337 : FOR( i = 0; i < size; i++ )
661 : {
662 234404 : Scale_sig32( p_output_fx[i], output_frame, Q14 - Q11 ); // Q14
663 : }
664 :
665 80933 : ivas_spar_dec_agc_pca_fx( st_ivas, p_output_fx, output_frame );
666 : }
667 : }
668 :
669 151232 : test();
670 151232 : test();
671 151232 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
672 : {
673 32208 : Word16 q_shift = 0;
674 32208 : move16();
675 32208 : ivas_masa_prerender_fx( st_ivas, p_output_fx, &q_shift, output_frame, nchan_remapped );
676 96624 : FOR( i = 0; i < 2; i++ )
677 : {
678 64416 : Scale_sig32( p_output_fx[i], output_frame, negate( q_shift ) );
679 : }
680 : }
681 119024 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) )
682 : {
683 : /* loudness correction */
684 29841 : ivas_dirac_dec_binaural_sba_gain_fx( p_output_fx, nchan_remapped, output_frame );
685 :
686 77252 : FOR( i = 0; i < st_ivas->nchan_transport; i++ )
687 : {
688 47411 : Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q
689 : }
690 : }
691 : }
692 80378 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
693 : {
694 : Word16 nchan_ism, nchan_transport_ism;
695 : Word16 dirac_bs_md_write_idx;
696 :
697 6418 : set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 );
698 :
699 : /* Set the number of objects for the parametric rendering */
700 6418 : dirac_bs_md_write_idx = 0;
701 6418 : move16();
702 6418 : IF( st_ivas->hSpatParamRendCom != NULL )
703 : {
704 4840 : st_ivas->hSpatParamRendCom->numIsmDirections = 0;
705 4840 : move16();
706 4840 : test();
707 4840 : if ( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && NE_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
708 : {
709 1248 : st_ivas->hSpatParamRendCom->numIsmDirections = st_ivas->nchan_ism;
710 1248 : move16();
711 : }
712 :
713 4840 : dirac_bs_md_write_idx = st_ivas->hSpatParamRendCom->dirac_bs_md_write_idx; /* Store the write-index for this frame */
714 4840 : move16();
715 : }
716 :
717 :
718 : /* set ISM parameters and decode ISM metadata in OMASA format */
719 6418 : Word16 q_output = 11;
720 6418 : move16();
721 : // NOTE: the following is done to calculate the number of hIsmMetaData indices
722 : Word16 tmp_nchan_ism;
723 6418 : IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) )
724 : {
725 2029 : tmp_nchan_ism = 1;
726 2029 : move16();
727 : }
728 4389 : ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
729 : {
730 1623 : tmp_nchan_ism = 0;
731 1623 : move16();
732 : }
733 : ELSE
734 : {
735 2766 : tmp_nchan_ism = st_ivas->nchan_ism;
736 2766 : move16();
737 : }
738 :
739 15778 : FOR( n = 0; n < tmp_nchan_ism; n++ )
740 : {
741 9360 : set32_fx( p_output_fx[n], 0, L_FRAME48k );
742 : }
743 :
744 : /* MASA metadata decoding */
745 6418 : IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st_ivas->hCPE[0]->hCoreCoder[0], &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
746 : {
747 0 : return error;
748 : }
749 :
750 : /* Configuration of combined-format bit-budget distribution */
751 6418 : ivas_set_surplus_brate_dec( st_ivas, &ism_total_brate );
752 :
753 6418 : st_ivas->hCPE[0]->hCoreCoder[0]->bit_stream = &( st_ivas->bit_stream[( ism_total_brate / FRAMES_PER_SEC )] );
754 :
755 6418 : IF( NE_32( ( error = ivas_omasa_ism_metadata_dec_fx( st_ivas, ism_total_brate, &nchan_ism, &nchan_transport_ism, dirac_bs_md_write_idx, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
756 : {
757 0 : return error;
758 : }
759 :
760 17401 : FOR( n = 0; n < nchan_transport_ism; n++ )
761 : {
762 10983 : IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, n, &p_output_fx[st_ivas->nchan_transport + n], output_frame, nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
763 : {
764 0 : return error;
765 : }
766 : }
767 :
768 : /* decode MASA channels */
769 6418 : IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
770 : {
771 0 : return error;
772 : }
773 :
774 : /* shifting both the channels from variable q_output to constant Q-factor (Q11) */
775 5424338 : FOR( Word16 k = 0; k < output_frame; k++ )
776 : {
777 5417920 : p_output_fx[0][k] = L_shr( p_output_fx[0][k], sub( Q11, q_output ) );
778 5417920 : move32();
779 5417920 : p_output_fx[1][k] = L_shr( p_output_fx[1][k], sub( Q11, q_output ) );
780 5417920 : move32();
781 : }
782 :
783 6418 : IF( EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) )
784 : {
785 1314 : Copy32( p_output_fx[0], p_output_fx[1], output_frame ); /* Copy mono signal to stereo output channels */
786 : }
787 :
788 30237 : FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
789 : {
790 23819 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
791 : }
792 :
793 6418 : Word16 output_q = 11;
794 6418 : move16();
795 6418 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
796 : {
797 975 : ivas_mono_downmix_render_passive_fx( st_ivas, p_output_fx, output_frame );
798 :
799 975 : output_q = 8;
800 975 : move16();
801 : }
802 5443 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
803 : {
804 : /* sanity check in case of bitrate switching */
805 603 : IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
806 : {
807 0 : return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Incorrect output configuration specified for combined MASA and ISM format" );
808 : }
809 :
810 603 : ivas_omasa_rearrange_channels_fx( p_output_fx, nchan_transport_ism, output_frame );
811 :
812 603 : output_q = 11;
813 603 : move16();
814 :
815 603 : ivas_jbm_dec_copy_masa_meta_to_buffer( st_ivas );
816 : }
817 6418 : IF( NE_16( output_q, Q11 ) )
818 : {
819 4660 : FOR( n = 0; n < s_max( getNumChanSynthesis( st_ivas ), nchan_transport_ism + st_ivas->nchan_transport ); n++ )
820 : {
821 3685 : Scale_sig32( p_output_fx[n], output_frame, sub( Q11, output_q ) ); // Q11
822 : }
823 : }
824 : }
825 73960 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
826 : {
827 : Word16 nchan_ism, sba_ch_idx;
828 :
829 30003 : set16_fx( nb_bits_metadata, 0, MAX_SCE + 1 );
830 30003 : nchan_ism = st_ivas->nchan_ism;
831 30003 : move16();
832 30003 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
833 : {
834 : /* set ISM parameters and decode ISM metadata in OSBA format */
835 13100 : IF( NE_32( ( error = ivas_osba_ism_metadata_dec_fx( st_ivas, ivas_total_brate, &nchan_ism, &nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
836 : {
837 0 : return error;
838 : }
839 13100 : sba_ch_idx = st_ivas->nchan_ism;
840 13100 : move16();
841 : }
842 : ELSE
843 : {
844 16903 : nb_bits_metadata[1] = add( nb_bits_metadata[1], NO_BITS_MASA_ISM_NO_OBJ );
845 16903 : sba_ch_idx = 0;
846 16903 : move16();
847 16903 : move16();
848 : }
849 :
850 : /* SBA metadata decoding */
851 30003 : IF( NE_32( ( error = ivas_spar_dec_fx( st_ivas, nb_bits_metadata ) ), IVAS_ERR_OK ) )
852 : {
853 0 : return error;
854 : }
855 :
856 30003 : test();
857 30003 : IF( EQ_16( st_ivas->nchan_transport, CPE_CHANNELS ) && GE_16( st_ivas->nCPE, 1 ) )
858 : {
859 5017 : st_ivas->hCPE[0]->element_brate = ivas_total_brate;
860 5017 : move32();
861 : }
862 :
863 : /* core-decoding of transport channels */
864 30003 : Word16 q_output = 11;
865 30003 : move16();
866 :
867 30003 : IF( EQ_16( st_ivas->nSCE, 1 ) )
868 : {
869 6255 : set32_fx( p_output_fx[0], 0, L_FRAME48k );
870 :
871 6255 : IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
872 : {
873 0 : return error;
874 : }
875 : }
876 23748 : ELSE IF( EQ_16( st_ivas->nCPE, 1 ) )
877 : {
878 :
879 5017 : IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, add( nb_bits_metadata[0], nb_bits_metadata[1] ) ) ), IVAS_ERR_OK ) )
880 : {
881 0 : return error;
882 : }
883 :
884 5017 : IF( NE_16( q_output, Q11 ) )
885 : {
886 0 : Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
887 0 : Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
888 : }
889 : }
890 18731 : ELSE IF( GT_16( st_ivas->nCPE, 1 ) )
891 : {
892 18731 : IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] + nb_bits_metadata[1] ) ), IVAS_ERR_OK ) )
893 : {
894 0 : return error;
895 : }
896 : }
897 :
898 30003 : IF( st_ivas->sba_dirac_stereo_flag )
899 : {
900 12320 : FOR( i = 0; i < st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport; i++ )
901 : {
902 9320 : Scale_sig32( p_output_fx[i + sba_ch_idx], output_frame, Q14 - Q11 ); // Q14
903 : }
904 3000 : SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
905 : Word16 nchan_transport;
906 3000 : nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
907 3000 : move16();
908 3000 : nchan_out = nchan_transport;
909 3000 : move16();
910 3000 : ivas_agc_dec_process_fx( st_ivas->hSpar->hAgcDec, ( p_output_fx + sba_ch_idx ), ( p_output_fx + sba_ch_idx ), st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, output_frame );
911 :
912 3000 : IF( st_ivas->hSpar->hPCA != NULL )
913 : {
914 0 : ivas_pca_dec_fx( st_ivas->hSpar->hPCA, output_frame, st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate, st_ivas->bfi, &p_output_fx[sba_ch_idx] );
915 : }
916 3000 : ivas_spar_dec_gen_umx_mat_fx( st_ivas->hSpar->hMdDec, st_ivas->nchan_transport, IVAS_MAX_NUM_BANDS, st_ivas->bfi, ivas_get_spar_dec_md_num_subframes( st_ivas->sba_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate ) );
917 : {
918 : Word16 q;
919 3000 : hCPE = st_ivas->hCPE[0];
920 3000 : hSCE = st_ivas->hSCE[0];
921 3000 : s = 0;
922 3000 : move16();
923 9000 : FOR( i = 0; i < 2; i++ )
924 : {
925 6000 : s = s_min( s, L_norm_arr( p_output_fx[sba_ch_idx + i], L_FRAME48k ) - 11 /* Guard bits */ );
926 : }
927 9000 : FOR( i = 0; i < 2; i++ )
928 : {
929 6000 : Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, s ); // Q(11+s)
930 : }
931 3000 : hCPE->hStereoDft->q_dft = add( Q11, s );
932 3000 : move16();
933 3000 : IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
934 : {
935 30 : hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft;
936 30 : hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft;
937 30 : move16();
938 30 : move16();
939 : }
940 :
941 3000 : q = hCPE->hStereoDft->q_dft;
942 3000 : move16();
943 3000 : scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );
944 9000 : FOR( i = 0; i < CPE_CHANNELS; ++i )
945 : {
946 6000 : scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
947 6000 : scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
948 : }
949 3000 : IF( hCPE->hCoreCoder[0] != NULL )
950 : {
951 3000 : Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ) ); // q
952 3000 : Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, sub( q, hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ) ); // q
953 3000 : hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q;
954 3000 : move16();
955 : }
956 3000 : IF( hCPE->hStereoDft != NULL )
957 : {
958 3000 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
959 3000 : scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft
960 3000 : hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft;
961 3000 : move16();
962 : }
963 :
964 3000 : IF( hSCE != NULL )
965 : {
966 361 : Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft
967 361 : hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft;
968 361 : move16();
969 361 : Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft
970 361 : hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft;
971 361 : move16();
972 : }
973 9000 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
974 : {
975 6000 : scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
976 6000 : hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft;
977 6000 : move16();
978 : }
979 9000 : FOR( i = 0; i < CPE_CHANNELS; i++ )
980 6000 : Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx
981 3000 : ivas_sba_dirac_stereo_dec_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame, 0 );
982 9000 : FOR( i = 0; i < 2; i++ )
983 : {
984 6000 : Scale_sig32( p_output_fx[sba_ch_idx + i], L_FRAME48k, negate( s ) );
985 : }
986 :
987 9000 : FOR( i = 0; i < CPE_CHANNELS; i++ )
988 6000 : Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( 11, hCPE->q_prev_synth_fx ) ); // Q11
989 :
990 3000 : scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
991 9000 : FOR( i = 0; i < CPE_CHANNELS; ++i )
992 : {
993 6000 : scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
994 6000 : scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
995 : }
996 :
997 3000 : IF( hCPE->hCoreCoder[0] != NULL )
998 : {
999 :
1000 3000 : Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB
1001 3000 : Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda
1002 : }
1003 3000 : IF( hCPE->hStereoDft != NULL )
1004 : {
1005 3000 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
1006 3000 : scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11
1007 3000 : hCPE->hStereoDft->q_ap_fade_mem_fx = Q11;
1008 3000 : move16();
1009 : }
1010 :
1011 9000 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
1012 : {
1013 6000 : scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
1014 6000 : hCPE->q_output_mem_fx[ii] = Q11;
1015 6000 : move16();
1016 : }
1017 : }
1018 : }
1019 :
1020 : /* HP filtering */
1021 151395 : FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
1022 : {
1023 121392 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
1024 : }
1025 :
1026 30003 : nchan_remapped = ivas_sba_remapTCs_fx( &p_output_fx[sba_ch_idx], st_ivas, output_frame );
1027 :
1028 30003 : test();
1029 30003 : test();
1030 30003 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
1031 7213 : {
1032 7213 : num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate );
1033 7213 : SPAR_DEC_HANDLE hSpar = st_ivas->hSpar;
1034 : Word16 nchan_transport;
1035 : // num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands;
1036 7213 : nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
1037 7213 : move16();
1038 7213 : nchan_out = nchan_transport;
1039 7213 : move16();
1040 7213 : Word16 Q_p_output = s_max( 3, sub( L_norm_arr( p_output_fx[sba_ch_idx], imult1616( output_frame, nchan_transport ) ), 1 ) );
1041 7213 : Q_p_output = s_min( Q_p_output, 19 ); // to restrict Q-factor of p_ouptut to Q30
1042 18105 : FOR( ch = 0; ch < nchan_transport; ch++ )
1043 : {
1044 10892 : Scale_sig32( p_output_fx[sba_ch_idx + ch], output_frame, Q_p_output ); // Q_p_output + Q11
1045 : }
1046 7213 : Q_p_output = add( Q11, Q_p_output );
1047 7213 : hSpar->hMdDec->Q_mixer_mat = 31;
1048 7213 : move16();
1049 :
1050 7213 : ivas_sba_mix_matrix_determiner_fx( st_ivas->hSpar, &p_output_fx[sba_ch_idx], st_ivas->bfi, nchan_remapped, output_frame, num_md_sub_frames, sub( Q_p_output, Q11 ) );
1051 18105 : FOR( Word16 c = 0; c < nchan_transport; c++ )
1052 : {
1053 10892 : Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); // Q11
1054 : }
1055 : }
1056 22790 : ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->sba_dirac_stereo_flag == 0 )
1057 : {
1058 18790 : Word16 size = add( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, sba_ch_idx );
1059 18790 : if ( EQ_16( size, 3 ) )
1060 : {
1061 4370 : size = add( size, 1 );
1062 : }
1063 :
1064 86530 : FOR( i = sba_ch_idx; i < size; i++ )
1065 : {
1066 67740 : Scale_sig32( p_output_fx[i], output_frame, ( Q14 - Q11 ) ); // Q14
1067 : }
1068 :
1069 18790 : ivas_spar_dec_agc_pca_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame );
1070 : }
1071 :
1072 30003 : test();
1073 30003 : test();
1074 30003 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
1075 : {
1076 : /* loudness correction */
1077 7213 : ivas_dirac_dec_binaural_sba_gain_fx( &p_output_fx[sba_ch_idx], nchan_remapped, output_frame ); /*returns Q-1*/
1078 :
1079 18105 : FOR( i = 0; i < nchan_remapped; i++ )
1080 : {
1081 10892 : Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q
1082 : }
1083 : }
1084 22790 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
1085 : {
1086 1000 : ivas_mono_downmix_render_passive_fx( st_ivas, p_output_fx, output_frame );
1087 :
1088 1000 : Scale_sig32( p_output_fx[0], L_FRAME48k, Q11 - Q8 ); // Q11
1089 :
1090 : /* add W */
1091 2000 : FOR( n = 0; n < nchan_out; n++ )
1092 : {
1093 1000 : v_add_32( p_output_fx[n], p_output_fx[n + s_max( nchan_out, nchan_ism )], p_output_fx[n], output_frame );
1094 : }
1095 : }
1096 : }
1097 43957 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
1098 : {
1099 :
1100 : // st = (st_ivas->nSCE > 0) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
1101 43957 : IF( st_ivas->nSCE > 0 )
1102 : {
1103 9720 : st = st_ivas->hSCE[0]->hCoreCoder[0];
1104 : }
1105 : ELSE
1106 : {
1107 34237 : st = st_ivas->hCPE[0]->hCoreCoder[0];
1108 : }
1109 :
1110 43957 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
1111 : {
1112 : /* LFE channel decoder */
1113 24307 : ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] );
1114 :
1115 24307 : Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11
1116 24307 : IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ), IVAS_ERR_OK ) )
1117 : {
1118 0 : return error;
1119 : }
1120 : /* HP filtering */
1121 182047 : FOR( n = 0; n < st_ivas->nchan_transport; n++ )
1122 : {
1123 157740 : IF( NE_16( n, LFE_CHANNEL ) )
1124 : {
1125 133433 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
1126 : }
1127 : }
1128 :
1129 24307 : test();
1130 24307 : test();
1131 24307 : test();
1132 24307 : IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || NE_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) )
1133 : {
1134 150 : IF( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) )
1135 : {
1136 0 : ivas_mc2sba_fx( st_ivas->hTransSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX );
1137 : }
1138 : }
1139 :
1140 24307 : test();
1141 24307 : test();
1142 24307 : IF( ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) )
1143 : {
1144 3030 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
1145 : {
1146 3030 : s = Q16 - Q11;
1147 3030 : move16();
1148 3030 : s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) );
1149 21390 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i )
1150 : {
1151 18360 : Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s)
1152 : }
1153 3030 : ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx );
1154 21390 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i )
1155 : {
1156 18360 : Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11
1157 : }
1158 : }
1159 0 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
1160 : {
1161 0 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hOutSetup.ambisonics_order, 0 );
1162 : }
1163 : }
1164 : }
1165 19650 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
1166 : {
1167 : /* LFE channel decoder */
1168 780 : ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] );
1169 :
1170 780 : Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11
1171 :
1172 780 : ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] );
1173 :
1174 780 : IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1175 : {
1176 0 : return error;
1177 : }
1178 : /* HP filtering */
1179 7020 : FOR( n = 0; n < st_ivas->nchan_transport; n++ )
1180 : {
1181 6240 : IF( NE_16( n, LFE_CHANNEL ) )
1182 : {
1183 5460 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
1184 : }
1185 : }
1186 :
1187 : /* Rendering */
1188 780 : test();
1189 780 : test();
1190 780 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
1191 : {
1192 : /* Compensate loudness for not doing full upmix */
1193 50 : FOR( n = 4; n < 8; n++ )
1194 : {
1195 40 : Scale_sig32( p_output_fx[n], output_frame, 1 );
1196 : }
1197 :
1198 10 : test();
1199 10 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
1200 : {
1201 10 : s = Q16 - Q11;
1202 10 : move16();
1203 : Word16 nchan_transport;
1204 10 : nchan_transport = audioCfg2channels( IVAS_AUDIO_CONFIG_5_1_2 );
1205 10 : s = sub( s, find_guarded_bits_fx( nchan_transport ) );
1206 90 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i )
1207 : {
1208 80 : Scale_sig32( p_output_fx[i], output_frame, s );
1209 : }
1210 10 : ivas_ls_setup_conversion_fx( st_ivas, nchan_transport, output_frame, p_output_fx, p_output_fx );
1211 90 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i )
1212 : {
1213 80 : Scale_sig32( p_output_fx[i], output_frame, negate( s ) );
1214 : }
1215 : }
1216 : }
1217 : }
1218 18870 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
1219 : {
1220 : /* read Parametric MC parameters from the bitstream */
1221 8780 : ivas_param_mc_dec_read_BS_fx( ivas_total_brate, st, st_ivas->hParamMC, &nb_bits_metadata[0] );
1222 :
1223 8780 : IF( EQ_16( st_ivas->nCPE, 1 ) )
1224 : {
1225 8720 : Word16 q_output = 11;
1226 8720 : move16();
1227 :
1228 8720 : IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1229 : {
1230 0 : return error;
1231 : }
1232 8720 : IF( NE_16( q_output, Q11 ) )
1233 : {
1234 0 : Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
1235 0 : Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
1236 : }
1237 : }
1238 60 : ELSE IF( GT_16( st_ivas->nCPE, 1 ) )
1239 : {
1240 60 : IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1241 : {
1242 0 : return error;
1243 : }
1244 : }
1245 :
1246 : /* HP filtering */
1247 26400 : FOR( n = 0; n < st_ivas->nchan_transport; n++ )
1248 : {
1249 17620 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
1250 : }
1251 :
1252 : /* Rendering */
1253 8780 : test();
1254 8780 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
1255 : {
1256 20 : ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx );
1257 : }
1258 : }
1259 10090 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
1260 : {
1261 10090 : IF( st_ivas->hOutSetup.separateChannelEnabled )
1262 : {
1263 550 : st = st_ivas->hCPE[0]->hCoreCoder[0]; /* Metadata is always with CPE in the case of separated channel */
1264 : }
1265 :
1266 : /* read McMASA parameters from the bitstream */
1267 :
1268 10090 : IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1269 : {
1270 0 : return error;
1271 : }
1272 :
1273 10090 : IF( st_ivas->hOutSetup.separateChannelEnabled )
1274 : {
1275 : /* Decode the transport audio signals */
1276 550 : Word16 q_output = 11;
1277 550 : move16();
1278 :
1279 550 : IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1280 : {
1281 0 : return error;
1282 : }
1283 550 : IF( NE_16( q_output, Q11 ) )
1284 : {
1285 0 : Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
1286 0 : Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
1287 : }
1288 :
1289 : /* Identify the index of the separated channel, always LFE_CHANNEL-1 here */
1290 550 : n = LFE_CHANNEL - 1;
1291 550 : move16();
1292 :
1293 : /* Decode the separated channel to output[n] to be combined with the synthesized channels */
1294 :
1295 550 : set32_fx( p_output_fx[n], 0, L_FRAME48k );
1296 :
1297 550 : IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[n], output_frame, 0 ) ), IVAS_ERR_OK ) )
1298 : {
1299 0 : return error;
1300 : }
1301 550 : test();
1302 550 : test();
1303 550 : test();
1304 550 : test();
1305 550 : test();
1306 550 : test();
1307 550 : test();
1308 : /* Delay the separated channel to sync with CLDFB delay of the DirAC synthesis, and synthesize the LFE signal. */
1309 550 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
1310 : EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
1311 : EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) )
1312 : {
1313 150 : ivas_lfe_synth_with_filters_fx( st_ivas->hMasa->hMasaLfeSynth, p_output_fx, output_frame, n, LFE_CHANNEL );
1314 : }
1315 400 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 )
1316 : {
1317 : /* Delay the separated channel to sync with the DirAC rendering */
1318 0 : delay_signal32_fx( p_output_fx[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size );
1319 : }
1320 : }
1321 : ELSE
1322 : {
1323 9540 : Word16 q_output = 11;
1324 9540 : move16();
1325 9540 : IF( EQ_16( st_ivas->nSCE, 1 ) )
1326 : {
1327 9170 : set32_fx( p_output_fx[0], 0, L_FRAME48k );
1328 :
1329 9170 : IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1330 : {
1331 0 : return error;
1332 : }
1333 : }
1334 370 : ELSE IF( EQ_16( st_ivas->nCPE, 1 ) )
1335 : {
1336 :
1337 370 : IF( NE_32( ( error = ivas_cpe_dec_fx( st_ivas, 0, &p_output_fx[0], output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1338 : {
1339 0 : return error;
1340 : }
1341 370 : IF( NE_16( q_output, Q11 ) )
1342 : {
1343 0 : Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
1344 0 : Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
1345 : }
1346 : }
1347 : }
1348 :
1349 10090 : IF( st_ivas->sba_dirac_stereo_flag != 0 ) /* use the flag to trigger the DFT upmix */
1350 : {
1351 : Word16 q;
1352 1180 : hCPE = st_ivas->hCPE[0];
1353 1180 : hSCE = st_ivas->hSCE[0];
1354 1180 : s = 0;
1355 1180 : move16();
1356 3540 : FOR( i = 0; i < 2; i++ )
1357 : {
1358 2360 : s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 /* Guard bits */ );
1359 : }
1360 3540 : FOR( i = 0; i < 2; i++ )
1361 : {
1362 2360 : Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s)
1363 : }
1364 :
1365 1180 : hCPE->hStereoDft->q_dft = add( Q11, s );
1366 1180 : move16();
1367 1180 : IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
1368 : {
1369 1180 : hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft;
1370 1180 : hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft;
1371 :
1372 1180 : move16();
1373 1180 : move16();
1374 : }
1375 :
1376 1180 : q = hCPE->hStereoDft->q_dft;
1377 1180 : move16();
1378 :
1379 1180 : scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );
1380 3540 : FOR( i = 0; i < CPE_CHANNELS; ++i )
1381 : {
1382 2360 : scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
1383 2360 : scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
1384 : }
1385 :
1386 1180 : IF( hCPE->hCoreCoder[0] != NULL )
1387 : {
1388 1180 : Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, L_FRAME32k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB ); // q
1389 1180 : Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, L_FRAME48k, q - hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda ); // q
1390 1180 : hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q;
1391 1180 : move16();
1392 : }
1393 1180 : IF( hCPE->hStereoDft != NULL )
1394 : {
1395 1180 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
1396 1180 : scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA( 16000, DELAY_BWE_TOTAL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // q_dft
1397 1180 : hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft;
1398 1180 : move16();
1399 : }
1400 1180 : IF( st_ivas->hSpar != NULL )
1401 : {
1402 0 : st_ivas->hSpar->hMdDec->Q_mixer_mat = 30;
1403 0 : move16();
1404 : }
1405 :
1406 1180 : IF( hSCE != NULL )
1407 : {
1408 1180 : Scale_sig32( &hSCE->save_hb_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_hb_synth_fx ); // q_dft
1409 1180 : hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft;
1410 1180 : move16();
1411 1180 : Scale_sig32( &hSCE->save_synth_fx[0], extract_l( Mpy_32_32( hCPE->hCoreCoder[0]->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ), hCPE->hStereoDft->q_dft - hSCE->q_save_synth_fx ); // q_dft
1412 1180 : hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft;
1413 1180 : move16();
1414 : }
1415 3540 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
1416 : {
1417 2360 : scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, hCPE->q_output_mem_fx[ii] ) ); // q_dft
1418 2360 : hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft;
1419 2360 : move16();
1420 : }
1421 3540 : FOR( i = 0; i < CPE_CHANNELS; i++ )
1422 2360 : Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( hCPE->q_prev_synth_fx, Q11 ) ); // q_prev_synth_fx
1423 1180 : ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame, 1 );
1424 3540 : FOR( i = 0; i < 2; i++ )
1425 : {
1426 2360 : Scale_sig32( p_output_fx[i], L_FRAME48k, negate( s ) );
1427 : }
1428 3540 : FOR( i = 0; i < CPE_CHANNELS; i++ )
1429 2360 : Scale_sig32( hCPE->prev_synth_fx[i], NS2SA_FX2( output_Fs, IVAS_DEC_DELAY_NS - STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->q_prev_synth_fx ) ); // Q11
1430 :
1431 1180 : scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) );
1432 3540 : FOR( i = 0; i < CPE_CHANNELS; ++i )
1433 : {
1434 2360 : scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
1435 2360 : scale_sig32( hCPE->input_mem_fx[i], NS2SA_FX2( hCPE->hCoreCoder[0]->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
1436 : }
1437 :
1438 1180 : IF( hCPE->hCoreCoder[0] != NULL )
1439 : {
1440 1180 : Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda_LB, q ) ); // Q_old_wtda_LB
1441 1180 : Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[0]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[0]->hHQ_core->Q_old_wtda, q ) ); // Q_old_wtda
1442 : }
1443 1180 : IF( hCPE->hStereoDft != NULL )
1444 : {
1445 1180 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
1446 1180 : scale_sig32( hCPE->hStereoDft->ap_delay_mem_fx, NS2SA_FX2( 16000, DELAY_BWE_TOTAL_NS ), sub( Q11, hCPE->hStereoDft->q_ap_fade_mem_fx ) ); // Q11
1447 1180 : hCPE->hStereoDft->q_ap_fade_mem_fx = Q11;
1448 1180 : move16();
1449 : }
1450 1180 : IF( st_ivas->hSpar != NULL )
1451 : {
1452 0 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
1453 : {
1454 0 : scale_sig32( hCPE->output_mem_fx[ii], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
1455 0 : hCPE->q_output_mem_fx[ii] = Q11;
1456 0 : move16();
1457 : }
1458 : }
1459 : }
1460 :
1461 : /* HP filtering */
1462 22830 : FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
1463 : {
1464 12740 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
1465 : }
1466 :
1467 10090 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) )
1468 : {
1469 500 : ivas_mono_stereo_downmix_mcmasa_fx( st_ivas, p_output_fx, output_frame );
1470 : }
1471 : }
1472 : }
1473 :
1474 : /*----------------------------------------------------------------*
1475 : * Write IVAS transport channels
1476 : *----------------------------------------------------------------*/
1477 :
1478 396879 : IF( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) )
1479 : {
1480 19405 : ivas_syn_output_f_fx( p_output_fx, output_frame, st_ivas->hTcBuffer->nchan_transport_jbm, data_fx );
1481 : }
1482 : ELSE
1483 : {
1484 : /* directly copy to tc buffers */
1485 : /*note : the q of cldfb buffers (imag/real) are needed to be Q_p_output - 5 here 6 is taken for that*/
1486 377474 : ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, output_frame );
1487 : }
1488 :
1489 : /*----------------------------------------------------------------*
1490 : * Common updates
1491 : *----------------------------------------------------------------*/
1492 :
1493 396879 : IF( !st_ivas->bfi ) /* do not update if first frame(s) are lost or NO_DATA */
1494 : {
1495 388314 : st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate;
1496 388314 : move32();
1497 388314 : IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) )
1498 : {
1499 18751 : st_ivas->last_active_ivas_total_brate = st_ivas->last_active_ivas_total_brate;
1500 18751 : move32();
1501 : }
1502 : ELSE
1503 : {
1504 369563 : st_ivas->last_active_ivas_total_brate = ivas_total_brate;
1505 369563 : move32();
1506 : }
1507 : }
1508 :
1509 396879 : test();
1510 396879 : test();
1511 396879 : if ( LT_16( st_ivas->ini_frame, MAX_FRAME_COUNTER ) && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) ) /* keep "st_ivas->ini_frame = 0" until first good received frame */
1512 : {
1513 111784 : st_ivas->ini_frame = add( st_ivas->ini_frame, 1 );
1514 111784 : move16();
1515 : }
1516 :
1517 396879 : test();
1518 396879 : test();
1519 396879 : if ( LT_16( st_ivas->ini_active_frame, MAX_FRAME_COUNTER ) && !( st_ivas->bfi && st_ivas->ini_frame == 0 ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) ) /* needed in MASA decoder in case the first active frame is BFI, and there were SID-frames decoded before */
1520 : {
1521 110873 : st_ivas->ini_active_frame = add( st_ivas->ini_active_frame, 1 );
1522 110873 : move16();
1523 : }
1524 :
1525 396879 : st_ivas->last_ivas_format = st_ivas->ivas_format;
1526 396879 : move32();
1527 396879 : pop_wmops();
1528 :
1529 396879 : return IVAS_ERR_OK;
1530 : }
1531 :
1532 :
1533 : /*--------------------------------------------------------------------------*
1534 : * ivas_jbm_dec_feed_tc_to_renderer()
1535 : *
1536 : * Feed decoded transport channels and metadata to the IVAS JBM renderer routine
1537 : *--------------------------------------------------------------------------*/
1538 399979 : void ivas_jbm_dec_feed_tc_to_renderer_fx(
1539 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1540 : const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */
1541 : Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/
1542 : Word32 *data_fx /* i : transport channels Q11*/
1543 : )
1544 : {
1545 399979 : Word32 data_f_fx[MAX_CLDFB_DIGEST_CHANNELS][MAX_JBM_L_FRAME48k] = { 0 }; /* Word32 buffer for transport channels that will be directly converted with the CLDFB */
1546 : Word32 *p_data_f_fx[MAX_CLDFB_DIGEST_CHANNELS];
1547 : Word16 i;
1548 :
1549 3599811 : FOR( i = 0; i < MAX_CLDFB_DIGEST_CHANNELS; i++ )
1550 : {
1551 3199832 : set_zero_fx( data_f_fx[i], MAX_JBM_L_FRAME48k );
1552 : }
1553 399979 : if ( st_ivas->hTcBuffer )
1554 : {
1555 399979 : st_ivas->hTcBuffer->q_tc_fx = 11;
1556 399979 : move16();
1557 : }
1558 : Word16 n, n_render_timeslots;
1559 :
1560 399979 : push_wmops( "ivas_jbm_dec_feed_tc_to_rendererer" );
1561 3599811 : FOR( n = 0; n < MAX_CLDFB_DIGEST_CHANNELS; n++ )
1562 : {
1563 3199832 : p_data_f_fx[n] = &data_f_fx[n][0];
1564 : }
1565 :
1566 399979 : IF( st_ivas->hDecoderConfig->Opt_tsm )
1567 : {
1568 19405 : ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data_fx, p_data_f_fx, 11 );
1569 : }
1570 : ELSE
1571 : {
1572 380574 : *nSamplesResidual = 0;
1573 380574 : move16();
1574 : }
1575 399979 : n_render_timeslots = idiv1616( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity );
1576 :
1577 399979 : test();
1578 399979 : IF( EQ_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
1579 : {
1580 127492 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
1581 :
1582 127492 : test();
1583 127492 : test();
1584 127492 : IF( ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1585 : {
1586 5462 : ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
1587 : }
1588 : }
1589 272487 : ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) )
1590 : {
1591 0 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
1592 : }
1593 272487 : ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
1594 : {
1595 : /* Rendering */
1596 68224 : IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1597 : {
1598 13208 : test();
1599 13208 : test();
1600 13208 : test();
1601 13208 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
1602 : {
1603 7955 : ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots );
1604 :
1605 7955 : ivas_param_ism_params_to_masa_param_mapping_fx( st_ivas );
1606 : }
1607 5253 : ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
1608 : {
1609 :
1610 5253 : ivas_param_ism_dec_digest_tc_fx( st_ivas, n_render_timeslots, p_data_f_fx, Q11 );
1611 : }
1612 : }
1613 : ELSE /* ISM_MODE_DISC */
1614 : {
1615 55016 : ivas_ism_dec_digest_tc_fx( st_ivas );
1616 : }
1617 : }
1618 204263 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
1619 : {
1620 137306 : IF( st_ivas->hSCE[0] )
1621 : {
1622 44077 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1623 44077 : IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1624 : {
1625 4043 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1626 : }
1627 44077 : scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
1628 44077 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1629 : }
1630 137306 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1631 : }
1632 66957 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1633 : {
1634 :
1635 26213 : IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
1636 : {
1637 12100 : ivas_ism_dec_digest_tc_fx( st_ivas );
1638 :
1639 12100 : test();
1640 12100 : test();
1641 12100 : test();
1642 12100 : test();
1643 : /* delay the objects here for all renderers where it is needed */
1644 12100 : IF(
1645 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
1646 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
1647 : EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
1648 : EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
1649 : EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1650 : {
1651 47020 : FOR( n = 0; n < st_ivas->nchan_ism; n++ )
1652 : {
1653 36130 : delay_signal32_fx( st_ivas->hTcBuffer->tc_fx[n], st_ivas->hTcBuffer->n_samples_available, st_ivas->hSbaIsmData->delayBuffer_fx[n], st_ivas->hSbaIsmData->delayBuffer_size );
1654 : }
1655 : }
1656 :
1657 12100 : IF( !st_ivas->sba_dirac_stereo_flag )
1658 : {
1659 10890 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
1660 : {
1661 : Word16 temp, temp_e;
1662 4680 : temp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size, &temp_e );
1663 4680 : n_render_timeslots = extract_l( L_shr( L_mult0( n_render_timeslots, temp ), sub( 15, temp_e ) ) );
1664 : }
1665 :
1666 10890 : IF( st_ivas->hSCE[0] )
1667 : {
1668 0 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1669 0 : if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1670 : {
1671 0 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1672 : }
1673 0 : scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
1674 0 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1675 : }
1676 10890 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1677 : }
1678 : }
1679 : ELSE
1680 : {
1681 14113 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
1682 :
1683 14113 : IF( st_ivas->hSCE[0] )
1684 : {
1685 5894 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1686 5894 : if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1687 : {
1688 85 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1689 : }
1690 5894 : scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
1691 5894 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1692 : }
1693 14113 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1694 : }
1695 : }
1696 40744 : ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
1697 : {
1698 4840 : test();
1699 4840 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1700 : {
1701 108 : n_render_timeslots = i_mult( n_render_timeslots, idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ) );
1702 : }
1703 :
1704 4840 : IF( st_ivas->hSCE[0] )
1705 : {
1706 4840 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1707 4840 : if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1708 : {
1709 448 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1710 : }
1711 4840 : scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31- (st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp - shift)
1712 4840 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1713 4840 : move16();
1714 : }
1715 4840 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1716 :
1717 4840 : IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1718 : {
1719 1783 : ivas_ism_dec_digest_tc_fx( st_ivas );
1720 : }
1721 : }
1722 35904 : ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
1723 : {
1724 35904 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
1725 : {
1726 18974 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
1727 : }
1728 16930 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
1729 : {
1730 770 : ivas_mc_paramupmix_dec_digest_tc( st_ivas, (UWord8) n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1731 : }
1732 16160 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
1733 : {
1734 :
1735 8760 : Word16 nchan_transport = st_ivas->nchan_transport;
1736 8760 : move16();
1737 8760 : Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
1738 : Word16 nchan_out_cov;
1739 8760 : test();
1740 8760 : test();
1741 8760 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
1742 : {
1743 6910 : nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
1744 : }
1745 1850 : ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
1746 : {
1747 340 : nchan_out_cov = nchan_out_transport;
1748 340 : move16();
1749 : }
1750 1510 : ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
1751 : {
1752 150 : nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
1753 : }
1754 : ELSE
1755 : {
1756 1360 : nchan_out_cov = nchan_out_transport;
1757 1360 : move16();
1758 : }
1759 :
1760 8760 : scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); // Q(31-1)
1761 8760 : st_ivas->hParamMC->proto_matrix_int_e = 1;
1762 8760 : move16();
1763 :
1764 8760 : ivas_param_mc_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, (Word32 **) p_data_f_fx, Q11 );
1765 :
1766 8760 : scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); // Q(31-1+1)
1767 :
1768 : Word16 shift;
1769 121880 : FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ )
1770 : {
1771 113120 : shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, nchan_transport * nchan_transport ) );
1772 113120 : scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_fx[param_band_idx], s_min( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_len, i_mult( nchan_transport, nchan_transport ) ), shift ); // Q(31-cx_old_e+shift)
1773 113120 : st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cx_old_e[param_band_idx], shift );
1774 113120 : move16();
1775 :
1776 113120 : shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov );
1777 113120 : scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], i_mult( nchan_out_cov, nchan_out_cov ), shift ); // Q(31-cy_old_e+shift)
1778 113120 : st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_e[param_band_idx], shift );
1779 113120 : move16();
1780 : }
1781 : }
1782 7400 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
1783 : {
1784 7400 : IF( st_ivas->hSCE[0] )
1785 : {
1786 7190 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1787 7190 : if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1788 : {
1789 975 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1790 : }
1791 7190 : scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
1792 7190 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1793 7190 : move16();
1794 : }
1795 7400 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1796 : }
1797 : }
1798 :
1799 399979 : pop_wmops();
1800 399979 : return;
1801 : }
1802 :
1803 : /*--------------------------------------------------------------------------*
1804 : * ivas_dec_render()
1805 : *
1806 : * Principal IVAS JBM rendering routine
1807 : *--------------------------------------------------------------------------*/
1808 411989 : ivas_error ivas_jbm_dec_render_fx(
1809 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1810 : const UWord16 nSamplesAsked, /* i : number of samples wanted */
1811 : UWord16 *nSamplesRendered, /* o : number of samples rendered */
1812 : UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */
1813 : Word16 *data /* o : output synthesis signal Q0*/
1814 : )
1815 : {
1816 : Word16 n, nchan_out;
1817 : Word16 nchan_transport;
1818 : Word16 nchan_remapped;
1819 : Word32 output_Fs;
1820 : AUDIO_CONFIG output_config;
1821 : Word16 nSamplesAskedLocal;
1822 : ivas_error error;
1823 : Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS];
1824 : Word32 *p_tc_fx[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS];
1825 : Word16 subframe_len, gd_bits, exp, nchan_in, i, j, ch;
1826 411989 : const Word16 output_q_factor = Q11;
1827 411989 : move16();
1828 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1829 :
1830 411989 : push_wmops( "ivas_dec_render" );
1831 : /*----------------------------------------------------------------*
1832 : * Initialization of local vars after struct has been set
1833 : *----------------------------------------------------------------*/
1834 :
1835 411989 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1836 411989 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
1837 411989 : move32();
1838 411989 : nchan_out = st_ivas->hDecoderConfig->nchan_out;
1839 411989 : move16();
1840 411989 : nchan_transport = st_ivas->hTcBuffer->nchan_transport_jbm;
1841 411989 : move16();
1842 411989 : output_config = st_ivas->hDecoderConfig->output_config;
1843 411989 : move32();
1844 411989 : nSamplesAskedLocal = add( nSamplesAsked, st_ivas->hTcBuffer->n_samples_discard );
1845 411989 : move16();
1846 :
1847 8651769 : FOR( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
1848 : {
1849 8239780 : p_output_fx[n] = st_ivas->p_output_fx[n];
1850 : }
1851 411989 : IF( !st_ivas->hDecoderConfig->Opt_tsm )
1852 : {
1853 1666768 : FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ )
1854 : {
1855 1286194 : p_tc_fx[n] = p_output_fx[n];
1856 : }
1857 :
1858 6469758 : FOR( n = 0; n < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; n++ )
1859 : {
1860 6089184 : st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n];
1861 : }
1862 : }
1863 : ELSE
1864 : {
1865 127917 : FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ )
1866 : {
1867 96502 : p_tc_fx[n] = &st_ivas->hTcBuffer->tc_fx[n][st_ivas->hTcBuffer->n_samples_rendered];
1868 : }
1869 : }
1870 :
1871 411989 : st_ivas->hTcBuffer->no_channels = st_ivas->hTcBuffer->nchan_buffer_full;
1872 411989 : move16();
1873 : /*----------------------------------------------------------------*
1874 : * Update combined orientation access index
1875 : *----------------------------------------------------------------*/
1876 :
1877 411989 : IF( st_ivas->hCombinedOrientationData != NULL )
1878 : {
1879 : /* take the discard samples into account here to make sure head rotation stays on the correct 5ms grid */
1880 69350 : st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start = sub( st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start, st_ivas->hTcBuffer->n_samples_discard );
1881 69350 : move16();
1882 :
1883 69350 : ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
1884 : }
1885 :
1886 : /*----------------------------------------------------------------*
1887 : * Rendering
1888 : *----------------------------------------------------------------*/
1889 411989 : test();
1890 411989 : IF( EQ_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) )
1891 : {
1892 0 : assert( 0 );
1893 : }
1894 411989 : ELSE IF( EQ_32( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
1895 : {
1896 : Word16 slot_size, tmp, e;
1897 :
1898 128726 : slot_size = st_ivas->hTcBuffer->n_samples_granularity;
1899 128726 : move16();
1900 :
1901 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
1902 128726 : tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e );
1903 128726 : tmp = shr( tmp, sub( 15, e ) );
1904 :
1905 128726 : ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx );
1906 : }
1907 283263 : ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
1908 : {
1909 : /* Rendering */
1910 0 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
1911 : {
1912 0 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
1913 0 : move16();
1914 :
1915 0 : ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx );
1916 : }
1917 : }
1918 283263 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
1919 : {
1920 : /* Rendering */
1921 70910 : IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1922 : {
1923 15233 : test();
1924 15233 : test();
1925 15233 : test();
1926 15233 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
1927 : {
1928 8674 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output_fx );
1929 : }
1930 6559 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
1931 : {
1932 0 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
1933 0 : move16();
1934 0 : ivas_apply_non_diegetic_panning_fx( p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered );
1935 : }
1936 6559 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
1937 : {
1938 6559 : ivas_param_ism_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx );
1939 :
1940 6559 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
1941 : {
1942 : /* Convert CICP19 -> Ambisonics */
1943 4516 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
1944 : }
1945 : }
1946 : }
1947 : ELSE /* ISM_MODE_DISC */
1948 : {
1949 55677 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
1950 55677 : move16();
1951 :
1952 55677 : test();
1953 55677 : test();
1954 : /* Loudspeaker or Ambisonics rendering */
1955 55677 : IF( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
1956 : {
1957 : /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */
1958 20811 : ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered );
1959 : }
1960 34866 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
1961 : {
1962 1500 : ivas_apply_non_diegetic_panning_fx( p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered );
1963 : }
1964 33366 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
1965 : {
1966 : /* Convert to Ambisonics; used also for ISM->HOA3->binaural rendering */
1967 20780 : FOR( i = 0; i < st_ivas->nchan_transport; i++ )
1968 : {
1969 270028 : FOR( j = 0; j < 16; j++ )
1970 : {
1971 254144 : st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29
1972 254144 : move32();
1973 254144 : st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29
1974 254144 : move32();
1975 : }
1976 : }
1977 4896 : ivas_ism2sba_sf_fx( st_ivas->hTcBuffer->tc_fx, p_output_fx, st_ivas->hIsmRendererData, st_ivas->nchan_transport, *nSamplesRendered, st_ivas->hTcBuffer->n_samples_rendered, st_ivas->hIntSetup.ambisonics_order );
1978 4896 : Word16 sba_num_chans = imult1616( add( st_ivas->hIntSetup.ambisonics_order, 1 ), add( st_ivas->hIntSetup.ambisonics_order, 1 ) );
1979 65032 : FOR( j = 0; j < sba_num_chans; j++ )
1980 : {
1981 60136 : scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); // Q11
1982 : }
1983 :
1984 :
1985 20780 : FOR( i = 0; i < st_ivas->nchan_transport; i++ )
1986 : {
1987 270028 : FOR( j = 0; j < 16; j++ )
1988 : {
1989 254144 : st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30
1990 254144 : move32();
1991 254144 : st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q29 -> Q30
1992 254144 : move32();
1993 : }
1994 : }
1995 : }
1996 :
1997 : /* Binaural rendering */
1998 55677 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
1999 : {
2000 28470 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
2001 : {
2002 0 : return error;
2003 : }
2004 : }
2005 27207 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2006 : {
2007 10711 : st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
2008 10711 : subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity );
2009 10711 : gd_bits = find_guarded_bits_fx( subframe_len );
2010 10711 : exp = 13;
2011 10711 : move16();
2012 10711 : nchan_in = 12;
2013 10711 : move16();
2014 10711 : nchan_out = 2;
2015 10711 : move16();
2016 10711 : exp = sub( exp, gd_bits );
2017 10711 : *st_ivas->hCrendWrapper->p_io_qfactor = exp;
2018 10711 : move16();
2019 139243 : FOR( i = 0; i < nchan_in; i++ )
2020 : {
2021 128532 : scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11
2022 : }
2023 10711 : IF( NE_32( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL, NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, *nSamplesRendered, output_Fs ) ), IVAS_ERR_OK ) )
2024 : {
2025 0 : return error;
2026 : }
2027 32133 : FOR( i = 0; i < nchan_out; i++ )
2028 : {
2029 21422 : scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11
2030 : }
2031 : }
2032 : }
2033 : }
2034 212353 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
2035 : {
2036 143066 : nchan_remapped = nchan_transport;
2037 143066 : move16();
2038 143066 : test();
2039 143066 : test();
2040 : /* Loudspeakers, Ambisonics or Binaural rendering */
2041 143066 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
2042 : {
2043 45229 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2044 : }
2045 97837 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
2046 : {
2047 15964 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) )
2048 : {
2049 0 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
2050 0 : move16();
2051 0 : FOR( n = 0; n < nchan_remapped; n++ )
2052 : {
2053 0 : Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered );
2054 : }
2055 0 : IF( NE_32( ( error = ivas_sba_linear_renderer_fx( p_output_fx, *nSamplesRendered, nchan_remapped, 0, output_config, st_ivas->hOutSetup ) ), IVAS_ERR_OK ) )
2056 : {
2057 0 : return error;
2058 : }
2059 : }
2060 15964 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
2061 : {
2062 15964 : ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx );
2063 : }
2064 : }
2065 : ELSE
2066 : {
2067 81873 : IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2068 : {
2069 0 : return error;
2070 : }
2071 : }
2072 : }
2073 69287 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
2074 : {
2075 5407 : nchan_remapped = st_ivas->nchan_transport;
2076 5407 : move16();
2077 5407 : test();
2078 5407 : test();
2079 5407 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
2080 : {
2081 2699 : test();
2082 2699 : IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) )
2083 : {
2084 122 : IF( NE_32( ( error = ivas_omasa_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx ) ), IVAS_ERR_OK ) )
2085 : {
2086 0 : return error;
2087 : }
2088 : }
2089 : ELSE
2090 : {
2091 2577 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2092 : }
2093 : }
2094 2708 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
2095 : {
2096 2708 : ivas_omasa_dirac_rend_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2097 : }
2098 : }
2099 63880 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2100 : {
2101 27036 : nchan_remapped = nchan_transport;
2102 27036 : move16();
2103 : /* Loudspeakers, Ambisonics or Binaural rendering */
2104 27036 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
2105 : {
2106 12100 : test();
2107 12100 : test();
2108 12100 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
2109 : {
2110 : SPAR_DEC_HANDLE hSpar;
2111 4680 : hSpar = st_ivas->hSpar;
2112 4680 : hSpar->hMdDec->Q_mixer_mat = 30;
2113 4680 : move16();
2114 :
2115 4680 : IF( NE_32( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2116 : {
2117 0 : return error;
2118 : }
2119 : }
2120 7420 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) )
2121 : {
2122 1210 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
2123 1210 : move16();
2124 :
2125 1210 : test();
2126 : /* shift SBA channels to avoid overwrite by ISM upmix in 1 object case and non-TSM unified channel memory*/
2127 1210 : IF( EQ_16( st_ivas->nchan_ism, 1 ) && EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 0 ) )
2128 : {
2129 0 : Copy32( p_tc_fx[2], p_output_fx[3], *nSamplesRendered );
2130 0 : Copy32( p_tc_fx[1], p_output_fx[2], *nSamplesRendered );
2131 0 : p_tc_fx[1] = p_output_fx[2];
2132 0 : p_tc_fx[2] = p_output_fx[3];
2133 : }
2134 :
2135 : /* render objects */
2136 1210 : ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered );
2137 :
2138 : /* add already rendered SBA part */
2139 3630 : FOR( n = 0; n < nchan_out; n++ )
2140 : {
2141 2420 : v_add_fixed_no_hdrm( p_output_fx[n], p_tc_fx[n + st_ivas->nchan_ism], p_output_fx[n], *nSamplesRendered );
2142 : }
2143 : }
2144 6210 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) || EQ_32( st_ivas->renderer_type, RENDERER_OSBA_LS ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2145 : {
2146 4000 : IF( NE_32( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2147 : {
2148 0 : return error;
2149 : }
2150 : }
2151 2210 : ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/
2152 : {
2153 2210 : IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, &p_output_fx[st_ivas->nchan_ism] ) ), IVAS_ERR_OK ) )
2154 : {
2155 0 : return error;
2156 : }
2157 :
2158 8050 : FOR( n = 0; n < st_ivas->nchan_ism; n++ )
2159 : {
2160 5840 : Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered );
2161 : }
2162 : }
2163 : ELSE
2164 : {
2165 0 : IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2166 : {
2167 0 : return error;
2168 : }
2169 : }
2170 : }
2171 14936 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
2172 : {
2173 7656 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2174 : }
2175 : ELSE
2176 : {
2177 7280 : IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2178 : {
2179 0 : return error;
2180 : }
2181 :
2182 7280 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
2183 : {
2184 13430 : FOR( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- )
2185 : {
2186 12640 : Copy32( p_output_fx[n], p_output_fx[n + st_ivas->nchan_ism], *nSamplesRendered );
2187 : }
2188 3950 : FOR( n = 0; n < st_ivas->nchan_ism; n++ )
2189 : {
2190 3160 : set32_fx( p_output_fx[n], 0, *nSamplesRendered );
2191 : }
2192 : }
2193 : }
2194 : }
2195 36844 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
2196 : {
2197 36844 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
2198 : {
2199 19914 : Word16 crendInPlaceRotation = FALSE;
2200 19914 : move16();
2201 19914 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
2202 19914 : move16();
2203 :
2204 19914 : test();
2205 19914 : test();
2206 19914 : test();
2207 19914 : IF( NE_32( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) )
2208 : {
2209 150 : IF( LT_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) )
2210 : {
2211 150 : crendInPlaceRotation = TRUE;
2212 150 : move16();
2213 :
2214 150 : ivas_mc2sba_fx( st_ivas->hTransSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX );
2215 : }
2216 : }
2217 :
2218 19914 : test();
2219 : /* Rendering */
2220 19914 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2221 : {
2222 11960 : st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
2223 11960 : subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity );
2224 11960 : gd_bits = find_guarded_bits_fx( subframe_len );
2225 11960 : exp = 13;
2226 11960 : move16();
2227 11960 : IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ), IVAS_ERR_OK ) )
2228 : {
2229 0 : return error;
2230 : }
2231 11960 : IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) )
2232 : {
2233 0 : return error;
2234 : }
2235 11960 : exp = sub( exp, gd_bits );
2236 11960 : *st_ivas->hCrendWrapper->p_io_qfactor = exp;
2237 11960 : move16();
2238 :
2239 94520 : FOR( i = 0; i < nchan_in; i++ )
2240 : {
2241 82560 : scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11
2242 82560 : IF( st_ivas->hDecoderConfig->Opt_tsm )
2243 : {
2244 0 : scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11
2245 : }
2246 : }
2247 11960 : IF( NE_32( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, st_ivas->intern_config, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
2248 : &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs ) ),
2249 : IVAS_ERR_OK ) )
2250 : {
2251 0 : return error;
2252 : }
2253 :
2254 11960 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx );
2255 :
2256 94520 : FOR( i = 0; i < nchan_in; i++ )
2257 : {
2258 82560 : scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11
2259 82560 : IF( st_ivas->hDecoderConfig->Opt_tsm )
2260 : {
2261 0 : scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11
2262 : }
2263 : }
2264 : }
2265 7954 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
2266 : {
2267 4404 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
2268 4404 : move16();
2269 :
2270 4404 : ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx );
2271 : }
2272 3550 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
2273 : {
2274 490 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
2275 : }
2276 3060 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
2277 : {
2278 3060 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
2279 : {
2280 0 : return error;
2281 : }
2282 :
2283 3060 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx );
2284 : }
2285 : }
2286 16930 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
2287 : {
2288 770 : ivas_mc_paramupmix_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc_fx, p_output_fx );
2289 :
2290 770 : test();
2291 770 : test();
2292 : /* Rendering */
2293 770 : 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 )
2294 : {
2295 160 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx );
2296 : }
2297 610 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
2298 : {
2299 0 : ivas_ls_setup_conversion_fx( st_ivas, MC_PARAMUPMIX_MAX_INPUT_CHANS, *nSamplesRendered, p_output_fx, p_output_fx );
2300 : }
2301 610 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
2302 : {
2303 10 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
2304 : }
2305 600 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
2306 : {
2307 0 : IF( NE_32( ( error = ivas_td_binaural_renderer_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
2308 : {
2309 0 : return error;
2310 : }
2311 :
2312 0 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx );
2313 : }
2314 : }
2315 16160 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
2316 : {
2317 : Word16 channel_active_fx[MAX_OUTPUT_CHANNELS];
2318 : Word16 nchan_out_cov;
2319 8760 : Word16 nchan_out_cldfb = 0;
2320 8760 : move16();
2321 :
2322 8760 : set16_fx( channel_active_fx, 0, MAX_CICP_CHANNELS );
2323 8760 : Word16 nchan_transport_tmp = st_ivas->nchan_transport;
2324 8760 : move16();
2325 8760 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
2326 8760 : move32();
2327 8760 : Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
2328 8760 : test();
2329 8760 : test();
2330 8760 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2331 : {
2332 6910 : nchan_out_cldfb = BINAURAL_CHANNELS;
2333 6910 : move16();
2334 6910 : set16_fx( channel_active_fx, 1, BINAURAL_CHANNELS );
2335 6910 : nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
2336 : }
2337 1850 : ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
2338 : {
2339 340 : nchan_out_cov = nchan_out_transport;
2340 340 : move16();
2341 340 : nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
2342 : }
2343 1510 : ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_COV ) || EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
2344 : {
2345 150 : nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
2346 150 : nchan_out_cldfb = nchan_out_cov;
2347 150 : move16();
2348 150 : set16_fx( channel_active_fx, 1, nchan_out_cov );
2349 : }
2350 : ELSE
2351 : {
2352 1360 : nchan_out_cov = nchan_out_transport;
2353 1360 : move16();
2354 1360 : nchan_out_cldfb = nchan_out_transport;
2355 1360 : move16();
2356 1360 : set16_fx( channel_active_fx, 1, nchan_out_cov );
2357 : }
2358 8760 : IF( st_ivas->hParamMC->max_band_decorr > 0 )
2359 : {
2360 : Word16 tmp;
2361 8760 : tmp = L_norm_arr( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len );
2362 8760 : scale_sig32( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_fx, st_ivas->hParamMC->h_freq_domain_decorr_ap_state->decorr_buffer_len, tmp ); // Q(st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer+ tmp)
2363 8760 : st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer = add( st_ivas->hParamMC->h_freq_domain_decorr_ap_state->q_decorr_buffer, tmp );
2364 8760 : move16();
2365 : }
2366 : /* CLDFB synthesis */
2367 35840 : FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
2368 : {
2369 27080 : IF( st_ivas->cldfbSynDec[ch] )
2370 : {
2371 27080 : scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, ( Q5 - Q11 ) ); // Q5
2372 27080 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5;
2373 27080 : move16();
2374 : }
2375 : }
2376 : Word16 tempp;
2377 121880 : FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ )
2378 : {
2379 113120 : tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len );
2380 113120 : scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_len, tempp ); // Q(31-(st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx]- tempp))
2381 113120 : st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx], tempp );
2382 113120 : move16();
2383 :
2384 113120 : IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
2385 : {
2386 90900 : tempp = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len );
2387 90900 : scale_sig32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_len, tempp ); // Q(31- (st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] - tempp))
2388 90900 : st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx] = sub( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx], tempp );
2389 90900 : move16();
2390 : }
2391 : }
2392 :
2393 8760 : ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx );
2394 :
2395 35840 : FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
2396 : {
2397 27080 : IF( st_ivas->cldfbSynDec[ch] )
2398 : {
2399 27080 : scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q11
2400 27080 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
2401 27080 : move16();
2402 : }
2403 : }
2404 8760 : IF( EQ_16( st_ivas->hParamMC->slots_rendered, st_ivas->hParamMC->num_slots ) )
2405 : {
2406 123780 : FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ )
2407 : {
2408 115020 : IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
2409 : {
2410 90900 : Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_fx[param_band_idx], imult1616( nchan_transport_tmp, nchan_out_cov ) );
2411 90900 : st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_res_exp[param_band_idx];
2412 90900 : move16();
2413 : }
2414 115020 : Copy32( st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_fx[param_band_idx], st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_fx[param_band_idx], imult1616( nchan_transport_tmp, nchan_out_cov ) );
2415 115020 : st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_old_exp[param_band_idx] = st_ivas->hParamMC->h_output_synthesis_cov_state.mixing_matrix_exp[param_band_idx];
2416 115020 : move16();
2417 : }
2418 : }
2419 : }
2420 7400 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
2421 : {
2422 7400 : Word16 offset = imult1616( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->slot_size );
2423 7400 : nchan_remapped = st_ivas->nchan_transport;
2424 7400 : move16();
2425 :
2426 7400 : test();
2427 7400 : test();
2428 7400 : test();
2429 7400 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_32( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) )
2430 : {
2431 5760 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2432 : }
2433 1640 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) /* rendering to CICPxx and Ambisonics */
2434 : {
2435 1640 : ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx );
2436 :
2437 1640 : test();
2438 1640 : test();
2439 1640 : test();
2440 1640 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
2441 : {
2442 : /* we still need to copy the separate channel if available */
2443 290 : IF( st_ivas->hOutSetup.separateChannelEnabled )
2444 : {
2445 25 : Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
2446 : }
2447 :
2448 290 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
2449 : }
2450 1350 : ELSE IF( EQ_32( st_ivas->intern_config, IVAS_AUDIO_CONFIG_5_1 ) && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ) )
2451 : {
2452 0 : FOR( n = st_ivas->hIntSetup.nchan_out_woLFE + st_ivas->hIntSetup.num_lfe; n < ( st_ivas->hOutSetup.nchan_out_woLFE + st_ivas->hOutSetup.num_lfe ); n++ )
2453 : {
2454 0 : set32_fx( p_output_fx[n], 0, *nSamplesRendered );
2455 : }
2456 : }
2457 : }
2458 :
2459 : /* copy discrete C and TD LFE from internal TC to output */
2460 7400 : IF( st_ivas->hOutSetup.separateChannelEnabled )
2461 : {
2462 200 : test();
2463 200 : test();
2464 200 : test();
2465 200 : test();
2466 200 : test();
2467 200 : test();
2468 200 : test();
2469 200 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
2470 : EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
2471 : EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && GT_16( st_ivas->hOutSetup.num_lfe, 0 ) ) )
2472 : {
2473 150 : Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL] + offset, p_output_fx[LFE_CHANNEL], *nSamplesRendered );
2474 150 : Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
2475 : }
2476 50 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 )
2477 : {
2478 : /* Delay the separated channel to sync with the DirAC rendering */
2479 0 : Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
2480 : }
2481 : }
2482 : }
2483 : }
2484 :
2485 : /*----------------------------------------------------------------*
2486 : * Write IVAS output channels
2487 : * - compensation for saturation
2488 : * - float to integer conversion
2489 : *----------------------------------------------------------------*/
2490 :
2491 411989 : st_ivas->hTcBuffer->n_samples_available = sub( st_ivas->hTcBuffer->n_samples_available, *nSamplesRendered );
2492 411989 : st_ivas->hTcBuffer->n_samples_rendered = add( st_ivas->hTcBuffer->n_samples_rendered, *nSamplesRendered );
2493 411989 : move16();
2494 411989 : move16();
2495 :
2496 : /* update global combined orientation start index */
2497 411989 : ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
2498 :
2499 411989 : IF( st_ivas->hTcBuffer->n_samples_discard > 0 )
2500 : {
2501 286 : FOR( n = 0; n < s_min( MAX_OUTPUT_CHANNELS, ivas_get_nchan_buffers_dec( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) ); n++ )
2502 : {
2503 264 : p_output_fx[n] += st_ivas->hTcBuffer->n_samples_discard;
2504 : }
2505 22 : *nSamplesRendered = sub( (Word16) *nSamplesRendered, st_ivas->hTcBuffer->n_samples_discard );
2506 22 : move16();
2507 22 : st_ivas->hTcBuffer->n_samples_discard = 0;
2508 22 : move16();
2509 : }
2510 :
2511 : {
2512 411989 : IF( NE_32( st_ivas->ivas_format, MONO_FORMAT ) )
2513 : {
2514 : #ifndef DISABLE_LIMITER
2515 408889 : ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, nchan_out, *nSamplesRendered, st_ivas->BER_detect, output_q_factor );
2516 : #endif
2517 : }
2518 : }
2519 :
2520 411989 : ivas_syn_output_fx( p_output_fx, output_q_factor, *nSamplesRendered, nchan_out, data );
2521 :
2522 411989 : *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available;
2523 411989 : move16();
2524 :
2525 411989 : pop_wmops();
2526 411989 : return IVAS_ERR_OK;
2527 : }
2528 :
2529 : /*--------------------------------------------------------------------------*
2530 : * ivas_jbm_dec_dec_flush_renderer()
2531 : *
2532 : * Flush samples if renderer granularity changes on a bitrate change
2533 : *--------------------------------------------------------------------------*/
2534 :
2535 318 : ivas_error ivas_jbm_dec_flush_renderer_fx(
2536 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
2537 : const Word16 tc_granularity_new, /* i : new renderer granularity */
2538 : const RENDERER_TYPE renderer_type_old, /* i : old renderer type */
2539 : const AUDIO_CONFIG intern_config_old, /* i : old internal config */
2540 : const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */
2541 : const MC_MODE mc_mode_old, /* i : old MC mode */
2542 : const ISM_MODE ism_mode_old, /* i : old ISM mode */
2543 : UWord16 *nSamplesRendered, /* o : number of samples flushed */
2544 : Word16 *data /* o : output synthesis signal Q0*/
2545 : )
2546 : {
2547 : ivas_error error;
2548 : Word16 n_samples_still_available;
2549 : Word16 n_slots_still_available;
2550 : Word16 n_samples_to_render;
2551 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
2552 : Word32 output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
2553 : Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS];
2554 : Word16 nchan_in, nchan_out, gd_bits, n_chan_inp, i, shift;
2555 318 : IF( !st_ivas->hDecoderConfig->Opt_tsm )
2556 : {
2557 217 : return IVAS_ERR_OK;
2558 : }
2559 :
2560 101 : *nSamplesRendered = 0;
2561 101 : move16();
2562 101 : hTcBuffer = st_ivas->hTcBuffer;
2563 :
2564 : /* get number of possible slots in new granularity */
2565 101 : n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered );
2566 :
2567 : // n_slots_still_available = n_samples_still_available / tc_granularity_new;
2568 : Word16 tmp, tmp_e;
2569 101 : tmp = BASOP_Util_Divide1616_Scale( n_samples_still_available, tc_granularity_new, &tmp_e );
2570 101 : n_slots_still_available = shr( tmp, sub( 15, tmp_e ) );
2571 101 : *nSamplesRendered = imult1616( n_slots_still_available, tc_granularity_new );
2572 101 : n_samples_to_render = *nSamplesRendered;
2573 101 : move16();
2574 101 : move16();
2575 101 : n_samples_still_available = sub( n_samples_still_available, n_samples_to_render );
2576 101 : assert( n_samples_still_available < tc_granularity_new );
2577 :
2578 : /* update combined orientation access index */
2579 101 : ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
2580 :
2581 101 : IF( n_slots_still_available )
2582 : {
2583 : Word16 ch_idx;
2584 :
2585 : /* render what is still there with zero padding */
2586 151 : FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
2587 : {
2588 : /* move it at the beginning of the TC buffer with zero padding */
2589 129 : Copy32( hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch_idx], n_samples_to_render );
2590 129 : set_zero_fx( hTcBuffer->tc_fx[ch_idx] + n_samples_to_render, hTcBuffer->n_samples_granularity - n_samples_to_render );
2591 129 : Copy32( hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered + n_samples_to_render, hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_granularity, n_samples_still_available );
2592 : }
2593 : /* simple change of the slot info */
2594 22 : hTcBuffer->num_slots = 1;
2595 22 : hTcBuffer->nb_subframes = 1;
2596 22 : hTcBuffer->subframes_rendered = 0;
2597 22 : hTcBuffer->slots_rendered = 0;
2598 22 : hTcBuffer->subframe_nbslots[0] = 1;
2599 22 : hTcBuffer->n_samples_buffered = add( hTcBuffer->n_samples_granularity, n_samples_still_available );
2600 22 : hTcBuffer->n_samples_available = 0;
2601 22 : hTcBuffer->n_samples_flushed = n_samples_to_render;
2602 : #ifdef CR_FIX_JBM_FLUSH_OFFSET
2603 : hTcBuffer->n_samples_rendered = 0;
2604 : #else
2605 22 : hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity;
2606 : #endif
2607 22 : move16();
2608 22 : move16();
2609 22 : move16();
2610 22 : move16();
2611 22 : move16();
2612 22 : move16();
2613 22 : move16();
2614 22 : move16();
2615 22 : move16();
2616 :
2617 462 : FOR( ch_idx = 0; ch_idx < ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ); ch_idx++ )
2618 : {
2619 440 : p_output_fx[ch_idx] = output_fx[ch_idx];
2620 : }
2621 :
2622 22 : test();
2623 22 : IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
2624 : {
2625 7 : IF( EQ_16( ism_mode_old, ISM_MODE_DISC ) )
2626 : {
2627 : /* Binaural rendering */
2628 7 : IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_OBJECTS_TD ) )
2629 : {
2630 0 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) )
2631 : {
2632 0 : return error;
2633 : }
2634 : }
2635 7 : ELSE IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2636 : {
2637 : /*TODO :To be tested : no stream entering---------------------------------------*/
2638 : /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */
2639 7 : set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); // 32767=1.0f in Q15
2640 :
2641 7 : ivas_ism_render_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity );
2642 :
2643 7 : st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
2644 7 : *st_ivas->hCrendWrapper->p_io_qfactor = 11;
2645 7 : move16();
2646 :
2647 7 : shift = MAX_16;
2648 7 : move16();
2649 7 : n_chan_inp = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
2650 :
2651 91 : FOR( i = 0; i < n_chan_inp; i++ )
2652 : {
2653 84 : shift = s_min( shift, L_norm_arr( p_output_fx[i], hTcBuffer->n_samples_granularity ) );
2654 : }
2655 :
2656 7 : gd_bits = sub( find_guarded_bits_fx( imult1616( hTcBuffer->subframe_nbslots[0], hTcBuffer->n_samples_granularity ) ), shift );
2657 :
2658 7 : *st_ivas->hCrendWrapper->p_io_qfactor = sub( *st_ivas->hCrendWrapper->p_io_qfactor, gd_bits );
2659 7 : move16();
2660 :
2661 91 : FOR( i = 0; i < n_chan_inp; i++ )
2662 : {
2663 84 : scale_sig32( p_output_fx[i], hTcBuffer->n_samples_granularity, sub( *st_ivas->hCrendWrapper->p_io_qfactor, Q11 ) ); // Q(*st_ivas->hCrendWrapper->p_io_qfactor)
2664 : }
2665 :
2666 7 : IF( NE_32( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, IVAS_AUDIO_CONFIG_7_1_4, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR, st_ivas->hDecoderConfig, NULL,
2667 : NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ),
2668 : IVAS_ERR_OK ) )
2669 : {
2670 0 : return error;
2671 : }
2672 :
2673 91 : FOR( i = 0; i < n_chan_inp; i++ )
2674 : {
2675 84 : scale_sig32( p_output_fx[i], hTcBuffer->n_samples_granularity, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q(11)
2676 : }
2677 7 : *st_ivas->hCrendWrapper->p_io_qfactor = Q11;
2678 7 : move16();
2679 : }
2680 : }
2681 : ELSE
2682 : {
2683 0 : return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong ISM_MODE in VoIP renderer flushing!" );
2684 : }
2685 : }
2686 15 : ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
2687 : {
2688 0 : IF( EQ_16( mc_mode_old, MC_MODE_MCT ) )
2689 : {
2690 0 : test();
2691 0 : IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2692 : {
2693 : /*TODO :To be tested : no stream entering*/
2694 0 : st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
2695 0 : IF( NE_32( ( error = getAudioConfigNumChannels( intern_config_old, &nchan_in ) ), IVAS_ERR_OK ) )
2696 : {
2697 0 : return error;
2698 : }
2699 0 : IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) )
2700 : {
2701 0 : return error;
2702 : }
2703 0 : *st_ivas->hCrendWrapper->p_io_qfactor = 11;
2704 0 : move16();
2705 0 : IF( NE_32( ( error = ivas_rend_crendProcessSubframe( st_ivas->hCrendWrapper, intern_config_old, st_ivas->hOutSetup.output_config, st_ivas->hDecoderConfig, st_ivas->hCombinedOrientationData,
2706 : hIntSetupOld, st_ivas->hEFAPdata, st_ivas->hTcBuffer, hTcBuffer->tc_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ),
2707 : IVAS_ERR_OK ) )
2708 : {
2709 0 : return error;
2710 : }
2711 :
2712 0 : ivas_binaural_add_LFE_fx( st_ivas, hTcBuffer->n_samples_granularity, st_ivas->hTcBuffer->tc_fx, p_output_fx );
2713 : }
2714 0 : ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
2715 : {
2716 0 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) )
2717 : {
2718 0 : return error;
2719 : }
2720 0 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, st_ivas->hTcBuffer->tc_fx, p_output_fx );
2721 : }
2722 : }
2723 : ELSE
2724 : {
2725 0 : return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong MC_MODE in VoIP renderer flushing!" );
2726 : }
2727 : }
2728 15 : ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
2729 : {
2730 6 : IF( EQ_16( ism_mode_old, ISM_MASA_MODE_DISC ) )
2731 : {
2732 : Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS];
2733 :
2734 6 : move16();
2735 22 : FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
2736 : {
2737 16 : tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered];
2738 16 : Copy32( st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hMasaIsmData->delayBuffer_size ); /*Q11*/
2739 : }
2740 :
2741 6 : IF( st_ivas->nchan_ism > 0 )
2742 : {
2743 4 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) )
2744 : {
2745 0 : return error;
2746 : }
2747 : }
2748 : ELSE
2749 : {
2750 6 : FOR( ch_idx = 0; ch_idx < st_ivas->hDecoderConfig->nchan_out; ch_idx++ )
2751 : {
2752 4 : set_zero_fx( p_output_fx[ch_idx], (Word16) ( *nSamplesRendered ) );
2753 : }
2754 2 : st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, 1 );
2755 2 : st_ivas->hTcBuffer->subframes_rendered = add( st_ivas->hTcBuffer->subframes_rendered, 1 );
2756 2 : move16();
2757 2 : move16();
2758 : }
2759 : }
2760 : }
2761 9 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2762 : {
2763 : Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS];
2764 : Word16 last_spar_md_idx;
2765 : Word16 last_dirac_md_idx;
2766 : UWord16 nSamplesAvailableNext;
2767 :
2768 9 : last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1];
2769 9 : last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1];
2770 9 : move16();
2771 9 : move16();
2772 : /* copy from ISM delay buffer to the correct place in tcs */
2773 27 : FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
2774 : {
2775 18 : tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered];
2776 18 : Copy32( st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hSbaIsmData->delayBuffer_size );
2777 : }
2778 :
2779 : /* transfer adapted sf info from hTcBuffer to SPAR and DirAC */
2780 9 : st_ivas->hSpar->nb_subframes = 1;
2781 9 : st_ivas->hSpar->subframes_rendered = 0;
2782 9 : st_ivas->hSpar->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
2783 9 : st_ivas->hSpar->slots_rendered = 0;
2784 9 : st_ivas->hSpar->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
2785 9 : st_ivas->hSpatParamRendCom->nb_subframes = 1;
2786 9 : st_ivas->hSpatParamRendCom->subframes_rendered = 0;
2787 9 : st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
2788 9 : st_ivas->hSpatParamRendCom->slots_rendered = 0;
2789 9 : st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
2790 9 : move16();
2791 9 : move16();
2792 9 : move16();
2793 9 : move16();
2794 9 : move16();
2795 9 : move16();
2796 9 : move16();
2797 9 : move16();
2798 9 : move16();
2799 9 : move16();
2800 :
2801 : /* also adapt md maps, just use the last index */
2802 9 : set16_fx( st_ivas->hSpar->render_to_md_map, last_spar_md_idx, n_slots_still_available );
2803 9 : set16_fx( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available );
2804 :
2805 : /* render the last subframe */
2806 9 : IF( NE_32( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, (UWord16) hTcBuffer->n_samples_granularity, nSamplesRendered, &nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2807 : {
2808 0 : return error;
2809 : }
2810 : }
2811 : ELSE
2812 : {
2813 0 : return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong IVAS format in VoIP renderer flushing!" );
2814 : }
2815 : #ifdef CR_FIX_JBM_FLUSH_OFFSET
2816 : hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity;
2817 : #endif
2818 : }
2819 :
2820 : /* update global combined orientation start index */
2821 101 : ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
2822 :
2823 101 : *nSamplesRendered = n_samples_to_render;
2824 101 : move16();
2825 : /* Only write out the valid data*/
2826 : {
2827 101 : IF( NE_16( st_ivas->ivas_format, MONO_FORMAT ) )
2828 : {
2829 : #ifndef DISABLE_LIMITER
2830 101 : Word16 ch_idx, exp = 11;
2831 101 : move16();
2832 1717 : FOR( ch_idx = 0; ch_idx < MAX_CICP_CHANNELS; ch_idx++ )
2833 : {
2834 1616 : p_output_fx[ch_idx] = output_fx[ch_idx];
2835 : }
2836 101 : ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, exp );
2837 : #endif
2838 : }
2839 : }
2840 :
2841 101 : ivas_syn_output_fx( p_output_fx, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, data );
2842 101 : return IVAS_ERR_OK;
2843 : }
2844 :
2845 :
2846 : /*--------------------------------------------------------------------------*
2847 : * ivas_jbm_dec_set_discard_samples()
2848 : *
2849 : * Set number of samples to discard in the first subframe if the renderer granularity changes on a bitrate change
2850 : *--------------------------------------------------------------------------*/
2851 :
2852 324 : ivas_error ivas_jbm_dec_set_discard_samples(
2853 : Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */
2854 : )
2855 : {
2856 : Word16 nMaxSlotsPerSubframe, nSlotsInFirstSubframe;
2857 : Word16 temp, temp_e;
2858 : /* render first frame with front zero padding and discarding those samples */
2859 : // nMaxSlotsPerSubframe = (Word16)(st_ivas->hDecoderConfig->output_Fs / (FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES)) / st_ivas->hTcBuffer->n_samples_granularity;
2860 324 : temp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), &temp_e );
2861 324 : temp = shr( temp, sub( 15, temp_e ) );
2862 324 : nMaxSlotsPerSubframe = BASOP_Util_Divide1616_Scale( temp, st_ivas->hTcBuffer->n_samples_granularity, &temp_e );
2863 324 : nMaxSlotsPerSubframe = shr( nMaxSlotsPerSubframe, sub( 15, temp_e ) ); // Q0
2864 324 : nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] );
2865 324 : IF( nSlotsInFirstSubframe > 0 )
2866 : {
2867 22 : st_ivas->hTcBuffer->n_samples_discard = imult1616( sub( nMaxSlotsPerSubframe, nSlotsInFirstSubframe ), st_ivas->hTcBuffer->n_samples_granularity );
2868 : /* set last subframes number to max to ensure correct continuation */
2869 22 : st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nMaxSlotsPerSubframe;
2870 22 : move16();
2871 22 : move16();
2872 : }
2873 :
2874 324 : return IVAS_ERR_OK;
2875 : }
2876 :
2877 :
2878 : /*--------------------------------------------------------------------------*
2879 : * ivas_jbm_dec_get_adapted_linear_interpolator()
2880 : *
2881 : * Get an interpolator that is adapted to time scale modified IVAS frame
2882 : *--------------------------------------------------------------------------*/
2883 17686 : void ivas_jbm_dec_get_adapted_linear_interpolator_fx(
2884 : const Word16 default_interp_length, /* i : default length of the (full-frame) interpolator */
2885 : const Word16 interp_length, /* i : length of the interpolator to be created */
2886 : Word16 *interpolator_fx /* o : the interpolator Q15 */
2887 : )
2888 : {
2889 : Word16 jbm_segment_len, idx;
2890 : Word16 dec_fx;
2891 : Word16 dec_e;
2892 :
2893 17686 : jbm_segment_len = shr( default_interp_length, 1 );
2894 17686 : dec_fx = divide1616( 1, default_interp_length ); /*32767 / default_interp_length*/
2895 :
2896 17686 : interpolator_fx[interp_length - 1] = 32767; /* (1.0f in Q15) -1 */
2897 17686 : move16();
2898 17686 : interpolator_fx[interp_length - 2] = add( sub( 32767, dec_fx ), 1 ); // Use 32768 to maintain precision
2899 17686 : move16();
2900 1540746 : FOR( idx = interp_length - 3; idx >= jbm_segment_len; idx-- )
2901 : {
2902 1523060 : interpolator_fx[idx] = s_max( 0, sub( interpolator_fx[idx + 1], dec_fx ) );
2903 1523060 : move16();
2904 : }
2905 :
2906 17686 : IF( interpolator_fx[idx + 1] > 0 )
2907 : {
2908 17685 : dec_fx = BASOP_Util_Divide1616_Scale( interpolator_fx[idx + 1], add( jbm_segment_len, 1 ), &dec_e );
2909 17685 : dec_fx = shr( dec_fx, sub( 15, dec_e ) ); // Q0
2910 1575477 : FOR( ; idx >= 0; idx-- )
2911 : {
2912 1557792 : interpolator_fx[idx] = sub( interpolator_fx[idx + 1], dec_fx );
2913 1557792 : move16();
2914 : }
2915 : }
2916 : ELSE
2917 : {
2918 1 : set16_fx( interpolator_fx, 0, idx + 1 );
2919 : }
2920 :
2921 17686 : return;
2922 : }
2923 :
2924 : /*--------------------------------------------------------------------------*
2925 : * ivas_jbm_dec_get_adapted_subframes()
2926 : *
2927 : * Get an interpolator that is adapted to time scale modified IVAS frame
2928 : *--------------------------------------------------------------------------*/
2929 :
2930 290284 : void ivas_jbm_dec_get_adapted_subframes(
2931 : const Word16 nCldfbTs, /* i : number of time slots in the current frame */
2932 : Word16 *subframe_nbslots, /* i/o: subframe grid */
2933 : Word16 *nb_subframes /* i/o: number of subframes in the frame */
2934 : )
2935 : {
2936 : UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe;
2937 290284 : UWord16 nCldfbSlotsLocal = nCldfbTs;
2938 290284 : move16();
2939 : Word16 temp, temp_e;
2940 : /* get last subframe size from previous frame, determine how many slots have to be processed
2941 : in the first subframe (i.e. potential leftover of a 5ms subframe) */
2942 290284 : nSlotsInFirstSubframe = ( sub( PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, subframe_nbslots[*nb_subframes - 1] ) );
2943 290284 : *nb_subframes = 0;
2944 290284 : move16();
2945 290284 : IF( nSlotsInFirstSubframe > 0 )
2946 : {
2947 7849 : *nb_subframes = 1;
2948 7849 : move16();
2949 7849 : nCldfbSlotsLocal = sub( nCldfbSlotsLocal, nSlotsInFirstSubframe );
2950 : }
2951 :
2952 290284 : temp = BASOP_Util_Divide3232_Scale( L_add( nCldfbSlotsLocal, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1 ), PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, &temp_e );
2953 290284 : *nb_subframes = add( *nb_subframes, shr( temp, sub( 15, temp_e ) ) ); // Q0
2954 290284 : move16();
2955 290284 : nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME;
2956 290284 : move16();
2957 :
2958 290284 : set16_fx( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
2959 290284 : set16_fx( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes );
2960 :
2961 290284 : IF( nSlotsInFirstSubframe > 0 )
2962 : {
2963 7849 : subframe_nbslots[0] = nSlotsInFirstSubframe;
2964 7849 : move16();
2965 : }
2966 :
2967 290284 : IF( nSlotsInLastSubframe > 0 )
2968 : {
2969 7861 : subframe_nbslots[*nb_subframes - 1] = nSlotsInLastSubframe;
2970 7861 : move16();
2971 : }
2972 :
2973 290284 : return;
2974 : }
2975 : /*--------------------------------------------------------------------------*
2976 : * ivas_jbm_dec_get_adapted_linear_interpolator()
2977 : *
2978 : * Get an meta data map adapted to a time scale modified IVAS frame
2979 : *--------------------------------------------------------------------------*/
2980 :
2981 254992 : void ivas_jbm_dec_get_md_map(
2982 : const Word16 default_len, /* i : default frame length in metadata slots */
2983 : const Word16 len, /* i : length of the modfied frames in metadata slots */
2984 : const Word16 subframe_len, /* i : default length of a subframe */
2985 : const Word16 offset, /* i : current read offset into the md buffer */
2986 : const Word16 buf_len, /* i : length of the metadata buffer */
2987 : Word16 *map /* o : metadata index map */
2988 : )
2989 : {
2990 : Word16 jbm_segment_len, map_idx, src_idx, src_idx_map;
2991 : Word32 dec_fx, src_idx_fx;
2992 : Word16 temp_e;
2993 : Word16 temp;
2994 254992 : jbm_segment_len = shr( default_len, 1 );
2995 :
2996 2294961 : FOR( ( map_idx = len - 1, src_idx = default_len - 1 ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) )
2997 : {
2998 2039969 : temp = BASOP_Util_Divide1616_Scale( src_idx, subframe_len, &temp_e );
2999 2039969 : temp = shr( temp, sub( 15, temp_e ) ); // Q0
3000 2039969 : src_idx_map = s_max( 0, temp );
3001 2039969 : map[map_idx] = add( offset, src_idx_map ) % buf_len;
3002 2039969 : move16();
3003 : }
3004 :
3005 : /* changed part (first segment), interpolate index to parameters
3006 : (we do not want to interpolate and smooth acutal direction/diffuseness values even more) */
3007 254992 : IF( src_idx >= 0 )
3008 : {
3009 254986 : dec_fx = BASOP_Util_Divide3232_Scale( L_shl( add( src_idx, 1 ), 16 ), jbm_segment_len, &temp_e );
3010 254986 : dec_fx = L_shr( dec_fx, sub( 15, temp_e ) );
3011 254986 : src_idx_fx = L_sub( L_shl( add( src_idx, 1 ), 16 ), dec_fx );
3012 2294874 : FOR( ; map_idx >= 0; map_idx-- )
3013 : {
3014 2039888 : temp = BASOP_Util_Divide1616_Scale( round_fx( src_idx_fx ), subframe_len, &temp_e );
3015 2039888 : temp = shr( temp, sub( 15, temp_e ) ); // Q0
3016 2039888 : src_idx = s_max( 0, temp );
3017 2039888 : map[map_idx] = add( offset, src_idx ) % buf_len;
3018 2039888 : src_idx_fx = L_sub( src_idx_fx, dec_fx );
3019 : }
3020 : }
3021 : ELSE
3022 : {
3023 6 : set16_fx( map, offset, add( map_idx, 1 ) );
3024 : }
3025 :
3026 254992 : return;
3027 : }
3028 :
3029 : /*--------------------------------------------------------------------------*
3030 : * ivas_jbm_dec_get_md_map_even_spacing()
3031 : *
3032 : * Get an meta data map adapted to a time scale modified IVAS frame. Distribute slots evenly across the modified frame.
3033 : *--------------------------------------------------------------------------*/
3034 :
3035 31994 : void ivas_jbm_dec_get_md_map_even_spacing(
3036 : const Word16 len, /* i : length of the modfied frames in metadata slots */
3037 : const Word16 subframe_len, /* i : default length of a subframe */
3038 : const Word16 offset, /* i : current read offset into the md buffer */
3039 : const Word16 buf_len, /* i : length of the metadata buffer */
3040 : Word16 *map /* o : metadata index map */
3041 : )
3042 : {
3043 : Word16 map_idx, sf_idx, sf_length, increment, subframes_written;
3044 : Word32 decimal_fx, decimal_sum_fx, eps_fx; // q = 16
3045 : Word16 subframe_map_length[MAX_PARAM_SPATIAL_SUBFRAMES];
3046 :
3047 : /* subframe map length */
3048 31994 : sf_length = idiv1616( len, subframe_len );
3049 31994 : IF( len % subframe_len == 0 )
3050 : {
3051 : /* even subframes */
3052 159915 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
3053 : {
3054 127932 : subframe_map_length[sf_idx] = sf_length;
3055 127932 : move16();
3056 : }
3057 : }
3058 : ELSE
3059 : {
3060 : /* uneven subframes */
3061 : Word32 temp;
3062 : Word16 temp_e;
3063 11 : temp = BASOP_Util_Divide3232_Scale( L_shl( len, 16 ), subframe_len, &temp_e );
3064 11 : temp = L_shr( temp, sub( 15, temp_e ) ); // Q16
3065 11 : decimal_fx = L_sub( temp, L_shl( sf_length, 16 ) ); // Q16
3066 11 : decimal_sum_fx = decimal_fx;
3067 :
3068 11 : eps_fx = 65;
3069 11 : move32();
3070 11 : move32();
3071 55 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
3072 : {
3073 44 : increment = extract_l( L_shr( L_add( decimal_sum_fx, eps_fx ), 16 ) );
3074 44 : subframe_map_length[sf_idx] = add( sf_length, increment );
3075 44 : move16();
3076 44 : IF( increment > 0 )
3077 : {
3078 22 : decimal_sum_fx = L_sub( decimal_sum_fx, ONE_IN_Q16 );
3079 : }
3080 44 : decimal_sum_fx = L_add( decimal_sum_fx, decimal_fx );
3081 : }
3082 : }
3083 :
3084 : /* map slots to subframes */
3085 31994 : sf_idx = 0;
3086 31994 : subframes_written = 0;
3087 31994 : move16();
3088 31994 : move16();
3089 544016 : FOR( map_idx = 0; map_idx < len; map_idx++ )
3090 : {
3091 512022 : map[map_idx] = add( offset, sf_idx ) % buf_len;
3092 512022 : move16();
3093 512022 : IF( GE_16( sub( map_idx, subframes_written ), sub( subframe_map_length[sf_idx], 1 ) ) )
3094 : {
3095 127976 : subframes_written = add( subframes_written, subframe_map_length[sf_idx] );
3096 127976 : sf_idx = add( sf_idx, 1 );
3097 : }
3098 : }
3099 :
3100 31994 : return;
3101 : }
3102 :
3103 : /*--------------------------------------------------------------------------*
3104 : * ivas_jbm_dec_get_num_tc_channels()
3105 : *
3106 : * Get the number of transport channels provided by the JBM transport channel decode function
3107 : *--------------------------------------------------------------------------*/
3108 :
3109 :
3110 6849 : Word16 ivas_jbm_dec_get_num_tc_channels_fx(
3111 : Decoder_Struct *st_ivas /* i : IVAS decoder handle */
3112 : )
3113 : {
3114 : Word16 num_tc;
3115 : Word32 ivas_total_brate;
3116 : AUDIO_CONFIG output_config;
3117 :
3118 :
3119 6849 : IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) )
3120 : {
3121 892 : num_tc = st_ivas->hDecoderConfig->nchan_out;
3122 892 : move16();
3123 : }
3124 : ELSE
3125 : {
3126 5957 : num_tc = st_ivas->nchan_transport;
3127 5957 : move16();
3128 : }
3129 6849 : output_config = st_ivas->hDecoderConfig->output_config;
3130 6849 : move16();
3131 :
3132 6849 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
3133 6849 : move32();
3134 :
3135 6849 : test();
3136 6849 : test();
3137 6849 : test();
3138 6849 : IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) )
3139 : {
3140 3 : num_tc = st_ivas->hDecoderConfig->nchan_out;
3141 3 : move16();
3142 : }
3143 6846 : ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) )
3144 : {
3145 22 : num_tc = 1;
3146 22 : move16();
3147 : }
3148 6824 : ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
3149 : {
3150 1066 : if ( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
3151 : {
3152 2 : num_tc = 1;
3153 2 : move16();
3154 : }
3155 : }
3156 5758 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
3157 : {
3158 3055 : test();
3159 3055 : test();
3160 3055 : test();
3161 3055 : test();
3162 3055 : test();
3163 3055 : test();
3164 3055 : IF( st_ivas->sba_dirac_stereo_flag )
3165 : {
3166 124 : num_tc = CPE_CHANNELS;
3167 124 : move16();
3168 : }
3169 2931 : ELSE IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( ivas_total_brate, IVAS_SID_5k2 ) && GT_16( st_ivas->nCPE, 0 ) && st_ivas->hCPE[0] != NULL && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) )
3170 : {
3171 626 : num_tc = 1; /* Only one channel transported */
3172 626 : move16();
3173 : }
3174 :
3175 3055 : test();
3176 3055 : test();
3177 3055 : test();
3178 3055 : test();
3179 3055 : IF( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) && EQ_16( st_ivas->nchan_transport, 2 ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
3180 : {
3181 5 : num_tc = CPE_CHANNELS;
3182 5 : move16();
3183 : }
3184 3055 : IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) )
3185 : {
3186 1263 : if ( EQ_16( num_tc, 3 ) )
3187 : {
3188 267 : num_tc = add( num_tc, 1 );
3189 : }
3190 : }
3191 : }
3192 2703 : ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
3193 : {
3194 1098 : IF( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
3195 : {
3196 1095 : test();
3197 1095 : IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
3198 : {
3199 693 : num_tc = add( num_tc, 1 );
3200 : }
3201 402 : ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
3202 : {
3203 402 : num_tc = add( num_tc, st_ivas->nchan_ism );
3204 : }
3205 : }
3206 : }
3207 1605 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
3208 : {
3209 :
3210 :
3211 501 : if ( st_ivas->sba_dirac_stereo_flag )
3212 : {
3213 94 : num_tc = CPE_CHANNELS;
3214 94 : move16();
3215 : }
3216 :
3217 501 : test();
3218 501 : test();
3219 501 : if ( ( st_ivas->sba_planar && GE_16( num_tc, 3 ) ) || EQ_16( num_tc, 3 ) )
3220 : {
3221 115 : num_tc = add( num_tc, 1 );
3222 : }
3223 501 : if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
3224 : {
3225 96 : num_tc = add( num_tc, st_ivas->nchan_ism );
3226 : }
3227 : }
3228 1104 : ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
3229 : {
3230 1059 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
3231 : {
3232 5 : num_tc = 1;
3233 5 : move16();
3234 : }
3235 1054 : ELSE IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) )
3236 : {
3237 26 : num_tc = 2;
3238 26 : move16();
3239 : }
3240 1028 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
3241 : {
3242 : /* do all static dmx already in the TC decoder if less channels than transported... */
3243 517 : test();
3244 517 : test();
3245 517 : test();
3246 517 : test();
3247 517 : test();
3248 517 : IF( NE_16( st_ivas->transport_config, st_ivas->intern_config ) && ( EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( st_ivas->intern_config, IVAS_AUDIO_CONFIG_HOA3 ) ) )
3249 : {
3250 1 : if ( GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ) ) )
3251 : {
3252 0 : num_tc = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
3253 : }
3254 : }
3255 516 : ELSE IF( ( EQ_16( st_ivas->renderer_type, RENDERER_MC ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ), add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) )
3256 : {
3257 0 : num_tc = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
3258 : }
3259 : }
3260 511 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
3261 : {
3262 9 : num_tc = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
3263 9 : move16();
3264 : }
3265 502 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
3266 : {
3267 216 : if ( st_ivas->hOutSetup.separateChannelEnabled )
3268 : {
3269 11 : num_tc = add( num_tc, 1 );
3270 : }
3271 216 : test();
3272 216 : test();
3273 216 : test();
3274 216 : test();
3275 216 : test();
3276 216 : test();
3277 216 : test();
3278 226 : if ( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
3279 30 : EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
3280 20 : EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_2 ) || ( EQ_16( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe > 0 ) ) )
3281 : {
3282 : /* LFE is synthesized in TD with the TCs*/
3283 1 : num_tc = add( num_tc, 1 );
3284 : }
3285 : }
3286 : }
3287 45 : ELSE IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
3288 : {
3289 0 : num_tc = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN;
3290 0 : move16();
3291 : }
3292 :
3293 6849 : return num_tc;
3294 : }
3295 :
3296 : /*--------------------------------------------------------------------------*
3297 : * ivas_jbm_dec_copy_tc()
3298 : *
3299 : * Copy interleaved transport chnannels to the correct buffers, update the TC
3300 : * buffer handle
3301 : *--------------------------------------------------------------------------*/
3302 19405 : static void ivas_jbm_dec_copy_tc(
3303 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
3304 : const Word16 nSamplesForRendering, /* i : number of samples to digest */
3305 : Word16 *nSamplesResidual, /* o : number of samples that will be left for the next frame */
3306 : Word32 *data, /* i : (interleaved) transport channel samples data_q*/
3307 : Word32 *tc_digest_f[], /* o : samples that will be directly digested (e.g. by CLDFB) data_q*/
3308 : Word16 data_q )
3309 : {
3310 : Word16 ch;
3311 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
3312 : Word16 n_samples_still_available, m;
3313 : Word16 n_ch_full_copy;
3314 : Word16 n_ch_res_copy;
3315 :
3316 19405 : hTcBuffer = st_ivas->hTcBuffer;
3317 19405 : n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered );
3318 19405 : hTcBuffer->n_samples_buffered = add( add( n_samples_still_available, nSamplesForRendering ), hTcBuffer->n_samples_discard );
3319 19405 : hTcBuffer->n_samples_available = i_mult( hTcBuffer->n_samples_granularity, idiv1616( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_granularity ) );
3320 19405 : *nSamplesResidual = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_available );
3321 19405 : move16();
3322 19405 : move16();
3323 19405 : move16();
3324 19405 : n_ch_full_copy = s_min( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
3325 19405 : n_ch_res_copy = sub( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
3326 :
3327 60104 : FOR( ch = 0; ch < n_ch_full_copy; ch++ )
3328 : {
3329 40699 : set32_fx( hTcBuffer->tc_fx[ch], 0, hTcBuffer->n_samples_discard );
3330 40699 : Copy32( hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_discard, n_samples_still_available );
3331 32047796 : FOR( m = 0; m < nSamplesForRendering; m++ )
3332 : {
3333 32007097 : hTcBuffer->tc_fx[ch][n_samples_still_available + hTcBuffer->n_samples_discard + m] = data[m * st_ivas->hTcBuffer->nchan_transport_jbm + ch];
3334 32007097 : move32();
3335 : }
3336 : }
3337 :
3338 19405 : IF( n_ch_res_copy > 0 )
3339 : {
3340 4518 : FOR( ; ch < hTcBuffer->nchan_transport_jbm; ch++ )
3341 : {
3342 3012 : Copy32( hTcBuffer->tc_fx[ch], tc_digest_f[ch], n_samples_still_available );
3343 2894538 : FOR( m = 0; m < nSamplesForRendering; m++ )
3344 : {
3345 2891526 : tc_digest_f[ch][n_samples_still_available + m] = data[( m * st_ivas->hTcBuffer->nchan_transport_jbm ) + ch]; // data_q
3346 2891526 : move32();
3347 : }
3348 3012 : Copy32( tc_digest_f[ch] + hTcBuffer->n_samples_available, hTcBuffer->tc_fx[ch], *nSamplesResidual );
3349 : }
3350 : }
3351 19405 : hTcBuffer->q_tc_fx = data_q;
3352 19405 : move16();
3353 19405 : hTcBuffer->n_samples_rendered = 0;
3354 19405 : move16();
3355 19405 : hTcBuffer->subframes_rendered = 0;
3356 19405 : move16();
3357 :
3358 19405 : return;
3359 : }
3360 :
3361 : /*--------------------------------------------------------------------------*
3362 : * ivas_jbm_dec_get_render_granularity()
3363 : *
3364 : *
3365 : *--------------------------------------------------------------------------*/
3366 :
3367 : /*! r: render granularity */
3368 :
3369 :
3370 1907 : Word16 ivas_jbm_dec_get_render_granularity(
3371 : const RENDERER_TYPE rendererType, /* i : renderer type */
3372 : const IVAS_FORMAT ivas_format, /* i : ivas format */
3373 : const MC_MODE mc_mode, /* i : MC mode */
3374 : const Word32 output_Fs /* i : sampling rate Q0*/
3375 : )
3376 : {
3377 : Word16 render_granularity;
3378 :
3379 1907 : test();
3380 1907 : test();
3381 1907 : IF( EQ_32( rendererType, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
3382 : {
3383 467 : test();
3384 467 : IF( ( EQ_32( ivas_format, MC_FORMAT ) ) && ( EQ_32( mc_mode, MC_MODE_PARAMUPMIX ) ) )
3385 : {
3386 0 : render_granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS );
3387 : }
3388 : ELSE
3389 : {
3390 467 : render_granularity = NS2SA_FX2( output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
3391 : }
3392 : }
3393 : ELSE
3394 : {
3395 1440 : render_granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS );
3396 : }
3397 :
3398 1907 : return render_granularity;
3399 : }
3400 :
3401 :
3402 : /*--------------------------------------------------------------------------*
3403 : * ivas_jbm_dec_tc_buffer_open()
3404 : *
3405 : * open and initialize JBM transport channel buffer
3406 : *--------------------------------------------------------------------------*/
3407 :
3408 :
3409 594 : ivas_error ivas_jbm_dec_tc_buffer_open_fx(
3410 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
3411 : const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */
3412 : const Word16 nchan_transport_jbm, /* i : number of real transport channels */
3413 : const Word16 nchan_transport_internal, /* i : number of totally buffered channels */
3414 : const Word16 nchan_full, /* i : number of channels to fully store */
3415 : const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */
3416 : )
3417 : {
3418 : Word16 nsamp_to_allocate;
3419 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
3420 : Word16 nMaxSlotsPerSubframe;
3421 : Word16 nchan_residual;
3422 : Word16 ch_idx;
3423 : Word16 tmp, tmp_e;
3424 : Word32 tmp32;
3425 :
3426 : /*-----------------------------------------------------------------*
3427 : * prepare library opening
3428 : *-----------------------------------------------------------------*/
3429 :
3430 594 : IF( ( hTcBuffer = (DECODER_TC_BUFFER_HANDLE) malloc( sizeof( DECODER_TC_BUFFER ) ) ) == NULL )
3431 : {
3432 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) );
3433 : }
3434 :
3435 594 : hTcBuffer->tc_buffer_mode = tc_buffer_mode;
3436 594 : move16();
3437 594 : hTcBuffer->nchan_transport_jbm = nchan_transport_jbm;
3438 594 : move16();
3439 594 : hTcBuffer->nchan_transport_internal = nchan_transport_internal;
3440 594 : move16();
3441 594 : hTcBuffer->nchan_buffer_full = nchan_full;
3442 594 : move16();
3443 594 : nchan_residual = sub( nchan_transport_internal, nchan_full );
3444 594 : hTcBuffer->n_samples_granularity = n_samples_granularity;
3445 594 : move16();
3446 594 : hTcBuffer->n_samples_available = 0;
3447 594 : move16();
3448 594 : hTcBuffer->n_samples_buffered = 0;
3449 594 : move16();
3450 594 : hTcBuffer->n_samples_rendered = 0;
3451 594 : move16();
3452 594 : hTcBuffer->slots_rendered = 0;
3453 594 : move16();
3454 594 : hTcBuffer->subframes_rendered = 0;
3455 594 : move16();
3456 594 : hTcBuffer->n_samples_discard = 0;
3457 594 : move16();
3458 594 : hTcBuffer->n_samples_flushed = 0;
3459 594 : move16();
3460 594 : hTcBuffer->nb_subframes = MAX_PARAM_SPATIAL_SUBFRAMES;
3461 594 : move16();
3462 594 : nsamp_to_allocate = 0;
3463 594 : move16();
3464 :
3465 594 : tmp32 = L_mult0( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity ); // Q0
3466 594 : tmp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, tmp32, &tmp_e );
3467 594 : nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); // Q0
3468 :
3469 594 : hTcBuffer->num_slots = mult0( nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES );
3470 594 : move16();
3471 :
3472 594 : set16_fx( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
3473 594 : set16_fx( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES );
3474 :
3475 594 : IF( EQ_16( hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_NONE ) )
3476 : {
3477 0 : hTcBuffer->tc_buffer_fx = NULL;
3478 :
3479 0 : FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3480 : {
3481 0 : hTcBuffer->tc_fx[ch_idx] = NULL;
3482 : }
3483 : }
3484 : ELSE
3485 : {
3486 : Word16 n_samp_full, n_samp_residual;
3487 : Word32 offset;
3488 594 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3489 : {
3490 27 : n_samp_full = add( NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ), sub( hTcBuffer->n_samples_granularity, 1 ) );
3491 27 : n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 );
3492 : }
3493 : ELSE
3494 : {
3495 : /* n_samp_full = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */
3496 567 : n_samp_full = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) );
3497 567 : n_samp_residual = 0;
3498 567 : move16();
3499 : }
3500 :
3501 594 : nsamp_to_allocate = mult0( hTcBuffer->nchan_buffer_full, n_samp_full );
3502 594 : nsamp_to_allocate = add( nsamp_to_allocate, mult0( nchan_residual, n_samp_residual ) );
3503 :
3504 594 : IF( nsamp_to_allocate == 0 )
3505 : {
3506 14 : hTcBuffer->tc_buffer_fx = NULL;
3507 :
3508 238 : FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3509 : {
3510 224 : hTcBuffer->tc_fx[ch_idx] = NULL;
3511 : }
3512 : }
3513 : ELSE
3514 : {
3515 580 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3516 : {
3517 27 : IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL )
3518 : {
3519 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) );
3520 : }
3521 27 : set32_fx( hTcBuffer->tc_buffer_fx, 0, nsamp_to_allocate );
3522 :
3523 27 : offset = 0;
3524 27 : move16();
3525 125 : FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
3526 : {
3527 98 : hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
3528 98 : offset = L_add( offset, n_samp_full );
3529 : }
3530 29 : FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ )
3531 : {
3532 2 : hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
3533 2 : offset = L_add( offset, n_samp_residual );
3534 : }
3535 359 : FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3536 : {
3537 332 : hTcBuffer->tc_fx[ch_idx] = NULL;
3538 : }
3539 : }
3540 : ELSE
3541 : {
3542 553 : hTcBuffer->tc_buffer_fx = NULL;
3543 : }
3544 : }
3545 : }
3546 :
3547 594 : st_ivas->hTcBuffer = hTcBuffer;
3548 :
3549 594 : return IVAS_ERR_OK;
3550 : }
3551 :
3552 :
3553 : /*--------------------------------------------------------------------------*
3554 : * ivas_jbm_dec_tc_buffer_reconfigure()
3555 : *
3556 : * open and initialize JBM transport channel buffer
3557 : *--------------------------------------------------------------------------*/
3558 :
3559 :
3560 3499 : ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx(
3561 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
3562 : const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */
3563 : const Word16 nchan_transport_jbm, /* i : new number of real transport channels */
3564 : const Word16 nchan_transport_internal, /* i : new number of totally buffered channels */
3565 : const Word16 nchan_full, /* i : new number of channels to fully store */
3566 : const Word16 n_samples_granularity /* i : new granularity of the renderer/buffer */
3567 : )
3568 : {
3569 : Word16 nsamp_to_allocate, n_samp_full, n_samp_residual, offset, nchan_residual;
3570 : Word16 ch_idx;
3571 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
3572 :
3573 3499 : hTcBuffer = st_ivas->hTcBuffer;
3574 3499 : move16();
3575 :
3576 :
3577 : /* if granularity changes, adapt subframe_nb_slots */
3578 3499 : IF( NE_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) )
3579 : {
3580 : Word16 nMaxSlotsPerSubframeNew;
3581 :
3582 642 : nMaxSlotsPerSubframeNew = idiv1616( divide3216( st_ivas->hDecoderConfig->output_Fs, ( ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) >> 1 ) ), n_samples_granularity ); // Q0
3583 : /* if samples were flushed, take that into account here */
3584 642 : test();
3585 642 : IF( LT_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) && hTcBuffer->n_samples_flushed > 0 )
3586 : {
3587 22 : hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = idiv1616( hTcBuffer->n_samples_flushed, n_samples_granularity );
3588 22 : hTcBuffer->n_samples_flushed = 0;
3589 22 : move16();
3590 22 : move16();
3591 : }
3592 : ELSE
3593 : {
3594 620 : hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = nMaxSlotsPerSubframeNew;
3595 620 : move16();
3596 : }
3597 : }
3598 :
3599 3499 : hTcBuffer->tc_buffer_mode = tc_buffer_mode;
3600 3499 : move16();
3601 3499 : hTcBuffer->nchan_transport_jbm = nchan_transport_jbm;
3602 3499 : move16();
3603 3499 : hTcBuffer->nchan_transport_internal = nchan_transport_internal;
3604 3499 : move16();
3605 3499 : hTcBuffer->nchan_buffer_full = nchan_full;
3606 3499 : move16();
3607 3499 : nchan_residual = sub( nchan_transport_internal, nchan_full );
3608 3499 : hTcBuffer->n_samples_granularity = n_samples_granularity;
3609 3499 : move16();
3610 :
3611 : /* realloc buffers */
3612 3499 : IF( hTcBuffer->tc_buffer_fx != NULL )
3613 : {
3614 927 : free( hTcBuffer->tc_buffer_fx );
3615 927 : hTcBuffer->tc_buffer_fx = NULL;
3616 : }
3617 :
3618 3499 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3619 : {
3620 927 : n_samp_full = ( add( NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ), sub( hTcBuffer->n_samples_granularity, 1 ) ) );
3621 927 : n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 );
3622 : }
3623 : ELSE
3624 : {
3625 2572 : n_samp_full = extract_l( Mult_32_16( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) );
3626 2572 : n_samp_residual = 0;
3627 2572 : move16();
3628 : }
3629 3499 : nsamp_to_allocate = imult1616( hTcBuffer->nchan_buffer_full, n_samp_full );
3630 3499 : nsamp_to_allocate = add( nsamp_to_allocate, imult1616( nchan_residual, n_samp_residual ) );
3631 :
3632 3499 : IF( nsamp_to_allocate == 0 )
3633 : {
3634 292 : hTcBuffer->tc_buffer_fx = NULL;
3635 4964 : FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3636 : {
3637 4672 : hTcBuffer->tc_fx[ch_idx] = NULL;
3638 : }
3639 : }
3640 : ELSE
3641 : {
3642 3207 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3643 : {
3644 :
3645 927 : IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL )
3646 : {
3647 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR JBM TC Buffer\n" ) );
3648 : }
3649 927 : set32_fx( hTcBuffer->tc_buffer_fx, 0, nsamp_to_allocate );
3650 :
3651 927 : offset = 0;
3652 927 : move16();
3653 4492 : FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
3654 : {
3655 3565 : hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
3656 3565 : offset = add( offset, n_samp_full );
3657 : }
3658 927 : FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ )
3659 : {
3660 0 : hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
3661 0 : offset = add( offset, n_samp_residual );
3662 : }
3663 12194 : FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3664 : {
3665 11267 : hTcBuffer->tc_fx[ch_idx] = NULL;
3666 : }
3667 :
3668 927 : hTcBuffer->tc_buff_len = nsamp_to_allocate;
3669 927 : move16();
3670 :
3671 927 : offset = 0;
3672 927 : move16();
3673 4492 : FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
3674 : {
3675 3565 : offset = add( offset, n_samp_full );
3676 : }
3677 927 : FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ )
3678 : {
3679 0 : offset = add( offset, n_samp_residual );
3680 : }
3681 : }
3682 : ELSE
3683 : {
3684 2280 : hTcBuffer->tc_buffer_fx = NULL;
3685 : }
3686 : }
3687 :
3688 3499 : return IVAS_ERR_OK;
3689 : }
3690 :
3691 :
3692 : /*--------------------------------------------------------------------------*
3693 : * ivas_jbm_dec_tc_buffer_playout()
3694 : *
3695 : *
3696 : *--------------------------------------------------------------------------*/
3697 :
3698 128726 : static void ivas_jbm_dec_tc_buffer_playout_fx(
3699 : Decoder_Struct *st_ivas,
3700 : const UWord16 nSamplesAsked,
3701 : UWord16 *nSamplesRendered,
3702 : Word32 *output_fx[] /*Q11*/
3703 : )
3704 : {
3705 : Word16 ch_idx, slot_size, slots_to_render, first_sf, last_sf, tmp, e;
3706 :
3707 128726 : slot_size = st_ivas->hTcBuffer->n_samples_granularity;
3708 128726 : move16();
3709 :
3710 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
3711 128726 : tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e );
3712 128726 : tmp = shr( tmp, sub( 15, e ) ); // Q0
3713 128726 : slots_to_render = s_min( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), tmp );
3714 128726 : st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); // Q0
3715 128726 : *nSamplesRendered = (UWord16) L_mult0( slots_to_render, slot_size );
3716 128726 : first_sf = st_ivas->hTcBuffer->subframes_rendered;
3717 128726 : last_sf = first_sf;
3718 128726 : move16();
3719 128726 : move16();
3720 128726 : move16();
3721 128726 : move16();
3722 :
3723 639859 : WHILE( slots_to_render > 0 )
3724 : {
3725 511133 : slots_to_render = sub( slots_to_render, st_ivas->hTcBuffer->subframe_nbslots[last_sf] );
3726 511133 : last_sf = add( last_sf, 1 );
3727 : }
3728 :
3729 374940 : FOR( ch_idx = 0; ch_idx < st_ivas->hTcBuffer->nchan_transport_jbm; ch_idx++ )
3730 : {
3731 246214 : Copy32( st_ivas->hTcBuffer->tc_fx[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered, output_fx[ch_idx], *nSamplesRendered );
3732 : }
3733 :
3734 128726 : st_ivas->hTcBuffer->subframes_rendered = last_sf;
3735 128726 : move16();
3736 :
3737 128726 : return;
3738 : }
3739 :
3740 :
3741 : /*--------------------------------------------------------------------------*
3742 : * ivas_jbm_dec_tc_buffer_close()
3743 : *
3744 : * Close JBM transport channel buffer
3745 : *--------------------------------------------------------------------------*/
3746 :
3747 604 : void ivas_jbm_dec_tc_buffer_close(
3748 : DECODER_TC_BUFFER_HANDLE *phTcBuffer /* i/o: TC buffer handle */
3749 : )
3750 : {
3751 : Word16 i;
3752 :
3753 604 : IF( *phTcBuffer != NULL )
3754 : {
3755 10098 : FOR( i = 0; i < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; i++ )
3756 : {
3757 9504 : ( *phTcBuffer )->tc_fx[i] = NULL;
3758 : }
3759 :
3760 594 : IF( ( *phTcBuffer )->tc_buffer_fx != NULL )
3761 : {
3762 27 : free( ( *phTcBuffer )->tc_buffer_fx );
3763 27 : ( *phTcBuffer )->tc_buffer_fx = NULL;
3764 : }
3765 :
3766 594 : free( *phTcBuffer );
3767 594 : *phTcBuffer = NULL;
3768 : }
3769 :
3770 604 : return;
3771 : }
3772 :
3773 : /*--------------------------------------------------------------------------*
3774 : * ivas_jbm_dec_td_renderers_adapt_subframes()
3775 : *
3776 : * Close JBM transport channel buffer
3777 : *--------------------------------------------------------------------------*/
3778 230248 : void ivas_jbm_dec_td_renderers_adapt_subframes(
3779 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
3780 : )
3781 : {
3782 : Word16 nMaxSlotsPerSubframe, nSlotsAvailable, tmp, exp, tmp1, tmp2, s1, s2;
3783 : UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe;
3784 :
3785 : /* nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; */
3786 230248 : tmp = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) );
3787 230248 : tmp = BASOP_Util_Divide1616_Scale( tmp, st_ivas->hTcBuffer->n_samples_granularity, &exp );
3788 230248 : nMaxSlotsPerSubframe = shr( tmp, sub( 15, exp ) ); // Q0
3789 :
3790 : /* nSlotsAvailable = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; */
3791 230248 : tmp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &exp );
3792 230248 : nSlotsAvailable = shr( tmp, sub( 15, exp ) ); // Q0
3793 :
3794 230248 : st_ivas->hTcBuffer->num_slots = nSlotsAvailable;
3795 230248 : move16();
3796 : /* st_ivas->hTcBuffer->n_samples_available = nSlotsAvailable * st_ivas->hTcBuffer->n_samples_granularity; */
3797 230248 : st_ivas->hTcBuffer->n_samples_available = i_mult( nSlotsAvailable, st_ivas->hTcBuffer->n_samples_granularity );
3798 230248 : move16();
3799 230248 : nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] );
3800 230248 : st_ivas->hTcBuffer->nb_subframes = 0;
3801 230248 : move16();
3802 :
3803 230248 : IF( nSlotsInFirstSubframe > 0 )
3804 : {
3805 2950 : st_ivas->hTcBuffer->nb_subframes = 1;
3806 2950 : move16();
3807 2950 : nSlotsAvailable = sub( nSlotsAvailable, nSlotsInFirstSubframe );
3808 : }
3809 :
3810 230248 : s1 = sub( norm_s( nSlotsAvailable ), 1 );
3811 230248 : s2 = norm_s( nMaxSlotsPerSubframe );
3812 :
3813 230248 : tmp1 = shl( nSlotsAvailable, s1 );
3814 230248 : tmp2 = shl( nMaxSlotsPerSubframe, s2 );
3815 :
3816 230248 : tmp = div_s( tmp1, tmp2 );
3817 230248 : st_ivas->hTcBuffer->nb_subframes = add( st_ivas->hTcBuffer->nb_subframes, ceil_fx16( tmp, sub( 15, sub( s2, s1 ) ) ) );
3818 230248 : move16();
3819 :
3820 230248 : nSlotsInLastSubframe = nSlotsAvailable % nMaxSlotsPerSubframe;
3821 230248 : move16();
3822 230248 : set16_fx( st_ivas->hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
3823 230248 : set16_fx( st_ivas->hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, st_ivas->hTcBuffer->nb_subframes );
3824 :
3825 230248 : if ( nSlotsInFirstSubframe > 0 )
3826 : {
3827 2950 : st_ivas->hTcBuffer->subframe_nbslots[0] = nSlotsInFirstSubframe;
3828 2950 : move16();
3829 : }
3830 :
3831 230248 : if ( nSlotsInLastSubframe > 0 )
3832 : {
3833 2955 : st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nSlotsInLastSubframe;
3834 2955 : move16();
3835 : }
3836 :
3837 230248 : st_ivas->hTcBuffer->slots_rendered = 0;
3838 230248 : move16();
3839 230248 : st_ivas->hTcBuffer->subframes_rendered = 0;
3840 230248 : move16();
3841 :
3842 230248 : return;
3843 : }
3844 : /*--------------------------------------------------------------------------*
3845 : * ivas_jbm_dec_get_tc_buffer_mode()
3846 : *
3847 : *
3848 : *--------------------------------------------------------------------------*/
3849 :
3850 4819 : TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode(
3851 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
3852 : )
3853 : {
3854 : TC_BUFFER_MODE buffer_mode;
3855 4819 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3856 4819 : move16();
3857 :
3858 4819 : SWITCH( st_ivas->renderer_type )
3859 : {
3860 : /* all renderers where we are done after TC decoding (might include DMX to mono/stereo */
3861 740 : case RENDERER_DISABLE:
3862 : case RENDERER_MCMASA_MONO_STEREO:
3863 : case RENDERER_OSBA_STEREO:
3864 : case RENDERER_MONO_DOWNMIX:
3865 740 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3866 740 : move16();
3867 740 : BREAK;
3868 3576 : case RENDERER_TD_PANNING:
3869 : case RENDERER_BINAURAL_OBJECTS_TD:
3870 : case RENDERER_BINAURAL_FASTCONV:
3871 : case RENDERER_BINAURAL_FASTCONV_ROOM:
3872 : case RENDERER_BINAURAL_PARAMETRIC:
3873 : case RENDERER_BINAURAL_PARAMETRIC_ROOM:
3874 : case RENDERER_STEREO_PARAMETRIC:
3875 : case RENDERER_DIRAC:
3876 : case RENDERER_PARAM_ISM:
3877 : case RENDERER_BINAURAL_MIXER_CONV:
3878 : case RENDERER_BINAURAL_MIXER_CONV_ROOM:
3879 : case RENDERER_OSBA_AMBI:
3880 : case RENDERER_OSBA_LS:
3881 3576 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3882 3576 : move16();
3883 3576 : BREAK;
3884 2 : case RENDERER_NON_DIEGETIC_DOWNMIX:
3885 2 : IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) )
3886 : {
3887 1 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3888 1 : move16();
3889 : }
3890 : ELSE
3891 : {
3892 1 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3893 1 : move16();
3894 : }
3895 2 : break;
3896 70 : case RENDERER_MC_PARAMMC:
3897 70 : IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
3898 : {
3899 2 : buffer_mode = TC_BUFFER_MODE_BUFFER; /* TCs are already the DMX to mono or stereo */
3900 2 : move16();
3901 : }
3902 : ELSE
3903 : {
3904 68 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3905 68 : move16();
3906 : }
3907 70 : BREAK;
3908 102 : case RENDERER_MC:
3909 102 : if ( NE_16( ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ), st_ivas->hDecoderConfig->nchan_out ) )
3910 : {
3911 95 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3912 95 : move16();
3913 : }
3914 102 : BREAK;
3915 329 : case RENDERER_SBA_LINEAR_ENC:
3916 329 : test();
3917 329 : test();
3918 329 : test();
3919 329 : test();
3920 329 : IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) && ( EQ_32( st_ivas->renderer_type, RENDERER_MC ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ) && GE_16( ( add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe ) ), ( add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe ) ) ) )
3921 : {
3922 0 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3923 0 : move16();
3924 : }
3925 : ELSE
3926 : {
3927 329 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3928 329 : move16();
3929 : }
3930 329 : BREAK;
3931 0 : case RENDERER_SBA_LINEAR_DEC:
3932 0 : test();
3933 0 : test();
3934 0 : IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
3935 : {
3936 0 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3937 0 : move16();
3938 : }
3939 : ELSE
3940 : {
3941 0 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3942 0 : move16();
3943 : }
3944 0 : BREAK;
3945 : }
3946 :
3947 4819 : return buffer_mode;
3948 : }
3949 :
3950 :
3951 : /*--------------------------------------------------------------------------*
3952 : * ivas_jbm_dec_copy_tc_no_tsm()
3953 : *
3954 : *
3955 : *--------------------------------------------------------------------------*/
3956 :
3957 380574 : void ivas_jbm_dec_copy_tc_no_tsm_fx(
3958 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle Q0 */
3959 : Word32 *tc_fx[], /* i : transport channels Q11 */
3960 : const Word16 output_frame /* i : output frame size Q0 */
3961 : )
3962 : {
3963 : Word16 Q_tc;
3964 : Word16 n_ch_full_copy;
3965 : Word16 n_ch_cldfb;
3966 : Word16 ch_idx;
3967 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
3968 :
3969 380574 : hTcBuffer = st_ivas->hTcBuffer;
3970 380574 : hTcBuffer->n_samples_buffered = output_frame;
3971 380574 : hTcBuffer->n_samples_available = hTcBuffer->n_samples_buffered;
3972 380574 : move16();
3973 380574 : move16();
3974 380574 : n_ch_full_copy = s_min( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
3975 380574 : n_ch_cldfb = sub( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
3976 :
3977 380574 : Q_tc = 11; /*tc buffer is at Q11*/
3978 380574 : move16();
3979 : /* copy full tcs*/
3980 380574 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3981 : {
3982 0 : FOR( ch_idx = 0; ch_idx < n_ch_full_copy; ch_idx++ )
3983 : {
3984 0 : Copy32( tc_fx[ch_idx], st_ivas->hTcBuffer->tc_fx[ch_idx], hTcBuffer->n_samples_buffered ); // keeping tc_fx in Q11
3985 : }
3986 : }
3987 380574 : ch_idx = 0;
3988 380574 : move16();
3989 :
3990 : /* CLDFB ana for ParamMC/ParamISM */
3991 380574 : IF( n_ch_cldfb > 0 )
3992 : {
3993 : Word32 *cldfb_real_buffer_fx;
3994 : Word32 *cldfb_imag_buffer_fx;
3995 : Word16 cldfb_ch, slot_idx, num_freq_bands;
3996 :
3997 12507 : cldfb_real_buffer_fx = NULL;
3998 12507 : cldfb_imag_buffer_fx = NULL;
3999 12507 : num_freq_bands = 0;
4000 12507 : move16();
4001 :
4002 12507 : IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) ISM_FORMAT ) )
4003 : {
4004 3747 : cldfb_real_buffer_fx = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx;
4005 3747 : cldfb_imag_buffer_fx = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx;
4006 3747 : num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands;
4007 3747 : move16();
4008 :
4009 3747 : ivas_ism_param_dec_tc_gain_ajust_fx( st_ivas, output_frame, output_frame / 2, tc_fx, &Q_tc );
4010 3747 : Scale_sig32( tc_fx[0], output_frame, sub( Q11, Q_tc ) ); /*keepeing tc_fx at Q11*/
4011 3747 : Scale_sig32( tc_fx[1], output_frame, sub( Q11, Q_tc ) ); /*keepeing tc_fx at Q11*/
4012 : }
4013 8760 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) MC_FORMAT ) )
4014 : {
4015 8760 : cldfb_real_buffer_fx = st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx;
4016 8760 : cldfb_imag_buffer_fx = st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx;
4017 8760 : num_freq_bands = st_ivas->hParamMC->num_freq_bands;
4018 8760 : move16();
4019 : }
4020 : /* CLDFB Analysis*/
4021 :
4022 37561 : FOR( cldfb_ch = 0; cldfb_ch < n_ch_cldfb; ( cldfb_ch++, ch_idx++ ) )
4023 : {
4024 425918 : FOR( slot_idx = 0; slot_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; slot_idx++ )
4025 : {
4026 400864 : Q_tc = 11;
4027 400864 : move16();
4028 400864 : cldfbAnalysis_ts_fx_fixed_q( &( tc_fx[ch_idx][num_freq_bands * slot_idx] ),
4029 400864 : &cldfb_real_buffer_fx[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
4030 400864 : &cldfb_imag_buffer_fx[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
4031 : num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch], &Q_tc );
4032 400864 : IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) MC_FORMAT ) )
4033 : {
4034 280960 : st_ivas->hParamMC->Cldfb_RealBuffer_tc_e = sub( 31, Q_tc );
4035 280960 : st_ivas->hParamMC->Cldfb_ImagBuffer_tc_e = sub( 31, Q_tc );
4036 280960 : move16();
4037 280960 : move16();
4038 : }
4039 : }
4040 : }
4041 : }
4042 380574 : hTcBuffer->n_samples_rendered = 0;
4043 380574 : move16();
4044 380574 : hTcBuffer->subframes_rendered = 0;
4045 380574 : move16();
4046 :
4047 380574 : return;
4048 : }
4049 :
4050 : /*--------------------------------------------------------------------------*
4051 : * ivas_jbm_dec_metadata_open()
4052 : *
4053 : * Open structure for metadata buffering in JBM
4054 : *--------------------------------------------------------------------------*/
4055 :
4056 44 : ivas_error ivas_jbm_dec_metadata_open(
4057 : Decoder_Struct *st_ivas )
4058 : {
4059 : JBM_METADATA_HANDLE hJbmMetadata;
4060 44 : IF( ( hJbmMetadata = (JBM_METADATA_HANDLE) malloc( sizeof( JBM_METADATA ) ) ) == NULL )
4061 : {
4062 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM metadata handle\n" ) );
4063 : }
4064 44 : hJbmMetadata->sf_write_idx = 0;
4065 44 : move16();
4066 44 : hJbmMetadata->sf_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_PARAM_SPATIAL_SUBFRAMES;
4067 44 : move16();
4068 :
4069 44 : hJbmMetadata->slot_write_idx = 0;
4070 44 : move16();
4071 44 : hJbmMetadata->slot_read_idx = 0;
4072 44 : move16();
4073 44 : hJbmMetadata->slot_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
4074 44 : move16();
4075 :
4076 44 : st_ivas->hJbmMetadata = hJbmMetadata;
4077 :
4078 44 : return IVAS_ERR_OK;
4079 : }
4080 :
4081 :
4082 : /*--------------------------------------------------------------------------*
4083 : * ivas_jbm_dec_copy_masa_meta_to_buffer()
4084 : *
4085 : * Copy decoded MASA metadata to a ring buffer
4086 : *--------------------------------------------------------------------------*/
4087 :
4088 5462 : static void ivas_jbm_dec_copy_masa_meta_to_buffer(
4089 : Decoder_Struct *st_ivas )
4090 : {
4091 : Word16 sf, dir, band;
4092 : JBM_METADATA_HANDLE hJbmMetadata;
4093 : MASA_DECODER_EXT_OUT_META *extOutMeta;
4094 : Word16 write_idx;
4095 :
4096 5462 : hJbmMetadata = st_ivas->hJbmMetadata;
4097 5462 : extOutMeta = st_ivas->hMasa->data.extOutMeta;
4098 :
4099 27310 : FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
4100 : {
4101 21848 : write_idx = ( hJbmMetadata->sf_write_idx + sf ) % hJbmMetadata->sf_md_buffer_length;
4102 21848 : move16();
4103 65544 : FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
4104 : {
4105 1092400 : FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
4106 : {
4107 1048704 : hJbmMetadata->directionIndexBuffer[dir][write_idx][band] = extOutMeta->directionIndex[dir][sf][band];
4108 1048704 : move16();
4109 1048704 : hJbmMetadata->directToTotalRatioBuffer[dir][write_idx][band] = extOutMeta->directToTotalRatio[dir][sf][band];
4110 1048704 : move16();
4111 1048704 : hJbmMetadata->spreadCoherenceBuffer[dir][write_idx][band] = extOutMeta->spreadCoherence[dir][sf][band];
4112 1048704 : move16();
4113 : }
4114 : }
4115 :
4116 546200 : FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
4117 : {
4118 524352 : hJbmMetadata->diffuseToTotalRatioBuffer[write_idx][band] = extOutMeta->diffuseToTotalRatio[sf][band];
4119 524352 : move16();
4120 524352 : hJbmMetadata->surroundCoherenceBuffer[write_idx][band] = extOutMeta->surroundCoherence[sf][band];
4121 524352 : move16();
4122 : }
4123 :
4124 21848 : hJbmMetadata->numberOfDirections[write_idx] = extOutMeta->descriptiveMeta.numberOfDirections;
4125 21848 : move16();
4126 : }
4127 :
4128 5462 : return;
4129 : }
4130 :
4131 :
4132 : /*--------------------------------------------------------------------------*
4133 : * ivas_jbm_masa_sf_to_slot_map()
4134 : *
4135 : * Map input MASA metadata subframes to slots in JBM processing
4136 : *--------------------------------------------------------------------------*/
4137 5462 : static void ivas_jbm_masa_sf_to_slot_map(
4138 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
4139 : const Word16 nCldfbTs /* i : number of CLDFB time slots */
4140 : )
4141 : {
4142 : Word16 sf_to_slot_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME];
4143 : Word16 num_slots_in_subfr;
4144 : JBM_METADATA_HANDLE hJbmMetadata;
4145 : Word16 slot_idx;
4146 : Word16 write_idx, sf_index;
4147 :
4148 : /* Set values */
4149 5462 : hJbmMetadata = st_ivas->hJbmMetadata;
4150 5462 : num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
4151 5462 : move16();
4152 :
4153 : /* Map input subframes to slots */
4154 5462 : ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, MAX_PARAM_SPATIAL_SUBFRAMES, sf_to_slot_map );
4155 :
4156 92874 : FOR( slot_idx = 0; slot_idx < nCldfbTs; slot_idx++ )
4157 : {
4158 87412 : write_idx = ( add( hJbmMetadata->slot_write_idx, slot_idx ) ) % hJbmMetadata->slot_md_buffer_length;
4159 87412 : move16();
4160 87412 : sf_index = ( add( hJbmMetadata->sf_write_idx, sf_to_slot_map[slot_idx] ) ) % hJbmMetadata->sf_md_buffer_length;
4161 87412 : move16();
4162 :
4163 87412 : hJbmMetadata->sf_to_slot_map[write_idx] = sf_index;
4164 87412 : move16();
4165 : }
4166 :
4167 5462 : hJbmMetadata->sf_write_idx = ( add( hJbmMetadata->sf_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) ) % hJbmMetadata->sf_md_buffer_length;
4168 5462 : move16();
4169 5462 : hJbmMetadata->slot_write_idx = ( add( hJbmMetadata->slot_write_idx, nCldfbTs ) ) % hJbmMetadata->slot_md_buffer_length;
4170 5462 : move16();
4171 :
4172 5462 : return;
4173 : }
4174 :
4175 : /*--------------------------------------------------------------------------*
4176 : * ivas_jbm_masa_sf_to_sf_map()
4177 : *
4178 : * Map input MASA metadata subframes to output subframes in JBM processing
4179 : *--------------------------------------------------------------------------*/
4180 :
4181 1308 : void ivas_jbm_masa_sf_to_sf_map(
4182 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
4183 : )
4184 : {
4185 : Word16 sf_to_sf_map[MAX_PARAM_SPATIAL_SUBFRAMES];
4186 : JBM_METADATA_HANDLE hJbmMetadata;
4187 : MASA_DECODER_EXT_OUT_META *extOutMeta;
4188 : Word16 slot_read_idx, sf_read_idx;
4189 : Word16 sf_idx;
4190 : Word16 dir, band;
4191 : UWord8 numberOfDirections;
4192 :
4193 : /* Set values */
4194 1308 : hJbmMetadata = st_ivas->hJbmMetadata;
4195 1308 : extOutMeta = st_ivas->hMasa->data.extOutMeta;
4196 :
4197 : /* Map slots to subframes */
4198 6540 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
4199 : {
4200 5232 : slot_read_idx = ( add( hJbmMetadata->slot_read_idx, 2 ) ) % hJbmMetadata->slot_md_buffer_length; /* Take the latter one of the middle slots of the output subframe */
4201 5232 : move16();
4202 5232 : sf_to_sf_map[sf_idx] = hJbmMetadata->sf_to_slot_map[slot_read_idx];
4203 5232 : move16();
4204 5232 : hJbmMetadata->slot_read_idx = ( add( hJbmMetadata->slot_read_idx, CLDFB_SLOTS_PER_SUBFRAME ) ) % hJbmMetadata->slot_md_buffer_length;
4205 5232 : move16();
4206 : }
4207 :
4208 : /* Copy mapped metadata to the EXT meta buffer for writing */
4209 6540 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
4210 : {
4211 5232 : sf_read_idx = sf_to_sf_map[sf_idx];
4212 5232 : move16();
4213 :
4214 15696 : FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
4215 : {
4216 261600 : FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
4217 : {
4218 251136 : extOutMeta->directionIndex[dir][sf_idx][band] = hJbmMetadata->directionIndexBuffer[dir][sf_read_idx][band];
4219 251136 : move16();
4220 251136 : extOutMeta->directToTotalRatio[dir][sf_idx][band] = hJbmMetadata->directToTotalRatioBuffer[dir][sf_read_idx][band];
4221 251136 : move16();
4222 251136 : extOutMeta->spreadCoherence[dir][sf_idx][band] = hJbmMetadata->spreadCoherenceBuffer[dir][sf_read_idx][band];
4223 251136 : move16();
4224 : }
4225 : }
4226 :
4227 130800 : FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
4228 : {
4229 125568 : extOutMeta->diffuseToTotalRatio[sf_idx][band] = hJbmMetadata->diffuseToTotalRatioBuffer[sf_read_idx][band];
4230 125568 : move16();
4231 125568 : extOutMeta->surroundCoherence[sf_idx][band] = hJbmMetadata->surroundCoherenceBuffer[sf_read_idx][band];
4232 125568 : move16();
4233 : }
4234 : }
4235 :
4236 : /* Determine the number of directions for the frame to be written */
4237 1308 : numberOfDirections = 0;
4238 1308 : move16();
4239 5594 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
4240 : {
4241 4524 : sf_read_idx = sf_to_sf_map[sf_idx];
4242 4524 : move16();
4243 :
4244 4524 : IF( hJbmMetadata->numberOfDirections[sf_read_idx] == 1 )
4245 : {
4246 238 : numberOfDirections = 1;
4247 238 : move16();
4248 238 : BREAK;
4249 : }
4250 : }
4251 :
4252 1308 : extOutMeta->descriptiveMeta.numberOfDirections = numberOfDirections;
4253 1308 : move16();
4254 :
4255 1308 : return;
4256 : }
|