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 "isar_prot.h"
41 : #include "lib_isar_pre_rend.h"
42 : #include "ivas_prot_fx.h"
43 : #include "jbm_jb4sb.h"
44 : #include "jbm_pcmdsp_apa.h"
45 : #include "jbm_pcmdsp_fifo.h"
46 : #include <math.h>
47 : #include <assert.h>
48 : #include "wmc_auto.h"
49 :
50 : #define INV_1000_Q31 2147484 /*1/1000 IN Q31*/
51 :
52 : /*---------------------------------------------------------------------*
53 : * Local structs
54 : *---------------------------------------------------------------------*/
55 :
56 : struct IVAS_DEC_VOIP
57 : {
58 : UWord16 nSamplesFrame; /* Total number of samples in a frame (includes number of channels) */
59 : JB4_HANDLE hJBM;
60 : UWord16 lastDecodedWasActive;
61 : JB4_DATAUNIT_HANDLE hCurrentDataUnit; /* Points to the currently processed data unit */
62 : UWord16 *bs_conversion_buf; /* Buffer for bitstream conversion from packed to serial */
63 : Word16 nSamplesRendered20ms; /* how many samples have been rendered since the last 20ms render border*/
64 : #ifdef SUPPORT_JBM_TRACEFILE
65 : IVAS_JBM_TRACE_DATA JbmTraceData;
66 : #endif
67 : };
68 :
69 : typedef struct IVAS_DEC_VOIP IVAS_DEC_VOIP;
70 :
71 : struct IVAS_DEC
72 : {
73 : IVAS_DEC_MODE mode;
74 : UWord16 nSamplesFrame;
75 : Decoder_Struct *st_ivas;
76 : IVAS_DEC_VOIP *hVoIP;
77 : bool hasBeenFedFirstGoodFrame; /* False on init. Gets set to true after first good frame has been fed into the decoder, but not decoded yet. */
78 : 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 */
79 : bool isInitialized;
80 :
81 : Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */
82 : bool Opt_VOIP; /* flag indicating VOIP mode with JBM */
83 : Word16 tsm_scale; /* scale for TSM operation */
84 : Word16 tsm_max_scaling;
85 : Word16 timeScalingDone; /* have we done already one TSM in a 20ms frame? */
86 : Word16 tsm_quality; /*Q14*/
87 : Word32 *apaExecBuffer_fx; /* Buffer for APA scaling */
88 : PCMDSP_APA_HANDLE hTimeScaler;
89 : bool needNewFrame;
90 : bool hasBeenFedFrame;
91 : bool updateOrientation;
92 : UWord16 nSamplesAvailableNext;
93 : Word16 nSamplesRendered;
94 : Word16 nTransportChannelsOld;
95 : Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */
96 : Word16 sdp_hf_only; /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */
97 : Word16 prev_ft_speech; /* RXDTX handler: previous frametype flag for G.192 format AMRWB SID_FIRST detection */
98 : Word16 CNG; /* RXDTX handler: CNG=1, nonCNG=0 */
99 : };
100 :
101 : /*---------------------------------------------------------------------*
102 : * Local function declarations
103 : *---------------------------------------------------------------------*/
104 :
105 : static void IVAS_DEC_Close_VoIP( IVAS_DEC_VOIP *hVoIP );
106 : #ifdef SUPPORT_JBM_TRACEFILE
107 : static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, const UWord32 systemTimestamp_ms, const UWord16 extBufferedSamples, const Word32 output_Fs );
108 : #endif
109 : static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas, const Word16 nOutSamples, Word32 *floatBuf, Word16 *pcmBuf );
110 : 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 );
111 : static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig );
112 : static ivas_error IVAS_DEC_VoIP_reconfigure( IVAS_DEC_HANDLE hIvasDec, const UWord16 nTransportChannels, const UWord16 l_ts );
113 : static ivas_error IVAS_DEC_Setup( IVAS_DEC_HANDLE hIvasDec, UWord16 *nTcBufferGranularity, UWord8 *nTransportChannels, UWord8 *nOutChannels, UWord16 *nSamplesRendered, Word16 *data );
114 : static ivas_error IVAS_DEC_GetTcSamples( IVAS_DEC_HANDLE hIvasDec, Word32 *pcmBuf_fx, Word16 *nOutSamples );
115 : static ivas_error IVAS_DEC_RendererFeedTcSamples( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesForRendering, Word16 *nSamplesResidual, Word32 *pcmBuf );
116 : static ivas_error IVAS_DEC_GetRenderedSamples( IVAS_DEC_HANDLE hIvasDec, const UWord16 nSamplesForRendering, UWord16 *nSamplesRendered, UWord16 *nSamplesAvailableNext, Word16 *pcmBuf );
117 : static ivas_error IVAS_DEC_GetBufferedNumberOfSamples( IVAS_DEC_HANDLE hIvasDec, Word16 *nSamplesBuffered );
118 : static Word16 get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize );
119 : static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesRendered );
120 : static ivas_error isar_set_split_rend_setup( ISAR_DEC_SPLIT_REND_WRAPPER *hSplitBinRend, const ISAR_SPLIT_REND_CONFIG_DATA *hSplitBinConfig, const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, ISAR_SPLIT_REND_BITS_DATA *splitRendBits );
121 : static ivas_error ivas_dec_reconfig_split_rend( Decoder_Struct *st_ivas );
122 : static ivas_error ivas_dec_init_split_rend( Decoder_Struct *st_ivas );
123 : static ivas_error ivas_create_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend_out );
124 : static void ivas_destroy_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend_out );
125 :
126 :
127 : /*---------------------------------------------------------------------*
128 : * IVAS_DEC_Open()
129 : *
130 : * Open IVAS decoder
131 : *---------------------------------------------------------------------*/
132 :
133 : /* may return an error but may still have allocated memory - thus run Close also in case of error to release memory */
134 613 : ivas_error IVAS_DEC_Open(
135 : IVAS_DEC_HANDLE *phIvasDec, /* i/o: pointer to an IVAS decoder handle to be opened */
136 : const IVAS_DEC_MODE mode /* i : compatibility mode (EVS or IVAS) */
137 : )
138 : {
139 : IVAS_DEC_HANDLE hIvasDec;
140 : Decoder_Struct *st_ivas;
141 :
142 613 : IF( phIvasDec == NULL )
143 : {
144 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
145 : }
146 :
147 : /*-----------------------------------------------------------------*
148 : * Allocate and initialize IVAS application decoder handle
149 : *-----------------------------------------------------------------*/
150 :
151 613 : IF( ( *phIvasDec = (IVAS_DEC_HANDLE) malloc( sizeof( struct IVAS_DEC ) ) ) == NULL )
152 : {
153 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" );
154 : }
155 :
156 613 : hIvasDec = *phIvasDec;
157 613 : hIvasDec->hVoIP = NULL;
158 613 : hIvasDec->apaExecBuffer_fx = NULL;
159 613 : hIvasDec->hTimeScaler = NULL;
160 613 : hIvasDec->tsm_scale = 100;
161 613 : hIvasDec->tsm_max_scaling = 0;
162 613 : hIvasDec->tsm_quality = ONE_IN_Q14; /*1.f Q14*/
163 613 : hIvasDec->timeScalingDone = 0;
164 613 : hIvasDec->needNewFrame = false;
165 613 : hIvasDec->nTransportChannelsOld = 0;
166 613 : hIvasDec->nSamplesAvailableNext = 0;
167 613 : hIvasDec->nSamplesRendered = 0;
168 613 : hIvasDec->nSamplesFrame = 0;
169 613 : hIvasDec->hasBeenFedFrame = false;
170 613 : hIvasDec->hasBeenFedFirstGoodFrame = false;
171 613 : hIvasDec->hasDecodedFirstGoodFrame = false;
172 613 : hIvasDec->isInitialized = false;
173 613 : hIvasDec->updateOrientation = false;
174 613 : move16();
175 613 : move16();
176 613 : move16();
177 613 : move16();
178 613 : move16();
179 613 : move16();
180 613 : move16();
181 613 : move16();
182 613 : move16();
183 613 : move16();
184 613 : move16();
185 613 : move16();
186 613 : move16();
187 :
188 613 : hIvasDec->mode = mode;
189 613 : move16();
190 :
191 613 : hIvasDec->bitstreamformat = G192;
192 613 : hIvasDec->Opt_VOIP = 0;
193 613 : hIvasDec->amrwb_rfc4867_flag = -1;
194 613 : hIvasDec->prev_ft_speech = 1; /* RXDTX handler previous frametype flag for G.192 format AMRWB SID_FIRST detection */
195 613 : hIvasDec->CNG = 0; /* RXDTX handler CNG = 1, no CNG = 0*/
196 613 : move16();
197 613 : move16();
198 613 : move16();
199 613 : move16();
200 613 : move16();
201 :
202 : /*-----------------------------------------------------------------*
203 : * Initialize IVAS-codec decoder state
204 : *-----------------------------------------------------------------*/
205 :
206 613 : IF( ( hIvasDec->st_ivas = (Decoder_Struct *) malloc( sizeof( Decoder_Struct ) ) ) == NULL )
207 : {
208 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder structure" );
209 : }
210 :
211 613 : IF( ( hIvasDec->st_ivas->hDecoderConfig = (DECODER_CONFIG_HANDLE) malloc( sizeof( DECODER_CONFIG ) ) ) == NULL )
212 : {
213 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Decoder config structure" );
214 : }
215 :
216 : /*-----------------------------------------------------------------*
217 : * Initialize IVAS-codec decoder state
218 : *-----------------------------------------------------------------*/
219 :
220 613 : st_ivas = hIvasDec->st_ivas;
221 :
222 : /* initialize Decoder Config. handle */
223 613 : init_decoder_config( hIvasDec->st_ivas->hDecoderConfig );
224 :
225 : /* initialize pointers to handles to NULL */
226 613 : ivas_initialize_handles_dec( st_ivas );
227 :
228 : /* set high-level parameters */
229 613 : IF( EQ_16( mode, IVAS_DEC_MODE_EVS ) )
230 : {
231 3 : st_ivas->codec_mode = 0; /* unknown before first frame */
232 3 : st_ivas->element_mode_init = EVS_MONO;
233 3 : st_ivas->ivas_format = MONO_FORMAT;
234 3 : st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID;
235 3 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID;
236 3 : st_ivas->writeFECoffset = 0;
237 3 : hIvasDec->hasDecodedFirstGoodFrame = true; /* Functionality to suppress output for initial lost frames is disabled in EVS operation */
238 3 : move16();
239 3 : move16();
240 3 : move16();
241 3 : move16();
242 3 : move16();
243 3 : move16();
244 3 : move16();
245 :
246 3 : return IVAS_ERR_OK;
247 : }
248 610 : ELSE IF( EQ_16( mode, IVAS_DEC_MODE_IVAS ) )
249 : {
250 610 : st_ivas->codec_mode = 0; /* unknown before first frame */
251 610 : st_ivas->element_mode_init = -1;
252 610 : st_ivas->ivas_format = UNDEFINED_FORMAT;
253 610 : st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID;
254 610 : st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID;
255 610 : st_ivas->renderer_type = RENDERER_DISABLE;
256 610 : st_ivas->ini_frame = 0;
257 610 : st_ivas->ini_active_frame = 0;
258 610 : st_ivas->writeFECoffset = 0;
259 :
260 610 : st_ivas->ism_mode = ISM_MODE_NONE;
261 610 : st_ivas->mc_mode = MC_MODE_NONE;
262 :
263 610 : st_ivas->sba_order = 0;
264 610 : st_ivas->sba_planar = 0;
265 610 : st_ivas->sba_analysis_order = 0;
266 :
267 610 : move16();
268 610 : move16();
269 610 : move16();
270 610 : move16();
271 610 : move16();
272 610 : move16();
273 610 : move16();
274 610 : move16();
275 610 : move16();
276 610 : move16();
277 610 : move16();
278 610 : move16();
279 610 : move16();
280 610 : move16();
281 610 : return IVAS_ERR_OK;
282 : }
283 :
284 0 : return IVAS_ERR_WRONG_PARAMS;
285 : }
286 :
287 : /*-------------------------------------------------------------------------*
288 : * isar_set_split_rend_setup()
289 : *
290 : * Setup IVAS split rendering
291 : *-------------------------------------------------------------------------*/
292 :
293 0 : static ivas_error isar_set_split_rend_setup(
294 : ISAR_DEC_SPLIT_REND_WRAPPER *hSplitBinRend,
295 : const ISAR_SPLIT_REND_CONFIG_DATA *hSplitBinConfig,
296 : const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,
297 : ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o : output split rendering bits */
298 : )
299 : {
300 0 : splitRendBits->bits_read = 0;
301 0 : splitRendBits->bits_written = 0;
302 0 : splitRendBits->buf_len = ISAR_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES;
303 0 : splitRendBits->codec = ISAR_SPLIT_REND_CODEC_DEFAULT;
304 0 : splitRendBits->pose_correction = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE;
305 0 : splitRendBits->codec_frame_size_ms = 0;
306 0 : splitRendBits->isar_frame_size_ms = 0;
307 0 : splitRendBits->lc3plus_highres = 0;
308 :
309 0 : if ( ( hSplitBinRend->hMultiBinCldfbData = (ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA ) ) ) == NULL )
310 : {
311 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" );
312 : }
313 :
314 0 : ISAR_PRE_REND_GetMultiBinPoseData( hSplitBinConfig, &hSplitBinRend->splitrend.multiBinPoseData, ( hCombinedOrientationData != NULL ) ? hCombinedOrientationData->sr_pose_pred_axis : DEFAULT_AXIS );
315 :
316 0 : if ( hCombinedOrientationData != NULL )
317 : {
318 0 : isar_set_split_rend_ht_setup_fx( &hSplitBinRend->splitrend, hCombinedOrientationData->Quaternions, hCombinedOrientationData->Rmat_fx );
319 : }
320 :
321 0 : return IVAS_ERR_OK;
322 : }
323 :
324 : /*---------------------------------------------------------------------*
325 : * init_decoder_config()
326 : *
327 : * Initialize Decoder Config. handle
328 : *---------------------------------------------------------------------*/
329 :
330 613 : static void init_decoder_config(
331 : DECODER_CONFIG_HANDLE hDecoderConfig /* i/o: configuration structure */
332 : )
333 : {
334 613 : hDecoderConfig->Opt_AMR_WB = 0;
335 613 : hDecoderConfig->nchan_out = 1;
336 613 : hDecoderConfig->output_config = IVAS_AUDIO_CONFIG_INVALID;
337 613 : hDecoderConfig->Opt_LsCustom = 0;
338 613 : hDecoderConfig->Opt_HRTF_binary = 0;
339 613 : hDecoderConfig->Opt_Headrotation = 0;
340 613 : hDecoderConfig->Opt_RendConfigCustom = 0;
341 613 : hDecoderConfig->orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE;
342 613 : hDecoderConfig->Opt_non_diegetic_pan = 0;
343 613 : hDecoderConfig->non_diegetic_pan_gain_fx = 0; // Q15
344 613 : hDecoderConfig->Opt_tsm = 0;
345 613 : hDecoderConfig->Opt_delay_comp = 0;
346 613 : hDecoderConfig->Opt_ExternalOrientation = 0;
347 613 : hDecoderConfig->Opt_dpid_on = 0;
348 613 : hDecoderConfig->Opt_aeid_on = 0;
349 613 : move16();
350 613 : move16();
351 613 : move16();
352 613 : move16();
353 613 : move16();
354 613 : move16();
355 613 : move16();
356 613 : move16();
357 613 : move16();
358 613 : move16();
359 613 : move16();
360 613 : move16();
361 613 : move16();
362 613 : move16();
363 613 : move16();
364 :
365 613 : return;
366 : }
367 :
368 :
369 : /*---------------------------------------------------------------------*
370 : * IVAS_DEC_Close( )
371 : *
372 : *
373 : *---------------------------------------------------------------------*/
374 :
375 626 : void IVAS_DEC_Close(
376 : IVAS_DEC_HANDLE *phIvasDec /* i/o: pointer to IVAS decoder handle */
377 : )
378 : {
379 : /* Free all memory */
380 626 : test();
381 626 : IF( phIvasDec == NULL || *phIvasDec == NULL )
382 : {
383 13 : return;
384 : }
385 :
386 613 : IF( ( *phIvasDec )->hVoIP )
387 : {
388 28 : IVAS_DEC_Close_VoIP( ( *phIvasDec )->hVoIP );
389 28 : ( *phIvasDec )->hVoIP = NULL;
390 : }
391 :
392 : /* destroy Split binaural renderer (ISAR) handle */
393 613 : ivas_destroy_handle_isar( &( *phIvasDec )->st_ivas->hSplitBinRend );
394 :
395 613 : IF( ( *phIvasDec )->st_ivas )
396 : {
397 613 : ivas_destroy_dec_fx( ( *phIvasDec )->st_ivas );
398 613 : ( *phIvasDec )->st_ivas = NULL;
399 : }
400 :
401 613 : apa_exit( &( *phIvasDec )->hTimeScaler );
402 :
403 613 : IF( ( *phIvasDec )->apaExecBuffer_fx != NULL )
404 : {
405 28 : free( ( *phIvasDec )->apaExecBuffer_fx );
406 : }
407 613 : free( *phIvasDec );
408 613 : *phIvasDec = NULL;
409 613 : phIvasDec = NULL;
410 :
411 613 : return;
412 : }
413 :
414 :
415 : /*---------------------------------------------------------------------*
416 : * mapIvasFormat( )
417 : *
418 : *
419 : *---------------------------------------------------------------------*/
420 :
421 50 : static IVAS_DEC_BS_FORMAT mapIvasFormat(
422 : const IVAS_FORMAT ivas_format )
423 : {
424 50 : SWITCH( ivas_format )
425 : {
426 0 : case MONO_FORMAT:
427 0 : return IVAS_DEC_BS_MONO;
428 1 : case STEREO_FORMAT:
429 1 : return IVAS_DEC_BS_STEREO;
430 15 : case ISM_FORMAT:
431 15 : return IVAS_DEC_BS_OBJ;
432 4 : case MC_FORMAT:
433 4 : return IVAS_DEC_BS_MC;
434 6 : case SBA_FORMAT:
435 6 : return IVAS_DEC_BS_SBA;
436 3 : case SBA_ISM_FORMAT:
437 3 : return IVAS_DEC_BS_SBA_ISM;
438 17 : case MASA_FORMAT:
439 17 : return IVAS_DEC_BS_MASA;
440 4 : case MASA_ISM_FORMAT:
441 4 : return IVAS_DEC_BS_MASA_ISM;
442 0 : default:
443 0 : BREAK;
444 : }
445 :
446 0 : return IVAS_DEC_BS_UNKOWN;
447 : }
448 :
449 :
450 : /*---------------------------------------------------------------------*
451 : * IVAS_DEC_Configure( )
452 : *
453 : * Decoder configuration
454 : * legacy code behavior: if no output format set, then it's EVS mono
455 : *---------------------------------------------------------------------*/
456 :
457 613 : ivas_error IVAS_DEC_Configure(
458 : #ifdef FIX_745_FIX_DATA_TYPE_CONVERSION
459 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
460 : const UWord32 sampleRate, /* i : output sampling frequency */
461 : const IVAS_AUDIO_CONFIG outputConfig, /* i : output configuration */
462 : const bool tsmEnabled, /* i : enable time scale modification */
463 : const IVAS_RENDER_FRAMESIZE renderFramesize, /* i : rendering frame size */
464 : const bool customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */
465 : const bool hrtfReaderEnabled, /* i : enable HRTF binary file input */
466 : const bool enableHeadRotation, /* i : enable head rotation for binaural output */
467 : const bool enableExternalOrientation, /* i : enable external orientations */
468 : const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */
469 : const bool renderConfigEnabled, /* i : enable Renderer config. file for binaural output */
470 : const bool non_diegetic_pan_enabled, /* i : enabled diegetic panning */
471 : const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain */
472 : const bool dpidEnabled, /* i : enable directivity pattern option */
473 : const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */
474 : const bool delayCompensationEnabled /* i : enable delay compensation */
475 : #else
476 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
477 : const UWord32 sampleRate, /* i : output sampling frequency */
478 : const AUDIO_CONFIG outputConfig, /* i : output configuration */
479 : const Word16 tsmEnabled, /* i : enable time scale modification */
480 : const IVAS_RENDER_FRAMESIZE renderFramesize, /* i : rendering frame size */
481 : const Word16 customLsOutputEnabled, /* i : enable custom loudspeaker setup handle */
482 : const Word16 hrtfReaderEnabled, /* i : enable HRTF binary file input */
483 : const Word16 enableHeadRotation, /* i : enable head rotation for binaural output */
484 : const Word16 enableExternalOrientation, /* i : enable external orientations */
485 : const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i : head orientation tracking type */
486 : const Word16 renderConfigEnabled, /* i : enable Renderer config. file for binaural output */
487 : const Word16 Opt_non_diegetic_pan, /* i : diegetic or not */
488 : const Word16 non_diegetic_pan_gain_fx, /* i : non diegetic panning gain Q15 */
489 : const Word16 Opt_dpid_on, /* i : enable directivity pattern option */
490 : const UWord16 acousticEnvironmentId, /* i : Acoustic environment ID */
491 : const Word16 delayCompensationEnabled /* i : enable delay compensation */
492 : #endif
493 : )
494 : {
495 : Decoder_Struct *st_ivas;
496 : DECODER_CONFIG_HANDLE hDecoderConfig;
497 : ivas_error error;
498 :
499 613 : test();
500 613 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
501 : {
502 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
503 : }
504 :
505 613 : test();
506 613 : test();
507 613 : test();
508 613 : IF( NE_32( sampleRate, 8000 ) && NE_32( sampleRate, 16000 ) && NE_32( sampleRate, 32000 ) && NE_32( sampleRate, 48000 ) )
509 : {
510 0 : return IVAS_ERR_WRONG_PARAMS;
511 : }
512 :
513 613 : test();
514 613 : test();
515 613 : test();
516 613 : test();
517 : #ifdef FIX_745_FIX_DATA_TYPE_CONVERSION
518 613 : IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) && !( ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MONO ) && non_diegetic_pan_enabled == false ) ||
519 : ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_STEREO ) && non_diegetic_pan_enabled ) ) )
520 : #else
521 : IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) && !( ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MONO ) && Opt_non_diegetic_pan == 0 ) ||
522 : ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_STEREO ) && EQ_16( Opt_non_diegetic_pan, 1 ) ) ) )
523 : #endif
524 : {
525 0 : return IVAS_ERR_WRONG_MODE;
526 : }
527 :
528 613 : st_ivas = hIvasDec->st_ivas;
529 613 : hDecoderConfig = st_ivas->hDecoderConfig;
530 613 : hDecoderConfig->output_config = outputConfig;
531 613 : move16();
532 :
533 613 : IF( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_INVALID ) )
534 : {
535 0 : return IVAS_ERR_WRONG_PARAMS;
536 : }
537 :
538 613 : hDecoderConfig->output_Fs = sampleRate;
539 613 : move32();
540 613 : IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
541 : {
542 3 : st_ivas->element_mode_init = EVS_MONO;
543 3 : hDecoderConfig->nchan_out = 1;
544 3 : move16();
545 3 : move16();
546 : }
547 :
548 613 : test();
549 613 : IF( NE_16( outputConfig, IVAS_AUDIO_CONFIG_EXTERNAL ) && NE_16( outputConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
550 : {
551 560 : hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config );
552 560 : move16();
553 : }
554 :
555 : #ifdef FIX_745_FIX_DATA_TYPE_CONVERSION
556 613 : hDecoderConfig->Opt_tsm = (Word16) tsmEnabled;
557 613 : hDecoderConfig->Opt_LsCustom = (Word16) customLsOutputEnabled;
558 613 : hDecoderConfig->Opt_Headrotation = (Word16) enableHeadRotation;
559 : #else
560 : hDecoderConfig->Opt_tsm = tsmEnabled;
561 : hDecoderConfig->Opt_LsCustom = customLsOutputEnabled;
562 : hDecoderConfig->Opt_Headrotation = enableHeadRotation;
563 : #endif
564 613 : hDecoderConfig->orientation_tracking = orientation_tracking;
565 : #ifdef FIX_745_FIX_DATA_TYPE_CONVERSION
566 613 : hDecoderConfig->Opt_HRTF_binary = (Word16) hrtfReaderEnabled;
567 613 : hDecoderConfig->Opt_RendConfigCustom = (Word16) renderConfigEnabled;
568 613 : hDecoderConfig->Opt_non_diegetic_pan = (Word16) non_diegetic_pan_enabled;
569 : #else
570 : hDecoderConfig->Opt_HRTF_binary = hrtfReaderEnabled;
571 : hDecoderConfig->Opt_RendConfigCustom = renderConfigEnabled;
572 : hDecoderConfig->Opt_non_diegetic_pan = Opt_non_diegetic_pan;
573 : #endif
574 613 : hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; // Q15
575 : #ifdef FIX_745_FIX_DATA_TYPE_CONVERSION
576 613 : hDecoderConfig->Opt_delay_comp = (Word16) delayCompensationEnabled;
577 : #else
578 : hDecoderConfig->Opt_delay_comp = delayCompensationEnabled;
579 : #endif
580 613 : hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation;
581 : #ifdef FIX_745_FIX_DATA_TYPE_CONVERSION
582 613 : hDecoderConfig->Opt_dpid_on = (Word16) dpidEnabled;
583 : #else
584 : hDecoderConfig->Opt_dpid_on = Opt_dpid_on;
585 : #endif
586 613 : IF( NE_32( (Word32) acousticEnvironmentId, 65535 ) )
587 : {
588 4 : hDecoderConfig->Opt_aeid_on = TRUE;
589 : }
590 : ELSE
591 : {
592 609 : hDecoderConfig->Opt_aeid_on = FALSE;
593 : }
594 613 : move16();
595 613 : move16();
596 613 : move16();
597 613 : move16();
598 613 : move16();
599 613 : move16();
600 613 : move16();
601 613 : move16();
602 613 : move16();
603 613 : move16();
604 613 : move16();
605 :
606 613 : IF( EQ_16( renderFramesize, IVAS_RENDER_FRAMESIZE_UNKNOWN ) )
607 : {
608 0 : return IVAS_ERR_WRONG_PARAMS;
609 : }
610 :
611 613 : IF( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_EXTERNAL ) )
612 : {
613 50 : hDecoderConfig->render_framesize = IVAS_RENDER_FRAMESIZE_20MS;
614 : }
615 : ELSE
616 : {
617 563 : hDecoderConfig->render_framesize = renderFramesize;
618 : }
619 613 : move16();
620 :
621 : #ifndef FIX_1135_EXT_RENDERER_HANDLES
622 : IF( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
623 : {
624 : hDecoderConfig->Opt_Headrotation = TRUE;
625 : move16();
626 : }
627 : #endif
628 : /* Set decoder parameters to initial values */
629 613 : IF( NE_32( ( error = ivas_init_decoder_front( st_ivas ) ), IVAS_ERR_OK ) )
630 : {
631 0 : return error;
632 : }
633 :
634 : /* create ISAR handle */
635 613 : IF( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
636 : {
637 0 : IF( ( error = ivas_create_handle_isar( &st_ivas->hSplitBinRend ) ) != IVAS_ERR_OK )
638 : {
639 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for ISAR handle" );
640 : }
641 : }
642 :
643 613 : if ( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
644 : {
645 3 : hIvasDec->st_ivas->ivas_format = MONO_FORMAT;
646 3 : move16();
647 : }
648 :
649 613 : hIvasDec->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 );
650 613 : hIvasDec->nSamplesAvailableNext = 0;
651 613 : hIvasDec->nSamplesRendered = 0;
652 613 : hIvasDec->tsm_scale = 100;
653 613 : hIvasDec->tsm_max_scaling = 0;
654 613 : hIvasDec->tsm_quality = ONE_IN_Q14 /*1.0f Q14*/;
655 613 : move16();
656 613 : move16();
657 613 : move16();
658 613 : move16();
659 613 : move16();
660 :
661 613 : return IVAS_ERR_OK;
662 : }
663 :
664 :
665 : /*---------------------------------------------------------------------*
666 : * IVAS_DEC_EnableSplitRendering( )
667 : *
668 : * Intitialize Split rendering
669 : *---------------------------------------------------------------------*/
670 :
671 0 : ivas_error IVAS_DEC_EnableSplitRendering(
672 : IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle */
673 : )
674 : {
675 : DECODER_CONFIG_HANDLE hDecoderConfig;
676 :
677 0 : test();
678 0 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
679 : {
680 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
681 : }
682 :
683 0 : hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;
684 0 : move32();
685 :
686 0 : hDecoderConfig->Opt_Headrotation = 1;
687 0 : move16();
688 0 : hDecoderConfig->render_framesize = IVAS_RENDER_FRAMESIZE_20MS;
689 0 : move32();
690 :
691 0 : return IVAS_ERR_OK;
692 : }
693 :
694 :
695 : /*---------------------------------------------------------------------*
696 : * get_render_framesize_ms( )
697 : *
698 : * Get the 5ms flag
699 : *---------------------------------------------------------------------*/
700 :
701 229 : static Word16 get_render_frame_size_ms(
702 : const IVAS_RENDER_FRAMESIZE render_framesize )
703 : {
704 229 : IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
705 : {
706 0 : return ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) );
707 : }
708 229 : ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
709 : {
710 0 : return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 1 );
711 : }
712 229 : ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
713 : {
714 229 : return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 2 );
715 : }
716 :
717 0 : return 0;
718 : }
719 :
720 :
721 : /*---------------------------------------------------------------------*
722 : * IVAS_DEC_SetRenderFramesize( )
723 : *
724 : * Get the 5ms flag
725 : *---------------------------------------------------------------------*/
726 :
727 0 : ivas_error IVAS_DEC_SetRenderFramesize(
728 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
729 : const IVAS_RENDER_FRAMESIZE render_framesize /* i : render framesize */
730 : )
731 : {
732 0 : test();
733 0 : test();
734 0 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hDecoderConfig == NULL )
735 : {
736 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
737 : }
738 :
739 0 : IF( hIvasDec->st_ivas->hExtOrientationData != NULL )
740 : {
741 0 : hIvasDec->st_ivas->hExtOrientationData->num_subframes = (Word16) render_framesize;
742 : }
743 0 : IF( hIvasDec->st_ivas->hCombinedOrientationData != NULL )
744 : {
745 0 : hIvasDec->st_ivas->hCombinedOrientationData->num_subframes = (Word16) render_framesize;
746 : }
747 :
748 0 : hIvasDec->st_ivas->hDecoderConfig->render_framesize = render_framesize;
749 0 : move16();
750 :
751 0 : return IVAS_ERR_OK;
752 : }
753 :
754 : /*---------------------------------------------------------------------*
755 : * IVAS_DEC_GetGetRenderFramesize( )
756 : *
757 : * Get the 5ms flag
758 : *---------------------------------------------------------------------*/
759 :
760 613 : ivas_error IVAS_DEC_GetRenderFramesize(
761 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
762 : IVAS_RENDER_FRAMESIZE *render_framesize /* o : render framesize */
763 : )
764 : {
765 613 : test();
766 613 : test();
767 613 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL )
768 : {
769 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
770 : }
771 :
772 613 : *render_framesize = hIvasDec->st_ivas->hDecoderConfig->render_framesize;
773 613 : move16();
774 :
775 613 : return IVAS_ERR_OK;
776 : }
777 :
778 :
779 : /*---------------------------------------------------------------------*
780 : * IVAS_DEC_GetGetRenderFramesizeSamples( )
781 : *
782 : * Get render framesize in samples
783 : *---------------------------------------------------------------------*/
784 :
785 613 : ivas_error IVAS_DEC_GetRenderFramesizeSamples(
786 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
787 : Word16 *render_framesize /* o : render framesize in samples Q0 */
788 : )
789 : {
790 : Word16 tmp;
791 :
792 613 : test();
793 613 : test();
794 613 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL )
795 : {
796 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
797 : }
798 :
799 613 : tmp = (Word16) Mpy_32_16_1( hIvasDec->st_ivas->hDecoderConfig->output_Fs, INV_FR_P_S_MX_PRM_SPL_SBFR_Q15 );
800 :
801 613 : IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
802 : {
803 0 : *render_framesize = tmp;
804 : }
805 613 : ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
806 : {
807 0 : *render_framesize = shl( tmp, 1 );
808 : }
809 613 : ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
810 : {
811 613 : *render_framesize = shl( tmp, 2 );
812 : }
813 : ELSE
814 : {
815 0 : *render_framesize = 0;
816 : }
817 613 : move16();
818 :
819 613 : return IVAS_ERR_OK;
820 : }
821 :
822 : /*---------------------------------------------------------------------*
823 : * IVAS_DEC_GetGetRenderFramesizeMs( )
824 : *
825 : * Get render framesize in milliseconds
826 : *---------------------------------------------------------------------*/
827 :
828 28 : ivas_error IVAS_DEC_GetRenderFramesizeMs(
829 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
830 : UWord32 *render_framesize /* o : render framesize in samples Q0 */
831 : )
832 : {
833 28 : test();
834 28 : test();
835 28 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL )
836 : {
837 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
838 : }
839 :
840 28 : *render_framesize = get_render_frame_size_ms( hIvasDec->st_ivas->hDecoderConfig->render_framesize );
841 28 : move32();
842 :
843 28 : return IVAS_ERR_OK;
844 : }
845 :
846 : /*---------------------------------------------------------------------*
847 : * IVAS_DEC_GetGetReferencesUpdateFrequency( )
848 : *
849 : * Get update frequency of the reference vector/orientation
850 : *---------------------------------------------------------------------*/
851 :
852 613 : ivas_error IVAS_DEC_GetReferencesUpdateFrequency(
853 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
854 : Word16 *update_frequency /* o : update frequency Q0 */
855 : )
856 : {
857 613 : test();
858 613 : test();
859 613 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || update_frequency == NULL )
860 : {
861 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
862 : }
863 :
864 613 : IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
865 : {
866 0 : *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES;
867 0 : move16();
868 : }
869 613 : ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
870 : {
871 0 : *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 1;
872 0 : move16();
873 : }
874 613 : ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
875 : {
876 613 : *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 2;
877 613 : move16();
878 : }
879 :
880 613 : return IVAS_ERR_OK;
881 : }
882 :
883 : /*---------------------------------------------------------------------*
884 : * IVAS_DEC_GetGetNumOrientationSubframes( )
885 : *
886 : * Get the number of subframes for head/ecernal orientation per render frame
887 : *---------------------------------------------------------------------*/
888 :
889 413041 : ivas_error IVAS_DEC_GetNumOrientationSubframes(
890 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
891 : Word16 *num_subframes /* o : render framesize */
892 : )
893 : {
894 413041 : test();
895 413041 : test();
896 413041 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || num_subframes == NULL )
897 : {
898 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
899 : }
900 :
901 413041 : *num_subframes = (Word16) hIvasDec->st_ivas->hDecoderConfig->render_framesize;
902 413041 : move16();
903 :
904 413041 : return IVAS_ERR_OK;
905 : }
906 :
907 :
908 : /*---------------------------------------------------------------------*
909 : * IVAS_DEC_EnableVoIP( )
910 : *
911 : * Intitialize JBM
912 : * jbmSafetyMargin: allowed delay reserve in addition to network jitter
913 : * to reduce late-loss, default: 60 [milliseconds]
914 : *---------------------------------------------------------------------*/
915 :
916 28 : ivas_error IVAS_DEC_EnableVoIP(
917 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
918 : const Word16 jbmSafetyMargin, /* i : allowed delay reserve for JBM, in milliseconds */
919 : const IVAS_DEC_INPUT_FORMAT inputFormat /* i : format of the input bitstream */
920 : )
921 : {
922 : DECODER_CONFIG_HANDLE hDecoderConfig;
923 : ivas_error error;
924 :
925 28 : test();
926 28 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
927 : {
928 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
929 : }
930 :
931 28 : hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;
932 :
933 28 : hIvasDec->Opt_VOIP = 1;
934 28 : hDecoderConfig->Opt_tsm = 1;
935 28 : move16();
936 28 : move16();
937 28 : IF( NE_16( (Word16) hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
938 : {
939 24 : hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config );
940 24 : move16();
941 : }
942 :
943 28 : IF( NE_32( ( error = input_format_API_to_internal( inputFormat, &hIvasDec->bitstreamformat, &hIvasDec->sdp_hf_only, true ) ), IVAS_ERR_OK ) )
944 : {
945 0 : return error;
946 : }
947 :
948 28 : IF( ( hIvasDec->hVoIP = malloc( sizeof( IVAS_DEC_VOIP ) ) ) == NULL )
949 : {
950 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
951 : }
952 :
953 28 : hIvasDec->hVoIP->lastDecodedWasActive = 0;
954 28 : move16();
955 28 : hIvasDec->hVoIP->hCurrentDataUnit = NULL;
956 28 : hIvasDec->hVoIP->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 );
957 28 : move16();
958 28 : hIvasDec->hVoIP->nSamplesRendered20ms = 0;
959 28 : move16();
960 :
961 : #define WMC_TOOL_SKIP
962 : /* Bitstream conversion is not counted towards complexity and memory usage */
963 28 : hIvasDec->hVoIP->bs_conversion_buf = malloc( sizeof( UWord16 ) * ( MAX_BITS_PER_FRAME + 4 * 8 ) );
964 : #undef WMC_TOOL_SKIP
965 :
966 28 : IF( hIvasDec->hVoIP->bs_conversion_buf == NULL )
967 : {
968 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
969 : }
970 :
971 : /* initialize JBM */
972 28 : IF( NE_32( ( error = JB4_Create( &hIvasDec->hVoIP->hJBM ) != IVAS_ERR_OK ), IVAS_ERR_OK ) )
973 : {
974 0 : return error;
975 : }
976 :
977 28 : IF( JB4_Init( hIvasDec->hVoIP->hJBM, jbmSafetyMargin ) != 0 )
978 : {
979 0 : return IVAS_ERR_FAILED_ALLOC;
980 : }
981 :
982 28 : return IVAS_ERR_OK;
983 : }
984 :
985 :
986 : /*---------------------------------------------------------------------*
987 : * IVAS_DEC_FeedFrame_Serial( )
988 : *
989 : *
990 : *---------------------------------------------------------------------*/
991 :
992 412227 : ivas_error IVAS_DEC_FeedFrame_Serial(
993 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
994 : UWord16 *serial, /* i : buffer containing serial input bitstream. Each bit should be stored as a single uint16_t value */
995 : const UWord16 num_bits, /* i : number of bits in input bitstream */
996 : Word16 bfi /* i : bad frame indicator flag */
997 : )
998 : {
999 : ivas_error error;
1000 :
1001 412227 : IF( !hIvasDec->isInitialized )
1002 : {
1003 : /* Once first frame is fed, finish initialization in EVS Mono.
1004 : * In IVAS mode, initialization is done in ivas_dec(). */
1005 613 : IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
1006 : {
1007 3 : IF( NE_32( ( error = ivas_init_decoder_fx( hIvasDec->st_ivas ) ), IVAS_ERR_OK ) )
1008 : {
1009 0 : return error;
1010 : }
1011 3 : Word32 ivas_total_brate = hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate;
1012 3 : move32();
1013 3 : test();
1014 3 : IF( ( EQ_16( hIvasDec->st_ivas->ivas_format, MC_FORMAT ) ) && ( EQ_16( hIvasDec->st_ivas->mc_mode, MC_MODE_PARAMMC ) ) )
1015 : {
1016 : MC_LS_SETUP mc_ls_setup;
1017 0 : mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( hIvasDec->st_ivas->transport_config );
1018 0 : hIvasDec->st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
1019 : }
1020 :
1021 3 : test();
1022 3 : IF( hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL )
1023 0 : {
1024 0 : DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
1025 0 : st->ini_frame = 0;
1026 0 : st->prev_use_partial_copy = 0;
1027 0 : move16();
1028 0 : move16();
1029 0 : hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = imult3216( hIvasDec->hVoIP->hCurrentDataUnit->dataSize, FRAMES_PER_SEC );
1030 0 : move32();
1031 : }
1032 : ELSE
1033 : {
1034 3 : hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = ACELP_8k00;
1035 3 : move32();
1036 : }
1037 3 : hIvasDec->isInitialized = true;
1038 3 : move16();
1039 : }
1040 : }
1041 :
1042 412227 : if ( !bfi ) /* TODO(mcjbm): Is this ok for bfi == 2 (partial frame)? Is there enough info to fully configure decoder? */
1043 : {
1044 402162 : hIvasDec->hasBeenFedFirstGoodFrame = true;
1045 402162 : move16();
1046 : }
1047 :
1048 : /* Update redundant frame information in EVS (pre- read indices) */
1049 412227 : test();
1050 412227 : test();
1051 412227 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) && hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL )
1052 : {
1053 0 : DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
1054 0 : st->bit_stream = serial;
1055 :
1056 0 : test();
1057 0 : IF( hIvasDec->hVoIP->hCurrentDataUnit->partial_frame || st->prev_use_partial_copy )
1058 : {
1059 0 : st->next_coder_type = hIvasDec->hVoIP->hCurrentDataUnit->nextCoderType;
1060 : }
1061 : ELSE
1062 : {
1063 0 : st->next_coder_type = INACTIVE;
1064 : }
1065 0 : move16();
1066 :
1067 0 : test();
1068 0 : if ( EQ_16( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame, 1 ) && NE_16( bfi, 1 ) )
1069 : {
1070 0 : bfi = 2;
1071 0 : move16();
1072 : }
1073 : }
1074 :
1075 412227 : IF( NE_32( ( error = read_indices_fx( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ), IVAS_ERR_OK ) )
1076 : {
1077 0 : return error;
1078 : }
1079 :
1080 : /* Update redundant frame information in EVS (post- read indices) */
1081 412227 : test();
1082 412227 : test();
1083 412227 : test();
1084 412227 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) &&
1085 : hIvasDec->hVoIP != NULL &&
1086 : hIvasDec->hVoIP->hCurrentDataUnit != NULL &&
1087 : ( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame != 0 ) )
1088 : {
1089 0 : DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
1090 0 : st->codec_mode = MODE2;
1091 0 : st->use_partial_copy = 1;
1092 0 : move16();
1093 0 : move16();
1094 : }
1095 :
1096 412227 : hIvasDec->needNewFrame = false;
1097 412227 : hIvasDec->hasBeenFedFrame = true;
1098 412227 : hIvasDec->nSamplesRendered = 0;
1099 412227 : hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;
1100 412227 : move16();
1101 412227 : move16();
1102 412227 : move16();
1103 412227 : move16();
1104 :
1105 412227 : return IVAS_ERR_OK;
1106 : }
1107 :
1108 :
1109 : /*---------------------------------------------------------------------*
1110 : * IVAS_DEC_GetSamples( )
1111 : *
1112 : * Main function to decode to PCM data
1113 : *---------------------------------------------------------------------*/
1114 :
1115 :
1116 424340 : ivas_error IVAS_DEC_GetSamples(
1117 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1118 : const Word16 nSamplesAsked, /* i : number of samples wanted by the caller */
1119 : 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 */
1120 : Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */
1121 : bool *needNewFrame /* o :indication that the decoder needs a new frame */
1122 : )
1123 : {
1124 : ivas_error error;
1125 : Word16 nOutSamplesElse, nSamplesToRender;
1126 : UWord16 nSamplesRendered, nSamplesRendered_loop, l_ts, nTimeScalerOutSamples;
1127 : UWord8 nTransportChannels, nOutChannels;
1128 :
1129 424340 : nSamplesRendered = 0;
1130 424340 : nOutChannels = 0;
1131 424340 : nSamplesRendered_loop = 0;
1132 424340 : l_ts = 0;
1133 424340 : nTransportChannels = 0;
1134 424340 : move16();
1135 424340 : move16();
1136 424340 : move16();
1137 424340 : move16();
1138 424340 : move16();
1139 :
1140 424340 : test();
1141 424340 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1142 : {
1143 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1144 : }
1145 :
1146 424340 : IF( hIvasDec->updateOrientation )
1147 : {
1148 : /*----------------------------------------------------------------*
1149 : * Combine orientations
1150 : *----------------------------------------------------------------*/
1151 :
1152 69653 : 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 ) )
1153 : {
1154 0 : return error;
1155 : }
1156 :
1157 : /*----------------------------------------------------------------*
1158 : * Binaural split rendering setup
1159 : *----------------------------------------------------------------*/
1160 :
1161 69653 : IF( EQ_32( hIvasDec->st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( hIvasDec->st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
1162 : {
1163 0 : IF( hIvasDec->st_ivas->hCombinedOrientationData != NULL )
1164 : {
1165 0 : isar_set_split_rend_ht_setup_fx( &hIvasDec->st_ivas->hSplitBinRend->splitrend, hIvasDec->st_ivas->hCombinedOrientationData->Quaternions, hIvasDec->st_ivas->hCombinedOrientationData->Rmat_fx );
1166 : }
1167 : }
1168 :
1169 69653 : hIvasDec->updateOrientation = false;
1170 69653 : move16();
1171 : }
1172 :
1173 424340 : test();
1174 424340 : IF( !hIvasDec->hasBeenFedFrame && hIvasDec->nSamplesAvailableNext == 0 )
1175 : {
1176 : /* no frame was fed, do nothing but ask for a frame */
1177 0 : *needNewFrame = true;
1178 0 : *nOutSamples = 0;
1179 0 : hIvasDec->needNewFrame = true;
1180 0 : move16();
1181 0 : move16();
1182 0 : move16();
1183 0 : return IVAS_ERR_OK;
1184 : }
1185 :
1186 424340 : test();
1187 : /* check if we are still at the beginning with bad frames, put out zeroes, keep track of subframes */
1188 424340 : IF( !hIvasDec->isInitialized && hIvasDec->st_ivas->bfi )
1189 : {
1190 0 : hIvasDec->hasBeenFedFrame = false;
1191 0 : move16();
1192 0 : set16_fx( pcmBuf, 0, imult1616( hIvasDec->st_ivas->hDecoderConfig->nchan_out, nSamplesAsked ) );
1193 0 : hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesAsked );
1194 0 : move16();
1195 0 : *nOutSamples = nSamplesAsked;
1196 0 : move16();
1197 0 : hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesAsked );
1198 0 : move16();
1199 0 : IF( hIvasDec->nSamplesAvailableNext == 0 )
1200 : {
1201 0 : hIvasDec->needNewFrame = true;
1202 0 : *needNewFrame = true;
1203 0 : move16();
1204 0 : move16();
1205 : }
1206 : }
1207 : ELSE
1208 : {
1209 : /* check if we need to run the setup function */
1210 424340 : test();
1211 424340 : IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ){
1212 : /* setup */
1213 :
1214 412227 : IF( NE_32( ( error = IVAS_DEC_Setup( hIvasDec, &l_ts, &nTransportChannels, &nOutChannels, &nSamplesRendered_loop, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) ){
1215 0 : return error;
1216 : }
1217 : }
1218 : {
1219 : /* check if we need to run the setup function, tc decoding and feeding the renderer */
1220 424340 : test();
1221 424340 : IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame )
1222 : {
1223 : Word16 nResidualSamples, nSamplesTcsScaled;
1224 412227 : nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
1225 :
1226 412227 : test();
1227 412227 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm && NE_16( (Word16) nTransportChannels, hIvasDec->nTransportChannelsOld ) )
1228 : {
1229 969 : IF( NE_32( ( error = IVAS_DEC_VoIP_reconfigure( hIvasDec, nTransportChannels, l_ts ) ), IVAS_ERR_OK ) )
1230 : {
1231 0 : return error;
1232 : }
1233 : }
1234 :
1235 : /* IVAS decoder */
1236 412227 : IF( NE_32( ( error = IVAS_DEC_GetTcSamples( hIvasDec, hIvasDec->apaExecBuffer_fx, &nOutSamplesElse ) ), IVAS_ERR_OK ) )
1237 : {
1238 0 : return error;
1239 : }
1240 :
1241 : /* JBM */
1242 412227 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
1243 : {
1244 19553 : IF( apa_set_scale_fx( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 )
1245 : {
1246 0 : return IVAS_ERR_UNKNOWN;
1247 : }
1248 :
1249 : // tmp apaExecBuffer
1250 19553 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
1251 : {
1252 : Word16 tmp_apaExecBuffer[APA_BUF];
1253 0 : FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i )
1254 : {
1255 0 : tmp_apaExecBuffer[i] = extract_l( L_shr( hIvasDec->apaExecBuffer_fx[i], Q11 ) ); // Q0
1256 : }
1257 0 : IF( apa_exec_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, &nTimeScalerOutSamples ) != 0 )
1258 : {
1259 0 : return IVAS_ERR_UNKNOWN;
1260 : }
1261 0 : FOR( Word32 i = 0; i < APA_BUF_PER_CHANNEL * nTransportChannels; ++i )
1262 : {
1263 0 : hIvasDec->apaExecBuffer_fx[i] = L_shl( tmp_apaExecBuffer[i], Q11 ); // Q11
1264 : }
1265 : }
1266 : ELSE
1267 : {
1268 19553 : 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 )
1269 : {
1270 0 : return IVAS_ERR_UNKNOWN;
1271 : }
1272 : }
1273 19553 : assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) );
1274 19553 : nSamplesTcsScaled = idiv1616U( extract_l( nTimeScalerOutSamples ), nTransportChannels );
1275 19553 : hIvasDec->timeScalingDone = 1;
1276 19553 : move16();
1277 : }
1278 : ELSE
1279 : {
1280 392674 : nSamplesTcsScaled = hIvasDec->nSamplesFrame;
1281 392674 : move16();
1282 : }
1283 : #ifdef DEBUG_MODE_JBM
1284 : dbgwrite( &nTimeScalerOutSamples, sizeof( uint16_t ), 1, 1, "./res/JBM_nTimeScaleOutSamples.dat" );
1285 : #endif
1286 :
1287 : /* Feed decoded transport channels samples to the renderer */
1288 412227 : IF( NE_32( ( error = IVAS_DEC_RendererFeedTcSamples( hIvasDec, nSamplesTcsScaled, &nResidualSamples, hIvasDec->apaExecBuffer_fx ) ), IVAS_ERR_OK ) )
1289 : {
1290 0 : return error;
1291 : }
1292 : #ifdef DEBUG_MODE_JBM
1293 : dbgwrite( &nResidualSamples, sizeof( int16_t ), 1, 1, "./res/JBM_nResidualSamples.dat" );
1294 : #endif
1295 :
1296 :
1297 412227 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
1298 : {
1299 : /* feed residual samples to TSM for the next call */
1300 19553 : IF( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ) != 0 )
1301 : {
1302 0 : return IVAS_ERR_UNKNOWN;
1303 : }
1304 : }
1305 412227 : hIvasDec->hasBeenFedFrame = false;
1306 412227 : move16();
1307 : }
1308 :
1309 : /* render IVAS frames directly to the output buffer */
1310 424340 : nSamplesToRender = sub( nSamplesAsked, nSamplesRendered );
1311 424340 : IF( NE_32( ( error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ), IVAS_ERR_OK ) )
1312 : {
1313 0 : return error;
1314 : }
1315 :
1316 424340 : nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
1317 424340 : nSamplesToRender = sub( nSamplesToRender, nSamplesRendered_loop );
1318 424340 : IF( hIvasDec->nSamplesAvailableNext == 0 )
1319 : {
1320 412206 : *needNewFrame = true;
1321 412206 : hIvasDec->needNewFrame = true;
1322 412206 : move16();
1323 412206 : move16();
1324 : }
1325 : ELSE
1326 : {
1327 12134 : *needNewFrame = false;
1328 12134 : move16();
1329 : }
1330 : }
1331 : }
1332 :
1333 424340 : *nOutSamples = nSamplesRendered;
1334 424340 : move16();
1335 :
1336 424340 : return IVAS_ERR_OK;
1337 : }
1338 :
1339 :
1340 : /*---------------------------------------------------------------------*
1341 : * IVAS_DEC_GetSplitBinauralBitstream( )
1342 : *
1343 : *
1344 : *---------------------------------------------------------------------*/
1345 :
1346 0 : ivas_error IVAS_DEC_GetSplitBinauralBitstream(
1347 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1348 : Word16 *pcmBuf_out, /* o : output synthesis signal for BINAURAL_SPLIT_PCM */
1349 : ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o : output split rendering bits */
1350 : Word16 *nOutSamples, /* o : number of samples per channel written to output buffer */
1351 : bool *needNewFrame /* o : indication that the decoder needs a new frame */
1352 : )
1353 : {
1354 : Decoder_Struct *st_ivas;
1355 : AUDIO_CONFIG output_config;
1356 : Word32 output_Fs;
1357 : Word32 *pOutput[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES];
1358 : Word32 Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
1359 : Word32 Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
1360 : Word16 numSamplesPerChannelToDecode;
1361 : Word16 i, j, k;
1362 : ivas_error error;
1363 : ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend;
1364 : Word16 max_band;
1365 : Word16 pcm_out_flag;
1366 : Word16 td_input;
1367 : Word16 numPoses;
1368 : Word16 slots_rendered, slots_rendered_new;
1369 : Word16 ro_md_flag;
1370 : IVAS_QUATERNION Quaternion;
1371 :
1372 : #ifdef FIX_VOIP_FUNCTIONS
1373 0 : test();
1374 0 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1375 : {
1376 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1377 : }
1378 :
1379 : #endif
1380 0 : st_ivas = hIvasDec->st_ivas;
1381 0 : output_config = st_ivas->hDecoderConfig->output_config;
1382 0 : output_Fs = st_ivas->hDecoderConfig->output_Fs;
1383 0 : numSamplesPerChannelToDecode = (Word16) ( output_Fs / FRAMES_PER_SEC ); // TODO remove division
1384 :
1385 0 : *needNewFrame = false;
1386 0 : hSplitBinRend = st_ivas->hSplitBinRend;
1387 :
1388 0 : IF( ( error = isar_set_split_rend_setup( hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK )
1389 : {
1390 0 : return error;
1391 : }
1392 :
1393 0 : FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; i++ )
1394 : {
1395 0 : FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ )
1396 : {
1397 0 : FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
1398 : {
1399 0 : Cldfb_RealBuffer_Binaural[i][j][k] = 0;
1400 0 : Cldfb_ImagBuffer_Binaural[i][j][k] = 0;
1401 0 : move32();
1402 0 : move32();
1403 : }
1404 : }
1405 : }
1406 :
1407 0 : FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; i++ )
1408 : {
1409 0 : FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ )
1410 : {
1411 0 : set32_fx( hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
1412 0 : set32_fx( hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
1413 : }
1414 : }
1415 :
1416 0 : numPoses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;
1417 0 : move16();
1418 :
1419 0 : IF( NE_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) &&
1420 : ( EQ_32( hIvasDec->st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) ||
1421 : EQ_16( hIvasDec->st_ivas->hRenderConfig->split_rend_config.dof, 0 ) ) )
1422 : {
1423 0 : numSamplesPerChannelToDecode = (Word16) ( output_Fs / FRAMES_PER_SEC ); // TODO remove division
1424 0 : numSamplesPerChannelToDecode = (Word16) ( numSamplesPerChannelToDecode / MAX_PARAM_SPATIAL_SUBFRAMES ); // TODO remove division
1425 0 : numSamplesPerChannelToDecode *= (Word16) st_ivas->hDecoderConfig->render_framesize;
1426 0 : move16();
1427 0 : move16();
1428 : }
1429 :
1430 0 : IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 )
1431 : {
1432 0 : return IVAS_ERR_WRONG_PARAMS;
1433 : }
1434 :
1435 0 : test();
1436 0 : IF( st_ivas->hTcBuffer == NULL || hIvasDec->hasBeenFedFrame )
1437 : {
1438 0 : slots_rendered = 0;
1439 : }
1440 : ELSE
1441 : {
1442 : /* this is needed for OMASA-DISC, because the td-rend granularity is 240 samples at 48kHz, leading to wrong slot count. */
1443 0 : test();
1444 0 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1445 : {
1446 0 : slots_rendered = st_ivas->hTcBuffer->n_samples_rendered / NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // TODO remove division
1447 : }
1448 : ELSE
1449 : {
1450 0 : slots_rendered = st_ivas->hTcBuffer->n_samples_rendered / st_ivas->hTcBuffer->n_samples_granularity;
1451 : }
1452 : }
1453 :
1454 : /* Decode and render */
1455 0 : IF( ( error = IVAS_DEC_GetSamples( hIvasDec, numSamplesPerChannelToDecode, pcmBuf_out, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK )
1456 : {
1457 0 : return error;
1458 : }
1459 :
1460 0 : FOR( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i )
1461 : {
1462 0 : pOutput[i] = hSplitBinRend->hMultiBinCldfbData->output_fx[i];
1463 0 : move32();
1464 : }
1465 :
1466 0 : IF( st_ivas->hTcBuffer == NULL )
1467 : {
1468 0 : slots_rendered_new = 0;
1469 0 : move16();
1470 : }
1471 : ELSE
1472 : {
1473 : /* this is needed for OMASA-DISC, because the td-rend granularity is 240 samples at 48kHz, leading to wrong slot count. */
1474 0 : IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1475 : {
1476 0 : slots_rendered_new = st_ivas->hTcBuffer->n_samples_rendered / NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // TODO remove division
1477 : }
1478 : ELSE
1479 : {
1480 0 : slots_rendered_new = st_ivas->hTcBuffer->n_samples_rendered / st_ivas->hTcBuffer->n_samples_granularity; // TODO remove division
1481 : }
1482 : }
1483 :
1484 0 : FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, numPoses ); ++i )
1485 : {
1486 0 : FOR( j = slots_rendered; j < slots_rendered_new; ++j )
1487 : {
1488 0 : Copy32( hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[i][j], Cldfb_RealBuffer_Binaural[i][j - slots_rendered], CLDFB_NO_CHANNELS_MAX );
1489 0 : Copy32( hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[i][j], Cldfb_ImagBuffer_Binaural[i][j - slots_rendered], CLDFB_NO_CHANNELS_MAX );
1490 : }
1491 : }
1492 :
1493 0 : max_band = (Word16) ( ( BINAURAL_MAXBANDS * output_Fs ) / 48000 ); // TODO remove division
1494 0 : move16();
1495 0 : pcm_out_flag = ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0;
1496 0 : td_input = st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC && st_ivas->renderer_type != RENDERER_BINAURAL_PARAMETRIC_ROOM && st_ivas->renderer_type != RENDERER_STEREO_PARAMETRIC;
1497 :
1498 0 : IF( st_ivas->hBinRendererTd != NULL )
1499 : {
1500 0 : ro_md_flag = 1;
1501 0 : move16();
1502 : }
1503 : ELSE
1504 : {
1505 0 : ro_md_flag = 0;
1506 0 : move16();
1507 : }
1508 :
1509 0 : IF( st_ivas->hHeadTrackData != NULL )
1510 : {
1511 0 : Quaternion = st_ivas->hHeadTrackData->Quaternions[0];
1512 : }
1513 : ELSE
1514 : {
1515 0 : Quaternion.w_fx = -12582912;
1516 0 : Quaternion.x_fx = 0;
1517 0 : Quaternion.y_fx = 0;
1518 0 : Quaternion.z_fx = 0;
1519 : }
1520 0 : Word16 q1 = 31, q2 = 31, Q_buff;
1521 : Word16 Q_out[CLDFB_NO_COL_MAX];
1522 0 : Q_out[0] = 31;
1523 0 : Word16 num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;
1524 :
1525 0 : for ( i = 0; i < i_mult( BINAURAL_CHANNELS, numPoses ); i++ )
1526 : {
1527 0 : for ( j = 0; j < CLDFB_NO_COL_MAX; j++ )
1528 : {
1529 0 : q1 = s_min( q1, L_norm_arr( Cldfb_RealBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX ) );
1530 0 : q2 = s_min( q2, L_norm_arr( Cldfb_ImagBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX ) );
1531 : }
1532 : }
1533 0 : Q_buff = s_min( q1, q2 );
1534 0 : for ( i = 0; i < i_mult( BINAURAL_CHANNELS, numPoses ); i++ )
1535 : {
1536 0 : for ( j = 0; j < CLDFB_NO_COL_MAX; j++ )
1537 : {
1538 0 : scale_sig32( Cldfb_RealBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX, Q_buff );
1539 0 : scale_sig32( Cldfb_ImagBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX, Q_buff );
1540 : }
1541 : }
1542 0 : Q_buff = add( Q_buff, Q6 );
1543 :
1544 0 : IF( NE_16( td_input, 0 ) )
1545 : {
1546 : /*TD input*/
1547 : /*if CLDFB handles have been allocated then assume valid multi binaural input in out[][] buffer and perform CLDFB analysis*/
1548 : /* local float2fix, to be removed */
1549 0 : num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;
1550 :
1551 0 : FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i )
1552 : {
1553 0 : Q_out[0] = s_min( Q_out[0], L_norm_arr( pOutput[i], L_FRAME48k ) );
1554 : }
1555 :
1556 0 : FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i )
1557 : {
1558 0 : scale_sig32( pOutput[i], L_FRAME48k, Q_out[0] );
1559 : }
1560 0 : Q_out[0] = add( Q_out[0], Q11 );
1561 0 : Q_out[1] = Q_out[0];
1562 : }
1563 :
1564 0 : IF( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( &hSplitBinRend->splitrend,
1565 : Quaternion,
1566 : st_ivas->hRenderConfig->split_rend_config.splitRendBitRate,
1567 : st_ivas->hRenderConfig->split_rend_config.codec,
1568 : st_ivas->hRenderConfig->split_rend_config.isar_frame_size_ms,
1569 : st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms,
1570 : splitRendBits,
1571 : Cldfb_RealBuffer_Binaural,
1572 : Cldfb_ImagBuffer_Binaural,
1573 : max_band, pOutput, 1, !td_input, pcm_out_flag, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK )
1574 : {
1575 0 : return error;
1576 : }
1577 :
1578 : /* convert to int16 with limiting for BINAURAL_SPLIT_PCM */
1579 0 : IF( pcm_out_flag )
1580 : {
1581 0 : FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
1582 : {
1583 0 : scale_sig32( pOutput[j], numSamplesPerChannelToDecode, sub( Q11, Q_out[j] ) ); // Q11
1584 : }
1585 0 : IF( EQ_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
1586 : {
1587 : #ifndef DISABLE_LIMITER
1588 0 : ivas_limiter_dec_fx( st_ivas->hLimiter, pOutput, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToDecode, st_ivas->BER_detect, Q11 );
1589 : #endif
1590 : }
1591 : else
1592 : {
1593 0 : ivas_limiter_dec_fx( st_ivas->hLimiter, pOutput, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToDecode, st_ivas->BER_detect, Q11 );
1594 : }
1595 :
1596 0 : ivas_syn_output_fx( pOutput, Q11, numSamplesPerChannelToDecode, st_ivas->hDecoderConfig->nchan_out, (int16_t *) pcmBuf_out );
1597 : }
1598 :
1599 0 : free( st_ivas->hSplitBinRend->hMultiBinCldfbData );
1600 :
1601 0 : return IVAS_ERR_OK;
1602 : }
1603 :
1604 :
1605 : /*---------------------------------------------------------------------*
1606 : * IVAS_DEC_Setup( )
1607 : *
1608 : *
1609 : *---------------------------------------------------------------------*/
1610 :
1611 412227 : static ivas_error IVAS_DEC_Setup(
1612 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1613 : UWord16 *nTcBufferGranularity, /* o : granularity of the TC Buffer */
1614 : UWord8 *nTransportChannels, /* o : number of decoded transport PCM channels */
1615 : UWord8 *nOutChannels, /* o : number of decoded out channels (PCM or CLDFB) */
1616 : UWord16 *nSamplesRendered, /* o : number of samples flushed from the last frame */
1617 : Word16 *data /* o : output synthesis signal Q0 */
1618 : )
1619 : {
1620 : ivas_error error;
1621 :
1622 412227 : *nSamplesRendered = 0;
1623 412227 : move16();
1624 :
1625 412227 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
1626 : {
1627 3100 : IF( EQ_16( (Word16) hIvasDec->st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
1628 : {
1629 1000 : *nTransportChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN;
1630 1000 : *nOutChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN;
1631 : }
1632 : ELSE
1633 : {
1634 2100 : *nTransportChannels = 1;
1635 2100 : *nOutChannels = 1;
1636 : }
1637 3100 : move16();
1638 3100 : move16();
1639 : }
1640 : ELSE
1641 : {
1642 : Decoder_Struct *st_ivas;
1643 :
1644 409127 : st_ivas = hIvasDec->st_ivas;
1645 :
1646 : /*----------------------------------------------------------------*
1647 : * IVAS decoder setup
1648 : * - read IVAS format signaling
1649 : * - read IVAS format specific signaling
1650 : * - initialize decoder in the first frame based on IVAS format and number of transport channels
1651 : * - reconfigure the decoder when the number of TC or IVAS total bitrate change
1652 : *----------------------------------------------------------------*/
1653 :
1654 409127 : IF( st_ivas->bfi == 0 )
1655 : {
1656 : Word32 ivas_total_brate;
1657 400461 : ivas_total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
1658 : Word16 SrcInd[MAX_NUM_TDREND_CHANNELS];
1659 400461 : Word16 num_src = 0;
1660 400461 : move16();
1661 :
1662 400461 : test();
1663 400461 : test();
1664 400461 : test();
1665 400461 : test();
1666 400461 : test();
1667 400461 : test();
1668 400461 : test();
1669 400461 : test();
1670 400461 : test();
1671 400461 : 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 ) )
1672 : {
1673 0 : IF( st_ivas->hSpar )
1674 : {
1675 0 : Word16 Q_tmp = getScaleFactor16( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16 );
1676 0 : Scale_sig( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16, sub( Q_tmp, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ) );
1677 0 : st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_tmp;
1678 : }
1679 : }
1680 :
1681 400461 : test();
1682 400461 : test();
1683 400461 : test();
1684 400461 : test();
1685 400461 : test();
1686 400461 : 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 )
1687 : {
1688 0 : IF( st_ivas->hSpar )
1689 : {
1690 0 : Word16 Q_tmp = getScaleFactor16( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16 );
1691 0 : Scale_sig( st_ivas->hSpar->hFbMixer->cldfb_cross_fade_fx, 16, sub( Q_tmp, st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q ) );
1692 0 : st_ivas->hSpar->hFbMixer->cldfb_cross_fade_q = Q_tmp;
1693 0 : move16();
1694 : }
1695 : }
1696 :
1697 400461 : IF( NE_32( ( error = ivas_dec_setup( st_ivas, nSamplesRendered, data ) ), IVAS_ERR_OK ) )
1698 : {
1699 0 : return error;
1700 : }
1701 400461 : test();
1702 400461 : IF( ( st_ivas->ivas_format == MC_FORMAT ) && ( st_ivas->mc_mode == MC_MODE_PARAMMC ) )
1703 : {
1704 : MC_LS_SETUP mc_ls_setup;
1705 10216 : mc_ls_setup = ivas_mc_map_output_config_to_mc_ls_setup_fx( st_ivas->transport_config );
1706 10216 : st_ivas->nchan_transport = ivas_param_mc_getNumTransportChannels_fx( ivas_total_brate, mc_ls_setup );
1707 : }
1708 :
1709 400461 : test();
1710 400461 : test();
1711 400461 : test();
1712 400461 : test();
1713 400461 : test();
1714 400461 : test();
1715 400461 : 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 ) )
1716 : {
1717 674 : IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1718 : {
1719 0 : Word16 nchan_rend = num_src;
1720 0 : IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1721 : {
1722 0 : nchan_rend--; /* Skip LFE channel -- added to the others */
1723 : }
1724 0 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
1725 : {
1726 0 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
1727 0 : IF( Src_p->SrcSpatial_p != NULL )
1728 : {
1729 0 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
1730 0 : move16();
1731 : }
1732 0 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
1733 0 : SrcSpatial_p->q_Pos_p = Q31;
1734 0 : move16();
1735 : }
1736 : }
1737 : }
1738 :
1739 :
1740 400461 : test();
1741 400461 : test();
1742 400461 : test();
1743 400461 : test();
1744 400461 : test();
1745 400461 : 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 )
1746 : {
1747 0 : IF( EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
1748 : {
1749 0 : Word16 nchan_rend = num_src;
1750 0 : test();
1751 0 : IF( EQ_16( st_ivas->ivas_format, MC_FORMAT ) && NE_16( st_ivas->transport_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
1752 : {
1753 0 : nchan_rend--; /* Skip LFE channel -- added to the others */
1754 : }
1755 0 : FOR( Word16 nS = 0; nS < nchan_rend; nS++ )
1756 : {
1757 0 : TDREND_SRC_t *Src_p = st_ivas->hBinRendererTd->Sources[SrcInd[nS]];
1758 0 : IF( Src_p->SrcSpatial_p != NULL )
1759 : {
1760 0 : Src_p->SrcSpatial_p->q_Pos_p = Q31;
1761 0 : move16();
1762 : }
1763 0 : TDREND_SRC_SPATIAL_t *SrcSpatial_p = st_ivas->hBinRendererTd->Sources[nS]->SrcSpatial_p;
1764 0 : SrcSpatial_p->q_Pos_p = Q31;
1765 0 : move16();
1766 : }
1767 : }
1768 : }
1769 : }
1770 :
1771 409127 : *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm;
1772 409127 : *nTcBufferGranularity = (UWord16) st_ivas->hTcBuffer->n_samples_granularity;
1773 409127 : *nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out;
1774 409127 : move16();
1775 409127 : move16();
1776 409127 : move16();
1777 :
1778 : /*-----------------------------------------------------------------*
1779 : * ISAR:
1780 : * - initialize ISAR handle at the first frame
1781 : * - reconfigure the ISAR handle in case of bitrate switching (renderer might change)
1782 : *-----------------------------------------------------------------*/
1783 :
1784 409127 : test();
1785 409127 : IF( st_ivas->ini_frame == 0 && ( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) ) )
1786 : {
1787 0 : IF( ( error = ivas_dec_init_split_rend( st_ivas ) ) != IVAS_ERR_OK )
1788 : {
1789 0 : return error;
1790 : }
1791 : }
1792 :
1793 409127 : test();
1794 409127 : IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
1795 : {
1796 0 : IF( ( error = ivas_dec_reconfig_split_rend( st_ivas ) ) != IVAS_ERR_OK )
1797 : {
1798 0 : return error;
1799 : }
1800 : }
1801 : }
1802 :
1803 412227 : return IVAS_ERR_OK;
1804 : }
1805 :
1806 :
1807 : /*---------------------------------------------------------------------*
1808 : * IVAS_DEC_GetTcSamples( )
1809 : *
1810 : * Main function to decode to PCM data of the transport channels
1811 : *---------------------------------------------------------------------*/
1812 :
1813 412227 : static ivas_error IVAS_DEC_GetTcSamples(
1814 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1815 : 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 */
1816 : Word16 *nOutSamples /* o : number of samples per channel written to output buffer */
1817 : )
1818 : {
1819 : Decoder_Struct *st_ivas;
1820 : ivas_error error;
1821 :
1822 412227 : test();
1823 412227 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1824 : {
1825 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1826 : }
1827 :
1828 412227 : st_ivas = hIvasDec->st_ivas;
1829 :
1830 412227 : *nOutSamples = (Word16) Mpy_32_16_1( st_ivas->hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 );
1831 412227 : move16();
1832 :
1833 412227 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
1834 : {
1835 3100 : IF( NE_32( ( error = evs_dec_main_fx( st_ivas, *nOutSamples, pcmBuf_fx, NULL ) ), IVAS_ERR_OK ) )
1836 : {
1837 0 : return error;
1838 : }
1839 : }
1840 409127 : ELSE IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_IVAS ) )
1841 : {
1842 : /* run the main IVAS decoding routine */
1843 : /*------------------------flt 2 fix----------------------*/
1844 : Word16 n;
1845 : Decoder_State *st, **sts; /* used for bitstream handling */
1846 : Word16 nCPE, cpe_id;
1847 409127 : nCPE = st_ivas->nCPE;
1848 :
1849 409127 : IF( st_ivas->hDecoderConfig->Opt_tsm == 0 )
1850 : {
1851 2837418 : FOR( n = 0; n < ivas_get_nchan_buffers_dec_fx( st_ivas, st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate ); n++ )
1852 : {
1853 2447844 : set32_fx( st_ivas->p_output_fx[n], 0, L_FRAME48k );
1854 2447844 : st_ivas->hTcBuffer->tc_fx[n] = st_ivas->p_output_fx[n]; // Q11
1855 : }
1856 : }
1857 :
1858 :
1859 : CPE_DEC_HANDLE hCPE;
1860 409127 : test();
1861 409127 : test();
1862 409127 : test();
1863 409127 : test();
1864 409127 : test();
1865 409127 : 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 ) ) )
1866 : {
1867 :
1868 98420 : nCPE = st_ivas->nCPE;
1869 98420 : move16();
1870 359864 : FOR( cpe_id = 0; cpe_id < st_ivas->nCPE; cpe_id++ )
1871 : {
1872 261444 : hCPE = st_ivas->hCPE[cpe_id];
1873 261444 : sts = hCPE->hCoreCoder;
1874 :
1875 :
1876 784332 : FOR( n = 0; n < CPE_CHANNELS; n++ )
1877 : {
1878 522888 : st = hCPE->hCoreCoder[n];
1879 522888 : IF( st->hTcxDec )
1880 522888 : st->hTcxDec->conNoiseLevelIndex = st->hTcxDec->NoiseLevelIndex_bfi;
1881 522888 : IF( st->hTcxDec )
1882 522888 : st->hTcxDec->conCurrLevelIndex = st->hTcxDec->CurrLevelIndex_bfi;
1883 : }
1884 : }
1885 : }
1886 :
1887 : /* Function call: ivas_jbm_dec_tc function */
1888 409127 : IF( NE_32( ( error = ivas_jbm_dec_tc_fx( st_ivas, pcmBuf_fx ) ), IVAS_ERR_OK ) )
1889 : {
1890 0 : return error;
1891 : }
1892 :
1893 409127 : hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */
1894 :
1895 409127 : test();
1896 409127 : test();
1897 409127 : test();
1898 409127 : test();
1899 409127 : test();
1900 409127 : test();
1901 409127 : 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 ) ) )
1902 : {
1903 359864 : FOR( cpe_id = 0; cpe_id < nCPE; cpe_id++ )
1904 : {
1905 261444 : hCPE = st_ivas->hCPE[cpe_id];
1906 261444 : sts = hCPE->hCoreCoder;
1907 784332 : FOR( n = 0; n < 2; n++ )
1908 : {
1909 :
1910 : /*-------------------cldfb-start-------------------------*/
1911 : /*note : cldfb_size here signifies the original size which was assigned to cldfb_state_fx buffer not its current size*/
1912 522888 : IF( sts[n]->cldfbAna != NULL )
1913 : {
1914 120 : scale_sig32( sts[n]->cldfbAna->cldfb_state_fx, sts[n]->cldfbAna->cldfb_size, sub( Q11, Q10 ) ); // Q11
1915 120 : sts[n]->cldfbAna->Q_cldfb_state = Q11;
1916 120 : move16();
1917 : }
1918 522888 : IF( sts[n]->cldfbSyn != NULL )
1919 : {
1920 522888 : scale_sig32( sts[n]->cldfbSyn->cldfb_state_fx, sts[n]->cldfbSyn->cldfb_size, sub( Q11, Q4 ) ); // Q11
1921 522888 : sts[n]->cldfbSyn->Q_cldfb_state = Q11;
1922 522888 : move16();
1923 : }
1924 : /*-------------------cldfb-end---------------------------*/
1925 : }
1926 : }
1927 : }
1928 : }
1929 412227 : if ( hIvasDec->hasBeenFedFirstGoodFrame )
1930 : {
1931 412227 : hIvasDec->hasDecodedFirstGoodFrame = true;
1932 412227 : move16();
1933 : }
1934 :
1935 412227 : return IVAS_ERR_OK;
1936 : }
1937 :
1938 :
1939 : /*---------------------------------------------------------------------*
1940 : * IVAS_DEC_Rendered_FeedTcSamples( )
1941 : *
1942 : * Feed decoded transport channels samples to the renderer
1943 : *---------------------------------------------------------------------*/
1944 :
1945 412227 : static ivas_error IVAS_DEC_RendererFeedTcSamples(
1946 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1947 : const Word16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */
1948 : Word16 *nSamplesResidual, /* o : number of samples not fitting into the renderer grid and buffer for the next call */
1949 : 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*/
1950 : )
1951 : {
1952 : Decoder_Struct *st_ivas;
1953 :
1954 412227 : test();
1955 412227 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1956 : {
1957 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1958 : }
1959 :
1960 412227 : st_ivas = hIvasDec->st_ivas;
1961 :
1962 : /* feed the TCs to the IVAS renderer */
1963 412227 : ivas_jbm_dec_feed_tc_to_renderer_fx( st_ivas, nSamplesForRendering, nSamplesResidual, pcmBuf );
1964 :
1965 412227 : return IVAS_ERR_OK;
1966 : }
1967 :
1968 :
1969 : /*---------------------------------------------------------------------*
1970 : * IVAS_DEC_GetRenderedSamples( )
1971 : *
1972 : * Main function to render the transport channels to PCM output data
1973 : *---------------------------------------------------------------------*/
1974 :
1975 424361 : static ivas_error IVAS_DEC_GetRenderedSamples(
1976 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
1977 : const UWord16 nSamplesForRendering, /* i : number of TC samples wanted from the renderer */
1978 : UWord16 *nSamplesRendered, /* o : number of samples rendered */
1979 : UWord16 *nSamplesAvailableNext, /* o : number of samples still available in the renerer pipeline */
1980 : Word16 *pcmBuf /* o : output synthesis signal Q0 */
1981 : )
1982 : {
1983 : Decoder_Struct *st_ivas;
1984 : ivas_error error;
1985 :
1986 424361 : test();
1987 424361 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
1988 : {
1989 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
1990 : }
1991 :
1992 424361 : st_ivas = hIvasDec->st_ivas;
1993 :
1994 : /* run the main IVAS decoding routine */
1995 424361 : error = ivas_jbm_dec_render_fx( st_ivas, nSamplesForRendering, nSamplesRendered, nSamplesAvailableNext, pcmBuf );
1996 :
1997 424361 : return error;
1998 : }
1999 :
2000 :
2001 : /*---------------------------------------------------------------------*
2002 : * IVAS_DEC_GetBufferedNumberOfSamples( )
2003 : *
2004 : * Returns the number of objects available in the decoded bitstream
2005 : *---------------------------------------------------------------------*/
2006 :
2007 19525 : static ivas_error IVAS_DEC_GetBufferedNumberOfSamples(
2008 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2009 : Word16 *nSamplesBuffered /* o : number of samples still buffered */
2010 : )
2011 : {
2012 19525 : *nSamplesBuffered = 0;
2013 19525 : move16();
2014 :
2015 19525 : test();
2016 19525 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2017 : {
2018 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2019 : }
2020 :
2021 : /* check if the TC buffer already exists, otherweise nothing is buffered anyway */
2022 19525 : if ( hIvasDec->st_ivas->hTcBuffer != NULL )
2023 : {
2024 19525 : *nSamplesBuffered = sub( hIvasDec->st_ivas->hTcBuffer->n_samples_buffered, hIvasDec->st_ivas->hTcBuffer->n_samples_rendered );
2025 19525 : *nSamplesBuffered = add( *nSamplesBuffered, hIvasDec->hVoIP->nSamplesRendered20ms );
2026 19525 : move16();
2027 : }
2028 :
2029 19525 : return IVAS_ERR_OK;
2030 : }
2031 :
2032 :
2033 : /*---------------------------------------------------------------------*
2034 : * IVAS_DEC_GetNumObjects( )
2035 : *
2036 : * Returns the number of objects available in the decoded bitstream
2037 : *---------------------------------------------------------------------*/
2038 :
2039 24462 : ivas_error IVAS_DEC_GetNumObjects(
2040 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2041 : UWord16 *numObjects /* o : number of objects for which the decoder has been configured */
2042 : )
2043 : {
2044 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
2045 : Word16 is_masa_ism;
2046 :
2047 24462 : is_masa_ism = 0;
2048 24462 : move16();
2049 : #endif
2050 :
2051 24462 : test();
2052 24462 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2053 : {
2054 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2055 : }
2056 :
2057 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
2058 24462 : IF( hIvasDec->st_ivas->hMasa != NULL )
2059 : {
2060 758 : IF( EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) )
2061 : {
2062 758 : is_masa_ism = 1;
2063 758 : move16();
2064 : }
2065 : }
2066 :
2067 24462 : test();
2068 24462 : test();
2069 24462 : test();
2070 24462 : IF( EQ_32( hIvasDec->st_ivas->ivas_format, ISM_FORMAT ) ||
2071 : EQ_32( hIvasDec->st_ivas->ivas_format, SBA_ISM_FORMAT ) ||
2072 : EQ_32( hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) ||
2073 : EQ_16( is_masa_ism, 1 ) )
2074 : #else
2075 : test();
2076 : test();
2077 : 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 ) )
2078 : #endif
2079 : {
2080 24462 : *numObjects = hIvasDec->st_ivas->nchan_ism;
2081 : }
2082 : ELSE
2083 : {
2084 0 : *numObjects = 0;
2085 : }
2086 24462 : move16();
2087 :
2088 24462 : return IVAS_ERR_OK;
2089 : }
2090 :
2091 :
2092 : /*---------------------------------------------------------------------*
2093 : * IVAS_DEC_GetFormat( )
2094 : *
2095 : * Returns the format of currently decoded bitstream.
2096 : * Note: bitstream format is only known after the first (good) frame has been decoded.
2097 : *---------------------------------------------------------------------*/
2098 :
2099 50 : ivas_error IVAS_DEC_GetFormat(
2100 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2101 : IVAS_DEC_BS_FORMAT *format /* o : format detected from bitstream fed to the decoder */
2102 : )
2103 : {
2104 : #ifdef FIX_VOIP_FUNCTIONS
2105 50 : test();
2106 50 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2107 : {
2108 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2109 : }
2110 :
2111 : #endif
2112 50 : IF( hIvasDec->hasDecodedFirstGoodFrame )
2113 : {
2114 50 : *format = mapIvasFormat( hIvasDec->st_ivas->ivas_format );
2115 : }
2116 : ELSE
2117 : {
2118 0 : *format = IVAS_DEC_BS_UNKOWN;
2119 : }
2120 50 : move32();
2121 :
2122 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
2123 50 : test();
2124 50 : if ( EQ_32( *format, IVAS_DEC_BS_MASA ) && EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) )
2125 : {
2126 0 : *format = IVAS_DEC_BS_MASA_ISM;
2127 0 : move32();
2128 : }
2129 : #endif
2130 :
2131 50 : return IVAS_ERR_OK;
2132 : }
2133 :
2134 :
2135 : /*---------------------------------------------------------------------*
2136 : * getInputBufferSize()
2137 : *
2138 : *
2139 : *---------------------------------------------------------------------*/
2140 :
2141 613 : static Word16 getOutputBufferSize(
2142 : const Decoder_Struct *st_ivas /* i : IVAS decoder handle */
2143 : )
2144 : {
2145 613 : IF( st_ivas->hDecoderConfig == NULL )
2146 : {
2147 0 : return -1;
2148 : }
2149 :
2150 613 : IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
2151 : {
2152 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 ) );
2153 : }
2154 563 : ELSE IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
2155 : {
2156 3 : IF( st_ivas->hLsSetupCustom == NULL )
2157 : {
2158 0 : return -1;
2159 : }
2160 :
2161 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 ) );
2162 : }
2163 : ELSE
2164 : {
2165 560 : return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->nchan_out ), INV_FRAME_PER_SEC_Q15 ) );
2166 : }
2167 : }
2168 :
2169 :
2170 : /*---------------------------------------------------------------------*
2171 : * IVAS_DEC_GetOutputBufferSize()
2172 : *
2173 : *
2174 : *---------------------------------------------------------------------*/
2175 :
2176 613 : ivas_error IVAS_DEC_GetOutputBufferSize(
2177 : const IVAS_DEC_HANDLE hIvasDec, /* i : IVAS decoder handle */
2178 : Word16 *outputBufferSize /* o : total number of samples expected in the output buffer for current decoder configuration */
2179 : )
2180 : {
2181 613 : test();
2182 613 : test();
2183 613 : IF( outputBufferSize == NULL || hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2184 : {
2185 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2186 : }
2187 :
2188 613 : *outputBufferSize = getOutputBufferSize( hIvasDec->st_ivas );
2189 613 : move16();
2190 :
2191 613 : IF( EQ_16( *outputBufferSize, -1 ) )
2192 : {
2193 0 : return IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE;
2194 : }
2195 : ELSE
2196 : {
2197 613 : return IVAS_ERR_OK;
2198 : }
2199 : }
2200 :
2201 :
2202 : /*---------------------------------------------------------------------*
2203 : * IVAS_DEC_GetNumOutputChannels( )
2204 : *
2205 : * Returns number of output channels
2206 : *---------------------------------------------------------------------*/
2207 :
2208 613 : ivas_error IVAS_DEC_GetNumOutputChannels(
2209 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2210 : Word16 *numOutputChannels /* o : number of PCM output channels */
2211 : )
2212 : {
2213 : #ifdef FIX_VOIP_FUNCTIONS
2214 613 : test();
2215 613 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2216 : {
2217 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2218 : }
2219 :
2220 : #endif
2221 613 : IF( hIvasDec->hasDecodedFirstGoodFrame )
2222 : {
2223 613 : *numOutputChannels = hIvasDec->st_ivas->hDecoderConfig->nchan_out;
2224 : }
2225 : ELSE
2226 : {
2227 0 : *numOutputChannels = 0;
2228 : }
2229 613 : move16();
2230 :
2231 613 : return IVAS_ERR_OK;
2232 : }
2233 :
2234 :
2235 : /*---------------------------------------------------------------------*
2236 : * IVAS_DEC_GetObjectMetadata( )
2237 : *
2238 : * Get metadata of one object decoded in the most recent frame
2239 : *---------------------------------------------------------------------*/
2240 68942 : ivas_error IVAS_DEC_GetObjectMetadata(
2241 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2242 : IVAS_ISM_METADATA *metadata, /* o : struct where metadata decoded in most recently decoded frame will be written */
2243 : const UWord16 zero_flag, /* i : if this flag is enabled, this function outputs a zero-initialized metadata struct */
2244 : const UWord16 objectIdx /* i : index of the queried object */
2245 : )
2246 : {
2247 : Decoder_Struct *st_ivas;
2248 : ISM_METADATA_HANDLE hIsmMeta;
2249 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
2250 : Word16 is_masa_ism;
2251 :
2252 68942 : is_masa_ism = 0;
2253 68942 : move16();
2254 : #endif
2255 :
2256 68942 : test();
2257 68942 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2258 : {
2259 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2260 : }
2261 :
2262 68942 : st_ivas = hIvasDec->st_ivas;
2263 :
2264 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
2265 68942 : IF( hIvasDec->st_ivas->hMasa != NULL )
2266 : {
2267 2148 : IF( EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) )
2268 : {
2269 2148 : is_masa_ism = 1;
2270 2148 : move16();
2271 : }
2272 : }
2273 :
2274 68942 : test();
2275 68942 : test();
2276 68942 : test();
2277 80090 : if ( NE_32( st_ivas->ivas_format, ISM_FORMAT ) &&
2278 20300 : NE_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) &&
2279 9304 : NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) &&
2280 152 : EQ_16( is_masa_ism, 0 ) )
2281 : #else
2282 : test();
2283 : test();
2284 : 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 ) )
2285 : #endif
2286 : {
2287 0 : return IVAS_ERR_WRONG_MODE;
2288 : }
2289 :
2290 68942 : IF( GE_16( objectIdx, st_ivas->nchan_ism ) )
2291 : {
2292 0 : return IVAS_ERR_INVALID_INDEX;
2293 : }
2294 :
2295 68942 : hIsmMeta = st_ivas->hIsmMetaData[objectIdx];
2296 :
2297 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
2298 68942 : test();
2299 68942 : test();
2300 68942 : test();
2301 68942 : IF( hIsmMeta == NULL ||
2302 : EQ_16( zero_flag, 1 ) ||
2303 : ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) )
2304 : #else
2305 : IF( hIsmMeta == NULL || zero_flag )
2306 : #endif
2307 : {
2308 2584 : metadata->azimuth_fx = 0; // Q22
2309 2584 : metadata->elevation_fx = 0; // Q22
2310 2584 : metadata->radius_fx = 512; // Q9
2311 2584 : metadata->yaw_fx = 0; // Q22
2312 2584 : metadata->pitch_fx = 0; // Q22
2313 2584 : metadata->spread_fx = 0; // Q22
2314 2584 : metadata->gainFactor_fx = ONE_IN_Q31; // Q31
2315 2584 : metadata->non_diegetic_flag = 0;
2316 : }
2317 : ELSE
2318 : {
2319 66358 : metadata->azimuth_fx = hIsmMeta->azimuth_fx; // Q22
2320 66358 : metadata->elevation_fx = hIsmMeta->elevation_fx; // Q22
2321 66358 : metadata->radius_fx = hIsmMeta->radius_fx; // Q9
2322 66358 : metadata->yaw_fx = hIsmMeta->yaw_fx; // Q22
2323 66358 : metadata->pitch_fx = hIsmMeta->pitch_fx; // Q22
2324 66358 : metadata->spread_fx = 0; // Q22
2325 66358 : metadata->gainFactor_fx = ONE_IN_Q31;
2326 66358 : metadata->non_diegetic_flag = hIsmMeta->non_diegetic_flag;
2327 : }
2328 :
2329 68942 : move32();
2330 68942 : move32();
2331 68942 : move32();
2332 68942 : move32();
2333 68942 : move32();
2334 68942 : move32();
2335 68942 : move16();
2336 68942 : move16();
2337 68942 : return IVAS_ERR_OK;
2338 : }
2339 :
2340 : /*---------------------------------------------------------------------*
2341 : * IVAS_DEC_GetMasaMetadata( )
2342 : *
2343 : * Get metadata of the most recently decoded MASA frame
2344 : *---------------------------------------------------------------------*/
2345 :
2346 5617 : ivas_error IVAS_DEC_GetMasaMetadata(
2347 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2348 : 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 */
2349 : const UWord8 getFromJbmBuffer /* i : get metadata from a JBM buffer */
2350 : )
2351 : {
2352 5617 : test();
2353 5617 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2354 : {
2355 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2356 : }
2357 :
2358 5617 : test();
2359 5617 : IF( NE_16( hIvasDec->st_ivas->ivas_format, MASA_FORMAT ) && NE_16( hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) )
2360 : {
2361 0 : return IVAS_ERR_WRONG_MODE;
2362 : }
2363 :
2364 5617 : IF( getFromJbmBuffer )
2365 : {
2366 1308 : ivas_jbm_masa_sf_to_sf_map( hIvasDec->st_ivas );
2367 : }
2368 :
2369 5617 : *hMasaExtOutMeta = hIvasDec->st_ivas->hMasa->data.extOutMeta;
2370 :
2371 5617 : return IVAS_ERR_OK;
2372 : }
2373 :
2374 :
2375 : /*---------------------------------------------------------------------*
2376 : * IVAS_DEC_FeedHeadTrackData( )
2377 : *
2378 : * Feed the decoder with the head tracking data
2379 : *---------------------------------------------------------------------*/
2380 :
2381 278972 : ivas_error IVAS_DEC_FeedHeadTrackData(
2382 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2383 : IVAS_QUATERNION orientation, /* i : head-tracking data, listener orientation */
2384 : IVAS_VECTOR3 Pos, /* i : listener position */
2385 : const Word16 subframe_idx, /* i : subframe index */
2386 : const ISAR_SPLIT_REND_ROT_AXIS rot_axis /* i : external control for rotation axis for split rendering */
2387 : )
2388 : {
2389 : HEAD_TRACK_DATA_HANDLE hHeadTrackData;
2390 : ivas_error error;
2391 :
2392 278972 : test();
2393 278972 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2394 : {
2395 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2396 : }
2397 :
2398 278972 : hHeadTrackData = hIvasDec->st_ivas->hHeadTrackData;
2399 :
2400 278972 : IF( hHeadTrackData == NULL )
2401 : {
2402 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2403 : }
2404 :
2405 : /* Move head-tracking data to the decoder handle */
2406 : /* check for Euler angle signaling */
2407 : /* check for Euler angle signaling */
2408 278972 : IF( EQ_32( orientation.w_fx, L_negate( 12582912 ) ) && EQ_16( orientation.q_fact, Q22 ) )
2409 : {
2410 0 : Euler2Quat_fx( deg2rad_fx( orientation.x_fx ), deg2rad_fx( orientation.y_fx ), deg2rad_fx( orientation.z_fx ), &orientation );
2411 0 : modify_Quat_q_fx( &orientation, &orientation, Q29 );
2412 : }
2413 :
2414 278972 : Word32 updateRate_fx = 1677721600; // value is 200 in Q23
2415 278972 : move32();
2416 278972 : orientation.w_fx = L_shl( orientation.w_fx, sub( Q29, orientation.q_fact ) ); // Q29
2417 278972 : orientation.x_fx = L_shl( orientation.x_fx, sub( Q29, orientation.q_fact ) ); // Q29
2418 278972 : orientation.y_fx = L_shl( orientation.y_fx, sub( Q29, orientation.q_fact ) ); // Q29
2419 278972 : orientation.z_fx = L_shl( orientation.z_fx, sub( Q29, orientation.q_fact ) ); // Q29
2420 278972 : hHeadTrackData->OrientationTracker->refRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29
2421 278972 : hHeadTrackData->OrientationTracker->refRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29
2422 278972 : hHeadTrackData->OrientationTracker->refRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29
2423 278972 : hHeadTrackData->OrientationTracker->refRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) ); // Q29
2424 278972 : hHeadTrackData->OrientationTracker->absAvgRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
2425 278972 : hHeadTrackData->OrientationTracker->absAvgRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
2426 278972 : hHeadTrackData->OrientationTracker->absAvgRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
2427 278972 : hHeadTrackData->OrientationTracker->absAvgRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
2428 :
2429 278972 : orientation.q_fact = Q29;
2430 278972 : hHeadTrackData->OrientationTracker->refRot.q_fact = Q29;
2431 278972 : hHeadTrackData->OrientationTracker->absAvgRot.q_fact = Q29;
2432 278972 : move16();
2433 278972 : move16();
2434 278972 : move16();
2435 :
2436 278972 : IF( NE_32( ( error = ivas_orient_trk_Process_fx( hHeadTrackData->OrientationTracker, orientation, updateRate_fx, &hHeadTrackData->Quaternions[subframe_idx] ) ), IVAS_ERR_OK ) )
2437 : {
2438 0 : return error;
2439 : }
2440 :
2441 278972 : hHeadTrackData->Pos[subframe_idx].x_fx = Pos.x_fx;
2442 278972 : hHeadTrackData->Pos[subframe_idx].y_fx = Pos.y_fx;
2443 278972 : hHeadTrackData->Pos[subframe_idx].z_fx = Pos.z_fx;
2444 278972 : hHeadTrackData->Pos[subframe_idx].q_fact = Pos.q_fact;
2445 278972 : move32();
2446 278972 : move32();
2447 278972 : move32();
2448 278972 : move16();
2449 :
2450 278972 : hHeadTrackData->sr_pose_pred_axis = rot_axis;
2451 278972 : move32();
2452 :
2453 278972 : hIvasDec->updateOrientation = true;
2454 278972 : move16();
2455 :
2456 278972 : return IVAS_ERR_OK;
2457 : }
2458 :
2459 :
2460 : /*---------------------------------------------------------------------*
2461 : * IVAS_DEC_FeedRefRotData( )
2462 : *
2463 : * Feed the decoder with the reference rotation
2464 : *---------------------------------------------------------------------*/
2465 :
2466 0 : ivas_error IVAS_DEC_FeedRefRotData(
2467 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2468 : IVAS_QUATERNION rotation /* i : reference rotation data */
2469 : )
2470 : {
2471 : ivas_orient_trk_state_t *pOtr;
2472 :
2473 0 : test();
2474 0 : test();
2475 0 : test();
2476 0 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHeadTrackData == NULL || hIvasDec->st_ivas->hHeadTrackData->OrientationTracker == NULL )
2477 : {
2478 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2479 : }
2480 :
2481 0 : pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker;
2482 :
2483 0 : pOtr->refRot.w_fx = rotation.w_fx; // rotation.q_fact
2484 0 : pOtr->refRot.x_fx = rotation.x_fx; // rotation.q_fact
2485 0 : pOtr->refRot.z_fx = rotation.z_fx; // rotation.q_fact
2486 0 : pOtr->refRot.y_fx = rotation.y_fx; // rotation.q_fact
2487 :
2488 0 : pOtr->refRot.q_fact = rotation.q_fact;
2489 0 : move32();
2490 0 : move32();
2491 0 : move32();
2492 0 : move32();
2493 :
2494 0 : hIvasDec->updateOrientation = true;
2495 0 : move16();
2496 :
2497 0 : return IVAS_ERR_OK;
2498 : }
2499 :
2500 :
2501 : /*---------------------------------------------------------------------*
2502 : * IVAS_DEC_FeedRefVectorData( )
2503 : *
2504 : * Feed the decoder with a reference vector spanning from listenerPos
2505 : * to refPos. Only available in OTR_TRACKING_REF_POS and
2506 : * OTR_TRACKING_REF_POS_LEV modes.
2507 : *---------------------------------------------------------------------*/
2508 :
2509 4004 : ivas_error IVAS_DEC_FeedRefVectorData(
2510 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2511 : IVAS_VECTOR3 listenerPos, /* i : Listener position */
2512 : IVAS_VECTOR3 refPos /* i : Reference position */
2513 : )
2514 : {
2515 : ivas_orient_trk_state_t *pOtr;
2516 :
2517 4004 : test();
2518 4004 : test();
2519 4004 : test();
2520 4004 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHeadTrackData == NULL || hIvasDec->st_ivas->hHeadTrackData->OrientationTracker == NULL )
2521 : {
2522 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2523 : }
2524 :
2525 4004 : pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker;
2526 :
2527 4004 : hIvasDec->updateOrientation = true;
2528 4004 : move16();
2529 :
2530 4004 : ivas_error error_fx = ivas_orient_trk_SetReferenceVector_fx( pOtr, listenerPos, refPos );
2531 4004 : return error_fx;
2532 : }
2533 :
2534 : /*---------------------------------------------------------------------*
2535 : * IVAS_DEC_FeedExternalOrientationData( )
2536 : *
2537 : * Feed the decoder with the external orientation data
2538 : *---------------------------------------------------------------------*/
2539 :
2540 116924 : ivas_error IVAS_DEC_FeedExternalOrientationData(
2541 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2542 : IVAS_QUATERNION orientation, /* i : external orientation data */
2543 : Word8 enableHeadRotation, /* i : flag to enable head rotation for this frame */
2544 : Word8 enableExternalOrientation, /* i : flag to enable external orientation for this frame */
2545 : Word8 enableRotationInterpolation, /* i : flag to interpolate rotations from current and previous frames */
2546 : Word16 numFramesToTargetOrientation, /* i : number of frames until target orientation is reached */
2547 : const Word16 subframe_idx /* i : subframe index */
2548 : )
2549 : {
2550 : EXTERNAL_ORIENTATION_HANDLE hExternalOrientationData;
2551 :
2552 116924 : test();
2553 116924 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2554 : {
2555 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2556 : }
2557 :
2558 116924 : hExternalOrientationData = hIvasDec->st_ivas->hExtOrientationData;
2559 :
2560 116924 : IF( hExternalOrientationData == NULL )
2561 : {
2562 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2563 : }
2564 :
2565 116924 : orientation.q_fact = Q29;
2566 116924 : move16();
2567 :
2568 : /* Move external orientation data to the decoder handle (invert orientations) */
2569 116924 : QuaternionInverse_fx( orientation, &hExternalOrientationData->Quaternions[subframe_idx] );
2570 :
2571 116924 : hExternalOrientationData->enableHeadRotation[subframe_idx] = enableHeadRotation;
2572 116924 : hExternalOrientationData->enableExternalOrientation[subframe_idx] = enableExternalOrientation;
2573 116924 : hExternalOrientationData->enableRotationInterpolation[subframe_idx] = enableRotationInterpolation;
2574 116924 : hExternalOrientationData->numFramesToTargetOrientation[subframe_idx] = numFramesToTargetOrientation;
2575 116924 : move16();
2576 116924 : move16();
2577 116924 : move16();
2578 116924 : move16();
2579 :
2580 116924 : hIvasDec->updateOrientation = true;
2581 116924 : move16();
2582 :
2583 116924 : return IVAS_ERR_OK;
2584 : }
2585 :
2586 :
2587 : /*---------------------------------------------------------------------*
2588 : * IVAS_DEC_FeedCustomLsData( )
2589 : *
2590 : * Feed the decoder with the Custom loudspeaker data
2591 : *---------------------------------------------------------------------*/
2592 :
2593 : /*! r: error code */
2594 3 : ivas_error IVAS_DEC_FeedCustomLsData(
2595 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2596 : const IVAS_CUSTOM_LS_DATA hLsCustomData /* i : Custom loudspeaker setup data */
2597 : )
2598 : {
2599 : Word16 i, is_planar;
2600 : IVAS_LSSETUP_CUSTOM_HANDLE hLsSetupCustom;
2601 :
2602 3 : test();
2603 3 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
2604 : {
2605 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2606 : }
2607 :
2608 3 : hLsSetupCustom = hIvasDec->st_ivas->hLsSetupCustom;
2609 :
2610 3 : IF( hLsSetupCustom == NULL )
2611 : {
2612 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2613 : }
2614 :
2615 : /* Move Custom LS layout data to the decoder handle */
2616 :
2617 : /* Loudspeaker azimuths and elevations */
2618 3 : hLsSetupCustom->num_spk = hLsCustomData.num_spk;
2619 3 : move16();
2620 :
2621 3 : Copy32( hLsCustomData.azimuth_fx, hLsSetupCustom->ls_azimuth_fx, hLsCustomData.num_spk ); // Q22
2622 3 : Copy32( hLsCustomData.elevation_fx, hLsSetupCustom->ls_elevation_fx, hLsCustomData.num_spk ); // Q22
2623 :
2624 : /* Set planar flag */
2625 3 : is_planar = 1;
2626 3 : move16();
2627 51 : FOR( i = 0; i < hLsCustomData.num_spk; i++ )
2628 : {
2629 48 : test();
2630 48 : if ( is_planar && hLsSetupCustom->ls_elevation_fx[i] != 0 )
2631 : {
2632 3 : is_planar = 0;
2633 3 : move16();
2634 : }
2635 : }
2636 3 : hLsSetupCustom->is_planar_setup = is_planar;
2637 3 : move16();
2638 :
2639 : /* Loudspeaker LFE */
2640 3 : hLsSetupCustom->num_lfe = hLsCustomData.num_lfe;
2641 3 : move16();
2642 3 : Copy( hLsCustomData.lfe_idx, hLsSetupCustom->lfe_idx, hLsCustomData.num_lfe );
2643 :
2644 3 : return IVAS_ERR_OK;
2645 : }
2646 :
2647 :
2648 : /*---------------------------------------------------------------------*
2649 : * IVAS_DEC_GetHrtfHandle( )
2650 : *
2651 : *
2652 : *---------------------------------------------------------------------*/
2653 :
2654 48 : ivas_error IVAS_DEC_GetHrtfHandle(
2655 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2656 : IVAS_DEC_HRTF_HANDLE **hHrtfTD /* o : HRTF handle */
2657 : )
2658 : {
2659 48 : test();
2660 48 : test();
2661 48 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfTD == NULL )
2662 : {
2663 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2664 : }
2665 :
2666 48 : *hHrtfTD = &hIvasDec->st_ivas->hHrtfTD;
2667 :
2668 48 : return IVAS_ERR_OK;
2669 : }
2670 :
2671 :
2672 : /*---------------------------------------------------------------------*
2673 : * IVAS_DEC_GetHrtfCRendHandle( )
2674 : *
2675 : *
2676 : *---------------------------------------------------------------------*/
2677 :
2678 48 : ivas_error IVAS_DEC_GetHrtfCRendHandle(
2679 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2680 : IVAS_DEC_HRTF_CREND_HANDLE **hSetOfHRTF /* o : Set of HRTF handle */
2681 : )
2682 : {
2683 48 : test();
2684 48 : test();
2685 48 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hSetOfHRTF == NULL )
2686 : {
2687 0 : return IVAS_ERR_WRONG_PARAMS;
2688 : }
2689 :
2690 48 : *hSetOfHRTF = &hIvasDec->st_ivas->hSetOfHRTF;
2691 :
2692 48 : return IVAS_ERR_OK;
2693 : }
2694 :
2695 :
2696 : /*---------------------------------------------------------------------*
2697 : * IVAS_DEC_GetHrtfFastConvHandle( )
2698 : *
2699 : *
2700 : *---------------------------------------------------------------------*/
2701 :
2702 24 : ivas_error IVAS_DEC_GetHrtfFastConvHandle(
2703 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2704 : IVAS_DEC_HRTF_FASTCONV_HANDLE **hHrtfFastConv /* o : FASTCONV HRTF handle */
2705 : )
2706 : {
2707 24 : test();
2708 24 : test();
2709 24 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfFastConv == NULL )
2710 : {
2711 0 : return IVAS_ERR_WRONG_PARAMS;
2712 : }
2713 :
2714 24 : *hHrtfFastConv = &hIvasDec->st_ivas->hHrtfFastConv;
2715 :
2716 24 : return IVAS_ERR_OK;
2717 : }
2718 :
2719 :
2720 : /*---------------------------------------------------------------------*
2721 : * IVAS_DEC_GetHrtfParamBinHandle( )
2722 : *
2723 : *
2724 : *---------------------------------------------------------------------*/
2725 :
2726 24 : ivas_error IVAS_DEC_GetHrtfParamBinHandle(
2727 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2728 : IVAS_DEC_HRTF_PARAMBIN_HANDLE **hHrtfParambin /* o : Parametric binauralizer HRTF handle */
2729 : )
2730 : {
2731 24 : test();
2732 24 : test();
2733 24 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfParambin == NULL )
2734 : {
2735 0 : return IVAS_ERR_WRONG_PARAMS;
2736 : }
2737 :
2738 24 : *hHrtfParambin = &hIvasDec->st_ivas->hHrtfParambin;
2739 :
2740 24 : return IVAS_ERR_OK;
2741 : }
2742 :
2743 :
2744 : /*---------------------------------------------------------------------*
2745 : * IVAS_DEC_GetHrtfStatisticsHandle( )
2746 : *
2747 : *
2748 : *---------------------------------------------------------------------*/
2749 :
2750 24 : ivas_error IVAS_DEC_GetHrtfStatisticsHandle(
2751 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2752 : IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics /* o : HRTF statistics handle */
2753 : )
2754 : {
2755 24 : if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfStatistics == NULL )
2756 : {
2757 0 : return IVAS_ERR_WRONG_PARAMS;
2758 : }
2759 :
2760 24 : *hHrtfStatistics = &hIvasDec->st_ivas->hHrtfStatistics;
2761 :
2762 24 : return IVAS_ERR_OK;
2763 : }
2764 :
2765 :
2766 : /*---------------------------------------------------------------------*
2767 : * copyRendererConfigStruct( )
2768 : *
2769 : *
2770 : *---------------------------------------------------------------------*/
2771 :
2772 64 : static ivas_error copyRendererConfigStruct(
2773 : RENDER_CONFIG_HANDLE hRCin,
2774 : IVAS_RENDER_CONFIG_HANDLE hRCout )
2775 : {
2776 64 : test();
2777 64 : IF( hRCin == NULL || hRCout == NULL )
2778 : {
2779 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2780 : }
2781 :
2782 : #ifndef FIX_587_DEFAULT_REVERB
2783 : hRCout->roomAcoustics.override = hRCin->roomAcoustics.override;
2784 : #endif
2785 64 : hRCout->roomAcoustics.nBands = hRCin->roomAcoustics.nBands;
2786 64 : hRCout->roomAcoustics.acousticPreDelay_fx = hRCin->roomAcoustics.acousticPreDelay_fx;
2787 64 : hRCout->roomAcoustics.inputPreDelay_fx = hRCin->roomAcoustics.inputPreDelay_fx;
2788 :
2789 64 : Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16
2790 64 : Copy32( hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26
2791 64 : Copy32( hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30
2792 64 : Copy( hRCin->directivity_fx, hRCout->directivity_fx, 3 * MAX_NUM_OBJECTS );
2793 :
2794 64 : hRCout->split_rend_config = hRCin->split_rend_config;
2795 :
2796 64 : hRCout->roomAcoustics.use_er = hRCin->roomAcoustics.use_er;
2797 64 : hRCout->roomAcoustics.lowComplexity = hRCin->roomAcoustics.lowComplexity;
2798 64 : move16();
2799 64 : move16();
2800 64 : move16();
2801 64 : move32();
2802 64 : move32();
2803 64 : move32();
2804 :
2805 64 : return IVAS_ERR_OK;
2806 : }
2807 :
2808 :
2809 : /*---------------------------------------------------------------------*
2810 : * IVAS_DEC_GetRenderConfig( )
2811 : *
2812 : *
2813 : *---------------------------------------------------------------------*/
2814 :
2815 64 : ivas_error IVAS_DEC_GetRenderConfig(
2816 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2817 : const IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render configuration handle */
2818 : )
2819 : {
2820 64 : test();
2821 64 : test();
2822 64 : test();
2823 64 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL || hRCout == NULL )
2824 : {
2825 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2826 : }
2827 :
2828 64 : return copyRendererConfigStruct( hIvasDec->st_ivas->hRenderConfig, hRCout );
2829 : }
2830 :
2831 :
2832 : /*! r: error code*/
2833 0 : ivas_error IVAS_DEC_GetDefaultRenderConfig(
2834 : IVAS_RENDER_CONFIG_HANDLE hRCout /* o : Render config handle */
2835 : )
2836 : {
2837 : RENDER_CONFIG_DATA RCin;
2838 0 : RENDER_CONFIG_HANDLE hRCin = &RCin;
2839 : ivas_error error;
2840 :
2841 0 : IF( NE_32( ( error = ivas_render_config_init_from_rom_fx( &hRCin ) ), IVAS_ERR_OK ) )
2842 : {
2843 0 : return error;
2844 : }
2845 :
2846 0 : return copyRendererConfigStruct( hRCin, hRCout );
2847 : }
2848 :
2849 :
2850 : /*---------------------------------------------------------------------*
2851 : * IVAS_DEC_FeedRenderConfig( )
2852 : *
2853 : *
2854 : *---------------------------------------------------------------------*/
2855 :
2856 43 : ivas_error IVAS_DEC_FeedRenderConfig(
2857 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2858 : const IVAS_RENDER_CONFIG_DATA renderConfig /* i : Render configuration struct */
2859 : )
2860 : {
2861 : RENDER_CONFIG_HANDLE hRenderConfig;
2862 : ivas_error error;
2863 :
2864 43 : test();
2865 43 : test();
2866 43 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL )
2867 : {
2868 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
2869 : }
2870 :
2871 43 : hRenderConfig = hIvasDec->st_ivas->hRenderConfig;
2872 : #ifndef FIX_587_DEFAULT_REVERB
2873 : hRenderConfig->roomAcoustics.override = renderConfig.roomAcoustics.override;
2874 : #endif
2875 43 : hRenderConfig->roomAcoustics.nBands = renderConfig.roomAcoustics.nBands;
2876 43 : hRenderConfig->roomAcoustics.acousticPreDelay_fx = renderConfig.roomAcoustics.acousticPreDelay_fx;
2877 43 : hRenderConfig->roomAcoustics.inputPreDelay_fx = renderConfig.roomAcoustics.inputPreDelay_fx;
2878 :
2879 43 : hRenderConfig->roomAcoustics.use_er = 0;
2880 43 : move16();
2881 43 : move16();
2882 43 : move16();
2883 43 : move32();
2884 43 : move32();
2885 43 : IF( EQ_16( renderConfig.roomAcoustics.use_er, 1 ) )
2886 : {
2887 14 : hRenderConfig->roomAcoustics.use_er = renderConfig.roomAcoustics.use_er;
2888 14 : hRenderConfig->roomAcoustics.lowComplexity = renderConfig.roomAcoustics.lowComplexity;
2889 14 : hRenderConfig->roomAcoustics.dimensions = renderConfig.roomAcoustics.dimensions;
2890 14 : hRenderConfig->roomAcoustics.ListenerOrigin = renderConfig.roomAcoustics.ListenerOrigin;
2891 :
2892 14 : Copy32( renderConfig.roomAcoustics.AbsCoeff_fx, hRenderConfig->roomAcoustics.AbsCoeff_fx, IVAS_ROOM_ABS_COEFF );
2893 14 : move16();
2894 14 : move32();
2895 : }
2896 :
2897 43 : Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX ); // Q16
2898 43 : Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26
2899 43 : Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX ); // Q30
2900 :
2901 : #ifdef FIX_1053_REVERB_RECONFIGURATION
2902 : /* Re-initialize reverb instance if already available */
2903 :
2904 : /* TD renderer Jot reverberator */
2905 43 : IF( hIvasDec->st_ivas->hReverb != NULL )
2906 : {
2907 0 : IF( ( error = ivas_reverb_open_fx( &hIvasDec->st_ivas->hReverb, hIvasDec->st_ivas->hHrtfStatistics, hRenderConfig, hIvasDec->st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
2908 : {
2909 0 : return error;
2910 : }
2911 : }
2912 :
2913 : /* CREND Jot reverberator */
2914 43 : test();
2915 43 : test();
2916 43 : IF( hIvasDec->st_ivas->hCrendWrapper != NULL && hIvasDec->st_ivas->hCrendWrapper->hCrend[0] != NULL && hIvasDec->st_ivas->hCrendWrapper->hCrend[0]->hReverb != NULL )
2917 : {
2918 4 : IF( ( error = ivas_reverb_open_fx( &hIvasDec->st_ivas->hCrendWrapper->hCrend[0]->hReverb, hIvasDec->st_ivas->hHrtfStatistics, hRenderConfig, hIvasDec->st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
2919 : {
2920 0 : return error;
2921 : }
2922 : }
2923 :
2924 43 : test();
2925 : /* FB reverberator */
2926 43 : IF( hIvasDec->st_ivas->hDiracDecBin[0] != NULL && hIvasDec->st_ivas->hDiracDecBin[0]->hReverb != NULL )
2927 : {
2928 4 : ivas_binaural_reverb_close_fx( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ) );
2929 : #ifdef FIX_1139_REV_COLORATION_SHORT_T60
2930 4 : IF( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK )
2931 : #else
2932 : IF( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hDiracDecBin[0]->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL ) ) != IVAS_ERR_OK )
2933 : #endif
2934 : {
2935 0 : return error;
2936 : }
2937 : }
2938 :
2939 43 : test();
2940 : /* Fastconv CLDFB reverberator */
2941 43 : IF( hIvasDec->st_ivas->hBinRenderer != NULL && hIvasDec->st_ivas->hBinRenderer->hReverb != NULL )
2942 : {
2943 3 : ivas_binaural_reverb_close_fx( &( hIvasDec->st_ivas->hBinRenderer->hReverb ) );
2944 : #ifdef FIX_1139_REV_COLORATION_SHORT_T60
2945 3 : IF( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hBinRenderer->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hBinRenderer->conv_band, hIvasDec->st_ivas->hBinRenderer->timeSlots, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK )
2946 : #else
2947 : IF( ( error = ivas_binaural_reverb_init( &( hIvasDec->st_ivas->hBinRenderer->hReverb ), hIvasDec->st_ivas->hHrtfStatistics, hIvasDec->st_ivas->hBinRenderer->conv_band, hIvasDec->st_ivas->hBinRenderer->timeSlots, &( hRenderConfig->roomAcoustics ), hIvasDec->st_ivas->hDecoderConfig->output_Fs, NULL, NULL ) ) != IVAS_ERR_OK )
2948 : #endif
2949 : {
2950 0 : return error;
2951 : }
2952 : }
2953 : #endif
2954 :
2955 43 : Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS );
2956 : #ifdef CONF_DISTATT
2957 43 : Copy32( renderConfig.distAtt_fx, hRenderConfig->distAtt_fx, 3 );
2958 : #endif
2959 :
2960 43 : hRenderConfig->split_rend_config = renderConfig.split_rend_config;
2961 :
2962 : /* Overwrite any pose correction settings if 0 DOF (no pose correction) was selected */
2963 43 : IF( hRenderConfig->split_rend_config.dof == 0 )
2964 : {
2965 0 : hRenderConfig->split_rend_config.poseCorrectionMode = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE;
2966 : }
2967 :
2968 43 : IF( is_split_rendering_enabled( hIvasDec->st_ivas->hDecoderConfig, hRenderConfig ) )
2969 : {
2970 0 : IF( ( error = isar_split_rend_validate_config( &hRenderConfig->split_rend_config, ( hIvasDec->st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0 ) ) != IVAS_ERR_OK )
2971 : {
2972 0 : return error;
2973 : }
2974 : }
2975 :
2976 43 : return IVAS_ERR_OK;
2977 : }
2978 :
2979 :
2980 : /*---------------------------------------------------------------------*
2981 : * IVAS_DEC_GetDelay( )
2982 : *
2983 : *
2984 : *---------------------------------------------------------------------*/
2985 :
2986 6227 : ivas_error IVAS_DEC_GetDelay(
2987 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
2988 : Word16 *nSamples, /* o : decoder delay in samples */
2989 : Word32 *timeScale /* o : time scale of the delay, equal to decoder output sampling rate */
2990 : )
2991 : {
2992 : Decoder_Struct *st_ivas;
2993 : DECODER_CONFIG_HANDLE hDecoderConfig;
2994 : Word32 out_fs_fx;
2995 :
2996 6227 : test();
2997 6227 : test();
2998 6227 : test();
2999 6227 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || nSamples == NULL || timeScale == NULL )
3000 : {
3001 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3002 : }
3003 :
3004 6227 : IF( !hIvasDec->hasDecodedFirstGoodFrame )
3005 : {
3006 : /* Delay depends on IVAS format, which is unknown until first frame has been decoded */
3007 0 : return IVAS_ERR_WAITING_FOR_BITSTREAM;
3008 : }
3009 :
3010 6227 : st_ivas = hIvasDec->st_ivas;
3011 6227 : hDecoderConfig = st_ivas->hDecoderConfig;
3012 :
3013 6227 : IF( NE_32( hDecoderConfig->output_Fs, 48000 ) )
3014 : {
3015 1548 : IF( NE_32( hDecoderConfig->output_Fs, 32000 ) )
3016 : {
3017 81 : out_fs_fx = FS_16K_IN_NS_Q31;
3018 : }
3019 : ELSE
3020 : {
3021 1467 : out_fs_fx = FS_32K_IN_NS_Q31;
3022 : }
3023 : }
3024 : ELSE
3025 : {
3026 4679 : out_fs_fx = FS_48K_IN_NS_Q31;
3027 : }
3028 6227 : move32();
3029 :
3030 : #ifdef NONBE_FIX_984_OMASA_EXT_OUTPUT
3031 6227 : nSamples[1] = NS2SA_FX2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbSynDec[0], (Word16) EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) );
3032 6227 : move16();
3033 : #else
3034 : nSamples[1] = NS2SA_FX2( hDecoderConfig->output_Fs, get_delay_fx( DEC, hDecoderConfig->output_Fs, st_ivas->ivas_format, st_ivas->cldfbAnaDec[0], hDecoderConfig->output_config ) );
3035 : move16();
3036 : #endif
3037 6227 : nSamples[2] = extract_l( W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ) );
3038 6227 : move16();
3039 6227 : nSamples[0] = add( nSamples[1], nSamples[2] );
3040 6227 : move16();
3041 :
3042 6227 : test();
3043 6227 : IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) )
3044 : {
3045 : /* note: in MASA, all delay is compensated at the decoder by default, so subtract the encoder delay for print-out */
3046 5729 : nSamples[1] = sub( nSamples[1], NS2SA_FX2( hDecoderConfig->output_Fs, IVAS_ENC_DELAY_NS ) );
3047 5729 : move16();
3048 : }
3049 :
3050 6227 : *timeScale = hDecoderConfig->output_Fs;
3051 6227 : move32();
3052 :
3053 6227 : return IVAS_ERR_OK;
3054 : }
3055 :
3056 :
3057 : /*---------------------------------------------------------------------*
3058 : * IVAS_DEC_HasDecodedFirstGoodFrame( )
3059 : *
3060 : *
3061 : *---------------------------------------------------------------------*/
3062 :
3063 813 : ivas_error IVAS_DEC_HasDecodedFirstGoodFrame(
3064 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3065 : bool *hasDecodedFirstGoodFrame /* o : flag indicating if the decoder has decoded a good frame since it was configured */
3066 : )
3067 : {
3068 813 : test();
3069 813 : test();
3070 813 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hasDecodedFirstGoodFrame == NULL )
3071 : {
3072 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3073 : }
3074 :
3075 813 : *hasDecodedFirstGoodFrame = hIvasDec->hasDecodedFirstGoodFrame;
3076 813 : move16();
3077 :
3078 813 : return IVAS_ERR_OK;
3079 : }
3080 :
3081 :
3082 : /*---------------------------------------------------------------------*
3083 : * IVAS_DEC_GetPcmFrameSize( )
3084 : *
3085 : *
3086 : *---------------------------------------------------------------------*/
3087 :
3088 613 : ivas_error IVAS_DEC_GetPcmFrameSize(
3089 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3090 : Word32 *pcmFrameSize /* o : total size of the PCM output frame. This takes into account the number of output channels Q0 */
3091 : )
3092 : {
3093 613 : test();
3094 613 : test();
3095 613 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || pcmFrameSize == NULL )
3096 : {
3097 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3098 : }
3099 :
3100 613 : IF( hIvasDec->hasDecodedFirstGoodFrame )
3101 : {
3102 613 : *pcmFrameSize = Mult_32_16( imult3216( hIvasDec->st_ivas->hDecoderConfig->output_Fs, hIvasDec->st_ivas->hDecoderConfig->nchan_out ), INV_FRAME_PER_SEC_Q15 );
3103 : }
3104 : ELSE
3105 : {
3106 0 : *pcmFrameSize = 0;
3107 : }
3108 613 : move32();
3109 :
3110 613 : return IVAS_ERR_OK;
3111 : }
3112 :
3113 :
3114 : /*---------------------------------------------------------------------*
3115 : * isSidFrame( )
3116 : *
3117 : * Check if a frame contains a SID
3118 : *---------------------------------------------------------------------*/
3119 :
3120 17671 : static bool isSidFrame(
3121 : const UWord16 size )
3122 : {
3123 17671 : IF( EQ_16( size, ( SID_1k75 / FRAMES_PER_SEC ) ) )
3124 : {
3125 0 : return true; /* AMR-WB SID */
3126 : }
3127 17671 : ELSE IF( EQ_16( size, ( SID_2k40 / FRAMES_PER_SEC ) ) )
3128 : {
3129 0 : return true; /* EVS SID */
3130 : }
3131 17671 : ELSE IF( EQ_16( size, ( IVAS_SID_5k2 / FRAMES_PER_SEC ) ) )
3132 : {
3133 268 : return true; /* IVAS SID */
3134 : }
3135 :
3136 17403 : return false;
3137 : }
3138 :
3139 17645 : static void bsCompactToSerial(
3140 : const UWord8 *compact,
3141 : UWord16 *serial,
3142 : const UWord16 num_bits )
3143 : {
3144 : /* Bitstream conversion is not counted towards complexity and memory usage */
3145 : #define WMC_TOOL_SKIP
3146 : UWord32 i;
3147 17645 : UWord8 byte = 0;
3148 17645 : const UWord8 mask = 0x80;
3149 17645 : move16();
3150 17645 : move16();
3151 :
3152 30046981 : FOR( i = 0; i < num_bits; ++i )
3153 : {
3154 30029336 : if ( ( i % 8 ) == 0 )
3155 : {
3156 3753667 : byte = compact[i / 8];
3157 3753667 : move16();
3158 : }
3159 :
3160 30029336 : serial[i] = shr( s_and( byte, mask ), 7 );
3161 30029336 : move16();
3162 :
3163 30029336 : byte = (UWord8) shl( byte, 1 );
3164 : }
3165 :
3166 : /* Add 4 padding bytes required by core coder */
3167 582285 : FOR( i = 0; i < 4 * 8; ++i )
3168 : {
3169 564640 : serial[( num_bits + i )] = 0;
3170 564640 : move16();
3171 : }
3172 : #undef WMC_TOOL_SKIP
3173 17645 : }
3174 :
3175 :
3176 : /*---------------------------------------------------------------------*
3177 : * IVAS_DEC_VoIP_FeedFrame( )
3178 : *
3179 : * Feed RTP packet into internal jitter buffer
3180 : *---------------------------------------------------------------------*/
3181 :
3182 17671 : ivas_error IVAS_DEC_VoIP_FeedFrame(
3183 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3184 : UWord8 *au, /* i : buffer containing input access unit */
3185 : const UWord16 auSize, /* i : size of the access unit */
3186 : const UWord16 rtpSequenceNumber, /* i : RTP sequence number (16 bits) */
3187 : const UWord32 rtpTimeStamp, /* i : RTP timestamp (32 bits) */
3188 : const UWord32 rcvTime_ms, /* i : receive time of the RTP packet in milliseconds */
3189 : const bool qBit /* i : Q bit for AMR-WB IO */
3190 : )
3191 : {
3192 : JB4_DATAUNIT_HANDLE dataUnit;
3193 : Word16 partialCopyFrameType, partialCopyOffset;
3194 : Word16 result;
3195 :
3196 : #ifdef FIX_VOIP_FUNCTIONS
3197 17671 : test();
3198 17671 : test();
3199 17671 : IF( hIvasDec == NULL || hIvasDec->hVoIP == NULL || au == NULL )
3200 : {
3201 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3202 : }
3203 :
3204 : #endif
3205 17671 : IF( auSize == 0 )
3206 : {
3207 0 : return IVAS_ERR_OK; /* ignore empty/NO_DATA frame - shouldn't be transmitted in RTP */
3208 : }
3209 :
3210 17671 : IF( GT_16( shr( add( auSize, 7 ), 3 ), (Word16) MAX_AU_SIZE ) )
3211 : {
3212 0 : return IVAS_ERR_INVALID_BITSTREAM;
3213 : }
3214 :
3215 17671 : partialCopyFrameType = 0;
3216 17671 : move16();
3217 17671 : partialCopyOffset = 0;
3218 17671 : move16();
3219 :
3220 17671 : IF( EQ_16( hIvasDec->mode, (Word16) IVAS_DEC_MODE_EVS ) )
3221 : {
3222 : /* check if frame contains a partial copy and get its offset */
3223 0 : evs_dec_previewFrame( au, auSize, &partialCopyFrameType, &partialCopyOffset );
3224 : }
3225 :
3226 : /* create data unit for primary copy in the frame */
3227 17671 : dataUnit = JB4_AllocDataUnit( hIvasDec->hVoIP->hJBM );
3228 17671 : mvc2c( au, dataUnit->data, shr( add( auSize, 7 ), 3 ) );
3229 17671 : dataUnit->dataSize = auSize;
3230 17671 : dataUnit->duration = 20;
3231 17671 : dataUnit->sequenceNumber = rtpSequenceNumber;
3232 17671 : dataUnit->silenceIndicator = isSidFrame( dataUnit->dataSize );
3233 17671 : move16();
3234 17671 : dataUnit->timeScale = 1000;
3235 17671 : dataUnit->rcvTime = rcvTime_ms;
3236 17671 : dataUnit->timeStamp = rtpTimeStamp;
3237 17671 : dataUnit->partial_frame = 0;
3238 17671 : dataUnit->partialCopyOffset = partialCopyOffset;
3239 17671 : dataUnit->qBit = qBit;
3240 17671 : move16();
3241 17671 : move16();
3242 17671 : move16();
3243 17671 : move16();
3244 17671 : move16();
3245 17671 : move32();
3246 17671 : move32();
3247 17671 : move32();
3248 17671 : move32();
3249 :
3250 : /* add the frame to the JBM */
3251 17671 : result = JB4_PushDataUnit( hIvasDec->hVoIP->hJBM, dataUnit, rcvTime_ms );
3252 17671 : IF( result != 0 )
3253 : {
3254 0 : return IVAS_ERR_UNKNOWN;
3255 : }
3256 :
3257 17671 : test();
3258 17671 : IF( NE_16( partialCopyFrameType, RF_NO_DATA ) && partialCopyOffset != 0 )
3259 : {
3260 : /* create data unit for partial copy in the frame */
3261 0 : dataUnit = JB4_AllocDataUnit( hIvasDec->hVoIP->hJBM );
3262 0 : mvc2c( au, dataUnit->data, shr( add( auSize, 7 ), 3 ) );
3263 0 : dataUnit->dataSize = auSize;
3264 0 : dataUnit->duration = 20;
3265 0 : dataUnit->sequenceNumber = rtpSequenceNumber;
3266 0 : dataUnit->silenceIndicator = 0; /* there are no partial copies for SID frames */
3267 0 : dataUnit->timeScale = 1000;
3268 0 : dataUnit->rcvTime = rcvTime_ms;
3269 0 : dataUnit->timeStamp = (UWord32) W_sub( rtpTimeStamp, imult3216( dataUnit->duration, partialCopyOffset ) );
3270 0 : move32();
3271 0 : dataUnit->partial_frame = 1;
3272 0 : dataUnit->partialCopyOffset = partialCopyOffset;
3273 0 : dataUnit->qBit = qBit;
3274 0 : move16();
3275 0 : move16();
3276 0 : move16();
3277 0 : move16();
3278 0 : move16();
3279 0 : move32();
3280 0 : move32();
3281 0 : move32();
3282 :
3283 : /* add the frame to the JBM */
3284 0 : result = JB4_PushDataUnit( hIvasDec->hVoIP->hJBM, dataUnit, rcvTime_ms );
3285 0 : IF( result != 0 )
3286 : {
3287 0 : return IVAS_ERR_UNKNOWN;
3288 : }
3289 : }
3290 :
3291 17671 : return IVAS_ERR_OK;
3292 : }
3293 :
3294 :
3295 : /*---------------------------------------------------------------------*
3296 : * IVAS_DEC_VoIP_SetScale( )
3297 : *
3298 : * Set the TSM scale
3299 : *---------------------------------------------------------------------*/
3300 :
3301 19753 : ivas_error IVAS_DEC_VoIP_SetScale(
3302 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3303 : const Word16 maxScaling, /* i : max allowed absolute difference in samples from the default 20ms frame size */
3304 : const Word16 scale /* i : TSM scale to set in percent of the default frame size */
3305 : )
3306 : {
3307 : #ifdef FIX_VOIP_FUNCTIONS
3308 19753 : test();
3309 19753 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
3310 : {
3311 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3312 : }
3313 :
3314 : #endif
3315 19753 : IF( !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
3316 : {
3317 0 : return IVAS_ERR_TSM_NOT_ENABLED;
3318 : }
3319 : ELSE
3320 : {
3321 19753 : hIvasDec->tsm_scale = scale;
3322 19753 : hIvasDec->tsm_max_scaling = maxScaling;
3323 19753 : move16();
3324 19753 : move16();
3325 : }
3326 :
3327 19753 : return IVAS_ERR_OK;
3328 : }
3329 :
3330 :
3331 : /*---------------------------------------------------------------------*
3332 : * IVAS_DEC_TSM_SetQuality( )
3333 : *
3334 : * set the quality theshold for the time scale modiciation that is used
3335 : * to determine if the TSM yielded a signal that satisfies the minimum
3336 : * quality requirements.
3337 : * quality is lower limit for minimum quality
3338 : * Range is [-2;2] - where positive values allow
3339 : * only pasting with same phase information
3340 : * Negative values would yield cross phased pasting
3341 : * When not setting the minimum quality with this function the default
3342 : * value used is 1.0f
3343 : *
3344 : *---------------------------------------------------------------------*/
3345 :
3346 0 : ivas_error IVAS_DEC_TSM_SetQuality(
3347 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3348 : const Word16 quality /* i : target TSM quality Q14 */
3349 : )
3350 : {
3351 : #ifdef FIX_VOIP_FUNCTIONS
3352 0 : test();
3353 0 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
3354 : {
3355 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3356 : }
3357 :
3358 : #endif
3359 0 : IF( !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
3360 : {
3361 0 : return IVAS_ERR_TSM_NOT_ENABLED;
3362 : }
3363 : ELSE
3364 : {
3365 0 : hIvasDec->tsm_quality = quality; // Q14
3366 0 : move16();
3367 : }
3368 :
3369 0 : return IVAS_ERR_OK;
3370 : }
3371 :
3372 :
3373 : /*---------------------------------------------------------------------*
3374 : * IVAS_DEC_VoIP_GetSamples( )
3375 : *
3376 : * Main function to decode one frame in VoIP
3377 : *---------------------------------------------------------------------*/
3378 :
3379 19754 : ivas_error IVAS_DEC_VoIP_GetSamples(
3380 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3381 : UWord16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */
3382 : 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 */
3383 : const UWord32 systemTimestamp_ms /* i : current system timestamp */
3384 : #ifdef SUPPORT_JBM_TRACEFILE
3385 : ,
3386 : JbmTraceFileWriterFn jbmWriterFn,
3387 : void *jbmWriter
3388 : #endif
3389 : )
3390 : {
3391 : Decoder_Struct *st_ivas;
3392 : DECODER_CONFIG_HANDLE hDecoderConfig;
3393 : IVAS_DEC_VOIP *hVoIP;
3394 : UWord32 extBufferedTime_ms, scale, maxScaling;
3395 : JB4_DATAUNIT_HANDLE dataUnit;
3396 : UWord16 extBufferedSamples;
3397 : Word16 result;
3398 : ivas_error error;
3399 : Word16 nSamplesRendered;
3400 : UWord8 nOutChannels;
3401 :
3402 : #ifdef FIX_VOIP_FUNCTIONS
3403 19754 : test();
3404 19754 : test();
3405 19754 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->hVoIP == NULL )
3406 : {
3407 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3408 : }
3409 :
3410 : #endif
3411 19754 : st_ivas = hIvasDec->st_ivas;
3412 19754 : hDecoderConfig = st_ivas->hDecoderConfig;
3413 19754 : hVoIP = hIvasDec->hVoIP;
3414 19754 : nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out;
3415 19754 : nSamplesRendered = 0;
3416 19754 : move16();
3417 19754 : move16();
3418 19754 : move16();
3419 :
3420 19754 : IF( nSamplesPerChannel == 0 )
3421 : {
3422 0 : return IVAS_ERR_WRONG_PARAMS;
3423 : }
3424 :
3425 : /* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */
3426 51620 : WHILE( LT_16( nSamplesRendered, nSamplesPerChannel ) )
3427 : {
3428 31866 : IF( hIvasDec->nSamplesAvailableNext == 0 )
3429 : {
3430 : Word16 nSamplesBuffered;
3431 19753 : nSamplesBuffered = 0;
3432 19753 : move16();
3433 19753 : IF( hIvasDec->hasBeenFedFirstGoodFrame )
3434 : {
3435 19525 : IF( NE_32( ( error = IVAS_DEC_GetBufferedNumberOfSamples( hIvasDec, &nSamplesBuffered ) ), IVAS_ERR_OK ) )
3436 : {
3437 0 : return error;
3438 : }
3439 : }
3440 :
3441 19753 : extBufferedSamples = nSamplesBuffered;
3442 19753 : move16();
3443 : Word16 exp;
3444 19753 : extBufferedTime_ms = BASOP_Util_Divide3232_Scale( imult3216( extBufferedSamples, 1000 ), hDecoderConfig->output_Fs, &exp );
3445 19753 : extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, sub( 15, exp ) ); // Q0
3446 19753 : dataUnit = NULL;
3447 :
3448 : /* pop one access unit from the jitter buffer */
3449 19753 : result = JB4_PopDataUnit( hVoIP->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling );
3450 19753 : IF( result != 0 )
3451 : {
3452 0 : return IVAS_ERR_UNKNOWN;
3453 : }
3454 :
3455 19753 : IF( EQ_32( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
3456 : {
3457 0 : if ( GT_32( maxScaling, 20 ) )
3458 : {
3459 0 : maxScaling = 20;
3460 0 : move16();
3461 : }
3462 : }
3463 19753 : maxScaling = Mult_32_32( imult3216( hDecoderConfig->output_Fs, (Word16) maxScaling ), INV_1000_Q31 );
3464 :
3465 : #ifdef DEBUG_MODE_JBM
3466 : dbgwrite( &extBufferedSamples, sizeof( uint16_t ), 1, 1, "./res/JBM_extBufferedSamples.dat" );
3467 : dbgwrite( &systemTimestamp_ms, sizeof( uint32_t ), 1, 1, "./res/JBM_systemTimestamp.dat" );
3468 : dbgwrite( &scale, sizeof( uint32_t ), 1, 1, "./res/JBM_scale.dat" );
3469 : dbgwrite( &maxScaling, sizeof( uint32_t ), 1, 1, "./res/JBM_maxScale.dat" );
3470 : #endif
3471 :
3472 : /* avoid time scaling multiple times in one sound card slot */
3473 19753 : IF( NE_64( scale, 100U ) )
3474 : {
3475 595 : IF( hIvasDec->timeScalingDone )
3476 : {
3477 0 : scale = 100;
3478 0 : move32();
3479 : }
3480 : }
3481 :
3482 : /* limit scale to range supported by time scaler */
3483 19753 : IF( LT_32( scale, APA_MIN_SCALE ) )
3484 : {
3485 0 : scale = APA_MIN_SCALE;
3486 0 : move32();
3487 : }
3488 19753 : ELSE IF( GT_32( scale, APA_MAX_SCALE ) )
3489 : {
3490 0 : scale = APA_MAX_SCALE;
3491 0 : move32();
3492 : }
3493 :
3494 19753 : IF( NE_32( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, (Word16) maxScaling, (Word16) scale ) ), IVAS_ERR_OK ) )
3495 : {
3496 0 : return error;
3497 : }
3498 :
3499 : /* copy bitstream into decoder state */
3500 19753 : IF( dataUnit )
3501 : {
3502 17645 : hIvasDec->hVoIP->hCurrentDataUnit = dataUnit;
3503 :
3504 17645 : bsCompactToSerial( dataUnit->data, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize );
3505 :
3506 :
3507 17645 : IF( NE_32( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ) ), IVAS_ERR_OK ) )
3508 : {
3509 0 : return error;
3510 : }
3511 : }
3512 2108 : ELSE IF( hIvasDec->hasDecodedFirstGoodFrame )
3513 : {
3514 : /* Decoder has been initialized with first good frame - do PLC */
3515 1908 : IF( NE_32( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 ) ), IVAS_ERR_OK ) )
3516 : {
3517 0 : return error;
3518 : }
3519 : }
3520 :
3521 : #ifdef SUPPORT_JBM_TRACEFILE
3522 : /* jbmWriterFn and jbmWriter may be NULL if tracefile writing was not requested on CLI */
3523 19753 : test();
3524 19753 : IF( jbmWriterFn != NULL && jbmWriter != NULL )
3525 : {
3526 : /* write JBM trace data entry */
3527 19753 : store_JbmData( hVoIP, dataUnit, systemTimestamp_ms, extBufferedSamples, hDecoderConfig->output_Fs );
3528 19753 : IF( ( jbmWriterFn( &hVoIP->JbmTraceData, jbmWriter ) ) != IVAS_ERR_OK )
3529 : {
3530 0 : fprintf( stderr, "\nError writing JBM Trace data to file\n" );
3531 0 : return IVAS_ERR_UNKNOWN;
3532 : }
3533 : }
3534 : #endif
3535 19753 : IF( dataUnit )
3536 : {
3537 17645 : IF( dataUnit->partial_frame != 0 )
3538 : {
3539 0 : hVoIP->lastDecodedWasActive = 1;
3540 : }
3541 : ELSE
3542 : {
3543 17645 : hVoIP->lastDecodedWasActive = !dataUnit->silenceIndicator;
3544 : }
3545 17645 : move16();
3546 :
3547 : /* data unit memory is no longer used */
3548 17645 : JB4_FreeDataUnit( hVoIP->hJBM, dataUnit );
3549 : }
3550 :
3551 19753 : IF( !hIvasDec->hasBeenFedFirstGoodFrame )
3552 : {
3553 200 : hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;
3554 200 : hIvasDec->nSamplesRendered = 0;
3555 200 : move16();
3556 200 : move16();
3557 : }
3558 : }
3559 :
3560 : /* decode */
3561 31866 : IF( !hIvasDec->hasBeenFedFirstGoodFrame )
3562 : {
3563 : /* codec mode to use not known yet - simply output silence */
3564 : /* directly set output zero */
3565 200 : Word16 nSamplesToZero = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext );
3566 200 : set16_fx( pcmBuf + imult1616( nSamplesRendered, nOutChannels ), 0, imult1616( nSamplesToZero, nOutChannels ) );
3567 200 : nSamplesRendered = add( nSamplesRendered, nSamplesToZero );
3568 200 : hIvasDec->nSamplesRendered = add( hIvasDec->nSamplesRendered, nSamplesToZero );
3569 200 : hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesToZero );
3570 200 : move16();
3571 200 : move16();
3572 200 : update_voip_rendered20ms( hIvasDec, nSamplesToZero );
3573 : }
3574 : ELSE
3575 : {
3576 : Word16 nSamplesToRender, nSamplesRendered_loop;
3577 : bool tmp;
3578 31666 : nSamplesToRender = sub( nSamplesPerChannel, nSamplesRendered );
3579 :
3580 : /* render IVAS frames directly to the output buffer */
3581 31666 : IF( NE_32( ( error = IVAS_DEC_GetSamples( hIvasDec, nSamplesToRender, pcmBuf + imult1616( nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) )
3582 : {
3583 0 : return error;
3584 : }
3585 :
3586 31666 : nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
3587 31666 : update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop );
3588 : }
3589 : }
3590 :
3591 19754 : return IVAS_ERR_OK;
3592 : }
3593 :
3594 :
3595 : /*---------------------------------------------------------------------*
3596 : * update_voip_rendered20ms( )
3597 : *
3598 : * Function to flush remaining audio in VoIP
3599 : *---------------------------------------------------------------------*/
3600 :
3601 31866 : static void update_voip_rendered20ms(
3602 : IVAS_DEC_HANDLE hIvasDec,
3603 : const Word16 nSamplesRendered )
3604 : {
3605 : Word16 nSamplesRenderedTotal;
3606 :
3607 31866 : nSamplesRenderedTotal = add( hIvasDec->hVoIP->nSamplesRendered20ms, nSamplesRendered );
3608 :
3609 : /* we have crossed a 20ms border, reset the time scaling done flag */
3610 31866 : IF( GE_16( nSamplesRenderedTotal, hIvasDec->hVoIP->nSamplesFrame ) )
3611 : {
3612 19754 : hIvasDec->timeScalingDone = 0;
3613 19754 : move16();
3614 : }
3615 :
3616 : /* float code was: hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal % hIvasDec->hVoIP->nSamplesFrame; */
3617 31866 : hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal;
3618 31866 : move16();
3619 51620 : WHILE( GE_16( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->hVoIP->nSamplesFrame ) )
3620 : {
3621 19754 : hIvasDec->hVoIP->nSamplesRendered20ms = sub( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->hVoIP->nSamplesFrame );
3622 : }
3623 :
3624 31866 : return;
3625 : }
3626 :
3627 :
3628 : /*---------------------------------------------------------------------*
3629 : * IVAS_DEC_VoIP_Flush( )
3630 : *
3631 : * Function to flush remaining audio in VoIP
3632 : *---------------------------------------------------------------------*/
3633 :
3634 28 : ivas_error IVAS_DEC_Flush(
3635 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3636 : const Word16 nSamplesPerChannel, /* i : number of samples per channel requested to be written to output buffer */
3637 : 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 */
3638 : Word16 *nSamplesFlushed /* o : number of samples flushed */
3639 : )
3640 : {
3641 : ivas_error error;
3642 : UWord16 nSamplesToRender;
3643 : UWord16 nSamplesFlushedLocal;
3644 :
3645 : #ifdef FIX_VOIP_FUNCTIONS
3646 28 : test();
3647 28 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
3648 : {
3649 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3650 : }
3651 :
3652 : #endif
3653 28 : *nSamplesFlushed = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext );
3654 28 : move16();
3655 :
3656 28 : nSamplesToRender = (UWord16) *nSamplesFlushed;
3657 28 : move16();
3658 :
3659 : /* render IVAS frames */
3660 28 : error = IVAS_ERR_OK;
3661 28 : move16();
3662 :
3663 28 : test();
3664 28 : IF( GT_16( nSamplesToRender, 0 ) && NE_16( (Word16) hIvasDec->st_ivas->ivas_format, (Word16) MONO_FORMAT ) )
3665 : {
3666 21 : error = IVAS_DEC_GetRenderedSamples( hIvasDec, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf );
3667 : }
3668 : ELSE
3669 : {
3670 7 : *nSamplesFlushed = 0;
3671 7 : move16();
3672 : }
3673 :
3674 28 : return error;
3675 : }
3676 :
3677 :
3678 : /*---------------------------------------------------------------------*
3679 : * IVAS_DEC_VoIP_IsEmpty( )
3680 : *
3681 : *
3682 : *---------------------------------------------------------------------*/
3683 :
3684 210 : bool IVAS_DEC_VoIP_IsEmpty(
3685 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3686 : const Word16 nSamplesAsked )
3687 : {
3688 : #ifdef FIX_VOIP_FUNCTIONS
3689 210 : test();
3690 210 : IF( hIvasDec == NULL || hIvasDec->hVoIP == NULL )
3691 : {
3692 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3693 : }
3694 :
3695 : #endif
3696 210 : test();
3697 210 : return ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 && LT_16( hIvasDec->nSamplesAvailableNext, nSamplesAsked ) );
3698 : }
3699 :
3700 :
3701 : /*---------------------------------------------------------------------*
3702 : * IVAS_DEC_VoIP_Get_CA_offset( )
3703 : *
3704 : *
3705 : *---------------------------------------------------------------------*/
3706 :
3707 0 : ivas_error IVAS_DEC_VoIP_Get_CA_offset(
3708 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3709 : Word16 *optimum_offset,
3710 : Word16 *FEC_hi )
3711 : {
3712 0 : test();
3713 0 : test();
3714 0 : IF( ( hIvasDec == NULL || hIvasDec->hVoIP == NULL || hIvasDec->hVoIP->hJBM == NULL ) )
3715 : {
3716 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3717 : }
3718 :
3719 0 : *optimum_offset = JB4_getFECoffset( hIvasDec->hVoIP->hJBM );
3720 0 : *FEC_hi = JB4_FECoffset( hIvasDec->hVoIP->hJBM );
3721 0 : move16();
3722 0 : move16();
3723 :
3724 0 : return IVAS_ERR_OK;
3725 : }
3726 :
3727 :
3728 : /*---------------------------------------------------------------------*
3729 : * IVAS_DEC_Close_VoIP( )
3730 : *
3731 : *
3732 : *---------------------------------------------------------------------*/
3733 :
3734 28 : static void IVAS_DEC_Close_VoIP(
3735 : IVAS_DEC_VOIP *hVoIP /* i/o: IVAS decoder handle */
3736 : )
3737 : {
3738 28 : JB4_Destroy( &hVoIP->hJBM );
3739 :
3740 28 : IF( hVoIP->bs_conversion_buf != NULL )
3741 : {
3742 : #define WMC_TOOL_SKIP
3743 : /* Bitstream conversion is not counted towards complexity and memory usage */
3744 28 : free( hVoIP->bs_conversion_buf );
3745 : #undef WMC_TOOL_SKIP
3746 : }
3747 :
3748 28 : free( hVoIP );
3749 :
3750 28 : return;
3751 : }
3752 :
3753 :
3754 : #ifdef SUPPORT_JBM_TRACEFILE
3755 : /*---------------------------------------------------------------------*
3756 : * store_JbmData()
3757 : *
3758 : * Store JBM trace data entry
3759 : *---------------------------------------------------------------------*/
3760 :
3761 19753 : static void store_JbmData(
3762 : IVAS_DEC_VOIP *hVoIP,
3763 : JB4_DATAUNIT_HANDLE dataUnit,
3764 : const UWord32 systemTimestamp_ms,
3765 : const UWord16 extBufferedSamples,
3766 : const Word32 output_Fs )
3767 : {
3768 : IVAS_JBM_TRACE_DATA *JbmTraceData;
3769 :
3770 19753 : IF( hVoIP == NULL )
3771 : {
3772 0 : return;
3773 : }
3774 :
3775 19753 : JbmTraceData = &hVoIP->JbmTraceData;
3776 :
3777 19753 : JbmTraceData->systemTimestamp_ms = systemTimestamp_ms;
3778 19753 : JbmTraceData->extBufferedSamples = extBufferedSamples;
3779 19753 : JbmTraceData->lastDecodedWasActive = hVoIP->lastDecodedWasActive;
3780 19753 : JbmTraceData->output_Fs = output_Fs;
3781 19753 : JbmTraceData->dataUnit_flag = dataUnit != NULL;
3782 19753 : move16();
3783 19753 : move16();
3784 19753 : move16();
3785 19753 : move32();
3786 19753 : move32();
3787 19753 : IF( dataUnit != NULL )
3788 : {
3789 17645 : JbmTraceData->sequenceNumber = dataUnit->sequenceNumber;
3790 17645 : JbmTraceData->timeStamp = dataUnit->timeStamp;
3791 17645 : JbmTraceData->rcvTime = dataUnit->rcvTime;
3792 17645 : JbmTraceData->partial_frame = dataUnit->partial_frame;
3793 17645 : JbmTraceData->partialCopyOffset = dataUnit->partialCopyOffset;
3794 17645 : move16();
3795 17645 : move16();
3796 17645 : move16();
3797 17645 : move32();
3798 17645 : move32();
3799 : }
3800 :
3801 19753 : return;
3802 : }
3803 :
3804 :
3805 : /*---------------------------------------------------------------------*
3806 : * IVAS_DEC_GetJbmData()
3807 : *
3808 : *
3809 : *---------------------------------------------------------------------*/
3810 :
3811 0 : ivas_error IVAS_DEC_GetJbmData(
3812 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
3813 : IVAS_JBM_TRACE_DATA *JbmTraceData /* o : JBM Trace data */
3814 :
3815 : )
3816 : {
3817 : #ifdef FIX_VOIP_FUNCTIONS
3818 0 : test();
3819 0 : test();
3820 0 : IF( hIvasDec == NULL || hIvasDec->hVoIP == NULL || JbmTraceData == NULL )
3821 : #else
3822 : IF( hIvasDec->hVoIP == NULL )
3823 : #endif
3824 : {
3825 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
3826 : }
3827 :
3828 0 : *JbmTraceData = hIvasDec->hVoIP->JbmTraceData;
3829 :
3830 0 : return IVAS_ERR_OK;
3831 : }
3832 :
3833 : #endif
3834 :
3835 :
3836 : /*---------------------------------------------------------------------*
3837 : * IVAS_DEC_GetErrorMessage( )
3838 : *
3839 : * Maps error codes to error description strings
3840 : *---------------------------------------------------------------------*/
3841 :
3842 0 : const char *IVAS_DEC_GetErrorMessage(
3843 : ivas_error error /* i : decoder error code enum */
3844 : )
3845 : {
3846 0 : return ivas_error_to_string( error );
3847 : }
3848 :
3849 :
3850 : /*---------------------------------------------------------------------*
3851 : * printConfigInfo_dec( )
3852 : *
3853 : *
3854 : *---------------------------------------------------------------------*/
3855 :
3856 613 : static ivas_error printConfigInfo_dec(
3857 : Decoder_Struct *st_ivas,
3858 : const Word16 bitstreamformat,
3859 : const bool Opt_VOIP,
3860 : const bool quietModeEnabled )
3861 : {
3862 : ivas_error error;
3863 : Word8 config_str[50];
3864 : AUDIO_CONFIG output_config;
3865 :
3866 : /*-----------------------------------------------------------------*
3867 : * Print info on screen
3868 : *-----------------------------------------------------------------*/
3869 :
3870 613 : fprintf( stdout, "\n" );
3871 :
3872 : /*-----------------------------------------------------------------*
3873 : * Print output sampling frequency
3874 : *-----------------------------------------------------------------*/
3875 :
3876 613 : fprintf( stdout, "Output sampling rate: %d Hz\n", st_ivas->hDecoderConfig->output_Fs );
3877 :
3878 : /*-----------------------------------------------------------------*
3879 : * Print bitrate
3880 : *-----------------------------------------------------------------*/
3881 :
3882 613 : IF( !quietModeEnabled )
3883 : {
3884 0 : IF( !Opt_VOIP )
3885 : {
3886 0 : fprintf( stdout, "Bitrate: %.2f kbps\n", (float) st_ivas->hDecoderConfig->ivas_total_brate / 1000 );
3887 :
3888 0 : IF( st_ivas->hDecoderConfig->ivas_total_brate <= 0 )
3889 : {
3890 0 : IF( EQ_16( bitstreamformat, G192 ) )
3891 : {
3892 0 : fprintf( stdout, "Active Bitrate not identified in bitstream file \n" );
3893 : }
3894 : ELSE /* MIME */
3895 : {
3896 0 : fprintf( stdout, "Active Bitrate not identified from first MIME frame \n" );
3897 : }
3898 : }
3899 : }
3900 : }
3901 :
3902 : /*-----------------------------------------------------------------*
3903 : * Print output configuration
3904 : *-----------------------------------------------------------------*/
3905 :
3906 613 : IF( EQ_16( (Word16) st_ivas->ivas_format, MONO_FORMAT ) )
3907 : {
3908 3 : IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan )
3909 : {
3910 1 : fprintf( stdout, "Output configuration: mono EVS bit-exact decoding to stereo\n" );
3911 1 : float non_diegetic_pan_gain = fixedToFloat( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, 15 );
3912 1 : fprintf( stdout, "Non-diegetic panning: %.2f\n", non_diegetic_pan_gain * 90.f );
3913 : }
3914 : ELSE
3915 : {
3916 2 : fprintf( stdout, "Output configuration: mono EVS bit-exact decoding\n" );
3917 : }
3918 : }
3919 : ELSE
3920 : {
3921 610 : IF( !quietModeEnabled )
3922 : {
3923 0 : IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) )
3924 : {
3925 0 : fprintf( stdout, "Input configuration: Stereo\n" );
3926 : }
3927 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) )
3928 : {
3929 0 : IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MODE_PARAM ) )
3930 : {
3931 0 : fprintf( stdout, "Input configuration: ISM (ParamISM): 2 transport channels\n" );
3932 : }
3933 : ELSE
3934 : {
3935 0 : fprintf( stdout, "Input configuration: ISM: %d transport channel(s)\n", st_ivas->nchan_transport );
3936 : }
3937 : }
3938 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) )
3939 : {
3940 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 );
3941 : }
3942 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_ISM_FORMAT ) )
3943 : {
3944 0 : fprintf( stdout, "Input configuration: Combined Scene Based Audio, Ambisonic order %i, with %d Objects \n", st_ivas->sba_order, st_ivas->nchan_ism );
3945 : }
3946 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) )
3947 : {
3948 0 : fprintf( stdout, "Input configuration: MASA - %d channel(s)\n", st_ivas->nchan_transport );
3949 : }
3950 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) )
3951 : {
3952 0 : IF( NE_32( ( error = get_channel_config( st_ivas->transport_config, &config_str[0] ) ), IVAS_ERR_OK ) )
3953 : {
3954 0 : return error;
3955 : }
3956 :
3957 0 : fprintf( stdout, "Input configuration: %s\n", config_str );
3958 : }
3959 0 : ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) )
3960 : {
3961 0 : fprintf( stdout, "Input configuration: combined ISM and MASA (%i ISM stream(s)) \n", st_ivas->nchan_ism );
3962 : }
3963 : }
3964 :
3965 610 : output_config = st_ivas->hDecoderConfig->output_config;
3966 610 : move16();
3967 610 : get_channel_config( output_config, &config_str[0] );
3968 610 : fprintf( stdout, "Output configuration: %s\n", config_str );
3969 :
3970 610 : test();
3971 610 : test();
3972 610 : 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 ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( (Word16) output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) )
3973 : {
3974 201 : fprintf( stdout, "Render framesize: %dms\n", get_render_frame_size_ms( st_ivas->hDecoderConfig->render_framesize ) );
3975 : }
3976 610 : IF( st_ivas->hDecoderConfig->Opt_HRTF_binary )
3977 : {
3978 24 : fprintf( stdout, "HRIR/BRIR file: ON\n" );
3979 : }
3980 :
3981 610 : IF( st_ivas->hDecoderConfig->Opt_RendConfigCustom )
3982 : {
3983 32 : fprintf( stdout, "Renderer config. file: ON\n" );
3984 : }
3985 :
3986 610 : IF( st_ivas->hDecoderConfig->Opt_Headrotation )
3987 : {
3988 82 : fprintf( stdout, "Head rotation: ON\n" );
3989 : }
3990 :
3991 610 : IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation )
3992 : {
3993 31 : fprintf( stdout, "External orientation: ON\n" );
3994 : }
3995 :
3996 610 : IF( NE_16( (Word16) st_ivas->hDecoderConfig->orientation_tracking, IVAS_HEAD_ORIENT_TRK_NONE ) )
3997 : {
3998 16 : SWITCH( st_ivas->hDecoderConfig->orientation_tracking )
3999 : {
4000 12 : case IVAS_HEAD_ORIENT_TRK_AVG:
4001 12 : fprintf( stdout, "Orientation tracking: AVG\n" );
4002 12 : BREAK;
4003 0 : case IVAS_HEAD_ORIENT_TRK_REF:
4004 0 : fprintf( stdout, "Orientation tracking: REF\n" );
4005 0 : BREAK;
4006 2 : case IVAS_HEAD_ORIENT_TRK_REF_VEC:
4007 2 : fprintf( stdout, "Orientation tracking: REF_VEC\n" );
4008 2 : BREAK;
4009 2 : case IVAS_HEAD_ORIENT_TRK_REF_VEC_LEV:
4010 2 : fprintf( stdout, "Orientation tracking: REF_VEC_LEV\n" );
4011 2 : BREAK;
4012 0 : default:
4013 0 : BREAK;
4014 : }
4015 594 : }
4016 :
4017 610 : IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan )
4018 : {
4019 1 : float non_diegetic_pan_gain = fixedToFloat( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, 15 );
4020 1 : fprintf( stdout, "Non-diegetic panning: %.2f\n", non_diegetic_pan_gain * 90.f );
4021 : }
4022 :
4023 610 : IF( st_ivas->hDecoderConfig->Opt_dpid_on )
4024 : {
4025 2 : fprintf( stdout, "Directivity pattern: ON\n" );
4026 : }
4027 :
4028 610 : IF( st_ivas->hDecoderConfig->Opt_aeid_on )
4029 : {
4030 4 : fprintf( stdout, "Acoustic environment ID:ON\n" );
4031 : }
4032 : }
4033 :
4034 : /*-----------------------------------------------------------------*
4035 : * Print TSM mode info
4036 : *-----------------------------------------------------------------*/
4037 :
4038 613 : IF( st_ivas->hDecoderConfig->Opt_tsm )
4039 : {
4040 28 : fprintf( stdout, "TSM mode: ON\n" );
4041 : }
4042 :
4043 613 : return IVAS_ERR_OK;
4044 : }
4045 :
4046 :
4047 : /*---------------------------------------------------------------------*
4048 : * IVAS_DEC_PrintConfig( )
4049 : *
4050 : * Print decoder set-up info
4051 : *---------------------------------------------------------------------*/
4052 :
4053 : #ifdef FIX_VOIP_FUNCTIONS
4054 613 : ivas_error IVAS_DEC_PrintConfig(
4055 : #else
4056 : void IVAS_DEC_PrintConfig(
4057 : #endif
4058 : const IVAS_DEC_HANDLE hIvasDec,
4059 : const bool quietModeEnabled,
4060 : const bool voipMode )
4061 : {
4062 : #ifdef FIX_VOIP_FUNCTIONS
4063 613 : test();
4064 613 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
4065 : {
4066 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
4067 : }
4068 :
4069 : #endif
4070 613 : printConfigInfo_dec( hIvasDec->st_ivas, hIvasDec->bitstreamformat, voipMode, quietModeEnabled );
4071 :
4072 : #ifdef FIX_VOIP_FUNCTIONS
4073 613 : return IVAS_ERR_OK;
4074 : #else
4075 : return;
4076 : #endif
4077 : }
4078 :
4079 :
4080 : /*---------------------------------------------------------------------*
4081 : * IVAS_DEC_PrintDisclaimer( )
4082 : *
4083 : * Print IVAS disclaimer to console
4084 : *---------------------------------------------------------------------*/
4085 :
4086 626 : void IVAS_DEC_PrintDisclaimer( void )
4087 : {
4088 626 : print_disclaimer( stderr );
4089 :
4090 626 : return;
4091 : }
4092 :
4093 :
4094 : /*---------------------------------------------------------------------*
4095 : * evs_dec_main( )
4096 : *
4097 : * EVS codec main decoder fucntion
4098 : *---------------------------------------------------------------------*/
4099 :
4100 3100 : static ivas_error evs_dec_main_fx(
4101 : Decoder_Struct *st_ivas,
4102 : const Word16 nOutSamples,
4103 : Word32 *Buf_fx, // Q11
4104 : Word16 *pcmBuf // Q0
4105 : )
4106 : {
4107 : DEC_CORE_HANDLE *hCoreCoder;
4108 : Word16 mixer_left_fx, mixer_right_fx;
4109 : Word32 *p_output_fx[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN];
4110 : Word16 ch, n, i;
4111 : Word16 output_16[L_FRAME48k];
4112 : ivas_error error;
4113 :
4114 3100 : hCoreCoder = st_ivas->hSCE[0]->hCoreCoder;
4115 3100 : hCoreCoder[0]->total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
4116 3100 : move32();
4117 3100 : hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, 0x0290 /*Q0*/ ) ); // Q0
4118 3100 : move16();
4119 :
4120 3100 : mdct_switching_dec_fx( hCoreCoder[0] );
4121 :
4122 9300 : FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ )
4123 : {
4124 6200 : p_output_fx[ch] = st_ivas->p_output_fx[ch]; // Q0
4125 : }
4126 :
4127 : /* run the main EVS decoding routine */
4128 3100 : IF( EQ_16( hCoreCoder[0]->codec_mode, MODE1 ) )
4129 : {
4130 1850 : IF( hCoreCoder[0]->Opt_AMR_WB )
4131 : {
4132 0 : IF( NE_32( ( error = amr_wb_dec_fx( output_16, hCoreCoder[0] ) ), IVAS_ERR_OK ) )
4133 : {
4134 0 : return error;
4135 : }
4136 : }
4137 : ELSE
4138 : {
4139 1850 : IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) )
4140 : {
4141 0 : return error;
4142 : }
4143 : }
4144 : }
4145 : ELSE
4146 : {
4147 1250 : IF( hCoreCoder[0]->bfi == 0 )
4148 : {
4149 1250 : IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) )
4150 : {
4151 0 : return error;
4152 : }
4153 : }
4154 0 : ELSE IF( EQ_16( hCoreCoder[0]->bfi, 2 ) )
4155 : {
4156 0 : IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_FUTURE ) ), IVAS_ERR_OK ) )
4157 : {
4158 0 : return error;
4159 : }
4160 : }
4161 : ELSE
4162 : {
4163 0 : IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_MISSING ) ), IVAS_ERR_OK ) )
4164 : {
4165 0 : return error;
4166 : }
4167 : }
4168 : }
4169 :
4170 2643100 : FOR( i = 0; i < nOutSamples; i++ )
4171 : {
4172 2640000 : p_output_fx[0][i] = L_shl( output_16[i], Q11 ); /* Q11 */
4173 : }
4174 :
4175 3100 : st_ivas->BER_detect = hCoreCoder[0]->BER_detect;
4176 3100 : move16();
4177 3100 : IF( EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
4178 : {
4179 1000 : mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); // Q14
4180 1000 : mixer_right_fx = sub( MAX16B, mixer_left_fx );
4181 :
4182 1000 : v_multc_fixed_16( p_output_fx[0], mixer_right_fx, p_output_fx[1], nOutSamples ); /* Q11 */
4183 1000 : v_multc_fixed_16( p_output_fx[0], mixer_left_fx, p_output_fx[0], nOutSamples ); /* Q11 */
4184 : }
4185 :
4186 3100 : IF( !st_ivas->hDecoderConfig->Opt_tsm )
4187 : {
4188 3100 : ivas_jbm_dec_copy_tc_no_tsm_fx( st_ivas, p_output_fx, nOutSamples );
4189 : }
4190 0 : ELSE IF( Buf_fx != NULL )
4191 : {
4192 0 : FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
4193 : {
4194 0 : FOR( i = 0; i < nOutSamples; i++ )
4195 : {
4196 0 : Buf_fx[i * st_ivas->hDecoderConfig->nchan_out + n] = p_output_fx[n][i]; /* Does the same as above */ /* Q11 */
4197 0 : move32();
4198 : }
4199 : }
4200 : }
4201 : ELSE
4202 : {
4203 : /* ivas_syn_output( p_output, nOutSamples, st_ivas->hDecoderConfig->nchan_out, pcmBuf ); */
4204 0 : FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
4205 : {
4206 0 : FOR( i = 0; i < nOutSamples; i++ )
4207 : {
4208 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 */
4209 0 : move16();
4210 : }
4211 : }
4212 : }
4213 :
4214 3100 : return IVAS_ERR_OK;
4215 : }
4216 :
4217 :
4218 : /*---------------------------------------------------------------------*
4219 : * input_format_API_to_internal()
4220 : *
4221 : *
4222 : *---------------------------------------------------------------------*/
4223 :
4224 28 : static ivas_error input_format_API_to_internal(
4225 : IVAS_DEC_INPUT_FORMAT input_format,
4226 : Word16 *bitstream_format_internal,
4227 : Word16 *sdp_hf_only,
4228 : const bool is_voip_enabled )
4229 : {
4230 28 : SWITCH( input_format )
4231 : {
4232 28 : case IVAS_DEC_INPUT_FORMAT_G192:
4233 28 : IF( is_voip_enabled )
4234 : {
4235 28 : *bitstream_format_internal = VOIP_G192_RTP;
4236 : }
4237 : ELSE
4238 : {
4239 0 : *bitstream_format_internal = G192;
4240 : }
4241 28 : *sdp_hf_only = 0;
4242 28 : BREAK;
4243 0 : case IVAS_DEC_INPUT_FORMAT_MIME:
4244 0 : *bitstream_format_internal = MIME;
4245 0 : *sdp_hf_only = 0;
4246 0 : BREAK;
4247 0 : case IVAS_DEC_INPUT_FORMAT_RTPDUMP:
4248 0 : assert( is_voip_enabled && "RTP dump only supported in VoIP mode" );
4249 0 : *bitstream_format_internal = VOIP_RTPDUMP;
4250 0 : *sdp_hf_only = 0;
4251 0 : BREAK;
4252 0 : case IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF:
4253 0 : assert( is_voip_enabled && "RTP dump only supported in VoIP mode" );
4254 0 : *bitstream_format_internal = VOIP_RTPDUMP;
4255 0 : *sdp_hf_only = 1;
4256 0 : BREAK;
4257 0 : default:
4258 0 : return IVAS_ERR_INVALID_BITSTREAM;
4259 : }
4260 :
4261 28 : move16();
4262 28 : move16();
4263 28 : return IVAS_ERR_OK;
4264 : }
4265 :
4266 :
4267 : /*---------------------------------------------------------------------*
4268 : * IVAS_DEC_VoIP_reconfigure()
4269 : *
4270 : *
4271 : *---------------------------------------------------------------------*/
4272 :
4273 969 : static ivas_error IVAS_DEC_VoIP_reconfigure(
4274 : IVAS_DEC_HANDLE hIvasDec,
4275 : const UWord16 nTransportChannels,
4276 : const UWord16 l_ts )
4277 : {
4278 : Word16 apa_buffer_size;
4279 :
4280 969 : apa_buffer_size = hIvasDec->nSamplesFrame;
4281 969 : move16();
4282 :
4283 969 : IF( hIvasDec->apaExecBuffer_fx == NULL )
4284 : {
4285 : DECODER_CONFIG_HANDLE hDecoderConfig;
4286 :
4287 28 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
4288 : {
4289 : UWord16 wss, css;
4290 : Word32 startQuality;
4291 :
4292 28 : startQuality = L_shl( L_deposit_l( hIvasDec->tsm_quality ), Q2 ); /* Q14 --> Q16*/
4293 28 : apa_buffer_size = APA_BUF_PER_CHANNEL;
4294 :
4295 28 : move16();
4296 : /* get current renderer type*/
4297 28 : hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;
4298 :
4299 28 : IF( EQ_32( hDecoderConfig->output_Fs, 8000 ) )
4300 : {
4301 0 : wss = 1;
4302 0 : css = 1;
4303 : }
4304 28 : ELSE IF( EQ_32( hDecoderConfig->output_Fs, 16000 ) )
4305 : {
4306 3 : wss = 2;
4307 3 : css = 1;
4308 : }
4309 25 : ELSE IF( EQ_32( hDecoderConfig->output_Fs, 32000 ) )
4310 : {
4311 9 : wss = 4;
4312 9 : css = 2;
4313 : }
4314 16 : ELSE IF( EQ_32( hDecoderConfig->output_Fs, 48000 ) )
4315 : {
4316 16 : wss = 6;
4317 16 : css = 3;
4318 : }
4319 : ELSE
4320 : {
4321 0 : return IVAS_ERR_INIT_ERROR;
4322 : }
4323 :
4324 28 : move16();
4325 28 : move16();
4326 28 : test();
4327 28 : test();
4328 28 : test();
4329 28 : test();
4330 28 : IF( NE_32( (Word32) apa_init( &hIvasDec->hTimeScaler, nTransportChannels ), IVAS_ERR_OK ) ||
4331 : apa_set_rate( hIvasDec->hTimeScaler, hDecoderConfig->output_Fs ) != 0 ||
4332 : apa_set_complexity_options( hIvasDec->hTimeScaler, wss, css ) != 0 ||
4333 : apa_set_quality( hIvasDec->hTimeScaler, startQuality, 4, 4 ) != 0 ||
4334 : apa_set_renderer_granularity( hIvasDec->hTimeScaler, l_ts ) != 0 )
4335 : {
4336 0 : return IVAS_ERR_INIT_ERROR;
4337 : }
4338 :
4339 28 : IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
4340 : {
4341 0 : IF( apa_set_evs_compat_mode( hIvasDec->hTimeScaler, true ) != 0 )
4342 : {
4343 0 : return IVAS_ERR_INIT_ERROR;
4344 : }
4345 : }
4346 :
4347 28 : IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL )
4348 : {
4349 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
4350 : }
4351 :
4352 28 : set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) );
4353 : }
4354 : }
4355 : ELSE
4356 : {
4357 941 : IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
4358 : {
4359 941 : IF( apa_reconfigure( hIvasDec->hTimeScaler, nTransportChannels, l_ts ) != 0 )
4360 : {
4361 0 : return IVAS_ERR_INIT_ERROR;
4362 : }
4363 941 : apa_buffer_size = APA_BUF_PER_CHANNEL;
4364 941 : move16();
4365 941 : free( hIvasDec->apaExecBuffer_fx );
4366 941 : IF( ( hIvasDec->apaExecBuffer_fx = malloc( sizeof( Word32 ) * L_mult0( apa_buffer_size, (Word16) nTransportChannels ) ) ) == NULL )
4367 : {
4368 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
4369 : }
4370 941 : set_zero2_fx( hIvasDec->apaExecBuffer_fx, L_mult0( apa_buffer_size, (Word16) nTransportChannels ) );
4371 : }
4372 : /* realloc apa_exe_buffer */
4373 : }
4374 :
4375 969 : hIvasDec->nTransportChannelsOld = nTransportChannels;
4376 969 : move16();
4377 :
4378 969 : return IVAS_ERR_OK;
4379 : }
4380 :
4381 :
4382 : /*---------------------------------------------------------------------*
4383 : * IVAS_DEC_GetSplitRendBitstreamHeader()
4384 : *
4385 : *
4386 : *---------------------------------------------------------------------*/
4387 :
4388 0 : ivas_error IVAS_DEC_GetSplitRendBitstreamHeader(
4389 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
4390 : ISAR_SPLIT_REND_CODEC *pCodec, /* o : pointer to codec setting */
4391 : ISAR_SPLIT_REND_POSE_CORRECTION_MODE *poseCorrection, /* o : pointer to pose correction mode */
4392 : Word16 *pIsar_frame_size_ms, /* o : pointer to ISAR frame size setting */
4393 : Word16 *pCodec_frame_size_ms, /* o : pointer to codec frame size setting */
4394 : Word16 *pLc3plusHighRes )
4395 : {
4396 0 : test();
4397 0 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
4398 : {
4399 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
4400 : }
4401 :
4402 0 : *pCodec = hIvasDec->st_ivas->hRenderConfig->split_rend_config.codec;
4403 0 : *pCodec_frame_size_ms = hIvasDec->st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms;
4404 0 : *poseCorrection = hIvasDec->st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode;
4405 0 : *pIsar_frame_size_ms = hIvasDec->st_ivas->hRenderConfig->split_rend_config.isar_frame_size_ms;
4406 0 : *pLc3plusHighRes = hIvasDec->st_ivas->hRenderConfig->split_rend_config.lc3plus_highres;
4407 :
4408 0 : return IVAS_ERR_OK;
4409 : }
4410 :
4411 :
4412 : /*---------------------------------------------------------------------*
4413 : * IVAS_DEC_GetCldfbSamples()
4414 : *
4415 : * API function to output CLDFB samples
4416 : *---------------------------------------------------------------------*/
4417 :
4418 0 : ivas_error IVAS_DEC_GetCldfbSamples(
4419 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
4420 : Word32 *out_real, /* o : buffer for decoded PCM real output in CLDFB domain */
4421 : Word32 *out_imag, /* o : buffer for decoded PCM imag output in CLDFB domain */
4422 : AUDIO_CONFIG *audio_config, /* o : audio configuration */
4423 : Word16 *nOutSamples /* o : number of samples per channel written to output buffer */
4424 : )
4425 : {
4426 : ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend;
4427 : Word16 ch, b, slot_idx, num_chs, maxBand, num_samples;
4428 :
4429 0 : test();
4430 0 : test();
4431 0 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hSplitBinRend == NULL )
4432 : {
4433 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
4434 : }
4435 :
4436 0 : hSplitBinRend = hIvasDec->st_ivas->hSplitBinRend;
4437 0 : num_samples = 0;
4438 :
4439 0 : IF( hSplitBinRend->hCldfbDataOut != NULL )
4440 : {
4441 0 : *audio_config = hSplitBinRend->hCldfbDataOut->config;
4442 0 : IF( hSplitBinRend->hCldfbDataOut->config != IVAS_AUDIO_CONFIG_INVALID )
4443 : {
4444 0 : num_chs = audioCfg2channels( hSplitBinRend->hCldfbDataOut->config );
4445 0 : maxBand = (int16_t) ( ( CLDFB_NO_CHANNELS_MAX * hIvasDec->st_ivas->hDecoderConfig->output_Fs ) / 48000 );
4446 :
4447 0 : FOR( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX; slot_idx++ )
4448 : {
4449 0 : FOR( b = 0; b < maxBand; b++ )
4450 : {
4451 0 : FOR( ch = 0; ch < num_chs; ch++ )
4452 : {
4453 0 : *out_real++ = hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][slot_idx][b];
4454 0 : *out_imag++ = hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][slot_idx][b];
4455 : }
4456 : }
4457 : }
4458 0 : num_samples = CLDFB_NO_COL_MAX * maxBand;
4459 : }
4460 : }
4461 : ELSE
4462 : {
4463 0 : *audio_config = IVAS_AUDIO_CONFIG_INVALID;
4464 : }
4465 :
4466 0 : *nOutSamples = num_samples;
4467 :
4468 0 : return IVAS_ERR_OK;
4469 : }
4470 :
4471 :
4472 : /*-------------------------------------------------------------------*
4473 : * ivas_create_handle_isar()
4474 : *
4475 : * Initialize IVAS decoder split rend handle
4476 : *-------------------------------------------------------------------*/
4477 :
4478 0 : static ivas_error ivas_create_handle_isar(
4479 : ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend_out /* o : ISAR split binaural rendering handle */
4480 : )
4481 : {
4482 : ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend;
4483 :
4484 0 : if ( ( hSplitBinRend = (ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_WRAPPER ) ) ) == NULL )
4485 : {
4486 0 : return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" );
4487 : }
4488 :
4489 0 : isar_init_split_rend_handles( &hSplitBinRend->splitrend );
4490 :
4491 0 : hSplitBinRend->hMultiBinCldfbData = NULL;
4492 0 : hSplitBinRend->hCldfbDataOut = NULL;
4493 0 : hSplitBinRend->numTdSamplesPerChannelCached = 0;
4494 :
4495 0 : *hSplitBinRend_out = hSplitBinRend;
4496 :
4497 0 : return IVAS_ERR_OK;
4498 : }
4499 :
4500 :
4501 : /*-------------------------------------------------------------------*
4502 : * ivas_destroy_handle_isar()
4503 : *
4504 : * destroy IVAS decoder split rend handle
4505 : *-------------------------------------------------------------------*/
4506 :
4507 613 : static void ivas_destroy_handle_isar(
4508 : ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend /* i/o: ISAR split binaural rendering handle */
4509 : )
4510 : {
4511 613 : IF( *hSplitBinRend != NULL )
4512 : {
4513 0 : ISAR_PRE_REND_close( &( *hSplitBinRend )->splitrend, NULL );
4514 :
4515 0 : IF( ( *hSplitBinRend )->hCldfbDataOut != NULL )
4516 : {
4517 0 : free( ( *hSplitBinRend )->hCldfbDataOut );
4518 0 : ( *hSplitBinRend )->hCldfbDataOut = NULL;
4519 : }
4520 :
4521 0 : free( *hSplitBinRend );
4522 0 : *hSplitBinRend = NULL;
4523 : }
4524 :
4525 613 : return;
4526 : }
4527 :
4528 :
4529 : /*---------------------------------------------------------------------*
4530 : * IVAS_DEC_is_split_rendering_enabled()
4531 : *
4532 : *
4533 : *---------------------------------------------------------------------*/
4534 :
4535 1198 : int16_t IVAS_DEC_is_split_rendering_enabled(
4536 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
4537 : Word16 *isSplitRend /* o : flag to indicate if split rendering is enabled */
4538 : )
4539 : {
4540 : Decoder_Struct *st_ivas;
4541 :
4542 1198 : test();
4543 1198 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
4544 : {
4545 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
4546 : }
4547 :
4548 1198 : st_ivas = hIvasDec->st_ivas;
4549 :
4550 1198 : *isSplitRend = is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig );
4551 :
4552 1198 : return IVAS_ERR_OK;
4553 : }
4554 :
4555 :
4556 : /*-------------------------------------------------------------------*
4557 : * ivas_dec_reconfig_split_rend()
4558 : *
4559 : * IVAS decoder split rend reconfig
4560 : *-------------------------------------------------------------------*/
4561 :
4562 0 : static ivas_error ivas_dec_reconfig_split_rend(
4563 : Decoder_Struct *st_ivas /* i : IVAS decoder structure */
4564 : )
4565 : {
4566 : ivas_error error;
4567 : Word16 cldfb_in_flag, num_ch, ch, isCldfbNeeded, i, pcm_out_flag;
4568 : SPLIT_REND_WRAPPER *hSplitRendWrapper;
4569 :
4570 0 : hSplitRendWrapper = &st_ivas->hSplitBinRend->splitrend;
4571 0 : move16();
4572 0 : pcm_out_flag = ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0;
4573 0 : move16();
4574 0 : cldfb_in_flag = 0;
4575 0 : move16();
4576 :
4577 0 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
4578 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
4579 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ||
4580 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
4581 : {
4582 0 : cldfb_in_flag = 1;
4583 0 : move16();
4584 : }
4585 :
4586 0 : ISAR_PRE_REND_GetMultiBinPoseData( &st_ivas->hRenderConfig->split_rend_config, &hSplitRendWrapper->multiBinPoseData, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->sr_pose_pred_axis : DEFAULT_AXIS );
4587 :
4588 0 : isCldfbNeeded = 0;
4589 0 : move16();
4590 :
4591 0 : IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ||
4592 : ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) )
4593 : {
4594 0 : cldfb_in_flag = 0;
4595 0 : move16();
4596 : }
4597 :
4598 0 : IF( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) )
4599 : {
4600 0 : IF( EQ_16( cldfb_in_flag, 0 ) )
4601 : {
4602 0 : isCldfbNeeded = 1;
4603 0 : move16();
4604 : }
4605 0 : ELSE IF( EQ_16( st_ivas->hRenderConfig->split_rend_config.codec, ISAR_SPLIT_REND_CODEC_LC3PLUS ) && cldfb_in_flag )
4606 : {
4607 0 : isCldfbNeeded = 1;
4608 0 : move16();
4609 : }
4610 0 : ELSE IF( pcm_out_flag && cldfb_in_flag )
4611 : {
4612 0 : isCldfbNeeded = 1;
4613 0 : move16();
4614 : }
4615 : }
4616 0 : ELSE IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan )
4617 : {
4618 0 : isCldfbNeeded = 1;
4619 0 : move16();
4620 : }
4621 :
4622 0 : test();
4623 0 : IF( EQ_16( isCldfbNeeded, 1 ) && hSplitRendWrapper->hCldfbHandles == NULL )
4624 : {
4625 0 : IF( ( hSplitRendWrapper->hCldfbHandles = (CLDFB_HANDLES_WRAPPER_HANDLE) malloc( sizeof( CLDFB_HANDLES_WRAPPER ) ) ) == NULL )
4626 : {
4627 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB handles\n" ) );
4628 : }
4629 :
4630 0 : num_ch = i_mult( MAX_HEAD_ROT_POSES, BINAURAL_CHANNELS );
4631 0 : move16();
4632 0 : FOR( ch = 0; ch < num_ch; ch++ )
4633 : {
4634 0 : hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] = NULL;
4635 0 : move16();
4636 : }
4637 :
4638 0 : num_ch = i_mult( hSplitRendWrapper->multiBinPoseData.num_poses, BINAURAL_CHANNELS );
4639 0 : move16();
4640 :
4641 0 : FOR( ch = 0; ch < num_ch; ch++ )
4642 : {
4643 0 : IF( ( error = openCldfb_ivas_fx( &( hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] ), CLDFB_ANALYSIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS, DEC ) ) != IVAS_ERR_OK )
4644 : {
4645 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not open CLDFB handles\n" ) );
4646 : }
4647 : }
4648 :
4649 0 : FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
4650 : {
4651 0 : if ( ( error = openCldfb_ivas_fx( &( hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] ), CLDFB_SYNTHESIS, st_ivas->hDecoderConfig->output_Fs, CLDFB_PROTOTYPE_5_00MS, DEC ) ) != IVAS_ERR_OK )
4652 : {
4653 0 : return error;
4654 : }
4655 : }
4656 : }
4657 0 : ELSE IF( EQ_16( isCldfbNeeded, 0 ) && hSplitRendWrapper->hCldfbHandles != NULL )
4658 : {
4659 0 : num_ch = i_mult( MAX_HEAD_ROT_POSES, BINAURAL_CHANNELS );
4660 0 : move16();
4661 0 : FOR( ch = 0; ch < num_ch; ch++ )
4662 : {
4663 0 : IF( hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] != NULL )
4664 : {
4665 0 : deleteCldfb_ivas_fx( &hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] );
4666 0 : hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] = NULL;
4667 0 : move32();
4668 : }
4669 : }
4670 :
4671 0 : FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
4672 : {
4673 0 : IF( hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] != NULL )
4674 : {
4675 0 : deleteCldfb_ivas_fx( &hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] );
4676 0 : hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] = NULL;
4677 0 : move32();
4678 : }
4679 : }
4680 :
4681 0 : free( hSplitRendWrapper->hCldfbHandles );
4682 0 : hSplitRendWrapper->hCldfbHandles = NULL;
4683 0 : move32();
4684 : }
4685 :
4686 0 : IF( ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) &&
4687 : ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) &&
4688 : !( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) ) /* td-rend not needed? */
4689 : {
4690 0 : FOR( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i )
4691 : {
4692 0 : IF( st_ivas->hTdRendHandles[i] != NULL )
4693 : {
4694 0 : st_ivas->hTdRendHandles[i]->HrFiltSet_p = NULL;
4695 0 : move32();
4696 0 : ivas_td_binaural_close_fx( &st_ivas->hTdRendHandles[i] );
4697 : }
4698 : }
4699 : }
4700 :
4701 0 : return IVAS_ERR_OK;
4702 : }
4703 :
4704 :
4705 : /*-------------------------------------------------------------------*
4706 : * ivas_dec_init_split_rend()
4707 : *
4708 : * IVAS decoder split rendering initialization
4709 : *-------------------------------------------------------------------*/
4710 :
4711 0 : static ivas_error ivas_dec_init_split_rend(
4712 : Decoder_Struct *st_ivas /* i : IVAS decoder structure */
4713 : )
4714 : {
4715 : ivas_error error;
4716 : Word16 cldfb_in_flag, pcm_out_flag;
4717 : Word16 mixed_td_cldfb_flag;
4718 :
4719 0 : pcm_out_flag = ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0;
4720 0 : cldfb_in_flag = 0;
4721 0 : move16();
4722 :
4723 0 : IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
4724 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
4725 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ||
4726 : EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
4727 : {
4728 0 : cldfb_in_flag = 1;
4729 0 : move16();
4730 : }
4731 :
4732 0 : ISAR_PRE_REND_GetMultiBinPoseData( &st_ivas->hRenderConfig->split_rend_config, &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, ( st_ivas->hHeadTrackData != NULL ) ? st_ivas->hHeadTrackData->sr_pose_pred_axis : DEFAULT_AXIS );
4733 :
4734 0 : IF( EQ_16( cldfb_in_flag, 1 ) && ( EQ_16( st_ivas->hSplitBinRend->splitrend.multiBinPoseData.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) ) )
4735 : {
4736 0 : IF( ( st_ivas->hSplitBinRend->hCldfbDataOut = (ISAR_DEC_SPLIT_REND_CLDFB_OUT_DATA_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_CLDFB_OUT_DATA ) ) ) == NULL )
4737 : {
4738 0 : return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for cldfb data out buffer\n" ) );
4739 : }
4740 : }
4741 :
4742 0 : mixed_td_cldfb_flag = 0;
4743 0 : move16();
4744 0 : IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ||
4745 : ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) && EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_16( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) ) )
4746 : {
4747 0 : mixed_td_cldfb_flag = 1;
4748 0 : move16();
4749 : }
4750 :
4751 0 : error = ISAR_PRE_REND_open( &st_ivas->hSplitBinRend->splitrend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hDecoderConfig->output_Fs, cldfb_in_flag, pcm_out_flag, st_ivas->hDecoderConfig->render_framesize, mixed_td_cldfb_flag );
4752 0 : move16();
4753 :
4754 0 : return error;
4755 : }
4756 :
4757 :
4758 : /*---------------------------------------------------------------------*
4759 : * IVAS_DEC_is_split_rendering_coded_out()
4760 : *
4761 : *
4762 : *---------------------------------------------------------------------*/
4763 :
4764 1198 : Word16 IVAS_DEC_is_split_rendering_coded_out(
4765 : IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
4766 : int16_t *isSplitCoded /* o : flag to indicate if split rendering is enabled */
4767 : )
4768 : {
4769 : Decoder_Struct *st_ivas;
4770 :
4771 1198 : test();
4772 1198 : IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
4773 : {
4774 0 : return IVAS_ERR_UNEXPECTED_NULL_POINTER;
4775 : }
4776 :
4777 1198 : st_ivas = hIvasDec->st_ivas;
4778 1198 : *isSplitCoded = 0;
4779 1198 : move16();
4780 :
4781 1198 : test();
4782 1198 : test();
4783 1198 : test();
4784 1198 : IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ||
4785 : ( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_STEREO ) && st_ivas->hDecoderConfig->Opt_non_diegetic_pan && st_ivas->hRenderConfig->split_rend_config.dof == 0 ) )
4786 : {
4787 0 : *isSplitCoded = 1;
4788 0 : move16();
4789 : }
4790 :
4791 1198 : return IVAS_ERR_OK;
4792 : }
|