LCOV - code coverage report
Current view: top level - lib_dec - lib_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fa5c1457a864f30b71f903a41b38fb85641dc2f6 Lines: 1796 2655 67.6 %
Date: 2025-11-19 04:05:36 Functions: 70 93 75.3 %

          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 "ivas_cnst.h"
      35             : #include "ivas_prot_rend_fx.h"
      36             : #include "prot_fx.h"
      37             : #include "isar_prot.h"
      38             : #include "ivas_rom_com.h"
      39             : #include "lib_isar_pre_rend.h"
      40             : #include "ivas_prot_fx.h"
      41             : #include "jbm_jb4sb.h"
      42             : #include "jbm_pcmdsp_apa.h"
      43             : #include "jbm_pcmdsp_fifo.h"
      44             : #ifdef IVAS_RTPDUMP
      45             : #include "ivas_rtp_pi_data.h"
      46             : #endif
      47             : #include <math.h>
      48             : #include <assert.h>
      49             : #ifdef DEBUGGING
      50             : #include "float_to_fix_ops.h"
      51             : #endif
      52             : #include "wmc_auto.h"
      53             : 
      54             : 
      55             : /*---------------------------------------------------------------------*
      56             :  * Local structs
      57             :  *---------------------------------------------------------------------*/
      58             : 
      59             : struct IVAS_DEC_VOIP
      60             : {
      61             :     JB4_HANDLE hJBM;
      62             :     UWord16 lastDecodedWasActive;
      63             :     JB4_DATAUNIT_HANDLE hCurrentDataUnit; /* Points to the currently processed data unit */
      64             :     UWord16 *bs_conversion_buf;           /* Buffer for bitstream conversion from packed to serial */
      65             :     Word16 nSamplesRendered20ms;          /* how many samples have been rendered since the last 20ms render border*/
      66             : #ifdef SUPPORT_JBM_TRACEFILE
      67             :     IVAS_JBM_TRACE_DATA JbmTraceData;
      68             : #endif
      69             : };
      70             : 
      71             : typedef struct IVAS_DEC_VOIP IVAS_DEC_VOIP;
      72             : 
      73             : struct IVAS_DEC
      74             : {
      75             :     IVAS_DEC_MODE mode;
      76             :     UWord16 nSamplesFrame;
      77             :     Decoder_Struct *st_ivas;
      78             :     IVAS_DEC_VOIP *hVoIP;
      79             :     bool hasBeenFedFirstGoodFrame; /* False on init. Gets set to true after first good frame has been fed into the decoder, but not decoded yet.  */
      80             :     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 */
      81             :     bool isInitialized;
      82             : 
      83             :     Word16 bitstreamformat; /* Bitstream format flag (G.192/MIME/VOIP_G192_RTP/VOIP_RTPDUMP) */
      84             : #ifdef DEBUGGING
      85             :     bool Opt_VOIP; /* flag indicating VOIP mode with JBM */
      86             : #endif
      87             :     Word16 tsm_scale; /* scale for TSM operation */
      88             :     Word16 tsm_max_scaling;
      89             :     Word16 timeScalingDone; /* have we done already one TSM in a 20ms frame? */
      90             :     Word16 tsm_quality;     /*Q14*/
      91             :     PCMDSP_APA_HANDLE hTimeScaler;
      92             :     bool needNewFrame;
      93             :     bool hasBeenFedFrame;
      94             :     bool updateOrientation;
      95             :     UWord16 nSamplesAvailableNext;
      96             :     Word16 nTransportChannelsOld;
      97             :     Word16 amrwb_rfc4867_flag; /* MIME from rfc4867 is used */
      98             :     Word16 sdp_hf_only;        /* RTP payload format parameter: only Header-Full format without zero padding for size collision avoidance */
      99             :     Word16 prev_ft_speech;     /* RXDTX handler: previous frametype flag for  G.192 format AMRWB SID_FIRST detection */
     100             :     Word16 CNG;                /* RXDTX handler: CNG=1, nonCNG=0 */
     101             : 
     102             :     UWord16 nSamplesFlushed;
     103             :     Word16 *flushbuffer;
     104             :     bool hasBeenPreparedRendering;
     105             : };
     106             : 
     107             : 
     108             : /*---------------------------------------------------------------------*
     109             :  * Local function declarations
     110             :  *---------------------------------------------------------------------*/
     111             : 
     112             : static void ivas_destroy_handle_VoIP_fx( IVAS_DEC_VOIP *hVoIP );
     113             : #ifdef SUPPORT_JBM_TRACEFILE
     114             : static void store_JbmData( IVAS_DEC_VOIP *hVoIP, JB4_DATAUNIT_HANDLE dataUnit, const UWord32 systemTimestamp_ms, const UWord16 extBufferedSamples, const Word32 output_Fs );
     115             : #endif
     116             : static ivas_error evs_dec_main_fx( Decoder_Struct *st_ivas );
     117             : 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 );
     118             : static void init_decoder_config( DECODER_CONFIG_HANDLE hDecoderConfig );
     119             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
     120             : static ivas_error ivas_dec_setup_all( IVAS_DEC_HANDLE hIvasDec, UWord8 *nTransportChannels, ISAR_SPLIT_REND_BITS_DATA *splitRendBits );
     121             : #else
     122             : static ivas_error ivas_dec_setup_all( IVAS_DEC_HANDLE hIvasDec, UWord8 *nTransportChannels, const Word16 isSplitRend, ISAR_SPLIT_REND_BITS_DATA *splitRendBits );
     123             : #endif
     124             : static ivas_error apa_setup( IVAS_DEC_HANDLE hIvasDec, const bool isInitialized_voip, const UWord16 nTransportChannels );
     125             : 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 );
     126             : static ivas_error ivas_dec_reconfig_split_rend( Decoder_Struct *st_ivas );
     127             : static ivas_error ivas_dec_init_split_rend( Decoder_Struct *st_ivas );
     128             : static ivas_error ivas_create_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend_out );
     129             : static void ivas_destroy_handle_isar( ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend_out );
     130             : static Word16 get_render_frame_size_ms( IVAS_RENDER_FRAMESIZE render_framesize );
     131             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
     132             : static Word16 get_render_frame_size_samples( const DECODER_CONFIG_HANDLE hDecoderConfig );
     133             : static Word16 ivas_dec_split_rend_cldfb_in( const RENDERER_TYPE renderer_type );
     134             : #endif
     135             : static void update_voip_rendered20ms( IVAS_DEC_HANDLE hIvasDec, const Word16 nSamplesRendered );
     136             : 
     137             : 
     138             : /*---------------------------------------------------------------------*
     139             :  * IVAS_DEC_Open()
     140             :  *
     141             :  * Open IVAS decoder
     142             :  *---------------------------------------------------------------------*/
     143             : 
     144             : /* may return an error but may still have allocated memory - thus run Close also in case of error to release memory */
     145         645 : ivas_error IVAS_DEC_Open(
     146             :     IVAS_DEC_HANDLE *phIvasDec, /* i/o: pointer to an IVAS decoder handle to be opened  */
     147             :     const IVAS_DEC_MODE mode    /* i  : compatibility mode (EVS or IVAS)                */
     148             : )
     149             : {
     150             :     IVAS_DEC_HANDLE hIvasDec;
     151             :     Decoder_Struct *st_ivas;
     152             : 
     153         645 :     IF( phIvasDec == NULL )
     154             :     {
     155           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
     156             :     }
     157             : 
     158             :     /*-----------------------------------------------------------------*
     159             :      * Allocate and initialize IVAS application decoder handle
     160             :      *-----------------------------------------------------------------*/
     161             : 
     162         645 :     IF( ( *phIvasDec = (IVAS_DEC_HANDLE) malloc( sizeof( struct IVAS_DEC ) ) ) == NULL )
     163             :     {
     164           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" );
     165             :     }
     166             : 
     167         645 :     hIvasDec = *phIvasDec;
     168         645 :     hIvasDec->hVoIP = NULL;
     169         645 :     hIvasDec->hTimeScaler = NULL;
     170         645 :     hIvasDec->tsm_scale = 100;
     171         645 :     hIvasDec->tsm_max_scaling = 0;
     172         645 :     hIvasDec->tsm_quality = ONE_IN_Q14; /*1.f Q14*/
     173         645 :     hIvasDec->timeScalingDone = 0;
     174         645 :     hIvasDec->needNewFrame = false;
     175         645 :     hIvasDec->nTransportChannelsOld = 0;
     176         645 :     hIvasDec->nSamplesAvailableNext = 0;
     177         645 :     hIvasDec->nSamplesFrame = 0;
     178         645 :     hIvasDec->hasBeenFedFrame = false;
     179         645 :     hIvasDec->hasBeenFedFirstGoodFrame = false;
     180         645 :     hIvasDec->hasDecodedFirstGoodFrame = false;
     181         645 :     hIvasDec->isInitialized = false;
     182         645 :     hIvasDec->updateOrientation = false;
     183         645 :     move16();
     184         645 :     move16();
     185         645 :     move16();
     186         645 :     move16();
     187         645 :     move16();
     188         645 :     move16();
     189         645 :     move16();
     190         645 :     move16();
     191         645 :     move16();
     192         645 :     move16();
     193         645 :     move16();
     194         645 :     move16();
     195         645 :     move16();
     196         645 :     hIvasDec->flushbuffer = NULL;
     197         645 :     hIvasDec->nSamplesFlushed = 0;
     198         645 :     move16();
     199         645 :     hIvasDec->hasBeenPreparedRendering = false;
     200         645 :     move16();
     201             : 
     202         645 :     hIvasDec->mode = mode;
     203         645 :     move16();
     204             : 
     205         645 :     hIvasDec->bitstreamformat = G192;
     206         645 :     move16();
     207             : #ifdef DEBUGGING
     208             :     hIvasDec->Opt_VOIP = 0;
     209             :     move16();
     210             : #endif
     211         645 :     hIvasDec->amrwb_rfc4867_flag = -1;
     212         645 :     hIvasDec->prev_ft_speech = 1; /* RXDTX handler previous frametype flag for G.192 format AMRWB SID_FIRST detection */
     213         645 :     hIvasDec->CNG = 0;            /* RXDTX handler CNG = 1, no CNG = 0*/
     214         645 :     move16();
     215         645 :     move16();
     216         645 :     move16();
     217             : 
     218             :     /*-----------------------------------------------------------------*
     219             :      * Initialize IVAS-codec decoder state
     220             :      *-----------------------------------------------------------------*/
     221             : 
     222         645 :     IF( ( hIvasDec->st_ivas = (Decoder_Struct *) malloc( sizeof( Decoder_Struct ) ) ) == NULL )
     223             :     {
     224           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder structure" );
     225             :     }
     226             : 
     227         645 :     IF( ( hIvasDec->st_ivas->hDecoderConfig = (DECODER_CONFIG_HANDLE) malloc( sizeof( DECODER_CONFIG ) ) ) == NULL )
     228             :     {
     229           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for Decoder config structure" );
     230             :     }
     231             : 
     232             :     /*-----------------------------------------------------------------*
     233             :      * Initialize IVAS-codec decoder state
     234             :      *-----------------------------------------------------------------*/
     235             : 
     236         645 :     st_ivas = hIvasDec->st_ivas;
     237             : 
     238             :     /* initialize Decoder Config. handle */
     239         645 :     init_decoder_config( hIvasDec->st_ivas->hDecoderConfig );
     240             : 
     241             :     /* initialize pointers to handles to NULL */
     242         645 :     ivas_initialize_handles_dec( st_ivas );
     243             : 
     244             : #ifdef DECODER_FORMAT_SWITCHING
     245         645 :     st_ivas->restartNeeded = 0;
     246         645 :     move16();
     247             : #endif
     248             : 
     249             :     /* set high-level parameters */
     250         645 :     IF( EQ_16( mode, IVAS_DEC_MODE_EVS ) )
     251             :     {
     252           5 :         st_ivas->codec_mode = 0; /* unknown before first frame */
     253           5 :         st_ivas->element_mode_init = EVS_MONO;
     254           5 :         st_ivas->ivas_format = MONO_FORMAT;
     255           5 :         st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID;
     256           5 :         st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID;
     257           5 :         st_ivas->writeFECoffset = 0;
     258           5 :         hIvasDec->hasDecodedFirstGoodFrame = true; /* Functionality to suppress output for initial lost frames is disabled in EVS operation */
     259           5 :         move16();
     260           5 :         move16();
     261           5 :         move16();
     262           5 :         move16();
     263           5 :         move16();
     264           5 :         move16();
     265           5 :         move16();
     266             : 
     267           5 :         return IVAS_ERR_OK;
     268             :     }
     269         640 :     ELSE IF( EQ_16( mode, IVAS_DEC_MODE_IVAS ) )
     270             :     {
     271         640 :         st_ivas->codec_mode = 0; /* unknown before first frame */
     272         640 :         st_ivas->element_mode_init = -1;
     273         640 :         st_ivas->ivas_format = UNDEFINED_FORMAT;
     274         640 :         st_ivas->transport_config = IVAS_AUDIO_CONFIG_INVALID;
     275         640 :         st_ivas->intern_config = IVAS_AUDIO_CONFIG_INVALID;
     276         640 :         st_ivas->renderer_type = RENDERER_DISABLE;
     277         640 :         st_ivas->ini_frame = 0;
     278         640 :         st_ivas->ini_active_frame = 0;
     279         640 :         st_ivas->writeFECoffset = 0;
     280             : 
     281         640 :         st_ivas->ism_mode = ISM_MODE_NONE;
     282         640 :         st_ivas->mc_mode = MC_MODE_NONE;
     283             : 
     284         640 :         st_ivas->sba_order = 0;
     285         640 :         st_ivas->sba_planar = 0;
     286         640 :         st_ivas->sba_analysis_order = 0;
     287             : 
     288         640 :         move16();
     289         640 :         move16();
     290         640 :         move16();
     291         640 :         move16();
     292         640 :         move16();
     293         640 :         move16();
     294         640 :         move16();
     295         640 :         move16();
     296         640 :         move16();
     297         640 :         move16();
     298         640 :         move16();
     299         640 :         move16();
     300         640 :         move16();
     301         640 :         move16();
     302             : 
     303         640 :         return IVAS_ERR_OK;
     304             :     }
     305             : 
     306           0 :     return IVAS_ERR_WRONG_PARAMS;
     307             : }
     308             : 
     309             : 
     310             : /*-------------------------------------------------------------------------*
     311             :  * isar_set_split_rend_setup()
     312             :  *
     313             :  * Setup IVAS split rendering
     314             :  *-------------------------------------------------------------------------*/
     315             : 
     316           0 : static ivas_error isar_set_split_rend_setup(
     317             :     ISAR_DEC_SPLIT_REND_WRAPPER *hSplitBinRend,
     318             :     const ISAR_SPLIT_REND_CONFIG_DATA *hSplitBinConfig,
     319             :     const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,
     320             :     ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o  : output split rendering bits    */
     321             : )
     322             : {
     323           0 :     splitRendBits->bits_read = 0;
     324           0 :     splitRendBits->bits_written = 0;
     325           0 :     splitRendBits->buf_len = ISAR_MAX_SPLIT_REND_BITS_BUFFER_SIZE_IN_BYTES;
     326           0 :     splitRendBits->codec = ISAR_SPLIT_REND_CODEC_DEFAULT;
     327           0 :     splitRendBits->pose_correction = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE;
     328           0 :     splitRendBits->codec_frame_size_ms = 0;
     329           0 :     splitRendBits->isar_frame_size_ms = 0;
     330           0 :     splitRendBits->lc3plus_highres = 0;
     331           0 :     move16();
     332           0 :     move16();
     333           0 :     move16();
     334           0 :     move16();
     335           0 :     move16();
     336           0 :     move16();
     337           0 :     move16();
     338           0 :     move16();
     339             : 
     340             : #ifndef TMP_FIX_SPLIT_REND
     341             :     IF( ( hSplitBinRend->hMultiBinCldfbData = (ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA ) ) ) == NULL )
     342             :     {
     343             :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" );
     344             :     }
     345             : #endif
     346             : 
     347           0 :     ISAR_PRE_REND_GetMultiBinPoseData( hSplitBinConfig, &hSplitBinRend->splitrend.multiBinPoseData, ( hCombinedOrientationData != NULL ) ? hCombinedOrientationData->sr_pose_pred_axis : DEFAULT_AXIS );
     348             : 
     349           0 :     IF( hCombinedOrientationData != NULL )
     350             :     {
     351           0 :         isar_set_split_rend_ht_setup_fx( &hSplitBinRend->splitrend, hCombinedOrientationData->Quaternions, hCombinedOrientationData->Rmat_fx );
     352             :     }
     353             : 
     354           0 :     return IVAS_ERR_OK;
     355             : }
     356             : 
     357             : 
     358             : /*---------------------------------------------------------------------*
     359             :  * init_decoder_config()
     360             :  *
     361             :  * Initialize Decoder Config. handle
     362             :  *---------------------------------------------------------------------*/
     363             : 
     364         645 : static void init_decoder_config(
     365             :     DECODER_CONFIG_HANDLE hDecoderConfig /* i/o: configuration structure */
     366             : )
     367             : {
     368         645 :     hDecoderConfig->Opt_AMR_WB = 0;
     369         645 :     hDecoderConfig->nchan_out = 1;
     370         645 :     hDecoderConfig->output_config = IVAS_AUDIO_CONFIG_INVALID;
     371         645 :     hDecoderConfig->Opt_LsCustom = 0;
     372         645 :     hDecoderConfig->Opt_HRTF_binary = 0;
     373         645 :     hDecoderConfig->Opt_Headrotation = 0;
     374         645 :     hDecoderConfig->Opt_RendConfigCustom = 0;
     375             : #ifdef FIX_1318_ROOM_SIZE_CMD_LINE
     376         645 :     hDecoderConfig->Opt_RoomSize = IVAS_ROOM_SIZE_AUTO;
     377             : #endif
     378         645 :     hDecoderConfig->orientation_tracking = IVAS_HEAD_ORIENT_TRK_NONE;
     379         645 :     hDecoderConfig->Opt_non_diegetic_pan = 0;
     380         645 :     hDecoderConfig->non_diegetic_pan_gain_fx = 0; // Q15
     381         645 :     hDecoderConfig->Opt_tsm = 0;
     382         645 :     hDecoderConfig->Opt_delay_comp = 0;
     383         645 :     hDecoderConfig->Opt_ExternalOrientation = 0;
     384         645 :     hDecoderConfig->Opt_dpid_on = 0;
     385         645 :     hDecoderConfig->Opt_aeid_on = 0;
     386         645 :     hDecoderConfig->Opt_ObjEdit_on = 0;
     387         645 :     move16();
     388         645 :     move16();
     389         645 :     move16();
     390         645 :     move16();
     391         645 :     move16();
     392         645 :     move16();
     393         645 :     move16();
     394         645 :     move16();
     395         645 :     move16();
     396         645 :     move16();
     397         645 :     move16();
     398         645 :     move16();
     399         645 :     move16();
     400         645 :     move16();
     401         645 :     move16();
     402         645 :     move16();
     403             : 
     404         645 :     return;
     405             : }
     406             : 
     407             : 
     408             : /*---------------------------------------------------------------------*
     409             :  * IVAS_DEC_Close( )
     410             :  *
     411             :  * Deallocate IVAS decoder memory handles
     412             :  *---------------------------------------------------------------------*/
     413             : 
     414         645 : void IVAS_DEC_Close(
     415             :     IVAS_DEC_HANDLE *phIvasDec /* i/o: pointer to IVAS decoder handle   */
     416             : )
     417             : {
     418             :     /* Free all memory */
     419         645 :     test();
     420         645 :     IF( phIvasDec == NULL || *phIvasDec == NULL )
     421             :     {
     422           0 :         return;
     423             :     }
     424             : 
     425         645 :     IF( ( *phIvasDec )->hVoIP )
     426             :     {
     427          51 :         ivas_destroy_handle_VoIP_fx( ( *phIvasDec )->hVoIP );
     428          51 :         ( *phIvasDec )->hVoIP = NULL;
     429             :     }
     430             : 
     431         645 :     IF( ( *phIvasDec )->st_ivas )
     432             :     {
     433             :         /* destroy Split binaural renderer (ISAR) handle */
     434         645 :         ivas_destroy_handle_isar( &( *phIvasDec )->st_ivas->hSplitBinRend );
     435             : 
     436         645 :         ivas_destroy_dec_fx( ( *phIvasDec )->st_ivas );
     437         645 :         ( *phIvasDec )->st_ivas = NULL;
     438             :     }
     439             : 
     440         645 :     apa_exit( &( *phIvasDec )->hTimeScaler );
     441             : 
     442         645 :     IF( ( *phIvasDec )->flushbuffer != NULL )
     443             :     {
     444          51 :         free( ( *phIvasDec )->flushbuffer );
     445             :     }
     446             : 
     447         645 :     free( *phIvasDec );
     448         645 :     *phIvasDec = NULL;
     449         645 :     phIvasDec = NULL;
     450             : 
     451         645 :     return;
     452             : }
     453             : 
     454             : 
     455             : /*---------------------------------------------------------------------*
     456             :  * mapIvasFormat( )
     457             :  *
     458             :  *
     459             :  *---------------------------------------------------------------------*/
     460             : 
     461          52 : static IVAS_DEC_BS_FORMAT mapIvasFormat(
     462             :     const IVAS_FORMAT ivas_format )
     463             : {
     464          52 :     SWITCH( ivas_format )
     465             :     {
     466           0 :         case MONO_FORMAT:
     467           0 :             return IVAS_DEC_BS_MONO;
     468           2 :         case STEREO_FORMAT:
     469           2 :             return IVAS_DEC_BS_STEREO;
     470          15 :         case ISM_FORMAT:
     471          15 :             return IVAS_DEC_BS_OBJ;
     472           4 :         case MC_FORMAT:
     473           4 :             return IVAS_DEC_BS_MC;
     474           7 :         case SBA_FORMAT:
     475           7 :             return IVAS_DEC_BS_SBA;
     476           3 :         case SBA_ISM_FORMAT:
     477           3 :             return IVAS_DEC_BS_SBA_ISM;
     478          17 :         case MASA_FORMAT:
     479          17 :             return IVAS_DEC_BS_MASA;
     480           4 :         case MASA_ISM_FORMAT:
     481           4 :             return IVAS_DEC_BS_MASA_ISM;
     482           0 :         default:
     483           0 :             BREAK;
     484             :     }
     485             : 
     486           0 :     return IVAS_DEC_BS_UNKOWN;
     487             : }
     488             : 
     489             : 
     490             : /*---------------------------------------------------------------------*
     491             :  * create_flush_buffer()
     492             :  *
     493             :  * Create flush buffer - needed for binaural outputs with TSM or in VoIP mode
     494             :  *---------------------------------------------------------------------*/
     495             : 
     496          51 : static ivas_error create_flush_buffer_fx(
     497             :     IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle            */
     498             : )
     499             : {
     500          51 :     hIvasDec->flushbuffer = (Word16 *) malloc( CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( Word16 ) );
     501          51 :     if ( hIvasDec->flushbuffer == NULL )
     502             :     {
     503           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate JBM flush buffer" );
     504             :     }
     505             : 
     506          51 :     set16_fx( hIvasDec->flushbuffer, 0, CPE_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES );
     507             : 
     508          51 :     return IVAS_ERR_OK;
     509             : }
     510             : 
     511             : 
     512             : /*---------------------------------------------------------------------*
     513             :  * IVAS_DEC_Configure( )
     514             :  *
     515             :  * Decoder configuration
     516             :  * legacy behavior: if no output format set, then it's EVS mono
     517             :  *---------------------------------------------------------------------*/
     518             : 
     519         645 : ivas_error IVAS_DEC_Configure(
     520             :     IVAS_DEC_HANDLE hIvasDec,                          /* i/o: IVAS decoder handle                                 */
     521             :     const UWord32 sampleRate,                          /* i  : output sampling frequency                           */
     522             :     const IVAS_AUDIO_CONFIG outputConfig,              /* i  : output configuration                                */
     523             :     const IVAS_RENDER_FRAMESIZE renderFramesize,       /* i  : rendering frame size                                */
     524             :     const bool customLsOutputEnabled,                  /* i  : enable custom loudspeaker setup handle              */
     525             :     const bool hrtfReaderEnabled,                      /* i  : enable HRTF binary file input                       */
     526             :     const bool enableHeadRotation,                     /* i  : enable head rotation for binaural output            */
     527             :     const bool enableExternalOrientation,              /* i  : enable external orientations                        */
     528             :     const IVAS_HEAD_ORIENT_TRK_T orientation_tracking, /* i  : head orientation tracking type                      */
     529             :     const bool renderConfigEnabled,                    /* i  : enable Renderer config. file for binaural output    */
     530             : #ifdef FIX_1318_ROOM_SIZE_CMD_LINE
     531             :     const IVAS_ROOM_SIZE_T roomSize, /* i  : room size selector for reverb */
     532             : #endif
     533             :     const bool non_diegetic_pan_enabled,   /* i  : enabled diegetic panning                            */
     534             :     const Word16 non_diegetic_pan_gain_fx, /* i  : non diegetic panning gain                           */
     535             :     const bool dpidEnabled,                /* i  : enable directivity pattern option                   */
     536             :     const UWord16 acousticEnvironmentId,   /* i  : Acoustic environment ID                             */
     537             :     const bool objEditEnabled,             /* i  : enable object editing                               */
     538             :     const bool delayCompensationEnabled    /* i  : enable delay compensation                           */
     539             : )
     540             : {
     541             :     Decoder_Struct *st_ivas;
     542             :     DECODER_CONFIG_HANDLE hDecoderConfig;
     543             :     ivas_error error;
     544             : 
     545         645 :     test();
     546         645 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
     547             :     {
     548           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
     549             :     }
     550             : 
     551         645 :     test();
     552         645 :     test();
     553         645 :     test();
     554         645 :     IF( NE_32( sampleRate, 8000 ) && NE_32( sampleRate, 16000 ) && NE_32( sampleRate, 32000 ) && NE_32( sampleRate, 48000 ) )
     555             :     {
     556           0 :         return IVAS_ERR_WRONG_PARAMS;
     557             :     }
     558             : 
     559             : #ifdef FIX_1419_MONO_STEREO_UMX
     560         645 :     test();
     561         645 :     test();
     562         645 :     test();
     563         645 :     test();
     564         645 :     test();
     565         645 :     test();
     566         645 :     test();
     567         645 :     test();
     568         645 :     test();
     569         645 :     IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) &&
     570             :         ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_INVALID ) ||
     571             :           EQ_16( outputConfig, IVAS_AUDIO_CONFIG_ISM1 ) ||
     572             :           EQ_16( outputConfig, IVAS_AUDIO_CONFIG_ISM2 ) ||
     573             :           EQ_16( outputConfig, IVAS_AUDIO_CONFIG_ISM3 ) ||
     574             :           EQ_16( outputConfig, IVAS_AUDIO_CONFIG_ISM4 ) ||
     575             :           EQ_16( outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ||
     576             :           EQ_16( outputConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ||
     577             :           EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MASA1 ) ||
     578             :           EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MASA2 ) ) )
     579             : #else /* we now support all output formats, so this validation is redundant */
     580             :     test();
     581             :     test();
     582             :     test();
     583             :     test();
     584             :     IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) && !( ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_MONO ) && non_diegetic_pan_enabled == false ) ||
     585             :                                                          ( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_STEREO ) && non_diegetic_pan_enabled ) ) )
     586             : #endif
     587             :     {
     588           0 :         return IVAS_ERR_WRONG_MODE;
     589             :     }
     590             : 
     591         645 :     st_ivas = hIvasDec->st_ivas;
     592         645 :     hDecoderConfig = st_ivas->hDecoderConfig;
     593         645 :     hDecoderConfig->output_config = outputConfig;
     594         645 :     move16();
     595             : 
     596         645 :     IF( EQ_16( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_INVALID ) )
     597             :     {
     598           0 :         return IVAS_ERR_WRONG_PARAMS;
     599             :     }
     600             : 
     601         645 :     hDecoderConfig->output_Fs = sampleRate;
     602         645 :     move32();
     603         645 :     IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
     604             :     {
     605           5 :         st_ivas->element_mode_init = EVS_MONO;
     606           5 :         hDecoderConfig->nchan_out = 1;
     607           5 :         move16();
     608           5 :         move16();
     609             :     }
     610             : 
     611         645 :     test();
     612         645 :     IF( NE_16( outputConfig, IVAS_AUDIO_CONFIG_EXTERNAL ) && NE_16( outputConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
     613             :     {
     614         589 :         hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config );
     615         589 :         move16();
     616             :     }
     617             : 
     618         645 :     hDecoderConfig->Opt_LsCustom = (Word16) customLsOutputEnabled;
     619         645 :     hDecoderConfig->Opt_Headrotation = (Word16) enableHeadRotation;
     620         645 :     hDecoderConfig->orientation_tracking = orientation_tracking;
     621         645 :     hDecoderConfig->Opt_HRTF_binary = (Word16) hrtfReaderEnabled;
     622         645 :     hDecoderConfig->Opt_RendConfigCustom = (Word16) renderConfigEnabled;
     623             : #ifdef FIX_1318_ROOM_SIZE_CMD_LINE
     624         645 :     hDecoderConfig->Opt_RoomSize = roomSize;
     625             : #endif
     626         645 :     hDecoderConfig->Opt_non_diegetic_pan = (Word16) non_diegetic_pan_enabled;
     627         645 :     hDecoderConfig->non_diegetic_pan_gain_fx = non_diegetic_pan_gain_fx; // Q15
     628         645 :     hDecoderConfig->Opt_delay_comp = (Word16) delayCompensationEnabled;
     629         645 :     hDecoderConfig->Opt_ExternalOrientation = enableExternalOrientation;
     630         645 :     hDecoderConfig->Opt_dpid_on = (Word16) dpidEnabled;
     631             : #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT
     632         645 :     IF( NE_32( (UWord16) acousticEnvironmentId, IVAS_DEFAULT_AEID ) )
     633             : #else
     634             :     IF( NE_32( (Word32) acousticEnvironmentId, 65535 ) )
     635             : #endif
     636             :     {
     637           4 :         hDecoderConfig->Opt_aeid_on = TRUE;
     638             :     }
     639             :     ELSE
     640             :     {
     641         641 :         hDecoderConfig->Opt_aeid_on = FALSE;
     642             :     }
     643         645 :     hDecoderConfig->Opt_ObjEdit_on = (Word16) objEditEnabled;
     644         645 :     move16();
     645         645 :     move16();
     646         645 :     move16();
     647         645 :     move16();
     648         645 :     move16();
     649         645 :     move16();
     650         645 :     move16();
     651         645 :     move16();
     652         645 :     move16();
     653         645 :     move16();
     654         645 :     move16();
     655         645 :     move16();
     656             : 
     657         645 :     IF( EQ_16( renderFramesize, IVAS_RENDER_FRAMESIZE_UNKNOWN ) )
     658             :     {
     659           0 :         return IVAS_ERR_WRONG_PARAMS;
     660             :     }
     661             : 
     662         645 :     IF( EQ_16( outputConfig, IVAS_AUDIO_CONFIG_EXTERNAL ) )
     663             :     {
     664          53 :         hDecoderConfig->render_framesize = IVAS_RENDER_FRAMESIZE_20MS;
     665             :     }
     666             :     ELSE
     667             :     {
     668         592 :         hDecoderConfig->render_framesize = renderFramesize;
     669             :     }
     670         645 :     move16();
     671             : 
     672             :     /* Set decoder parameters to initial values */
     673         645 :     IF( NE_32( ( error = ivas_init_decoder_front( st_ivas ) ), IVAS_ERR_OK ) )
     674             :     {
     675           0 :         return error;
     676             :     }
     677             : 
     678             :     /* create ISAR handle */
     679         645 :     IF( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
     680             :     {
     681           0 :         IF( ( error = ivas_create_handle_isar( &st_ivas->hSplitBinRend ) ) != IVAS_ERR_OK )
     682             :         {
     683           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for ISAR handle" );
     684             :         }
     685             :     }
     686             : 
     687         645 :     if ( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
     688             :     {
     689           5 :         hIvasDec->st_ivas->ivas_format = MONO_FORMAT;
     690           5 :         move16();
     691             :     }
     692             : 
     693         645 :     hIvasDec->nSamplesFrame = (UWord16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FRAME_PER_SEC_Q15 );
     694             : 
     695         645 :     return IVAS_ERR_OK;
     696             : }
     697             : 
     698             : 
     699             : /*---------------------------------------------------------------------*
     700             :  * IVAS_DEC_EnableSplitRendering( )
     701             :  *
     702             :  * Update IVAS decoder config. if Split rendering is enabled
     703             :  *---------------------------------------------------------------------*/
     704             : 
     705           0 : ivas_error IVAS_DEC_EnableSplitRendering(
     706             :     IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle    */
     707             : )
     708             : {
     709             :     DECODER_CONFIG_HANDLE hDecoderConfig;
     710             : 
     711           0 :     test();
     712           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
     713             :     {
     714           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
     715             :     }
     716             : 
     717           0 :     hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;
     718           0 :     move32();
     719             : 
     720           0 :     hDecoderConfig->Opt_Headrotation = 1;
     721           0 :     move16();
     722           0 :     hDecoderConfig->render_framesize = IVAS_RENDER_FRAMESIZE_20MS;
     723           0 :     move32();
     724             : 
     725           0 :     return IVAS_ERR_OK;
     726             : }
     727             : 
     728             : 
     729             : /*---------------------------------------------------------------------*
     730             :  * get_render_framesize_ms( )
     731             :  *
     732             :  * Get render framesize in ms
     733             :  *---------------------------------------------------------------------*/
     734             : 
     735         265 : static Word16 get_render_frame_size_ms(
     736             :     const IVAS_RENDER_FRAMESIZE render_framesize )
     737             : {
     738         265 :     IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
     739             :     {
     740           0 :         return ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) );
     741             :     }
     742         265 :     ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
     743             :     {
     744           0 :         return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 1 );
     745             :     }
     746         265 :     ELSE IF( EQ_16( render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
     747             :     {
     748         265 :         return ( ( 1000 / ( FRAMES_PER_SEC * IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ) ) << 2 );
     749             :     }
     750             : 
     751           0 :     return 0;
     752             : }
     753             : 
     754             : 
     755             : /*---------------------------------------------------------------------*
     756             :  * IVAS_DEC_SetRenderFramesize( )
     757             :  *
     758             :  *  Set render framesize
     759             :  *---------------------------------------------------------------------*/
     760             : 
     761           0 : ivas_error IVAS_DEC_SetRenderFramesize(
     762             :     IVAS_DEC_HANDLE hIvasDec,                    /* i/o: IVAS decoder handle   */
     763             :     const IVAS_RENDER_FRAMESIZE render_framesize /* i  : render framesize      */
     764             : )
     765             : {
     766           0 :     test();
     767           0 :     test();
     768           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hDecoderConfig == NULL )
     769             :     {
     770           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
     771             :     }
     772             : 
     773           0 :     hIvasDec->st_ivas->hDecoderConfig->render_framesize = render_framesize;
     774           0 :     move16();
     775             : 
     776           0 :     IF( hIvasDec->st_ivas->hExtOrientationData != NULL )
     777             :     {
     778           0 :         hIvasDec->st_ivas->hExtOrientationData->num_subframes = (Word16) render_framesize;
     779           0 :         move16();
     780             :     }
     781             : 
     782           0 :     IF( hIvasDec->st_ivas->hCombinedOrientationData != NULL )
     783             :     {
     784           0 :         hIvasDec->st_ivas->hCombinedOrientationData->num_subframes = (Word16) render_framesize;
     785           0 :         move16();
     786             :     }
     787             : 
     788           0 :     return IVAS_ERR_OK;
     789             : }
     790             : 
     791             : 
     792             : /*---------------------------------------------------------------------*
     793             :  * IVAS_DEC_GetGetRenderFramesize( )
     794             :  *
     795             :  * Get render framesize
     796             :  *---------------------------------------------------------------------*/
     797             : 
     798         645 : ivas_error IVAS_DEC_GetRenderFramesize(
     799             :     IVAS_DEC_HANDLE hIvasDec,               /* i/o: IVAS decoder handle   */
     800             :     IVAS_RENDER_FRAMESIZE *render_framesize /* o  : render framesize      */
     801             : )
     802             : {
     803         645 :     test();
     804         645 :     test();
     805         645 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL )
     806             :     {
     807           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
     808             :     }
     809             : 
     810         645 :     *render_framesize = hIvasDec->st_ivas->hDecoderConfig->render_framesize;
     811         645 :     move16();
     812             : 
     813         645 :     return IVAS_ERR_OK;
     814             : }
     815             : 
     816             : 
     817             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
     818             : /*---------------------------------------------------------------------*
     819             :  * get_render_frame_size_samples( )
     820             :  *
     821             :  *
     822             :  *---------------------------------------------------------------------*/
     823             : 
     824         638 : static Word16 get_render_frame_size_samples(
     825             :     const DECODER_CONFIG_HANDLE hDecoderConfig /* i  : configuration structure */
     826             : )
     827             : {
     828             :     Word16 tmp;
     829         638 :     tmp = (Word16) Mpy_32_16_1( hDecoderConfig->output_Fs, INV_FR_P_S_MX_PRM_SPL_SBFR_Q15 );
     830             : 
     831         638 :     IF( EQ_16( hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
     832             :     {
     833             :         /* correct value already in tmp */
     834             :     }
     835         638 :     ELSE IF( EQ_16( hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
     836             :     {
     837           0 :         tmp = shl( tmp, 1 );
     838             :     }
     839         638 :     ELSE IF( EQ_16( hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
     840             :     {
     841         638 :         tmp = shl( tmp, 2 );
     842             :     }
     843             :     ELSE
     844             :     {
     845           0 :         tmp = 0;
     846             :     }
     847             : 
     848         638 :     return tmp;
     849             : }
     850             : #endif
     851             : 
     852             : 
     853             : /*---------------------------------------------------------------------*
     854             :  * IVAS_DEC_GetGetRenderFramesizeSamples( )
     855             :  *
     856             :  * Get render framesize in samples
     857             :  *---------------------------------------------------------------------*/
     858             : 
     859         638 : ivas_error IVAS_DEC_GetRenderFramesizeSamples(
     860             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle               */
     861             :     Word16 *render_framesize  /* o  : render framesize in samples Q0    */
     862             : )
     863             : {
     864             : #ifndef FIX_1119_SPLIT_RENDERING_VOIP
     865             :     Word16 tmp;
     866             : #endif
     867             : 
     868         638 :     test();
     869         638 :     test();
     870         638 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL )
     871             :     {
     872           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
     873             :     }
     874             : 
     875             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
     876         638 :     *render_framesize = get_render_frame_size_samples( hIvasDec->st_ivas->hDecoderConfig );
     877             : #else
     878             :     tmp = (Word16) Mpy_32_16_1( hIvasDec->st_ivas->hDecoderConfig->output_Fs, INV_FR_P_S_MX_PRM_SPL_SBFR_Q15 );
     879             : 
     880             :     IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
     881             :     {
     882             :         *render_framesize = tmp;
     883             :     }
     884             :     ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
     885             :     {
     886             :         *render_framesize = shl( tmp, 1 );
     887             :     }
     888             :     ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
     889             :     {
     890             :         *render_framesize = shl( tmp, 2 );
     891             :     }
     892             :     ELSE
     893             :     {
     894             :         *render_framesize = 0;
     895             :     }
     896             : #endif
     897         638 :     move16();
     898             : 
     899         638 :     return IVAS_ERR_OK;
     900             : }
     901             : 
     902             : 
     903             : /*---------------------------------------------------------------------*
     904             :  * IVAS_DEC_GetGetRenderFramesizeMs( )
     905             :  *
     906             :  * Get render framesize in milliseconds
     907             :  *---------------------------------------------------------------------*/
     908             : 
     909          44 : ivas_error IVAS_DEC_GetRenderFramesizeMs(
     910             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle               */
     911             :     UWord32 *render_framesize /* o  : render framesize in samples Q0    */
     912             : )
     913             : {
     914          44 :     test();
     915          44 :     test();
     916          44 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || render_framesize == NULL )
     917             :     {
     918           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
     919             :     }
     920             : 
     921          44 :     *render_framesize = get_render_frame_size_ms( hIvasDec->st_ivas->hDecoderConfig->render_framesize );
     922          44 :     move32();
     923             : 
     924          44 :     return IVAS_ERR_OK;
     925             : }
     926             : 
     927             : 
     928             : /*---------------------------------------------------------------------*
     929             :  * IVAS_DEC_GetGetReferencesUpdateFrequency( )
     930             :  *
     931             :  * Get update frequency of the reference vector/orientation
     932             :  *---------------------------------------------------------------------*/
     933             : 
     934         638 : ivas_error IVAS_DEC_GetReferencesUpdateFrequency(
     935             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle       */
     936             :     Word16 *update_frequency  /* o  : update frequency Q0       */
     937             : )
     938             : {
     939         638 :     test();
     940         638 :     test();
     941         638 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || update_frequency == NULL )
     942             :     {
     943           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
     944             :     }
     945             : 
     946         638 :     IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
     947             :     {
     948           0 :         *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES;
     949           0 :         move16();
     950             :     }
     951         638 :     ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_10MS ) )
     952             :     {
     953           0 :         *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 1;
     954           0 :         move16();
     955             :     }
     956         638 :     ELSE IF( EQ_16( hIvasDec->st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) )
     957             :     {
     958         638 :         *update_frequency = IVAS_MAX_PARAM_SPATIAL_SUBFRAMES >> 2;
     959         638 :         move16();
     960             :     }
     961             : 
     962         638 :     return IVAS_ERR_OK;
     963             : }
     964             : 
     965             : /*---------------------------------------------------------------------*
     966             :  * IVAS_DEC_GetGetNumOrientationSubframes( )
     967             :  *
     968             :  * Get the number of subframes for head/external orientation per render frame
     969             :  *---------------------------------------------------------------------*/
     970             : 
     971      508545 : ivas_error IVAS_DEC_GetNumOrientationSubframes(
     972             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle   */
     973             :     Word16 *num_subframes     /* o  : render framesize      */
     974             : )
     975             : {
     976      508545 :     test();
     977      508545 :     test();
     978      508545 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || num_subframes == NULL )
     979             :     {
     980           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
     981             :     }
     982             : 
     983      508545 :     *num_subframes = (Word16) hIvasDec->st_ivas->hDecoderConfig->render_framesize;
     984      508545 :     move16();
     985             : 
     986      508545 :     return IVAS_ERR_OK;
     987             : }
     988             : 
     989             : 
     990             : /*---------------------------------------------------------------------*
     991             :  * IVAS_DEC_EnableVoIP( )
     992             :  *
     993             :  * Intitialize JBM
     994             :  * jbmSafetyMargin: allowed delay reserve in addition to network jitter
     995             :  * to reduce late-loss, default: 60 [milliseconds]
     996             :  *---------------------------------------------------------------------*/
     997             : 
     998          51 : ivas_error IVAS_DEC_EnableVoIP(
     999             :     IVAS_DEC_HANDLE hIvasDec,               /* i/o: IVAS decoder handle                             */
    1000             :     const Word16 jbmSafetyMargin,           /* i  : allowed delay reserve for JBM, in milliseconds  */
    1001             :     const IVAS_DEC_INPUT_FORMAT inputFormat /* i  : format of the input bitstream                   */
    1002             : )
    1003             : {
    1004             :     DECODER_CONFIG_HANDLE hDecoderConfig;
    1005             :     ivas_error error;
    1006             : 
    1007          51 :     test();
    1008          51 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    1009             :     {
    1010           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    1011             :     }
    1012             : 
    1013          51 :     hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;
    1014             : 
    1015             : #ifdef DEBUGGING
    1016             :     hIvasDec->Opt_VOIP = 1;
    1017             : #endif
    1018          51 :     hDecoderConfig->Opt_tsm = 1;
    1019          51 :     move16();
    1020          51 :     move16();
    1021             : 
    1022          51 :     IF( NE_16( (Word16) hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
    1023             :     {
    1024          45 :         hDecoderConfig->nchan_out = audioCfg2channels( hDecoderConfig->output_config );
    1025          45 :         move16();
    1026             :     }
    1027             : 
    1028          51 :     IF( NE_32( ( error = input_format_API_to_internal( inputFormat, &hIvasDec->bitstreamformat, &hIvasDec->sdp_hf_only, true ) ), IVAS_ERR_OK ) )
    1029             :     {
    1030           0 :         return error;
    1031             :     }
    1032             : 
    1033          51 :     IF( ( hIvasDec->hVoIP = malloc( sizeof( IVAS_DEC_VOIP ) ) ) == NULL )
    1034             :     {
    1035           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
    1036             :     }
    1037             : 
    1038          51 :     hIvasDec->hVoIP->lastDecodedWasActive = 0;
    1039          51 :     move16();
    1040          51 :     hIvasDec->hVoIP->hCurrentDataUnit = NULL;
    1041          51 :     hIvasDec->hVoIP->nSamplesRendered20ms = 0;
    1042          51 :     move16();
    1043             : 
    1044             : #define WMC_TOOL_SKIP
    1045             :     /* Bitstream conversion is not counted towards complexity and memory usage */
    1046          51 :     hIvasDec->hVoIP->bs_conversion_buf = malloc( sizeof( UWord16 ) * ( MAX_BITS_PER_FRAME + 4 * 8 ) );
    1047             : #undef WMC_TOOL_SKIP
    1048             : 
    1049          51 :     IF( hIvasDec->hVoIP->bs_conversion_buf == NULL )
    1050             :     {
    1051           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate VoIP handle" );
    1052             :     }
    1053             : 
    1054             :     /* initialize JBM */
    1055          51 :     IF( NE_32( ( error = JB4_Create( &hIvasDec->hVoIP->hJBM ) != IVAS_ERR_OK ), IVAS_ERR_OK ) )
    1056             :     {
    1057           0 :         return error;
    1058             :     }
    1059             : 
    1060          51 :     IF( JB4_Init( hIvasDec->hVoIP->hJBM, jbmSafetyMargin ) != 0 )
    1061             :     {
    1062           0 :         return IVAS_ERR_FAILED_ALLOC;
    1063             :     }
    1064             : 
    1065             : #ifdef NONBE_1122_KEEP_EVS_MODE_UNCHANGED
    1066          51 :     if ( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
    1067             :     {
    1068           2 :         JB4_TMP_SetEvsCompatFlag( hIvasDec->hVoIP->hJBM );
    1069             :     }
    1070             : #endif
    1071             : 
    1072             :     /* init flush buffer (needed for binaural outputs) */
    1073          51 :     IF( ( error = create_flush_buffer_fx( hIvasDec ) ) != IVAS_ERR_OK )
    1074             :     {
    1075           0 :         fprintf( stderr, "\nError in create_flush_buffer , code: %d\n", error );
    1076           0 :         return error;
    1077             :     }
    1078             : 
    1079          51 :     return IVAS_ERR_OK;
    1080             : }
    1081             : 
    1082             : 
    1083             : /*---------------------------------------------------------------------*
    1084             :  * IVAS_DEC_FeedFrame_Serial( )
    1085             :  *
    1086             :  *
    1087             :  *---------------------------------------------------------------------*/
    1088             : 
    1089      507622 : ivas_error IVAS_DEC_FeedFrame_Serial(
    1090             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                   */
    1091             :     UWord16 *serial,          /* i  : buffer containing serial input bitstream. Each bit should be stored as a single uint16_t value  */
    1092             :     const UWord16 num_bits,   /* i  : number of bits in input bitstream     */
    1093             :     Word16 bfi                /* i  : bad frame indicator flag              */
    1094             : )
    1095             : {
    1096             :     ivas_error error;
    1097             : 
    1098             : #ifdef FIX_1388_MSAN_ivas_init_decoder
    1099      507622 :     test();
    1100      507622 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    1101             :     {
    1102           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    1103             :     }
    1104             : #endif
    1105             : 
    1106      507622 :     IF( !hIvasDec->isInitialized )
    1107             :     {
    1108             :         /* Once first frame is fed, finish initialization in EVS Mono.
    1109             :          * In IVAS mode, initialization is done in ivas_dec(). */
    1110         718 :         IF( EQ_16( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
    1111             :         {
    1112             : #ifdef FIX_1388_MSAN_ivas_init_decoder
    1113           5 :             hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = ACELP_8k00;
    1114           5 :             move32();
    1115             : 
    1116             : #endif
    1117           5 :             IF( NE_32( ( error = ivas_init_decoder_fx( hIvasDec->st_ivas ) ), IVAS_ERR_OK ) )
    1118             :             {
    1119           0 :                 return error;
    1120             :             }
    1121             : 
    1122           5 :             test();
    1123           5 :             IF( hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL )
    1124             :             {
    1125           0 :                 DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
    1126           0 :                 st->ini_frame = 0;
    1127           0 :                 st->prev_use_partial_copy = 0;
    1128           0 :                 move16();
    1129           0 :                 move16();
    1130           0 :                 hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = imult3216( hIvasDec->hVoIP->hCurrentDataUnit->dataSize, FRAMES_PER_SEC );
    1131           0 :                 move32();
    1132             :             }
    1133             : #ifndef FIX_1388_MSAN_ivas_init_decoder
    1134             :             ELSE
    1135             :             {
    1136             :                 hIvasDec->st_ivas->hDecoderConfig->ivas_total_brate = ACELP_8k00;
    1137             :                 move32();
    1138             :             }
    1139             : #endif
    1140             : 
    1141           5 :             hIvasDec->isInitialized = true;
    1142           5 :             move16();
    1143             :         }
    1144             :     }
    1145             : 
    1146      507622 :     if ( !bfi ) /* TODO(mcjbm): Is this ok for bfi == 2 (partial frame)? Is there enough info to fully configure decoder? */
    1147             :     {
    1148      494130 :         hIvasDec->hasBeenFedFirstGoodFrame = true;
    1149      494130 :         move16();
    1150             :     }
    1151             : 
    1152             :     /* Update redundant frame information in EVS (pre- read indices) */
    1153      507622 :     test();
    1154      507622 :     test();
    1155      507622 :     IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) && hIvasDec->hVoIP != NULL && hIvasDec->hVoIP->hCurrentDataUnit != NULL )
    1156             :     {
    1157        2050 :         DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
    1158        2050 :         st->bit_stream = serial;
    1159             : 
    1160        2050 :         test();
    1161        2050 :         IF( hIvasDec->hVoIP->hCurrentDataUnit->partial_frame || st->prev_use_partial_copy )
    1162             :         {
    1163           0 :             st->next_coder_type = hIvasDec->hVoIP->hCurrentDataUnit->nextCoderType;
    1164             :         }
    1165             :         ELSE
    1166             :         {
    1167        2050 :             st->next_coder_type = INACTIVE;
    1168             :         }
    1169        2050 :         move16();
    1170             : 
    1171        2050 :         test();
    1172        2050 :         if ( EQ_16( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame, 1 ) && NE_16( bfi, 1 ) )
    1173             :         {
    1174           0 :             bfi = 2;
    1175           0 :             move16();
    1176             :         }
    1177             :     }
    1178             : 
    1179      507622 :     IF( NE_32( ( error = read_indices_fx( hIvasDec->st_ivas, serial, num_bits, &hIvasDec->prev_ft_speech, &hIvasDec->CNG, bfi ) ), IVAS_ERR_OK ) )
    1180             :     {
    1181           0 :         return error;
    1182             :     }
    1183             : 
    1184             :     /* Update redundant frame information in EVS (post- read indices) */
    1185      507622 :     test();
    1186      507622 :     test();
    1187      507622 :     test();
    1188      507622 :     IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) &&
    1189             :         hIvasDec->hVoIP != NULL &&
    1190             :         hIvasDec->hVoIP->hCurrentDataUnit != NULL &&
    1191             :         ( (Word16) hIvasDec->hVoIP->hCurrentDataUnit->partial_frame != 0 ) )
    1192             :     {
    1193           0 :         DEC_CORE_HANDLE st = hIvasDec->st_ivas->hSCE[0]->hCoreCoder[0];
    1194           0 :         st->codec_mode = MODE2;
    1195           0 :         st->use_partial_copy = 1;
    1196           0 :         move16();
    1197           0 :         move16();
    1198             :     }
    1199             : 
    1200      507622 :     hIvasDec->needNewFrame = false;
    1201      507622 :     hIvasDec->hasBeenFedFrame = true;
    1202      507622 :     hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;
    1203      507622 :     move16();
    1204      507622 :     move16();
    1205      507622 :     move16();
    1206             : 
    1207      507622 :     return IVAS_ERR_OK;
    1208             : }
    1209             : 
    1210             : 
    1211             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    1212             : /*---------------------------------------------------------------------*
    1213             :  * isar_get_frame_size( )
    1214             :  *
    1215             :  *
    1216             :  *---------------------------------------------------------------------*/
    1217             : 
    1218           0 : static Word16 isar_get_frame_size(
    1219             :     Decoder_Struct *st_ivas /* i  : IVAS decoder handle */
    1220             : )
    1221             : {
    1222             :     Word32 output_Fs;
    1223             :     Word16 nSamplesPerChannel;
    1224             : 
    1225           0 :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
    1226             : 
    1227           0 :     test();
    1228           0 :     test();
    1229           0 :     IF( NE_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) &&
    1230             :         ( EQ_32( st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) ||
    1231             :           EQ_32( st_ivas->hRenderConfig->split_rend_config.dof, 0 ) ) )
    1232             :     {
    1233           0 :         nSamplesPerChannel = extract_l( ar_div( output_Fs, FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) );
    1234           0 :         nSamplesPerChannel = imult1616( nSamplesPerChannel, st_ivas->hDecoderConfig->render_framesize );
    1235             :     }
    1236             :     ELSE
    1237             :     {
    1238           0 :         nSamplesPerChannel = extract_l( ar_div( output_Fs, FRAMES_PER_SEC ) );
    1239             :     }
    1240             : 
    1241           0 :     return nSamplesPerChannel;
    1242             : }
    1243             : 
    1244             : 
    1245             : /*---------------------------------------------------------------------*
    1246             :  * isar_render_poses( )
    1247             :  *
    1248             :  *
    1249             :  *---------------------------------------------------------------------*/
    1250             : 
    1251           0 : static ivas_error isar_render_poses(
    1252             :     IVAS_DEC_HANDLE hIvasDec,   /* i/o: IVAS decoder handle                                        */
    1253             :     const Word16 nSamplesAsked, /* i  : number of samples wanted by the caller                     */
    1254             :     Word16 *nOutSamples,        /* o  : number of samples per channel written to output buffer     */
    1255             :     bool *needNewFrame          /* o  : indication that the decoder needs a new frame              */
    1256             : )
    1257             : {
    1258             : #ifndef FIX_1119_SPLIT_RENDERING_VOIP
    1259             :     // Note for reviewers: Code in this function was moved and adapted from IVAS_DEC_GetSplitBinauralBitstream,
    1260             :     //                     see #else branch of FIX_1119_SPLIT_RENDERING_VOIP there for reference
    1261             : #endif
    1262             :     Word16 pcmBuf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES * L_FRAME48k];
    1263             :     Decoder_Struct *st_ivas;
    1264             :     ivas_error error;
    1265             :     Word16 numPoses;
    1266             : 
    1267           0 :     test();
    1268           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    1269             :     {
    1270           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    1271             :     }
    1272             : 
    1273           0 :     *needNewFrame = false;
    1274           0 :     move16();
    1275             : 
    1276           0 :     st_ivas = hIvasDec->st_ivas;
    1277             : 
    1278           0 :     numPoses = st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses;
    1279           0 :     move16();
    1280             : 
    1281             :     /* init flush buffer for rate switch if not already initizalized */
    1282           0 :     IF( hIvasDec->flushbuffer == NULL )
    1283             :     {
    1284             :         /* hIvasDec->flushbuffer = (void *) malloc( sizeof( Word16 ) * numPoses * BINAURAL_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); */
    1285             :         /* set16_fx( (Word16 *) hIvasDec->flushbuffer, 0, numPoses * BINAURAL_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ); */
    1286             :         Word16 num_samples_flushbuffer;
    1287           0 :         num_samples_flushbuffer = mult0( mult0( numPoses, BINAURAL_CHANNELS ), shl( div_l( hIvasDec->nSamplesFrame, IVAS_MAX_PARAM_SPATIAL_SUBFRAMES ), 1 ) );
    1288           0 :         hIvasDec->flushbuffer = (void *) malloc( L_mult0( sizeof( Word16 ), num_samples_flushbuffer ) );
    1289           0 :         set16_fx( (Word16 *) hIvasDec->flushbuffer, 0, num_samples_flushbuffer );
    1290             :     }
    1291             : 
    1292             :     /* render */
    1293           0 :     IF( NE_32( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesAsked, pcmBuf, nOutSamples, needNewFrame ) ), IVAS_ERR_OK ) )
    1294             :     {
    1295           0 :         return error;
    1296             :     }
    1297             : 
    1298           0 :     IF( !hIvasDec->hasBeenFedFirstGoodFrame )
    1299             :     {
    1300           0 :         return IVAS_ERR_OK;
    1301             :     }
    1302             : 
    1303             :     /* NOTE: Here BASOP differs from the float version. In float, we push samples to TD ring buffer here. In BASOP, TD signals are only available in 16 bit here.
    1304             :      * To save TD signals in 32-bit precision, samples are pushed via ivas_TD_RINGBUF_PushChannels in ivas_jbm_dec_render_fx within IVAS_DEC_GetSamplesRenderer. */
    1305             : 
    1306           0 :     return error;
    1307             : }
    1308             : 
    1309             : 
    1310             : /*---------------------------------------------------------------------*
    1311             :  * isar_generate_metadata_and_bitstream( )
    1312             :  *
    1313             :  *
    1314             :  *---------------------------------------------------------------------*/
    1315             : 
    1316           0 : static ivas_error isar_generate_metadata_and_bitstream(
    1317             :     Decoder_Struct *st_ivas,                             /* i/o: IVAS decoder handle                */
    1318             :     Word32 **p_head_pose_buf,                            /* i/o: PCM buffer with head-pose data     */
    1319             :     Word16 nSamples,                                     /* i  : duration of audio (in samples per channel) for which metadata should be generated */
    1320             :     ISAR_SPLIT_REND_BITS_DATA *splitRendBits,            /* o  : output split rendering bits        */
    1321             :     Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS] /* o  : Q-format of each channel of p_head_pose_buf */
    1322             : )
    1323             : {
    1324             : #ifndef FIX_1119_SPLIT_RENDERING_VOIP
    1325             :     // Note for reviewers: Code in this function was moved and adapted from IVAS_DEC_GetSplitBinauralBitstream,
    1326             :     //                     see #else branch of FIX_1119_SPLIT_RENDERING_VOIP there for reference
    1327             : #endif
    1328             :     ivas_error error;
    1329             :     ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend;
    1330             :     Word16 max_band;
    1331             :     Word16 pcm_out_flag;
    1332             :     Word16 cldfb_in_flag;
    1333             :     Word16 ro_md_flag;
    1334             :     IVAS_QUATERNION Quaternion;
    1335             :     Word16 i, j, num_poses, num_cldfb_slots, n_samples_in_cldfb_slot;
    1336             :     Word32 *p_Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX];
    1337             :     Word32 *p_Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX];
    1338             : 
    1339           0 :     hSplitBinRend = st_ivas->hSplitBinRend;
    1340             : 
    1341           0 :     max_band = extract_l( ar_div( imult3216( st_ivas->hDecoderConfig->output_Fs, BINAURAL_MAXBANDS ), 48000 ) );
    1342           0 :     move16();
    1343           0 :     cldfb_in_flag = ivas_dec_split_rend_cldfb_in( st_ivas->renderer_type );
    1344           0 :     move16();
    1345           0 :     pcm_out_flag = 0;
    1346           0 :     move16();
    1347           0 :     if ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    1348             :     {
    1349           0 :         pcm_out_flag = 1;
    1350           0 :         move16();
    1351             :     }
    1352             : 
    1353           0 :     IF( cldfb_in_flag )
    1354             :     {
    1355           0 :         n_samples_in_cldfb_slot = NS2SA_FX2( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS );
    1356           0 :         assert( nSamples % n_samples_in_cldfb_slot == 0 );
    1357           0 :         num_cldfb_slots = int_div_s_x( nSamples, n_samples_in_cldfb_slot );
    1358             : 
    1359           0 :         num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;
    1360           0 :         move16();
    1361             : 
    1362           0 :         FOR( i = 0; i < imult1616( BINAURAL_CHANNELS, num_poses ); ++i )
    1363             :         {
    1364           0 :             FOR( j = 0; j < num_cldfb_slots; ++j )
    1365             :             {
    1366             :                 /* Save pointers to first CLDFB column in the ring buffer. Allows us to save
    1367             :                  * significant amounts of memory by not copying CLDFB values into a separate buffer. */
    1368           0 :                 ivas_CLDFB_RINGBUF_GetByIdx( hSplitBinRend->hMultiBinCldfbData[i], &p_Cldfb_RealBuffer_Binaural[i][j], &p_Cldfb_ImagBuffer_Binaural[i][j], 0 );
    1369             : 
    1370             :                 /* Pop the CLDFB column we just saved pointers to. This is fine as long as we use
    1371             :                  * the saved columns only before any new columns are pushed to the buffer - the new
    1372             :                  * columns could potentially overwrite the old columns we wanted to use.
    1373             :                  * This requirement is fulfilled in this case. */
    1374           0 :                 ivas_CLDFB_RINGBUF_Pop( hSplitBinRend->hMultiBinCldfbData[i], NULL, NULL, CLDFB_NO_CHANNELS_MAX );
    1375             :             }
    1376             :         }
    1377             :     }
    1378             :     ELSE
    1379             :     {
    1380           0 :         ivas_TD_RINGBUF_PopChannels( st_ivas->hSplitBinRend->hMultiBinTdData, p_head_pose_buf, nSamples );
    1381             : 
    1382           0 :         num_cldfb_slots = 0; // just to avoid compilation warning
    1383           0 :         num_poses = 0;       // just to avoid compilation warning
    1384           0 :         move16();
    1385           0 :         move16();
    1386             :     }
    1387             : 
    1388           0 :     IF( st_ivas->hBinRendererTd != NULL )
    1389             :     {
    1390           0 :         ro_md_flag = 1;
    1391           0 :         move16();
    1392             :     }
    1393             :     ELSE
    1394             :     {
    1395           0 :         ro_md_flag = 0;
    1396           0 :         move16();
    1397             :     }
    1398             : 
    1399           0 :     IF( st_ivas->hHeadTrackData != NULL )
    1400             :     {
    1401           0 :         Quaternion = st_ivas->hHeadTrackData->Quaternions[0];
    1402             :         /* Copy of a struct: 4x Word32 and 1x Word32 */
    1403           0 :         move32();
    1404           0 :         move32();
    1405           0 :         move32();
    1406           0 :         move32();
    1407           0 :         move16();
    1408             :     }
    1409             :     ELSE
    1410             :     {
    1411           0 :         Quaternion.w_fx = -12582912;
    1412           0 :         move32();
    1413           0 :         Quaternion.x_fx = 0;
    1414           0 :         move32();
    1415           0 :         Quaternion.y_fx = 0;
    1416           0 :         move32();
    1417           0 :         Quaternion.z_fx = 0;
    1418           0 :         move32();
    1419             :     }
    1420           0 :     Word16 q1 = 31, q2 = 31, Q_buff;
    1421           0 :     move32();
    1422           0 :     move32();
    1423           0 :     Q_out[0] = 31;
    1424           0 :     move32();
    1425             : 
    1426           0 :     IF( EQ_16( cldfb_in_flag, 1 ) )
    1427             :     {
    1428           0 :         FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, num_poses ); i++ )
    1429             :         {
    1430           0 :             FOR( j = 0; j < num_cldfb_slots; j++ )
    1431             :             {
    1432           0 :                 q1 = s_min( q1, L_norm_arr( p_Cldfb_RealBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX ) );
    1433           0 :                 q2 = s_min( q2, L_norm_arr( p_Cldfb_ImagBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX ) );
    1434             :             }
    1435             :         }
    1436           0 :         Q_buff = s_min( q1, q2 );
    1437           0 :         FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, num_poses ); i++ )
    1438             :         {
    1439           0 :             FOR( j = 0; j < num_cldfb_slots; j++ )
    1440             :             {
    1441           0 :                 scale_sig32( p_Cldfb_RealBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX, Q_buff );
    1442           0 :                 scale_sig32( p_Cldfb_ImagBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX, Q_buff );
    1443             :             }
    1444             :         }
    1445           0 :         Q_buff = add( Q_buff, Q6 );
    1446             :     }
    1447             :     ELSE
    1448             :     {
    1449             :         /*TD input*/
    1450             :         /*if CLDFB handles have been allocated then assume valid multi binaural input in out[][] buffer and perform CLDFB analysis*/
    1451           0 :         num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;
    1452           0 :         move16();
    1453             : 
    1454           0 :         FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i )
    1455             :         {
    1456           0 :             Q_out[0] = s_min( Q_out[0], L_norm_arr( p_head_pose_buf[i], L_FRAME48k ) );
    1457             :         }
    1458             : 
    1459           0 :         FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i )
    1460             :         {
    1461           0 :             scale_sig32( p_head_pose_buf[i], L_FRAME48k, Q_out[0] );
    1462             :         }
    1463           0 :         Q_out[0] = add( Q_out[0], Q11 );
    1464           0 :         Q_out[1] = Q_out[0];
    1465           0 :         move16();
    1466           0 :         Q_buff = Q31 + Q6; // likely unneeded
    1467           0 :         move16();
    1468             :     }
    1469             : 
    1470           0 :     IF( NE_32( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( &hSplitBinRend->splitrend,
    1471             :                                                                 Quaternion,
    1472             :                                                                 st_ivas->hRenderConfig->split_rend_config.splitRendBitRate,
    1473             :                                                                 st_ivas->hRenderConfig->split_rend_config.codec,
    1474             :                                                                 st_ivas->hRenderConfig->split_rend_config.isar_frame_size_ms,
    1475             :                                                                 st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms,
    1476             :                                                                 splitRendBits,
    1477             :                                                                 p_Cldfb_RealBuffer_Binaural,
    1478             :                                                                 p_Cldfb_ImagBuffer_Binaural,
    1479             :                                                                 max_band, p_head_pose_buf, 1, cldfb_in_flag, pcm_out_flag, ro_md_flag, Q_buff, &Q_out[0] ) ),
    1480             :                IVAS_ERR_OK ) )
    1481             :     {
    1482           0 :         return error;
    1483             :     }
    1484             : 
    1485           0 :     return IVAS_ERR_OK;
    1486             : }
    1487             : #endif /* FIX_1119_SPLIT_RENDERING_VOIP */
    1488             : 
    1489             : 
    1490             : /*---------------------------------------------------------------------*
    1491             :  * IVAS_DEC_GetSamplesRenderer( )
    1492             :  *
    1493             :  * Main function to render the decoded data to output data
    1494             :  *---------------------------------------------------------------------*/
    1495             : 
    1496      533218 : ivas_error IVAS_DEC_GetSamplesRenderer(
    1497             :     IVAS_DEC_HANDLE hIvasDec,   /* i/o: IVAS decoder handle                                                     */
    1498             :     const Word16 nSamplesAsked, /* i  : number of samples wanted by the caller                                  */
    1499             :     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 */
    1500             :     Word16 *nOutSamples,        /* o  : number of samples per channel written to output buffer                  */
    1501             :     bool *needNewFrame          /* o  :indication that the decoder needs a new frame                            */
    1502             : )
    1503             : {
    1504             :     ivas_error error;
    1505             :     UWord16 nSamplesRendered, nSamplesRendered_loop;
    1506             :     UWord8 nOutChannels;
    1507             :     Decoder_Struct *st_ivas;
    1508             : 
    1509      533218 :     nSamplesRendered = 0;
    1510      533218 :     nOutChannels = 0;
    1511      533218 :     nSamplesRendered_loop = 0;
    1512      533218 :     move16();
    1513      533218 :     move16();
    1514      533218 :     move16();
    1515             : 
    1516      533218 :     test();
    1517      533218 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    1518             :     {
    1519           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    1520             :     }
    1521             : 
    1522             :     /* the rendering needs to be prepared at this point */
    1523      533218 :     IF( hIvasDec->hasBeenPreparedRendering == false )
    1524             :     {
    1525           0 :         return IVAS_ERR_UNKNOWN;
    1526             :     }
    1527             : 
    1528      533218 :     st_ivas = hIvasDec->st_ivas;
    1529             : 
    1530      533218 :     IF( hIvasDec->updateOrientation )
    1531             :     {
    1532             :         /*----------------------------------------------------------------*
    1533             :          * Combine orientations
    1534             :          *----------------------------------------------------------------*/
    1535             : 
    1536       79306 :         IF( NE_32( ( error = combine_external_and_head_orientations_dec( st_ivas->hHeadTrackData, st_ivas->hExtOrientationData, st_ivas->hCombinedOrientationData ) ), IVAS_ERR_OK ) )
    1537             :         {
    1538           0 :             return error;
    1539             :         }
    1540             : 
    1541             :         /*----------------------------------------------------------------*
    1542             :          * Binaural split rendering setup
    1543             :          *----------------------------------------------------------------*/
    1544             : 
    1545       79306 :         IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    1546             :         {
    1547           0 :             IF( st_ivas->hCombinedOrientationData != NULL )
    1548             :             {
    1549           0 :                 isar_set_split_rend_ht_setup_fx( &st_ivas->hSplitBinRend->splitrend, st_ivas->hCombinedOrientationData->Quaternions, st_ivas->hCombinedOrientationData->Rmat_fx );
    1550             :             }
    1551             :         }
    1552             : 
    1553       79306 :         hIvasDec->updateOrientation = false;
    1554       79306 :         move16();
    1555             :     }
    1556             : 
    1557      533218 :     test();
    1558      533218 :     IF( !hIvasDec->hasBeenFedFrame && hIvasDec->nSamplesAvailableNext == 0 )
    1559             :     {
    1560             :         /* no frame was fed, do nothing but ask for a frame */
    1561           0 :         *needNewFrame = true;
    1562           0 :         *nOutSamples = 0;
    1563           0 :         hIvasDec->needNewFrame = true;
    1564           0 :         move16();
    1565           0 :         move16();
    1566           0 :         move16();
    1567             : 
    1568           0 :         return IVAS_ERR_OK;
    1569             :     }
    1570             : 
    1571             :     /* check if we are still at the beginning with bad frames, put out zeroes, keep track of subframes */
    1572      533218 :     test();
    1573      533218 :     IF( !hIvasDec->isInitialized && st_ivas->bfi )
    1574             :     {
    1575          80 :         hIvasDec->hasBeenFedFrame = false;
    1576          80 :         move16();
    1577          80 :         set16_fx( pcmBuf, 0, imult1616( st_ivas->hDecoderConfig->nchan_out, nSamplesAsked ) );
    1578          80 :         nSamplesRendered = nSamplesAsked;
    1579          80 :         move16();
    1580          80 :         hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesAsked );
    1581          80 :         move16();
    1582             :     }
    1583             :     ELSE
    1584             :     {
    1585      533138 :         nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out;
    1586      533138 :         hIvasDec->hasBeenFedFrame = false;
    1587             : 
    1588             :         /* check for possible flushed samples from a rate switch */
    1589             : #ifdef FIX_2174_JBM_BASOP_ALIGNMENT
    1590      533138 :         IF( GT_16( hIvasDec->nSamplesFlushed, 0 ) )
    1591             : #else
    1592             :         IF( GE_16( hIvasDec->nSamplesFlushed, 0 ) )
    1593             : #endif
    1594             :         {
    1595             :             /* note: offset (rendered samples) is always 0 */
    1596         270 :             Copy( hIvasDec->flushbuffer, pcmBuf, imult1616( hIvasDec->nSamplesFlushed, nOutChannels ) );
    1597             : 
    1598         270 :             nSamplesRendered = hIvasDec->nSamplesFlushed;
    1599         270 :             hIvasDec->nSamplesFlushed = 0;
    1600         270 :             move16();
    1601         270 :             move16();
    1602             :         }
    1603             : 
    1604             :         /* render IVAS frames directly to the output buffer */
    1605      533138 :         IF( ( error = ivas_jbm_dec_render_fx( st_ivas, sub( nSamplesAsked, nSamplesRendered ), &nSamplesRendered_loop, &hIvasDec->nSamplesAvailableNext, pcmBuf + imult3216( nSamplesRendered, nOutChannels ) ) ) != IVAS_ERR_OK )
    1606             :         {
    1607           0 :             return error;
    1608             :         }
    1609             : 
    1610      533138 :         nSamplesRendered = add( nSamplesRendered, nSamplesRendered_loop );
    1611             :     }
    1612             : 
    1613      533218 :     IF( hIvasDec->nSamplesAvailableNext == 0 )
    1614             :     {
    1615      507589 :         *needNewFrame = true;
    1616      507589 :         move16();
    1617      507589 :         hIvasDec->needNewFrame = true;
    1618      507589 :         move16();
    1619             :     }
    1620             :     ELSE
    1621             :     {
    1622       25629 :         *needNewFrame = false;
    1623       25629 :         move16();
    1624             :     }
    1625             : 
    1626      533218 :     *nOutSamples = nSamplesRendered;
    1627      533218 :     move16();
    1628             : 
    1629      533218 :     return IVAS_ERR_OK;
    1630             : }
    1631             : 
    1632             : 
    1633             : /*---------------------------------------------------------------------*
    1634             :  * IVAS_DEC_GetSplitBinauralBitstream( )
    1635             :  *
    1636             :  * Get split-rendering bitstream
    1637             :  *---------------------------------------------------------------------*/
    1638             : 
    1639           0 : ivas_error IVAS_DEC_GetSplitBinauralBitstream(
    1640             :     IVAS_DEC_HANDLE hIvasDec,                 /* i/o: IVAS decoder handle                                       */
    1641             :     Word16 *pcmBuf_out,                       /* o  : output synthesis signal for BINAURAL_SPLIT_PCM            */
    1642             :     ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o  : output split rendering bits                               */
    1643             :     Word16 *nOutSamples,                      /* o  : number of samples per channel written to output buffer    */
    1644             :     bool *needNewFrame                        /* o  : indication that the decoder needs a new frame             */
    1645             : )
    1646             : {
    1647             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    1648             :     Decoder_Struct *st_ivas;
    1649             :     ivas_error error;
    1650             :     Word32 head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k];
    1651             :     Word32 *p_head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES];
    1652             :     Word16 i;
    1653             :     Word16 pcm_out_flag;
    1654             :     Word16 numSamplesPerChannelToOutput;
    1655             :     Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS];
    1656             : 
    1657           0 :     test();
    1658           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    1659             :     {
    1660           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    1661             :     }
    1662             : 
    1663           0 :     st_ivas = hIvasDec->st_ivas;
    1664             : 
    1665           0 :     IF( EQ_16( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ), 0 ) )
    1666             :     {
    1667           0 :         return IVAS_ERR_WRONG_PARAMS;
    1668             :     }
    1669             : 
    1670           0 :     numSamplesPerChannelToOutput = isar_get_frame_size( st_ivas );
    1671           0 :     move16();
    1672           0 :     pcm_out_flag = 0;
    1673           0 :     move16();
    1674           0 :     if ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    1675             :     {
    1676           0 :         pcm_out_flag = 1;
    1677           0 :         move16();
    1678             :     }
    1679             : 
    1680           0 :     IF( NE_32( ( error = isar_render_poses( hIvasDec, numSamplesPerChannelToOutput, nOutSamples, needNewFrame ) ), IVAS_ERR_OK ) )
    1681             :     {
    1682           0 :         return error;
    1683             :     }
    1684             : 
    1685           0 :     IF( !hIvasDec->hasBeenFedFirstGoodFrame )
    1686             :     {
    1687           0 :         return IVAS_ERR_OK;
    1688             :     }
    1689             : 
    1690           0 :     FOR( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i )
    1691             :     {
    1692           0 :         p_head_pose_buf[i] = head_pose_buf[i];
    1693             :     }
    1694             : 
    1695           0 :     IF( NE_32( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nOutSamples, splitRendBits, Q_out ) ), IVAS_ERR_OK ) )
    1696             :     {
    1697           0 :         return error;
    1698             :     }
    1699             : 
    1700             :     /* convert to int16 with limiting for BINAURAL_SPLIT_PCM */
    1701           0 :     IF( pcm_out_flag )
    1702             :     {
    1703           0 :         FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
    1704             :         {
    1705           0 :             scale_sig32( p_head_pose_buf[i], numSamplesPerChannelToOutput, sub( Q11, Q_out[i] ) ); // Q11
    1706             :         }
    1707           0 :         IF( EQ_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
    1708             :         {
    1709             : #ifndef DISABLE_LIMITER
    1710           0 :             ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToOutput, st_ivas->BER_detect, Q11 );
    1711             : #endif
    1712             :         }
    1713             :         ELSE
    1714             :         {
    1715           0 :             ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToOutput, st_ivas->BER_detect, Q11 );
    1716             :         }
    1717             : 
    1718           0 :         ivas_syn_output_fx( p_head_pose_buf, Q11, numSamplesPerChannelToOutput, st_ivas->hDecoderConfig->nchan_out, pcmBuf_out );
    1719             :     }
    1720             : #else
    1721             :     Decoder_Struct *st_ivas;
    1722             :     AUDIO_CONFIG output_config;
    1723             :     Word32 output_Fs;
    1724             :     Word32 *pOutput[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES];
    1725             :     Word32 Cldfb_RealBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1726             :     Word32 Cldfb_ImagBuffer_Binaural[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS][CLDFB_NO_COL_MAX][CLDFB_NO_CHANNELS_MAX];
    1727             :     Word16 numSamplesPerChannelToDecode;
    1728             :     Word16 i, j, k;
    1729             :     ivas_error error;
    1730             :     ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend;
    1731             :     Word16 max_band;
    1732             :     Word16 pcm_out_flag;
    1733             :     Word16 td_input;
    1734             :     Word16 numPoses;
    1735             :     Word16 slots_rendered, slots_rendered_new;
    1736             :     Word16 ro_md_flag;
    1737             :     IVAS_QUATERNION Quaternion;
    1738             : 
    1739             :     test();
    1740             :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    1741             :     {
    1742             :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    1743             :     }
    1744             : 
    1745             :     st_ivas = hIvasDec->st_ivas;
    1746             :     output_config = st_ivas->hDecoderConfig->output_config;
    1747             :     output_Fs = st_ivas->hDecoderConfig->output_Fs;
    1748             :     numSamplesPerChannelToDecode = (Word16) ( output_Fs / FRAMES_PER_SEC ); // TODO remove division
    1749             : 
    1750             :     *needNewFrame = false;
    1751             :     hSplitBinRend = st_ivas->hSplitBinRend;
    1752             : 
    1753             :     FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; i++ )
    1754             :     {
    1755             :         FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ )
    1756             :         {
    1757             :             FOR( k = 0; k < CLDFB_NO_CHANNELS_MAX; k++ )
    1758             :             {
    1759             :                 Cldfb_RealBuffer_Binaural[i][j][k] = 0;
    1760             :                 Cldfb_ImagBuffer_Binaural[i][j][k] = 0;
    1761             :                 move32();
    1762             :                 move32();
    1763             :             }
    1764             :         }
    1765             :     }
    1766             : 
    1767             :     FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; i++ )
    1768             :     {
    1769             :         FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ )
    1770             :         {
    1771             :             set32_fx( hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
    1772             :             set32_fx( hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[i][j], 0, CLDFB_NO_CHANNELS_MAX );
    1773             :         }
    1774             :     }
    1775             : 
    1776             :     numPoses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;
    1777             :     move16();
    1778             : 
    1779             :     /* init flush buffer for rate switch if not already initizalized */
    1780             :     IF( hIvasDec->flushbuffer == NULL )
    1781             :     {
    1782             :         hIvasDec->flushbuffer = (void *) malloc( numPoses * BINAURAL_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( float ) );
    1783             :         set16_fx( (Word16 *) hIvasDec->flushbuffer, 0, numPoses * BINAURAL_CHANNELS * hIvasDec->nSamplesFrame / IVAS_MAX_PARAM_SPATIAL_SUBFRAMES );
    1784             :     }
    1785             : 
    1786             :     IF( NE_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_20MS ) &&
    1787             :         ( EQ_32( st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) ||
    1788             :           EQ_16( st_ivas->hRenderConfig->split_rend_config.dof, 0 ) ) )
    1789             :     {
    1790             :         numSamplesPerChannelToDecode = (Word16) ( output_Fs / FRAMES_PER_SEC );                                 // TODO remove division
    1791             :         numSamplesPerChannelToDecode = (Word16) ( numSamplesPerChannelToDecode / MAX_PARAM_SPATIAL_SUBFRAMES ); // TODO remove division
    1792             :         numSamplesPerChannelToDecode *= (Word16) st_ivas->hDecoderConfig->render_framesize;
    1793             :         move16();
    1794             :         move16();
    1795             :     }
    1796             : 
    1797             :     IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig ) == 0 )
    1798             :     {
    1799             :         return IVAS_ERR_WRONG_PARAMS;
    1800             :     }
    1801             : 
    1802             :     test();
    1803             :     IF( st_ivas->hTcBuffer == NULL || hIvasDec->hasBeenFedFrame )
    1804             :     {
    1805             :         slots_rendered = 0;
    1806             :     }
    1807             :     ELSE
    1808             :     {
    1809             :         /* this is needed for OMASA-DISC, because the td-rend granularity is 240 samples at 48kHz, leading to wrong slot count. */
    1810             :         test();
    1811             :         IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
    1812             :         {
    1813             :             slots_rendered = st_ivas->hTcBuffer->n_samples_rendered / NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // TODO remove division
    1814             :         }
    1815             :         ELSE
    1816             :         {
    1817             :             slots_rendered = st_ivas->hTcBuffer->n_samples_rendered / st_ivas->hTcBuffer->n_samples_granularity;
    1818             :         }
    1819             :     }
    1820             : 
    1821             :     /* Decode and render */
    1822             :     IF( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, numSamplesPerChannelToDecode, pcmBuf_out, nOutSamples, needNewFrame ) ) != IVAS_ERR_OK )
    1823             :     {
    1824             :         return error;
    1825             :     }
    1826             : 
    1827             :     IF( !hIvasDec->hasBeenFedFirstGoodFrame )
    1828             :     {
    1829             :         return IVAS_ERR_OK;
    1830             :     }
    1831             : 
    1832             :     FOR( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i )
    1833             :     {
    1834             :         pOutput[i] = hSplitBinRend->hMultiBinCldfbData->output_fx[i];
    1835             :         move32();
    1836             :     }
    1837             : 
    1838             :     IF( st_ivas->hTcBuffer == NULL )
    1839             :     {
    1840             :         slots_rendered_new = 0;
    1841             :         move16();
    1842             :     }
    1843             :     ELSE
    1844             :     {
    1845             :         /* this is needed for OMASA-DISC, because the td-rend granularity is 240 samples at 48kHz, leading to wrong slot count. */
    1846             :         IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) )
    1847             :         {
    1848             :             slots_rendered_new = st_ivas->hTcBuffer->n_samples_rendered / NS2SA( st_ivas->hDecoderConfig->output_Fs, CLDFB_SLOT_NS ); // TODO remove division
    1849             :         }
    1850             :         ELSE
    1851             :         {
    1852             :             slots_rendered_new = st_ivas->hTcBuffer->n_samples_rendered / st_ivas->hTcBuffer->n_samples_granularity; // TODO remove division
    1853             :         }
    1854             :     }
    1855             : 
    1856             :     FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, numPoses ); ++i )
    1857             :     {
    1858             :         FOR( j = slots_rendered; j < slots_rendered_new; ++j )
    1859             :         {
    1860             :             Copy32( hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[i][j], Cldfb_RealBuffer_Binaural[i][j - slots_rendered], CLDFB_NO_CHANNELS_MAX );
    1861             :             Copy32( hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[i][j], Cldfb_ImagBuffer_Binaural[i][j - slots_rendered], CLDFB_NO_CHANNELS_MAX );
    1862             :         }
    1863             :     }
    1864             : 
    1865             :     max_band = (Word16) ( ( BINAURAL_MAXBANDS * output_Fs ) / 48000 ); // TODO remove division
    1866             :     move16();
    1867             :     pcm_out_flag = ( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0;
    1868             :     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;
    1869             : 
    1870             :     IF( st_ivas->hBinRendererTd != NULL )
    1871             :     {
    1872             :         ro_md_flag = 1;
    1873             :         move16();
    1874             :     }
    1875             :     ELSE
    1876             :     {
    1877             :         ro_md_flag = 0;
    1878             :         move16();
    1879             :     }
    1880             : 
    1881             :     IF( st_ivas->hHeadTrackData != NULL )
    1882             :     {
    1883             :         Quaternion = st_ivas->hHeadTrackData->Quaternions[0];
    1884             :     }
    1885             :     ELSE
    1886             :     {
    1887             :         Quaternion.w_fx = -12582912;
    1888             :         Quaternion.x_fx = 0;
    1889             :         Quaternion.y_fx = 0;
    1890             :         Quaternion.z_fx = 0;
    1891             :     }
    1892             :     Word16 q1 = 31, q2 = 31, Q_buff;
    1893             :     Word16 Q_out[CLDFB_NO_COL_MAX];
    1894             :     Q_out[0] = 31;
    1895             :     Word16 num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;
    1896             : 
    1897             :     FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, numPoses ); i++ )
    1898             :     {
    1899             :         FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ )
    1900             :         {
    1901             :             q1 = s_min( q1, L_norm_arr( Cldfb_RealBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX ) );
    1902             :             q2 = s_min( q2, L_norm_arr( Cldfb_ImagBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX ) );
    1903             :         }
    1904             :     }
    1905             :     Q_buff = s_min( q1, q2 );
    1906             :     FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, numPoses ); i++ )
    1907             :     {
    1908             :         FOR( j = 0; j < CLDFB_NO_COL_MAX; j++ )
    1909             :         {
    1910             :             scale_sig32( Cldfb_RealBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX, Q_buff );
    1911             :             scale_sig32( Cldfb_ImagBuffer_Binaural[i][j], CLDFB_NO_CHANNELS_MAX, Q_buff );
    1912             :         }
    1913             :     }
    1914             :     Q_buff = add( Q_buff, Q6 );
    1915             : 
    1916             :     IF( NE_16( td_input, 0 ) )
    1917             :     {
    1918             :         /*TD input*/
    1919             :         /*if CLDFB handles have been allocated then assume valid multi binaural input in out[][] buffer and perform CLDFB analysis*/
    1920             :         /* local float2fix, to be removed */
    1921             :         num_poses = hSplitBinRend->splitrend.multiBinPoseData.num_poses;
    1922             : 
    1923             :         FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i )
    1924             :         {
    1925             :             Q_out[0] = s_min( Q_out[0], L_norm_arr( pOutput[i], L_FRAME48k ) );
    1926             :         }
    1927             : 
    1928             :         FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i )
    1929             :         {
    1930             :             scale_sig32( pOutput[i], L_FRAME48k, Q_out[0] );
    1931             :         }
    1932             :         Q_out[0] = add( Q_out[0], Q11 );
    1933             :         Q_out[1] = Q_out[0];
    1934             :     }
    1935             : 
    1936             :     IF( ( error = ISAR_PRE_REND_MultiBinToSplitBinaural( &hSplitBinRend->splitrend,
    1937             :                                                          Quaternion,
    1938             :                                                          st_ivas->hRenderConfig->split_rend_config.splitRendBitRate,
    1939             :                                                          st_ivas->hRenderConfig->split_rend_config.codec,
    1940             :                                                          st_ivas->hRenderConfig->split_rend_config.isar_frame_size_ms,
    1941             :                                                          st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms,
    1942             :                                                          splitRendBits,
    1943             :                                                          Cldfb_RealBuffer_Binaural,
    1944             :                                                          Cldfb_ImagBuffer_Binaural,
    1945             :                                                          max_band, pOutput, 1, !td_input, pcm_out_flag, ro_md_flag, Q_buff, &Q_out[0] ) ) != IVAS_ERR_OK )
    1946             :     {
    1947             :         return error;
    1948             :     }
    1949             : 
    1950             :     /* convert to int16 with limiting for BINAURAL_SPLIT_PCM */
    1951             :     IF( pcm_out_flag )
    1952             :     {
    1953             :         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1954             :         {
    1955             :             scale_sig32( pOutput[j], numSamplesPerChannelToDecode, sub( Q11, Q_out[j] ) ); // Q11
    1956             :         }
    1957             :         IF( EQ_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
    1958             :         {
    1959             : #ifndef DISABLE_LIMITER
    1960             :             ivas_limiter_dec_fx( st_ivas->hLimiter, pOutput, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToDecode, st_ivas->BER_detect, Q11 );
    1961             : #endif
    1962             :         }
    1963             :         else
    1964             :         {
    1965             :             ivas_limiter_dec_fx( st_ivas->hLimiter, pOutput, st_ivas->hDecoderConfig->nchan_out, numSamplesPerChannelToDecode, st_ivas->BER_detect, Q11 );
    1966             :         }
    1967             : 
    1968             :         ivas_syn_output_fx( pOutput, Q11, numSamplesPerChannelToDecode, st_ivas->hDecoderConfig->nchan_out, (Word16 *) pcmBuf_out );
    1969             :     }
    1970             : 
    1971             : #ifndef TMP_FIX_SPLIT_REND
    1972             :     free( st_ivas->hSplitBinRend->hMultiBinCldfbData );
    1973             : #endif
    1974             : #endif
    1975             : 
    1976           0 :     return IVAS_ERR_OK;
    1977             : }
    1978             : 
    1979             : 
    1980             : /*---------------------------------------------------------------------*
    1981             :  * ivas_dec_setup_all()
    1982             :  *
    1983             :  * Set-up all decoder parts: IVAS decoder, ISAR
    1984             :  *---------------------------------------------------------------------*/
    1985             : 
    1986      507534 : static ivas_error ivas_dec_setup_all(
    1987             :     IVAS_DEC_HANDLE hIvasDec,   /* i/o: IVAS decoder handle                        */
    1988             :     UWord8 *nTransportChannels, /* o  : number of decoded transport PCM channels   */
    1989             : #ifndef FIX_1119_SPLIT_RENDERING_VOIP
    1990             :     const Word16 isSplitRend, /* i  : split rendering enabled flag               */
    1991             : #endif
    1992             :     ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o  : output split rendering bits                */
    1993             : )
    1994             : {
    1995             :     ivas_error error;
    1996             : 
    1997      507534 :     IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
    1998             :     {
    1999        5150 :         IF( EQ_16( (Word16) hIvasDec->st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
    2000             :         {
    2001        1000 :             *nTransportChannels = MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN;
    2002             :         }
    2003             :         ELSE
    2004             :         {
    2005        4150 :             *nTransportChannels = 1;
    2006             :         }
    2007        5150 :         move16();
    2008             :     }
    2009             :     ELSE
    2010             :     {
    2011             :         Decoder_Struct *st_ivas;
    2012             : 
    2013      502384 :         st_ivas = hIvasDec->st_ivas;
    2014             : 
    2015             :         /* Setup IVAS split rendering */
    2016             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    2017      502384 :         IF( splitRendBits != NULL )
    2018             : #else
    2019             :         IF( isSplitRend )
    2020             : #endif
    2021             :         {
    2022           0 :             IF( ( error = isar_set_split_rend_setup( st_ivas->hSplitBinRend, &st_ivas->hRenderConfig->split_rend_config, st_ivas->hCombinedOrientationData, splitRendBits ) ) != IVAS_ERR_OK )
    2023             :             {
    2024           0 :                 return error;
    2025             :             }
    2026             :         }
    2027             : 
    2028             :         /*----------------------------------------------------------------*
    2029             :          * IVAS decoder setup
    2030             :          * - read IVAS format signaling
    2031             :          * - read IVAS format specific signaling
    2032             :          * - initialize decoder in the first frame based on IVAS format and number of transport channels
    2033             :          * - reconfigure the decoder when the number of TC or IVAS total bitrate change
    2034             :          *----------------------------------------------------------------*/
    2035             : 
    2036      502384 :         IF( EQ_16( st_ivas->bfi, 0 ) )
    2037             :         {
    2038      490337 :             error = IVAS_ERR_OK; // this is just to help the clang-formatting keep alignments
    2039      490337 :             IF( ( error = ivas_dec_setup( st_ivas ) ) != IVAS_ERR_OK )
    2040             :             {
    2041           0 :                 return error;
    2042             :             }
    2043             :         }
    2044             : 
    2045      502384 :         *nTransportChannels = (UWord8) st_ivas->hTcBuffer->nchan_transport_jbm;
    2046      502384 :         move16();
    2047             : 
    2048             :         /*-----------------------------------------------------------------*
    2049             :          * ISAR:
    2050             :          * - initialize ISAR handle at the first frame
    2051             :          * - reconfigure the ISAR handle in case of bitrate switching (renderer might change)
    2052             :          *-----------------------------------------------------------------*/
    2053             : 
    2054      502384 :         test();
    2055             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    2056      502384 :         IF( EQ_16( st_ivas->ini_frame, 0 ) && splitRendBits != NULL )
    2057             : #else
    2058             :         IF( st_ivas->ini_frame == 0 && isSplitRend )
    2059             : #endif
    2060             :         {
    2061           0 :             IF( ( error = ivas_dec_init_split_rend( st_ivas ) ) != IVAS_ERR_OK )
    2062             :             {
    2063           0 :                 return error;
    2064             :             }
    2065             :         }
    2066             : 
    2067      502384 :         test();
    2068      502384 :         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 ) )
    2069             :         {
    2070           0 :             IF( ( error = ivas_dec_reconfig_split_rend( st_ivas ) ) != IVAS_ERR_OK )
    2071             :             {
    2072           0 :                 return error;
    2073             :             }
    2074             :         }
    2075             :     }
    2076             : 
    2077      507534 :     return IVAS_ERR_OK;
    2078             : }
    2079             : 
    2080             : 
    2081             : /*---------------------------------------------------------------------*
    2082             :  * IVAS_DEC_GetNumObjects( )
    2083             :  *
    2084             :  * Returns the number of objects available in the decoded bitstream
    2085             :  *---------------------------------------------------------------------*/
    2086             : 
    2087       27712 : ivas_error IVAS_DEC_GetNumObjects(
    2088             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                                         */
    2089             :     UWord16 *numObjects       /* o  : number of objects for which the decoder has been configured */
    2090             : )
    2091             : {
    2092             :     Word16 is_masa_ism;
    2093             : 
    2094       27712 :     is_masa_ism = 0;
    2095       27712 :     move16();
    2096             : 
    2097       27712 :     test();
    2098       27712 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2099             :     {
    2100           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2101             :     }
    2102             : 
    2103       27712 :     IF( hIvasDec->st_ivas->hMasa != NULL )
    2104             :     {
    2105        4009 :         IF( EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) )
    2106             :         {
    2107        4009 :             is_masa_ism = 1;
    2108        4009 :             move16();
    2109             :         }
    2110             :     }
    2111             : 
    2112       27712 :     test();
    2113       27712 :     test();
    2114       27712 :     test();
    2115       27712 :     IF( EQ_32( hIvasDec->st_ivas->ivas_format, ISM_FORMAT ) ||
    2116             :         EQ_32( hIvasDec->st_ivas->ivas_format, SBA_ISM_FORMAT ) ||
    2117             :         EQ_32( hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) ||
    2118             :         EQ_16( is_masa_ism, 1 ) )
    2119             :     {
    2120       27712 :         *numObjects = hIvasDec->st_ivas->nchan_ism;
    2121             :     }
    2122             :     ELSE
    2123             :     {
    2124           0 :         *numObjects = 0;
    2125             :     }
    2126       27712 :     move16();
    2127             : 
    2128       27712 :     return IVAS_ERR_OK;
    2129             : }
    2130             : 
    2131             : 
    2132             : /*---------------------------------------------------------------------*
    2133             :  * IVAS_DEC_GetFormat( )
    2134             :  *
    2135             :  * Returns the format of currently decoded bitstream.
    2136             :  * Note: bitstream format is only known after the first (good) frame has been decoded.
    2137             :  *---------------------------------------------------------------------*/
    2138             : 
    2139          52 : ivas_error IVAS_DEC_GetFormat(
    2140             :     IVAS_DEC_HANDLE hIvasDec,  /* i/o: IVAS decoder handle                               */
    2141             :     IVAS_DEC_BS_FORMAT *format /* o  : format detected from bitstream fed to the decoder */
    2142             : )
    2143             : {
    2144          52 :     test();
    2145          52 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2146             :     {
    2147           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2148             :     }
    2149             : 
    2150          52 :     IF( hIvasDec->hasDecodedFirstGoodFrame )
    2151             :     {
    2152          52 :         *format = mapIvasFormat( hIvasDec->st_ivas->ivas_format );
    2153             :     }
    2154             :     ELSE
    2155             :     {
    2156           0 :         *format = IVAS_DEC_BS_UNKOWN;
    2157             :     }
    2158          52 :     move32();
    2159             : 
    2160             : #ifdef DECODER_FORMAT_SWITCHING
    2161          52 :     test();
    2162          52 :     IF( EQ_32( *format, IVAS_DEC_BS_MASA ) && hIvasDec->st_ivas->hMasa != NULL )
    2163             :     {
    2164          17 :         IF( EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) )
    2165             :         {
    2166           0 :             *format = IVAS_DEC_BS_MASA_ISM;
    2167           0 :             move32();
    2168             :         }
    2169             :     }
    2170             : #else
    2171             :     test();
    2172             :     if ( EQ_32( *format, IVAS_DEC_BS_MASA ) && EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) )
    2173             :     {
    2174             :         *format = IVAS_DEC_BS_MASA_ISM;
    2175             :         move32();
    2176             :     }
    2177             : #endif
    2178             : 
    2179          52 :     return IVAS_ERR_OK;
    2180             : }
    2181             : 
    2182             : 
    2183             : /*---------------------------------------------------------------------*
    2184             :  * getOutputBufferSize()
    2185             :  *
    2186             :  * Get size of output buffer in samples
    2187             :  *---------------------------------------------------------------------*/
    2188             : 
    2189        1276 : static Word16 getOutputBufferSize(
    2190             :     const Decoder_Struct *st_ivas /* i  : IVAS decoder handle */
    2191             : )
    2192             : {
    2193        1276 :     IF( st_ivas->hDecoderConfig == NULL )
    2194             :     {
    2195           0 :         return -1;
    2196             :     }
    2197             : 
    2198        1276 :     IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_EXTERNAL ) )
    2199             :     {
    2200         104 :         return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, ( MAX_OUTPUT_CHANNELS + MAX_NUM_OBJECTS ) ), INV_FRAME_PER_SEC_Q15 ) );
    2201             :     }
    2202        1172 :     ELSE IF( EQ_16( (Word16) st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
    2203             :     {
    2204           6 :         IF( st_ivas->hLsSetupCustom == NULL )
    2205             :         {
    2206           0 :             return -1;
    2207             :         }
    2208             : 
    2209           6 :         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 ) );
    2210             :     }
    2211             :     ELSE
    2212             :     {
    2213        1166 :         return extract_l( Mult_32_16( imult3216( st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->nchan_out ), INV_FRAME_PER_SEC_Q15 ) );
    2214             :     }
    2215             : }
    2216             : 
    2217             : 
    2218             : /*---------------------------------------------------------------------*
    2219             :  * IVAS_DEC_GetOutputBufferSize()
    2220             :  *
    2221             :  * Returns size of output buffer in samples
    2222             :  *---------------------------------------------------------------------*/
    2223             : 
    2224        1276 : ivas_error IVAS_DEC_GetOutputBufferSize(
    2225             :     const IVAS_DEC_HANDLE hIvasDec, /* i  : IVAS decoder handle                                                                     */
    2226             :     Word16 *outputBufferSize        /* o  : total number of samples expected in the output buffer for current decoder configuration */
    2227             : )
    2228             : {
    2229        1276 :     test();
    2230        1276 :     test();
    2231        1276 :     IF( outputBufferSize == NULL || hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2232             :     {
    2233           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2234             :     }
    2235             : 
    2236        1276 :     *outputBufferSize = getOutputBufferSize( hIvasDec->st_ivas );
    2237        1276 :     move16();
    2238             : 
    2239        1276 :     IF( EQ_16( *outputBufferSize, -1 ) )
    2240             :     {
    2241           0 :         return IVAS_ERR_INVALID_OUTPUT_BUFFER_SIZE;
    2242             :     }
    2243             :     ELSE
    2244             :     {
    2245        1276 :         return IVAS_ERR_OK;
    2246             :     }
    2247             : }
    2248             : 
    2249             : 
    2250             : /*---------------------------------------------------------------------*
    2251             :  * IVAS_DEC_GetNumOutputChannels( )
    2252             :  *
    2253             :  * Returns number of output channels
    2254             :  *---------------------------------------------------------------------*/
    2255             : 
    2256         638 : ivas_error IVAS_DEC_GetNumOutputChannels(
    2257             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle             */
    2258             :     Word16 *numOutputChannels /* o  : number of PCM output channels   */
    2259             : )
    2260             : {
    2261         638 :     test();
    2262         638 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2263             :     {
    2264           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2265             :     }
    2266             : 
    2267         638 :     IF( hIvasDec->hasDecodedFirstGoodFrame )
    2268             :     {
    2269         638 :         *numOutputChannels = hIvasDec->st_ivas->hDecoderConfig->nchan_out;
    2270             :     }
    2271             :     ELSE
    2272             :     {
    2273           0 :         *numOutputChannels = 0;
    2274             :     }
    2275         638 :     move16();
    2276             : 
    2277         638 :     return IVAS_ERR_OK;
    2278             : }
    2279             : 
    2280             : 
    2281             : /*---------------------------------------------------------------------*
    2282             :  * IVAS_DEC_GetObjectMetadata( )
    2283             :  *
    2284             :  * Get metadata of one object decoded in the most recent frame
    2285             :  *---------------------------------------------------------------------*/
    2286             : 
    2287       79846 : ivas_error IVAS_DEC_GetObjectMetadata(
    2288             :     IVAS_DEC_HANDLE hIvasDec,    /* i/o: IVAS decoder handle                                                                */
    2289             :     IVAS_ISM_METADATA *metadata, /* o  : struct where metadata decoded in most recently decoded frame will be written       */
    2290             :     const UWord16 zero_flag,     /* i  : if this flag is enabled, this function outputs a zero-initialized metadata struct  */
    2291             :     const UWord16 objectIdx      /* i  : index of the queried object                                                        */
    2292             : )
    2293             : {
    2294             :     Decoder_Struct *st_ivas;
    2295             :     ISM_METADATA_HANDLE hIsmMeta;
    2296             :     Word16 is_masa_ism;
    2297             : 
    2298       79846 :     is_masa_ism = 0;
    2299       79846 :     move16();
    2300             : 
    2301       79846 :     test();
    2302       79846 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2303             :     {
    2304           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2305             :     }
    2306             : 
    2307       79846 :     st_ivas = hIvasDec->st_ivas;
    2308             : 
    2309       79846 :     IF( st_ivas->hMasa != NULL )
    2310             :     {
    2311       13052 :         IF( EQ_32( hIvasDec->st_ivas->hMasa->config.input_ivas_format, MASA_ISM_FORMAT ) )
    2312             :         {
    2313       13052 :             is_masa_ism = 1;
    2314       13052 :             move16();
    2315             :         }
    2316             :     }
    2317             : 
    2318       79846 :     test();
    2319       79846 :     test();
    2320       79846 :     test();
    2321       79846 :     IF( NE_32( st_ivas->ivas_format, ISM_FORMAT ) &&
    2322             :         NE_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) &&
    2323             :         NE_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) &&
    2324             :         EQ_16( is_masa_ism, 0 ) )
    2325             :     {
    2326           0 :         return IVAS_ERR_WRONG_MODE;
    2327             :     }
    2328             : 
    2329       79846 :     IF( GE_16( objectIdx, st_ivas->nchan_ism ) )
    2330             :     {
    2331           0 :         return IVAS_ERR_INVALID_INDEX;
    2332             :     }
    2333             : 
    2334       79846 :     hIsmMeta = st_ivas->hIsmMetaData[objectIdx];
    2335             : 
    2336       79846 :     test();
    2337       79846 :     test();
    2338       79846 :     test();
    2339       79846 :     IF( hIsmMeta == NULL ||
    2340             :         EQ_16( zero_flag, 1 ) ||
    2341             :         ( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) && EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) ) )
    2342             :     {
    2343        3442 :         metadata->azimuth_fx = 0;             // Q22
    2344        3442 :         metadata->elevation_fx = 0;           // Q22
    2345        3442 :         metadata->radius_fx = 512;            // Q9
    2346        3442 :         metadata->yaw_fx = 0;                 // Q22
    2347        3442 :         metadata->pitch_fx = 0;               // Q22
    2348        3442 :         metadata->spread_fx = 0;              // Q22
    2349        3442 :         metadata->gainFactor_fx = ONE_IN_Q29; // Q31
    2350        3442 :         metadata->non_diegetic_flag = 0;
    2351             :     }
    2352             :     ELSE
    2353             :     {
    2354       76404 :         IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) )
    2355             :         {
    2356       55612 :             metadata->azimuth_fx = hIsmMeta->edited_azimuth_fx;
    2357       55612 :             metadata->elevation_fx = hIsmMeta->edited_elevation_fx;
    2358       55612 :             metadata->radius_fx = hIsmMeta->edited_radius_fx;
    2359       55612 :             metadata->yaw_fx = hIsmMeta->edited_yaw_fx;
    2360       55612 :             metadata->pitch_fx = hIsmMeta->edited_pitch_fx;
    2361       55612 :             metadata->spread_fx = 0;
    2362       55612 :             metadata->gainFactor_fx = hIsmMeta->edited_gain_fx;
    2363       55612 :             metadata->non_diegetic_flag = hIsmMeta->non_diegetic_flag;
    2364             :         }
    2365       20792 :         ELSE IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
    2366             :         {
    2367        2172 :             metadata->azimuth_fx = st_ivas->hParamIsmDec->edited_azimuth_values_fx[objectIdx];
    2368        2172 :             metadata->elevation_fx = st_ivas->hParamIsmDec->edited_elevation_values_fx[objectIdx];
    2369        2172 :             metadata->radius_fx = hIsmMeta->radius_fx;
    2370        2172 :             metadata->yaw_fx = hIsmMeta->yaw_fx;
    2371        2172 :             metadata->pitch_fx = hIsmMeta->pitch_fx;
    2372        2172 :             metadata->spread_fx = 0;
    2373        2172 :             metadata->gainFactor_fx = ONE_IN_Q29;
    2374        2172 :             metadata->non_diegetic_flag = hIsmMeta->non_diegetic_flag;
    2375             :         }
    2376       18620 :         ELSE IF( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
    2377             :         {
    2378       17620 :             metadata->azimuth_fx = st_ivas->hIsmMetaData[objectIdx]->edited_azimuth_fx;
    2379       17620 :             metadata->elevation_fx = st_ivas->hIsmMetaData[objectIdx]->edited_elevation_fx;
    2380       17620 :             metadata->radius_fx = st_ivas->hIsmMetaData[objectIdx]->edited_radius_fx;
    2381       17620 :             metadata->yaw_fx = st_ivas->hIsmMetaData[objectIdx]->edited_yaw_fx;
    2382       17620 :             metadata->pitch_fx = st_ivas->hIsmMetaData[objectIdx]->edited_pitch_fx;
    2383       17620 :             metadata->spread_fx = 0;
    2384       17620 :             metadata->gainFactor_fx = st_ivas->hIsmMetaData[objectIdx]->edited_gain_fx;
    2385       17620 :             metadata->non_diegetic_flag = st_ivas->hIsmMetaData[objectIdx]->non_diegetic_flag;
    2386             :         }
    2387             :         ELSE
    2388             :         {
    2389        1000 :             metadata->azimuth_fx = hIsmMeta->azimuth_fx;     // Q22
    2390        1000 :             metadata->elevation_fx = hIsmMeta->elevation_fx; // Q22
    2391        1000 :             metadata->radius_fx = hIsmMeta->radius_fx;       // Q9
    2392        1000 :             metadata->yaw_fx = hIsmMeta->yaw_fx;             // Q22
    2393        1000 :             metadata->pitch_fx = hIsmMeta->pitch_fx;         // Q22
    2394        1000 :             metadata->spread_fx = 0;                         // Q22
    2395        1000 :             metadata->gainFactor_fx = ONE_IN_Q29;
    2396        1000 :             metadata->non_diegetic_flag = hIsmMeta->non_diegetic_flag;
    2397             :         }
    2398             :     }
    2399             : 
    2400       79846 :     move32();
    2401       79846 :     move32();
    2402       79846 :     move32();
    2403       79846 :     move32();
    2404       79846 :     move32();
    2405       79846 :     move32();
    2406       79846 :     move16();
    2407       79846 :     move16();
    2408             : 
    2409       79846 :     return IVAS_ERR_OK;
    2410             : }
    2411             : 
    2412             : 
    2413             : /*---------------------------------------------------------------------*
    2414             :  * IVAS_DEC_GetMasaMetadata( )
    2415             :  *
    2416             :  * Get metadata of the most recently decoded MASA frame
    2417             :  *---------------------------------------------------------------------*/
    2418             : 
    2419       19466 : ivas_error IVAS_DEC_GetMasaMetadata(
    2420             :     IVAS_DEC_HANDLE hIvasDec,                          /* i/o: IVAS decoder handle              */
    2421             :     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 */
    2422             :     const UWord8 getFromJbmBuffer                      /* i  : get metadata from a JBM buffer   */
    2423             : )
    2424             : {
    2425       19466 :     test();
    2426       19466 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2427             :     {
    2428           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2429             :     }
    2430             : 
    2431       19466 :     test();
    2432       19466 :     IF( NE_16( hIvasDec->st_ivas->ivas_format, MASA_FORMAT ) && NE_16( hIvasDec->st_ivas->ivas_format, MASA_ISM_FORMAT ) )
    2433             :     {
    2434           0 :         return IVAS_ERR_WRONG_MODE;
    2435             :     }
    2436             : 
    2437       19466 :     IF( getFromJbmBuffer )
    2438             :     {
    2439        3007 :         ivas_jbm_masa_sf_to_sf_map( hIvasDec->st_ivas );
    2440             :     }
    2441             : 
    2442       19466 :     *hMasaExtOutMeta = hIvasDec->st_ivas->hMasa->data.extOutMeta;
    2443             : 
    2444       19466 :     return IVAS_ERR_OK;
    2445             : }
    2446             : 
    2447             : 
    2448             : /*---------------------------------------------------------------------*
    2449             :  * IVAS_DEC_FeedHeadTrackData( )
    2450             :  *
    2451             :  * Feed the decoder with the head tracking data
    2452             :  *---------------------------------------------------------------------*/
    2453             : 
    2454      317620 : ivas_error IVAS_DEC_FeedHeadTrackData(
    2455             :     IVAS_DEC_HANDLE hIvasDec,               /* i/o: IVAS decoder handle                                     */
    2456             :     IVAS_QUATERNION orientation,            /* i  : head-tracking data, listener orientation                */
    2457             :     IVAS_VECTOR3 Pos,                       /* i  : listener position                                       */
    2458             :     const Word16 subframe_idx,              /* i  : subframe index                                          */
    2459             :     const ISAR_SPLIT_REND_ROT_AXIS rot_axis /* i  : external control for rotation axis for split rendering  */
    2460             : )
    2461             : {
    2462             :     HEAD_TRACK_DATA_HANDLE hHeadTrackData;
    2463             :     ivas_error error;
    2464             : 
    2465      317620 :     test();
    2466      317620 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2467             :     {
    2468           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2469             :     }
    2470             : 
    2471      317620 :     hHeadTrackData = hIvasDec->st_ivas->hHeadTrackData;
    2472             : 
    2473      317620 :     IF( hHeadTrackData == NULL )
    2474             :     {
    2475           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2476             :     }
    2477             : 
    2478             :     /* Move head-tracking data to the decoder handle */
    2479             :     /* check for Euler angle signaling */
    2480             :     /* check for Euler angle signaling */
    2481      317620 :     IF( EQ_32( orientation.w_fx, L_negate( 12582912 ) ) && EQ_16( orientation.q_fact, Q22 ) )
    2482             :     {
    2483           0 :         Euler2Quat_fx( deg2rad_fx( orientation.x_fx ), deg2rad_fx( orientation.y_fx ), deg2rad_fx( orientation.z_fx ), &orientation );
    2484           0 :         modify_Quat_q_fx( &orientation, &orientation, Q29 );
    2485             :     }
    2486             : 
    2487      317620 :     Word32 updateRate_fx = 1677721600; // value is 200 in Q23
    2488      317620 :     move32();
    2489      317620 :     orientation.w_fx = L_shl( orientation.w_fx, sub( Q29, orientation.q_fact ) );                                                                                                       // Q29
    2490      317620 :     orientation.x_fx = L_shl( orientation.x_fx, sub( Q29, orientation.q_fact ) );                                                                                                       // Q29
    2491      317620 :     orientation.y_fx = L_shl( orientation.y_fx, sub( Q29, orientation.q_fact ) );                                                                                                       // Q29
    2492      317620 :     orientation.z_fx = L_shl( orientation.z_fx, sub( Q29, orientation.q_fact ) );                                                                                                       // Q29
    2493      317620 :     hHeadTrackData->OrientationTracker->refRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) );          // Q29
    2494      317620 :     hHeadTrackData->OrientationTracker->refRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) );          // Q29
    2495      317620 :     hHeadTrackData->OrientationTracker->refRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) );          // Q29
    2496      317620 :     hHeadTrackData->OrientationTracker->refRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->refRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->refRot.q_fact ) );          // Q29
    2497      317620 :     hHeadTrackData->OrientationTracker->absAvgRot.w_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.w_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
    2498      317620 :     hHeadTrackData->OrientationTracker->absAvgRot.x_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.x_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
    2499      317620 :     hHeadTrackData->OrientationTracker->absAvgRot.y_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.y_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
    2500      317620 :     hHeadTrackData->OrientationTracker->absAvgRot.z_fx = L_shl( hHeadTrackData->OrientationTracker->absAvgRot.z_fx, sub( Q29, hHeadTrackData->OrientationTracker->absAvgRot.q_fact ) ); // Q29
    2501             : 
    2502      317620 :     orientation.q_fact = Q29;
    2503      317620 :     hHeadTrackData->OrientationTracker->refRot.q_fact = Q29;
    2504      317620 :     hHeadTrackData->OrientationTracker->absAvgRot.q_fact = Q29;
    2505      317620 :     move16();
    2506      317620 :     move16();
    2507      317620 :     move16();
    2508             : 
    2509      317620 :     IF( NE_32( ( error = ivas_orient_trk_Process_fx( hHeadTrackData->OrientationTracker, orientation, updateRate_fx, &hHeadTrackData->Quaternions[subframe_idx] ) ), IVAS_ERR_OK ) )
    2510             :     {
    2511           0 :         return error;
    2512             :     }
    2513             : 
    2514      317620 :     hHeadTrackData->Pos[subframe_idx].x_fx = Pos.x_fx;
    2515      317620 :     hHeadTrackData->Pos[subframe_idx].y_fx = Pos.y_fx;
    2516      317620 :     hHeadTrackData->Pos[subframe_idx].z_fx = Pos.z_fx;
    2517      317620 :     hHeadTrackData->Pos[subframe_idx].q_fact = Pos.q_fact;
    2518      317620 :     move32();
    2519      317620 :     move32();
    2520      317620 :     move32();
    2521      317620 :     move16();
    2522             : 
    2523      317620 :     hHeadTrackData->sr_pose_pred_axis = rot_axis;
    2524      317620 :     move32();
    2525             : 
    2526      317620 :     hIvasDec->updateOrientation = true;
    2527      317620 :     move16();
    2528             : 
    2529      317620 :     return IVAS_ERR_OK;
    2530             : }
    2531             : 
    2532             : 
    2533             : /*---------------------------------------------------------------------*
    2534             :  * IVAS_DEC_FeedRefRotData( )
    2535             :  *
    2536             :  * Feed the decoder with the reference rotation data
    2537             :  *---------------------------------------------------------------------*/
    2538             : 
    2539           0 : ivas_error IVAS_DEC_FeedRefRotData(
    2540             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle     */
    2541             :     IVAS_QUATERNION rotation  /* i  : reference rotation data */
    2542             : )
    2543             : {
    2544             :     ivas_orient_trk_state_t *pOtr;
    2545             : 
    2546           0 :     test();
    2547           0 :     test();
    2548           0 :     test();
    2549           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHeadTrackData == NULL || hIvasDec->st_ivas->hHeadTrackData->OrientationTracker == NULL )
    2550             :     {
    2551           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2552             :     }
    2553             : 
    2554           0 :     pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker;
    2555             : 
    2556           0 :     pOtr->refRot.w_fx = rotation.w_fx; // rotation.q_fact
    2557           0 :     pOtr->refRot.x_fx = rotation.x_fx; // rotation.q_fact
    2558           0 :     pOtr->refRot.z_fx = rotation.z_fx; // rotation.q_fact
    2559           0 :     pOtr->refRot.y_fx = rotation.y_fx; // rotation.q_fact
    2560             : 
    2561           0 :     pOtr->refRot.q_fact = rotation.q_fact;
    2562           0 :     move32();
    2563           0 :     move32();
    2564           0 :     move32();
    2565           0 :     move32();
    2566             : 
    2567           0 :     hIvasDec->updateOrientation = true;
    2568           0 :     move16();
    2569             : 
    2570           0 :     return IVAS_ERR_OK;
    2571             : }
    2572             : 
    2573             : 
    2574             : /*---------------------------------------------------------------------*
    2575             :  * IVAS_DEC_FeedRefVectorData( )
    2576             :  *
    2577             :  * Feed the decoder with a reference vector spanning from listenerPos
    2578             :  * to refPos. Only available in OTR_TRACKING_REF_POS and
    2579             :  * OTR_TRACKING_REF_POS_LEV modes.
    2580             :  *---------------------------------------------------------------------*/
    2581             : 
    2582        4004 : ivas_error IVAS_DEC_FeedRefVectorData(
    2583             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle     */
    2584             :     IVAS_VECTOR3 listenerPos, /* i  : Listener position       */
    2585             :     IVAS_VECTOR3 refPos       /* i  : Reference position      */
    2586             : )
    2587             : {
    2588             :     ivas_orient_trk_state_t *pOtr;
    2589             : 
    2590        4004 :     test();
    2591        4004 :     test();
    2592        4004 :     test();
    2593        4004 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHeadTrackData == NULL || hIvasDec->st_ivas->hHeadTrackData->OrientationTracker == NULL )
    2594             :     {
    2595           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2596             :     }
    2597             : 
    2598        4004 :     pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker;
    2599             : 
    2600        4004 :     hIvasDec->updateOrientation = true;
    2601        4004 :     move16();
    2602             : 
    2603        4004 :     return ivas_orient_trk_SetReferenceVector_fx( pOtr, listenerPos, refPos );
    2604             : }
    2605             : 
    2606             : 
    2607             : /*---------------------------------------------------------------------*
    2608             :  * IVAS_DEC_FeedExternalOrientationData( )
    2609             :  *
    2610             :  * Feed the decoder with the external orientation data
    2611             :  *---------------------------------------------------------------------*/
    2612             : 
    2613      132524 : ivas_error IVAS_DEC_FeedExternalOrientationData(
    2614             :     IVAS_DEC_HANDLE hIvasDec,            /* i/o: IVAS decoder handle                                                     */
    2615             :     IVAS_QUATERNION orientation,         /* i  : external orientation data                                               */
    2616             :     Word8 enableHeadRotation,            /* i  : flag to enable head rotation for this frame                             */
    2617             :     Word8 enableExternalOrientation,     /* i  : flag to enable external orientation for this frame                      */
    2618             :     Word8 enableRotationInterpolation,   /* i  : flag to interpolate rotations from current and previous frames          */
    2619             :     Word16 numFramesToTargetOrientation, /* i  : number of frames until target orientation is reached                    */
    2620             :     const Word16 subframe_idx            /* i  : subframe index                                                          */
    2621             : )
    2622             : {
    2623             :     EXTERNAL_ORIENTATION_HANDLE hExternalOrientationData;
    2624             : 
    2625      132524 :     test();
    2626      132524 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2627             :     {
    2628           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2629             :     }
    2630             : 
    2631      132524 :     hExternalOrientationData = hIvasDec->st_ivas->hExtOrientationData;
    2632             : 
    2633      132524 :     IF( hExternalOrientationData == NULL )
    2634             :     {
    2635           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2636             :     }
    2637             : 
    2638      132524 :     orientation.q_fact = Q29;
    2639      132524 :     move16();
    2640             : 
    2641             :     /* Move external orientation data to the decoder handle (invert orientations) */
    2642      132524 :     QuaternionInverse_fx( orientation, &hExternalOrientationData->Quaternions[subframe_idx] );
    2643             : 
    2644      132524 :     hExternalOrientationData->enableHeadRotation[subframe_idx] = enableHeadRotation;
    2645      132524 :     hExternalOrientationData->enableExternalOrientation[subframe_idx] = enableExternalOrientation;
    2646      132524 :     hExternalOrientationData->enableRotationInterpolation[subframe_idx] = enableRotationInterpolation;
    2647      132524 :     hExternalOrientationData->numFramesToTargetOrientation[subframe_idx] = numFramesToTargetOrientation;
    2648      132524 :     move16();
    2649      132524 :     move16();
    2650      132524 :     move16();
    2651      132524 :     move16();
    2652             : 
    2653      132524 :     hIvasDec->updateOrientation = true;
    2654      132524 :     move16();
    2655             : 
    2656      132524 :     return IVAS_ERR_OK;
    2657             : }
    2658             : 
    2659             : 
    2660             : /*---------------------------------------------------------------------*
    2661             :  * IVAS_DEC_FeedCustomLsData( )
    2662             :  *
    2663             :  * Feed the decoder with the Custom loudspeaker data
    2664             :  *---------------------------------------------------------------------*/
    2665             : 
    2666             : /*! r: error code */
    2667           3 : ivas_error IVAS_DEC_FeedCustomLsData(
    2668             :     IVAS_DEC_HANDLE hIvasDec,               /* i/o: IVAS decoder handle             */
    2669             :     const IVAS_CUSTOM_LS_DATA hLsCustomData /* i  : Custom loudspeaker setup data   */
    2670             : )
    2671             : {
    2672             :     Word16 i, is_planar;
    2673             :     IVAS_LSSETUP_CUSTOM_HANDLE hLsSetupCustom;
    2674             : 
    2675           3 :     test();
    2676           3 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2677             :     {
    2678           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2679             :     }
    2680             : 
    2681           3 :     hLsSetupCustom = hIvasDec->st_ivas->hLsSetupCustom;
    2682             : 
    2683           3 :     IF( hLsSetupCustom == NULL )
    2684             :     {
    2685           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2686             :     }
    2687             : 
    2688             :     /* Move Custom LS layout data to the decoder handle */
    2689             : 
    2690             :     /* Loudspeaker azimuths and elevations */
    2691           3 :     hLsSetupCustom->num_spk = hLsCustomData.num_spk;
    2692           3 :     move16();
    2693             : 
    2694           3 :     Copy32( hLsCustomData.azimuth_fx, hLsSetupCustom->ls_azimuth_fx, hLsCustomData.num_spk );     // Q22
    2695           3 :     Copy32( hLsCustomData.elevation_fx, hLsSetupCustom->ls_elevation_fx, hLsCustomData.num_spk ); // Q22
    2696             : 
    2697             :     /* Set planar flag */
    2698           3 :     is_planar = 1;
    2699           3 :     move16();
    2700          51 :     FOR( i = 0; i < hLsCustomData.num_spk; i++ )
    2701             :     {
    2702          48 :         test();
    2703          48 :         if ( is_planar && hLsSetupCustom->ls_elevation_fx[i] != 0 )
    2704             :         {
    2705           3 :             is_planar = 0;
    2706           3 :             move16();
    2707             :         }
    2708             :     }
    2709           3 :     hLsSetupCustom->is_planar_setup = is_planar;
    2710           3 :     move16();
    2711             : 
    2712             :     /* Loudspeaker LFE */
    2713           3 :     hLsSetupCustom->num_lfe = hLsCustomData.num_lfe;
    2714           3 :     move16();
    2715           3 :     Copy( hLsCustomData.lfe_idx, hLsSetupCustom->lfe_idx, hLsCustomData.num_lfe );
    2716             : 
    2717           3 :     return IVAS_ERR_OK;
    2718             : }
    2719             : 
    2720             : 
    2721             : /*---------------------------------------------------------------------*
    2722             :  * IVAS_DEC_GetHrtfTDrendHandle( )
    2723             :  *
    2724             :  * Get TD binaural renderer handle
    2725             :  *---------------------------------------------------------------------*/
    2726             : 
    2727         162 : ivas_error IVAS_DEC_GetHrtfTDrendHandle(
    2728             :     IVAS_DEC_HANDLE hIvasDec,         /* i/o: IVAS decoder handle      */
    2729             :     IVAS_DEC_HRTF_TD_HANDLE **hHrtfTD /* o  : TD rend. HRTF handle     */
    2730             : )
    2731             : {
    2732         162 :     test();
    2733         162 :     test();
    2734         162 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfTD == NULL )
    2735             :     {
    2736           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2737             :     }
    2738             : 
    2739         162 :     *hHrtfTD = &hIvasDec->st_ivas->hHrtfTD;
    2740             : 
    2741         162 :     return IVAS_ERR_OK;
    2742             : }
    2743             : 
    2744             : 
    2745             : /*---------------------------------------------------------------------*
    2746             :  * IVAS_DEC_GetHrtfCRendHandle( )
    2747             :  *
    2748             :  * Get Crend binaural renderer handle
    2749             :  *---------------------------------------------------------------------*/
    2750             : 
    2751          28 : ivas_error IVAS_DEC_GetHrtfCRendHandle(
    2752             :     IVAS_DEC_HANDLE hIvasDec,               /* i/o: IVAS decoder handle      */
    2753             :     IVAS_DEC_HRTF_CREND_HANDLE **hHrtfCrend /* o  : Crend HRTF handle        */
    2754             : )
    2755             : {
    2756          28 :     test();
    2757          28 :     test();
    2758          28 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfCrend == NULL )
    2759             :     {
    2760           0 :         return IVAS_ERR_WRONG_PARAMS;
    2761             :     }
    2762             : 
    2763          28 :     *hHrtfCrend = &hIvasDec->st_ivas->hHrtfCrend;
    2764             : 
    2765          28 :     return IVAS_ERR_OK;
    2766             : }
    2767             : 
    2768             : 
    2769             : /*---------------------------------------------------------------------*
    2770             :  * IVAS_DEC_GetHrtfFastConvHandle( )
    2771             :  *
    2772             :  * Get FastConv binaural renderer handle
    2773             :  *---------------------------------------------------------------------*/
    2774             : 
    2775          73 : ivas_error IVAS_DEC_GetHrtfFastConvHandle(
    2776             :     IVAS_DEC_HANDLE hIvasDec,                     /* i/o: IVAS decoder handle    */
    2777             :     IVAS_DEC_HRTF_FASTCONV_HANDLE **hHrtfFastConv /* o  : FASTCONV HRTF handle   */
    2778             : )
    2779             : {
    2780          73 :     test();
    2781          73 :     test();
    2782          73 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfFastConv == NULL )
    2783             :     {
    2784           0 :         return IVAS_ERR_WRONG_PARAMS;
    2785             :     }
    2786             : 
    2787          73 :     *hHrtfFastConv = &hIvasDec->st_ivas->hHrtfFastConv;
    2788             : 
    2789          73 :     return IVAS_ERR_OK;
    2790             : }
    2791             : 
    2792             : 
    2793             : /*---------------------------------------------------------------------*
    2794             :  * IVAS_DEC_GetHrtfParamBinHandle( )
    2795             :  *
    2796             :  * Get Parametric binaural renderer handle
    2797             :  *---------------------------------------------------------------------*/
    2798             : 
    2799         339 : ivas_error IVAS_DEC_GetHrtfParamBinHandle(
    2800             :     IVAS_DEC_HANDLE hIvasDec,                     /* i/o: IVAS decoder handle                 */
    2801             :     IVAS_DEC_HRTF_PARAMBIN_HANDLE **hHrtfParambin /* o  : Parametric binauralizer HRTF handle */
    2802             : )
    2803             : {
    2804         339 :     test();
    2805         339 :     test();
    2806         339 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfParambin == NULL )
    2807             :     {
    2808           0 :         return IVAS_ERR_WRONG_PARAMS;
    2809             :     }
    2810             : 
    2811         339 :     *hHrtfParambin = &hIvasDec->st_ivas->hHrtfParambin;
    2812             : 
    2813         339 :     return IVAS_ERR_OK;
    2814             : }
    2815             : 
    2816             : 
    2817             : /*---------------------------------------------------------------------*
    2818             :  * IVAS_DEC_GetHrtfStatisticsHandle( )
    2819             :  *
    2820             :  * Get HRTF statistics (room effect) binaural renderer handle
    2821             :  *---------------------------------------------------------------------*/
    2822             : 
    2823         641 : ivas_error IVAS_DEC_GetHrtfStatisticsHandle(
    2824             :     IVAS_DEC_HANDLE hIvasDec,                         /* i/o: IVAS decoder handle       */
    2825             :     IVAS_DEC_HRTF_STATISTICS_HANDLE **hHrtfStatistics /* o  : HRTF statistics handle    */
    2826             : )
    2827             : {
    2828         641 :     test();
    2829         641 :     test();
    2830         641 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHrtfStatistics == NULL )
    2831             :     {
    2832         590 :         return IVAS_ERR_WRONG_PARAMS;
    2833             :     }
    2834             : 
    2835          51 :     *hHrtfStatistics = &hIvasDec->st_ivas->hHrtfStatistics;
    2836             : 
    2837          51 :     return IVAS_ERR_OK;
    2838             : }
    2839             : 
    2840             : 
    2841             : /*---------------------------------------------------------------------*
    2842             :  * IVAS_DEC_HRTF_binary_open( )
    2843             :  *
    2844             :  * Allocate HRTF binary handles
    2845             :  *---------------------------------------------------------------------*/
    2846             : 
    2847         898 : ivas_error IVAS_DEC_HRTF_binary_open(
    2848             :     IVAS_DEC_HANDLE hIvasDec,                      /* i/o: IVAS decoder handle      */
    2849             :     const IVAS_BIN_RENDERER_TYPE binaural_renderer /* i  : binaural renderer type   */
    2850             : )
    2851             : {
    2852             :     ivas_error error;
    2853             :     Decoder_Struct *st_ivas;
    2854             : 
    2855         898 :     st_ivas = hIvasDec->st_ivas;
    2856             : 
    2857         898 :     test();
    2858         898 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2859             :     {
    2860           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2861             :     }
    2862             : 
    2863         898 :     IF( st_ivas->hDecoderConfig->Opt_HRTF_binary )
    2864             :     {
    2865             :         /* TD binaural renderer */
    2866         898 :         test();
    2867         898 :         test();
    2868         898 :         IF( ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_TDREND ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) && st_ivas->hHrtfTD == NULL )
    2869             :         {
    2870         162 :             IF( ( error = ivas_HRTF_binary_open_fx( &( st_ivas->hHrtfTD ) ) ) != IVAS_ERR_OK )
    2871             :             {
    2872           0 :                 return error;
    2873             :             }
    2874             :         }
    2875             : 
    2876             :         /* Crend binaural renderer */
    2877         898 :         test();
    2878         898 :         test();
    2879         898 :         IF( ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_CREND ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) && st_ivas->hHrtfCrend == NULL )
    2880             :         {
    2881          28 :             IF( ( error = ivas_HRTF_CRend_binary_open_fx( &( st_ivas->hHrtfCrend ) ) ) != IVAS_ERR_OK )
    2882             :             {
    2883           0 :                 return error;
    2884             :             }
    2885             :         }
    2886             : 
    2887             :         /* FastConv binaural renderer */
    2888         898 :         test();
    2889         898 :         test();
    2890         898 :         IF( ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_FASTCONV ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) && st_ivas->hHrtfFastConv == NULL )
    2891             :         {
    2892          68 :             IF( ( error = ivas_HRTF_fastconv_binary_open_fx( &st_ivas->hHrtfFastConv ) ) != IVAS_ERR_OK )
    2893             :             {
    2894           0 :                 return error;
    2895             :             }
    2896             :         }
    2897             : 
    2898             :         /* Parametric binaural renderer */
    2899         898 :         test();
    2900         898 :         test();
    2901         898 :         IF( ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_PARAMBIN ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) && st_ivas->hHrtfParambin == NULL )
    2902             :         {
    2903          90 :             IF( ( error = ivas_HRTF_parambin_binary_open_fx( &st_ivas->hHrtfParambin ) ) != IVAS_ERR_OK )
    2904             :             {
    2905           0 :                 return error;
    2906             :             }
    2907             :         }
    2908             : 
    2909         898 :         test();
    2910         898 :         test();
    2911         898 :         test();
    2912         898 :         IF( st_ivas->hHrtfStatistics == NULL && ( EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_FASTCONV ) || EQ_32( binaural_renderer, IVAS_BIN_RENDERER_TYPE_CREND ) ) && st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
    2913             :         {
    2914           3 :             IF( ( error = ivas_HRTF_statistics_binary_open_fx( &st_ivas->hHrtfStatistics ) ) != IVAS_ERR_OK )
    2915             :             {
    2916           0 :                 return error;
    2917             :             }
    2918             :         }
    2919             :     }
    2920             : 
    2921         898 :     return IVAS_ERR_OK;
    2922             : }
    2923             : 
    2924             : 
    2925             : /*---------------------------------------------------------------------*
    2926             :  * IVAS_DEC_HRTF_binary_close( )
    2927             :  *
    2928             :  * Deallocate HRTF binary handles
    2929             :  *---------------------------------------------------------------------*/
    2930             : 
    2931         449 : ivas_error IVAS_DEC_HRTF_binary_close(
    2932             :     IVAS_DEC_HANDLE hIvasDec,                          /* i/o: IVAS decoder handle              */
    2933             :     const IVAS_BIN_RENDERER_TYPE binaural_renderer_old /* i  : previous binaural renderer type  */
    2934             : )
    2935             : {
    2936             :     Decoder_Struct *st_ivas;
    2937             : 
    2938         449 :     test();
    2939         449 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    2940             :     {
    2941           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    2942             :     }
    2943             : 
    2944         449 :     st_ivas = hIvasDec->st_ivas;
    2945             : 
    2946         449 :     test();
    2947         449 :     IF( st_ivas->hDecoderConfig->Opt_HRTF_binary && st_ivas->ini_frame > 0 )
    2948             :     {
    2949         425 :         test();
    2950         425 :         IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_TDREND ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) )
    2951             :         {
    2952         422 :             ivas_HRTF_binary_close_fx( &st_ivas->hHrtfTD );
    2953             :         }
    2954             : 
    2955         425 :         test();
    2956         425 :         IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_CREND ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) )
    2957             :         {
    2958             :             /* CRend binaural renderer handle */
    2959         402 :             ivas_HRTF_CRend_binary_close_fx( &st_ivas->hHrtfCrend );
    2960             :         }
    2961             : 
    2962         425 :         test();
    2963         425 :         IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_FASTCONV ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) )
    2964             :         {
    2965             :             /* Fastconv HRTF memories */
    2966         360 :             ivas_binaural_hrtf_close_fx( &st_ivas->hHrtfFastConv );
    2967             : 
    2968             :             /* Fastconv HRTF filters */
    2969         360 :             ivas_HRTF_fastconv_binary_close_fx( &st_ivas->hHrtfFastConv );
    2970             :         }
    2971             : 
    2972         425 :         test();
    2973         425 :         IF( !( EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_PARAMBIN ) || EQ_32( binaural_renderer_old, IVAS_BIN_RENDERER_TYPE_DEFAULT ) ) )
    2974             :         {
    2975             :             /* Parametric binauralizer HRTF filters */
    2976          91 :             ivas_HRTF_parambin_binary_close_fx( &st_ivas->hHrtfParambin );
    2977             :         }
    2978             :     }
    2979             : 
    2980         449 :     return IVAS_ERR_OK;
    2981             : }
    2982             : 
    2983             : 
    2984             : #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT
    2985             : /*---------------------------------------------------------------------*
    2986             :  * IVAS_DEC_AddAcousticEnvironment( )
    2987             :  *
    2988             :  * Adds acoustic environment configuration
    2989             :  *---------------------------------------------------------------------*/
    2990             : 
    2991          43 : ivas_error IVAS_DEC_AddAcousticEnvironment(
    2992             :     IVAS_DEC_HANDLE hIvasDec,                                 /* i/o: IVAS decoder handle         */
    2993             :     const IVAS_ROOM_ACOUSTICS_CONFIG_DATA roomAcousticsConfig /* i  : Room acoustic configuration */
    2994             : )
    2995             : {
    2996             :     Word16 n;
    2997             :     Decoder_Struct *st_ivas;
    2998          43 :     IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAE = NULL;
    2999             : 
    3000          43 :     test();
    3001          43 :     test();
    3002          43 :     test();
    3003          43 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || ( hIvasDec->st_ivas->acousticEnvironmentsCount > 0 && hIvasDec->st_ivas->pAcousticEnvironments == NULL ) )
    3004             :     {
    3005           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3006             :     }
    3007             : 
    3008          43 :     st_ivas = hIvasDec->st_ivas;
    3009             : 
    3010             :     /* Check if already there */
    3011          64 :     FOR( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ )
    3012             :     {
    3013          21 :         IF( st_ivas->pAcousticEnvironments[n].aeID == roomAcousticsConfig.aeID )
    3014             :         {
    3015           0 :             move32();
    3016           0 :             pAE = &st_ivas->pAcousticEnvironments[n];
    3017           0 :             break;
    3018             :         }
    3019             :     }
    3020             : 
    3021             :     /* If not found */
    3022          43 :     IF( pAE == NULL )
    3023             :     {
    3024          43 :         IVAS_ROOM_ACOUSTICS_CONFIG_DATA *ppAE = malloc( ( st_ivas->acousticEnvironmentsCount + 1 ) * sizeof( IVAS_ROOM_ACOUSTICS_CONFIG_DATA ) );
    3025             : 
    3026          43 :         IF( ppAE == NULL )
    3027             :         {
    3028           0 :             return IVAS_ERR_FAILED_ALLOC;
    3029             :         }
    3030             : 
    3031          64 :         FOR( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ )
    3032             :         {
    3033          21 :             pAE = &ppAE[n];
    3034          21 :             pAE->aeID = st_ivas->pAcousticEnvironments[n].aeID;
    3035          21 :             pAE->nBands = st_ivas->pAcousticEnvironments[n].nBands;
    3036          21 :             pAE->acousticPreDelay_fx = st_ivas->pAcousticEnvironments[n].acousticPreDelay_fx;
    3037          21 :             pAE->inputPreDelay_fx = st_ivas->pAcousticEnvironments[n].inputPreDelay_fx;
    3038             : 
    3039          21 :             Copy32( st_ivas->pAcousticEnvironments[n].pFc_input_fx, pAE->pFc_input_fx, CLDFB_NO_CHANNELS_MAX );           // Q16
    3040          21 :             Copy32( st_ivas->pAcousticEnvironments[n].pAcoustic_rt60_fx, pAE->pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26
    3041          21 :             Copy32( st_ivas->pAcousticEnvironments[n].pAcoustic_dsr_fx, pAE->pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX );   // Q30
    3042             : 
    3043          21 :             pAE->use_er = st_ivas->pAcousticEnvironments[n].use_er;
    3044             : 
    3045          21 :             move16();
    3046          21 :             move16();
    3047          21 :             move32();
    3048          21 :             move32();
    3049          21 :             move16();
    3050             : 
    3051          21 :             IF( EQ_16( pAE->use_er, 1 ) )
    3052             :             {
    3053           7 :                 pAE->lowComplexity = st_ivas->pAcousticEnvironments[n].lowComplexity;
    3054           7 :                 move32();
    3055             : 
    3056           7 :                 pAE->dimensions.x_fx = st_ivas->pAcousticEnvironments[n].dimensions.x_fx;
    3057           7 :                 pAE->dimensions.y_fx = st_ivas->pAcousticEnvironments[n].dimensions.y_fx;
    3058           7 :                 pAE->dimensions.z_fx = st_ivas->pAcousticEnvironments[n].dimensions.z_fx;
    3059           7 :                 move32();
    3060           7 :                 move32();
    3061           7 :                 move32();
    3062             : 
    3063           7 :                 pAE->ListenerOrigin.x_fx = st_ivas->pAcousticEnvironments[n].ListenerOrigin.x_fx;
    3064           7 :                 pAE->ListenerOrigin.y_fx = st_ivas->pAcousticEnvironments[n].ListenerOrigin.y_fx;
    3065           7 :                 pAE->ListenerOrigin.z_fx = st_ivas->pAcousticEnvironments[n].ListenerOrigin.z_fx;
    3066           7 :                 move32();
    3067           7 :                 move32();
    3068           7 :                 move32();
    3069             : 
    3070           7 :                 Copy32( st_ivas->pAcousticEnvironments[n].AbsCoeff_fx, pAE->AbsCoeff_fx, IVAS_ROOM_ABS_COEFF );
    3071             :             }
    3072             :         }
    3073             : 
    3074          43 :         free( st_ivas->pAcousticEnvironments );
    3075          43 :         st_ivas->pAcousticEnvironments = ppAE;
    3076             : 
    3077          43 :         n = st_ivas->acousticEnvironmentsCount++;
    3078          43 :         pAE = &st_ivas->pAcousticEnvironments[n];
    3079          43 :         move32();
    3080          43 :         move16();
    3081          43 :         move32();
    3082             :     }
    3083             : 
    3084          43 :     pAE->aeID = roomAcousticsConfig.aeID;
    3085          43 :     pAE->nBands = roomAcousticsConfig.nBands;
    3086          43 :     pAE->acousticPreDelay_fx = roomAcousticsConfig.acousticPreDelay_fx;
    3087          43 :     pAE->inputPreDelay_fx = roomAcousticsConfig.inputPreDelay_fx;
    3088             : 
    3089          43 :     Copy32( roomAcousticsConfig.pFc_input_fx, pAE->pFc_input_fx, CLDFB_NO_CHANNELS_MAX );           // Q16
    3090          43 :     Copy32( roomAcousticsConfig.pAcoustic_rt60_fx, pAE->pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26
    3091          43 :     Copy32( roomAcousticsConfig.pAcoustic_dsr_fx, pAE->pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX );   // Q30
    3092             : 
    3093          43 :     pAE->use_er = roomAcousticsConfig.use_er;
    3094             : 
    3095          43 :     move16();
    3096          43 :     move16();
    3097          43 :     move32();
    3098          43 :     move32();
    3099          43 :     move16();
    3100             : 
    3101          43 :     IF( EQ_16( pAE->use_er, 1 ) )
    3102             :     {
    3103          18 :         pAE->lowComplexity = roomAcousticsConfig.lowComplexity;
    3104          18 :         move32();
    3105             : 
    3106          18 :         pAE->dimensions.x_fx = roomAcousticsConfig.dimensions.x_fx;
    3107          18 :         pAE->dimensions.y_fx = roomAcousticsConfig.dimensions.y_fx;
    3108          18 :         pAE->dimensions.z_fx = roomAcousticsConfig.dimensions.z_fx;
    3109          18 :         move32();
    3110          18 :         move32();
    3111          18 :         move32();
    3112             : 
    3113          18 :         pAE->ListenerOrigin.x_fx = roomAcousticsConfig.ListenerOrigin.x_fx;
    3114          18 :         pAE->ListenerOrigin.y_fx = roomAcousticsConfig.ListenerOrigin.y_fx;
    3115          18 :         pAE->ListenerOrigin.z_fx = roomAcousticsConfig.ListenerOrigin.z_fx;
    3116          18 :         move32();
    3117          18 :         move32();
    3118          18 :         move32();
    3119             : 
    3120          18 :         Copy32( roomAcousticsConfig.AbsCoeff_fx, pAE->AbsCoeff_fx, IVAS_ROOM_ABS_COEFF );
    3121             :     }
    3122             : 
    3123          43 :     return IVAS_ERR_OK;
    3124             : }
    3125             : 
    3126             : 
    3127             : /*---------------------------------------------------------------------*
    3128             :  * IVAS_DEC_GetAcousticEnvironment( )
    3129             :  *
    3130             :  * Gets acoustic environment configuration with a given ID
    3131             :  *---------------------------------------------------------------------*/
    3132             : 
    3133          29 : ivas_error IVAS_DEC_GetAcousticEnvironment(
    3134             :     IVAS_DEC_HANDLE hIvasDec,               /* i/o: IVAS decoder handle                     */
    3135             :     UWord16 aeID,                           /* i  : Acoustic environment ID                 */
    3136             :     IVAS_ROOM_ACOUSTICS_CONFIG_DATA *pAcEnv /* o  : Room acoustic environment data pointer  */
    3137             : )
    3138             : {
    3139             :     Word16 n, m;
    3140          29 :     Word16 found = 0;
    3141          29 :     move16();
    3142             :     Decoder_Struct *st_ivas;
    3143             : 
    3144          29 :     test();
    3145          29 :     IF( hIvasDec == NULL || pAcEnv == NULL )
    3146             :     {
    3147           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3148             :     }
    3149             : 
    3150          29 :     st_ivas = hIvasDec->st_ivas;
    3151          29 :     move32();
    3152             : 
    3153             :     /* In case of default AE ID, select the first one available */
    3154          29 :     test();
    3155          29 :     IF( aeID == (UWord16) IVAS_DEFAULT_AEID && st_ivas->acousticEnvironmentsCount > 0 )
    3156             :     {
    3157          25 :         aeID = st_ivas->pAcousticEnvironments[0].aeID;
    3158          25 :         move32();
    3159             :     }
    3160             : 
    3161          72 :     FOR( n = 0; n < st_ivas->acousticEnvironmentsCount; n++ )
    3162             :     {
    3163          43 :         IVAS_ROOM_ACOUSTICS_CONFIG_DATA ae = st_ivas->pAcousticEnvironments[n];
    3164          43 :         move32();
    3165          43 :         IF( aeID == ae.aeID )
    3166             :         {
    3167          29 :             found = 1;
    3168          29 :             pAcEnv->aeID = aeID;
    3169          29 :             pAcEnv->nBands = ae.nBands;
    3170          29 :             pAcEnv->inputPreDelay_fx = ae.inputPreDelay_fx;
    3171          29 :             move16();
    3172          29 :             move16();
    3173          29 :             move16();
    3174          29 :             move32();
    3175             : 
    3176         879 :             FOR( m = 0; m < pAcEnv->nBands; m++ )
    3177             :             {
    3178         850 :                 pAcEnv->pFc_input_fx[m] = ae.pFc_input_fx[m];
    3179         850 :                 pAcEnv->pAcoustic_rt60_fx[m] = ae.pAcoustic_rt60_fx[m];
    3180         850 :                 pAcEnv->pAcoustic_dsr_fx[m] = ae.pAcoustic_dsr_fx[m];
    3181         850 :                 move32();
    3182         850 :                 move32();
    3183         850 :                 move32();
    3184             :             }
    3185             : 
    3186             :             /* If ER are allocated then propagate parameters */
    3187          29 :             pAcEnv->use_er = ae.use_er;
    3188          29 :             move16();
    3189             : 
    3190          29 :             IF( ae.use_er != 0 )
    3191             :             {
    3192           7 :                 pAcEnv->lowComplexity = ae.lowComplexity;
    3193           7 :                 move32();
    3194             : 
    3195           7 :                 pAcEnv->dimensions.x_fx = ae.dimensions.x_fx;
    3196           7 :                 pAcEnv->dimensions.y_fx = ae.dimensions.y_fx;
    3197           7 :                 pAcEnv->dimensions.z_fx = ae.dimensions.z_fx;
    3198           7 :                 move32();
    3199           7 :                 move32();
    3200           7 :                 move32();
    3201             : 
    3202           7 :                 pAcEnv->ListenerOrigin.x_fx = ae.ListenerOrigin.x_fx;
    3203           7 :                 pAcEnv->ListenerOrigin.y_fx = ae.ListenerOrigin.y_fx;
    3204           7 :                 pAcEnv->ListenerOrigin.z_fx = ae.ListenerOrigin.z_fx;
    3205           7 :                 move32();
    3206           7 :                 move32();
    3207           7 :                 move32();
    3208             : 
    3209           7 :                 Copy32( ae.AbsCoeff_fx, pAcEnv->AbsCoeff_fx, IVAS_ROOM_ABS_COEFF );
    3210             :             }
    3211             :         }
    3212             :     }
    3213             : 
    3214          29 :     IF( found == 0 )
    3215             :     {
    3216           0 :         return IVAS_ERR_ACOUSTIC_ENVIRONMENT_MISSING;
    3217             :     }
    3218             :     ELSE
    3219             :     {
    3220          29 :         return IVAS_ERR_OK;
    3221             :     }
    3222             : }
    3223             : 
    3224             : #endif
    3225             : 
    3226             : /*---------------------------------------------------------------------*
    3227             :  * copyRendererConfigStruct( )
    3228             :  *
    3229             :  *
    3230             :  *---------------------------------------------------------------------*/
    3231             : 
    3232          64 : static ivas_error copyRendererConfigStruct(
    3233             :     RENDER_CONFIG_HANDLE hRCin,
    3234             :     IVAS_RENDER_CONFIG_HANDLE hRCout )
    3235             : {
    3236          64 :     test();
    3237          64 :     IF( hRCin == NULL || hRCout == NULL )
    3238             :     {
    3239           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3240             :     }
    3241             : 
    3242             : #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT
    3243          64 :     hRCout->roomAcoustics.aeID = hRCin->roomAcoustics.aeID;
    3244          64 :     move16();
    3245             : #endif
    3246          64 :     hRCout->roomAcoustics.nBands = hRCin->roomAcoustics.nBands;
    3247          64 :     hRCout->roomAcoustics.acousticPreDelay_fx = hRCin->roomAcoustics.acousticPreDelay_fx;
    3248          64 :     hRCout->roomAcoustics.inputPreDelay_fx = hRCin->roomAcoustics.inputPreDelay_fx;
    3249             : 
    3250          64 :     Copy32( hRCin->roomAcoustics.pFc_input_fx, hRCout->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX );           // Q16
    3251          64 :     Copy32( hRCin->roomAcoustics.pAcoustic_rt60_fx, hRCout->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26
    3252          64 :     Copy32( hRCin->roomAcoustics.pAcoustic_dsr_fx, hRCout->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX );   // Q30
    3253          64 :     Copy( hRCin->directivity_fx, hRCout->directivity_fx, 3 * MAX_NUM_OBJECTS );
    3254          64 :     Copy32( hRCin->distAtt_fx, hRCout->distAtt_fx, 3 );
    3255             : 
    3256          64 :     hRCout->split_rend_config = hRCin->split_rend_config;
    3257             : 
    3258          64 :     hRCout->roomAcoustics.use_er = hRCin->roomAcoustics.use_er;
    3259          64 :     hRCout->roomAcoustics.lowComplexity = hRCin->roomAcoustics.lowComplexity;
    3260          64 :     move16();
    3261          64 :     move16();
    3262          64 :     move16();
    3263          64 :     move32();
    3264          64 :     move32();
    3265          64 :     move32();
    3266             : 
    3267          64 :     return IVAS_ERR_OK;
    3268             : }
    3269             : 
    3270             : 
    3271             : /*---------------------------------------------------------------------*
    3272             :  * IVAS_DEC_GetRenderConfig( )
    3273             :  *
    3274             :  * Return renderer configuration parameters handle
    3275             :  *---------------------------------------------------------------------*/
    3276             : 
    3277          64 : ivas_error IVAS_DEC_GetRenderConfig(
    3278             :     IVAS_DEC_HANDLE hIvasDec,              /* i/o: IVAS decoder handle         */
    3279             :     const IVAS_RENDER_CONFIG_HANDLE hRCout /* o  : Render configuration handle */
    3280             : )
    3281             : {
    3282          64 :     test();
    3283          64 :     test();
    3284          64 :     test();
    3285          64 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL || hRCout == NULL )
    3286             :     {
    3287           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3288             :     }
    3289             : 
    3290          64 :     return copyRendererConfigStruct( hIvasDec->st_ivas->hRenderConfig, hRCout );
    3291             : }
    3292             : 
    3293             : 
    3294             : /*---------------------------------------------------------------------*
    3295             :  * IVAS_DEC_GetDefaultRenderConfig( )
    3296             :  *
    3297             :  * Return default renderer configuration parameters
    3298             :  *---------------------------------------------------------------------*/
    3299             : 
    3300             : /*! r: error code*/
    3301           0 : ivas_error IVAS_DEC_GetDefaultRenderConfig(
    3302             :     IVAS_RENDER_CONFIG_HANDLE hRCout /* o  : Render config handle   */
    3303             : )
    3304             : {
    3305             :     RENDER_CONFIG_DATA RCin;
    3306           0 :     RENDER_CONFIG_HANDLE hRCin = &RCin;
    3307             :     ivas_error error;
    3308             : 
    3309           0 :     IF( NE_32( ( error = ivas_render_config_init_from_rom_fx( &hRCin ) ), IVAS_ERR_OK ) )
    3310             :     {
    3311           0 :         return error;
    3312             :     }
    3313             : 
    3314           0 :     return copyRendererConfigStruct( hRCin, hRCout );
    3315             : }
    3316             : 
    3317             : 
    3318             : /*---------------------------------------------------------------------*
    3319             :  * IVAS_DEC_FeedRenderConfig( )
    3320             :  *
    3321             :  * Set renderer configuration (acoustic environment) parameters
    3322             :  *---------------------------------------------------------------------*/
    3323             : 
    3324          43 : ivas_error IVAS_DEC_FeedRenderConfig(
    3325             :     IVAS_DEC_HANDLE hIvasDec,                  /* i/o: IVAS decoder handle         */
    3326             :     const IVAS_RENDER_CONFIG_DATA renderConfig /* i  : Render configuration struct */
    3327             : )
    3328             : {
    3329             :     RENDER_CONFIG_HANDLE hRenderConfig;
    3330             :     Decoder_Struct *st_ivas;
    3331             :     ivas_error error;
    3332             : 
    3333          43 :     test();
    3334          43 :     test();
    3335          43 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL )
    3336             :     {
    3337           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3338             :     }
    3339             : 
    3340          43 :     hRenderConfig = hIvasDec->st_ivas->hRenderConfig;
    3341          43 :     st_ivas = hIvasDec->st_ivas;
    3342             : 
    3343             : #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT
    3344          43 :     hRenderConfig->roomAcoustics.aeID = renderConfig.roomAcoustics.aeID;
    3345          43 :     move16();
    3346             : #endif
    3347          43 :     hRenderConfig->roomAcoustics.nBands = renderConfig.roomAcoustics.nBands;
    3348          43 :     hRenderConfig->roomAcoustics.acousticPreDelay_fx = renderConfig.roomAcoustics.acousticPreDelay_fx;
    3349          43 :     hRenderConfig->roomAcoustics.inputPreDelay_fx = renderConfig.roomAcoustics.inputPreDelay_fx;
    3350             : 
    3351          43 :     hRenderConfig->roomAcoustics.use_er = 0;
    3352          43 :     move16();
    3353          43 :     move16();
    3354          43 :     move16();
    3355          43 :     move32();
    3356          43 :     move32();
    3357          43 :     IF( EQ_16( renderConfig.roomAcoustics.use_er, 1 ) )
    3358             :     {
    3359          14 :         hRenderConfig->roomAcoustics.use_er = renderConfig.roomAcoustics.use_er;
    3360          14 :         hRenderConfig->roomAcoustics.lowComplexity = renderConfig.roomAcoustics.lowComplexity;
    3361          14 :         hRenderConfig->roomAcoustics.dimensions = renderConfig.roomAcoustics.dimensions;
    3362          14 :         hRenderConfig->roomAcoustics.ListenerOrigin = renderConfig.roomAcoustics.ListenerOrigin;
    3363             : 
    3364          14 :         Copy32( renderConfig.roomAcoustics.AbsCoeff_fx, hRenderConfig->roomAcoustics.AbsCoeff_fx, IVAS_ROOM_ABS_COEFF );
    3365          14 :         move16();
    3366          14 :         move32();
    3367             :     }
    3368             : 
    3369          43 :     Copy32( renderConfig.roomAcoustics.pFc_input_fx, hRenderConfig->roomAcoustics.pFc_input_fx, CLDFB_NO_CHANNELS_MAX );           // Q16
    3370          43 :     Copy32( renderConfig.roomAcoustics.pAcoustic_rt60_fx, hRenderConfig->roomAcoustics.pAcoustic_rt60_fx, CLDFB_NO_CHANNELS_MAX ); // Q26
    3371          43 :     Copy32( renderConfig.roomAcoustics.pAcoustic_dsr_fx, hRenderConfig->roomAcoustics.pAcoustic_dsr_fx, CLDFB_NO_CHANNELS_MAX );   // Q30
    3372             : 
    3373             :     /* Re-initialize reverb instance if already available */
    3374             : 
    3375             :     /* TD renderer Jot reverberator */
    3376          43 :     IF( st_ivas->hReverb != NULL )
    3377             :     {
    3378           0 :         IF( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
    3379             :         {
    3380           0 :             return error;
    3381             :         }
    3382             :     }
    3383             : 
    3384             :     /* CREND Jot reverberator */
    3385          43 :     test();
    3386          43 :     test();
    3387          43 :     IF( st_ivas->hCrendWrapper != NULL && st_ivas->hCrendWrapper->hCrend[0] != NULL && st_ivas->hCrendWrapper->hCrend[0]->hReverb != NULL )
    3388             :     {
    3389           4 :         IF( ( error = ivas_reverb_open_fx( &st_ivas->hCrendWrapper->hCrend[0]->hReverb, hIvasDec->st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
    3390             :         {
    3391           0 :             return error;
    3392             :         }
    3393             :     }
    3394             : 
    3395             :     /* Parametric renderer reverberator */
    3396          43 :     test();
    3397          43 :     IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->hReverb != NULL )
    3398             :     {
    3399           4 :         ivas_binaural_reverb_close_fx( &( st_ivas->hDiracDecBin[0]->hReverb ) );
    3400             : 
    3401           4 :         IF( ( error = ivas_binaural_reverb_init_fx( &( 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 )
    3402             :         {
    3403           0 :             return error;
    3404             :         }
    3405             :     }
    3406             : 
    3407             :     /* FastConv renderer reverberator */
    3408          43 :     test();
    3409          43 :     IF( st_ivas->hBinRenderer != NULL && st_ivas->hBinRenderer->hReverb != NULL )
    3410             :     {
    3411           3 :         ivas_binaural_reverb_close_fx( &( st_ivas->hBinRenderer->hReverb ) );
    3412             : 
    3413           3 :         IF( ( error = ivas_binaural_reverb_init_fx( &( 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 )
    3414             :         {
    3415           0 :             return error;
    3416             :         }
    3417             :     }
    3418             : 
    3419          43 :     Copy( renderConfig.directivity_fx, hRenderConfig->directivity_fx, 3 * MAX_NUM_OBJECTS );
    3420          43 :     Copy32( renderConfig.distAtt_fx, hRenderConfig->distAtt_fx, 3 );
    3421             : 
    3422          43 :     hRenderConfig->split_rend_config = renderConfig.split_rend_config;
    3423             : 
    3424             :     /* Overwrite any pose correction settings if 0 DOF (no pose correction) was selected */
    3425          43 :     IF( hRenderConfig->split_rend_config.dof == 0 )
    3426             :     {
    3427           0 :         hRenderConfig->split_rend_config.poseCorrectionMode = ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE;
    3428           0 :         move16();
    3429             :     }
    3430             : 
    3431          43 :     IF( is_split_rendering_enabled( st_ivas->hDecoderConfig, hRenderConfig ) )
    3432             :     {
    3433           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 )
    3434             :         {
    3435           0 :             return error;
    3436             :         }
    3437             :     }
    3438             : 
    3439          43 :     return IVAS_ERR_OK;
    3440             : }
    3441             : 
    3442             : #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT
    3443             : 
    3444             : /*---------------------------------------------------------------------*
    3445             :  * feedAcousticEnvPI( )
    3446             :  *
    3447             :  * Set acoustic environment from the PI data
    3448             :  *---------------------------------------------------------------------*/
    3449             : 
    3450           0 : static ivas_error feedAcousticEnvPI(
    3451             :     IVAS_DEC_HANDLE hIvasDec,                   /* i/o: IVAS decoder handle         */
    3452             :     const IVAS_PIDATA_ACOUSTIC_ENV hAcoustEnvPI /* i  : Render configuration struct */
    3453             : )
    3454             : {
    3455             :     RENDER_CONFIG_HANDLE hRenderConfig;
    3456             :     Decoder_Struct *st_ivas;
    3457             :     ivas_error error;
    3458             : 
    3459           0 :     test();
    3460           0 :     test();
    3461           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hRenderConfig == NULL )
    3462             :     {
    3463           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3464             :     }
    3465             : 
    3466           0 :     hRenderConfig = hIvasDec->st_ivas->hRenderConfig;
    3467           0 :     st_ivas = hIvasDec->st_ivas;
    3468           0 :     move32();
    3469           0 :     move32();
    3470             : 
    3471             :     /* Ignore if AE ID already in use */
    3472           0 :     IF( EQ_16( hRenderConfig->roomAcoustics.aeID, hAcoustEnvPI.aeid ) )
    3473             :     {
    3474           0 :         return IVAS_ERR_OK;
    3475             :     }
    3476             : 
    3477             :     /* Attempt to load the one already available */
    3478           0 :     IF( ( error = IVAS_DEC_GetAcousticEnvironment( hIvasDec, hAcoustEnvPI.aeid, &hRenderConfig->roomAcoustics ) ) == IVAS_ERR_ACOUSTIC_ENVIRONMENT_MISSING )
    3479             :     {
    3480             :         /* Add the new compact room environment */
    3481             :         IVAS_ROOM_ACOUSTICS_CONFIG_DATA acEnv;
    3482             : 
    3483           0 :         acEnv.aeID = hAcoustEnvPI.aeid;
    3484           0 :         acEnv.nBands = IVAS_PI_AE_NUM_BANDS;
    3485           0 :         move16();
    3486           0 :         move16();
    3487             : 
    3488           0 :         acEnv.pFc_input_fx[IVAS_PI_AE_LOW] = IVAS_PI_AE_LOW_FREQ * 0x10000; /* Q16 */
    3489           0 :         acEnv.pFc_input_fx[IVAS_PI_AE_MID] = IVAS_PI_AE_MID_FREQ * 0x10000;
    3490           0 :         acEnv.pFc_input_fx[IVAS_PI_AE_HIGH] = IVAS_PI_AE_HIGH_FREQ * 0x10000;
    3491           0 :         move32();
    3492           0 :         move32();
    3493           0 :         move32();
    3494             : 
    3495           0 :         acEnv.pAcoustic_rt60_fx[IVAS_PI_AE_LOW] = hAcoustEnvPI.rt60_fx[IVAS_PI_AE_LOW];
    3496           0 :         acEnv.pAcoustic_rt60_fx[IVAS_PI_AE_MID] = hAcoustEnvPI.rt60_fx[IVAS_PI_AE_MID];
    3497           0 :         acEnv.pAcoustic_rt60_fx[IVAS_PI_AE_HIGH] = hAcoustEnvPI.rt60_fx[IVAS_PI_AE_HIGH];
    3498           0 :         acEnv.inputPreDelay_fx = ( ( hAcoustEnvPI.rt60_fx[IVAS_PI_AE_MID] * 0x00CCCCC ) >> 26 ); /* Q26 RT60[MID] / 10 -> Q27 */
    3499           0 :         move32();
    3500           0 :         move32();
    3501           0 :         move32();
    3502           0 :         move32();
    3503             : 
    3504           0 :         acEnv.pAcoustic_dsr_fx[IVAS_PI_AE_LOW] = hAcoustEnvPI.dsr_fx[IVAS_PI_AE_LOW];
    3505           0 :         acEnv.pAcoustic_dsr_fx[IVAS_PI_AE_MID] = hAcoustEnvPI.dsr_fx[IVAS_PI_AE_MID];
    3506           0 :         acEnv.pAcoustic_dsr_fx[IVAS_PI_AE_HIGH] = hAcoustEnvPI.dsr_fx[IVAS_PI_AE_HIGH];
    3507           0 :         move32();
    3508           0 :         move32();
    3509           0 :         move32();
    3510             : 
    3511           0 :         acEnv.use_er = hAcoustEnvPI.availEarlyReflections;
    3512           0 :         move16();
    3513             : 
    3514           0 :         IF( hAcoustEnvPI.availEarlyReflections )
    3515             :         {
    3516           0 :             hRenderConfig->roomAcoustics.dimensions.x_fx = hAcoustEnvPI.roomDimensions.x_fx;
    3517           0 :             hRenderConfig->roomAcoustics.dimensions.y_fx = hAcoustEnvPI.roomDimensions.y_fx;
    3518           0 :             hRenderConfig->roomAcoustics.dimensions.z_fx = hAcoustEnvPI.roomDimensions.z_fx;
    3519           0 :             move32();
    3520           0 :             move32();
    3521           0 :             move32();
    3522             : 
    3523           0 :             Copy32( hAcoustEnvPI.absorbCoeffs_fx, hRenderConfig->roomAcoustics.AbsCoeff_fx, IVAS_ROOM_ABS_COEFF );
    3524             :         }
    3525             : 
    3526           0 :         IF( ( error = IVAS_DEC_AddAcousticEnvironment( hIvasDec, acEnv ) ) != IVAS_ERR_OK )
    3527             :         {
    3528           0 :             return error;
    3529             :         }
    3530             : 
    3531           0 :         IF( ( error = IVAS_DEC_GetAcousticEnvironment( hIvasDec, hAcoustEnvPI.aeid, &hRenderConfig->roomAcoustics ) ) != IVAS_ERR_OK )
    3532             :         {
    3533           0 :             return error;
    3534             :         }
    3535             :     }
    3536             : 
    3537             :     /* Re-initialize reverb instance if already available */
    3538             : 
    3539             :     /* TD renderer Jot reverberator */
    3540           0 :     IF( st_ivas->hReverb != NULL )
    3541             :     {
    3542           0 :         IF( ( error = ivas_reverb_open_fx( &st_ivas->hReverb, st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
    3543             :         {
    3544           0 :             return error;
    3545             :         }
    3546             :     }
    3547             : 
    3548             :     /* CREND Jot reverberator */
    3549           0 :     test();
    3550           0 :     test();
    3551           0 :     IF( st_ivas->hCrendWrapper != NULL && st_ivas->hCrendWrapper->hCrend[0] != NULL && st_ivas->hCrendWrapper->hCrend[0]->hReverb != NULL )
    3552             :     {
    3553           0 :         IF( ( error = ivas_reverb_open_fx( &st_ivas->hCrendWrapper->hCrend[0]->hReverb, st_ivas->hHrtfStatistics, hRenderConfig, st_ivas->hDecoderConfig->output_Fs ) ) != IVAS_ERR_OK )
    3554             :         {
    3555           0 :             return error;
    3556             :         }
    3557             :     }
    3558             : 
    3559             :     /* Parametric renderer reverberator */
    3560           0 :     test();
    3561           0 :     IF( st_ivas->hDiracDecBin[0] != NULL && st_ivas->hDiracDecBin[0]->hReverb != NULL )
    3562             :     {
    3563           0 :         ivas_binaural_reverb_close_fx( &( st_ivas->hDiracDecBin[0]->hReverb ) );
    3564             : 
    3565           0 :         IF( ( error = ivas_binaural_reverb_init_fx( &( st_ivas->hDiracDecBin[0]->hReverb ), st_ivas->hHrtfStatistics, st_ivas->hSpatParamRendCom->num_freq_bands, CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES,
    3566             :                                                     &( hRenderConfig->roomAcoustics ), st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK )
    3567             :         {
    3568           0 :             return error;
    3569             :         }
    3570             :     }
    3571             : 
    3572             :     /* FastConv renderer reverberator */
    3573           0 :     test();
    3574           0 :     IF( st_ivas->hBinRenderer != NULL && st_ivas->hBinRenderer->hReverb != NULL )
    3575             :     {
    3576           0 :         ivas_binaural_reverb_close_fx( &( st_ivas->hBinRenderer->hReverb ) );
    3577             : 
    3578           0 :         IF( ( error = ivas_binaural_reverb_init_fx( &( st_ivas->hBinRenderer->hReverb ), st_ivas->hHrtfStatistics, st_ivas->hBinRenderer->conv_band, st_ivas->hBinRenderer->timeSlots,
    3579             :                                                     &( hRenderConfig->roomAcoustics ), st_ivas->hDecoderConfig->output_Fs, NULL, NULL, NULL ) ) != IVAS_ERR_OK )
    3580             :         {
    3581           0 :             return error;
    3582             :         }
    3583             :     }
    3584             : 
    3585           0 :     return IVAS_ERR_OK;
    3586             : }
    3587             : 
    3588             : #endif
    3589             : 
    3590             : /*---------------------------------------------------------------------*
    3591             :  * IVAS_DEC_GetDelay( )
    3592             :  *
    3593             :  * Return IVAS decoder delay in nanoseconds
    3594             :  *---------------------------------------------------------------------*/
    3595             : 
    3596       20104 : ivas_error IVAS_DEC_GetDelay(
    3597             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                                            */
    3598             :     Word16 *nSamples,         /* o  : decoder delay in samples                                       */
    3599             :     Word32 *timeScale         /* o  : time scale of the delay, equal to decoder output sampling rate */
    3600             : )
    3601             : {
    3602             :     Decoder_Struct *st_ivas;
    3603             :     DECODER_CONFIG_HANDLE hDecoderConfig;
    3604             :     Word32 out_fs_fx;
    3605             : 
    3606       20104 :     test();
    3607       20104 :     test();
    3608       20104 :     test();
    3609       20104 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || nSamples == NULL || timeScale == NULL )
    3610             :     {
    3611           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3612             :     }
    3613             : 
    3614       20104 :     IF( !hIvasDec->hasDecodedFirstGoodFrame )
    3615             :     {
    3616             :         /* Delay depends on IVAS format, which is unknown until first frame has been decoded */
    3617           0 :         return IVAS_ERR_WAITING_FOR_BITSTREAM;
    3618             :     }
    3619             : 
    3620       20104 :     st_ivas = hIvasDec->st_ivas;
    3621       20104 :     hDecoderConfig = st_ivas->hDecoderConfig;
    3622             : 
    3623       20104 :     IF( NE_32( hDecoderConfig->output_Fs, 48000 ) )
    3624             :     {
    3625        2246 :         IF( NE_32( hDecoderConfig->output_Fs, 32000 ) )
    3626             :         {
    3627          81 :             out_fs_fx = FS_16K_IN_NS_Q31;
    3628             :         }
    3629             :         ELSE
    3630             :         {
    3631        2165 :             out_fs_fx = FS_32K_IN_NS_Q31;
    3632             :         }
    3633             :     }
    3634             :     ELSE
    3635             :     {
    3636       17858 :         out_fs_fx = FS_48K_IN_NS_Q31;
    3637             :     }
    3638       20104 :     move32();
    3639             : 
    3640       20104 :     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 ) ) );
    3641       20104 :     move16();
    3642       20104 :     nSamples[2] = extract_l( W_round64_L( W_mult0_32_32( L_shl( st_ivas->binaural_latency_ns, 1 ), out_fs_fx ) ) );
    3643       20104 :     move16();
    3644       20104 :     nSamples[0] = add( nSamples[1], nSamples[2] );
    3645       20104 :     move16();
    3646             : 
    3647       20104 :     test();
    3648       20104 :     IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) || EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) )
    3649             :     {
    3650             :         /* note: in MASA, all delay is compensated at the decoder by default, so subtract the encoder delay for print-out */
    3651       19587 :         nSamples[1] = sub( nSamples[1], NS2SA_FX2( hDecoderConfig->output_Fs, IVAS_ENC_DELAY_NS ) );
    3652       19587 :         move16();
    3653             :     }
    3654             : 
    3655       20104 :     *timeScale = hDecoderConfig->output_Fs;
    3656       20104 :     move32();
    3657             : 
    3658       20104 :     return IVAS_ERR_OK;
    3659             : }
    3660             : 
    3661             : 
    3662             : /*---------------------------------------------------------------------*
    3663             :  * IVAS_DEC_HasDecodedFirstGoodFrame( )
    3664             :  *
    3665             :  * Return flag indicating if the decoder has decoded a good frame
    3666             :  *---------------------------------------------------------------------*/
    3667             : 
    3668        1002 : ivas_error IVAS_DEC_HasDecodedFirstGoodFrame(
    3669             :     IVAS_DEC_HANDLE hIvasDec,      /* i/o: IVAS decoder handle                                                             */
    3670             :     bool *hasDecodedFirstGoodFrame /* o  : flag indicating if the decoder has decoded a good frame since it was configured */
    3671             : )
    3672             : {
    3673        1002 :     test();
    3674        1002 :     test();
    3675        1002 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hasDecodedFirstGoodFrame == NULL )
    3676             :     {
    3677           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3678             :     }
    3679             : 
    3680        1002 :     *hasDecodedFirstGoodFrame = hIvasDec->hasDecodedFirstGoodFrame;
    3681        1002 :     move16();
    3682             : 
    3683        1002 :     return IVAS_ERR_OK;
    3684             : }
    3685             : 
    3686             : 
    3687             : /*---------------------------------------------------------------------*
    3688             :  * isSidFrame( )
    3689             :  *
    3690             :  * Check if a frame contains a SID
    3691             :  *---------------------------------------------------------------------*/
    3692             : 
    3693       40525 : static bool isSidFrame(
    3694             :     const UWord16 size )
    3695             : {
    3696       40525 :     IF( EQ_16( size, ( SID_1k75 / FRAMES_PER_SEC ) ) )
    3697             :     {
    3698           0 :         return true; /* AMR-WB SID */
    3699             :     }
    3700       40525 :     ELSE IF( EQ_16( size, ( SID_2k40 / FRAMES_PER_SEC ) ) )
    3701             :     {
    3702           0 :         return true; /* EVS SID */
    3703             :     }
    3704       40525 :     ELSE IF( EQ_16( size, ( IVAS_SID_5k2 / FRAMES_PER_SEC ) ) )
    3705             :     {
    3706         264 :         return true; /* IVAS SID */
    3707             :     }
    3708             : 
    3709       40261 :     return false;
    3710             : }
    3711             : 
    3712             : 
    3713             : /*---------------------------------------------------------------------*
    3714             :  * bsCompactToSerial( )
    3715             :  *
    3716             :  * Bitstream conversion to Byte format
    3717             :  *---------------------------------------------------------------------*/
    3718             : 
    3719       40489 : static void bsCompactToSerial(
    3720             :     const UWord8 *compact,
    3721             :     UWord16 *serial,
    3722             :     const UWord16 num_bits )
    3723             : {
    3724             : /* Bitstream conversion is not counted towards complexity and memory usage */
    3725             : #define WMC_TOOL_SKIP
    3726             :     UWord32 i;
    3727       40489 :     UWord8 byte = 0;
    3728       40489 :     const UWord8 mask = 0x80;
    3729       40489 :     move16();
    3730       40489 :     move16();
    3731             : 
    3732    86448705 :     FOR( i = 0; i < num_bits; ++i )
    3733             :     {
    3734    86408216 :         if ( ( i % 8 ) == 0 )
    3735             :         {
    3736    10801027 :             byte = compact[i / 8];
    3737    10801027 :             move16();
    3738             :         }
    3739             : 
    3740    86408216 :         serial[i] = shr( s_and( byte, mask ), 7 );
    3741    86408216 :         move16();
    3742             : 
    3743    86408216 :         byte = (UWord8) shl( byte, 1 );
    3744             :     }
    3745             : 
    3746             :     /* Add 4 padding bytes required by core coder */
    3747     1336137 :     FOR( i = 0; i < 4 * 8; ++i )
    3748             :     {
    3749     1295648 :         serial[( num_bits + i )] = 0;
    3750     1295648 :         move16();
    3751             :     }
    3752             : #undef WMC_TOOL_SKIP
    3753       40489 : }
    3754             : 
    3755             : 
    3756             : /*---------------------------------------------------------------------*
    3757             :  * IVAS_DEC_VoIP_FeedFrame( )
    3758             :  *
    3759             :  * Feed RTP packet into internal jitter buffer
    3760             :  *---------------------------------------------------------------------*/
    3761             : 
    3762       40525 : ivas_error IVAS_DEC_VoIP_FeedFrame(
    3763             :     IVAS_DEC_HANDLE hIvasDec,        /* i/o: IVAS decoder handle                             */
    3764             :     UWord8 *au,                      /* i  : buffer containing input access unit             */
    3765             :     const UWord16 auSize,            /* i  : size of the access unit                         */
    3766             :     const UWord16 rtpSequenceNumber, /* i  : RTP sequence number (16 bits)                   */
    3767             :     const UWord32 rtpTimeStamp,      /* i  : RTP timestamp (32 bits)                         */
    3768             :     const UWord32 rcvTime_ms,        /* i  : receive time of the RTP packet in milliseconds  */
    3769             :     const bool qBit                  /* i  : Q bit for AMR-WB IO                             */
    3770             : )
    3771             : {
    3772             :     JB4_DATAUNIT_HANDLE dataUnit;
    3773             :     Word16 partialCopyFrameType, partialCopyOffset;
    3774             :     Word16 result;
    3775             : 
    3776       40525 :     test();
    3777       40525 :     test();
    3778       40525 :     IF( hIvasDec == NULL || hIvasDec->hVoIP == NULL || au == NULL )
    3779             :     {
    3780           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3781             :     }
    3782             : 
    3783       40525 :     IF( auSize == 0 )
    3784             :     {
    3785           0 :         return IVAS_ERR_OK; /* ignore empty/NO_DATA frame - shouldn't be transmitted in RTP */
    3786             :     }
    3787             : 
    3788       40525 :     IF( GT_16( shr( add( auSize, 7 ), 3 ), (Word16) MAX_AU_SIZE ) )
    3789             :     {
    3790           0 :         return IVAS_ERR_INVALID_BITSTREAM;
    3791             :     }
    3792             : 
    3793       40525 :     partialCopyFrameType = 0;
    3794       40525 :     move16();
    3795       40525 :     partialCopyOffset = 0;
    3796       40525 :     move16();
    3797             : 
    3798       40525 :     IF( EQ_16( hIvasDec->mode, (Word16) IVAS_DEC_MODE_EVS ) )
    3799             :     {
    3800             :         /* check if frame contains a partial copy and get its offset */
    3801        2050 :         evs_dec_previewFrame( au, auSize, &partialCopyFrameType, &partialCopyOffset );
    3802             :     }
    3803             : 
    3804             :     /* create data unit for primary copy in the frame */
    3805       40525 :     dataUnit = JB4_AllocDataUnit( hIvasDec->hVoIP->hJBM );
    3806       40525 :     mvc2c( au, dataUnit->data, shr( add( auSize, 7 ), 3 ) );
    3807       40525 :     dataUnit->dataSize = auSize;
    3808       40525 :     dataUnit->duration = 20;
    3809       40525 :     dataUnit->sequenceNumber = rtpSequenceNumber;
    3810       40525 :     dataUnit->silenceIndicator = isSidFrame( dataUnit->dataSize );
    3811       40525 :     move16();
    3812       40525 :     dataUnit->timeScale = 1000;
    3813       40525 :     dataUnit->rcvTime = rcvTime_ms;
    3814       40525 :     dataUnit->timeStamp = rtpTimeStamp;
    3815       40525 :     dataUnit->partial_frame = 0;
    3816       40525 :     dataUnit->partialCopyOffset = partialCopyOffset;
    3817       40525 :     dataUnit->qBit = qBit;
    3818       40525 :     move16();
    3819       40525 :     move16();
    3820       40525 :     move16();
    3821       40525 :     move16();
    3822       40525 :     move16();
    3823       40525 :     move32();
    3824       40525 :     move32();
    3825       40525 :     move32();
    3826       40525 :     move32();
    3827             : 
    3828             :     /* add the frame to the JBM */
    3829       40525 :     result = JB4_PushDataUnit( hIvasDec->hVoIP->hJBM, dataUnit, rcvTime_ms );
    3830       40525 :     IF( result != 0 )
    3831             :     {
    3832           0 :         return IVAS_ERR_UNKNOWN;
    3833             :     }
    3834             : 
    3835       40525 :     test();
    3836       40525 :     IF( NE_16( partialCopyFrameType, RF_NO_DATA ) && partialCopyOffset != 0 )
    3837             :     {
    3838             :         /* create data unit for partial copy in the frame */
    3839           0 :         dataUnit = JB4_AllocDataUnit( hIvasDec->hVoIP->hJBM );
    3840           0 :         mvc2c( au, dataUnit->data, shr( add( auSize, 7 ), 3 ) );
    3841           0 :         dataUnit->dataSize = auSize;
    3842           0 :         dataUnit->duration = 20;
    3843           0 :         dataUnit->sequenceNumber = rtpSequenceNumber;
    3844           0 :         dataUnit->silenceIndicator = 0; /* there are no partial copies for SID frames */
    3845           0 :         dataUnit->timeScale = 1000;
    3846           0 :         dataUnit->rcvTime = rcvTime_ms;
    3847           0 :         dataUnit->timeStamp = (UWord32) W_sub( rtpTimeStamp, imult3216( dataUnit->duration, partialCopyOffset ) );
    3848           0 :         move32();
    3849           0 :         dataUnit->partial_frame = 1;
    3850           0 :         dataUnit->partialCopyOffset = partialCopyOffset;
    3851           0 :         dataUnit->qBit = qBit;
    3852           0 :         move16();
    3853           0 :         move16();
    3854           0 :         move16();
    3855           0 :         move16();
    3856           0 :         move16();
    3857           0 :         move32();
    3858           0 :         move32();
    3859           0 :         move32();
    3860             : 
    3861             :         /* add the frame to the JBM */
    3862           0 :         result = JB4_PushDataUnit( hIvasDec->hVoIP->hJBM, dataUnit, rcvTime_ms );
    3863           0 :         IF( result != 0 )
    3864             :         {
    3865           0 :             return IVAS_ERR_UNKNOWN;
    3866             :         }
    3867             :     }
    3868             : 
    3869       40525 :     return IVAS_ERR_OK;
    3870             : }
    3871             : 
    3872             : 
    3873             : /*---------------------------------------------------------------------*
    3874             :  * IVAS_DEC_VoIP_SetScale( )
    3875             :  *
    3876             :  * Set the TSM scale
    3877             :  *---------------------------------------------------------------------*/
    3878             : 
    3879       43610 : ivas_error IVAS_DEC_VoIP_SetScale(
    3880             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                                                         */
    3881             :     const Word16 maxScaling,  /* i  : max allowed absolute difference in samples from the default 20ms frame size */
    3882             :     const Word16 scale        /* i  : TSM scale to set in percent of the default frame size                       */
    3883             : )
    3884             : {
    3885       43610 :     test();
    3886       43610 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    3887             :     {
    3888           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3889             :     }
    3890             : 
    3891       43610 :     IF( hIvasDec->st_ivas->hDecoderConfig->Opt_tsm == 0 )
    3892             :     {
    3893           0 :         return IVAS_ERR_TSM_NOT_ENABLED;
    3894             :     }
    3895             :     ELSE
    3896             :     {
    3897       43610 :         hIvasDec->tsm_scale = scale;
    3898       43610 :         hIvasDec->tsm_max_scaling = maxScaling;
    3899       43610 :         move16();
    3900       43610 :         move16();
    3901             :     }
    3902             : 
    3903       43610 :     return IVAS_ERR_OK;
    3904             : }
    3905             : 
    3906             : #ifdef VARIABLE_SPEED_DECODING
    3907             : 
    3908             : /*---------------------------------------------------------------------*
    3909             :  * IVAS_DEC_EnableTsm( )
    3910             :  *
    3911             :  * Enable Time-Scale Modification (TSM)
    3912             :  *---------------------------------------------------------------------*/
    3913             : 
    3914             : ivas_error IVAS_DEC_EnableTsm(
    3915             :     IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle   */
    3916             : )
    3917             : {
    3918             :     AUDIO_CONFIG output_config;
    3919             :     ivas_error error;
    3920             : 
    3921             :     test();
    3922             :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    3923             :     {
    3924             :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3925             :     }
    3926             : 
    3927             :     hIvasDec->st_ivas->hDecoderConfig->Opt_tsm = 1;
    3928             :     move16();
    3929             : 
    3930             :     /* Init flush buffer if necessary (only needed for binaural) */
    3931             :     output_config = hIvasDec->st_ivas->hDecoderConfig->output_config;
    3932             : 
    3933             :     test();
    3934             :     test();
    3935             :     test();
    3936             :     test();
    3937             :     test();
    3938             :     IF( hIvasDec->flushbuffer == NULL && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) || EQ_32( output_config == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) || EQ_32( output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ) )
    3939             :     {
    3940             :         IF( ( error = create_flush_buffer( hIvasDec ) ) != IVAS_ERR_OK )
    3941             :         {
    3942             :             return error;
    3943             :         }
    3944             :     }
    3945             : 
    3946             :     return IVAS_ERR_OK;
    3947             : }
    3948             : 
    3949             : 
    3950             : /*---------------------------------------------------------------------*
    3951             :  * IVAS_DEC_TSM_SetQuality( )
    3952             :  *
    3953             :  * set the quality theshold for the time scale modiciation that is used
    3954             :  * to determine if the TSM yielded a signal that satisfies the minimum
    3955             :  * quality requirements.
    3956             :  * quality is lower limit for minimum quality
    3957             :  * Range is [-2;2] - where positive values allow
    3958             :  * only pasting with same phase information
    3959             :  * Negative values would yield cross phased pasting
    3960             :  * When not setting the minimum quality with this function the default
    3961             :  * value used is 1.0f
    3962             :  *
    3963             :  *---------------------------------------------------------------------*/
    3964             : 
    3965             : ivas_error IVAS_DEC_TSM_SetQuality(
    3966             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle       */
    3967             :     const Word16 quality      /* i  : target TSM quality Q14    */
    3968             : )
    3969             : {
    3970             :     test();
    3971             :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    3972             :     {
    3973             :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    3974             :     }
    3975             : 
    3976             :     IF( !hIvasDec->st_ivas->hDecoderConfig->Opt_tsm )
    3977             :     {
    3978             :         return IVAS_ERR_TSM_NOT_ENABLED;
    3979             :     }
    3980             :     ELSE
    3981             :     {
    3982             :         hIvasDec->tsm_quality = quality; // Q14
    3983             :         move16();
    3984             :     }
    3985             : 
    3986             :     return IVAS_ERR_OK;
    3987             : }
    3988             : 
    3989             : #endif
    3990             : 
    3991             : /*---------------------------------------------------------------------*
    3992             :  * renderer_type_to_mode()
    3993             :  *
    3994             :  * Convert (codec library) renderer type to (API public) binaural renderer mode
    3995             :  *---------------------------------------------------------------------*/
    3996             : 
    3997             : /*! r: binaural renderer mode (API type) */
    3998      978658 : static IVAS_BIN_RENDERER_TYPE renderer_type_to_mode(
    3999             :     const RENDERER_TYPE renderer_type /* i  : renderer type (codec library type) */
    4000             : )
    4001             : {
    4002             :     IVAS_BIN_RENDERER_TYPE binaural_renderer;
    4003             : 
    4004      978658 :     SWITCH( renderer_type )
    4005             :     {
    4006       47328 :         case RENDERER_BINAURAL_OBJECTS_TD:
    4007       47328 :             binaural_renderer = IVAS_BIN_RENDERER_TYPE_TDREND;
    4008       47328 :             BREAK;
    4009       24495 :         case RENDERER_BINAURAL_MIXER_CONV:
    4010             :         case RENDERER_BINAURAL_MIXER_CONV_ROOM:
    4011       24495 :             binaural_renderer = IVAS_BIN_RENDERER_TYPE_CREND;
    4012       24495 :             BREAK;
    4013       27607 :         case RENDERER_BINAURAL_FASTCONV:
    4014       27607 :             binaural_renderer = IVAS_BIN_RENDERER_TYPE_FASTCONV;
    4015       27607 :             BREAK;
    4016       13320 :         case RENDERER_BINAURAL_FASTCONV_ROOM:
    4017       13320 :             binaural_renderer = IVAS_BIN_RENDERER_TYPE_FASTCONV;
    4018       13320 :             BREAK;
    4019       99916 :         case RENDERER_BINAURAL_PARAMETRIC:
    4020             :         case RENDERER_BINAURAL_PARAMETRIC_ROOM:
    4021       99916 :             binaural_renderer = IVAS_BIN_RENDERER_TYPE_PARAMBIN;
    4022       99916 :             BREAK;
    4023      765992 :         default:
    4024      765992 :             binaural_renderer = IVAS_BIN_RENDERER_TYPE_NONE;
    4025      765992 :             BREAK;
    4026             :     }
    4027      978658 :     move32();
    4028             : 
    4029      978658 :     return binaural_renderer;
    4030             : }
    4031             : 
    4032             : 
    4033             : /*---------------------------------------------------------------------*
    4034             :  * IVAS_DEC_ReadFormat( )
    4035             :  *
    4036             :  * Read main parameters from the bitstream to set-up the decoder:
    4037             :  * - IVAS format
    4038             :  * - IVAS format specific signaling
    4039             :  * - compensate for renderer granularity change in JBM
    4040             :  *---------------------------------------------------------------------*/
    4041             : 
    4042      504785 : ivas_error IVAS_DEC_ReadFormat(
    4043             :     IVAS_DEC_HANDLE hIvasDec,                      /* i/o: IVAS decoder handle                      */
    4044             :     IVAS_BIN_RENDERER_TYPE *binaural_renderer,     /* o  : binaural renderer type                   */
    4045             :     IVAS_BIN_RENDERER_TYPE *binaural_renderer_sec, /* o  : secondary binaural renderer type         */
    4046             :     IVAS_AUDIO_CONFIG *hrtf_set_audio_cfg          /* o  : HRTF set audio config.                   */
    4047             : )
    4048             : {
    4049             :     ivas_error error;
    4050             :     Decoder_Struct *st_ivas;
    4051             : #ifndef DECODER_FORMAT_SWITCHING
    4052             :     IVAS_FORMAT ivas_format_old;
    4053             : #endif
    4054             :     ISM_MODE ism_mode_old;
    4055             :     MC_MODE mc_mode_old;
    4056             :     Word16 nchan_transport_old;
    4057             :     AUDIO_CONFIG intern_config_old, transport_config_old, output_config;
    4058             :     RENDERER_TYPE renderer_type_old, renderer_type_sec_new, renderer_type_sec_old;
    4059             : 
    4060      504785 :     test();
    4061      504785 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    4062             :     {
    4063           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    4064             :     }
    4065             : 
    4066      504785 :     st_ivas = hIvasDec->st_ivas;
    4067             : #ifndef DECODER_FORMAT_SWITCHING
    4068             :     ivas_format_old = st_ivas->ivas_format;
    4069             : #endif
    4070      504785 :     ism_mode_old = st_ivas->ism_mode;
    4071      504785 :     mc_mode_old = st_ivas->mc_mode;
    4072      504785 :     nchan_transport_old = st_ivas->nchan_transport;
    4073      504785 :     intern_config_old = st_ivas->intern_config;
    4074      504785 :     transport_config_old = st_ivas->transport_config;
    4075      504785 :     renderer_type_old = st_ivas->renderer_type;
    4076      504785 :     renderer_type_sec_old = ivas_renderer_secondary_select_fx( st_ivas );
    4077      504785 :     move32();
    4078             : #ifndef DECODER_FORMAT_SWITCHING
    4079             :     move32();
    4080             : #endif
    4081      504785 :     move32();
    4082      504785 :     move16();
    4083      504785 :     move32();
    4084      504785 :     move32();
    4085      504785 :     move32();
    4086      504785 :     move32();
    4087             : 
    4088      504785 :     output_config = st_ivas->hDecoderConfig->output_config;
    4089      504785 :     move32();
    4090             : 
    4091      504785 :     IF( EQ_32( st_ivas->ivas_format, MONO_FORMAT ) )
    4092             :     {
    4093        5150 :         return IVAS_ERR_OK;
    4094             :     }
    4095             : 
    4096      499635 :     IF( st_ivas->bfi == 0 )
    4097             :     {
    4098      489329 :         IF( NE_32( error = ivas_dec_get_format_fx( st_ivas ), IVAS_ERR_OK ) )
    4099             :         {
    4100           0 :             return error;
    4101             :         }
    4102             : 
    4103             : #ifdef DECODER_FORMAT_SWITCHING
    4104      489329 :         IF( EQ_16( st_ivas->restartNeeded, 1 ) )
    4105             :         {
    4106           0 :             return IVAS_ERR_OK;
    4107             :         }
    4108             : #else
    4109             : 
    4110             :         test();
    4111             :         test();
    4112             :         test();
    4113             :         IF( NE_32( ivas_format_old, st_ivas->ivas_format ) && GT_16( st_ivas->ini_frame, 0 ) && ( NE_32( st_ivas->ivas_format, MASA_FORMAT ) && NE_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ) )
    4114             :         {
    4115             :             return ( IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "IVAS format switching is not allowed." ) );
    4116             :         }
    4117             : #endif
    4118             : 
    4119             :         /* Select binaural renderer */
    4120      489329 :         ivas_renderer_select( st_ivas );
    4121      489329 :         *binaural_renderer = renderer_type_to_mode( st_ivas->renderer_type );
    4122             : 
    4123             :         /* Select secondary binaural renderer (used in combined formats) */
    4124      489329 :         renderer_type_sec_new = ivas_renderer_secondary_select_fx( st_ivas );
    4125      489329 :         *binaural_renderer_sec = renderer_type_to_mode( renderer_type_sec_new );
    4126             : 
    4127             :         /* select HRTF audio configuration to load the right HRTF set for the external binary file */
    4128      489329 :         *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_INVALID;
    4129      489329 :         move32();
    4130      489329 :         IF( EQ_32( *binaural_renderer, IVAS_BIN_RENDERER_TYPE_FASTCONV ) )
    4131             :         {
    4132       40927 :             IF( EQ_32( st_ivas->ivas_format, SBA_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    4133             :             {
    4134             :                 /* SHD HRIRs */
    4135       31763 :                 *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_HOA3;
    4136       31763 :                 move32();
    4137             : 
    4138       31763 :                 IF( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
    4139             :                 {
    4140             :                     /* BRIRs */
    4141       10950 :                     *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_7_1_4;
    4142       10950 :                     move32();
    4143             :                 }
    4144             :             }
    4145        9164 :             ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) )
    4146             :             {
    4147             :                 /* HRIRs */
    4148        9164 :                 *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_7_1_4;
    4149        9164 :                 move32();
    4150        9164 :                 test();
    4151        9164 :                 test();
    4152        9164 :                 IF( st_ivas->hDecoderConfig->Opt_Headrotation &&
    4153             :                     ( NE_32( st_ivas->mc_mode, MC_MODE_PARAMUPMIX ) || NE_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) )
    4154             :                 {
    4155             :                     /* SHD HRIRs for low complexity rotation */
    4156        5670 :                     *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_HOA3;
    4157        5670 :                     move32();
    4158             :                 }
    4159             :             }
    4160             :         }
    4161      448402 :         ELSE IF( EQ_32( *binaural_renderer, IVAS_BIN_RENDERER_TYPE_CREND ) )
    4162             :         {
    4163       24495 :             IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) )
    4164             :             {
    4165             :                 /* BRIRs */
    4166       10568 :                 *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_7_1_4;
    4167       10568 :                 move32();
    4168             :             }
    4169       13927 :             ELSE IF( EQ_32( st_ivas->ivas_format, MC_FORMAT ) && EQ_32( st_ivas->mc_mode, MC_MODE_MCT ) )
    4170             :             {
    4171       13927 :                 test();
    4172             :                 /* BRIRs */
    4173       13927 :                 *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_7_1_4;
    4174       13927 :                 move32();
    4175       13927 :                 test();
    4176       13927 :                 test();
    4177       13927 :                 IF( st_ivas->hDecoderConfig->Opt_Headrotation && ( EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL ) || EQ_32( output_config, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) )
    4178             :                 {
    4179             :                     /* SHD HRIRs for low complexity rotation */
    4180         209 :                     *hrtf_set_audio_cfg = IVAS_AUDIO_CONFIG_HOA3;
    4181         209 :                     move32();
    4182             :                 }
    4183             :             }
    4184             :         }
    4185             : 
    4186      489329 :         test();
    4187      489329 :         test();
    4188      489329 :         test();
    4189      489329 :         test();
    4190             :         /* JBM: compensate when binaural renderer granularity changes (happens in bitrate switching) */
    4191      489329 :         IF( st_ivas->ini_active_frame > 0 && st_ivas->hDecoderConfig->Opt_tsm &&
    4192             :             ( NE_32( renderer_type_old, st_ivas->renderer_type ) ||
    4193             :               NE_32( renderer_type_sec_old, renderer_type_sec_new ) ) )
    4194             :         {
    4195        1381 :             Word16 tc_granularity_new = ivas_jbm_dec_get_render_granularity_fx( st_ivas->renderer_type, renderer_type_sec_new, st_ivas->hDecoderConfig->output_Fs );
    4196             : 
    4197        1381 :             st_ivas->nchan_transport = nchan_transport_old;
    4198        1381 :             move16();
    4199             : 
    4200        1381 :             IF( st_ivas->hTcBuffer == NULL )
    4201             :             {
    4202           0 :                 return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    4203             :             }
    4204             : 
    4205             :             /* when granularity goes down, render what still fits in the new granularity */
    4206        1381 :             IF( LT_32( tc_granularity_new, st_ivas->hTcBuffer->n_samples_granularity ) )
    4207             :             {
    4208         529 :                 IF( NE_32( ( error = ivas_jbm_dec_flush_renderer_fx( st_ivas, tc_granularity_new, renderer_type_old, intern_config_old, &st_ivas->hIntSetup, mc_mode_old, ism_mode_old, &hIvasDec->nSamplesFlushed, hIvasDec->flushbuffer ) ), IVAS_ERR_OK ) )
    4209             :                 {
    4210           0 :                     return error;
    4211             :                 }
    4212             :             }
    4213             :         }
    4214             :     }
    4215             : 
    4216      499635 :     st_ivas->ism_mode = ism_mode_old;
    4217      499635 :     st_ivas->mc_mode = mc_mode_old;
    4218      499635 :     st_ivas->nchan_transport = nchan_transport_old;
    4219      499635 :     st_ivas->intern_config = intern_config_old;
    4220      499635 :     st_ivas->transport_config = transport_config_old;
    4221      499635 :     st_ivas->renderer_type = renderer_type_old;
    4222      499635 :     move32();
    4223      499635 :     move32();
    4224      499635 :     move16();
    4225      499635 :     move32();
    4226      499635 :     move32();
    4227      499635 :     move32();
    4228             : 
    4229      499635 :     return IVAS_ERR_OK;
    4230             : }
    4231             : 
    4232             : 
    4233             : /*---------------------------------------------------------------------*
    4234             :  * apa_exec_evs_wrapper( )
    4235             :  *
    4236             :  *
    4237             :  *---------------------------------------------------------------------*/
    4238             : 
    4239        2050 : static ivas_error apa_exec_evs_wrapper(
    4240             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle            */
    4241             :     const UWord8 nTransportChannels,
    4242             :     UWord16 *nTimeScalerOutSamples )
    4243             : {
    4244             :     Word16 ch;
    4245             :     UWord16 apa_buff_len;
    4246             :     Word16 tmp_apaExecBuffer[CPE_CHANNELS * APA_BUF / APA_MAX_NUM_CHANNELS]; /* in EVS, 2 output channels */
    4247             :     DECODER_TC_BUFFER_HANDLE hTcBuffer;
    4248             : 
    4249        2050 :     test();
    4250        2050 :     test();
    4251        2050 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hTcBuffer == NULL )
    4252             :     {
    4253           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    4254             :     }
    4255             : 
    4256        2050 :     apa_buff_len = (UWord16) shl( mult0( hIvasDec->nSamplesFrame, nTransportChannels ), 1 );
    4257             : 
    4258        2050 :     hTcBuffer = hIvasDec->st_ivas->hTcBuffer;
    4259             : 
    4260     3938050 :     FOR( ch = 0; ch < apa_buff_len; ++ch )
    4261             :     {
    4262     3936000 :         tmp_apaExecBuffer[ch] = extract_l( L_shr( hTcBuffer->tc_buffer_fx[ch], Q11 ) ); // Q0
    4263             :     }
    4264             : 
    4265        2050 :     IF( apa_exec_fx( hIvasDec->hTimeScaler, tmp_apaExecBuffer, (UWord16) mult0( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, tmp_apaExecBuffer, nTimeScalerOutSamples ) != 0 )
    4266             :     {
    4267           0 :         return IVAS_ERR_UNKNOWN;
    4268             :     }
    4269             : 
    4270     3938050 :     FOR( ch = 0; ch < apa_buff_len; ++ch )
    4271             :     {
    4272     3936000 :         hTcBuffer->tc_buffer_fx[ch] = L_shl( tmp_apaExecBuffer[ch], Q11 ); // Q11
    4273             :     }
    4274             : 
    4275        2050 :     return IVAS_ERR_OK;
    4276             : }
    4277             : 
    4278             : 
    4279             : /*---------------------------------------------------------------------*
    4280             :  * IVAS_DEC_GetSamplesDecoder( )
    4281             :  *
    4282             :  * Main function to run setup, decode transport channels, do TSM and feed to renderer.
    4283             :  *---------------------------------------------------------------------*/
    4284             : 
    4285      507614 : ivas_error IVAS_DEC_GetSamplesDecoder(
    4286             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle            */
    4287             : #ifndef FIX_1119_SPLIT_RENDERING_VOIP
    4288             :     const Word16 isSplitRend, /* i  : split rendering enabled flag   */
    4289             : #endif
    4290             :     ISAR_SPLIT_REND_BITS_DATA *splitRendBits /* o  : output split rendering bits    */
    4291             : )
    4292             : {
    4293             :     ivas_error error;
    4294             :     Decoder_Struct *st_ivas;
    4295             :     UWord16 nTimeScalerOutSamples;
    4296             :     UWord8 nTransportChannels;
    4297             :     Word16 nResidualSamples, nSamplesTcsScaled;
    4298             :     bool isInitialized_voip;
    4299             : 
    4300      507614 :     test();
    4301      507614 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    4302             :     {
    4303           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    4304             :     }
    4305             : 
    4306      507614 :     test();
    4307      507614 :     IF( !hIvasDec->hasBeenFedFirstGoodFrame && !hIvasDec->isInitialized ) /* note: 'isInitialized' is related to EVS decoder */
    4308             :     {
    4309          80 :         return IVAS_ERR_OK;
    4310             :     }
    4311             : 
    4312      507534 :     st_ivas = hIvasDec->st_ivas;
    4313      507534 :     test();
    4314      507534 :     isInitialized_voip = hIvasDec->hTimeScaler != NULL;
    4315             : 
    4316      507534 :     test();
    4317      507534 :     IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame ) /* wait for the first good frame */
    4318             :     {
    4319             :         /*-----------------------------------------------------------------*
    4320             :          * Setup all decoder parts (IVAS decoder, ISAR)
    4321             :          *-----------------------------------------------------------------*/
    4322             : 
    4323             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    4324      507534 :         IF( NE_32( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, splitRendBits ) ), IVAS_ERR_OK ) )
    4325             : #else
    4326             :         IF( ( error = ivas_dec_setup_all( hIvasDec, &nTransportChannels, isSplitRend, splitRendBits ) ) != IVAS_ERR_OK )
    4327             : #endif
    4328             :         {
    4329           0 :             return error;
    4330             :         }
    4331             : 
    4332             :         /*-----------------------------------------------------------------*
    4333             :          * IVAS decoder: decode transport channels and metadata
    4334             :          *-----------------------------------------------------------------*/
    4335             : 
    4336      507534 :         IF( EQ_32( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
    4337             :         {
    4338        5150 :             IF( ( error = evs_dec_main_fx( st_ivas ) ) != IVAS_ERR_OK )
    4339             :             {
    4340           0 :                 return error;
    4341             :             }
    4342             :         }
    4343      502384 :         ELSE IF( EQ_32( hIvasDec->mode, IVAS_DEC_MODE_IVAS ) )
    4344             :         {
    4345      502384 :             IF( ( error = ivas_jbm_dec_tc_fx( st_ivas ) ) != IVAS_ERR_OK )
    4346             :             {
    4347           0 :                 return error;
    4348             :             }
    4349             : 
    4350      502384 :             hIvasDec->isInitialized = true; /* Initialization done in ivas_dec() */
    4351      502384 :             move16();
    4352             :         }
    4353             : 
    4354      507534 :         if ( hIvasDec->hasBeenFedFirstGoodFrame )
    4355             :         {
    4356      507534 :             hIvasDec->hasDecodedFirstGoodFrame = true;
    4357      507534 :             move16();
    4358             :         }
    4359             : 
    4360             :         /*-----------------------------------------------------------------*
    4361             :          * JBM
    4362             :          *-----------------------------------------------------------------*/
    4363             : 
    4364      507534 :         IF( st_ivas->hDecoderConfig->Opt_tsm )
    4365             :         {
    4366       43318 :             IF( NE_16( nTransportChannels, hIvasDec->nTransportChannelsOld ) )
    4367             :             {
    4368        3886 :                 IF( ( error = apa_setup( hIvasDec, isInitialized_voip, nTransportChannels ) ) != IVAS_ERR_OK )
    4369             :                 {
    4370           0 :                     return error;
    4371             :                 }
    4372             :             }
    4373             : 
    4374       43318 :             IF( apa_set_scale_fx( hIvasDec->hTimeScaler, hIvasDec->tsm_scale ) != 0 )
    4375             :             {
    4376           0 :                 return IVAS_ERR_UNKNOWN;
    4377             :             }
    4378             : 
    4379             :             /* convert deinterleaved decoded TC audio channels buffer to an interleaved one */
    4380       43318 :             ivas_buffer_deinterleaved_to_interleaved_fx( st_ivas->p_output_fx, nTransportChannels, hIvasDec->nSamplesFrame, st_ivas->hTcBuffer->tc_buffer_fx );
    4381             : 
    4382       43318 :             IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
    4383             :             {
    4384        2050 :                 apa_exec_evs_wrapper( hIvasDec, nTransportChannels, &nTimeScalerOutSamples );
    4385             :             }
    4386             :             ELSE
    4387             :             {
    4388       41268 :                 IF( apa_exec_ivas_fx( hIvasDec->hTimeScaler, st_ivas->hTcBuffer->tc_buffer_fx, (UWord16) imult3216( hIvasDec->nSamplesFrame, nTransportChannels ), (UWord16) hIvasDec->tsm_max_scaling, st_ivas->hTcBuffer->tc_buffer_fx, &nTimeScalerOutSamples ) != 0 )
    4389             :                 {
    4390           0 :                     return IVAS_ERR_UNKNOWN;
    4391             :                 }
    4392             :             }
    4393             : 
    4394       43318 :             assert( LE_32( (Word32) nTimeScalerOutSamples, APA_BUF ) );
    4395       43318 :             nSamplesTcsScaled = idiv1616U( extract_l( nTimeScalerOutSamples ), nTransportChannels );
    4396       43318 :             hIvasDec->timeScalingDone = 1;
    4397       43318 :             move16();
    4398             : 
    4399             :             /* convert interleaved time-scaled TC audio channels buffer to deinterleaved one */
    4400       43318 :             ivas_buffer_interleaved_to_deinterleaved_fx( st_ivas->hTcBuffer->tc_buffer_fx, nTransportChannels, nSamplesTcsScaled, NS2SA( st_ivas->hDecoderConfig->output_Fs, MAX_JBM_L_FRAME_NS ) );
    4401             :         }
    4402             :         else
    4403             :         {
    4404      464216 :             nSamplesTcsScaled = hIvasDec->nSamplesFrame;
    4405             :         }
    4406             : 
    4407             :         /*-----------------------------------------------------------------*
    4408             :          * Feed decoded transport channels samples to the renderer
    4409             :          *-----------------------------------------------------------------*/
    4410             : 
    4411      507534 :         ivas_jbm_dec_feed_tc_to_renderer_fx( st_ivas, nSamplesTcsScaled, &nResidualSamples );
    4412             : 
    4413      507534 :         IF( st_ivas->hDecoderConfig->Opt_tsm )
    4414             :         {
    4415             :             /* feed residual samples to TSM for the next call */
    4416             : #ifdef FIX_2174_JBM_BASOP_ALIGNMENT
    4417       43318 :             IF( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (UWord16) nResidualSamples ) != 0 )
    4418             : #else
    4419             :             IF( apa_set_renderer_residual_samples( hIvasDec->hTimeScaler, (uint16_t) nResidualSamples ) != 0 )
    4420             : #endif
    4421             :             {
    4422           0 :                 return IVAS_ERR_UNKNOWN;
    4423             :             }
    4424             :         }
    4425      507534 :         hIvasDec->hasBeenFedFrame = false;
    4426      507534 :         move16();
    4427             :     }
    4428             : 
    4429      507534 :     hIvasDec->hasBeenPreparedRendering = false;
    4430      507534 :     move16();
    4431             : 
    4432             :     /*-----------------------------------------------------------------*
    4433             :      * Set editable metadata
    4434             :      *-----------------------------------------------------------------*/
    4435             : 
    4436      507534 :     IF( st_ivas->hIsmMetaData[0] )
    4437             :     {
    4438      163352 :         test();
    4439      163352 :         test();
    4440      163352 :         IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    4441             :         {
    4442      159081 :             test();
    4443      159081 :             test();
    4444      159081 :             test();
    4445      159081 :             IF( EQ_32( st_ivas->ism_mode, ISM_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_DISC ) || EQ_32( st_ivas->ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    4446             :             {
    4447             :                 Word16 obj;
    4448      127878 :                 ISM_METADATA_HANDLE *hIsmMetaData = st_ivas->hIsmMetaData;
    4449      496164 :                 FOR( obj = 0; obj < st_ivas->nchan_ism; obj++ )
    4450             :                 {
    4451      368286 :                     hIsmMetaData[obj]->edited_azimuth_fx = hIsmMetaData[obj]->azimuth_fx;
    4452      368286 :                     move32();
    4453      368286 :                     hIsmMetaData[obj]->edited_elevation_fx = hIsmMetaData[obj]->elevation_fx;
    4454      368286 :                     move32();
    4455      368286 :                     hIsmMetaData[obj]->edited_yaw_fx = hIsmMetaData[obj]->yaw_fx;
    4456      368286 :                     move32();
    4457      368286 :                     hIsmMetaData[obj]->edited_pitch_fx = hIsmMetaData[obj]->pitch_fx;
    4458      368286 :                     move32();
    4459      368286 :                     hIsmMetaData[obj]->edited_radius_fx = hIsmMetaData[obj]->radius_fx;
    4460      368286 :                     move32();
    4461             : #ifdef FIX_2148_OBJ_EDIT_ISSUE_WITH_OSBA
    4462      368286 :                     hIsmMetaData[obj]->edited_gain_fx = ONE_IN_Q29;
    4463      368286 :                     move32();
    4464             : #endif
    4465             :                 }
    4466             : 
    4467      127878 :                 if ( EQ_32( st_ivas->ism_mode, ISM_SBA_MODE_DISC ) )
    4468             :                 {
    4469       22482 :                     st_ivas->hSbaIsmData->gain_bed_fx = ONE_IN_Q29; // TODO: Check Q value
    4470       22482 :                     move32();
    4471             :                 }
    4472             :             }
    4473             :         }
    4474             :     }
    4475             : 
    4476      507534 :     IF( st_ivas->hParamIsmDec != NULL )
    4477             :     {
    4478       21013 :         IF( EQ_32( st_ivas->ism_mode, ISM_MODE_PARAM ) )
    4479             :         {
    4480       21013 :             Word16 obj = 0;
    4481       21013 :             PARAM_ISM_DEC_HANDLE hParamIsmDec = st_ivas->hParamIsmDec;
    4482       98309 :             FOR( obj = 0; obj < st_ivas->nchan_ism; obj++ )
    4483             :             {
    4484       77296 :                 hParamIsmDec->edited_azimuth_values_fx[obj] = hParamIsmDec->azimuth_values_fx[obj];
    4485       77296 :                 hParamIsmDec->edited_elevation_values_fx[obj] = hParamIsmDec->elevation_values_fx[obj];
    4486       77296 :                 move32();
    4487       77296 :                 move32();
    4488             :             }
    4489             :         }
    4490             :     }
    4491             : 
    4492      507534 :     return IVAS_ERR_OK;
    4493             : }
    4494             : 
    4495             : 
    4496             : /*---------------------------------------------------------------------*
    4497             :  * IVAS_DEC_GetEditableParameters( )
    4498             :  *
    4499             :  * Get editable metadata parameters
    4500             :  *---------------------------------------------------------------------*/
    4501             : 
    4502       16028 : ivas_error IVAS_DEC_GetEditableParameters(
    4503             :     IVAS_DEC_HANDLE hIvasDec,                         /* i/o: IVAS decoder handle              */
    4504             :     IVAS_EDITABLE_PARAMETERS *hIvasEditableParameters /* o  : object editing parameters handle */
    4505             : )
    4506             : {
    4507             :     Word16 obj, dirac_read_idx;
    4508             :     Decoder_Struct *st_ivas;
    4509             :     ISM_MODE ism_mode;
    4510             : 
    4511       16028 :     test();
    4512       16028 :     test();
    4513       16028 :     IF( hIvasEditableParameters == NULL || hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    4514             :     {
    4515           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    4516             :     }
    4517             : 
    4518       16028 :     IF( !hIvasDec->hasBeenFedFirstGoodFrame )
    4519             :     {
    4520           1 :         hIvasEditableParameters->num_obj = 0;
    4521           1 :         move16();
    4522             : 
    4523           1 :         return IVAS_ERR_OK;
    4524             :     }
    4525             : 
    4526       16027 :     st_ivas = hIvasDec->st_ivas;
    4527       16027 :     ism_mode = st_ivas->ism_mode;
    4528             : 
    4529       16027 :     test();
    4530       16027 :     test();
    4531       16027 :     test();
    4532       16027 :     test();
    4533       16027 :     IF( !( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ||
    4534             :            EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ||
    4535             :            EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ||
    4536             :            ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && GT_16( st_ivas->nchan_ism, 0 ) ) ) )
    4537             : 
    4538           0 :     hIvasEditableParameters->gain_bed_fx = ONE_IN_Q29;
    4539       16027 :     move32();
    4540       16027 :     hIvasEditableParameters->num_obj = st_ivas->nchan_ism;
    4541       16027 :     move16();
    4542             : 
    4543       16027 :     test();
    4544       16027 :     test();
    4545       16027 :     test();
    4546       16027 :     IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    4547             :     {
    4548       12019 :         test();
    4549       12019 :         IF( EQ_32( ism_mode, ISM_MODE_DISC ) || EQ_32( ism_mode, ISM_SBA_MODE_DISC ) )
    4550             :         {
    4551       31651 :             FOR( obj = 0; obj < hIvasEditableParameters->num_obj; obj++ )
    4552             :             {
    4553       24739 :                 hIvasEditableParameters->ism_metadata[obj].azimuth_fx = st_ivas->hIsmMetaData[obj]->azimuth_fx;
    4554       24739 :                 move32();
    4555       24739 :                 hIvasEditableParameters->ism_metadata[obj].elevation_fx = st_ivas->hIsmMetaData[obj]->elevation_fx;
    4556       24739 :                 move32();
    4557       24739 :                 hIvasEditableParameters->ism_metadata[obj].yaw_fx = st_ivas->hIsmMetaData[obj]->yaw_fx;
    4558       24739 :                 move32();
    4559       24739 :                 hIvasEditableParameters->ism_metadata[obj].pitch_fx = st_ivas->hIsmMetaData[obj]->pitch_fx;
    4560       24739 :                 move32();
    4561       24739 :                 hIvasEditableParameters->ism_metadata[obj].radius_fx = st_ivas->hIsmMetaData[obj]->radius_fx;
    4562       24739 :                 move16();
    4563       24739 :                 hIvasEditableParameters->ism_metadata[obj].gain_fx = st_ivas->hIsmMetaData[obj]->edited_gain_fx;
    4564       24739 :                 move32();
    4565       24739 :                 hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = st_ivas->hIsmMetaData[obj]->non_diegetic_flag;
    4566       24739 :                 move16();
    4567             :             }
    4568             : 
    4569        6912 :             IF( EQ_32( ism_mode, ISM_SBA_MODE_DISC ) )
    4570             :             {
    4571        2404 :                 hIvasEditableParameters->gain_bed_fx = ONE_IN_Q29;
    4572        2404 :                 move32();
    4573             :             }
    4574             :         }
    4575        5107 :         ELSE IF( EQ_32( ism_mode, ISM_MODE_PARAM ) )
    4576             :         {
    4577       21029 :             FOR( obj = 0; obj < hIvasEditableParameters->num_obj; obj++ )
    4578             :             {
    4579       16522 :                 hIvasEditableParameters->ism_metadata[obj].azimuth_fx = st_ivas->hParamIsmDec->azimuth_values_fx[obj];
    4580       16522 :                 move32();
    4581       16522 :                 hIvasEditableParameters->ism_metadata[obj].elevation_fx = st_ivas->hParamIsmDec->elevation_values_fx[obj];
    4582       16522 :                 move32();
    4583       16522 :                 hIvasEditableParameters->ism_metadata[obj].yaw_fx = 0;
    4584       16522 :                 move32();
    4585       16522 :                 hIvasEditableParameters->ism_metadata[obj].pitch_fx = 0;
    4586       16522 :                 move32();
    4587       16522 :                 hIvasEditableParameters->ism_metadata[obj].radius_fx = 0;
    4588       16522 :                 move16();
    4589       16522 :                 hIvasEditableParameters->ism_metadata[obj].gain_fx = ONE_IN_Q29;
    4590       16522 :                 move32();
    4591       16522 :                 hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = 0;
    4592       16522 :                 move16();
    4593             :             }
    4594             :         }
    4595         600 :         ELSE IF( EQ_32( ism_mode, ISM_MODE_NONE ) )
    4596             :         {
    4597         600 :             hIvasEditableParameters->num_obj = 0;
    4598         600 :             move16();
    4599             :         }
    4600             : #ifdef DEBUGGING
    4601             :         ELSE
    4602             :         {
    4603             :             assert( 0 && "This should never happen!" );
    4604             :         }
    4605             : #endif
    4606             :     }
    4607        4008 :     ELSE IF( EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) || ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && GT_16( st_ivas->nchan_ism, 0 ) ) )
    4608             :     {
    4609             :         /* object editing possible only in two highest OMASA modes */
    4610        4008 :         test();
    4611        4008 :         IF( EQ_32( ism_mode, ISM_MASA_MODE_DISC ) )
    4612             :         {
    4613        9034 :             FOR( obj = 0; obj < hIvasEditableParameters->num_obj; obj++ )
    4614             :             {
    4615        6692 :                 hIvasEditableParameters->ism_metadata[obj].azimuth_fx = st_ivas->hIsmMetaData[obj]->azimuth_fx;
    4616        6692 :                 move32();
    4617        6692 :                 hIvasEditableParameters->ism_metadata[obj].elevation_fx = st_ivas->hIsmMetaData[obj]->elevation_fx;
    4618        6692 :                 move32();
    4619        6692 :                 hIvasEditableParameters->ism_metadata[obj].yaw_fx = st_ivas->hIsmMetaData[obj]->yaw_fx;
    4620        6692 :                 move32();
    4621        6692 :                 hIvasEditableParameters->ism_metadata[obj].pitch_fx = st_ivas->hIsmMetaData[obj]->pitch_fx;
    4622        6692 :                 move32();
    4623        6692 :                 hIvasEditableParameters->ism_metadata[obj].radius_fx = st_ivas->hIsmMetaData[obj]->radius_fx;
    4624        6692 :                 move32();
    4625             : 
    4626             :                 /* reset the otherwise unused "gain" field for the object */
    4627        6692 :                 st_ivas->hIsmMetaData[obj]->edited_gain_fx = ONE_IN_Q29;
    4628        6692 :                 move32();
    4629        6692 :                 hIvasEditableParameters->ism_metadata[obj].gain_fx = st_ivas->hIsmMetaData[obj]->edited_gain_fx;
    4630        6692 :                 move32();
    4631        6692 :                 hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = st_ivas->hIsmMetaData[obj]->non_diegetic_flag;
    4632        6692 :                 move16();
    4633             :             }
    4634             :         }
    4635        1666 :         ELSE IF( EQ_32( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
    4636             :         {
    4637             :             /* Handle MONO output */
    4638        1332 :             IF( NE_32( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
    4639             :             {
    4640        1332 :                 dirac_read_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->subframes_rendered];
    4641             :             }
    4642             :             ELSE
    4643             :             {
    4644           0 :                 dirac_read_idx = 0;
    4645             :             }
    4646        1332 :             move16();
    4647             : 
    4648        5996 :             FOR( obj = 0; obj < hIvasEditableParameters->num_obj; obj++ )
    4649             :             {
    4650        4664 :                 hIvasEditableParameters->ism_metadata[obj].azimuth_fx = L_shl( L_deposit_l( st_ivas->hMasaIsmData->azimuth_ism_fx[obj][dirac_read_idx] ), Q22 );
    4651        4664 :                 hIvasEditableParameters->ism_metadata[obj].elevation_fx = L_shl( L_deposit_l( st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ), Q22 );
    4652        4664 :                 move32();
    4653        4664 :                 move32();
    4654             : 
    4655        4664 :                 hIvasEditableParameters->ism_metadata[obj].yaw_fx = st_ivas->hIsmMetaData[obj]->yaw_fx;
    4656        4664 :                 hIvasEditableParameters->ism_metadata[obj].pitch_fx = st_ivas->hIsmMetaData[obj]->pitch_fx;
    4657        4664 :                 hIvasEditableParameters->ism_metadata[obj].radius_fx = st_ivas->hIsmMetaData[obj]->radius_fx;
    4658        4664 :                 move32();
    4659        4664 :                 move32();
    4660        4664 :                 move32();
    4661             : 
    4662             :                 /* reset the otherwise unused "gain" field for the object */
    4663        4664 :                 st_ivas->hIsmMetaData[obj]->edited_gain_fx = ONE_IN_Q29;
    4664        4664 :                 hIvasEditableParameters->ism_metadata[obj].gain_fx = st_ivas->hIsmMetaData[obj]->edited_gain_fx;
    4665        4664 :                 hIvasEditableParameters->ism_metadata[obj].non_diegetic_flag = st_ivas->hIsmMetaData[obj]->non_diegetic_flag;
    4666        4664 :                 move32();
    4667        4664 :                 move32();
    4668        4664 :                 move16();
    4669             :             }
    4670             :         }
    4671         334 :         ELSE IF( EQ_32( ism_mode, ISM_MASA_MODE_MASA_ONE_OBJ ) || EQ_32( ism_mode, ISM_MODE_NONE ) )
    4672             :         {
    4673         334 :             hIvasEditableParameters->num_obj = 0;
    4674         334 :             move16();
    4675             :         }
    4676             : #ifdef DEBUGGING
    4677             :         ELSE
    4678             :         {
    4679             :             assert( 0 && "This should never happen!" );
    4680             :         }
    4681             : #endif
    4682             :     }
    4683             : 
    4684       16027 :     return IVAS_ERR_OK;
    4685             : }
    4686             : 
    4687             : 
    4688             : /*---------------------------------------------------------------------*
    4689             :  * IVAS_DEC_SetEditableParameters( )
    4690             :  *
    4691             :  * Set editable metadata parameters
    4692             :  *---------------------------------------------------------------------*/
    4693             : 
    4694       16028 : ivas_error IVAS_DEC_SetEditableParameters(
    4695             :     IVAS_DEC_HANDLE hIvasDec,                        /* i/o: IVAS decoder handle              */
    4696             :     IVAS_EDITABLE_PARAMETERS hIvasEditableParameters /* i  : object editing parameters handle */
    4697             : )
    4698             : {
    4699             :     Word16 dirac_read_idx, obj;
    4700             :     Decoder_Struct *st_ivas;
    4701             :     ISM_MODE ism_mode;
    4702             : 
    4703       16028 :     test();
    4704       16028 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    4705             :     {
    4706           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    4707             :     }
    4708             : 
    4709       16028 :     IF( !hIvasDec->hasBeenFedFirstGoodFrame )
    4710             :     {
    4711           1 :         return IVAS_ERR_OK;
    4712             :     }
    4713             : 
    4714       16027 :     st_ivas = hIvasDec->st_ivas;
    4715       16027 :     ism_mode = st_ivas->ism_mode;
    4716             : 
    4717       16027 :     test();
    4718       16027 :     test();
    4719       16027 :     test();
    4720       16027 :     test();
    4721       16027 :     IF( !( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) ||
    4722             :            EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) ||
    4723             :            EQ_32( st_ivas->ivas_format, MASA_ISM_FORMAT ) ||
    4724             :            ( EQ_32( st_ivas->ivas_format, MASA_FORMAT ) && GT_16( st_ivas->nchan_ism, 0 ) ) ) )
    4725             :     {
    4726           0 :         return IVAS_ERROR( IVAS_ERR_WRONG_MODE, "Object editing no supported in this operation mode." );
    4727             :     }
    4728             : 
    4729       16027 :     test();
    4730       16027 :     test();
    4731       16027 :     test();
    4732       16027 :     IF( EQ_32( st_ivas->ivas_format, ISM_FORMAT ) || EQ_32( st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    4733             :     {
    4734       12019 :         test();
    4735       12019 :         IF( EQ_32( ism_mode, ISM_MODE_DISC ) || EQ_32( ism_mode, ISM_SBA_MODE_DISC ) )
    4736             :         {
    4737             : #ifdef DEBUGGING
    4738             :             assert( hIvasEditableParameters.num_obj == st_ivas->nchan_ism );
    4739             : #endif
    4740       31651 :             FOR( obj = 0; obj < hIvasEditableParameters.num_obj; obj++ )
    4741             :             {
    4742       24739 :                 st_ivas->hIsmMetaData[obj]->edited_azimuth_fx = hIvasEditableParameters.ism_metadata[obj].azimuth_fx;
    4743       24739 :                 move32();
    4744       24739 :                 st_ivas->hIsmMetaData[obj]->edited_elevation_fx = hIvasEditableParameters.ism_metadata[obj].elevation_fx;
    4745       24739 :                 move32();
    4746       24739 :                 st_ivas->hIsmMetaData[obj]->edited_radius_fx = hIvasEditableParameters.ism_metadata[obj].radius_fx;
    4747       24739 :                 move32();
    4748       24739 :                 st_ivas->hIsmMetaData[obj]->edited_yaw_fx = hIvasEditableParameters.ism_metadata[obj].yaw_fx;
    4749       24739 :                 move32();
    4750       24739 :                 st_ivas->hIsmMetaData[obj]->edited_pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx;
    4751       24739 :                 move32();
    4752             : #ifdef FIX_GAIN_EDIT_LIMITS
    4753       24739 :                 IF( GT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MAX_Q29 ) )
    4754             :                 {
    4755           0 :                     st_ivas->hIsmMetaData[obj]->edited_gain_fx = EDIT_GAIN_MAX_Q29;
    4756           0 :                     move32();
    4757             :                 }
    4758             :                 ELSE
    4759             :                 {
    4760       24739 :                     st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx;
    4761       24739 :                     move32();
    4762             :                 }
    4763             : #else
    4764             :                 st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx;
    4765             :                 move32();
    4766             : #endif
    4767       24739 :                 st_ivas->hIsmMetaData[obj]->non_diegetic_flag = hIvasEditableParameters.ism_metadata[obj].non_diegetic_flag;
    4768       24739 :                 move16();
    4769             :             }
    4770             : 
    4771        6912 :             IF( EQ_32( ism_mode, ISM_SBA_MODE_DISC ) )
    4772             :             {
    4773             : #ifdef FIX_GAIN_EDIT_LIMITS
    4774        2404 :                 IF( GT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MAX_Q29 ) )
    4775             :                 {
    4776           0 :                     st_ivas->hSbaIsmData->gain_bed_fx = EDIT_GAIN_MAX_Q29;
    4777           0 :                     move32();
    4778             :                 }
    4779             :                 ELSE
    4780             :                 {
    4781        2404 :                     st_ivas->hSbaIsmData->gain_bed_fx = hIvasEditableParameters.gain_bed_fx;
    4782        2404 :                     move32();
    4783             :                 }
    4784             : #else
    4785             :                 st_ivas->hSbaIsmData->gain_bed_fx = hIvasEditableParameters.gain_bed_fx;
    4786             :                 move32();
    4787             : #endif
    4788             :             }
    4789             :         }
    4790        5107 :         ELSE IF( EQ_32( ism_mode, ISM_MODE_PARAM ) )
    4791             :         {
    4792             : #ifdef DEBUGGING
    4793             :             assert( hIvasEditableParameters.num_obj == st_ivas->nchan_ism );
    4794             : #endif
    4795       21029 :             FOR( obj = 0; obj < hIvasEditableParameters.num_obj; obj++ )
    4796             :             {
    4797       16522 :                 st_ivas->hParamIsmDec->edited_azimuth_values_fx[obj] = hIvasEditableParameters.ism_metadata[obj].azimuth_fx;
    4798       16522 :                 move32();
    4799       16522 :                 st_ivas->hParamIsmDec->edited_elevation_values_fx[obj] = hIvasEditableParameters.ism_metadata[obj].elevation_fx;
    4800       16522 :                 move32();
    4801             : 
    4802       16522 :                 IF( st_ivas->hMasaIsmData != NULL )
    4803             :                 {
    4804             : #ifdef FIX_GAIN_EDIT_LIMITS
    4805             :                     /* Limit gain edit to a range of +12dB to -24dB with parametric ISM mode */
    4806       12004 :                     IF( GT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MAX_Q29 ) )
    4807             :                     {
    4808           0 :                         st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = EDIT_GAIN_MAX_Q12; // Q12
    4809           0 :                         move16();
    4810             :                     }
    4811       12004 :                     ELSE IF( LT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MIN_Q29 ) )
    4812             :                     {
    4813           0 :                         st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = EDIT_GAIN_MIN_Q12; // Q12
    4814           0 :                         move16();
    4815             :                     }
    4816             :                     ELSE
    4817             :                     {
    4818       12004 :                         st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 -> Q12
    4819       12004 :                         move16();
    4820             :                     }
    4821             : #else
    4822             :                     st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 -> Q12
    4823             :                     move32();
    4824             : #endif
    4825             : 
    4826             :                     /* Detect direction editing in Param-ISM mode  */
    4827       12004 :                     IF( GT_32( L_abs( L_sub( st_ivas->hParamIsmDec->azimuth_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ), OMASA_AZI_EDIT_THR_Q22 ) ||    // | azi_orig[obj] - azi_edit[obj] | > azi_threshold
    4828             :                         GT_32( L_abs( L_sub( st_ivas->hParamIsmDec->elevation_values_fx[obj], hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ), OMASA_ELE_EDIT_THR_Q22 ) ) // | ele_orig[obj] - ele_edit[obj] | > ele_threshold
    4829             :                     {
    4830       11996 :                         st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1;
    4831             :                     }
    4832             :                     ELSE
    4833             :                     {
    4834           8 :                         st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 0;
    4835             :                     }
    4836       12004 :                     move16();
    4837             : 
    4838             :                     /* Detect gain editing in Param-ISM mode */
    4839       12004 :                     IF( GT_16( abs_s( sub( ONE_IN_Q12, shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ) ) ), OMASA_GAIN_EDIT_THR_Q12 ) ) // | 1.0f - gain_edit[obj] | > gain_threshold
    4840             :                     {
    4841       11340 :                         st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 1;
    4842             :                     }
    4843             :                     ELSE
    4844             :                     {
    4845         664 :                         st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 0;
    4846             :                     }
    4847       12004 :                     move16();
    4848             :                 }
    4849             :             }
    4850             : 
    4851        4507 :             IF( st_ivas->hMasaIsmData != NULL )
    4852             :             {
    4853             :                 /* MASA is not present with the ISM format */
    4854        3001 :                 st_ivas->hMasaIsmData->masa_gain_is_edited = 0;
    4855        3001 :                 move16();
    4856             :             }
    4857             :         }
    4858         600 :         ELSE IF( EQ_32( ism_mode, ISM_MODE_NONE ) )
    4859             :         {
    4860         600 :             IF( NE_16( hIvasEditableParameters.num_obj, 0 ) )
    4861             :             {
    4862           0 :                 return IVAS_ERR_OBJECTS_EDITING_NOT_SUPPORTED;
    4863             :             }
    4864             :         }
    4865             : #ifdef DEBUGGING
    4866             :         ELSE
    4867             :         {
    4868             :             assert( 0 && "This should never happen!" );
    4869             :         }
    4870             : #endif
    4871             :     }
    4872        4008 :     ELSE IF( EQ_16( st_ivas->ivas_format, MASA_ISM_FORMAT ) && ( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) || EQ_16( ism_mode, ISM_MASA_MODE_DISC ) ) )
    4873             :     {
    4874             :         Word32 id_th;
    4875             :         Word32 threshold_azi, threshold_ele;
    4876             : 
    4877             : #ifdef DEBUGGING
    4878             :         assert( hIvasEditableParameters.num_obj == st_ivas->nchan_ism );
    4879             : #endif
    4880       15030 :         FOR( obj = 0; obj < hIvasEditableParameters.num_obj; obj++ )
    4881             :         {
    4882       11356 :             IF( st_ivas->hMasaIsmData != NULL )
    4883             :             {
    4884             :                 /* copy relevant fields also to OMASA structs, but only if the value has been changed. original values are in st_ivas->hIsmMetaData */
    4885             :                 /* first, need to convert float values to ints used internally */
    4886             :                 Word16 new_azi, new_ele;
    4887             : 
    4888       11356 :                 new_azi = extract_l( L_shr( L_add( L_abs( hIvasEditableParameters.ism_metadata[obj].azimuth_fx ), 2097152 ), Q22 ) ); // Q22->Q0
    4889       11356 :                 IF( LT_32( hIvasEditableParameters.ism_metadata[obj].azimuth_fx, 0 ) )
    4890             :                 {
    4891        3740 :                     new_azi = negate( new_azi );
    4892             :                 }
    4893             : 
    4894       11356 :                 new_ele = extract_l( L_shr( L_add( L_abs( hIvasEditableParameters.ism_metadata[obj].elevation_fx ), 2097152 ), Q22 ) ); // Q22->Q0
    4895       11356 :                 IF( LT_32( hIvasEditableParameters.ism_metadata[obj].elevation_fx, 0 ) )
    4896             :                 {
    4897        3577 :                     new_ele = negate( new_ele );
    4898             :                 }
    4899             : 
    4900       11356 :                 IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) )
    4901             :                 {
    4902             :                     /* Handle MONO output */
    4903        4664 :                     IF( NE_16( st_ivas->renderer_type, RENDERER_MONO_DOWNMIX ) )
    4904             :                     {
    4905        4664 :                         dirac_read_idx = st_ivas->hSpatParamRendCom->render_to_md_map[st_ivas->hSpatParamRendCom->subframes_rendered];
    4906             :                     }
    4907             :                     ELSE
    4908             :                     {
    4909           0 :                         dirac_read_idx = 0;
    4910             :                     }
    4911        4664 :                     move16();
    4912             : 
    4913             :                     /* determine thresholds for detecting object metadata edit for direction based on quantization resolution of the spatial direction parameters.
    4914             :                      * these depend from the number of bits used to transmit the directions,
    4915             :                      * which in turn depends from the object priority and importance:
    4916             :                      * importance -> priority -> number of bits -> elevation resolution -> elevation ring index -> azimuth resolution.
    4917             :                      * leading to elevation_resolution -> elevation threshold and azimuth resolution -> azimuth threshold */
    4918        4664 :                     id_th = extract_l( L_shr( L_add( Mpy_32_16_1( delta_theta_masa_inv_fx[st_ivas->hMasaIsmData->bits_ism[obj] - 3], abs_s( st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ) ), 32768 ), 16 ) ); // + 0.5f in Q16
    4919        4664 :                     threshold_azi = Mpy_32_32( 1509949440, no_phi_masa_inv_fx[st_ivas->hMasaIsmData->bits_ism[obj] - 1][id_th] );                                                                                              // Q = 22;
    4920        4664 :                     threshold_ele = delta_theta_masa_fx[st_ivas->hMasaIsmData->bits_ism[obj] - 3];
    4921             : 
    4922        4664 :                     test();
    4923        4664 :                     IF( ( GT_32( L_shl( abs_s( sub( new_azi, st_ivas->hMasaIsmData->azimuth_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_azi ) ) ||  // | azi_edit[obj] - azi_orig[obj] | > azi_threshold
    4924             :                         ( GT_32( L_shl( abs_s( sub( new_ele, st_ivas->hMasaIsmData->elevation_ism_fx[obj][dirac_read_idx] ) ), 22 ), threshold_ele ) ) ) // | ele_edit[obj] - ele_orig[obj] | > ele_threshold
    4925             :                     {
    4926             :                         /* at least one of the threshold is exceeded, so use new direction value and set editing detection flag */
    4927        4456 :                         st_ivas->hMasaIsmData->azimuth_ism_edited_fx[obj] = new_azi;
    4928        4456 :                         move32();
    4929        4456 :                         st_ivas->hMasaIsmData->elevation_ism_edited_fx[obj] = new_ele;
    4930        4456 :                         move32();
    4931             : 
    4932        4456 :                         st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1;
    4933             :                     }
    4934             :                     ELSE
    4935             :                     {
    4936         208 :                         st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 0;
    4937             :                     }
    4938        4664 :                     move16();
    4939             :                 }
    4940             :                 ELSE
    4941             :                 {
    4942             :                     /* detect editing in ISM_MASA_MODE_DISC mode */
    4943        6692 :                     test();
    4944        6692 :                     IF( L_abs( L_sub( st_ivas->hIsmMetaData[obj]->azimuth_fx, hIvasEditableParameters.ism_metadata[obj].azimuth_fx ) ) > OMASA_AZI_EDIT_THR_Q22 ||    // | azi_orig[obj] - azi_edit[obj] | > azi_threshold
    4945             :                         L_abs( L_sub( st_ivas->hIsmMetaData[obj]->elevation_fx, hIvasEditableParameters.ism_metadata[obj].elevation_fx ) ) > OMASA_ELE_EDIT_THR_Q22 ) // | ele_orig[obj] - ele_edit[obj] | > ele_threshold
    4946             :                     {
    4947        6690 :                         st_ivas->hMasaIsmData->azimuth_ism_edited_fx[obj] = new_azi;
    4948        6690 :                         move32();
    4949        6690 :                         st_ivas->hMasaIsmData->elevation_ism_edited_fx[obj] = new_ele;
    4950        6690 :                         move32();
    4951             : 
    4952        6690 :                         st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 1;
    4953             :                     }
    4954             :                     ELSE
    4955             :                     {
    4956           2 :                         st_ivas->hMasaIsmData->ism_dir_is_edited[obj] = 0;
    4957             :                     }
    4958        6692 :                     move16();
    4959             :                 }
    4960             : 
    4961             :                 /* compare pre-edit gain and the edited one to detect editing */
    4962       11356 :                 IF( GT_16( abs_s( sub( shr( extract_h( st_ivas->hIsmMetaData[obj]->edited_gain_fx ), Q1 ), shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ) ) ), OMASA_GAIN_EDIT_THR_Q12 ) ) // | gain_edit[obj] - gain_orig[obj] | > gain_threshold
    4963             :                 {
    4964       10453 :                     st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 1;
    4965             : #ifdef FIX_GAIN_EDIT_LIMITS
    4966             :                     /* Limit gain edit to a range of +12dB to -24dB with parametric OMASA mode */
    4967       10453 :                     test();
    4968       10453 :                     IF( GT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MAX_Q29 ) )
    4969             :                     {
    4970           0 :                         st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = EDIT_GAIN_MAX_Q12;
    4971           0 :                         move16();
    4972             :                     }
    4973       10453 :                     ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && LT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MIN_Q29 ) )
    4974             :                     {
    4975           0 :                         st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = EDIT_GAIN_MIN_Q12;
    4976           0 :                         move16();
    4977             :                     }
    4978             :                     ELSE
    4979             :                     {
    4980       10453 :                         st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 --> Q12
    4981       10453 :                         move16();
    4982             :                     }
    4983             : #else
    4984             :                     st_ivas->hMasaIsmData->gain_ism_edited_fx[obj] = shr( extract_h( hIvasEditableParameters.ism_metadata[obj].gain_fx ), Q1 ); // Q29 --> Q12
    4985             :                     move16();
    4986             : #endif
    4987             :                 }
    4988             :                 ELSE
    4989             :                 {
    4990         903 :                     st_ivas->hMasaIsmData->ism_gain_is_edited[obj] = 0u;
    4991             :                 }
    4992       11356 :                 move32();
    4993             :             }
    4994             : 
    4995             :             /* Copy edited values to hIsmMetaData struct */
    4996       11356 :             IF( st_ivas->hIsmMetaData[obj] != NULL )
    4997             :             {
    4998       11356 :                 st_ivas->hIsmMetaData[obj]->edited_azimuth_fx = hIvasEditableParameters.ism_metadata[obj].azimuth_fx;
    4999       11356 :                 move32();
    5000       11356 :                 st_ivas->hIsmMetaData[obj]->edited_elevation_fx = hIvasEditableParameters.ism_metadata[obj].elevation_fx;
    5001       11356 :                 move32();
    5002             : #ifdef FIX_2192_OBJ_EDITING_EXT_METADATA
    5003       11356 :                 IF( EQ_16( ism_mode, ISM_MASA_MODE_DISC ) )
    5004             :                 {
    5005        6692 :                     st_ivas->hIsmMetaData[obj]->edited_yaw_fx = hIvasEditableParameters.ism_metadata[obj].yaw_fx;
    5006        6692 :                     move16();
    5007        6692 :                     st_ivas->hIsmMetaData[obj]->edited_pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx;
    5008        6692 :                     move16();
    5009        6692 :                     st_ivas->hIsmMetaData[obj]->edited_radius_fx = hIvasEditableParameters.ism_metadata[obj].radius_fx;
    5010        6692 :                     move16();
    5011             :                 }
    5012             : #else
    5013             :                 st_ivas->hIsmMetaData[obj]->edited_yaw_fx = hIvasEditableParameters.ism_metadata[obj].yaw_fx;
    5014             :                 move32();
    5015             :                 st_ivas->hIsmMetaData[obj]->edited_pitch_fx = hIvasEditableParameters.ism_metadata[obj].pitch_fx;
    5016             :                 move32();
    5017             :                 st_ivas->hIsmMetaData[obj]->edited_radius_fx = hIvasEditableParameters.ism_metadata[obj].radius_fx;
    5018             :                 move32();
    5019             : #endif
    5020             : #ifdef FIX_GAIN_EDIT_LIMITS
    5021       11356 :                 test();
    5022       11356 :                 IF( GT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MAX_Q29 ) )
    5023             :                 {
    5024           0 :                     st_ivas->hIsmMetaData[obj]->edited_gain_fx = EDIT_GAIN_MAX_Q29;
    5025             :                 }
    5026       11356 :                 ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && LT_32( hIvasEditableParameters.ism_metadata[obj].gain_fx, EDIT_GAIN_MIN_Q29 ) )
    5027             :                 {
    5028           0 :                     st_ivas->hIsmMetaData[obj]->edited_gain_fx = EDIT_GAIN_MIN_Q29;
    5029             :                 }
    5030             :                 ELSE
    5031             :                 {
    5032       11356 :                     st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx;
    5033             :                 }
    5034             : #else
    5035             :                 st_ivas->hIsmMetaData[obj]->edited_gain_fx = hIvasEditableParameters.ism_metadata[obj].gain_fx;
    5036             :                 move32();
    5037             : #endif
    5038       11356 :                 st_ivas->hIsmMetaData[obj]->non_diegetic_flag = hIvasEditableParameters.ism_metadata[obj].non_diegetic_flag;
    5039       11356 :                 move16();
    5040             :             }
    5041             :         }
    5042             : 
    5043        3674 :         IF( GT_16( abs_s( sub( shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 ), ONE_IN_Q12 ) ), OMASA_GAIN_EDIT_THR_Q12 ) ) // | gain_bed - 1.0f | > gain_threshold
    5044             :         {
    5045             : #ifdef FIX_GAIN_EDIT_LIMITS
    5046             :             /* Limit gain edit to a range of +12dB to -24dB with parametric OMASA mode */
    5047        3500 :             test();
    5048        3500 :             IF( GT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MAX_Q29 ) )
    5049             :             {
    5050           0 :                 st_ivas->hMasaIsmData->gain_masa_edited_fx = EDIT_GAIN_MAX_Q12;
    5051           0 :                 move16();
    5052             :             }
    5053        3500 :             ELSE IF( EQ_16( ism_mode, ISM_MASA_MODE_PARAM_ONE_OBJ ) && LT_32( hIvasEditableParameters.gain_bed_fx, EDIT_GAIN_MIN_Q29 ) )
    5054             :             {
    5055           0 :                 st_ivas->hMasaIsmData->gain_masa_edited_fx = EDIT_GAIN_MIN_Q12;
    5056           0 :                 move16();
    5057             :             }
    5058             :             ELSE
    5059             :             {
    5060        3500 :                 st_ivas->hMasaIsmData->gain_masa_edited_fx = shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 );
    5061        3500 :                 move16();
    5062             :             }
    5063             : #else
    5064             :             st_ivas->hMasaIsmData->gain_masa_edited_fx = shr( extract_h( hIvasEditableParameters.gain_bed_fx ), Q1 );
    5065             :             move32();
    5066             : #endif
    5067        3500 :             st_ivas->hMasaIsmData->masa_gain_is_edited = 1;
    5068             :         }
    5069             :         ELSE
    5070             :         {
    5071         174 :             st_ivas->hMasaIsmData->masa_gain_is_edited = 0;
    5072             :         }
    5073        3674 :         move16();
    5074             :     }
    5075             : 
    5076       16027 :     return IVAS_ERR_OK;
    5077             : }
    5078             : 
    5079             : 
    5080             : /*---------------------------------------------------------------------*
    5081             :  * IVAS_DEC_PrepareRenderer( )
    5082             :  *
    5083             :  * prepare IVAS renderer
    5084             :  *---------------------------------------------------------------------*/
    5085             : 
    5086      507614 : ivas_error IVAS_DEC_PrepareRenderer(
    5087             :     IVAS_DEC_HANDLE hIvasDec /* i/o: IVAS decoder handle    */
    5088             : )
    5089             : {
    5090      507614 :     test();
    5091      507614 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    5092             :     {
    5093           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    5094             :     }
    5095             : 
    5096      507614 :     test();
    5097      507614 :     IF( hIvasDec->hasBeenFedFirstGoodFrame || hIvasDec->isInitialized ) /* note: 'isInitialized' is related to EVS decoder */
    5098             :     {
    5099      507534 :         ivas_dec_prepare_renderer_fx( hIvasDec->st_ivas );
    5100             :     }
    5101             : 
    5102      507614 :     hIvasDec->hasBeenPreparedRendering = true;
    5103      507614 :     move16();
    5104             : 
    5105      507614 :     return IVAS_ERR_OK;
    5106             : }
    5107             : 
    5108             : 
    5109             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    5110             : 
    5111             : /*---------------------------------------------------------------------*
    5112             :  * ivas_dec_voip_get_samples_common( )
    5113             :  *
    5114             :  * Main function to output one frame in VoIP. Holds common code for
    5115             :  * regular output configs and split rendering configs.
    5116             :  *---------------------------------------------------------------------*/
    5117             : 
    5118      127418 : static ivas_error ivas_dec_voip_get_samples_common
    5119             : 
    5120             : #else
    5121             : /*---------------------------------------------------------------------*
    5122             :  * IVAS_DEC_VoIP_GetSamples( )
    5123             :  *
    5124             :  * Main function to decode one frame in VoIP
    5125             :  *---------------------------------------------------------------------*/
    5126             : ivas_error IVAS_DEC_VoIP_GetSamples
    5127             : #endif
    5128             :     (
    5129             :         IVAS_DEC_HANDLE hIvasDec,              /* i/o: IVAS decoder handle                                                     */
    5130             :         UWord16 nSamplesPerChannel,            /* i  : number of samples per channel requested to be written to output buffer  */
    5131             :         /* const IVAS_DEC_PCM_TYPE pcmType, */ /* i  : type for the decoded PCM resolution                                     */
    5132             :         Word16 *pcmBuf,                        /* o  : output synthesis signal                                                 */
    5133             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    5134             :         ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o  : output split rendering bits                                    */
    5135             :         Word32 **p_head_pose_buf,                 /* i  : PCM buffer with head-pose data                                          */
    5136             : #endif
    5137             : #ifdef SUPPORT_JBM_TRACEFILE
    5138             :         JbmTraceFileWriterFn jbmWriterFn,
    5139             :         void *jbmWriter,
    5140             : #endif
    5141             :         bool *bitstreamReadDone,             /* o  : flag indicating that bitstream was read                 */
    5142             :         UWord16 *nSamplesRendered,           /* o  : number of samples rendered                              */
    5143             :         bool *parametersAvailableForEditing, /* o  : indicates whether objects editing is available          */
    5144             :         const UWord32 systemTimestamp_ms     /* i  : current system timestamp                    */
    5145             :     )
    5146             : {
    5147             :     Decoder_Struct *st_ivas;
    5148             :     DECODER_CONFIG_HANDLE hDecoderConfig;
    5149             :     IVAS_DEC_VOIP *hVoIP;
    5150             :     UWord32 extBufferedTime_ms, scale, maxScaling;
    5151             :     JB4_DATAUNIT_HANDLE dataUnit;
    5152             :     UWord16 extBufferedSamples;
    5153             :     Word16 result;
    5154             :     ivas_error error;
    5155             :     UWord8 nOutChannels;
    5156             : 
    5157      127418 :     *parametersAvailableForEditing = false;
    5158      127418 :     move16();
    5159             : 
    5160      127418 :     test();
    5161      127418 :     test();
    5162      127418 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->hVoIP == NULL )
    5163             :     {
    5164           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    5165             :     }
    5166             : 
    5167      127418 :     st_ivas = hIvasDec->st_ivas;
    5168      127418 :     hDecoderConfig = st_ivas->hDecoderConfig;
    5169      127418 :     hVoIP = hIvasDec->hVoIP;
    5170      127418 :     nOutChannels = (UWord8) st_ivas->hDecoderConfig->nchan_out;
    5171      127418 :     move16();
    5172             : 
    5173      127418 :     IF( nSamplesPerChannel == 0 )
    5174             :     {
    5175           0 :         return IVAS_ERR_WRONG_PARAMS;
    5176             :     }
    5177             : 
    5178             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    5179      127418 :     test();
    5180      127418 :     test();
    5181      127418 :     IF( ( EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ||
    5182             :           EQ_32( hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ) &&
    5183             :         splitRendBits == NULL )
    5184             :     {
    5185           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    5186             :     }
    5187             : #endif
    5188             : 
    5189             :     /* make sure that the FIFO after decoder/scaler contains at least one sound card frame (i.e. 20ms) */
    5190      196632 :     WHILE( LT_16( *nSamplesRendered, nSamplesPerChannel ) )
    5191             :     {
    5192      153021 :         IF( hIvasDec->nSamplesAvailableNext == 0 )
    5193             :         {
    5194             :             Word16 nSamplesBuffered;
    5195       43610 :             nSamplesBuffered = 0;
    5196       43610 :             move16();
    5197             : 
    5198       43610 :             IF( hIvasDec->hasBeenFedFirstGoodFrame )
    5199             :             {
    5200             :                 /* check if the TC buffer already exists, otherweise nothing is buffered anyway */
    5201       43274 :                 IF( st_ivas->hTcBuffer != NULL )
    5202             :                 {
    5203       43274 :                     nSamplesBuffered = sub( st_ivas->hTcBuffer->n_samples_buffered, st_ivas->hTcBuffer->n_samples_rendered );
    5204       43274 :                     nSamplesBuffered = add( nSamplesBuffered, hVoIP->nSamplesRendered20ms );
    5205             :                 }
    5206             :             }
    5207             : 
    5208       43610 :             extBufferedSamples = nSamplesBuffered;
    5209       43610 :             move16();
    5210             :             Word16 exp;
    5211       43610 :             extBufferedTime_ms = BASOP_Util_Divide3232_Scale( imult3216( extBufferedSamples, 1000 ), hDecoderConfig->output_Fs, &exp );
    5212       43610 :             extBufferedTime_ms = (UWord32) W_shr( extBufferedTime_ms, sub( 15, exp ) ); // Q0
    5213       43610 :             dataUnit = NULL;
    5214             : 
    5215             :             /* pop one access unit from the jitter buffer */
    5216       43610 :             result = JB4_PopDataUnit( hVoIP->hJBM, systemTimestamp_ms, extBufferedTime_ms, &dataUnit, &scale, &maxScaling );
    5217       43610 :             IF( result != 0 )
    5218             :             {
    5219       40489 :                 return IVAS_ERR_UNKNOWN;
    5220             :             }
    5221             : 
    5222       43610 :             IF( EQ_32( hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
    5223             :             {
    5224        2058 :                 if ( GT_32( maxScaling, 20 ) )
    5225             :                 {
    5226           0 :                     maxScaling = 20;
    5227           0 :                     move16();
    5228             :                 }
    5229             :             }
    5230       43610 :             maxScaling = Mult_32_32( imult3216( hDecoderConfig->output_Fs, (Word16) maxScaling ), INV_1000_Q31 );
    5231             : 
    5232             : #ifdef DEBUG_MODE_JBM
    5233             :             dbgwrite( &extBufferedSamples, sizeof( uint16_t ), 1, 1, "./res/JBM_extBufferedSamples.dat" );
    5234             :             dbgwrite( &systemTimestamp_ms, sizeof( uint32_t ), 1, 1, "./res/JBM_systemTimestamp.dat" );
    5235             :             dbgwrite( &scale, sizeof( uint32_t ), 1, 1, "./res/JBM_scale.dat" );
    5236             :             dbgwrite( &maxScaling, sizeof( uint32_t ), 1, 1, "./res/JBM_maxScale.dat" );
    5237             : #endif
    5238             :             /* avoid time scaling multiple times within one 20ms frame*/
    5239       43610 :             IF( NE_64( scale, 100U ) )
    5240             :             {
    5241         778 :                 IF( hIvasDec->timeScalingDone )
    5242             :                 {
    5243           0 :                     scale = 100;
    5244           0 :                     move32();
    5245             :                 }
    5246             :             }
    5247             : 
    5248             :             /* limit scale to range supported by time scaler */
    5249       43610 :             IF( LT_32( scale, APA_MIN_SCALE ) )
    5250             :             {
    5251           0 :                 scale = APA_MIN_SCALE;
    5252           0 :                 move32();
    5253             :             }
    5254       43610 :             ELSE IF( GT_32( scale, APA_MAX_SCALE ) )
    5255             :             {
    5256           0 :                 scale = APA_MAX_SCALE;
    5257           0 :                 move32();
    5258             :             }
    5259             : 
    5260       43610 :             IF( NE_32( ( error = IVAS_DEC_VoIP_SetScale( hIvasDec, (Word16) maxScaling, (Word16) scale ) ), IVAS_ERR_OK ) )
    5261             :             {
    5262           0 :                 return error;
    5263             :             }
    5264             : 
    5265             :             /* copy bitstream into decoder state */
    5266       43610 :             IF( dataUnit )
    5267             :             {
    5268       40489 :                 hIvasDec->hVoIP->hCurrentDataUnit = dataUnit;
    5269             : 
    5270       40489 :                 bsCompactToSerial( dataUnit->data, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize );
    5271             : 
    5272       40489 :                 IF( NE_32( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, dataUnit->dataSize, 0 ) ), IVAS_ERR_OK ) )
    5273             :                 {
    5274           0 :                     return error;
    5275             :                 }
    5276             : 
    5277       40489 :                 *bitstreamReadDone = true;
    5278             :             }
    5279        3121 :             ELSE IF( hIvasDec->hasDecodedFirstGoodFrame )
    5280             :             {
    5281             :                 /* Decoder has been initialized with first good frame - do PLC */
    5282        2837 :                 IF( NE_32( ( error = IVAS_DEC_FeedFrame_Serial( hIvasDec, hIvasDec->hVoIP->bs_conversion_buf, 0, 1 ) ), IVAS_ERR_OK ) )
    5283             :                 {
    5284           0 :                     return error;
    5285             :                 }
    5286             :             }
    5287             : 
    5288             : #ifdef SUPPORT_JBM_TRACEFILE
    5289             :             /* jbmWriterFn and jbmWriter may be NULL if tracefile writing was not requested on CLI */
    5290       43610 :             test();
    5291       43610 :             IF( jbmWriterFn != NULL && jbmWriter != NULL )
    5292             :             {
    5293             :                 /* write JBM trace data entry */
    5294       34824 :                 store_JbmData( hVoIP, dataUnit, systemTimestamp_ms, extBufferedSamples, hDecoderConfig->output_Fs );
    5295       34824 :                 IF( ( jbmWriterFn( &hVoIP->JbmTraceData, jbmWriter ) ) != IVAS_ERR_OK )
    5296             :                 {
    5297           0 :                     fprintf( stderr, "\nError writing JBM Trace data to file\n" );
    5298           0 :                     return IVAS_ERR_UNKNOWN;
    5299             :                 }
    5300             :             }
    5301             : #endif
    5302       43610 :             IF( dataUnit )
    5303             :             {
    5304       40489 :                 IF( dataUnit->partial_frame != 0 )
    5305             :                 {
    5306           0 :                     hVoIP->lastDecodedWasActive = 1;
    5307             :                 }
    5308             :                 ELSE
    5309             :                 {
    5310       40489 :                     hVoIP->lastDecodedWasActive = !dataUnit->silenceIndicator;
    5311             :                 }
    5312       40489 :                 move16();
    5313             : 
    5314             :                 /* data unit memory is no longer used */
    5315       40489 :                 JB4_FreeDataUnit( hVoIP->hJBM, dataUnit );
    5316             :             }
    5317             : 
    5318       43610 :             test();
    5319       43610 :             IF( hIvasDec->hasBeenFedFirstGoodFrame && *bitstreamReadDone == true )
    5320             :             {
    5321             :                 /* new bitstream was feeded, return for reconfiguration */
    5322       40489 :                 return IVAS_ERR_OK;
    5323             :             }
    5324             : 
    5325        3121 :             IF( !hIvasDec->hasBeenFedFirstGoodFrame )
    5326             :             {
    5327         292 :                 hIvasDec->nSamplesAvailableNext = hIvasDec->nSamplesFrame;
    5328         292 :                 move16();
    5329             :             }
    5330             :         }
    5331             : 
    5332             :         /* decode */
    5333      112532 :         IF( !hIvasDec->hasBeenFedFirstGoodFrame )
    5334             :         {
    5335             :             /* codec mode to use not known yet - simply output silence */
    5336             :             /* directly set output zero */
    5337         292 :             Word16 nSamplesToZero = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext );
    5338         292 :             set16_fx( pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), 0, imult1616( nSamplesToZero, nOutChannels ) );
    5339         292 :             *nSamplesRendered = add( *nSamplesRendered, nSamplesToZero );
    5340         292 :             hIvasDec->nSamplesAvailableNext = sub( hIvasDec->nSamplesAvailableNext, nSamplesToZero );
    5341         292 :             move16();
    5342         292 :             move16();
    5343         292 :             update_voip_rendered20ms( hIvasDec, nSamplesToZero );
    5344             :         }
    5345             :         ELSE
    5346             :         {
    5347             :             Word16 nSamplesToRender, nSamplesRendered_loop;
    5348             :             bool tmp;
    5349             : 
    5350             :             /* decode TCs, do TSM and prepare the renderer */
    5351      112240 :             test();
    5352      112240 :             IF( !hIvasDec->isInitialized || hIvasDec->hasBeenFedFrame )
    5353             :             {
    5354       43318 :                 test();
    5355       43318 :                 IF( hIvasDec->nSamplesAvailableNext == 0 || EQ_16( hIvasDec->nSamplesAvailableNext, hIvasDec->nSamplesFrame ) )
    5356             :                 {
    5357             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    5358       43318 :                     IF( NE_32( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, splitRendBits ) ), IVAS_ERR_OK ) )
    5359             : #else
    5360             :                     IF( ( error = IVAS_DEC_GetSamplesDecoder( hIvasDec, 0, 0 ) ) != IVAS_ERR_OK )
    5361             : #endif
    5362             :                     {
    5363       43318 :                         return error;
    5364             :                     }
    5365             : 
    5366       43318 :                     *bitstreamReadDone = false;
    5367       43318 :                     move16();
    5368       43318 :                     *parametersAvailableForEditing = true;
    5369       43318 :                     move16();
    5370             : 
    5371       43318 :                     return IVAS_ERR_OK;
    5372             :                 }
    5373             :             }
    5374             : 
    5375       68922 :             nSamplesToRender = sub( nSamplesPerChannel, *nSamplesRendered );
    5376             : 
    5377             :             /* check if we still need to prepare the renderer */
    5378       68922 :             IF( hIvasDec->hasBeenPreparedRendering == false )
    5379             :             {
    5380       43318 :                 IF( NE_32( ( error = IVAS_DEC_PrepareRenderer( hIvasDec ) ), IVAS_ERR_OK ) )
    5381             :                 {
    5382           0 :                     return error;
    5383             :                 }
    5384             :             }
    5385             : 
    5386             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    5387       68922 :             IF( splitRendBits != NULL )
    5388             :             {
    5389             :                 /* Render head poses from time-scaled transport channels */
    5390           0 :                 IF( NE_32( ( error = isar_render_poses( hIvasDec, nSamplesToRender, &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) )
    5391             :                 {
    5392           0 :                     return error;
    5393             :                 }
    5394             :             }
    5395             :             ELSE
    5396             :             {
    5397             : #endif
    5398             :                 /* render IVAS frames  directly to the output buffer */
    5399       68922 :                 IF( NE_32( ( error = IVAS_DEC_GetSamplesRenderer( hIvasDec, nSamplesToRender, pcmBuf + imult1616( *nSamplesRendered, nOutChannels ), &nSamplesRendered_loop, &tmp ) ), IVAS_ERR_OK ) )
    5400             :                 {
    5401           0 :                     return error;
    5402             :                 }
    5403             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    5404             :             }
    5405             : #endif
    5406             : 
    5407       68922 :             *nSamplesRendered = add( *nSamplesRendered, nSamplesRendered_loop );
    5408       68922 :             update_voip_rendered20ms( hIvasDec, nSamplesRendered_loop );
    5409             :         }
    5410             :     }
    5411             : 
    5412             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    5413       43611 :     IF( hIvasDec->hasDecodedFirstGoodFrame && splitRendBits != NULL )
    5414             :     {
    5415             :         Word16 Q_out[MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS];
    5416             :         Word16 i;
    5417             : 
    5418             :         /* Analyse head poses over entire frame, generate ISAR metadata and maybe encode if split coded */
    5419           0 :         IF( NE_32( ( error = isar_generate_metadata_and_bitstream( st_ivas, p_head_pose_buf, *nSamplesRendered, splitRendBits, Q_out ) ), IVAS_ERR_OK ) )
    5420             :         {
    5421           0 :             return error;
    5422             :         }
    5423             : 
    5424             :         /* Synthesise PCM output if split PCM */
    5425           0 :         IF( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    5426             :         {
    5427           0 :             FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
    5428             :             {
    5429           0 :                 scale_sig32( p_head_pose_buf[i], *nSamplesRendered, sub( Q11, Q_out[i] ) ); // Q11
    5430             :             }
    5431             : 
    5432           0 :             IF( EQ_32( st_ivas->hDecoderConfig->render_framesize, IVAS_RENDER_FRAMESIZE_5MS ) )
    5433             :             {
    5434             : #ifndef DISABLE_LIMITER
    5435           0 :                 ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, Q11 );
    5436             : #endif
    5437             :             }
    5438             :             ELSE
    5439             :             {
    5440           0 :                 ivas_limiter_dec_fx( st_ivas->hLimiter, p_head_pose_buf, st_ivas->hDecoderConfig->nchan_out, *nSamplesRendered, st_ivas->BER_detect, Q11 );
    5441             :             }
    5442             : 
    5443           0 :             ivas_syn_output_fx( p_head_pose_buf, Q11, *nSamplesRendered, st_ivas->hDecoderConfig->nchan_out, pcmBuf );
    5444             :         }
    5445             :     }
    5446             : #endif
    5447             : 
    5448       43611 :     return IVAS_ERR_OK;
    5449             : }
    5450             : 
    5451             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    5452             : 
    5453             : /*---------------------------------------------------------------------*
    5454             :  * IVAS_DEC_VoIP_GetSamples( )
    5455             :  *
    5456             :  * Main function to decode one frame in VoIP
    5457             :  *---------------------------------------------------------------------*/
    5458             : 
    5459      127418 : ivas_error IVAS_DEC_VoIP_GetSamples(
    5460             :     IVAS_DEC_HANDLE hIvasDec,              /* i/o: IVAS decoder handle                                                     */
    5461             :     UWord16 nSamplesPerChannel,            /* i  : number of samples per channel requested to be written to output buffer  */
    5462             :     /* const IVAS_DEC_PCM_TYPE pcmType, */ /* i  : type for the decoded PCM resolution                                     */
    5463             :     Word16 *pcmBuf,                        /* o  : output synthesis signal                                                 */
    5464             : #ifdef SUPPORT_JBM_TRACEFILE
    5465             :     JbmTraceFileWriterFn jbmWriterFn,
    5466             :     void *jbmWriter,
    5467             : #endif
    5468             :     bool *bitstreamReadDone,             /* o  : flag indicating that bitstream was read                                 */
    5469             :     UWord16 *nSamplesRendered,           /* o  : number of samples rendered                                              */
    5470             :     bool *parametersAvailableForEditing, /* o  : indicates whether objects editing is available                          */
    5471             :     const UWord32 systemTimestamp_ms     /* i  : current system timestamp                                                */
    5472             : )
    5473             : {
    5474      127418 :     return ivas_dec_voip_get_samples_common(
    5475             :         hIvasDec,
    5476             :         nSamplesPerChannel,
    5477             :         /* pcmType, */
    5478             :         pcmBuf,
    5479             :         NULL,
    5480             :         NULL,
    5481             : #ifdef SUPPORT_JBM_TRACEFILE
    5482             :         jbmWriterFn,
    5483             :         jbmWriter,
    5484             : #endif
    5485             :         bitstreamReadDone,
    5486             :         nSamplesRendered,
    5487             :         parametersAvailableForEditing,
    5488             :         systemTimestamp_ms );
    5489             : }
    5490             : 
    5491             : 
    5492             : /*---------------------------------------------------------------------*
    5493             :  * IVAS_DEC_VoIP_GetSplitBinauralBitstream( )
    5494             :  *
    5495             :  * Main function to decode one split-rendering frame in VoIP
    5496             :  *---------------------------------------------------------------------*/
    5497             : 
    5498             : /*! r: error code */
    5499           0 : ivas_error IVAS_DEC_VoIP_GetSplitBinauralBitstream(
    5500             :     IVAS_DEC_HANDLE hIvasDec,                 /* i/o: IVAS decoder handle                                                     */
    5501             :     /* const IVAS_DEC_PCM_TYPE pcmType, */    /* i  : type for the decoded PCM resolution                                     */
    5502             :     Word16 *pcmBuf,                           /* o  : output synthesis signal                                                 */
    5503             :     ISAR_SPLIT_REND_BITS_DATA *splitRendBits, /* o  : output split rendering bits                                             */
    5504             : #ifdef SUPPORT_JBM_TRACEFILE
    5505             :     JbmTraceFileWriterFn jbmWriterFn,
    5506             :     void *jbmWriter,
    5507             : #endif
    5508             :     bool *bitstreamReadDone,             /* o  : flag indicating that bitstream was read                                 */
    5509             :     UWord16 *nSamplesRendered,           /* o  : number of samples rendered                                              */
    5510             :     bool *parametersAvailableForEditing, /* o  : indicates whether objects editing is available                          */
    5511             :     const UWord32 systemTimestamp_ms     /* i  : current system timestamp                                                */
    5512             : )
    5513             : {
    5514             :     Word16 i;
    5515             :     Word32 head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES][L_FRAME48k];
    5516             :     Word32 *pp_head_pose_buf[BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES];
    5517           0 :     ivas_error error = IVAS_ERR_UNKNOWN;
    5518           0 :     Word16 nSamplesPerChannel = 0;
    5519           0 :     move16();
    5520             : 
    5521           0 :     IF( NE_32( ( error = IVAS_DEC_GetRenderFramesizeSamples( hIvasDec, &nSamplesPerChannel ) ), IVAS_ERR_OK ) )
    5522             :     {
    5523           0 :         return error;
    5524             :     }
    5525             : 
    5526             :     /* Set pointers to beginning of head pose buffers */
    5527           0 :     FOR( i = 0; i < BINAURAL_CHANNELS * MAX_HEAD_ROT_POSES; ++i )
    5528             :     {
    5529           0 :         pp_head_pose_buf[i] = head_pose_buf[i];
    5530             :     }
    5531             : 
    5532           0 :     return ivas_dec_voip_get_samples_common(
    5533             :         hIvasDec,
    5534             :         nSamplesPerChannel,
    5535             :         /* IVAS_DEC_PCM_INT16, */
    5536             :         pcmBuf,
    5537             :         splitRendBits,
    5538             :         pp_head_pose_buf,
    5539             : #ifdef SUPPORT_JBM_TRACEFILE
    5540             :         jbmWriterFn,
    5541             :         jbmWriter,
    5542             : #endif
    5543             :         bitstreamReadDone,
    5544             :         nSamplesRendered,
    5545             :         parametersAvailableForEditing,
    5546             :         systemTimestamp_ms );
    5547             : }
    5548             : #endif
    5549             : 
    5550             : 
    5551             : /*---------------------------------------------------------------------*
    5552             :  * update_voip_rendered20ms( )
    5553             :  *
    5554             :  * pdate the number of samples that have been rendered since the last 20ms render border
    5555             :  *---------------------------------------------------------------------*/
    5556             : 
    5557       69214 : static void update_voip_rendered20ms(
    5558             :     IVAS_DEC_HANDLE hIvasDec,
    5559             :     const Word16 nSamplesRendered )
    5560             : {
    5561             :     Word16 nSamplesRenderedTotal;
    5562             : 
    5563       69214 :     nSamplesRenderedTotal = add( hIvasDec->hVoIP->nSamplesRendered20ms, nSamplesRendered );
    5564             : 
    5565             :     /* we have crossed a 20ms border, reset the time scaling done flag */
    5566       69214 :     IF( GE_16( nSamplesRenderedTotal, hIvasDec->nSamplesFrame ) )
    5567             :     {
    5568       43611 :         hIvasDec->timeScalingDone = 0;
    5569       43611 :         move16();
    5570             :     }
    5571             : 
    5572             :     /* float code was: hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal % hIvasDec->hVoIP->nSamplesFrame; */
    5573       69214 :     hIvasDec->hVoIP->nSamplesRendered20ms = nSamplesRenderedTotal;
    5574       69214 :     move16();
    5575      112825 :     WHILE( GE_16( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->nSamplesFrame ) )
    5576             :     {
    5577       43611 :         hIvasDec->hVoIP->nSamplesRendered20ms = sub( hIvasDec->hVoIP->nSamplesRendered20ms, hIvasDec->nSamplesFrame );
    5578             :     }
    5579             : 
    5580       69214 :     return;
    5581             : }
    5582             : 
    5583             : 
    5584             : /*---------------------------------------------------------------------*
    5585             :  * IVAS_DEC_VoIP_Flush( )
    5586             :  *
    5587             :  * Function to flush remaining audio samples in VoIP
    5588             :  *---------------------------------------------------------------------*/
    5589             : 
    5590          44 : ivas_error IVAS_DEC_Flush(
    5591             :     IVAS_DEC_HANDLE hIvasDec,        /* i/o: IVAS decoder handle                                                           */
    5592             :     const Word16 nSamplesPerChannel, /* i  : number of samples per channel requested to be written to output buffer        */
    5593             :     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 */
    5594             :     Word16 *nSamplesFlushed          /* o  : number of samples flushed                                                     */
    5595             : )
    5596             : {
    5597             :     ivas_error error;
    5598             :     UWord16 nSamplesToRender;
    5599             :     UWord16 nSamplesFlushedLocal;
    5600             : 
    5601          44 :     test();
    5602          44 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    5603             :     {
    5604           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    5605             :     }
    5606             : 
    5607             : #ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR
    5608          44 :     hIvasDec->st_ivas->flushing = 1;
    5609          44 :     move16();
    5610             : #endif
    5611             : 
    5612          44 :     *nSamplesFlushed = s_min( nSamplesPerChannel, hIvasDec->nSamplesAvailableNext );
    5613          44 :     move16();
    5614             : 
    5615          44 :     nSamplesToRender = (UWord16) *nSamplesFlushed;
    5616          44 :     move16();
    5617             : 
    5618             :     /* render IVAS frames  */
    5619          44 :     error = IVAS_ERR_OK;
    5620          44 :     move16();
    5621             : 
    5622          44 :     test();
    5623          44 :     IF( GT_16( nSamplesToRender, 0 ) && NE_16( (Word16) hIvasDec->st_ivas->ivas_format, (Word16) MONO_FORMAT ) )
    5624             :     {
    5625          25 :         error = ivas_jbm_dec_render_fx( hIvasDec->st_ivas, nSamplesToRender, &nSamplesFlushedLocal, &hIvasDec->nSamplesAvailableNext, pcmBuf );
    5626             :     }
    5627             :     ELSE
    5628             :     {
    5629          19 :         *nSamplesFlushed = 0;
    5630          19 :         move16();
    5631             :     }
    5632             : 
    5633             : #ifdef TMP_1342_WORKAROUND_DEC_FLUSH_BROKEN_IN_SR
    5634          44 :     hIvasDec->st_ivas->flushing = 0;
    5635          44 :     move16();
    5636             : #endif
    5637             : 
    5638          44 :     return error;
    5639             : }
    5640             : 
    5641             : 
    5642             : #ifdef DECODER_FORMAT_SWITCHING
    5643             : /*---------------------------------------------------------------------*
    5644             :  * IVAS_DEC_isRestartNeeded( )
    5645             :  *
    5646             :  *
    5647             :  *---------------------------------------------------------------------*/
    5648             : 
    5649       40489 : ivas_error IVAS_DEC_isRestartNeeded(
    5650             :     IVAS_DEC_HANDLE hIvasDec, /* i  : IVAS decoder handle            */
    5651             :     bool *restartNeeded       /* o  : flag to signal decoder restart */
    5652             : )
    5653             : {
    5654       40489 :     test();
    5655       40489 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    5656             :     {
    5657           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    5658             :     }
    5659             : 
    5660       40489 :     *restartNeeded = false;
    5661       40489 :     move16();
    5662       40489 :     if ( EQ_16( hIvasDec->st_ivas->restartNeeded, 1 ) )
    5663             :     {
    5664           0 :         *restartNeeded = true;
    5665           0 :         move16();
    5666             :     }
    5667             : 
    5668       40489 :     return IVAS_ERR_OK;
    5669             : }
    5670             : 
    5671             : 
    5672             : #endif
    5673             : /*---------------------------------------------------------------------*
    5674             :  * IVAS_DEC_VoIP_IsEmpty( )
    5675             :  *
    5676             :  * Returns 'true' if decoder has no data in VoIP jitter buffer
    5677             :  *---------------------------------------------------------------------*/
    5678             : 
    5679       43655 : ivas_error IVAS_DEC_VoIP_IsEmpty(
    5680             :     IVAS_DEC_HANDLE hIvasDec,   /* i/o: IVAS decoder handle              */
    5681             :     const Word16 nSamplesAsked, /* i  : number of output samples asked   */
    5682             :     bool *isEmpty               /* o  : isEmpty flag                     */
    5683             : )
    5684             : {
    5685       43655 :     test();
    5686       43655 :     IF( hIvasDec == NULL || hIvasDec->hVoIP == NULL )
    5687             :     {
    5688           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    5689             :     }
    5690             : 
    5691       43655 :     *isEmpty = false;
    5692       43655 :     move16();
    5693       43655 :     test();
    5694       43655 :     if ( ( JB4_bufferedDataUnits( hIvasDec->hVoIP->hJBM ) == 0 ) && LT_16( hIvasDec->nSamplesAvailableNext, nSamplesAsked ) )
    5695             :     {
    5696         916 :         *isEmpty = true;
    5697         916 :         move16();
    5698             :     }
    5699             : 
    5700       43655 :     return IVAS_ERR_OK;
    5701             : }
    5702             : 
    5703             : 
    5704             : /*---------------------------------------------------------------------*
    5705             :  * IVAS_DEC_VoIP_Get_CA_offset( )
    5706             :  *
    5707             :  *
    5708             :  *---------------------------------------------------------------------*/
    5709             : 
    5710           0 : ivas_error IVAS_DEC_VoIP_Get_CA_offset(
    5711             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle */
    5712             :     Word16 *optimum_offset,
    5713             :     Word16 *FEC_hi )
    5714             : {
    5715           0 :     test();
    5716           0 :     test();
    5717           0 :     IF( ( hIvasDec == NULL || hIvasDec->hVoIP == NULL || hIvasDec->hVoIP->hJBM == NULL ) )
    5718             :     {
    5719           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    5720             :     }
    5721             : 
    5722           0 :     *optimum_offset = JB4_getFECoffset( hIvasDec->hVoIP->hJBM );
    5723           0 :     *FEC_hi = JB4_FECoffset( hIvasDec->hVoIP->hJBM );
    5724           0 :     move16();
    5725           0 :     move16();
    5726             : 
    5727           0 :     return IVAS_ERR_OK;
    5728             : }
    5729             : 
    5730             : 
    5731             : /*---------------------------------------------------------------------*
    5732             :  * ivas_destroy_handle_VoIP( )
    5733             :  *
    5734             :  * Deallocate VoIP handle
    5735             :  *---------------------------------------------------------------------*/
    5736             : 
    5737          51 : static void ivas_destroy_handle_VoIP_fx(
    5738             :     IVAS_DEC_VOIP *hVoIP /* i/o: IVAS decoder handle */
    5739             : )
    5740             : {
    5741          51 :     JB4_Destroy( &hVoIP->hJBM );
    5742             : 
    5743          51 :     IF( hVoIP->bs_conversion_buf != NULL )
    5744             :     {
    5745             : #define WMC_TOOL_SKIP
    5746             :         /* Bitstream conversion is not counted towards complexity and memory usage */
    5747          51 :         free( hVoIP->bs_conversion_buf );
    5748             : #undef WMC_TOOL_SKIP
    5749             :     }
    5750             : 
    5751          51 :     free( hVoIP );
    5752             : 
    5753          51 :     return;
    5754             : }
    5755             : 
    5756             : #ifdef SUPPORT_JBM_TRACEFILE
    5757             : 
    5758             : /*---------------------------------------------------------------------*
    5759             :  * store_JbmData()
    5760             :  *
    5761             :  * Store JBM trace data entry
    5762             :  *---------------------------------------------------------------------*/
    5763             : 
    5764       34824 : static void store_JbmData(
    5765             :     IVAS_DEC_VOIP *hVoIP,
    5766             :     JB4_DATAUNIT_HANDLE dataUnit,
    5767             :     const UWord32 systemTimestamp_ms,
    5768             :     const UWord16 extBufferedSamples,
    5769             :     const Word32 output_Fs )
    5770             : {
    5771             :     IVAS_JBM_TRACE_DATA *JbmTraceData;
    5772             : 
    5773       34824 :     IF( hVoIP == NULL )
    5774             :     {
    5775           0 :         return;
    5776             :     }
    5777             : 
    5778       34824 :     JbmTraceData = &hVoIP->JbmTraceData;
    5779             : 
    5780       34824 :     JbmTraceData->systemTimestamp_ms = systemTimestamp_ms;
    5781       34824 :     JbmTraceData->extBufferedSamples = extBufferedSamples;
    5782       34824 :     JbmTraceData->lastDecodedWasActive = hVoIP->lastDecodedWasActive;
    5783       34824 :     JbmTraceData->output_Fs = output_Fs;
    5784       34824 :     JbmTraceData->dataUnit_flag = dataUnit != NULL;
    5785       34824 :     move16();
    5786       34824 :     move16();
    5787       34824 :     move16();
    5788       34824 :     move32();
    5789       34824 :     move32();
    5790       34824 :     IF( dataUnit != NULL )
    5791             :     {
    5792       31739 :         JbmTraceData->sequenceNumber = dataUnit->sequenceNumber;
    5793       31739 :         JbmTraceData->timeStamp = dataUnit->timeStamp;
    5794       31739 :         JbmTraceData->rcvTime = dataUnit->rcvTime;
    5795       31739 :         JbmTraceData->partial_frame = dataUnit->partial_frame;
    5796       31739 :         JbmTraceData->partialCopyOffset = dataUnit->partialCopyOffset;
    5797       31739 :         move16();
    5798       31739 :         move16();
    5799       31739 :         move16();
    5800       31739 :         move32();
    5801       31739 :         move32();
    5802             :     }
    5803             : 
    5804       34824 :     return;
    5805             : }
    5806             : 
    5807             : 
    5808             : /*---------------------------------------------------------------------*
    5809             :  * IVAS_DEC_GetJbmData()
    5810             :  *
    5811             :  *
    5812             :  *---------------------------------------------------------------------*/
    5813             : 
    5814           0 : ivas_error IVAS_DEC_GetJbmData(
    5815             :     IVAS_DEC_HANDLE hIvasDec,         /* i/o: IVAS decoder handle */
    5816             :     IVAS_JBM_TRACE_DATA *JbmTraceData /* o  : JBM Trace data      */
    5817             : 
    5818             : )
    5819             : {
    5820           0 :     test();
    5821           0 :     test();
    5822           0 :     IF( hIvasDec == NULL || hIvasDec->hVoIP == NULL || JbmTraceData == NULL )
    5823             :     {
    5824           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    5825             :     }
    5826             : 
    5827           0 :     *JbmTraceData = hIvasDec->hVoIP->JbmTraceData;
    5828             : 
    5829           0 :     return IVAS_ERR_OK;
    5830             : }
    5831             : 
    5832             : #endif
    5833             : 
    5834             : /*---------------------------------------------------------------------*
    5835             :  * IVAS_DEC_GetErrorMessage( )
    5836             :  *
    5837             :  * Maps error codes to error description strings
    5838             :  *---------------------------------------------------------------------*/
    5839             : 
    5840           0 : const char *IVAS_DEC_GetErrorMessage(
    5841             :     ivas_error error /* i  : decoder error code enum */
    5842             : )
    5843             : {
    5844           0 :     return ivas_error_to_string( error );
    5845             : }
    5846             : 
    5847             : 
    5848             : /*---------------------------------------------------------------------*
    5849             :  * printConfigInfo_dec( )
    5850             :  *
    5851             :  *
    5852             :  *---------------------------------------------------------------------*/
    5853             : 
    5854         645 : static ivas_error printConfigInfo_dec(
    5855             :     Decoder_Struct *st_ivas,
    5856             :     const Word16 bitstreamformat,
    5857             :     const bool Opt_VOIP,
    5858             :     const bool quietModeEnabled )
    5859             : {
    5860             :     ivas_error error;
    5861             :     Word8 config_str[50];
    5862             :     AUDIO_CONFIG output_config;
    5863             : 
    5864             :     /*-----------------------------------------------------------------*
    5865             :      * Print info on screen
    5866             :      *-----------------------------------------------------------------*/
    5867             : 
    5868         645 :     fprintf( stdout, "\n" );
    5869             : 
    5870             :     /*-----------------------------------------------------------------*
    5871             :      * Print output sampling frequency
    5872             :      *-----------------------------------------------------------------*/
    5873             : 
    5874         645 :     fprintf( stdout, "Output sampling rate:   %d Hz\n", st_ivas->hDecoderConfig->output_Fs );
    5875             : 
    5876             :     /*-----------------------------------------------------------------*
    5877             :      * Print bitrate
    5878             :      *-----------------------------------------------------------------*/
    5879             : 
    5880         645 :     IF( !quietModeEnabled )
    5881             :     {
    5882           0 :         IF( !Opt_VOIP )
    5883             :         {
    5884           0 :             fprintf( stdout, "Bitrate:                %.2f kbps\n", (float) st_ivas->hDecoderConfig->ivas_total_brate / 1000 );
    5885             : 
    5886           0 :             IF( st_ivas->hDecoderConfig->ivas_total_brate <= 0 )
    5887             :             {
    5888           0 :                 IF( EQ_16( bitstreamformat, G192 ) )
    5889             :                 {
    5890           0 :                     fprintf( stdout, "Active Bitrate not identified in bitstream file \n" );
    5891             :                 }
    5892             :                 ELSE /* MIME */
    5893             :                 {
    5894           0 :                     fprintf( stdout, "Active Bitrate not identified from first MIME frame \n" );
    5895             :                 }
    5896             :             }
    5897             :         }
    5898             :     }
    5899             : 
    5900             :     /*-----------------------------------------------------------------*
    5901             :      * Print output configuration
    5902             :      *-----------------------------------------------------------------*/
    5903             : 
    5904         645 :     IF( EQ_16( (Word16) st_ivas->ivas_format, MONO_FORMAT ) )
    5905             :     {
    5906           5 :         IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan )
    5907             :         {
    5908           1 :             fprintf( stdout, "Output configuration:   mono EVS bit-exact decoding to stereo\n" );
    5909           1 :             float non_diegetic_pan_gain = (float) ( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx ) / (float) ( 1LL << Q15 );
    5910           1 :             fprintf( stdout, "Non-diegetic panning:   %.2f\n", non_diegetic_pan_gain * 90.f );
    5911             :         }
    5912             :         ELSE
    5913             :         {
    5914             : #ifdef FIX_1419_MONO_STEREO_UMX
    5915           4 :             output_config = st_ivas->hDecoderConfig->output_config;
    5916           4 :             IF( NE_16( (Word16) output_config, IVAS_AUDIO_CONFIG_MONO ) )
    5917             :             {
    5918           0 :                 get_channel_config( output_config, &config_str[0] );
    5919           0 :                 fprintf( stdout, "Output configuration:   mono EVS bit-exact decoding rendering to %s\n", config_str );
    5920             :             }
    5921             :             ELSE
    5922             :             {
    5923             : #endif
    5924           4 :                 fprintf( stdout, "Output configuration:   mono EVS bit-exact decoding\n" );
    5925             : #ifdef FIX_1419_MONO_STEREO_UMX
    5926             :             }
    5927             : #endif
    5928             :         }
    5929             :     }
    5930             :     ELSE
    5931             :     {
    5932         640 :         IF( !quietModeEnabled )
    5933             :         {
    5934           0 :             IF( EQ_16( (Word16) st_ivas->ivas_format, STEREO_FORMAT ) )
    5935             :             {
    5936           0 :                 fprintf( stdout, "Input configuration:    Stereo\n" );
    5937             :             }
    5938           0 :             ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, ISM_FORMAT ) )
    5939             :             {
    5940           0 :                 IF( EQ_16( (Word16) st_ivas->ism_mode, ISM_MODE_PARAM ) )
    5941             :                 {
    5942           0 :                     fprintf( stdout, "Input configuration:    ISM (ParamISM): 2 transport channels\n" );
    5943             :                 }
    5944             :                 ELSE
    5945             :                 {
    5946           0 :                     fprintf( stdout, "Input configuration:    ISM: %d transport channel(s)\n", st_ivas->nchan_transport );
    5947             :                 }
    5948             :             }
    5949           0 :             ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_FORMAT ) )
    5950             :             {
    5951           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 );
    5952             :             }
    5953           0 :             ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, SBA_ISM_FORMAT ) )
    5954             :             {
    5955           0 :                 fprintf( stdout, "Input configuration:    Combined Scene Based Audio, Ambisonic order %i, with %d Objects \n", st_ivas->sba_order, st_ivas->nchan_ism );
    5956             :             }
    5957           0 :             ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_FORMAT ) )
    5958             :             {
    5959           0 :                 fprintf( stdout, "Input configuration:    MASA - %d channel(s)\n", st_ivas->nchan_transport );
    5960             :             }
    5961           0 :             ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MC_FORMAT ) )
    5962             :             {
    5963           0 :                 IF( NE_32( ( error = get_channel_config( st_ivas->transport_config, &config_str[0] ) ), IVAS_ERR_OK ) )
    5964             :                 {
    5965           0 :                     return error;
    5966             :                 }
    5967             : 
    5968           0 :                 fprintf( stdout, "Input configuration:    %s\n", config_str );
    5969             :             }
    5970           0 :             ELSE IF( EQ_16( (Word16) st_ivas->ivas_format, MASA_ISM_FORMAT ) )
    5971             :             {
    5972           0 :                 fprintf( stdout, "Input configuration:    combined ISM and MASA (%i ISM stream(s)) \n", st_ivas->nchan_ism );
    5973             :             }
    5974             :         }
    5975             : 
    5976         640 :         output_config = st_ivas->hDecoderConfig->output_config;
    5977         640 :         move16();
    5978         640 :         get_channel_config( output_config, &config_str[0] );
    5979         640 :         fprintf( stdout, "Output configuration:   %s\n", config_str );
    5980             : 
    5981         640 :         test();
    5982         640 :         test();
    5983         640 :         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 ) ) )
    5984             :         {
    5985         221 :             fprintf( stdout, "Render framesize:       %dms\n", get_render_frame_size_ms( st_ivas->hDecoderConfig->render_framesize ) );
    5986             :         }
    5987         640 :         IF( st_ivas->hDecoderConfig->Opt_HRTF_binary )
    5988             :         {
    5989          24 :             fprintf( stdout, "HRIR/BRIR file:         ON\n" );
    5990             :         }
    5991             : 
    5992         640 :         IF( st_ivas->hDecoderConfig->Opt_RendConfigCustom )
    5993             :         {
    5994          32 :             fprintf( stdout, "Renderer config. file:  ON\n" );
    5995             :         }
    5996             : 
    5997         640 :         IF( st_ivas->hDecoderConfig->Opt_Headrotation )
    5998             :         {
    5999          83 :             fprintf( stdout, "Head rotation:          ON\n" );
    6000             :         }
    6001             : 
    6002         640 :         IF( st_ivas->hDecoderConfig->Opt_ExternalOrientation )
    6003             :         {
    6004          31 :             fprintf( stdout, "External orientation:   ON\n" );
    6005             :         }
    6006             : 
    6007         640 :         IF( NE_16( (Word16) st_ivas->hDecoderConfig->orientation_tracking, IVAS_HEAD_ORIENT_TRK_NONE ) )
    6008             :         {
    6009          16 :             SWITCH( st_ivas->hDecoderConfig->orientation_tracking )
    6010             :             {
    6011          12 :                 case IVAS_HEAD_ORIENT_TRK_AVG:
    6012          12 :                     fprintf( stdout, "Orientation tracking:   AVG\n" );
    6013          12 :                     BREAK;
    6014           0 :                 case IVAS_HEAD_ORIENT_TRK_REF:
    6015           0 :                     fprintf( stdout, "Orientation tracking:   REF\n" );
    6016           0 :                     BREAK;
    6017           2 :                 case IVAS_HEAD_ORIENT_TRK_REF_VEC:
    6018           2 :                     fprintf( stdout, "Orientation tracking:   REF_VEC\n" );
    6019           2 :                     BREAK;
    6020           2 :                 case IVAS_HEAD_ORIENT_TRK_REF_VEC_LEV:
    6021           2 :                     fprintf( stdout, "Orientation tracking:   REF_VEC_LEV\n" );
    6022           2 :                     BREAK;
    6023           0 :                 default:
    6024           0 :                     BREAK;
    6025             :             }
    6026         624 :         }
    6027             : 
    6028         640 :         IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan )
    6029             :         {
    6030           1 :             float non_diegetic_pan_gain = (float) ( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx ) / (float) ( 1LL << Q15 );
    6031           1 :             fprintf( stdout, "Non-diegetic panning:   %.2f\n", non_diegetic_pan_gain * 90.f );
    6032             :         }
    6033             : 
    6034         640 :         IF( st_ivas->hDecoderConfig->Opt_dpid_on )
    6035             :         {
    6036           2 :             fprintf( stdout, "Directivity pattern:    ON\n" );
    6037             :         }
    6038             : 
    6039         640 :         IF( st_ivas->hDecoderConfig->Opt_aeid_on )
    6040             :         {
    6041           4 :             fprintf( stdout, "Acoustic environment ID:ON\n" );
    6042             :         }
    6043             : 
    6044         640 :         IF( st_ivas->hDecoderConfig->Opt_ObjEdit_on )
    6045             :         {
    6046          13 :             fprintf( stdout, "Objects editing :       ON\n" );
    6047             :         }
    6048             :     }
    6049             : 
    6050             :     /*-----------------------------------------------------------------*
    6051             :      * Print TSM mode info
    6052             :      *-----------------------------------------------------------------*/
    6053             : 
    6054         645 :     IF( st_ivas->hDecoderConfig->Opt_tsm )
    6055             :     {
    6056          51 :         fprintf( stdout, "TSM mode:               ON\n" );
    6057             :     }
    6058             : 
    6059         645 :     return IVAS_ERR_OK;
    6060             : }
    6061             : 
    6062             : 
    6063             : /*---------------------------------------------------------------------*
    6064             :  * IVAS_DEC_PrintConfig( )
    6065             :  *
    6066             :  * Print decoder set-up info
    6067             :  *---------------------------------------------------------------------*/
    6068             : 
    6069         645 : ivas_error IVAS_DEC_PrintConfig(
    6070             :     const IVAS_DEC_HANDLE hIvasDec,
    6071             :     const bool quietModeEnabled,
    6072             :     const bool voipMode )
    6073             : {
    6074         645 :     test();
    6075         645 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    6076             :     {
    6077           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    6078             :     }
    6079             : 
    6080         645 :     printConfigInfo_dec( hIvasDec->st_ivas, hIvasDec->bitstreamformat, voipMode, quietModeEnabled );
    6081             : 
    6082         645 :     return IVAS_ERR_OK;
    6083             : }
    6084             : 
    6085             : 
    6086             : /*---------------------------------------------------------------------*
    6087             :  * IVAS_DEC_PrintDisclaimer( )
    6088             :  *
    6089             :  * Print IVAS disclaimer to console
    6090             :  *---------------------------------------------------------------------*/
    6091             : 
    6092         638 : void IVAS_DEC_PrintDisclaimer( void )
    6093             : {
    6094         638 :     print_disclaimer( stderr );
    6095             : 
    6096         638 :     return;
    6097             : }
    6098             : 
    6099             : 
    6100             : /*---------------------------------------------------------------------*
    6101             :  * evs_dec_main( )
    6102             :  *
    6103             :  * EVS codec main decoder fucntion
    6104             :  *---------------------------------------------------------------------*/
    6105             : 
    6106        5150 : static ivas_error evs_dec_main_fx(
    6107             :     Decoder_Struct *st_ivas )
    6108             : {
    6109             :     DEC_CORE_HANDLE *hCoreCoder;
    6110             :     Word16 mixer_left_fx, mixer_right_fx;
    6111             : #ifdef FIX_1419_MONO_STEREO_UMX
    6112             :     Word32 *p_output_fx[MAX_TRANSPORT_CHANNELS];
    6113             : #else
    6114             :     Word32 *p_output_fx[MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN];
    6115             : #endif
    6116             :     Word16 ch, i, nOutSamples;
    6117             :     Word16 output_16[L_FRAME48k];
    6118             :     ivas_error error;
    6119             : 
    6120        5150 :     hCoreCoder = st_ivas->hSCE[0]->hCoreCoder;
    6121        5150 :     hCoreCoder[0]->total_brate = st_ivas->hDecoderConfig->ivas_total_brate;
    6122        5150 :     move32();
    6123        5150 :     hCoreCoder[0]->output_frame_fx = extract_l( Mult_32_16( hCoreCoder[0]->output_Fs, INV_FRAME_PER_SEC_Q15 ) ); // Q0
    6124        5150 :     move16();
    6125        5150 :     nOutSamples = hCoreCoder[0]->output_frame_fx;
    6126        5150 :     move16();
    6127             : 
    6128        5150 :     mdct_switching_dec_fx( hCoreCoder[0] );
    6129             : 
    6130             : #ifdef FIX_1419_MONO_STEREO_UMX
    6131       66950 :     FOR( ch = 0; ch < MAX_TRANSPORT_CHANNELS; ch++ )
    6132             : #else
    6133             :     FOR( ch = 0; ch < MAX_OUTPUT_CHANNELS_IN_DIEGETIC_PAN; ch++ )
    6134             : #endif
    6135             :     {
    6136       61800 :         p_output_fx[ch] = st_ivas->p_output_fx[ch]; // Q0
    6137             : #ifdef FIX_1419_MONO_STEREO_UMX
    6138       61800 :         IF( p_output_fx[ch] != NULL )
    6139             :         {
    6140        6150 :             set_zero_fx( p_output_fx[ch], L_FRAME48k );
    6141             :         }
    6142             : #endif
    6143             :     }
    6144             : 
    6145             :     /* run the main EVS decoding routine */
    6146        5150 :     IF( EQ_16( hCoreCoder[0]->codec_mode, MODE1 ) )
    6147             :     {
    6148        2615 :         IF( hCoreCoder[0]->Opt_AMR_WB )
    6149             :         {
    6150           0 :             IF( NE_32( ( error = amr_wb_dec_fx( output_16, hCoreCoder[0] ) ), IVAS_ERR_OK ) )
    6151             :             {
    6152           0 :                 return error;
    6153             :             }
    6154             :         }
    6155             :         ELSE
    6156             :         {
    6157        2615 :             IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) )
    6158             :             {
    6159           0 :                 return error;
    6160             :             }
    6161             :         }
    6162             :     }
    6163             :     ELSE
    6164             :     {
    6165        2535 :         IF( hCoreCoder[0]->bfi == 0 )
    6166             :         {
    6167        2535 :             IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_NORMAL ) ), IVAS_ERR_OK ) )
    6168             :             {
    6169           0 :                 return error;
    6170             :             }
    6171             :         }
    6172           0 :         ELSE IF( EQ_16( hCoreCoder[0]->bfi, 2 ) )
    6173             :         {
    6174           0 :             IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_FUTURE ) ), IVAS_ERR_OK ) )
    6175             :             {
    6176           0 :                 return error;
    6177             :             }
    6178             :         }
    6179             :         ELSE
    6180             :         {
    6181           0 :             IF( NE_32( ( error = evs_dec_fx( hCoreCoder[0], output_16, FRAMEMODE_MISSING ) ), IVAS_ERR_OK ) )
    6182             :             {
    6183           0 :                 return error;
    6184             :             }
    6185             :         }
    6186             :     }
    6187             : 
    6188     4613150 :     FOR( i = 0; i < nOutSamples; i++ )
    6189             :     {
    6190     4608000 :         p_output_fx[0][i] = L_shl( output_16[i], Q11 ); /* Q11 */
    6191             :     }
    6192             : 
    6193        5150 :     st_ivas->BER_detect = hCoreCoder[0]->BER_detect;
    6194        5150 :     move16();
    6195        5150 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_NON_DIEGETIC_DOWNMIX ) )
    6196             :     {
    6197        1000 :         mixer_left_fx = add( shr( st_ivas->hDecoderConfig->non_diegetic_pan_gain_fx, Q1 ), ONE_IN_Q14 ); // Q14
    6198        1000 :         mixer_right_fx = sub( MAX16B, mixer_left_fx );
    6199             : 
    6200        1000 :         v_multc_fx_16( p_output_fx[0], mixer_right_fx, p_output_fx[1], nOutSamples ); /* Q11 */
    6201        1000 :         v_multc_fx_16( p_output_fx[0], mixer_left_fx, p_output_fx[0], nOutSamples );  /* Q11 */
    6202             :     }
    6203             : 
    6204             : #ifdef FIX_1419_MONO_STEREO_UMX
    6205        5150 :     test();
    6206        5150 :     IF( st_ivas->hDecoderConfig->Opt_tsm && EQ_16( st_ivas->hDecoderConfig->nchan_out, 1 ) )
    6207             : #else
    6208             :     IF( st_ivas->hDecoderConfig->Opt_tsm )
    6209             : #endif
    6210             :     {
    6211             :         /* BE workaround: in order to keep EVS bit-exact wrt. TS 26.443, convert 'float' output data to 'short' before the TSM */
    6212             :         /* not applicable in BASOP */
    6213             :     }
    6214             : 
    6215        5150 :     return IVAS_ERR_OK;
    6216             : }
    6217             : 
    6218             : 
    6219             : /*---------------------------------------------------------------------*
    6220             :  * input_format_API_to_internal()
    6221             :  *
    6222             :  *
    6223             :  *---------------------------------------------------------------------*/
    6224             : 
    6225          51 : static ivas_error input_format_API_to_internal(
    6226             :     IVAS_DEC_INPUT_FORMAT input_format,
    6227             :     Word16 *bitstream_format_internal,
    6228             :     Word16 *sdp_hf_only,
    6229             :     const bool is_voip_enabled )
    6230             : {
    6231          51 :     SWITCH( input_format )
    6232             :     {
    6233          35 :         case IVAS_DEC_INPUT_FORMAT_G192:
    6234          35 :             IF( is_voip_enabled )
    6235             :             {
    6236          35 :                 *bitstream_format_internal = VOIP_G192_RTP;
    6237             :             }
    6238             :             ELSE
    6239             :             {
    6240           0 :                 *bitstream_format_internal = G192;
    6241             :             }
    6242          35 :             *sdp_hf_only = 0;
    6243          35 :             BREAK;
    6244           0 :         case IVAS_DEC_INPUT_FORMAT_MIME:
    6245           0 :             *bitstream_format_internal = MIME;
    6246           0 :             *sdp_hf_only = 0;
    6247           0 :             BREAK;
    6248           0 :         case IVAS_DEC_INPUT_FORMAT_RTPDUMP:
    6249           0 :             assert( is_voip_enabled && "RTP dump only supported in VoIP mode" );
    6250           0 :             *bitstream_format_internal = VOIP_RTPDUMP;
    6251           0 :             *sdp_hf_only = 0;
    6252           0 :             BREAK;
    6253          16 :         case IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF:
    6254          16 :             assert( is_voip_enabled && "RTP dump only supported in VoIP mode" );
    6255          16 :             *bitstream_format_internal = VOIP_RTPDUMP;
    6256          16 :             *sdp_hf_only = 1;
    6257          16 :             BREAK;
    6258           0 :         default:
    6259           0 :             return IVAS_ERR_INVALID_BITSTREAM;
    6260             :     }
    6261             : 
    6262          51 :     move16();
    6263          51 :     move16();
    6264             : 
    6265          51 :     return IVAS_ERR_OK;
    6266             : }
    6267             : 
    6268             : 
    6269             : /*---------------------------------------------------------------------*
    6270             :  * apa_setup()
    6271             :  *
    6272             :  * Setup APA decoder
    6273             :  *---------------------------------------------------------------------*/
    6274             : 
    6275        3886 : static ivas_error apa_setup(
    6276             :     IVAS_DEC_HANDLE hIvasDec,
    6277             :     const bool isInitialized_voip,
    6278             :     const UWord16 nTransportChannels )
    6279             : {
    6280             :     UWord16 l_ts;
    6281             : 
    6282        3886 :     l_ts = (UWord16) hIvasDec->st_ivas->hTcBuffer->n_samples_granularity;
    6283        3886 :     move16();
    6284             : 
    6285        3886 :     IF( !isInitialized_voip )
    6286             :     {
    6287             :         DECODER_CONFIG_HANDLE hDecoderConfig;
    6288             : 
    6289             :         UWord16 wss, css;
    6290             :         Word32 startQuality;
    6291             : 
    6292          44 :         startQuality = L_shl( L_deposit_l( hIvasDec->tsm_quality ), Q2 ); /* Q14 --> Q16*/
    6293          44 :         hDecoderConfig = hIvasDec->st_ivas->hDecoderConfig;
    6294             : 
    6295          44 :         IF( EQ_32( hDecoderConfig->output_Fs, 8000 ) )
    6296             :         {
    6297           0 :             wss = 1;
    6298           0 :             css = 1;
    6299             :         }
    6300          44 :         ELSE IF( EQ_32( hDecoderConfig->output_Fs, 16000 ) )
    6301             :         {
    6302           3 :             wss = 2;
    6303           3 :             css = 1;
    6304             :         }
    6305          41 :         ELSE IF( EQ_32( hDecoderConfig->output_Fs, 32000 ) )
    6306             :         {
    6307           9 :             wss = 4;
    6308           9 :             css = 2;
    6309             :         }
    6310          32 :         ELSE IF( EQ_32( hDecoderConfig->output_Fs, 48000 ) )
    6311             :         {
    6312          32 :             wss = 6;
    6313          32 :             css = 3;
    6314             :         }
    6315             :         ELSE
    6316             :         {
    6317           0 :             return IVAS_ERR_INIT_ERROR;
    6318             :         }
    6319             : 
    6320          44 :         move16();
    6321          44 :         move16();
    6322             : 
    6323          44 :         test();
    6324          44 :         test();
    6325          44 :         test();
    6326          44 :         test();
    6327          44 :         IF( NE_32( (Word32) apa_init( &hIvasDec->hTimeScaler, nTransportChannels ), IVAS_ERR_OK ) ||
    6328             :             apa_set_rate( hIvasDec->hTimeScaler, hDecoderConfig->output_Fs ) != 0 ||
    6329             :             apa_set_complexity_options( hIvasDec->hTimeScaler, wss, css ) != 0 ||
    6330             :             apa_set_quality( hIvasDec->hTimeScaler, startQuality, 4, 4 ) != 0 ||
    6331             :             apa_set_renderer_granularity( hIvasDec->hTimeScaler, l_ts ) != 0 )
    6332             :         {
    6333           0 :             return IVAS_ERR_INIT_ERROR;
    6334             :         }
    6335             : 
    6336          44 :         IF( EQ_16( (Word16) hIvasDec->mode, IVAS_DEC_MODE_EVS ) )
    6337             :         {
    6338           2 :             IF( apa_set_evs_compat_mode( hIvasDec->hTimeScaler, true ) != 0 )
    6339             :             {
    6340           0 :                 return IVAS_ERR_INIT_ERROR;
    6341             :             }
    6342             :         }
    6343             :     }
    6344             :     ELSE
    6345             :     {
    6346        3842 :         IF( apa_reconfigure( hIvasDec->hTimeScaler, nTransportChannels, l_ts ) != 0 )
    6347             :         {
    6348           0 :             return IVAS_ERR_INIT_ERROR;
    6349             :         }
    6350             :     }
    6351             : 
    6352        3886 :     hIvasDec->nTransportChannelsOld = nTransportChannels;
    6353        3886 :     move16();
    6354             : 
    6355        3886 :     return IVAS_ERR_OK;
    6356             : }
    6357             : 
    6358             : 
    6359             : /*---------------------------------------------------------------------*
    6360             :  * IVAS_DEC_GetSplitRendBitstreamHeader()
    6361             :  *
    6362             :  *
    6363             :  *---------------------------------------------------------------------*/
    6364             : 
    6365           0 : ivas_error IVAS_DEC_GetSplitRendBitstreamHeader(
    6366             :     IVAS_DEC_HANDLE hIvasDec,                             /* i/o: IVAS decoder handle                   */
    6367             :     ISAR_SPLIT_REND_CODEC *pCodec,                        /* o  : pointer to codec setting              */
    6368             :     ISAR_SPLIT_REND_POSE_CORRECTION_MODE *poseCorrection, /* o  : pointer to pose correction mode       */
    6369             :     Word16 *pIsar_frame_size_ms,                          /* o  : pointer to ISAR frame size setting    */
    6370             :     Word16 *pCodec_frame_size_ms,                         /* o  : pointer to codec frame size setting   */
    6371             :     Word16 *pLc3plusHighRes                               /* o  : pointer to LC3plus High-Res setting   */
    6372             : )
    6373             : {
    6374           0 :     test();
    6375           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    6376             :     {
    6377           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    6378             :     }
    6379             : 
    6380           0 :     *pCodec = hIvasDec->st_ivas->hRenderConfig->split_rend_config.codec;
    6381           0 :     *pCodec_frame_size_ms = hIvasDec->st_ivas->hRenderConfig->split_rend_config.codec_frame_size_ms;
    6382           0 :     *poseCorrection = hIvasDec->st_ivas->hRenderConfig->split_rend_config.poseCorrectionMode;
    6383           0 :     *pIsar_frame_size_ms = hIvasDec->st_ivas->hRenderConfig->split_rend_config.isar_frame_size_ms;
    6384           0 :     *pLc3plusHighRes = hIvasDec->st_ivas->hRenderConfig->split_rend_config.lc3plus_highres;
    6385             : 
    6386           0 :     return IVAS_ERR_OK;
    6387             : }
    6388             : 
    6389             : 
    6390             : /*---------------------------------------------------------------------*
    6391             :  * IVAS_DEC_GetCldfbSamples()
    6392             :  *
    6393             :  * API function to output CLDFB samples
    6394             :  *---------------------------------------------------------------------*/
    6395             : 
    6396           0 : ivas_error IVAS_DEC_GetCldfbSamples(
    6397             :     IVAS_DEC_HANDLE hIvasDec,   /* i/o: IVAS decoder handle                                    */
    6398             :     Word32 *out_real,           /* o  : buffer for decoded PCM real output in CLDFB domain     */
    6399             :     Word32 *out_imag,           /* o  : buffer for decoded PCM imag output in CLDFB domain     */
    6400             :     AUDIO_CONFIG *audio_config, /* o  : audio configuration                                    */
    6401             :     Word16 *nOutSamples         /* o  : number of samples per channel written to output buffer */
    6402             : )
    6403             : {
    6404             :     ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend;
    6405             :     Word16 ch, b, slot_idx, num_chs, maxBand, num_samples;
    6406             : 
    6407           0 :     test();
    6408           0 :     test();
    6409           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hSplitBinRend == NULL )
    6410             :     {
    6411           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    6412             :     }
    6413             : 
    6414           0 :     hSplitBinRend = hIvasDec->st_ivas->hSplitBinRend;
    6415           0 :     num_samples = 0;
    6416             : 
    6417           0 :     IF( hSplitBinRend->hCldfbDataOut != NULL )
    6418             :     {
    6419           0 :         *audio_config = hSplitBinRend->hCldfbDataOut->config;
    6420           0 :         IF( hSplitBinRend->hCldfbDataOut->config != IVAS_AUDIO_CONFIG_INVALID )
    6421             :         {
    6422           0 :             num_chs = audioCfg2channels( hSplitBinRend->hCldfbDataOut->config );
    6423           0 :             maxBand = (Word16) ( ( CLDFB_NO_CHANNELS_MAX * hIvasDec->st_ivas->hDecoderConfig->output_Fs ) / 48000 );
    6424             : 
    6425           0 :             FOR( slot_idx = 0; slot_idx < CLDFB_NO_COL_MAX; slot_idx++ )
    6426             :             {
    6427           0 :                 FOR( b = 0; b < maxBand; b++ )
    6428             :                 {
    6429           0 :                     FOR( ch = 0; ch < num_chs; ch++ )
    6430             :                     {
    6431           0 :                         *out_real++ = hSplitBinRend->hCldfbDataOut->Cldfb_RealBuffer_fx[ch][slot_idx][b];
    6432           0 :                         *out_imag++ = hSplitBinRend->hCldfbDataOut->Cldfb_ImagBuffer_fx[ch][slot_idx][b];
    6433             :                     }
    6434             :                 }
    6435             :             }
    6436           0 :             num_samples = CLDFB_NO_COL_MAX * maxBand;
    6437             :         }
    6438             :     }
    6439             :     ELSE
    6440             :     {
    6441           0 :         *audio_config = IVAS_AUDIO_CONFIG_INVALID;
    6442             :     }
    6443             : 
    6444           0 :     *nOutSamples = num_samples;
    6445             : 
    6446           0 :     return IVAS_ERR_OK;
    6447             : }
    6448             : 
    6449             : 
    6450             : /*-------------------------------------------------------------------*
    6451             :  * ivas_create_handle_isar()
    6452             :  *
    6453             :  * Initialize IVAS decoder split-rendering handle
    6454             :  *-------------------------------------------------------------------*/
    6455             : 
    6456           0 : static ivas_error ivas_create_handle_isar(
    6457             :     ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend_out /* o  : ISAR split binaural rendering handle */
    6458             : )
    6459             : {
    6460             :     ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE hSplitBinRend;
    6461             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    6462             :     Word16 i;
    6463             : #endif
    6464             : 
    6465           0 :     IF( ( hSplitBinRend = (ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_WRAPPER ) ) ) == NULL )
    6466             :     {
    6467           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for IVAS decoder handle" );
    6468             :     }
    6469             : 
    6470           0 :     isar_init_split_rend_handles( &hSplitBinRend->splitrend );
    6471             : 
    6472             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    6473           0 :     hSplitBinRend->hMultiBinTdData = NULL;
    6474           0 :     FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i )
    6475             :     {
    6476           0 :         hSplitBinRend->hMultiBinCldfbData[i] = NULL;
    6477             :     }
    6478             : #else
    6479             :     hSplitBinRend->hMultiBinCldfbData = NULL;
    6480             : #endif
    6481           0 :     hSplitBinRend->hCldfbDataOut = NULL;
    6482           0 :     hSplitBinRend->numTdSamplesPerChannelCached = 0;
    6483           0 :     move16();
    6484             : 
    6485           0 :     *hSplitBinRend_out = hSplitBinRend;
    6486             : 
    6487           0 :     return IVAS_ERR_OK;
    6488             : }
    6489             : 
    6490             : 
    6491             : /*-------------------------------------------------------------------*
    6492             :  * ivas_destroy_handle_isar()
    6493             :  *
    6494             :  * destroy IVAS decoder split rend handle
    6495             :  *-------------------------------------------------------------------*/
    6496             : 
    6497         645 : static void ivas_destroy_handle_isar(
    6498             :     ISAR_DEC_SPLIT_REND_WRAPPER_HANDLE *hSplitBinRend /* i/o: ISAR split binaural rendering handle */
    6499             : )
    6500             : {
    6501             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    6502             :     Word16 i;
    6503             : #endif
    6504             : 
    6505         645 :     IF( *hSplitBinRend != NULL )
    6506             :     {
    6507             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    6508           0 :         IF( ( *hSplitBinRend )->hMultiBinTdData != NULL )
    6509             :         {
    6510           0 :             ivas_TD_RINGBUF_Close( &( *hSplitBinRend )->hMultiBinTdData );
    6511             :         }
    6512             : 
    6513           0 :         FOR( i = 0; i < MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS; ++i )
    6514             :         {
    6515           0 :             IF( ( *hSplitBinRend )->hMultiBinCldfbData[i] != NULL )
    6516             :             {
    6517           0 :                 ivas_CLDFB_RINGBUF_Close( &( *hSplitBinRend )->hMultiBinCldfbData[i] );
    6518             :             }
    6519             :         }
    6520             : #else
    6521             : #ifdef TMP_FIX_SPLIT_REND
    6522             :         free( ( *hSplitBinRend )->hMultiBinCldfbData );
    6523             :         ( *hSplitBinRend )->hMultiBinCldfbData = NULL;
    6524             : #endif
    6525             : #endif
    6526             : 
    6527           0 :         ISAR_PRE_REND_close( &( *hSplitBinRend )->splitrend, NULL );
    6528             : 
    6529           0 :         IF( ( *hSplitBinRend )->hCldfbDataOut != NULL )
    6530             :         {
    6531           0 :             free( ( *hSplitBinRend )->hCldfbDataOut );
    6532           0 :             ( *hSplitBinRend )->hCldfbDataOut = NULL;
    6533             :         }
    6534             : 
    6535           0 :         free( *hSplitBinRend );
    6536           0 :         *hSplitBinRend = NULL;
    6537             :     }
    6538             : 
    6539         645 :     return;
    6540             : }
    6541             : 
    6542             : 
    6543             : /*---------------------------------------------------------------------*
    6544             :  * IVAS_DEC_is_split_rendering_enabled()
    6545             :  *
    6546             :  *
    6547             :  *---------------------------------------------------------------------*/
    6548             : 
    6549             : /*! r: decoder error code */
    6550        1276 : ivas_error IVAS_DEC_is_split_rendering_enabled(
    6551             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                               */
    6552             :     Word16 *isSplitRend       /* o  : flag to indicate if split rendering is enabled    */
    6553             : )
    6554             : {
    6555             :     Decoder_Struct *st_ivas;
    6556             : 
    6557        1276 :     test();
    6558        1276 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    6559             :     {
    6560           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    6561             :     }
    6562             : 
    6563        1276 :     st_ivas = hIvasDec->st_ivas;
    6564             : 
    6565        1276 :     *isSplitRend = is_split_rendering_enabled( st_ivas->hDecoderConfig, st_ivas->hRenderConfig );
    6566             : 
    6567        1276 :     return IVAS_ERR_OK;
    6568             : }
    6569             : 
    6570             : 
    6571             : /*-------------------------------------------------------------------*
    6572             :  * ivas_dec_reconfig_split_rend()
    6573             :  *
    6574             :  * IVAS decoder split rend reconfig
    6575             :  *-------------------------------------------------------------------*/
    6576             : 
    6577           0 : static ivas_error ivas_dec_reconfig_split_rend(
    6578             :     Decoder_Struct *st_ivas /* i  : IVAS decoder structure      */
    6579             : )
    6580             : {
    6581             :     ivas_error error;
    6582             :     Word16 cldfb_in_flag, num_ch, ch, isCldfbNeeded, i, pcm_out_flag;
    6583             :     SPLIT_REND_WRAPPER *hSplitRendWrapper;
    6584             : 
    6585           0 :     hSplitRendWrapper = &st_ivas->hSplitBinRend->splitrend;
    6586           0 :     move16();
    6587           0 :     pcm_out_flag = ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) ? 1 : 0;
    6588           0 :     move16();
    6589           0 :     cldfb_in_flag = 0;
    6590           0 :     move16();
    6591             : 
    6592           0 :     test();
    6593           0 :     test();
    6594           0 :     test();
    6595           0 :     IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
    6596             :         EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
    6597             :         EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ||
    6598             :         EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
    6599             :     {
    6600           0 :         cldfb_in_flag = 1;
    6601           0 :         move16();
    6602             :     }
    6603             : 
    6604           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 );
    6605             : 
    6606           0 :     isCldfbNeeded = 0;
    6607           0 :     move16();
    6608             : 
    6609           0 :     test();
    6610           0 :     test();
    6611           0 :     test();
    6612           0 :     test();
    6613           0 :     IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ||
    6614             :         ( 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 ) ) )
    6615             :     {
    6616           0 :         cldfb_in_flag = 0;
    6617           0 :         move16();
    6618             :     }
    6619             : 
    6620           0 :     IF( NE_16( st_ivas->renderer_type, RENDERER_DISABLE ) )
    6621             :     {
    6622           0 :         IF( EQ_16( cldfb_in_flag, 0 ) )
    6623             :         {
    6624           0 :             isCldfbNeeded = 1;
    6625           0 :             move16();
    6626             :         }
    6627           0 :         ELSE IF( EQ_16( st_ivas->hRenderConfig->split_rend_config.codec, ISAR_SPLIT_REND_CODEC_LC3PLUS ) && cldfb_in_flag )
    6628             :         {
    6629           0 :             isCldfbNeeded = 1;
    6630           0 :             move16();
    6631             :         }
    6632           0 :         ELSE IF( pcm_out_flag && cldfb_in_flag )
    6633             :         {
    6634           0 :             isCldfbNeeded = 1;
    6635           0 :             move16();
    6636             :         }
    6637             :     }
    6638           0 :     ELSE IF( st_ivas->hDecoderConfig->Opt_non_diegetic_pan )
    6639             :     {
    6640           0 :         isCldfbNeeded = 1;
    6641           0 :         move16();
    6642             :     }
    6643             : 
    6644           0 :     test();
    6645           0 :     test();
    6646           0 :     IF( EQ_16( isCldfbNeeded, 1 ) && hSplitRendWrapper->hCldfbHandles == NULL )
    6647             :     {
    6648           0 :         IF( ( hSplitRendWrapper->hCldfbHandles = (CLDFB_HANDLES_WRAPPER_HANDLE) malloc( sizeof( CLDFB_HANDLES_WRAPPER ) ) ) == NULL )
    6649             :         {
    6650           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for CLDFB handles\n" ) );
    6651             :         }
    6652             : 
    6653           0 :         num_ch = MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS;
    6654           0 :         move16();
    6655           0 :         FOR( ch = 0; ch < num_ch; ch++ )
    6656             :         {
    6657           0 :             hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] = NULL;
    6658           0 :             move16();
    6659             :         }
    6660             : 
    6661           0 :         num_ch = i_mult( hSplitRendWrapper->multiBinPoseData.num_poses, BINAURAL_CHANNELS );
    6662           0 :         move16();
    6663             : 
    6664           0 :         FOR( ch = 0; ch < num_ch; ch++ )
    6665             :         {
    6666           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 )
    6667             :             {
    6668           0 :                 return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not open CLDFB handles\n" ) );
    6669             :             }
    6670             :         }
    6671             : 
    6672           0 :         FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    6673             :         {
    6674           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 )
    6675             :             {
    6676           0 :                 return error;
    6677             :             }
    6678             :         }
    6679             :     }
    6680           0 :     ELSE IF( EQ_16( isCldfbNeeded, 0 ) && hSplitRendWrapper->hCldfbHandles != NULL )
    6681             :     {
    6682           0 :         num_ch = MAX_HEAD_ROT_POSES * BINAURAL_CHANNELS;
    6683           0 :         move16();
    6684           0 :         FOR( ch = 0; ch < num_ch; ch++ )
    6685             :         {
    6686           0 :             IF( hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] != NULL )
    6687             :             {
    6688           0 :                 deleteCldfb_fx( &hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] );
    6689           0 :                 hSplitRendWrapper->hCldfbHandles->cldfbAna[ch] = NULL;
    6690           0 :                 move32();
    6691             :             }
    6692             :         }
    6693             : 
    6694           0 :         FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    6695             :         {
    6696           0 :             IF( hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] != NULL )
    6697             :             {
    6698           0 :                 deleteCldfb_fx( &hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] );
    6699           0 :                 hSplitRendWrapper->hCldfbHandles->cldfbSyn[ch] = NULL;
    6700           0 :                 move32();
    6701             :             }
    6702             :         }
    6703             : 
    6704           0 :         free( hSplitRendWrapper->hCldfbHandles );
    6705           0 :         hSplitRendWrapper->hCldfbHandles = NULL;
    6706           0 :         move32();
    6707             :     }
    6708             : 
    6709           0 :     test();
    6710           0 :     test();
    6711           0 :     test();
    6712           0 :     test();
    6713           0 :     test();
    6714           0 :     IF( ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_OBJECTS_TD ) ) &&
    6715             :         ( NE_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) || NE_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) &&
    6716             :         !( 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? */
    6717             :     {
    6718           0 :         FOR( i = 0; i < MAX_HEAD_ROT_POSES - 1; ++i )
    6719             :         {
    6720           0 :             IF( st_ivas->hTdRendHandles[i] != NULL )
    6721             :             {
    6722           0 :                 st_ivas->hTdRendHandles[i]->HrFiltSet_p = NULL;
    6723           0 :                 move32();
    6724           0 :                 ivas_td_binaural_close_fx( &st_ivas->hTdRendHandles[i] );
    6725             :             }
    6726             :         }
    6727             :     }
    6728             : 
    6729           0 :     return IVAS_ERR_OK;
    6730             : }
    6731             : 
    6732             : 
    6733             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    6734             : /*-------------------------------------------------------------------*
    6735             :  * ivas_dec_split_rend_cldfb_in()
    6736             :  *
    6737             :  *
    6738             :  *-------------------------------------------------------------------*/
    6739             : 
    6740           0 : static Word16 ivas_dec_split_rend_cldfb_in(
    6741             :     const RENDERER_TYPE renderer_type /* i  : renderer type     */
    6742             : )
    6743             : {
    6744           0 :     test();
    6745           0 :     test();
    6746           0 :     test();
    6747           0 :     IF( EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
    6748             :         EQ_32( renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
    6749             :         EQ_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ||
    6750             :         EQ_32( renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
    6751             :     {
    6752           0 :         return 1;
    6753             :     }
    6754             :     ELSE
    6755             :     {
    6756           0 :         return 0;
    6757             :     }
    6758             : }
    6759             : #endif
    6760             : 
    6761             : 
    6762             : /*-------------------------------------------------------------------*
    6763             :  * ivas_dec_init_split_rend()
    6764             :  *
    6765             :  * IVAS decoder split rendering initialization
    6766             :  *-------------------------------------------------------------------*/
    6767             : 
    6768           0 : static ivas_error ivas_dec_init_split_rend(
    6769             :     Decoder_Struct *st_ivas /* i  : IVAS decoder structure      */
    6770             : )
    6771             : {
    6772             :     ivas_error error;
    6773             :     Word16 cldfb_in_flag, pcm_out_flag;
    6774             :     Word16 mixed_td_cldfb_flag;
    6775             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    6776             :     Word16 i, num_poses;
    6777             :     ISAR_SPLIT_REND_ROT_AXIS head_rot_axis;
    6778             : #endif
    6779             : 
    6780           0 :     pcm_out_flag = 0;
    6781           0 :     move16();
    6782           0 :     if ( EQ_32( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
    6783             :     {
    6784           0 :         pcm_out_flag = 1;
    6785           0 :         move16();
    6786             :     }
    6787           0 :     cldfb_in_flag = 0;
    6788           0 :     move16();
    6789             : 
    6790             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    6791           0 :     cldfb_in_flag = ivas_dec_split_rend_cldfb_in( st_ivas->renderer_type );
    6792             : #else
    6793             : 
    6794             : #ifdef TMP_FIX_SPLIT_REND
    6795             :     /* note: this is intra-frame heap memory */
    6796             :     IF( ( st_ivas->hSplitBinRend->hMultiBinCldfbData = (ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_MULTI_BIN_CLDFB_DATA ) ) ) == NULL )
    6797             :     {
    6798             :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" );
    6799             :     }
    6800             : #endif
    6801             : 
    6802             :     IF( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) ||
    6803             :         EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) ||
    6804             :         EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC ) ||
    6805             :         EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_PARAMETRIC_ROOM ) )
    6806             :     {
    6807             :         cldfb_in_flag = 1;
    6808             :         move16();
    6809             :     }
    6810             : #endif
    6811             : 
    6812             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
    6813           0 :     head_rot_axis = DEFAULT_AXIS;
    6814           0 :     move32();
    6815           0 :     if ( st_ivas->hHeadTrackData != NULL )
    6816             :     {
    6817           0 :         head_rot_axis = st_ivas->hHeadTrackData->sr_pose_pred_axis;
    6818           0 :         move32();
    6819             :     }
    6820             : 
    6821           0 :     ISAR_PRE_REND_GetMultiBinPoseData( &st_ivas->hRenderConfig->split_rend_config, &st_ivas->hSplitBinRend->splitrend.multiBinPoseData, head_rot_axis );
    6822             : 
    6823           0 :     num_poses = st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses;
    6824           0 :     move16();
    6825           0 :     assert( num_poses <= MAX_HEAD_ROT_POSES );
    6826             : 
    6827           0 :     IF( cldfb_in_flag )
    6828             :     {
    6829           0 :         FOR( i = 0; i < num_poses * BINAURAL_CHANNELS; ++i )
    6830             :         {
    6831             :             /* note: this is intra-frame heap memory */
    6832           0 :             IF( NE_32( ( error = ivas_CLDFB_RINGBUF_Open( &st_ivas->hSplitBinRend->hMultiBinCldfbData[i], CLDFB_NO_COL_MAX ) ), IVAS_ERR_OK ) )
    6833             :             {
    6834           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" );
    6835             :             }
    6836             :         }
    6837             :     }
    6838             :     ELSE
    6839             :     {
    6840           0 :         IF( NE_32( ( error = ivas_TD_RINGBUF_Open( &st_ivas->hSplitBinRend->hMultiBinTdData, get_render_frame_size_samples( st_ivas->hDecoderConfig ), i_mult( num_poses, BINAURAL_CHANNELS ) ) ), IVAS_ERR_OK ) )
    6841             :         {
    6842           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for split rendering structure" );
    6843             :         }
    6844             :     }
    6845             : #else
    6846             : 
    6847             :     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 );
    6848             : #endif
    6849             : 
    6850           0 :     IF( EQ_16( cldfb_in_flag, 1 ) && ( EQ_16( st_ivas->hSplitBinRend->splitrend.multiBinPoseData.poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_NONE ) ) )
    6851             :     {
    6852           0 :         IF( ( st_ivas->hSplitBinRend->hCldfbDataOut = (ISAR_DEC_SPLIT_REND_CLDFB_OUT_DATA_HANDLE) malloc( sizeof( ISAR_DEC_SPLIT_REND_CLDFB_OUT_DATA ) ) ) == NULL )
    6853             :         {
    6854           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for cldfb data out buffer\n" ) );
    6855             :         }
    6856             :     }
    6857             : 
    6858           0 :     mixed_td_cldfb_flag = 0;
    6859           0 :     move16();
    6860           0 :     test();
    6861           0 :     test();
    6862           0 :     test();
    6863           0 :     test();
    6864           0 :     IF( ( EQ_16( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV ) && EQ_16( st_ivas->ivas_format, SBA_ISM_FORMAT ) ) ||
    6865             :         ( 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 ) ) )
    6866             :     {
    6867           0 :         mixed_td_cldfb_flag = 1;
    6868           0 :         move16();
    6869             :     }
    6870             : 
    6871           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 );
    6872           0 :     move16();
    6873             : 
    6874           0 :     return error;
    6875             : }
    6876             : 
    6877             : 
    6878             : /*---------------------------------------------------------------------*
    6879             :  * IVAS_DEC_is_split_rendering_coded_out()
    6880             :  *
    6881             :  * Return flag to indicate if split rendering is enabled
    6882             :  *---------------------------------------------------------------------*/
    6883             : 
    6884             : /*! r: decoder error code */
    6885        1276 : ivas_error IVAS_DEC_is_split_rendering_coded_out(
    6886             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                               */
    6887             :     Word16 *isSplitCoded      /* o  : flag to indicate if split rendering is enabled    */
    6888             : )
    6889             : {
    6890             :     Decoder_Struct *st_ivas;
    6891             : 
    6892        1276 :     test();
    6893        1276 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    6894             :     {
    6895           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    6896             :     }
    6897             : 
    6898        1276 :     st_ivas = hIvasDec->st_ivas;
    6899        1276 :     *isSplitCoded = 0;
    6900        1276 :     move16();
    6901             : 
    6902        1276 :     test();
    6903        1276 :     test();
    6904        1276 :     test();
    6905        1276 :     IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) ||
    6906             :         ( 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 ) )
    6907             :     {
    6908           0 :         *isSplitCoded = 1;
    6909           0 :         move16();
    6910             :     }
    6911             : 
    6912        1276 :     return IVAS_ERR_OK;
    6913             : }
    6914             : 
    6915             : #ifdef IVAS_RTPDUMP
    6916             : 
    6917             : /*---------------------------------------------------------------------*
    6918             :  * feedSinglePIorientation( )
    6919             :  *
    6920             :  * Feed a single orientation PI data to external orientation handle.
    6921             :  *---------------------------------------------------------------------*/
    6922             : 
    6923           0 : static ivas_error feedSinglePIorientation(
    6924             :     IVAS_DEC_HANDLE hIvasDec,         /* i/o: IVAS decoder handle                                                      */
    6925             :     const bool isOrientationSaved,    /* i  : flag to indicate if an orientation for this PI type was previously saved */
    6926             :     IVAS_QUATERNION *savedOrientation /* i  : previously saved orientation for this PI type                            */
    6927             : )
    6928             : {
    6929             :     Word16 i;
    6930             :     ivas_error error;
    6931             :     Decoder_Struct *st_ivas;
    6932             :     IVAS_QUATERNION savedInvOrientation;
    6933             : 
    6934           0 :     test();
    6935           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    6936             :     {
    6937           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    6938             :     }
    6939             : 
    6940           0 :     st_ivas = hIvasDec->st_ivas;
    6941             : 
    6942           0 :     IF( isOrientationSaved )
    6943             :     {
    6944           0 :         IF( !st_ivas->hExtOrientationData )
    6945             :         {
    6946           0 :             IF( NE_32( error = ivas_external_orientation_open_fx( &( st_ivas->hExtOrientationData ), st_ivas->hDecoderConfig->render_framesize ), IVAS_ERR_OK ) )
    6947             :             {
    6948           0 :                 return error;
    6949             :             }
    6950             :         }
    6951             : 
    6952           0 :         IF( !st_ivas->hCombinedOrientationData )
    6953             :         {
    6954           0 :             IF( NE_32( error = ivas_combined_orientation_open_fx( &( st_ivas->hCombinedOrientationData ), st_ivas->hDecoderConfig->output_Fs, st_ivas->hDecoderConfig->render_framesize ), IVAS_ERR_OK ) )
    6955             :             {
    6956           0 :                 return error;
    6957             :             }
    6958             :         }
    6959             : 
    6960           0 :         QuaternionInverse_fx( *savedOrientation, &savedInvOrientation );
    6961             : 
    6962             :         /* use the new PI orientation or the previously saved orientation in processing */
    6963           0 :         FOR( i = 0; i < st_ivas->hExtOrientationData->num_subframes; i++ )
    6964             :         {
    6965           0 :             QuaternionProduct_fx( st_ivas->hExtOrientationData->Quaternions[i], savedInvOrientation,
    6966           0 :                                   &st_ivas->hExtOrientationData->Quaternions[i] );
    6967           0 :             st_ivas->hExtOrientationData->enableExternalOrientation[i] = true;
    6968           0 :             move16();
    6969             :         }
    6970             : 
    6971           0 :         hIvasDec->updateOrientation = true;
    6972           0 :         move16();
    6973             :     }
    6974             : 
    6975           0 :     return IVAS_ERR_OK;
    6976             : }
    6977             : 
    6978             : #endif
    6979             : 
    6980             : #ifdef RTP_S4_251135_CR26253_0016_REV1
    6981             : 
    6982             : /*---------------------------------------------------------------------*
    6983             :  * setDiegeticInput( )
    6984             :  *
    6985             :  * Set isDiegeticInput flag for combined orientation handle based on PI data.
    6986             :  *---------------------------------------------------------------------*/
    6987             : 
    6988           0 : static void setDiegeticInputPI(
    6989             :     IVAS_DEC_HANDLE hIvasDec,    /* i/o: IVAS decoder handle                                                     */
    6990             :     const bool *diegeticPIValues /* i  : diegetic values for the input stream                                    */
    6991             : )
    6992             : {
    6993             :     Word16 i;
    6994             : 
    6995           0 :     IF( hIvasDec->st_ivas->hCombinedOrientationData != NULL )
    6996             :     {
    6997           0 :         FOR( i = 0; i < ( 1 + IVAS_MAX_NUM_OBJECTS ); i++ )
    6998             :         {
    6999           0 :             hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPI[i] = diegeticPIValues[i];
    7000           0 :             move16();
    7001             :         }
    7002             : 
    7003           0 :         hIvasDec->st_ivas->hCombinedOrientationData->isDiegeticInputPISet = true;
    7004           0 :         move16();
    7005             :     }
    7006             : 
    7007           0 :     return;
    7008             : }
    7009             : 
    7010             : #endif
    7011             : 
    7012             : #ifdef IVAS_RTPDUMP
    7013             : /*---------------------------------------------------------------------*
    7014             :  * IVAS_DEC_FeedPiDataToDecoder( )
    7015             :  *
    7016             :  *
    7017             :  *---------------------------------------------------------------------*/
    7018             : 
    7019           0 : ivas_error IVAS_DEC_FeedPiDataToDecoder(
    7020             :     IVAS_DEC_HANDLE hIvasDec, /* i/o: IVAS decoder handle                       */
    7021             :     hPiDataTs piData,         /* i  : PI data received in rtp packet            */
    7022             :     UWord32 numPiData         /* i  : number of PI data received in rtp packet  */
    7023             : )
    7024             : {
    7025             :     UWord32 i;
    7026             :     Decoder_Struct *st_ivas;
    7027           0 :     ivas_error error = IVAS_ERR_OK;
    7028           0 :     move32();
    7029             : 
    7030           0 :     test();
    7031           0 :     IF( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    7032             :     {
    7033           0 :         return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    7034             :     }
    7035             : 
    7036           0 :     st_ivas = hIvasDec->st_ivas;
    7037             : 
    7038           0 :     FOR( i = 0; i < numPiData; i++ )
    7039             :     {
    7040           0 :         UWord32 piDataType = piData->data.noPiData.piDataType;
    7041           0 :         move32();
    7042             : 
    7043           0 :         SWITCH( piDataType )
    7044             :         {
    7045           0 :             case IVAS_PI_SCENE_ORIENTATION:
    7046             :             {
    7047           0 :                 IVAS_QUATERNION *quat = &piData->data.scene.orientation;
    7048             : #ifdef DEBUGGING
    7049             :                 fprintf( stdout, "PI_SCENE_ORIENTATION : %f, %f, %f, %f\n",
    7050             :                          fixedToFloat( quat->w_fx, Q15 ),
    7051             :                          fixedToFloat( quat->x_fx, Q15 ),
    7052             :                          fixedToFloat( quat->y_fx, Q15 ),
    7053             :                          fixedToFloat( quat->z_fx, Q15 ) );
    7054             : #endif
    7055           0 :                 error = feedSinglePIorientation( hIvasDec, true, quat );
    7056             :             }
    7057           0 :                 BREAK;
    7058             : 
    7059           0 :             case IVAS_PI_DEVICE_ORIENTATION_COMPENSATED:
    7060             :             {
    7061           0 :                 IVAS_QUATERNION *quat = &piData->data.deviceCompensated.orientation;
    7062             : #ifdef DEBUGGING
    7063             :                 fprintf( stdout, "PI_DEVICE_ORIENTATION : %f, %f, %f, %f\n",
    7064             :                          fixedToFloat( quat->w_fx, Q15 ),
    7065             :                          fixedToFloat( quat->x_fx, Q15 ),
    7066             :                          fixedToFloat( quat->y_fx, Q15 ),
    7067             :                          fixedToFloat( quat->z_fx, Q15 ) );
    7068             : #endif
    7069           0 :                 error = feedSinglePIorientation( hIvasDec, true, quat );
    7070             :             }
    7071           0 :                 BREAK;
    7072             : 
    7073             : #ifdef IVAS_RTPDUMP_ACOUSTIC_ENVIRONMENT
    7074           0 :             case IVAS_PI_ACOUSTIC_ENVIRONMENT:
    7075             :             {
    7076             :                 UWord16 aeid;
    7077           0 :                 aeid = piData->data.acousticEnv.aeid;
    7078           0 :                 move16();
    7079             : #ifdef DEBUGGING
    7080             :                 fprintf( stdout, "PI_ACOUSTIC_ENVIRONMENT : AEID : %d\n", aeid );
    7081             : #endif
    7082           0 :                 test();
    7083           0 :                 test();
    7084           0 :                 IF( piData->data.acousticEnv.availLateReverb && st_ivas->hRenderConfig != NULL && aeid != st_ivas->hRenderConfig->roomAcoustics.aeID )
    7085             :                 {
    7086           0 :                     error = feedAcousticEnvPI( hIvasDec, piData->data.acousticEnv );
    7087             :                 }
    7088             :             }
    7089           0 :                 BREAK;
    7090             : #endif
    7091             : 
    7092             : #ifdef RTP_S4_251135_CR26253_0016_REV1
    7093           0 :             case IVAS_PI_DIEGETIC_TYPE:
    7094             :             {
    7095             : #ifdef DEBUGGING
    7096             :                 fprintf( stdout, "PI_DIEGETIC_TYPE : %d, %d, %d, %d, %d\n", piData->data.digeticIndicator.isDiegetic[0], piData->data.digeticIndicator.isDiegetic[1], piData->data.digeticIndicator.isDiegetic[2], piData->data.digeticIndicator.isDiegetic[3], piData->data.digeticIndicator.isDiegetic[4] );
    7097             : #endif
    7098           0 :                 setDiegeticInputPI( hIvasDec, piData->data.digeticIndicator.isDiegetic );
    7099             :             }
    7100           0 :                 BREAK;
    7101             : #endif
    7102             : 
    7103           0 :             default:
    7104             :             {
    7105             :                 /* NOT HANDLED PI DATA  - DO NOTHING */
    7106             :             }
    7107           0 :                 BREAK;
    7108             :         }
    7109             : 
    7110           0 :         IF( NE_32( error, IVAS_ERR_OK ) )
    7111             :         {
    7112           0 :             return error;
    7113             :         }
    7114             : 
    7115           0 :         piData++;
    7116             :     }
    7117             : 
    7118           0 :     return IVAS_ERR_OK;
    7119             : }
    7120             : #endif

Generated by: LCOV version 1.14