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 "ivas_cnst.h"
37 : #include "prot_fx.h"
38 : #include "ivas_prot_fx.h"
39 : #include "ivas_stat_enc.h"
40 : #include "ivas_rom_com.h"
41 : #include "wmc_auto.h"
42 : #include "ivas_prot_fx.h"
43 : #include "prot_fx_enc.h"
44 : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
45 : #include <string.h>
46 : #endif
47 :
48 :
49 : /*-------------------------------------------------------------------*
50 : * ivas_write_format()
51 : *
52 : * Write IVAS format signaling
53 : *-------------------------------------------------------------------*/
54 :
55 425922 : void ivas_write_format_fx(
56 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
57 : )
58 : {
59 : Word16 ind, nBits, extra_bits;
60 :
61 425922 : ind = 0;
62 425922 : move16();
63 :
64 425922 : nBits = IVAS_FORMAT_SIGNALING_NBITS;
65 425922 : move16();
66 :
67 425922 : extra_bits = sub( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED, IVAS_FORMAT_SIGNALING_NBITS );
68 :
69 425922 : switch ( st_ivas->hEncoderConfig->ivas_format )
70 : {
71 72486 : case STEREO_FORMAT:
72 72486 : ind = 0;
73 72486 : move16();
74 72486 : BREAK;
75 103826 : case ISM_FORMAT:
76 103826 : ind = 2;
77 103826 : move16();
78 103826 : IF( GE_32( st_ivas->hEncoderConfig->ivas_total_brate, IVAS_24k4 ) )
79 : {
80 95106 : ind = 4;
81 95106 : move16();
82 :
83 95106 : nBits = add( nBits, extra_bits ); /* Q0 */
84 : }
85 103826 : BREAK;
86 48850 : case MC_FORMAT:
87 48850 : ind = 1;
88 48850 : move16();
89 48850 : BREAK;
90 122500 : case SBA_FORMAT:
91 122500 : ind = 6;
92 122500 : move16();
93 :
94 122500 : nBits = add( nBits, extra_bits ); /* Q0 */
95 122500 : BREAK;
96 30626 : case MASA_FORMAT:
97 30626 : ind = 7;
98 30626 : move16();
99 :
100 30626 : nBits = add( nBits, extra_bits ); /* Q0 */
101 30626 : BREAK;
102 10634 : case MASA_ISM_FORMAT:
103 10634 : IF( st_ivas->ism_mode == ISM_MODE_NONE )
104 : {
105 2388 : ind = 7; /* send MASA format */
106 2388 : move16();
107 2388 : nBits = add( nBits, extra_bits ); /* Q0 */
108 : }
109 : ELSE
110 : {
111 8246 : ind = 10;
112 8246 : move16();
113 8246 : nBits = add( nBits, add( extra_bits, IVAS_COMBINED_FORMAT_SIGNALLING_BITS ) ); /* Q0 */
114 : }
115 10634 : BREAK;
116 37000 : case SBA_ISM_FORMAT:
117 37000 : IF( LT_32( st_ivas->hEncoderConfig->ivas_total_brate, IVAS_24k4 ) )
118 : {
119 2881 : ind = 6; /* send SBA format */
120 2881 : move16();
121 2881 : nBits = add( nBits, extra_bits ); /* Q0 */
122 : }
123 : ELSE
124 : {
125 34119 : ind = 11; /* 1011 */
126 34119 : move16();
127 34119 : nBits = add( nBits, add( extra_bits, IVAS_COMBINED_FORMAT_SIGNALLING_BITS ) ); /* Q0 */
128 : }
129 37000 : BREAK;
130 0 : default:
131 0 : assert( !"Invalid format. Aborting." );
132 : BREAK;
133 : }
134 :
135 425922 : IF( st_ivas->hSCE[0] != NULL )
136 : {
137 181689 : push_indice( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, IND_IVAS_FORMAT, ind, nBits );
138 : }
139 244233 : ELSE IF( st_ivas->hCPE[0] != NULL )
140 : {
141 244233 : push_indice( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, IND_IVAS_FORMAT, ind, nBits );
142 : }
143 :
144 425922 : return;
145 : }
146 :
147 : /*-------------------------------------------------------------------*
148 : * ivas_write_format_sid()
149 : *
150 : * Write IVAS format signaling in SID frames
151 : *-------------------------------------------------------------------*/
152 :
153 2773 : void ivas_write_format_sid_fx(
154 : const IVAS_FORMAT ivas_format, /* i : IVAS format */
155 : const Word16 element_mode, /* i : element bitrate Q0*/
156 : BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
157 : const Word16 sba_order, /* i : Ambisonic (SBA) order */
158 : const Word16 sba_planar /* i : SBA planar flag */
159 : )
160 : {
161 2773 : Word16 ind = 0; /* to avoid compilation warning */
162 2773 : move16();
163 :
164 2773 : SWITCH( ivas_format )
165 : {
166 1875 : case STEREO_FORMAT:
167 1875 : IF( EQ_16( element_mode, IVAS_CPE_MDCT ) )
168 : {
169 416 : ind = SID_MDCT_STEREO;
170 416 : move16();
171 : }
172 1459 : ELSE IF( EQ_16( element_mode, IVAS_CPE_DFT ) )
173 : {
174 1459 : ind = SID_DFT_STEREO;
175 1459 : move16();
176 : }
177 : ELSE
178 : {
179 0 : assert( !"Wrong stereo mode for SID format signaling" );
180 : }
181 1875 : BREAK;
182 536 : case ISM_FORMAT:
183 536 : ind = SID_ISM;
184 536 : move16();
185 536 : BREAK;
186 171 : case SBA_FORMAT:
187 171 : SWITCH( element_mode )
188 : {
189 110 : case IVAS_SCE:
190 110 : ind = SID_SBA_1TC;
191 110 : move16();
192 110 : BREAK;
193 61 : case IVAS_CPE_MDCT:
194 61 : ind = SID_SBA_2TC;
195 61 : move16();
196 61 : BREAK;
197 0 : default:
198 0 : assert( !"Wrong element mode for SBA DTX!" );
199 : BREAK;
200 : }
201 171 : BREAK;
202 191 : case MASA_FORMAT:
203 191 : IF( EQ_16( element_mode, IVAS_SCE ) )
204 : {
205 117 : ind = SID_MASA_1TC;
206 117 : move16();
207 : }
208 : ELSE
209 : {
210 74 : ind = SID_MASA_2TC;
211 74 : move16();
212 : }
213 191 : BREAK;
214 0 : default:
215 0 : assert( !"Reserved SID format symbol written." );
216 : BREAK;
217 : }
218 :
219 2773 : push_indice( hBstr, IND_IVAS_FORMAT, ind, SID_FORMAT_NBITS );
220 :
221 2773 : IF( EQ_32( ivas_format, SBA_FORMAT ) )
222 : {
223 : /* Write SBA planar flag */
224 171 : push_indice( hBstr, IND_SMODE, sba_planar, SBA_PLANAR_BITS );
225 :
226 : /* Write SBA order */
227 171 : push_indice( hBstr, IND_SMODE, sba_order, SBA_ORDER_BITS );
228 : }
229 :
230 2773 : return;
231 : }
232 :
233 : /*-------------------------------------------------------------------*
234 : * getNumChanAnalysis()
235 : *
236 : * get number of input channels used for analysis/coding
237 : *-------------------------------------------------------------------*/
238 :
239 : /*! r: number of channels to be analysed */
240 425542 : Word16 getNumChanAnalysis_fx(
241 : Encoder_Struct *st_ivas /* i : IVAS encoder structure */
242 : )
243 : {
244 : Word16 n;
245 :
246 425542 : n = add( st_ivas->nSCE, CPE_CHANNELS * st_ivas->nCPE ); /* Q0 */
247 425542 : test();
248 425542 : test();
249 425542 : test();
250 425542 : test();
251 425542 : IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_FORMAT ) )
252 : {
253 122988 : n = imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ); /* Q0 */
254 : }
255 302554 : ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MC_FORMAT ) && ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) || EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) ) )
256 : {
257 22012 : n = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */
258 22012 : move16();
259 : }
260 280542 : ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
261 : {
262 800 : n = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */
263 800 : move16();
264 : }
265 279742 : ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
266 : {
267 20754 : n = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */
268 20754 : move16();
269 : }
270 258988 : ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) )
271 : {
272 9088 : n = st_ivas->hEncoderConfig->nchan_inp; /* Q0 */
273 9088 : move16();
274 : }
275 249900 : ELSE IF( EQ_32( st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) )
276 : {
277 37074 : n = add( st_ivas->hEncoderConfig->nchan_ism, imult1616( add( st_ivas->sba_analysis_order, 1 ), add( st_ivas->sba_analysis_order, 1 ) ) ); /* Q0 */
278 : }
279 :
280 425542 : return n;
281 : }
282 : /*-------------------------------------------------------------------*
283 : * copy_encoder_config_fx()
284 : *
285 : * Copy configuration structrue to the state structrure
286 : *-------------------------------------------------------------------*/
287 :
288 24168 : void copy_encoder_config_fx(
289 : Encoder_Struct *st_ivas, /* i : IVAS encoder structure */
290 : Encoder_State *st_fx, /* o : encoder state structure */
291 : const Word16 flag_all /* i : flag 1==update all, 0=partial update Q0*/
292 : )
293 : {
294 24168 : IF( flag_all )
295 : {
296 8836 : st_fx->input_Fs = st_ivas->hEncoderConfig->input_Fs; /* Q0 */
297 8836 : move32();
298 :
299 8836 : st_fx->last_codec_mode = st_ivas->last_codec_mode; /* Q0 */
300 8836 : move16();
301 8836 : st_fx->last_total_brate = st_ivas->hEncoderConfig->last_ivas_total_brate; /* Q0 */
302 8836 : move32();
303 :
304 8836 : st_fx->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON; /* Q0 */
305 8836 : move16();
306 :
307 8836 : st_fx->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR; /* Q0 */
308 8836 : move16();
309 : }
310 :
311 24168 : st_fx->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB; /* Q0 */
312 24168 : move16();
313 24168 : st_fx->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR; /* Q0 */
314 24168 : move16();
315 :
316 24168 : st_fx->codec_mode = st_ivas->codec_mode; /* Q0 */
317 24168 : move16();
318 24168 : st_fx->max_bwidth = st_ivas->hEncoderConfig->max_bwidth; /* Q0 */
319 24168 : move16();
320 :
321 24168 : st_fx->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON; /* Q0 */
322 24168 : move16();
323 24168 : st_fx->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset; /* Q0 */
324 24168 : move16();
325 24168 : st_fx->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator; /* Q0 */
326 24168 : move16();
327 :
328 : #ifdef DEBUGGING
329 : st_fx->force = st_ivas->hEncoderConfig->force;
330 : #ifdef DEBUG_FORCE_DIR
331 : st_fx->force_dir = st_ivas->hEncoderConfig->force_dir;
332 : #endif
333 : #endif
334 :
335 24168 : st_fx->element_mode = st_ivas->hEncoderConfig->element_mode_init; /* Q0 */
336 24168 : move16();
337 :
338 24168 : return;
339 : }
340 :
341 : /*-------------------------------------------------------------------------
342 : * ivas_initialize_handles_enc_fx()
343 : *
344 : * NULL initialization of handles
345 : *-------------------------------------------------------------------------*/
346 :
347 627 : void ivas_initialize_handles_enc_fx(
348 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
349 : )
350 : {
351 : Word16 i;
352 :
353 3135 : FOR( i = 0; i < MAX_SCE; i++ )
354 : {
355 2508 : st_ivas->hSCE[i] = NULL;
356 : }
357 :
358 4389 : FOR( i = 0; i < MAX_CPE; i++ )
359 : {
360 3762 : st_ivas->hCPE[i] = NULL;
361 : }
362 :
363 627 : st_ivas->mem_hp20_in_fx = NULL;
364 :
365 : /* ISM metadata handles */
366 3135 : FOR( i = 0; i < MAX_NUM_OBJECTS; i++ )
367 : {
368 2508 : st_ivas->hIsmMetaData[i] = NULL;
369 : }
370 :
371 : /* ISM DTX handle */
372 627 : st_ivas->hISMDTX = NULL;
373 :
374 : /* Q Metadata handle */
375 627 : st_ivas->hQMetaData = NULL;
376 :
377 : /* DirAC handle */
378 627 : st_ivas->hDirAC = NULL;
379 :
380 : /* ParamISM handle */
381 627 : st_ivas->hParamIsm = NULL;
382 : /* SPAR handle */
383 627 : st_ivas->hSpar = NULL;
384 :
385 : /* MASA encoder handle */
386 627 : st_ivas->hMasa = NULL;
387 :
388 : /* MCT handle */
389 627 : st_ivas->hMCT = NULL;
390 :
391 : /* MC Param-Upmix handle */
392 627 : st_ivas->hMCParamUpmix = NULL;
393 :
394 : /* Parametric MC handle */
395 627 : st_ivas->hParamMC = NULL;
396 :
397 : /* Multi-channel MASA handle */
398 627 : st_ivas->hMcMasa = NULL;
399 :
400 : /* Stereo downmix for EVS encoder handle */
401 627 : st_ivas->hStereoDmxEVS = NULL;
402 :
403 : /* LFE handle */
404 627 : st_ivas->hLFE = NULL;
405 :
406 : /* LFE low pass filter handle */
407 627 : st_ivas->hLfeLpf = NULL;
408 :
409 : /* Object MASA handle */
410 627 : st_ivas->hOMasa = NULL;
411 :
412 : /* OSBA handle */
413 627 : st_ivas->hOSba = NULL;
414 :
415 627 : return;
416 : }
417 :
418 :
419 : /*-------------------------------------------------------------------*
420 : * ivas_init_encoder()
421 : *
422 : * Initialize IVAS encoder state structure
423 : *-------------------------------------------------------------------*/
424 627 : ivas_error ivas_init_encoder_fx(
425 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
426 : )
427 : {
428 : Word16 i, n;
429 : Word16 nchan_inp_buff;
430 : Word16 sce_id, cpe_id;
431 : IVAS_FORMAT ivas_format;
432 : Word32 input_Fs, ivas_total_brate;
433 : Word32 element_brate_tmp[MAX_NUM_OBJECTS];
434 : ENCODER_CONFIG_HANDLE hEncoderConfig;
435 : ivas_error error;
436 :
437 627 : error = IVAS_ERR_OK;
438 627 : move32();
439 :
440 627 : hEncoderConfig = st_ivas->hEncoderConfig;
441 627 : ivas_format = hEncoderConfig->ivas_format;
442 627 : move32();
443 627 : input_Fs = hEncoderConfig->input_Fs; /* Q0 */
444 627 : move32();
445 627 : ivas_total_brate = hEncoderConfig->ivas_total_brate; /* Q0 */
446 627 : move32();
447 :
448 627 : hEncoderConfig->last_ivas_total_brate = ivas_total_brate; /* Q0 */
449 627 : move32();
450 :
451 627 : if ( NE_16( ivas_format, MONO_FORMAT ) )
452 : {
453 : /* In IVAS, ensure that minimum coded bandwidth is WB */
454 624 : hEncoderConfig->max_bwidth = s_max( hEncoderConfig->max_bwidth, WB ); /* Q0 */
455 624 : move16();
456 : }
457 627 : st_ivas->ism_mode = ISM_MODE_NONE;
458 627 : move32();
459 627 : st_ivas->mc_mode = MC_MODE_NONE;
460 627 : move32();
461 :
462 627 : st_ivas->nchan_transport = -1;
463 627 : move16();
464 :
465 : /*-----------------------------------------------------------------*
466 : * Allocate floating-point input audio buffers
467 : *-----------------------------------------------------------------*/
468 :
469 627 : nchan_inp_buff = hEncoderConfig->nchan_inp; /* Q0 */
470 627 : move16();
471 627 : IF( EQ_16( ivas_format, MONO_FORMAT ) )
472 : {
473 3 : nchan_inp_buff = 0;
474 3 : move16();
475 : }
476 624 : ELSE IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) )
477 : {
478 44 : IF( EQ_16( sub( hEncoderConfig->nchan_inp, hEncoderConfig->nchan_ism ), 1 ) ) /* mono is duplicated in monoMASA */
479 : {
480 12 : nchan_inp_buff = add( nchan_inp_buff, 1 ); /* Q0 */
481 : }
482 :
483 44 : nchan_inp_buff = add( nchan_inp_buff, 1 ); /* for *data_separated_object Q0*/
484 : }
485 :
486 4301 : FOR( n = 0; n < nchan_inp_buff; n++ )
487 : {
488 : /* note: these are intra-frame heap memories */
489 3674 : IF( ( st_ivas->p_data_fx[n] = (Word32 *) malloc( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) * sizeof( Word32 ) ) ) == NULL )
490 : {
491 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point input audio buffer!\n" ) );
492 : }
493 3674 : set32_fx( st_ivas->p_data_fx[n], 0, extract_l( Mpy_32_16_1( input_Fs, INV_FRAME_PER_SEC_Q15 ) ) );
494 : }
495 627 : st_ivas->q_data_fx = Q11;
496 627 : move16();
497 9493 : FOR( ; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
498 : {
499 8866 : st_ivas->p_data_fx[n] = NULL;
500 : }
501 :
502 :
503 : /*-----------------------------------------------------------------*
504 : * Allocate and initialize buffer of indices
505 : *-----------------------------------------------------------------*/
506 :
507 : /* set the maximum allowed number of indices in the list */
508 627 : st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( ivas_format, ivas_total_brate ); /* Q0 */
509 627 : move16();
510 :
511 : /* allocate buffer of indices */
512 627 : IF( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL )
513 : {
514 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) );
515 : }
516 :
517 : /* reset the list of indices */
518 496367 : FOR( i = 0; i < st_ivas->ivas_max_num_indices; i++ )
519 : {
520 495740 : st_ivas->ind_list[i].nb_bits = -1;
521 495740 : move16();
522 : }
523 :
524 : #ifdef BITSTERAM_ANALYSIS
525 : for ( i = 0; i < st_ivas->ivas_max_num_indices; i++ )
526 : {
527 : memset( st_ivas->ind_list[i].function_name, 'A', 100 * sizeof( char ) );
528 : }
529 : #endif
530 :
531 : /* set the maximum allowed number of metadata indices in the list */
532 627 : st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate ); /* Q0 */
533 627 : move16();
534 : /* allocate buffer of metadata indices */
535 627 : IF( st_ivas->ivas_max_num_indices_metadata > 0 )
536 : {
537 624 : IF( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL )
538 : {
539 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) );
540 : }
541 :
542 : /* reset the list of metadata indices */
543 249364 : FOR( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ )
544 : {
545 248740 : st_ivas->ind_list_metadata[i].nb_bits = -1;
546 248740 : move16();
547 : }
548 : }
549 : ELSE
550 : {
551 3 : st_ivas->ind_list_metadata = NULL;
552 : }
553 :
554 : /*-----------------------------------------------------------------*
555 : * Allocate and initialize SCE/CPE and other handles
556 : *-----------------------------------------------------------------*/
557 :
558 627 : IF( EQ_32( ivas_format, MONO_FORMAT ) )
559 : {
560 3 : st_ivas->nSCE = 1; /* in mono, there is always only one SCE */
561 3 : move16();
562 3 : st_ivas->nCPE = 0;
563 3 : move16();
564 3 : st_ivas->nchan_transport = 1;
565 3 : move16();
566 3 : sce_id = 0;
567 3 : move16();
568 3 : test();
569 3 : IF( NE_32( ( error = create_evs_sce_enc_fx( st_ivas, sce_id, ivas_total_brate ) ), IVAS_ERR_OK ) )
570 : {
571 0 : return error;
572 : }
573 : /* prepare stereo downmix for EVS */
574 3 : IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) )
575 : {
576 2 : IF( ( error = stereo_dmx_evs_init_encoder_fx( &( st_ivas->hStereoDmxEVS ), input_Fs ) ) != IVAS_ERR_OK )
577 : {
578 0 : return error;
579 : }
580 : }
581 : }
582 624 : ELSE IF( EQ_32( ivas_format, STEREO_FORMAT ) )
583 : {
584 68 : st_ivas->nSCE = 0;
585 68 : move16();
586 68 : st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */
587 68 : move16();
588 68 : st_ivas->nchan_transport = CPE_CHANNELS;
589 68 : move16();
590 68 : cpe_id = 0;
591 68 : move16();
592 :
593 68 : IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK )
594 : {
595 0 : return error;
596 : }
597 : }
598 556 : ELSE IF( EQ_32( ivas_format, ISM_FORMAT ) )
599 : {
600 74 : st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate ); /* Q0 */
601 74 : move32();
602 :
603 74 : IF( ( error = ivas_ism_metadata_enc_create_fx( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK )
604 : {
605 0 : return error;
606 : }
607 :
608 261 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
609 : {
610 187 : IF( ( error = create_sce_enc_fx( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK )
611 : {
612 0 : return error;
613 : }
614 : }
615 :
616 74 : IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
617 : {
618 17 : IF( ( error = ivas_param_ism_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
619 : {
620 0 : return error;
621 : }
622 : }
623 :
624 74 : IF( st_ivas->hEncoderConfig->Opt_DTX_ON )
625 : {
626 14 : IF( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK )
627 : {
628 0 : return error;
629 : }
630 : }
631 : }
632 482 : ELSE IF( EQ_32( ivas_format, SBA_FORMAT ) || EQ_32( ivas_format, MASA_FORMAT ) )
633 : {
634 319 : IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
635 : {
636 0 : return error;
637 : }
638 :
639 319 : IF( EQ_32( ivas_format, SBA_FORMAT ) )
640 : {
641 244 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); /* Q0 */
642 244 : move16();
643 :
644 244 : IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK )
645 : {
646 0 : return error;
647 : }
648 244 : IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
649 : {
650 0 : return error;
651 : }
652 : }
653 : ELSE
654 : {
655 75 : st_ivas->nchan_transport = hEncoderConfig->nchan_inp; /* Q0 */
656 75 : move16();
657 :
658 75 : IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
659 : {
660 0 : return error;
661 : }
662 : }
663 :
664 449 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
665 : {
666 : Word32 res_dec, res_frac;
667 130 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
668 130 : IF( ( error = create_sce_enc_fx( st_ivas, sce_id, res_dec ) ) != IVAS_ERR_OK )
669 : {
670 0 : return error;
671 : }
672 130 : test();
673 130 : IF( EQ_16( ivas_format, SBA_FORMAT ) && st_ivas->hEncoderConfig->Opt_DTX_ON )
674 : {
675 45 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1;
676 45 : move16();
677 : }
678 : }
679 :
680 591 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
681 : {
682 : Word32 res_dec, res_frac;
683 272 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
684 272 : IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK )
685 : {
686 0 : return error;
687 : }
688 :
689 816 : FOR( n = 0; n < CPE_CHANNELS; n++ )
690 : {
691 544 : if ( hEncoderConfig->Opt_DTX_ON )
692 : {
693 56 : st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1;
694 56 : move16();
695 : }
696 : }
697 : }
698 :
699 319 : IF( GT_16( st_ivas->nCPE, 1 ) )
700 : {
701 83 : IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK )
702 : {
703 0 : return error;
704 : }
705 : }
706 : }
707 163 : ELSE IF( EQ_16( ivas_format, MASA_ISM_FORMAT ) )
708 : {
709 : Word32 ism_total_brate;
710 : Word16 k;
711 :
712 44 : st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( ivas_total_brate, hEncoderConfig->nchan_ism ); /* Q0 */
713 44 : move32();
714 44 : st_ivas->nchan_transport = 2;
715 44 : move16();
716 :
717 44 : IF( ( error = ivas_ism_metadata_enc_create_fx( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK )
718 : {
719 0 : return error;
720 : }
721 :
722 44 : k = 0;
723 44 : move16();
724 44 : test();
725 359 : WHILE( LT_16( k, SIZE_IVAS_BRATE_TBL ) && NE_32( ivas_total_brate, ivas_brate_tbl[k] ) )
726 : {
727 315 : k++;
728 : }
729 :
730 44 : ism_total_brate = 0;
731 44 : move32();
732 111 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
733 : {
734 67 : ism_total_brate = L_add( ism_total_brate, sep_object_brate[k - 2][st_ivas->nSCE - 1] ); /* Q0 */
735 67 : IF( ( error = create_sce_enc_fx( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ) != IVAS_ERR_OK )
736 : {
737 0 : return error;
738 : }
739 : }
740 :
741 44 : IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
742 : {
743 0 : return error;
744 : }
745 44 : IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
746 : {
747 0 : return error;
748 : }
749 :
750 44 : IF( NE_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
751 : {
752 27 : IF( ( error = ivas_omasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
753 : {
754 0 : return error;
755 : }
756 : }
757 :
758 44 : IF( GE_32( L_sub( ivas_total_brate, ism_total_brate ), MIN_BRATE_MDCT_STEREO ) )
759 : {
760 17 : st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
761 17 : move16();
762 : }
763 : ELSE
764 : {
765 27 : st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT;
766 27 : move16();
767 : }
768 :
769 44 : IF( ( error = create_cpe_enc_fx( st_ivas, 0, L_sub( ivas_total_brate, ism_total_brate ) ) ) != IVAS_ERR_OK )
770 : {
771 0 : return error;
772 : }
773 : }
774 119 : ELSE IF( EQ_32( ivas_format, SBA_ISM_FORMAT ) )
775 : {
776 37 : st_ivas->ism_mode = ISM_MODE_NONE;
777 37 : move16();
778 :
779 37 : st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism );
780 :
781 37 : IF( ( error = ivas_ism_metadata_enc_create_fx( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK )
782 : {
783 0 : return error;
784 : }
785 :
786 : /* allocate and initialize SBA handles */
787 37 : IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
788 : {
789 0 : return error;
790 : }
791 :
792 37 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order_fx( ivas_total_brate, st_ivas->hEncoderConfig->sba_order ); /* Q0 */
793 :
794 37 : IF( ( error = ivas_spar_enc_open_fx( st_ivas, 0 ) ) != IVAS_ERR_OK )
795 : {
796 0 : return error;
797 : }
798 :
799 37 : IF( ( error = ivas_dirac_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
800 : {
801 0 : return error;
802 : }
803 :
804 37 : IF( EQ_32( st_ivas->ism_mode, ISM_MODE_NONE ) )
805 : {
806 : /* allocate and initialize SBA core-coders */
807 18 : IF( EQ_16( st_ivas->nchan_transport, 1 ) )
808 : {
809 12 : IF( ( error = create_sce_enc_fx( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK )
810 : {
811 0 : return error;
812 : }
813 : }
814 :
815 25 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
816 : {
817 : Word32 res_dec, res_frac;
818 7 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
819 7 : IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK )
820 : {
821 0 : return error;
822 : }
823 : }
824 :
825 18 : IF( GT_16( st_ivas->nCPE, 1 ) )
826 : {
827 1 : IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK )
828 : {
829 0 : return error;
830 : }
831 : }
832 : }
833 : ELSE
834 : {
835 : /* allocate and initialize MCT core coder */
836 : {
837 : int16_t n_all;
838 :
839 19 : n_all = add( st_ivas->nchan_transport, st_ivas->hEncoderConfig->nchan_ism );
840 19 : st_ivas->nCPE = shr_r( n_all, 1 );
841 : }
842 :
843 86 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
844 : {
845 : Word32 res_dec, res_frac;
846 67 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nchan_transport, &res_dec, &res_frac, 0 );
847 67 : IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK )
848 : {
849 0 : return error;
850 : }
851 : }
852 :
853 19 : IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK )
854 : {
855 0 : return error;
856 : }
857 : }
858 37 : IF( ( error = ivas_osba_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
859 : {
860 0 : return error;
861 : }
862 : }
863 82 : ELSE IF( EQ_32( ivas_format, MC_FORMAT ) )
864 : {
865 82 : st_ivas->mc_mode = ivas_mc_mode_select_fx( hEncoderConfig->mc_input_setup, ivas_total_brate ); /* Q0 */
866 82 : move32();
867 :
868 82 : IF( ( error = ivas_create_lfe_lpf_enc_fx( &st_ivas->hLfeLpf, hEncoderConfig->input_Fs ) ) != IVAS_ERR_OK )
869 : {
870 0 : return error;
871 : }
872 :
873 82 : IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
874 : {
875 36 : st_ivas->nSCE = 0;
876 36 : move16();
877 36 : st_ivas->nCPE = shr( hEncoderConfig->nchan_inp, CPE_CHANNELS_LOG2 ); /* Q0 */
878 36 : move16();
879 :
880 181 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
881 : {
882 : Word32 res_dec, res_frac;
883 145 : iDiv_and_mod_32( ivas_total_brate, sub( hEncoderConfig->nchan_inp, 1 ), &res_dec, &res_frac, 0 );
884 145 : IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, imult3216( res_dec, CPE_CHANNELS ) ) ) != IVAS_ERR_OK )
885 : {
886 0 : return error;
887 : }
888 : }
889 :
890 36 : IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK )
891 : {
892 0 : return error;
893 : }
894 :
895 36 : IF( ( error = ivas_create_lfe_enc_fx( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK )
896 : {
897 0 : return error;
898 : }
899 :
900 36 : st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels_fx( st_ivas->hEncoderConfig->mc_input_setup ); /* Q0 */
901 36 : move16();
902 : }
903 46 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) )
904 : {
905 5 : st_ivas->nSCE = 0;
906 5 : move16();
907 5 : st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS >> 1;
908 5 : move16();
909 5 : st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
910 5 : move16();
911 :
912 5 : IF( ( error = ivas_mc_paramupmix_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
913 : {
914 0 : return error;
915 : }
916 :
917 25 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
918 : {
919 : Word32 res_dec, res_frac;
920 20 : iDiv_and_mod_32( ivas_total_brate, st_ivas->nCPE, &res_dec, &res_frac, 0 );
921 20 : IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, res_dec ) ) != IVAS_ERR_OK )
922 : {
923 0 : return error;
924 : }
925 : }
926 :
927 5 : IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK )
928 : {
929 0 : return error;
930 : }
931 :
932 5 : IF( ( error = ivas_create_lfe_enc_fx( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK )
933 : {
934 0 : return error;
935 : }
936 : }
937 41 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) )
938 : {
939 10 : IF( ( error = ivas_param_mc_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
940 : {
941 0 : return error;
942 : }
943 :
944 20 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
945 : {
946 : Word32 res_dec, res_frac;
947 10 : iDiv_and_mod_32( ivas_total_brate, add( st_ivas->nCPE, st_ivas->nSCE ), &res_dec, &res_frac, 0 );
948 10 : IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, res_dec ) ) != IVAS_ERR_OK )
949 : {
950 0 : return error;
951 : }
952 : }
953 :
954 10 : IF( GT_16( st_ivas->nCPE, 1 ) )
955 : {
956 0 : IF( ( error = create_mct_enc_fx( st_ivas ) ) != IVAS_ERR_OK )
957 : {
958 0 : return error;
959 : }
960 : }
961 : }
962 31 : ELSE IF( EQ_32( st_ivas->mc_mode, MC_MODE_MCMASA ) )
963 : {
964 : Word32 brate_sce, brate_cpe;
965 :
966 31 : ivas_mcmasa_setNumTransportChannels_fx( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate );
967 :
968 31 : IF( ( error = ivas_qmetadata_open_fx( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
969 : {
970 0 : return error;
971 : }
972 :
973 31 : IF( ( error = ivas_masa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
974 : {
975 0 : return error;
976 : }
977 :
978 31 : IF( ( error = ivas_mcmasa_enc_open_fx( st_ivas ) ) != IVAS_ERR_OK )
979 : {
980 0 : return error;
981 : }
982 31 : ivas_mcmasa_split_brate_fx( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe );
983 :
984 60 : FOR( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
985 : {
986 29 : IF( ( error = create_sce_enc_fx( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK )
987 : {
988 0 : return error;
989 : }
990 : }
991 :
992 36 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
993 : {
994 5 : hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; /* Q0 */
995 5 : move16();
996 :
997 5 : IF( ( error = create_cpe_enc_fx( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK )
998 : {
999 0 : return error;
1000 : }
1001 : }
1002 : }
1003 : }
1004 :
1005 : /*-----------------------------------------------------------------*
1006 : * Allocate and initialize HP20 filter memories
1007 : *-----------------------------------------------------------------*/
1008 :
1009 : /* set number of input channels used for analysis/coding */
1010 627 : n = getNumChanAnalysis_fx( st_ivas ); /* Q0 */
1011 627 : move16();
1012 :
1013 627 : IF( n > 0 )
1014 : {
1015 627 : IF( ( st_ivas->mem_hp20_in_fx = (Word32 **) malloc( n * sizeof( Word32 * ) ) ) == NULL )
1016 : {
1017 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
1018 : }
1019 : }
1020 : ELSE
1021 : {
1022 0 : st_ivas->mem_hp20_in_fx = NULL;
1023 : }
1024 :
1025 3403 : FOR( i = 0; i < n; i++ )
1026 : {
1027 2776 : IF( ( st_ivas->mem_hp20_in_fx[i] = (Word32 *) malloc( ( L_HP20_MEM + 2 ) * sizeof( Word32 ) ) ) == NULL )
1028 : {
1029 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
1030 : }
1031 :
1032 2776 : set32_fx( st_ivas->mem_hp20_in_fx[i], 0, L_HP20_MEM + 2 );
1033 : }
1034 :
1035 627 : return error;
1036 : }
1037 : /*-------------------------------------------------------------------------
1038 : * destroy_core_enc()
1039 : *
1040 : * Close core encoder handles
1041 : *-------------------------------------------------------------------------*/
1042 :
1043 8833 : void destroy_core_enc_fx(
1044 : ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */
1045 : )
1046 : {
1047 : Word16 i;
1048 :
1049 8833 : destroy_cldfb_encoder_fx( hCoreCoder );
1050 :
1051 8833 : IF( hCoreCoder->hSignalBuf != NULL )
1052 : {
1053 8764 : free( hCoreCoder->hSignalBuf );
1054 8764 : hCoreCoder->hSignalBuf = NULL;
1055 : }
1056 :
1057 8833 : IF( hCoreCoder->hBstr != NULL )
1058 : {
1059 : /* reset buffer of indices */
1060 8764 : FOR( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ )
1061 : {
1062 0 : hCoreCoder->hBstr->ind_list[i].nb_bits = -1;
1063 0 : move16();
1064 : }
1065 8764 : free( hCoreCoder->hBstr );
1066 8764 : hCoreCoder->hBstr = NULL;
1067 : }
1068 :
1069 8833 : IF( hCoreCoder->hLPDmem != NULL )
1070 : {
1071 3087 : free( hCoreCoder->hLPDmem );
1072 3087 : hCoreCoder->hLPDmem = NULL;
1073 : }
1074 :
1075 8833 : IF( hCoreCoder->hTranDet != NULL )
1076 : {
1077 8764 : free( hCoreCoder->hTranDet );
1078 8764 : hCoreCoder->hTranDet = NULL;
1079 : }
1080 :
1081 8833 : IF( hCoreCoder->hNoiseEst != NULL )
1082 : {
1083 8752 : free( hCoreCoder->hNoiseEst );
1084 8752 : hCoreCoder->hNoiseEst = NULL;
1085 : }
1086 :
1087 8833 : IF( hCoreCoder->hVAD != NULL )
1088 : {
1089 8683 : free( hCoreCoder->hVAD );
1090 8683 : hCoreCoder->hVAD = NULL;
1091 : }
1092 :
1093 8833 : IF( hCoreCoder->hVAD_CLDFB != NULL )
1094 : {
1095 : /* This is not required as we are not allocating memory dynamically */
1096 : // free( hCoreCoder->hVAD_CLDFB );
1097 0 : hCoreCoder->hVAD_CLDFB = NULL;
1098 : }
1099 :
1100 8833 : IF( hCoreCoder->hTdCngEnc != NULL )
1101 : {
1102 85 : free( hCoreCoder->hTdCngEnc );
1103 85 : hCoreCoder->hTdCngEnc = NULL;
1104 : }
1105 :
1106 8833 : IF( hCoreCoder->hDtxEnc != NULL )
1107 : {
1108 488 : free( hCoreCoder->hDtxEnc );
1109 488 : hCoreCoder->hDtxEnc = NULL;
1110 : }
1111 :
1112 8833 : IF( hCoreCoder->hSpMusClas != NULL )
1113 : {
1114 8752 : free( hCoreCoder->hSpMusClas );
1115 8752 : hCoreCoder->hSpMusClas = NULL;
1116 : }
1117 :
1118 8833 : IF( hCoreCoder->hGSCEnc != NULL )
1119 : {
1120 3087 : free( hCoreCoder->hGSCEnc );
1121 3087 : hCoreCoder->hGSCEnc = NULL;
1122 : }
1123 :
1124 8833 : IF( hCoreCoder->hSC_VBR != NULL )
1125 : {
1126 0 : free( hCoreCoder->hSC_VBR );
1127 0 : hCoreCoder->hSC_VBR = NULL;
1128 : }
1129 :
1130 8833 : IF( hCoreCoder->hAmrwb_IO != NULL )
1131 : {
1132 0 : free( hCoreCoder->hAmrwb_IO );
1133 0 : hCoreCoder->hAmrwb_IO = NULL;
1134 : }
1135 :
1136 8833 : IF( hCoreCoder->hBWE_TD != NULL )
1137 : {
1138 3086 : free( hCoreCoder->hBWE_TD );
1139 3086 : hCoreCoder->hBWE_TD = NULL;
1140 : }
1141 :
1142 8833 : IF( hCoreCoder->hBWE_FD != NULL )
1143 : {
1144 3086 : free( hCoreCoder->hBWE_FD );
1145 3086 : hCoreCoder->hBWE_FD = NULL;
1146 : }
1147 :
1148 8833 : IF( hCoreCoder->hRF != NULL )
1149 : {
1150 0 : free( hCoreCoder->hRF );
1151 0 : hCoreCoder->hRF = NULL;
1152 : }
1153 :
1154 8833 : IF( hCoreCoder->hTECEnc != NULL )
1155 : {
1156 0 : free( hCoreCoder->hTECEnc );
1157 0 : hCoreCoder->hTECEnc = NULL;
1158 : }
1159 :
1160 8833 : IF( hCoreCoder->hTcxEnc != NULL )
1161 : {
1162 8682 : free( hCoreCoder->hTcxEnc );
1163 8682 : hCoreCoder->hTcxEnc = NULL;
1164 : }
1165 :
1166 8833 : IF( hCoreCoder->hTcxCfg != NULL )
1167 : {
1168 8682 : free( hCoreCoder->hTcxCfg );
1169 8682 : hCoreCoder->hTcxCfg = NULL;
1170 : }
1171 :
1172 8833 : IF( hCoreCoder->hIGFEnc != NULL )
1173 : {
1174 6681 : free( hCoreCoder->hIGFEnc );
1175 6681 : hCoreCoder->hIGFEnc = NULL;
1176 : }
1177 :
1178 8833 : IF( hCoreCoder->hPlcExt != NULL )
1179 : {
1180 0 : free( hCoreCoder->hPlcExt );
1181 0 : hCoreCoder->hPlcExt = NULL;
1182 : }
1183 :
1184 8833 : IF( hCoreCoder->hHQ_core != NULL )
1185 : {
1186 3106 : free( hCoreCoder->hHQ_core );
1187 3106 : hCoreCoder->hHQ_core = NULL;
1188 : }
1189 :
1190 8833 : free( hCoreCoder );
1191 :
1192 8833 : return;
1193 : }
1194 :
1195 3 : void destroy_evs_core_enc_fx(
1196 : ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */
1197 : )
1198 : {
1199 : Word16 i;
1200 :
1201 3 : destroy_encoder_fx( hCoreCoder );
1202 :
1203 3 : IF( hCoreCoder->hSignalBuf != NULL )
1204 : {
1205 3 : free( hCoreCoder->hSignalBuf );
1206 3 : hCoreCoder->hSignalBuf = NULL;
1207 : }
1208 :
1209 3 : IF( hCoreCoder->hBstr != NULL )
1210 : {
1211 : /* reset buffer of indices */
1212 3 : FOR( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ )
1213 : {
1214 0 : hCoreCoder->hBstr->ind_list[i].nb_bits = -1;
1215 0 : move16();
1216 : }
1217 3 : free( hCoreCoder->hBstr );
1218 3 : hCoreCoder->hBstr = NULL;
1219 : }
1220 :
1221 3 : IF( hCoreCoder->hLPDmem != NULL )
1222 : {
1223 3 : free( hCoreCoder->hLPDmem );
1224 3 : hCoreCoder->hLPDmem = NULL;
1225 : }
1226 :
1227 3 : IF( hCoreCoder->hTranDet != NULL )
1228 : {
1229 0 : free( hCoreCoder->hTranDet );
1230 0 : hCoreCoder->hTranDet = NULL;
1231 : }
1232 :
1233 3 : IF( hCoreCoder->hNoiseEst != NULL )
1234 : {
1235 3 : free( hCoreCoder->hNoiseEst );
1236 3 : hCoreCoder->hNoiseEst = NULL;
1237 : }
1238 :
1239 3 : IF( hCoreCoder->hVAD != NULL )
1240 : {
1241 3 : free( hCoreCoder->hVAD );
1242 3 : hCoreCoder->hVAD = NULL;
1243 : }
1244 :
1245 3 : IF( hCoreCoder->hVAD_CLDFB != NULL )
1246 : {
1247 : /* This is not required as we are not allocating memory dynamically */
1248 : // free( hCoreCoder->hVAD_CLDFB );
1249 3 : hCoreCoder->hVAD_CLDFB = NULL;
1250 : }
1251 :
1252 3 : IF( hCoreCoder->hTdCngEnc != NULL )
1253 : {
1254 3 : free( hCoreCoder->hTdCngEnc );
1255 3 : hCoreCoder->hTdCngEnc = NULL;
1256 : }
1257 :
1258 3 : IF( hCoreCoder->hDtxEnc != NULL )
1259 : {
1260 3 : free( hCoreCoder->hDtxEnc );
1261 3 : hCoreCoder->hDtxEnc = NULL;
1262 : }
1263 :
1264 3 : IF( hCoreCoder->hSpMusClas != NULL )
1265 : {
1266 3 : free( hCoreCoder->hSpMusClas );
1267 3 : hCoreCoder->hSpMusClas = NULL;
1268 : }
1269 :
1270 3 : IF( hCoreCoder->hGSCEnc != NULL )
1271 : {
1272 3 : free( hCoreCoder->hGSCEnc );
1273 3 : hCoreCoder->hGSCEnc = NULL;
1274 : }
1275 :
1276 3 : IF( hCoreCoder->hSC_VBR != NULL )
1277 : {
1278 3 : free( hCoreCoder->hSC_VBR );
1279 3 : hCoreCoder->hSC_VBR = NULL;
1280 : }
1281 :
1282 3 : IF( hCoreCoder->hAmrwb_IO != NULL )
1283 : {
1284 3 : free( hCoreCoder->hAmrwb_IO );
1285 3 : hCoreCoder->hAmrwb_IO = NULL;
1286 : }
1287 :
1288 3 : IF( hCoreCoder->hBWE_TD != NULL )
1289 : {
1290 3 : free( hCoreCoder->hBWE_TD );
1291 3 : hCoreCoder->hBWE_TD = NULL;
1292 : }
1293 :
1294 3 : IF( hCoreCoder->hBWE_FD != NULL )
1295 : {
1296 3 : free( hCoreCoder->hBWE_FD );
1297 3 : hCoreCoder->hBWE_FD = NULL;
1298 : }
1299 :
1300 3 : IF( hCoreCoder->hRF != NULL )
1301 : {
1302 3 : free( hCoreCoder->hRF );
1303 3 : hCoreCoder->hRF = NULL;
1304 : }
1305 :
1306 3 : IF( hCoreCoder->hTECEnc != NULL )
1307 : {
1308 3 : free( hCoreCoder->hTECEnc );
1309 3 : hCoreCoder->hTECEnc = NULL;
1310 : }
1311 :
1312 3 : IF( hCoreCoder->hTcxEnc != NULL )
1313 : {
1314 3 : free( hCoreCoder->hTcxEnc );
1315 3 : hCoreCoder->hTcxEnc = NULL;
1316 : }
1317 :
1318 3 : IF( hCoreCoder->hTcxCfg != NULL )
1319 : {
1320 3 : free( hCoreCoder->hTcxCfg );
1321 3 : hCoreCoder->hTcxCfg = NULL;
1322 : }
1323 :
1324 3 : IF( hCoreCoder->hIGFEnc != NULL )
1325 : {
1326 3 : free( hCoreCoder->hIGFEnc );
1327 3 : hCoreCoder->hIGFEnc = NULL;
1328 : }
1329 :
1330 3 : IF( hCoreCoder->hPlcExt != NULL )
1331 : {
1332 3 : free( hCoreCoder->hPlcExt );
1333 3 : hCoreCoder->hPlcExt = NULL;
1334 : }
1335 :
1336 3 : IF( hCoreCoder->hHQ_core != NULL )
1337 : {
1338 3 : free( hCoreCoder->hHQ_core );
1339 3 : hCoreCoder->hHQ_core = NULL;
1340 : }
1341 :
1342 3 : free( hCoreCoder );
1343 :
1344 3 : return;
1345 : }
1346 :
1347 :
1348 : /*-------------------------------------------------------------------------
1349 : * ivas_destroy_enc_fx()
1350 : *
1351 : * Close IVAS encoder handles
1352 : *-------------------------------------------------------------------------*/
1353 627 : void ivas_destroy_enc_fx(
1354 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
1355 : )
1356 : {
1357 : Word16 i, n, nchan_inp;
1358 627 : nchan_inp = st_ivas->hEncoderConfig->nchan_inp;
1359 627 : move16();
1360 :
1361 : /* SCE handles */
1362 3135 : for ( i = 0; i < MAX_SCE; i++ )
1363 : {
1364 2508 : if ( st_ivas->hSCE[i] != NULL )
1365 : {
1366 409 : destroy_sce_enc_fx( st_ivas->hSCE[i], EQ_16( st_ivas->hEncoderConfig->element_mode_init, EVS_MONO ) );
1367 409 : st_ivas->hSCE[i] = NULL;
1368 : }
1369 : }
1370 :
1371 : /* CPE handles */
1372 4389 : for ( i = 0; i < MAX_CPE; i++ )
1373 : {
1374 3762 : if ( st_ivas->hCPE[i] != NULL )
1375 : {
1376 748 : destroy_cpe_enc( st_ivas->hCPE[i] );
1377 748 : st_ivas->hCPE[i] = NULL;
1378 : }
1379 : }
1380 :
1381 : /* HP20 filter handles */
1382 627 : if ( st_ivas->mem_hp20_in_fx != NULL )
1383 : {
1384 627 : n = getNumChanAnalysis_fx( st_ivas ); /* Q0 */
1385 :
1386 3526 : for ( i = 0; i < n; i++ )
1387 : {
1388 2899 : free( st_ivas->mem_hp20_in_fx[i] );
1389 2899 : st_ivas->mem_hp20_in_fx[i] = NULL;
1390 : }
1391 627 : free( st_ivas->mem_hp20_in_fx );
1392 627 : st_ivas->mem_hp20_in_fx = NULL;
1393 : }
1394 :
1395 : /* ISM metadata handles */
1396 627 : ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 );
1397 :
1398 : /* ISM DTX Handle */
1399 627 : if ( st_ivas->hISMDTX != NULL )
1400 : {
1401 14 : free( st_ivas->hISMDTX );
1402 14 : st_ivas->hISMDTX = NULL;
1403 : }
1404 :
1405 : /* Q Metadata handle */
1406 627 : ivas_qmetadata_close_fx( &( st_ivas->hQMetaData ) );
1407 :
1408 : /* DirAC handle */
1409 627 : ivas_dirac_enc_close_fx( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs );
1410 :
1411 : /* ParamISM handle */
1412 627 : ivas_param_ism_enc_close_fx( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs );
1413 :
1414 : /* SPAR handle */
1415 627 : ivas_spar_enc_close_fx( &( st_ivas->hSpar ), st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 );
1416 :
1417 : /* MASA handle */
1418 627 : ivas_masa_enc_close_fx( &( st_ivas->hMasa ) );
1419 :
1420 : /* MCT handle */
1421 627 : ivas_mct_enc_close_fx( &( st_ivas->hMCT ) );
1422 :
1423 : /* LFE handle */
1424 627 : ivas_lfe_enc_close_fx( &( st_ivas->hLFE ) );
1425 :
1426 : /* LFE low pass filter state */
1427 627 : ivas_lfe_lpf_enc_close_fx( &( st_ivas->hLfeLpf ) );
1428 :
1429 : /* Param-Upmix MC handle */
1430 627 : ivas_mc_paramupmix_enc_close_fx( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs );
1431 :
1432 : /* Parametric MC handle */
1433 627 : ivas_param_mc_enc_close_fx( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs );
1434 :
1435 : /* Multi-channel MASA handle */
1436 627 : ivas_mcmasa_enc_close_fx( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs );
1437 :
1438 : /* OMASA handle */
1439 627 : ivas_omasa_enc_close_fx( &( st_ivas->hOMasa ) );
1440 :
1441 : /* OSBA handle */
1442 627 : ivas_osba_enc_close_fx( &( st_ivas->hOSba ) );
1443 :
1444 : /* Stereo downmix for EVS encoder handle */
1445 627 : stereo_dmx_evs_close_encoder_fx( &( st_ivas->hStereoDmxEVS ) );
1446 :
1447 : /* Encoder configuration handle */
1448 627 : IF( st_ivas->hEncoderConfig != NULL )
1449 : {
1450 627 : free( st_ivas->hEncoderConfig );
1451 627 : st_ivas->hEncoderConfig = NULL;
1452 : }
1453 :
1454 : /* Buffer of indices */
1455 627 : IF( st_ivas->ind_list != NULL )
1456 : {
1457 627 : free( st_ivas->ind_list );
1458 : }
1459 :
1460 627 : IF( st_ivas->ind_list_metadata != NULL )
1461 : {
1462 624 : free( st_ivas->ind_list_metadata );
1463 : }
1464 :
1465 : /* floating-point input audio buffers */
1466 13167 : FOR( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
1467 : {
1468 12540 : IF( st_ivas->p_data_fx[n] != NULL )
1469 : {
1470 3674 : free( st_ivas->p_data_fx[n] );
1471 3674 : st_ivas->p_data_fx[n] = NULL;
1472 : }
1473 : }
1474 :
1475 : /* main IVAS handle */
1476 627 : free( st_ivas );
1477 :
1478 627 : return;
1479 : }
1480 :
1481 : /*-------------------------------------------------------------------------
1482 : * ivas_initialize_MD_bstr_enc_fx()
1483 : *
1484 : * Allocate and initialize SCE/CPE MD bitstream handle
1485 : *-------------------------------------------------------------------------*/
1486 :
1487 4354 : ivas_error ivas_initialize_MD_bstr_enc_fx(
1488 : BSTR_ENC_HANDLE *hMetaData_out, /* o : encoder MD bitstream handle */
1489 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
1490 : )
1491 : {
1492 : BSTR_ENC_HANDLE hMetaData;
1493 :
1494 4354 : IF( ( hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL )
1495 : {
1496 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) );
1497 : }
1498 :
1499 : /* set pointer to the buffer of metadata indices */
1500 4354 : hMetaData->ind_list = st_ivas->ind_list_metadata;
1501 4354 : hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata;
1502 4354 : hMetaData->ivas_max_num_indices = &st_ivas->ivas_max_num_indices_metadata; /* Q0 */
1503 4354 : hMetaData->st_ivas = st_ivas;
1504 :
1505 4354 : reset_indices_enc_fx( hMetaData, st_ivas->ivas_max_num_indices_metadata );
1506 :
1507 4354 : *hMetaData_out = hMetaData;
1508 :
1509 4354 : return IVAS_ERR_OK;
1510 : }
1511 :
1512 :
1513 : /*-------------------------------------------------------------------------
1514 : * ivas_destroy_MD_bstr_enc_fx()
1515 : *
1516 : * Destroy SCE/CPE MD bitstream handle
1517 : *-------------------------------------------------------------------------*/
1518 :
1519 9385 : void ivas_destroy_MD_bstr_enc_fx(
1520 : BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */
1521 : )
1522 : {
1523 9385 : test();
1524 9385 : IF( hMetaData == NULL || *hMetaData == NULL )
1525 : {
1526 5031 : return;
1527 : }
1528 :
1529 4354 : free( *hMetaData );
1530 4354 : *hMetaData = NULL;
1531 :
1532 4354 : return;
1533 : }
|