Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #include <assert.h>
34 : #include <stdint.h>
35 : #include "options.h"
36 : #include "cnst.h"
37 : #include "ivas_cnst.h"
38 : #include "rom_com.h"
39 : #include "prot_fx.h"
40 : #include "ivas_prot_fx.h"
41 : #include "ivas_rom_com.h"
42 : #include "wmc_auto.h"
43 : #include <math.h>
44 :
45 :
46 : /*--------------------------------------------------------------------------*
47 : * Local function prototypes
48 : *--------------------------------------------------------------------------*/
49 :
50 : static void read_stereo_mode_and_bwidth_fx( CPE_DEC_HANDLE hCPE, const Decoder_Struct *st_ivas );
51 :
52 : static void stereo_mode_combined_format_dec_fx( const Decoder_Struct *st_ivas, CPE_DEC_HANDLE hCPE );
53 :
54 :
55 : /*--------------------------------------------------------------------------*
56 : * ivas_cpe_dec_fx()
57 : *
58 : * Channel Pair Element (CPE) decoding routine
59 : *--------------------------------------------------------------------------*/
60 :
61 386540 : ivas_error ivas_cpe_dec_fx(
62 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
63 : const Word16 cpe_id, /* i : CPE # identifier */
64 : Word32 *output[CPE_CHANNELS], /* o : output synthesis signal Q11*/
65 : const Word16 output_frame, /* i : output frame length per channel */
66 : const Word16 nb_bits_metadata /* i : number of metadata bits */
67 : )
68 : {
69 : Word16 i, n, n_channels;
70 : Word16 nb_bits, last_core;
71 : Word16 last_bwidth;
72 : Word16 tdm_ratio_idx;
73 : Word32 outputHB_fx[CPE_CHANNELS][L_FRAME48k]; /* buffer for output HB synthesis, both channels */ /* Q11 */
74 : Word16 q_res_buf;
75 : Word32 res_buf_fx[STEREO_DFT_N_8k]; /* Q(q_res_buf) */
76 : CPE_DEC_HANDLE hCPE;
77 : Decoder_State **sts;
78 : Word32 ivas_total_brate;
79 : ivas_error error;
80 : Word32 cpe_brate;
81 : Word32 element_brate_ref;
82 : Word32 quo, rem;
83 :
84 386540 : error = IVAS_ERR_OK;
85 386540 : move32();
86 386540 : q_res_buf = Q8;
87 386540 : move16();
88 :
89 386540 : push_wmops( "ivas_cpe_dec" );
90 :
91 386540 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
92 386540 : move32();
93 :
94 386540 : hCPE = st_ivas->hCPE[cpe_id];
95 386540 : sts = hCPE->hCoreCoder;
96 :
97 386540 : last_core = sts[0]->last_core;
98 386540 : move16();
99 386540 : last_bwidth = sts[0]->last_bwidth;
100 386540 : move16();
101 :
102 386540 : sts[0]->BER_detect = s_or( sts[0]->BER_detect, st_ivas->BER_detect );
103 386540 : sts[1]->BER_detect = s_or( sts[1]->BER_detect, st_ivas->BER_detect );
104 386540 : move16();
105 386540 : move16();
106 :
107 386540 : element_brate_ref = hCPE->element_brate;
108 386540 : move32();
109 :
110 : /*------------------------------------------------------------------*
111 : * Read stereo technology info & audio bandwidth
112 : *-----------------------------------------------------------------*/
113 :
114 386540 : stereo_mode_combined_format_dec_fx( st_ivas, hCPE );
115 :
116 386540 : read_stereo_mode_and_bwidth_fx( hCPE, st_ivas );
117 :
118 : /*----------------------------------------------------------------*
119 : * dynamically allocate data structures depending on the actual stereo mode
120 : *----------------------------------------------------------------*/
121 :
122 1159620 : FOR( Word16 ind1 = 0; ind1 < 2; ind1++ )
123 : {
124 773080 : test();
125 773080 : IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core )
126 : {
127 710266 : Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx32, L_FRAME48k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda ) ); // Q11
128 : }
129 : }
130 1159620 : FOR( Word16 ind1 = 0; ind1 < 2; ind1++ )
131 : {
132 773080 : IF( hCPE->hCoreCoder[ind1]->hHQ_core )
133 : {
134 710266 : Copy_Scale_sig_16_32_no_sat( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, L_FRAME32k, sub( Q11, hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB ) ); // Q11
135 710266 : hCPE->hCoreCoder[ind1]->hHQ_core->q_old_outLB_fx = Q11;
136 710266 : move16();
137 : }
138 : }
139 :
140 386540 : IF( NE_32( ( error = stereo_memory_dec_fx( ivas_total_brate, hCPE, nb_bits_metadata, st_ivas->hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->mc_mode, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) )
141 : {
142 0 : return error;
143 : }
144 :
145 1159620 : FOR( Word16 ind1 = 0; ind1 < 2; ind1++ )
146 : {
147 773080 : test();
148 773080 : IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core )
149 : {
150 710282 : Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx32, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_fx, L_FRAME48k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda, Q11 ) ); // Q_old_wtda
151 : }
152 : }
153 1159620 : FOR( Word16 ind1 = 0; ind1 < 2; ind1++ )
154 : {
155 773080 : test();
156 773080 : IF( hCPE->hCoreCoder[ind1] && hCPE->hCoreCoder[ind1]->hHQ_core )
157 : {
158 710282 : Copy_Scale_sig_32_16( hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx32, hCPE->hCoreCoder[ind1]->hHQ_core->old_out_LB_fx, L_FRAME32k, sub( hCPE->hCoreCoder[ind1]->hHQ_core->Q_old_wtda_LB, Q11 ) ); // Q_old_wtda
159 : }
160 : }
161 :
162 : /*------------------------------------------------------------------*
163 : * Initialization
164 : *-----------------------------------------------------------------*/
165 :
166 386540 : n_channels = CPE_CHANNELS;
167 386540 : move16();
168 386540 : if ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
169 : {
170 59047 : n_channels = 1; /* in DFT stereo, only M channel is coded */
171 59047 : move16();
172 : }
173 :
174 386540 : tdm_ratio_idx = LRTD_STEREO_RIGHT_IS_PRIM;
175 386540 : move16();
176 :
177 1100573 : FOR( n = 0; n < n_channels; n++ )
178 : {
179 714033 : sts[n]->idchan = n;
180 714033 : move16();
181 714033 : sts[n]->element_mode = hCPE->element_mode;
182 714033 : move16();
183 :
184 714033 : if ( !st_ivas->bfi )
185 : {
186 701971 : sts[n]->tdm_LRTD_flag = 0;
187 701971 : move16();
188 : }
189 :
190 : /* TD stereo parameters */
191 714033 : IF( hCPE->hStereoTD != NULL )
192 : {
193 7502 : hCPE->hStereoTD->tdm_lp_reuse_flag = 0;
194 7502 : move16();
195 7502 : hCPE->hStereoTD->tdm_low_rate_mode = 0;
196 7502 : move16();
197 7502 : hCPE->hStereoTD->tdm_Pitch_reuse_flag = 0;
198 7502 : move16();
199 : }
200 : }
201 :
202 : /*----------------------------------------------------------------*
203 : * Resets/updates in case of stereo switching
204 : *----------------------------------------------------------------*/
205 :
206 386540 : stereo_switching_dec( hCPE, ivas_total_brate );
207 :
208 : /*----------------------------------------------------------------*
209 : * Configuration of stereo decoder
210 : *----------------------------------------------------------------*/
211 :
212 : /* Force to MODE1 in IVAS */
213 1100573 : FOR( n = 0; n < n_channels; n++ )
214 : {
215 714033 : sts[n]->codec_mode = MODE1;
216 714033 : move16();
217 : }
218 :
219 386540 : test();
220 386540 : test();
221 386540 : test();
222 386540 : test();
223 386540 : IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && ( NE_32( hCPE->element_brate, hCPE->last_element_brate ) || NE_16( hCPE->last_element_mode, hCPE->element_mode ) || sts[0]->ini_frame == 0 || ( NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) ) )
224 : {
225 : STEREO_DFT_CONFIG_DATA_HANDLE hConfig;
226 4492 : IF( hCPE->hStereoDft == NULL )
227 : {
228 61 : hConfig = NULL;
229 : }
230 : ELSE
231 : {
232 4431 : hConfig = hCPE->hStereoDft->hConfig;
233 : }
234 4492 : test();
235 4492 : IF( st_ivas->hQMetaData != NULL && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
236 : {
237 1098 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
238 : {
239 440 : stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, 35 /* 0.7f * FRAMES_PER_SEC */ ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
240 : }
241 : ELSE
242 : {
243 658 : stereo_dft_config_fx( hConfig, L_mult0( st_ivas->hQMetaData->bits_frame_nominal, FRAMES_PER_SEC ), &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
244 : }
245 : }
246 : ELSE
247 : {
248 : /* Note: This only works for stereo operation. If DTX would be applied for multiple CPEs a different bitrate signaling is needed */
249 3394 : IF( LE_32( ivas_total_brate, IVAS_SID_5k2 ) )
250 : {
251 2859 : stereo_dft_config_fx( hConfig, ivas_total_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
252 : }
253 : ELSE
254 : {
255 535 : stereo_dft_config_fx( hConfig, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
256 : }
257 : }
258 : }
259 :
260 386540 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
261 : {
262 3751 : IF( hCPE->hStereoTD->tdm_LRTD_flag )
263 : {
264 3625 : iDiv_and_mod_32( L_shr( hCPE->element_brate, 1 ), FRAMES_PER_SEC, &quo, &rem, 0 );
265 3625 : sts[0]->bits_frame_nominal = extract_l( quo );
266 3625 : sts[1]->bits_frame_nominal = extract_l( quo );
267 3625 : move16();
268 3625 : move16();
269 : }
270 : ELSE
271 : {
272 126 : stereo_dft_config_fx( NULL, hCPE->element_brate, &sts[0]->bits_frame_nominal, &sts[1]->bits_frame_nominal );
273 : }
274 : }
275 :
276 : /*----------------------------------------------------------------*
277 : * Set bitrates per channel
278 : * Set bitstream buffers per channel
279 : *----------------------------------------------------------------*/
280 :
281 386540 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
282 : {
283 59047 : IF( !st_ivas->bfi )
284 : {
285 : /* Update DFT Stereo memories */
286 58159 : stereo_dft_dec_update_fx( hCPE->hStereoDft, output_frame, 0 );
287 :
288 58159 : test();
289 58159 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LE_32( ivas_total_brate, IVAS_SID_5k2 ) )
290 : {
291 530 : IF( ivas_total_brate == FRAME_NO_DATA )
292 : {
293 456 : hCPE->hCoreCoder[n]->core_brate = ivas_total_brate;
294 456 : move32();
295 456 : hCPE->hCoreCoder[0]->total_brate = ivas_total_brate;
296 456 : move32();
297 : }
298 : ELSE
299 : {
300 74 : hCPE->hCoreCoder[n]->core_brate = SID_2k40;
301 74 : move32();
302 : }
303 : }
304 :
305 : /* read DFT Stereo side info */
306 58159 : nb_bits = extract_h( L_msu( Mpy_32_16_1( L_shl( hCPE->element_brate, 15 ), 1311 /* 1/FRAMES_PER_SEC in Q16*/ ), 26214, sts[0]->bits_frame_nominal ) );
307 58159 : cpe_brate = st_ivas->hCPE[0]->element_brate;
308 58159 : move32();
309 58159 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
310 : {
311 2641 : iDiv_and_mod_32( cpe_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
312 2641 : sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata );
313 2641 : IF( hCPE->brate_surplus < 0 )
314 : {
315 2166 : iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
316 2166 : quo = L_negate( quo );
317 : }
318 : ELSE
319 : {
320 475 : iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 );
321 : }
322 2641 : sts[1]->bit_stream = sts[1]->bit_stream + extract_l( quo );
323 : }
324 : ELSE
325 : {
326 55518 : iDiv_and_mod_32( ivas_total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
327 55518 : sts[1]->bit_stream = sts[0]->bit_stream + sub( sub( extract_l( quo ), 1 ), nb_bits_metadata );
328 : }
329 :
330 58159 : IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
331 : {
332 1492 : nb_bits = sub( nb_bits, SID_FORMAT_NBITS );
333 1492 : sts[1]->bit_stream = sts[1]->bit_stream - SID_FORMAT_NBITS;
334 : /* set total bitrate of Stereo CNG parameters for BER detection */
335 1492 : sts[1]->total_brate = IVAS_SID_5k2 - SID_2k40;
336 1492 : move32();
337 : }
338 :
339 58159 : test();
340 58159 : test();
341 58159 : test();
342 58159 : test();
343 58159 : IF( ( ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) || ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) ) ) && GT_32( ivas_total_brate, IVAS_SID_5k2 ) )
344 : {
345 5426 : sts[0]->total_brate = hCPE->element_brate; /* Only mono downmix was transmitted in this case */
346 5426 : move32();
347 : }
348 : ELSE
349 : {
350 52733 : test();
351 52733 : IF( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
352 : {
353 6161 : nb_bits = sub( nb_bits, nb_bits_metadata );
354 6161 : IF( hCPE->brate_surplus < 0 )
355 : {
356 912 : iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
357 912 : quo = L_negate( quo );
358 912 : nb_bits = add( nb_bits, extract_l( quo ) );
359 : }
360 : }
361 :
362 52733 : stereo_dft_dec_read_BS_fx( ivas_total_brate, hCPE->element_brate, &sts[0]->total_brate, sts[1], hCPE->hStereoDft, sts[0]->bwidth, output_frame, res_buf_fx, &nb_bits, hCPE->hStereoCng->coh_fx, st_ivas->ivas_format );
363 : }
364 :
365 : /* subtract metadata bitbudget */
366 58159 : sts[0]->total_brate = L_sub( sts[0]->total_brate, L_mult0( nb_bits_metadata, FRAMES_PER_SEC ) ); // Q0
367 58159 : move32();
368 :
369 : /* subtract bit-rate for combined format coding */
370 58159 : test();
371 58159 : test();
372 58159 : test();
373 58159 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) )
374 : {
375 2641 : sts[0]->total_brate = L_add( sts[0]->total_brate, hCPE->brate_surplus );
376 2641 : move32();
377 : }
378 : }
379 : ELSE
380 : {
381 888 : hCPE->hStereoDft->sg_mem_corrupt = 1;
382 888 : move16();
383 : }
384 : }
385 327493 : ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
386 : {
387 : /* signal bitrate for BW selection in the SCh */
388 3751 : sts[0]->bits_frame_channel = 0;
389 3751 : move16();
390 3751 : iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
391 3751 : sts[1]->bits_frame_channel = extract_l( quo );
392 3751 : move16();
393 3751 : IF( hCPE->brate_surplus < 0 )
394 : {
395 0 : iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
396 0 : quo = L_negate( quo );
397 : }
398 : ELSE
399 : {
400 3751 : iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 );
401 : }
402 3751 : sts[1]->bits_frame_channel = add( sts[1]->bits_frame_channel, extract_l( quo ) );
403 3751 : move16();
404 3751 : IF( st_ivas->hQMetaData != NULL )
405 : {
406 60 : sts[1]->bits_frame_channel = sub( sts[1]->bits_frame_channel, st_ivas->hQMetaData->metadata_max_bits );
407 60 : move16();
408 : }
409 : }
410 323742 : ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) )
411 : {
412 : /* compute bit-rate surplus per channel in combined format coding */
413 : Word32 brate_surplus[CPE_CHANNELS];
414 323742 : test();
415 323742 : test();
416 323742 : IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
417 : {
418 3724 : IF( hCPE->brate_surplus < 0 )
419 : {
420 3606 : iDiv_and_mod_32( L_abs( hCPE->brate_surplus ), FRAMES_PER_SEC, &quo, &rem, 0 );
421 3606 : quo = L_negate( quo );
422 : }
423 : ELSE
424 : {
425 118 : iDiv_and_mod_32( hCPE->brate_surplus, FRAMES_PER_SEC, &quo, &rem, 0 );
426 : }
427 3724 : brate_surplus[0] = L_shr( L_mult( extract_l( L_shr( quo, 1 ) ), FRAMES_PER_SEC ), 1 );
428 3724 : move32();
429 3724 : brate_surplus[1] = L_sub( hCPE->brate_surplus, brate_surplus[0] );
430 3724 : move32();
431 : }
432 :
433 323742 : test();
434 323742 : test();
435 323742 : IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && ( sts[0]->first_CNG == 0 || sts[1]->first_CNG == 0 ) )
436 : {
437 30 : IF( NE_32( ( error = initMdctStereoDtxData_fx( hCPE ) ), IVAS_ERR_OK ) )
438 : {
439 0 : return error;
440 : }
441 : }
442 :
443 : /* this is just for initialization, the true values of "total_brate" and "bits_frame_channel" are set later */
444 971226 : FOR( n = 0; n < n_channels; n++ )
445 : {
446 647484 : IF( EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
447 : {
448 1154 : sts[n]->total_brate = SID_2k40;
449 1154 : move32();
450 1154 : sts[1]->bit_stream = sts[0]->bit_stream + SID_2k40 / FRAMES_PER_SEC;
451 : }
452 : ELSE
453 : {
454 : /*total bitrate must be set to the element bitrate to avoid false BER IF bits read are larger than half the bitrate*/
455 646330 : sts[n]->total_brate = hCPE->element_brate;
456 646330 : move32();
457 : }
458 647484 : iDiv_and_mod_32( sts[n]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
459 647484 : sts[n]->bits_frame_nominal = extract_l( quo );
460 647484 : iDiv_and_mod_32( hCPE->element_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
461 647484 : sts[n]->bits_frame_channel = extract_l( L_shr( quo, sub( n_channels, 1 ) ) );
462 647484 : move16();
463 647484 : move16();
464 :
465 : /* subtract bit-rate for combined format coding */
466 647484 : test();
467 647484 : test();
468 647484 : IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
469 : {
470 7448 : IF( brate_surplus[n] < 0 )
471 : {
472 7212 : iDiv_and_mod_32( L_abs( brate_surplus[n] ), FRAMES_PER_SEC, &quo, &rem, 0 );
473 7212 : quo = L_negate( quo );
474 : }
475 : ELSE
476 : {
477 236 : iDiv_and_mod_32( brate_surplus[n], FRAMES_PER_SEC, &quo, &rem, 0 );
478 : }
479 7448 : sts[n]->bits_frame_channel = add( sts[n]->bits_frame_channel, extract_l( quo ) );
480 7448 : sts[n]->total_brate = L_add( sts[n]->total_brate, brate_surplus[n] );
481 7448 : move16();
482 7448 : move32();
483 : }
484 : }
485 :
486 323742 : IF( !st_ivas->hMCT )
487 : {
488 82604 : test();
489 82604 : IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) && EQ_32( ivas_total_brate, IVAS_SID_5k2 ) )
490 : {
491 501 : FOR( n = 0; n < n_channels; n++ )
492 : {
493 334 : sts[n]->bits_frame_channel = sub( sts[n]->bits_frame_channel, shr( nb_bits_metadata, sub( n_channels, 1 ) ) );
494 334 : move16();
495 : }
496 : }
497 : ELSE
498 : {
499 : /* subtract metadata bitbudget */
500 82437 : sts[0]->bits_frame_channel = sub( sts[0]->bits_frame_channel, nb_bits_metadata );
501 82437 : move16();
502 : }
503 : }
504 : }
505 :
506 : /*----------------------------------------------------------------*
507 : * Core codec configuration
508 : *----------------------------------------------------------------*/
509 :
510 1100573 : FOR( n = 0; n < n_channels; n++ )
511 : {
512 : /* set ACELP12k8 / ACELP16k flag for flexible ACELP core */
513 714033 : IF( hCPE->hStereoTD != NULL )
514 : {
515 7502 : sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, hCPE->hStereoTD->tdm_LRTD_flag, sts[n]->bwidth, sts[n]->cng_type );
516 7502 : move16();
517 : }
518 : ELSE
519 : {
520 706531 : sts[n]->flag_ACELP16k = set_ACELP_flag_IVAS( hCPE->element_mode, hCPE->element_brate, sts[n]->total_brate, n, 0, sts[n]->bwidth, sts[n]->cng_type );
521 706531 : move16();
522 : }
523 : }
524 :
525 1100573 : FOR( n = 0; n < n_channels; n++ )
526 : {
527 : /* set VAD flag */
528 714033 : IF( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) )
529 : {
530 18695 : sts[n]->VAD = 0;
531 18695 : move16();
532 18695 : sts[n]->active_cnt = 0;
533 18695 : move16();
534 18695 : if ( sts[1] != NULL )
535 : {
536 18695 : sts[1]->active_cnt = 0;
537 18695 : move16();
538 : }
539 : }
540 : ELSE
541 : {
542 695338 : sts[n]->VAD = 1;
543 695338 : move16();
544 695338 : sts[n]->active_cnt = add( sts[n]->active_cnt, 1 );
545 695338 : sts[n]->active_cnt = s_min( sts[n]->active_cnt, 100 );
546 695338 : move16();
547 695338 : move16();
548 : }
549 :
550 : /* set CNA flag */
551 714033 : test();
552 714033 : test();
553 714033 : IF( ( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && LE_32( hCPE->element_brate, CNA_MAX_BRATE_DFT_STEREO ) ) || LE_32( hCPE->element_brate, CNA_MAX_BRATE_STEREO ) )
554 : {
555 68141 : sts[n]->flag_cna = 1;
556 68141 : move16();
557 : }
558 : ELSE
559 : {
560 645892 : sts[n]->flag_cna = 0;
561 645892 : move16();
562 : }
563 : }
564 :
565 : /* configure TD stereo decoder */
566 386540 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
567 : {
568 3751 : IF( !st_ivas->bfi )
569 : {
570 3695 : tdm_configure_dec_fx( st_ivas->ivas_format, st_ivas->ism_mode, hCPE, &tdm_ratio_idx, nb_bits_metadata );
571 :
572 3695 : iDiv_and_mod_32( sts[0]->total_brate, FRAMES_PER_SEC, &quo, &rem, 0 );
573 3695 : sts[1]->bit_stream = sts[0]->bit_stream + extract_l( quo );
574 : }
575 : ELSE
576 : {
577 56 : sts[1]->coder_type = sts[1]->last_coder_type;
578 56 : move16();
579 56 : tdm_ratio_idx = hCPE->hStereoTD->tdm_last_ratio_idx;
580 56 : move16();
581 : }
582 : }
583 :
584 : /*----------------------------------------------------------------*
585 : * Core Decoder
586 : *----------------------------------------------------------------*/
587 :
588 386540 : test();
589 386540 : test();
590 386540 : IF( NE_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) )
591 : {
592 344494 : IF( NE_32( ( error = ivas_core_dec_fx( st_ivas, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, NULL, st_ivas->sba_dirac_stereo_flag ) ), IVAS_ERR_OK ) )
593 : {
594 0 : return error;
595 : }
596 : }
597 :
598 386540 : IF( st_ivas->hMCT )
599 : {
600 241138 : pop_wmops();
601 :
602 241138 : return error;
603 : }
604 :
605 : /*----------------------------------------------------------------*
606 : * Stereo decoder & upmixing
607 : *----------------------------------------------------------------*/
608 145402 : test();
609 145402 : test();
610 145402 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && !( EQ_16( hCPE->nchan_out, 1 ) && EQ_16( hCPE->hStereoDft->hConfig->res_cod_mode, STEREO_DFT_RES_COD_OFF ) ) )
611 42046 : {
612 : Word32 DFT_fx[CPE_CHANNELS][STEREO_DFT_BUF_MAX]; // q_dft
613 42046 : set32_fx( DFT_fx[0], 0, STEREO_DFT_BUF_MAX );
614 42046 : set32_fx( DFT_fx[1], 0, STEREO_DFT_BUF_MAX );
615 :
616 : /* core decoder */
617 42046 : IF( NE_32( ( error = ivas_core_dec_fx( NULL, NULL, hCPE, st_ivas->hMCT, n_channels, output, outputHB_fx, DFT_fx, 0 ) ), IVAS_ERR_OK ) )
618 : {
619 0 : return error;
620 : }
621 :
622 : // Scaling of DFT's
623 : Word16 shift;
624 : Word32 tmp1, tmp2;
625 : Word16 shift1, shift2;
626 42046 : maximum_abs_32_fx( DFT_fx[0], STEREO_DFT_BUF_MAX, &tmp1 );
627 42046 : maximum_abs_32_fx( DFT_fx[1], STEREO_DFT_BUF_MAX, &tmp2 );
628 :
629 42046 : IF( tmp1 == 0 )
630 : {
631 5497 : shift1 = Q31;
632 5497 : move16();
633 : }
634 : ELSE
635 : {
636 36549 : shift1 = norm_l( tmp1 );
637 : }
638 42046 : IF( tmp2 == 0 )
639 : {
640 22788 : shift2 = Q31;
641 22788 : move16();
642 : }
643 : ELSE
644 : {
645 19258 : shift2 = norm_l( tmp2 );
646 : }
647 42046 : shift = s_min( shift1, shift2 );
648 :
649 42046 : IF( NE_16( shift, 31 ) )
650 : {
651 36553 : shift = sub( add( hCPE->hStereoDft->q_dft, shift ), Q15 ); /* Q15 for guard bits */
652 :
653 36553 : IF( GT_16( shift, hCPE->hStereoDft->q_dft ) )
654 : {
655 1263 : Scale_sig32( DFT_fx[0], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift
656 1263 : Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( shift, hCPE->hStereoDft->q_dft ) ); // shift
657 1263 : hCPE->hStereoDft->q_dft = shift;
658 1263 : move16();
659 : }
660 : }
661 : ELSE
662 : {
663 5493 : hCPE->hStereoDft->q_dft = Q8;
664 5493 : move16();
665 : }
666 :
667 : /* DFT Stereo residual decoding */
668 42046 : test();
669 42046 : IF( hCPE->hStereoDft->res_cod_band_max > 0 && !st_ivas->bfi )
670 : {
671 : Word16 q;
672 : Word16 q_out_DFT[2];
673 :
674 16830 : q = Q11;
675 16830 : move16();
676 :
677 16830 : Copy_Scale_sig_32_16( hCPE->hCoreCoder[0]->old_pitch_buf_fx, hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), -( Q10 ) ); // Q16->Q6
678 :
679 16830 : stereo_dft_dec_res_fx( hCPE, res_buf_fx, q_res_buf, output[1] );
680 :
681 16830 : Copy_Scale_sig_16_32_DEPREC( hCPE->hCoreCoder[0]->old_pitch_buf_16_fx, hCPE->hCoreCoder[0]->old_pitch_buf_fx, ( ( 2 * NB_SUBFR16k ) + 2 ), 10 ); // Q6->Q16
682 :
683 16830 : Scale_sig32( output[1], L_FRAME8k, ( Q11 - Q15 ) ); // Q15 -> Q11
684 :
685 16830 : q_out_DFT[0] = q_out_DFT[1] = hCPE->hStereoDft->q_dft;
686 16830 : move16();
687 16830 : move16();
688 :
689 16830 : stereo_dft_dec_analyze_fx( hCPE, output[1], DFT_fx, 1, L_FRAME8k, output_frame, DFT_STEREO_DEC_ANA_LB, 0, 0, &q, q_out_DFT );
690 :
691 16830 : Scale_sig32( DFT_fx[1], STEREO_DFT_BUF_MAX, sub( hCPE->hStereoDft->q_dft, q_out_DFT[1] ) ); // q_dft
692 : }
693 :
694 : /* DFT stereo CNG */
695 : {
696 : Word16 q_dft;
697 :
698 42046 : q_dft = hCPE->hStereoDft->q_dft;
699 42046 : move16();
700 :
701 42046 : stereo_dtf_cng_fx( hCPE, ivas_total_brate, DFT_fx, output_frame, q_dft );
702 : }
703 :
704 : /* decoding */
705 42046 : IF( EQ_16( hCPE->nchan_out, 1 ) )
706 : {
707 5345 : IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
708 : {
709 20 : hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft;
710 20 : move16();
711 100 : FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ )
712 : {
713 80 : hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft;
714 80 : move16();
715 : }
716 20 : hCPE->hStereoDft->first_frame = 0;
717 20 : move16();
718 : }
719 :
720 5345 : scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft
721 5345 : hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft;
722 5345 : move16();
723 5345 : stereo_dft_unify_dmx_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng->prev_sid_nodata );
724 5345 : scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15
725 5345 : hCPE->hStereoDft->q_res_cod_mem_fx = Q15;
726 5345 : move16();
727 : }
728 : ELSE
729 : {
730 : {
731 36701 : IF( EQ_16( hCPE->hStereoDft->first_frame, 1 ) )
732 : {
733 422 : hCPE->hStereoDft->q_smoothed_nrg = hCPE->hStereoDft->q_dft;
734 422 : move16();
735 2110 : FOR( Word16 ii = 0; ii < (Word16) ( sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx ) / sizeof( hCPE->hStereoDft->q_DFT_past_DMX_fx[0] ) ); ii++ )
736 : {
737 1688 : hCPE->hStereoDft->q_DFT_past_DMX_fx[ii] = hCPE->hStereoDft->q_dft;
738 1688 : move16();
739 : }
740 422 : hCPE->hStereoDft->first_frame = 0;
741 422 : move16();
742 : }
743 :
744 36701 : scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( hCPE->hStereoDft->q_dft, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // q_dft
745 36701 : hCPE->hStereoDft->q_res_cod_mem_fx = hCPE->hStereoDft->q_dft;
746 36701 : move16();
747 : }
748 36701 : stereo_dft_dec_fx( hCPE->hStereoDft, sts[0], DFT_fx, hCPE->input_mem_fx[1], hCPE->hStereoCng, 0, 0, 0, 0, 0, 0, MAX_PARAM_SPATIAL_SUBFRAMES );
749 36701 : scale_sig32( hCPE->hStereoDft->res_cod_mem_fx, STEREO_DFT_OVL_8k, sub( Q15, hCPE->hStereoDft->q_res_cod_mem_fx ) ); // Q15
750 36701 : hCPE->hStereoDft->q_res_cod_mem_fx = Q15;
751 36701 : move16();
752 : }
753 :
754 120793 : FOR( n = 0; n < hCPE->nchan_out; n++ )
755 : {
756 78747 : Scale_sig32( output[n], L_FRAME48k, sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
757 78747 : scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( hCPE->hStereoDft->q_dft, Q11 ) ); // q_dft
758 78747 : hCPE->q_output_mem_fx[n] = hCPE->hStereoDft->q_dft;
759 78747 : move16();
760 : }
761 :
762 : /* synthesis iFFT */
763 120793 : FOR( n = 0; n < hCPE->nchan_out; n++ )
764 : {
765 78747 : stereo_dft_dec_synthesize_fx( hCPE, DFT_fx, n, output[n], output_frame );
766 : }
767 :
768 : // delete below
769 120793 : FOR( n = 0; n < hCPE->nchan_out; n++ )
770 : {
771 78747 : Scale_sig32( output[n], L_FRAME48k, sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
772 78747 : scale_sig32( hCPE->output_mem_fx[n], NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, STEREO_DFT32MS_OVL_NS ), sub( Q11, hCPE->hStereoDft->q_dft ) ); // Q11
773 78747 : hCPE->q_output_mem_fx[n] = Q11;
774 78747 : move16();
775 : }
776 : }
777 103356 : ELSE IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
778 : {
779 3751 : test();
780 3751 : if ( NE_16( hCPE->last_element_mode, IVAS_CPE_TD ) && sts[0]->tdm_LRTD_flag )
781 : {
782 58 : hCPE->hStereoTD->tdm_last_ratio_idx = tdm_ratio_idx;
783 58 : move16();
784 : }
785 :
786 : /* TD stereo upmixing */
787 3751 : stereo_tdm_combine_fx( hCPE, output[0], output[1], output_frame, 0, tdm_ratio_idx );
788 3751 : IF( sts[0]->tdm_LRTD_flag )
789 : {
790 3625 : stereo_tdm_combine_fx( hCPE, outputHB_fx[0], outputHB_fx[1], output_frame, 0, tdm_ratio_idx );
791 : }
792 :
793 3751 : hCPE->hStereoCng->last_tdm_idx = hCPE->hStereoTD->tdm_last_ratio_idx;
794 3751 : move16();
795 3751 : hCPE->hStereoTD->tdm_last_ratio_idx = tdm_ratio_idx;
796 3751 : move16();
797 :
798 3751 : IF( EQ_16( hCPE->nchan_out, 1 ) )
799 : {
800 : /* Scale the Right channel with the gain */
801 1347 : stereo_tca_scale_R_channel_fx( hCPE, output[1], output_frame );
802 : /* stereo to mono downmix */
803 808387 : FOR( i = 0; i < output_frame; i++ )
804 : {
805 807040 : output[0][i] = L_shr( L_add( output[0][i], output[1][i] ), 1 );
806 807040 : move32();
807 : }
808 : }
809 : }
810 :
811 : /*----------------------------------------------------------------*
812 : * Update parameters for stereo CNA
813 : *----------------------------------------------------------------*/
814 :
815 : // stereo_cna_update_params( hCPE, output_flt, output_frame, tdm_ratio_idx );
816 145402 : stereo_cna_update_params_fx( hCPE, output, output_frame, tdm_ratio_idx );
817 :
818 : /*----------------------------------------------------------------*
819 : * Synthesis synchronization between CPE modes
820 : *----------------------------------------------------------------*/
821 :
822 145402 : IF( !st_ivas->sba_dirac_stereo_flag )
823 : {
824 144064 : synchro_synthesis_fx( ivas_total_brate, hCPE, output, output_frame, 0, Q11 );
825 : }
826 :
827 145402 : test();
828 145402 : test();
829 145402 : test();
830 145402 : test();
831 145402 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) && ( is_DTXrate( ivas_total_brate ) == 0 || ( EQ_16( is_DTXrate( ivas_total_brate ), 1 ) && is_DTXrate( st_ivas->hDecoderConfig->last_ivas_total_brate ) == 0 ) ) )
832 : {
833 5910 : applyDmxMdctStereo_fx( hCPE, output, output_frame );
834 : }
835 :
836 : /*----------------------------------------------------------------*
837 : * IC-BWE: output LB and HB mix in ACELP mode
838 : *----------------------------------------------------------------*/
839 :
840 145402 : stereo_icBWE_decproc_fx( hCPE, output, outputHB_fx, last_core, last_bwidth, output_frame );
841 145402 : smooth_dft2td_transition_fx( hCPE, output, output_frame );
842 :
843 : /*----------------------------------------------------------------*
844 : * Temporal ICA, stereo adjustment and upmix
845 : *----------------------------------------------------------------*/
846 :
847 145402 : stereo_tca_dec_fx( hCPE, output, output_frame );
848 :
849 :
850 : /*----------------------------------------------------------------*
851 : * Common Stereo updates
852 : *----------------------------------------------------------------*/
853 :
854 145402 : hCPE->last_element_brate = hCPE->element_brate;
855 145402 : move32();
856 145402 : hCPE->last_element_mode = hCPE->element_mode;
857 145402 : move32();
858 :
859 145402 : if ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
860 : {
861 6418 : hCPE->element_brate = element_brate_ref;
862 6418 : move32();
863 : }
864 :
865 145402 : test();
866 145402 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
867 : {
868 62798 : stereo_cng_dec_update( hCPE, ivas_total_brate );
869 : }
870 :
871 145402 : st_ivas->BER_detect = s_or( st_ivas->BER_detect, sts[0]->BER_detect );
872 145402 : st_ivas->BER_detect = s_or( st_ivas->BER_detect, sts[1]->BER_detect );
873 145402 : move16();
874 145402 : move16();
875 :
876 :
877 145402 : pop_wmops();
878 145402 : return error;
879 : }
880 :
881 :
882 : /*-------------------------------------------------------------------------
883 : * create_cpe_dec_fx()
884 : *
885 : * Create, allocate and initialize IVAS decoder CPE handle
886 : *-------------------------------------------------------------------------*/
887 :
888 2438 : ivas_error create_cpe_dec(
889 : Decoder_Struct *st_ivas, /* i/o: IVAS decoder structure */
890 : const Word16 cpe_id, /* i : CPE # identifier */
891 : const Word32 element_brate /* i : element bitrate */
892 : )
893 : {
894 : Word16 i, n;
895 : CPE_DEC_HANDLE hCPE;
896 : Decoder_State *st;
897 : Word32 output_Fs;
898 : ivas_error error;
899 : Word32 cpe_brate;
900 :
901 2438 : error = IVAS_ERR_OK;
902 2438 : move32();
903 :
904 : /*-----------------------------------------------------------------*
905 : * Allocate CPE handle
906 : *-----------------------------------------------------------------*/
907 :
908 2438 : IF( ( hCPE = (CPE_DEC_HANDLE) malloc( sizeof( CPE_DEC_DATA ) ) ) == NULL )
909 : {
910 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CPE\n" ) );
911 : }
912 :
913 : /*-----------------------------------------------------------------*
914 : * Initialization - general parameters
915 : *-----------------------------------------------------------------*/
916 :
917 2438 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
918 2438 : move32();
919 2438 : hCPE->cpe_id = cpe_id;
920 2438 : move16();
921 2438 : hCPE->element_brate = element_brate;
922 2438 : move32();
923 2438 : hCPE->last_element_brate = hCPE->element_brate;
924 2438 : move32();
925 2438 : hCPE->element_mode = st_ivas->element_mode_init;
926 2438 : move16();
927 2438 : hCPE->last_element_mode = st_ivas->element_mode_init;
928 2438 : move16();
929 :
930 2438 : hCPE->hStereoDft = NULL;
931 2438 : hCPE->hStereoDftDmx = NULL;
932 2438 : hCPE->hStereoTD = NULL;
933 2438 : hCPE->hStereoMdct = NULL;
934 2438 : hCPE->hStereoTCA = NULL;
935 2438 : hCPE->hStereoICBWE = NULL;
936 2438 : hCPE->hStereoCng = NULL;
937 :
938 2438 : hCPE->stereo_switching_counter = 10;
939 2438 : move16();
940 2438 : hCPE->NbFrameMod = 7;
941 2438 : move16();
942 2438 : hCPE->lt_es_em_fx = 0;
943 2438 : move32();
944 :
945 : /* Note: nchan_out is considered to be related to the structure. This is nchan_out for CPE and for MASA_format is always 2. */
946 2438 : test();
947 2438 : test();
948 2438 : test();
949 2438 : IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) )
950 : {
951 1897 : hCPE->nchan_out = CPE_CHANNELS;
952 1897 : move16();
953 : }
954 : ELSE
955 : {
956 541 : hCPE->nchan_out = s_min( CPE_CHANNELS, st_ivas->hDecoderConfig->nchan_out );
957 541 : move16();
958 : }
959 :
960 2438 : test();
961 2438 : test();
962 2438 : test();
963 2438 : IF( EQ_16( extract_l( st_ivas->ivas_format ), MASA_ISM_FORMAT ) && ( EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( (Word16) st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) )
964 : {
965 32 : cpe_brate = element_brate;
966 32 : move32();
967 : }
968 : ELSE
969 : {
970 2406 : cpe_brate = st_ivas->hDecoderConfig->ivas_total_brate;
971 2406 : move32();
972 : }
973 :
974 2438 : test();
975 2438 : test();
976 2438 : test();
977 2438 : test();
978 4857 : if ( ( ( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) && LT_32( st_ivas->hDecoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) ) ||
979 2479 : ( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && LT_32( cpe_brate, MASA_STEREO_MIN_BITRATE ) ) ) &&
980 28 : GT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
981 : {
982 28 : hCPE->nchan_out = 1;
983 28 : move16();
984 : }
985 :
986 7314 : FOR( n = 0; n < CPE_CHANNELS; n++ )
987 : {
988 4876 : set32_fx( hCPE->prev_hb_synth_fx[n], 0, NS2SA_FX2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, DELAY_BWE_TOTAL_NS ) ) );
989 4876 : set32_fx( hCPE->prev_synth_fx[n], 0, NS2SA_FX2( output_Fs, L_sub( IVAS_DEC_DELAY_NS, STEREO_DFT32MS_OVL_NS ) ) );
990 : }
991 2438 : hCPE->q_prev_synth_fx = 0;
992 2438 : move16();
993 2438 : hCPE->brate_surplus = 0;
994 2438 : move32();
995 :
996 : /*-----------------------------------------------------------------*
997 : * DFT stereo I/O Buffers: allocate and initialize
998 : *-----------------------------------------------------------------*/
999 :
1000 7314 : FOR( i = 0; i < CPE_CHANNELS; i++ )
1001 : {
1002 4876 : test();
1003 4876 : test();
1004 4876 : test();
1005 4876 : test();
1006 4876 : test();
1007 4876 : IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) ||
1008 : ( EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) && EQ_16( (Word16) st_ivas->mc_mode, MC_MODE_MCMASA ) ) || st_ivas->sba_dirac_stereo_flag )
1009 : {
1010 730 : IF( ( hCPE->input_mem_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL )
1011 : {
1012 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
1013 : }
1014 730 : set32_fx( hCPE->input_mem_fx[i], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
1015 :
1016 730 : IF( ( hCPE->input_mem_LB_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * STEREO_DFT32MS_OVL_16k ) ) == NULL )
1017 : {
1018 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
1019 : }
1020 730 : set32_fx( hCPE->input_mem_LB_fx[i], 0, STEREO_DFT32MS_OVL_16k );
1021 :
1022 730 : IF( i == 0 )
1023 : {
1024 365 : IF( ( hCPE->input_mem_BPF_fx[0] = (Word32 *) malloc( sizeof( Word32 ) * STEREO_DFT32MS_OVL_16k ) ) == NULL )
1025 : {
1026 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
1027 : }
1028 365 : set32_fx( hCPE->input_mem_BPF_fx[0], 0, STEREO_DFT32MS_OVL_16k );
1029 : }
1030 :
1031 730 : IF( ( hCPE->output_mem_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) ) ) == NULL )
1032 : {
1033 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
1034 : }
1035 730 : set32_fx( hCPE->output_mem_fx[i], 0, NS2SA_FX2( output_Fs, STEREO_DFT32MS_OVL_NS ) );
1036 730 : hCPE->q_output_mem_fx[i] = Q11;
1037 730 : move16();
1038 730 : IF( LT_16( i, hCPE->nchan_out ) )
1039 : {
1040 680 : IF( ( hCPE->prev_synth_chs_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * NS2SA_FX2( output_Fs, FRAME_SIZE_NS ) ) ) == NULL )
1041 : {
1042 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for DFT stereo memory\n" ) );
1043 : }
1044 680 : set32_fx( hCPE->prev_synth_chs_fx[i], 0, NS2SA_FX2( output_Fs, FRAME_SIZE_NS ) );
1045 : }
1046 : ELSE
1047 : {
1048 50 : hCPE->prev_synth_chs_fx[i] = NULL;
1049 : }
1050 : }
1051 : ELSE
1052 : {
1053 4146 : hCPE->input_mem_fx[i] = NULL;
1054 4146 : hCPE->input_mem_LB_fx[i] = NULL;
1055 4146 : if ( i == 0 )
1056 : {
1057 2073 : hCPE->input_mem_BPF_fx[0] = NULL;
1058 : }
1059 4146 : hCPE->output_mem_fx[i] = NULL;
1060 4146 : hCPE->q_output_mem_fx[i] = 0;
1061 4146 : move16();
1062 4146 : hCPE->prev_synth_chs_fx[i] = NULL;
1063 : }
1064 : }
1065 :
1066 : /*-----------------------------------------------------------------*
1067 : * CoreCoder, 2 instances: allocate and initialize
1068 : *-----------------------------------------------------------------*/
1069 :
1070 7240 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1071 : {
1072 4839 : IF( st_ivas->sba_dirac_stereo_flag && EQ_16( st_ivas->nchan_transport, 1 ) )
1073 : {
1074 : /* for SBA DirAC stereo output CPE element is only used for upmix, core coder is found in SCE element used for core decoding */
1075 37 : BREAK;
1076 : }
1077 :
1078 4802 : IF( ( st = (DEC_CORE_HANDLE) malloc( sizeof( Decoder_State ) ) ) == NULL )
1079 : {
1080 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CoreCoder structure\n" ) );
1081 : }
1082 :
1083 4802 : copy_decoder_config( st_ivas, st );
1084 :
1085 : // st->total_brate = hCPE->element_brate / ( CPE_CHANNELS );
1086 4802 : st->total_brate = L_shr( hCPE->element_brate, 1 ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
1087 4802 : move32();
1088 4802 : st->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
1089 4802 : move32();
1090 4802 : st->is_ism_format = 0;
1091 4802 : move16();
1092 :
1093 4802 : IF( NE_32( ( error = init_decoder_ivas_fx( st, n, st_ivas->mc_mode ) ), IVAS_ERR_OK ) )
1094 : {
1095 0 : return error;
1096 : }
1097 :
1098 4802 : hCPE->hCoreCoder[n] = st;
1099 : }
1100 :
1101 : /*-----------------------------------------------------------------*
1102 : * DFT stereo initialization
1103 : *-----------------------------------------------------------------*/
1104 :
1105 :
1106 2438 : test();
1107 2438 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) || ( st_ivas->sba_dirac_stereo_flag && hCPE->cpe_id == 0 ) )
1108 : {
1109 193 : IF( NE_32( ( error = stereo_dft_dec_create_fx( &( hCPE->hStereoDft ), hCPE->element_brate, output_Fs, st_ivas->sba_dirac_stereo_flag, st_ivas->nchan_transport ) ), IVAS_ERR_OK ) )
1110 : {
1111 0 : return error;
1112 : }
1113 : }
1114 :
1115 : /*-----------------------------------------------------------------*
1116 : * DFT stereo mono DMX initialization
1117 : *-----------------------------------------------------------------*/
1118 :
1119 2438 : test();
1120 2438 : IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( hCPE->nchan_out, 1 ) )
1121 : {
1122 45 : IF( ( hCPE->hStereoDftDmx = (STEREO_DFT_DMX_DATA_HANDLE) malloc( sizeof( STEREO_DFT_DMX_DATA ) ) ) == NULL )
1123 : {
1124 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo DFT mono output\n" ) );
1125 : }
1126 :
1127 45 : stereo_dft_dmx_out_reset_fx( hCPE->hStereoDftDmx );
1128 : }
1129 :
1130 : /*-----------------------------------------------------------------*
1131 : * Temporal inter-channel alignment initialization
1132 : *-----------------------------------------------------------------*/
1133 :
1134 2438 : test();
1135 2438 : test();
1136 2438 : test();
1137 2438 : IF( ( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) || ( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) ) ) && NE_16( hCPE->nchan_out, 1 ) )
1138 : {
1139 98 : IF( ( hCPE->hStereoTCA = (STEREO_TCA_DEC_HANDLE) malloc( sizeof( STEREO_TCA_DEC_DATA ) ) ) == NULL )
1140 : {
1141 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo TCA\n" ) );
1142 : }
1143 :
1144 98 : stereo_tca_init_dec_fx( hCPE->hStereoTCA );
1145 : }
1146 :
1147 : /*-----------------------------------------------------------------*
1148 : * Stereo IC BWE initialization
1149 : *-----------------------------------------------------------------*/
1150 :
1151 2438 : test();
1152 2438 : test();
1153 2438 : IF( NE_16( hCPE->element_mode, IVAS_CPE_MDCT ) && !( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) && EQ_16( hCPE->nchan_out, 1 ) ) )
1154 : {
1155 89 : IF( ( hCPE->hStereoICBWE = (STEREO_ICBWE_DEC_HANDLE) malloc( sizeof( STEREO_ICBWE_DEC_DATA ) ) ) == NULL )
1156 : {
1157 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo ICBWE\n" ) );
1158 : }
1159 :
1160 89 : stereo_icBWE_init_dec_fx( hCPE->hStereoICBWE );
1161 : }
1162 :
1163 : /*-----------------------------------------------------------------*
1164 : * TD stereo initialization
1165 : *-----------------------------------------------------------------*/
1166 :
1167 2438 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
1168 : {
1169 0 : IF( ( hCPE->hStereoTD = (STEREO_TD_DEC_DATA_HANDLE) malloc( sizeof( STEREO_TD_DEC_DATA ) ) ) == NULL )
1170 : {
1171 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for TD Stereo\n" ) );
1172 : }
1173 :
1174 0 : stereo_td_init_dec_fx( hCPE->hStereoTD, hCPE->last_element_mode );
1175 : }
1176 :
1177 : /*-----------------------------------------------------------------*
1178 : * MDCT stereo initialization
1179 : *-----------------------------------------------------------------*/
1180 :
1181 2438 : test();
1182 2438 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) && EQ_16( st_ivas->nCPE, 1 ) )
1183 : {
1184 339 : IF( ( hCPE->hStereoMdct = (STEREO_MDCT_DEC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_DEC_DATA ) ) ) == NULL )
1185 : {
1186 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo MDCT\n" ) );
1187 : }
1188 :
1189 339 : test();
1190 339 : IF( EQ_32( st_ivas->ivas_format, STEREO_FORMAT ) && LE_32( hCPE->element_brate, MAX_MDCT_ITD_BRATE ) )
1191 : {
1192 13 : hCPE->hStereoMdct->use_itd = 1;
1193 13 : move16();
1194 : }
1195 : ELSE
1196 : {
1197 326 : hCPE->hStereoMdct->use_itd = 0;
1198 326 : move16();
1199 : }
1200 :
1201 339 : hCPE->hStereoMdct->reverse_dmx = 0;
1202 339 : move16();
1203 339 : hCPE->hStereoMdct->smooth_ratio_fx = ONE_IN_Q26;
1204 339 : move32();
1205 339 : set16_fx( hCPE->hStereoMdct->prev_ms_mask[0], 0, MAX_SFB );
1206 339 : set16_fx( hCPE->hStereoMdct->prev_ms_mask[1], 0, MAX_SFB );
1207 339 : hCPE->hStereoMdct->lastCoh_fx = ONE_IN_Q14;
1208 339 : move16();
1209 339 : hCPE->hStereoMdct->mdct_stereo_mode[0] = SMDCT_DUAL_MONO;
1210 339 : move16();
1211 339 : hCPE->hStereoMdct->mdct_stereo_mode[1] = SMDCT_DUAL_MONO;
1212 339 : move16();
1213 339 : hCPE->hStereoMdct->IGFStereoMode[0] = -1;
1214 339 : move16();
1215 339 : hCPE->hStereoMdct->IGFStereoMode[1] = -1;
1216 339 : move16();
1217 : }
1218 :
1219 : /*-----------------------------------------------------------------*
1220 : * Stereo CNG initialization
1221 : *-----------------------------------------------------------------*/
1222 :
1223 2438 : test();
1224 2438 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) || EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
1225 : {
1226 97 : IF( ( hCPE->hStereoCng = (STEREO_CNG_DEC_HANDLE) malloc( sizeof( STEREO_CNG_DEC ) ) ) == NULL )
1227 : {
1228 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Stereo CNG\n" ) );
1229 : }
1230 97 : stereo_cng_init_dec_fx( hCPE->hStereoCng, &hCPE->hCoreCoder[0]->hFdCngDec->hFdCngCom->frameSize );
1231 : }
1232 :
1233 2438 : st_ivas->hCPE[cpe_id] = hCPE;
1234 :
1235 2438 : return error;
1236 : }
1237 :
1238 :
1239 : /*-------------------------------------------------------------------------
1240 : * destroy_cpe_dec_fx()
1241 : *
1242 : * Destroy and deallocate IVAS decoder CPE handle
1243 : *-------------------------------------------------------------------------*/
1244 :
1245 2438 : void destroy_cpe_dec(
1246 : CPE_DEC_HANDLE hCPE /* i/o: CPE decoder structure */
1247 : )
1248 : {
1249 : Word16 n;
1250 : Decoder_State *st;
1251 :
1252 7314 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1253 : {
1254 4876 : st = hCPE->hCoreCoder[n];
1255 :
1256 4876 : IF( st != NULL )
1257 : {
1258 4698 : destroy_core_dec_fx( st );
1259 :
1260 4698 : free( st );
1261 4698 : st = NULL;
1262 : }
1263 : }
1264 :
1265 2438 : IF( hCPE->hStereoDft != NULL )
1266 : {
1267 176 : stereo_dft_dec_destroy( &( hCPE->hStereoDft ) );
1268 176 : hCPE->hStereoDft = NULL;
1269 : }
1270 :
1271 2438 : IF( hCPE->hStereoDftDmx != NULL )
1272 : {
1273 31 : free( hCPE->hStereoDftDmx );
1274 31 : hCPE->hStereoDftDmx = NULL;
1275 : }
1276 :
1277 2438 : IF( hCPE->hStereoTD != NULL )
1278 : {
1279 1 : free( hCPE->hStereoTD );
1280 1 : hCPE->hStereoTD = NULL;
1281 : }
1282 :
1283 2438 : IF( hCPE->hStereoMdct != NULL )
1284 : {
1285 363 : free( hCPE->hStereoMdct );
1286 363 : hCPE->hStereoMdct = NULL;
1287 : }
1288 :
1289 2438 : IF( hCPE->hStereoTCA != NULL )
1290 : {
1291 97 : free( hCPE->hStereoTCA );
1292 97 : hCPE->hStereoTCA = NULL;
1293 : }
1294 :
1295 2438 : IF( hCPE->hStereoICBWE != NULL )
1296 : {
1297 103 : free( hCPE->hStereoICBWE );
1298 103 : hCPE->hStereoICBWE = NULL;
1299 : }
1300 :
1301 2438 : IF( hCPE->input_mem_LB_fx[0] != NULL )
1302 : {
1303 1095 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1304 : {
1305 730 : free( hCPE->input_mem_LB_fx[n] );
1306 730 : hCPE->input_mem_LB_fx[n] = NULL;
1307 730 : free( hCPE->input_mem_fx[n] );
1308 730 : hCPE->input_mem_fx[n] = NULL;
1309 730 : free( hCPE->output_mem_fx[n] );
1310 730 : hCPE->output_mem_fx[n] = NULL;
1311 :
1312 730 : IF( hCPE->prev_synth_chs_fx[n] != NULL )
1313 : {
1314 693 : free( hCPE->prev_synth_chs_fx[n] );
1315 693 : hCPE->prev_synth_chs_fx[n] = NULL;
1316 : }
1317 : }
1318 365 : free( hCPE->input_mem_BPF_fx[0] );
1319 365 : hCPE->input_mem_BPF_fx[0] = NULL;
1320 : }
1321 :
1322 2438 : IF( hCPE->hStereoCng != NULL )
1323 : {
1324 81 : free( hCPE->hStereoCng );
1325 81 : hCPE->hStereoCng = NULL;
1326 : }
1327 :
1328 2438 : free( hCPE );
1329 :
1330 2438 : return;
1331 : }
1332 :
1333 :
1334 : /*-------------------------------------------------------------------------
1335 : * read_stereo_mode_and_bwidth_fx()
1336 : *
1337 : * Read stereo technology info & audio bandwidth
1338 : *-------------------------------------------------------------------------*/
1339 :
1340 386540 : static void read_stereo_mode_and_bwidth_fx(
1341 : CPE_DEC_HANDLE hCPE, /* i/o: CPE handle */
1342 : const Decoder_Struct *st_ivas /* i : decoder main structure */
1343 : )
1344 : {
1345 : Decoder_State **sts;
1346 :
1347 : /*-----------------------------------------------------------------*
1348 : * BFI or NO_DATA frame: Use stereo parameters from last (active) frame
1349 : *-----------------------------------------------------------------*/
1350 :
1351 386540 : test();
1352 386540 : if ( st_ivas->bfi || LT_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
1353 : {
1354 18929 : hCPE->element_mode = hCPE->last_element_mode;
1355 18929 : move16();
1356 : }
1357 :
1358 : /*-----------------------------------------------------------------*
1359 : * SID frame: get element mode from SID side info
1360 : *-----------------------------------------------------------------*/
1361 :
1362 367611 : ELSE IF( EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_SID_5k2 ) )
1363 : {
1364 2069 : SWITCH( st_ivas->sid_format )
1365 : {
1366 1418 : case SID_DFT_STEREO:
1367 1418 : hCPE->element_mode = IVAS_CPE_DFT;
1368 1418 : move16();
1369 : /* Read CNG type */
1370 1418 : hCPE->hCoreCoder[0]->cng_type = get_next_indice_fx( hCPE->hCoreCoder[0], 1 );
1371 :
1372 : /* Read BW information in SID */
1373 1418 : hCPE->hCoreCoder[0]->bwidth = get_next_indice_fx( hCPE->hCoreCoder[0], 2 );
1374 1418 : move16();
1375 1418 : move16();
1376 :
1377 1418 : BREAK;
1378 577 : case SID_MDCT_STEREO:
1379 : /* 2TC SBA DTX also uses MDCT-Stereo DTX */
1380 : case SID_SBA_2TC:
1381 577 : hCPE->element_mode = IVAS_CPE_MDCT;
1382 577 : move16();
1383 577 : BREAK;
1384 0 : case SID_SBA_1TC:
1385 0 : assert( !"Forbidden value for SID format in CPE (SBA 1TC), should have already been adressed earlier" );
1386 : BREAK;
1387 0 : case SID_MASA_1TC:
1388 0 : hCPE->element_mode = IVAS_SCE;
1389 0 : move16();
1390 0 : BREAK;
1391 74 : case SID_MASA_2TC:
1392 : /* 2TC MASA DTX uses MDCT or DFT based core */
1393 74 : if ( EQ_16( hCPE->element_mode, IVAS_CPE_TD ) )
1394 : {
1395 0 : hCPE->element_mode = IVAS_CPE_DFT;
1396 0 : move16();
1397 : }
1398 74 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_DFT ) )
1399 : {
1400 : /* Read CNG type */
1401 74 : hCPE->hCoreCoder[0]->cng_type = get_next_indice_fx( hCPE->hCoreCoder[0], 1 );
1402 :
1403 : /* Read BW information in SID */
1404 74 : hCPE->hCoreCoder[0]->bwidth = get_next_indice_fx( hCPE->hCoreCoder[0], 2 );
1405 74 : move16();
1406 74 : move16();
1407 : }
1408 74 : BREAK;
1409 0 : default:
1410 : /* this is what has been done for all modes previously, may need adaptation in the future */
1411 0 : hCPE->element_mode = hCPE->last_element_mode;
1412 0 : move16();
1413 0 : BREAK;
1414 : }
1415 : }
1416 :
1417 : /*-----------------------------------------------------------------*
1418 : * active frame: read element mode and audio bandwidth info
1419 : *-----------------------------------------------------------------*/
1420 :
1421 : ELSE
1422 : {
1423 365542 : sts = hCPE->hCoreCoder;
1424 365542 : test();
1425 365542 : IF( st_ivas->hMCT && hCPE->cpe_id != 0 )
1426 : {
1427 146170 : sts[0]->bwidth = st_ivas->hCPE[0]->hCoreCoder[0]->bwidth;
1428 146170 : move16();
1429 146170 : sts[1]->bwidth = st_ivas->hCPE[0]->hCoreCoder[0]->bwidth;
1430 146170 : move16();
1431 : }
1432 : ELSE
1433 : {
1434 : /* read stereo technology info */
1435 219372 : test();
1436 219372 : IF( LT_32( hCPE->element_brate, MIN_BRATE_MDCT_STEREO ) && st_ivas->hMCT == NULL )
1437 : {
1438 51503 : hCPE->element_mode = add( get_next_indice_fx( sts[0], NBITS_ELEMENT_MODE ), IVAS_CPE_DFT );
1439 51503 : move16();
1440 : }
1441 : ELSE
1442 : {
1443 167869 : hCPE->element_mode = IVAS_CPE_MDCT;
1444 167869 : move16();
1445 : }
1446 :
1447 : /* read the bandwidth */
1448 219372 : IF( LT_32( hCPE->element_brate, MIN_BRATE_FB_STEREO ) )
1449 : {
1450 : /* WB and SWB are supported */
1451 31674 : sts[0]->bwidth = add( get_next_indice_fx( sts[0], 1 ), WB );
1452 31674 : move16();
1453 31674 : sts[1]->bwidth = sts[0]->bwidth;
1454 31674 : move16();
1455 : }
1456 : ELSE
1457 : {
1458 : /* WB, SWB and FB are supported */
1459 187698 : sts[0]->bwidth = get_next_indice_fx( sts[0], NBITS_BWIDTH );
1460 187698 : move16();
1461 187698 : sts[1]->bwidth = sts[0]->bwidth;
1462 187698 : move16();
1463 : }
1464 : }
1465 : }
1466 :
1467 386540 : return;
1468 : }
1469 :
1470 :
1471 : /*-------------------------------------------------------------------------
1472 : * stereo_mode_combined_format_dec_fx()
1473 : *
1474 : * Set stereo format in a combined format
1475 : *-------------------------------------------------------------------------*/
1476 :
1477 386540 : static void stereo_mode_combined_format_dec_fx(
1478 : const Decoder_Struct *st_ivas, /* i : decoder main structure */
1479 : CPE_DEC_HANDLE hCPE /* i/o: CPE handle */
1480 : )
1481 : {
1482 : Word32 element_brate_ref;
1483 :
1484 386540 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) )
1485 : {
1486 6418 : element_brate_ref = hCPE->element_brate;
1487 6418 : move32();
1488 :
1489 6418 : test();
1490 6418 : test();
1491 6418 : test();
1492 6418 : test();
1493 6418 : IF( EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) &&
1494 : ( ( EQ_16( st_ivas->nchan_ism, 3 ) && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_96k ) ) ||
1495 : ( EQ_16( st_ivas->nchan_ism, 4 ) && EQ_32( st_ivas->hDecoderConfig->ivas_total_brate, IVAS_128k ) ) ) )
1496 : {
1497 422 : IF( !st_ivas->bfi )
1498 : {
1499 : /* read OMASA stereo mode signalling */
1500 420 : IF( get_next_indice_fx( hCPE->hCoreCoder[0], NBITS_ELEMENT_MODE ) )
1501 : {
1502 0 : hCPE->element_mode = IVAS_CPE_MDCT;
1503 0 : move16();
1504 : }
1505 : ELSE
1506 : {
1507 420 : hCPE->element_mode = IVAS_CPE_DFT;
1508 420 : move16();
1509 : }
1510 : }
1511 :
1512 422 : IF( EQ_16( hCPE->element_mode, IVAS_CPE_MDCT ) )
1513 : {
1514 0 : hCPE->element_brate = IVAS_64k;
1515 0 : move32();
1516 0 : hCPE->brate_surplus = L_sub( hCPE->brate_surplus, L_sub( hCPE->element_brate, element_brate_ref ) );
1517 0 : move32();
1518 : }
1519 : }
1520 : }
1521 :
1522 386540 : return;
1523 : }
|