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 "enh32.h"
34 : #include <assert.h>
35 : #include <stdint.h>
36 : #include "options.h"
37 : #include "cnst.h"
38 : #include "ivas_cnst.h"
39 : #include "prot_fx.h"
40 : #include "ivas_prot_rend_fx.h"
41 : #include "rom_com.h"
42 : #include "ivas_rom_com.h"
43 : #include "ivas_rom_dec.h"
44 : #include <math.h>
45 : #include "wmc_auto.h"
46 : #include "ivas_prot_fx.h"
47 : /*-------------------------------------------------------------------*
48 : * ivas_sba_set_cna_cng_flag()
49 : *
50 : * Set CNA/CNG flags in IVAS SBA decoder
51 : *-------------------------------------------------------------------*/
52 4309 : void ivas_sba_set_cna_cng_flag(
53 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
54 : )
55 : {
56 : Word16 n, cpe_id;
57 4309 : test();
58 4309 : test();
59 4309 : test();
60 4309 : test();
61 4309 : test();
62 4309 : test();
63 4309 : test();
64 4309 : IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) && EQ_16( st_ivas->nchan_transport, 1 ) )
65 : {
66 : /* skip as done in init function */
67 : /* st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 0; */
68 : /* st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 0; */
69 : }
70 3796 : ELSE IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && EQ_16( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) || ( 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 ) ) ) )
71 : {
72 226 : st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag = 1;
73 226 : move16();
74 226 : st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag = 1;
75 226 : move16();
76 : }
77 3570 : ELSE IF( EQ_16( st_ivas->nchan_transport, 2 ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
78 : {
79 7203 : FOR( n = 0; n < CPE_CHANNELS; n++ )
80 : {
81 4802 : st_ivas->hCPE[0]->hCoreCoder[n]->cna_dirac_flag = 0;
82 4802 : move16();
83 4802 : st_ivas->hCPE[0]->hCoreCoder[n]->cng_sba_flag = 1;
84 4802 : move16();
85 : }
86 : }
87 : ELSE
88 : {
89 3693 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
90 : {
91 7572 : FOR( n = 0; n < CPE_CHANNELS; n++ )
92 : {
93 5048 : st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cna_dirac_flag = 0;
94 5048 : move16();
95 5048 : st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 0;
96 5048 : move16();
97 : }
98 : }
99 : }
100 :
101 4309 : return;
102 : }
103 :
104 : /*-------------------------------------------------------------------*
105 : * ivas_sba_dec_reconfigure_fx()
106 : *
107 : * Reconfigure IVAS SBA decoder
108 : *-------------------------------------------------------------------*/
109 :
110 1872 : ivas_error ivas_sba_dec_reconfigure_fx(
111 : Decoder_Struct *st_ivas /* i/o: IVAS decoder structure */
112 : )
113 : {
114 : Word16 nchan_transport_old, nSCE_old, nCPE_old, nchan_hp20_old;
115 : AUDIO_CONFIG intern_config_old;
116 : Word16 numCldfbAnalyses_old, numCldfbSyntheses_old;
117 : Word16 sba_dirac_stereo_flag_old;
118 : Word32 ivas_total_brate;
119 : Word32 last_ivas_total_brate;
120 : Word16 num_channels, num_md_sub_frames;
121 : Word16 nchan_out_buff;
122 : DECODER_CONFIG_HANDLE hDecoderConfig;
123 : ivas_error error;
124 : ISM_MODE ism_mode_old;
125 : Word16 granularity_new;
126 : Word16 nchan_transport;
127 :
128 1872 : ism_mode_old = st_ivas->ism_mode;
129 1872 : hDecoderConfig = st_ivas->hDecoderConfig;
130 1872 : ivas_total_brate = hDecoderConfig->ivas_total_brate;
131 1872 : move32();
132 1872 : last_ivas_total_brate = st_ivas->last_active_ivas_total_brate;
133 1872 : move32();
134 :
135 : /*-----------------------------------------------------------------*
136 : * Set SBA high-level parameters
137 : * Save old SBA high-level parameters
138 : *-----------------------------------------------------------------*/
139 :
140 1872 : ivas_init_dec_get_num_cldfb_instances_fx( st_ivas, &numCldfbAnalyses_old, &numCldfbSyntheses_old );
141 1872 : nchan_hp20_old = getNumChanSynthesis( st_ivas );
142 :
143 1872 : IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
144 : {
145 744 : IF( EQ_16( ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->nchan_ism ), ISM_SBA_MODE_DISC ) )
146 : {
147 291 : st_ivas->ism_mode = ISM_SBA_MODE_DISC;
148 291 : move16();
149 : }
150 : ELSE
151 : {
152 453 : st_ivas->ism_mode = ISM_MODE_NONE;
153 453 : move16();
154 : }
155 : }
156 : ELSE
157 : {
158 1128 : st_ivas->ism_mode = ISM_MODE_NONE;
159 1128 : move16();
160 : }
161 :
162 1872 : nSCE_old = st_ivas->nSCE;
163 1872 : move16();
164 1872 : nCPE_old = st_ivas->nCPE;
165 1872 : move16();
166 1872 : nchan_transport_old = st_ivas->nchan_transport;
167 1872 : move16();
168 1872 : sba_dirac_stereo_flag_old = st_ivas->sba_dirac_stereo_flag;
169 1872 : move16();
170 :
171 1872 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->sba_order );
172 :
173 1872 : granularity_new = st_ivas->hTcBuffer->n_samples_granularity; /*Q0*/
174 1872 : move16();
175 :
176 : /* we may need to flush only for binaural and OSBA and TSM */
177 1872 : test();
178 1872 : test();
179 1872 : test();
180 1872 : IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) )
181 : {
182 : /* determine new granularity */
183 562 : granularity_new = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, ivas_renderer_secondary_select_fx( st_ivas ), st_ivas->hDecoderConfig->output_Fs );
184 :
185 : /* flush renderer on granularity change form 5ms to 1.25ms, again only possible for binaural rendering */
186 562 : IF( LT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
187 : {
188 : /* flush already done in IVAS_DEC_ReadFormat() */
189 : }
190 407 : ELSE IF( GT_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
191 : {
192 160 : if ( NE_32( ( error = ivas_jbm_dec_set_discard_samples_fx( st_ivas ) ), IVAS_ERR_OK ) )
193 : {
194 0 : return error;
195 : }
196 :
197 : /* make sure the changed number of slots in the last subframe is not lost in the following steps */
198 160 : IF( st_ivas->hSpatParamRendCom != NULL )
199 : {
200 160 : st_ivas->hSpatParamRendCom->subframe_nbslots[st_ivas->hSpatParamRendCom->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; /*Q0*/
201 160 : move32();
202 : }
203 160 : st_ivas->hSpar->subframe_nbslots[st_ivas->hSpar->nb_subframes - 1] = st_ivas->hTcBuffer->subframe_nbslots[st_ivas->hTcBuffer->nb_subframes - 1]; /*Q0*/
204 160 : move32();
205 : }
206 : }
207 :
208 : /* save old */
209 1872 : IF( NE_16( ism_mode_old, ISM_SBA_MODE_DISC ) && NE_16( st_ivas->hTcBuffer->tc_buffer_mode, TC_BUFFER_MODE_BUFFER ) )
210 : {
211 1350 : test();
212 1350 : IF( st_ivas->hDirAC == NULL && st_ivas->hSpar != NULL )
213 : {
214 294 : st_ivas->hTcBuffer->num_slots = st_ivas->hSpar->num_slots;
215 294 : move16();
216 294 : st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpar->nb_subframes;
217 294 : move16();
218 294 : st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpar->slots_rendered;
219 294 : move16();
220 294 : st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpar->subframes_rendered;
221 294 : move16();
222 294 : Copy( st_ivas->hSpar->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
223 : }
224 1056 : ELSE IF( st_ivas->hSpatParamRendCom != NULL )
225 : {
226 1056 : st_ivas->hTcBuffer->num_slots = st_ivas->hSpatParamRendCom->num_slots;
227 1056 : move16();
228 1056 : st_ivas->hTcBuffer->nb_subframes = st_ivas->hSpatParamRendCom->nb_subframes;
229 1056 : move16();
230 1056 : st_ivas->hTcBuffer->slots_rendered = st_ivas->hSpatParamRendCom->slots_rendered;
231 1056 : move16();
232 1056 : st_ivas->hTcBuffer->subframes_rendered = st_ivas->hSpatParamRendCom->subframes_rendered;
233 1056 : move16();
234 1056 : Copy( st_ivas->hSpatParamRendCom->subframe_nbslots, st_ivas->hTcBuffer->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
235 : }
236 : }
237 :
238 : /*-----------------------------------------------------------------*
239 : * Allocate, initialize, and configure SBA handles
240 : *-----------------------------------------------------------------*/
241 :
242 : Word16 sba_order_internal;
243 : SPAR_DEC_HANDLE hSpar;
244 1872 : hSpar = st_ivas->hSpar;
245 :
246 1872 : sba_order_internal = s_min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); /*Q0*/
247 :
248 1872 : IF( hSpar != NULL )
249 : {
250 1872 : test();
251 1872 : test();
252 1872 : IF( ( hSpar->hPCA != NULL ) && ( NE_32( hDecoderConfig->ivas_total_brate, PCA_BRATE ) || NE_16( st_ivas->sba_order, 1 ) ) )
253 : {
254 16 : free( st_ivas->hSpar->hPCA );
255 16 : hSpar->hPCA = NULL;
256 : }
257 :
258 1872 : test();
259 1872 : test();
260 1872 : test();
261 1872 : test();
262 1872 : test();
263 1872 : IF( NE_16( nchan_transport_old, ivas_get_sba_num_TCs_fx( ivas_total_brate, sba_order_internal ) ) || ( GE_32( last_ivas_total_brate, IVAS_512k ) && LT_32( ivas_total_brate, IVAS_512k ) ) || ( LT_32( last_ivas_total_brate, IVAS_512k ) && GE_32( ivas_total_brate, IVAS_512k ) ) )
264 : {
265 1516 : ivas_spar_dec_close_fx( &( st_ivas->hSpar ), hDecoderConfig->output_Fs, 1 );
266 :
267 1516 : if ( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 1 ) ), IVAS_ERR_OK ) )
268 : {
269 0 : return error;
270 : }
271 : }
272 356 : ELSE IF( LT_32( last_ivas_total_brate, IVAS_24k4 ) && GE_32( ivas_total_brate, IVAS_24k4 ) )
273 : {
274 51 : num_channels = st_ivas->hSpar->hMdDec->spar_md_cfg.num_umx_chs; /*Q0*/
275 51 : move16();
276 51 : ivas_spar_md_dec_matrix_close_fx( st_ivas->hSpar->hMdDec, num_channels );
277 :
278 51 : num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( sba_order_internal, ivas_total_brate, st_ivas->last_active_ivas_total_brate );
279 51 : if ( NE_32( ( error = ivas_spar_md_dec_matrix_open_fx( st_ivas->hSpar->hMdDec, num_channels, num_md_sub_frames ) ), IVAS_ERR_OK ) )
280 : {
281 0 : return error;
282 : }
283 : }
284 :
285 1872 : test();
286 1872 : test();
287 1872 : test();
288 1872 : test();
289 1872 : IF( hSpar->hPCA == NULL && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, PCA_BRATE ) && EQ_16( st_ivas->sba_order, 1 ) && ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) )
290 : {
291 0 : IF( ( hSpar->hPCA = (PCA_DEC_STATE *) malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL )
292 : {
293 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" );
294 : }
295 :
296 0 : ivas_pca_dec_init_fx( hSpar->hPCA );
297 : }
298 :
299 1872 : ivas_spar_config_fx( ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format );
300 : }
301 : ELSE
302 : {
303 0 : if ( NE_32( ( error = ivas_spar_dec_open_fx( st_ivas, 0 ) ), IVAS_ERR_OK ) )
304 : {
305 0 : return error;
306 : }
307 : }
308 :
309 1872 : hSpar = st_ivas->hSpar;
310 1872 : st_ivas->sba_dirac_stereo_flag = ivas_get_sba_dirac_stereo_flag( st_ivas );
311 1872 : move16();
312 :
313 1872 : IF( EQ_16( st_ivas->nchan_transport, 1 ) )
314 : {
315 674 : st_ivas->element_mode_init = IVAS_SCE;
316 674 : move16();
317 : }
318 : ELSE
319 : {
320 1198 : st_ivas->element_mode_init = IVAS_CPE_MDCT;
321 1198 : move16();
322 : }
323 :
324 : /*-----------------------------------------------------------------*
325 : * Renderer selection
326 : *-----------------------------------------------------------------*/
327 :
328 : /* renderer might have changed */
329 1872 : intern_config_old = st_ivas->intern_config;
330 1872 : move16();
331 1872 : ivas_renderer_select( st_ivas );
332 :
333 : /* side effect of the renderer selection can be a changed internal config */
334 1872 : IF( NE_16( st_ivas->intern_config, intern_config_old ) )
335 : {
336 388 : ivas_output_init( &( st_ivas->hIntSetup ), st_ivas->intern_config );
337 : }
338 :
339 : /*-------------------------------------------------------------------*
340 : * Reallocate and initialize binaural rendering handles
341 : *--------------------------------------------------------------------*/
342 :
343 1872 : test();
344 1872 : test();
345 1872 : test();
346 1872 : test();
347 1872 : IF( st_ivas->hBinRenderer == NULL && ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
348 : {
349 : /* open fastconv binaural renderer */
350 197 : IF( NE_32( ( error = ivas_binRenderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
351 : {
352 0 : return error;
353 : }
354 : }
355 1675 : ELSE IF( st_ivas->hBinRenderer != NULL && ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ) )
356 : {
357 191 : ivas_binRenderer_close_fx( &st_ivas->hBinRenderer );
358 : }
359 :
360 1872 : IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) && st_ivas->hMonoDmxRenderer == NULL )
361 : {
362 0 : IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
363 : {
364 0 : return error;
365 : }
366 : }
367 :
368 1872 : IF( NE_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
369 : {
370 1872 : ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
371 : }
372 :
373 1872 : IF( NE_32( ( error = ivas_dirac_sba_config_fx( st_ivas->hQMetaData, &st_ivas->element_mode_init, ivas_total_brate, st_ivas->sba_analysis_order, ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) ? IVAS_MAX_NUM_BANDS : ( IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ), st_ivas->ivas_format ) ), IVAS_ERR_OK ) )
374 : {
375 0 : return error;
376 : }
377 :
378 1872 : IF( ( ( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) ) && ( NE_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) ) ) || ( ( NE_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_FOA ) ) && ( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) && ( NE_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) ) ) )
379 1343 : {
380 : DIRAC_CONFIG_FLAG flag_config;
381 :
382 1343 : flag_config = DIRAC_OPEN;
383 1343 : if ( st_ivas->hDirAC != NULL )
384 : {
385 1315 : flag_config = DIRAC_RECONFIGURE_MODE;
386 : }
387 :
388 1343 : IF( NE_32( ( error = ivas_dirac_dec_config_fx( st_ivas, flag_config ) ), IVAS_ERR_OK ) )
389 : {
390 0 : return error;
391 : }
392 : }
393 : ELSE
394 : {
395 : Word16 band_grouping[IVAS_MAX_NUM_BANDS + 1];
396 :
397 529 : st_ivas->hSpar->enc_param_start_band = s_min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); /*Q0*/
398 529 : move16();
399 529 : IF( ivas_get_hodirac_flag_fx( ivas_total_brate, st_ivas->sba_analysis_order ) )
400 : {
401 44 : st_ivas->hSpar->enc_param_start_band = 0;
402 44 : move16();
403 :
404 44 : set_c( (Word8 *) st_ivas->hQMetaData->twoDirBands, (Word8) 1, st_ivas->hQMetaData->q_direction[0].cfg.nbands ); /*Q0*/
405 44 : st_ivas->hQMetaData->numTwoDirBands = (UWord8) st_ivas->hQMetaData->q_direction[0].cfg.nbands;
406 44 : move16();
407 : }
408 :
409 529 : ivas_dirac_config_bands_fx( band_grouping, IVAS_MAX_NUM_BANDS, (Word16) ( L_add( st_ivas->hDecoderConfig->output_Fs, 400 ) / CLDFB_BANDWIDTH ),
410 529 : st_ivas->hSpar->dirac_to_spar_md_bands, st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->enc_param_start_band, 0, 1 );
411 :
412 529 : if ( st_ivas->hDirAC )
413 : {
414 25 : st_ivas->hDirAC->hConfig->enc_param_start_band = st_ivas->hSpar->enc_param_start_band;
415 25 : move16();
416 : }
417 : }
418 :
419 1872 : IF( EQ_16( st_ivas->renderer_type, RENDERER_DISABLE ) )
420 : {
421 237 : ivas_dirac_rend_close_fx( &( st_ivas->hDirACRend ) );
422 237 : ivas_spat_hSpatParamRendCom_close_fx( &( st_ivas->hSpatParamRendCom ) );
423 237 : ivas_dirac_dec_close_fx( &( st_ivas->hDirAC ) );
424 237 : vbap_free_data_fx( &( st_ivas->hVBAPdata ) );
425 : }
426 :
427 1872 : if ( st_ivas->hDirAC != NULL )
428 : {
429 1343 : st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band;
430 1343 : move16();
431 : }
432 :
433 : /*-----------------------------------------------------------------*
434 : * Allocate, initialize, and configure SCE/CPE/MCT handles
435 : *-----------------------------------------------------------------*/
436 :
437 1872 : nchan_transport = st_ivas->nchan_transport;
438 1872 : move16();
439 1872 : IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
440 : {
441 744 : test();
442 744 : test();
443 744 : IF( EQ_16( ism_mode_old, ISM_MODE_NONE ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
444 212 : {
445 : Word32 temp_brate[MAX_SCE];
446 :
447 212 : st_ivas->ism_mode = ISM_SBA_MODE_DISC;
448 212 : move16();
449 :
450 212 : IF( NE_32( ( error = ivas_ism_metadata_dec_create_fx( st_ivas, st_ivas->nchan_ism, temp_brate ) ), IVAS_ERR_OK ) )
451 : {
452 0 : return error;
453 : }
454 :
455 212 : test();
456 212 : test();
457 212 : test();
458 212 : test();
459 212 : test();
460 212 : test();
461 212 : test();
462 212 : test();
463 212 : IF( ( EQ_16( st_ivas->renderer_type, RENDERER_TD_PANNING ) ||
464 : EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) ||
465 : EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_ENC ) ||
466 : EQ_16( st_ivas->renderer_type, RENDERER_OSBA_STEREO ) ||
467 : EQ_16( st_ivas->renderer_type, RENDERER_OSBA_AMBI ) ||
468 : EQ_16( st_ivas->renderer_type, RENDERER_OSBA_LS ) ||
469 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
470 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
471 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_MIXER_CONV_ROOM ) ) )
472 : {
473 186 : IF( NE_32( ( error = ivas_ism_renderer_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
474 : {
475 0 : return error;
476 : }
477 : }
478 :
479 212 : IF( EQ_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
480 : {
481 0 : IF( st_ivas->hMonoDmxRenderer == NULL )
482 : {
483 0 : IF( NE_32( ( error = ivas_mono_dmx_renderer_open( st_ivas ) ), IVAS_ERR_OK ) )
484 : {
485 0 : return error;
486 : }
487 : }
488 : }
489 : ELSE
490 : {
491 212 : ivas_mono_dmx_renderer_close( &st_ivas->hMonoDmxRenderer );
492 : }
493 :
494 212 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) )
495 : {
496 : /* Allocate TD renderer for the objects in DISC mode */
497 160 : IF( st_ivas->hBinRendererTd == NULL )
498 : {
499 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
500 : Word16 num_src;
501 160 : IF( NE_32( ( error = ivas_td_binaural_open_fx( st_ivas, SrcInd, &num_src ) ), IVAS_ERR_OK ) )
502 : {
503 0 : return error;
504 : }
505 160 : IF( EQ_32( st_ivas->hOutSetup.output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) )
506 : {
507 50 : IF( NE_32( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, st_ivas->hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ), IVAS_ERR_OK ) )
508 : {
509 0 : return error;
510 : }
511 : }
512 : }
513 : }
514 :
515 : /* Allocate memory for OSBA delay buffer */
516 212 : IF( NE_32( ( error = ivas_osba_data_open_fx( st_ivas ) ), IVAS_ERR_OK ) )
517 : {
518 0 : return error;
519 : }
520 :
521 212 : nchan_transport = add( nchan_transport, st_ivas->nchan_ism );
522 212 : st_ivas->nCPE = shr_r( nchan_transport, 1 );
523 212 : move16();
524 : }
525 532 : ELSE IF( EQ_16( ism_mode_old, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->ism_mode, ISM_MODE_NONE ) )
526 : {
527 : /* ISM renderer handle */
528 205 : ivas_ism_renderer_close( &st_ivas->hIsmRendererData );
529 205 : ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 );
530 205 : ivas_osba_data_close_fx( &st_ivas->hSbaIsmData );
531 :
532 : /* Time Domain binaural renderer handle */
533 205 : IF( st_ivas->hBinRendererTd != NULL )
534 : {
535 155 : ivas_td_binaural_close_fx( &st_ivas->hBinRendererTd );
536 : }
537 :
538 205 : nchan_transport = st_ivas->nchan_transport;
539 205 : move16();
540 205 : nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism ); /*Q0*/
541 205 : st_ivas->ism_mode = ISM_MODE_NONE;
542 205 : move16();
543 : }
544 327 : ELSE IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
545 : {
546 79 : nchan_transport = add( st_ivas->nchan_transport, st_ivas->nchan_ism );
547 79 : st_ivas->nCPE = shr_r( nchan_transport, 1 );
548 79 : nchan_transport_old = add( nchan_transport_old, st_ivas->nchan_ism );
549 : }
550 : }
551 :
552 1872 : IF( NE_32( ( error = ivas_corecoder_dec_reconfig_fx( st_ivas, nSCE_old, nCPE_old, nchan_transport_old, sba_dirac_stereo_flag_old, st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport, ( st_ivas->hDecoderConfig->ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ), IVAS_ERR_OK ) )
553 : {
554 0 : return error;
555 : }
556 :
557 : /*-----------------------------------------------------------------*
558 : * HP20 memories
559 : *-----------------------------------------------------------------*/
560 :
561 1872 : IF( NE_32( ( error = ivas_hp20_dec_reconfig_fx( st_ivas, nchan_hp20_old ) ), IVAS_ERR_OK ) )
562 : {
563 0 : return error;
564 : }
565 :
566 : /*-----------------------------------------------------------------*
567 : * TD Decorrelator
568 : *-----------------------------------------------------------------*/
569 :
570 1872 : IF( st_ivas->hDiracDecBin[0] != NULL )
571 : {
572 372 : IF( NE_32( ( error = ivas_td_decorr_reconfig_dec( st_ivas->ivas_format, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->nchan_transport, st_ivas->hDecoderConfig->output_Fs, &( st_ivas->hDiracDecBin[0]->hTdDecorr ), &( st_ivas->hDiracDecBin[0]->useTdDecorr ) ) ), IVAS_ERR_OK ) )
573 : {
574 0 : return error;
575 : }
576 : }
577 :
578 : /*-----------------------------------------------------------------*
579 : * CLDFB instances
580 : *-----------------------------------------------------------------*/
581 :
582 1872 : IF( NE_32( ( error = ivas_cldfb_dec_reconfig_fx( st_ivas, nchan_transport_old, numCldfbAnalyses_old, numCldfbSyntheses_old ) ), IVAS_ERR_OK ) )
583 : {
584 0 : return error;
585 : }
586 :
587 : /*-----------------------------------------------------------------*
588 : * JBM TC buffers
589 : *-----------------------------------------------------------------*/
590 :
591 : {
592 : Word16 tc_nchan_to_allocate;
593 : Word16 tc_nchan_tc;
594 : TC_BUFFER_MODE tc_buffer_mode;
595 :
596 1872 : tc_buffer_mode = TC_BUFFER_MODE_RENDERER;
597 1872 : move16();
598 1872 : tc_nchan_tc = ivas_jbm_dec_get_num_tc_channels_fx( st_ivas ); /*Q0*/
599 1872 : tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/
600 1872 : move16();
601 1872 : test();
602 1872 : test();
603 1872 : test();
604 1872 : test();
605 1872 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_MONO ) )
606 : {
607 273 : test();
608 273 : test();
609 273 : IF( ( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) && EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) ) )
610 : {
611 36 : tc_nchan_tc = add( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ); /*Q0*/
612 36 : tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/
613 36 : move16();
614 : }
615 : ELSE
616 : {
617 237 : tc_buffer_mode = TC_BUFFER_MODE_BUFFER;
618 237 : move16();
619 237 : tc_nchan_tc = st_ivas->hDecoderConfig->nchan_out; /*Q0*/
620 237 : move16();
621 237 : tc_nchan_to_allocate = tc_nchan_tc; /*Q0*/
622 237 : move16();
623 : }
624 : }
625 1599 : ELSE 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 ) )
626 : {
627 372 : tc_nchan_to_allocate = shl( BINAURAL_CHANNELS, 1 ); /*2 * BINAURAL_CHANNELS*/
628 : }
629 1227 : ELSE IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
630 : {
631 1227 : tc_nchan_to_allocate = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/
632 :
633 1227 : IF( EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
634 : {
635 255 : tc_nchan_to_allocate = add( tc_nchan_to_allocate, st_ivas->nchan_ism ); /*Q0*/
636 : }
637 : }
638 : ELSE
639 : {
640 0 : test();
641 0 : test();
642 0 : test();
643 0 : test();
644 0 : IF( EQ_16( st_ivas->nchan_transport, 1 ) && ( ( EQ_16( st_ivas->renderer_type, RENDERER_DIRAC ) && EQ_16( st_ivas->hDirACRend->synthesisConf, DIRAC_SYNTHESIS_GAIN_SHD ) ) || ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) ) ) )
645 : {
646 0 : tc_nchan_to_allocate++; /* we need a channel for the CNG in this case*/
647 : }
648 : }
649 :
650 1872 : test();
651 1872 : test();
652 1872 : test();
653 1872 : IF( NE_16( tc_nchan_tc, st_ivas->hTcBuffer->nchan_transport_jbm ) || NE_16( tc_nchan_to_allocate, st_ivas->hTcBuffer->nchan_transport_internal ) || NE_16( tc_buffer_mode, st_ivas->hTcBuffer->tc_buffer_mode ) || NE_16( granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
654 : {
655 1332 : if ( NE_32( ( error = ivas_jbm_dec_tc_buffer_reconfigure_fx( st_ivas, tc_buffer_mode, tc_nchan_tc, tc_nchan_to_allocate, tc_nchan_to_allocate, granularity_new ) ), IVAS_ERR_OK ) )
656 : {
657 0 : return error;
658 : }
659 : }
660 : }
661 :
662 : /* resync SPAR and DirAC JBM info from TC Buffer */
663 1872 : test();
664 1872 : IF( st_ivas->hSpatParamRendCom != NULL && EQ_16( st_ivas->hSpatParamRendCom->slot_size, st_ivas->hTcBuffer->n_samples_granularity ) )
665 : {
666 1124 : Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpatParamRendCom->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
667 1124 : st_ivas->hSpatParamRendCom->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
668 1124 : move16();
669 1124 : st_ivas->hSpatParamRendCom->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
670 1124 : move16();
671 : }
672 1872 : Copy( st_ivas->hTcBuffer->subframe_nbslots, st_ivas->hSpar->subframe_nbslots, MAX_JBM_SUBFRAMES_5MS ); /*Q0*/
673 1872 : st_ivas->hSpar->nb_subframes = st_ivas->hTcBuffer->nb_subframes;
674 1872 : move16();
675 1872 : st_ivas->hSpar->subframes_rendered = st_ivas->hTcBuffer->subframes_rendered;
676 1872 : move16();
677 :
678 1872 : test();
679 1872 : test();
680 1872 : IF( EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
681 : {
682 219 : Word16 granularityMultiplier = idiv1616( st_ivas->hTcBuffer->n_samples_granularity, st_ivas->hSpatParamRendCom->slot_size ); /*Q0*/
683 : Word16 n;
684 1971 : FOR( n = 0; n < MAX_JBM_SUBFRAMES_5MS; n++ )
685 : {
686 1752 : st_ivas->hSpatParamRendCom->subframe_nbslots[n] = i_mult( st_ivas->hTcBuffer->subframe_nbslots[n], granularityMultiplier ); /*Q0*/
687 1752 : move16();
688 1752 : st_ivas->hSpar->subframe_nbslots[n] = st_ivas->hSpatParamRendCom->subframe_nbslots[n];
689 1752 : move16();
690 : }
691 : }
692 :
693 : /*-----------------------------------------------------------------*
694 : * output audio buffers
695 : *-----------------------------------------------------------------*/
696 :
697 1872 : nchan_out_buff = ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); /*Q0*/
698 1872 : IF( ( error = ivas_output_buff_dec_fx( st_ivas->p_output_fx, nchan_out_buff, hDecoderConfig->Opt_tsm, st_ivas->hTcBuffer ) ) != IVAS_ERR_OK )
699 : {
700 0 : return error;
701 : }
702 :
703 1872 : return IVAS_ERR_OK;
704 : }
705 :
706 :
707 : /*-------------------------------------------------------------------*
708 : * ivas_sba_dec_digest_tc()
709 : *
710 : *
711 : *-------------------------------------------------------------------*/
712 :
713 242815 : void ivas_sba_dec_digest_tc_fx(
714 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
715 : const Word16 nCldfbSlots, /* i : number of CLDFB slots Q0*/
716 : const Word16 nSamplesForRendering /* i : number of samples provided Q0*/
717 : )
718 : {
719 : Word16 ch_idx, nchan_transport;
720 :
721 : /* set the md map */
722 242815 : test();
723 242815 : IF( st_ivas->hDirAC != NULL || EQ_32( st_ivas->renderer_type, RENDERER_OMASA_OBJECT_EXT ) )
724 : {
725 198442 : ivas_dirac_dec_set_md_map_fx( st_ivas, nCldfbSlots );
726 : }
727 :
728 242815 : test();
729 242815 : IF( EQ_16( st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
730 : {
731 147764 : ivas_spar_dec_digest_tc_fx( st_ivas, st_ivas->nchan_transport, nCldfbSlots, nSamplesForRendering );
732 : }
733 :
734 242815 : test();
735 242815 : IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->useTdDecorr )
736 : {
737 : Word16 nSamplesLeftForTD, default_frame;
738 : Word32 *decorr_signal[BINAURAL_CHANNELS];
739 : Word32 *p_tc[2 * BINAURAL_CHANNELS];
740 :
741 : /* default_frame = (int16_t) ( st_ivas->hDecoderConfig->output_Fs / FRAMES_PER_SEC ); */
742 34609 : default_frame = extract_l( Mpy_32_32( st_ivas->hDecoderConfig->output_Fs, ONE_BY_FRAMES_PER_SEC_Q31 ) ); /*Q0*/
743 34609 : nSamplesLeftForTD = nSamplesForRendering; /*Q0*/
744 34609 : move16();
745 :
746 103827 : FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ )
747 : {
748 69218 : decorr_signal[ch_idx] = st_ivas->hTcBuffer->tc_fx[( ch_idx + BINAURAL_CHANNELS )]; /*Q11*/
749 69218 : move32();
750 69218 : p_tc[ch_idx] = st_ivas->hTcBuffer->tc_fx[ch_idx]; /*Q11*/
751 69218 : move32();
752 : }
753 :
754 69226 : WHILE( nSamplesLeftForTD )
755 : {
756 34617 : Word16 nSamplesToDecorr = s_min( nSamplesLeftForTD, default_frame ); /*Q0*/
757 :
758 34617 : IF( st_ivas->hDiracDecBin[0]->hTdDecorr )
759 : {
760 34617 : ivas_td_decorr_process_fx( st_ivas->hDiracDecBin[0]->hTdDecorr, p_tc, decorr_signal, nSamplesToDecorr );
761 : }
762 :
763 103851 : FOR( ch_idx = 0; ch_idx < BINAURAL_CHANNELS; ch_idx++ )
764 : {
765 69234 : decorr_signal[ch_idx] += nSamplesToDecorr;
766 69234 : p_tc[ch_idx] += nSamplesToDecorr;
767 : }
768 34617 : nSamplesLeftForTD = sub( nSamplesLeftForTD, nSamplesToDecorr ); /*Q0*/
769 : }
770 : }
771 :
772 : /* if we have a late CNG generation, do it here */
773 242815 : nchan_transport = st_ivas->nchan_transport; /*Q0*/
774 242815 : move16();
775 :
776 242815 : test();
777 242815 : test();
778 242815 : test();
779 242815 : test();
780 242815 : test();
781 242815 : if ( EQ_16( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && ( GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) || ( LE_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) && st_ivas->nCPE > 0 && EQ_16( st_ivas->hCPE[0]->nchan_out, 1 ) ) ) )
782 : {
783 12668 : nchan_transport = 1;
784 12668 : move16(); /* Only one channel transported */
785 : }
786 :
787 242815 : test();
788 242815 : test();
789 242815 : test();
790 242815 : test();
791 242815 : test();
792 242815 : test();
793 242815 : test();
794 242815 : test();
795 242815 : test();
796 242815 : test();
797 242815 : test();
798 242815 : IF( ( ( NE_16( st_ivas->ivas_format, SBA_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) && EQ_16( st_ivas->nchan_transport, 1 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cna_dirac_flag ) ||
799 : ( ( EQ_16( st_ivas->renderer_type, RENDERER_STEREO_PARAMETRIC ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) || EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ) && ( EQ_16( nchan_transport, 1 ) && NE_16( st_ivas->nchan_transport, 2 ) && st_ivas->hSCE[0]->hCoreCoder[0] != NULL && st_ivas->hSCE[0]->hCoreCoder[0]->cng_sba_flag ) ) )
800 : {
801 31693 : Decoder_State *st = st_ivas->hSCE[0]->hCoreCoder[0];
802 31693 : Scale_sig( st->hFdCngDec->hFdCngCom->A_cng, M + 1, sub( norm_s( sub( st->hFdCngDec->hFdCngCom->A_cng[0], 1 ) ), 2 ) ); /*Q12 -> Q13*/
803 :
804 31693 : generate_masking_noise_lb_dirac_fx( st->hFdCngDec->hFdCngCom, st_ivas->hTcBuffer->tc_fx[1], nCldfbSlots, st_ivas->hSpatParamRendCom, st->cna_dirac_flag && st->flag_cna );
805 : }
806 :
807 242815 : return;
808 : }
809 :
810 : /*-------------------------------------------------------------------*
811 : * ivas_sba_dec_render()
812 : *
813 : *
814 : *-------------------------------------------------------------------*/
815 :
816 111074 : ivas_error ivas_sba_dec_render_fx(
817 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */
818 : const UWord16 nSamplesAsked, /* i : number of CLDFB slots requested Q0*/
819 : UWord16 *nSamplesRendered, /* o : number of CLDFB slots rendered Q0*/
820 : UWord16 *nSamplesAvailableNext, /* o : number of CLDFB slots still to render Q0*/
821 : Word32 *output_fx[] /* o : rendered time signal Q11*/
822 : )
823 : {
824 : Word16 slots_to_render, first_sf, last_sf, subframe_idx, n_samples_sf;
825 : UWord16 slot_size, ch;
826 : UWord16 nchan_internal, nchan_out;
827 : SPAR_DEC_HANDLE hSpar;
828 : SPAT_PARAM_REND_COMMON_DATA_HANDLE hSpatParamRendCom;
829 : Word32 *output_fx_local[MAX_OUTPUT_CHANNELS];
830 : ivas_error error;
831 :
832 111074 : hSpar = st_ivas->hSpar;
833 111074 : hSpatParamRendCom = st_ivas->hSpatParamRendCom;
834 111074 : nchan_internal = ivas_sba_get_nchan_metadata_fx( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate );
835 111074 : nchan_out = add( st_ivas->hIntSetup.nchan_out_woLFE, st_ivas->hIntSetup.num_lfe ); /*Q0*/
836 111074 : IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
837 : {
838 21417 : nchan_out = s_max( nchan_internal, st_ivas->hDecoderConfig->nchan_out );
839 :
840 21417 : IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
841 : {
842 2400 : nchan_out = s_max( nchan_internal, sub( st_ivas->hDecoderConfig->nchan_out, st_ivas->nchan_ism ) );
843 : }
844 19017 : ELSE IF( EQ_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
845 : {
846 4000 : nchan_out = BINAURAL_CHANNELS;
847 4000 : move16();
848 : }
849 : }
850 111074 : nchan_out = s_min( nchan_out, ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ) );
851 :
852 855577 : FOR( ch = 0; ch < nchan_out; ch++ )
853 : {
854 744503 : output_fx_local[ch] = output_fx[ch]; /*Q11*/
855 : }
856 :
857 111074 : slot_size = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); /*Q0*/
858 111074 : move16();
859 :
860 : /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
861 111074 : slots_to_render = s_min( sub( hSpar->num_slots, hSpar->slots_rendered ), idiv1616( nSamplesAsked, slot_size ) ); /*Q0*/
862 111074 : *nSamplesRendered = imult1616( slots_to_render, slot_size ); /*Q0*/
863 111074 : move16();
864 111074 : first_sf = hSpar->subframes_rendered; /*Q0*/
865 111074 : last_sf = first_sf; /*Q0*/
866 111074 : move16();
867 111074 : move16();
868 547812 : WHILE( slots_to_render > 0 )
869 : {
870 436738 : slots_to_render = sub( slots_to_render, hSpar->subframe_nbslots[last_sf] ); /*Q0*/
871 436738 : last_sf = add( last_sf, 1 );
872 : }
873 :
874 547812 : FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
875 : {
876 436738 : n_samples_sf = imult1616( slot_size, hSpar->subframe_nbslots[subframe_idx] ); /*Q0*/
877 :
878 436738 : ivas_spar_dec_upmixer_sf_fx( st_ivas, output_fx_local, nchan_internal );
879 :
880 436738 : test();
881 436738 : IF( EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
882 : {
883 81295 : Word32 gain = st_ivas->hSbaIsmData->gain_bed_fx; // Q29
884 81295 : move32();
885 :
886 81295 : test();
887 81295 : IF( NE_32( gain, ONE_IN_Q29 ) && NE_32( gain, 0 ) )
888 : {
889 46751 : FOR( ch = 0; ch < nchan_out; ch++ )
890 : {
891 7862724 : FOR( Word16 i = 0; i < n_samples_sf; i++ )
892 : {
893 : Word32 tmp1;
894 7826400 : tmp1 = Mpy_32_32( output_fx_local[ch][i], gain ); // Q11 + Q29 - 31 = Q9
895 7826400 : output_fx_local[ch][i] = L_shl( tmp1, 2 ); // Q9 --> Q11
896 : }
897 : }
898 : }
899 : }
900 :
901 3349702 : FOR( ch = 0; ch < nchan_out; ch++ )
902 : {
903 2912964 : output_fx_local[ch] = output_fx_local[ch] + n_samples_sf; /*Q11*/
904 : }
905 : /* update combined orientation access index */
906 436738 : ivas_combined_orientation_update_index( st_ivas->hCombinedOrientationData, n_samples_sf );
907 : }
908 :
909 111074 : IF( EQ_16( st_ivas->renderer_type, RENDERER_SBA_LINEAR_DEC ) )
910 : {
911 64450 : if ( NE_32( ( error = ivas_sba_linear_renderer_fx( output_fx, *nSamplesRendered, st_ivas->hIntSetup.nchan_out_woLFE, 0, st_ivas->hDecoderConfig->output_config, st_ivas->hOutSetup ) ), IVAS_ERR_OK ) )
912 : {
913 0 : return error;
914 : }
915 : }
916 :
917 111074 : IF( st_ivas->hDirAC != NULL && EQ_16( hSpar->slots_rendered, hSpar->num_slots ) )
918 : {
919 64329 : IF( EQ_16( st_ivas->hDirAC->hConfig->dec_param_estim, 1 ) )
920 : {
921 50699 : hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_CLDFB_TIMESLOTS ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/
922 50699 : move16();
923 : }
924 : ELSE
925 : {
926 13630 : hSpatParamRendCom->dirac_read_idx = add( hSpatParamRendCom->dirac_read_idx, DEFAULT_JBM_SUBFRAMES_5MS ) % hSpatParamRendCom->dirac_md_buffer_length; /*Q0*/
927 13630 : move16();
928 : }
929 64329 : move16();
930 : }
931 :
932 111074 : *nSamplesAvailableNext = imult1616( sub( hSpar->num_slots, hSpar->slots_rendered ), slot_size ); /*Q0*/
933 111074 : move16();
934 :
935 111074 : return IVAS_ERR_OK;
936 : }
|