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