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 :
44 : /*-------------------------------------------------------------------*
45 : * ivas_corecoder_enc_reconfig()
46 : *
47 : * Allocate, initialize, and configure SCE/CPE/MCT handles in case of bitrate switching
48 : *-------------------------------------------------------------------*/
49 :
50 5332 : ivas_error ivas_corecoder_enc_reconfig(
51 : Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
52 : const int16_t nSCE_old, /* i : number of SCEs in previous frame */
53 : const int16_t nCPE_old, /* i : number of CPEs in previous frame */
54 : const int16_t nchan_transport_old, /* i : number of TCs in previous frame */
55 : const int32_t brate_SCE, /* i : bitrate to be set for the SCEs */
56 : const int32_t brate_CPE, /* i : bitrate to be set for the CPEs */
57 : const MC_MODE last_mc_mode /* i : switching between MC modes: last mode */
58 : )
59 : {
60 : int16_t n, sce_id, cpe_id;
61 : int16_t len_inp_memory, n_CoreCoder_existing, nSCE_existing, nCPE_existing;
62 : float input_buff[MCT_MAX_BLOCKS][L_FRAME48k + NS2SA( 48000, IVAS_FB_ENC_DELAY_NS )];
63 : BSTR_ENC_HANDLE hBstr;
64 : int16_t i, nb_bits;
65 : Indice temp_ind_list[MAX_NUM_IND_TEMP_LIST];
66 : int16_t nb_bits_tot;
67 : int16_t nchan_transport_real, nchan_transport_old_real;
68 : ENCODER_CONFIG_HANDLE hEncoderConfig;
69 : ivas_error error;
70 :
71 : /*-----------------------------------------------------------------*
72 : * Initialization
73 : *-----------------------------------------------------------------*/
74 :
75 5332 : hEncoderConfig = st_ivas->hEncoderConfig;
76 5332 : error = IVAS_ERR_OK;
77 :
78 5332 : len_inp_memory = (int16_t) ( hEncoderConfig->input_Fs / FRAMES_PER_SEC );
79 5332 : if ( hEncoderConfig->ivas_format == SBA_FORMAT )
80 : {
81 1020 : len_inp_memory += NS2SA( hEncoderConfig->input_Fs, IVAS_FB_ENC_DELAY_NS );
82 : }
83 :
84 5332 : nchan_transport_old_real = nchan_transport_old;
85 5332 : nchan_transport_real = st_ivas->nchan_transport;
86 :
87 5332 : if ( st_ivas->ism_mode == ISM_SBA_MODE_DISC )
88 : {
89 255 : nchan_transport_real += st_ivas->hEncoderConfig->nchan_ism;
90 : }
91 :
92 : /*-----------------------------------------------------------------*
93 : * Switching between SCE(s)/CPE(s)/MCT
94 : *-----------------------------------------------------------------*/
95 :
96 5332 : 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 */
97 : {
98 2538 : for ( sce_id = 0; sce_id < st_ivas->nSCE; sce_id++ )
99 : {
100 1412 : copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
101 1412 : st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
102 1412 : 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() */
103 : }
104 :
105 2288 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
106 : {
107 1162 : st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
108 :
109 : /* prepare bitstream buffers */
110 3486 : for ( n = 0; n < CPE_CHANNELS; n++ )
111 : {
112 2324 : copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
113 :
114 2324 : 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() */
115 : }
116 : }
117 :
118 1126 : if ( st_ivas->nCPE > 1 )
119 : {
120 289 : if ( ( error = mct_enc_reconfigure( st_ivas, 0 ) ) != IVAS_ERR_OK )
121 : {
122 0 : return error;
123 : }
124 : }
125 : }
126 : else
127 : {
128 :
129 : /* in SCE+CPE McMASA nchan_transport is still 2, fix the numbers */
130 4206 : if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA )
131 : {
132 273 : nchan_transport_old_real = nSCE_old + CPE_CHANNELS * nCPE_old;
133 : }
134 :
135 4206 : if ( hEncoderConfig->ivas_format == MC_FORMAT && st_ivas->mc_mode == MC_MODE_MCMASA )
136 : {
137 257 : nchan_transport_real = st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE;
138 : }
139 :
140 : /* something in transport changes */
141 4206 : hBstr = NULL;
142 :
143 : /* get the index list pointers */
144 4206 : if ( nSCE_old )
145 : {
146 2291 : hBstr = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr;
147 : }
148 1915 : else if ( nCPE_old )
149 : {
150 1915 : hBstr = st_ivas->hCPE[0]->hCoreCoder[0]->hBstr;
151 : }
152 : #ifdef DEBUGGING
153 : else
154 : {
155 : assert( 0 && "At least one SCE or one CPE should have existed before!\n" );
156 : }
157 : #endif
158 :
159 : /* save bitstream information */
160 4206 : nb_bits_tot = hBstr->nb_bits_tot;
161 4206 : i = 0;
162 4206 : nb_bits = 0;
163 7905 : while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
164 : {
165 3699 : if ( hBstr->ind_list[i].nb_bits > 0 )
166 : {
167 3699 : temp_ind_list[i].id = hBstr->ind_list[i].id;
168 3699 : temp_ind_list[i].value = hBstr->ind_list[i].value;
169 3699 : temp_ind_list[i].nb_bits = hBstr->ind_list[i].nb_bits;
170 3699 : hBstr->ind_list[i].nb_bits = -1;
171 : }
172 :
173 3699 : hBstr->nb_bits_tot = 0;
174 3699 : hBstr->nb_ind_tot = 0;
175 :
176 3699 : nb_bits += temp_ind_list[i].nb_bits;
177 3699 : i++;
178 : }
179 :
180 42567 : for ( ; i < MAX_NUM_IND_TEMP_LIST; i++ )
181 : {
182 : /* reset nb_bits of all other indices to -1 */
183 38361 : temp_ind_list[i].nb_bits = -1;
184 : }
185 :
186 : #ifdef DEBUGGING
187 : assert( ( nb_bits == nb_bits_tot ) && "Error saving bitstream information during core-coder reconfiguration!\n" );
188 : #endif
189 :
190 4206 : if ( hEncoderConfig->ivas_format == MC_FORMAT && last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA )
191 : {
192 : /* within McMASA we can modify the transport signals when switching */
193 : /* copy earlier dmx buffers */
194 39 : if ( nSCE_old > 0 )
195 : {
196 29 : set_zero( input_buff[0], len_inp_memory );
197 29 : mvr2r( st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, input_buff[0], len_inp_memory );
198 : }
199 :
200 117 : for ( n = 0; n < CPE_CHANNELS; n++ )
201 : {
202 78 : set_zero( input_buff[n + 1], len_inp_memory );
203 78 : if ( nCPE_old > 0 )
204 : {
205 42 : mvr2r( st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, input_buff[n + 1], len_inp_memory );
206 : }
207 : }
208 :
209 39 : ivas_mcmasa_dmx_modify( len_inp_memory, input_buff, nSCE_old + CPE_CHANNELS * nCPE_old, st_ivas->nSCE + CPE_CHANNELS * st_ivas->nCPE );
210 :
211 39 : n_CoreCoder_existing = 0;
212 : }
213 : else
214 : {
215 4167 : n_CoreCoder_existing = min( nchan_transport_real, nchan_transport_old_real );
216 : }
217 :
218 : /* destroy superfluous core-coder elements */
219 6804 : for ( sce_id = st_ivas->nSCE; sce_id < nSCE_old; sce_id++ )
220 : {
221 : /* save input audio buffers */
222 2598 : if ( n_CoreCoder_existing > sce_id )
223 : {
224 1543 : mvr2r( st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, input_buff[sce_id], len_inp_memory );
225 : }
226 :
227 2598 : destroy_sce_enc( st_ivas->hSCE[sce_id] );
228 2598 : st_ivas->hSCE[sce_id] = NULL;
229 : }
230 :
231 6338 : for ( cpe_id = st_ivas->nCPE; cpe_id < nCPE_old; cpe_id++ )
232 : {
233 : /* save input audio buffers */
234 6396 : for ( n = 0; n < CPE_CHANNELS; n++ )
235 : {
236 4264 : if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
237 : {
238 663 : mvr2r( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, input_buff[( cpe_id - st_ivas->nCPE ) * CPE_CHANNELS + n], len_inp_memory );
239 : }
240 : }
241 :
242 2132 : destroy_cpe_enc( st_ivas->hCPE[cpe_id] );
243 2132 : st_ivas->hCPE[cpe_id] = NULL;
244 : }
245 :
246 4206 : if ( st_ivas->nCPE <= 1 && st_ivas->hMCT != NULL )
247 : {
248 477 : ivas_mct_enc_close( &( st_ivas->hMCT ) );
249 : }
250 :
251 : /* special case, if we have MCT now and had a single CPE before, remove the MDCT Stereo handles */
252 4206 : if ( st_ivas->nCPE > 1 && nCPE_old == 1 )
253 : {
254 326 : free( st_ivas->hCPE[0]->hStereoMdct );
255 326 : st_ivas->hCPE[0]->hStereoMdct = NULL;
256 : }
257 :
258 : /* create missing core coder elements and set element bitrates for already existing ones */
259 4206 : if ( st_ivas->nSCE > 0 )
260 : {
261 2257 : nSCE_existing = min( nSCE_old, st_ivas->nSCE );
262 :
263 4004 : for ( sce_id = 0; sce_id < nSCE_existing; sce_id++ )
264 : {
265 1747 : copy_encoder_config( st_ivas, st_ivas->hSCE[sce_id]->hCoreCoder[0], 0 );
266 1747 : st_ivas->hSCE[sce_id]->element_brate = brate_SCE;
267 1747 : 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() */
268 :
269 1747 : ivas_destroy_MD_bstr_enc( &( st_ivas->hSCE[sce_id]->hMetaData ) );
270 : }
271 :
272 4836 : for ( sce_id = nSCE_existing; sce_id < st_ivas->nSCE; sce_id++ )
273 : {
274 2579 : if ( ( error = create_sce_enc( st_ivas, sce_id, brate_SCE ) ) != IVAS_ERR_OK )
275 : {
276 0 : return error;
277 : }
278 :
279 : /* propagate input audio buffers */
280 2579 : if ( n_CoreCoder_existing > sce_id && hEncoderConfig->ivas_format != MASA_ISM_FORMAT )
281 : {
282 663 : mvr2r( input_buff[sce_id], st_ivas->hSCE[sce_id]->hCoreCoder[0]->input_buff, len_inp_memory );
283 : }
284 :
285 : /* only reset indices if it is not the first index list, this already contains the IVAS format bits */
286 2579 : if ( sce_id > 0 || hEncoderConfig->ivas_format == MASA_ISM_FORMAT )
287 : {
288 1906 : reset_indices_enc( st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr, st_ivas->hSCE[sce_id]->hCoreCoder[0]->hBstr->nb_ind_tot );
289 : }
290 : }
291 :
292 2257 : if ( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData == NULL )
293 : {
294 576 : if ( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK )
295 : {
296 0 : return error;
297 : }
298 : }
299 : }
300 :
301 4206 : if ( st_ivas->nCPE > 0 )
302 : {
303 2929 : nCPE_existing = min( nCPE_old, st_ivas->nCPE );
304 :
305 5367 : for ( cpe_id = 0; cpe_id < nCPE_existing; cpe_id++ )
306 : {
307 2438 : st_ivas->hCPE[cpe_id]->element_brate = brate_CPE;
308 :
309 : /* allocate buffer of indices */
310 7314 : for ( n = 0; n < CPE_CHANNELS; n++ )
311 : {
312 4876 : copy_encoder_config( st_ivas, st_ivas->hCPE[cpe_id]->hCoreCoder[n], 0 );
313 4876 : 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() */
314 :
315 4876 : if ( ( cpe_id * CPE_CHANNELS + n > 0 ) ||
316 2225 : ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) ||
317 2213 : ( hEncoderConfig->ivas_format == MASA_ISM_FORMAT && st_ivas->nSCE > 0 ) )
318 : {
319 3619 : reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot );
320 : }
321 : }
322 : }
323 :
324 5171 : for ( cpe_id = nCPE_existing; cpe_id < st_ivas->nCPE; cpe_id++ )
325 : {
326 2242 : if ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->hMcMasa->separateChannelEnabled )
327 : {
328 12 : st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
329 : }
330 :
331 2242 : if ( ( error = create_cpe_enc( st_ivas, cpe_id, brate_CPE ) ) != IVAS_ERR_OK )
332 : {
333 0 : return error;
334 : }
335 :
336 : /* propagate input audio buffers */
337 6726 : for ( n = 0; n < CPE_CHANNELS; n++ )
338 : {
339 4484 : if ( n_CoreCoder_existing > cpe_id * CPE_CHANNELS + n )
340 : {
341 699 : mvr2r( input_buff[n], st_ivas->hCPE[cpe_id]->hCoreCoder[n]->input_buff, len_inp_memory );
342 : }
343 : }
344 :
345 6726 : for ( n = 0; n < CPE_CHANNELS; n++ )
346 : {
347 : /* only reset indices if it is not the first index list, this already contains the IVAS format bits */
348 4484 : if ( cpe_id * CPE_CHANNELS + n > 0 || ( st_ivas->mc_mode == MC_MODE_MCMASA && st_ivas->nSCE > 0 ) )
349 : {
350 3792 : reset_indices_enc( st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr, st_ivas->hCPE[cpe_id]->hCoreCoder[n]->hBstr->nb_ind_tot );
351 : }
352 :
353 4484 : if ( hEncoderConfig->Opt_DTX_ON )
354 : {
355 48 : st_ivas->hCPE[cpe_id]->hCoreCoder[n]->cng_sba_flag = 1;
356 : }
357 : }
358 : }
359 : }
360 :
361 : /* restore bitstream - IVAS format bits should be written in the first core channel of the first SCE/CPE */
362 4206 : i = 0;
363 4206 : nb_bits = 0;
364 4206 : if ( st_ivas->nSCE > 0 )
365 : {
366 4294 : while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
367 : {
368 2037 : if ( temp_ind_list[i].nb_bits > 0 )
369 : {
370 2037 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id;
371 2037 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value;
372 2037 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits;
373 : }
374 :
375 2037 : nb_bits += temp_ind_list[i].nb_bits;
376 2037 : i++;
377 : }
378 2257 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i;
379 2257 : st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
380 : }
381 1949 : else if ( st_ivas->nCPE > 0 )
382 : {
383 3611 : while ( nb_bits < nb_bits_tot && i < MAX_NUM_IND_TEMP_LIST )
384 : {
385 1662 : if ( temp_ind_list[i].nb_bits > 0 )
386 : {
387 1662 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].id = temp_ind_list[i].id;
388 1662 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].value = temp_ind_list[i].value;
389 1662 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list[i].nb_bits = temp_ind_list[i].nb_bits;
390 : }
391 :
392 1662 : nb_bits += temp_ind_list[i].nb_bits;
393 1662 : i++;
394 : }
395 1949 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_ind_tot = i;
396 1949 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->nb_bits_tot = nb_bits_tot;
397 : }
398 :
399 : #ifdef DEBUGGING
400 : assert( ( nb_bits == nb_bits_tot ) && "Error restoring bitstream information during core-coder reconfiguration!\n" );
401 : #endif
402 :
403 :
404 4206 : if ( last_mc_mode == MC_MODE_MCMASA && st_ivas->mc_mode == MC_MODE_MCMASA )
405 : {
406 : /* restore modified transport signal */
407 39 : if ( st_ivas->nSCE )
408 : {
409 29 : mvr2r( input_buff[0], st_ivas->hSCE[0]->hCoreCoder[0]->input_buff, len_inp_memory );
410 : }
411 :
412 39 : if ( st_ivas->nCPE )
413 : {
414 75 : for ( n = 0; n < CPE_CHANNELS; n++ )
415 : {
416 50 : mvr2r( input_buff[n + 1], st_ivas->hCPE[0]->hCoreCoder[n]->input_buff, len_inp_memory );
417 : }
418 : }
419 : }
420 :
421 4206 : if ( st_ivas->nCPE > 1 && nCPE_old <= 1 )
422 : {
423 804 : if ( nCPE_old == 1 )
424 : {
425 : /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handles for MCT */
426 978 : for ( n = 0; n < CPE_CHANNELS; n++ )
427 : {
428 652 : st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
429 652 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
430 1304 : st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
431 652 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
432 652 : st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
433 652 : st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
434 :
435 652 : 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 )
436 : {
437 0 : return error;
438 : }
439 : }
440 : }
441 :
442 804 : if ( ( error = create_mct_enc( st_ivas ) ) != IVAS_ERR_OK )
443 : {
444 0 : return error;
445 : }
446 : }
447 3402 : else if ( st_ivas->hMCT != NULL && st_ivas->nCPE > 1 )
448 : {
449 157 : if ( ( error = mct_enc_reconfigure( st_ivas, nchan_transport_old_real != nchan_transport_real ) ) != IVAS_ERR_OK )
450 : {
451 0 : return error;
452 : }
453 : }
454 :
455 : /* alllocate buffer for metadata indices */
456 4206 : if ( st_ivas->nCPE > 0 )
457 : {
458 2929 : if ( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData == NULL )
459 : {
460 369 : if ( ( error = ivas_initialize_MD_bstr_enc( &( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData ), st_ivas ) ) != IVAS_ERR_OK )
461 : {
462 0 : return error;
463 : }
464 : }
465 :
466 2929 : reset_indices_enc( st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData, st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData->nb_ind_tot );
467 :
468 4680 : for ( cpe_id = 0; cpe_id < st_ivas->nCPE - 1; cpe_id++ )
469 : {
470 1751 : ivas_destroy_MD_bstr_enc( &( st_ivas->hCPE[cpe_id]->hMetaData ) );
471 : }
472 : }
473 :
474 : /* special case, if we have a single CPE and had MCT before we need to init the MDCT stereo handles here */
475 4206 : if ( st_ivas->nCPE == 1 && nCPE_old > 1 )
476 : {
477 335 : if ( ( st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct = (STEREO_MDCT_ENC_DATA_HANDLE) malloc( sizeof( STEREO_MDCT_ENC_DATA ) ) ) == NULL )
478 : {
479 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for MDCT Stereo \n" ) );
480 : }
481 :
482 : /* set correct nominal bitrates and igf config already here, needed for the correct init of the MDCT Stereo handle */
483 1005 : for ( n = 0; n < CPE_CHANNELS; n++ )
484 : {
485 670 : st_ivas->hCPE[0]->hCoreCoder[n]->total_brate = st_ivas->hCPE[0]->element_brate;
486 670 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal = (int16_t) ( st_ivas->hCPE[0]->element_brate / FRAMES_PER_SEC );
487 1340 : st_ivas->hCPE[0]->hCoreCoder[n]->igf = getIgfPresent( st_ivas->hCPE[0]->hCoreCoder[n]->element_mode,
488 670 : st_ivas->hCPE[0]->hCoreCoder[n]->bits_frame_nominal * FRAMES_PER_SEC,
489 670 : st_ivas->hCPE[0]->hCoreCoder[n]->bwidth,
490 670 : st_ivas->hCPE[0]->hCoreCoder[n]->rf_mode );
491 :
492 670 : 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 )
493 : {
494 0 : return error;
495 : }
496 :
497 : /* reset mct_chan_mode */
498 670 : st_ivas->hCPE[0]->hCoreCoder[n]->mct_chan_mode = MCT_CHAN_MODE_REGULAR;
499 : }
500 :
501 : #ifdef DEBUGGING
502 : st_ivas->hCPE[st_ivas->nCPE - 1]->hStereoMdct->mdct_stereo_mode_cmdl = hEncoderConfig->stereo_mode_cmdl;
503 : #endif
504 335 : 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 );
505 335 : 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 ) );
506 : }
507 : }
508 :
509 5332 : return error;
510 : }
|