LCOV - code coverage report
Current view: top level - lib_rend - ivas_objectRenderer_mix_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ da9cc8ead0679b4682d329fdff98cf1616159273 Lines: 253 326 77.6 %
Date: 2025-10-13 22:24:20 Functions: 8 8 100.0 %

          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 <stdint.h>
      34             : #include "options.h"
      35             : #include "prot_fx.h"
      36             : #include "ivas_prot_rend_fx.h"
      37             : #include "ivas_rom_TdBinauralRenderer.h"
      38             : #include "ivas_error.h"
      39             : #include "wmc_auto.h"
      40             : #include "ivas_rom_rend.h"
      41             : #ifndef FIX_989_TD_REND_ROM
      42             : #include "ivas_rom_binaural_crend_head.h"
      43             : #endif
      44             : #include "ivas_prot_fx.h"
      45             : 
      46             : /*-------------------------------------------------------------------*
      47             :  * Local constants
      48             :  *-------------------------------------------------------------------*/
      49             : #ifndef FIX_989_TD_REND_ROM
      50             : #define RESAMPLE_FACTOR_16_48 ( 16.0f / 48.0f )
      51             : #define RESAMPLE_FACTOR_32_48 ( 32.0f / 48.0f )
      52             : #endif
      53             : #ifndef FIX_CREND_SIMPLIFY_CODE
      54             : #define RESAMPLE_FACTOR_16_48_FX ( 5461 )  // Q14
      55             : #define RESAMPLE_FACTOR_32_48_FX ( 10922 ) // Q14
      56             : #endif
      57             : 
      58             : /*-------------------------------------------------------------------------
      59             :  * Local functions declaration
      60             :  *-------------------------------------------------------------------------*/
      61             : static ivas_error DefaultBSplineModel_fx( TDREND_HRFILT_FiltSet_t *HrFiltSet_p, const Word32 output_Fs );
      62             : 
      63             : /*-------------------------------------------------------------------*
      64             :  * TDREND_MIX_LIST_SetPos()
      65             :  *
      66             :  * Sets the listener's position in the specified mixer unit.
      67             :  --------------------------------------------------------------------*/
      68             : 
      69      685912 : void TDREND_MIX_LIST_SetPos_fx(
      70             :     BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd,     /* i/o: TD renderer handle      */
      71             :     const Word32 *Pos_p /* i  : Listener's position     */ // Q Pos_fx->q_fact
      72             : )
      73             : {
      74             :     TDREND_MIX_Listener_t *Listener_p;
      75             : 
      76      685912 :     Listener_p = hBinRendererTd->Listener_p;
      77      685912 :     test();
      78      685912 :     test();
      79      685912 :     IF( NE_32( Pos_p[0], Listener_p->Pos_fx[0] ) || NE_32( Pos_p[1], Listener_p->Pos_fx[1] ) || NE_32( Pos_p[2], Listener_p->Pos_fx[2] ) )
      80             :     {
      81             :         /* Set position */
      82        6688 :         Copy32( Pos_p, Listener_p->Pos_fx, 3 ); // Q Pos_fx->q_fact
      83             : 
      84             :         /* Set pose update flag */
      85        6688 :         Listener_p->PoseUpdated = TRUE;
      86        6688 :         move16();
      87             :     }
      88             : 
      89      685912 :     return;
      90             : }
      91             : 
      92             : 
      93             : /*-------------------------------------------------------------------*
      94             :  * TDREND_MIX_LIST_SetOrient()
      95             :  *
      96             :  * Sets the listener's orientation vectors in the specified mixer unit.
      97             :  --------------------------------------------------------------------*/
      98             : 
      99      685912 : ivas_error TDREND_MIX_LIST_SetOrient_fx(
     100             :     BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle                  */
     101             :     const Word32 *FrontVec_p_fx,
     102             :     /* i  : Listener's orientation front vector */ // orient_q
     103             :     const Word32 *UpVec_p_fx,
     104             :     /* i  : Listener's orientation up vector    */ // orient_q
     105             :     const Word16 orient_q                          /* i  : Listener's orientation q-factor     */
     106             : )
     107             : {
     108             : 
     109             :     TDREND_MIX_Listener_t *List_p;
     110             :     /* Value verification */
     111      685912 :     test();
     112      685912 :     test();
     113      685912 :     IF( ( FrontVec_p_fx[0] == 0 ) && ( FrontVec_p_fx[1] == 0 ) && ( FrontVec_p_fx[2] == 0 ) )
     114             :     {
     115           0 :         return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Zero front vector. Command is ignored!\n" ) );
     116             :     }
     117             : 
     118      685912 :     IF( ( UpVec_p_fx[0] == 0 ) && ( UpVec_p_fx[1] == 0 ) && ( UpVec_p_fx[2] == 0 ) )
     119             :     {
     120           0 :         return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Zero up vector. Command is ignored!\n" ) );
     121             :     }
     122             : 
     123      685912 :     test();
     124      685912 :     test();
     125             :     /* Get listener */
     126      685912 :     List_p = hBinRendererTd->Listener_p;
     127             : 
     128             :     /* Evaluate the normalized orientation vectors and set pose update flag */
     129      685912 :     List_p->PoseUpdated = TDREND_SPATIAL_EvalOrthonormOrient_fx( List_p->Front_fx, List_p->Up_fx, List_p->Right_fx, FrontVec_p_fx, UpVec_p_fx, orient_q ); // Q0
     130      685912 :     move16();
     131             : 
     132      685912 :     return IVAS_ERR_OK;
     133             : }
     134             : 
     135             : 
     136             : /*-------------------------------------------------------------------*
     137             :  * TDREND_MIX_Dealloc()
     138             :  *
     139             :  * Deallocates the TDREND_MIX_t variable
     140             :  --------------------------------------------------------------------*/
     141             : 
     142         939 : void TDREND_MIX_Dealloc_fx(
     143             :     BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd /* i/o: TD renderer handle    */
     144             : )
     145             : {
     146             :     Word16 i;
     147             : 
     148             :     /* Deallocate source list */
     149        2578 :     FOR( i = 0; i < hBinRendererTd->NumOfSrcs; i++ )
     150             :     {
     151        1639 :         TDREND_SRC_Dealloc( hBinRendererTd->Sources[i] );
     152             :     }
     153             :     /* Deallocate Listener and RendListener */
     154         939 :     IF( hBinRendererTd->Listener_p != NULL )
     155             :     {
     156         939 :         free( hBinRendererTd->Listener_p );
     157         939 :         hBinRendererTd->Listener_p = NULL;
     158             :     }
     159             :     /* Dealloc HR filter set */
     160         939 :     test();
     161         939 :     IF( ( *hBinRendererTd->pHrFiltSet_p != NULL ) && ( hBinRendererTd->HrFiltSet_p != NULL ) )
     162             :     {
     163         358 :         IF( EQ_16( hBinRendererTd->HrFiltSet_p->FilterMethod, TDREND_HRFILT_Method_BSplineModel ) )
     164             :         {
     165         358 :             BSplineModelEvalDealloc_fx( &hBinRendererTd->HrFiltSet_p->ModelParams, &hBinRendererTd->HrFiltSet_p->ModelEval );
     166             :         }
     167             :         ELSE
     168             :         {
     169           0 :             IF( hBinRendererTd->HrFiltSet_p->Elev_p_fx != NULL )
     170             :             {
     171           0 :                 free( hBinRendererTd->HrFiltSet_p->Elev_p_fx );
     172           0 :                 hBinRendererTd->HrFiltSet_p->Elev_p_fx = NULL;
     173             :             }
     174           0 :             IF( hBinRendererTd->HrFiltSet_p->Azim_p_fx != NULL )
     175             :             {
     176           0 :                 free( hBinRendererTd->HrFiltSet_p->Azim_p_fx );
     177           0 :                 hBinRendererTd->HrFiltSet_p->Azim_p_fx = NULL;
     178             :             }
     179           0 :             IF( hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx != NULL )
     180             :             {
     181           0 :                 free( hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx );
     182           0 :                 hBinRendererTd->HrFiltSet_p->LeftFiltSet_p_fx = NULL;
     183             :             }
     184           0 :             IF( hBinRendererTd->HrFiltSet_p->RightFiltSet_p_fx != NULL )
     185             :             {
     186           0 :                 free( hBinRendererTd->HrFiltSet_p->RightFiltSet_p_fx );
     187           0 :                 hBinRendererTd->HrFiltSet_p->RightFiltSet_p_fx = NULL;
     188             :             }
     189             :         }
     190             : 
     191             : #ifdef USE_TDREND_16BIT_ROM
     192         358 :         IF( hBinRendererTd->HrFiltSet_p->ModelParams.modelROM )
     193             :         {
     194         358 :             if ( hBinRendererTd->HrFiltSet_p->ModelParams.UseItdModel )
     195             :             {
     196         358 :                 free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.elevKSeq_dyn_fx );
     197         358 :                 free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.azimKSeq_dyn_fx );
     198         358 :                 free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.W_dyn_fx );
     199         358 :                 free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.azimBsShape_dyn_fx );
     200         358 :                 free( hBinRendererTd->HrFiltSet_p->ModelParamsITD.elevBsShape_dyn_fx );
     201             :             }
     202         358 :             free( hBinRendererTd->HrFiltSet_p->ModelParams.elevKSeq_dyn_fx );
     203             : #ifndef FIX_989_TD_REND_ROM
     204             :             free( hBinRendererTd->HrFiltSet_p->ModelParams.azimDim2_dyn );
     205             : #endif
     206         358 :             free( hBinRendererTd->HrFiltSet_p->ModelParams.AlphaL_dyn_fx );
     207         358 :             free( hBinRendererTd->HrFiltSet_p->ModelParams.AlphaR_dyn_fx );
     208             : 
     209         358 :             free( hBinRendererTd->HrFiltSet_p->ModelParams.elevBsShape_dyn_fx );
     210             :         }
     211             : #endif
     212             : 
     213             : 
     214         358 :         IF( EQ_16( hBinRendererTd->HrFiltSet_p->ModelParams.modelROM, 1 ) )
     215             :         {
     216         358 :             free( hBinRendererTd->HrFiltSet_p );
     217         358 :             hBinRendererTd->HrFiltSet_p = NULL;
     218         358 :             *hBinRendererTd->pHrFiltSet_p = NULL;
     219             :         }
     220             :     }
     221             : 
     222         939 :     return;
     223             : }
     224             : 
     225             : 
     226             : /*-------------------------------------------------------------------*
     227             :  * TDREND_MIX_Init()
     228             :  *
     229             :  * Initializes the mixer and sets HRTF
     230             :  --------------------------------------------------------------------*/
     231         939 : ivas_error TDREND_MIX_Init_fx(
     232             :     BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd,                         /* i/o: TD renderer handle                       */
     233             :     TDREND_HRFILT_FiltSet_t **hHrtfTD,                                         /* i/o: HRTF data (initialized in case of NULL)  */
     234             :     const TDREND_MixSpatSpec_t *MixSpatSpec_p,                                 /* i  : Mixer spatial specification              */
     235             :     const Word32 output_Fs /* i  : Output sampling rate                     */ // Q0
     236             : )
     237             : {
     238             :     ivas_error error;
     239         939 :     hBinRendererTd->Gain_fx = ONE_IN_Q14;
     240         939 :     move16();
     241             :     /* Init source list */
     242             :     /* Spatial settings */
     243         939 :     IF( MixSpatSpec_p != NULL )
     244             :     {
     245         939 :         hBinRendererTd->UseCommonDistAttenModel = MixSpatSpec_p->UseCommonDistAttenModel; // Q0
     246         939 :         move16();
     247         939 :         hBinRendererTd->DistAttenModel = MixSpatSpec_p->DistAttenModel; // Q0
     248         939 :         move16();
     249             :     }
     250             :     ELSE
     251             :     {
     252           0 :         hBinRendererTd->UseCommonDistAttenModel = TRUE; // Q0
     253           0 :         move16();
     254           0 :         hBinRendererTd->DistAttenModel = 0x0000; /* Distance attenuation not activated; */ // Q0
     255           0 :         move16();
     256             :     }
     257             :     /* Init virtual and rendering listeners for spatial mixers */
     258         939 :     TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Pos_fx, 0, 0, 0 );
     259         939 :     hBinRendererTd->Listener_p->Pos_q = Q25;
     260         939 :     move16();
     261         939 :     TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Vel_fx, 0, 0, 0 );
     262         939 :     TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Front_fx, 0, 0, -ONE_IN_Q30 );
     263         939 :     TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Up_fx, 0, ONE_IN_Q30, 0 );
     264         939 :     TDREND_SPATIAL_VecInit_fx( hBinRendererTd->Listener_p->Right_fx, ONE_IN_Q30, 0, 0 );
     265             :     /* Init HR filter set */
     266         939 :     IF( *hHrtfTD == NULL )
     267             :     {
     268         358 :         IF( ( hBinRendererTd->HrFiltSet_p = (TDREND_HRFILT_FiltSet_t *) malloc( sizeof( TDREND_HRFILT_FiltSet_t ) ) ) == NULL )
     269             :         {
     270           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
     271             :         }
     272             : 
     273         358 :         IF( NE_32( ( error = DefaultBSplineModel_fx( hBinRendererTd->HrFiltSet_p, output_Fs ) ), IVAS_ERR_OK ) )
     274             :         {
     275           0 :             return error;
     276             :         }
     277         358 :         *hHrtfTD = hBinRendererTd->HrFiltSet_p;
     278             :     }
     279             :     ELSE
     280             :     {
     281         581 :         hBinRendererTd->HrFiltSet_p = *hHrtfTD;
     282             :     }
     283             : 
     284         939 :     hBinRendererTd->pHrFiltSet_p = hHrtfTD;
     285             : 
     286         939 :     IF( NE_32( hBinRendererTd->HrFiltSet_p->SampleRate, output_Fs ) )
     287             :     {
     288           0 :         return ( IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "The sampling rate for the HR filter set does not match the output sampling rate.\n" ) );
     289             :     }
     290         939 :     return IVAS_ERR_OK;
     291             : }
     292             : 
     293             : /*-------------------------------------------------------------------*
     294             :  * TDREND_MIX_SetDistAttenModel()
     295             :  *
     296             :  * Set the distance attenuation model of the mixer
     297             :  --------------------------------------------------------------------*/
     298             : 
     299         939 : ivas_error TDREND_MIX_SetDistAttenModel(
     300             :     BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle         */
     301             :     const TDREND_DistAttenModel_t DistAttenModel       /* i  : Distance attenuation model */
     302             : )
     303             : {
     304             :     /* Value validation */
     305         939 :     test();
     306         939 :     IF( LT_16( DistAttenModel, TDREND_DIST_ATTEN_MODEL_INV_DIST ) || GT_16( DistAttenModel, TDREND_DIST_ATTEN_MODEL_INV_DIST_CLAMPED ) )
     307             :     {
     308           0 :         return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Invalid distance attenuation model!\n" ) );
     309             :     }
     310             :     ELSE
     311             :     {
     312             :         /* Set the common distance attenuation model */
     313         939 :         hBinRendererTd->DistAttenModel = DistAttenModel; // Q0
     314         939 :         move32();
     315             : 
     316             :         /* If using common distance attenuation model, set it. */
     317         939 :         IF( hBinRendererTd->UseCommonDistAttenModel )
     318             :         {
     319         939 :             hBinRendererTd->DistAttenEnabled = TRUE; // Q0
     320         939 :             move16();
     321         939 :             hBinRendererTd->DistAttenModel = DistAttenModel; // Q0
     322         939 :             move32();
     323             :         }
     324             :     }
     325         939 :     return IVAS_ERR_OK;
     326             : }
     327             : 
     328             : 
     329             : /*-------------------------------------------------------------------*
     330             :  * TDREND_MIX_AddSrc()
     331             :  *
     332             :  * Adds the specified input source unit to the specified mixer unit.
     333             :  --------------------------------------------------------------------*/
     334        1639 : ivas_error TDREND_MIX_AddSrc_fx(
     335             :     BINAURAL_TD_OBJECT_RENDERER_HANDLE hBinRendererTd, /* i/o: TD renderer handle                */
     336             :     Word16 *SrcInd,
     337             :     /* o  : Source index                      */ // Q0
     338             :     const TDREND_PosType_t PosType               /* i  : Position type (absolute/relative) */
     339             : )
     340             : {
     341             :     TDREND_SRC_t *Src_p;
     342             :     ivas_error error;
     343             : 
     344             : #ifndef FIX_989_TD_REND_ROM
     345             :     error = IVAS_ERR_OK;
     346             : #endif
     347        1639 :     move32();
     348             :     /* Get unique source index */
     349        1639 :     *SrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); // Q0
     350        1639 :     move16();
     351        1639 :     hBinRendererTd->MaxSrcInd = add( hBinRendererTd->MaxSrcInd, 1 ); // Q0
     352        1639 :     move16();
     353        1639 :     hBinRendererTd->NumOfSrcs = add( hBinRendererTd->NumOfSrcs, 1 ); // Q0
     354        1639 :     move16();
     355             : 
     356        1639 :     IF( GT_16( hBinRendererTd->NumOfSrcs, MAX_NUM_TDREND_CHANNELS ) )
     357             :     {
     358           0 :         return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Maximum number of sources exceeded!\n" ) );
     359             :     }
     360             :     ELSE
     361             :     {
     362        1639 :         test();
     363        1639 :         IF( LT_16( PosType, TDREND_POSTYPE_ABSOLUTE ) || GT_16( PosType, TDREND_POSTYPE_NON_DIEGETIC ) )
     364             :         {
     365           0 :             return ( IVAS_ERROR( IVAS_ERR_INTERNAL, "Invalid position type!\n" ) );
     366             :         }
     367             :         ELSE
     368             :         {
     369             :             /* Alloc and init a complete source: signal+spatial+rend components */
     370        1639 :             IF( NE_32( ( error = TDREND_SRC_Alloc( &Src_p ) ), IVAS_ERR_OK ) )
     371             :             {
     372           0 :                 return error;
     373             :             }
     374             : 
     375        1639 :             TDREND_SRC_Init_fx( Src_p, PosType );
     376             : 
     377             :             /* Special OpenAL initialization due to a common distance attenuation model */
     378        1639 :             IF( NE_16( hBinRendererTd->DistAttenModel, 0 ) )
     379             :             {
     380        1639 :                 Src_p->SrcSpatial_p->DistAttenEnabled = TRUE; // Q0
     381        1639 :                 move16();
     382        1639 :                 Src_p->SrcSpatial_p->DistAtten.DistAttenModel = hBinRendererTd->DistAttenModel; // Q0
     383        1639 :                 move32();
     384             :             }
     385             :             /* Add source to mixer */
     386        1639 :             hBinRendererTd->Sources[*SrcInd] = Src_p;
     387             :         }
     388             :     }
     389             : 
     390             : #ifdef FIX_989_TD_REND_ROM
     391        1639 :     return IVAS_ERR_OK;
     392             : #else
     393             :     return error;
     394             : #endif
     395             : }
     396             : 
     397             : /*-------------------------------------------------------------------*
     398             :  * BSplineModelEvalAlloc()
     399             :  *
     400             :  * Allocate the B Spline HR Filter model.
     401             :  --------------------------------------------------------------------*/
     402             : 
     403         358 : static ivas_error BSplineModelEvalAlloc_fx(
     404             :     ModelParams_t *model,  /* i  : Model parameters           */
     405             :     ModelEval_t *modelEval /* i/o: Model evaluation structure */
     406             : )
     407             : {
     408         358 :     IF( ( modelEval->hrfModL_fx = (Word32 *) malloc( model->K * sizeof( Word32 ) ) ) == NULL )
     409             :     {
     410           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
     411             :     }
     412             : 
     413         358 :     IF( ( modelEval->hrfModR_fx = (Word32 *) malloc( model->K * sizeof( Word32 ) ) ) == NULL )
     414             :     {
     415           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
     416             :     }
     417             : 
     418         358 :     return IVAS_ERR_OK;
     419             : }
     420             : 
     421             : 
     422             : /*-------------------------------------------------------------------*
     423             :  * DefaultBSplineModel()
     424             :  *
     425             :  * Init default HRTF model
     426             :  --------------------------------------------------------------------*/
     427             : 
     428         358 : static ivas_error DefaultBSplineModel_fx(
     429             :     TDREND_HRFILT_FiltSet_t *HrFiltSet_p,                       /* o  : Loaded HR filter set      */
     430             :     const Word32 output_Fs /* i  : Output sampling rate      */ // Q0
     431             : )
     432             : {
     433             :     ModelParams_t *model;
     434             :     ModelParamsITD_t *modelITD;
     435             :     Word16 i, j;
     436             :     ivas_error error;
     437             : #ifdef FIX_989_TD_REND_ROM
     438             :     Word16 azimSegSamples;
     439             : #endif
     440         358 :     HrFiltSet_p->FilterMethod = TDREND_HRFILT_Method_BSplineModel;
     441         358 :     move16();
     442         358 :     model = &( HrFiltSet_p->ModelParams );
     443         358 :     modelITD = &( HrFiltSet_p->ModelParamsITD );
     444             : 
     445             : 
     446             :     /* Set ROM flag for correct deallocation */
     447         358 :     model->modelROM = TRUE;
     448         358 :     move16();
     449             : 
     450             : #ifdef FIX_989_TD_REND_ROM
     451         358 :     model->UseItdModel = defaultHRIR_rom_model_configuration[0]; // Q0
     452         358 :     move16();
     453         358 :     model->elevDim3 = defaultHRIR_rom_model_configuration[1]; // Q0
     454         358 :     move16();
     455         358 :     model->AlphaN = defaultHRIR_rom_model_configuration[2]; // Q0
     456         358 :     move16();
     457         358 :     model->num_unique_azim_splines = defaultHRIR_rom_model_configuration[3]; // Q0
     458         358 :     move16();
     459         358 :     model->elevSegSamples = defaultHRIR_rom_model_configuration[4]; // Q0
     460         358 :     move16();
     461         358 :     model->elevBsLen = defaultHRIR_rom_elevBsLen;     // Q0
     462         358 :     model->elevBsStart = defaultHRIR_rom_elevBsStart; // Q0
     463             : #else
     464             :     /* int16_t parameters */
     465             :     model->UseItdModel = 1; // Q0
     466             :     move16();
     467             :     model->SplineDegree = 4; // Q0
     468             :     move16();
     469             :     model->elevDim2 = 17; // Q0
     470             :     move16();
     471             :     model->elevDim3 = 15; // Q0
     472             :     move16();
     473             :     model->AlphaN = 470; // Q0
     474             :     move16();
     475             :     model->num_unique_azim_splines = 1; // Q0
     476             :     move16();
     477             :     model->elevSegSamples = 4; // Q0
     478             :     move16();
     479             :     model->elevBsLen[0] = 5; // Q0
     480             :     move16();
     481             :     model->elevBsLen[1] = 9; // Q0
     482             :     move16();
     483             :     model->elevBsLen[2] = 13; // Q0
     484             :     move16();
     485             :     model->elevBsLen[3] = 9; // Q0
     486             :     move16();
     487             :     model->elevBsStart[0] = 0; // Q0
     488             :     move16();
     489             :     model->elevBsStart[1] = 5; // Q0
     490             :     move16();
     491             :     model->elevBsStart[2] = 14; // Q0
     492             :     move16();
     493             :     model->elevBsStart[3] = 27; // Q0
     494             :     move16();
     495             : 
     496             :     model->azimDim2 = defaultHRIR_rom_azimDim2;                              // Q0
     497             : #endif
     498         358 :     model->azimDim3 = defaultHRIR_rom_azimDim3;                       // Q0
     499         358 :     model->azim_start_idx = defaultHRIR_rom_azim_start_idx;           // Q0
     500         358 :     model->azimSegSamples = defaultHRIR_rom_azimSegSamples;           // Q0
     501         358 :     model->azimShapeIdx = defaultHRIR_rom_azimShapeIdx;               // Q0
     502         358 :     model->azimShapeSampFactor = defaultHRIR_rom_azimShapeSampFactor; // Q0
     503             : 
     504             : #ifdef USE_TDREND_16BIT_ROM
     505         358 :     model->elevKSeq_dyn_fx = (Word32 *) malloc( ( model->elevDim3 - 2 ) * sizeof( Word32 ) );
     506         358 :     if ( model->elevKSeq_dyn_fx == NULL )
     507             :     {
     508           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     509             :     }
     510         358 :     Copy_Scale_sig_16_32_r( defaultHRIR_rom_elevKSeq_fx, model->elevKSeq_dyn_fx, ( model->elevDim3 - 2 ), Q22 - defaultHRIR_rom_elevKSeq_Q_fx ); // Q22
     511         358 :     model->elevKSeq_fx = model->elevKSeq_dyn_fx;
     512             : #else
     513             :     model->elevKSeq_fx = defaultHRIR_rom_elevKSeq_fx;                        // Q22
     514             : #endif
     515             : 
     516             : #ifdef USE_TDREND_16BIT_ROM
     517         358 :     model->elevBsShape_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_elevBsShape_fx ) * sizeof( Word32 ) / sizeof( Word16 ) );
     518         358 :     if ( model->elevBsShape_dyn_fx == NULL )
     519             :     {
     520           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     521             :     }
     522         358 :     Copy_Scale_sig_16_32_r( defaultHRIR_rom_elevBsShape_fx, model->elevBsShape_dyn_fx, sizeof( defaultHRIR_rom_elevBsShape_fx ) / sizeof( Word16 ), Q30 - defaultHRIR_rom_elevBsShape_Q_fx ); // Q30
     523         358 :     model->elevBsShape_fx = model->elevBsShape_dyn_fx;
     524             : #else
     525             :     model->elevBsShape_fx = (const Word32 *) defaultHRIR_rom_elevBsShape_fx; // Q30
     526             : #endif
     527             : 
     528         358 :     IF( ( model->azimBsShape_fx = (const Word32 **) malloc( model->num_unique_azim_splines * sizeof( Word32 * ) ) ) == NULL )
     529             :     {
     530           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
     531             :     }
     532             : #ifdef USE_TDREND_16BIT_ROM
     533         358 :     model->azimBsShape_dyn_fx = (Word32 **) malloc( sizeof( Word32 * ) );
     534         358 :     if ( model->azimBsShape_dyn_fx == NULL )
     535             :     {
     536           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     537             :     }
     538         358 :     model->azimBsShape_dyn_fx[0] = (Word32 *) malloc( sizeof( defaultHRIR_rom_azimBsShape_fx ) * sizeof( Word32 ) / sizeof( Word16 ) );
     539         358 :     if ( model->azimBsShape_dyn_fx[0] == NULL )
     540             :     {
     541           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     542             :     }
     543         358 :     Copy_Scale_sig_16_32_r( defaultHRIR_rom_azimBsShape_fx, model->azimBsShape_dyn_fx[0], sizeof( defaultHRIR_rom_azimBsShape_fx ) / sizeof( Word16 ), Q30 - defaultHRIR_rom_azimBsShape_Q_fx ); // Q30
     544         358 :     model->azimBsShape_fx[0] = model->azimBsShape_dyn_fx[0];
     545             : #else
     546             :     model->azimBsShape_fx[0] = defaultHRIR_rom_azimBsShape_fx;               // Q30
     547             : #endif
     548             : #ifdef FIX_989_TD_REND_ROM
     549         358 :     if ( ( model->azimKSeq_fx = (Word32 **) malloc( model->elevDim3 * sizeof( Word32 * ) ) ) == NULL )
     550             : #else
     551             :     IF( ( model->azimKSeq_fx = (Word32 **) malloc( 18 * sizeof( Word32 * ) ) ) == NULL )
     552             : #endif
     553             :     {
     554           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
     555             :     }
     556             : #ifdef FIX_989_TD_REND_ROM
     557        5728 :     FOR( i = 0; i < model->elevDim3; i++ )
     558             :     {
     559        5370 :         if ( ( model->azimKSeq_fx[i] = (Word32 *) malloc( ( model->azimDim3[i] + 1 ) * sizeof( Word32 * ) ) ) == NULL )
     560             :         {
     561           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
     562             :         }
     563             : 
     564        5370 :         IF( LT_16( model->azimShapeIdx[i], 0 ) )
     565             :         {
     566         716 :             azimSegSamples = 360;
     567             :         }
     568             :         ELSE
     569             :         {
     570        4654 :             azimSegSamples = defaultHRIR_rom_azimSegSamples[model->azimShapeIdx[i]]; // Q0
     571             :         }
     572        5370 :         move16();
     573             : 
     574        5370 :         assert( azimSegSamples == 360 / model->azimDim3[i] );
     575      179000 :         FOR( j = 0; j < model->azimDim3[i] + 1; j++ )
     576             :         {
     577      173630 :             model->azimKSeq_fx[i][j] = L_shl_r( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), Q22 ); // Q22
     578      173630 :             move32();
     579             :         }
     580             :     }
     581             : #else
     582             :     IF( ( model->azimKSeq_fx[0] = (Word32 *) malloc( 2 * sizeof( Word32 * ) ) ) == NULL )
     583             :     {
     584             :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
     585             :     }
     586             :     IF( ( model->azimKSeq_fx[model->elevDim3 - 1] = (Word32 *) malloc( 2 * sizeof( Word32 * ) ) ) == NULL )
     587             :     {
     588             :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
     589             :     }
     590             :     model->azimKSeq_fx[0][0] = 0;
     591             :     model->azimKSeq_fx[model->elevDim3 - 1][0] = 0;
     592             :     model->azimKSeq_fx[0][1] = 360 << Q22;                   // Q22
     593             :     model->azimKSeq_fx[model->elevDim3 - 1][1] = 360 << Q22; // Q22
     594             :     move32();
     595             :     move32();
     596             :     move32();
     597             :     move32();
     598             : 
     599             :     FOR( i = 1; i < sub( model->elevDim3, 1 ); i++ )
     600             :     {
     601             :         IF( ( model->azimKSeq_fx[i] = (Word32 *) malloc( model->azimDim2[i] * sizeof( Word32 * ) ) ) == NULL ) /* azimDim2[i] = 91, i=2..15 */
     602             :         {
     603             :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Binaural TD renderer\n" ) );
     604             :         }
     605             :         FOR( j = 0; j < model->azimDim2[i]; j++ )
     606             :         {
     607             :             model->azimKSeq_fx[i][j] = L_shl_r( L_mult0( defaultHRIR_rom_azimSegSamples[0], j ), Q22 ); // Q22
     608             :             move32();
     609             :         }
     610             :     }
     611             : #endif
     612         358 :     SWITCH( output_Fs )
     613             :     {
     614         327 :         case 48000:
     615             : #ifdef USE_TDREND_16BIT_ROM
     616         327 :             model->AlphaL_dyn_fx = (Word32 *) malloc( 60160 * sizeof( Word32 ) );
     617         327 :             if ( model->AlphaL_dyn_fx == NULL )
     618             :             {
     619           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     620             :             }
     621         327 :             Copy_Scale_sig_16_32_r( defaultHRIR_rom_AlphaL48_fx, model->AlphaL_dyn_fx, 30080, Q30 - defaultHRIR_rom_Alpha48_Q_fx );                 // Q30
     622         327 :             Copy_Scale_sig_16_32_r( &defaultHRIR_rom_AlphaL48_fx[30080], &model->AlphaL_dyn_fx[30080], 30080, Q30 - defaultHRIR_rom_Alpha48_Q_fx ); // Q30
     623         327 :             model->AlphaL_fx = model->AlphaL_dyn_fx;
     624         327 :             model->AlphaL_e = Q15 - defaultHRIR_rom_Alpha48_Q_fx;
     625             : #else
     626             :             model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL48_fx; // Q30
     627             :             model->AlphaL_e = 1;
     628             : #endif
     629         327 :             move16();
     630             : #ifdef USE_TDREND_16BIT_ROM
     631         327 :             model->AlphaR_dyn_fx = (Word32 *) malloc( 60160 * sizeof( Word32 ) );
     632         327 :             if ( model->AlphaR_dyn_fx == NULL )
     633             :             {
     634           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     635             :             }
     636         327 :             Copy_Scale_sig_16_32_r( defaultHRIR_rom_AlphaR48_fx, model->AlphaR_dyn_fx, 30080, Q30 - defaultHRIR_rom_Alpha48_Q_fx );                 // Q22
     637         327 :             Copy_Scale_sig_16_32_r( &defaultHRIR_rom_AlphaR48_fx[30080], &model->AlphaR_dyn_fx[30080], 30080, Q30 - defaultHRIR_rom_Alpha48_Q_fx ); // Q22
     638         327 :             model->AlphaR_fx = model->AlphaR_dyn_fx;
     639         327 :             model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha48_Q_fx;
     640             : #else
     641             :             model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR48_fx; // Q30
     642             :             model->AlphaR_e = 1;
     643             : #endif
     644         327 :             move16();
     645         327 :             model->EL_fx = (const Word32 *) defaultHRIR_rom_EL48_fx; // Q28
     646             : #ifdef USE_TDREND_16BIT_ROM
     647         327 :             model->EL_e = Q31 - defaultHRIR_rom_E48_Q_fx;
     648             : #else
     649             :             model->EL_e = 3;
     650             : #endif
     651         327 :             move16();
     652         327 :             model->ER_fx = (const Word32 *) defaultHRIR_rom_ER48_fx; // Q28
     653             : #ifdef USE_TDREND_16BIT_ROM
     654         327 :             model->ER_e = Q31 - defaultHRIR_rom_E48_Q_fx;
     655             : #else
     656             :             model->ER_e = 3;
     657             : #endif
     658         327 :             move16();
     659             : #ifdef FIX_989_TD_REND_ROM
     660         327 :             model->K = defaultHRIR_rom_model_configuration[5]; // Q0
     661             : #else
     662             :             model->K = 128;                                                  // Q0
     663             : #endif
     664         327 :             move16();
     665         327 :             IF( HrFiltSet_p->ModelParams.UseItdModel )
     666             :             {
     667         327 :                 modelITD->resamp_factor_fx = ONE_IN_Q14; // Q14
     668         327 :                 move16();
     669             :             }
     670         327 :             BREAK;
     671          31 :         case 32000:
     672             : #ifdef USE_TDREND_16BIT_ROM
     673          31 :             model->AlphaL_dyn_fx = (Word32 *) malloc( 40420 * sizeof( Word32 ) );
     674          31 :             if ( model->AlphaL_dyn_fx == NULL )
     675             :             {
     676           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     677             :             }
     678          31 :             Copy_Scale_sig_16_32_r( defaultHRIR_rom_AlphaL32_fx, model->AlphaL_dyn_fx, 20210, Q30 - defaultHRIR_rom_Alpha32_Q_fx );                 // Q22
     679          31 :             Copy_Scale_sig_16_32_r( &defaultHRIR_rom_AlphaL32_fx[20210], &model->AlphaL_dyn_fx[20210], 20210, Q30 - defaultHRIR_rom_Alpha32_Q_fx ); // Q22
     680          31 :             model->AlphaL_fx = model->AlphaL_dyn_fx;
     681          31 :             model->AlphaL_e = Q15 - defaultHRIR_rom_Alpha32_Q_fx;
     682             : #else
     683             :             model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL32_fx; // Q30
     684             :             model->AlphaL_e = 1;
     685             : #endif
     686          31 :             move16();
     687             : #ifdef USE_TDREND_16BIT_ROM
     688          31 :             model->AlphaR_dyn_fx = (Word32 *) malloc( 40420 * sizeof( Word32 ) );
     689          31 :             if ( model->AlphaR_dyn_fx == NULL )
     690             :             {
     691           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     692             :             }
     693          31 :             Copy_Scale_sig_16_32_r( defaultHRIR_rom_AlphaR32_fx, model->AlphaR_dyn_fx, 20210, Q30 - defaultHRIR_rom_Alpha32_Q_fx );                 // Q22
     694          31 :             Copy_Scale_sig_16_32_r( &defaultHRIR_rom_AlphaR32_fx[20210], &model->AlphaR_dyn_fx[20210], 20210, Q30 - defaultHRIR_rom_Alpha32_Q_fx ); // Q22
     695          31 :             model->AlphaR_fx = model->AlphaR_dyn_fx;
     696          31 :             model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha32_Q_fx;
     697             : #else
     698             :             model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR32_fx; // Q30
     699             :             model->AlphaR_e = 1;
     700             : #endif
     701          31 :             move16();
     702          31 :             model->EL_fx = (const Word32 *) defaultHRIR_rom_EL32_fx; // Q28
     703             : #ifdef USE_TDREND_16BIT_ROM
     704          31 :             model->EL_e = Q31 - defaultHRIR_rom_E32_Q_fx;
     705             : #else
     706             :             model->EL_e = 3;
     707             : #endif
     708          31 :             move16();
     709          31 :             model->ER_fx = (const Word32 *) defaultHRIR_rom_ER32_fx; // Q28
     710             : #ifdef USE_TDREND_16BIT_ROM
     711          31 :             model->ER_e = Q31 - defaultHRIR_rom_E32_Q_fx;
     712             : #else
     713             :             model->ER_e = 3;
     714             : #endif
     715          31 :             move16();
     716             : #ifdef FIX_989_TD_REND_ROM
     717          31 :             model->K = ( RESAMPLE_FACTOR_32_48_FX * defaultHRIR_rom_model_configuration[5] + ( 1 << 14 ) - 1 ) >> 14; // Q0
     718             : #else
     719             :             model->K = 86;                                                   // Q0
     720             : #endif
     721          31 :             move16();
     722          31 :             IF( HrFiltSet_p->ModelParams.UseItdModel )
     723             :             {
     724          31 :                 modelITD->resamp_factor_fx = RESAMPLE_FACTOR_32_48_FX; // Q14
     725          31 :                 move16();
     726             :             }
     727          31 :             BREAK;
     728           0 :         case 16000:
     729             : #ifdef USE_TDREND_16BIT_ROM
     730           0 :             model->AlphaL_dyn_fx = (Word32 *) malloc( 20210 * sizeof( Word32 ) );
     731           0 :             if ( model->AlphaL_dyn_fx == NULL )
     732             :             {
     733           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     734             :             }
     735           0 :             Copy_Scale_sig_16_32_r( defaultHRIR_rom_AlphaL16_fx, model->AlphaL_dyn_fx, 20210, Q30 - defaultHRIR_rom_Alpha16_Q_fx ); // Q22
     736           0 :             model->AlphaL_fx = model->AlphaL_dyn_fx;
     737           0 :             model->AlphaL_e = Q15 - defaultHRIR_rom_Alpha16_Q_fx;
     738             : #else
     739             :             model->AlphaL_fx = (const Word32 *) defaultHRIR_rom_AlphaL16_fx; // Q30
     740             :             model->AlphaL_e = 1;
     741             : #endif
     742           0 :             move16();
     743             : #ifdef USE_TDREND_16BIT_ROM
     744           0 :             model->AlphaR_dyn_fx = (Word32 *) malloc( 20210 * sizeof( Word32 ) );
     745           0 :             if ( model->AlphaR_dyn_fx == NULL )
     746             :             {
     747           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     748             :             }
     749           0 :             Copy_Scale_sig_16_32_r( defaultHRIR_rom_AlphaR16_fx, model->AlphaR_dyn_fx, 20210, Q30 - defaultHRIR_rom_Alpha16_Q_fx ); // Q22
     750           0 :             model->AlphaR_fx = model->AlphaR_dyn_fx;
     751           0 :             model->AlphaR_e = Q15 - defaultHRIR_rom_Alpha16_Q_fx;
     752             : #else
     753             :             model->AlphaR_fx = (const Word32 *) defaultHRIR_rom_AlphaR16_fx; // Q30
     754             :             model->AlphaR_e = 1;
     755             : #endif
     756           0 :             move16();
     757           0 :             model->EL_fx = (const Word32 *) defaultHRIR_rom_EL16_fx; // Q28
     758             : #ifdef USE_TDREND_16BIT_ROM
     759           0 :             model->EL_e = Q31 - defaultHRIR_rom_E16_Q_fx;
     760             :             //           model->EL_e = 3;
     761             : #else
     762             :             model->EL_e = 3;
     763             : #endif
     764           0 :             move16();
     765           0 :             model->ER_fx = (const Word32 *) defaultHRIR_rom_ER16_fx; // Q28
     766             : #ifdef USE_TDREND_16BIT_ROM
     767           0 :             model->ER_e = Q31 - defaultHRIR_rom_E16_Q_fx;
     768             :             //           model->ER_e = 3;
     769             : #else
     770             :             model->ER_e = 3;
     771             : #endif
     772           0 :             move16();
     773             : #ifdef FIX_989_TD_REND_ROM
     774           0 :             model->K = ( RESAMPLE_FACTOR_16_48_FX * defaultHRIR_rom_model_configuration[5] + ( 1 << 14 ) - 1 ) >> 14; // Q0
     775             : #else
     776             :             model->K = 43; // Q0
     777             : #endif
     778           0 :             move16();
     779           0 :             IF( HrFiltSet_p->ModelParams.UseItdModel )
     780             :             {
     781           0 :                 modelITD->resamp_factor_fx = RESAMPLE_FACTOR_16_48_FX; // Q14
     782           0 :                 move16();
     783             :             }
     784           0 :             BREAK;
     785           0 :         default:
     786           0 :             BREAK;
     787             :     }
     788             : 
     789             : #ifdef FIX_989_TD_REND_ROM
     790         358 :     modelITD->elevDim3 = defaultHRIR_rom_ITD_model_configuration[0];
     791         358 :     move16();
     792         358 :     modelITD->azimDim3 = defaultHRIR_rom_ITD_model_configuration[1];
     793         358 :     move16();
     794         358 :     modelITD->elevSegSamples = defaultHRIR_rom_ITD_model_configuration[2];
     795         358 :     move16();
     796         358 :     modelITD->azimSegSamples = defaultHRIR_rom_ITD_model_configuration[3];
     797         358 :     move16();
     798         358 :     modelITD->elevBsLen = defaultHRIR_rom_ITD_elevBsLen;
     799         358 :     modelITD->elevBsStart = defaultHRIR_rom_ITD_elevBsStart;
     800             : #else
     801             :     modelITD->N = 4;       // Q0
     802             :     move16();
     803             :     modelITD->elevDim2 = 20; // Q0
     804             :     move16();
     805             :     modelITD->elevDim3 = 18; // Q0
     806             :     move16();
     807             :     modelITD->azimDim2 = 41; // Q0
     808             :     move16();
     809             :     modelITD->azimDim3 = 41; // Q0
     810             :     move16();
     811             :     modelITD->elevSegSamples = 3; // Q0
     812             :     move16();
     813             :     modelITD->elevBsLen[0] = 4; // Q0
     814             :     move16();
     815             :     modelITD->elevBsLen[1] = 7; // Q0
     816             :     move16();
     817             :     modelITD->elevBsLen[2] = 10; // Q0
     818             :     move16();
     819             :     modelITD->elevBsLen[3] = 7; // Q0
     820             :     move16();
     821             :     modelITD->elevBsStart[0] = 0; // Q0
     822             :     move16();
     823             :     modelITD->elevBsStart[1] = 4; // Q0
     824             :     move16();
     825             :     modelITD->elevBsStart[2] = 11; // Q0
     826             :     move16();
     827             :     modelITD->elevBsStart[3] = 21; // Q0
     828             :     move16();
     829             : #endif
     830             : 
     831             : #ifdef USE_TDREND_16BIT_ROM
     832         358 :     modelITD->elevKSeq_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_elevKSeq_fx ) * sizeof( Word32 ) / sizeof( Word16 ) );
     833         358 :     if ( modelITD->elevKSeq_dyn_fx == NULL )
     834             :     {
     835           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     836             :     }
     837         358 :     Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_elevKSeq_fx, modelITD->elevKSeq_dyn_fx, sizeof( defaultHRIR_rom_ITD_elevKSeq_fx ) / sizeof( Word16 ), Q22 - defaultHRIR_rom_ITD_elevKSeq_Q_fx ); // Q22
     838             : 
     839         358 :     modelITD->elevKSeq_fx = modelITD->elevKSeq_dyn_fx;
     840             : #else
     841             :     modelITD->elevKSeq_fx = defaultHRIR_rom_ITD_elevKSeq_fx; // Q22
     842             : #endif
     843             : 
     844             : #ifdef FIX_989_TD_REND_ROM
     845         358 :     modelITD->azimBsLen = defaultHRIR_rom_ITD_azimBsLen;
     846         358 :     modelITD->azimBsStart = defaultHRIR_rom_ITD_azimBsStart;
     847             : #else
     848             :     modelITD->azimBsLen[0] = 11;                             // Q0
     849             :     move16();
     850             :     modelITD->azimBsLen[1] = 21; // Q0
     851             :     move16();
     852             :     modelITD->azimBsLen[2] = 31; // Q0
     853             :     move16();
     854             :     modelITD->azimBsLen[3] = 21; // Q0
     855             :     move16();
     856             :     modelITD->azimBsStart[0] = 0; // Q0
     857             :     move16();
     858             :     modelITD->azimBsStart[1] = 11; // Q0
     859             :     move16();
     860             :     modelITD->azimBsStart[2] = 32; // Q0
     861             :     move16();
     862             :     modelITD->azimBsStart[3] = 63; // Q0
     863             :     move16();
     864             : 
     865             :     modelITD->azimSegSamples = 10; // Q0
     866             :     move16();
     867             : #endif
     868             : 
     869             : #ifdef USE_TDREND_16BIT_ROM
     870         358 :     modelITD->azimKSeq_dyn_fx = (Word32 *) malloc( ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ) * sizeof( Word32 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */
     871         358 :     if ( modelITD->azimKSeq_dyn_fx == NULL )
     872             :     {
     873           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     874             :     }
     875         358 :     Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_azimKSeq_fx, modelITD->azimKSeq_dyn_fx, ( ( modelITD->azimDim3 + 1 ) / 2 - 2 ), Q22 - defaultHRIR_rom_ITD_azimKSeq_Q_fx ); // Q22
     876         358 :     modelITD->azimKSeq_fx = modelITD->azimKSeq_dyn_fx;
     877             : #else
     878             :     modelITD->azimKSeq_fx = defaultHRIR_rom_ITD_azimKSeq_fx;    // Q22
     879             : #endif
     880             : #ifdef USE_TDREND_16BIT_ROM
     881         358 :     modelITD->W_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_W_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */
     882         358 :     if ( modelITD->W_dyn_fx == NULL )
     883             :     {
     884           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     885             :     }
     886         358 :     Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_W_fx, modelITD->W_dyn_fx, sizeof( defaultHRIR_rom_ITD_W_fx ) / sizeof( Word16 ), Q25 - defaultHRIR_rom_ITD_W_Q_fx ); // Q22
     887         358 :     modelITD->W_fx = modelITD->W_dyn_fx;
     888         358 :     modelITD->W_e = Q15 - defaultHRIR_rom_ITD_W_Q_fx;
     889             : #else
     890             :     modelITD->W_fx = (const Word32 *) defaultHRIR_rom_ITD_W_fx; // Q25
     891             :     modelITD->W_e = 6;
     892             : #endif
     893         358 :     move16();
     894             : #ifdef USE_TDREND_16BIT_ROM
     895         358 :     modelITD->azimBsShape_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_azimBsShape_fx ) * sizeof( Word32 ) / sizeof( Word16 ) ); /* basis functions are flipped around 180 deg, number of basis functions above/below is (N+1)/2 */
     896         358 :     if ( modelITD->azimBsShape_dyn_fx == NULL )
     897             :     {
     898           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     899             :     }
     900         358 :     Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_azimBsShape_fx, modelITD->azimBsShape_dyn_fx, sizeof( defaultHRIR_rom_ITD_azimBsShape_fx ) / sizeof( Word16 ), Q30 - defaultHRIR_rom_ITD_azimBsShape_Q_fx ); // Q22
     901         358 :     modelITD->azimBsShape_fx = modelITD->azimBsShape_dyn_fx;
     902             : #else
     903             :     modelITD->azimBsShape_fx = defaultHRIR_rom_ITD_azimBsShape_fx; // Q30
     904             : #endif
     905             : #ifdef USE_TDREND_16BIT_ROM
     906         358 :     modelITD->elevBsShape_dyn_fx = (Word32 *) malloc( sizeof( defaultHRIR_rom_ITD_elevBsShape_fx ) * sizeof( Word32 ) / sizeof( Word16 ) );
     907         358 :     if ( modelITD->elevBsShape_dyn_fx == NULL )
     908             :     {
     909           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for hrtf data" );
     910             :     }
     911         358 :     Copy_Scale_sig_16_32_r( defaultHRIR_rom_ITD_elevBsShape_fx, modelITD->elevBsShape_dyn_fx, sizeof( defaultHRIR_rom_ITD_elevBsShape_fx ) / sizeof( Word16 ), Q30 - defaultHRIR_rom_ITD_elevBsShape_Q_fx ); // Q22
     912         358 :     modelITD->elevBsShape_fx = modelITD->elevBsShape_dyn_fx;
     913             : #else
     914             :     modelITD->elevBsShape_fx = defaultHRIR_rom_ITD_elevBsShape_fx; // Q30
     915             : #endif
     916             : 
     917         358 :     HRTF_model_precalc( model );
     918             : 
     919         358 :     HrFiltSet_p->latency_s_fx = defaultHRIR_rom_latency_s_fx; // Q31
     920         358 :     move32();
     921             : #ifdef USE_TDREND_16BIT_ROM
     922         358 :     HrFiltSet_p->latency_s_Q_fx = sub( Q31, defaultHRIR_rom_latency_s_Q_fx ); // Q31
     923             : #endif
     924         358 :     HrFiltSet_p->SampleRate = output_Fs; // Q0
     925         358 :     move32();
     926         358 :     HrFiltSet_p->FiltLength = HrFiltSet_p->ModelParams.K; // Q0
     927         358 :     move16();
     928             : 
     929         358 :     IF( NE_32( ( error = BSplineModelEvalAlloc_fx( &HrFiltSet_p->ModelParams, &HrFiltSet_p->ModelEval ) ), IVAS_ERR_OK ) )
     930             :     {
     931           0 :         return error;
     932             :     }
     933             : 
     934         358 :     return IVAS_ERR_OK;
     935             : }

Generated by: LCOV version 1.14