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 "lib_dec.h"
34 : #include <math.h>
35 : #include <assert.h>
36 : #include <string.h>
37 : #include "ivas_cnst.h"
38 : #include "ivas_prot_rend_fx.h"
39 : #include "prot_fx.h"
40 : #include "ivas_prot_fx.h"
41 :
42 : #include "jbm_jb4sb.h"
43 : #include "jbm_pcmdsp_apa.h"
44 : #include "jbm_pcmdsp_fifo.h"
45 : #include <math.h>
46 : #include <assert.h>
47 : #include "wmc_auto.h"
48 :
49 : #define INV_1000_Q31 2147484 /*1/1000 IN Q31*/
50 :
51 : /*---------------------------------------------------------------------*
52 : * Local structs
53 : *---------------------------------------------------------------------*/
54 : struct IVAS_DEC_VOIP
55 : {
56 : UWord16 nSamplesFrame; /* Total number of samples in a frame (includes number of channels) */
57 : JB4_HANDLE hJBM;
58 : UWord16 lastDecodedWasActive;
59 : JB4_DATAUNIT_HANDLE hCurrentDataUnit; /* Points to the currently processed data unit */
60 : UWord16 *bs_conversion_buf; /* Buffer for bitstream conversion from packed to serial */
61 : #ifdef SUPPORT_JBM_TRACEFILE
62 : IVAS_JBM_TRACE_DATA JbmTraceData;
63 : #endif
64 : };
65 :
66 : typedef struct IVAS_DEC_VOIP IVAS_DEC_VOIP;
67 :
68 : struct IVAS_DEC
69 : {
70 : IVAS_DEC_MODE mode;
71 : UWord16 nSamplesFrame;
72 : Decoder_Struct *st_ivas;
73 : IVAS_DEC_VOIP *hVoIP;
74 : bool hasBeenFedFirstGoodFrame; /* False on init. Gets set to true after first good frame has been fed into the decoder, but not decoded yet. */
75 : bool hasDecodedFirstGoodFrame; /* False on init. Gets set to true after first good frame has been decoded -> all bitstream information is known from that point on */
76 : bool isInitialized;
77 :
78 : Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */
79 : bool Opt_VOIP; /* flag indicating VOIP mode with JBM */
80 : Word16 tsm_scale; /* scale for TSM operation */
81 : Word16 tsm_max_scaling;
82 : Word32 *apaExecBuffer_fx; /* Buffer for APA scaling */
83 : Word16 tsm_quality; /*Q14*/
84 : PCMDSP_APA_HANDLE hTimeScaler;
85 : bool needNewFrame;
86 : bool hasBeenFedFrame;
87 : bool updateOrientation;
88 : UWord16 nSamplesAvailableNext;
89 : Word16 nSamplesRendered;
90 : Word16 nTransportChannelsOld;
91 : Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */
92 : Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */
93 : Word16 prev_ft_speech; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */
94 : Word16 CNG; /* RXDTX handler: CNG=1, nonCNG=0 */
95 : };
96 :
97 : /*---------------------------------------------------------------------*
98 : * Local function declarations
99 : *---------------------------------------------------------------------*/
100 :
101 : static void IVAS_DEC_Close_VoIP( IVAS_DEC_VOIP *hVoIP );
102 : #ifdef SUPPORT_JBM_TRACEFILE
103 : static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, const UWord32 systemTimestamp_ms, const UWord16 extBufferedSamples, const Word32 output_Fs );
104 : #endif
105 : static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSamples, Word32 *floatBuf, Word16 *pcmBuf );
106 : static ivas_error input_format_API_to_internal( IVAS_DEC_INPUT_FORMAT input_format, Word16 *bitstream_format_internal, Word16 *sdp_hf_only, const bool is_voip_enabled );
107 : static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig );
108 : static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const UWord16 nTransportChannels, const UWord16 l_ts );
109 : static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, UWord16 *nTcBufferGranularity, UWord8 *nTransportChannels, UWord8 *nOutChannels, UWord16 *nSamplesRendered, Word16 *data );
110 : static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, Word32 *pcmBuf_fx, Word16 *nOutSamples );
111 : static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *pcmBuf );
112 : static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const UWord16 nSamplesForRendering, UWord16 *nSamplesRendered, UWord16 *nSamplesAvailableNext, Word16 *pcmBuf );
113 : static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, Word16 *nSamplesBuffered );
114 : static Word16 get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize );
115 :
116 :
117 : /*---------------------------------------------------------------------*
118 : * IVAS_DEC_Open()
119 : *
120 : * Open IVAS decoder
121 : *---------------------------------------------------------------------*/
122 :
123 : /* may return an error but may still have allocated memory - thus run Close also in case of error to release memory */
124 604 : ivas_error IVAS_DEC_Open(
125 : IVAS_DEC_HANDLE *phIvasDec, /* i/o: pointer to an IVAS decoder handle to be opened */
126 : const IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */
127 : )
128 : {
129 : IVAS_DEC_HANDLE hIvasDec;
130 : Decoder_Struct *st_ivas;
131 :
132 604 : IF( phIvasDec == NULL )
133 : {
134 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
135 : }
136 :
137 : /*-----------------------------------------------------------------*
138 : * Allocate and initialize IVAS application decoder handle
139 : *-----------------------------------------------------------------*/
140 :
141 604 : IF( ( *phIvasDec = (IVAS_DEC_HANDLE) malloc( sizeof( struct IVAS_DEC ) ) ) == NULL )
142 : {
143 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" );
144 : }
145 604 : hIvasDec = *phIvasDec;
146 604 : hIvasDec->hVoIP = NULL;
147 604 : hIvasDec->apaExecBuffer_fx = NULL;
148 604 : hIvasDec->hTimeScaler = NULL;
149 604 : hIvasDec->tsm_scale = 100;
150 604 : hIvasDec->tsm_max_scaling = 0;
151 604 : hIvasDec->tsm_quality = ONE_IN_Q14; /*1.f Q14*/
152 604 : hIvasDec->needNewFrame = false;
153 604 : hIvasDec->nTransportChannelsOld = 0;
154 604 : hIvasDec->nSamplesAvailableNext = 0;
155 604 : hIvasDec->nSamplesRendered = 0;
156 604 : hIvasDec->nSamplesFrame = 0;
157 604 : hIvasDec->hasBeenFedFrame = false;
158 604 : hIvasDec->hasBeenFedFirstGoodFrame = false;
159 604 : hIvasDec->hasDecodedFirstGoodFrame = false;
160 604 : hIvasDec->isInitialized = false;
161 604 : hIvasDec->updateOrientation = false;
162 604 : move16();
163 604 : move16();
164 604 : move16();
165 604 : move16();
166 604 : move16();
167 604 : move16();
168 604 : move16();
169 604 : move16();
170 604 : move16();
171 604 : move16();
172 604 : move16();
173 604 : move16();
174 :
175 604 : hIvasDec->mode = mode;
176 604 : move16();
177 :
178 604 : hIvasDec->bitstreamformat = G192;
179 604 : hIvasDec->Opt_VOIP = 0;
180 604 : hIvasDec->amrwb_rfc4867_flag = -1;
181 604 : hIvasDec->prev_ft_speech = 1; /* RXDTX handler previous frametype flag for G.192 format AMRWB SID_FIRST detection */
182 604 : hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/
183 604 : move16();
184 604 : move16();
185 604 : move16();
186 604 : move16();
187 604 : move16();
188 : /*-----------------------------------------------------------------*
189 : * Initialize IVAS-codec decoder state
190 : *-----------------------------------------------------------------*/
191 :
192 604 : IF( ( hIvasDec->st_ivas = (Decoder_Struct *) malloc( sizeof( Decoder_Struct ) ) ) == NULL )
193 : {
194 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder structure" );
195 : }
196 :
197 604 : IF( ( hIvasDec->st_ivas->hDecoderConfig = (DECODER_CONFIG_HANDLE) malloc( sizeof( DECODER_CONFIG ) ) ) == NULL )
198 : {
199 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Decoder config structure" );
200 : }
201 :
202 : /*-----------------------------------------------------------------*
203 : * Initialize IVAS-codec decoder state
204 : *-----------------------------------------------------------------*/
205 :
206 604 : st_ivas = hIvasDec->st_ivas;
207 :
208 : /* initialize Decoder Config. handle */
209 604 : init_decoder_config( hIvasDec->st_ivas->hDecoderConfig );
210 :
211 : /* initialize pointers to handles to NULL */
212 604 : ivas_initialize_handles_dec( st_ivas );
213 :
214 : /* set high-level parameters */
215 604 : IF( EQ_16( mode, IVAS_DEC_MODE_EVS ) )
216 : {
217 3 : st_ivas->codec_mode = 0; /* unknown before first frame */
218 3 : st_ivas->element_mode_init = EVS_MONO;
219 3 : st_ivas->ivas_format = MONO_FORMAT;
220 3 : st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID;
221 3 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID;
222 3 : st_ivas->writeFECoffset = 0;
223 3 : hIvasDec->hasDecodedFirstGoodFrame = true; /* Functionality to suppress output for initial lost frames is disabled in EVS operation */
224 3 : move16();
225 3 : move16();
226 3 : move16();
227 3 : move16();
228 3 : move16();
229 3 : move16();
230 3 : move16();
231 :
232 3 : return IVAS_ERR_OK;
233 : }
234 601 : ELSE IF( EQ_16( mode, IVAS_DEC_MODE_IVAS ) )
235 : {
236 601 : st_ivas->codec_mode = 0; /* unknown before first frame */
237 601 : st_ivas->element_mode_init = -1;
238 601 : st_ivas->ivas_format = UNDEFINED_FORMAT;
239 601 : st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID;
240 601 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID;
241 601 : st_ivas->renderer_type = RENDERER_DISABLE;
242 601 : st_ivas->ini_frame = 0;
243 601 : st_ivas->ini_active_frame = 0;
244 601 : st_ivas->writeFECoffset = 0;
245 :
246 601 : st_ivas->ism_mode = ISM_MODE_NONE;
247 601 : st_ivas->mc_mode = MC_MODE_NONE;
248 :
249 601 : st_ivas->sba_order = 0;
250 601 : st_ivas->sba_planar = 0;
251 601 : st_ivas->sba_analysis_order = 0;
252 :
253 601 : move16();
254 601 : move16();
255 601 : move16();
256 601 : move16();
257 601 : move16();
258 601 : move16();
259 601 : move16();
260 601 : move16();
261 601 : move16();
262 601 : move16();
263 601 : move16();
264 601 : move16();
265 601 : move16();
266 601 : move16();
267 601 : return IVAS_ERR_OK;
268 : }
269 :
270 0 : return IVAS_ERR_WRONG_PARAMS;
271 : }
272 :
273 :
274 : /*---------------------------------------------------------------------*
275 : * init_decoder_config()
276 : *
277 : * Initialize Decoder Config. handle
278 : *---------------------------------------------------------------------*/
279 :
280 604 : static void init_decoder_config(
281 : DECODER_CONFIG_HANDLE hDecoderConfig /* i/o: configuration structure */
282 : )
283 : {
284 604 : hDecoderConfig->Opt_AMR_WB = 0;
285 604 : hDecoderConfig->nchan_out = 1;
286 604 : hDecoderConfig->output_config = IVAS_AUDIO_CONFIG_INVALID;
287 604 : hDecoderConfig->Opt_LsCustom = 0;
288 604 : hDecoderConfig->Opt_HRTF_binary = 0;
289 604 : hDecoderConfig->Opt_Headrotation = 0;
290 604 : hDecoderConfig->Opt_RendConfigCustom = 0;
291 604 : hDecoderConfig->orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE;
292 604 : hDecoderConfig->Opt_non_diegetic_pan = 0;
293 604 : hDecoderConfig->non_diegetic_pan_gain_fx = 0; // Q15
294 604 : hDecoderConfig->Opt_tsm = 0;
295 604 : hDecoderConfig->Opt_delay_comp = 0;
296 604 : hDecoderConfig->Opt_ExternalOrientation = 0;
297 604 : hDecoderConfig->Opt_dpid_on = 0;
298 604 : hDecoderConfig->Opt_aeid_on = 0;
299 604 : move16();
300 604 : move16();
301 604 : move16();
302 604 : move16();
303 604 : move16();
304 604 : move16();
305 604 : move16();
306 604 : move16();
307 604 : move16();
308 604 : move16();
309 604 : move16();
310 604 : move16();
311 604 : move16();
312 604 : move16();
313 604 : move16();
314 604 : return;
315 : }
316 :
317 :
318 : /*---------------------------------------------------------------------*
319 : * IVAS_DEC_Close( )
320 : *
321 : *
322 : *---------------------------------------------------------------------*/
323 :
324 620 : void IVAS_DEC_Close(
325 : IVAS_DEC_HANDLE *phIvasDec /* i/o: pointer to IVAS decoder handle */
326 : )
327 : {
328 : /* Free all memory */
329 620 : test();
330 620 : IF( phIvasDec == NULL || *phIvasDec == NULL )
331 : {
332 16 : return;
333 : }
334 :
335 604 : IF( ( *phIvasDec )->hVoIP )
336 : {
337 27 : IVAS_DEC_Close_VoIP( ( *phIvasDec )->hVoIP );
338 27 : ( *phIvasDec )->hVoIP = NULL;
339 : }
340 :
341 604 : IF( ( *phIvasDec )->st_ivas )
342 : {
343 604 : ivas_destroy_dec_fx( ( *phIvasDec )->st_ivas );
344 604 : ( *phIvasDec )->st_ivas = NULL;
345 : }
346 :
347 604 : apa_exit( &( *phIvasDec )->hTimeScaler );
348 :
349 604 : IF( ( *phIvasDec )->apaExecBuffer_fx != NULL )
350 : {
351 27 : free( ( *phIvasDec )->apaExecBuffer_fx );
352 : }
353 604 : free( *phIvasDec );
354 604 : *phIvasDec = NULL;
355 604 : phIvasDec = NULL;
356 :
357 604 : return;
358 : }
359 :
360 :
361 : /*---------------------------------------------------------------------*
362 : * mapIvasFormat( )
363 : *
364 : *
365 : *---------------------------------------------------------------------*/
366 :
367 44 : static IVAS_DEC_BS_FORMAT mapIvasFormat(
368 : const IVAS_FORMAT ivas_format )
369 : {
370 44 : SWITCH( ivas_format )
371 : {
372 0 : case MONO_FORMAT:
373 0 : return IVAS_DEC_BS_MONO;
374 0 : case STEREO_FORMAT:
375 0 : return IVAS_DEC_BS_STEREO;
376 15 : case ISM_FORMAT:
377 15 : return IVAS_DEC_BS_OBJ;
378 0 : case MC_FORMAT:
379 0 : return IVAS_DEC_BS_MC;
380 6 : case SBA_FORMAT:
381 6 : return IVAS_DEC_BS_SBA;
382 3 : case SBA_ISM_FORMAT:
383 3 : return IVAS_DEC_BS_SBA_ISM;
384 17 : case MASA_FORMAT:
385 17 : return IVAS_DEC_BS_MASA;
386 3 : case MASA_ISM_FORMAT:
387 3 : return IVAS_DEC_BS_MASA_ISM;
388 0 : default:
389 0 : BREAK;
390 : }
391 :
392 0 : return IVAS_DEC_BS_UNKOWN;
393 : }
394 :
395 :
396 : /*---------------------------------------------------------------------*
397 : * IVAS_DEC_Configure( )
398 : *
399 : * Decoder configuration
400 : * legacy code behavior: if no output format set, then it's EVS mono
401 : *---------------------------------------------------------------------*/
402 :
403 604 : ivas_error IVAS_DEC_Configure(
404 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
405 : const UWord32 sampleRate, /* i : output sampling frequency */
406 : const AUDIO_CONFIG outputConfig, /* i : output configuration */
407 : const Word16 tsmEnabled, /* i : enable time scale modification */
408 : const IVAS_RENDER_FRAMESIZE renderFramesize, /* i : rendering frame size */
409 : const Word16 customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */
410 : const Word16 hrtfReaderEnabled, /* i : enable HRTF binary file input */
411 : const Word16 enableHeadRotation, /* i : enable head rotation for binaural output */
412 : const Word16 enableExternalOrientation, /* i : enable external orientations */
413 : const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */
414 : const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */
415 : const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */
416 : const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain Q15 */
417 : const Word16 Opt_dpid_on, /* i : enable directivity pattern option */
418 : const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */
419 : const Word16 delayCompensationEnabled /* i : enable delay compensation */
420 : )
421 : {
422 : Decoder_Struct *st_ivas;
423 : DECODER_CONFIG_HANDLE hDecoderConfig;
424 : ivas_error error;
425 :
426 604 : error = IVAS_ERR_OK;
427 604 : move32();
428 604 : test();
429 604 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
430 : {
431 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
432 : }
433 :
434 604 : test();
435 604 : test();
436 604 : test();
437 604 : IF( NE_32( sampleRate, 8000 ) && NE_32( sampleRate, 16000 ) && NE_32( sampleRate, 32000 ) && NE_32( sampleRate, 48000 ) )
438 : {
439 0 : return IVAS_ERR_WRONG_PARAMS;
440 : }
441 :
442 604 : test();
443 604 : test();
444 604 : test();
445 604 : test();
446 604 : IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) && !( ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MONO ) && Opt_non_diegetic_pan == 0 ) ||
447 : ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_STEREO ) && EQ_16( Opt_non_diegetic_pan, 1 ) ) ) )
448 : {
449 0 : return IVAS_ERR_WRONG_MODE;
450 : }
451 :
452 604 : st_ivas = hIvasDec->st_ivas;
453 :
454 604 : hDecoderConfig = st_ivas->hDecoderConfig;
455 :
456 604 : hDecoderConfig->output_config = outputConfig;
457 604 : move16();
458 604 : IF( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_INVALID ) )
459 : {
460 0 : return IVAS_ERR_WRONG_PARAMS;
461 : }
462 :
463 604 : hDecoderConfig->output_Fs = sampleRate;
464 604 : move32();
465 604 : IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
466 : {
467 3 : st_ivas->element_mode_init = EVS_MONO;
468 3 : hDecoderConfig->nchan_out = 1;
469 3 : move16();
470 3 : move16();
471 : }
472 :
473 604 : test();
474 604 : IF( NE_16( outputConfig, IVAS_AUDIO_CONFIG_EXTERNAL ) && NE_16( outputConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
475 : {
476 551 : hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config );
477 551 : move16();
478 : }
479 :
480 604 : hDecoderConfig->Opt_tsm = tsmEnabled;
481 604 : hDecoderConfig->Opt_LsCustom = customLsOutputEnabled;
482 604 : hDecoderConfig->Opt_Headrotation = enableHeadRotation;
483 604 : hDecoderConfig->orientation_tracking = orientation_tracking;
484 604 : hDecoderConfig->Opt_HRTF_binary = hrtfReaderEnabled;
485 604 : hDecoderConfig->Opt_RendConfigCustom = renderConfigEnabled;
486 604 : hDecoderConfig->Opt_non_diegetic_pan = Opt_non_diegetic_pan;
487 604 : hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; // Q15
488 604 : hDecoderConfig->Opt_delay_comp = delayCompensationEnabled;
489 604 : hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation;
490 604 : hDecoderConfig->Opt_dpid_on = Opt_dpid_on;
491 604 : IF( NE_32( (Word32) acousticEnvironmentId, 65535 ) )
492 : {
493 1 : hDecoderConfig->Opt_aeid_on = TRUE;
494 : }
495 : ELSE
496 : {
497 603 : hDecoderConfig->Opt_aeid_on = FALSE;
498 : }
499 604 : move16();
500 604 : move16();
501 604 : move16();
502 604 : move16();
503 604 : move16();
504 604 : move16();
505 604 : move16();
506 604 : move16();
507 604 : move16();
508 604 : move16();
509 604 : move16();
510 :
511 604 : IF( EQ_16( renderFramesize, IVAS_RENDER_FRAMESIZE_UNKNOWN ) )
512 : {
513 0 : return IVAS_ERR_WRONG_PARAMS;
514 : }
515 604 : IF( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_EXTERNAL ) )
516 : {
517 50 : hDecoderConfig->render_framesize = IVAS_RENDER_FRAMESIZE_20MS;
518 : }
519 : ELSE
520 : {
521 554 : hDecoderConfig->render_framesize = renderFramesize;
522 : }
523 :
524 604 : move16();
525 :
526 : /* Set decoder parameters to initial values */
527 604 : IF( NE_32( ( error = ivas_init_decoder_front( st_ivas ) ), IVAS_ERR_OK ) )
528 : {
529 0 : return error;
530 : }
531 :
532 604 : if ( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
533 : {
534 3 : hIvasDec->st_ivas->ivas_format = MONO_FORMAT;
535 3 : move16();
536 : }
537 :
538 604 : hIvasDec->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 );
539 604 : hIvasDec->nSamplesAvailableNext = 0;
540 604 : hIvasDec->nSamplesRendered = 0;
541 604 : hIvasDec->tsm_scale = 100;
542 604 : hIvasDec->tsm_max_scaling = 0;
543 604 : hIvasDec->tsm_quality = ONE_IN_Q14 /*1.0f Q14*/;
544 604 : move16();
545 604 : move16();
546 604 : move16();
547 604 : move16();
548 604 : move16();
549 :
550 604 : return error;
551 : }
552 :
553 :
554 : /*---------------------------------------------------------------------*
555 : * get_render_framesize_ms( )
556 : *
557 : * Get the 5ms flag
558 : *---------------------------------------------------------------------*/
559 :
560 220 : Word16 get_render_frame_size_ms(
561 : const IVAS_RENDER_FRAMESIZE render_framesize )
562 : {
563 220 : IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
564 : {
565 0 : return ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) );
566 : }
567 220 : ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
568 : {
569 0 : return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 1 );
570 : }
571 220 : ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
572 : {
573 220 : return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 2 );
574 : }
575 0 : return 0;
576 : }
577 :
578 :
579 : /*---------------------------------------------------------------------*
580 : * IVAS_DEC_SetRenderFramesize( )
581 : *
582 : * Get the 5ms flag
583 : *---------------------------------------------------------------------*/
584 :
585 0 : ivas_error IVAS_DEC_SetRenderFramesize(
586 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
587 : const IVAS_RENDER_FRAMESIZE render_framesize /* i : render framesize */
588 : )
589 : {
590 0 : test();
591 0 : test();
592 0 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hDecoderConfig == NULL )
593 : {
594 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
595 : }
596 :
597 0 : hIvasDec->st_ivas->hDecoderConfig->render_framesize = render_framesize;
598 0 : move16();
599 :
600 0 : return IVAS_ERR_OK;
601 : }
602 :
603 : /*---------------------------------------------------------------------*
604 : * IVAS_DEC_GetGetRenderFramesize( )
605 : *
606 : * Get the 5ms flag
607 : *---------------------------------------------------------------------*/
608 :
609 604 : ivas_error IVAS_DEC_GetRenderFramesize(
610 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
611 : IVAS_RENDER_FRAMESIZE *render_framesize /* o : render framesize */
612 : )
613 : {
614 604 : test();
615 604 : test();
616 604 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL )
617 : {
618 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
619 : }
620 :
621 604 : *render_framesize = hIvasDec->st_ivas->hDecoderConfig->render_framesize;
622 604 : move16();
623 :
624 604 : return IVAS_ERR_OK;
625 : }
626 :
627 : /*---------------------------------------------------------------------*
628 : * IVAS_DEC_GetGetRenderFramesizeSamples( )
629 : *
630 : * Get render framesize in samples
631 : *---------------------------------------------------------------------*/
632 :
633 600 : ivas_error IVAS_DEC_GetRenderFramesizeSamples(
634 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
635 : Word16 *render_framesize /* o : render framesize in samples Q0 */
636 : )
637 : {
638 : Word16 tmp;
639 600 : test();
640 600 : test();
641 600 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL )
642 : {
643 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
644 : }
645 :
646 600 : tmp = (Word16) Mpy_32_16_1( hIvasDec->st_ivas->hDecoderConfig->output_Fs, INV_FR_P_S_MX_PRM_SPL_SBFR_Q15 );
647 :
648 600 : IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
649 : {
650 0 : *render_framesize = tmp;
651 : }
652 600 : ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
653 : {
654 0 : *render_framesize = shl( tmp, 1 );
655 : }
656 600 : ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
657 : {
658 600 : *render_framesize = shl( tmp, 2 );
659 : }
660 : ELSE
661 : {
662 0 : *render_framesize = 0;
663 : }
664 600 : move16();
665 :
666 600 : return IVAS_ERR_OK;
667 : }
668 :
669 : /*---------------------------------------------------------------------*
670 : * IVAS_DEC_GetGetRenderFramesizeMs( )
671 : *
672 : * Get render framesize in milliseconds
673 : *---------------------------------------------------------------------*/
674 :
675 27 : ivas_error IVAS_DEC_GetRenderFramesizeMs(
676 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
677 : UWord32 *render_framesize /* o : render framesize in samples Q0 */
678 : )
679 : {
680 27 : test();
681 27 : test();
682 27 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL )
683 : {
684 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
685 : }
686 :
687 27 : *render_framesize = get_render_frame_size_ms( hIvasDec->st_ivas->hDecoderConfig->render_framesize );
688 27 : move32();
689 :
690 27 : return IVAS_ERR_OK;
691 : }
692 :
693 : /*---------------------------------------------------------------------*
694 : * IVAS_DEC_GetGetReferencesUpdateFrequency( )
695 : *
696 : * Get update frequency of the reference vector/orientation
697 : *---------------------------------------------------------------------*/
698 :
699 600 : ivas_error IVAS_DEC_GetReferencesUpdateFrequency(
700 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
701 : Word16 *update_frequency /* o : update frequency Q0 */
702 : )
703 : {
704 600 : test();
705 600 : test();
706 600 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || update_frequency == NULL )
707 : {
708 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
709 : }
710 :
711 600 : IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
712 : {
713 0 : *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES;
714 0 : move16();
715 : }
716 600 : ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
717 : {
718 0 : *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 1;
719 0 : move16();
720 : }
721 600 : ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
722 : {
723 600 : *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 2;
724 600 : move16();
725 : }
726 :
727 600 : return IVAS_ERR_OK;
728 : }
729 :
730 : /*---------------------------------------------------------------------*
731 : * IVAS_DEC_GetGetNumOrientationSubframes( )
732 : *
733 : * Get the number of subframes for head/ecernal orientation per render frame
734 : *---------------------------------------------------------------------*/
735 :
736 400769 : ivas_error IVAS_DEC_GetNumOrientationSubframes(
737 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
738 : Word16 *num_subframes /* o : render framesize */
739 : )
740 : {
741 400769 : test();
742 400769 : test();
743 400769 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || num_subframes == NULL )
744 : {
745 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
746 : }
747 :
748 400769 : *num_subframes = (Word16) hIvasDec->st_ivas->hDecoderConfig->render_framesize;
749 400769 : move16();
750 :
751 400769 : return IVAS_ERR_OK;
752 : }
753 :
754 :
755 : /*---------------------------------------------------------------------*
756 : * IVAS_DEC_EnableVoIP( )
757 : *
758 : * Intitialize JBM
759 : * jbmSafetyMargin: allowed delay reserve in addition to network jitter
760 : * to reduce late-loss, default: 60 [milliseconds]
761 : *---------------------------------------------------------------------*/
762 :
763 27 : ivas_error IVAS_DEC_EnableVoIP(
764 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
765 : const Word16 jbmSafetyMargin, /* i : allowed delay reserve for JBM, in milliseconds */
766 : const IVAS_DEC_INPUT_FORMAT inputFormat /* i : format of the input bitstream */
767 : )
768 : {
769 : DECODER_CONFIG_HANDLE hDecoderConfig;
770 : ivas_error error;
771 :
772 27 : error = IVAS_ERR_OK;
773 27 : move32();
774 :
775 27 : test();
776 27 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
777 : {
778 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
779 : }
780 :
781 27 : hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;
782 :
783 27 : hIvasDec->Opt_VOIP = 1;
784 27 : hDecoderConfig->Opt_tsm = 1;
785 27 : move16();
786 27 : move16();
787 27 : IF( NE_16( (Word16) hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
788 : {
789 23 : hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config );
790 23 : move16();
791 : }
792 :
793 27 : IF( NE_32( ( error = input_format_API_to_internal( inputFormat, &hIvasDec->bitstreamformat, &hIvasDec->sdp_hf_only, true ) ), IVAS_ERR_OK ) )
794 : {
795 0 : return error;
796 : }
797 :
798 27 : IF( ( hIvasDec->hVoIP = malloc( sizeof( IVAS_DEC_VOIP ) ) ) == NULL )
799 : {
800 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
801 : }
802 :
803 27 : hIvasDec->hVoIP->lastDecodedWasActive = 0;
804 27 : move16();
805 27 : hIvasDec->hVoIP->hCurrentDataUnit = NULL;
806 27 : hIvasDec->hVoIP->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 );
807 27 : move16();
808 :
809 : #define WMC_TOOL_SKIP
810 : /* Bitstream conversion is not counted towards complexity and memory usage */
811 27 : hIvasDec->hVoIP->bs_conversion_buf = malloc( sizeof( UWord16 ) * ( MAX_BITS_PER_FRAME + 4 * 8 ) );
812 : #undef WMC_TOOL_SKIP
813 :
814 27 : IF( hIvasDec->hVoIP->bs_conversion_buf == NULL )
815 : {
816 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
817 : }
818 :
819 : /* initialize JBM */
820 27 : IF( NE_32( ( error = JB4_Create( &hIvasDec->hVoIP->hJBM ) != IVAS_ERR_OK ), IVAS_ERR_OK ) )
821 : {
822 0 : return error;
823 : }
824 :
825 27 : IF( JB4_Init( hIvasDec->hVoIP->hJBM, jbmSafetyMargin ) != 0 )
826 : {
827 0 : return IVAS_ERR_FAILED_ALLOC;
828 : }
829 :
830 27 : return error;
831 : }
832 :
833 :
834 : /*---------------------------------------------------------------------*
835 : * IVAS_DEC_FeedFrame_Serial( )
836 : *
837 : *
838 : *---------------------------------------------------------------------*/
839 :
840 399985 : ivas_error IVAS_DEC_FeedFrame_Serial(
841 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
842 : UWord16 *serial, /* i : buffer containing serial input bitstream. Each bit should be stored as a single uint16_t value */
843 : const UWord16 num_bits, /* i : number of bits in input bitstream */
844 : Word16 bfi /* i : bad frame indicator flag */
845 : )
846 : {
847 : ivas_error error;
848 :
849 399985 : IF( !hIvasDec->isInitialized )
850 : {
851 : /* Once first frame is fed, finish initialization in EVS Mono.
852 : * In IVAS mode, initialization is done in ivas_dec(). */
853 600 : IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
854 : {
855 3 : IF( NE_32( ( error = ivas_init_decoder_fx( hIvasDec->st_ivas ) ), IVAS_ERR_OK ) )
856 : {
857 0 : return error;
858 : }
859 3 : Word32 ivas_total_brate = hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate;
860 3 : move32();
861 3 : test();
862 3 : IF( ( EQ_16( hIvasDec->st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_16( hIvasDec->st_ivas->mc_mode, MC_MODE_PARAMMC ) ) )
863 : {
864 : MC_LS_SETUP mc_ls_setup;
865 0 : mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( hIvasDec->st_ivas->transport_config );
866 0 : hIvasDec->st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
867 : }
868 :
869 3 : test();
870 3 : IF( hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL )
871 0 : {
872 0 : DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
873 0 : st->ini_frame = 0;
874 0 : st->prev_use_partial_copy = 0;
875 0 : move16();
876 0 : move16();
877 0 : hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = imult3216( hIvasDec->hVoIP->hCurrentDataUnit->dataSize, FRAMES_PER_SEC );
878 0 : move32();
879 : }
880 : ELSE
881 : {
882 3 : hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = ACELP_8k00;
883 3 : move32();
884 : }
885 3 : hIvasDec->isInitialized = true;
886 3 : move16();
887 : }
888 : }
889 :
890 399985 : if ( !bfi ) /* TODO(mcjbm): Is this ok for bfi == 2 (partial frame)? Is there enough info to fully configure decoder? */
891 : {
892 390021 : hIvasDec->hasBeenFedFirstGoodFrame = true;
893 390021 : move16();
894 : }
895 :
896 : /* Update redundant frame information in EVS (pre- read indices) */
897 399985 : test();
898 399985 : test();
899 399985 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) && hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL )
900 : {
901 0 : DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
902 0 : st->bit_stream = serial;
903 :
904 0 : test();
905 0 : IF( hIvasDec->hVoIP->hCurrentDataUnit->partial_frame || st->prev_use_partial_copy )
906 : {
907 0 : st->next_coder_type = hIvasDec->hVoIP->hCurrentDataUnit->nextCoderType;
908 : }
909 : ELSE
910 : {
911 0 : st->next_coder_type = INACTIVE;
912 : }
913 0 : move16();
914 :
915 0 : test();
916 0 : if ( EQ_16( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame, 1 ) && NE_16( bfi, 1 ) )
917 : {
918 0 : bfi = 2;
919 0 : move16();
920 : }
921 : }
922 :
923 399985 : IF( NE_32( ( error = read_indices_fx( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ), IVAS_ERR_OK ) )
924 : {
925 0 : return error;
926 : }
927 :
928 : /* Update redundant frame information in EVS (post- read indices) */
929 399985 : test();
930 399985 : test();
931 399985 : test();
932 399985 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) &&
933 : hIvasDec->hVoIP != NULL &&
934 : hIvasDec->hVoIP->hCurrentDataUnit != NULL &&
935 : ( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame != 0 ) )
936 : {
937 0 : DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
938 0 : st->codec_mode = MODE2;
939 0 : st->use_partial_copy = 1;
940 0 : move16();
941 0 : move16();
942 : }
943 :
944 399985 : hIvasDec->needNewFrame = false;
945 399985 : hIvasDec->hasBeenFedFrame = true;
946 399985 : hIvasDec->nSamplesRendered = 0;
947 399985 : hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;
948 399985 : move16();
949 399985 : move16();
950 399985 : move16();
951 399985 : move16();
952 :
953 399985 : return IVAS_ERR_OK;
954 : }
955 :
956 :
957 : /*---------------------------------------------------------------------*
958 : * IVAS_DEC_GetSamples( )
959 : *
960 : * Main function to decode to PCM data
961 : *---------------------------------------------------------------------*/
962 :
963 :
964 411975 : ivas_error IVAS_DEC_GetSamples(
965 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
966 : const Word16 nSamplesAsked, /* i : number of samples wanted by the caller */
967 : Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */
968 : Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */
969 : bool *needNewFrame /* o :indication that the decoder needs a new frame */
970 : )
971 : {
972 : ivas_error error;
973 : Word16 nOutSamplesElse, nSamplesToRender;
974 : UWord16 nSamplesRendered, nSamplesRendered_loop, l_ts, nTimeScalerOutSamples;
975 : UWord8 nTransportChannels, nOutChannels;
976 :
977 411975 : nSamplesRendered = 0;
978 411975 : nOutChannels = 0;
979 411975 : nSamplesRendered_loop = 0;
980 411975 : l_ts = 0;
981 411975 : nTransportChannels = 0;
982 411975 : move16();
983 411975 : move16();
984 411975 : move16();
985 411975 : move16();
986 411975 : move16();
987 :
988 411975 : test();
989 411975 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
990 : {
991 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
992 : }
993 :
994 411975 : IF( hIvasDec->updateOrientation )
995 : {
996 : /*----------------------------------------------------------------*
997 : * Combine orientations
998 : *----------------------------------------------------------------*/
999 :
1000 69350 : IF( NE_32( ( error = combine_external_and_head_orientations_dec( hIvasDec->st_ivas->hHeadTrackData, hIvasDec->st_ivas->hExtOrientationData, hIvasDec->st_ivas->hCombinedOrientationData ) ), IVAS_ERR_OK ) )
1001 : {
1002 0 : return error;
1003 : }
1004 69350 : hIvasDec->updateOrientation = false;
1005 69350 : move16();
1006 : }
1007 :
1008 411975 : test();
1009 411975 : IF( !hIvasDec->hasBeenFedFrame && hIvasDec->nSamplesAvailableNext == 0 )
1010 : {
1011 : /* no frame was fed, do nothing but ask for a frame */
1012 0 : *needNewFrame = true;
1013 0 : *nOutSamples = 0;
1014 0 : hIvasDec->needNewFrame = true;
1015 0 : move16();
1016 0 : move16();
1017 0 : move16();
1018 0 : return IVAS_ERR_OK;
1019 : }
1020 :
1021 411975 : test();
1022 : /* check if we are still at the beginning with bad frames, put out zeroes, keep track of subframes */
1023 411975 : IF( !hIvasDec->isInitialized && hIvasDec->st_ivas->bfi )
1024 : {
1025 0 : hIvasDec->hasBeenFedFrame = false;
1026 0 : move16();
1027 0 : set16_fx( pcmBuf, 0, imult1616( hIvasDec->st_ivas->hDecoderConfig->nchan_out, nSamplesAsked ) );
1028 0 : hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesAsked );
1029 0 : move16();
1030 0 : *nOutSamples = nSamplesAsked;
1031 0 : move16();
1032 0 : hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesAsked );
1033 0 : move16();
1034 0 : IF( hIvasDec->nSamplesAvailableNext == 0 )
1035 : {
1036 0 : hIvasDec->needNewFrame = true;
1037 0 : *needNewFrame = true;
1038 0 : move16();
1039 0 : move16();
1040 : }
1041 : }
1042 : ELSE
1043 : {
1044 : /* check if we need to run the setup function */
1045 411975 : test();
1046 411975 : IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ){
1047 : /* setup */
1048 :
1049 399985 : IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ){
1050 6 : return error;
1051 : }
1052 : }
1053 : {
1054 : /* check if we need to run the setup function, tc decoding and feeding the renderer */
1055 411969 : test();
1056 411969 : IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame )
1057 : {
1058 : Word16 nResidualSamples, nSamplesTcsScaled;
1059 399979 : nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
1060 :
1061 399979 : test();
1062 399979 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && NE_16( (Word16) nTransportChannels, hIvasDec->nTransportChannelsOld ) )
1063 : {
1064 953 : IF( NE_32( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ), IVAS_ERR_OK ) )
1065 : {
1066 0 : return error;
1067 : }
1068 : }
1069 :
1070 : /* IVAS decoder */
1071 399979 : IF( NE_32( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ), IVAS_ERR_OK ) )
1072 : {
1073 0 : return error;
1074 : }
1075 :
1076 : /* JBM */
1077 399979 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
1078 : {
1079 19405 : IF( apa_set_scale_fx( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 )
1080 : {
1081 0 : return IVAS_ERR_UNKNOWN;
1082 : }
1083 :
1084 : // tmp apaExecBuffer
1085 19405 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
1086 : {
1087 : Word16 tmp_apaExecBuffer[APA_BUF];
1088 0 : FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i )
1089 : {
1090 0 : tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0
1091 : }
1092 0 : IF( apa_exec_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 )
1093 : {
1094 0 : return IVAS_ERR_UNKNOWN;
1095 : }
1096 0 : FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i )
1097 : {
1098 0 : hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11
1099 : }
1100 : }
1101 : ELSE
1102 : {
1103 19405 : IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, hIvasDec->apaExecBuffer_fx, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, hIvasDec->apaExecBuffer_fx, &nTimeScalerOutSamples ) != 0 )
1104 : {
1105 0 : return IVAS_ERR_UNKNOWN;
1106 : }
1107 : }
1108 19405 : assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) );
1109 19405 : nSamplesTcsScaled = idiv1616U( extract_l( nTimeScalerOutSamples ), nTransportChannels );
1110 : }
1111 : ELSE
1112 : {
1113 380574 : nSamplesTcsScaled = hIvasDec->nSamplesFrame;
1114 380574 : move16();
1115 : }
1116 :
1117 : /* Feed decoded transport channels samples to the renderer */
1118 399979 : IF( NE_32( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer_fx ) ), IVAS_ERR_OK ) )
1119 : {
1120 0 : return error;
1121 : }
1122 :
1123 399979 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
1124 : {
1125 : /* feed residual samples to TSM for the next call */
1126 19405 : IF( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ) != 0 )
1127 : {
1128 0 : return IVAS_ERR_UNKNOWN;
1129 : }
1130 : }
1131 399979 : hIvasDec->hasBeenFedFrame = false;
1132 399979 : move16();
1133 : }
1134 :
1135 : /* render IVAS frames directly to the output buffer */
1136 411969 : nSamplesToRender = sub( nSamplesAsked, nSamplesRendered );
1137 411969 : IF( NE_32( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) )
1138 : {
1139 0 : return error;
1140 : }
1141 :
1142 411969 : nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
1143 411969 : nSamplesToRender = sub( nSamplesToRender, nSamplesRendered_loop );
1144 411969 : IF( hIvasDec->nSamplesAvailableNext == 0 )
1145 : {
1146 399959 : *needNewFrame = true;
1147 399959 : hIvasDec->needNewFrame = true;
1148 399959 : move16();
1149 399959 : move16();
1150 : }
1151 : ELSE
1152 : {
1153 12010 : *needNewFrame = false;
1154 12010 : move16();
1155 : }
1156 : }
1157 : }
1158 :
1159 411969 : *nOutSamples = nSamplesRendered;
1160 411969 : move16();
1161 :
1162 411969 : return IVAS_ERR_OK;
1163 : }
1164 :
1165 :
1166 : /*---------------------------------------------------------------------*
1167 : * IVAS_DEC_Setup( )
1168 : *
1169 : *
1170 : *---------------------------------------------------------------------*/
1171 :
1172 399985 : static ivas_error IVAS_DEC_Setup(
1173 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1174 : UWord16 *nTcBufferGranularity, /* o : granularity of the TC Buffer */
1175 : UWord8 *nTransportChannels, /* o : number of decoded transport PCM channels */
1176 : UWord8 *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */
1177 : UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame */
1178 : Word16 *data /* o : output synthesis signal Q0 */
1179 : )
1180 : {
1181 : ivas_error error;
1182 :
1183 399985 : *nSamplesRendered = 0;
1184 399985 : move16();
1185 :
1186 399985 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
1187 : {
1188 3100 : IF( EQ_16( (Word16) hIvasDec->st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
1189 : {
1190 1000 : *nTransportChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN;
1191 1000 : *nOutChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN;
1192 : }
1193 : ELSE
1194 : {
1195 2100 : *nTransportChannels = 1;
1196 2100 : *nOutChannels = 1;
1197 : }
1198 3100 : move16();
1199 3100 : move16();
1200 : }
1201 : ELSE
1202 : {
1203 : Decoder_Struct *st_ivas;
1204 :
1205 396885 : st_ivas = hIvasDec->st_ivas;
1206 :
1207 : /*----------------------------------------------------------------*
1208 : * IVAS decoder setup
1209 : * - read IVAS format signaling
1210 : * - read IVAS format specific signaling
1211 : * - initialize decoder in the first frame based on IVAS format and number of transport channels
1212 : * - reconfigure the decoder when the number of TC or IVAS total bitrate change
1213 : *----------------------------------------------------------------*/
1214 :
1215 396885 : IF( st_ivas->bfi == 0 )
1216 : {
1217 : Word32 ivas_total_brate;
1218 388320 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
1219 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
1220 388320 : Word16 num_src = 0;
1221 388320 : move16();
1222 :
1223 388320 : test();
1224 388320 : test();
1225 388320 : test();
1226 388320 : test();
1227 388320 : test();
1228 388320 : test();
1229 388320 : test();
1230 388320 : test();
1231 388320 : test();
1232 388320 : IF( is_DTXrate( ivas_total_brate ) == 0 && ( !( st_ivas->ini_active_frame == 0 && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) ) && st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] && st_ivas->ivas_format == MASA_FORMAT && st_ivas->last_ivas_format != MASA_FORMAT && ( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 ) )
1233 : {
1234 0 : IF( st_ivas->hSpar )
1235 : {
1236 0 : Word16 Q_tmp = getScaleFactor16( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16 );
1237 0 : Scale_sig( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16, sub( Q_tmp, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ) );
1238 0 : st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_tmp;
1239 : }
1240 : }
1241 :
1242 388320 : test();
1243 388320 : test();
1244 388320 : test();
1245 388320 : test();
1246 388320 : test();
1247 388320 : IF( is_DTXrate( ivas_total_brate ) == 0 && EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && GT_16( st_ivas->ini_frame, 0 ) && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 )
1248 : {
1249 0 : IF( st_ivas->hSpar )
1250 : {
1251 0 : Word16 Q_tmp = getScaleFactor16( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16 );
1252 0 : Scale_sig( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16, sub( Q_tmp, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ) );
1253 0 : st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_tmp;
1254 0 : move16();
1255 : }
1256 : }
1257 :
1258 388320 : IF( NE_32( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
1259 : {
1260 6 : return error;
1261 : }
1262 388314 : test();
1263 388314 : IF( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMMC ) )
1264 : {
1265 : MC_LS_SETUP mc_ls_setup;
1266 8750 : mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
1267 8750 : st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
1268 : }
1269 :
1270 388314 : test();
1271 388314 : test();
1272 388314 : test();
1273 388314 : test();
1274 388314 : test();
1275 388314 : test();
1276 388314 : IF( is_DTXrate( ivas_total_brate ) == 0 && ( !( st_ivas->ini_active_frame == 0 && NE_32( ivas_total_brate, FRAME_NO_DATA ) && LT_32( ivas_total_brate, MASA_STEREO_MIN_BITRATE ) && EQ_16( st_ivas->nCPE, 1 ) ) ) && st_ivas->bit_stream[( ivas_total_brate / FRAMES_PER_SEC ) - 1] && st_ivas->ivas_format == MASA_FORMAT && ( ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) || st_ivas->ini_active_frame == 0 ) )
1277 : {
1278 1047 : IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1279 : {
1280 0 : Word16 nchan_rend = num_src;
1281 0 : IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1282 : {
1283 0 : nchan_rend--; /* Skip LFE channel -- added to the others */
1284 : }
1285 0 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
1286 : {
1287 0 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
1288 0 : IF( Src_p->SrcSpatial_p != NULL )
1289 : {
1290 0 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
1291 0 : move16();
1292 : }
1293 0 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
1294 0 : SrcSpatial_p->q_Pos_p = Q31;
1295 0 : move16();
1296 : }
1297 : }
1298 : }
1299 :
1300 :
1301 388314 : test();
1302 388314 : test();
1303 388314 : test();
1304 388314 : test();
1305 388314 : test();
1306 388314 : IF( is_DTXrate( ivas_total_brate ) == 0 && EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) && st_ivas->ini_frame > 0 && ( GT_32( ivas_total_brate, IVAS_SID_5k2 ) && NE_32( ivas_total_brate, st_ivas->hDecoderConfig->last_ivas_total_brate ) ) && st_ivas->ini_active_frame == 0 )
1307 : {
1308 0 : IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1309 : {
1310 0 : Word16 nchan_rend = num_src;
1311 0 : test();
1312 0 : IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1313 : {
1314 0 : nchan_rend--; /* Skip LFE channel -- added to the others */
1315 : }
1316 0 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
1317 : {
1318 0 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
1319 0 : IF( Src_p->SrcSpatial_p != NULL )
1320 : {
1321 0 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
1322 0 : move16();
1323 : }
1324 0 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
1325 0 : SrcSpatial_p->q_Pos_p = Q31;
1326 0 : move16();
1327 : }
1328 : }
1329 : }
1330 : }
1331 :
1332 396879 : *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm;
1333 396879 : *nTcBufferGranularity = (UWord16) st_ivas->hTcBuffer->n_samples_granularity;
1334 396879 : *nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out;
1335 396879 : move16();
1336 396879 : move16();
1337 396879 : move16();
1338 : }
1339 :
1340 399979 : return IVAS_ERR_OK;
1341 : }
1342 :
1343 :
1344 : /*---------------------------------------------------------------------*
1345 : * IVAS_DEC_GetTcSamples( )
1346 : *
1347 : * Main function to decode to PCM data of the transport channels
1348 : *---------------------------------------------------------------------*/
1349 :
1350 399979 : static ivas_error IVAS_DEC_GetTcSamples(
1351 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1352 : Word32 *pcmBuf_fx, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q11 */
1353 : Word16 *nOutSamples /* o : number of samples per channel written to output buffer */
1354 : )
1355 : {
1356 : Decoder_Struct *st_ivas;
1357 : ivas_error error;
1358 :
1359 :
1360 399979 : test();
1361 399979 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1362 : {
1363 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1364 : }
1365 :
1366 399979 : st_ivas = hIvasDec->st_ivas;
1367 :
1368 399979 : *nOutSamples = (Word16) Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 );
1369 399979 : move16();
1370 :
1371 399979 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
1372 : {
1373 3100 : IF( NE_32( ( error = evs_dec_main_fx( st_ivas, *nOutSamples, pcmBuf_fx, NULL ) ), IVAS_ERR_OK ) )
1374 : {
1375 0 : return error;
1376 : }
1377 : }
1378 396879 : ELSE IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_IVAS ) )
1379 : {
1380 : /* run the main IVAS decoding routine */
1381 : /*------------------------flt 2 fix----------------------*/
1382 : Word16 n;
1383 : Decoder_State *st, **sts; /* used for bitstream handling */
1384 : Word16 nCPE, cpe_id;
1385 396879 : nCPE = st_ivas->nCPE;
1386 :
1387 396879 : IF( st_ivas->hDecoderConfig->Opt_tsm == 0 )
1388 : {
1389 2735838 : FOR( n = 0; n < ivas_get_nchan_buffers_dec_ivas_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ )
1390 : {
1391 2358364 : set32_fx( st_ivas->p_output_fx[n], 0, L_FRAME48k );
1392 2358364 : st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; // Q11
1393 : }
1394 : }
1395 :
1396 :
1397 : CPE_DEC_HANDLE hCPE;
1398 396879 : test();
1399 396879 : test();
1400 396879 : test();
1401 396879 : test();
1402 396879 : test();
1403 396879 : IF( ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) || EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) || ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) && ( GT_16( st_ivas->nCPE, 1 ) ) )
1404 : {
1405 :
1406 93116 : nCPE = st_ivas->nCPE;
1407 93116 : move16();
1408 334254 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1409 : {
1410 241138 : hCPE = st_ivas->hCPE[cpe_id];
1411 241138 : sts = hCPE->hCoreCoder;
1412 :
1413 :
1414 723414 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1415 : {
1416 482276 : st = hCPE->hCoreCoder[n];
1417 482276 : IF( st->hTcxDec )
1418 482276 : st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi;
1419 482276 : IF( st->hTcxDec )
1420 482276 : st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi;
1421 : }
1422 : }
1423 : }
1424 :
1425 : /* Function call: ivas_jbm_dec_tc function */
1426 396879 : IF( NE_32( ( error = ivas_jbm_dec_tc_fx( st_ivas, pcmBuf_fx ) ), IVAS_ERR_OK ) )
1427 : {
1428 0 : return error;
1429 : }
1430 :
1431 396879 : hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */
1432 :
1433 396879 : test();
1434 396879 : test();
1435 396879 : test();
1436 396879 : test();
1437 396879 : test();
1438 396879 : test();
1439 396879 : IF( ( EQ_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) || EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) || ( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_FORMAT ) ) || EQ_32( st_ivas->mc_mode, MC_MODE_PARAMMC ) ) && ( GT_16( st_ivas->nCPE, 1 ) ) )
1440 : {
1441 334254 : FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
1442 : {
1443 241138 : hCPE = st_ivas->hCPE[cpe_id];
1444 241138 : sts = hCPE->hCoreCoder;
1445 723414 : FOR( n = 0; n < 2; n++ )
1446 : {
1447 :
1448 : /*-------------------cldfb-start-------------------------*/
1449 : /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/
1450 482276 : IF( sts[n]->cldfbAna != NULL )
1451 : {
1452 120 : scale_sig32( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); // Q11
1453 120 : sts[n]->cldfbAna->Q_cldfb_state = Q11;
1454 120 : move16();
1455 : }
1456 482276 : IF( sts[n]->cldfbSyn != NULL )
1457 : {
1458 482276 : scale_sig32( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_size, sub( Q11, Q4 ) ); // Q11
1459 482276 : sts[n]->cldfbSyn->Q_cldfb_state = Q11;
1460 482276 : move16();
1461 : }
1462 : /*-------------------cldfb-end---------------------------*/
1463 : }
1464 : }
1465 : }
1466 : }
1467 399979 : if ( hIvasDec->hasBeenFedFirstGoodFrame )
1468 : {
1469 399979 : hIvasDec->hasDecodedFirstGoodFrame = true;
1470 399979 : move16();
1471 : }
1472 :
1473 399979 : return IVAS_ERR_OK;
1474 : }
1475 :
1476 :
1477 : /*---------------------------------------------------------------------*
1478 : * IVAS_DEC_Rendered_FeedTcSamples( )
1479 : *
1480 : * Feed decoded transport channels samples to the renderer
1481 : *---------------------------------------------------------------------*/
1482 :
1483 399979 : static ivas_error IVAS_DEC_RendererFeedTcSamples(
1484 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1485 : const Word16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */
1486 : Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call */
1487 : Word32 *pcmBuf /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q11*/
1488 : )
1489 : {
1490 : Decoder_Struct *st_ivas;
1491 :
1492 399979 : test();
1493 399979 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1494 : {
1495 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1496 : }
1497 :
1498 399979 : st_ivas = hIvasDec->st_ivas;
1499 :
1500 : /* feed the TCs to the IVAS renderer */
1501 399979 : ivas_jbm_dec_feed_tc_to_renderer_fx( st_ivas, nSamplesForRendering, nSamplesResidual, pcmBuf );
1502 :
1503 399979 : return IVAS_ERR_OK;
1504 : }
1505 :
1506 :
1507 : /*---------------------------------------------------------------------*
1508 : * IVAS_DEC_GetRenderedSamples( )
1509 : *
1510 : * Main function to render the transport channels to PCM output data
1511 : *---------------------------------------------------------------------*/
1512 :
1513 411969 : static ivas_error IVAS_DEC_GetRenderedSamples(
1514 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1515 : const UWord16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */
1516 : UWord16 *nSamplesRendered, /* o : number of samples rendered */
1517 : UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the renerer pipeline */
1518 : Word16 *pcmBuf // Q0
1519 : )
1520 : {
1521 : Decoder_Struct *st_ivas;
1522 : ivas_error error;
1523 :
1524 411969 : test();
1525 411969 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1526 : {
1527 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1528 : }
1529 :
1530 411969 : st_ivas = hIvasDec->st_ivas;
1531 :
1532 : /* run the main IVAS decoding routine */
1533 411969 : error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcmBuf );
1534 :
1535 411969 : return error;
1536 : }
1537 :
1538 :
1539 : /*---------------------------------------------------------------------*
1540 : * IVAS_DEC_GetBufferedNumberOfSamples( )
1541 : *
1542 : * Returns the number of objects available in the decoded bitstream
1543 : *---------------------------------------------------------------------*/
1544 :
1545 19378 : static ivas_error IVAS_DEC_GetBufferedNumberOfSamples(
1546 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1547 : Word16 *nSamplesBuffered /* o : number of samples still buffered */
1548 : )
1549 : {
1550 19378 : *nSamplesBuffered = 0;
1551 19378 : move16();
1552 19378 : test();
1553 19378 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1554 : {
1555 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1556 : }
1557 :
1558 : /* check if the TC buffer already exists, otherweise nothing is buffered anyway */
1559 19378 : if ( hIvasDec->st_ivas->hTcBuffer != NULL )
1560 : {
1561 19378 : *nSamplesBuffered = sub( hIvasDec->st_ivas->hTcBuffer->n_samples_buffered, hIvasDec->st_ivas->hTcBuffer->n_samples_rendered );
1562 19378 : move16();
1563 : }
1564 :
1565 19378 : return IVAS_ERR_OK;
1566 : }
1567 :
1568 :
1569 : /*---------------------------------------------------------------------*
1570 : * IVAS_DEC_GetNumObjects( )
1571 : *
1572 : * Returns the number of objects available in the decoded bitstream
1573 : *---------------------------------------------------------------------*/
1574 :
1575 24310 : ivas_error IVAS_DEC_GetNumObjects(
1576 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1577 : UWord16 *numObjects /* o : number of objects for which the decoder has been configured */
1578 : )
1579 : {
1580 24310 : test();
1581 24310 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1582 : {
1583 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1584 : }
1585 24310 : test();
1586 24310 : test();
1587 24310 : IF( EQ_16( (Word16) hIvasDec->st_ivas->ivas_format, ISM_FORMAT ) || EQ_16( (Word16) hIvasDec->st_ivas->ivas_format, SBA_ISM_FORMAT ) || EQ_16( (Word16) hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) )
1588 : {
1589 24310 : *numObjects = hIvasDec->st_ivas->nchan_ism;
1590 : }
1591 : ELSE
1592 : {
1593 0 : *numObjects = 0;
1594 : }
1595 24310 : move16();
1596 :
1597 24310 : return IVAS_ERR_OK;
1598 : }
1599 :
1600 :
1601 : /*---------------------------------------------------------------------*
1602 : * IVAS_DEC_GetFormat( )
1603 : *
1604 : * Returns the format of currently decoded bitstream.
1605 : * Note: bitstream format is only known after the first (good) frame has been decoded.
1606 : *---------------------------------------------------------------------*/
1607 :
1608 44 : ivas_error IVAS_DEC_GetFormat(
1609 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1610 : IVAS_DEC_BS_FORMAT *format /* o : format detected from bitstream fed to the decoder */
1611 : )
1612 : {
1613 44 : IF( hIvasDec->hasDecodedFirstGoodFrame )
1614 : {
1615 44 : *format = mapIvasFormat( hIvasDec->st_ivas->ivas_format );
1616 : }
1617 : ELSE
1618 : {
1619 0 : *format = IVAS_DEC_BS_UNKOWN;
1620 : }
1621 44 : move32();
1622 :
1623 44 : return IVAS_ERR_OK;
1624 : }
1625 :
1626 :
1627 : /*---------------------------------------------------------------------*
1628 : * getInputBufferSize()
1629 : *
1630 : *
1631 : *---------------------------------------------------------------------*/
1632 :
1633 600 : static Word16 getOutputBufferSize(
1634 : const Decoder_Struct *st_ivas /* i : IVAS decoder handle */
1635 : )
1636 : {
1637 600 : IF( st_ivas->hDecoderConfig == NULL )
1638 : {
1639 0 : return -1;
1640 : }
1641 :
1642 600 : IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
1643 : {
1644 50 : return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, ( IVAS_MAX_OUTPUT_CHANNELS + IVAS_MAX_NUM_OBJECTS ) ), INV_FRAME_PER_SEC_Q15 ) );
1645 : }
1646 550 : ELSE IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1647 : {
1648 3 : IF( st_ivas->hLsSetupCustom == NULL )
1649 : {
1650 0 : return -1;
1651 : }
1652 :
1653 3 : return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, add( st_ivas->hLsSetupCustom->num_spk, st_ivas->hLsSetupCustom->num_lfe ) ), INV_FRAME_PER_SEC_Q15 ) );
1654 : }
1655 : ELSE
1656 : {
1657 547 : return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->nchan_out ), INV_FRAME_PER_SEC_Q15 ) );
1658 : }
1659 : }
1660 :
1661 :
1662 : /*---------------------------------------------------------------------*
1663 : * IVAS_DEC_GetOutputBufferSize()
1664 : *
1665 : *
1666 : *---------------------------------------------------------------------*/
1667 :
1668 600 : ivas_error IVAS_DEC_GetOutputBufferSize(
1669 : const IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */
1670 : Word16 *outputBufferSize /* o : total number of samples expected in the output buffer for current decoder configuration */
1671 : )
1672 : {
1673 600 : test();
1674 600 : test();
1675 600 : IF( outputBufferSize == NULL || hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1676 : {
1677 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1678 : }
1679 :
1680 600 : *outputBufferSize = getOutputBufferSize( hIvasDec->st_ivas );
1681 600 : move16();
1682 :
1683 600 : IF( EQ_16( *outputBufferSize, -1 ) )
1684 : {
1685 0 : return IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE;
1686 : }
1687 : ELSE
1688 : {
1689 600 : return IVAS_ERR_OK;
1690 : }
1691 : }
1692 :
1693 :
1694 : /*---------------------------------------------------------------------*
1695 : * IVAS_DEC_GetNumOutputChannels( )
1696 : *
1697 : * Returns number of output channels
1698 : *---------------------------------------------------------------------*/
1699 :
1700 594 : ivas_error IVAS_DEC_GetNumOutputChannels(
1701 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1702 : Word16 *numOutputChannels /* o : number of PCM output channels */
1703 : )
1704 : {
1705 594 : IF( hIvasDec->hasDecodedFirstGoodFrame )
1706 : {
1707 594 : *numOutputChannels = hIvasDec->st_ivas->hDecoderConfig->nchan_out;
1708 : }
1709 : ELSE
1710 : {
1711 0 : *numOutputChannels = 0;
1712 : }
1713 594 : move16();
1714 :
1715 594 : return IVAS_ERR_OK;
1716 : }
1717 :
1718 :
1719 : /*---------------------------------------------------------------------*
1720 : * IVAS_DEC_GetObjectMetadata( )
1721 : *
1722 : * Get metadata of one object decoded in the most recent frame
1723 : *---------------------------------------------------------------------*/
1724 68338 : ivas_error IVAS_DEC_GetObjectMetadata(
1725 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1726 : IVAS_ISM_METADATA *metadata, /* o : struct where metadata decoded in most recently decoded frame will be written */
1727 : const UWord16 zero_flag, /* i : if this flag is enabled, this function outputs a zero-initialized metadata struct */
1728 : const UWord16 objectIdx /* i : index of the queried object */
1729 : )
1730 : {
1731 : Decoder_Struct *st_ivas;
1732 : ISM_METADATA_HANDLE hIsmMeta;
1733 :
1734 68338 : test();
1735 68338 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1736 : {
1737 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1738 : }
1739 :
1740 68338 : st_ivas = hIvasDec->st_ivas;
1741 68338 : test();
1742 68338 : test();
1743 68338 : IF( NE_16( st_ivas->ivas_format, ISM_FORMAT ) && NE_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
1744 : {
1745 0 : return IVAS_ERR_WRONG_MODE;
1746 : }
1747 :
1748 68338 : IF( GE_16( objectIdx, st_ivas->nchan_ism ) )
1749 : {
1750 0 : return IVAS_ERR_INVALID_INDEX;
1751 : }
1752 :
1753 68338 : hIsmMeta = st_ivas->hIsmMetaData[objectIdx];
1754 :
1755 68338 : IF( hIsmMeta == NULL || zero_flag )
1756 : {
1757 3200 : metadata->azimuth_fx = 0; // Q22
1758 3200 : metadata->elevation_fx = 0; // Q22
1759 3200 : metadata->radius_fx = 512; // Q9
1760 3200 : metadata->yaw_fx = 0; // Q22
1761 3200 : metadata->pitch_fx = 0; // Q22
1762 3200 : metadata->spread_fx = 0; // Q22
1763 3200 : metadata->gainFactor_fx = ONE_IN_Q31; // Q31
1764 3200 : metadata->non_diegetic_flag = 0;
1765 : }
1766 : ELSE
1767 : {
1768 65138 : metadata->azimuth_fx = hIsmMeta->azimuth_fx; // Q22
1769 65138 : metadata->elevation_fx = hIsmMeta->elevation_fx; // Q22
1770 65138 : metadata->radius_fx = hIsmMeta->radius_fx; // Q9
1771 65138 : metadata->yaw_fx = hIsmMeta->yaw_fx; // Q22
1772 65138 : metadata->pitch_fx = hIsmMeta->pitch_fx; // Q22
1773 65138 : metadata->spread_fx = 0; // Q22
1774 65138 : metadata->gainFactor_fx = ONE_IN_Q31;
1775 65138 : metadata->non_diegetic_flag = hIsmMeta->non_diegetic_flag;
1776 : }
1777 :
1778 68338 : move32();
1779 68338 : move32();
1780 68338 : move32();
1781 68338 : move32();
1782 68338 : move32();
1783 68338 : move32();
1784 68338 : move16();
1785 68338 : move16();
1786 68338 : return IVAS_ERR_OK;
1787 : }
1788 :
1789 : /*---------------------------------------------------------------------*
1790 : * IVAS_DEC_GetMasaMetadata( )
1791 : *
1792 : * Get metadata of the most recently decoded MASA frame
1793 : *---------------------------------------------------------------------*/
1794 :
1795 5465 : ivas_error IVAS_DEC_GetMasaMetadata(
1796 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1797 : MASA_DECODER_EXT_OUT_META_HANDLE *hMasaExtOutMeta, /* o : pointer to handle, which will be set to point to metadata from the most recently decoded frame */
1798 : const UWord8 getFromJbmBuffer /* i : get metadata from a JBM buffer */
1799 : )
1800 : {
1801 5465 : test();
1802 5465 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1803 : {
1804 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1805 : }
1806 :
1807 5465 : test();
1808 5465 : IF( NE_16( hIvasDec->st_ivas->ivas_format, MASA_FORMAT ) && NE_16( hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) )
1809 : {
1810 0 : return IVAS_ERR_WRONG_MODE;
1811 : }
1812 :
1813 5465 : IF( getFromJbmBuffer )
1814 : {
1815 1308 : ivas_jbm_masa_sf_to_sf_map( hIvasDec->st_ivas );
1816 : }
1817 :
1818 5465 : *hMasaExtOutMeta = hIvasDec->st_ivas->hMasa->data.extOutMeta;
1819 :
1820 5465 : return IVAS_ERR_OK;
1821 : }
1822 :
1823 :
1824 : /*---------------------------------------------------------------------*
1825 : * IVAS_DEC_FeedHeadTrackData( )
1826 : *
1827 : * Feed the decoder with the head tracking data
1828 : *---------------------------------------------------------------------*/
1829 :
1830 277720 : ivas_error IVAS_DEC_FeedHeadTrackData(
1831 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1832 : IVAS_QUATERNION orientation, /* i : head-tracking data, listener orientation */
1833 : IVAS_VECTOR3 Pos, /* i : listener position */
1834 : const Word16 subframe_idx /* i : subframe index */
1835 : )
1836 : {
1837 : HEAD_TRACK_DATA_HANDLE hHeadTrackData;
1838 : ivas_error error;
1839 :
1840 277720 : test();
1841 277720 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1842 : {
1843 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1844 : }
1845 :
1846 277720 : hHeadTrackData = hIvasDec->st_ivas->hHeadTrackData;
1847 :
1848 277720 : IF( hHeadTrackData == NULL )
1849 : {
1850 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1851 : }
1852 :
1853 : /* Move head-tracking data to the decoder handle */
1854 : /* check for Euler angle signaling */
1855 277720 : IF( EQ_32( orientation.w_fx, -1610612736 /* -3.0f in Q29 */ ) )
1856 : {
1857 0 : Euler2Quat_fx( deg2rad_fx( orientation.x_fx ), deg2rad_fx( orientation.y_fx ), deg2rad_fx( orientation.z_fx ), &orientation );
1858 : }
1859 :
1860 277720 : Word32 updateRate_fx = 1677721600; // value is 200 in Q23
1861 277720 : move32();
1862 277720 : orientation.w_fx = L_shl( orientation.w_fx, sub( Q29, orientation.q_fact ) ); // Q29
1863 277720 : orientation.x_fx = L_shl( orientation.x_fx, sub( Q29, orientation.q_fact ) ); // Q29
1864 277720 : orientation.y_fx = L_shl( orientation.y_fx, sub( Q29, orientation.q_fact ) ); // Q29
1865 277720 : orientation.z_fx = L_shl( orientation.z_fx, sub( Q29, orientation.q_fact ) ); // Q29
1866 277720 : hHeadTrackData->OrientationTracker->refRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29
1867 277720 : hHeadTrackData->OrientationTracker->refRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29
1868 277720 : hHeadTrackData->OrientationTracker->refRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29
1869 277720 : hHeadTrackData->OrientationTracker->refRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29
1870 277720 : hHeadTrackData->OrientationTracker->absAvgRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
1871 277720 : hHeadTrackData->OrientationTracker->absAvgRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
1872 277720 : hHeadTrackData->OrientationTracker->absAvgRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
1873 277720 : hHeadTrackData->OrientationTracker->absAvgRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
1874 :
1875 277720 : orientation.q_fact = Q29;
1876 277720 : hHeadTrackData->OrientationTracker->refRot.q_fact = Q29;
1877 277720 : hHeadTrackData->OrientationTracker->absAvgRot.q_fact = Q29;
1878 277720 : move16();
1879 277720 : move16();
1880 277720 : move16();
1881 :
1882 277720 : IF( NE_32( ( error = ivas_orient_trk_Process_fx( hHeadTrackData->OrientationTracker, orientation, updateRate_fx, &hHeadTrackData->Quaternions[subframe_idx] ) ), IVAS_ERR_OK ) )
1883 : {
1884 0 : return error;
1885 : }
1886 :
1887 277720 : hHeadTrackData->Pos[subframe_idx].x_fx = Pos.x_fx;
1888 277720 : hHeadTrackData->Pos[subframe_idx].y_fx = Pos.y_fx;
1889 277720 : hHeadTrackData->Pos[subframe_idx].z_fx = Pos.z_fx;
1890 277720 : hHeadTrackData->Pos[subframe_idx].q_fact = Pos.q_fact;
1891 277720 : move32();
1892 277720 : move32();
1893 277720 : move32();
1894 277720 : move16();
1895 :
1896 277720 : hIvasDec->updateOrientation = true;
1897 277720 : move16();
1898 :
1899 277720 : return IVAS_ERR_OK;
1900 : }
1901 :
1902 :
1903 : /*---------------------------------------------------------------------*
1904 : * IVAS_DEC_FeedRefRotData( )
1905 : *
1906 : * Feed the decoder with the reference rotation
1907 : *---------------------------------------------------------------------*/
1908 :
1909 0 : ivas_error IVAS_DEC_FeedRefRotData(
1910 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1911 : IVAS_QUATERNION rotation /* i : reference rotation data */
1912 : )
1913 : {
1914 : ivas_orient_trk_state_t *pOtr;
1915 :
1916 0 : test();
1917 0 : test();
1918 0 : test();
1919 0 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHeadTrackData == NULL || hIvasDec->st_ivas->hHeadTrackData->OrientationTracker == NULL )
1920 : {
1921 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1922 : }
1923 :
1924 0 : pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker;
1925 :
1926 0 : pOtr->refRot.w_fx = rotation.w_fx; // rotation.q_fact
1927 0 : pOtr->refRot.x_fx = rotation.x_fx; // rotation.q_fact
1928 0 : pOtr->refRot.z_fx = rotation.z_fx; // rotation.q_fact
1929 0 : pOtr->refRot.y_fx = rotation.y_fx; // rotation.q_fact
1930 :
1931 0 : pOtr->refRot.q_fact = rotation.q_fact;
1932 0 : move32();
1933 0 : move32();
1934 0 : move32();
1935 0 : move32();
1936 :
1937 0 : hIvasDec->updateOrientation = true;
1938 0 : move16();
1939 :
1940 0 : return IVAS_ERR_OK;
1941 : }
1942 :
1943 :
1944 : /*---------------------------------------------------------------------*
1945 : * IVAS_DEC_FeedRefVectorData( )
1946 : *
1947 : * Feed the decoder with a reference vector spanning from listenerPos
1948 : * to refPos. Only available in OTR_TRACKING_REF_POS and
1949 : * OTR_TRACKING_REF_POS_LEV modes.
1950 : *---------------------------------------------------------------------*/
1951 :
1952 4004 : ivas_error IVAS_DEC_FeedRefVectorData(
1953 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1954 : IVAS_VECTOR3 listenerPos, /* i : Listener position */
1955 : IVAS_VECTOR3 refPos /* i : Reference position */
1956 : )
1957 : {
1958 : ivas_orient_trk_state_t *pOtr;
1959 :
1960 4004 : test();
1961 4004 : test();
1962 4004 : test();
1963 4004 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHeadTrackData == NULL || hIvasDec->st_ivas->hHeadTrackData->OrientationTracker == NULL )
1964 : {
1965 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1966 : }
1967 :
1968 4004 : pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker;
1969 :
1970 4004 : hIvasDec->updateOrientation = true;
1971 4004 : move16();
1972 :
1973 4004 : ivas_error error_fx = ivas_orient_trk_SetReferenceVector_fx( pOtr, listenerPos, refPos );
1974 4004 : return error_fx;
1975 : }
1976 :
1977 : /*---------------------------------------------------------------------*
1978 : * IVAS_DEC_FeedExternalOrientationData( )
1979 : *
1980 : * Feed the decoder with the external orientation data
1981 : *---------------------------------------------------------------------*/
1982 :
1983 116924 : ivas_error IVAS_DEC_FeedExternalOrientationData(
1984 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1985 : IVAS_QUATERNION orientation, /* i : external orientation data */
1986 : Word8 enableHeadRotation, /* i : flag to enable head rotation for this frame */
1987 : Word8 enableExternalOrientation, /* i : flag to enable external orientation for this frame */
1988 : Word8 enableRotationInterpolation, /* i : flag to interpolate rotations from current and previous frames */
1989 : Word16 numFramesToTargetOrientation, /* i : number of frames until target orientation is reached */
1990 : const Word16 subframe_idx /* i : subframe index */
1991 : )
1992 : {
1993 : EXTERNAL_ORIENTATION_HANDLE hExternalOrientationData;
1994 :
1995 116924 : test();
1996 116924 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1997 : {
1998 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1999 : }
2000 :
2001 116924 : hExternalOrientationData = hIvasDec->st_ivas->hExtOrientationData;
2002 :
2003 116924 : IF( hExternalOrientationData == NULL )
2004 : {
2005 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2006 : }
2007 116924 : orientation.q_fact = Q29;
2008 116924 : move16();
2009 : /* Move external orientation data to the decoder handle (invert orientations) */
2010 116924 : QuaternionInverse_fx( orientation, &hExternalOrientationData->Quaternions[subframe_idx] );
2011 :
2012 116924 : hExternalOrientationData->enableHeadRotation[subframe_idx] = enableHeadRotation;
2013 116924 : hExternalOrientationData->enableExternalOrientation[subframe_idx] = enableExternalOrientation;
2014 116924 : hExternalOrientationData->enableRotationInterpolation[subframe_idx] = enableRotationInterpolation;
2015 116924 : hExternalOrientationData->numFramesToTargetOrientation[subframe_idx] = numFramesToTargetOrientation;
2016 116924 : move16();
2017 116924 : move16();
2018 116924 : move16();
2019 116924 : move16();
2020 :
2021 116924 : hIvasDec->updateOrientation = true;
2022 116924 : move16();
2023 :
2024 116924 : return IVAS_ERR_OK;
2025 : }
2026 :
2027 :
2028 : /*---------------------------------------------------------------------*
2029 : * IVAS_DEC_FeedCustomLsData( )
2030 : *
2031 : * Feed the decoder with the Custom loudspeaker data
2032 : *---------------------------------------------------------------------*/
2033 :
2034 : /*! r: error code */
2035 3 : ivas_error IVAS_DEC_FeedCustomLsData(
2036 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2037 : const IVAS_CUSTOM_LS_DATA hLsCustomData /* i : Custom loudspeaker setup data */
2038 : )
2039 : {
2040 : Word16 i, is_planar;
2041 : IVAS_LSSETUP_CUSTOM_HANDLE hLsSetupCustom;
2042 :
2043 3 : test();
2044 3 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2045 : {
2046 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2047 : }
2048 :
2049 3 : hLsSetupCustom = hIvasDec->st_ivas->hLsSetupCustom;
2050 :
2051 3 : IF( hLsSetupCustom == NULL )
2052 : {
2053 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2054 : }
2055 :
2056 : /* Move Custom LS layout data to the decoder handle */
2057 :
2058 : /* Loudspeaker azimuths and elevations */
2059 3 : hLsSetupCustom->num_spk = hLsCustomData.num_spk;
2060 3 : move16();
2061 :
2062 3 : Copy32( hLsCustomData.azimuth_fx, hLsSetupCustom->ls_azimuth_fx, hLsCustomData.num_spk ); // Q22
2063 3 : Copy32( hLsCustomData.elevation_fx, hLsSetupCustom->ls_elevation_fx, hLsCustomData.num_spk ); // Q22
2064 :
2065 : /* Set planar flag */
2066 3 : is_planar = 1;
2067 3 : move16();
2068 51 : FOR( i = 0; i < hLsCustomData.num_spk; i++ )
2069 : {
2070 48 : test();
2071 48 : if ( is_planar && hLsSetupCustom->ls_elevation_fx[i] != 0 )
2072 : {
2073 3 : is_planar = 0;
2074 3 : move16();
2075 : }
2076 : }
2077 3 : hLsSetupCustom->is_planar_setup = is_planar;
2078 3 : move16();
2079 :
2080 : /* Loudspeaker LFE */
2081 3 : hLsSetupCustom->num_lfe = hLsCustomData.num_lfe;
2082 3 : move16();
2083 3 : Copy( hLsCustomData.lfe_idx, hLsSetupCustom->lfe_idx, hLsCustomData.num_lfe );
2084 :
2085 3 : return IVAS_ERR_OK;
2086 : }
2087 :
2088 :
2089 : /*---------------------------------------------------------------------*
2090 : * IVAS_DEC_GetHrtfHandle( )
2091 : *
2092 : *
2093 : *---------------------------------------------------------------------*/
2094 :
2095 46 : ivas_error IVAS_DEC_GetHrtfHandle(
2096 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2097 : IVAS_DEC_HRTF_HANDLE *hHrtfTD /* o : HRTF handle */
2098 : )
2099 : {
2100 46 : test();
2101 46 : test();
2102 46 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfTD == NULL )
2103 : {
2104 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2105 : }
2106 :
2107 46 : *hHrtfTD = hIvasDec->st_ivas->hHrtfTD;
2108 :
2109 46 : return IVAS_ERR_OK;
2110 : }
2111 :
2112 :
2113 : /*---------------------------------------------------------------------*
2114 : * IVAS_DEC_GetHrtfCRendHandle( )
2115 : *
2116 : *
2117 : *---------------------------------------------------------------------*/
2118 :
2119 46 : ivas_error IVAS_DEC_GetHrtfCRendHandle(
2120 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2121 : IVAS_DEC_HRTF_CREND_HANDLE *hSetOfHRTF /* o : Set of HRTF handle */
2122 : )
2123 : {
2124 46 : test();
2125 46 : test();
2126 46 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hSetOfHRTF == NULL )
2127 : {
2128 0 : return IVAS_ERR_WRONG_PARAMS;
2129 : }
2130 :
2131 46 : *hSetOfHRTF = hIvasDec->st_ivas->hSetOfHRTF;
2132 :
2133 46 : return IVAS_ERR_OK;
2134 : }
2135 :
2136 :
2137 : /*---------------------------------------------------------------------*
2138 : * IVAS_DEC_GetHrtfFastConvHandle( )
2139 : *
2140 : *
2141 : *---------------------------------------------------------------------*/
2142 :
2143 23 : ivas_error IVAS_DEC_GetHrtfFastConvHandle(
2144 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2145 : IVAS_DEC_HRTF_FASTCONV_HANDLE *hHrtfFastConv /* o : FASTCONV HRTF handle */
2146 : )
2147 : {
2148 23 : test();
2149 23 : test();
2150 23 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfFastConv == NULL )
2151 : {
2152 0 : return IVAS_ERR_WRONG_PARAMS;
2153 : }
2154 :
2155 23 : *hHrtfFastConv = hIvasDec->st_ivas->hHrtfFastConv;
2156 :
2157 23 : return IVAS_ERR_OK;
2158 : }
2159 :
2160 :
2161 : /*---------------------------------------------------------------------*
2162 : * IVAS_DEC_GetHrtfParamBinHandle( )
2163 : *
2164 : *
2165 : *---------------------------------------------------------------------*/
2166 :
2167 23 : ivas_error IVAS_DEC_GetHrtfParamBinHandle(
2168 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2169 : IVAS_DEC_HRTF_PARAMBIN_HANDLE *hHrtfParambin /* o : Parametric binauralizer HRTF handle */
2170 : )
2171 : {
2172 23 : test();
2173 23 : test();
2174 23 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfParambin == NULL )
2175 : {
2176 0 : return IVAS_ERR_WRONG_PARAMS;
2177 : }
2178 :
2179 23 : *hHrtfParambin = hIvasDec->st_ivas->hHrtfParambin;
2180 :
2181 23 : return IVAS_ERR_OK;
2182 : }
2183 :
2184 : /*---------------------------------------------------------------------*
2185 : * copyRendererConfigStruct( )
2186 : *
2187 : *
2188 : *---------------------------------------------------------------------*/
2189 :
2190 29 : static ivas_error copyRendererConfigStruct(
2191 : RENDER_CONFIG_HANDLE hRCin,
2192 : IVAS_RENDER_CONFIG_HANDLE hRCout )
2193 : {
2194 29 : test();
2195 29 : IF( hRCin == NULL || hRCout == NULL )
2196 : {
2197 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2198 : }
2199 :
2200 29 : hRCout->roomAcoustics.override = hRCin->roomAcoustics.override;
2201 29 : hRCout->roomAcoustics.nBands = hRCin->roomAcoustics.nBands;
2202 29 : hRCout->roomAcoustics.acousticPreDelay_fx = hRCin->roomAcoustics.acousticPreDelay_fx;
2203 29 : hRCout->roomAcoustics.inputPreDelay_fx = hRCin->roomAcoustics.inputPreDelay_fx;
2204 :
2205 29 : Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16
2206 29 : Copy32( hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26
2207 29 : Copy32( hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30
2208 29 : Copy( hRCin->directivity_fx, hRCout->directivity_fx, 3 * MAX_NUM_OBJECTS );
2209 29 : hRCout->roomAcoustics.use_er = hRCin->roomAcoustics.use_er;
2210 29 : hRCout->roomAcoustics.lowComplexity = hRCin->roomAcoustics.lowComplexity;
2211 29 : move16();
2212 29 : move16();
2213 29 : move16();
2214 29 : move32();
2215 29 : move32();
2216 29 : move32();
2217 :
2218 29 : return IVAS_ERR_OK;
2219 : }
2220 :
2221 :
2222 : /*---------------------------------------------------------------------*
2223 : * IVAS_DEC_GetRenderConfig( )
2224 : *
2225 : *
2226 : *---------------------------------------------------------------------*/
2227 :
2228 29 : ivas_error IVAS_DEC_GetRenderConfig(
2229 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2230 : const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */
2231 : )
2232 : {
2233 29 : test();
2234 29 : test();
2235 29 : test();
2236 29 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL || hRCout == NULL )
2237 : {
2238 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2239 : }
2240 :
2241 29 : return copyRendererConfigStruct( hIvasDec->st_ivas->hRenderConfig, hRCout );
2242 : }
2243 :
2244 : /*! r: error code*/
2245 0 : ivas_error IVAS_DEC_GetDefaultRenderConfig(
2246 : IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render config handle */
2247 : )
2248 : {
2249 : RENDER_CONFIG_DATA RCin;
2250 0 : RENDER_CONFIG_HANDLE hRCin = &RCin;
2251 : ivas_error error;
2252 0 : IF( NE_32( ( error = ivas_render_config_init_from_rom_fx( &hRCin ) ), IVAS_ERR_OK ) )
2253 : {
2254 0 : return error;
2255 : }
2256 :
2257 0 : return copyRendererConfigStruct( hRCin, hRCout );
2258 : }
2259 :
2260 :
2261 : /*---------------------------------------------------------------------*
2262 : * IVAS_DEC_FeedRenderConfig( )
2263 : *
2264 : *
2265 : *---------------------------------------------------------------------*/
2266 :
2267 25 : ivas_error IVAS_DEC_FeedRenderConfig(
2268 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2269 : const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */
2270 : )
2271 : {
2272 : RENDER_CONFIG_HANDLE hRenderConfig;
2273 :
2274 25 : test();
2275 25 : test();
2276 25 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL )
2277 : {
2278 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2279 : }
2280 :
2281 25 : hRenderConfig = hIvasDec->st_ivas->hRenderConfig;
2282 25 : hRenderConfig->roomAcoustics.override = renderConfig.roomAcoustics.override;
2283 25 : hRenderConfig->roomAcoustics.nBands = renderConfig.roomAcoustics.nBands;
2284 25 : hRenderConfig->roomAcoustics.acousticPreDelay_fx = renderConfig.roomAcoustics.acousticPreDelay_fx;
2285 25 : hRenderConfig->roomAcoustics.inputPreDelay_fx = renderConfig.roomAcoustics.inputPreDelay_fx;
2286 :
2287 25 : hRenderConfig->roomAcoustics.use_er = 0;
2288 25 : move16();
2289 25 : move16();
2290 25 : move16();
2291 25 : move32();
2292 25 : move32();
2293 25 : IF( EQ_16( renderConfig.roomAcoustics.use_er, 1 ) )
2294 : {
2295 4 : hRenderConfig->roomAcoustics.use_er = renderConfig.roomAcoustics.use_er;
2296 4 : hRenderConfig->roomAcoustics.lowComplexity = renderConfig.roomAcoustics.lowComplexity;
2297 4 : hRenderConfig->roomAcoustics.dimensions = renderConfig.roomAcoustics.dimensions;
2298 4 : hRenderConfig->roomAcoustics.ListenerOrigin = renderConfig.roomAcoustics.ListenerOrigin;
2299 :
2300 4 : Copy32( renderConfig.roomAcoustics.AbsCoeff_fx, hRenderConfig->roomAcoustics.AbsCoeff_fx, IVAS_ROOM_ABS_COEFF );
2301 4 : move16();
2302 4 : move32();
2303 : }
2304 :
2305 25 : Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16
2306 25 : Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26
2307 25 : Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30
2308 :
2309 25 : Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS );
2310 :
2311 25 : return IVAS_ERR_OK;
2312 : }
2313 :
2314 :
2315 : /*---------------------------------------------------------------------*
2316 : * IVAS_DEC_GetDelay( )
2317 : *
2318 : *
2319 : *---------------------------------------------------------------------*/
2320 :
2321 594 : ivas_error IVAS_DEC_GetDelay(
2322 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2323 : Word16 *nSamples, /* o : decoder delay in samples */
2324 : Word32 *timeScale /* o : time scale of the delay, equal to decoder output sampling rate */
2325 : )
2326 : {
2327 : Decoder_Struct *st_ivas;
2328 : DECODER_CONFIG_HANDLE hDecoderConfig;
2329 : Word32 out_fs_fx;
2330 :
2331 594 : test();
2332 594 : test();
2333 594 : test();
2334 594 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || nSamples == NULL || timeScale == NULL )
2335 : {
2336 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2337 : }
2338 :
2339 594 : IF( !hIvasDec->hasDecodedFirstGoodFrame )
2340 : {
2341 : /* Delay depends on IVAS format, which is unknown until first frame has been decoded */
2342 0 : return IVAS_ERR_WAITING_FOR_BITSTREAM;
2343 : }
2344 :
2345 594 : st_ivas = hIvasDec->st_ivas;
2346 594 : hDecoderConfig = st_ivas->hDecoderConfig;
2347 :
2348 594 : IF( NE_32( hDecoderConfig->output_Fs, 48000 ) )
2349 : {
2350 242 : IF( NE_32( hDecoderConfig->output_Fs, 32000 ) )
2351 : {
2352 79 : out_fs_fx = FS_16K_IN_NS_Q31;
2353 : }
2354 : ELSE
2355 : {
2356 163 : out_fs_fx = FS_32K_IN_NS_Q31;
2357 : }
2358 : }
2359 : ELSE
2360 : {
2361 352 : out_fs_fx = FS_48K_IN_NS_Q31;
2362 : }
2363 594 : move32();
2364 :
2365 594 : nSamples[1] = NS2SA_FX2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0] ) );
2366 594 : move16();
2367 594 : nSamples[2] = extract_l( W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ) );
2368 594 : move16();
2369 594 : nSamples[0] = add( nSamples[1], nSamples[2] );
2370 594 : move16();
2371 :
2372 594 : IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) )
2373 : {
2374 : /* note: in MASA, all delay is compensated at the decoder by default, so subtract the encoder delay for print-out */
2375 80 : nSamples[1] = sub( nSamples[1], NS2SA_FX2( hDecoderConfig->output_Fs, IVAS_ENC_DELAY_NS ) );
2376 80 : move16();
2377 : }
2378 :
2379 594 : *timeScale = hDecoderConfig->output_Fs;
2380 594 : move32();
2381 :
2382 594 : return IVAS_ERR_OK;
2383 : }
2384 :
2385 :
2386 : /*---------------------------------------------------------------------*
2387 : * IVAS_DEC_HasDecodedFirstGoodFrame( )
2388 : *
2389 : *
2390 : *---------------------------------------------------------------------*/
2391 :
2392 784 : ivas_error IVAS_DEC_HasDecodedFirstGoodFrame(
2393 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2394 : bool *hasDecodedFirstGoodFrame /* o : flag indicating if the decoder has decoded a good frame since it was configured */
2395 : )
2396 : {
2397 784 : test();
2398 784 : test();
2399 784 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hasDecodedFirstGoodFrame == NULL )
2400 : {
2401 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2402 : }
2403 :
2404 784 : *hasDecodedFirstGoodFrame = hIvasDec->hasDecodedFirstGoodFrame;
2405 784 : move16();
2406 :
2407 784 : return IVAS_ERR_OK;
2408 : }
2409 :
2410 :
2411 : /*---------------------------------------------------------------------*
2412 : * IVAS_DEC_GetPcmFrameSize( )
2413 : *
2414 : *
2415 : *---------------------------------------------------------------------*/
2416 :
2417 594 : ivas_error IVAS_DEC_GetPcmFrameSize(
2418 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2419 : Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels Q0 */
2420 : )
2421 : {
2422 594 : test();
2423 594 : test();
2424 594 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || pcmFrameSize == NULL )
2425 : {
2426 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2427 : }
2428 :
2429 594 : IF( hIvasDec->hasDecodedFirstGoodFrame )
2430 : {
2431 594 : *pcmFrameSize = Mult_32_16( imult3216( hIvasDec->st_ivas->hDecoderConfig->output_Fs, hIvasDec->st_ivas->hDecoderConfig->nchan_out ), INV_FRAME_PER_SEC_Q15 );
2432 : }
2433 : ELSE
2434 : {
2435 0 : *pcmFrameSize = 0;
2436 : }
2437 594 : move32();
2438 :
2439 594 : return IVAS_ERR_OK;
2440 : }
2441 :
2442 :
2443 : /*---------------------------------------------------------------------*
2444 : * isSidFrame( )
2445 : *
2446 : * Check if a frame contains a SID
2447 : *---------------------------------------------------------------------*/
2448 :
2449 17523 : static bool isSidFrame(
2450 : const UWord16 size )
2451 : {
2452 17523 : IF( EQ_16( size, ( SID_1k75 / FRAMES_PER_SEC ) ) )
2453 : {
2454 0 : return true; /* AMR-WB SID */
2455 : }
2456 17523 : ELSE IF( EQ_16( size, ( SID_2k40 / FRAMES_PER_SEC ) ) )
2457 : {
2458 0 : return true; /* EVS SID */
2459 : }
2460 17523 : ELSE IF( EQ_16( size, ( IVAS_SID_5k2 / FRAMES_PER_SEC ) ) )
2461 : {
2462 268 : return true; /* IVAS SID */
2463 : }
2464 :
2465 17255 : return false;
2466 : }
2467 :
2468 17540 : static void bsCompactToSerial( const UWord8 *compact, UWord16 *serial, UWord16 num_bits )
2469 : {
2470 : /* Bitstream conversion is not counted towards complexity and memory usage */
2471 : #define WMC_TOOL_SKIP
2472 : UWord32 i;
2473 17540 : UWord8 byte = 0;
2474 17540 : const UWord8 mask = 0x80;
2475 17540 : move16();
2476 17540 : move16();
2477 :
2478 29609164 : FOR( i = 0; i < num_bits; ++i )
2479 : {
2480 29591624 : if ( ( i % 8 ) == 0 )
2481 : {
2482 3698953 : byte = compact[i / 8];
2483 3698953 : move16();
2484 : }
2485 :
2486 29591624 : serial[i] = shr( s_and( byte, mask ), 7 );
2487 29591624 : move16();
2488 :
2489 29591624 : byte = (UWord8) shl( byte, 1 );
2490 : }
2491 :
2492 : /* Add 4 padding bytes required by core coder */
2493 578820 : FOR( i = 0; i < 4 * 8; ++i )
2494 : {
2495 561280 : serial[( num_bits + i )] = 0;
2496 561280 : move16();
2497 : }
2498 : #undef WMC_TOOL_SKIP
2499 17540 : }
2500 :
2501 :
2502 : /*---------------------------------------------------------------------*
2503 : * IVAS_DEC_VoIP_FeedFrame( )
2504 : *
2505 : * Feed RTP packet into internal jitter buffer
2506 : *---------------------------------------------------------------------*/
2507 :
2508 17523 : ivas_error IVAS_DEC_VoIP_FeedFrame(
2509 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2510 : UWord8 *au, /* i : buffer containing input access unit */
2511 : const UWord16 auSize, /* i : size of the access unit */
2512 : const UWord16 rtpSequenceNumber, /* i : RTP sequence number (16 bits) */
2513 : const UWord32 rtpTimeStamp, /* i : RTP timestamp (32 bits) */
2514 : const UWord32 rcvTime_ms, /* i : receive time of the RTP packet in milliseconds */
2515 : const bool qBit /* i : Q bit for AMR-WB IO */
2516 : )
2517 : {
2518 : JB4_DATAUNIT_HANDLE dataUnit;
2519 : Word16 partialCopyFrameType, partialCopyOffset;
2520 : Word16 result;
2521 :
2522 17523 : IF( auSize == 0 )
2523 : {
2524 0 : return IVAS_ERR_OK; /* ignore empty/NO_DATA frame - shouldn't be transmitted in RTP */
2525 : }
2526 17523 : IF( GT_16( shr( add( auSize, 7 ), 3 ), (Word16) MAX_AU_SIZE ) )
2527 : {
2528 0 : return IVAS_ERR_INVALID_BITSTREAM;
2529 : }
2530 :
2531 : /* check if frame contains a partial copy and get its offset */
2532 17523 : evs_dec_previewFrame( au, auSize, &partialCopyFrameType, &partialCopyOffset );
2533 :
2534 : /* create data unit for primary copy in the frame */
2535 17523 : dataUnit = JB4_AllocDataUnit( hIvasDec->hVoIP->hJBM );
2536 17523 : mvc2c( au, dataUnit->data, shr( add( auSize, 7 ), 3 ) );
2537 17523 : dataUnit->dataSize = auSize;
2538 17523 : dataUnit->duration = 20;
2539 17523 : dataUnit->sequenceNumber = rtpSequenceNumber;
2540 17523 : dataUnit->silenceIndicator = isSidFrame( dataUnit->dataSize );
2541 17523 : move16();
2542 17523 : dataUnit->timeScale = 1000;
2543 17523 : dataUnit->rcvTime = rcvTime_ms;
2544 17523 : dataUnit->timeStamp = rtpTimeStamp;
2545 17523 : dataUnit->partial_frame = 0;
2546 17523 : dataUnit->partialCopyOffset = partialCopyOffset;
2547 17523 : dataUnit->qBit = qBit;
2548 17523 : move16();
2549 17523 : move16();
2550 17523 : move16();
2551 17523 : move16();
2552 17523 : move16();
2553 17523 : move32();
2554 17523 : move32();
2555 17523 : move32();
2556 17523 : move32();
2557 :
2558 : /* add the frame to the JBM */
2559 17523 : result = JB4_PushDataUnit( hIvasDec->hVoIP->hJBM, dataUnit, rcvTime_ms );
2560 17523 : IF( result != 0 )
2561 : {
2562 0 : return IVAS_ERR_UNKNOWN;
2563 : }
2564 :
2565 17523 : test();
2566 17523 : IF( NE_16( partialCopyFrameType, RF_NO_DATA ) && partialCopyOffset != 0 )
2567 : {
2568 : /* create data unit for partial copy in the frame */
2569 764 : dataUnit = JB4_AllocDataUnit( hIvasDec->hVoIP->hJBM );
2570 764 : mvc2c( au, dataUnit->data, shr( add( auSize, 7 ), 3 ) );
2571 764 : dataUnit->dataSize = auSize;
2572 764 : dataUnit->duration = 20;
2573 764 : dataUnit->sequenceNumber = rtpSequenceNumber;
2574 764 : dataUnit->silenceIndicator = 0; /* there are no partial copies for SID frames */
2575 764 : dataUnit->timeScale = 1000;
2576 764 : dataUnit->rcvTime = rcvTime_ms;
2577 764 : dataUnit->timeStamp = (UWord32) W_sub( rtpTimeStamp, imult3216( dataUnit->duration, partialCopyOffset ) );
2578 764 : move32();
2579 764 : dataUnit->partial_frame = 1;
2580 764 : dataUnit->partialCopyOffset = partialCopyOffset;
2581 764 : dataUnit->qBit = qBit;
2582 764 : move16();
2583 764 : move16();
2584 764 : move16();
2585 764 : move16();
2586 764 : move16();
2587 764 : move32();
2588 764 : move32();
2589 764 : move32();
2590 :
2591 : /* add the frame to the JBM */
2592 764 : result = JB4_PushDataUnit( hIvasDec->hVoIP->hJBM, dataUnit, rcvTime_ms );
2593 764 : IF( result != 0 )
2594 : {
2595 0 : return IVAS_ERR_UNKNOWN;
2596 : }
2597 : }
2598 :
2599 17523 : return IVAS_ERR_OK;
2600 : }
2601 :
2602 : /*---------------------------------------------------------------------*
2603 : * IVAS_DEC_VoIP_SetScale( )
2604 : *
2605 : * Set the TSM scale
2606 : *---------------------------------------------------------------------*/
2607 :
2608 19595 : ivas_error IVAS_DEC_VoIP_SetScale(
2609 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2610 : const Word16 maxScaling, /* i : max allowed absolute difference in samples from the default 20ms frame size */
2611 : const Word16 scale /* i : TSM scale to set in percent of the default frame size */
2612 : )
2613 : {
2614 : ivas_error error;
2615 :
2616 19595 : error = IVAS_ERR_OK;
2617 19595 : move32();
2618 :
2619 19595 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == false )
2620 : {
2621 0 : return IVAS_ERR_TSM_NOT_ENABLED;
2622 : }
2623 : ELSE
2624 : {
2625 19595 : hIvasDec->tsm_scale = scale;
2626 19595 : hIvasDec->tsm_max_scaling = maxScaling;
2627 19595 : move16();
2628 19595 : move16();
2629 : }
2630 :
2631 19595 : return error;
2632 : }
2633 :
2634 : /*---------------------------------------------------------------------*
2635 : * IVAS_DEC_VoIP_SetScale( )
2636 : *
2637 : * Set the TSM scale
2638 : *---------------------------------------------------------------------*/
2639 :
2640 0 : ivas_error IVAS_DEC_TSM_SetQuality(
2641 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2642 : const Word16 quality /* i : target TSM quality Q14 */
2643 : )
2644 : {
2645 : ivas_error error;
2646 :
2647 0 : error = IVAS_ERR_OK;
2648 0 : move32();
2649 :
2650 0 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == false )
2651 : {
2652 0 : return IVAS_ERR_TSM_NOT_ENABLED;
2653 : }
2654 : ELSE
2655 : {
2656 0 : hIvasDec->tsm_quality = quality; // Q14
2657 0 : move16();
2658 : }
2659 :
2660 0 : return error;
2661 : }
2662 :
2663 :
2664 : /*---------------------------------------------------------------------*
2665 : * IVAS_DEC_VoIP_GetSamples( )
2666 : *
2667 : * Main function to decode one frame in VoIP
2668 : *---------------------------------------------------------------------*/
2669 :
2670 19595 : ivas_error IVAS_DEC_VoIP_GetSamples(
2671 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2672 : UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */
2673 : Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */
2674 : const UWord32 systemTimestamp_ms /* i : current system timestamp */
2675 : #ifdef SUPPORT_JBM_TRACEFILE
2676 : ,
2677 : JbmTraceFileWriterFn jbmWriterFn,
2678 : void *jbmWriter
2679 : #endif
2680 : )
2681 : {
2682 : Decoder_Struct *st_ivas;
2683 : DECODER_CONFIG_HANDLE hDecoderConfig;
2684 : IVAS_DEC_VOIP *hVoIP;
2685 : UWord32 extBufferedTime_ms, scale, maxScaling;
2686 : JB4_DATAUNIT_HANDLE dataUnit;
2687 : UWord16 extBufferedSamples;
2688 : Word16 timeScalingDone;
2689 : Word16 result;
2690 : ivas_error error;
2691 : Word16 nSamplesRendered;
2692 : UWord8 nOutChannels;
2693 :
2694 19595 : st_ivas = hIvasDec->st_ivas;
2695 19595 : hDecoderConfig = st_ivas->hDecoderConfig;
2696 19595 : hVoIP = hIvasDec->hVoIP;
2697 19595 : timeScalingDone = 0;
2698 19595 : nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out;
2699 19595 : nSamplesRendered = 0;
2700 19595 : move16();
2701 19595 : move16();
2702 19595 : move16();
2703 :
2704 19595 : IF( nSamplesPerChannel == 0 )
2705 : {
2706 0 : return IVAS_ERR_WRONG_PARAMS;
2707 : }
2708 :
2709 : /* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */
2710 51180 : WHILE( LT_16( nSamplesRendered, nSamplesPerChannel ) )
2711 : {
2712 31585 : IF( hIvasDec->nSamplesAvailableNext == 0 )
2713 : {
2714 : Word16 nSamplesBuffered;
2715 19595 : nSamplesBuffered = 0;
2716 19595 : move16();
2717 19595 : IF( hIvasDec->hasBeenFedFirstGoodFrame )
2718 : {
2719 19378 : IF( NE_32( ( error = IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ) ), IVAS_ERR_OK ) )
2720 : {
2721 0 : return error;
2722 : }
2723 : }
2724 :
2725 19595 : extBufferedSamples = add( nSamplesRendered, nSamplesBuffered );
2726 : Word16 exp;
2727 19595 : extBufferedTime_ms = BASOP_Util_Divide3232_Scale( imult3216( extBufferedSamples, 1000 ), hDecoderConfig->output_Fs, &exp );
2728 19595 : extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, sub( 15, exp ) ); // Q0
2729 19595 : dataUnit = NULL;
2730 :
2731 : /* pop one access unit from the jitter buffer */
2732 19595 : result = JB4_PopDataUnit( hVoIP->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling );
2733 19595 : IF( result != 0 )
2734 : {
2735 0 : return IVAS_ERR_UNKNOWN;
2736 : }
2737 :
2738 19595 : IF( EQ_32( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
2739 : {
2740 0 : if ( GT_32( maxScaling, 20 ) )
2741 : {
2742 0 : maxScaling = 20;
2743 0 : move16();
2744 : }
2745 : }
2746 19595 : maxScaling = Mult_32_32( imult3216( hDecoderConfig->output_Fs, (Word16) maxScaling ), INV_1000_Q31 );
2747 :
2748 : /* avoid time scaling multiple times in one sound card slot */
2749 19595 : IF( NE_64( scale, 100U ) )
2750 : {
2751 718 : IF( timeScalingDone )
2752 : {
2753 4 : scale = 100;
2754 4 : move32();
2755 : }
2756 : ELSE
2757 : {
2758 714 : timeScalingDone = 1;
2759 714 : move16();
2760 : }
2761 : }
2762 :
2763 : /* limit scale to range supported by time scaler */
2764 19595 : IF( LT_32( scale, APA_MIN_SCALE ) )
2765 : {
2766 0 : scale = APA_MIN_SCALE;
2767 0 : move32();
2768 : }
2769 19595 : ELSE IF( GT_32( scale, APA_MAX_SCALE ) )
2770 : {
2771 0 : scale = APA_MAX_SCALE;
2772 0 : move32();
2773 : }
2774 :
2775 19595 : IF( NE_32( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, (Word16) maxScaling, (Word16) scale ) ), IVAS_ERR_OK ) )
2776 : {
2777 0 : return error;
2778 : }
2779 :
2780 : /* copy bitstream into decoder state */
2781 19595 : IF( dataUnit )
2782 : {
2783 17540 : hIvasDec->hVoIP->hCurrentDataUnit = dataUnit;
2784 :
2785 17540 : bsCompactToSerial( dataUnit->data, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize );
2786 :
2787 :
2788 17540 : IF( NE_32( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ) ), IVAS_ERR_OK ) )
2789 : {
2790 0 : return error;
2791 : }
2792 : }
2793 2055 : ELSE IF( hIvasDec->hasDecodedFirstGoodFrame )
2794 : {
2795 : /* Decoder has been initialized with first good frame - do PLC */
2796 1865 : IF( NE_32( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 ) ), IVAS_ERR_OK ) )
2797 : {
2798 0 : return error;
2799 : }
2800 : }
2801 :
2802 : #ifdef SUPPORT_JBM_TRACEFILE
2803 : /* jbmWriterFn and jbmWriter may be NULL if tracefile writing was not requested on CLI */
2804 19595 : test();
2805 19595 : IF( jbmWriterFn != NULL && jbmWriter != NULL )
2806 : {
2807 : /* write JBM trace data entry */
2808 19595 : store_JbmData( hVoIP, dataUnit, systemTimestamp_ms, extBufferedSamples, hDecoderConfig->output_Fs );
2809 19595 : IF( ( jbmWriterFn( &hVoIP->JbmTraceData, jbmWriter ) ) != IVAS_ERR_OK )
2810 : {
2811 0 : fprintf( stderr, "\nError writing JBM Trace data to file\n" );
2812 0 : return IVAS_ERR_UNKNOWN;
2813 : }
2814 : }
2815 : #endif
2816 19595 : IF( dataUnit )
2817 : {
2818 17540 : IF( dataUnit->partial_frame != 0 )
2819 : {
2820 41 : hVoIP->lastDecodedWasActive = 1;
2821 : }
2822 : ELSE
2823 : {
2824 17499 : hVoIP->lastDecodedWasActive = !dataUnit->silenceIndicator;
2825 : }
2826 17540 : move16();
2827 :
2828 : /* data unit memory is no longer used */
2829 17540 : JB4_FreeDataUnit( hVoIP->hJBM, dataUnit );
2830 : }
2831 :
2832 19595 : IF( !hIvasDec->hasBeenFedFirstGoodFrame )
2833 : {
2834 190 : hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;
2835 190 : hIvasDec->nSamplesRendered = 0;
2836 190 : move16();
2837 190 : move16();
2838 : }
2839 : }
2840 :
2841 : /* decode */
2842 31585 : IF( !hIvasDec->hasBeenFedFirstGoodFrame )
2843 : {
2844 : /* codec mode to use not known yet - simply output silence */
2845 : /* directly set output zero */
2846 190 : Word16 nSamplesToZero = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext );
2847 190 : set16_fx( pcmBuf + imult1616( nSamplesRendered, nOutChannels ), 0, imult1616( nSamplesToZero, nOutChannels ) );
2848 190 : nSamplesRendered = add( nSamplesRendered, nSamplesToZero );
2849 190 : hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesToZero );
2850 190 : hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesToZero );
2851 190 : move16();
2852 190 : move16();
2853 : }
2854 : ELSE
2855 : {
2856 : Word16 nSamplesToRender, nSamplesRendered_loop;
2857 : bool tmp;
2858 31395 : nSamplesToRender = sub( nSamplesPerChannel, nSamplesRendered );
2859 :
2860 : /* render IVAS frames directly to the output buffer */
2861 31395 : IF( NE_32( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + imult1616( nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) )
2862 : {
2863 0 : return error;
2864 : }
2865 :
2866 31395 : nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
2867 : }
2868 : }
2869 :
2870 19595 : return IVAS_ERR_OK;
2871 : }
2872 :
2873 :
2874 : /*---------------------------------------------------------------------*
2875 : * IVAS_DEC_VoIP_Flush( )
2876 : *
2877 : * Function to flush remaining audio in VoIP
2878 : *---------------------------------------------------------------------*/
2879 :
2880 0 : ivas_error IVAS_DEC_Flush(
2881 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2882 : const Word16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */
2883 : Word16 *pcmBuf, /* i/o: buffer for decoded PCM output. The memory must already be allocated and be able to hold the expected number of output samples, based on frame size and number of output channels Q0 */
2884 : Word16 *nSamplesFlushed /* o : number of samples flushed */
2885 : )
2886 : {
2887 : ivas_error error;
2888 : UWord16 nSamplesToRender;
2889 : UWord16 nSamplesFlushedLocal;
2890 :
2891 0 : *nSamplesFlushed = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext );
2892 0 : move16();
2893 :
2894 0 : nSamplesToRender = (UWord16) *nSamplesFlushed;
2895 0 : move16();
2896 :
2897 : /* render IVAS frames */
2898 0 : error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf );
2899 :
2900 0 : return error;
2901 : }
2902 :
2903 :
2904 : /*---------------------------------------------------------------------*
2905 : * IVAS_DEC_VoIP_IsEmpty( )
2906 : *
2907 : *
2908 : *---------------------------------------------------------------------*/
2909 :
2910 206 : bool IVAS_DEC_VoIP_IsEmpty(
2911 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2912 : const Word16 nSamplesAsked )
2913 : {
2914 206 : test();
2915 206 : return ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 && LT_16( hIvasDec->nSamplesAvailableNext, nSamplesAsked ) );
2916 : }
2917 :
2918 :
2919 : /*---------------------------------------------------------------------*
2920 : * IVAS_DEC_VoIP_Get_CA_offset( )
2921 : *
2922 : *
2923 : *---------------------------------------------------------------------*/
2924 :
2925 0 : ivas_error IVAS_DEC_VoIP_Get_CA_offset(
2926 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2927 : Word16 *optimum_offset,
2928 : Word16 *FEC_hi )
2929 : {
2930 0 : test();
2931 0 : test();
2932 0 : IF( ( hIvasDec == NULL || hIvasDec->hVoIP == NULL || hIvasDec->hVoIP->hJBM == NULL ) )
2933 : {
2934 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2935 : }
2936 :
2937 0 : *optimum_offset = JB4_getFECoffset( hIvasDec->hVoIP->hJBM );
2938 0 : *FEC_hi = JB4_FECoffset( hIvasDec->hVoIP->hJBM );
2939 0 : move16();
2940 0 : move16();
2941 :
2942 0 : return IVAS_ERR_OK;
2943 : }
2944 :
2945 :
2946 : /*---------------------------------------------------------------------*
2947 : * IVAS_DEC_Close_VoIP( )
2948 : *
2949 : *
2950 : *---------------------------------------------------------------------*/
2951 :
2952 27 : static void IVAS_DEC_Close_VoIP(
2953 : IVAS_DEC_VOIP *hVoIP /* i/o: IVAS decoder handle */
2954 : )
2955 : {
2956 27 : JB4_Destroy( &hVoIP->hJBM );
2957 :
2958 27 : IF( hVoIP->bs_conversion_buf != NULL )
2959 : {
2960 : #define WMC_TOOL_SKIP
2961 : /* Bitstream conversion is not counted towards complexity and memory usage */
2962 27 : free( hVoIP->bs_conversion_buf );
2963 : #undef WMC_TOOL_SKIP
2964 : }
2965 :
2966 27 : free( hVoIP );
2967 :
2968 27 : return;
2969 : }
2970 :
2971 :
2972 : #ifdef SUPPORT_JBM_TRACEFILE
2973 : /*---------------------------------------------------------------------*
2974 : * store_JbmData()
2975 : *
2976 : * Store JBM trace data entry
2977 : *---------------------------------------------------------------------*/
2978 :
2979 19595 : static void store_JbmData(
2980 : IVAS_DEC_VOIP *hVoIP,
2981 : JB4_DATAUNIT_HANDLE dataUnit,
2982 : const UWord32 systemTimestamp_ms,
2983 : const UWord16 extBufferedSamples,
2984 : const Word32 output_Fs )
2985 : {
2986 : IVAS_JBM_TRACE_DATA *JbmTraceData;
2987 :
2988 19595 : IF( hVoIP == NULL )
2989 : {
2990 0 : return;
2991 : }
2992 :
2993 19595 : JbmTraceData = &hVoIP->JbmTraceData;
2994 :
2995 19595 : JbmTraceData->systemTimestamp_ms = systemTimestamp_ms;
2996 19595 : JbmTraceData->extBufferedSamples = extBufferedSamples;
2997 19595 : JbmTraceData->lastDecodedWasActive = hVoIP->lastDecodedWasActive;
2998 19595 : JbmTraceData->output_Fs = output_Fs;
2999 19595 : JbmTraceData->dataUnit_flag = dataUnit != NULL;
3000 19595 : move16();
3001 19595 : move16();
3002 19595 : move16();
3003 19595 : move32();
3004 19595 : move32();
3005 19595 : IF( dataUnit != NULL )
3006 : {
3007 17540 : JbmTraceData->sequenceNumber = dataUnit->sequenceNumber;
3008 17540 : JbmTraceData->timeStamp = dataUnit->timeStamp;
3009 17540 : JbmTraceData->rcvTime = dataUnit->rcvTime;
3010 17540 : JbmTraceData->partial_frame = dataUnit->partial_frame;
3011 17540 : JbmTraceData->partialCopyOffset = dataUnit->partialCopyOffset;
3012 17540 : move16();
3013 17540 : move16();
3014 17540 : move16();
3015 17540 : move32();
3016 17540 : move32();
3017 : }
3018 :
3019 19595 : return;
3020 : }
3021 :
3022 :
3023 : /*---------------------------------------------------------------------*
3024 : * IVAS_DEC_GetJbmData()
3025 : *
3026 : *
3027 : *---------------------------------------------------------------------*/
3028 :
3029 0 : ivas_error IVAS_DEC_GetJbmData(
3030 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3031 : IVAS_JBM_TRACE_DATA *JbmTraceData /* o : JBM Trace data */
3032 :
3033 : )
3034 : {
3035 0 : IF( hIvasDec->hVoIP == NULL )
3036 : {
3037 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3038 : }
3039 :
3040 0 : *JbmTraceData = hIvasDec->hVoIP->JbmTraceData;
3041 :
3042 0 : return IVAS_ERR_OK;
3043 : }
3044 :
3045 : #endif
3046 :
3047 :
3048 : /*---------------------------------------------------------------------*
3049 : * IVAS_DEC_GetErrorMessage( )
3050 : *
3051 : * Maps error codes to error description strings
3052 : *---------------------------------------------------------------------*/
3053 :
3054 6 : const char *IVAS_DEC_GetErrorMessage(
3055 : ivas_error error /* i : decoder error code enum */
3056 : )
3057 : {
3058 6 : return ivas_error_to_string( error );
3059 : }
3060 :
3061 :
3062 : /*---------------------------------------------------------------------*
3063 : * printConfigInfo_dec( )
3064 : *
3065 : *
3066 : *---------------------------------------------------------------------*/
3067 :
3068 604 : static ivas_error printConfigInfo_dec(
3069 : Decoder_Struct *st_ivas,
3070 : const Word16 bitstreamformat,
3071 : const bool Opt_VOIP,
3072 : const bool quietModeEnabled )
3073 : {
3074 : ivas_error error;
3075 : Word8 config_str[50];
3076 : AUDIO_CONFIG output_config;
3077 :
3078 : /*-----------------------------------------------------------------*
3079 : * Print info on screen
3080 : *-----------------------------------------------------------------*/
3081 :
3082 604 : fprintf( stdout, "\n" );
3083 :
3084 : /*-----------------------------------------------------------------*
3085 : * Print output sampling frequency
3086 : *-----------------------------------------------------------------*/
3087 :
3088 604 : fprintf( stdout, "Output sampling rate: %d Hz\n", st_ivas->hDecoderConfig->output_Fs );
3089 :
3090 : /*-----------------------------------------------------------------*
3091 : * Print bitrate
3092 : *-----------------------------------------------------------------*/
3093 :
3094 604 : IF( !quietModeEnabled )
3095 : {
3096 0 : IF( !Opt_VOIP )
3097 : {
3098 0 : fprintf( stdout, "Bitrate: %.2f kbps\n", (float) st_ivas->hDecoderConfig->ivas_total_brate / 1000 );
3099 :
3100 0 : IF( st_ivas->hDecoderConfig->ivas_total_brate <= 0 )
3101 : {
3102 0 : IF( EQ_16( bitstreamformat, G192 ) )
3103 : {
3104 0 : fprintf( stdout, "Active Bitrate not identified in bitstream file \n" );
3105 : }
3106 : ELSE /* MIME */
3107 : {
3108 0 : fprintf( stdout, "Active Bitrate not identified from first MIME frame \n" );
3109 : }
3110 : }
3111 : }
3112 : }
3113 :
3114 : /*-----------------------------------------------------------------*
3115 : * Print output configuration
3116 : *-----------------------------------------------------------------*/
3117 :
3118 604 : IF( EQ_16( (Word16) st_ivas->ivas_format, MONO_FORMAT ) )
3119 : {
3120 3 : IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan )
3121 : {
3122 1 : fprintf( stdout, "Output configuration: mono EVS bit-exact decoding to stereo\n" );
3123 1 : float non_diegetic_pan_gain = fixedToFloat( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, 15 );
3124 1 : fprintf( stdout, "Non-diegetic panning: %.2f\n", non_diegetic_pan_gain * 90.f );
3125 : }
3126 : ELSE
3127 : {
3128 2 : fprintf( stdout, "Output configuration: mono EVS bit-exact decoding\n" );
3129 : }
3130 : }
3131 : ELSE
3132 : {
3133 601 : IF( !quietModeEnabled )
3134 : {
3135 0 : IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) )
3136 : {
3137 0 : fprintf( stdout, "Input configuration: Stereo\n" );
3138 : }
3139 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) )
3140 : {
3141 0 : IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MODE_PARAM ) )
3142 : {
3143 0 : fprintf( stdout, "Input configuration: ISM (ParamISM): 2 transport channels\n" );
3144 : }
3145 : ELSE
3146 : {
3147 0 : fprintf( stdout, "Input configuration: ISM: %d transport channel(s)\n", st_ivas->nchan_transport );
3148 : }
3149 : }
3150 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) )
3151 : {
3152 0 : fprintf( stdout, "Input configuration: Scene Based Audio, Ambisonic order %i%s, %d transport channel(s)\n", st_ivas->sba_order, st_ivas->sba_planar ? " (Planar)" : "", st_ivas->nchan_transport );
3153 : }
3154 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_ISM_FORMAT ) )
3155 : {
3156 0 : fprintf( stdout, "Input configuration: Combined Scene Based Audio, Ambisonic order %i, with %d Objects \n", st_ivas->sba_order, st_ivas->nchan_ism );
3157 : }
3158 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) )
3159 : {
3160 0 : fprintf( stdout, "Input configuration: MASA - %d channel(s)\n", st_ivas->nchan_transport );
3161 : }
3162 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) )
3163 : {
3164 0 : IF( NE_32( ( error = get_channel_config( st_ivas->transport_config, &config_str[0] ) ), IVAS_ERR_OK ) )
3165 : {
3166 0 : return error;
3167 : }
3168 :
3169 0 : fprintf( stdout, "Input configuration: %s\n", config_str );
3170 : }
3171 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) )
3172 : {
3173 0 : fprintf( stdout, "Input configuration: combined ISM and MASA (%i ISM stream(s)) \n", st_ivas->nchan_ism );
3174 : }
3175 : }
3176 :
3177 601 : output_config = st_ivas->hDecoderConfig->output_config;
3178 601 : move16();
3179 601 : get_channel_config( output_config, &config_str[0] );
3180 601 : fprintf( stdout, "Output configuration: %s\n", config_str );
3181 :
3182 601 : test();
3183 601 : test();
3184 601 : IF( ( EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) )
3185 : {
3186 193 : fprintf( stdout, "Render framesize: %dms\n", get_render_frame_size_ms( st_ivas->hDecoderConfig->render_framesize ) );
3187 : }
3188 601 : IF( st_ivas->hDecoderConfig->Opt_HRTF_binary )
3189 : {
3190 23 : fprintf( stdout, "HRIR/BRIR file: ON\n" );
3191 : }
3192 :
3193 601 : IF( st_ivas->hDecoderConfig->Opt_RendConfigCustom )
3194 : {
3195 29 : fprintf( stdout, "Renderer config. file: ON\n" );
3196 : }
3197 :
3198 601 : IF( st_ivas->hDecoderConfig->Opt_Headrotation )
3199 : {
3200 81 : fprintf( stdout, "Head rotation: ON\n" );
3201 : }
3202 :
3203 601 : IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation )
3204 : {
3205 31 : fprintf( stdout, "External orientation: ON\n" );
3206 : }
3207 :
3208 601 : IF( NE_16( (Word16) st_ivas->hDecoderConfig->orientation_tracking, IVAS_HEAD_ORIENT_TRK_NONE ) )
3209 : {
3210 16 : SWITCH( st_ivas->hDecoderConfig->orientation_tracking )
3211 : {
3212 12 : case IVAS_HEAD_ORIENT_TRK_AVG:
3213 12 : fprintf( stdout, "Orientation tracking: AVG\n" );
3214 12 : BREAK;
3215 0 : case IVAS_HEAD_ORIENT_TRK_REF:
3216 0 : fprintf( stdout, "Orientation tracking: REF\n" );
3217 0 : BREAK;
3218 2 : case IVAS_HEAD_ORIENT_TRK_REF_VEC:
3219 2 : fprintf( stdout, "Orientation tracking: REF_VEC\n" );
3220 2 : BREAK;
3221 2 : case IVAS_HEAD_ORIENT_TRK_REF_VEC_LEV:
3222 2 : fprintf( stdout, "Orientation tracking: REF_VEC_LEV\n" );
3223 2 : BREAK;
3224 0 : default:
3225 0 : BREAK;
3226 : }
3227 585 : }
3228 :
3229 601 : IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan )
3230 : {
3231 1 : float non_diegetic_pan_gain = fixedToFloat( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, 15 );
3232 1 : fprintf( stdout, "Non-diegetic panning: %.2f\n", non_diegetic_pan_gain * 90.f );
3233 : }
3234 :
3235 601 : IF( st_ivas->hDecoderConfig->Opt_dpid_on )
3236 : {
3237 2 : fprintf( stdout, "Directivity pattern: ON\n" );
3238 : }
3239 :
3240 601 : IF( st_ivas->hDecoderConfig->Opt_aeid_on )
3241 : {
3242 1 : fprintf( stdout, "Acoustic environment ID:ON\n" );
3243 : }
3244 : }
3245 :
3246 : /*-----------------------------------------------------------------*
3247 : * Print TSM mode info
3248 : *-----------------------------------------------------------------*/
3249 :
3250 604 : IF( st_ivas->hDecoderConfig->Opt_tsm )
3251 : {
3252 27 : fprintf( stdout, "TSM mode: ON\n" );
3253 : }
3254 :
3255 604 : return IVAS_ERR_OK;
3256 : }
3257 :
3258 :
3259 : /*---------------------------------------------------------------------*
3260 : * IVAS_DEC_PrintConfig( )
3261 : *
3262 : * Print decoder set-up info
3263 : *---------------------------------------------------------------------*/
3264 :
3265 604 : void IVAS_DEC_PrintConfig(
3266 : const IVAS_DEC_HANDLE hIvasDec,
3267 : const bool quietModeEnabled,
3268 : const bool voipMode )
3269 : {
3270 604 : printConfigInfo_dec( hIvasDec->st_ivas, hIvasDec->bitstreamformat, voipMode, quietModeEnabled );
3271 :
3272 604 : return;
3273 : }
3274 :
3275 :
3276 : /*---------------------------------------------------------------------*
3277 : * IVAS_DEC_PrintDisclaimer( )
3278 : *
3279 : * Print IVAS disclaimer to console
3280 : *---------------------------------------------------------------------*/
3281 :
3282 620 : void IVAS_DEC_PrintDisclaimer( void )
3283 : {
3284 620 : print_disclaimer( stderr );
3285 :
3286 620 : return;
3287 : }
3288 :
3289 :
3290 : /*---------------------------------------------------------------------*
3291 : * evs_dec_main( )
3292 : *
3293 : * EVS codec main decoder fucntion
3294 : *---------------------------------------------------------------------*/
3295 :
3296 3100 : static ivas_error evs_dec_main_fx(
3297 : Decoder_Struct *st_ivas,
3298 : const Word16 nOutSamples,
3299 : Word32 *Buf_fx, // Q11
3300 : Word16 *pcmBuf // Q0
3301 : )
3302 : {
3303 : DEC_CORE_HANDLE *hCoreCoder;
3304 : Word16 mixer_left_fx, mixer_right_fx;
3305 : Word32 *p_output_fx[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN];
3306 : Word16 ch, n, i;
3307 : Word16 output_16[L_FRAME48k];
3308 : ivas_error error;
3309 :
3310 3100 : hCoreCoder = st_ivas->hSCE[0]->hCoreCoder;
3311 3100 : hCoreCoder[0]->total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
3312 3100 : hCoreCoder[0]->total_num_bits = st_ivas->num_bits;
3313 3100 : move16();
3314 3100 : move32();
3315 3100 : hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 /*Q0*/ ) ); // Q0
3316 3100 : move16();
3317 3100 : mdct_switching_dec_fx( hCoreCoder[0] );
3318 :
3319 9300 : FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ )
3320 : {
3321 6200 : p_output_fx[ch] = st_ivas->p_output_fx[ch]; // Q0
3322 : }
3323 :
3324 : /* run the main EVS decoding routine */
3325 3100 : IF( EQ_16( hCoreCoder[0]->codec_mode, MODE1 ) )
3326 : {
3327 1852 : IF( hCoreCoder[0]->Opt_AMR_WB )
3328 : {
3329 0 : IF( NE_32( ( error = amr_wb_dec_fx( output_16, hCoreCoder[0] ) ), IVAS_ERR_OK ) )
3330 : {
3331 0 : return error;
3332 : }
3333 : }
3334 : ELSE
3335 : {
3336 1852 : IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) )
3337 : {
3338 0 : return error;
3339 : }
3340 : }
3341 : }
3342 : ELSE
3343 : {
3344 1248 : IF( hCoreCoder[0]->bfi == 0 )
3345 : {
3346 1248 : IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) )
3347 : {
3348 0 : return error;
3349 : }
3350 : }
3351 0 : ELSE IF( EQ_16( hCoreCoder[0]->bfi, 2 ) )
3352 : {
3353 0 : IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_FUTURE ) ), IVAS_ERR_OK ) )
3354 : {
3355 0 : return error;
3356 : }
3357 : }
3358 : ELSE
3359 : {
3360 0 : IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_MISSING ) ), IVAS_ERR_OK ) )
3361 : {
3362 0 : return error;
3363 : }
3364 : }
3365 : }
3366 :
3367 2643100 : FOR( i = 0; i < nOutSamples; i++ )
3368 : {
3369 2640000 : p_output_fx[0][i] = L_shl( output_16[i], Q11 ); /* Q11 */
3370 : }
3371 :
3372 3100 : st_ivas->BER_detect = hCoreCoder[0]->BER_detect;
3373 3100 : move16();
3374 3100 : IF( EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
3375 : {
3376 1000 : mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); // Q14
3377 1000 : mixer_right_fx = sub( MAX16B, mixer_left_fx );
3378 :
3379 1000 : v_multc_fixed_16( p_output_fx[0], mixer_right_fx, p_output_fx[1], nOutSamples ); /* Q11 */
3380 1000 : v_multc_fixed_16( p_output_fx[0], mixer_left_fx, p_output_fx[0], nOutSamples ); /* Q11 */
3381 : }
3382 :
3383 3100 : IF( !st_ivas->hDecoderConfig->Opt_tsm )
3384 : {
3385 3100 : ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, nOutSamples );
3386 : }
3387 0 : ELSE IF( Buf_fx != NULL )
3388 : {
3389 0 : FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
3390 : {
3391 0 : FOR( i = 0; i < nOutSamples; i++ )
3392 : {
3393 0 : Buf_fx[i * st_ivas->hDecoderConfig->nchan_out + n] = p_output_fx[n][i]; /* Does the same as above */ /* Q11 */
3394 0 : move32();
3395 : }
3396 : }
3397 : }
3398 : ELSE
3399 : {
3400 : /* ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); */
3401 0 : FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
3402 : {
3403 0 : FOR( i = 0; i < nOutSamples; i++ )
3404 : {
3405 0 : pcmBuf[i * st_ivas->hDecoderConfig->nchan_out + n] = extract_l( L_shr( p_output_fx[n][i], Q11 ) ); /* Does the same as above */ /* Q0 */
3406 0 : move16();
3407 : }
3408 : }
3409 : }
3410 :
3411 3100 : return IVAS_ERR_OK;
3412 : }
3413 :
3414 :
3415 : /*---------------------------------------------------------------------*
3416 : * input_format_API_to_internal()
3417 : *
3418 : *
3419 : *---------------------------------------------------------------------*/
3420 :
3421 27 : static ivas_error input_format_API_to_internal(
3422 : IVAS_DEC_INPUT_FORMAT input_format,
3423 : Word16 *bitstream_format_internal,
3424 : Word16 *sdp_hf_only,
3425 : const bool is_voip_enabled )
3426 : {
3427 27 : SWITCH( input_format )
3428 : {
3429 27 : case IVAS_DEC_INPUT_FORMAT_G192:
3430 27 : IF( is_voip_enabled )
3431 : {
3432 27 : *bitstream_format_internal = VOIP_G192_RTP;
3433 : }
3434 : ELSE
3435 : {
3436 0 : *bitstream_format_internal = G192;
3437 : }
3438 27 : *sdp_hf_only = 0;
3439 27 : BREAK;
3440 0 : case IVAS_DEC_INPUT_FORMAT_MIME:
3441 0 : *bitstream_format_internal = MIME;
3442 0 : *sdp_hf_only = 0;
3443 0 : BREAK;
3444 0 : case IVAS_DEC_INPUT_FORMAT_RTPDUMP:
3445 0 : assert( is_voip_enabled && "RTP dump only supported in VoIP mode" );
3446 0 : *bitstream_format_internal = VOIP_RTPDUMP;
3447 0 : *sdp_hf_only = 0;
3448 0 : BREAK;
3449 0 : case IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF:
3450 0 : assert( is_voip_enabled && "RTP dump only supported in VoIP mode" );
3451 0 : *bitstream_format_internal = VOIP_RTPDUMP;
3452 0 : *sdp_hf_only = 1;
3453 0 : BREAK;
3454 0 : default:
3455 0 : return IVAS_ERR_INVALID_BITSTREAM;
3456 : }
3457 :
3458 27 : move16();
3459 27 : move16();
3460 27 : return IVAS_ERR_OK;
3461 : }
3462 :
3463 :
3464 : /*---------------------------------------------------------------------*
3465 : * IVAS_DEC_VoIP_reconfigure()
3466 : *
3467 : *
3468 : *---------------------------------------------------------------------*/
3469 :
3470 953 : static ivas_error IVAS_DEC_VoIP_reconfigure(
3471 : IVAS_DEC_HANDLE hIvasDec,
3472 : const UWord16 nTransportChannels,
3473 : const UWord16 l_ts )
3474 : {
3475 : Word16 apa_buffer_size;
3476 :
3477 953 : apa_buffer_size = hIvasDec->nSamplesFrame;
3478 953 : move16();
3479 :
3480 953 : IF( hIvasDec->apaExecBuffer_fx == NULL )
3481 : {
3482 : DECODER_CONFIG_HANDLE hDecoderConfig;
3483 :
3484 27 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
3485 : {
3486 : UWord16 wss, css;
3487 : Word32 startQuality;
3488 :
3489 27 : startQuality = L_shl( L_deposit_l( hIvasDec->tsm_quality ), Q2 ); /* Q14 --> Q16*/
3490 27 : apa_buffer_size = APA_BUF_PER_CHANNEL;
3491 :
3492 27 : move16();
3493 : /* get current renderer type*/
3494 27 : hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;
3495 :
3496 27 : IF( EQ_32( hDecoderConfig->output_Fs, 8000 ) )
3497 : {
3498 0 : wss = 1;
3499 0 : css = 1;
3500 : }
3501 27 : ELSE IF( EQ_32( hDecoderConfig->output_Fs, 16000 ) )
3502 : {
3503 3 : wss = 2;
3504 3 : css = 1;
3505 : }
3506 24 : ELSE IF( EQ_32( hDecoderConfig->output_Fs, 32000 ) )
3507 : {
3508 8 : wss = 4;
3509 8 : css = 2;
3510 : }
3511 16 : ELSE IF( EQ_32( hDecoderConfig->output_Fs, 48000 ) )
3512 : {
3513 16 : wss = 6;
3514 16 : css = 3;
3515 : }
3516 : ELSE
3517 : {
3518 0 : return IVAS_ERR_INIT_ERROR;
3519 : }
3520 :
3521 27 : move16();
3522 27 : move16();
3523 27 : test();
3524 27 : test();
3525 27 : test();
3526 27 : test();
3527 27 : IF( NE_32( (Word32) apa_init( &hIvasDec->hTimeScaler, nTransportChannels ), IVAS_ERR_OK ) ||
3528 : apa_set_rate( hIvasDec->hTimeScaler, hDecoderConfig->output_Fs ) != 0 ||
3529 : apa_set_complexity_options( hIvasDec->hTimeScaler, wss, css ) != 0 ||
3530 : apa_set_quality( hIvasDec->hTimeScaler, startQuality, 4, 4 ) != 0 ||
3531 : apa_set_renderer_granularity( hIvasDec->hTimeScaler, l_ts ) != 0 )
3532 : {
3533 0 : return IVAS_ERR_INIT_ERROR;
3534 : }
3535 :
3536 27 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
3537 : {
3538 0 : IF( apa_set_evs_compat_mode( hIvasDec->hTimeScaler, true ) != 0 )
3539 : {
3540 0 : return IVAS_ERR_INIT_ERROR;
3541 : }
3542 : }
3543 :
3544 27 : IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL )
3545 : {
3546 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
3547 : }
3548 :
3549 27 : set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) );
3550 : }
3551 : }
3552 : ELSE
3553 : {
3554 926 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
3555 : {
3556 926 : IF( apa_reconfigure( hIvasDec->hTimeScaler, nTransportChannels, l_ts ) != 0 )
3557 : {
3558 0 : return IVAS_ERR_INIT_ERROR;
3559 : }
3560 926 : apa_buffer_size = APA_BUF_PER_CHANNEL;
3561 926 : move16();
3562 926 : free( hIvasDec->apaExecBuffer_fx );
3563 926 : IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL )
3564 : {
3565 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
3566 : }
3567 926 : set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) );
3568 : }
3569 : /* realloc apa_exe_buffer */
3570 : }
3571 :
3572 953 : hIvasDec->nTransportChannelsOld = nTransportChannels;
3573 953 : move16();
3574 :
3575 953 : return IVAS_ERR_OK;
3576 : }
|