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 "cnst.h"
36 : #include "ivas_cnst.h"
37 : #include "rom_com.h"
38 : #include "prot.h"
39 : #include "ivas_prot.h"
40 : #include "ivas_rom_com.h"
41 : #ifdef DEBUGGING
42 : #include "debug.h"
43 : #endif
44 : #include "wmc_auto.h"
45 :
46 : /*-------------------------------------------------------------------*
47 : * ivas_enc()
48 : *
49 : * Principal IVAS encoder routine
50 : *-------------------------------------------------------------------*/
51 :
52 424288 : ivas_error ivas_enc(
53 : Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */
54 : const int16_t *data, /* i : input signal */
55 : const int16_t n_samples /* i : number of input samples */
56 : )
57 : {
58 : int16_t i, n, input_frame, n_samples_chan, nchan_inp;
59 : int32_t input_Fs;
60 : IVAS_FORMAT ivas_format;
61 : ENCODER_CONFIG_HANDLE hEncoderConfig;
62 : BSTR_ENC_HANDLE hMetaData;
63 : int16_t nb_bits_metadata[MAX_SCE + 1];
64 : float *data_f[MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS];
65 : int32_t ivas_total_brate;
66 : ivas_error error;
67 424288 : error = IVAS_ERR_OK;
68 :
69 424288 : push_wmops( "ivas_enc" );
70 :
71 : /*------------------------------------------------------------------*
72 : * Initialization - general
73 : *-----------------------------------------------------------------*/
74 :
75 424288 : hEncoderConfig = st_ivas->hEncoderConfig;
76 :
77 424288 : input_Fs = hEncoderConfig->input_Fs;
78 424288 : ivas_format = hEncoderConfig->ivas_format;
79 424288 : nchan_inp = hEncoderConfig->nchan_inp;
80 424288 : ivas_total_brate = hEncoderConfig->ivas_total_brate;
81 :
82 424288 : input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC );
83 424288 : n_samples_chan = n_samples / nchan_inp;
84 :
85 424288 : set_s( nb_bits_metadata, 0, MAX_SCE + 1 );
86 :
87 : /*----------------------------------------------------------------*
88 : * convert 'short' input data to 'float'
89 : *----------------------------------------------------------------*/
90 :
91 8910048 : for ( n = 0; n < MAX_INPUT_CHANNELS + MAX_NUM_OBJECTS; n++ )
92 : {
93 8485760 : data_f[n] = st_ivas->p_data_f[n];
94 : }
95 :
96 424288 : n = 0;
97 2961898 : while ( n < nchan_inp )
98 : {
99 : #ifdef DEBUG_MODE_LFE
100 : if ( n == LFE_CHANNEL )
101 : {
102 : int16_t tmp[L_FRAME48k];
103 : for ( i = 0; i < n_samples_chan; i++ )
104 : {
105 : tmp[i] = data[i * nchan_inp + n];
106 : }
107 : dbgwrite( tmp, sizeof( int16_t ), n_samples_chan, 1, "./lfe_chan_in.raw" );
108 : }
109 : #endif
110 2082362250 : for ( i = 0; i < n_samples_chan; i++ )
111 : {
112 2079824640 : data_f[n][i] = (float) data[i * nchan_inp + n];
113 : }
114 2537610 : n++;
115 : }
116 :
117 424288 : if ( n_samples_chan < input_frame )
118 : {
119 0 : for ( n = 0; n < nchan_inp; n++ )
120 : {
121 0 : set_f( data_f[n] + n_samples_chan, 0.0f, input_frame - n_samples_chan );
122 : }
123 : }
124 :
125 : #ifdef DEBUG_MODE_LFE
126 : dbgwrite( data_f[LFE_CHANNEL], sizeof( float ), n_samples_chan, 1, "./res/lfe_input" );
127 : #endif
128 :
129 424288 : if ( ivas_format == SBA_FORMAT )
130 : {
131 122500 : if ( ( error = ivas_sba_enc_reconfigure( st_ivas ) ) != IVAS_ERR_OK )
132 : {
133 0 : return error;
134 : }
135 : }
136 301788 : else if ( ivas_format == SBA_ISM_FORMAT )
137 : {
138 37000 : if ( ( error = ivas_osba_enc_reconfig( st_ivas ) ) != IVAS_ERR_OK )
139 : {
140 0 : return error;
141 : }
142 : }
143 :
144 : /*----------------------------------------------------------------*
145 : * HP filtering
146 : *----------------------------------------------------------------*/
147 :
148 424288 : n = getNumChanAnalysis( st_ivas );
149 :
150 : #ifndef DEBUG_SPAR_BYPASS_EVS_CODEC
151 : /* bypass EVS coding in float precision, emulating EVS encoder/decoder delay */
152 2240898 : for ( i = 0; i < n; i++ )
153 : {
154 1816610 : if ( ( ivas_format == SBA_FORMAT ) && !( st_ivas->sba_analysis_order > 1 ) )
155 : {
156 443080 : hp20( data_f[HOA_keep_ind[st_ivas->hSpar->hMdEnc->HOA_md_ind[i]]], input_frame, st_ivas->mem_hp20_in[i], input_Fs );
157 : }
158 1373530 : else if ( !( ivas_format == MC_FORMAT && i == LFE_CHANNEL ) )
159 : {
160 1324680 : hp20( data_f[i], input_frame, st_ivas->mem_hp20_in[i], input_Fs );
161 : }
162 : }
163 : #endif
164 :
165 : /*----------------------------------------------------------------*
166 : * write IVAS format signaling
167 : *----------------------------------------------------------------*/
168 :
169 424288 : ivas_write_format( st_ivas );
170 :
171 : /*----------------------------------------------------------------*
172 : * Encoding
173 : *----------------------------------------------------------------*/
174 :
175 424288 : if ( ivas_format == STEREO_FORMAT )
176 : {
177 72486 : st_ivas->hCPE[0]->element_brate = ivas_total_brate;
178 72486 : if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, 0 /* no metadata */ ) ) != IVAS_ERR_OK )
179 : {
180 0 : return error;
181 : }
182 : }
183 351802 : else if ( ivas_format == ISM_FORMAT )
184 : {
185 : /* select ISM format mode; reconfigure the ISM format encoder */
186 103826 : if ( ( error = ivas_ism_enc_config( st_ivas ) ) != IVAS_ERR_OK )
187 : {
188 0 : return error;
189 : }
190 :
191 103826 : if ( st_ivas->ism_mode == ISM_MODE_PARAM )
192 : {
193 20720 : ivas_param_ism_enc( st_ivas, data_f, input_frame );
194 :
195 : /* Stereo DMX generation */
196 20720 : ivas_param_ism_stereo_dmx( st_ivas, data_f, input_frame );
197 :
198 : /* Core coding of Stereo DMX */
199 20720 : if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK )
200 : {
201 0 : return error;
202 : }
203 : }
204 83106 : else if ( st_ivas->ism_mode == ISM_MODE_DISC )
205 : {
206 : /* Analysis, decision about bitrates per channel & core coding */
207 83106 : if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, nb_bits_metadata, 0 ) ) != IVAS_ERR_OK )
208 : {
209 0 : return error;
210 : }
211 : }
212 : }
213 247976 : else if ( ivas_format == SBA_FORMAT || ivas_format == MASA_FORMAT )
214 : {
215 : /* MASA configuration */
216 153126 : if ( ivas_format == MASA_FORMAT )
217 : {
218 30626 : ivas_masa_enc_reconfigure( st_ivas );
219 : }
220 :
221 : /* SBA/MASA metadata encoding and SBA/MASA metadata bitstream writing */
222 153126 : hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
223 :
224 153126 : if ( st_ivas->hQMetaData != NULL && ivas_format == MASA_FORMAT )
225 : {
226 30626 : ivas_masa_estimate_energy( st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport ); /* energy-estimation uses TF-resolution: 4x24 */
227 :
228 30626 : if ( ( error = ivas_masa_enc_config( st_ivas ) ) != IVAS_ERR_OK )
229 : {
230 0 : return error;
231 : }
232 :
233 30626 : if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1,
234 : ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK )
235 : {
236 0 : return error;
237 : }
238 : }
239 122500 : else if ( ivas_format == SBA_FORMAT )
240 : {
241 122500 : if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK )
242 : {
243 0 : return error;
244 : }
245 : }
246 :
247 153126 : if ( ivas_format == SBA_FORMAT )
248 : {
249 122500 : ivas_sba_getTCs( data_f, st_ivas, input_frame );
250 : }
251 :
252 : /* core-coding of transport channels */
253 153126 : if ( st_ivas->nSCE == 1 )
254 : {
255 51371 : if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
256 : {
257 0 : return error;
258 : }
259 : }
260 101755 : else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */
261 : {
262 51516 : if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
263 : {
264 0 : return error;
265 : }
266 : }
267 50239 : else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */
268 : {
269 50239 : if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
270 : {
271 0 : return error;
272 : }
273 : }
274 : }
275 94850 : else if ( ivas_format == MASA_ISM_FORMAT )
276 : {
277 : float *data_separated_object;
278 : int16_t idx_separated_object;
279 : int16_t flag_omasa_ener_brate;
280 :
281 9000 : flag_omasa_ener_brate = 0;
282 :
283 : /* Stereo transport is used also with monoMASA, duplicate mono if monoMASA */
284 9000 : if ( ( st_ivas->hEncoderConfig->nchan_inp - hEncoderConfig->nchan_ism ) == 1 )
285 : {
286 2700 : v_multc( data_f[hEncoderConfig->nchan_ism], 1.0f / SQRT2, data_f[hEncoderConfig->nchan_ism], input_frame );
287 2700 : mvr2r( data_f[hEncoderConfig->nchan_ism], data_f[hEncoderConfig->nchan_ism + 1], input_frame );
288 : }
289 :
290 : /* Estimate TF-tile energy for the input MASA stream */
291 9000 : ivas_masa_estimate_energy( st_ivas->hMasa, &( data_f[hEncoderConfig->nchan_ism] ), input_frame, st_ivas->nchan_transport );
292 :
293 9000 : if ( ( error = ivas_omasa_enc_config( st_ivas ) ) != IVAS_ERR_OK )
294 : {
295 0 : return error;
296 : }
297 :
298 9000 : set_s( nb_bits_metadata, 0, MAX_SCE + 1 );
299 9000 : idx_separated_object = 0;
300 :
301 9000 : data_separated_object = data_f[hEncoderConfig->nchan_ism + CPE_CHANNELS];
302 :
303 : /* put audio object data in SCE's */
304 9000 : if ( st_ivas->ism_mode != ISM_MASA_MODE_DISC )
305 : {
306 : /* Estimate MASA parameters for the objects */
307 5858 : ivas_omasa_enc( st_ivas->hOMasa, st_ivas->hMasa, st_ivas->hIsmMetaData, data_f, input_frame, st_ivas->nchan_transport, hEncoderConfig->nchan_ism, st_ivas->ism_mode, data_separated_object, &idx_separated_object );
308 : }
309 :
310 : /* Encode ISMs transport channels */
311 9000 : n = 0;
312 9000 : if ( st_ivas->ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ )
313 : {
314 1862 : if ( ( error = ivas_sce_enc( st_ivas, 0, data_separated_object, input_frame, nb_bits_metadata[1] ) ) != IVAS_ERR_OK ) /* there are no metadata bits in SCE in this mode */
315 : {
316 0 : return error;
317 : }
318 : }
319 7138 : else if ( st_ivas->ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ )
320 : {
321 2054 : if ( ( error = ivas_ism_enc( st_ivas, &data_separated_object, input_frame, &nb_bits_metadata[1], 0 ) ) != IVAS_ERR_OK )
322 : {
323 0 : return error;
324 : }
325 : }
326 5084 : else if ( st_ivas->ism_mode == ISM_MASA_MODE_DISC )
327 : {
328 3142 : flag_omasa_ener_brate = ivas_omasa_ener_brate( st_ivas->hEncoderConfig->nchan_ism, ivas_total_brate, data_f, input_frame );
329 :
330 : /* Analysis, decision about bitrates per channel & core coding */
331 3142 : if ( ( error = ivas_ism_enc( st_ivas, data_f, input_frame, &nb_bits_metadata[1], flag_omasa_ener_brate ) ) != IVAS_ERR_OK )
332 : {
333 0 : return error;
334 : }
335 3142 : n = st_ivas->hEncoderConfig->nchan_ism;
336 : }
337 :
338 9000 : hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
339 :
340 9000 : if ( st_ivas->nSCE > 0 )
341 : {
342 : /* update pointer to the buffer of indices (ISM indices were alredy written) */
343 7058 : hMetaData->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData->nb_ind_tot;
344 7058 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[st_ivas->nSCE - 1]->hCoreCoder[0]->hBstr->nb_ind_tot;
345 : }
346 :
347 : /* Encode MASA parameters and write MASA metadata bitstream */
348 9000 : if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, nb_bits_metadata, st_ivas->nchan_transport, ivas_format, ivas_total_brate, st_ivas->hEncoderConfig->Opt_DTX_ON, st_ivas->nchan_transport == 2 ? st_ivas->hCPE[0]->element_mode : -1,
349 9000 : st_ivas->ism_mode, hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, idx_separated_object, st_ivas->hOMasa, st_ivas->hIsmMetaData[0]->ism_imp, flag_omasa_ener_brate ) ) != IVAS_ERR_OK )
350 : {
351 0 : return error;
352 : }
353 :
354 : /* Configuration of combined-format bit-budget distribution */
355 : #ifdef DEBUG_MODE_INFO
356 : ivas_set_surplus_brate_enc( st_ivas, nb_bits_metadata );
357 : #else
358 9000 : ivas_set_surplus_brate_enc( st_ivas );
359 : #endif
360 :
361 : /* Encode MASA transport channels */
362 9000 : if ( ( ivas_cpe_enc( st_ivas, 0, data_f[n], data_f[n + 1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
363 : {
364 0 : return error;
365 : }
366 : }
367 85850 : else if ( ivas_format == SBA_ISM_FORMAT )
368 : {
369 : int16_t planar_sba_orig;
370 37000 : planar_sba_orig = hEncoderConfig->sba_planar;
371 :
372 : /* Analyze objects and determine needed audio signals */
373 37000 : ivas_osba_enc( st_ivas->hOSba, st_ivas->hIsmMetaData, data_f, input_frame, hEncoderConfig->nchan_ism, st_ivas->ism_mode, st_ivas->sba_analysis_order, hEncoderConfig->input_Fs, hEncoderConfig->sba_planar );
374 :
375 37000 : if ( st_ivas->ism_mode == ISM_MODE_NONE )
376 : {
377 : /*once SBA and ISM are combined into SBA signal then disable planar flag*/
378 14920 : hEncoderConfig->sba_planar = 0;
379 14920 : if ( st_ivas->nchan_transport == 1 )
380 : {
381 6970 : hMetaData = st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData;
382 : }
383 : else
384 : {
385 7950 : hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
386 : }
387 :
388 : /* SBA metadata encoding and SBA metadata bitstream writing */
389 14920 : if ( ( error = ivas_spar_enc( st_ivas, data_f, input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK )
390 : {
391 0 : return error;
392 : }
393 :
394 14920 : hEncoderConfig->sba_planar = planar_sba_orig;
395 : }
396 : else
397 : {
398 22080 : n = hEncoderConfig->nchan_ism;
399 22080 : hMetaData = st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
400 :
401 22080 : if ( ( error = ivas_ism_metadata_enc( &st_ivas->hEncoderConfig->ivas_total_brate, n, st_ivas->hEncoderConfig->nchan_ism, st_ivas->hIsmMetaData, NULL, hMetaData, &nb_bits_metadata[1], 0, st_ivas->ism_mode, NULL, st_ivas->hEncoderConfig->ism_extended_metadata_flag, -1, 0, NULL, st_ivas->hCPE[0]->hCoreCoder[0]->ini_frame ) ) != IVAS_ERR_OK )
402 : {
403 0 : return error;
404 : }
405 :
406 : /* SBA metadata encoding and SBA metadata bitstream writing */
407 22080 : if ( ( error = ivas_spar_enc( st_ivas, &data_f[n], input_frame, nb_bits_metadata, hMetaData ) ) != IVAS_ERR_OK )
408 : {
409 0 : return error;
410 : }
411 :
412 : /* get SBA TCs */
413 22080 : ivas_sba_getTCs( &data_f[n], st_ivas, input_frame );
414 : }
415 :
416 : /* core-coding of transport channels */
417 37000 : if ( st_ivas->nSCE == 1 )
418 : {
419 6970 : if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
420 : {
421 0 : return error;
422 : }
423 : }
424 30030 : else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */
425 : {
426 6360 : if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
427 : {
428 0 : return error;
429 : }
430 : }
431 23670 : else if ( st_ivas->nCPE > 1 ) /* FOA/HOA format */
432 : {
433 23670 : if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, nb_bits_metadata[0] ) ) != IVAS_ERR_OK )
434 : {
435 0 : return error;
436 : }
437 : }
438 : }
439 48850 : else if ( ivas_format == MC_FORMAT )
440 : {
441 : /* select MC format mode; write MC LS setup; reconfigure the MC format encoder */
442 48850 : if ( ( error = ivas_mc_enc_config( st_ivas ) ) != IVAS_ERR_OK )
443 : {
444 0 : return error;
445 : }
446 :
447 48850 : hMetaData = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[st_ivas->nSCE - 1]->hMetaData : st_ivas->hCPE[st_ivas->nCPE - 1]->hMetaData;
448 :
449 : /* LFE low pass filter */
450 48850 : ivas_lfe_lpf_enc_apply( st_ivas->hLfeLpf, data_f[LFE_CHANNEL], input_frame );
451 :
452 : /* LFE channel encoder */
453 48850 : if ( st_ivas->mc_mode == MC_MODE_MCT )
454 : {
455 26130 : st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr;
456 :
457 26130 : ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr );
458 : }
459 :
460 48850 : if ( st_ivas->mc_mode == MC_MODE_MCT )
461 : {
462 26130 : if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, 0 ) ) != IVAS_ERR_OK )
463 : {
464 0 : return error;
465 : }
466 : }
467 22720 : else if ( st_ivas->mc_mode == MC_MODE_PARAMUPMIX )
468 : {
469 : /* encode MC ParamUpmix parameters and write bitstream */
470 790 : ivas_mc_paramupmix_enc( st_ivas, hMetaData, data_f, input_frame );
471 :
472 790 : st_ivas->hLFE->hBstr = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0]->hBstr : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr;
473 790 : ivas_lfe_enc( st_ivas->hLFE, data_f[LFE_CHANNEL], input_frame, st_ivas->hLFE->hBstr );
474 :
475 790 : if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK )
476 : {
477 0 : return error;
478 : }
479 : }
480 21930 : else if ( st_ivas->mc_mode == MC_MODE_PARAMMC )
481 : {
482 : /* encode Parametric MC parameters and write bitstream */
483 10250 : ivas_param_mc_enc( st_ivas, hMetaData, data_f, input_frame );
484 :
485 10250 : if ( st_ivas->nCPE == 1 ) /* Stereo DMX */
486 : {
487 10140 : if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK )
488 : {
489 0 : return error;
490 : }
491 : }
492 110 : else if ( st_ivas->nCPE > 1 )
493 : {
494 110 : if ( ( error = ivas_mct_enc( st_ivas, data_f, input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK )
495 : {
496 0 : return error;
497 : }
498 : }
499 : }
500 11680 : else if ( st_ivas->mc_mode == MC_MODE_MCMASA )
501 : {
502 11680 : if ( st_ivas->hMcMasa->separateChannelEnabled )
503 : {
504 625 : hMetaData = st_ivas->hCPE[0]->hMetaData; /* Metadata is always with CPE in the case of separated channel */
505 : }
506 :
507 11680 : ivas_mcmasa_enc( st_ivas->hMcMasa, st_ivas->hQMetaData, st_ivas->hMasa, data_f, input_frame, st_ivas->nchan_transport, nchan_inp );
508 :
509 11680 : if ( ( error = ivas_masa_encode( st_ivas->hMasa, st_ivas->hQMetaData, hMetaData, &nb_bits_metadata[0], st_ivas->nchan_transport, ivas_format, ivas_total_brate, 0, -1,
510 : ISM_MODE_NONE, -1, NULL, -1, NULL, 0, 0 ) ) != IVAS_ERR_OK )
511 : {
512 0 : return error;
513 : }
514 :
515 11680 : if ( st_ivas->hMcMasa->separateChannelEnabled )
516 : {
517 625 : if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[2], input_frame, 0 ) ) != IVAS_ERR_OK )
518 : {
519 0 : return error;
520 : }
521 :
522 625 : st_ivas->hCPE[0]->hCoreCoder[0]->hBstr->ind_list = st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->ind_list + st_ivas->hSCE[0]->hCoreCoder[0]->hBstr->nb_ind_tot;
523 :
524 625 : if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK )
525 : {
526 0 : return error;
527 : }
528 : }
529 : else
530 : {
531 11055 : if ( st_ivas->nSCE == 1 )
532 : {
533 10635 : if ( ( error = ivas_sce_enc( st_ivas, 0, data_f[0], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK )
534 : {
535 0 : return error;
536 : }
537 : }
538 420 : else if ( st_ivas->nCPE == 1 ) /* Stereo DMX */
539 : {
540 420 : if ( ( error = ivas_cpe_enc( st_ivas, 0, data_f[0], data_f[1], input_frame, hMetaData->nb_bits_tot ) ) != IVAS_ERR_OK )
541 : {
542 0 : return error;
543 : }
544 : }
545 : }
546 : }
547 : }
548 :
549 : /*----------------------------------------------------------------*
550 : * Common updates
551 : *----------------------------------------------------------------*/
552 :
553 424288 : hEncoderConfig->last_ivas_total_brate = ivas_total_brate;
554 :
555 : #ifdef DEBUG_MODE_INFO
556 : {
557 : float tmpF = ivas_total_brate / 1000.0f;
558 : dbgwrite( &tmpF, sizeof( float ), 1, input_frame, "res/ivas_total_brate" );
559 : }
560 : #endif
561 :
562 424288 : pop_wmops();
563 424288 : return error;
564 : }
|