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