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 : Word16 Q_p_output;
1041 7213 : Word16 min_norm = 31;
1042 7213 : move16();
1043 :
1044 18105 : FOR( ch = 0; ch < nchan_transport; ++ch )
1045 : {
1046 10892 : Word16 norm = L_norm_arr( p_output_fx[sba_ch_idx + ch], output_frame ); // Normalize per channel
1047 10892 : min_norm = s_min( norm, min_norm );
1048 : }
1049 :
1050 7213 : Q_p_output = s_max( 3, sub( min_norm, 1 ) );
1051 :
1052 7213 : Q_p_output = s_min( Q_p_output, 19 ); // to restrict Q-factor of p_ouptut to Q30
1053 18105 : FOR( ch = 0; ch < nchan_transport; ch++ )
1054 : {
1055 10892 : Scale_sig32( p_output_fx[sba_ch_idx + ch], output_frame, Q_p_output ); // Q_p_output + Q11
1056 : }
1057 7213 : Q_p_output = add( Q11, Q_p_output );
1058 7213 : hSpar->hMdDec->Q_mixer_mat = 31;
1059 7213 : move16();
1060 :
1061 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 ) );
1062 18105 : FOR( Word16 c = 0; c < nchan_transport; c++ )
1063 : {
1064 10892 : Scale_sig32( p_output_fx[sba_ch_idx + c], output_frame, Q11 ); // Q11
1065 : }
1066 : }
1067 22790 : ELSE IF( NE_32( st_ivas->renderer_type, RENDERER_DISABLE ) && st_ivas->sba_dirac_stereo_flag == 0 )
1068 : {
1069 18790 : Word16 size = add( st_ivas->hSpar->hMdDec->spar_md_cfg.nchan_transport, sba_ch_idx );
1070 18790 : if ( EQ_16( size, 3 ) )
1071 : {
1072 4370 : size = add( size, 1 );
1073 : }
1074 :
1075 86530 : FOR( i = sba_ch_idx; i < size; i++ )
1076 : {
1077 67740 : Scale_sig32( p_output_fx[i], output_frame, ( Q14 - Q11 ) ); // Q14
1078 : }
1079 :
1080 18790 : ivas_spar_dec_agc_pca_fx( st_ivas, &p_output_fx[sba_ch_idx], output_frame );
1081 : }
1082 :
1083 30003 : test();
1084 30003 : test();
1085 30003 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
1086 : {
1087 : /* loudness correction */
1088 7213 : ivas_dirac_dec_binaural_sba_gain_fx( &p_output_fx[sba_ch_idx], nchan_remapped, output_frame ); /*returns Q-1*/
1089 :
1090 18105 : FOR( i = 0; i < nchan_remapped; i++ )
1091 : {
1092 10892 : Scale_sig32( p_output_fx[i], output_frame, 1 ); // Q-1 -> Q
1093 : }
1094 : }
1095 22790 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
1096 : {
1097 1000 : ivas_mono_downmix_render_passive_fx( st_ivas, p_output_fx, output_frame );
1098 :
1099 1000 : Scale_sig32( p_output_fx[0], L_FRAME48k, Q11 - Q8 ); // Q11
1100 :
1101 : /* add W */
1102 2000 : FOR( n = 0; n < nchan_out; n++ )
1103 : {
1104 1000 : v_add_32( p_output_fx[n], p_output_fx[n + s_max( nchan_out, nchan_ism )], p_output_fx[n], output_frame );
1105 : }
1106 : }
1107 : }
1108 43957 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
1109 : {
1110 :
1111 : // st = (st_ivas->nSCE > 0) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0];
1112 43957 : IF( st_ivas->nSCE > 0 )
1113 : {
1114 9720 : st = st_ivas->hSCE[0]->hCoreCoder[0];
1115 : }
1116 : ELSE
1117 : {
1118 34237 : st = st_ivas->hCPE[0]->hCoreCoder[0];
1119 : }
1120 :
1121 43957 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
1122 : {
1123 : /* LFE channel decoder */
1124 24307 : ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] );
1125 :
1126 24307 : Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11
1127 24307 : IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, 0 ) ), IVAS_ERR_OK ) )
1128 : {
1129 0 : return error;
1130 : }
1131 : /* HP filtering */
1132 182047 : FOR( n = 0; n < st_ivas->nchan_transport; n++ )
1133 : {
1134 157740 : IF( NE_16( n, LFE_CHANNEL ) )
1135 : {
1136 133433 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
1137 : }
1138 : }
1139 :
1140 24307 : test();
1141 24307 : test();
1142 24307 : test();
1143 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 ) ) )
1144 : {
1145 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 ) ) )
1146 : {
1147 0 : ivas_mc2sba_fx( st_ivas->hTransSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX );
1148 : }
1149 : }
1150 :
1151 24307 : test();
1152 24307 : test();
1153 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 ) ) )
1154 : {
1155 3030 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
1156 : {
1157 3030 : s = Q16 - Q11;
1158 3030 : move16();
1159 3030 : s = sub( s, find_guarded_bits_fx( st_ivas->nchan_transport ) );
1160 21390 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i )
1161 : {
1162 18360 : Scale_sig32( p_output_fx[i], output_frame, s ); // Q(11+s)
1163 : }
1164 3030 : ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx );
1165 21390 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_transport ); ++i )
1166 : {
1167 18360 : Scale_sig32( p_output_fx[i], output_frame, negate( s ) ); // Q11
1168 : }
1169 : }
1170 0 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
1171 : {
1172 0 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, output_frame, st_ivas->hOutSetup.ambisonics_order, 0 );
1173 : }
1174 : }
1175 : }
1176 19650 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
1177 : {
1178 : /* LFE channel decoder */
1179 780 : ivas_lfe_dec_fx( st_ivas->hLFE, st, output_frame, st_ivas->bfi, p_output_fx[LFE_CHANNEL] );
1180 :
1181 780 : Scale_sig32( p_output_fx[LFE_CHANNEL], L_FRAME48k, Q11 - Q9 ); // Q11
1182 :
1183 780 : ivas_mc_paramupmix_dec_read_BS( st_ivas, st, st_ivas->hMCParamUpmix, &nb_bits_metadata[0] );
1184 :
1185 780 : IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1186 : {
1187 0 : return error;
1188 : }
1189 : /* HP filtering */
1190 7020 : FOR( n = 0; n < st_ivas->nchan_transport; n++ )
1191 : {
1192 6240 : IF( NE_16( n, LFE_CHANNEL ) )
1193 : {
1194 5460 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
1195 : }
1196 : }
1197 :
1198 : /* Rendering */
1199 780 : test();
1200 780 : test();
1201 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 ) ) )
1202 : {
1203 : /* Compensate loudness for not doing full upmix */
1204 50 : FOR( n = 4; n < 8; n++ )
1205 : {
1206 40 : Scale_sig32( p_output_fx[n], output_frame, 1 );
1207 : }
1208 :
1209 10 : test();
1210 10 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
1211 : {
1212 10 : s = Q16 - Q11;
1213 10 : move16();
1214 : Word16 nchan_transport;
1215 10 : nchan_transport = audioCfg2channels( IVAS_AUDIO_CONFIG_5_1_2 );
1216 10 : s = sub( s, find_guarded_bits_fx( nchan_transport ) );
1217 90 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i )
1218 : {
1219 80 : Scale_sig32( p_output_fx[i], output_frame, s );
1220 : }
1221 10 : ivas_ls_setup_conversion_fx( st_ivas, nchan_transport, output_frame, p_output_fx, p_output_fx );
1222 90 : FOR( i = 0; i < s_max( st_ivas->hDecoderConfig->nchan_out, nchan_transport ); ++i )
1223 : {
1224 80 : Scale_sig32( p_output_fx[i], output_frame, negate( s ) );
1225 : }
1226 : }
1227 : }
1228 : }
1229 18870 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
1230 : {
1231 : /* read Parametric MC parameters from the bitstream */
1232 8780 : ivas_param_mc_dec_read_BS_fx( ivas_total_brate, st, st_ivas->hParamMC, &nb_bits_metadata[0] );
1233 :
1234 8780 : IF( EQ_16( st_ivas->nCPE, 1 ) )
1235 : {
1236 8720 : Word16 q_output = 11;
1237 8720 : move16();
1238 :
1239 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 ) )
1240 : {
1241 0 : return error;
1242 : }
1243 8720 : IF( NE_16( q_output, Q11 ) )
1244 : {
1245 0 : Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
1246 0 : Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
1247 : }
1248 : }
1249 60 : ELSE IF( GT_16( st_ivas->nCPE, 1 ) )
1250 : {
1251 60 : IF( NE_32( ( error = ivas_mct_dec_fx( st_ivas, p_output_fx, output_frame, nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1252 : {
1253 0 : return error;
1254 : }
1255 : }
1256 :
1257 : /* HP filtering */
1258 26400 : FOR( n = 0; n < st_ivas->nchan_transport; n++ )
1259 : {
1260 17620 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
1261 : }
1262 :
1263 : /* Rendering */
1264 8780 : test();
1265 8780 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_MONO ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_STEREO ) )
1266 : {
1267 20 : ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, output_frame, p_output_fx, p_output_fx );
1268 : }
1269 : }
1270 10090 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
1271 : {
1272 10090 : IF( st_ivas->hOutSetup.separateChannelEnabled )
1273 : {
1274 550 : st = st_ivas->hCPE[0]->hCoreCoder[0]; /* Metadata is always with CPE in the case of separated channel */
1275 : }
1276 :
1277 : /* read McMASA parameters from the bitstream */
1278 :
1279 10090 : IF( NE_32( ( error = ivas_masa_decode_fx( st_ivas, st, &nb_bits_metadata[0] ) ), IVAS_ERR_OK ) )
1280 : {
1281 0 : return error;
1282 : }
1283 :
1284 10090 : IF( st_ivas->hOutSetup.separateChannelEnabled )
1285 : {
1286 : /* Decode the transport audio signals */
1287 550 : Word16 q_output = 11;
1288 550 : move16();
1289 :
1290 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 ) )
1291 : {
1292 0 : return error;
1293 : }
1294 550 : IF( NE_16( q_output, Q11 ) )
1295 : {
1296 0 : Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
1297 0 : Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
1298 : }
1299 :
1300 : /* Identify the index of the separated channel, always LFE_CHANNEL-1 here */
1301 550 : n = LFE_CHANNEL - 1;
1302 550 : move16();
1303 :
1304 : /* Decode the separated channel to output[n] to be combined with the synthesized channels */
1305 :
1306 550 : set32_fx( p_output_fx[n], 0, L_FRAME48k );
1307 :
1308 550 : IF( NE_32( ( error = ivas_sce_dec_fx( st_ivas, 0, &p_output_fx[n], output_frame, 0 ) ), IVAS_ERR_OK ) )
1309 : {
1310 0 : return error;
1311 : }
1312 550 : test();
1313 550 : test();
1314 550 : test();
1315 550 : test();
1316 550 : test();
1317 550 : test();
1318 550 : test();
1319 : /* Delay the separated channel to sync with CLDFB delay of the DirAC synthesis, and synthesize the LFE signal. */
1320 550 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
1321 : EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
1322 : 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 ) )
1323 : {
1324 150 : ivas_lfe_synth_with_filters_fx( st_ivas->hMasa->hMasaLfeSynth, p_output_fx, output_frame, n, LFE_CHANNEL );
1325 : }
1326 400 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 )
1327 : {
1328 : /* Delay the separated channel to sync with the DirAC rendering */
1329 0 : delay_signal32_fx( p_output_fx[n], output_frame, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_fx, st_ivas->hMasa->hMasaLfeSynth->delayBuffer_syncDirAC_size );
1330 : }
1331 : }
1332 : ELSE
1333 : {
1334 9540 : Word16 q_output = 11;
1335 9540 : move16();
1336 9540 : IF( EQ_16( st_ivas->nSCE, 1 ) )
1337 : {
1338 9170 : set32_fx( p_output_fx[0], 0, L_FRAME48k );
1339 :
1340 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 ) )
1341 : {
1342 0 : return error;
1343 : }
1344 : }
1345 370 : ELSE IF( EQ_16( st_ivas->nCPE, 1 ) )
1346 : {
1347 :
1348 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 ) )
1349 : {
1350 0 : return error;
1351 : }
1352 370 : IF( NE_16( q_output, Q11 ) )
1353 : {
1354 0 : Scale_sig32( p_output_fx[0], output_frame, sub( Q11, q_output ) ); // Q11
1355 0 : Scale_sig32( p_output_fx[1], output_frame, sub( Q11, q_output ) ); // Q11
1356 : }
1357 : }
1358 : }
1359 :
1360 10090 : IF( st_ivas->sba_dirac_stereo_flag != 0 ) /* use the flag to trigger the DFT upmix */
1361 : {
1362 : Word16 q;
1363 1180 : hCPE = st_ivas->hCPE[0];
1364 1180 : hSCE = st_ivas->hSCE[0];
1365 1180 : s = 0;
1366 1180 : move16();
1367 3540 : FOR( i = 0; i < 2; i++ )
1368 : {
1369 2360 : s = s_min( s, L_norm_arr( p_output_fx[i], L_FRAME48k ) - 11 /* Guard bits */ );
1370 : }
1371 3540 : FOR( i = 0; i < 2; i++ )
1372 : {
1373 2360 : Scale_sig32( p_output_fx[i], L_FRAME48k, s ); // Q(11+s)
1374 : }
1375 :
1376 1180 : hCPE->hStereoDft->q_dft = add( Q11, s );
1377 1180 : move16();
1378 1180 : IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
1379 : {
1380 1180 : hCPE->hStereoDft->q_smoothed_nrg = Q6; // hCPE->hStereoDft->q_dft;
1381 1180 : hCPE->hStereoDft->q_ap_delay_mem_fx = hCPE->hStereoDft->q_dft;
1382 :
1383 1180 : move16();
1384 1180 : move16();
1385 : }
1386 :
1387 1180 : q = hCPE->hStereoDft->q_dft;
1388 1180 : move16();
1389 :
1390 1180 : scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) );
1391 3540 : FOR( i = 0; i < CPE_CHANNELS; ++i )
1392 : {
1393 2360 : scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
1394 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
1395 : }
1396 :
1397 1180 : IF( hCPE->hCoreCoder[0] != NULL )
1398 : {
1399 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
1400 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
1401 1180 : hCPE->hCoreCoder[0]->hHQ_core->q_old_outLB_fx = q;
1402 1180 : move16();
1403 : }
1404 1180 : IF( hCPE->hStereoDft != NULL )
1405 : {
1406 1180 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA( 16000, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
1407 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
1408 1180 : hCPE->hStereoDft->q_ap_fade_mem_fx = hCPE->hStereoDft->q_dft;
1409 1180 : move16();
1410 : }
1411 1180 : IF( st_ivas->hSpar != NULL )
1412 : {
1413 0 : st_ivas->hSpar->hMdDec->Q_mixer_mat = 30;
1414 0 : move16();
1415 : }
1416 :
1417 1180 : IF( hSCE != NULL )
1418 : {
1419 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
1420 1180 : hSCE->q_save_hb_synth_fx = hCPE->hStereoDft->q_dft;
1421 1180 : move16();
1422 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
1423 1180 : hSCE->q_save_synth_fx = hCPE->hStereoDft->q_dft;
1424 1180 : move16();
1425 : }
1426 3540 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
1427 : {
1428 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
1429 2360 : hCPE->q_output_mem_fx[ii] = hCPE->hStereoDft->q_dft;
1430 2360 : move16();
1431 : }
1432 3540 : FOR( i = 0; i < CPE_CHANNELS; i++ )
1433 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
1434 1180 : ivas_sba_dirac_stereo_dec_fx( st_ivas, p_output_fx, output_frame, 1 );
1435 3540 : FOR( i = 0; i < 2; i++ )
1436 : {
1437 2360 : Scale_sig32( p_output_fx[i], L_FRAME48k, negate( s ) );
1438 : }
1439 3540 : FOR( i = 0; i < CPE_CHANNELS; i++ )
1440 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
1441 :
1442 1180 : scale_sig32( hCPE->input_mem_BPF_fx[0], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) );
1443 3540 : FOR( i = 0; i < CPE_CHANNELS; ++i )
1444 : {
1445 2360 : scale_sig32( hCPE->input_mem_LB_fx[i], STEREO_DFT32MS_OVL_16k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
1446 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
1447 : }
1448 :
1449 1180 : IF( hCPE->hCoreCoder[0] != NULL )
1450 : {
1451 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
1452 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
1453 : }
1454 1180 : IF( hCPE->hStereoDft != NULL )
1455 : {
1456 1180 : scale_sig32( hCPE->hStereoDft->buff_LBTCX_mem_fx, NS2SA_FX2( 16000, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
1457 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
1458 1180 : hCPE->hStereoDft->q_ap_fade_mem_fx = Q11;
1459 1180 : move16();
1460 : }
1461 1180 : IF( st_ivas->hSpar != NULL )
1462 : {
1463 0 : FOR( ii = 0; ii < CPE_CHANNELS; ii++ )
1464 : {
1465 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
1466 0 : hCPE->q_output_mem_fx[ii] = Q11;
1467 0 : move16();
1468 : }
1469 : }
1470 : }
1471 :
1472 : /* HP filtering */
1473 22830 : FOR( n = 0; n < getNumChanSynthesis( st_ivas ); n++ )
1474 : {
1475 12740 : hp20_fx_32( p_output_fx[n], output_frame, st_ivas->mem_hp20_out_fx[n], output_Fs );
1476 : }
1477 :
1478 10090 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MCMASA_MONO_STEREO ) )
1479 : {
1480 500 : ivas_mono_stereo_downmix_mcmasa_fx( st_ivas, p_output_fx, output_frame );
1481 : }
1482 : }
1483 : }
1484 :
1485 : /*----------------------------------------------------------------*
1486 : * Write IVAS transport channels
1487 : *----------------------------------------------------------------*/
1488 :
1489 396879 : IF( EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 1 ) )
1490 : {
1491 19405 : ivas_syn_output_f_fx( p_output_fx, output_frame, st_ivas->hTcBuffer->nchan_transport_jbm, data_fx );
1492 : }
1493 : ELSE
1494 : {
1495 : /* directly copy to tc buffers */
1496 : /*note : the q of cldfb buffers (imag/real) are needed to be Q_p_output - 5 here 6 is taken for that*/
1497 377474 : ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, output_frame );
1498 : }
1499 :
1500 : /*----------------------------------------------------------------*
1501 : * Common updates
1502 : *----------------------------------------------------------------*/
1503 :
1504 396879 : IF( !st_ivas->bfi ) /* do not update if first frame(s) are lost or NO_DATA */
1505 : {
1506 388314 : st_ivas->hDecoderConfig->last_ivas_total_brate = ivas_total_brate;
1507 388314 : move32();
1508 388314 : IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) )
1509 : {
1510 18751 : st_ivas->last_active_ivas_total_brate = st_ivas->last_active_ivas_total_brate;
1511 18751 : move32();
1512 : }
1513 : ELSE
1514 : {
1515 369563 : st_ivas->last_active_ivas_total_brate = ivas_total_brate;
1516 369563 : move32();
1517 : }
1518 : }
1519 :
1520 396879 : test();
1521 396879 : test();
1522 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 */
1523 : {
1524 111784 : st_ivas->ini_frame = add( st_ivas->ini_frame, 1 );
1525 111784 : move16();
1526 : }
1527 :
1528 396879 : test();
1529 396879 : test();
1530 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 */
1531 : {
1532 110873 : st_ivas->ini_active_frame = add( st_ivas->ini_active_frame, 1 );
1533 110873 : move16();
1534 : }
1535 :
1536 396879 : st_ivas->last_ivas_format = st_ivas->ivas_format;
1537 396879 : move32();
1538 396879 : pop_wmops();
1539 :
1540 396879 : return IVAS_ERR_OK;
1541 : }
1542 :
1543 :
1544 : /*--------------------------------------------------------------------------*
1545 : * ivas_jbm_dec_feed_tc_to_renderer()
1546 : *
1547 : * Feed decoded transport channels and metadata to the IVAS JBM renderer routine
1548 : *--------------------------------------------------------------------------*/
1549 399979 : void ivas_jbm_dec_feed_tc_to_renderer_fx(
1550 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1551 : const Word16 nSamplesForRendering, /* i : number of TC samples available for rendering */
1552 : Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call*/
1553 : Word32 *data_fx /* i : transport channels Q11*/
1554 : )
1555 : {
1556 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 */
1557 : Word32 *p_data_f_fx[MAX_CLDFB_DIGEST_CHANNELS];
1558 : Word16 i;
1559 :
1560 3599811 : FOR( i = 0; i < MAX_CLDFB_DIGEST_CHANNELS; i++ )
1561 : {
1562 3199832 : set_zero_fx( data_f_fx[i], MAX_JBM_L_FRAME48k );
1563 : }
1564 399979 : if ( st_ivas->hTcBuffer )
1565 : {
1566 399979 : st_ivas->hTcBuffer->q_tc_fx = 11;
1567 399979 : move16();
1568 : }
1569 : Word16 n, n_render_timeslots;
1570 :
1571 399979 : push_wmops( "ivas_jbm_dec_feed_tc_to_rendererer" );
1572 3599811 : FOR( n = 0; n < MAX_CLDFB_DIGEST_CHANNELS; n++ )
1573 : {
1574 3199832 : p_data_f_fx[n] = &data_f_fx[n][0];
1575 : }
1576 :
1577 399979 : IF( st_ivas->hDecoderConfig->Opt_tsm )
1578 : {
1579 19405 : ivas_jbm_dec_copy_tc( st_ivas, nSamplesForRendering, nSamplesResidual, data_fx, p_data_f_fx, 11 );
1580 : }
1581 : ELSE
1582 : {
1583 380574 : *nSamplesResidual = 0;
1584 380574 : move16();
1585 : }
1586 399979 : n_render_timeslots = idiv1616( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity );
1587 :
1588 399979 : test();
1589 399979 : IF( EQ_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
1590 : {
1591 127492 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
1592 :
1593 127492 : test();
1594 127492 : test();
1595 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 ) )
1596 : {
1597 5462 : ivas_jbm_masa_sf_to_slot_map( st_ivas, n_render_timeslots );
1598 : }
1599 : }
1600 272487 : ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) )
1601 : {
1602 0 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
1603 : }
1604 272487 : ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
1605 : {
1606 : /* Rendering */
1607 68224 : IF( EQ_16( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1608 : {
1609 13208 : test();
1610 13208 : test();
1611 13208 : test();
1612 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 ) )
1613 : {
1614 7955 : ivas_dirac_dec_set_md_map_fx( st_ivas, n_render_timeslots );
1615 :
1616 7955 : ivas_param_ism_params_to_masa_param_mapping_fx( st_ivas );
1617 : }
1618 5253 : ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
1619 : {
1620 :
1621 5253 : ivas_param_ism_dec_digest_tc_fx( st_ivas, n_render_timeslots, p_data_f_fx, Q11 );
1622 : }
1623 : }
1624 : ELSE /* ISM_MODE_DISC */
1625 : {
1626 55016 : ivas_ism_dec_digest_tc_fx( st_ivas );
1627 : }
1628 : }
1629 204263 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
1630 : {
1631 137306 : IF( st_ivas->hSCE[0] )
1632 : {
1633 44077 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1634 44077 : IF( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1635 : {
1636 4043 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1637 : }
1638 44077 : scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
1639 44077 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1640 : }
1641 137306 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1642 : }
1643 66957 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1644 : {
1645 :
1646 26213 : IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
1647 : {
1648 12100 : ivas_ism_dec_digest_tc_fx( st_ivas );
1649 :
1650 12100 : test();
1651 12100 : test();
1652 12100 : test();
1653 12100 : test();
1654 : /* delay the objects here for all renderers where it is needed */
1655 12100 : IF(
1656 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
1657 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
1658 : EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
1659 : EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
1660 : EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1661 : {
1662 47020 : FOR( n = 0; n < st_ivas->nchan_ism; n++ )
1663 : {
1664 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 );
1665 : }
1666 : }
1667 :
1668 12100 : IF( !st_ivas->sba_dirac_stereo_flag )
1669 : {
1670 10890 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
1671 : {
1672 : Word16 temp, temp_e;
1673 4680 : temp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size, &temp_e );
1674 4680 : n_render_timeslots = extract_l( L_shr( L_mult0( n_render_timeslots, temp ), sub( 15, temp_e ) ) );
1675 : }
1676 :
1677 10890 : IF( st_ivas->hSCE[0] )
1678 : {
1679 0 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1680 0 : if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1681 : {
1682 0 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1683 : }
1684 0 : scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
1685 0 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1686 : }
1687 10890 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1688 : }
1689 : }
1690 : ELSE
1691 : {
1692 14113 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
1693 :
1694 14113 : IF( st_ivas->hSCE[0] )
1695 : {
1696 5894 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1697 5894 : if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1698 : {
1699 85 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1700 : }
1701 5894 : scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
1702 5894 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1703 : }
1704 14113 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1705 : }
1706 : }
1707 40744 : ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
1708 : {
1709 4840 : test();
1710 4840 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1711 : {
1712 108 : n_render_timeslots = i_mult( n_render_timeslots, idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ) );
1713 : }
1714 :
1715 4840 : IF( st_ivas->hSCE[0] )
1716 : {
1717 4840 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1718 4840 : if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1719 : {
1720 448 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1721 : }
1722 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)
1723 4840 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1724 4840 : move16();
1725 : }
1726 4840 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1727 :
1728 4840 : IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1729 : {
1730 1783 : ivas_ism_dec_digest_tc_fx( st_ivas );
1731 : }
1732 : }
1733 35904 : ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
1734 : {
1735 35904 : IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
1736 : {
1737 18974 : ivas_jbm_dec_td_renderers_adapt_subframes( st_ivas );
1738 : }
1739 16930 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
1740 : {
1741 770 : ivas_mc_paramupmix_dec_digest_tc( st_ivas, (UWord8) n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1742 : }
1743 16160 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
1744 : {
1745 :
1746 8760 : Word16 nchan_transport = st_ivas->nchan_transport;
1747 8760 : move16();
1748 8760 : Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
1749 : Word16 nchan_out_cov;
1750 8760 : test();
1751 8760 : test();
1752 8760 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
1753 : {
1754 6910 : nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
1755 : }
1756 1850 : ELSE IF( EQ_16( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
1757 : {
1758 340 : nchan_out_cov = nchan_out_transport;
1759 340 : move16();
1760 : }
1761 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 ) )
1762 : {
1763 150 : nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
1764 : }
1765 : ELSE
1766 : {
1767 1360 : nchan_out_cov = nchan_out_transport;
1768 1360 : move16();
1769 : }
1770 :
1771 8760 : scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, -1 ); // Q(31-1)
1772 8760 : st_ivas->hParamMC->proto_matrix_int_e = 1;
1773 8760 : move16();
1774 :
1775 8760 : ivas_param_mc_dec_digest_tc_fx( st_ivas, (UWord8) n_render_timeslots, (Word32 **) p_data_f_fx, Q11 );
1776 :
1777 8760 : scale_sig32( st_ivas->hParamMC->proto_matrix_int_fx, st_ivas->hParamMC->proto_matrix_int_len, 1 ); // Q(31-1+1)
1778 :
1779 : Word16 shift;
1780 121880 : FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ )
1781 : {
1782 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 ) );
1783 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)
1784 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 );
1785 113120 : move16();
1786 :
1787 113120 : shift = getScaleFactor32( st_ivas->hParamMC->h_output_synthesis_cov_state.cy_old_fx[param_band_idx], nchan_out_cov * nchan_out_cov );
1788 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)
1789 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 );
1790 113120 : move16();
1791 : }
1792 : }
1793 7400 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
1794 : {
1795 7400 : IF( st_ivas->hSCE[0] )
1796 : {
1797 7190 : Word16 shift = getScaleFactor32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN );
1798 7190 : if ( LT_16( sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift ), 4 ) )
1799 : {
1800 975 : shift = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, 4 );
1801 : }
1802 7190 : scale_sig32( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevel, FFTCLDFBLEN, shift ); // Q(31-cngNoiseLevelExp+shift)
1803 7190 : st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp = sub( st_ivas->hSCE[0]->hCoreCoder[0]->hFdCngDec->hFdCngCom->cngNoiseLevelExp, shift );
1804 7190 : move16();
1805 : }
1806 7400 : ivas_sba_dec_digest_tc_fx( st_ivas, n_render_timeslots, st_ivas->hTcBuffer->n_samples_available );
1807 : }
1808 : }
1809 :
1810 399979 : pop_wmops();
1811 399979 : return;
1812 : }
1813 :
1814 : /*--------------------------------------------------------------------------*
1815 : * ivas_dec_render()
1816 : *
1817 : * Principal IVAS JBM rendering routine
1818 : *--------------------------------------------------------------------------*/
1819 411989 : ivas_error ivas_jbm_dec_render_fx(
1820 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
1821 : const UWord16 nSamplesAsked, /* i : number of samples wanted */
1822 : UWord16 *nSamplesRendered, /* o : number of samples rendered */
1823 : UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the rendering pipeline */
1824 : Word16 *data /* o : output synthesis signal Q0*/
1825 : )
1826 : {
1827 : Word16 n, nchan_out;
1828 : Word16 nchan_transport;
1829 : Word16 nchan_remapped;
1830 : Word32 output_Fs;
1831 : AUDIO_CONFIG output_config;
1832 : Word16 nSamplesAskedLocal;
1833 : ivas_error error;
1834 : Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS];
1835 : Word32 *p_tc_fx[MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS];
1836 : Word16 subframe_len, gd_bits, exp, nchan_in, i, j, ch;
1837 411989 : const Word16 output_q_factor = Q11;
1838 411989 : move16();
1839 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
1840 :
1841 411989 : push_wmops( "ivas_dec_render" );
1842 : /*----------------------------------------------------------------*
1843 : * Initialization of local vars after struct has been set
1844 : *----------------------------------------------------------------*/
1845 :
1846 411989 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
1847 411989 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
1848 411989 : move32();
1849 411989 : nchan_out = st_ivas->hDecoderConfig->nchan_out;
1850 411989 : move16();
1851 411989 : nchan_transport = st_ivas->hTcBuffer->nchan_transport_jbm;
1852 411989 : move16();
1853 411989 : output_config = st_ivas->hDecoderConfig->output_config;
1854 411989 : move32();
1855 411989 : nSamplesAskedLocal = add( nSamplesAsked, st_ivas->hTcBuffer->n_samples_discard );
1856 411989 : move16();
1857 :
1858 8651769 : FOR( n = 0; n < MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
1859 : {
1860 8239780 : p_output_fx[n] = st_ivas->p_output_fx[n];
1861 : }
1862 411989 : IF( !st_ivas->hDecoderConfig->Opt_tsm )
1863 : {
1864 1666768 : FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ )
1865 : {
1866 1286194 : p_tc_fx[n] = p_output_fx[n];
1867 : }
1868 :
1869 6469758 : FOR( n = 0; n < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; n++ )
1870 : {
1871 6089184 : st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n];
1872 : }
1873 : }
1874 : ELSE
1875 : {
1876 127917 : FOR( n = 0; n < st_ivas->hTcBuffer->nchan_buffer_full; n++ )
1877 : {
1878 96502 : p_tc_fx[n] = &st_ivas->hTcBuffer->tc_fx[n][st_ivas->hTcBuffer->n_samples_rendered];
1879 : }
1880 : }
1881 :
1882 411989 : st_ivas->hTcBuffer->no_channels = st_ivas->hTcBuffer->nchan_buffer_full;
1883 411989 : move16();
1884 : /*----------------------------------------------------------------*
1885 : * Update combined orientation access index
1886 : *----------------------------------------------------------------*/
1887 :
1888 411989 : IF( st_ivas->hCombinedOrientationData != NULL )
1889 : {
1890 : /* take the discard samples into account here to make sure head rotation stays on the correct 5ms grid */
1891 69350 : st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start = sub( st_ivas->hCombinedOrientationData->cur_subframe_samples_rendered_start, st_ivas->hTcBuffer->n_samples_discard );
1892 69350 : move16();
1893 :
1894 69350 : ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
1895 : }
1896 :
1897 : /*----------------------------------------------------------------*
1898 : * Rendering
1899 : *----------------------------------------------------------------*/
1900 411989 : test();
1901 411989 : IF( EQ_32( st_ivas->ivas_format, UNDEFINED_FORMAT ) )
1902 : {
1903 0 : assert( 0 );
1904 : }
1905 411989 : ELSE IF( EQ_32( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
1906 : {
1907 : Word16 slot_size, tmp, e;
1908 :
1909 128726 : slot_size = st_ivas->hTcBuffer->n_samples_granularity;
1910 128726 : move16();
1911 :
1912 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
1913 128726 : tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e );
1914 128726 : tmp = shr( tmp, sub( 15, e ) );
1915 :
1916 128726 : ivas_jbm_dec_tc_buffer_playout_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, p_output_fx );
1917 : }
1918 283263 : ELSE IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) )
1919 : {
1920 : /* Rendering */
1921 0 : IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
1922 : {
1923 0 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
1924 0 : move16();
1925 :
1926 0 : ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx );
1927 : }
1928 : }
1929 283263 : ELSE IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
1930 : {
1931 : /* Rendering */
1932 70910 : IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
1933 : {
1934 15233 : test();
1935 15233 : test();
1936 15233 : test();
1937 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 ) )
1938 : {
1939 8674 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, st_ivas->nchan_transport, p_output_fx );
1940 : }
1941 6559 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
1942 : {
1943 0 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
1944 0 : move16();
1945 0 : ivas_apply_non_diegetic_panning_fx( p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered );
1946 : }
1947 6559 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_PARAM_ISM ) || EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
1948 : {
1949 6559 : ivas_param_ism_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx );
1950 :
1951 6559 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
1952 : {
1953 : /* Convert CICP19 -> Ambisonics */
1954 4516 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
1955 : }
1956 : }
1957 : }
1958 : ELSE /* ISM_MODE_DISC */
1959 : {
1960 55677 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
1961 55677 : move16();
1962 :
1963 55677 : test();
1964 55677 : test();
1965 : /* Loudspeaker or Ambisonics rendering */
1966 55677 : IF( EQ_32( st_ivas->renderer_type, RENDERER_TD_PANNING ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
1967 : {
1968 : /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */
1969 20811 : ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered );
1970 : }
1971 34866 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
1972 : {
1973 1500 : ivas_apply_non_diegetic_panning_fx( p_output_fx, st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, *nSamplesRendered );
1974 : }
1975 33366 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
1976 : {
1977 : /* Convert to Ambisonics; used also for ISM->HOA3->binaural rendering */
1978 20780 : FOR( i = 0; i < st_ivas->nchan_transport; i++ )
1979 : {
1980 270028 : FOR( j = 0; j < 16; j++ )
1981 : {
1982 254144 : st_ivas->hIsmRendererData->gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q30 -> Q29
1983 254144 : move32();
1984 254144 : st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shr( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q30 -> Q29
1985 254144 : move32();
1986 : }
1987 : }
1988 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 );
1989 4896 : Word16 sba_num_chans = imult1616( add( st_ivas->hIntSetup.ambisonics_order, 1 ), add( st_ivas->hIntSetup.ambisonics_order, 1 ) );
1990 65032 : FOR( j = 0; j < sba_num_chans; j++ )
1991 : {
1992 60136 : scale_sig32( p_output_fx[j], *nSamplesRendered, sub( Q11, sub( add( output_q_factor, 29 ), 31 ) ) ); // Q11
1993 : }
1994 :
1995 :
1996 20780 : FOR( i = 0; i < st_ivas->nchan_transport; i++ )
1997 : {
1998 270028 : FOR( j = 0; j < 16; j++ )
1999 : {
2000 254144 : st_ivas->hIsmRendererData->gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->gains_fx[i][j], 1 ); // Q29 -> Q30
2001 254144 : move32();
2002 254144 : st_ivas->hIsmRendererData->prev_gains_fx[i][j] = L_shl( st_ivas->hIsmRendererData->prev_gains_fx[i][j], 1 ); // Q29 -> Q30
2003 254144 : move32();
2004 : }
2005 : }
2006 : }
2007 :
2008 : /* Binaural rendering */
2009 55677 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
2010 : {
2011 28470 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
2012 : {
2013 0 : return error;
2014 : }
2015 : }
2016 27207 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2017 : {
2018 10711 : st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
2019 10711 : subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity );
2020 10711 : gd_bits = find_guarded_bits_fx( subframe_len );
2021 10711 : exp = 13;
2022 10711 : move16();
2023 10711 : nchan_in = 12;
2024 10711 : move16();
2025 10711 : nchan_out = 2;
2026 10711 : move16();
2027 10711 : exp = sub( exp, gd_bits );
2028 10711 : *st_ivas->hCrendWrapper->p_io_qfactor = exp;
2029 10711 : move16();
2030 139243 : FOR( i = 0; i < nchan_in; i++ )
2031 : {
2032 128532 : scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11
2033 : }
2034 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 ) )
2035 : {
2036 0 : return error;
2037 : }
2038 32133 : FOR( i = 0; i < nchan_out; i++ )
2039 : {
2040 21422 : scale_sig32( p_output_fx[i], *nSamplesRendered, sub( 11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11
2041 : }
2042 : }
2043 : }
2044 : }
2045 212353 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
2046 : {
2047 143066 : nchan_remapped = nchan_transport;
2048 143066 : move16();
2049 143066 : test();
2050 143066 : test();
2051 : /* Loudspeakers, Ambisonics or Binaural rendering */
2052 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 ) )
2053 : {
2054 45229 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2055 : }
2056 97837 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) )
2057 : {
2058 15964 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) )
2059 : {
2060 0 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
2061 0 : move16();
2062 0 : FOR( n = 0; n < nchan_remapped; n++ )
2063 : {
2064 0 : Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered );
2065 : }
2066 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 ) )
2067 : {
2068 0 : return error;
2069 : }
2070 : }
2071 15964 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
2072 : {
2073 15964 : ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx );
2074 : }
2075 : }
2076 : ELSE
2077 : {
2078 81873 : IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2079 : {
2080 0 : return error;
2081 : }
2082 : }
2083 : }
2084 69287 : ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
2085 : {
2086 5407 : nchan_remapped = st_ivas->nchan_transport;
2087 5407 : move16();
2088 5407 : test();
2089 5407 : test();
2090 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 ) )
2091 : {
2092 2699 : test();
2093 2699 : IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) && EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) )
2094 : {
2095 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 ) )
2096 : {
2097 0 : return error;
2098 : }
2099 : }
2100 : ELSE
2101 : {
2102 2577 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2103 : }
2104 : }
2105 2708 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_DIRAC ) )
2106 : {
2107 2708 : ivas_omasa_dirac_rend_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2108 : }
2109 : }
2110 63880 : ELSE IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2111 : {
2112 27036 : nchan_remapped = nchan_transport;
2113 27036 : move16();
2114 : /* Loudspeakers, Ambisonics or Binaural rendering */
2115 27036 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
2116 : {
2117 12100 : test();
2118 12100 : test();
2119 12100 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
2120 : {
2121 : SPAR_DEC_HANDLE hSpar;
2122 4680 : hSpar = st_ivas->hSpar;
2123 4680 : hSpar->hMdDec->Q_mixer_mat = 30;
2124 4680 : move16();
2125 :
2126 4680 : IF( NE_32( ( error = ivas_osba_dirac_td_binaural_jbm_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2127 : {
2128 0 : return error;
2129 : }
2130 : }
2131 7420 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) )
2132 : {
2133 1210 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
2134 1210 : move16();
2135 :
2136 1210 : test();
2137 : /* shift SBA channels to avoid overwrite by ISM upmix in 1 object case and non-TSM unified channel memory*/
2138 1210 : IF( EQ_16( st_ivas->nchan_ism, 1 ) && EQ_16( st_ivas->hDecoderConfig->Opt_tsm, 0 ) )
2139 : {
2140 0 : Copy32( p_tc_fx[2], p_output_fx[3], *nSamplesRendered );
2141 0 : Copy32( p_tc_fx[1], p_output_fx[2], *nSamplesRendered );
2142 0 : p_tc_fx[1] = p_output_fx[2];
2143 0 : p_tc_fx[2] = p_output_fx[3];
2144 : }
2145 :
2146 : /* render objects */
2147 1210 : ivas_ism_render_sf_fx( st_ivas, p_output_fx, *nSamplesRendered );
2148 :
2149 : /* add already rendered SBA part */
2150 3630 : FOR( n = 0; n < nchan_out; n++ )
2151 : {
2152 2420 : v_add_fixed_no_hdrm( p_output_fx[n], p_tc_fx[n + st_ivas->nchan_ism], p_output_fx[n], *nSamplesRendered );
2153 : }
2154 : }
2155 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 ) )
2156 : {
2157 4000 : IF( NE_32( ( error = ivas_osba_render_sf_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2158 : {
2159 0 : return error;
2160 : }
2161 : }
2162 2210 : ELSE IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) ) /*EXT output = individual objects + HOA3*/
2163 : {
2164 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 ) )
2165 : {
2166 0 : return error;
2167 : }
2168 :
2169 8050 : FOR( n = 0; n < st_ivas->nchan_ism; n++ )
2170 : {
2171 5840 : Copy32( st_ivas->hTcBuffer->tc_fx[n] + st_ivas->hTcBuffer->n_samples_rendered, p_output_fx[n], *nSamplesRendered );
2172 : }
2173 : }
2174 : ELSE
2175 : {
2176 0 : IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2177 : {
2178 0 : return error;
2179 : }
2180 : }
2181 : }
2182 14936 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
2183 : {
2184 7656 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2185 : }
2186 : ELSE
2187 : {
2188 7280 : IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx ) ), IVAS_ERR_OK ) )
2189 : {
2190 0 : return error;
2191 : }
2192 :
2193 7280 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
2194 : {
2195 13430 : FOR( n = st_ivas->hIntSetup.nchan_out_woLFE - 1; n >= 0; n-- )
2196 : {
2197 12640 : Copy32( p_output_fx[n], p_output_fx[n + st_ivas->nchan_ism], *nSamplesRendered );
2198 : }
2199 3950 : FOR( n = 0; n < st_ivas->nchan_ism; n++ )
2200 : {
2201 3160 : set32_fx( p_output_fx[n], 0, *nSamplesRendered );
2202 : }
2203 : }
2204 : }
2205 : }
2206 36844 : ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
2207 : {
2208 36844 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
2209 : {
2210 19914 : Word16 crendInPlaceRotation = FALSE;
2211 19914 : move16();
2212 19914 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
2213 19914 : move16();
2214 :
2215 19914 : test();
2216 19914 : test();
2217 19914 : test();
2218 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 ) ) )
2219 : {
2220 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 ) ) )
2221 : {
2222 150 : crendInPlaceRotation = TRUE;
2223 150 : move16();
2224 :
2225 150 : ivas_mc2sba_fx( st_ivas->hTransSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hIntSetup.ambisonics_order, GAIN_LFE_FX );
2226 : }
2227 : }
2228 :
2229 19914 : test();
2230 : /* Rendering */
2231 19914 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2232 : {
2233 11960 : st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
2234 11960 : subframe_len = imult1616( st_ivas->hTcBuffer->subframe_nbslots[0], st_ivas->hTcBuffer->n_samples_granularity );
2235 11960 : gd_bits = find_guarded_bits_fx( subframe_len );
2236 11960 : exp = 13;
2237 11960 : move16();
2238 11960 : IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->intern_config, &nchan_in ) ), IVAS_ERR_OK ) )
2239 : {
2240 0 : return error;
2241 : }
2242 11960 : IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) )
2243 : {
2244 0 : return error;
2245 : }
2246 11960 : exp = sub( exp, gd_bits );
2247 11960 : *st_ivas->hCrendWrapper->p_io_qfactor = exp;
2248 11960 : move16();
2249 :
2250 94520 : FOR( i = 0; i < nchan_in; i++ )
2251 : {
2252 82560 : scale_sig32( p_output_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11
2253 82560 : IF( st_ivas->hDecoderConfig->Opt_tsm )
2254 : {
2255 0 : scale_sig32( p_tc_fx[i], *nSamplesRendered, negate( sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ) ); // Q11
2256 : }
2257 : }
2258 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,
2259 : &st_ivas->hIntSetup, st_ivas->hEFAPdata, st_ivas->hTcBuffer, crendInPlaceRotation ? p_output_fx : p_tc_fx, p_output_fx, *nSamplesRendered, output_Fs ) ),
2260 : IVAS_ERR_OK ) )
2261 : {
2262 0 : return error;
2263 : }
2264 :
2265 11960 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx );
2266 :
2267 94520 : FOR( i = 0; i < nchan_in; i++ )
2268 : {
2269 82560 : scale_sig32( p_output_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11
2270 82560 : IF( st_ivas->hDecoderConfig->Opt_tsm )
2271 : {
2272 0 : scale_sig32( p_tc_fx[i], *nSamplesRendered, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q11
2273 : }
2274 : }
2275 : }
2276 7954 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
2277 : {
2278 4404 : *nSamplesRendered = s_min( st_ivas->hTcBuffer->n_samples_available, nSamplesAskedLocal );
2279 4404 : move16();
2280 :
2281 4404 : ivas_ls_setup_conversion_fx( st_ivas, st_ivas->nchan_transport, *nSamplesRendered, p_tc_fx, p_output_fx );
2282 : }
2283 3550 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
2284 : {
2285 490 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_tc_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
2286 : }
2287 3060 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
2288 : {
2289 3060 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
2290 : {
2291 0 : return error;
2292 : }
2293 :
2294 3060 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_tc_fx, p_output_fx );
2295 : }
2296 : }
2297 16930 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
2298 : {
2299 770 : ivas_mc_paramupmix_dec_render( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_tc_fx, p_output_fx );
2300 :
2301 770 : test();
2302 770 : test();
2303 : /* Rendering */
2304 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 )
2305 : {
2306 160 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx );
2307 : }
2308 610 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_MC ) )
2309 : {
2310 0 : ivas_ls_setup_conversion_fx( st_ivas, MC_PARAMUPMIX_MAX_INPUT_CHANS, *nSamplesRendered, p_output_fx, p_output_fx );
2311 : }
2312 610 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
2313 : {
2314 10 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
2315 : }
2316 600 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
2317 : {
2318 0 : IF( NE_32( ( error = ivas_td_binaural_renderer_fx( st_ivas, p_output_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
2319 : {
2320 0 : return error;
2321 : }
2322 :
2323 0 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, p_output_fx, p_output_fx );
2324 : }
2325 : }
2326 16160 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
2327 : {
2328 : Word16 channel_active_fx[MAX_OUTPUT_CHANNELS];
2329 : Word16 nchan_out_cov;
2330 8760 : Word16 nchan_out_cldfb = 0;
2331 8760 : move16();
2332 :
2333 8760 : set16_fx( channel_active_fx, 0, MAX_CICP_CHANNELS );
2334 8760 : Word16 nchan_transport_tmp = st_ivas->nchan_transport;
2335 8760 : move16();
2336 8760 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
2337 8760 : move32();
2338 8760 : Word16 nchan_out_transport = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
2339 8760 : test();
2340 8760 : test();
2341 8760 : IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
2342 : {
2343 6910 : nchan_out_cldfb = BINAURAL_CHANNELS;
2344 6910 : move16();
2345 6910 : set16_fx( channel_active_fx, 1, BINAURAL_CHANNELS );
2346 6910 : nchan_out_cov = add( st_ivas->hTransSetup.nchan_out_woLFE, st_ivas->hTransSetup.num_lfe );
2347 : }
2348 1850 : ELSE IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_LS_CONV_CLDFB ) )
2349 : {
2350 340 : nchan_out_cov = nchan_out_transport;
2351 340 : move16();
2352 340 : nchan_out_cldfb = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
2353 : }
2354 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 ) )
2355 : {
2356 150 : nchan_out_cov = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
2357 150 : nchan_out_cldfb = nchan_out_cov;
2358 150 : move16();
2359 150 : set16_fx( channel_active_fx, 1, nchan_out_cov );
2360 : }
2361 : ELSE
2362 : {
2363 1360 : nchan_out_cov = nchan_out_transport;
2364 1360 : move16();
2365 1360 : nchan_out_cldfb = nchan_out_transport;
2366 1360 : move16();
2367 1360 : set16_fx( channel_active_fx, 1, nchan_out_cov );
2368 : }
2369 8760 : IF( st_ivas->hParamMC->max_band_decorr > 0 )
2370 : {
2371 : Word16 tmp;
2372 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 );
2373 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)
2374 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 );
2375 8760 : move16();
2376 : }
2377 : /* CLDFB synthesis */
2378 35840 : FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
2379 : {
2380 27080 : IF( st_ivas->cldfbSynDec[ch] )
2381 : {
2382 27080 : scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, ( Q5 - Q11 ) ); // Q5
2383 27080 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q5;
2384 27080 : move16();
2385 : }
2386 : }
2387 : Word16 tempp;
2388 121880 : FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->num_param_bands_synth; param_band_idx++ )
2389 : {
2390 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 );
2391 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))
2392 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 );
2393 113120 : move16();
2394 :
2395 113120 : IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
2396 : {
2397 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 );
2398 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))
2399 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 );
2400 90900 : move16();
2401 : }
2402 : }
2403 :
2404 8760 : ivas_param_mc_dec_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx, channel_active_fx );
2405 :
2406 35840 : FOR( ch = 0; ch < nchan_out_cldfb; ch++ )
2407 : {
2408 27080 : IF( st_ivas->cldfbSynDec[ch] )
2409 : {
2410 27080 : scale_sig32( st_ivas->cldfbSynDec[ch]->cldfb_state_fx, st_ivas->cldfbSynDec[ch]->cldfb_size, Q11 - Q5 ); // Q11
2411 27080 : st_ivas->cldfbSynDec[ch]->Q_cldfb_state = Q11;
2412 27080 : move16();
2413 : }
2414 : }
2415 8760 : IF( EQ_16( st_ivas->hParamMC->slots_rendered, st_ivas->hParamMC->num_slots ) )
2416 : {
2417 123780 : FOR( Word16 param_band_idx = 0; param_band_idx < st_ivas->hParamMC->hMetadataPMC->nbands_coded; param_band_idx++ )
2418 : {
2419 115020 : IF( LT_16( st_ivas->hParamMC->band_grouping[param_band_idx], st_ivas->hParamMC->h_output_synthesis_params.max_band_decorr ) )
2420 : {
2421 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 ) );
2422 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];
2423 90900 : move16();
2424 : }
2425 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 ) );
2426 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];
2427 115020 : move16();
2428 : }
2429 : }
2430 : }
2431 7400 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
2432 : {
2433 7400 : Word16 offset = imult1616( hSpatParamRendCom->slots_rendered, hSpatParamRendCom->slot_size );
2434 7400 : nchan_remapped = st_ivas->nchan_transport;
2435 7400 : move16();
2436 :
2437 7400 : test();
2438 7400 : test();
2439 7400 : test();
2440 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 ) )
2441 : {
2442 5760 : ivas_dirac_dec_binaural_render_fx( st_ivas, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, nchan_remapped, p_output_fx );
2443 : }
2444 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 */
2445 : {
2446 1640 : ivas_dirac_dec_render_fx( st_ivas, nchan_remapped, nSamplesAskedLocal, nSamplesRendered, nSamplesAvailableNext, p_output_fx );
2447 :
2448 1640 : test();
2449 1640 : test();
2450 1640 : test();
2451 1640 : IF( EQ_32( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) )
2452 : {
2453 : /* we still need to copy the separate channel if available */
2454 290 : IF( st_ivas->hOutSetup.separateChannelEnabled )
2455 : {
2456 25 : Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
2457 : }
2458 :
2459 290 : ivas_mc2sba_fx( st_ivas->hIntSetup, p_output_fx, p_output_fx, *nSamplesRendered, st_ivas->hOutSetup.ambisonics_order, 0 );
2460 : }
2461 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 ) ) )
2462 : {
2463 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++ )
2464 : {
2465 0 : set32_fx( p_output_fx[n], 0, *nSamplesRendered );
2466 : }
2467 : }
2468 : }
2469 :
2470 : /* copy discrete C and TD LFE from internal TC to output */
2471 7400 : IF( st_ivas->hOutSetup.separateChannelEnabled )
2472 : {
2473 200 : test();
2474 200 : test();
2475 200 : test();
2476 200 : test();
2477 200 : test();
2478 200 : test();
2479 200 : test();
2480 200 : IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
2481 : EQ_32( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
2482 : 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 ) ) )
2483 : {
2484 150 : Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL] + offset, p_output_fx[LFE_CHANNEL], *nSamplesRendered );
2485 150 : Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
2486 : }
2487 50 : ELSE IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) && st_ivas->hOutSetup.num_lfe == 0 )
2488 : {
2489 : /* Delay the separated channel to sync with the DirAC rendering */
2490 0 : Copy32( st_ivas->hTcBuffer->tc_fx[LFE_CHANNEL - 1] + offset, p_output_fx[st_ivas->hOutSetup.separateChannelIndex], *nSamplesRendered );
2491 : }
2492 : }
2493 : }
2494 : }
2495 :
2496 : /*----------------------------------------------------------------*
2497 : * Write IVAS output channels
2498 : * - compensation for saturation
2499 : * - float to integer conversion
2500 : *----------------------------------------------------------------*/
2501 :
2502 411989 : st_ivas->hTcBuffer->n_samples_available = sub( st_ivas->hTcBuffer->n_samples_available, *nSamplesRendered );
2503 411989 : st_ivas->hTcBuffer->n_samples_rendered = add( st_ivas->hTcBuffer->n_samples_rendered, *nSamplesRendered );
2504 411989 : move16();
2505 411989 : move16();
2506 :
2507 : /* update global combined orientation start index */
2508 411989 : ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
2509 :
2510 411989 : IF( st_ivas->hTcBuffer->n_samples_discard > 0 )
2511 : {
2512 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++ )
2513 : {
2514 264 : p_output_fx[n] += st_ivas->hTcBuffer->n_samples_discard;
2515 : }
2516 22 : *nSamplesRendered = sub( (Word16) *nSamplesRendered, st_ivas->hTcBuffer->n_samples_discard );
2517 22 : move16();
2518 22 : st_ivas->hTcBuffer->n_samples_discard = 0;
2519 22 : move16();
2520 : }
2521 :
2522 : {
2523 411989 : IF( NE_32( st_ivas->ivas_format, MONO_FORMAT ) )
2524 : {
2525 : #ifndef DISABLE_LIMITER
2526 408889 : ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, nchan_out, *nSamplesRendered, st_ivas->BER_detect, output_q_factor );
2527 : #endif
2528 : }
2529 : }
2530 :
2531 411989 : ivas_syn_output_fx( p_output_fx, output_q_factor, *nSamplesRendered, nchan_out, data );
2532 :
2533 411989 : *nSamplesAvailableNext = st_ivas->hTcBuffer->n_samples_available;
2534 411989 : move16();
2535 :
2536 411989 : pop_wmops();
2537 411989 : return IVAS_ERR_OK;
2538 : }
2539 :
2540 : /*--------------------------------------------------------------------------*
2541 : * ivas_jbm_dec_dec_flush_renderer()
2542 : *
2543 : * Flush samples if renderer granularity changes on a bitrate change
2544 : *--------------------------------------------------------------------------*/
2545 :
2546 318 : ivas_error ivas_jbm_dec_flush_renderer_fx(
2547 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
2548 : const Word16 tc_granularity_new, /* i : new renderer granularity */
2549 : const RENDERER_TYPE renderer_type_old, /* i : old renderer type */
2550 : const AUDIO_CONFIG intern_config_old, /* i : old internal config */
2551 : const IVAS_OUTPUT_SETUP_HANDLE hIntSetupOld, /* i : old internal output setup */
2552 : const MC_MODE mc_mode_old, /* i : old MC mode */
2553 : const ISM_MODE ism_mode_old, /* i : old ISM mode */
2554 : UWord16 *nSamplesRendered, /* o : number of samples flushed */
2555 : Word16 *data /* o : output synthesis signal Q0*/
2556 : )
2557 : {
2558 : ivas_error error;
2559 : Word16 n_samples_still_available;
2560 : Word16 n_slots_still_available;
2561 : Word16 n_samples_to_render;
2562 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
2563 : Word32 output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
2564 : Word32 *p_output_fx[MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS];
2565 : Word16 nchan_in, nchan_out, gd_bits, n_chan_inp, i, shift;
2566 318 : IF( !st_ivas->hDecoderConfig->Opt_tsm )
2567 : {
2568 217 : return IVAS_ERR_OK;
2569 : }
2570 :
2571 101 : *nSamplesRendered = 0;
2572 101 : move16();
2573 101 : hTcBuffer = st_ivas->hTcBuffer;
2574 :
2575 : /* get number of possible slots in new granularity */
2576 101 : n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered );
2577 :
2578 : // n_slots_still_available = n_samples_still_available / tc_granularity_new;
2579 : Word16 tmp, tmp_e;
2580 101 : tmp = BASOP_Util_Divide1616_Scale( n_samples_still_available, tc_granularity_new, &tmp_e );
2581 101 : n_slots_still_available = shr( tmp, sub( 15, tmp_e ) );
2582 101 : *nSamplesRendered = imult1616( n_slots_still_available, tc_granularity_new );
2583 101 : n_samples_to_render = *nSamplesRendered;
2584 101 : move16();
2585 101 : move16();
2586 101 : n_samples_still_available = sub( n_samples_still_available, n_samples_to_render );
2587 101 : assert( n_samples_still_available < tc_granularity_new );
2588 :
2589 : /* update combined orientation access index */
2590 101 : ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
2591 :
2592 101 : IF( n_slots_still_available )
2593 : {
2594 : Word16 ch_idx;
2595 :
2596 : /* render what is still there with zero padding */
2597 151 : FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
2598 : {
2599 : /* move it at the beginning of the TC buffer with zero padding */
2600 129 : Copy32( hTcBuffer->tc_fx[ch_idx] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch_idx], n_samples_to_render );
2601 129 : set_zero_fx( hTcBuffer->tc_fx[ch_idx] + n_samples_to_render, hTcBuffer->n_samples_granularity - n_samples_to_render );
2602 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 );
2603 : }
2604 : /* simple change of the slot info */
2605 22 : hTcBuffer->num_slots = 1;
2606 22 : hTcBuffer->nb_subframes = 1;
2607 22 : hTcBuffer->subframes_rendered = 0;
2608 22 : hTcBuffer->slots_rendered = 0;
2609 22 : hTcBuffer->subframe_nbslots[0] = 1;
2610 22 : hTcBuffer->n_samples_buffered = add( hTcBuffer->n_samples_granularity, n_samples_still_available );
2611 22 : hTcBuffer->n_samples_available = 0;
2612 22 : hTcBuffer->n_samples_flushed = n_samples_to_render;
2613 : #ifdef CR_FIX_JBM_FLUSH_OFFSET
2614 : hTcBuffer->n_samples_rendered = 0;
2615 : #else
2616 22 : hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity;
2617 : #endif
2618 22 : move16();
2619 22 : move16();
2620 22 : move16();
2621 22 : move16();
2622 22 : move16();
2623 22 : move16();
2624 22 : move16();
2625 22 : move16();
2626 22 : move16();
2627 :
2628 462 : FOR( ch_idx = 0; ch_idx < ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ); ch_idx++ )
2629 : {
2630 440 : p_output_fx[ch_idx] = output_fx[ch_idx];
2631 : }
2632 :
2633 22 : test();
2634 22 : IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
2635 : {
2636 7 : IF( EQ_16( ism_mode_old, ISM_MODE_DISC ) )
2637 : {
2638 : /* Binaural rendering */
2639 7 : IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_OBJECTS_TD ) )
2640 : {
2641 0 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) )
2642 : {
2643 0 : return error;
2644 : }
2645 : }
2646 7 : ELSE IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2647 : {
2648 : /*TODO :To be tested : no stream entering---------------------------------------*/
2649 : /* Convert to CICPxx; used also for ISM->CICP19->binaural_room rendering */
2650 7 : set16_fx( st_ivas->hIsmRendererData->interpolator_fx, 32767, hTcBuffer->n_samples_granularity ); // 32767=1.0f in Q15
2651 :
2652 7 : ivas_ism_render_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity );
2653 :
2654 7 : st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
2655 7 : *st_ivas->hCrendWrapper->p_io_qfactor = 11;
2656 7 : move16();
2657 :
2658 7 : shift = MAX_16;
2659 7 : move16();
2660 7 : n_chan_inp = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
2661 :
2662 91 : FOR( i = 0; i < n_chan_inp; i++ )
2663 : {
2664 84 : shift = s_min( shift, L_norm_arr( p_output_fx[i], hTcBuffer->n_samples_granularity ) );
2665 : }
2666 :
2667 7 : gd_bits = sub( find_guarded_bits_fx( imult1616( hTcBuffer->subframe_nbslots[0], hTcBuffer->n_samples_granularity ) ), shift );
2668 :
2669 7 : *st_ivas->hCrendWrapper->p_io_qfactor = sub( *st_ivas->hCrendWrapper->p_io_qfactor, gd_bits );
2670 7 : move16();
2671 :
2672 91 : FOR( i = 0; i < n_chan_inp; i++ )
2673 : {
2674 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)
2675 : }
2676 :
2677 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,
2678 : NULL, NULL, st_ivas->hTcBuffer, p_output_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ),
2679 : IVAS_ERR_OK ) )
2680 : {
2681 0 : return error;
2682 : }
2683 :
2684 91 : FOR( i = 0; i < n_chan_inp; i++ )
2685 : {
2686 84 : scale_sig32( p_output_fx[i], hTcBuffer->n_samples_granularity, sub( Q11, *st_ivas->hCrendWrapper->p_io_qfactor ) ); // Q(11)
2687 : }
2688 7 : *st_ivas->hCrendWrapper->p_io_qfactor = Q11;
2689 7 : move16();
2690 : }
2691 : }
2692 : ELSE
2693 : {
2694 0 : return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong ISM_MODE in VoIP renderer flushing!" );
2695 : }
2696 : }
2697 15 : ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
2698 : {
2699 0 : IF( EQ_16( mc_mode_old, MC_MODE_MCT ) )
2700 : {
2701 0 : test();
2702 0 : IF( EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV ) || EQ_16( renderer_type_old, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
2703 : {
2704 : /*TODO :To be tested : no stream entering*/
2705 0 : st_ivas->hCrendWrapper->p_io_qfactor = &st_ivas->hCrendWrapper->io_qfactor;
2706 0 : IF( NE_32( ( error = getAudioConfigNumChannels( intern_config_old, &nchan_in ) ), IVAS_ERR_OK ) )
2707 : {
2708 0 : return error;
2709 : }
2710 0 : IF( NE_32( ( error = getAudioConfigNumChannels( st_ivas->hOutSetup.output_config, &nchan_out ) ), IVAS_ERR_OK ) )
2711 : {
2712 0 : return error;
2713 : }
2714 0 : *st_ivas->hCrendWrapper->p_io_qfactor = 11;
2715 0 : move16();
2716 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,
2717 : hIntSetupOld, st_ivas->hEFAPdata, st_ivas->hTcBuffer, hTcBuffer->tc_fx, p_output_fx, hTcBuffer->n_samples_granularity, st_ivas->hDecoderConfig->output_Fs ) ),
2718 : IVAS_ERR_OK ) )
2719 : {
2720 0 : return error;
2721 : }
2722 :
2723 0 : ivas_binaural_add_LFE_fx( st_ivas, hTcBuffer->n_samples_granularity, st_ivas->hTcBuffer->tc_fx, p_output_fx );
2724 : }
2725 0 : ELSE IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) )
2726 : {
2727 0 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) )
2728 : {
2729 0 : return error;
2730 : }
2731 0 : ivas_binaural_add_LFE_fx( st_ivas, *nSamplesRendered, st_ivas->hTcBuffer->tc_fx, p_output_fx );
2732 : }
2733 : }
2734 : ELSE
2735 : {
2736 0 : return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong MC_MODE in VoIP renderer flushing!" );
2737 : }
2738 : }
2739 15 : ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
2740 : {
2741 6 : IF( EQ_16( ism_mode_old, ISM_MASA_MODE_DISC ) )
2742 : {
2743 : Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS];
2744 :
2745 6 : move16();
2746 22 : FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
2747 : {
2748 16 : tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered];
2749 16 : Copy32( st_ivas->hMasaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hMasaIsmData->delayBuffer_size ); /*Q11*/
2750 : }
2751 :
2752 6 : IF( st_ivas->nchan_ism > 0 )
2753 : {
2754 4 : IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_output_fx, hTcBuffer->n_samples_granularity ) ), IVAS_ERR_OK ) )
2755 : {
2756 0 : return error;
2757 : }
2758 : }
2759 : ELSE
2760 : {
2761 6 : FOR( ch_idx = 0; ch_idx < st_ivas->hDecoderConfig->nchan_out; ch_idx++ )
2762 : {
2763 4 : set_zero_fx( p_output_fx[ch_idx], (Word16) ( *nSamplesRendered ) );
2764 : }
2765 2 : st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, 1 );
2766 2 : st_ivas->hTcBuffer->subframes_rendered = add( st_ivas->hTcBuffer->subframes_rendered, 1 );
2767 2 : move16();
2768 2 : move16();
2769 : }
2770 : }
2771 : }
2772 9 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
2773 : {
2774 : Word32 *tc_local_fx[MAX_TRANSPORT_CHANNELS];
2775 : Word16 last_spar_md_idx;
2776 : Word16 last_dirac_md_idx;
2777 : UWord16 nSamplesAvailableNext;
2778 :
2779 9 : last_spar_md_idx = st_ivas->hSpar->render_to_md_map[st_ivas->hSpar->slots_rendered - 1];
2780 9 : last_dirac_md_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->slots_rendered - 1];
2781 9 : move16();
2782 9 : move16();
2783 : /* copy from ISM delay buffer to the correct place in tcs */
2784 27 : FOR( ch_idx = 0; ch_idx < st_ivas->nchan_ism; ch_idx++ )
2785 : {
2786 18 : tc_local_fx[ch_idx] = &st_ivas->hTcBuffer->tc_fx[ch_idx + 2][hTcBuffer->n_samples_rendered];
2787 18 : Copy32( st_ivas->hSbaIsmData->delayBuffer_fx[ch_idx], tc_local_fx[ch_idx], st_ivas->hSbaIsmData->delayBuffer_size );
2788 : }
2789 :
2790 : /* transfer adapted sf info from hTcBuffer to SPAR and DirAC */
2791 9 : st_ivas->hSpar->nb_subframes = 1;
2792 9 : st_ivas->hSpar->subframes_rendered = 0;
2793 9 : st_ivas->hSpar->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
2794 9 : st_ivas->hSpar->slots_rendered = 0;
2795 9 : st_ivas->hSpar->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
2796 9 : st_ivas->hSpatParamRendCom->nb_subframes = 1;
2797 9 : st_ivas->hSpatParamRendCom->subframes_rendered = 0;
2798 9 : st_ivas->hSpatParamRendCom->subframe_nbslots[0] = JBM_CLDFB_SLOTS_IN_SUBFRAME;
2799 9 : st_ivas->hSpatParamRendCom->slots_rendered = 0;
2800 9 : st_ivas->hSpatParamRendCom->num_slots = JBM_CLDFB_SLOTS_IN_SUBFRAME;
2801 9 : move16();
2802 9 : move16();
2803 9 : move16();
2804 9 : move16();
2805 9 : move16();
2806 9 : move16();
2807 9 : move16();
2808 9 : move16();
2809 9 : move16();
2810 9 : move16();
2811 :
2812 : /* also adapt md maps, just use the last index */
2813 9 : set16_fx( st_ivas->hSpar->render_to_md_map, last_spar_md_idx, n_slots_still_available );
2814 9 : set16_fx( st_ivas->hSpatParamRendCom->render_to_md_map, last_dirac_md_idx, n_slots_still_available );
2815 :
2816 : /* render the last subframe */
2817 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 ) )
2818 : {
2819 0 : return error;
2820 : }
2821 : }
2822 : ELSE
2823 : {
2824 0 : return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Wrong IVAS format in VoIP renderer flushing!" );
2825 : }
2826 : #ifdef CR_FIX_JBM_FLUSH_OFFSET
2827 : hTcBuffer->n_samples_rendered = hTcBuffer->n_samples_granularity;
2828 : #endif
2829 : }
2830 :
2831 : /* update global combined orientation start index */
2832 101 : ivas_combined_orientation_update_start_index( st_ivas->hCombinedOrientationData, *nSamplesRendered );
2833 :
2834 101 : *nSamplesRendered = n_samples_to_render;
2835 101 : move16();
2836 : /* Only write out the valid data*/
2837 : {
2838 101 : IF( NE_16( st_ivas->ivas_format, MONO_FORMAT ) )
2839 : {
2840 : #ifndef DISABLE_LIMITER
2841 101 : Word16 ch_idx, exp = 11;
2842 101 : move16();
2843 1717 : FOR( ch_idx = 0; ch_idx < MAX_CICP_CHANNELS; ch_idx++ )
2844 : {
2845 1616 : p_output_fx[ch_idx] = output_fx[ch_idx];
2846 : }
2847 101 : ivas_limiter_dec_fx( st_ivas->hLimiter, p_output_fx, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, exp );
2848 : #endif
2849 : }
2850 : }
2851 :
2852 101 : ivas_syn_output_fx( p_output_fx, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, data );
2853 101 : return IVAS_ERR_OK;
2854 : }
2855 :
2856 :
2857 : /*--------------------------------------------------------------------------*
2858 : * ivas_jbm_dec_set_discard_samples()
2859 : *
2860 : * Set number of samples to discard in the first subframe if the renderer granularity changes on a bitrate change
2861 : *--------------------------------------------------------------------------*/
2862 :
2863 324 : ivas_error ivas_jbm_dec_set_discard_samples(
2864 : Decoder_Struct *st_ivas /* i/o: main IVAS decoder structre */
2865 : )
2866 : {
2867 : Word16 nMaxSlotsPerSubframe, nSlotsInFirstSubframe;
2868 : Word16 temp, temp_e;
2869 : /* render first frame with front zero padding and discarding those samples */
2870 : // nMaxSlotsPerSubframe = (Word16)(st_ivas->hDecoderConfig->output_Fs / (FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES)) / st_ivas->hTcBuffer->n_samples_granularity;
2871 324 : temp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ), &temp_e );
2872 324 : temp = shr( temp, sub( 15, temp_e ) );
2873 324 : nMaxSlotsPerSubframe = BASOP_Util_Divide1616_Scale( temp, st_ivas->hTcBuffer->n_samples_granularity, &temp_e );
2874 324 : nMaxSlotsPerSubframe = shr( nMaxSlotsPerSubframe, sub( 15, temp_e ) ); // Q0
2875 324 : nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] );
2876 324 : IF( nSlotsInFirstSubframe > 0 )
2877 : {
2878 22 : st_ivas->hTcBuffer->n_samples_discard = imult1616( sub( nMaxSlotsPerSubframe, nSlotsInFirstSubframe ), st_ivas->hTcBuffer->n_samples_granularity );
2879 : /* set last subframes number to max to ensure correct continuation */
2880 22 : st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nMaxSlotsPerSubframe;
2881 22 : move16();
2882 22 : move16();
2883 : }
2884 :
2885 324 : return IVAS_ERR_OK;
2886 : }
2887 :
2888 :
2889 : /*--------------------------------------------------------------------------*
2890 : * ivas_jbm_dec_get_adapted_linear_interpolator()
2891 : *
2892 : * Get an interpolator that is adapted to time scale modified IVAS frame
2893 : *--------------------------------------------------------------------------*/
2894 17686 : void ivas_jbm_dec_get_adapted_linear_interpolator_fx(
2895 : const Word16 default_interp_length, /* i : default length of the (full-frame) interpolator */
2896 : const Word16 interp_length, /* i : length of the interpolator to be created */
2897 : Word16 *interpolator_fx /* o : the interpolator Q15 */
2898 : )
2899 : {
2900 : Word16 jbm_segment_len, idx;
2901 : Word16 dec_fx;
2902 : Word16 dec_e;
2903 :
2904 17686 : jbm_segment_len = shr( default_interp_length, 1 );
2905 17686 : dec_fx = divide1616( 1, default_interp_length ); /*32767 / default_interp_length*/
2906 :
2907 17686 : interpolator_fx[interp_length - 1] = 32767; /* (1.0f in Q15) -1 */
2908 17686 : move16();
2909 17686 : interpolator_fx[interp_length - 2] = add( sub( 32767, dec_fx ), 1 ); // Use 32768 to maintain precision
2910 17686 : move16();
2911 1540746 : FOR( idx = interp_length - 3; idx >= jbm_segment_len; idx-- )
2912 : {
2913 1523060 : interpolator_fx[idx] = s_max( 0, sub( interpolator_fx[idx + 1], dec_fx ) );
2914 1523060 : move16();
2915 : }
2916 :
2917 17686 : IF( interpolator_fx[idx + 1] > 0 )
2918 : {
2919 17685 : dec_fx = BASOP_Util_Divide1616_Scale( interpolator_fx[idx + 1], add( jbm_segment_len, 1 ), &dec_e );
2920 17685 : dec_fx = shr( dec_fx, sub( 15, dec_e ) ); // Q0
2921 1575477 : FOR( ; idx >= 0; idx-- )
2922 : {
2923 1557792 : interpolator_fx[idx] = sub( interpolator_fx[idx + 1], dec_fx );
2924 1557792 : move16();
2925 : }
2926 : }
2927 : ELSE
2928 : {
2929 1 : set16_fx( interpolator_fx, 0, idx + 1 );
2930 : }
2931 :
2932 17686 : return;
2933 : }
2934 :
2935 : /*--------------------------------------------------------------------------*
2936 : * ivas_jbm_dec_get_adapted_subframes()
2937 : *
2938 : * Get an interpolator that is adapted to time scale modified IVAS frame
2939 : *--------------------------------------------------------------------------*/
2940 :
2941 290284 : void ivas_jbm_dec_get_adapted_subframes(
2942 : const Word16 nCldfbTs, /* i : number of time slots in the current frame */
2943 : Word16 *subframe_nbslots, /* i/o: subframe grid */
2944 : Word16 *nb_subframes /* i/o: number of subframes in the frame */
2945 : )
2946 : {
2947 : UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe;
2948 290284 : UWord16 nCldfbSlotsLocal = nCldfbTs;
2949 290284 : move16();
2950 : Word16 temp, temp_e;
2951 : /* get last subframe size from previous frame, determine how many slots have to be processed
2952 : in the first subframe (i.e. potential leftover of a 5ms subframe) */
2953 290284 : nSlotsInFirstSubframe = ( sub( PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, subframe_nbslots[*nb_subframes - 1] ) );
2954 290284 : *nb_subframes = 0;
2955 290284 : move16();
2956 290284 : IF( nSlotsInFirstSubframe > 0 )
2957 : {
2958 7849 : *nb_subframes = 1;
2959 7849 : move16();
2960 7849 : nCldfbSlotsLocal = sub( nCldfbSlotsLocal, nSlotsInFirstSubframe );
2961 : }
2962 :
2963 290284 : temp = BASOP_Util_Divide3232_Scale( L_add( nCldfbSlotsLocal, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME - 1 ), PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, &temp_e );
2964 290284 : *nb_subframes = add( *nb_subframes, shr( temp, sub( 15, temp_e ) ) ); // Q0
2965 290284 : move16();
2966 290284 : nSlotsInLastSubframe = nCldfbSlotsLocal % PARAM_MC_MAX_NSLOTS_IN_SUBFRAME;
2967 290284 : move16();
2968 :
2969 290284 : set16_fx( subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
2970 290284 : set16_fx( subframe_nbslots, PARAM_MC_MAX_NSLOTS_IN_SUBFRAME, *nb_subframes );
2971 :
2972 290284 : IF( nSlotsInFirstSubframe > 0 )
2973 : {
2974 7849 : subframe_nbslots[0] = nSlotsInFirstSubframe;
2975 7849 : move16();
2976 : }
2977 :
2978 290284 : IF( nSlotsInLastSubframe > 0 )
2979 : {
2980 7861 : subframe_nbslots[*nb_subframes - 1] = nSlotsInLastSubframe;
2981 7861 : move16();
2982 : }
2983 :
2984 290284 : return;
2985 : }
2986 : /*--------------------------------------------------------------------------*
2987 : * ivas_jbm_dec_get_adapted_linear_interpolator()
2988 : *
2989 : * Get an meta data map adapted to a time scale modified IVAS frame
2990 : *--------------------------------------------------------------------------*/
2991 :
2992 254992 : void ivas_jbm_dec_get_md_map(
2993 : const Word16 default_len, /* i : default frame length in metadata slots */
2994 : const Word16 len, /* i : length of the modfied frames in metadata slots */
2995 : const Word16 subframe_len, /* i : default length of a subframe */
2996 : const Word16 offset, /* i : current read offset into the md buffer */
2997 : const Word16 buf_len, /* i : length of the metadata buffer */
2998 : Word16 *map /* o : metadata index map */
2999 : )
3000 : {
3001 : Word16 jbm_segment_len, map_idx, src_idx, src_idx_map;
3002 : Word32 dec_fx, src_idx_fx;
3003 : Word16 temp_e;
3004 : Word16 temp;
3005 254992 : jbm_segment_len = shr( default_len, 1 );
3006 :
3007 2294961 : FOR( ( map_idx = len - 1, src_idx = default_len - 1 ); map_idx >= jbm_segment_len; ( map_idx--, src_idx-- ) )
3008 : {
3009 2039969 : temp = BASOP_Util_Divide1616_Scale( src_idx, subframe_len, &temp_e );
3010 2039969 : temp = shr( temp, sub( 15, temp_e ) ); // Q0
3011 2039969 : src_idx_map = s_max( 0, temp );
3012 2039969 : map[map_idx] = add( offset, src_idx_map ) % buf_len;
3013 2039969 : move16();
3014 : }
3015 :
3016 : /* changed part (first segment), interpolate index to parameters
3017 : (we do not want to interpolate and smooth acutal direction/diffuseness values even more) */
3018 254992 : IF( src_idx >= 0 )
3019 : {
3020 254986 : dec_fx = BASOP_Util_Divide3232_Scale( L_shl( add( src_idx, 1 ), 16 ), jbm_segment_len, &temp_e );
3021 254986 : dec_fx = L_shr( dec_fx, sub( 15, temp_e ) );
3022 254986 : src_idx_fx = L_sub( L_shl( add( src_idx, 1 ), 16 ), dec_fx );
3023 2294874 : FOR( ; map_idx >= 0; map_idx-- )
3024 : {
3025 2039888 : temp = BASOP_Util_Divide1616_Scale( round_fx( src_idx_fx ), subframe_len, &temp_e );
3026 2039888 : temp = shr( temp, sub( 15, temp_e ) ); // Q0
3027 2039888 : src_idx = s_max( 0, temp );
3028 2039888 : map[map_idx] = add( offset, src_idx ) % buf_len;
3029 2039888 : src_idx_fx = L_sub( src_idx_fx, dec_fx );
3030 : }
3031 : }
3032 : ELSE
3033 : {
3034 6 : set16_fx( map, offset, add( map_idx, 1 ) );
3035 : }
3036 :
3037 254992 : return;
3038 : }
3039 :
3040 : /*--------------------------------------------------------------------------*
3041 : * ivas_jbm_dec_get_md_map_even_spacing()
3042 : *
3043 : * Get an meta data map adapted to a time scale modified IVAS frame. Distribute slots evenly across the modified frame.
3044 : *--------------------------------------------------------------------------*/
3045 :
3046 31994 : void ivas_jbm_dec_get_md_map_even_spacing(
3047 : const Word16 len, /* i : length of the modfied frames in metadata slots */
3048 : const Word16 subframe_len, /* i : default length of a subframe */
3049 : const Word16 offset, /* i : current read offset into the md buffer */
3050 : const Word16 buf_len, /* i : length of the metadata buffer */
3051 : Word16 *map /* o : metadata index map */
3052 : )
3053 : {
3054 : Word16 map_idx, sf_idx, sf_length, increment, subframes_written;
3055 : Word32 decimal_fx, decimal_sum_fx, eps_fx; // q = 16
3056 : Word16 subframe_map_length[MAX_PARAM_SPATIAL_SUBFRAMES];
3057 :
3058 : /* subframe map length */
3059 31994 : sf_length = idiv1616( len, subframe_len );
3060 31994 : IF( len % subframe_len == 0 )
3061 : {
3062 : /* even subframes */
3063 159915 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
3064 : {
3065 127932 : subframe_map_length[sf_idx] = sf_length;
3066 127932 : move16();
3067 : }
3068 : }
3069 : ELSE
3070 : {
3071 : /* uneven subframes */
3072 : Word32 temp;
3073 : Word16 temp_e;
3074 11 : temp = BASOP_Util_Divide3232_Scale( L_shl( len, 16 ), subframe_len, &temp_e );
3075 11 : temp = L_shr( temp, sub( 15, temp_e ) ); // Q16
3076 11 : decimal_fx = L_sub( temp, L_shl( sf_length, 16 ) ); // Q16
3077 11 : decimal_sum_fx = decimal_fx;
3078 :
3079 11 : eps_fx = 65;
3080 11 : move32();
3081 11 : move32();
3082 55 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
3083 : {
3084 44 : increment = extract_l( L_shr( L_add( decimal_sum_fx, eps_fx ), 16 ) );
3085 44 : subframe_map_length[sf_idx] = add( sf_length, increment );
3086 44 : move16();
3087 44 : IF( increment > 0 )
3088 : {
3089 22 : decimal_sum_fx = L_sub( decimal_sum_fx, ONE_IN_Q16 );
3090 : }
3091 44 : decimal_sum_fx = L_add( decimal_sum_fx, decimal_fx );
3092 : }
3093 : }
3094 :
3095 : /* map slots to subframes */
3096 31994 : sf_idx = 0;
3097 31994 : subframes_written = 0;
3098 31994 : move16();
3099 31994 : move16();
3100 544016 : FOR( map_idx = 0; map_idx < len; map_idx++ )
3101 : {
3102 512022 : map[map_idx] = add( offset, sf_idx ) % buf_len;
3103 512022 : move16();
3104 512022 : IF( GE_16( sub( map_idx, subframes_written ), sub( subframe_map_length[sf_idx], 1 ) ) )
3105 : {
3106 127976 : subframes_written = add( subframes_written, subframe_map_length[sf_idx] );
3107 127976 : sf_idx = add( sf_idx, 1 );
3108 : }
3109 : }
3110 :
3111 31994 : return;
3112 : }
3113 :
3114 : /*--------------------------------------------------------------------------*
3115 : * ivas_jbm_dec_get_num_tc_channels()
3116 : *
3117 : * Get the number of transport channels provided by the JBM transport channel decode function
3118 : *--------------------------------------------------------------------------*/
3119 :
3120 :
3121 6849 : Word16 ivas_jbm_dec_get_num_tc_channels_fx(
3122 : Decoder_Struct *st_ivas /* i : IVAS decoder handle */
3123 : )
3124 : {
3125 : Word16 num_tc;
3126 : Word32 ivas_total_brate;
3127 : AUDIO_CONFIG output_config;
3128 :
3129 :
3130 6849 : IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) )
3131 : {
3132 892 : num_tc = st_ivas->hDecoderConfig->nchan_out;
3133 892 : move16();
3134 : }
3135 : ELSE
3136 : {
3137 5957 : num_tc = st_ivas->nchan_transport;
3138 5957 : move16();
3139 : }
3140 6849 : output_config = st_ivas->hDecoderConfig->output_config;
3141 6849 : move16();
3142 :
3143 6849 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
3144 6849 : move32();
3145 :
3146 6849 : test();
3147 6849 : test();
3148 6849 : test();
3149 6849 : IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) )
3150 : {
3151 3 : num_tc = st_ivas->hDecoderConfig->nchan_out;
3152 3 : move16();
3153 : }
3154 6846 : ELSE IF( EQ_16( st_ivas->ivas_format, STEREO_FORMAT ) && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) )
3155 : {
3156 22 : num_tc = 1;
3157 22 : move16();
3158 : }
3159 6824 : ELSE IF( EQ_16( st_ivas->ivas_format, ISM_FORMAT ) )
3160 : {
3161 1066 : if ( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
3162 : {
3163 2 : num_tc = 1;
3164 2 : move16();
3165 : }
3166 : }
3167 5758 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, MASA_FORMAT ) )
3168 : {
3169 3055 : test();
3170 3055 : test();
3171 3055 : test();
3172 3055 : test();
3173 3055 : test();
3174 3055 : test();
3175 3055 : IF( st_ivas->sba_dirac_stereo_flag )
3176 : {
3177 124 : num_tc = CPE_CHANNELS;
3178 124 : move16();
3179 : }
3180 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 ) ) ) )
3181 : {
3182 626 : num_tc = 1; /* Only one channel transported */
3183 626 : move16();
3184 : }
3185 :
3186 3055 : test();
3187 3055 : test();
3188 3055 : test();
3189 3055 : test();
3190 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 ) )
3191 : {
3192 5 : num_tc = CPE_CHANNELS;
3193 5 : move16();
3194 : }
3195 3055 : IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) )
3196 : {
3197 1263 : if ( EQ_16( num_tc, 3 ) )
3198 : {
3199 267 : num_tc = add( num_tc, 1 );
3200 : }
3201 : }
3202 : }
3203 2703 : ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
3204 : {
3205 1098 : IF( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
3206 : {
3207 1095 : test();
3208 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 ) )
3209 : {
3210 693 : num_tc = add( num_tc, 1 );
3211 : }
3212 402 : ELSE IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
3213 : {
3214 402 : num_tc = add( num_tc, st_ivas->nchan_ism );
3215 : }
3216 : }
3217 : }
3218 1605 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
3219 : {
3220 :
3221 :
3222 501 : if ( st_ivas->sba_dirac_stereo_flag )
3223 : {
3224 94 : num_tc = CPE_CHANNELS;
3225 94 : move16();
3226 : }
3227 :
3228 501 : test();
3229 501 : test();
3230 501 : if ( ( st_ivas->sba_planar && GE_16( num_tc, 3 ) ) || EQ_16( num_tc, 3 ) )
3231 : {
3232 115 : num_tc = add( num_tc, 1 );
3233 : }
3234 501 : if ( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
3235 : {
3236 96 : num_tc = add( num_tc, st_ivas->nchan_ism );
3237 : }
3238 : }
3239 1104 : ELSE IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) )
3240 : {
3241 1059 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
3242 : {
3243 5 : num_tc = 1;
3244 5 : move16();
3245 : }
3246 1054 : ELSE IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) )
3247 : {
3248 26 : num_tc = 2;
3249 26 : move16();
3250 : }
3251 1028 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCT ) )
3252 : {
3253 : /* do all static dmx already in the TC decoder if less channels than transported... */
3254 517 : test();
3255 517 : test();
3256 517 : test();
3257 517 : test();
3258 517 : test();
3259 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 ) ) )
3260 : {
3261 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 ) ) )
3262 : {
3263 0 : num_tc = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe );
3264 : }
3265 : }
3266 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 ) ) )
3267 : {
3268 0 : num_tc = add( st_ivas->hOutSetup.nchan_out_woLFE, st_ivas->hOutSetup.num_lfe );
3269 : }
3270 : }
3271 511 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
3272 : {
3273 9 : num_tc = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
3274 9 : move16();
3275 : }
3276 502 : ELSE IF( EQ_16( st_ivas->mc_mode, MC_MODE_MCMASA ) )
3277 : {
3278 216 : if ( st_ivas->hOutSetup.separateChannelEnabled )
3279 : {
3280 11 : num_tc = add( num_tc, 1 );
3281 : }
3282 216 : test();
3283 216 : test();
3284 216 : test();
3285 216 : test();
3286 216 : test();
3287 216 : test();
3288 216 : test();
3289 226 : if ( st_ivas->hOutSetup.separateChannelEnabled && ( EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1 ) ||
3290 30 : EQ_16( output_config, IVAS_AUDIO_CONFIG_5_1_4 ) || EQ_16( output_config, IVAS_AUDIO_CONFIG_7_1_4 ) ||
3291 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 ) ) )
3292 : {
3293 : /* LFE is synthesized in TD with the TCs*/
3294 1 : num_tc = add( num_tc, 1 );
3295 : }
3296 : }
3297 : }
3298 45 : ELSE IF( EQ_16( st_ivas->ivas_format, MONO_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
3299 : {
3300 0 : num_tc = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN;
3301 0 : move16();
3302 : }
3303 :
3304 6849 : return num_tc;
3305 : }
3306 :
3307 : /*--------------------------------------------------------------------------*
3308 : * ivas_jbm_dec_copy_tc()
3309 : *
3310 : * Copy interleaved transport chnannels to the correct buffers, update the TC
3311 : * buffer handle
3312 : *--------------------------------------------------------------------------*/
3313 19405 : static void ivas_jbm_dec_copy_tc(
3314 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
3315 : const Word16 nSamplesForRendering, /* i : number of samples to digest */
3316 : Word16 *nSamplesResidual, /* o : number of samples that will be left for the next frame */
3317 : Word32 *data, /* i : (interleaved) transport channel samples data_q*/
3318 : Word32 *tc_digest_f[], /* o : samples that will be directly digested (e.g. by CLDFB) data_q*/
3319 : Word16 data_q )
3320 : {
3321 : Word16 ch;
3322 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
3323 : Word16 n_samples_still_available, m;
3324 : Word16 n_ch_full_copy;
3325 : Word16 n_ch_res_copy;
3326 :
3327 19405 : hTcBuffer = st_ivas->hTcBuffer;
3328 19405 : n_samples_still_available = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_rendered );
3329 19405 : hTcBuffer->n_samples_buffered = add( add( n_samples_still_available, nSamplesForRendering ), hTcBuffer->n_samples_discard );
3330 19405 : hTcBuffer->n_samples_available = i_mult( hTcBuffer->n_samples_granularity, idiv1616( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_granularity ) );
3331 19405 : *nSamplesResidual = sub( hTcBuffer->n_samples_buffered, hTcBuffer->n_samples_available );
3332 19405 : move16();
3333 19405 : move16();
3334 19405 : move16();
3335 19405 : n_ch_full_copy = s_min( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
3336 19405 : n_ch_res_copy = sub( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
3337 :
3338 60104 : FOR( ch = 0; ch < n_ch_full_copy; ch++ )
3339 : {
3340 40699 : set32_fx( hTcBuffer->tc_fx[ch], 0, hTcBuffer->n_samples_discard );
3341 40699 : Copy32( hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_rendered, hTcBuffer->tc_fx[ch] + hTcBuffer->n_samples_discard, n_samples_still_available );
3342 32047796 : FOR( m = 0; m < nSamplesForRendering; m++ )
3343 : {
3344 32007097 : hTcBuffer->tc_fx[ch][n_samples_still_available + hTcBuffer->n_samples_discard + m] = data[m * st_ivas->hTcBuffer->nchan_transport_jbm + ch];
3345 32007097 : move32();
3346 : }
3347 : }
3348 :
3349 19405 : IF( n_ch_res_copy > 0 )
3350 : {
3351 4518 : FOR( ; ch < hTcBuffer->nchan_transport_jbm; ch++ )
3352 : {
3353 3012 : Copy32( hTcBuffer->tc_fx[ch], tc_digest_f[ch], n_samples_still_available );
3354 2894538 : FOR( m = 0; m < nSamplesForRendering; m++ )
3355 : {
3356 2891526 : tc_digest_f[ch][n_samples_still_available + m] = data[( m * st_ivas->hTcBuffer->nchan_transport_jbm ) + ch]; // data_q
3357 2891526 : move32();
3358 : }
3359 3012 : Copy32( tc_digest_f[ch] + hTcBuffer->n_samples_available, hTcBuffer->tc_fx[ch], *nSamplesResidual );
3360 : }
3361 : }
3362 19405 : hTcBuffer->q_tc_fx = data_q;
3363 19405 : move16();
3364 19405 : hTcBuffer->n_samples_rendered = 0;
3365 19405 : move16();
3366 19405 : hTcBuffer->subframes_rendered = 0;
3367 19405 : move16();
3368 :
3369 19405 : return;
3370 : }
3371 :
3372 : /*--------------------------------------------------------------------------*
3373 : * ivas_jbm_dec_get_render_granularity()
3374 : *
3375 : *
3376 : *--------------------------------------------------------------------------*/
3377 :
3378 : /*! r: render granularity */
3379 :
3380 :
3381 1907 : Word16 ivas_jbm_dec_get_render_granularity(
3382 : const RENDERER_TYPE rendererType, /* i : renderer type */
3383 : const IVAS_FORMAT ivas_format, /* i : ivas format */
3384 : const MC_MODE mc_mode, /* i : MC mode */
3385 : const Word32 output_Fs /* i : sampling rate Q0*/
3386 : )
3387 : {
3388 : Word16 render_granularity;
3389 :
3390 1907 : test();
3391 1907 : test();
3392 1907 : IF( EQ_32( rendererType, RENDERER_BINAURAL_OBJECTS_TD ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV ) || EQ_32( rendererType, RENDERER_BINAURAL_MIXER_CONV_ROOM ) )
3393 : {
3394 467 : test();
3395 467 : IF( ( EQ_32( ivas_format, MC_FORMAT ) ) && ( EQ_32( mc_mode, MC_MODE_PARAMUPMIX ) ) )
3396 : {
3397 0 : render_granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS );
3398 : }
3399 : ELSE
3400 : {
3401 467 : render_granularity = NS2SA_FX2( output_Fs, FRAME_SIZE_NS / MAX_PARAM_SPATIAL_SUBFRAMES );
3402 : }
3403 : }
3404 : ELSE
3405 : {
3406 1440 : render_granularity = NS2SA_FX2( output_Fs, CLDFB_SLOT_NS );
3407 : }
3408 :
3409 1907 : return render_granularity;
3410 : }
3411 :
3412 :
3413 : /*--------------------------------------------------------------------------*
3414 : * ivas_jbm_dec_tc_buffer_open()
3415 : *
3416 : * open and initialize JBM transport channel buffer
3417 : *--------------------------------------------------------------------------*/
3418 :
3419 :
3420 594 : ivas_error ivas_jbm_dec_tc_buffer_open_fx(
3421 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
3422 : const TC_BUFFER_MODE tc_buffer_mode, /* i : buffer mode */
3423 : const Word16 nchan_transport_jbm, /* i : number of real transport channels */
3424 : const Word16 nchan_transport_internal, /* i : number of totally buffered channels */
3425 : const Word16 nchan_full, /* i : number of channels to fully store */
3426 : const Word16 n_samples_granularity /* i : granularity of the renderer/buffer */
3427 : )
3428 : {
3429 : Word16 nsamp_to_allocate;
3430 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
3431 : Word16 nMaxSlotsPerSubframe;
3432 : Word16 nchan_residual;
3433 : Word16 ch_idx;
3434 : Word16 tmp, tmp_e;
3435 : Word32 tmp32;
3436 :
3437 : /*-----------------------------------------------------------------*
3438 : * prepare library opening
3439 : *-----------------------------------------------------------------*/
3440 :
3441 594 : IF( ( hTcBuffer = (DECODER_TC_BUFFER_HANDLE) malloc( sizeof( DECODER_TC_BUFFER ) ) ) == NULL )
3442 : {
3443 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) );
3444 : }
3445 :
3446 594 : hTcBuffer->tc_buffer_mode = tc_buffer_mode;
3447 594 : move16();
3448 594 : hTcBuffer->nchan_transport_jbm = nchan_transport_jbm;
3449 594 : move16();
3450 594 : hTcBuffer->nchan_transport_internal = nchan_transport_internal;
3451 594 : move16();
3452 594 : hTcBuffer->nchan_buffer_full = nchan_full;
3453 594 : move16();
3454 594 : nchan_residual = sub( nchan_transport_internal, nchan_full );
3455 594 : hTcBuffer->n_samples_granularity = n_samples_granularity;
3456 594 : move16();
3457 594 : hTcBuffer->n_samples_available = 0;
3458 594 : move16();
3459 594 : hTcBuffer->n_samples_buffered = 0;
3460 594 : move16();
3461 594 : hTcBuffer->n_samples_rendered = 0;
3462 594 : move16();
3463 594 : hTcBuffer->slots_rendered = 0;
3464 594 : move16();
3465 594 : hTcBuffer->subframes_rendered = 0;
3466 594 : move16();
3467 594 : hTcBuffer->n_samples_discard = 0;
3468 594 : move16();
3469 594 : hTcBuffer->n_samples_flushed = 0;
3470 594 : move16();
3471 594 : hTcBuffer->nb_subframes = MAX_PARAM_SPATIAL_SUBFRAMES;
3472 594 : move16();
3473 594 : nsamp_to_allocate = 0;
3474 594 : move16();
3475 :
3476 594 : tmp32 = L_mult0( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES, hTcBuffer->n_samples_granularity ); // Q0
3477 594 : tmp = BASOP_Util_Divide3232_Scale( st_ivas->hDecoderConfig->output_Fs, tmp32, &tmp_e );
3478 594 : nMaxSlotsPerSubframe = shr( tmp, sub( 15, tmp_e ) ); // Q0
3479 :
3480 594 : hTcBuffer->num_slots = mult0( nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES );
3481 594 : move16();
3482 :
3483 594 : set16_fx( hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
3484 594 : set16_fx( hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, MAX_PARAM_SPATIAL_SUBFRAMES );
3485 :
3486 594 : IF( EQ_16( hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_NONE ) )
3487 : {
3488 0 : hTcBuffer->tc_buffer_fx = NULL;
3489 :
3490 0 : FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3491 : {
3492 0 : hTcBuffer->tc_fx[ch_idx] = NULL;
3493 : }
3494 : }
3495 : ELSE
3496 : {
3497 : Word16 n_samp_full, n_samp_residual;
3498 : Word32 offset;
3499 594 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3500 : {
3501 27 : n_samp_full = add( NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ), sub( hTcBuffer->n_samples_granularity, 1 ) );
3502 27 : n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 );
3503 : }
3504 : ELSE
3505 : {
3506 : /* n_samp_full = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */
3507 567 : n_samp_full = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) );
3508 567 : n_samp_residual = 0;
3509 567 : move16();
3510 : }
3511 :
3512 594 : nsamp_to_allocate = mult0( hTcBuffer->nchan_buffer_full, n_samp_full );
3513 594 : nsamp_to_allocate = add( nsamp_to_allocate, mult0( nchan_residual, n_samp_residual ) );
3514 :
3515 594 : IF( nsamp_to_allocate == 0 )
3516 : {
3517 14 : hTcBuffer->tc_buffer_fx = NULL;
3518 :
3519 238 : FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3520 : {
3521 224 : hTcBuffer->tc_fx[ch_idx] = NULL;
3522 : }
3523 : }
3524 : ELSE
3525 : {
3526 580 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3527 : {
3528 27 : IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL )
3529 : {
3530 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM TC Buffer\n" ) );
3531 : }
3532 27 : set32_fx( hTcBuffer->tc_buffer_fx, 0, nsamp_to_allocate );
3533 :
3534 27 : offset = 0;
3535 27 : move16();
3536 125 : FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
3537 : {
3538 98 : hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
3539 98 : offset = L_add( offset, n_samp_full );
3540 : }
3541 29 : FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ )
3542 : {
3543 2 : hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
3544 2 : offset = L_add( offset, n_samp_residual );
3545 : }
3546 359 : FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3547 : {
3548 332 : hTcBuffer->tc_fx[ch_idx] = NULL;
3549 : }
3550 : }
3551 : ELSE
3552 : {
3553 553 : hTcBuffer->tc_buffer_fx = NULL;
3554 : }
3555 : }
3556 : }
3557 :
3558 594 : st_ivas->hTcBuffer = hTcBuffer;
3559 :
3560 594 : return IVAS_ERR_OK;
3561 : }
3562 :
3563 :
3564 : /*--------------------------------------------------------------------------*
3565 : * ivas_jbm_dec_tc_buffer_reconfigure()
3566 : *
3567 : * open and initialize JBM transport channel buffer
3568 : *--------------------------------------------------------------------------*/
3569 :
3570 :
3571 3499 : ivas_error ivas_jbm_dec_tc_buffer_reconfigure_fx(
3572 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
3573 : const TC_BUFFER_MODE tc_buffer_mode, /* i : new buffer mode */
3574 : const Word16 nchan_transport_jbm, /* i : new number of real transport channels */
3575 : const Word16 nchan_transport_internal, /* i : new number of totally buffered channels */
3576 : const Word16 nchan_full, /* i : new number of channels to fully store */
3577 : const Word16 n_samples_granularity /* i : new granularity of the renderer/buffer */
3578 : )
3579 : {
3580 : Word16 nsamp_to_allocate, n_samp_full, n_samp_residual, offset, nchan_residual;
3581 : Word16 ch_idx;
3582 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
3583 :
3584 3499 : hTcBuffer = st_ivas->hTcBuffer;
3585 3499 : move16();
3586 :
3587 :
3588 : /* if granularity changes, adapt subframe_nb_slots */
3589 3499 : IF( NE_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) )
3590 : {
3591 : Word16 nMaxSlotsPerSubframeNew;
3592 :
3593 642 : nMaxSlotsPerSubframeNew = idiv1616( divide3216( st_ivas->hDecoderConfig->output_Fs, ( ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) >> 1 ) ), n_samples_granularity ); // Q0
3594 : /* if samples were flushed, take that into account here */
3595 642 : test();
3596 642 : IF( LT_16( n_samples_granularity, hTcBuffer->n_samples_granularity ) && hTcBuffer->n_samples_flushed > 0 )
3597 : {
3598 22 : hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = idiv1616( hTcBuffer->n_samples_flushed, n_samples_granularity );
3599 22 : hTcBuffer->n_samples_flushed = 0;
3600 22 : move16();
3601 22 : move16();
3602 : }
3603 : ELSE
3604 : {
3605 620 : hTcBuffer->subframe_nbslots[hTcBuffer->subframes_rendered - 1] = nMaxSlotsPerSubframeNew;
3606 620 : move16();
3607 : }
3608 : }
3609 :
3610 3499 : hTcBuffer->tc_buffer_mode = tc_buffer_mode;
3611 3499 : move16();
3612 3499 : hTcBuffer->nchan_transport_jbm = nchan_transport_jbm;
3613 3499 : move16();
3614 3499 : hTcBuffer->nchan_transport_internal = nchan_transport_internal;
3615 3499 : move16();
3616 3499 : hTcBuffer->nchan_buffer_full = nchan_full;
3617 3499 : move16();
3618 3499 : nchan_residual = sub( nchan_transport_internal, nchan_full );
3619 3499 : hTcBuffer->n_samples_granularity = n_samples_granularity;
3620 3499 : move16();
3621 :
3622 : /* realloc buffers */
3623 3499 : IF( hTcBuffer->tc_buffer_fx != NULL )
3624 : {
3625 927 : free( hTcBuffer->tc_buffer_fx );
3626 927 : hTcBuffer->tc_buffer_fx = NULL;
3627 : }
3628 :
3629 3499 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3630 : {
3631 927 : n_samp_full = ( add( NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ), sub( hTcBuffer->n_samples_granularity, 1 ) ) );
3632 927 : n_samp_residual = sub( hTcBuffer->n_samples_granularity, 1 );
3633 : }
3634 : ELSE
3635 : {
3636 2572 : n_samp_full = extract_l( Mult_32_16( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 ) );
3637 2572 : n_samp_residual = 0;
3638 2572 : move16();
3639 : }
3640 3499 : nsamp_to_allocate = imult1616( hTcBuffer->nchan_buffer_full, n_samp_full );
3641 3499 : nsamp_to_allocate = add( nsamp_to_allocate, imult1616( nchan_residual, n_samp_residual ) );
3642 :
3643 3499 : IF( nsamp_to_allocate == 0 )
3644 : {
3645 292 : hTcBuffer->tc_buffer_fx = NULL;
3646 4964 : FOR( ch_idx = 0; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3647 : {
3648 4672 : hTcBuffer->tc_fx[ch_idx] = NULL;
3649 : }
3650 : }
3651 : ELSE
3652 : {
3653 3207 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3654 : {
3655 :
3656 927 : IF( ( hTcBuffer->tc_buffer_fx = (Word32 *) malloc( nsamp_to_allocate * sizeof( Word32 ) ) ) == NULL )
3657 : {
3658 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory FOR JBM TC Buffer\n" ) );
3659 : }
3660 927 : set32_fx( hTcBuffer->tc_buffer_fx, 0, nsamp_to_allocate );
3661 :
3662 927 : offset = 0;
3663 927 : move16();
3664 4492 : FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
3665 : {
3666 3565 : hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
3667 3565 : offset = add( offset, n_samp_full );
3668 : }
3669 927 : FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ )
3670 : {
3671 0 : hTcBuffer->tc_fx[ch_idx] = &hTcBuffer->tc_buffer_fx[offset];
3672 0 : offset = add( offset, n_samp_residual );
3673 : }
3674 12194 : FOR( ; ch_idx < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; ch_idx++ )
3675 : {
3676 11267 : hTcBuffer->tc_fx[ch_idx] = NULL;
3677 : }
3678 :
3679 927 : hTcBuffer->tc_buff_len = nsamp_to_allocate;
3680 927 : move16();
3681 :
3682 927 : offset = 0;
3683 927 : move16();
3684 4492 : FOR( ch_idx = 0; ch_idx < hTcBuffer->nchan_buffer_full; ch_idx++ )
3685 : {
3686 3565 : offset = add( offset, n_samp_full );
3687 : }
3688 927 : FOR( ; ch_idx < hTcBuffer->nchan_transport_internal; ch_idx++ )
3689 : {
3690 0 : offset = add( offset, n_samp_residual );
3691 : }
3692 : }
3693 : ELSE
3694 : {
3695 2280 : hTcBuffer->tc_buffer_fx = NULL;
3696 : }
3697 : }
3698 :
3699 3499 : return IVAS_ERR_OK;
3700 : }
3701 :
3702 :
3703 : /*--------------------------------------------------------------------------*
3704 : * ivas_jbm_dec_tc_buffer_playout()
3705 : *
3706 : *
3707 : *--------------------------------------------------------------------------*/
3708 :
3709 128726 : static void ivas_jbm_dec_tc_buffer_playout_fx(
3710 : Decoder_Struct *st_ivas,
3711 : const UWord16 nSamplesAsked,
3712 : UWord16 *nSamplesRendered,
3713 : Word32 *output_fx[] /*Q11*/
3714 : )
3715 : {
3716 : Word16 ch_idx, slot_size, slots_to_render, first_sf, last_sf, tmp, e;
3717 :
3718 128726 : slot_size = st_ivas->hTcBuffer->n_samples_granularity;
3719 128726 : move16();
3720 :
3721 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
3722 128726 : tmp = BASOP_Util_Divide1616_Scale( nSamplesAsked, slot_size, &e );
3723 128726 : tmp = shr( tmp, sub( 15, e ) ); // Q0
3724 128726 : slots_to_render = s_min( sub( st_ivas->hTcBuffer->num_slots, st_ivas->hTcBuffer->slots_rendered ), tmp );
3725 128726 : st_ivas->hTcBuffer->slots_rendered = add( st_ivas->hTcBuffer->slots_rendered, slots_to_render ); // Q0
3726 128726 : *nSamplesRendered = (UWord16) L_mult0( slots_to_render, slot_size );
3727 128726 : first_sf = st_ivas->hTcBuffer->subframes_rendered;
3728 128726 : last_sf = first_sf;
3729 128726 : move16();
3730 128726 : move16();
3731 128726 : move16();
3732 128726 : move16();
3733 :
3734 639859 : WHILE( slots_to_render > 0 )
3735 : {
3736 511133 : slots_to_render = sub( slots_to_render, st_ivas->hTcBuffer->subframe_nbslots[last_sf] );
3737 511133 : last_sf = add( last_sf, 1 );
3738 : }
3739 :
3740 374940 : FOR( ch_idx = 0; ch_idx < st_ivas->hTcBuffer->nchan_transport_jbm; ch_idx++ )
3741 : {
3742 246214 : Copy32( st_ivas->hTcBuffer->tc_fx[ch_idx] + st_ivas->hTcBuffer->n_samples_rendered, output_fx[ch_idx], *nSamplesRendered );
3743 : }
3744 :
3745 128726 : st_ivas->hTcBuffer->subframes_rendered = last_sf;
3746 128726 : move16();
3747 :
3748 128726 : return;
3749 : }
3750 :
3751 :
3752 : /*--------------------------------------------------------------------------*
3753 : * ivas_jbm_dec_tc_buffer_close()
3754 : *
3755 : * Close JBM transport channel buffer
3756 : *--------------------------------------------------------------------------*/
3757 :
3758 604 : void ivas_jbm_dec_tc_buffer_close(
3759 : DECODER_TC_BUFFER_HANDLE *phTcBuffer /* i/o: TC buffer handle */
3760 : )
3761 : {
3762 : Word16 i;
3763 :
3764 604 : IF( *phTcBuffer != NULL )
3765 : {
3766 10098 : FOR( i = 0; i < MAX_TRANSPORT_CHANNELS + MAX_NUM_OBJECTS; i++ )
3767 : {
3768 9504 : ( *phTcBuffer )->tc_fx[i] = NULL;
3769 : }
3770 :
3771 594 : IF( ( *phTcBuffer )->tc_buffer_fx != NULL )
3772 : {
3773 27 : free( ( *phTcBuffer )->tc_buffer_fx );
3774 27 : ( *phTcBuffer )->tc_buffer_fx = NULL;
3775 : }
3776 :
3777 594 : free( *phTcBuffer );
3778 594 : *phTcBuffer = NULL;
3779 : }
3780 :
3781 604 : return;
3782 : }
3783 :
3784 : /*--------------------------------------------------------------------------*
3785 : * ivas_jbm_dec_td_renderers_adapt_subframes()
3786 : *
3787 : * Close JBM transport channel buffer
3788 : *--------------------------------------------------------------------------*/
3789 230248 : void ivas_jbm_dec_td_renderers_adapt_subframes(
3790 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
3791 : )
3792 : {
3793 : Word16 nMaxSlotsPerSubframe, nSlotsAvailable, tmp, exp, tmp1, tmp2, s1, s2;
3794 : UWord16 nSlotsInLastSubframe, nSlotsInFirstSubframe;
3795 :
3796 : /* nMaxSlotsPerSubframe = (Word16) ( st_ivas->hDecoderConfig->output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) ) / st_ivas->hTcBuffer->n_samples_granularity; */
3797 230248 : tmp = extract_l( Mpy_32_32_r( st_ivas->hDecoderConfig->output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) );
3798 230248 : tmp = BASOP_Util_Divide1616_Scale( tmp, st_ivas->hTcBuffer->n_samples_granularity, &exp );
3799 230248 : nMaxSlotsPerSubframe = shr( tmp, sub( 15, exp ) ); // Q0
3800 :
3801 : /* nSlotsAvailable = st_ivas->hTcBuffer->n_samples_available / st_ivas->hTcBuffer->n_samples_granularity; */
3802 230248 : tmp = BASOP_Util_Divide1616_Scale( st_ivas->hTcBuffer->n_samples_available, st_ivas->hTcBuffer->n_samples_granularity, &exp );
3803 230248 : nSlotsAvailable = shr( tmp, sub( 15, exp ) ); // Q0
3804 :
3805 230248 : st_ivas->hTcBuffer->num_slots = nSlotsAvailable;
3806 230248 : move16();
3807 : /* st_ivas->hTcBuffer->n_samples_available = nSlotsAvailable * st_ivas->hTcBuffer->n_samples_granularity; */
3808 230248 : st_ivas->hTcBuffer->n_samples_available = i_mult( nSlotsAvailable, st_ivas->hTcBuffer->n_samples_granularity );
3809 230248 : move16();
3810 230248 : nSlotsInFirstSubframe = sub( nMaxSlotsPerSubframe, st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] );
3811 230248 : st_ivas->hTcBuffer->nb_subframes = 0;
3812 230248 : move16();
3813 :
3814 230248 : IF( nSlotsInFirstSubframe > 0 )
3815 : {
3816 2950 : st_ivas->hTcBuffer->nb_subframes = 1;
3817 2950 : move16();
3818 2950 : nSlotsAvailable = sub( nSlotsAvailable, nSlotsInFirstSubframe );
3819 : }
3820 :
3821 230248 : s1 = sub( norm_s( nSlotsAvailable ), 1 );
3822 230248 : s2 = norm_s( nMaxSlotsPerSubframe );
3823 :
3824 230248 : tmp1 = shl( nSlotsAvailable, s1 );
3825 230248 : tmp2 = shl( nMaxSlotsPerSubframe, s2 );
3826 :
3827 230248 : tmp = div_s( tmp1, tmp2 );
3828 230248 : st_ivas->hTcBuffer->nb_subframes = add( st_ivas->hTcBuffer->nb_subframes, ceil_fx16( tmp, sub( 15, sub( s2, s1 ) ) ) );
3829 230248 : move16();
3830 :
3831 230248 : nSlotsInLastSubframe = nSlotsAvailable % nMaxSlotsPerSubframe;
3832 230248 : move16();
3833 230248 : set16_fx( st_ivas->hTcBuffer->subframe_nbslots, 0, MAX_JBM_SUBFRAMES_5MS );
3834 230248 : set16_fx( st_ivas->hTcBuffer->subframe_nbslots, nMaxSlotsPerSubframe, st_ivas->hTcBuffer->nb_subframes );
3835 :
3836 230248 : if ( nSlotsInFirstSubframe > 0 )
3837 : {
3838 2950 : st_ivas->hTcBuffer->subframe_nbslots[0] = nSlotsInFirstSubframe;
3839 2950 : move16();
3840 : }
3841 :
3842 230248 : if ( nSlotsInLastSubframe > 0 )
3843 : {
3844 2955 : st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1] = nSlotsInLastSubframe;
3845 2955 : move16();
3846 : }
3847 :
3848 230248 : st_ivas->hTcBuffer->slots_rendered = 0;
3849 230248 : move16();
3850 230248 : st_ivas->hTcBuffer->subframes_rendered = 0;
3851 230248 : move16();
3852 :
3853 230248 : return;
3854 : }
3855 : /*--------------------------------------------------------------------------*
3856 : * ivas_jbm_dec_get_tc_buffer_mode()
3857 : *
3858 : *
3859 : *--------------------------------------------------------------------------*/
3860 :
3861 4819 : TC_BUFFER_MODE ivas_jbm_dec_get_tc_buffer_mode(
3862 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
3863 : )
3864 : {
3865 : TC_BUFFER_MODE buffer_mode;
3866 4819 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3867 4819 : move16();
3868 :
3869 4819 : SWITCH( st_ivas->renderer_type )
3870 : {
3871 : /* all renderers where we are done after TC decoding (might include DMX to mono/stereo */
3872 740 : case RENDERER_DISABLE:
3873 : case RENDERER_MCMASA_MONO_STEREO:
3874 : case RENDERER_OSBA_STEREO:
3875 : case RENDERER_MONO_DOWNMIX:
3876 740 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3877 740 : move16();
3878 740 : BREAK;
3879 3576 : case RENDERER_TD_PANNING:
3880 : case RENDERER_BINAURAL_OBJECTS_TD:
3881 : case RENDERER_BINAURAL_FASTCONV:
3882 : case RENDERER_BINAURAL_FASTCONV_ROOM:
3883 : case RENDERER_BINAURAL_PARAMETRIC:
3884 : case RENDERER_BINAURAL_PARAMETRIC_ROOM:
3885 : case RENDERER_STEREO_PARAMETRIC:
3886 : case RENDERER_DIRAC:
3887 : case RENDERER_PARAM_ISM:
3888 : case RENDERER_BINAURAL_MIXER_CONV:
3889 : case RENDERER_BINAURAL_MIXER_CONV_ROOM:
3890 : case RENDERER_OSBA_AMBI:
3891 : case RENDERER_OSBA_LS:
3892 3576 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3893 3576 : move16();
3894 3576 : BREAK;
3895 2 : case RENDERER_NON_DIEGETIC_DOWNMIX:
3896 2 : IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) )
3897 : {
3898 1 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3899 1 : move16();
3900 : }
3901 : ELSE
3902 : {
3903 1 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3904 1 : move16();
3905 : }
3906 2 : break;
3907 70 : case RENDERER_MC_PARAMMC:
3908 70 : IF( EQ_32( st_ivas->hParamMC->synthesis_conf, PARAM_MC_SYNTH_MONO_STEREO ) )
3909 : {
3910 2 : buffer_mode = TC_BUFFER_MODE_BUFFER; /* TCs are already the DMX to mono or stereo */
3911 2 : move16();
3912 : }
3913 : ELSE
3914 : {
3915 68 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3916 68 : move16();
3917 : }
3918 70 : BREAK;
3919 102 : case RENDERER_MC:
3920 102 : if ( NE_16( ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ), st_ivas->hDecoderConfig->nchan_out ) )
3921 : {
3922 95 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3923 95 : move16();
3924 : }
3925 102 : BREAK;
3926 329 : case RENDERER_SBA_LINEAR_ENC:
3927 329 : test();
3928 329 : test();
3929 329 : test();
3930 329 : test();
3931 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 ) ) ) )
3932 : {
3933 0 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3934 0 : move16();
3935 : }
3936 : ELSE
3937 : {
3938 329 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3939 329 : move16();
3940 : }
3941 329 : BREAK;
3942 0 : case RENDERER_SBA_LINEAR_DEC:
3943 0 : test();
3944 0 : test();
3945 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 ) ) )
3946 : {
3947 0 : buffer_mode = TC_BUFFER_MODE_BUFFER;
3948 0 : move16();
3949 : }
3950 : ELSE
3951 : {
3952 0 : buffer_mode = TC_BUFFER_MODE_RENDERER;
3953 0 : move16();
3954 : }
3955 0 : BREAK;
3956 : }
3957 :
3958 4819 : return buffer_mode;
3959 : }
3960 :
3961 :
3962 : /*--------------------------------------------------------------------------*
3963 : * ivas_jbm_dec_copy_tc_no_tsm()
3964 : *
3965 : *
3966 : *--------------------------------------------------------------------------*/
3967 :
3968 380574 : void ivas_jbm_dec_copy_tc_no_tsm_fx(
3969 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle Q0 */
3970 : Word32 *tc_fx[], /* i : transport channels Q11 */
3971 : const Word16 output_frame /* i : output frame size Q0 */
3972 : )
3973 : {
3974 : Word16 Q_tc;
3975 : Word16 n_ch_full_copy;
3976 : Word16 n_ch_cldfb;
3977 : Word16 ch_idx;
3978 : DECODER_TC_BUFFER_HANDLE hTcBuffer;
3979 :
3980 380574 : hTcBuffer = st_ivas->hTcBuffer;
3981 380574 : hTcBuffer->n_samples_buffered = output_frame;
3982 380574 : hTcBuffer->n_samples_available = hTcBuffer->n_samples_buffered;
3983 380574 : move16();
3984 380574 : move16();
3985 380574 : n_ch_full_copy = s_min( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
3986 380574 : n_ch_cldfb = sub( hTcBuffer->nchan_transport_jbm, hTcBuffer->nchan_buffer_full );
3987 :
3988 380574 : Q_tc = 11; /*tc buffer is at Q11*/
3989 380574 : move16();
3990 : /* copy full tcs*/
3991 380574 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3992 : {
3993 0 : FOR( ch_idx = 0; ch_idx < n_ch_full_copy; ch_idx++ )
3994 : {
3995 0 : Copy32( tc_fx[ch_idx], st_ivas->hTcBuffer->tc_fx[ch_idx], hTcBuffer->n_samples_buffered ); // keeping tc_fx in Q11
3996 : }
3997 : }
3998 380574 : ch_idx = 0;
3999 380574 : move16();
4000 :
4001 : /* CLDFB ana for ParamMC/ParamISM */
4002 380574 : IF( n_ch_cldfb > 0 )
4003 : {
4004 : Word32 *cldfb_real_buffer_fx;
4005 : Word32 *cldfb_imag_buffer_fx;
4006 : Word16 cldfb_ch, slot_idx, num_freq_bands;
4007 :
4008 12507 : cldfb_real_buffer_fx = NULL;
4009 12507 : cldfb_imag_buffer_fx = NULL;
4010 12507 : num_freq_bands = 0;
4011 12507 : move16();
4012 :
4013 12507 : IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) ISM_FORMAT ) )
4014 : {
4015 3747 : cldfb_real_buffer_fx = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_RealBuffer_tc_fx;
4016 3747 : cldfb_imag_buffer_fx = st_ivas->hParamIsmDec->hParamIsmRendering->Cldfb_ImagBuffer_tc_fx;
4017 3747 : num_freq_bands = st_ivas->hSpatParamRendCom->num_freq_bands;
4018 3747 : move16();
4019 :
4020 3747 : ivas_ism_param_dec_tc_gain_ajust_fx( st_ivas, output_frame, output_frame / 2, tc_fx, &Q_tc );
4021 3747 : Scale_sig32( tc_fx[0], output_frame, sub( Q11, Q_tc ) ); /*keepeing tc_fx at Q11*/
4022 3747 : Scale_sig32( tc_fx[1], output_frame, sub( Q11, Q_tc ) ); /*keepeing tc_fx at Q11*/
4023 : }
4024 8760 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) MC_FORMAT ) )
4025 : {
4026 8760 : cldfb_real_buffer_fx = st_ivas->hParamMC->Cldfb_RealBuffer_tc_fx;
4027 8760 : cldfb_imag_buffer_fx = st_ivas->hParamMC->Cldfb_ImagBuffer_tc_fx;
4028 8760 : num_freq_bands = st_ivas->hParamMC->num_freq_bands;
4029 8760 : move16();
4030 : }
4031 : /* CLDFB Analysis*/
4032 :
4033 37561 : FOR( cldfb_ch = 0; cldfb_ch < n_ch_cldfb; ( cldfb_ch++, ch_idx++ ) )
4034 : {
4035 425918 : FOR( slot_idx = 0; slot_idx < DEFAULT_JBM_CLDFB_TIMESLOTS; slot_idx++ )
4036 : {
4037 400864 : Q_tc = 11;
4038 400864 : move16();
4039 400864 : cldfbAnalysis_ts_fx_fixed_q( &( tc_fx[ch_idx][num_freq_bands * slot_idx] ),
4040 400864 : &cldfb_real_buffer_fx[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
4041 400864 : &cldfb_imag_buffer_fx[slot_idx * num_freq_bands * n_ch_cldfb + cldfb_ch * num_freq_bands],
4042 : num_freq_bands, st_ivas->cldfbAnaDec[cldfb_ch], &Q_tc );
4043 400864 : IF( EQ_16( (Word16) st_ivas->ivas_format, (Word16) MC_FORMAT ) )
4044 : {
4045 280960 : st_ivas->hParamMC->Cldfb_RealBuffer_tc_e = sub( 31, Q_tc );
4046 280960 : st_ivas->hParamMC->Cldfb_ImagBuffer_tc_e = sub( 31, Q_tc );
4047 280960 : move16();
4048 280960 : move16();
4049 : }
4050 : }
4051 : }
4052 : }
4053 380574 : hTcBuffer->n_samples_rendered = 0;
4054 380574 : move16();
4055 380574 : hTcBuffer->subframes_rendered = 0;
4056 380574 : move16();
4057 :
4058 380574 : return;
4059 : }
4060 :
4061 : /*--------------------------------------------------------------------------*
4062 : * ivas_jbm_dec_metadata_open()
4063 : *
4064 : * Open structure for metadata buffering in JBM
4065 : *--------------------------------------------------------------------------*/
4066 :
4067 44 : ivas_error ivas_jbm_dec_metadata_open(
4068 : Decoder_Struct *st_ivas )
4069 : {
4070 : JBM_METADATA_HANDLE hJbmMetadata;
4071 44 : IF( ( hJbmMetadata = (JBM_METADATA_HANDLE) malloc( sizeof( JBM_METADATA ) ) ) == NULL )
4072 : {
4073 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for JBM metadata handle\n" ) );
4074 : }
4075 44 : hJbmMetadata->sf_write_idx = 0;
4076 44 : move16();
4077 44 : hJbmMetadata->sf_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_PARAM_SPATIAL_SUBFRAMES;
4078 44 : move16();
4079 :
4080 44 : hJbmMetadata->slot_write_idx = 0;
4081 44 : move16();
4082 44 : hJbmMetadata->slot_read_idx = 0;
4083 44 : move16();
4084 44 : hJbmMetadata->slot_md_buffer_length = MASA_JBM_RINGBUFFER_FRAMES * MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME;
4085 44 : move16();
4086 :
4087 44 : st_ivas->hJbmMetadata = hJbmMetadata;
4088 :
4089 44 : return IVAS_ERR_OK;
4090 : }
4091 :
4092 :
4093 : /*--------------------------------------------------------------------------*
4094 : * ivas_jbm_dec_copy_masa_meta_to_buffer()
4095 : *
4096 : * Copy decoded MASA metadata to a ring buffer
4097 : *--------------------------------------------------------------------------*/
4098 :
4099 5462 : static void ivas_jbm_dec_copy_masa_meta_to_buffer(
4100 : Decoder_Struct *st_ivas )
4101 : {
4102 : Word16 sf, dir, band;
4103 : JBM_METADATA_HANDLE hJbmMetadata;
4104 : MASA_DECODER_EXT_OUT_META *extOutMeta;
4105 : Word16 write_idx;
4106 :
4107 5462 : hJbmMetadata = st_ivas->hJbmMetadata;
4108 5462 : extOutMeta = st_ivas->hMasa->data.extOutMeta;
4109 :
4110 27310 : FOR( sf = 0; sf < MAX_PARAM_SPATIAL_SUBFRAMES; sf++ )
4111 : {
4112 21848 : write_idx = ( hJbmMetadata->sf_write_idx + sf ) % hJbmMetadata->sf_md_buffer_length;
4113 21848 : move16();
4114 65544 : FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
4115 : {
4116 1092400 : FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
4117 : {
4118 1048704 : hJbmMetadata->directionIndexBuffer[dir][write_idx][band] = extOutMeta->directionIndex[dir][sf][band];
4119 1048704 : move16();
4120 1048704 : hJbmMetadata->directToTotalRatioBuffer[dir][write_idx][band] = extOutMeta->directToTotalRatio[dir][sf][band];
4121 1048704 : move16();
4122 1048704 : hJbmMetadata->spreadCoherenceBuffer[dir][write_idx][band] = extOutMeta->spreadCoherence[dir][sf][band];
4123 1048704 : move16();
4124 : }
4125 : }
4126 :
4127 546200 : FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
4128 : {
4129 524352 : hJbmMetadata->diffuseToTotalRatioBuffer[write_idx][band] = extOutMeta->diffuseToTotalRatio[sf][band];
4130 524352 : move16();
4131 524352 : hJbmMetadata->surroundCoherenceBuffer[write_idx][band] = extOutMeta->surroundCoherence[sf][band];
4132 524352 : move16();
4133 : }
4134 :
4135 21848 : hJbmMetadata->numberOfDirections[write_idx] = extOutMeta->descriptiveMeta.numberOfDirections;
4136 21848 : move16();
4137 : }
4138 :
4139 5462 : return;
4140 : }
4141 :
4142 :
4143 : /*--------------------------------------------------------------------------*
4144 : * ivas_jbm_masa_sf_to_slot_map()
4145 : *
4146 : * Map input MASA metadata subframes to slots in JBM processing
4147 : *--------------------------------------------------------------------------*/
4148 5462 : static void ivas_jbm_masa_sf_to_slot_map(
4149 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
4150 : const Word16 nCldfbTs /* i : number of CLDFB time slots */
4151 : )
4152 : {
4153 : Word16 sf_to_slot_map[MAX_JBM_SUBFRAMES_5MS * JBM_CLDFB_SLOTS_IN_SUBFRAME];
4154 : Word16 num_slots_in_subfr;
4155 : JBM_METADATA_HANDLE hJbmMetadata;
4156 : Word16 slot_idx;
4157 : Word16 write_idx, sf_index;
4158 :
4159 : /* Set values */
4160 5462 : hJbmMetadata = st_ivas->hJbmMetadata;
4161 5462 : num_slots_in_subfr = CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES;
4162 5462 : move16();
4163 :
4164 : /* Map input subframes to slots */
4165 5462 : ivas_jbm_dec_get_md_map_even_spacing( nCldfbTs, num_slots_in_subfr, 0, MAX_PARAM_SPATIAL_SUBFRAMES, sf_to_slot_map );
4166 :
4167 92874 : FOR( slot_idx = 0; slot_idx < nCldfbTs; slot_idx++ )
4168 : {
4169 87412 : write_idx = ( add( hJbmMetadata->slot_write_idx, slot_idx ) ) % hJbmMetadata->slot_md_buffer_length;
4170 87412 : move16();
4171 87412 : sf_index = ( add( hJbmMetadata->sf_write_idx, sf_to_slot_map[slot_idx] ) ) % hJbmMetadata->sf_md_buffer_length;
4172 87412 : move16();
4173 :
4174 87412 : hJbmMetadata->sf_to_slot_map[write_idx] = sf_index;
4175 87412 : move16();
4176 : }
4177 :
4178 5462 : hJbmMetadata->sf_write_idx = ( add( hJbmMetadata->sf_write_idx, MAX_PARAM_SPATIAL_SUBFRAMES ) ) % hJbmMetadata->sf_md_buffer_length;
4179 5462 : move16();
4180 5462 : hJbmMetadata->slot_write_idx = ( add( hJbmMetadata->slot_write_idx, nCldfbTs ) ) % hJbmMetadata->slot_md_buffer_length;
4181 5462 : move16();
4182 :
4183 5462 : return;
4184 : }
4185 :
4186 : /*--------------------------------------------------------------------------*
4187 : * ivas_jbm_masa_sf_to_sf_map()
4188 : *
4189 : * Map input MASA metadata subframes to output subframes in JBM processing
4190 : *--------------------------------------------------------------------------*/
4191 :
4192 1308 : void ivas_jbm_masa_sf_to_sf_map(
4193 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
4194 : )
4195 : {
4196 : Word16 sf_to_sf_map[MAX_PARAM_SPATIAL_SUBFRAMES];
4197 : JBM_METADATA_HANDLE hJbmMetadata;
4198 : MASA_DECODER_EXT_OUT_META *extOutMeta;
4199 : Word16 slot_read_idx, sf_read_idx;
4200 : Word16 sf_idx;
4201 : Word16 dir, band;
4202 : UWord8 numberOfDirections;
4203 :
4204 : /* Set values */
4205 1308 : hJbmMetadata = st_ivas->hJbmMetadata;
4206 1308 : extOutMeta = st_ivas->hMasa->data.extOutMeta;
4207 :
4208 : /* Map slots to subframes */
4209 6540 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
4210 : {
4211 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 */
4212 5232 : move16();
4213 5232 : sf_to_sf_map[sf_idx] = hJbmMetadata->sf_to_slot_map[slot_read_idx];
4214 5232 : move16();
4215 5232 : hJbmMetadata->slot_read_idx = ( add( hJbmMetadata->slot_read_idx, CLDFB_SLOTS_PER_SUBFRAME ) ) % hJbmMetadata->slot_md_buffer_length;
4216 5232 : move16();
4217 : }
4218 :
4219 : /* Copy mapped metadata to the EXT meta buffer for writing */
4220 6540 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
4221 : {
4222 5232 : sf_read_idx = sf_to_sf_map[sf_idx];
4223 5232 : move16();
4224 :
4225 15696 : FOR( dir = 0; dir < MASA_MAXIMUM_DIRECTIONS; dir++ )
4226 : {
4227 261600 : FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
4228 : {
4229 251136 : extOutMeta->directionIndex[dir][sf_idx][band] = hJbmMetadata->directionIndexBuffer[dir][sf_read_idx][band];
4230 251136 : move16();
4231 251136 : extOutMeta->directToTotalRatio[dir][sf_idx][band] = hJbmMetadata->directToTotalRatioBuffer[dir][sf_read_idx][band];
4232 251136 : move16();
4233 251136 : extOutMeta->spreadCoherence[dir][sf_idx][band] = hJbmMetadata->spreadCoherenceBuffer[dir][sf_read_idx][band];
4234 251136 : move16();
4235 : }
4236 : }
4237 :
4238 130800 : FOR( band = 0; band < MASA_FREQUENCY_BANDS; band++ )
4239 : {
4240 125568 : extOutMeta->diffuseToTotalRatio[sf_idx][band] = hJbmMetadata->diffuseToTotalRatioBuffer[sf_read_idx][band];
4241 125568 : move16();
4242 125568 : extOutMeta->surroundCoherence[sf_idx][band] = hJbmMetadata->surroundCoherenceBuffer[sf_read_idx][band];
4243 125568 : move16();
4244 : }
4245 : }
4246 :
4247 : /* Determine the number of directions for the frame to be written */
4248 1308 : numberOfDirections = 0;
4249 1308 : move16();
4250 5594 : FOR( sf_idx = 0; sf_idx < MAX_PARAM_SPATIAL_SUBFRAMES; sf_idx++ )
4251 : {
4252 4524 : sf_read_idx = sf_to_sf_map[sf_idx];
4253 4524 : move16();
4254 :
4255 4524 : IF( hJbmMetadata->numberOfDirections[sf_read_idx] == 1 )
4256 : {
4257 238 : numberOfDirections = 1;
4258 238 : move16();
4259 238 : BREAK;
4260 : }
4261 : }
4262 :
4263 1308 : extOutMeta->descriptiveMeta.numberOfDirections = numberOfDirections;
4264 1308 : move16();
4265 :
4266 1308 : return;
4267 : }
|