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 <math.h>
34 : #include <assert.h>
35 : #include <stdio.h>
36 : #include <string.h>
37 : #include "options.h"
38 : #ifdef DEBUGGING
39 : #include "debug.h"
40 : #endif
41 : #include "lib_enc.h"
42 : #include "ivas_prot_fx.h"
43 : #include "prot_fx.h"
44 : #include "prot_fx_enc.h"
45 : #include "wmc_auto.h"
46 : #include "ivas_rom_enc.h"
47 :
48 : /*---------------------------------------------------------------------*
49 : * Local struct
50 : *---------------------------------------------------------------------*/
51 :
52 : struct IVAS_ENC
53 : {
54 : Encoder_Struct *st_ivas;
55 : ENC_CORE_HANDLE hCoreCoder;
56 : bool isConfigured;
57 : #ifdef DEBUGGING
58 : bool cmd_stereo;
59 : #endif
60 : bool switchingActive; /* flag for configuration changes during encoding - currently only used with mono */
61 : Word16 Opt_RF_ON_loc;
62 : Word16 rf_fec_offset_loc;
63 : bool ismMetadataProvided[MAX_NUM_OBJECTS];
64 : bool maxBandwidthUser; /* Was a specific max bandwith selected by the user? */
65 : IVAS_ENC_BANDWIDTH newBandwidthApi; /* maximum encoded bandwidth, as set on API level */
66 : bool extMetadataApi; /* External metadata requested, to be checked against current bit rate */
67 : };
68 :
69 : /*---------------------------------------------------------------------*
70 : * Local functions
71 : *---------------------------------------------------------------------*/
72 :
73 : // static ivas_error configureEncoder_fx( IVAS_ENC_HANDLE hIvasEnc, const Word32 inputFs, const Word32 initBitrate, const IVAS_ENC_BANDWIDTH initBandwidth, const IVAS_ENC_DTX_CONFIG dtxConfig, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig );
74 : static ivas_error setBandwidth_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_BANDWIDTH maxBandwidth );
75 : static ivas_error setChannelAwareConfig_fx( IVAS_ENC_HANDLE hIvasEnc, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig );
76 : static ivas_error sanitizeBandwidth_fx( const IVAS_ENC_HANDLE hIvasEnc );
77 : static ivas_error sanitizeBitrateISM_fx( const ENCODER_CONFIG_HANDLE hEncoderConfig, const bool extMetadataApi );
78 : static Word16 getInputBufferSize_fx( const Encoder_Struct *st_ivas );
79 : static ivas_error configureEncoder( IVAS_ENC_HANDLE hIvasEnc, const Word32 inputFs, const Word32 initBitrate, const IVAS_ENC_BANDWIDTH initBandwidth, const IVAS_ENC_DTX_CONFIG dtxConfig, const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig );
80 : static ivas_error setBitrate( IVAS_ENC_HANDLE hIvasEnc, const Word32 totalBitrate );
81 : static ivas_error doCommonConfigureChecks( IVAS_ENC_HANDLE hIvasEnc );
82 : static ivas_error doCommonSetterChecks( IVAS_ENC_HANDLE hIvasEnc );
83 : static void init_encoder_config( ENCODER_CONFIG_HANDLE hEncoderConfig );
84 : static void resetIsmMetadataProvidedFlags( IVAS_ENC_HANDLE hIvasEnc );
85 : static ivas_error bandwidthApiToInternal( const IVAS_ENC_BANDWIDTH maxBandwidth, Word16 *internalMaxBandwidth );
86 : static ivas_error fecIndicatorApiToInternal( const IVAS_ENC_FEC_INDICATOR fecIndicator, Word16 *fecIndicatorInternal );
87 : #ifdef DEBUGGING
88 : static ivas_error forcedModeApiToInternal( IVAS_ENC_FORCED_MODE forcedMode, int16_t *forcedModeInternal );
89 : #endif
90 :
91 :
92 : /*---------------------------------------------------------------------*
93 : * IVAS_ENC_Open()
94 : *
95 : * Open IVAS encoder
96 : *---------------------------------------------------------------------*/
97 :
98 0 : ivas_error IVAS_ENC_Open(
99 : IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to an encoder handle to be opened */
100 : )
101 : {
102 : Encoder_Struct *st_ivas;
103 :
104 0 : if ( phIvasEnc == NULL )
105 : {
106 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
107 : }
108 :
109 : /*-----------------------------------------------------------------*
110 : * Allocate and initialize IVAS application encoder handle
111 : *-----------------------------------------------------------------*/
112 :
113 0 : if ( ( *phIvasEnc = (IVAS_ENC_HANDLE) malloc( sizeof( struct IVAS_ENC ) ) ) == NULL )
114 : {
115 0 : return IVAS_ERR_FAILED_ALLOC;
116 : }
117 :
118 0 : ( *phIvasEnc )->hCoreCoder = NULL;
119 0 : ( *phIvasEnc )->isConfigured = false;
120 : #ifdef DEBUGGING
121 : ( *phIvasEnc )->cmd_stereo = false;
122 : #endif
123 0 : ( *phIvasEnc )->switchingActive = false;
124 0 : ( *phIvasEnc )->maxBandwidthUser = false;
125 0 : resetIsmMetadataProvidedFlags( *phIvasEnc );
126 :
127 : /*-----------------------------------------------------------------*
128 : * Allocate IVAS-codec encoder state
129 : *-----------------------------------------------------------------*/
130 :
131 0 : if ( ( ( *phIvasEnc )->st_ivas = (Encoder_Struct *) malloc( sizeof( Encoder_Struct ) ) ) == NULL )
132 : {
133 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS encoder structure" );
134 : }
135 :
136 0 : if ( ( ( *phIvasEnc )->st_ivas->hEncoderConfig = (ENCODER_CONFIG_HANDLE) malloc( sizeof( ENCODER_CONFIG ) ) ) == NULL )
137 : {
138 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Encoder config structure" );
139 : }
140 :
141 : /*-----------------------------------------------------------------*
142 : * Initialize IVAS-codec encoder state
143 : *-----------------------------------------------------------------*/
144 :
145 0 : st_ivas = ( *phIvasEnc )->st_ivas;
146 :
147 : /* initialize encoder Config. handle */
148 0 : init_encoder_config( st_ivas->hEncoderConfig );
149 :
150 : /* initialize pointers to handles to NULL */
151 0 : ivas_initialize_handles_enc_fx( st_ivas );
152 :
153 0 : st_ivas->ind_list = NULL;
154 0 : st_ivas->ind_list_metadata = NULL;
155 :
156 : /* set high-level parameters */
157 0 : st_ivas->mc_mode = MC_MODE_NONE;
158 0 : st_ivas->ism_mode = ISM_MODE_NONE;
159 0 : st_ivas->sba_analysis_order = 0;
160 0 : move16();
161 :
162 0 : return IVAS_ERR_OK;
163 : }
164 :
165 627 : ivas_error IVAS_ENC_Open_fx(
166 : IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to an encoder handle to be opened */
167 : )
168 : {
169 : Encoder_Struct *st_ivas;
170 :
171 627 : IF( phIvasEnc == NULL )
172 : {
173 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
174 : }
175 :
176 : /*-----------------------------------------------------------------*
177 : * Allocate and initialize IVAS application encoder handle
178 : *-----------------------------------------------------------------*/
179 :
180 627 : IF( ( *phIvasEnc = (IVAS_ENC_HANDLE) malloc( sizeof( struct IVAS_ENC ) ) ) == NULL )
181 : {
182 0 : return IVAS_ERR_FAILED_ALLOC;
183 : }
184 :
185 627 : ( *phIvasEnc )->hCoreCoder = NULL;
186 627 : ( *phIvasEnc )->isConfigured = false;
187 : #ifdef DEBUGGING
188 : ( *phIvasEnc )->cmd_stereo = false;
189 : #endif
190 627 : ( *phIvasEnc )->switchingActive = false;
191 627 : ( *phIvasEnc )->maxBandwidthUser = false;
192 627 : resetIsmMetadataProvidedFlags( *phIvasEnc );
193 :
194 : /*-----------------------------------------------------------------*
195 : * Allocate IVAS-codec encoder state
196 : *-----------------------------------------------------------------*/
197 :
198 627 : IF( ( ( *phIvasEnc )->st_ivas = (Encoder_Struct *) malloc( sizeof( Encoder_Struct ) ) ) == NULL )
199 : {
200 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS encoder structure" );
201 : }
202 :
203 627 : IF( ( ( *phIvasEnc )->st_ivas->hEncoderConfig = (ENCODER_CONFIG_HANDLE) malloc( sizeof( ENCODER_CONFIG ) ) ) == NULL )
204 : {
205 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Encoder config structure" );
206 : }
207 :
208 : /*-----------------------------------------------------------------*
209 : * Initialize IVAS-codec encoder state
210 : *-----------------------------------------------------------------*/
211 :
212 627 : st_ivas = ( *phIvasEnc )->st_ivas;
213 :
214 : /* initialize encoder Config. handle */
215 627 : init_encoder_config( st_ivas->hEncoderConfig );
216 :
217 : /* initialize pointers to handles to NULL */
218 627 : ivas_initialize_handles_enc_fx( st_ivas );
219 :
220 627 : st_ivas->ind_list = NULL;
221 627 : st_ivas->ind_list_metadata = NULL;
222 :
223 : /* set high-level parameters */
224 627 : st_ivas->mc_mode = MC_MODE_NONE;
225 627 : st_ivas->ism_mode = ISM_MODE_NONE;
226 627 : st_ivas->sba_analysis_order = 0;
227 627 : move16();
228 :
229 627 : return IVAS_ERR_OK;
230 : }
231 : /*---------------------------------------------------------------------*
232 : * IVAS_ENC_Close()
233 : *
234 : *
235 : *---------------------------------------------------------------------*/
236 :
237 627 : void IVAS_ENC_Close(
238 : IVAS_ENC_HANDLE *phIvasEnc /* i/o: pointer to IVAS encoder handle */
239 : )
240 : {
241 : /* Free all memory */
242 627 : test();
243 627 : IF( phIvasEnc == NULL || *phIvasEnc == NULL )
244 : {
245 0 : return;
246 : }
247 :
248 627 : IF( ( *phIvasEnc )->isConfigured )
249 : {
250 627 : ivas_destroy_enc_fx( ( *phIvasEnc )->st_ivas );
251 : }
252 : ELSE
253 : {
254 0 : IF( ( *phIvasEnc )->st_ivas->hEncoderConfig )
255 : {
256 0 : free( ( *phIvasEnc )->st_ivas->hEncoderConfig );
257 0 : ( *phIvasEnc )->st_ivas->hEncoderConfig = NULL;
258 : }
259 0 : free( ( *phIvasEnc )->st_ivas );
260 : }
261 :
262 627 : ( *phIvasEnc )->st_ivas = NULL;
263 :
264 627 : free( *phIvasEnc );
265 :
266 627 : *phIvasEnc = NULL;
267 627 : phIvasEnc = NULL;
268 :
269 627 : return;
270 : }
271 :
272 :
273 : /*---------------------------------------------------------------------*
274 : * IVAS_ENC_ConfigureForMono()
275 : *
276 : * Configure and initialize the mono encoder.
277 : *---------------------------------------------------------------------*/
278 :
279 3 : ivas_error IVAS_ENC_ConfigureForMono(
280 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
281 : const Word32 inputFs, /* i : input sampling frequency */
282 : const Word32 bitrate, /* i : requested bitrate of the output bitstream */
283 : const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */
284 : const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */
285 : const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
286 : const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig, /* i : configuration of channel-aware mode, can by set to default by using IVAS_ENC_GetDefaultChannelAwareConfig() */
287 : const bool downmixFromStereo, /* i : if true, the encoder accepts a stereo input and internally downmixes it to mono before encoding */
288 : const bool is_binaural /* i : if true, the input is binaural audio */
289 : )
290 : {
291 : ivas_error error;
292 :
293 3 : error = IVAS_ERR_OK;
294 :
295 3 : IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK )
296 : {
297 0 : return error;
298 : }
299 :
300 3 : hIvasEnc->st_ivas->hEncoderConfig->ivas_format = MONO_FORMAT;
301 3 : hIvasEnc->st_ivas->hEncoderConfig->is_binaural = (Word16) is_binaural;
302 3 : move16();
303 3 : move16();
304 :
305 3 : if ( downmixFromStereo )
306 : {
307 2 : hIvasEnc->st_ivas->hEncoderConfig->stereo_dmx_evs = 1;
308 2 : move16();
309 : }
310 3 : hIvasEnc->maxBandwidthUser = max_bwidth_user;
311 :
312 3 : error = configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, caConfig );
313 :
314 3 : return error;
315 : }
316 :
317 :
318 : /*---------------------------------------------------------------------*
319 : * IVAS_ENC_ConfigureForStereo()
320 : *
321 : * Configure and initialize the stereo encoder.
322 : *---------------------------------------------------------------------*/
323 :
324 68 : ivas_error IVAS_ENC_ConfigureForStereo(
325 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
326 : const Word32 inputFs, /* i : input sampling frequency */
327 : const Word32 bitrate, /* i : requested bitrate of the output bitstream */
328 : const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */
329 : const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */
330 : const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
331 : const bool is_binaural /* i : flag indicating if input is binaural audio */
332 : #ifdef DEBUGGING
333 : ,
334 : const IVAS_ENC_STEREO_MODE stereoMode /* i : forces a specific stereo coding mode */
335 : #endif
336 : )
337 : {
338 : Encoder_Struct *st_ivas;
339 : ENCODER_CONFIG_HANDLE hEncoderConfig;
340 :
341 : ivas_error error;
342 :
343 68 : IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK )
344 : {
345 0 : return error;
346 : }
347 :
348 68 : st_ivas = hIvasEnc->st_ivas;
349 68 : hEncoderConfig = st_ivas->hEncoderConfig;
350 68 : hEncoderConfig->nchan_inp = 2;
351 68 : move16();
352 68 : hEncoderConfig->ivas_format = STEREO_FORMAT;
353 68 : move16();
354 68 : hEncoderConfig->is_binaural = (Word16) is_binaural;
355 68 : move16();
356 :
357 : #ifdef DEBUGGING
358 : switch ( stereoMode )
359 : {
360 : case IVAS_ENC_STEREO_MODE_UNIFIED:
361 : hEncoderConfig->stereo_mode_cmdl = 1; /* set unified stereo by default */
362 : hEncoderConfig->element_mode_init = IVAS_CPE_DFT;
363 : hIvasEnc->cmd_stereo = true;
364 : break;
365 : case IVAS_ENC_STEREO_MODE_DFT:
366 : hEncoderConfig->element_mode_init = IVAS_CPE_DFT;
367 : hEncoderConfig->stereo_mode_cmdl = IVAS_CPE_DFT;
368 : break;
369 : case IVAS_ENC_STEREO_MODE_TD:
370 : hEncoderConfig->stereo_mode_cmdl = IVAS_CPE_TD;
371 : hEncoderConfig->element_mode_init = IVAS_CPE_TD;
372 : break;
373 : case IVAS_ENC_STEREO_MODE_MDCT_DECISION:
374 : hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
375 : hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION;
376 : break;
377 : #ifdef DEBUG_FORCE_MDCT_STEREO_MODE
378 : case IVAS_ENC_STEREO_MODE_MDCT_FORCE_LR:
379 : hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
380 : hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_FORCE_LR;
381 : break;
382 : case IVAS_ENC_STEREO_MODE_MDCT_FORCE_MS:
383 : hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
384 : hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_FORCE_MS;
385 : break;
386 : #endif
387 : default:
388 : return IVAS_ERR_INVALID_STEREO_MODE;
389 : break;
390 : }
391 : #endif /* DEBUGGING */
392 :
393 68 : hIvasEnc->maxBandwidthUser = max_bwidth_user;
394 :
395 68 : error = configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() );
396 :
397 68 : return error;
398 : }
399 :
400 :
401 : /*---------------------------------------------------------------------*
402 : * IVAS_ENC_ConfigureForMASAObjects()
403 : *
404 : * Configure and initialize the combined MASA and ISM encoder.
405 : *---------------------------------------------------------------------*/
406 44 : ivas_error IVAS_ENC_ConfigureForMASAObjects(
407 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
408 : const Word32 inputFs, /* i : input sampling frequency */
409 : const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */
410 : const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */
411 : const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
412 : const UWord16 numObjects, /* i : number of objects to be encoded */
413 : const Word16 masaVariant /* i : index specifying the number of MASA transport channels */
414 : )
415 : {
416 : Encoder_Struct *st_ivas;
417 : ivas_error error;
418 :
419 44 : IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK )
420 : {
421 0 : return error;
422 : }
423 :
424 44 : IF( GT_32( numObjects, MAX_NUM_OBJECTS ) )
425 : {
426 0 : return IVAS_ERR_TOO_MANY_INPUTS;
427 : }
428 44 : st_ivas = hIvasEnc->st_ivas;
429 44 : SWITCH( masaVariant )
430 : {
431 32 : case IVAS_ENC_MASA_2CH:
432 32 : st_ivas->hEncoderConfig->nchan_inp = add( CPE_CHANNELS, numObjects );
433 32 : st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */
434 32 : move16();
435 32 : move16();
436 32 : BREAK;
437 12 : case IVAS_ENC_MASA_1CH:
438 12 : st_ivas->hEncoderConfig->nchan_inp = add( 1, numObjects );
439 12 : st_ivas->hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */
440 12 : move16();
441 12 : move16();
442 12 : BREAK;
443 0 : default:
444 0 : return IVAS_ERR_INVALID_MASA_CONFIG;
445 : }
446 :
447 44 : st_ivas = hIvasEnc->st_ivas;
448 :
449 : /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */
450 44 : st_ivas->nchan_transport = sub( st_ivas->hEncoderConfig->nchan_inp, numObjects );
451 44 : st_ivas->hEncoderConfig->ivas_format = MASA_ISM_FORMAT;
452 44 : st_ivas->hEncoderConfig->nchan_ism = numObjects;
453 44 : move16();
454 44 : move16();
455 44 : move16();
456 :
457 44 : return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() );
458 : }
459 :
460 :
461 : /*---------------------------------------------------------------------*
462 : * IVAS_ENC_ConfigureForObjects()
463 : *
464 : * Configure and initialize the ISM encoder.
465 : *---------------------------------------------------------------------*/
466 :
467 74 : ivas_error IVAS_ENC_ConfigureForObjects(
468 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
469 : const Word32 inputFs, /* i : input sampling frequency */
470 : const Word32 bitrate, /* i : requested bitrate of the output bitstream */
471 : const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */
472 : const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */
473 : const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
474 : const UWord16 numObjects, /* i : number of objects to be encoded */
475 : const bool ism_extended_metadata /* i : Extended metadata used (true/false), where extended metadata includes radius and orientation */
476 : )
477 : {
478 : Encoder_Struct *st_ivas;
479 : ivas_error error;
480 :
481 74 : IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK )
482 : {
483 0 : return error;
484 : }
485 :
486 74 : IF( GT_32( numObjects, MAX_NUM_OBJECTS ) )
487 : {
488 0 : return IVAS_ERR_TOO_MANY_INPUTS;
489 : }
490 :
491 74 : st_ivas = hIvasEnc->st_ivas;
492 74 : st_ivas->hEncoderConfig->ivas_format = ISM_FORMAT;
493 74 : move16();
494 74 : st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE;
495 74 : move16();
496 74 : st_ivas->hEncoderConfig->nchan_inp = numObjects;
497 74 : move16();
498 74 : st_ivas->hEncoderConfig->nchan_ism = numObjects;
499 74 : move16();
500 74 : st_ivas->hEncoderConfig->ism_extended_metadata_flag = ism_extended_metadata;
501 74 : move16();
502 74 : hIvasEnc->extMetadataApi = ( ism_extended_metadata == 1 );
503 74 : hIvasEnc->maxBandwidthUser = max_bwidth_user;
504 :
505 74 : error = configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() );
506 :
507 74 : return error;
508 : }
509 :
510 :
511 : /*---------------------------------------------------------------------*
512 : * IVAS_ENC_FeedObjectMetadata()
513 : *
514 : *
515 : *---------------------------------------------------------------------*/
516 :
517 433276 : ivas_error IVAS_ENC_FeedObjectMetadata(
518 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
519 : const UWord16 ismIndex, /* i : object index */
520 : const IVAS_ISM_METADATA metadata /* i : object metadata handle for current frame */
521 : )
522 : {
523 : ivas_error error;
524 :
525 433276 : error = IVAS_ERR_OK;
526 :
527 433276 : IF( !hIvasEnc->isConfigured )
528 : {
529 0 : return IVAS_ERR_NOT_CONFIGURED;
530 : }
531 :
532 433276 : test();
533 433276 : test();
534 433276 : IF( NE_16( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, ISM_FORMAT ) && NE_16( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) && NE_16( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) )
535 : {
536 0 : return IVAS_ERR_METADATA_NOT_EXPECTED;
537 : }
538 :
539 433276 : IF( GT_32( ismIndex, hIvasEnc->st_ivas->hEncoderConfig->nchan_inp ) )
540 : {
541 0 : return IVAS_ERR_INVALID_INDEX;
542 : }
543 433276 : Word32 azimuth_fx = float_to_fix( metadata.azimuth, Q22 ); /* Q22 */
544 433276 : Word32 elevation_fx = float_to_fix( metadata.elevation, Q22 ); /* Q22 */
545 433276 : Word16 radius_fx = float_to_fix16( metadata.radius, Q9 ); /* Q9 */
546 433276 : Word32 yaw_fx = float_to_fix( metadata.yaw, Q22 ); /* Q22 */
547 433276 : Word32 pitch_fx = float_to_fix( metadata.pitch, Q22 ); /* Q22 */
548 433276 : error = ivas_set_ism_metadata_fx( hIvasEnc->st_ivas->hIsmMetaData[ismIndex], azimuth_fx, elevation_fx, radius_fx, yaw_fx, pitch_fx, metadata.non_diegetic_flag );
549 :
550 433276 : IF( error != IVAS_ERR_OK )
551 : {
552 0 : return error;
553 : }
554 :
555 433276 : hIvasEnc->ismMetadataProvided[ismIndex] = true;
556 :
557 433276 : return error;
558 : }
559 :
560 :
561 : /*---------------------------------------------------------------------*
562 : * IVAS_ENC_ConfigureForAmbisonics()
563 : *
564 : * Configure and initialize the SBA encoder.
565 : *---------------------------------------------------------------------*/
566 :
567 244 : ivas_error IVAS_ENC_ConfigureForAmbisonics(
568 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
569 : const Word32 inputFs, /* i : input sampling frequency */
570 : const Word32 bitrate, /* i : requested bitrate of the output bitstream */
571 : const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */
572 : const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */
573 : const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
574 : const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */
575 : const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */
576 : const bool Opt_PCA_ON /* i : PCA option flag */
577 : )
578 : {
579 : ENCODER_CONFIG_HANDLE hEncoderConfig;
580 : ivas_error error;
581 :
582 244 : IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK )
583 : {
584 0 : return error;
585 : }
586 :
587 244 : hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig;
588 :
589 244 : hEncoderConfig->ivas_format = SBA_FORMAT;
590 244 : hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */
591 244 : hEncoderConfig->sba_planar = isPlanar;
592 244 : hEncoderConfig->sba_order = order;
593 244 : move16();
594 244 : move16();
595 244 : move16();
596 :
597 : /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */
598 244 : hEncoderConfig->nchan_inp = ivas_sba_get_nchan_fx( hEncoderConfig->sba_order, 0 ); /*planar input arg. deliberately set to zero since input always in ACN/SN3D*/
599 244 : move16();
600 :
601 :
602 244 : hEncoderConfig->Opt_PCA_ON = (Word16) Opt_PCA_ON;
603 244 : move16();
604 :
605 244 : hIvasEnc->maxBandwidthUser = max_bwidth_user;
606 :
607 244 : error = configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() );
608 :
609 :
610 244 : return error;
611 : }
612 : /*---------------------------------------------------------------------*
613 : * IVAS_ENC_ConfigureForSBAObjects()
614 : *
615 : * Configure and initialize the combined SBA and ISM encoder.
616 : *---------------------------------------------------------------------*/
617 :
618 37 : ivas_error IVAS_ENC_ConfigureForSBAObjects(
619 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
620 : const Word32 inputFs, /* i : input sampling frequency */
621 : const Word32 bitrate, /* i : requested bitrate of the ouput bitstream */
622 : const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */
623 : const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
624 : const UWord16 numObjects, /* i : number of objects to be encoded */
625 : const IVAS_ENC_SBA_ORDER order, /* i : order of the Ambisonics input */
626 : const bool isPlanar, /* i : if true, input is treated as planar Ambisonics */
627 : const bool Opt_PCA_ON /* i : PCA option flag */
628 : )
629 : {
630 : Encoder_Struct *st_ivas;
631 : ivas_error error;
632 :
633 37 : IF( NE_16( ( error = doCommonConfigureChecks( hIvasEnc ) ), IVAS_ERR_OK ) )
634 : {
635 0 : return error;
636 : }
637 :
638 37 : IF( GT_32( numObjects, MAX_NUM_OBJECTS ) )
639 : {
640 0 : return IVAS_ERR_TOO_MANY_INPUTS;
641 : }
642 37 : st_ivas = hIvasEnc->st_ivas;
643 :
644 37 : st_ivas->hEncoderConfig->element_mode_init = IVAS_SCE; /* Just needs to be something not mono, will be set later */
645 37 : move16();
646 37 : st_ivas->hEncoderConfig->sba_planar = isPlanar;
647 37 : move16();
648 37 : st_ivas->hEncoderConfig->sba_order = order;
649 37 : move16();
650 :
651 : /* Input in ACN/SN3D in all cases (3D and planar): get number of channels */
652 : /*Input file will always contain all channels for a given order irrespective of planar flag*/
653 37 : st_ivas->hEncoderConfig->nchan_inp = add( ivas_sba_get_nchan_fx( st_ivas->hEncoderConfig->sba_order, 0 ), numObjects );
654 37 : move16();
655 37 : st_ivas->hEncoderConfig->Opt_PCA_ON = extract_l( Opt_PCA_ON );
656 37 : move16();
657 :
658 : /* Currently this is true but it is already shown in descriptive metadata that there can be inequality for this. */
659 37 : st_ivas->nchan_transport = sub( st_ivas->hEncoderConfig->nchan_inp, numObjects );
660 37 : move16();
661 37 : st_ivas->hEncoderConfig->ivas_format = SBA_ISM_FORMAT;
662 37 : move16();
663 37 : st_ivas->hEncoderConfig->nchan_ism = numObjects;
664 37 : move16();
665 :
666 37 : return configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() );
667 : }
668 :
669 :
670 : /*---------------------------------------------------------------------*
671 : * IVAS_ENC_ConfigureForMasa()
672 : *
673 : * Configure and initialize the MASA encoder.
674 : *---------------------------------------------------------------------*/
675 75 : ivas_error IVAS_ENC_ConfigureForMasa(
676 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
677 : const Word32 inputFs, /* i : input sampling frequency */
678 : const Word32 bitrate, /* i : requested bitrate of the output bitstream */
679 : const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */
680 : const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */
681 : const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
682 : const IVAS_ENC_MASA_VARIANT masaVariant /* i : type of MASA input (either 1 or 2 channels) */
683 : )
684 : {
685 : ENCODER_CONFIG_HANDLE hEncoderConfig;
686 : ivas_error error;
687 :
688 75 : IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK )
689 : {
690 0 : return error;
691 : }
692 :
693 75 : hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig;
694 :
695 75 : hEncoderConfig->ivas_format = MASA_FORMAT;
696 75 : move32();
697 :
698 75 : SWITCH( masaVariant )
699 : {
700 31 : case IVAS_ENC_MASA_1CH:
701 31 : hEncoderConfig->nchan_inp = 1;
702 31 : hEncoderConfig->element_mode_init = IVAS_SCE;
703 31 : move16();
704 31 : move16();
705 31 : BREAK;
706 44 : case IVAS_ENC_MASA_2CH:
707 44 : hEncoderConfig->nchan_inp = 2;
708 : #ifdef DEBUGGING
709 : hEncoderConfig->stereo_mode_cmdl = 1; /* set unified stereo by default */
710 : #endif
711 44 : hEncoderConfig->element_mode_init = IVAS_CPE_DFT; /* initialization only, might be changed later based on element_brate */
712 44 : move16();
713 44 : move16();
714 44 : BREAK;
715 0 : default:
716 0 : return IVAS_ERR_INVALID_MASA_CONFIG;
717 : }
718 :
719 75 : hIvasEnc->maxBandwidthUser = max_bwidth_user;
720 :
721 75 : error = configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() );
722 :
723 75 : return error;
724 : }
725 :
726 :
727 : /*---------------------------------------------------------------------*
728 : * IVAS_ENC_FeedMasaMetadata()
729 : *
730 : *
731 : *---------------------------------------------------------------------*/
732 :
733 39626 : ivas_error IVAS_ENC_FeedMasaMetadata(
734 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
735 : IVAS_MASA_METADATA_HANDLE hMasaMetadata /* i : MASA metadata for current frame */
736 : )
737 : {
738 39626 : IF( !hIvasEnc->isConfigured )
739 : {
740 0 : return IVAS_ERR_NOT_CONFIGURED;
741 : }
742 :
743 39626 : test();
744 39626 : IF( NE_32( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_FORMAT ) && NE_32( hIvasEnc->st_ivas->hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) )
745 : {
746 0 : return IVAS_ERR_METADATA_NOT_EXPECTED;
747 : }
748 :
749 39626 : hIvasEnc->st_ivas->hMasa->masaMetadata = *hMasaMetadata;
750 :
751 39626 : return IVAS_ERR_OK;
752 : }
753 :
754 :
755 : /*---------------------------------------------------------------------*
756 : * IVAS_ENC_ConfigureForMultichannel()
757 : *
758 : * Configure and initialize the MC encoder.
759 : *---------------------------------------------------------------------*/
760 :
761 82 : ivas_error IVAS_ENC_ConfigureForMultichannel(
762 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
763 : const Word32 inputFs, /* i : input sampling frequency */
764 : const Word32 bitrate, /* i : requested bitrate of the output bitstream */
765 : const bool max_bwidth_user, /* i : shows if bandwidth limitation was set by the user (true) or if default bandwidth was used (false) */
766 : const IVAS_ENC_BANDWIDTH maxBandwidth, /* i : bandwidth limitation */
767 : const IVAS_ENC_DTX_CONFIG dtxConfig, /* i : configuration of DTX, can by set to default by using IVAS_ENC_GetDefaultDtxConfig() */
768 : const IVAS_ENC_MC_LAYOUT mcLayout /* i : inpu MC layput */
769 : )
770 : {
771 : ENCODER_CONFIG_HANDLE hEncoderConfig;
772 : ivas_error error;
773 :
774 82 : IF( ( error = doCommonConfigureChecks( hIvasEnc ) ) != IVAS_ERR_OK )
775 : {
776 0 : return error;
777 : }
778 :
779 82 : hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig;
780 :
781 82 : hEncoderConfig->ivas_format = MC_FORMAT;
782 82 : move16();
783 82 : hEncoderConfig->element_mode_init = IVAS_CPE_MDCT; /*just for initialization*/
784 82 : move16();
785 :
786 82 : SWITCH( mcLayout )
787 : {
788 43 : case IVAS_ENC_MC_5_1:
789 43 : hEncoderConfig->mc_input_setup = MC_LS_SETUP_5_1;
790 43 : BREAK;
791 4 : case IVAS_ENC_MC_7_1:
792 4 : hEncoderConfig->mc_input_setup = MC_LS_SETUP_7_1;
793 4 : BREAK;
794 6 : case IVAS_ENC_MC_5_1_2:
795 6 : hEncoderConfig->mc_input_setup = MC_LS_SETUP_5_1_2;
796 6 : BREAK;
797 6 : case IVAS_ENC_MC_5_1_4:
798 6 : hEncoderConfig->mc_input_setup = MC_LS_SETUP_5_1_4;
799 6 : BREAK;
800 23 : case IVAS_ENC_MC_7_1_4:
801 23 : hEncoderConfig->mc_input_setup = MC_LS_SETUP_7_1_4;
802 23 : BREAK;
803 0 : default:
804 0 : return IVAS_ERR_INVALID_MC_LAYOUT;
805 : BREAK;
806 : }
807 :
808 82 : hEncoderConfig->nchan_inp = ivas_mc_ls_setup_get_num_channels_fx( hEncoderConfig->mc_input_setup );
809 82 : move16();
810 :
811 82 : hIvasEnc->maxBandwidthUser = max_bwidth_user;
812 :
813 82 : error = configureEncoder( hIvasEnc, inputFs, bitrate, maxBandwidth, dtxConfig, IVAS_ENC_GetDefaultChannelAwareConfig() );
814 :
815 82 : return error;
816 : }
817 :
818 :
819 : /*---------------------------------------------------------------------*
820 : * configureEncoder()
821 : *
822 : * Configure the IVAS encoder.
823 : *---------------------------------------------------------------------*/
824 :
825 627 : static ivas_error configureEncoder(
826 : IVAS_ENC_HANDLE hIvasEnc,
827 : const Word32 inputFs,
828 : const Word32 initBitrate,
829 : const IVAS_ENC_BANDWIDTH initBandwidth,
830 : const IVAS_ENC_DTX_CONFIG dtxConfig,
831 : const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig )
832 : {
833 : Encoder_Struct *st_ivas;
834 : ENCODER_CONFIG_HANDLE hEncoderConfig;
835 : ivas_error error;
836 : Word32 cpe_brate;
837 :
838 627 : error = IVAS_ERR_OK;
839 :
840 627 : st_ivas = hIvasEnc->st_ivas;
841 627 : hEncoderConfig = st_ivas->hEncoderConfig;
842 :
843 : /*-----------------------------------------------------------------*
844 : * Bandwidth limitation
845 : *-----------------------------------------------------------------*/
846 :
847 627 : IF( ( error = setBandwidth_fx( hIvasEnc, initBandwidth ) ) != IVAS_ERR_OK )
848 : {
849 0 : return error;
850 : }
851 :
852 : /*-----------------------------------------------------------------*
853 : * DTX/CNG
854 : *-----------------------------------------------------------------*/
855 :
856 627 : IF( dtxConfig.enabled )
857 : {
858 126 : hEncoderConfig->Opt_DTX_ON = 1;
859 126 : move16();
860 :
861 126 : IF( dtxConfig.variable_SID_rate )
862 : {
863 0 : hEncoderConfig->var_SID_rate_flag = 1;
864 0 : hEncoderConfig->interval_SID = 0;
865 0 : move16();
866 0 : move16();
867 : }
868 : ELSE
869 : {
870 126 : hEncoderConfig->var_SID_rate_flag = 0;
871 126 : move16();
872 :
873 126 : test();
874 126 : IF( GE_16( dtxConfig.SID_interval, 3 ) && LE_16( dtxConfig.SID_interval, 100 ) )
875 : {
876 126 : hEncoderConfig->interval_SID = dtxConfig.SID_interval;
877 126 : move16();
878 : }
879 : ELSE
880 : {
881 0 : return IVAS_ERR_INVALID_DTX_UPDATE_RATE;
882 : }
883 : }
884 : }
885 : ELSE
886 : {
887 501 : hEncoderConfig->Opt_DTX_ON = 0;
888 501 : move16();
889 : }
890 :
891 : /*-----------------------------------------------------------------*
892 : * Bitrate
893 : *-----------------------------------------------------------------*/
894 :
895 627 : hEncoderConfig->ivas_total_brate = initBitrate;
896 627 : move32();
897 :
898 : /* SC-VBR at 5.90 kbps */
899 627 : IF( EQ_32( hEncoderConfig->ivas_total_brate, ACELP_5k90 ) )
900 : {
901 0 : hEncoderConfig->ivas_total_brate = ACELP_7k20;
902 0 : hEncoderConfig->Opt_SC_VBR = 1;
903 0 : hEncoderConfig->last_Opt_SC_VBR = hEncoderConfig->Opt_SC_VBR;
904 0 : move32();
905 0 : move16();
906 0 : move16();
907 :
908 0 : if ( ( hEncoderConfig->max_bwidth != NB ) )
909 : {
910 0 : hEncoderConfig->max_bwidth = WB;
911 0 : move16();
912 : }
913 : }
914 :
915 : /* check if the entered bitrate is supported */
916 627 : test();
917 627 : IF( NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) ) /* IVAS */
918 : {
919 624 : IF( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) )
920 : {
921 0 : IF( hEncoderConfig->Opt_SC_VBR )
922 : {
923 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", ACELP_5k90 );
924 : }
925 : ELSE
926 : {
927 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS [bps]: %d", hEncoderConfig->ivas_total_brate );
928 : }
929 : }
930 :
931 624 : IF( EQ_16( hEncoderConfig->ivas_format, STEREO_FORMAT ) )
932 : {
933 : #ifdef DEBUGGING
934 : if ( hIvasEnc->cmd_stereo )
935 : #endif
936 : {
937 68 : hEncoderConfig->element_mode_init = IVAS_CPE_DFT;
938 : #ifdef DEBUGGING
939 : hEncoderConfig->stereo_mode_cmdl = 1;
940 : #endif
941 :
942 68 : if ( GE_32( hEncoderConfig->ivas_total_brate, MIN_BRATE_MDCT_STEREO ) )
943 : {
944 18 : hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
945 18 : move16();
946 : #ifdef DEBUGGING
947 : hEncoderConfig->stereo_mode_cmdl = 0;
948 : #endif
949 : }
950 : }
951 :
952 68 : test();
953 68 : test();
954 68 : IF( ( EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_TD ) || EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_DFT ) ) && GT_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) )
955 : {
956 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for TD/DFT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
957 : }
958 :
959 68 : test();
960 68 : IF( EQ_16( hEncoderConfig->element_mode_init, IVAS_CPE_MDCT ) && LT_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) )
961 : {
962 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for MDCT Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
963 : }
964 :
965 68 : IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) )
966 : {
967 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for Stereo specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
968 : }
969 : }
970 556 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) )
971 : {
972 74 : IF( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK )
973 : {
974 0 : return error;
975 : }
976 : }
977 482 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) )
978 : {
979 : /* nothing */
980 : }
981 238 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_FORMAT ) )
982 : {
983 : /* adapt element_mode according to the bitrate */
984 75 : test();
985 75 : IF( EQ_16( hEncoderConfig->nchan_inp, 2 ) && NE_16( hEncoderConfig->element_mode_init, IVAS_SCE ) )
986 : {
987 44 : IF( GE_32( hEncoderConfig->ivas_total_brate, IVAS_48k ) )
988 : {
989 22 : hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
990 22 : move16();
991 : }
992 22 : ELSE IF( LT_32( hEncoderConfig->ivas_total_brate, MASA_STEREO_MIN_BITRATE ) )
993 : {
994 14 : hEncoderConfig->element_mode_init = IVAS_CPE_DFT;
995 14 : move16();
996 : }
997 : }
998 : }
999 163 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) )
1000 : {
1001 44 : st_ivas->ism_mode = ivas_omasa_ism_mode_select_fx( st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism );
1002 44 : move32();
1003 :
1004 44 : cpe_brate = calculate_cpe_brate_MASA_ISM_fx( st_ivas->ism_mode, st_ivas->hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism );
1005 :
1006 : /*adapt element_mode according to the bit-rate*/
1007 44 : IF( NE_16( hEncoderConfig->element_mode_init, IVAS_SCE ) )
1008 : {
1009 44 : if ( GE_32( cpe_brate, IVAS_48k ) )
1010 : {
1011 17 : hEncoderConfig->element_mode_init = IVAS_CPE_MDCT;
1012 17 : move16();
1013 : }
1014 : }
1015 : }
1016 119 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) )
1017 : {
1018 37 : st_ivas->ism_mode = ISM_MODE_NONE;
1019 37 : move16();
1020 : }
1021 : }
1022 : ELSE /* EVS mono */
1023 : {
1024 3 : hEncoderConfig->ivas_format = MONO_FORMAT;
1025 3 : move16();
1026 3 : hEncoderConfig->element_mode_init = EVS_MONO;
1027 3 : move16();
1028 :
1029 3 : IF( !is_EVS_bitrate( hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB ) )
1030 : {
1031 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in EVS mono: %d", hEncoderConfig->ivas_total_brate );
1032 : }
1033 :
1034 3 : IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) )
1035 : {
1036 2 : hEncoderConfig->nchan_inp = 2;
1037 2 : move16();
1038 : }
1039 : }
1040 :
1041 : /*-----------------------------------------------------------------*
1042 : * Input sampling frequency
1043 : *-----------------------------------------------------------------*/
1044 627 : test();
1045 627 : test();
1046 627 : test();
1047 627 : IF( NE_32( inputFs, 8000 ) && NE_32( inputFs, 16000 ) && NE_32( inputFs, 32000 ) && NE_32( inputFs, 48000 ) )
1048 : {
1049 0 : return IVAS_ERR_INVALID_SAMPLING_RATE;
1050 : }
1051 :
1052 627 : hEncoderConfig->input_Fs = inputFs;
1053 627 : move32();
1054 :
1055 : /*-----------------------------------------------------------------*
1056 : * Channel-aware mode
1057 : *-----------------------------------------------------------------*/
1058 :
1059 627 : IF( ( error = setChannelAwareConfig_fx( hIvasEnc, caConfig ) ) != IVAS_ERR_OK )
1060 : {
1061 0 : return error;
1062 : }
1063 :
1064 : /*-----------------------------------------------------------------*
1065 : * Set codec mode
1066 : *-----------------------------------------------------------------*/
1067 :
1068 627 : st_ivas->codec_mode = MODE1; /* Note: in IVAS, set MODE1 */
1069 627 : move16();
1070 :
1071 627 : IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) )
1072 : {
1073 3 : IF( hEncoderConfig->Opt_AMR_WB )
1074 : {
1075 0 : st_ivas->codec_mode = MODE1;
1076 0 : move16();
1077 : }
1078 : ELSE
1079 : {
1080 3 : st_ivas->codec_mode = get_codec_mode( hEncoderConfig->ivas_total_brate );
1081 3 : move16();
1082 : }
1083 : }
1084 :
1085 627 : test();
1086 627 : IF( EQ_32( hEncoderConfig->ivas_total_brate, IVAS_13k2 ) && EQ_16( hEncoderConfig->Opt_RF_ON, 1 ) )
1087 : {
1088 0 : st_ivas->codec_mode = MODE2;
1089 0 : move16();
1090 : }
1091 :
1092 627 : st_ivas->last_codec_mode = st_ivas->codec_mode;
1093 627 : move16();
1094 :
1095 : /*-----------------------------------------------------------------*
1096 : * Sanity checks
1097 : *-----------------------------------------------------------------*/
1098 :
1099 627 : assert( hEncoderConfig->ivas_format != UNDEFINED_FORMAT && "\n IVAS format undefined" );
1100 :
1101 627 : test();
1102 627 : test();
1103 627 : IF( ( NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) || hEncoderConfig->stereo_dmx_evs ) && EQ_32( hEncoderConfig->input_Fs, 8000 ) )
1104 : {
1105 0 : return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "8kHz input sampling rate is not supported in IVAS." );
1106 : }
1107 :
1108 627 : test();
1109 627 : test();
1110 627 : test();
1111 627 : test();
1112 627 : test();
1113 627 : test();
1114 627 : IF( hEncoderConfig->Opt_DTX_ON && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) &&
1115 : ( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) && GT_16( ivas_get_sba_num_TCs_fx( hEncoderConfig->ivas_total_brate, 1 ), 2 ) ) ||
1116 : EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) )
1117 : {
1118 0 : return IVAS_ERROR( IVAS_ERR_DTX_NOT_SUPPORTED, "DTX is not supported in this IVAS format and element mode." );
1119 : }
1120 :
1121 627 : test();
1122 627 : test();
1123 627 : test();
1124 627 : IF( hEncoderConfig->Opt_PCA_ON && !( ( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) || EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) ) && EQ_32( hEncoderConfig->ivas_total_brate, PCA_BRATE ) && EQ_16( hEncoderConfig->sba_order, SBA_FOA_ORDER ) ) )
1125 : {
1126 0 : return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "PCA supported at SBA FOA 256 kbps only." );
1127 : }
1128 :
1129 627 : IF( ( error = sanitizeBandwidth_fx( hIvasEnc ) ) != IVAS_ERR_OK )
1130 : {
1131 0 : return error;
1132 : }
1133 :
1134 627 : test();
1135 627 : test();
1136 627 : test();
1137 627 : IF( hEncoderConfig->is_binaural && !( ( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) && hEncoderConfig->stereo_dmx_evs ) || EQ_16( hEncoderConfig->ivas_format, STEREO_FORMAT ) ) )
1138 : {
1139 0 : return IVAS_ERROR( IVAS_ERR_NOT_SUPPORTED_OPTION, "'-binaural' option is supported only with '-stereo' or '-stereo_dmx_evs'" );
1140 : }
1141 :
1142 : /*-----------------------------------------------------------------*
1143 : * Finalize initialization
1144 : *-----------------------------------------------------------------*/
1145 :
1146 627 : IF( ( error = ivas_init_encoder_fx( st_ivas ) ) != IVAS_ERR_OK )
1147 : {
1148 0 : return error;
1149 : }
1150 :
1151 627 : IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) )
1152 : {
1153 3 : hIvasEnc->hCoreCoder = st_ivas->hSCE[0]->hCoreCoder[0]; /* Note: this is needed for switching in EVS mono */
1154 : }
1155 : ELSE
1156 : {
1157 624 : hIvasEnc->hCoreCoder = NULL;
1158 : }
1159 :
1160 627 : hIvasEnc->Opt_RF_ON_loc = hEncoderConfig->Opt_RF_ON;
1161 627 : hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset;
1162 627 : move16();
1163 627 : move16();
1164 :
1165 627 : hIvasEnc->isConfigured = true;
1166 :
1167 627 : return error;
1168 : }
1169 : /*---------------------------------------------------------------------*
1170 : * IVAS_ENC_GetDelay()
1171 : *
1172 : *
1173 : *---------------------------------------------------------------------*/
1174 :
1175 627 : ivas_error IVAS_ENC_GetDelay(
1176 : const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */
1177 : Word16 *delay /* o : encoder delay Q0*/
1178 : )
1179 : {
1180 : ENCODER_CONFIG_HANDLE hEncoderConfig;
1181 :
1182 627 : hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig;
1183 :
1184 627 : IF( !hIvasEnc->isConfigured )
1185 : {
1186 0 : return IVAS_ERR_NOT_CONFIGURED;
1187 : }
1188 :
1189 627 : IF( delay == NULL )
1190 : {
1191 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1192 : }
1193 :
1194 627 : *delay = NS2SA_FX2( hEncoderConfig->input_Fs, get_delay_fx( ENC, hEncoderConfig->input_Fs, hEncoderConfig->ivas_format, NULL, 0 ) );
1195 627 : move16();
1196 :
1197 627 : *delay = imult1616( *delay, hEncoderConfig->nchan_inp ); /*Q0*/
1198 627 : move16();
1199 :
1200 627 : return IVAS_ERR_OK;
1201 : }
1202 :
1203 :
1204 : /*---------------------------------------------------------------------*
1205 : * getInputBufferSize()
1206 : *
1207 : *
1208 : *---------------------------------------------------------------------*/
1209 428015 : static Word16 getInputBufferSize_fx(
1210 : const Encoder_Struct *st_ivas /* i : IVAS encoder handle */
1211 : )
1212 : {
1213 428015 : return extract_l( Mpy_32_32( imult3216( st_ivas->hEncoderConfig->input_Fs, st_ivas->hEncoderConfig->nchan_inp ), ONE_BY_FRAMES_PER_SEC_Q31 ) );
1214 : }
1215 :
1216 : /*---------------------------------------------------------------------*
1217 : * IVAS_ENC_GetNumInChannels()
1218 : *
1219 : *
1220 : *---------------------------------------------------------------------*/
1221 627 : ivas_error IVAS_ENC_GetNumInChannels(
1222 : const IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
1223 : Word16 *numInChannels /* o : total number of samples expected in the input buffer for current encoder configuration */
1224 : )
1225 : {
1226 627 : test();
1227 627 : IF( hIvasEnc == NULL || numInChannels == NULL )
1228 : {
1229 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1230 : }
1231 :
1232 627 : IF( !hIvasEnc->isConfigured )
1233 : {
1234 0 : return IVAS_ERR_NOT_CONFIGURED;
1235 : }
1236 :
1237 627 : *numInChannels = hIvasEnc->st_ivas->hEncoderConfig->nchan_inp;
1238 627 : move16();
1239 :
1240 627 : return IVAS_ERR_OK;
1241 : }
1242 :
1243 :
1244 : /*---------------------------------------------------------------------*
1245 : * IVAS_ENC_GetInputBufferSize()
1246 : *
1247 : *
1248 : *---------------------------------------------------------------------*/
1249 627 : ivas_error IVAS_ENC_GetInputBufferSize(
1250 : const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */
1251 : Word16 *inputBufferSize /* o : total number of samples expected in the input buffer for current encoder configuration */
1252 : )
1253 : {
1254 627 : IF( !hIvasEnc->isConfigured )
1255 : {
1256 0 : return IVAS_ERR_NOT_CONFIGURED;
1257 : }
1258 :
1259 627 : IF( inputBufferSize == NULL )
1260 : {
1261 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1262 : }
1263 :
1264 627 : *inputBufferSize = getInputBufferSize_fx( hIvasEnc->st_ivas );
1265 627 : move16();
1266 :
1267 627 : return IVAS_ERR_OK;
1268 : }
1269 :
1270 :
1271 : /*---------------------------------------------------------------------*
1272 : * IVAS_ENC_EncodeFrameToSerial()
1273 : *
1274 : * Main function to encode one frame to a serial bitstream
1275 : *---------------------------------------------------------------------*/
1276 427388 : ivas_error IVAS_ENC_EncodeFrameToSerial(
1277 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
1278 : Word16 *inputBuffer, /* i : PCM input, Q0 Q0*/
1279 : Word16 inputBufferSize, /* i : total number of samples in the input buffer. Related function: IVAS_ENC_GetInputBufferSize() Q0*/
1280 : UWord16 *outputBitStream, /* o : pointer to serial output bitstream. The array must already be allocated and be of size at least IVAS_MAX_BITS_PER_FRAME Q0*/
1281 : UWord16 *numOutBits /* o : number of bits written to output bitstream. Each bit is stored as a single uint16_t value Q0*/
1282 : )
1283 : {
1284 : Encoder_Struct *st_ivas;
1285 : ENCODER_CONFIG_HANDLE hEncoderConfig;
1286 : Word16 i;
1287 : Word16 n, ch;
1288 : ivas_error error;
1289 :
1290 427388 : error = IVAS_ERR_OK;
1291 427388 : move32();
1292 :
1293 427388 : IF( !hIvasEnc->isConfigured )
1294 : {
1295 0 : return IVAS_ERR_NOT_CONFIGURED;
1296 : }
1297 :
1298 427388 : st_ivas = hIvasEnc->st_ivas;
1299 427388 : hEncoderConfig = st_ivas->hEncoderConfig;
1300 427388 : ENC_CORE_HANDLE hCoreCoder = hIvasEnc->hCoreCoder;
1301 :
1302 427388 : IF( NE_16( inputBufferSize, getInputBufferSize_fx( st_ivas ) ) )
1303 : {
1304 0 : return IVAS_ERR_INVALID_INPUT_BUFFER_SIZE;
1305 : }
1306 :
1307 427388 : IF( NE_32( ( error = sanitizeBandwidth_fx( hIvasEnc ) ), IVAS_ERR_OK ) )
1308 : {
1309 0 : return error;
1310 : }
1311 :
1312 427388 : IF( EQ_32( hEncoderConfig->ivas_format, ISM_FORMAT ) )
1313 : {
1314 407452 : FOR( i = 0; i < hEncoderConfig->nchan_inp; ++i )
1315 : {
1316 303626 : IF( !hIvasEnc->ismMetadataProvided[i] )
1317 : {
1318 6000 : ivas_ism_reset_metadata_API( hIvasEnc->st_ivas->hIsmMetaData[i] );
1319 : }
1320 : }
1321 103826 : resetIsmMetadataProvidedFlags( hIvasEnc );
1322 : }
1323 :
1324 427388 : test();
1325 427388 : test();
1326 427388 : test();
1327 427388 : test();
1328 427388 : IF( ( hEncoderConfig->Opt_RF_ON && ( NE_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) || EQ_32( hEncoderConfig->input_Fs, 8000 ) || hEncoderConfig->max_bwidth == NB ) ) || hEncoderConfig->rf_fec_offset == 0 )
1329 : {
1330 427388 : test();
1331 427388 : IF( EQ_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) && EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) )
1332 : {
1333 1050 : st_ivas->codec_mode = MODE1;
1334 1050 : move16();
1335 :
1336 1050 : reset_rf_indices_fx( hCoreCoder );
1337 : }
1338 427388 : hEncoderConfig->Opt_RF_ON = 0;
1339 427388 : move16();
1340 427388 : hEncoderConfig->rf_fec_offset = 0;
1341 427388 : move16();
1342 427388 : hIvasEnc->switchingActive = true;
1343 427388 : move16();
1344 : }
1345 :
1346 427388 : test();
1347 427388 : test();
1348 427388 : test();
1349 427388 : test();
1350 427388 : IF( hIvasEnc->Opt_RF_ON_loc && hIvasEnc->rf_fec_offset_loc != 0 && L_sub( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) == 0 && L_sub( hEncoderConfig->input_Fs, 8000 ) != 0 && hEncoderConfig->max_bwidth != NB )
1351 : {
1352 0 : st_ivas->codec_mode = MODE2;
1353 0 : move16();
1354 0 : test();
1355 0 : IF( hEncoderConfig->Opt_RF_ON == 0 && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) )
1356 : {
1357 0 : reset_rf_indices_fx( hCoreCoder );
1358 : }
1359 0 : hEncoderConfig->Opt_RF_ON = 1;
1360 0 : hEncoderConfig->rf_fec_offset = hIvasEnc->rf_fec_offset_loc;
1361 0 : hIvasEnc->switchingActive = true;
1362 0 : move16();
1363 0 : move16();
1364 0 : move16();
1365 : }
1366 :
1367 : /* in case of 8kHz sampling rate or when in "max_band NB" mode, limit the total bitrate to 24.40 kbps */
1368 427388 : test();
1369 427388 : test();
1370 427388 : IF( ( EQ_32( hEncoderConfig->input_Fs, 8000 ) || ( hEncoderConfig->max_bwidth == NB ) ) && GT_32( hEncoderConfig->ivas_total_brate, ACELP_24k40 ) )
1371 : {
1372 0 : hEncoderConfig->ivas_total_brate = ACELP_24k40;
1373 0 : st_ivas->codec_mode = MODE2;
1374 0 : hIvasEnc->switchingActive = true;
1375 0 : move32();
1376 0 : move16();
1377 0 : move16();
1378 : }
1379 :
1380 : /*-----------------------------------------------------------------*
1381 : * Re-allocate and re-initialize buffer of indices if IVAS total bitrate has changed
1382 : *-----------------------------------------------------------------*/
1383 :
1384 427388 : IF( NE_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->last_ivas_total_brate ) )
1385 : {
1386 : /* de-allocate old buffer of indices */
1387 6903 : free( st_ivas->ind_list );
1388 :
1389 : /* set the maximum allowed number of indices in the list */
1390 6903 : st_ivas->ivas_max_num_indices = get_ivas_max_num_indices_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate );
1391 6903 : move16();
1392 :
1393 : /* allocate new buffer of indices */
1394 6903 : IF( ( st_ivas->ind_list = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices * sizeof( Indice ) ) ) == NULL )
1395 : {
1396 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of indices!\n" ) );
1397 : }
1398 :
1399 : /* reset the list of indices */
1400 5416213 : FOR( i = 0; i < st_ivas->ivas_max_num_indices; i++ )
1401 : {
1402 5409310 : st_ivas->ind_list[i].nb_bits = -1;
1403 5409310 : move16();
1404 : }
1405 : #if defined( DEBUGGING ) && defined( DBG_BITSTREAM_ANALYSIS )
1406 : for ( i = 0; i < st_ivas->ivas_max_num_indices; i++ )
1407 : {
1408 : memset( st_ivas->ind_list[i].function_name, 'A', 100 * sizeof( char ) );
1409 : }
1410 : #endif
1411 : /* de-allocate old buffer of metadata indices */
1412 6903 : IF( st_ivas->ind_list_metadata != NULL )
1413 : {
1414 6903 : free( st_ivas->ind_list_metadata );
1415 : }
1416 :
1417 : /* set the maximum allowed number of metadata indices in the list */
1418 6903 : st_ivas->ivas_max_num_indices_metadata = get_ivas_max_num_indices_metadata_fx( hEncoderConfig->ivas_format, hEncoderConfig->ivas_total_brate );
1419 6903 : move16();
1420 :
1421 6903 : IF( st_ivas->ivas_max_num_indices_metadata > 0 )
1422 : {
1423 : /* allocate new buffer of metadata indices */
1424 6903 : IF( ( st_ivas->ind_list_metadata = (INDICE_HANDLE) malloc( st_ivas->ivas_max_num_indices_metadata * sizeof( Indice ) ) ) == NULL )
1425 : {
1426 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for buffer of metadata indices!\n" ) );
1427 : }
1428 :
1429 : /* reset the list of metadata indices */
1430 2407748 : FOR( i = 0; i < st_ivas->ivas_max_num_indices_metadata; i++ )
1431 : {
1432 2400845 : st_ivas->ind_list_metadata[i].nb_bits = -1;
1433 2400845 : move16();
1434 : }
1435 : }
1436 : ELSE
1437 : {
1438 0 : st_ivas->ind_list_metadata = NULL;
1439 : }
1440 :
1441 : /* set pointers to the new buffers of indices in each element */
1442 13325 : FOR( n = 0; n < st_ivas->nSCE; n++ )
1443 : {
1444 6422 : st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ind_list = st_ivas->ind_list;
1445 6422 : st_ivas->hSCE[n]->hCoreCoder[0]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list;
1446 :
1447 6422 : if ( st_ivas->hSCE[n]->hMetaData != NULL )
1448 : {
1449 3681 : st_ivas->hSCE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata;
1450 3681 : st_ivas->hSCE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata;
1451 : }
1452 : }
1453 :
1454 13541 : FOR( n = 0; n < st_ivas->nCPE; n++ )
1455 : {
1456 19914 : FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
1457 : {
1458 13276 : st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ind_list = st_ivas->ind_list;
1459 13276 : st_ivas->hCPE[n]->hCoreCoder[ch]->hBstr->ivas_ind_list_zero = &st_ivas->ind_list;
1460 : }
1461 :
1462 6638 : IF( st_ivas->hCPE[n]->hMetaData != NULL )
1463 : {
1464 4435 : st_ivas->hCPE[n]->hMetaData->ind_list = st_ivas->ind_list_metadata;
1465 4435 : st_ivas->hCPE[n]->hMetaData->ivas_ind_list_zero = &st_ivas->ind_list_metadata;
1466 : }
1467 : }
1468 : }
1469 :
1470 427388 : test();
1471 427388 : IF( hIvasEnc->switchingActive && EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) )
1472 : {
1473 3100 : copy_encoder_config_fx( st_ivas, hCoreCoder, 0 );
1474 3100 : hEncoderConfig->last_ivas_total_brate = hEncoderConfig->ivas_total_brate;
1475 3100 : move32();
1476 : }
1477 :
1478 : /* run the main encoding routine */
1479 427388 : IF( EQ_32( hEncoderConfig->ivas_format, MONO_FORMAT ) ) /* EVS mono */
1480 : {
1481 3100 : hCoreCoder->total_brate = hEncoderConfig->ivas_total_brate; /* needed in case of bitrate switching */
1482 3100 : move32();
1483 :
1484 3100 : IF( EQ_16( hEncoderConfig->stereo_dmx_evs, 1 ) )
1485 : {
1486 2100 : inputBufferSize = shr( inputBufferSize, 1 );
1487 2100 : stereo_dmx_evs_enc_fx( st_ivas->hStereoDmxEVS, hEncoderConfig->input_Fs, inputBuffer, inputBufferSize, hEncoderConfig->is_binaural );
1488 : }
1489 :
1490 3100 : IF( hEncoderConfig->Opt_AMR_WB )
1491 : {
1492 0 : amr_wb_enc_fx( hCoreCoder, inputBuffer, inputBufferSize );
1493 : }
1494 : ELSE
1495 : {
1496 : #ifdef DEBUG_MODE_INFO
1497 : dbgwrite( inputBuffer, sizeof( int16_t ), inputBufferSize, 1, strcat( fname( debug_dir, "ivas_input_dmx", 0, 1, ENC ), ".pcm" ) );
1498 : #endif
1499 3100 : hCoreCoder->input_frame_fx = inputBufferSize;
1500 3100 : move32();
1501 3100 : IF( NE_32( ( error = evs_enc_fx( hCoreCoder, inputBuffer, hCoreCoder->mem_hp20_in_fx, inputBufferSize ) ), IVAS_ERR_OK ) )
1502 : {
1503 0 : return error;
1504 : }
1505 : }
1506 : }
1507 : ELSE /* IVAS */
1508 : {
1509 424288 : IF( NE_32( ( error = ivas_enc_fx( st_ivas, inputBuffer, inputBufferSize ) ), IVAS_ERR_OK ) ){
1510 0 : return error;
1511 : }
1512 : }
1513 :
1514 : /* write indices into bitstream buffer */
1515 : {
1516 427388 : write_indices_ivas_fx( st_ivas, outputBitStream, numOutBits );
1517 : }
1518 : /* Reset switching flag before next call - can be set to "true" by some setters */
1519 427388 : hIvasEnc->switchingActive = false;
1520 427388 : move16();
1521 :
1522 427388 : return error;
1523 : }
1524 :
1525 :
1526 : /*---------------------------------------------------------------------*
1527 : * IVAS_ENC_SetBandwidth()
1528 : *
1529 : *
1530 : *---------------------------------------------------------------------*/
1531 :
1532 21150 : ivas_error IVAS_ENC_SetBandwidth(
1533 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
1534 : const IVAS_ENC_BANDWIDTH maxBandwidth /* i : bandwidth limitation to be used */
1535 : )
1536 : {
1537 : ivas_error error;
1538 :
1539 : /* Do additional checks for user-facing function */
1540 21150 : IF( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK )
1541 : {
1542 0 : return error;
1543 : }
1544 :
1545 : /* Use internal function to set bandiwdth */
1546 21150 : return setBandwidth_fx( hIvasEnc, maxBandwidth );
1547 : }
1548 :
1549 :
1550 : /*---------------------------------------------------------------------*
1551 : * IVAS_ENC_SetBitrate()
1552 : *
1553 : *
1554 : *---------------------------------------------------------------------*/
1555 :
1556 58138 : ivas_error IVAS_ENC_SetBitrate(
1557 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
1558 : const Word32 totalBitrate /* i : requested bitrate of the output bitstream */
1559 : )
1560 : {
1561 : ivas_error error;
1562 :
1563 : /* Do additional checks for user-facing function */
1564 58138 : IF( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK )
1565 : {
1566 0 : return error;
1567 : }
1568 :
1569 : /* Use internal function to set bitrate */
1570 58138 : return setBitrate( hIvasEnc, totalBitrate );
1571 : }
1572 :
1573 :
1574 : /*---------------------------------------------------------------------*
1575 : * IVAS_ENC_SetChannelAwareConfig()
1576 : *
1577 : * Sets the configuration of channel-aware mode. Since CA mode is only
1578 : * supported at 13.2 kbps, this function has no effect at other bitrates.
1579 : *---------------------------------------------------------------------*/
1580 :
1581 0 : ivas_error IVAS_ENC_SetChannelAwareConfig(
1582 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
1583 : const IVAS_ENC_CHANNEL_AWARE_CONFIG rfConfig /* i : configuration of channel-aware mode */
1584 : )
1585 : {
1586 : ivas_error error;
1587 :
1588 : /* Do additional checks for user-facing function */
1589 0 : IF( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK )
1590 : {
1591 0 : return error;
1592 : }
1593 :
1594 : /* Use internal function to set CA config */
1595 0 : return setChannelAwareConfig_fx( hIvasEnc, rfConfig );
1596 : }
1597 :
1598 : #ifdef DEBUGGING
1599 : /*---------------------------------------------------------------------*
1600 : * IVAS_ENC_SetForcedMode()
1601 : *
1602 : *
1603 : *---------------------------------------------------------------------*/
1604 :
1605 : ivas_error IVAS_ENC_SetForcedMode(
1606 : IVAS_ENC_HANDLE hIvasEnc, /* i/o: IVAS encoder handle */
1607 : const IVAS_ENC_FORCED_MODE forcedMode /* i : forced coding mode */
1608 : #ifdef DEBUG_FORCE_DIR
1609 : ,
1610 : const char *forcedModeDir /* i : directory containing external binary files for modes/parameters enforcement */
1611 : #endif
1612 : )
1613 : {
1614 : int16_t newForced;
1615 : ivas_error error;
1616 :
1617 : /* Do additional checks for user-facing function */
1618 : if ( ( error = doCommonSetterChecks( hIvasEnc ) ) != IVAS_ERR_OK )
1619 : {
1620 : return error;
1621 : }
1622 :
1623 : #ifdef DEBUG_FORCE_DIR
1624 : hIvasEnc->st_ivas->hEncoderConfig->force_dir[0] = '\0';
1625 : if ( forcedMode < IVAS_ENC_FORCE_FILE )
1626 : {
1627 : if ( ( error = forcedModeApiToInternal( forcedMode, &newForced ) ) != IVAS_ERR_OK )
1628 : {
1629 : return error;
1630 : }
1631 :
1632 : if ( hIvasEnc->st_ivas->hEncoderConfig->force != newForced )
1633 : {
1634 : hIvasEnc->st_ivas->hEncoderConfig->force = newForced;
1635 : hIvasEnc->switchingActive = true;
1636 : }
1637 : }
1638 : else if ( forcedMode == IVAS_ENC_FORCE_DIR )
1639 : {
1640 : strcpy( hIvasEnc->st_ivas->hEncoderConfig->force_dir, forcedModeDir );
1641 : hIvasEnc->st_ivas->hEncoderConfig->force = IVAS_ENC_FORCE_UNFORCED;
1642 : }
1643 : #else
1644 : if ( ( error = forcedModeApiToInternal( forcedMode, &newForced ) ) != IVAS_ERR_OK )
1645 : {
1646 : return error;
1647 : }
1648 :
1649 : if ( hIvasEnc->st_ivas->hEncoderConfig->force != newForced )
1650 : {
1651 : hIvasEnc->st_ivas->hEncoderConfig->force = newForced;
1652 : hIvasEnc->switchingActive = true;
1653 : }
1654 : #endif
1655 :
1656 : return IVAS_ERR_OK;
1657 : }
1658 : #endif /* DEBUGGING */
1659 :
1660 : /*---------------------------------------------------------------------*
1661 : * IVAS_ENC_GetDefaultBandwidth()
1662 : *
1663 : *
1664 : *---------------------------------------------------------------------*/
1665 :
1666 448 : IVAS_ENC_BANDWIDTH IVAS_ENC_GetDefaultBandwidth( const bool isEVS )
1667 : {
1668 448 : IVAS_ENC_BANDWIDTH bwidth = IVAS_ENC_BANDWIDTH_FB;
1669 :
1670 448 : if ( isEVS )
1671 : {
1672 3 : bwidth = IVAS_ENC_BANDWIDTH_SWB;
1673 : }
1674 :
1675 448 : return bwidth;
1676 : }
1677 :
1678 :
1679 : /*---------------------------------------------------------------------*
1680 : * IVAS_ENC_GetDefaultDtxConfig()
1681 : *
1682 : *
1683 : *---------------------------------------------------------------------*/
1684 :
1685 627 : IVAS_ENC_DTX_CONFIG IVAS_ENC_GetDefaultDtxConfig( void )
1686 : {
1687 : IVAS_ENC_DTX_CONFIG defaultDtxConfig;
1688 627 : defaultDtxConfig.enabled = false;
1689 627 : defaultDtxConfig.SID_interval = 0;
1690 627 : move16();
1691 627 : defaultDtxConfig.variable_SID_rate = false;
1692 :
1693 627 : return defaultDtxConfig;
1694 : }
1695 :
1696 :
1697 : /*---------------------------------------------------------------------*
1698 : * IVAS_ENC_GetDefaultChannelAwareConfig()
1699 : *
1700 : *
1701 : *---------------------------------------------------------------------*/
1702 :
1703 1251 : IVAS_ENC_CHANNEL_AWARE_CONFIG IVAS_ENC_GetDefaultChannelAwareConfig( void )
1704 : {
1705 : IVAS_ENC_CHANNEL_AWARE_CONFIG defaultCaConfig;
1706 1251 : defaultCaConfig.channelAwareModeEnabled = 0;
1707 1251 : move16();
1708 1251 : defaultCaConfig.fec_indicator = IVAS_ENC_FEC_HI;
1709 1251 : move16();
1710 1251 : defaultCaConfig.fec_offset = 0;
1711 1251 : move16();
1712 :
1713 1251 : return defaultCaConfig;
1714 : }
1715 :
1716 :
1717 : /*---------------------------------------------------------------------*
1718 : * IVAS_ENC_GetErrorMessage()
1719 : *
1720 : *
1721 : *---------------------------------------------------------------------*/
1722 :
1723 0 : const char *IVAS_ENC_GetErrorMessage(
1724 : ivas_error error /* i : encoder error code enum */
1725 : )
1726 : {
1727 0 : return ivas_error_to_string( error );
1728 : }
1729 :
1730 :
1731 : /*---------------------------------------------------------------------*
1732 : * Local functions
1733 : *---------------------------------------------------------------------*/
1734 :
1735 627 : static ivas_error printConfigInfo_enc(
1736 : IVAS_ENC_HANDLE hIvasEnc,
1737 : const Word16 channelAwareModeEnabled )
1738 : {
1739 : Encoder_Struct *st_ivas;
1740 : ENCODER_CONFIG_HANDLE hEncoderConfig;
1741 : Word16 newBandwidthApi;
1742 : ivas_error error;
1743 :
1744 627 : st_ivas = hIvasEnc->st_ivas;
1745 627 : hEncoderConfig = st_ivas->hEncoderConfig;
1746 :
1747 : /*-----------------------------------------------------------------*
1748 : * Print input signal sampling frequency
1749 : *-----------------------------------------------------------------*/
1750 :
1751 627 : fprintf( stdout, "Input sampling rate: %d Hz\n", hEncoderConfig->input_Fs );
1752 :
1753 : /*-----------------------------------------------------------------*
1754 : * Print bitrate
1755 : *-----------------------------------------------------------------*/
1756 :
1757 627 : IF( st_ivas->hEncoderConfig->Opt_SC_VBR )
1758 : {
1759 0 : fprintf( stdout, "Average bitrate: %.2f kbps\n", (float) ACELP_5k90 / 1000 );
1760 : }
1761 : ELSE
1762 : {
1763 627 : fprintf( stdout, "Bitrate: %.2f kbps\n", (float) hEncoderConfig->ivas_total_brate / 1000 );
1764 : }
1765 :
1766 : /*-----------------------------------------------------------------*
1767 : * Print IVAS format
1768 : *-----------------------------------------------------------------*/
1769 :
1770 627 : IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) )
1771 : {
1772 3 : IF( hEncoderConfig->stereo_dmx_evs )
1773 : {
1774 2 : fprintf( stdout, "IVAS format: stereo downmix to bit-exact EVS mono\n" );
1775 : }
1776 : ELSE
1777 : {
1778 1 : fprintf( stdout, "IVAS format: bit-exact EVS mono\n" );
1779 : }
1780 : }
1781 624 : ELSE IF( hEncoderConfig->ivas_format == STEREO_FORMAT )
1782 : {
1783 : #ifdef DEBUGGING
1784 : if ( hEncoderConfig->stereo_mode_cmdl == 1 )
1785 : {
1786 : fprintf( stdout, "IVAS format: stereo - Unified stereo\n" );
1787 : }
1788 : else if ( hEncoderConfig->element_mode_init == IVAS_CPE_DFT )
1789 : {
1790 : fprintf( stdout, "IVAS format: stereo - DFT stereo\n" );
1791 : }
1792 : else if ( hEncoderConfig->element_mode_init == IVAS_CPE_TD )
1793 : {
1794 : fprintf( stdout, "IVAS format: stereo - TD stereo\n" );
1795 : }
1796 : else if ( hEncoderConfig->element_mode_init == IVAS_CPE_MDCT )
1797 : {
1798 : fprintf( stdout, "IVAS format: stereo - MDCT stereo\n" );
1799 : }
1800 : #else
1801 68 : if ( hEncoderConfig->element_mode_init != IVAS_CPE_MDCT )
1802 : {
1803 50 : fprintf( stdout, "IVAS format: stereo - Unified stereo\n" );
1804 : }
1805 : else
1806 : {
1807 18 : fprintf( stdout, "IVAS format: stereo - MDCT stereo\n" );
1808 : }
1809 : #endif
1810 : }
1811 556 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) )
1812 : {
1813 74 : test();
1814 74 : IF( LE_32( hEncoderConfig->ivas_total_brate, ACELP_32k ) && GT_16( hEncoderConfig->nchan_inp, 2 ) )
1815 : {
1816 17 : fprintf( stdout, "IVAS format: Param-ISM (%i streams)\n", hEncoderConfig->nchan_inp );
1817 : }
1818 : ELSE
1819 : {
1820 57 : fprintf( stdout, "IVAS format: ISM (%i streams)\n", hEncoderConfig->nchan_inp );
1821 : }
1822 : }
1823 482 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_FORMAT ) )
1824 : {
1825 244 : fprintf( stdout, "IVAS format: Scene Based Audio, Ambisonic order %i %s ", hEncoderConfig->sba_order, hEncoderConfig->sba_planar ? "(Planar)" : "" );
1826 244 : IF( hEncoderConfig->Opt_PCA_ON )
1827 : {
1828 4 : fprintf( stdout, "- PCA configured with signal adaptive decision " );
1829 : }
1830 :
1831 244 : fprintf( stdout, "\n" );
1832 : }
1833 238 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_FORMAT ) )
1834 : {
1835 75 : fprintf( stdout, "IVAS format: MASA format\n" );
1836 : }
1837 163 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, MC_FORMAT ) )
1838 : {
1839 82 : IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1 )
1840 : {
1841 43 : fprintf( stdout, "IVAS mode: Multi-Channel 5.1 \n" );
1842 : }
1843 39 : ELSE IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_7_1 )
1844 : {
1845 4 : fprintf( stdout, "IVAS mode: Multi-Channel 7.1 \n" );
1846 : }
1847 35 : ELSE IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_2 )
1848 : {
1849 6 : fprintf( stdout, "IVAS mode: Multi-Channel 5.1+2 \n" );
1850 : }
1851 29 : ELSE IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_5_1_4 )
1852 : {
1853 6 : fprintf( stdout, "IVAS mode: Multi-Channel 5.1+4\n" );
1854 : }
1855 23 : ELSE IF( hEncoderConfig->mc_input_setup == MC_LS_SETUP_7_1_4 )
1856 : {
1857 23 : fprintf( stdout, "IVAS mode: Multi-Channel 7.1+4\n" );
1858 : }
1859 : }
1860 81 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, SBA_ISM_FORMAT ) )
1861 : {
1862 37 : fprintf( stdout, "IVAS format: combined ISM and SBA (%i ISM stream(s))\n", hEncoderConfig->nchan_ism );
1863 : }
1864 44 : ELSE IF( EQ_16( hEncoderConfig->ivas_format, MASA_ISM_FORMAT ) )
1865 : {
1866 44 : fprintf( stdout, "IVAS format: combined ISM and MASA (%i ISM stream(s))\n", hEncoderConfig->nchan_ism );
1867 : }
1868 :
1869 627 : IF( hEncoderConfig->is_binaural )
1870 : {
1871 0 : fprintf( stdout, "Optional indication: binaural audio\n" );
1872 : }
1873 :
1874 : /*-----------------------------------------------------------------*
1875 : * Print CNG update interval, if DTX is activated
1876 : *-----------------------------------------------------------------*/
1877 :
1878 627 : IF( hEncoderConfig->Opt_DTX_ON )
1879 : {
1880 126 : IF( hEncoderConfig->var_SID_rate_flag )
1881 : {
1882 0 : fprintf( stdout, "DTX: ON, variable CNG update interval\n" );
1883 : }
1884 : ELSE
1885 : {
1886 126 : fprintf( stdout, "DTX: ON, CNG update interval = %d frames\n", hEncoderConfig->interval_SID );
1887 : }
1888 : }
1889 :
1890 : /*-----------------------------------------------------------------*
1891 : * Print potential limitation of audio bandwidth
1892 : *-----------------------------------------------------------------*/
1893 :
1894 627 : IF( ( error = bandwidthApiToInternal( hIvasEnc->newBandwidthApi, &newBandwidthApi ) ) != IVAS_ERR_OK )
1895 : {
1896 0 : return error;
1897 : }
1898 :
1899 627 : test();
1900 627 : IF( st_ivas->hEncoderConfig->Opt_SC_VBR && !hEncoderConfig->Opt_DTX_ON )
1901 : {
1902 0 : return IVAS_ERROR( IVAS_ERR_WRONG_PARAMS, "\nError: SC-VBR 5900 bps not supported without DTX\n\n" );
1903 : }
1904 :
1905 627 : IF( EQ_16( hEncoderConfig->ivas_format, MONO_FORMAT ) )
1906 : {
1907 3 : IF( NE_16( newBandwidthApi, hEncoderConfig->max_bwidth ) )
1908 : {
1909 0 : IF( EQ_16( newBandwidthApi, FB ) )
1910 : {
1911 0 : fprintf( stdout, "\nFB coding not supported below %.2f kbps. ", ACELP_16k40 / 1000.f );
1912 0 : IF( EQ_16( hEncoderConfig->max_bwidth, WB ) )
1913 : {
1914 0 : fprintf( stdout, "Switching to WB.\n" );
1915 : }
1916 : ELSE
1917 : {
1918 0 : fprintf( stdout, "Switching to SWB.\n" );
1919 : }
1920 : }
1921 0 : ELSE IF( EQ_16( newBandwidthApi, SWB ) )
1922 : {
1923 0 : fprintf( stdout, "\nSWB coding not supported below %.2f kbps. Switching to WB.\n", ACELP_9k60 / 1000.f );
1924 : }
1925 : }
1926 :
1927 : /* in case of 8kHz input sampling or "-max_band NB", require the total bitrate to be below 24.40 kbps */
1928 3 : test();
1929 3 : test();
1930 3 : IF( ( ( newBandwidthApi == NB ) || EQ_32( hEncoderConfig->input_Fs, 8000 ) ) && GT_32( hEncoderConfig->ivas_total_brate, ACELP_24k40 ) )
1931 : {
1932 0 : fprintf( stdout, "\nError: Unsupported mode NB %d bps, NB mode supports rates 5900-24400 bps\n\n", hEncoderConfig->ivas_total_brate );
1933 0 : return IVAS_ERR_INVALID_BITRATE;
1934 : }
1935 : }
1936 : ELSE
1937 : {
1938 624 : IF( NE_16( newBandwidthApi, hEncoderConfig->max_bwidth ) )
1939 : {
1940 105 : IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) )
1941 : {
1942 23 : fprintf( stdout, "\nFB coding not supported below %.2f kbps for %i objects. Switching to SWB.\n", hEncoderConfig->nchan_ism * MIN_BRATE_FB_ISM / 1000.f, hEncoderConfig->nchan_ism );
1943 : }
1944 : ELSE
1945 : {
1946 82 : fprintf( stdout, "\nFB coding not supported below %.2f kbps. Switching to SWB.\n", MIN_BRATE_FB_STEREO / 1000.f );
1947 : }
1948 : }
1949 : }
1950 :
1951 : /*-----------------------------------------------------------------*
1952 : * Print Channel-aware limitation
1953 : *-----------------------------------------------------------------*/
1954 :
1955 627 : IF( channelAwareModeEnabled )
1956 : {
1957 0 : IF( hEncoderConfig->Opt_RF_ON == 0 )
1958 : {
1959 0 : fprintf( stdout, "\nChannel-aware mode is supported at 13.2 kbps 32/48 kHz only. Switching to normal mode.\n" );
1960 : }
1961 : }
1962 :
1963 627 : return IVAS_ERR_OK;
1964 : }
1965 :
1966 :
1967 : /*---------------------------------------------------------------------*
1968 : * setBitrate()
1969 : *
1970 : *
1971 : *---------------------------------------------------------------------*/
1972 :
1973 58138 : static ivas_error setBitrate(
1974 : IVAS_ENC_HANDLE hIvasEnc,
1975 : const Word32 totalBitrate )
1976 : {
1977 : Encoder_Struct *st_ivas;
1978 : ENCODER_CONFIG_HANDLE hEncoderConfig;
1979 : ivas_error error;
1980 :
1981 58138 : st_ivas = hIvasEnc->st_ivas;
1982 58138 : hEncoderConfig = st_ivas->hEncoderConfig;
1983 :
1984 58138 : hEncoderConfig->ivas_total_brate = totalBitrate;
1985 58138 : hIvasEnc->switchingActive = true;
1986 58138 : move32();
1987 :
1988 : /* channel-aware mode is supported only at 13.20 kbps */
1989 58138 : test();
1990 58138 : IF( hEncoderConfig->Opt_RF_ON && NE_32( hEncoderConfig->ivas_total_brate, ACELP_13k20 ) )
1991 : {
1992 0 : assert( 0 && "\nChannel-aware mode is supported only at 13.20 kbps\n" );
1993 : hEncoderConfig->Opt_RF_ON = 0;
1994 : move16();
1995 : }
1996 :
1997 58138 : IF( EQ_32( hEncoderConfig->ivas_total_brate, ACELP_5k90 ) )
1998 : {
1999 0 : st_ivas->hEncoderConfig->Opt_SC_VBR = 1;
2000 0 : hEncoderConfig->ivas_total_brate = ACELP_7k20;
2001 0 : move16();
2002 0 : move32();
2003 : }
2004 : ELSE
2005 : {
2006 58138 : st_ivas->hEncoderConfig->Opt_SC_VBR = 0;
2007 58138 : move16();
2008 : }
2009 :
2010 : /* check if the entered bitrate is supported */
2011 58138 : IF( hEncoderConfig->element_mode_init > EVS_MONO )
2012 : {
2013 58138 : IF( !is_IVAS_bitrate_fx( hEncoderConfig->ivas_total_brate ) )
2014 : {
2015 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in IVAS: %d", hEncoderConfig->ivas_total_brate );
2016 : }
2017 : }
2018 : ELSE
2019 : {
2020 0 : IF( !is_EVS_bitrate( hEncoderConfig->ivas_total_brate, &hEncoderConfig->Opt_AMR_WB ) )
2021 : {
2022 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Incorrect bitrate specification in EVS mono: %d", hEncoderConfig->ivas_total_brate );
2023 : }
2024 :
2025 : /* in case of 8kHz signal, limit the total bitrate to 24.40 kbps */
2026 0 : test();
2027 0 : IF( EQ_32( hEncoderConfig->input_Fs, 8000 ) && GT_32( hEncoderConfig->ivas_total_brate, ACELP_24k40 ) )
2028 : {
2029 0 : hEncoderConfig->ivas_total_brate = ACELP_24k40;
2030 0 : move32();
2031 : }
2032 : }
2033 :
2034 58138 : IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) )
2035 : {
2036 10086 : IF( ( error = sanitizeBitrateISM_fx( hEncoderConfig, hIvasEnc->extMetadataApi ) ) != IVAS_ERR_OK )
2037 : {
2038 0 : return error;
2039 : }
2040 : }
2041 :
2042 58138 : st_ivas->codec_mode = MODE1;
2043 58138 : move16();
2044 :
2045 58138 : IF( hEncoderConfig->element_mode_init == EVS_MONO )
2046 : {
2047 0 : IF( hEncoderConfig->Opt_AMR_WB )
2048 : {
2049 0 : st_ivas->codec_mode = MODE1;
2050 0 : move16();
2051 : }
2052 : ELSE
2053 : {
2054 0 : st_ivas->codec_mode = get_codec_mode( hEncoderConfig->ivas_total_brate );
2055 0 : move16();
2056 : }
2057 : }
2058 :
2059 58138 : return IVAS_ERR_OK;
2060 : }
2061 :
2062 :
2063 : /*---------------------------------------------------------------------*
2064 : * setChannelAwareConfig()
2065 : *
2066 : *
2067 : *---------------------------------------------------------------------*/
2068 :
2069 627 : static ivas_error setChannelAwareConfig_fx(
2070 : IVAS_ENC_HANDLE hIvasEnc,
2071 : const IVAS_ENC_CHANNEL_AWARE_CONFIG caConfig )
2072 : {
2073 : Word16 newFecIndicator;
2074 : ivas_error error;
2075 : Encoder_Struct *st_ivas;
2076 : ENCODER_CONFIG_HANDLE hEncoderConfig;
2077 :
2078 627 : st_ivas = hIvasEnc->st_ivas;
2079 627 : hEncoderConfig = st_ivas->hEncoderConfig;
2080 :
2081 : /* channel-aware mode is supported only at 13.20 kbps and with WB or SWB bandwidth */
2082 627 : test();
2083 627 : test();
2084 627 : test();
2085 627 : IF( ( caConfig.channelAwareModeEnabled && NE_32( st_ivas->hEncoderConfig->ivas_total_brate, ACELP_13k20 ) ) || ( hEncoderConfig->Opt_RF_ON && EQ_32( hEncoderConfig->input_Fs, 8000 ) ) )
2086 : {
2087 0 : hEncoderConfig->Opt_RF_ON = 0;
2088 0 : move16();
2089 0 : hEncoderConfig->rf_fec_offset = 0;
2090 0 : move16();
2091 0 : return IVAS_ERR_OK;
2092 : }
2093 :
2094 627 : IF( caConfig.channelAwareModeEnabled )
2095 : {
2096 0 : hEncoderConfig->Opt_RF_ON = 1;
2097 0 : move16();
2098 :
2099 : /* Convert FEC indicator from API type */
2100 0 : IF( ( error = fecIndicatorApiToInternal( caConfig.fec_indicator, &newFecIndicator ) ) != IVAS_ERR_OK )
2101 : {
2102 0 : return error;
2103 : }
2104 :
2105 : /* Set new values only if they differ from current values */
2106 0 : test();
2107 0 : IF( ( NE_16( newFecIndicator, hEncoderConfig->rf_fec_indicator ) || NE_16( caConfig.fec_offset, hEncoderConfig->rf_fec_offset ) ) )
2108 : {
2109 0 : hEncoderConfig->rf_fec_indicator = newFecIndicator;
2110 0 : move16();
2111 :
2112 : /* Check if new FEC offset has a valid value */
2113 0 : test();
2114 0 : test();
2115 0 : test();
2116 0 : test();
2117 0 : IF( EQ_16( caConfig.fec_offset, 0 ) || EQ_16( caConfig.fec_offset, 2 ) || EQ_16( caConfig.fec_offset, 3 ) || EQ_16( caConfig.fec_offset, 5 ) || EQ_16( caConfig.fec_offset, 7 ) )
2118 : {
2119 0 : hEncoderConfig->rf_fec_offset = caConfig.fec_offset;
2120 0 : move16();
2121 : }
2122 : ELSE
2123 : {
2124 0 : return IVAS_ERR_INVALID_FEC_OFFSET;
2125 : }
2126 :
2127 0 : hIvasEnc->switchingActive = true;
2128 : }
2129 :
2130 : /* Save a copy of FEC offset value - needed during encoding */
2131 0 : hIvasEnc->rf_fec_offset_loc = hEncoderConfig->rf_fec_offset;
2132 0 : move16();
2133 : }
2134 : ELSE
2135 : {
2136 627 : hEncoderConfig->Opt_RF_ON = 0;
2137 627 : move16();
2138 : }
2139 :
2140 627 : return IVAS_ERR_OK;
2141 : }
2142 : /*---------------------------------------------------------------------*
2143 : * doCommonConfigureChecks()
2144 : *
2145 : *
2146 : *---------------------------------------------------------------------*/
2147 :
2148 627 : static ivas_error doCommonConfigureChecks(
2149 : IVAS_ENC_HANDLE hIvasEnc )
2150 : {
2151 627 : test();
2152 627 : IF( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL )
2153 : {
2154 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2155 : }
2156 :
2157 627 : IF( hIvasEnc->isConfigured )
2158 : {
2159 0 : return IVAS_ERR_RECONFIGURE_NOT_SUPPORTED;
2160 : }
2161 :
2162 627 : return IVAS_ERR_OK;
2163 : }
2164 :
2165 :
2166 : /*---------------------------------------------------------------------*
2167 : * doCommonSetterChecks()
2168 : *
2169 : *
2170 : *---------------------------------------------------------------------*/
2171 :
2172 79288 : static ivas_error doCommonSetterChecks(
2173 : IVAS_ENC_HANDLE hIvasEnc )
2174 : {
2175 79288 : test();
2176 79288 : IF( hIvasEnc == NULL || hIvasEnc->st_ivas == NULL )
2177 : {
2178 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2179 : }
2180 :
2181 : /* Currently settings can be changed only after configuration step */
2182 79288 : IF( !hIvasEnc->isConfigured )
2183 : {
2184 0 : return IVAS_ERR_NOT_CONFIGURED;
2185 : }
2186 :
2187 79288 : return IVAS_ERR_OK;
2188 : }
2189 :
2190 :
2191 : /*---------------------------------------------------------------------*
2192 : * sanitizeBandwidth()
2193 : *
2194 : *
2195 : *---------------------------------------------------------------------*/
2196 :
2197 428015 : static ivas_error sanitizeBandwidth_fx(
2198 : const IVAS_ENC_HANDLE hIvasEnc )
2199 : {
2200 : ENCODER_CONFIG_HANDLE hEncoderConfig;
2201 : Word16 max_bwidth_tmp;
2202 :
2203 428015 : hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig;
2204 :
2205 428015 : max_bwidth_tmp = hIvasEnc->newBandwidthApi;
2206 :
2207 : /* Prevent st_ivas->max_bwidth from being higher than Fs/2 */
2208 428015 : test();
2209 428015 : test();
2210 428015 : test();
2211 428015 : IF( EQ_32( hEncoderConfig->input_Fs, 8000 ) && ( max_bwidth_tmp > NB ) )
2212 : {
2213 0 : max_bwidth_tmp = NB;
2214 0 : move16();
2215 : }
2216 428015 : ELSE IF( EQ_32( hEncoderConfig->input_Fs, 16000 ) && GT_16( max_bwidth_tmp, WB ) )
2217 : {
2218 0 : max_bwidth_tmp = WB;
2219 0 : move16();
2220 : }
2221 428015 : ELSE IF( EQ_32( hEncoderConfig->input_Fs, 32000 ) && GT_16( max_bwidth_tmp, SWB ) )
2222 : {
2223 1351 : max_bwidth_tmp = SWB;
2224 1351 : move16();
2225 : }
2226 :
2227 : /* NB coding not supported in IVAS. Switching to WB. */
2228 428015 : test();
2229 428015 : test();
2230 428015 : IF( ( max_bwidth_tmp == NB ) && NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) )
2231 : {
2232 301 : IF( GE_32( hEncoderConfig->input_Fs, 16000 ) )
2233 : {
2234 301 : max_bwidth_tmp = WB;
2235 301 : move16();
2236 : }
2237 : ELSE
2238 : {
2239 0 : return IVAS_ERR_INVALID_BITRATE;
2240 : }
2241 : }
2242 :
2243 428015 : IF( NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) )
2244 : {
2245 424912 : Word32 quo = 0, rem;
2246 424912 : move32();
2247 424912 : IF( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) )
2248 : {
2249 103900 : iDiv_and_mod_32( hEncoderConfig->ivas_total_brate, hEncoderConfig->nchan_ism, &quo, &rem, 0 );
2250 : }
2251 :
2252 424912 : test();
2253 424912 : test();
2254 424912 : test();
2255 424912 : test();
2256 424912 : IF( EQ_16( max_bwidth_tmp, FB ) && ( ( NE_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( hEncoderConfig->ivas_total_brate, MIN_BRATE_FB_STEREO ) ) ||
2257 : ( EQ_16( hEncoderConfig->ivas_format, ISM_FORMAT ) && LT_32( quo, MIN_BRATE_FB_ISM ) ) ) )
2258 : {
2259 60973 : max_bwidth_tmp = SWB;
2260 60973 : move16();
2261 : }
2262 : }
2263 :
2264 428015 : IF( NE_16( hEncoderConfig->max_bwidth, max_bwidth_tmp ) )
2265 : {
2266 5109 : hEncoderConfig->max_bwidth = max_bwidth_tmp;
2267 5109 : move16();
2268 5109 : hIvasEnc->switchingActive = true;
2269 : }
2270 :
2271 428015 : return IVAS_ERR_OK;
2272 : }
2273 : /*---------------------------------------------------------------------*
2274 : * sanitizeBitrateISM_fx()
2275 : *
2276 : *
2277 : *---------------------------------------------------------------------*/
2278 :
2279 10160 : static ivas_error sanitizeBitrateISM_fx(
2280 : const ENCODER_CONFIG_HANDLE hEncoderConfig,
2281 : const bool extMetadataApi )
2282 : {
2283 10160 : test();
2284 10160 : IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_128k ) && EQ_16( hEncoderConfig->nchan_inp, 1 ) )
2285 : {
2286 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 1 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
2287 : }
2288 :
2289 10160 : test();
2290 10160 : IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_256k ) && EQ_16( hEncoderConfig->nchan_inp, 2 ) )
2291 : {
2292 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
2293 : }
2294 :
2295 10160 : test();
2296 10160 : IF( GT_32( hEncoderConfig->ivas_total_brate, IVAS_384k ) && EQ_16( hEncoderConfig->nchan_inp, 3 ) )
2297 : {
2298 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too high bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
2299 : }
2300 :
2301 10160 : test();
2302 10160 : IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_16k4 ) && EQ_16( hEncoderConfig->nchan_inp, 2 ) )
2303 : {
2304 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 2 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
2305 : }
2306 :
2307 10160 : test();
2308 10160 : IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 3 ) )
2309 : {
2310 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 3 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
2311 : }
2312 :
2313 10160 : test();
2314 10160 : IF( LT_32( hEncoderConfig->ivas_total_brate, IVAS_24k4 ) && EQ_16( hEncoderConfig->nchan_inp, 4 ) )
2315 : {
2316 0 : return IVAS_ERROR( IVAS_ERR_INVALID_BITRATE, "Too low bitrate for 4 ISM specified in IVAS: %d", hEncoderConfig->ivas_total_brate );
2317 : }
2318 :
2319 10160 : IF( extMetadataApi )
2320 : {
2321 1007 : hEncoderConfig->ism_extended_metadata_flag = (Word16) GE_32( hEncoderConfig->ivas_total_brate, ISM_EXTENDED_METADATA_BRATE );
2322 1007 : move16();
2323 : }
2324 : ELSE
2325 : {
2326 9153 : hEncoderConfig->ism_extended_metadata_flag = 0;
2327 9153 : move16();
2328 : }
2329 :
2330 10160 : return IVAS_ERR_OK;
2331 : }
2332 : /*---------------------------------------------------------------------*
2333 : * setBandwidth_fx()
2334 : *
2335 : *
2336 : *---------------------------------------------------------------------*/
2337 :
2338 21777 : static ivas_error setBandwidth_fx(
2339 : IVAS_ENC_HANDLE hIvasEnc,
2340 : const IVAS_ENC_BANDWIDTH maxBandwidth )
2341 : {
2342 : ivas_error error;
2343 : Word16 newBandwidth;
2344 : ENCODER_CONFIG_HANDLE hEncoderConfig;
2345 :
2346 21777 : hEncoderConfig = hIvasEnc->st_ivas->hEncoderConfig;
2347 :
2348 : /* Convert bandwidth from API type */
2349 21777 : IF( ( error = bandwidthApiToInternal( maxBandwidth, &newBandwidth ) ) != IVAS_ERR_OK )
2350 : {
2351 0 : return error;
2352 : }
2353 :
2354 21777 : hIvasEnc->newBandwidthApi = newBandwidth;
2355 :
2356 : /* NB coding not supported in IVAS. Switching to WB. */
2357 21777 : test();
2358 21777 : test();
2359 21777 : IF( ( newBandwidth == NB ) && NE_16( hEncoderConfig->ivas_format, UNDEFINED_FORMAT ) && NE_16( hEncoderConfig->ivas_format, MONO_FORMAT ) )
2360 : {
2361 301 : newBandwidth = WB;
2362 301 : move16();
2363 : }
2364 :
2365 21777 : IF( hEncoderConfig->max_bwidth != newBandwidth )
2366 : {
2367 3669 : hEncoderConfig->max_bwidth = newBandwidth;
2368 3669 : hIvasEnc->switchingActive = true;
2369 3669 : move16();
2370 : }
2371 :
2372 21777 : return IVAS_ERR_OK;
2373 : }
2374 :
2375 : /*---------------------------------------------------------------------*
2376 : * resetIsmMetadataProvidedFlags()
2377 : *
2378 : *
2379 : *---------------------------------------------------------------------*/
2380 :
2381 104453 : static void resetIsmMetadataProvidedFlags(
2382 : IVAS_ENC_HANDLE hIvasEnc )
2383 : {
2384 : Word16 i;
2385 :
2386 522265 : FOR( i = 0; i < MAX_NUM_OBJECTS; ++i )
2387 : {
2388 417812 : hIvasEnc->ismMetadataProvided[i] = false;
2389 : }
2390 :
2391 104453 : return;
2392 : }
2393 :
2394 :
2395 : /*---------------------------------------------------------------------*
2396 : * bandwidthApiToInternal()
2397 : *
2398 : *
2399 : *---------------------------------------------------------------------*/
2400 :
2401 22404 : static ivas_error bandwidthApiToInternal(
2402 : const IVAS_ENC_BANDWIDTH maxBandwidth,
2403 : Word16 *internalMaxBandwidth )
2404 : {
2405 22404 : SWITCH( maxBandwidth )
2406 : {
2407 302 : case IVAS_ENC_BANDWIDTH_NB:
2408 302 : *internalMaxBandwidth = NB;
2409 302 : BREAK;
2410 7340 : case IVAS_ENC_BANDWIDTH_WB:
2411 7340 : *internalMaxBandwidth = WB;
2412 7340 : BREAK;
2413 7306 : case IVAS_ENC_BANDWIDTH_SWB:
2414 7306 : *internalMaxBandwidth = SWB;
2415 7306 : BREAK;
2416 7456 : case IVAS_ENC_BANDWIDTH_FB:
2417 7456 : *internalMaxBandwidth = FB;
2418 7456 : BREAK;
2419 0 : case IVAS_ENC_BANDWIDTH_UNDEFINED:
2420 : default:
2421 0 : return IVAS_ERR_INVALID_BANDWIDTH;
2422 : }
2423 :
2424 22404 : return IVAS_ERR_OK;
2425 : }
2426 :
2427 :
2428 : /*---------------------------------------------------------------------*
2429 : * fecIndicatorApiToInternal()
2430 : *
2431 : *
2432 : *---------------------------------------------------------------------*/
2433 :
2434 0 : static ivas_error fecIndicatorApiToInternal(
2435 : const IVAS_ENC_FEC_INDICATOR fecIndicator,
2436 : Word16 *fecIndicatorInternal )
2437 : {
2438 0 : SWITCH( fecIndicator )
2439 : {
2440 0 : case IVAS_ENC_FEC_LO:
2441 0 : *fecIndicatorInternal = 0;
2442 0 : BREAK;
2443 0 : case IVAS_ENC_FEC_HI:
2444 0 : *fecIndicatorInternal = 1;
2445 0 : BREAK;
2446 0 : default:
2447 0 : return IVAS_ERR_INTERNAL;
2448 : }
2449 :
2450 0 : return IVAS_ERR_OK;
2451 : }
2452 :
2453 : #ifdef DEBUGGING
2454 : /*---------------------------------------------------------------------*
2455 : * forcedModeApiToInternal()
2456 : *
2457 : *
2458 : *---------------------------------------------------------------------*/
2459 :
2460 : static ivas_error forcedModeApiToInternal(
2461 : IVAS_ENC_FORCED_MODE forcedMode,
2462 : int16_t *forcedModeInternal )
2463 : {
2464 : switch ( forcedMode )
2465 : {
2466 : case IVAS_ENC_FORCE_SPEECH:
2467 : *forcedModeInternal = FORCE_SPEECH;
2468 : break;
2469 : case IVAS_ENC_FORCE_MUSIC:
2470 : *forcedModeInternal = FORCE_MUSIC;
2471 : break;
2472 : case IVAS_ENC_FORCE_ACELP:
2473 : *forcedModeInternal = FORCE_ACELP;
2474 : break;
2475 : case IVAS_ENC_FORCE_GSC:
2476 : *forcedModeInternal = FORCE_GSC;
2477 : break;
2478 : #ifdef SUPPORT_FORCE_TCX10_TCX20
2479 : case IVAS_ENC_FORCE_TCX10:
2480 : *forcedModeInternal = FORCE_TCX10;
2481 : break;
2482 : case IVAS_ENC_FORCE_TCX20:
2483 : *forcedModeInternal = FORCE_TCX20;
2484 : break;
2485 : #else
2486 : case IVAS_ENC_FORCE_TCX:
2487 : *forcedModeInternal = FORCE_TCX;
2488 : break;
2489 : #endif
2490 : case IVAS_ENC_FORCE_HQ:
2491 : *forcedModeInternal = FORCE_HQ;
2492 : break;
2493 : case IVAS_ENC_FORCE_UNFORCED:
2494 : *forcedModeInternal = -1;
2495 : break;
2496 : default:
2497 : return IVAS_ERR_INVALID_FORCE_MODE;
2498 : break;
2499 : }
2500 :
2501 : return IVAS_ERR_OK;
2502 : }
2503 : #endif
2504 :
2505 : /*---------------------------------------------------------------------*
2506 : * IVAS_ENC_PrintConfig()
2507 : *
2508 : *
2509 : *---------------------------------------------------------------------*/
2510 :
2511 627 : ivas_error IVAS_ENC_PrintConfig(
2512 : const IVAS_ENC_HANDLE hIvasEnc, /* i : IVAS encoder handle */
2513 : const Word16 channelAwareModeEnabled /* i : channel-aware mode enabled flag */
2514 : )
2515 : {
2516 627 : return printConfigInfo_enc( hIvasEnc, channelAwareModeEnabled );
2517 : }
2518 :
2519 :
2520 : /*---------------------------------------------------------------------*
2521 : * IVAS_ENC_PrintDisclaimer()
2522 : *
2523 : * Print IVAS disclaimer to console
2524 : *---------------------------------------------------------------------*/
2525 :
2526 627 : void IVAS_ENC_PrintDisclaimer( void )
2527 : {
2528 627 : print_disclaimer( stderr );
2529 :
2530 627 : return;
2531 : }
2532 :
2533 :
2534 : /*---------------------------------------------------------------------*
2535 : * init_encoder_config()
2536 : *
2537 : * Initialize Encoder Config. handle
2538 : *---------------------------------------------------------------------*/
2539 :
2540 627 : static void init_encoder_config(
2541 : ENCODER_CONFIG_HANDLE hEncoderConfig /* o : configuration structure */
2542 : )
2543 : {
2544 627 : hEncoderConfig->ivas_total_brate = ACELP_12k65;
2545 627 : move32();
2546 627 : hEncoderConfig->max_bwidth = SWB;
2547 627 : move16();
2548 627 : hEncoderConfig->input_Fs = 16000;
2549 627 : move32();
2550 627 : hEncoderConfig->nchan_inp = 1;
2551 627 : move16();
2552 627 : hEncoderConfig->element_mode_init = EVS_MONO;
2553 627 : move16();
2554 627 : hEncoderConfig->ivas_format = UNDEFINED_FORMAT;
2555 627 : move16();
2556 627 : hEncoderConfig->is_binaural = 0;
2557 627 : move16();
2558 627 : hEncoderConfig->Opt_SC_VBR = 0;
2559 627 : move16();
2560 627 : hEncoderConfig->last_Opt_SC_VBR = 0;
2561 627 : move16();
2562 627 : hEncoderConfig->Opt_AMR_WB = 0;
2563 627 : move16();
2564 627 : hEncoderConfig->Opt_DTX_ON = 0;
2565 627 : move16();
2566 627 : hEncoderConfig->Opt_RF_ON = 0;
2567 627 : move16();
2568 627 : hEncoderConfig->rf_fec_offset = 0;
2569 627 : move16();
2570 627 : hEncoderConfig->rf_fec_indicator = 1;
2571 627 : move16();
2572 627 : hEncoderConfig->interval_SID = FIXED_SID_RATE;
2573 627 : move16();
2574 627 : hEncoderConfig->var_SID_rate_flag = 1;
2575 627 : move16();
2576 627 : hEncoderConfig->mc_input_setup = MC_LS_SETUP_INVALID;
2577 627 : move16();
2578 627 : hEncoderConfig->stereo_dmx_evs = 0;
2579 627 : move16();
2580 627 : hEncoderConfig->nchan_ism = 0;
2581 627 : move16();
2582 627 : hEncoderConfig->sba_order = 0;
2583 627 : move16();
2584 627 : hEncoderConfig->sba_planar = 0;
2585 627 : move16();
2586 627 : hEncoderConfig->ism_extended_metadata_flag = 0;
2587 627 : move16();
2588 : #ifdef DEBUGGING
2589 : hEncoderConfig->stereo_mode_cmdl = 0;
2590 : hEncoderConfig->force = -1;
2591 : hEncoderConfig->mdct_stereo_mode_cmdl = SMDCT_MS_DECISION;
2592 : #endif
2593 627 : hEncoderConfig->Opt_PCA_ON = 0;
2594 627 : move16();
2595 :
2596 627 : return;
2597 : }
|