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.h"
38 : #include "ivas_prot.h"
39 : #include "ivas_stat_enc.h"
40 : #include "ivas_rom_com.h"
41 : #ifdef DEBUGGING
42 : #include "debug.h"
43 : #endif
44 : #include "wmc_auto.h"
45 : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
46 : #include <string.h>
47 : #endif
48 :
49 :
50 : /*-------------------------------------------------------------------*
51 : * ivas_write_format()
52 : *
53 : * Write IVAS format signaling
54 : *-------------------------------------------------------------------*/
55 :
56 6270238 : void ivas_write_format(
57 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
58 : )
59 : {
60 : int16_t ind, nBits, extra_bits;
61 :
62 6270238 : ind = 0;
63 6270238 : nBits = IVAS_FORMAT_SIGNALING_NBITS;
64 6270238 : extra_bits = ( IVAS_FORMAT_SIGNALING_NBITS_EXTENDED - IVAS_FORMAT_SIGNALING_NBITS );
65 :
66 6270238 : switch ( st_ivas->hEncoderConfig->ivas_format )
67 : {
68 821403 : case STEREO_FORMAT:
69 821403 : ind = 0;
70 821403 : break;
71 847187 : case ISM_FORMAT:
72 847187 : ind = 2;
73 847187 : if ( st_ivas->hEncoderConfig->ivas_total_brate >= IVAS_24k4 )
74 : {
75 783507 : ind = 4;
76 783507 : nBits += extra_bits;
77 : }
78 847187 : break;
79 826320 : case MC_FORMAT:
80 826320 : ind = 1;
81 826320 : break;
82 2263408 : case SBA_FORMAT:
83 2263408 : ind = 6;
84 2263408 : nBits += extra_bits;
85 2263408 : break;
86 639723 : case MASA_FORMAT:
87 639723 : ind = 7;
88 639723 : nBits += extra_bits;
89 639723 : break;
90 406619 : case MASA_ISM_FORMAT:
91 406619 : if ( st_ivas->ism_mode == ISM_MODE_NONE )
92 : {
93 92302 : ind = 7; /* send MASA format */
94 92302 : nBits += extra_bits;
95 : }
96 : else
97 : {
98 314317 : ind = 10;
99 314317 : nBits += extra_bits + IVAS_COMBINED_FORMAT_SIGNALLING_BITS;
100 : }
101 406619 : break;
102 465578 : case SBA_ISM_FORMAT:
103 465578 : if ( st_ivas->hEncoderConfig->ivas_total_brate < IVAS_24k4 )
104 : {
105 33578 : ind = 6; /* send SBA format */
106 33578 : nBits += extra_bits;
107 : }
108 : else
109 : {
110 432000 : ind = 11; /* 1011 */
111 432000 : nBits += extra_bits + IVAS_COMBINED_FORMAT_SIGNALLING_BITS;
112 : }
113 465578 : break;
114 0 : default:
115 0 : assert( !"Invalid format. Aborting." );
116 : break;
117 : }
118 :
119 6270238 : if ( st_ivas->hSCE[0] != NULL )
120 : {
121 2424924 : push_indice( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr, IND_IVAS_FORMAT, ind, nBits );
122 : }
123 3845314 : else if ( st_ivas->hCPE[0] != NULL )
124 : {
125 3845314 : push_indice( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr, IND_IVAS_FORMAT, ind, nBits );
126 : }
127 :
128 6270238 : return;
129 : }
130 :
131 :
132 : /*-------------------------------------------------------------------*
133 : * ivas_write_format_sid()
134 : *
135 : * Write IVAS format signaling in SID frames
136 : *-------------------------------------------------------------------*/
137 :
138 13884 : void ivas_write_format_sid(
139 : const IVAS_FORMAT ivas_format, /* i : IVAS format */
140 : const int16_t element_mode, /* i : element bitrate */
141 : BSTR_ENC_HANDLE hBstr, /* i/o: encoder bitstream handle */
142 : const int16_t sba_order, /* i : Ambisonic (SBA) order */
143 : const int16_t sba_planar /* i : SBA planar flag */
144 : )
145 : {
146 13884 : int16_t ind = 0; /* to avoid compilation warning */
147 :
148 13884 : switch ( ivas_format )
149 : {
150 7860 : case STEREO_FORMAT:
151 7860 : if ( element_mode == IVAS_CPE_MDCT )
152 : {
153 1796 : ind = SID_MDCT_STEREO;
154 : }
155 6064 : else if ( element_mode == IVAS_CPE_DFT )
156 : {
157 6064 : ind = SID_DFT_STEREO;
158 : }
159 : else
160 : {
161 0 : assert( !"Wrong stereo mode for SID format signaling" );
162 : }
163 7860 : break;
164 3303 : case ISM_FORMAT:
165 3303 : ind = SID_ISM;
166 3303 : break;
167 1623 : case SBA_FORMAT:
168 1623 : switch ( element_mode )
169 : {
170 1049 : case IVAS_SCE:
171 1049 : ind = SID_SBA_1TC;
172 1049 : break;
173 574 : case IVAS_CPE_MDCT:
174 574 : ind = SID_SBA_2TC;
175 574 : break;
176 0 : default:
177 0 : assert( !"Wrong element mode for SBA DTX!" );
178 : break;
179 : }
180 1623 : break;
181 1098 : case MASA_FORMAT:
182 1098 : if ( element_mode == IVAS_SCE )
183 : {
184 681 : ind = SID_MASA_1TC;
185 : }
186 : else
187 : {
188 417 : ind = SID_MASA_2TC;
189 : }
190 1098 : break;
191 0 : default:
192 0 : assert( !"Reserved SID format symbol written." );
193 : break;
194 : }
195 :
196 13884 : push_indice( hBstr, IND_IVAS_FORMAT, ind, SID_FORMAT_NBITS );
197 :
198 13884 : if ( ivas_format == SBA_FORMAT )
199 : {
200 : /* Write SBA planar flag */
201 1623 : push_indice( hBstr, IND_SMODE, sba_planar, SBA_PLANAR_BITS );
202 :
203 : /* Write SBA order */
204 1623 : push_indice( hBstr, IND_SMODE, sba_order, SBA_ORDER_BITS );
205 : }
206 :
207 13884 : return;
208 : }
209 :
210 :
211 : /*-------------------------------------------------------------------*
212 : * getNumChanAnalysis()
213 : *
214 : * get number of input channels used for analysis/coding
215 : *-------------------------------------------------------------------*/
216 :
217 : /*! r: number of channels to be analysed */
218 6233219 : int16_t getNumChanAnalysis(
219 : Encoder_Struct *st_ivas /* i : IVAS encoder structure */
220 : )
221 : {
222 : int16_t n;
223 :
224 6233219 : n = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE;
225 6233219 : if ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT )
226 : {
227 2266224 : n = ( st_ivas->sba_analysis_order + 1 ) * ( st_ivas->sba_analysis_order + 1 );
228 : }
229 3966995 : else if ( st_ivas->hEncoderConfig->ivas_format == MC_FORMAT && ( st_ivas->mc_mode == MC_MODE_PARAMMC || st_ivas->mc_mode == MC_MODE_MCMASA ) )
230 : {
231 329592 : n = st_ivas->hEncoderConfig->nchan_inp;
232 : }
233 3637403 : else if ( st_ivas->hEncoderConfig->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
234 : {
235 45717 : n = st_ivas->hEncoderConfig->nchan_inp;
236 : }
237 3591686 : else if ( st_ivas->hEncoderConfig->ivas_format == ISM_FORMAT && st_ivas->ism_mode == ISM_MODE_PARAM )
238 : {
239 164753 : n = st_ivas->hEncoderConfig->nchan_inp;
240 : }
241 3426933 : else if ( st_ivas->hEncoderConfig->ivas_format == MASA_ISM_FORMAT )
242 : {
243 357922 : n = st_ivas->hEncoderConfig->nchan_inp;
244 : }
245 3069011 : else if ( st_ivas->hEncoderConfig->ivas_format == SBA_ISM_FORMAT )
246 : {
247 468372 : n = st_ivas->hEncoderConfig->nchan_ism + ( st_ivas->sba_analysis_order + 1 ) * ( st_ivas->sba_analysis_order + 1 );
248 : }
249 :
250 6233219 : return n;
251 : }
252 :
253 :
254 : /*-------------------------------------------------------------------*
255 : * copy_encoder_config()
256 : *
257 : * Copy configuration structrue to the state structrure
258 : *-------------------------------------------------------------------*/
259 :
260 490135 : void copy_encoder_config(
261 : Encoder_Struct *st_ivas, /* i : IVAS encoder structure */
262 : Encoder_State *st, /* o : encoder state structure */
263 : const int16_t flag_all /* i : flag 1==update all, 0=partial update*/
264 : )
265 : {
266 490135 : if ( flag_all )
267 : {
268 146600 : st->input_Fs = st_ivas->hEncoderConfig->input_Fs;
269 :
270 146600 : st->last_codec_mode = st_ivas->last_codec_mode;
271 146600 : st->last_total_brate = st_ivas->hEncoderConfig->last_ivas_total_brate;
272 :
273 146600 : st->Opt_DTX_ON = st_ivas->hEncoderConfig->Opt_DTX_ON;
274 :
275 146600 : st->last_Opt_SC_VBR = st_ivas->hEncoderConfig->last_Opt_SC_VBR;
276 : }
277 :
278 490135 : st->Opt_AMR_WB = st_ivas->hEncoderConfig->Opt_AMR_WB;
279 490135 : st->Opt_SC_VBR = st_ivas->hEncoderConfig->Opt_SC_VBR;
280 :
281 490135 : st->codec_mode = st_ivas->codec_mode;
282 490135 : st->max_bwidth = st_ivas->hEncoderConfig->max_bwidth;
283 :
284 490135 : st->Opt_RF_ON = st_ivas->hEncoderConfig->Opt_RF_ON;
285 490135 : st->rf_fec_offset = st_ivas->hEncoderConfig->rf_fec_offset;
286 490135 : st->rf_fec_indicator = st_ivas->hEncoderConfig->rf_fec_indicator;
287 :
288 : #ifdef DEBUGGING
289 : st->force = st_ivas->hEncoderConfig->force;
290 : #endif
291 490135 : st->element_mode = st_ivas->hEncoderConfig->element_mode_init;
292 :
293 490135 : return;
294 : }
295 :
296 :
297 : /*-------------------------------------------------------------------------
298 : * ivas_initialize_handles_enc()
299 : *
300 : * NULL initialization of handles
301 : *-------------------------------------------------------------------------*/
302 :
303 6855 : void ivas_initialize_handles_enc(
304 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
305 : )
306 : {
307 : int16_t i;
308 :
309 34275 : for ( i = 0; i < MAX_SCE; i++ )
310 : {
311 27420 : st_ivas->hSCE[i] = NULL;
312 : }
313 :
314 47985 : for ( i = 0; i < MAX_CPE; i++ )
315 : {
316 41130 : st_ivas->hCPE[i] = NULL;
317 : }
318 :
319 6855 : st_ivas->mem_hp20_in = NULL;
320 :
321 : /* ISM metadata handles */
322 34275 : for ( i = 0; i < MAX_NUM_OBJECTS; i++ )
323 : {
324 27420 : st_ivas->hIsmMetaData[i] = NULL;
325 : }
326 :
327 : /* ISM DTX handle */
328 6855 : st_ivas->hISMDTX = NULL;
329 :
330 : /* Q Metadata handle */
331 6855 : st_ivas->hQMetaData = NULL;
332 :
333 : /* DirAC handle */
334 6855 : st_ivas->hDirAC = NULL;
335 :
336 : /* ParamISM handle */
337 6855 : st_ivas->hParamIsm = NULL;
338 : /* SPAR handle */
339 6855 : st_ivas->hSpar = NULL;
340 :
341 : /* MASA encoder handle */
342 6855 : st_ivas->hMasa = NULL;
343 :
344 : /* MCT handle */
345 6855 : st_ivas->hMCT = NULL;
346 :
347 : /* MC Param-Upmix handle */
348 6855 : st_ivas->hMCParamUpmix = NULL;
349 :
350 : /* Parametric MC handle */
351 6855 : st_ivas->hParamMC = NULL;
352 :
353 : /* Multi-channel MASA handle */
354 6855 : st_ivas->hMcMasa = NULL;
355 :
356 : /* Stereo downmix for EVS encoder handle */
357 6855 : st_ivas->hStereoDmxEVS = NULL;
358 :
359 : /* LFE handle */
360 6855 : st_ivas->hLFE = NULL;
361 :
362 : /* LFE low pass filter handle */
363 6855 : st_ivas->hLfeLpf = NULL;
364 :
365 : /* Object MASA handle */
366 6855 : st_ivas->hOMasa = NULL;
367 :
368 : /* OSBA handle */
369 6855 : st_ivas->hOSba = NULL;
370 :
371 6855 : return;
372 : }
373 :
374 :
375 : /*-------------------------------------------------------------------*
376 : * ivas_init_encoder()
377 : *
378 : * Initialize IVAS encoder state structure
379 : *-------------------------------------------------------------------*/
380 :
381 6855 : ivas_error ivas_init_encoder(
382 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
383 : )
384 : {
385 : int16_t i, n;
386 : int16_t nchan_inp_buff;
387 : int16_t sce_id, cpe_id;
388 : IVAS_FORMAT ivas_format;
389 : int32_t input_Fs, ivas_total_brate;
390 : int32_t element_brate_tmp[MAX_NUM_OBJECTS];
391 : ENCODER_CONFIG_HANDLE hEncoderConfig;
392 : ivas_error error;
393 :
394 6855 : error = IVAS_ERR_OK;
395 :
396 6855 : hEncoderConfig = st_ivas->hEncoderConfig;
397 6855 : ivas_format = hEncoderConfig->ivas_format;
398 6855 : input_Fs = hEncoderConfig->input_Fs;
399 6855 : ivas_total_brate = hEncoderConfig->ivas_total_brate;
400 :
401 6855 : hEncoderConfig->last_ivas_total_brate = ivas_total_brate;
402 :
403 6855 : if ( ivas_format != MONO_FORMAT )
404 : {
405 : /* In IVAS, ensure that minimum coded bandwidth is WB */
406 6549 : hEncoderConfig->max_bwidth = max( hEncoderConfig->max_bwidth, WB );
407 : }
408 6855 : st_ivas->ism_mode = ISM_MODE_NONE;
409 6855 : st_ivas->mc_mode = MC_MODE_NONE;
410 :
411 6855 : st_ivas->nchan_transport = -1;
412 :
413 : #ifdef DEBUGGING
414 : st_ivas->noClipping = 0;
415 : st_ivas->maxOverload = 0;
416 : st_ivas->minOverload = 0;
417 : #endif
418 : /*-----------------------------------------------------------------*
419 : * Allocate floating-point input audio buffers
420 : *-----------------------------------------------------------------*/
421 :
422 6855 : nchan_inp_buff = hEncoderConfig->nchan_inp;
423 6855 : if ( ivas_format == MONO_FORMAT )
424 : {
425 306 : nchan_inp_buff = 0;
426 : }
427 6549 : else if ( ivas_format == MASA_ISM_FORMAT )
428 : {
429 1016 : if ( hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism == 1 ) /* mono is duplicated in monoMASA */
430 : {
431 473 : nchan_inp_buff++;
432 : }
433 :
434 1016 : nchan_inp_buff++; /* for *data_separated_object */
435 : }
436 :
437 53783 : for ( n = 0; n < nchan_inp_buff; n++ )
438 : {
439 : /* note: these are intra-frame heap memories */
440 46928 : if ( ( st_ivas->p_data_f[n] = (float *) malloc( ( input_Fs / FRAMES_PER_SEC ) * sizeof( float ) ) ) == NULL )
441 : {
442 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for floating-point input audio buffer!\n" ) );
443 : }
444 : }
445 97027 : for ( ; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
446 : {
447 90172 : st_ivas->p_data_f[n] = NULL;
448 : }
449 :
450 : /*-----------------------------------------------------------------*
451 : * Allocate and initialize buffer of indices
452 : *-----------------------------------------------------------------*/
453 :
454 : /* set the maximum allowed number of indices in the list */
455 6855 : st_ivas->ivas_max_num_indices = get_ivas_max_num_indices( ivas_format, ivas_total_brate );
456 :
457 : /* allocate buffer of indices */
458 6855 : if ( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL )
459 : {
460 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) );
461 : }
462 :
463 : /* reset the list of indices */
464 6418765 : for ( i = 0; i < st_ivas->ivas_max_num_indices; i++ )
465 : {
466 6411910 : st_ivas->ind_list[i].nb_bits = -1;
467 : }
468 :
469 : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
470 : for ( i = 0; i < st_ivas->ivas_max_num_indices; i++ )
471 : {
472 : memset( st_ivas->ind_list[i].function_name, 'A', 100 * sizeof( char ) );
473 : }
474 : #endif
475 :
476 : /* set the maximum allowed number of metadata indices in the list */
477 6855 : st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata( st_ivas->hEncoderConfig->ivas_format, st_ivas->hEncoderConfig->ivas_total_brate );
478 :
479 : /* allocate buffer of metadata indices */
480 6855 : if ( st_ivas->ivas_max_num_indices_metadata > 0 )
481 : {
482 6549 : if ( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL )
483 : {
484 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) );
485 : }
486 :
487 : /* reset the list of metadata indices */
488 3418704 : for ( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ )
489 : {
490 3412155 : st_ivas->ind_list_metadata[i].nb_bits = -1;
491 : }
492 : }
493 : else
494 : {
495 306 : st_ivas->ind_list_metadata = NULL;
496 : }
497 :
498 : /*-----------------------------------------------------------------*
499 : * Allocate and initialize SCE/CPE and other handles
500 : *-----------------------------------------------------------------*/
501 :
502 6855 : if ( ivas_format == MONO_FORMAT )
503 : {
504 306 : st_ivas->nSCE = 1; /* in mono, there is always only one SCE */
505 306 : st_ivas->nCPE = 0;
506 306 : st_ivas->nchan_transport = 1;
507 306 : sce_id = 0;
508 :
509 306 : if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate ) ) != IVAS_ERR_OK )
510 : {
511 0 : return error;
512 : }
513 :
514 : /* prepare stereo downmix for EVS */
515 306 : if ( hEncoderConfig->stereo_dmx_evs == 1 )
516 : {
517 121 : if ( ( error = stereo_dmx_evs_init_encoder( &( st_ivas->hStereoDmxEVS ), input_Fs ) ) != IVAS_ERR_OK )
518 : {
519 0 : return error;
520 : }
521 : }
522 : }
523 6549 : else if ( ivas_format == STEREO_FORMAT )
524 : {
525 279 : st_ivas->nSCE = 0;
526 279 : st_ivas->nCPE = 1; /* in stereo, there is always only one CPE */
527 279 : st_ivas->nchan_transport = CPE_CHANNELS;
528 279 : cpe_id = 0;
529 :
530 279 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate ) ) != IVAS_ERR_OK )
531 : {
532 0 : return error;
533 : }
534 : }
535 6270 : else if ( ivas_format == ISM_FORMAT )
536 : {
537 801 : st_ivas->ism_mode = ivas_ism_mode_select( hEncoderConfig->nchan_inp, ivas_total_brate );
538 :
539 801 : if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_inp, element_brate_tmp ) ) != IVAS_ERR_OK )
540 : {
541 0 : return error;
542 : }
543 :
544 2915 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
545 : {
546 2114 : if ( ( error = create_sce_enc( st_ivas, sce_id, element_brate_tmp[sce_id] ) ) != IVAS_ERR_OK )
547 : {
548 0 : return error;
549 : }
550 : }
551 :
552 801 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
553 : {
554 99 : if ( ( error = ivas_param_ism_enc_open( st_ivas ) ) != IVAS_ERR_OK )
555 : {
556 0 : return error;
557 : }
558 : }
559 :
560 801 : if ( st_ivas->hEncoderConfig->Opt_DTX_ON )
561 : {
562 293 : if ( ( error = ivas_ism_dtx_open( st_ivas ) ) != IVAS_ERR_OK )
563 : {
564 0 : return error;
565 : }
566 : }
567 : }
568 5469 : else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT )
569 : {
570 2040 : if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
571 : {
572 0 : return error;
573 : }
574 :
575 2040 : if ( ivas_format == SBA_FORMAT )
576 : {
577 1408 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order );
578 :
579 1408 : if ( ( error = ivas_spar_enc_open( st_ivas, 0 ) ) != IVAS_ERR_OK )
580 : {
581 0 : return error;
582 : }
583 :
584 1408 : if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK )
585 : {
586 0 : return error;
587 : }
588 : }
589 : else
590 : {
591 632 : st_ivas->nchan_transport = hEncoderConfig->nchan_inp;
592 :
593 632 : if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK )
594 : {
595 0 : return error;
596 : }
597 : }
598 :
599 2719 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
600 : {
601 679 : if ( ( error = create_sce_enc( st_ivas, sce_id, ivas_total_brate / st_ivas->nchan_transport ) ) != IVAS_ERR_OK )
602 : {
603 0 : return error;
604 : }
605 :
606 679 : if ( ivas_format == SBA_FORMAT && st_ivas->hEncoderConfig->Opt_DTX_ON )
607 : {
608 166 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->dtx_sce_sba = 1;
609 : }
610 : }
611 :
612 4022 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
613 : {
614 1982 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
615 : {
616 0 : return error;
617 : }
618 :
619 5946 : for ( n = 0; n < CPE_CHANNELS; n++ )
620 : {
621 3964 : if ( hEncoderConfig->Opt_DTX_ON )
622 : {
623 330 : st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1;
624 : }
625 : }
626 : }
627 :
628 2040 : if ( st_ivas->nCPE > 1 )
629 : {
630 621 : if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
631 : {
632 0 : return error;
633 : }
634 : }
635 : }
636 3429 : else if ( ivas_format == MASA_ISM_FORMAT )
637 : {
638 : int32_t ism_total_brate;
639 : int16_t k;
640 :
641 1016 : st_ivas->ism_mode = ivas_omasa_ism_mode_select( ivas_total_brate, hEncoderConfig->nchan_ism );
642 1016 : st_ivas->nchan_transport = 2;
643 :
644 1016 : if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK )
645 : {
646 0 : return error;
647 : }
648 :
649 1016 : k = 0;
650 8907 : while ( k < SIZE_IVAS_BRATE_TBL && ivas_total_brate != ivas_brate_tbl[k] )
651 : {
652 7891 : k++;
653 : }
654 :
655 1016 : ism_total_brate = 0;
656 2305 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
657 : {
658 1289 : ism_total_brate += sep_object_brate[k - 2][st_ivas->nSCE - 1];
659 1289 : if ( ( error = create_sce_enc( st_ivas, sce_id, sep_object_brate[k - 2][st_ivas->nSCE - 1] ) ) != IVAS_ERR_OK )
660 : {
661 0 : return error;
662 : }
663 : }
664 :
665 1016 : if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
666 : {
667 0 : return error;
668 : }
669 1016 : if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK )
670 : {
671 0 : return error;
672 : }
673 :
674 1016 : if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC )
675 : {
676 502 : if ( ( error = ivas_omasa_enc_open( st_ivas ) ) != IVAS_ERR_OK )
677 : {
678 0 : return error;
679 : }
680 : }
681 :
682 1016 : if ( ivas_total_brate - ism_total_brate >= MIN_BRATE_MDCT_STEREO )
683 : {
684 504 : st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
685 : }
686 : else
687 : {
688 512 : st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT;
689 : }
690 :
691 1016 : if ( ( error = create_cpe_enc( st_ivas, 0, ivas_total_brate - ism_total_brate ) ) != IVAS_ERR_OK )
692 : {
693 0 : return error;
694 : }
695 : }
696 2413 : else if ( ivas_format == SBA_ISM_FORMAT )
697 : {
698 1397 : st_ivas->ism_mode = ISM_MODE_NONE;
699 :
700 1397 : st_ivas->ism_mode = ivas_osba_ism_mode_select( ivas_total_brate, st_ivas->hEncoderConfig->nchan_ism );
701 :
702 1397 : if ( ( error = ivas_ism_metadata_enc_create( st_ivas, hEncoderConfig->nchan_ism, element_brate_tmp ) ) != IVAS_ERR_OK )
703 : {
704 0 : return error;
705 : }
706 :
707 : /* allocate and initialize SBA handles */
708 1397 : if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
709 : {
710 0 : return error;
711 : }
712 :
713 1397 : st_ivas->sba_analysis_order = ivas_sba_get_analysis_order( ivas_total_brate, st_ivas->hEncoderConfig->sba_order );
714 :
715 1397 : if ( ( error = ivas_spar_enc_open( st_ivas, 0 ) ) != IVAS_ERR_OK )
716 : {
717 0 : return error;
718 : }
719 :
720 1397 : if ( ( error = ivas_dirac_enc_open( st_ivas ) ) != IVAS_ERR_OK )
721 : {
722 0 : return error;
723 : }
724 :
725 1397 : if ( st_ivas->ism_mode == ISM_MODE_NONE )
726 : {
727 : /* allocate and initialize SBA core-coders */
728 687 : if ( st_ivas->nchan_transport == 1 )
729 : {
730 397 : if ( ( error = create_sce_enc( st_ivas, 0, ivas_total_brate ) ) != IVAS_ERR_OK )
731 : {
732 0 : return error;
733 : }
734 : }
735 :
736 1035 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
737 : {
738 348 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
739 : {
740 0 : return error;
741 : }
742 : }
743 :
744 687 : if ( st_ivas->nCPE > 1 )
745 : {
746 58 : if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
747 : {
748 0 : return error;
749 : }
750 : }
751 : }
752 : else
753 : {
754 : /* allocate and initialize MCT core coder */
755 :
756 : {
757 : int16_t n_all;
758 :
759 710 : n_all = st_ivas->nchan_transport + st_ivas->hEncoderConfig->nchan_ism;
760 710 : st_ivas->nCPE = ( n_all + 1 ) >> 1;
761 : }
762 3098 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
763 : {
764 2388 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nchan_transport ) * CPE_CHANNELS ) ) != IVAS_ERR_OK )
765 : {
766 0 : return error;
767 : }
768 : }
769 :
770 710 : if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
771 : {
772 0 : return error;
773 : }
774 : }
775 :
776 1397 : if ( ( error = ivas_osba_enc_open( st_ivas ) ) != IVAS_ERR_OK )
777 : {
778 0 : return error;
779 : }
780 : }
781 1016 : else if ( ivas_format == MC_FORMAT )
782 : {
783 1016 : st_ivas->mc_mode = ivas_mc_mode_select( hEncoderConfig->mc_input_setup, ivas_total_brate );
784 :
785 1016 : if ( ( error = ivas_create_lfe_lpf_enc( &st_ivas->hLfeLpf, input_Fs ) ) != IVAS_ERR_OK )
786 : {
787 0 : return error;
788 : }
789 :
790 1016 : if ( st_ivas->mc_mode == MC_MODE_MCT )
791 : {
792 584 : st_ivas->nSCE = 0;
793 584 : st_ivas->nCPE = hEncoderConfig->nchan_inp / CPE_CHANNELS;
794 :
795 2779 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
796 : {
797 2195 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / ( hEncoderConfig->nchan_inp - 1 ) * CPE_CHANNELS ) ) ) != IVAS_ERR_OK )
798 : {
799 0 : return error;
800 : }
801 : }
802 :
803 584 : if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
804 : {
805 0 : return error;
806 : }
807 :
808 584 : if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK )
809 : {
810 0 : return error;
811 : }
812 :
813 584 : st_ivas->nchan_transport = ivas_mc_ls_setup_get_num_channels( st_ivas->hEncoderConfig->mc_input_setup );
814 : }
815 432 : else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
816 : {
817 85 : st_ivas->nSCE = 0;
818 85 : st_ivas->nCPE = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS / 2;
819 85 : st_ivas->nchan_transport = MC_PARAMUPMIX_MAX_TRANSPORT_CHANS;
820 :
821 85 : if ( ( error = ivas_mc_paramupmix_enc_open( st_ivas ) ) != IVAS_ERR_OK )
822 : {
823 0 : return error;
824 : }
825 :
826 425 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
827 : {
828 340 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, ( ivas_total_brate / st_ivas->nCPE ) ) ) != IVAS_ERR_OK )
829 : {
830 0 : return error;
831 : }
832 : }
833 :
834 85 : if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
835 : {
836 0 : return error;
837 : }
838 :
839 85 : if ( ( error = ivas_create_lfe_enc( &st_ivas->hLFE, input_Fs ) ) != IVAS_ERR_OK )
840 : {
841 0 : return error;
842 : }
843 : }
844 347 : else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
845 : {
846 152 : if ( ( error = ivas_param_mc_enc_open( st_ivas ) ) != IVAS_ERR_OK )
847 : {
848 0 : return error;
849 : }
850 :
851 393 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
852 : {
853 241 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, ivas_total_brate / ( st_ivas->nCPE + st_ivas->nSCE ) ) ) != IVAS_ERR_OK )
854 : {
855 0 : return error;
856 : }
857 : }
858 :
859 152 : if ( st_ivas->nCPE > 1 )
860 : {
861 89 : if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
862 : {
863 0 : return error;
864 : }
865 : }
866 : }
867 195 : else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
868 : {
869 : int32_t brate_sce, brate_cpe;
870 :
871 195 : ivas_mcmasa_setNumTransportChannels( &( st_ivas->nchan_transport ), &( hEncoderConfig->element_mode_init ), ivas_total_brate );
872 :
873 195 : if ( ( error = ivas_qmetadata_open( &( st_ivas->hQMetaData ) ) ) != IVAS_ERR_OK )
874 : {
875 0 : return error;
876 : }
877 :
878 195 : if ( ( error = ivas_masa_enc_open( st_ivas ) ) != IVAS_ERR_OK )
879 : {
880 0 : return error;
881 : }
882 :
883 195 : if ( ( error = ivas_mcmasa_enc_open( st_ivas ) ) != IVAS_ERR_OK )
884 : {
885 0 : return error;
886 : }
887 :
888 195 : ivas_mcmasa_split_brate( st_ivas->hMcMasa->separateChannelEnabled, ivas_total_brate, st_ivas->nSCE, st_ivas->nCPE, &brate_sce, &brate_cpe );
889 :
890 376 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
891 : {
892 181 : if ( ( error = create_sce_enc( st_ivas, sce_id, brate_sce ) ) != IVAS_ERR_OK )
893 : {
894 0 : return error;
895 : }
896 : }
897 :
898 238 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
899 : {
900 43 : hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
901 :
902 43 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_cpe ) ) != IVAS_ERR_OK )
903 : {
904 0 : return error;
905 : }
906 : }
907 : }
908 : }
909 : #ifdef DEBUGGING
910 : else
911 : {
912 : return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Invalid IVAS format. Exiting.\n" );
913 : }
914 : #endif
915 :
916 : /*-----------------------------------------------------------------*
917 : * Allocate and initialize HP20 filter memories
918 : *-----------------------------------------------------------------*/
919 :
920 : /* set number of input channels used for analysis/coding */
921 6855 : n = getNumChanAnalysis( st_ivas );
922 :
923 6855 : if ( n > 0 )
924 : {
925 6855 : if ( ( st_ivas->mem_hp20_in = (float **) malloc( n * sizeof( float * ) ) ) == NULL )
926 : {
927 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
928 : }
929 : }
930 : else
931 : {
932 0 : st_ivas->mem_hp20_in = NULL;
933 : }
934 :
935 43096 : for ( i = 0; i < n; i++ )
936 : {
937 36241 : if ( ( st_ivas->mem_hp20_in[i] = (float *) malloc( L_HP20_MEM * sizeof( float ) ) ) == NULL )
938 : {
939 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HP20 filter memory\n" ) );
940 : }
941 :
942 36241 : set_f( st_ivas->mem_hp20_in[i], 0.0f, L_HP20_MEM );
943 : }
944 :
945 6855 : return error;
946 : }
947 :
948 :
949 : /*-------------------------------------------------------------------------
950 : * destroy_core_enc()
951 : *
952 : * Close core encoder handles
953 : *-------------------------------------------------------------------------*/
954 :
955 146600 : void destroy_core_enc(
956 : ENC_CORE_HANDLE hCoreCoder /* i/o: core encoder structure */
957 : )
958 : {
959 : int16_t i;
960 :
961 146600 : destroy_cldfb_encoder( hCoreCoder );
962 :
963 146600 : if ( hCoreCoder->hSignalBuf != NULL )
964 : {
965 146320 : free( hCoreCoder->hSignalBuf );
966 146320 : hCoreCoder->hSignalBuf = NULL;
967 : }
968 :
969 146600 : if ( hCoreCoder->hBstr != NULL )
970 : {
971 : /* reset buffer of indices */
972 146320 : for ( i = 0; i < hCoreCoder->hBstr->nb_ind_tot; i++ )
973 : {
974 0 : hCoreCoder->hBstr->ind_list[i].nb_bits = -1;
975 : }
976 146320 : free( hCoreCoder->hBstr );
977 146320 : hCoreCoder->hBstr = NULL;
978 : }
979 :
980 146600 : if ( hCoreCoder->hLPDmem != NULL )
981 : {
982 61349 : free( hCoreCoder->hLPDmem );
983 61349 : hCoreCoder->hLPDmem = NULL;
984 : }
985 :
986 146600 : if ( hCoreCoder->hTranDet != NULL )
987 : {
988 146320 : free( hCoreCoder->hTranDet );
989 146320 : hCoreCoder->hTranDet = NULL;
990 : }
991 :
992 146600 : if ( hCoreCoder->hNoiseEst != NULL )
993 : {
994 145821 : free( hCoreCoder->hNoiseEst );
995 145821 : hCoreCoder->hNoiseEst = NULL;
996 : }
997 :
998 146600 : if ( hCoreCoder->hVAD != NULL )
999 : {
1000 145541 : free( hCoreCoder->hVAD );
1001 145541 : hCoreCoder->hVAD = NULL;
1002 : }
1003 :
1004 146600 : if ( hCoreCoder->hVAD_CLDFB != NULL )
1005 : {
1006 306 : free( hCoreCoder->hVAD_CLDFB );
1007 306 : hCoreCoder->hVAD_CLDFB = NULL;
1008 : }
1009 :
1010 146600 : if ( hCoreCoder->hTdCngEnc != NULL )
1011 : {
1012 1177 : free( hCoreCoder->hTdCngEnc );
1013 1177 : hCoreCoder->hTdCngEnc = NULL;
1014 : }
1015 :
1016 146600 : if ( hCoreCoder->hDtxEnc != NULL )
1017 : {
1018 6363 : free( hCoreCoder->hDtxEnc );
1019 6363 : hCoreCoder->hDtxEnc = NULL;
1020 : }
1021 :
1022 146600 : if ( hCoreCoder->hSpMusClas != NULL )
1023 : {
1024 145821 : free( hCoreCoder->hSpMusClas );
1025 145821 : hCoreCoder->hSpMusClas = NULL;
1026 : }
1027 :
1028 146600 : if ( hCoreCoder->hGSCEnc != NULL )
1029 : {
1030 61349 : free( hCoreCoder->hGSCEnc );
1031 61349 : hCoreCoder->hGSCEnc = NULL;
1032 : }
1033 :
1034 146600 : if ( hCoreCoder->hSC_VBR != NULL )
1035 : {
1036 306 : free( hCoreCoder->hSC_VBR );
1037 306 : hCoreCoder->hSC_VBR = NULL;
1038 : }
1039 :
1040 146600 : if ( hCoreCoder->hAmrwb_IO != NULL )
1041 : {
1042 306 : free( hCoreCoder->hAmrwb_IO );
1043 306 : hCoreCoder->hAmrwb_IO = NULL;
1044 : }
1045 :
1046 146600 : if ( hCoreCoder->hBWE_TD != NULL )
1047 : {
1048 61346 : free( hCoreCoder->hBWE_TD );
1049 61346 : hCoreCoder->hBWE_TD = NULL;
1050 : }
1051 :
1052 146600 : if ( hCoreCoder->hBWE_FD != NULL )
1053 : {
1054 61346 : free( hCoreCoder->hBWE_FD );
1055 61346 : hCoreCoder->hBWE_FD = NULL;
1056 : }
1057 :
1058 146600 : if ( hCoreCoder->hRF != NULL )
1059 : {
1060 306 : free( hCoreCoder->hRF );
1061 306 : hCoreCoder->hRF = NULL;
1062 : }
1063 :
1064 146600 : if ( hCoreCoder->hTECEnc != NULL )
1065 : {
1066 306 : free( hCoreCoder->hTECEnc );
1067 306 : hCoreCoder->hTECEnc = NULL;
1068 : }
1069 :
1070 146600 : if ( hCoreCoder->hTcxEnc != NULL )
1071 : {
1072 145536 : free( hCoreCoder->hTcxEnc );
1073 145536 : hCoreCoder->hTcxEnc = NULL;
1074 : }
1075 :
1076 146600 : if ( hCoreCoder->hTcxCfg != NULL )
1077 : {
1078 145536 : free( hCoreCoder->hTcxCfg );
1079 145536 : hCoreCoder->hTcxCfg = NULL;
1080 : }
1081 :
1082 146600 : if ( hCoreCoder->hIGFEnc != NULL )
1083 : {
1084 122618 : free( hCoreCoder->hIGFEnc );
1085 122618 : hCoreCoder->hIGFEnc = NULL;
1086 : }
1087 :
1088 146600 : if ( hCoreCoder->hPlcExt != NULL )
1089 : {
1090 306 : free( hCoreCoder->hPlcExt );
1091 306 : hCoreCoder->hPlcExt = NULL;
1092 : }
1093 :
1094 146600 : if ( hCoreCoder->hHQ_core != NULL )
1095 : {
1096 61389 : free( hCoreCoder->hHQ_core );
1097 61389 : hCoreCoder->hHQ_core = NULL;
1098 : }
1099 :
1100 146600 : free( hCoreCoder );
1101 :
1102 146600 : return;
1103 : }
1104 :
1105 :
1106 : /*-------------------------------------------------------------------------
1107 : * ivas_destroy_enc()
1108 : *
1109 : * Close IVAS encoder handles
1110 : *-------------------------------------------------------------------------*/
1111 :
1112 6855 : void ivas_destroy_enc(
1113 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
1114 : )
1115 : {
1116 : int16_t i, n, nchan_inp;
1117 6855 : nchan_inp = st_ivas->hEncoderConfig->nchan_inp;
1118 :
1119 : /* SCE handles */
1120 34275 : for ( i = 0; i < MAX_SCE; i++ )
1121 : {
1122 27420 : if ( st_ivas->hSCE[i] != NULL )
1123 : {
1124 4903 : destroy_sce_enc( st_ivas->hSCE[i] );
1125 4903 : st_ivas->hSCE[i] = NULL;
1126 : }
1127 : }
1128 :
1129 : /* CPE handles */
1130 47985 : for ( i = 0; i < MAX_CPE; i++ )
1131 : {
1132 41130 : if ( st_ivas->hCPE[i] != NULL )
1133 : {
1134 9112 : destroy_cpe_enc( st_ivas->hCPE[i] );
1135 9112 : st_ivas->hCPE[i] = NULL;
1136 : }
1137 : }
1138 :
1139 : /* HP20 filter handles */
1140 6855 : if ( st_ivas->mem_hp20_in != NULL )
1141 : {
1142 6855 : n = getNumChanAnalysis( st_ivas );
1143 :
1144 43294 : for ( i = 0; i < n; i++ )
1145 : {
1146 36439 : free( st_ivas->mem_hp20_in[i] );
1147 36439 : st_ivas->mem_hp20_in[i] = NULL;
1148 : }
1149 6855 : free( st_ivas->mem_hp20_in );
1150 6855 : st_ivas->mem_hp20_in = NULL;
1151 : }
1152 :
1153 : /* ISM metadata handles */
1154 6855 : ivas_ism_metadata_close( st_ivas->hIsmMetaData, 0 );
1155 :
1156 : /* ISM DTX Handle */
1157 6855 : if ( st_ivas->hISMDTX != NULL )
1158 : {
1159 293 : free( st_ivas->hISMDTX );
1160 293 : st_ivas->hISMDTX = NULL;
1161 : }
1162 :
1163 : /* Q Metadata handle */
1164 6855 : ivas_qmetadata_close( &( st_ivas->hQMetaData ) );
1165 :
1166 : /* DirAC handle */
1167 6855 : ivas_dirac_enc_close( &( st_ivas->hDirAC ), st_ivas->hEncoderConfig->input_Fs );
1168 :
1169 : /* ParamISM handle */
1170 6855 : ivas_param_ism_enc_close( &( st_ivas->hParamIsm ), st_ivas->hEncoderConfig->input_Fs );
1171 :
1172 : /* SPAR handle */
1173 6855 : ivas_spar_enc_close( &( st_ivas->hSpar ), st_ivas->hEncoderConfig->input_Fs, nchan_inp, 0 );
1174 :
1175 : /* MASA handle */
1176 6855 : ivas_masa_enc_close( &( st_ivas->hMasa ) );
1177 :
1178 : /* MCT handle */
1179 6855 : ivas_mct_enc_close( &( st_ivas->hMCT ) );
1180 :
1181 : /* LFE handle */
1182 6855 : ivas_lfe_enc_close( &( st_ivas->hLFE ) );
1183 :
1184 : /* LFE low pass filter state */
1185 6855 : ivas_lfe_lpf_enc_close( &( st_ivas->hLfeLpf ) );
1186 :
1187 : /* Param-Upmix MC handle */
1188 6855 : ivas_mc_paramupmix_enc_close( &( st_ivas->hMCParamUpmix ), st_ivas->hEncoderConfig->input_Fs );
1189 :
1190 : /* Parametric MC handle */
1191 6855 : ivas_param_mc_enc_close( &( st_ivas->hParamMC ), st_ivas->hEncoderConfig->input_Fs );
1192 :
1193 : /* Multi-channel MASA handle */
1194 6855 : ivas_mcmasa_enc_close( &( st_ivas->hMcMasa ), st_ivas->hEncoderConfig->input_Fs );
1195 :
1196 : /* OMASA handle */
1197 6855 : ivas_omasa_enc_close( &( st_ivas->hOMasa ) );
1198 :
1199 : /* OSBA handle */
1200 6855 : ivas_osba_enc_close( &( st_ivas->hOSba ) );
1201 :
1202 : /* Stereo downmix for EVS encoder handle */
1203 6855 : stereo_dmx_evs_close_encoder( &( st_ivas->hStereoDmxEVS ) );
1204 :
1205 : /* Encoder configuration handle */
1206 6855 : if ( st_ivas->hEncoderConfig != NULL )
1207 : {
1208 6855 : free( st_ivas->hEncoderConfig );
1209 6855 : st_ivas->hEncoderConfig = NULL;
1210 : }
1211 :
1212 : /* Buffer of indices */
1213 6855 : if ( st_ivas->ind_list != NULL )
1214 : {
1215 6855 : free( st_ivas->ind_list );
1216 : }
1217 :
1218 6855 : if ( st_ivas->ind_list_metadata != NULL )
1219 : {
1220 6549 : free( st_ivas->ind_list_metadata );
1221 : }
1222 :
1223 : /* floating-point input audio buffers */
1224 143955 : for ( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
1225 : {
1226 137100 : if ( st_ivas->p_data_f[n] != NULL )
1227 : {
1228 46928 : free( st_ivas->p_data_f[n] );
1229 46928 : st_ivas->p_data_f[n] = NULL;
1230 : }
1231 : }
1232 :
1233 : /* main IVAS handle */
1234 6855 : free( st_ivas );
1235 :
1236 6855 : return;
1237 : }
1238 :
1239 : /*-------------------------------------------------------------------------
1240 : * ivas_initialize_MD_bstr_enc()
1241 : *
1242 : * Allocate and initialize SCE/CPE MD bitstream handle
1243 : *-------------------------------------------------------------------------*/
1244 :
1245 72906 : ivas_error ivas_initialize_MD_bstr_enc(
1246 : BSTR_ENC_HANDLE *hMetaData_out, /* o : encoder MD bitstream handle */
1247 : Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */
1248 : )
1249 : {
1250 : BSTR_ENC_HANDLE hMetaData;
1251 :
1252 72906 : if ( ( hMetaData = (BSTR_ENC_HANDLE) malloc( sizeof( BSTR_ENC_DATA ) ) ) == NULL )
1253 : {
1254 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MetaData structure\n" ) );
1255 : }
1256 :
1257 : /* set pointer to the buffer of metadata indices */
1258 72906 : hMetaData->ind_list = st_ivas->ind_list_metadata;
1259 72906 : hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata;
1260 72906 : hMetaData->ivas_max_num_indices = &st_ivas->ivas_max_num_indices_metadata;
1261 72906 : hMetaData->st_ivas = st_ivas;
1262 :
1263 72906 : reset_indices_enc( hMetaData, st_ivas->ivas_max_num_indices_metadata );
1264 :
1265 72906 : *hMetaData_out = hMetaData;
1266 :
1267 72906 : return IVAS_ERR_OK;
1268 : }
1269 :
1270 :
1271 : /*-------------------------------------------------------------------------
1272 : * ivas_destroy_MD_bstr_enc()
1273 : *
1274 : * Destroy SCE/CPE MD bitstream handle
1275 : *-------------------------------------------------------------------------*/
1276 :
1277 160719 : void ivas_destroy_MD_bstr_enc(
1278 : BSTR_ENC_HANDLE *hMetaData /* i/o: encoder MD bitstream handle */
1279 : )
1280 : {
1281 160719 : if ( hMetaData == NULL || *hMetaData == NULL )
1282 : {
1283 87813 : return;
1284 : }
1285 :
1286 72906 : free( *hMetaData );
1287 72906 : *hMetaData = NULL;
1288 :
1289 72906 : return;
1290 : }
|