Line data Source code
1 : /******************************************************************************************************
2 :
3 : (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
4 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
5 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
6 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
7 : contributors to this repository. All Rights Reserved.
8 :
9 : This software is protected by copyright law and by international treaties.
10 : The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
11 : Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
12 : Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
13 : Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
14 : contributors to this repository retain full ownership rights in their respective contributions in
15 : the software. This notice grants no license of any kind, including but not limited to patent
16 : license, nor is any license granted by implication, estoppel or otherwise.
17 :
18 : Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
19 : contributions.
20 :
21 : This software is provided "AS IS", without any express or implied warranties. The software is in the
22 : development stage. It is intended exclusively for experts who have experience with such software and
23 : solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
24 : and fitness for a particular purpose are hereby disclaimed and excluded.
25 :
26 : Any dispute, controversy or claim arising under or in relation to providing this software shall be
27 : submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
28 : accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
29 : the United Nations Convention on Contracts on the International Sales of Goods.
30 :
31 : *******************************************************************************************************/
32 :
33 : #include <stdint.h>
34 : #include "options.h"
35 : #include "ivas_cnst.h"
36 : #include "prot.h"
37 : #include "ivas_prot.h"
38 : #ifdef DEBUGGING
39 : #include "debug.h"
40 : #include <assert.h>
41 : #endif
42 : #include "wmc_auto.h"
43 : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
44 : #include <string.h>
45 : #endif
46 :
47 : /*-------------------------------------------------------------------*
48 : * ivas_corecoder_enc_reconfig()
49 : *
50 : * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching
51 : *-------------------------------------------------------------------*/
52 :
53 94158 : ivas_error ivas_corecoder_enc_reconfig(
54 : Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
55 : const int16_t nSCE_old, /* i : number of SCEs in previous frame */
56 : const int16_t nCPE_old, /* i : number of CPEs in previous frame */
57 : const int16_t nchan_transport_old, /* i : number of TCs in previous frame */
58 : const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */
59 : const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */
60 : const MC_MODE last_mc_mode /* i : switching between MC modes: last mode */
61 : )
62 : {
63 : int16_t n, sce_id, cpe_id;
64 : int16_t len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing;
65 : float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )];
66 : BSTR_ENC_HANDLE hBstr;
67 : int16_t i, nb_bits;
68 : Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST];
69 : int16_t nb_bits_tot;
70 : int16_t nchan_transport_real, nchan_transport_old_real;
71 : ENCODER_CONFIG_HANDLE hEncoderConfig;
72 : ivas_error error;
73 :
74 : /*-----------------------------------------------------------------*
75 : * Initialization
76 : *-----------------------------------------------------------------*/
77 :
78 94158 : hEncoderConfig = st_ivas->hEncoderConfig;
79 94158 : error = IVAS_ERR_OK;
80 :
81 94158 : len_inp_memory = (int16_t) ( hEncoderConfig->input_Fs / FRAMES_PER_SEC );
82 94158 : if ( hEncoderConfig->ivas_format == SBA_FORMAT )
83 : {
84 11474 : len_inp_memory += NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS );
85 : }
86 :
87 94158 : nchan_transport_old_real = nchan_transport_old;
88 94158 : nchan_transport_real = st_ivas->nchan_transport;
89 :
90 94158 : if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
91 : {
92 2806 : nchan_transport_real += st_ivas->hEncoderConfig->nchan_ism;
93 : }
94 :
95 : /*-----------------------------------------------------------------*
96 : * Switching between SCE(s)/CPE(s)/MCT
97 : *-----------------------------------------------------------------*/
98 :
99 94158 : if ( nchan_transport_real == nchan_transport_old_real && st_ivas->nSCE == nSCE_old && st_ivas->nCPE == nCPE_old ) /* in McMASA, nchan_transport may be the same, but nSCE/nCPE differs */
100 : {
101 35906 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
102 : {
103 18798 : copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
104 18798 : st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
105 18798 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
106 : }
107 :
108 36908 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
109 : {
110 19800 : st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
111 :
112 : /* prepare bitstream buffers */
113 59400 : for ( n = 0; n < CPE_CHANNELS; n++ )
114 : {
115 39600 : copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
116 :
117 39600 : st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
118 : }
119 : }
120 :
121 17108 : if ( st_ivas->nCPE > 1 )
122 : {
123 3787 : if ( ( error = mct_enc_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK )
124 : {
125 0 : return error;
126 : }
127 : }
128 : }
129 : else
130 : {
131 :
132 : /* in SCE+CPE McMASA nchan_transport is still 2, fix the numbers */
133 77050 : if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA )
134 : {
135 6403 : nchan_transport_old_real = nSCE_old + CPE_CHANNELS * nCPE_old;
136 : }
137 :
138 77050 : if ( hEncoderConfig->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA )
139 : {
140 6376 : nchan_transport_real = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE;
141 : }
142 :
143 : /* something in transport changes */
144 77050 : hBstr = NULL;
145 :
146 : /* get the index list pointers */
147 77050 : if ( nSCE_old )
148 : {
149 42757 : hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr;
150 : }
151 34293 : else if ( nCPE_old )
152 : {
153 34293 : hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr;
154 : }
155 : #ifdef DEBUGGING
156 : else
157 : {
158 : assert( 0 && "At least one SCE or one CPE should have existed before!\n" );
159 : }
160 : #endif
161 :
162 : /* save bitstream information */
163 77050 : nb_bits_tot = hBstr->nb_bits_tot;
164 77050 : i = 0;
165 77050 : nb_bits = 0;
166 156350 : while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
167 : {
168 79300 : if ( hBstr->ind_list[i].nb_bits > 0 )
169 : {
170 79300 : temp_ind_list[i].id = hBstr->ind_list[i].id;
171 79300 : temp_ind_list[i].value = hBstr->ind_list[i].value;
172 79300 : temp_ind_list[i].nb_bits = hBstr->ind_list[i].nb_bits;
173 : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
174 : strncpy( temp_ind_list[i].function_name, hBstr->ind_list[i].function_name, 100 );
175 : #endif
176 :
177 79300 : hBstr->ind_list[i].nb_bits = -1;
178 : }
179 :
180 79300 : hBstr->nb_bits_tot = 0;
181 79300 : hBstr->nb_ind_tot = 0;
182 :
183 79300 : nb_bits += temp_ind_list[i].nb_bits;
184 79300 : i++;
185 : }
186 :
187 768250 : for ( ; i < MAX_NUM_IND_TEMP_LIST; i++ )
188 : {
189 : /* reset nb_bits of all other indices to -1 */
190 691200 : temp_ind_list[i].nb_bits = -1;
191 : }
192 :
193 : #ifdef DEBUGGING
194 : assert( ( nb_bits == nb_bits_tot ) && "Error saving bitstream information during core-coder reconfiguration!\n" );
195 : #endif
196 :
197 77050 : if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA )
198 : {
199 : /* within McMASA we can modify the transport signals when switching */
200 : /* copy earlier dmx buffers */
201 1898 : if ( nSCE_old > 0 )
202 : {
203 1313 : set_zero( input_buff[0], len_inp_memory );
204 1313 : mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory );
205 : }
206 :
207 5694 : for ( n = 0; n < CPE_CHANNELS; n++ )
208 : {
209 3796 : set_zero( input_buff[n + 1], len_inp_memory );
210 3796 : if ( nCPE_old > 0 )
211 : {
212 2476 : mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory );
213 : }
214 : }
215 :
216 1898 : ivas_mcmasa_dmx_modify( len_inp_memory, input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE );
217 :
218 1898 : n_CoreCoder_existing = 0;
219 : }
220 : else
221 : {
222 75152 : n_CoreCoder_existing = min( nchan_transport_real, nchan_transport_old_real );
223 : }
224 :
225 : /* destroy superfluous core-coder elements */
226 130745 : for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
227 : {
228 : /* save input audio buffers */
229 53695 : if ( n_CoreCoder_existing > sce_id )
230 : {
231 33784 : mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory );
232 : }
233 :
234 53695 : destroy_sce_enc( st_ivas->hSCE[sce_id] );
235 53695 : st_ivas->hSCE[sce_id] = NULL;
236 : }
237 :
238 109090 : for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
239 : {
240 : /* save input audio buffers */
241 96120 : for ( n = 0; n < CPE_CHANNELS; n++ )
242 : {
243 64080 : if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
244 : {
245 7841 : mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory );
246 : }
247 : }
248 :
249 32040 : destroy_cpe_enc( st_ivas->hCPE[cpe_id] );
250 32040 : st_ivas->hCPE[cpe_id] = NULL;
251 : }
252 :
253 77050 : if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
254 : {
255 5756 : ivas_mct_enc_close( &( st_ivas->hMCT ) );
256 : }
257 :
258 : /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */
259 77050 : if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
260 : {
261 5084 : free( st_ivas->hCPE[0]->hStereoMdct );
262 5084 : st_ivas->hCPE[0]->hStereoMdct = NULL;
263 : }
264 :
265 : /* create missing core coder elements and set element bitrates for already existing ones */
266 77050 : if ( st_ivas->nSCE > 0 )
267 : {
268 42692 : nSCE_existing = min( nSCE_old, st_ivas->nSCE );
269 :
270 67563 : for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
271 : {
272 24871 : copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
273 24871 : st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
274 24871 : st_ivas->hSCE[sce_id]->hCoreCoder[0]->total_brate = st_ivas->hSCE[sce_id]->element_brate; /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
275 :
276 24871 : ivas_destroy_MD_bstr_enc( &( st_ivas->hSCE[sce_id]->hMetaData ) );
277 : }
278 :
279 96345 : for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ )
280 : {
281 53653 : if ( ( error = create_sce_enc( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK )
282 : {
283 0 : return error;
284 : }
285 :
286 : /* propagate input audio buffers */
287 53653 : if ( n_CoreCoder_existing > sce_id && hEncoderConfig->ivas_format != MASA_ISM_FORMAT )
288 : {
289 7841 : mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory );
290 : }
291 :
292 : /* only reset indices if it is not the first index list, this already contains the IVAS format bits */
293 53653 : if ( sce_id > 0 || hEncoderConfig->ivas_format == MASA_ISM_FORMAT )
294 : {
295 45227 : reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_ind_tot );
296 : }
297 : }
298 :
299 42692 : if ( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData == NULL )
300 : {
301 10638 : if ( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK )
302 : {
303 0 : return error;
304 : }
305 : }
306 : }
307 :
308 77050 : if ( st_ivas->nCPE > 0 )
309 : {
310 64979 : nCPE_existing = min( nCPE_old, st_ivas->nCPE );
311 :
312 127121 : for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
313 : {
314 62142 : st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
315 :
316 : /* allocate buffer of indices */
317 186426 : for ( n = 0; n < CPE_CHANNELS; n++ )
318 : {
319 124284 : copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
320 124284 : st_ivas->hCPE[cpe_id]->hCoreCoder[n]->total_brate = st_ivas->hCPE[cpe_id]->element_brate / ( st_ivas->nCPE > 1 ? 1 : CPE_CHANNELS ); /* dummy initialization for getting right pointers initialization of input buffers in init_coder_ace_plus() */
321 :
322 124284 : if ( ( cpe_id * CPE_CHANNELS + n > 0 ) ||
323 57159 : ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ||
324 56117 : ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 ) )
325 : {
326 97383 : reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot );
327 : }
328 : }
329 : }
330 :
331 97207 : for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ )
332 : {
333 32228 : if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hMcMasa->separateChannelEnabled )
334 : {
335 363 : st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
336 : }
337 :
338 32228 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK )
339 : {
340 0 : return error;
341 : }
342 :
343 : /* propagate input audio buffers */
344 96684 : for ( n = 0; n < CPE_CHANNELS; n++ )
345 : {
346 64456 : if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
347 : {
348 7907 : mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, len_inp_memory );
349 : }
350 : }
351 :
352 96684 : for ( n = 0; n < CPE_CHANNELS; n++ )
353 : {
354 : /* only reset indices if it is not the first index list, this already contains the IVAS format bits */
355 64456 : if ( cpe_id * CPE_CHANNELS + n > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) )
356 : {
357 56999 : reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot );
358 : }
359 :
360 64456 : if ( hEncoderConfig->Opt_DTX_ON )
361 : {
362 1972 : st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1;
363 : }
364 : }
365 : }
366 : }
367 :
368 : /* restore bitstream - IVAS format bits should be written in the first core channel of the first SCE/CPE */
369 77050 : i = 0;
370 77050 : nb_bits = 0;
371 77050 : if ( st_ivas->nSCE > 0 )
372 : {
373 86606 : while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
374 : {
375 43914 : if ( temp_ind_list[i].nb_bits > 0 )
376 : {
377 43914 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id;
378 43914 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value;
379 43914 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits;
380 : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
381 : strncpy( st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].function_name, temp_ind_list[i].function_name, 100 );
382 : #endif
383 : }
384 :
385 43914 : nb_bits += temp_ind_list[i].nb_bits;
386 43914 : i++;
387 : }
388 42692 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i;
389 42692 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
390 : }
391 34358 : else if ( st_ivas->nCPE > 0 )
392 : {
393 69744 : while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
394 : {
395 35386 : if ( temp_ind_list[i].nb_bits > 0 )
396 : {
397 35386 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id;
398 35386 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value;
399 35386 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits;
400 : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
401 : strncpy( st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].function_name, temp_ind_list[i].function_name, 100 );
402 : #endif
403 : }
404 :
405 35386 : nb_bits += temp_ind_list[i].nb_bits;
406 35386 : i++;
407 : }
408 34358 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i;
409 34358 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
410 : }
411 :
412 : #ifdef DEBUGGING
413 : assert( ( nb_bits == nb_bits_tot ) && "Error restoring bitstream information during core-coder reconfiguration!\n" );
414 : #endif
415 :
416 :
417 77050 : if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA )
418 : {
419 : /* restore modified transport signal */
420 1898 : if ( st_ivas->nSCE )
421 : {
422 1315 : mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory );
423 : }
424 :
425 1898 : if ( st_ivas->nCPE )
426 : {
427 3762 : for ( n = 0; n < CPE_CHANNELS; n++ )
428 : {
429 2508 : mvr2r( input_buff[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, len_inp_memory );
430 : }
431 : }
432 : }
433 :
434 77050 : if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
435 : {
436 10267 : if ( nCPE_old == 1 )
437 : {
438 : /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */
439 15252 : for ( n = 0; n < CPE_CHANNELS; n++ )
440 : {
441 10168 : st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
442 10168 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
443 20336 : st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
444 10168 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
445 10168 : st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
446 10168 : st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
447 :
448 10168 : if ( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ) != IVAS_ERR_OK )
449 : {
450 0 : return error;
451 : }
452 : }
453 : }
454 :
455 10267 : if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
456 : {
457 0 : return error;
458 : }
459 : }
460 66783 : else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
461 : {
462 3459 : if ( ( error = mct_enc_reconfigure( st_ivas, nchan_transport_old_real != nchan_transport_real ) ) != IVAS_ERR_OK )
463 : {
464 0 : return error;
465 : }
466 : }
467 :
468 : /* alllocate buffer for metadata indices */
469 77050 : if ( st_ivas->nCPE > 0 )
470 : {
471 64979 : if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL )
472 : {
473 6017 : if ( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK )
474 : {
475 0 : return error;
476 : }
477 : }
478 :
479 64979 : reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->nb_ind_tot );
480 :
481 94370 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ )
482 : {
483 29391 : ivas_destroy_MD_bstr_enc( &( st_ivas->hCPE[cpe_id]->hMetaData ) );
484 : }
485 : }
486 :
487 : /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */
488 77050 : if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
489 : {
490 5090 : if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL )
491 : {
492 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
493 : }
494 :
495 : /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */
496 15270 : for ( n = 0; n < CPE_CHANNELS; n++ )
497 : {
498 10180 : st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
499 10180 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
500 20360 : st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
501 10180 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
502 10180 : st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
503 10180 : st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
504 :
505 10180 : if ( ( error = IGF_Reconfig( &st_ivas->hCPE[0]->hCoreCoder[n]->hIGFEnc, st_ivas->hCPE[0]->hCoreCoder[n]->igf, 1, st_ivas->hCPE[0]->element_brate, st_ivas->hCPE[0]->hCoreCoder[n]->bwidth, st_ivas->hCPE[0]->hCoreCoder[n]->element_mode, st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode ) ) != IVAS_ERR_OK )
506 : {
507 0 : return error;
508 : }
509 :
510 : /* reset mct_chan_mode */
511 10180 : st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
512 : }
513 :
514 : #ifdef DEBUGGING
515 : st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->mdct_stereo_mode_cmdl = hEncoderConfig->stereo_mode_cmdl;
516 : #endif
517 5090 : initMdctStereoEncData( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct, hEncoderConfig->ivas_format, st_ivas->hCPE[st_ivas->nCPE - 1]->element_mode, st_ivas->hCPE[st_ivas->nCPE - 1]->element_brate, hEncoderConfig->max_bwidth, 0, NULL, 1 );
518 5090 : st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->isSBAStereoMode = ( ( hEncoderConfig->ivas_format == SBA_FORMAT || hEncoderConfig->ivas_format == SBA_ISM_FORMAT ) && ( st_ivas->nchan_transport == 2 ) );
519 : }
520 : }
521 :
522 94158 : return error;
523 : }
|