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 98413 : 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 98413 : hEncoderConfig = st_ivas->hEncoderConfig;
79 98413 : error = IVAS_ERR_OK;
80 :
81 98413 : len_inp_memory = (int16_t) ( hEncoderConfig->input_Fs / FRAMES_PER_SEC );
82 98413 : if ( hEncoderConfig->ivas_format == SBA_FORMAT )
83 : {
84 12217 : len_inp_memory += NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS );
85 : }
86 :
87 98413 : nchan_transport_old_real = nchan_transport_old;
88 98413 : nchan_transport_real = st_ivas->nchan_transport;
89 :
90 98413 : if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
91 : {
92 3061 : nchan_transport_real += st_ivas->hEncoderConfig->nchan_ism;
93 : }
94 :
95 : /*-----------------------------------------------------------------*
96 : * Switching between SCE(s)/CPE(s)/MCT
97 : *-----------------------------------------------------------------*/
98 :
99 98413 : 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 38285 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
102 : {
103 20218 : copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
104 20218 : st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
105 20218 : 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 38764 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
109 : {
110 20697 : st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
111 :
112 : /* prepare bitstream buffers */
113 62091 : for ( n = 0; n < CPE_CHANNELS; n++ )
114 : {
115 41394 : copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
116 :
117 41394 : 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 18067 : if ( st_ivas->nCPE > 1 )
122 : {
123 4020 : 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 80346 : if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA )
134 : {
135 6600 : nchan_transport_old_real = nSCE_old + CPE_CHANNELS * nCPE_old;
136 : }
137 :
138 80346 : if ( hEncoderConfig->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA )
139 : {
140 6560 : nchan_transport_real = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE;
141 : }
142 :
143 : /* something in transport changes */
144 80346 : hBstr = NULL;
145 :
146 : /* get the index list pointers */
147 80346 : if ( nSCE_old )
148 : {
149 44577 : hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr;
150 : }
151 35769 : else if ( nCPE_old )
152 : {
153 35769 : 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 80346 : nb_bits_tot = hBstr->nb_bits_tot;
164 80346 : i = 0;
165 80346 : nb_bits = 0;
166 162446 : while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
167 : {
168 82100 : if ( hBstr->ind_list[i].nb_bits > 0 )
169 : {
170 82100 : temp_ind_list[i].id = hBstr->ind_list[i].id;
171 82100 : temp_ind_list[i].value = hBstr->ind_list[i].value;
172 82100 : 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 82100 : hBstr->ind_list[i].nb_bits = -1;
178 : }
179 :
180 82100 : hBstr->nb_bits_tot = 0;
181 82100 : hBstr->nb_ind_tot = 0;
182 :
183 82100 : nb_bits += temp_ind_list[i].nb_bits;
184 82100 : i++;
185 : }
186 :
187 801706 : for ( ; i < MAX_NUM_IND_TEMP_LIST; i++ )
188 : {
189 : /* reset nb_bits of all other indices to -1 */
190 721360 : 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 80346 : 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 1919 : if ( nSCE_old > 0 )
202 : {
203 1330 : set_zero( input_buff[0], len_inp_memory );
204 1330 : mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory );
205 : }
206 :
207 5757 : for ( n = 0; n < CPE_CHANNELS; n++ )
208 : {
209 3838 : set_zero( input_buff[n + 1], len_inp_memory );
210 3838 : if ( nCPE_old > 0 )
211 : {
212 2498 : mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory );
213 : }
214 : }
215 :
216 1919 : 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 1919 : n_CoreCoder_existing = 0;
219 : }
220 : else
221 : {
222 78427 : n_CoreCoder_existing = min( nchan_transport_real, nchan_transport_old_real );
223 : }
224 :
225 : /* destroy superfluous core-coder elements */
226 136003 : for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
227 : {
228 : /* save input audio buffers */
229 55657 : if ( n_CoreCoder_existing > sce_id )
230 : {
231 34897 : mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory );
232 : }
233 :
234 55657 : destroy_sce_enc( st_ivas->hSCE[sce_id] );
235 55657 : st_ivas->hSCE[sce_id] = NULL;
236 : }
237 :
238 114114 : for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
239 : {
240 : /* save input audio buffers */
241 101304 : for ( n = 0; n < CPE_CHANNELS; n++ )
242 : {
243 67536 : if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
244 : {
245 8377 : 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 33768 : destroy_cpe_enc( st_ivas->hCPE[cpe_id] );
250 33768 : st_ivas->hCPE[cpe_id] = NULL;
251 : }
252 :
253 80346 : if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
254 : {
255 6149 : 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 80346 : if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
260 : {
261 5340 : free( st_ivas->hCPE[0]->hStereoMdct );
262 5340 : st_ivas->hCPE[0]->hStereoMdct = NULL;
263 : }
264 :
265 : /* create missing core coder elements and set element bitrates for already existing ones */
266 80346 : if ( st_ivas->nSCE > 0 )
267 : {
268 44483 : nSCE_existing = min( nSCE_old, st_ivas->nSCE );
269 :
270 70938 : for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
271 : {
272 26455 : copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
273 26455 : st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
274 26455 : 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 26455 : ivas_destroy_MD_bstr_enc( &( st_ivas->hSCE[sce_id]->hMetaData ) );
277 : }
278 :
279 100077 : for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ )
280 : {
281 55594 : 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 55594 : if ( n_CoreCoder_existing > sce_id && hEncoderConfig->ivas_format != MASA_ISM_FORMAT )
288 : {
289 8377 : 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 55594 : if ( sce_id > 0 || hEncoderConfig->ivas_format == MASA_ISM_FORMAT )
294 : {
295 46628 : 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 44483 : if ( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData == NULL )
300 : {
301 11121 : 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 80346 : if ( st_ivas->nCPE > 0 )
309 : {
310 67108 : nCPE_existing = min( nCPE_old, st_ivas->nCPE );
311 :
312 130992 : for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
313 : {
314 63884 : st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
315 :
316 : /* allocate buffer of indices */
317 191652 : for ( n = 0; n < CPE_CHANNELS; n++ )
318 : {
319 127768 : copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
320 127768 : 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 127768 : if ( ( cpe_id * CPE_CHANNELS + n > 0 ) ||
323 58719 : ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ||
324 57671 : ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 ) )
325 : {
326 99923 : 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 101156 : for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ )
332 : {
333 34048 : if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hMcMasa->separateChannelEnabled )
334 : {
335 371 : st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
336 : }
337 :
338 34048 : 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 102144 : for ( n = 0; n < CPE_CHANNELS; n++ )
345 : {
346 68096 : if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
347 : {
348 8473 : mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, len_inp_memory );
349 : }
350 : }
351 :
352 102144 : 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 68096 : if ( cpe_id * CPE_CHANNELS + n > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) )
356 : {
357 60078 : 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 68096 : if ( hEncoderConfig->Opt_DTX_ON )
361 : {
362 2128 : 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 80346 : i = 0;
370 80346 : nb_bits = 0;
371 80346 : if ( st_ivas->nSCE > 0 )
372 : {
373 89985 : while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
374 : {
375 45502 : if ( temp_ind_list[i].nb_bits > 0 )
376 : {
377 45502 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id;
378 45502 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value;
379 45502 : 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 45502 : nb_bits += temp_ind_list[i].nb_bits;
386 45502 : i++;
387 : }
388 44483 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i;
389 44483 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
390 : }
391 35863 : else if ( st_ivas->nCPE > 0 )
392 : {
393 72461 : while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
394 : {
395 36598 : if ( temp_ind_list[i].nb_bits > 0 )
396 : {
397 36598 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id;
398 36598 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value;
399 36598 : 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 36598 : nb_bits += temp_ind_list[i].nb_bits;
406 36598 : i++;
407 : }
408 35863 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i;
409 35863 : 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 80346 : if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA )
418 : {
419 : /* restore modified transport signal */
420 1919 : if ( st_ivas->nSCE )
421 : {
422 1332 : mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory );
423 : }
424 :
425 1919 : if ( st_ivas->nCPE )
426 : {
427 3801 : for ( n = 0; n < CPE_CHANNELS; n++ )
428 : {
429 2534 : mvr2r( input_buff[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, len_inp_memory );
430 : }
431 : }
432 : }
433 :
434 80346 : if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
435 : {
436 10912 : 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 16020 : for ( n = 0; n < CPE_CHANNELS; n++ )
440 : {
441 10680 : st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
442 10680 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
443 21360 : st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
444 10680 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
445 10680 : st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
446 10680 : st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
447 :
448 10680 : 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 10912 : if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
456 : {
457 0 : return error;
458 : }
459 : }
460 69434 : else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
461 : {
462 3589 : 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 80346 : if ( st_ivas->nCPE > 0 )
470 : {
471 67108 : if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL )
472 : {
473 6314 : 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 67108 : reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->nb_ind_tot );
480 :
481 97932 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ )
482 : {
483 30824 : 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 80346 : if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
489 : {
490 5357 : 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 16071 : for ( n = 0; n < CPE_CHANNELS; n++ )
497 : {
498 10714 : st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
499 10714 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
500 21428 : st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
501 10714 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
502 10714 : st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
503 10714 : st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
504 :
505 10714 : 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 10714 : 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 5357 : 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 5357 : 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 98413 : return error;
523 : }
|