LCOV - code coverage report
Current view: top level - lib_rend - ivas_crend.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 680 844 80.6 %
Date: 2025-09-11 08:49:05 Functions: 14 17 82.4 %

          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.h"
      36             : #include "ivas_prot.h"
      37             : #include "ivas_prot_rend.h"
      38             : #include "ivas_cnst.h"
      39             : #include "ivas_rom_rend.h"
      40             : #include <math.h>
      41             : #include "ivas_rom_binaural_crend_head.h"
      42             : #include "ivas_stat_rend.h"
      43             : #include "lib_rend.h"
      44             : #ifdef DEBUGGING
      45             : #include "debug.h"
      46             : #endif
      47             : #include "wmc_auto.h"
      48             : 
      49             : 
      50             : /*-------------------------------------------------------------------------
      51             :  * ivas_Crend_hrtf_init()
      52             :  *
      53             :  * Initialize hHrtf handle
      54             :  *------------------------------------------------------------------------*/
      55             : 
      56        9278 : ivas_error ivas_Crend_hrtf_init(
      57             :     HRTFS_CREND_DATA *hHrtf /* i/o: HRTF handle     */
      58             : )
      59             : {
      60             :     int16_t i, j;
      61             : 
      62        9278 :     if ( hHrtf == NULL )
      63             :     {
      64           0 :         return IVAS_ERR_WRONG_PARAMS;
      65             :     }
      66             : 
      67        9278 :     hHrtf->latency_s = 0;
      68        9278 :     hHrtf->max_num_ir = 0;
      69        9278 :     hHrtf->max_num_iterations = 0;
      70        9278 :     hHrtf->gain_lfe = 0;
      71        9278 :     hHrtf->index_frequency_max_diffuse = 0;
      72        9278 :     hHrtf->same_inv_diffuse_weight = 1;
      73             : 
      74      157726 :     for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
      75             :     {
      76      445344 :         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
      77             :         {
      78      296896 :             hHrtf->inv_diffuse_weight[j][i] = 0;
      79      296896 :             hHrtf->num_iterations[i][j] = 0;
      80      296896 :             hHrtf->pIndex_frequency_max[i][j] = NULL;
      81      296896 :             hHrtf->pOut_to_bin_re[i][j] = NULL;
      82      296896 :             hHrtf->pOut_to_bin_im[i][j] = NULL;
      83             :         }
      84             :     }
      85             : 
      86       27834 :     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
      87             :     {
      88       18556 :         hHrtf->num_iterations_diffuse[j] = 0;
      89       18556 :         hHrtf->pIndex_frequency_max_diffuse[j] = NULL;
      90       18556 :         hHrtf->pOut_to_bin_diffuse_re[j] = NULL;
      91       18556 :         hHrtf->pOut_to_bin_diffuse_im[j] = NULL;
      92             :     }
      93             : 
      94        9278 :     hHrtf->init_from_rom = 1;
      95             : 
      96        9278 :     return IVAS_ERR_OK;
      97             : }
      98             : 
      99             : 
     100             : /*-------------------------------------------------------------------------
     101             :  * ivas_hrtf_open()
     102             :  *
     103             :  * Open hHrtf handle for Crend renderer
     104             :  *------------------------------------------------------------------------*/
     105             : 
     106        7956 : static ivas_error ivas_hrtf_open(
     107             :     HRTFS_HANDLE *hHrtf_out /* o  : HRTF handle     */
     108             : )
     109             : {
     110             :     HRTFS_HANDLE hHrtf;
     111             :     ivas_error error;
     112             : 
     113        7956 :     if ( *hHrtf_out == NULL )
     114             :     {
     115        7956 :         if ( ( hHrtf = (HRTFS_HANDLE) malloc( sizeof( HRTFS_DATA ) ) ) == NULL )
     116             :         {
     117           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend HRTFS Handle\n" );
     118             :         }
     119             : 
     120        7956 :         if ( ( error = ivas_Crend_hrtf_init( hHrtf ) ) != IVAS_ERR_OK )
     121             :         {
     122           0 :             return error;
     123             :         }
     124             : 
     125        7956 :         *hHrtf_out = hHrtf;
     126             :     }
     127             :     else
     128             :     {
     129           0 :         return IVAS_ERR_INTERNAL;
     130             :     }
     131             : 
     132        7956 :     return IVAS_ERR_OK;
     133             : }
     134             : 
     135             : 
     136             : /*-------------------------------------------------------------------------
     137             :  * ivas_hrtf_close()
     138             :  *
     139             :  * Close hHrtf handle
     140             :  *------------------------------------------------------------------------*/
     141             : 
     142        7956 : static void ivas_hrtf_close(
     143             :     HRTFS_HANDLE *hHrtf /* i/o: HRTF handle         */
     144             : )
     145             : {
     146        7956 :     if ( hHrtf == NULL || *hHrtf == NULL )
     147             :     {
     148           0 :         return;
     149             :     }
     150             : 
     151        7956 :     free( *hHrtf );
     152        7956 :     *hHrtf = NULL;
     153             : 
     154        7956 :     return;
     155             : }
     156             : 
     157             : 
     158             : /*-------------------------------------------------------------------------
     159             :  * ivas_rend_initCrend()
     160             :  *
     161             :  * Allocate and initialize crend renderer handle
     162             :  *------------------------------------------------------------------------*/
     163             : 
     164        9278 : static ivas_error ivas_rend_initCrend(
     165             :     CREND_WRAPPER *pCrend,
     166             :     const AUDIO_CONFIG inConfig,
     167             :     const AUDIO_CONFIG outConfig,
     168             :     HRTFS_CREND_HANDLE hHrtfCrend,
     169             :     const int16_t ext_rend_flag,
     170             :     const int32_t output_Fs )
     171             : {
     172             :     int16_t i, j, tmp, tmp2;
     173             :     int16_t nchan_in;
     174             :     IVAS_REND_AudioConfigType inConfigType;
     175             :     HRTFS_HANDLE hHrtf;
     176             :     ivas_error error;
     177             : 
     178        9278 :     inConfigType = getAudioConfigType( inConfig );
     179        9278 :     hHrtf = pCrend->hHrtfCrend;
     180             : 
     181             :     /* Do all error checks up front so that the nested if later is easier */
     182        9278 :     if ( inConfigType != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED && inConfigType != IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS )
     183             :     {
     184           0 :         return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Encountered unsupported input config in Crend" );
     185             :     }
     186             : 
     187        9278 :     if ( outConfig != IVAS_AUDIO_CONFIG_BINAURAL && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED && outConfig != IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     188             :     {
     189           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Encountered unsupported output type in Crend" );
     190             :     }
     191             : 
     192        9278 :     if ( hHrtf == NULL )
     193             :     {
     194        9278 :         if ( hHrtfCrend != NULL && ext_rend_flag == 0 )
     195             :         {
     196             :             /* HRTF set loaded from binary file */
     197        1322 :             hHrtf = hHrtfCrend;
     198        1322 :             hHrtf->init_from_rom = 0;
     199             :         }
     200             :         else
     201             :         {
     202             :             /* create new handle when HRTF is loaded from ROM, or external renderer is used */
     203        7956 :             if ( ( error = ivas_hrtf_open( &hHrtf ) ) != IVAS_ERR_OK )
     204             :             {
     205           0 :                 return error;
     206             :             }
     207             : 
     208        7956 :             hHrtf->init_from_rom = 1;
     209        7956 :             if ( hHrtfCrend != NULL )
     210             :             {
     211           0 :                 hHrtf->init_from_rom = 0;
     212             :             }
     213             :         }
     214             :     }
     215             : 
     216        9278 :     if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK )
     217             :     {
     218           0 :         return error;
     219             :     }
     220        9278 :     hHrtf->max_num_ir = nchan_in;
     221             : 
     222        9278 :     if ( hHrtf->max_num_ir <= 0 )
     223             :     {
     224           0 :         return IVAS_ERR_INTERNAL_FATAL;
     225             :     }
     226             : 
     227        9278 :     if ( hHrtf->init_from_rom )
     228             :     {
     229        7956 :         if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
     230             :         {
     231        7044 :             hHrtf->max_num_ir -= 1; /* subtract LFE */
     232        7044 :             hHrtf->gain_lfe = GAIN_LFE;
     233             : 
     234        7044 :             if ( output_Fs == 48000 )
     235             :             {
     236        2941 :                 if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     237             :                 {
     238        2387 :                     hHrtf->latency_s = CRendBin_Combined_BRIR_latency_s;
     239        2387 :                     hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_48kHz;
     240        2387 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz;
     241             :                 }
     242             :                 else
     243             :                 {
     244         554 :                     hHrtf->latency_s = CRendBin_Combined_HRIR_latency_s;
     245         554 :                     hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_48kHz;
     246         554 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz;
     247             :                 }
     248             : 
     249        8823 :                 for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     250             :                 {
     251        5882 :                     if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     252             :                     {
     253        4774 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[j];
     254        4774 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[j];
     255        4774 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz[j];
     256        4774 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz[j];
     257             :                     }
     258             :                     else
     259             :                     {
     260        1108 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[j];
     261        1108 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     262        1108 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz[j];
     263        1108 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz[j];
     264             :                     }
     265             :                 }
     266             :             }
     267        4103 :             else if ( output_Fs == 32000 )
     268             :             {
     269        1932 :                 if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     270             :                 {
     271        1712 :                     hHrtf->latency_s = CRendBin_Combined_BRIR_latency_s;
     272        1712 :                     hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_32kHz;
     273        1712 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz;
     274             :                 }
     275             :                 else
     276             :                 {
     277         220 :                     hHrtf->latency_s = CRendBin_Combined_HRIR_latency_s;
     278         220 :                     hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_32kHz;
     279         220 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz;
     280             :                 }
     281             : 
     282        5796 :                 for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     283             :                 {
     284        3864 :                     if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     285             :                     {
     286        3424 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[j];
     287        3424 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[j];
     288        3424 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz[j];
     289        3424 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz[j];
     290             :                     }
     291             :                     else
     292             :                     {
     293         440 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[j];
     294         440 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
     295         440 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz[j];
     296         440 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz[j];
     297             :                     }
     298             :                 }
     299             :             }
     300        2171 :             else if ( output_Fs == 16000 )
     301             :             {
     302        2171 :                 if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     303             :                 {
     304        1279 :                     hHrtf->latency_s = CRendBin_Combined_BRIR_latency_s;
     305             : 
     306        1279 :                     hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_16kHz;
     307        1279 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_16kHz;
     308             :                 }
     309             :                 else
     310             :                 {
     311         892 :                     hHrtf->latency_s = CRendBin_Combined_HRIR_latency_s;
     312         892 :                     hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_16kHz;
     313         892 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_16kHz;
     314             :                 }
     315             : 
     316        6513 :                 for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     317             :                 {
     318        4342 :                     if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     319             :                     {
     320        2558 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_16kHz[j];
     321        2558 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[j];
     322        2558 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz[j];
     323        2558 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz[j];
     324             :                     }
     325             :                     else
     326             :                     {
     327        1784 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_16kHz[j];
     328        1784 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     329        1784 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz[j];
     330        1784 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz[j];
     331             :                     }
     332             :                 }
     333             :             }
     334             :             else
     335             :             {
     336           0 :                 return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     337             :             }
     338             : 
     339       70644 :             for ( i = 0; i < hHrtf->max_num_ir; i++ )
     340             :             {
     341       63600 :                 if ( inConfig == IVAS_AUDIO_CONFIG_5_1 )
     342             :                 {
     343        9260 :                     tmp = channelIndex_CICP6[i];
     344             :                 }
     345       54340 :                 else if ( inConfig == IVAS_AUDIO_CONFIG_7_1 )
     346             :                 {
     347        1246 :                     tmp = channelIndex_CICP12[i];
     348             :                 }
     349       53094 :                 else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_2 )
     350             :                 {
     351        2947 :                     tmp = channelIndex_CICP14[i];
     352             :                 }
     353       50147 :                 else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_4 )
     354             :                 {
     355        1692 :                     tmp = channelIndex_CICP16[i];
     356             :                 }
     357       48455 :                 else if ( inConfig == IVAS_AUDIO_CONFIG_7_1_4 )
     358             :                 {
     359       48455 :                     tmp = channelIndex_CICP19[i];
     360             :                 }
     361             :                 else
     362             :                 {
     363           0 :                     return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Channel configuration not specified!\n\n" );
     364             :                 }
     365             : 
     366       63600 :                 if ( output_Fs == 48000 )
     367             :                 {
     368       76149 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     369             :                     {
     370       50766 :                         if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     371             :                         {
     372       43538 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz[j][tmp];
     373       43538 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_48kHz[tmp][j];
     374       43538 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_48kHz[tmp][j];
     375       43538 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_BRIR_coeff_re_48kHz[tmp][j];
     376       43538 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_BRIR_coeff_im_48kHz[tmp][j];
     377             :                         }
     378             :                         else
     379             :                         {
     380        7228 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz[j][tmp];
     381        7228 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_48kHz[tmp][j];
     382        7228 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_48kHz[tmp][j];
     383        7228 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_HRIR_coeff_re_48kHz[tmp][j];
     384        7228 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_HRIR_coeff_im_48kHz[tmp][j];
     385             :                         }
     386             :                     }
     387             :                 }
     388       38217 :                 else if ( output_Fs == 32000 )
     389             :                 {
     390       60756 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     391             :                     {
     392       40504 :                         if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     393             :                         {
     394       36944 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz[j][tmp];
     395       36944 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_32kHz[tmp][j];
     396       36944 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_32kHz[tmp][j];
     397       36944 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_BRIR_coeff_re_32kHz[tmp][j];
     398       36944 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_BRIR_coeff_im_32kHz[tmp][j];
     399             :                         }
     400             :                         else
     401             :                         {
     402        3560 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz[j][tmp];
     403        3560 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_32kHz[tmp][j];
     404        3560 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_32kHz[tmp][j];
     405        3560 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_HRIR_coeff_re_32kHz[tmp][j];
     406        3560 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_HRIR_coeff_im_32kHz[tmp][j];
     407             :                         }
     408             :                     }
     409             :                 }
     410       17965 :                 else if ( output_Fs == 16000 )
     411             :                 {
     412       53895 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     413             :                     {
     414       35930 :                         if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     415             :                         {
     416       25650 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz[j][tmp];
     417       25650 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_16kHz[tmp][j];
     418       25650 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_16kHz[tmp][j];
     419       25650 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_BRIR_coeff_re_16kHz[tmp][j];
     420       25650 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_BRIR_coeff_im_16kHz[tmp][j];
     421             :                         }
     422             :                         else
     423             :                         {
     424       10280 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz[j][tmp];
     425       10280 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_16kHz[tmp][j];
     426       10280 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_16kHz[tmp][j];
     427       10280 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_Combined_HRIR_coeff_re_16kHz[tmp][j];
     428       10280 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_Combined_HRIR_coeff_im_16kHz[tmp][j];
     429             :                         }
     430             :                     }
     431             :                 }
     432             :                 else
     433             :                 {
     434           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     435             :                 }
     436             :             }
     437             :         }
     438         912 :         else if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS )
     439             :         {
     440         912 :             if ( inConfig == IVAS_AUDIO_CONFIG_HOA3 )
     441             :             {
     442         432 :                 if ( output_Fs == 48000 )
     443             :                 {
     444         272 :                     hHrtf->latency_s = CRendBin_HOA3_HRIR_latency_s;
     445         272 :                     hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_48kHz;
     446         272 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_48kHz;
     447             : 
     448        4624 :                     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     449             :                     {
     450       13056 :                         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     451             :                         {
     452        8704 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz[j][i];
     453        8704 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_48kHz[i][j];
     454        8704 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_48kHz[i][j];
     455        8704 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA3_HRIR_coeff_re_48kHz[i][j];
     456        8704 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA3_HRIR_coeff_im_48kHz[i][j];
     457             :                         }
     458             :                     }
     459         816 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     460             :                     {
     461         544 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_48kHz[j];
     462         544 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     463         544 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz[j];
     464         544 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz[j];
     465             :                     }
     466             :                 }
     467         160 :                 else if ( output_Fs == 32000 )
     468             :                 {
     469          80 :                     hHrtf->latency_s = CRendBin_HOA3_HRIR_latency_s;
     470          80 :                     hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_32kHz;
     471          80 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_32kHz;
     472             : 
     473        1360 :                     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     474             :                     {
     475        3840 :                         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     476             :                         {
     477        2560 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz[j][i];
     478        2560 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_32kHz[i][j];
     479        2560 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_32kHz[i][j];
     480        2560 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA3_HRIR_coeff_re_32kHz[i][j];
     481        2560 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA3_HRIR_coeff_im_32kHz[i][j];
     482             :                         }
     483             :                     }
     484             : 
     485         240 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     486             :                     {
     487         160 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_32kHz[j];
     488         160 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
     489         160 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz[j];
     490         160 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz[j];
     491             :                     }
     492             :                 }
     493          80 :                 else if ( output_Fs == 16000 )
     494             :                 {
     495          80 :                     hHrtf->latency_s = CRendBin_HOA3_HRIR_latency_s;
     496          80 :                     hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_16kHz;
     497          80 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_16kHz;
     498             : 
     499        1360 :                     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     500             :                     {
     501        3840 :                         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     502             :                         {
     503        2560 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz[j][i];
     504        2560 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_16kHz[i][j];
     505        2560 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_16kHz[i][j];
     506        2560 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA3_HRIR_coeff_re_16kHz[i][j];
     507        2560 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA3_HRIR_coeff_im_16kHz[i][j];
     508             :                         }
     509             :                     }
     510             : 
     511         240 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     512             :                     {
     513         160 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_16kHz[j];
     514         160 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     515         160 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz[j];
     516         160 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz[j];
     517             :                     }
     518             :                 }
     519             :                 else
     520             :                 {
     521           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     522             :                 }
     523             :             }
     524         480 :             else if ( inConfig == IVAS_AUDIO_CONFIG_HOA2 )
     525             :             {
     526         240 :                 if ( output_Fs == 48000 )
     527             :                 {
     528          80 :                     hHrtf->latency_s = CRendBin_HOA2_HRIR_latency_s;
     529          80 :                     hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_48kHz;
     530          80 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_48kHz;
     531             : 
     532         800 :                     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     533             :                     {
     534        2160 :                         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     535             :                         {
     536        1440 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz[j][i];
     537        1440 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_48kHz[i][j];
     538        1440 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_48kHz[i][j];
     539        1440 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA2_HRIR_coeff_re_48kHz[i][j];
     540        1440 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA2_HRIR_coeff_im_48kHz[i][j];
     541             :                         }
     542             :                     }
     543         240 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     544             :                     {
     545         160 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_48kHz[j];
     546         160 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     547         160 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz[j];
     548         160 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz[j];
     549             :                     }
     550             :                 }
     551         160 :                 else if ( output_Fs == 32000 )
     552             :                 {
     553          80 :                     hHrtf->latency_s = CRendBin_HOA2_HRIR_latency_s;
     554          80 :                     hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_32kHz;
     555          80 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_32kHz;
     556             : 
     557         800 :                     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     558             :                     {
     559        2160 :                         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     560             :                         {
     561        1440 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz[j][i];
     562        1440 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_32kHz[i][j];
     563        1440 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_32kHz[i][j];
     564        1440 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA2_HRIR_coeff_re_32kHz[i][j];
     565        1440 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA2_HRIR_coeff_im_32kHz[i][j];
     566             :                         }
     567             :                     }
     568             : 
     569         240 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     570             :                     {
     571         160 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_32kHz[j];
     572         160 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
     573         160 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz[j];
     574         160 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz[j];
     575             :                     }
     576             :                 }
     577          80 :                 else if ( output_Fs == 16000 )
     578             :                 {
     579          80 :                     hHrtf->latency_s = CRendBin_HOA2_HRIR_latency_s;
     580          80 :                     hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_16kHz;
     581          80 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_16kHz;
     582             : 
     583         800 :                     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     584             :                     {
     585        2160 :                         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     586             :                         {
     587        1440 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz[j][i];
     588        1440 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_16kHz[i][j];
     589        1440 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_16kHz[i][j];
     590        1440 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_HOA2_HRIR_coeff_re_16kHz[i][j];
     591        1440 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_HOA2_HRIR_coeff_im_16kHz[i][j];
     592             :                         }
     593             :                     }
     594             : 
     595         240 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     596             :                     {
     597         160 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_16kHz[j];
     598         160 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     599         160 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz[j];
     600         160 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz[j];
     601             :                     }
     602             :                 }
     603             :                 else
     604             :                 {
     605           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     606             :                 }
     607             :             }
     608         240 :             else if ( inConfig == IVAS_AUDIO_CONFIG_FOA )
     609             :             {
     610         240 :                 if ( output_Fs == 48000 )
     611             :                 {
     612          80 :                     hHrtf->latency_s = CRendBin_FOA_HRIR_latency_s;
     613          80 :                     hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_48kHz;
     614          80 :                     hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_48kHz;
     615             : 
     616         400 :                     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     617             :                     {
     618         960 :                         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     619             :                         {
     620         640 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz[j][i];
     621         640 :                             hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_48kHz[i][j];
     622         640 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_48kHz[i][j];
     623         640 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_FOA_HRIR_coeff_re_48kHz[i][j];
     624         640 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_FOA_HRIR_coeff_im_48kHz[i][j];
     625             :                         }
     626             :                     }
     627         240 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     628             :                     {
     629         160 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_48kHz[j];
     630         160 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     631         160 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz[j];
     632         160 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz[j];
     633             :                     }
     634             :                 }
     635         160 :                 else if ( output_Fs == 32000 )
     636             :                 {
     637          80 :                     hHrtf->latency_s = CRendBin_FOA_HRIR_latency_s;
     638          80 :                     hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_32kHz;
     639          80 :                     hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_32kHz;
     640             : 
     641         400 :                     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     642             :                     {
     643         960 :                         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     644             :                         {
     645         640 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz[j][i];
     646         640 :                             hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_32kHz[i][j];
     647         640 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_32kHz[i][j];
     648         640 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_FOA_HRIR_coeff_re_32kHz[i][j];
     649         640 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_FOA_HRIR_coeff_im_32kHz[i][j];
     650             :                         }
     651             :                     }
     652             : 
     653         240 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     654             :                     {
     655         160 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_32kHz[j];
     656         160 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
     657         160 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz[j];
     658         160 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz[j];
     659             :                     }
     660             :                 }
     661          80 :                 else if ( output_Fs == 16000 )
     662             :                 {
     663          80 :                     hHrtf->latency_s = CRendBin_FOA_HRIR_latency_s;
     664          80 :                     hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_16kHz;
     665          80 :                     hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_16kHz;
     666             : 
     667         400 :                     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     668             :                     {
     669         960 :                         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     670             :                         {
     671         640 :                             hHrtf->inv_diffuse_weight[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz[j][i];
     672         640 :                             hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_16kHz[i][j];
     673         640 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_16kHz[i][j];
     674         640 :                             hHrtf->pOut_to_bin_re[i][j] = CRendBin_FOA_HRIR_coeff_re_16kHz[i][j];
     675         640 :                             hHrtf->pOut_to_bin_im[i][j] = CRendBin_FOA_HRIR_coeff_im_16kHz[i][j];
     676             :                         }
     677             :                     }
     678             : 
     679         240 :                     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     680             :                     {
     681         160 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_16kHz[j];
     682         160 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     683         160 :                         hHrtf->pOut_to_bin_diffuse_re[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz[j];
     684         160 :                         hHrtf->pOut_to_bin_diffuse_im[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz[j];
     685             :                     }
     686             :                 }
     687             :                 else
     688             :                 {
     689           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     690             :                 }
     691             :             }
     692             :             else
     693             :             {
     694           0 :                 return IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "Encountered unsupported input config in Crend" );
     695             :             }
     696             :         }
     697             :         else
     698             :         {
     699           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL, "Unsupported renderer type in Crend" );
     700             :         }
     701             :     }
     702             :     else
     703             :     {
     704        1322 :         if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
     705             :         {
     706        1322 :             hHrtf->max_num_ir -= 1; /* subtract LFE */
     707        1322 :             hHrtf->gain_lfe = GAIN_LFE;
     708             :         }
     709             : 
     710        1322 :         if ( ext_rend_flag == 1 )
     711             :         {
     712           0 :             if ( hHrtfCrend == NULL )
     713             :             {
     714           0 :                 return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Invalid function parameters " );
     715             :             }
     716           0 :             hHrtf->latency_s = hHrtfCrend->latency_s;
     717           0 :             hHrtf->max_num_iterations = hHrtfCrend->max_num_iterations;
     718           0 :             hHrtf->index_frequency_max_diffuse = hHrtfCrend->index_frequency_max_diffuse;
     719             : 
     720           0 :             for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     721             :             {
     722           0 :                 hHrtf->num_iterations_diffuse[j] = hHrtfCrend->num_iterations_diffuse[j];
     723           0 :                 hHrtf->pIndex_frequency_max_diffuse[j] = hHrtfCrend->pIndex_frequency_max_diffuse[j];
     724           0 :                 hHrtf->pOut_to_bin_diffuse_re[j] = hHrtfCrend->pOut_to_bin_diffuse_re[j];
     725           0 :                 hHrtf->pOut_to_bin_diffuse_im[j] = hHrtfCrend->pOut_to_bin_diffuse_im[j];
     726             :             }
     727             :         }
     728             : 
     729        1322 :         if ( inConfig == IVAS_AUDIO_CONFIG_7_1 && ext_rend_flag == 0 )
     730             :         {
     731             :             /* hack to enable pointers swapping - needed when indexes of 'channelIndex_CICPx[]' are not in increasing order */
     732         189 :             for ( i = 5; i < hHrtf->max_num_ir; i++ )
     733             :             {
     734         126 :                 tmp = channelIndex_CICP12[i];
     735         126 :                 tmp2 = channelIndex_CICP14[i];
     736             : 
     737         378 :                 for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     738             :                 {
     739         252 :                     hHrtf->inv_diffuse_weight[j][tmp2] = hHrtfCrend->inv_diffuse_weight[j][tmp];
     740         252 :                     hHrtf->num_iterations[tmp2][j] = hHrtfCrend->num_iterations[tmp][j];
     741         252 :                     hHrtf->pIndex_frequency_max[tmp2][j] = hHrtfCrend->pIndex_frequency_max[tmp][j];
     742         252 :                     hHrtf->pOut_to_bin_re[tmp2][j] = hHrtfCrend->pOut_to_bin_re[tmp][j];
     743         252 :                     hHrtf->pOut_to_bin_im[tmp2][j] = hHrtfCrend->pOut_to_bin_im[tmp][j];
     744             :                 }
     745             :             }
     746             :         }
     747             : 
     748       14804 :         for ( i = 0; i < hHrtf->max_num_ir; i++ )
     749             :         {
     750       13482 :             if ( inConfig == IVAS_AUDIO_CONFIG_5_1 )
     751             :             {
     752         360 :                 tmp = channelIndex_CICP6[i];
     753             :             }
     754       13122 :             else if ( inConfig == IVAS_AUDIO_CONFIG_7_1 )
     755             :             {
     756         441 :                 if ( ext_rend_flag == 0 )
     757             :                 {
     758         441 :                     tmp = channelIndex_CICP14[i];
     759             :                 }
     760             :                 else
     761             :                 {
     762           0 :                     tmp = channelIndex_CICP12[i];
     763             :                 }
     764             :             }
     765       12681 :             else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_2 )
     766             :             {
     767         441 :                 tmp = channelIndex_CICP14[i];
     768             :             }
     769       12240 :             else if ( inConfig == IVAS_AUDIO_CONFIG_5_1_4 )
     770             :             {
     771         558 :                 tmp = channelIndex_CICP16[i];
     772             :             }
     773       11682 :             else if ( inConfig == IVAS_AUDIO_CONFIG_7_1_4 )
     774             :             {
     775       11682 :                 tmp = channelIndex_CICP19[i];
     776             :             }
     777           0 :             else if ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS )
     778             :             {
     779           0 :                 tmp = i;
     780             :             }
     781             :             else
     782             :             {
     783           0 :                 return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Channel configuration not specified!\n\n" );
     784             :             }
     785             : 
     786       40446 :             for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     787             :             {
     788       26964 :                 hHrtf->inv_diffuse_weight[j][i] = hHrtfCrend->inv_diffuse_weight[j][tmp];
     789       26964 :                 hHrtf->num_iterations[i][j] = hHrtfCrend->num_iterations[tmp][j];
     790             : 
     791       26964 :                 if ( ext_rend_flag == 0 )
     792             :                 {
     793             :                     /* in case of HRTF handle reuse, swap the pointers for correct deallocation at the exit */
     794             : #define WMC_TOOL_SKIP
     795       26964 :                     swap( hHrtf->pIndex_frequency_max[i][j], hHrtf->pIndex_frequency_max[tmp][j], const uint16_t * );
     796             :                     MOVE( 3 );
     797       26964 :                     swap( hHrtf->pOut_to_bin_re[i][j], hHrtf->pOut_to_bin_re[tmp][j], const float * );
     798             :                     MOVE( 3 );
     799       26964 :                     swap( hHrtf->pOut_to_bin_im[i][j], hHrtf->pOut_to_bin_im[tmp][j], const float * );
     800             :                     MOVE( 3 );
     801             : #undef WMC_TOOL_SKIP
     802             :                 }
     803             :                 else
     804             :                 {
     805           0 :                     hHrtf->pIndex_frequency_max[i][j] = hHrtfCrend->pIndex_frequency_max[tmp][j];
     806           0 :                     hHrtf->pOut_to_bin_re[i][j] = hHrtfCrend->pOut_to_bin_re[tmp][j];
     807           0 :                     hHrtf->pOut_to_bin_im[i][j] = hHrtfCrend->pOut_to_bin_im[tmp][j];
     808             :                 }
     809             :             }
     810             :         }
     811             :     }
     812             : 
     813        9278 :     hHrtf->same_inv_diffuse_weight = 1;
     814       96392 :     for ( i = 0; i < hHrtf->max_num_ir; i++ )
     815             :     {
     816       87114 :         if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
     817             :         {
     818       61202 :             if ( hHrtf->inv_diffuse_weight[0][i] != hHrtf->inv_diffuse_weight[1][i] )
     819             :             {
     820           0 :                 hHrtf->same_inv_diffuse_weight = 0;
     821             :             }
     822             :         }
     823             :     }
     824             : 
     825        9278 :     pCrend->hHrtfCrend = hHrtf;
     826             : 
     827        9278 :     return IVAS_ERR_OK;
     828             : }
     829             : 
     830             : 
     831             : /*-------------------------------------------------------------------------
     832             :  * ivas_shoebox_data_init()
     833             :  *
     834             :  * Initialize shoebox_data_t handle
     835             :  *------------------------------------------------------------------------*/
     836             : 
     837          64 : static ivas_error ivas_shoebox_data_init(
     838             :     shoebox_data_t *hShoeboxData /* i/o: shoebox_data_t handle     */
     839             : )
     840             : {
     841             :     int16_t i;
     842             : 
     843          64 :     if ( hShoeboxData == NULL )
     844             :     {
     845           0 :         return IVAS_ERR_WRONG_PARAMS;
     846             :     }
     847             : 
     848        9664 :     for ( i = 0; i < 150; i++ )
     849             :     {
     850        9600 :         hShoeboxData->data[i] = 0.0f;
     851             :     }
     852         128 :     for ( i = 0; i < 1; i++ )
     853             :     {
     854          64 :         hShoeboxData->size[i] = 0;
     855             :     }
     856             : 
     857          64 :     return IVAS_ERR_OK;
     858             : }
     859             : 
     860             : 
     861             : /*-------------------------------------------------------------------------
     862             :  * ivas_shoebox_output_init()
     863             :  *
     864             :  * Initialize shoebox_output_t handle
     865             :  *------------------------------------------------------------------------*/
     866             : 
     867          16 : static ivas_error ivas_shoebox_output_init(
     868             :     shoebox_output_t *hShoeboxOutput /* i/o: shoebox_output_t handle     */
     869             : )
     870             : {
     871             :     ivas_error error;
     872             : 
     873          16 :     if ( hShoeboxOutput == NULL )
     874             :     {
     875           0 :         return IVAS_ERR_WRONG_PARAMS;
     876             :     }
     877             : 
     878          16 :     hShoeboxOutput->n_sources = 0;
     879          16 :     hShoeboxOutput->n_ref = 0;
     880             : 
     881          16 :     if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->times ) ) != IVAS_ERR_OK )
     882             :     {
     883           0 :         return error;
     884             :     }
     885             : 
     886          16 :     if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->gains ) ) != IVAS_ERR_OK )
     887             :     {
     888           0 :         return error;
     889             :     }
     890             : 
     891          16 :     if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->az_angle ) ) != IVAS_ERR_OK )
     892             :     {
     893           0 :         return error;
     894             :     }
     895             : 
     896          16 :     if ( ( error = ivas_shoebox_data_init( &hShoeboxOutput->el_angle ) ) != IVAS_ERR_OK )
     897             :     {
     898           0 :         return error;
     899             :     }
     900             : 
     901          16 :     return IVAS_ERR_OK;
     902             : }
     903             : 
     904             : 
     905             : /*-------------------------------------------------------------------------
     906             :  * ivas_shoebox_config_init()
     907             :  *
     908             :  * Initialize shoebox_config_t handle
     909             :  *------------------------------------------------------------------------*/
     910             : 
     911          16 : static ivas_error ivas_shoebox_config_init_params(
     912             :     shoebox_config_t *hShoeboxConfig /* i/o: shoebox_config_t handle     */
     913             : )
     914             : {
     915             :     int16_t i;
     916             : 
     917          16 :     if ( hShoeboxConfig == NULL )
     918             :     {
     919           0 :         return IVAS_ERR_WRONG_PARAMS;
     920             :     }
     921             : 
     922          16 :     hShoeboxConfig->room_L = 0.0f;
     923          16 :     hShoeboxConfig->room_W = 0.0f;
     924          16 :     hShoeboxConfig->room_H = 0.0f;
     925             : 
     926         112 :     for ( i = 0; i < IVAS_ROOM_ABS_COEFF; i++ )
     927             :     {
     928          96 :         hShoeboxConfig->abs_coeff[i] = 0.0f;
     929             :     }
     930          64 :     for ( i = 0; i < 3; i++ )
     931             :     {
     932          48 :         hShoeboxConfig->list_orig[i] = 0.0f;
     933             :     }
     934             : 
     935          16 :     return IVAS_ERR_OK;
     936             : }
     937             : 
     938             : 
     939             : /*-------------------------------------------------------------------------
     940             :  * ivas_shoebox_obj_init()
     941             :  *
     942             :  * Initialize shoebox_obj_t handle
     943             :  *------------------------------------------------------------------------*/
     944             : 
     945          16 : static ivas_error ivas_shoebox_obj_init(
     946             :     shoebox_obj_t *hShoeboxObj /* i/o: shoebox_obj_t handle     */
     947             : )
     948             : {
     949             :     int16_t i;
     950             :     ivas_error error;
     951             : 
     952          16 :     if ( hShoeboxObj == NULL )
     953             :     {
     954           0 :         return IVAS_ERR_WRONG_PARAMS;
     955             :     }
     956             : 
     957          16 :     hShoeboxObj->isCartesian = 0;
     958          16 :     hShoeboxObj->isRelative = 0;
     959          16 :     hShoeboxObj->isZHeight = 0;
     960          16 :     hShoeboxObj->isRadians = 0;
     961          16 :     hShoeboxObj->MAX_SOURCES = 0;
     962          16 :     hShoeboxObj->max_bands = 0;
     963          16 :     hShoeboxObj->REF_ORDER = 0;
     964             : 
     965        1216 :     for ( i = 0; i < 75; i++ )
     966             :     {
     967        1200 :         hShoeboxObj->src_pos[i] = 0.0f;
     968             :     }
     969         416 :     for ( i = 0; i < 25; i++ )
     970             :     {
     971         400 :         hShoeboxObj->src_dist[i] = 0.0f;
     972             :     }
     973          64 :     for ( i = 0; i < 3; i++ )
     974             :     {
     975          48 :         hShoeboxObj->list_pos[i] = 0.0f;
     976             :     }
     977             : 
     978          16 :     hShoeboxObj->nSrc = 0;
     979          16 :     hShoeboxObj->radius = 0.0f;
     980          16 :     hShoeboxObj->min_wall_dist = 0.0f;
     981          16 :     hShoeboxObj->soundspeed = 0.0f;
     982          16 :     hShoeboxObj->air_coeff = 0.0f;
     983             : 
     984          16 :     if ( ( error = ivas_shoebox_config_init_params( &hShoeboxObj->cal ) ) != IVAS_ERR_OK )
     985             :     {
     986           0 :         return error;
     987             :     }
     988             : 
     989          16 :     return IVAS_ERR_OK;
     990             : }
     991             : 
     992             : 
     993             : /*-------------------------------------------------------------------------
     994             :  * ivas_er_init_handle()
     995             :  *
     996             :  * Initialize early reflections handle
     997             :  *------------------------------------------------------------------------*/
     998             : 
     999          16 : static ivas_error ivas_er_init_handle(
    1000             :     er_struct_t *reflections /* i/o: early reflections handle     */
    1001             : )
    1002             : {
    1003             :     int16_t i;
    1004             :     ivas_error error;
    1005             : 
    1006          16 :     if ( reflections == NULL )
    1007             :     {
    1008           0 :         return IVAS_ERR_WRONG_PARAMS;
    1009             :     }
    1010             : 
    1011          16 :     reflections->audio_config = IVAS_AUDIO_CONFIG_INVALID;
    1012          16 :     reflections->use_er = 0;
    1013          16 :     reflections->is_ready = 0;
    1014          16 :     reflections->circ_len = 0;
    1015          16 :     reflections->circ_insert = 0;
    1016          16 :     reflections->n_total_reflections = 0;
    1017          16 :     reflections->is_cartesian = 0;
    1018          16 :     reflections->is_relative = 0;
    1019          16 :     reflections->max_frame_size = 0;
    1020          16 :     reflections->output_Fs = 0.0f;
    1021             : 
    1022        1216 :     for ( i = 0; i < 75; i++ )
    1023             :     {
    1024        1200 :         reflections->source_positions[i] = 0.0f;
    1025             :     }
    1026          64 :     for ( i = 0; i < 3; i++ )
    1027             :     {
    1028          48 :         reflections->user_origin[i] = 0.0f;
    1029          48 :         if ( i == 2 )
    1030             :         {
    1031          16 :             reflections->user_origin[i] = ER_LIST_HEIGHT;
    1032             :         }
    1033             :     }
    1034             : 
    1035          16 :     reflections->circ_buffers = NULL;
    1036          16 :     reflections->closest_ch_idx = NULL;
    1037             : 
    1038          16 :     if ( ( error = ivas_shoebox_output_init( &reflections->shoebox_data ) ) != IVAS_ERR_OK )
    1039             :     {
    1040           0 :         return error;
    1041             :     }
    1042             : 
    1043          16 :     if ( ( error = ivas_shoebox_obj_init( &reflections->shoebox_lib ) ) != IVAS_ERR_OK )
    1044             :     {
    1045           0 :         return error;
    1046             :     }
    1047             : 
    1048          16 :     return IVAS_ERR_OK;
    1049             : }
    1050             : 
    1051             : 
    1052             : /*-------------------------------------------------------------------------
    1053             :  * ivas_rend_initCrendWrapper()
    1054             :  *
    1055             :  * Allocate and initialize crend renderer handle
    1056             :  *------------------------------------------------------------------------*/
    1057             : 
    1058        9278 : ivas_error ivas_rend_initCrendWrapper(
    1059             :     CREND_WRAPPER_HANDLE *pCrend,
    1060             :     const int16_t num_poses )
    1061             : {
    1062             :     int16_t i;
    1063             :     CREND_HANDLE hCrend;
    1064             :     int16_t pos_idx;
    1065             : 
    1066        9278 :     if ( pCrend == NULL )
    1067             :     {
    1068           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" );
    1069             :     }
    1070             : 
    1071        9278 :     if ( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL )
    1072             :     {
    1073           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" );
    1074             :     }
    1075             : 
    1076        9278 :     ( *pCrend )->binaural_latency_ns = 0;
    1077        9278 :     ( *pCrend )->hHrtfCrend = NULL;
    1078             : 
    1079       83502 :     for ( pos_idx = 0; pos_idx < MAX_HEAD_ROT_POSES; pos_idx++ )
    1080             :     {
    1081       74224 :         ( *pCrend )->hCrend[pos_idx] = NULL;
    1082             :     }
    1083             : 
    1084       18556 :     for ( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
    1085             :     {
    1086        9278 :         hCrend = NULL;
    1087        9278 :         if ( ( hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL )
    1088             :         {
    1089           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" );
    1090             :         }
    1091             : 
    1092        9278 :         hCrend->lfe_delay_line = NULL;
    1093             : 
    1094      157726 :         for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
    1095             :         {
    1096      148448 :             hCrend->freq_buffer_re[i] = NULL;
    1097      148448 :             hCrend->freq_buffer_im[i] = NULL;
    1098             :         }
    1099             : 
    1100       27834 :         for ( i = 0; i < BINAURAL_CHANNELS; i++ )
    1101             :         {
    1102       18556 :             hCrend->prev_out_buffer[i] = NULL;
    1103             :         }
    1104             : 
    1105        9278 :         hCrend->freq_buffer_re_diffuse[0] = NULL;
    1106        9278 :         hCrend->freq_buffer_re_diffuse[1] = NULL;
    1107        9278 :         hCrend->freq_buffer_im_diffuse[0] = NULL;
    1108        9278 :         hCrend->freq_buffer_im_diffuse[1] = NULL;
    1109        9278 :         hCrend->hReverb = NULL;
    1110        9278 :         hCrend->reflections = NULL;
    1111        9278 :         hCrend->delay_line_rw_index = 0;
    1112        9278 :         hCrend->diffuse_delay_line_rw_index = 0;
    1113        9278 :         hCrend->hTrack = NULL;
    1114        9278 :         hCrend->m_fYaw = 0;
    1115        9278 :         hCrend->m_fPitch = 0;
    1116        9278 :         hCrend->m_fRoll = 0;
    1117             : 
    1118        9278 :         ( *pCrend )->hCrend[pos_idx] = hCrend;
    1119             :     }
    1120             : 
    1121        9278 :     return IVAS_ERR_OK;
    1122             : }
    1123             : 
    1124             : 
    1125             : /*-------------------------------------------------------------------------
    1126             :  * ivas_rend_openMultiBinCrend()
    1127             :  *
    1128             :  * Allocate and initialize crend renderer handle
    1129             :  *------------------------------------------------------------------------*/
    1130             : 
    1131           0 : ivas_error ivas_rend_openMultiBinCrend(
    1132             :     CREND_WRAPPER_HANDLE *pCrend,
    1133             :     const AUDIO_CONFIG inConfig,
    1134             :     const AUDIO_CONFIG outConfig,
    1135             :     const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData,
    1136             :     const int32_t output_Fs )
    1137             : {
    1138           0 :     return ivas_rend_openCrend( pCrend, inConfig, outConfig, NULL /*hRendCfg*/, NULL, NULL /* hHrtfStatistics */, output_Fs, 0, pMultiBinPoseData->num_poses );
    1139             : }
    1140             : 
    1141             : 
    1142             : /*-------------------------------------------------------------------------
    1143             :  * ivas_rend_openCrend()
    1144             :  *
    1145             :  * Allocate and initialize crend renderer handle
    1146             :  *------------------------------------------------------------------------*/
    1147             : 
    1148        9278 : ivas_error ivas_rend_openCrend(
    1149             :     CREND_WRAPPER_HANDLE *pCrend,
    1150             :     const AUDIO_CONFIG inConfig,
    1151             :     const AUDIO_CONFIG outConfig,
    1152             :     RENDER_CONFIG_DATA *hRendCfg,
    1153             :     HRTFS_CREND_HANDLE hHrtfCrend,
    1154             :     HRTFS_STATISTICS_HANDLE hHrtfStatistics,
    1155             :     const int32_t output_Fs,
    1156             :     const int16_t ext_rend_flag,
    1157             :     const int16_t num_poses )
    1158             : {
    1159             :     int16_t i, subframe_length;
    1160             :     int32_t max_total_ir_len;
    1161             :     HRTFS_HANDLE hHrtf;
    1162             :     CREND_HANDLE hCrend;
    1163             :     ivas_error error;
    1164             :     int16_t pos_idx;
    1165             : 
    1166        9278 :     error = IVAS_ERR_OK;
    1167             : 
    1168        9278 :     if ( ( error = ivas_rend_initCrendWrapper( pCrend, num_poses ) ) != IVAS_ERR_OK )
    1169             :     {
    1170           0 :         return error;
    1171             :     }
    1172             : 
    1173        9278 :     subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES;
    1174             : 
    1175        9278 :     if ( ( *pCrend )->hHrtfCrend == NULL )
    1176             :     {
    1177        9278 :         if ( ( error = ivas_rend_initCrend( *pCrend, inConfig, outConfig, hHrtfCrend, ext_rend_flag, output_Fs ) ) != IVAS_ERR_OK )
    1178             :         {
    1179           0 :             return error;
    1180             :         }
    1181             :     }
    1182             : 
    1183       18556 :     for ( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
    1184             :     {
    1185        9278 :         hCrend = ( *pCrend )->hCrend[pos_idx];
    1186        9278 :         hHrtf = ( *pCrend )->hHrtfCrend;
    1187             : 
    1188        9278 :         if ( hHrtf != NULL )
    1189             :         {
    1190        9278 :             max_total_ir_len = hHrtf->max_num_iterations * subframe_length;
    1191             : 
    1192       96392 :             for ( i = 0; i < hHrtf->max_num_ir; i++ )
    1193             :             {
    1194       87114 :                 if ( ( hCrend->freq_buffer_re[i] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
    1195             :                 {
    1196           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1197             :                 }
    1198       87114 :                 set_zero_l( hCrend->freq_buffer_re[i], max_total_ir_len );
    1199             : 
    1200       87114 :                 if ( ( hCrend->freq_buffer_im[i] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
    1201             :                 {
    1202           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1203             :                 }
    1204       87114 :                 set_zero_l( hCrend->freq_buffer_im[i], max_total_ir_len );
    1205             :             }
    1206             : 
    1207       27834 :             for ( i = 0; i < BINAURAL_CHANNELS; i++ )
    1208             :             {
    1209       18556 :                 if ( ( hCrend->prev_out_buffer[i] = (float *) malloc( sizeof( float ) * subframe_length ) ) == NULL )
    1210             :                 {
    1211           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1212             :                 }
    1213       18556 :                 set_zero_l( hCrend->prev_out_buffer[i], subframe_length );
    1214             :             }
    1215             : 
    1216        9278 :             max_total_ir_len = hHrtf->num_iterations_diffuse[0] * subframe_length;
    1217             : 
    1218        9278 :             if ( max_total_ir_len > 0 )
    1219             :             {
    1220        6150 :                 if ( ( hCrend->freq_buffer_re_diffuse[0] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
    1221             :                 {
    1222           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1223             :                 }
    1224        6150 :                 if ( hHrtf->same_inv_diffuse_weight == 0 )
    1225             :                 {
    1226           0 :                     if ( ( hCrend->freq_buffer_re_diffuse[1] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
    1227             :                     {
    1228           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1229             :                     }
    1230             :                 }
    1231             :                 else
    1232             :                 {
    1233        6150 :                     hCrend->freq_buffer_re_diffuse[1] = NULL;
    1234             :                 }
    1235        6150 :                 set_zero_l( hCrend->freq_buffer_re_diffuse[0], max_total_ir_len );
    1236        6150 :                 if ( hCrend->freq_buffer_re_diffuse[1] != NULL )
    1237             :                 {
    1238           0 :                     set_zero_l( hCrend->freq_buffer_re_diffuse[1], max_total_ir_len );
    1239             :                 }
    1240             : 
    1241        6150 :                 if ( ( hCrend->freq_buffer_im_diffuse[0] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
    1242             :                 {
    1243           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1244             :                 }
    1245        6150 :                 if ( hHrtf->same_inv_diffuse_weight == 0 )
    1246             :                 {
    1247           0 :                     if ( ( hCrend->freq_buffer_im_diffuse[1] = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
    1248             :                     {
    1249           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1250             :                     }
    1251             :                 }
    1252             :                 else
    1253             :                 {
    1254        6150 :                     hCrend->freq_buffer_im_diffuse[1] = NULL;
    1255             :                 }
    1256        6150 :                 set_zero_l( hCrend->freq_buffer_im_diffuse[0], max_total_ir_len );
    1257        6150 :                 if ( hCrend->freq_buffer_im_diffuse[1] != NULL )
    1258             :                 {
    1259           0 :                     set_zero_l( hCrend->freq_buffer_im_diffuse[1], max_total_ir_len );
    1260             :                 }
    1261             :             }
    1262             :             else
    1263             :             {
    1264        3128 :                 hCrend->freq_buffer_re_diffuse[0] = NULL;
    1265        3128 :                 hCrend->freq_buffer_im_diffuse[0] = NULL;
    1266        3128 :                 hCrend->freq_buffer_re_diffuse[1] = NULL;
    1267        3128 :                 hCrend->freq_buffer_im_diffuse[1] = NULL;
    1268             :             }
    1269             : 
    1270        9278 :             max_total_ir_len = (int16_t) ( hHrtf->latency_s * output_Fs + 0.5f ) + subframe_length;
    1271        9278 :             if ( max_total_ir_len > 0 )
    1272             :             {
    1273        9278 :                 if ( ( hCrend->lfe_delay_line = (float *) malloc( sizeof( float ) * max_total_ir_len ) ) == NULL )
    1274             :                 {
    1275           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1276             :                 }
    1277        9278 :                 set_zero_l( hCrend->lfe_delay_line, max_total_ir_len );
    1278             :             }
    1279             :             else
    1280             :             {
    1281           0 :                 hCrend->lfe_delay_line = NULL;
    1282             :             }
    1283             : 
    1284        9278 :             if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
    1285             :             {
    1286        1539 :                 if ( ( error = ivas_reverb_open( &( hCrend->hReverb ), hHrtfStatistics, hRendCfg, output_Fs ) ) != IVAS_ERR_OK )
    1287             :                 {
    1288           0 :                     return error;
    1289             :                 }
    1290             : 
    1291        1539 :                 if ( hRendCfg->roomAcoustics.use_er == 1 )
    1292             :                 {
    1293             : 
    1294             :                     /* Allocate memory for reflections */
    1295          16 :                     hCrend->reflections = (er_struct_t *) malloc( sizeof( er_struct_t ) );
    1296          16 :                     if ( !hCrend->reflections )
    1297             :                     {
    1298           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections" );
    1299             :                     }
    1300          16 :                     if ( ( error = ivas_er_init_handle( hCrend->reflections ) ) != IVAS_ERR_OK )
    1301             :                     {
    1302           0 :                         return error;
    1303             :                     }
    1304             : 
    1305          16 :                     hCrend->reflections->use_er = hRendCfg->roomAcoustics.use_er;
    1306          16 :                     hCrend->reflections->lowComplexity = hRendCfg->roomAcoustics.lowComplexity;
    1307             : 
    1308             :                     /* Set sample rate and frame size */
    1309          16 :                     hCrend->reflections->output_Fs = (float) output_Fs;
    1310          16 :                     hCrend->reflections->max_frame_size = (int16_t) ( output_Fs / FRAMES_PER_SEC );
    1311             : 
    1312             :                     /* Init Shoebox */
    1313          16 :                     ivas_shoebox_config_init( &hCrend->reflections->shoebox_lib.cal, hRendCfg );
    1314             : 
    1315             :                     /* Init and compute Reflections */
    1316          16 :                     if ( ( error = ivas_er_init( hCrend->reflections, inConfig ) ) != IVAS_ERR_OK )
    1317             :                     {
    1318           0 :                         return error;
    1319             :                     }
    1320             :                 }
    1321             :                 else
    1322             :                 {
    1323        1523 :                     hCrend->reflections = NULL;
    1324             :                 }
    1325             :             }
    1326             :             else
    1327             :             {
    1328        7739 :                 hCrend->hReverb = NULL;
    1329             :             }
    1330             : 
    1331        9278 :             ( *pCrend )->binaural_latency_ns = (int32_t) ( ( *pCrend )->hHrtfCrend->latency_s * 1000000000.f );
    1332             :         }
    1333             : 
    1334        9278 :         ( *pCrend )->hCrend[pos_idx] = hCrend;
    1335             :     }
    1336             : 
    1337        9278 :     return IVAS_ERR_OK;
    1338             : }
    1339             : 
    1340             : 
    1341             : /*-------------------------------------------------------------------------
    1342             :  * ivas_rend_closeCrend()
    1343             :  *
    1344             :  * Deallocate Crend renderer handle
    1345             :  *------------------------------------------------------------------------*/
    1346             : 
    1347      351281 : void ivas_rend_closeCrend(
    1348             :     CREND_WRAPPER_HANDLE *pCrend )
    1349             : {
    1350             :     int16_t i;
    1351             :     int16_t pos_idx;
    1352             :     CREND_HANDLE hCrend;
    1353             : 
    1354      351281 :     if ( pCrend == NULL || *pCrend == NULL )
    1355             :     {
    1356      342003 :         return;
    1357             :     }
    1358             : 
    1359        9278 :     if ( ( *pCrend )->hHrtfCrend != NULL && ( *pCrend )->hHrtfCrend->init_from_rom )
    1360             :     {
    1361        7956 :         ivas_hrtf_close( &( *pCrend )->hHrtfCrend );
    1362             :     }
    1363             : 
    1364       83502 :     for ( pos_idx = 0; pos_idx < MAX_HEAD_ROT_POSES; pos_idx++ )
    1365             :     {
    1366       74224 :         hCrend = ( *pCrend )->hCrend[pos_idx];
    1367       74224 :         if ( hCrend != NULL )
    1368             :         {
    1369      157726 :             for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
    1370             :             {
    1371      148448 :                 if ( hCrend->freq_buffer_re[i] != NULL )
    1372             :                 {
    1373       87114 :                     free( hCrend->freq_buffer_re[i] );
    1374       87114 :                     hCrend->freq_buffer_re[i] = NULL;
    1375             :                 }
    1376      148448 :                 if ( hCrend->freq_buffer_im[i] != NULL )
    1377             :                 {
    1378       87114 :                     free( hCrend->freq_buffer_im[i] );
    1379       87114 :                     hCrend->freq_buffer_im[i] = NULL;
    1380             :                 }
    1381             :             }
    1382             : 
    1383       27834 :             for ( i = 0; i < BINAURAL_CHANNELS; i++ )
    1384             :             {
    1385       18556 :                 if ( hCrend->prev_out_buffer[i] != NULL )
    1386             :                 {
    1387       18556 :                     free( hCrend->prev_out_buffer[i] );
    1388       18556 :                     hCrend->prev_out_buffer[i] = NULL;
    1389             :                 }
    1390             :             }
    1391             : 
    1392        9278 :             if ( hCrend->lfe_delay_line != NULL )
    1393             :             {
    1394        9278 :                 free( hCrend->lfe_delay_line );
    1395        9278 :                 hCrend->lfe_delay_line = NULL;
    1396             :             }
    1397        9278 :             if ( hCrend->freq_buffer_re_diffuse[0] != NULL )
    1398             :             {
    1399        6150 :                 free( hCrend->freq_buffer_re_diffuse[0] );
    1400        6150 :                 hCrend->freq_buffer_re_diffuse[0] = NULL;
    1401             :             }
    1402             : 
    1403        9278 :             if ( hCrend->freq_buffer_im_diffuse[0] != NULL )
    1404             :             {
    1405        6150 :                 free( hCrend->freq_buffer_im_diffuse[0] );
    1406        6150 :                 hCrend->freq_buffer_im_diffuse[0] = NULL;
    1407             :             }
    1408             : 
    1409        9278 :             if ( hCrend->freq_buffer_re_diffuse[1] != NULL )
    1410             :             {
    1411           0 :                 free( hCrend->freq_buffer_re_diffuse[1] );
    1412           0 :                 hCrend->freq_buffer_re_diffuse[1] = NULL;
    1413             :             }
    1414             : 
    1415        9278 :             if ( hCrend->freq_buffer_im_diffuse[1] != NULL )
    1416             :             {
    1417           0 :                 free( hCrend->freq_buffer_im_diffuse[1] );
    1418           0 :                 hCrend->freq_buffer_im_diffuse[1] = NULL;
    1419             :             }
    1420             : 
    1421        9278 :             if ( hCrend->hTrack != NULL )
    1422             :             {
    1423           0 :                 free( hCrend->hTrack );
    1424           0 :                 hCrend->hTrack = NULL;
    1425             :             }
    1426             : 
    1427        9278 :             ivas_reverb_close( &hCrend->hReverb );
    1428             : 
    1429        9278 :             if ( hCrend->reflections != NULL )
    1430             :             {
    1431          16 :                 if ( hCrend->reflections->closest_ch_idx != NULL )
    1432             :                 {
    1433          16 :                     free( hCrend->reflections->closest_ch_idx );
    1434          16 :                     hCrend->reflections->closest_ch_idx = NULL;
    1435             :                 }
    1436             : 
    1437          16 :                 if ( hCrend->reflections->circ_buffers != NULL )
    1438             :                 {
    1439          16 :                     free( hCrend->reflections->circ_buffers );
    1440          16 :                     hCrend->reflections->circ_buffers = NULL;
    1441             :                 }
    1442             : 
    1443          16 :                 free( hCrend->reflections );
    1444          16 :                 hCrend->reflections = NULL;
    1445             :             }
    1446             : 
    1447        9278 :             free( hCrend );
    1448        9278 :             hCrend = NULL;
    1449        9278 :             ( *pCrend )->hCrend[pos_idx] = hCrend;
    1450             :         }
    1451             :     }
    1452             : 
    1453        9278 :     free( *pCrend );
    1454        9278 :     *pCrend = NULL;
    1455             : 
    1456        9278 :     return;
    1457             : }
    1458             : 
    1459             : 
    1460             : /*-------------------------------------------------------------------------
    1461             :  * ivas_rend_closeCldfbRend()
    1462             :  *
    1463             :  * Close CLDFB based fastconv binaural renderer memories
    1464             :  *------------------------------------------------------------------------*/
    1465             : 
    1466           0 : void ivas_rend_closeCldfbRend(
    1467             :     CLDFB_REND_WRAPPER *pCldfbRend )
    1468             : {
    1469           0 :     if ( pCldfbRend->hCldfbRend->hInputSetup != NULL )
    1470             :     {
    1471           0 :         free( pCldfbRend->hCldfbRend->hInputSetup );
    1472           0 :         pCldfbRend->hCldfbRend->hInputSetup = NULL;
    1473             :     }
    1474             : 
    1475           0 :     ivas_binRenderer_close( &pCldfbRend->hCldfbRend );
    1476           0 :     ivas_binaural_hrtf_close( &pCldfbRend->hHrtfFastConv );
    1477           0 :     ivas_HRTF_fastconv_binary_close( &pCldfbRend->hHrtfFastConv );
    1478             : 
    1479           0 :     return;
    1480             : }
    1481             : 
    1482             : 
    1483             : /*-----------------------------------------------------------------------------------------*
    1484             :  * Function ivas_rend_crendConvolver()
    1485             :  *
    1486             :  * Convolver block
    1487             :  *-----------------------------------------------------------------------------------------*/
    1488             : 
    1489    11505629 : static ivas_error ivas_rend_crendConvolver(
    1490             :     const CREND_WRAPPER *pCrend,
    1491             :     AUDIO_CONFIG inConfig,
    1492             :     AUDIO_CONFIG outConfig,
    1493             :     float *pcm_in[],
    1494             :     float *pcm_out[],
    1495             :     const int32_t output_Fs,
    1496             :     const int16_t i_ts,
    1497             :     const int16_t pos_idx )
    1498             : {
    1499             :     int16_t i, j, k, m;
    1500             :     int16_t subframe_length, idx_in;
    1501             :     int16_t lfe_idx_in;
    1502             :     int32_t offset, offset_in, offset_diffuse;
    1503             :     int16_t nchan_in, nchan_out;
    1504             :     const float *pIn;
    1505             :     const float *pFreq_filt_re, *pFreq_filt_im;
    1506    11505629 :     float *pFreq_buf_re = NULL, *pFreq_buf_im = NULL;
    1507    11505629 :     float *pFreq_buf2_re = NULL, *pFreq_buf2_im = NULL;
    1508             :     float pOut[2 /*Re,Im*/ * L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    1509             :     float tmp_out_re[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES], tmp_out_im[L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    1510             :     CREND_HANDLE hCrend;
    1511             :     ivas_error error;
    1512             : 
    1513    11505629 :     hCrend = pCrend->hCrend[pos_idx];
    1514             : 
    1515    11505629 :     if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK )
    1516             :     {
    1517           0 :         return error;
    1518             :     }
    1519             : 
    1520    11505629 :     if ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK )
    1521             :     {
    1522           0 :         return error;
    1523             :     }
    1524             : 
    1525    11505629 :     subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES;
    1526             : 
    1527    11505629 :     lfe_idx_in = -1;
    1528    11505629 :     if ( getAudioConfigType( inConfig ) == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
    1529             :     {
    1530     8577147 :         if ( inConfig != IVAS_AUDIO_CONFIG_LS_CUSTOM )
    1531             :         {
    1532     8577147 :             lfe_idx_in = LFE_CHANNEL;
    1533             :         }
    1534             :         else
    1535             :         {
    1536           0 :             assert( 0 && "Custom LS not supported in CRend" );
    1537             :         }
    1538             :     }
    1539             : 
    1540    11505629 :     offset = hCrend->delay_line_rw_index * subframe_length;                 /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */
    1541    11505629 :     offset_diffuse = hCrend->diffuse_delay_line_rw_index * subframe_length; /* subframe_length *( pCrend->hHrtfCrend->num_iterations_diffuse[0] - 1 ); */
    1542             : 
    1543    11505629 :     if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    1544             :     {
    1545     7524663 :         set_zero( &hCrend->freq_buffer_re_diffuse[0][offset_diffuse], subframe_length );
    1546     7524663 :         set_zero( &hCrend->freq_buffer_im_diffuse[0][offset_diffuse], subframe_length );
    1547     7524663 :         if ( pCrend->hHrtfCrend->same_inv_diffuse_weight == 0 )
    1548             :         {
    1549           0 :             set_zero( &hCrend->freq_buffer_re_diffuse[1][offset_diffuse], subframe_length );
    1550           0 :             set_zero( &hCrend->freq_buffer_im_diffuse[1][offset_diffuse], subframe_length );
    1551             :         }
    1552             :     }
    1553             : 
    1554    11505629 :     if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    1555             :     {
    1556     7524663 :         if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
    1557             :         {
    1558     7524663 :             pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse];
    1559     7524663 :             pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse];
    1560             :         }
    1561             :         else
    1562             :         {
    1563           0 :             pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse];
    1564           0 :             pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse];
    1565           0 :             pFreq_buf2_re = &hCrend->freq_buffer_re_diffuse[1][offset_diffuse];
    1566           0 :             pFreq_buf2_im = &hCrend->freq_buffer_im_diffuse[1][offset_diffuse];
    1567             :         }
    1568             :     }
    1569             : 
    1570    11505629 :     i = 0;
    1571   137367785 :     for ( idx_in = 0; idx_in < nchan_in; idx_in++ )
    1572             :     {
    1573   125862156 :         pIn = &pcm_in[idx_in][i_ts * subframe_length];
    1574   125862156 :         if ( idx_in != lfe_idx_in )
    1575             :         {
    1576   117285009 :             if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    1577             :             {
    1578    80264501 :                 if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
    1579             :                 {
    1580    80264501 :                     pFreq_filt_re = &hCrend->freq_buffer_re[i][offset];
    1581    80264501 :                     pFreq_filt_im = &hCrend->freq_buffer_im[i][offset];
    1582             : 
    1583  7393427934 :                     for ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ )
    1584             :                     {
    1585  7313163433 :                         pFreq_buf_re[k] += pFreq_filt_re[k] * pCrend->hHrtfCrend->inv_diffuse_weight[0][i];
    1586  7313163433 :                         pFreq_buf_im[k] += pFreq_filt_im[k] * pCrend->hHrtfCrend->inv_diffuse_weight[0][i];
    1587             :                     }
    1588             :                 }
    1589             :                 else
    1590             :                 {
    1591           0 :                     pFreq_filt_re = &hCrend->freq_buffer_re[i][offset];
    1592           0 :                     pFreq_filt_im = &hCrend->freq_buffer_im[i][offset];
    1593             : 
    1594           0 :                     for ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ )
    1595             :                     {
    1596           0 :                         pFreq_buf_re[k] += pFreq_filt_re[k] * pCrend->hHrtfCrend->inv_diffuse_weight[0][i];
    1597           0 :                         pFreq_buf_im[k] += pFreq_filt_im[k] * pCrend->hHrtfCrend->inv_diffuse_weight[0][i];
    1598           0 :                         pFreq_buf2_re[k] += pFreq_filt_re[k] * pCrend->hHrtfCrend->inv_diffuse_weight[1][i];
    1599           0 :                         pFreq_buf2_im[k] += pFreq_filt_im[k] * pCrend->hHrtfCrend->inv_diffuse_weight[1][i];
    1600             :                     }
    1601             :                 }
    1602             :             }
    1603             : 
    1604   117285009 :             ivas_mdft( pIn, &hCrend->freq_buffer_re[i][offset], &hCrend->freq_buffer_im[i][offset], subframe_length, subframe_length );
    1605   117285009 :             i++;
    1606             :         }
    1607             :     }
    1608             : 
    1609    34516887 :     for ( j = 0; j < nchan_out; j++ )
    1610             :     {
    1611    23011258 :         set_zero( tmp_out_re, subframe_length );
    1612    23011258 :         set_zero( tmp_out_im, subframe_length );
    1613             : 
    1614    23011258 :         i = 0;
    1615   274735570 :         for ( idx_in = 0; idx_in < nchan_in; idx_in++ )
    1616             :         {
    1617   251724312 :             if ( idx_in != lfe_idx_in )
    1618             :             {
    1619   234570018 :                 offset = 0;
    1620  3890510966 :                 for ( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ )
    1621             :                 {
    1622  3655940948 :                     offset_in = ( hCrend->delay_line_rw_index + pCrend->hHrtfCrend->max_num_iterations - pCrend->hHrtfCrend->num_iterations[i][j] + m + 1 );
    1623  3655940948 :                     offset_in = offset_in % ( pCrend->hHrtfCrend->max_num_iterations );
    1624  3655940948 :                     offset_in = offset_in * subframe_length;
    1625  3655940948 :                     pFreq_buf_re = &hCrend->freq_buffer_re[i][offset_in];
    1626  3655940948 :                     pFreq_buf_im = &hCrend->freq_buffer_im[i][offset_in];
    1627  3655940948 :                     pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re[i][j][offset];
    1628  3655940948 :                     pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im[i][j][offset];
    1629             : 
    1630 >41790*10^7 :                     for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ )
    1631             :                     {
    1632 >41425*10^7 :                         tmp_out_re[k] += pFreq_buf_re[k] * pFreq_filt_re[k] - pFreq_buf_im[k] * pFreq_filt_im[k];
    1633 >41425*10^7 :                         tmp_out_im[k] += pFreq_buf_re[k] * pFreq_filt_im[k] + pFreq_buf_im[k] * pFreq_filt_re[k];
    1634             :                     }
    1635  3655940948 :                     offset = offset + k;
    1636             :                 }
    1637   234570018 :                 i++;
    1638             :             }
    1639             :         }
    1640             : 
    1641    23011258 :         offset = 0;
    1642   624984298 :         for ( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ )
    1643             :         {
    1644   601973040 :             offset_diffuse = ( hCrend->diffuse_delay_line_rw_index + m + 1 );
    1645   601973040 :             offset_diffuse = offset_diffuse % pCrend->hHrtfCrend->num_iterations_diffuse[0];
    1646   601973040 :             offset_diffuse = offset_diffuse * subframe_length;
    1647   601973040 :             if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
    1648             :             {
    1649   601973040 :                 pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[0][offset_diffuse];
    1650   601973040 :                 pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[0][offset_diffuse];
    1651             :             }
    1652             :             else
    1653             :             {
    1654           0 :                 pFreq_buf_re = &hCrend->freq_buffer_re_diffuse[j][offset_diffuse];
    1655           0 :                 pFreq_buf_im = &hCrend->freq_buffer_im_diffuse[j][offset_diffuse];
    1656             :             }
    1657   601973040 :             pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re[j][offset];
    1658   601973040 :             pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im[j][offset];
    1659             : 
    1660 42030550736 :             for ( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ )
    1661             :             {
    1662 41428577696 :                 tmp_out_re[k] += pFreq_buf_re[k] * pFreq_filt_re[k] - pFreq_buf_im[k] * pFreq_filt_im[k];
    1663 41428577696 :                 tmp_out_im[k] += pFreq_buf_re[k] * pFreq_filt_im[k] + pFreq_buf_im[k] * pFreq_filt_re[k];
    1664             :             }
    1665   601973040 :             offset = offset + k;
    1666             :         }
    1667             : 
    1668    23011258 :         ivas_imdft( tmp_out_re, tmp_out_im, pOut, subframe_length );
    1669             : 
    1670    23011258 :         pFreq_buf_re = &pcm_out[j][i_ts * subframe_length];
    1671  3876672698 :         for ( k = 0; k < subframe_length; k++ )
    1672             :         {
    1673  3853661440 :             pFreq_buf_re[k] = pOut[k] + hCrend->prev_out_buffer[j][k];
    1674  3853661440 :             hCrend->prev_out_buffer[j][k] = pOut[k + subframe_length];
    1675             :         }
    1676             :     }
    1677             : 
    1678    11505629 :     hCrend->delay_line_rw_index++;
    1679    11505629 :     hCrend->delay_line_rw_index = hCrend->delay_line_rw_index % ( pCrend->hHrtfCrend->max_num_iterations );
    1680    11505629 :     if ( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    1681             :     {
    1682     7524663 :         hCrend->diffuse_delay_line_rw_index++;
    1683     7524663 :         hCrend->diffuse_delay_line_rw_index = hCrend->diffuse_delay_line_rw_index % ( pCrend->hHrtfCrend->num_iterations_diffuse[0] );
    1684             :     }
    1685             : 
    1686    11505629 :     return IVAS_ERR_OK;
    1687             : }
    1688             : 
    1689             : 
    1690             : /*-----------------------------------------------------------------------------------------*
    1691             :  * Function ivas_rend_crendProcessSubframe()
    1692             :  *
    1693             :  *
    1694             :  *-----------------------------------------------------------------------------------------*/
    1695             : 
    1696     6605417 : ivas_error ivas_rend_crendProcessSubframe(
    1697             :     const CREND_WRAPPER *pCrend,                                /* i/o: Crend wrapper handle                    */
    1698             :     const AUDIO_CONFIG inConfig,                                /* i  : input audio configuration               */
    1699             :     const AUDIO_CONFIG outConfig,                               /* i  : output audio configuration              */
    1700             :     const DECODER_CONFIG_HANDLE hDecoderConfig,                 /* i  : decoder config. structure               */
    1701             :     const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i  : combined orientation handle             */
    1702             :     const IVAS_OUTPUT_SETUP_HANDLE hIntSetup,                   /* i  : internal setup handle                   */
    1703             :     const EFAP_HANDLE hEFAPdata,                                /* i  : EFAP handle                             */
    1704             :     DECODER_TC_BUFFER_HANDLE hTcBuffer,                         /* i/o: JBM handle                              */
    1705             :     float *input_f[],                                           /* i  : transport channels                      */
    1706             :     float *output[],                                            /* i/o: input/output audio channels             */
    1707             :     const int16_t n_samples_to_render,                          /* i  : output frame length per channel         */
    1708             :     const int32_t output_Fs,                                    /* i  : output sampling rate                    */
    1709             :     const int16_t pos_idx                                       /* i  : pose index                              */
    1710             : )
    1711             : {
    1712             :     int16_t subframe_idx, subframe_len;
    1713             :     int16_t nchan_out, nchan_in, ch, first_sf, last_sf, slot_size, slots_to_render;
    1714             :     float *tc_local[MAX_OUTPUT_CHANNELS];
    1715             :     float *p_output[BINAURAL_CHANNELS];
    1716             :     float pcm_tmp[BINAURAL_CHANNELS][L_FRAME48k / MAX_PARAM_SPATIAL_SUBFRAMES];
    1717             :     float *p_pcm_tmp[BINAURAL_CHANNELS];
    1718             :     IVAS_REND_AudioConfigType inConfigType;
    1719             :     ivas_error error;
    1720             :     int8_t combinedOrientationEnabled;
    1721             :     CREND_HANDLE hCrend;
    1722             : 
    1723     6605417 :     hCrend = pCrend->hCrend[pos_idx];
    1724             : 
    1725     6605417 :     combinedOrientationEnabled = 0;
    1726     6605417 :     if ( hCombinedOrientationData != NULL )
    1727             :     {
    1728       73552 :         if ( hCombinedOrientationData->enableCombinedOrientation[0] != 0 )
    1729             :         {
    1730       73552 :             combinedOrientationEnabled = 1;
    1731             :         }
    1732             :     }
    1733             : 
    1734     6605417 :     push_wmops( "ivas_rend_crendProcessSubframe" );
    1735     6605417 :     inConfigType = getAudioConfigType( inConfig );
    1736             : 
    1737     6605417 :     if ( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ) != IVAS_ERR_OK )
    1738             :     {
    1739           0 :         return error;
    1740             :     }
    1741             : 
    1742     6605417 :     if ( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ) != IVAS_ERR_OK )
    1743             :     {
    1744           0 :         return error;
    1745             :     }
    1746             : 
    1747    79450109 :     for ( ch = 0; ch < nchan_in; ch++ )
    1748             :     {
    1749    72844692 :         tc_local[ch] = input_f[ch];
    1750             :     }
    1751             : 
    1752    19816251 :     for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    1753             :     {
    1754    13210834 :         p_pcm_tmp[ch] = pcm_tmp[ch];
    1755    13210834 :         p_output[ch] = output[ch];
    1756             :     }
    1757             : 
    1758     6605417 :     if ( hTcBuffer != NULL )
    1759             :     {
    1760      555593 :         slot_size = hTcBuffer->n_samples_granularity;
    1761             : 
    1762             :         /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    1763      555593 :         slots_to_render = min( hTcBuffer->num_slots - hTcBuffer->slots_rendered, n_samples_to_render / slot_size );
    1764      555593 :         first_sf = hTcBuffer->subframes_rendered;
    1765      555593 :         last_sf = first_sf;
    1766             : 
    1767     2377162 :         while ( slots_to_render > 0 )
    1768             :         {
    1769     1821569 :             slots_to_render -= hTcBuffer->subframe_nbslots[last_sf];
    1770     1821569 :             last_sf++;
    1771             :         }
    1772      555593 :         subframe_len = -1; /* will be set later */
    1773             :     }
    1774             :     else
    1775             :     {
    1776     6049824 :         subframe_len = (int16_t) ( output_Fs / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) );
    1777     6049824 :         first_sf = 0;
    1778     6049824 :         last_sf = n_samples_to_render / subframe_len;
    1779             :     }
    1780             : 
    1781    18111046 :     for ( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    1782             :     {
    1783    11505629 :         if ( hTcBuffer != NULL )
    1784             :         {
    1785     1821569 :             subframe_len = hTcBuffer->subframe_nbslots[subframe_idx] * hTcBuffer->n_samples_granularity;
    1786             :         }
    1787             : 
    1788             :         /* Early Reflections */
    1789    11505629 :         if ( hCrend->reflections != NULL )
    1790             :         {
    1791      148012 :             if ( hCrend->reflections->use_er == 1 && hCrend->reflections->is_ready == 1 )
    1792             :             {
    1793      148012 :                 if ( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local, inConfig ) ) != IVAS_ERR_OK )
    1794             :                 {
    1795           0 :                     return error;
    1796             :                 }
    1797             :             }
    1798             :         }
    1799             : 
    1800    11505629 :         if ( hDecoderConfig && combinedOrientationEnabled )
    1801             :         {
    1802             :             /* Rotation in SHD for:
    1803             :                     MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL
    1804             :                     SBA SPAR -> BINAURAL or BINAURAL_ROOM
    1805             :                 */
    1806      223026 :             if ( inConfig == IVAS_AUDIO_CONFIG_FOA || inConfig == IVAS_AUDIO_CONFIG_HOA2 || inConfig == IVAS_AUDIO_CONFIG_HOA3 )
    1807             :             {
    1808       44882 :                 rotateFrame_shd( hCombinedOrientationData, tc_local, subframe_len, *hIntSetup, 0 );
    1809             :             }
    1810             :             /* Rotation in SD for MC -> BINAURAL_ROOM */
    1811      178144 :             else if ( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup )
    1812             :             {
    1813      178144 :                 rotateFrame_sd( hCombinedOrientationData, tc_local, subframe_len, *hIntSetup, hEFAPdata, 0 );
    1814             :             }
    1815             :         }
    1816             : 
    1817    11505629 :         if ( ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
    1818             :         {
    1819    11505629 :             if ( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, tc_local, p_pcm_tmp, output_Fs, 0, pos_idx ) ) != IVAS_ERR_OK )
    1820             :             {
    1821           0 :                 return error;
    1822             :             }
    1823             : 
    1824    11505629 :             if ( pCrend->hCrend[0]->hReverb != NULL )
    1825             :             {
    1826     2151812 :                 if ( ( error = ivas_reverb_process( pCrend->hCrend[pos_idx]->hReverb, inConfig, 1, tc_local, p_pcm_tmp, 0 ) ) != IVAS_ERR_OK )
    1827             :                 {
    1828           0 :                     return error;
    1829             :                 }
    1830             :             }
    1831             : 
    1832   137367785 :             for ( ch = 0; ch < nchan_in; ch++ )
    1833             :             {
    1834   125862156 :                 tc_local[ch] += subframe_len;
    1835             :             }
    1836             : 
    1837    11505629 :             if ( hTcBuffer != NULL )
    1838             :             {
    1839     1821569 :                 hTcBuffer->slots_rendered += hTcBuffer->subframe_nbslots[subframe_idx];
    1840             :             }
    1841             :         }
    1842             :         else
    1843             :         {
    1844           0 :             return IVAS_ERR_INVALID_INPUT_FORMAT;
    1845             :         }
    1846             : 
    1847    34516887 :         for ( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    1848             :         {
    1849             :             /* move to output */
    1850    23011258 :             mvr2r( pcm_tmp[ch], p_output[ch], subframe_len );
    1851             : 
    1852    23011258 :             p_output[ch] += subframe_len;
    1853             :         }
    1854             : 
    1855             :         /* update combined orientation access index */
    1856    11505629 :         ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_len );
    1857             :     }
    1858             : 
    1859     6605417 :     if ( hTcBuffer != NULL )
    1860             :     {
    1861      555593 :         hTcBuffer->subframes_rendered = last_sf;
    1862             :     }
    1863             : 
    1864     6605417 :     pop_wmops();
    1865             : 
    1866     6605417 :     return IVAS_ERR_OK;
    1867             : }
    1868             : 
    1869             : 
    1870             : /*-----------------------------------------------------------------------------------------*
    1871             :  * Function ivas_rend_crend_ProcessSubframesSplitBin()
    1872             :  *
    1873             :  * Process call for IVAS Crend renderer
    1874             :  *-----------------------------------------------------------------------------------------*/
    1875             : 
    1876           0 : ivas_error ivas_rend_crendProcessSubframesSplitBin(
    1877             :     const CREND_WRAPPER *pCrend,                                /* i/o: Crend wrapper handle                    */
    1878             :     const AUDIO_CONFIG inConfig,                                /* i  : input audio configuration               */
    1879             :     const AUDIO_CONFIG outConfig,                               /* i  : output audio configuration              */
    1880             :     const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData,          /* i/o: pose correction data handle             */
    1881             :     const DECODER_CONFIG_HANDLE hDecoderConfig,                 /* i  : decoder config. structure               */
    1882             :     const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i  : combined orientation handle             */
    1883             :     const IVAS_OUTPUT_SETUP_HANDLE hIntSetup,                   /* i  : internal setup handle                   */
    1884             :     const EFAP_HANDLE hEFAPdata,                                /* i  : EFAP handle                             */
    1885             :     DECODER_TC_BUFFER_HANDLE hTcBuffer,                         /* i/o: JBM handle                              */
    1886             :     float *input_f[],                                           /* i  : transport channels                      */
    1887             :     float *output[],                                            /* i/o: input/output audio channels             */
    1888             :     const int16_t n_samples_to_render,                          /* i  : output frame length per channel         */
    1889             :     const int32_t output_Fs                                     /* i  : output sampling rate                    */
    1890             : )
    1891             : {
    1892             :     int16_t i, j;
    1893             :     int16_t sf;
    1894             :     int16_t pos_idx;
    1895             :     ivas_error error;
    1896             :     float gain_lfe;
    1897             :     float tmpLfeBuffer[L_FRAME48k];
    1898             :     int16_t original_subframes_rendered, original_slots_rendered;
    1899             :     float tmpInputBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k];
    1900             :     float *p_tmpInputBuffer[MAX_OUTPUT_CHANNELS];
    1901             :     float tmpSplitBinBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k];
    1902             :     COMBINED_ORIENTATION_DATA combinedOrientationDataLocal;
    1903             :     COMBINED_ORIENTATION_HANDLE pCombinedOrientationDataLocal;
    1904             : 
    1905             :     /* save current head positions */
    1906           0 :     pCombinedOrientationDataLocal = hCombinedOrientationData;
    1907           0 :     combinedOrientationDataLocal = *pCombinedOrientationDataLocal;
    1908           0 :     original_subframes_rendered = hTcBuffer->subframes_rendered;
    1909           0 :     original_slots_rendered = hTcBuffer->slots_rendered;
    1910             : 
    1911             :     /* copy input */
    1912           0 :     for ( i = 0; i < hIntSetup->nchan_out_woLFE; ++i )
    1913             :     {
    1914           0 :         mvr2r( input_f[i], tmpInputBuffer[i], n_samples_to_render );
    1915             :     }
    1916             : 
    1917           0 :     for ( i = 0; i < MAX_OUTPUT_CHANNELS; ++i )
    1918             :     {
    1919           0 :         p_tmpInputBuffer[i] = tmpInputBuffer[i];
    1920             :     }
    1921             : 
    1922             :     /* save current head positions */
    1923           0 :     pCombinedOrientationDataLocal = hCombinedOrientationData;
    1924           0 :     combinedOrientationDataLocal = *pCombinedOrientationDataLocal;
    1925           0 :     if ( pMultiBinPoseData->poseCorrectionMode == ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB )
    1926             :     {
    1927           0 :         for ( sf = 1; sf < hCombinedOrientationData->num_subframes; ++sf )
    1928             :         {
    1929           0 :             combinedOrientationDataLocal.Quaternions[sf] = combinedOrientationDataLocal.Quaternions[0];
    1930           0 :             for ( i = 0; i < 3; i++ )
    1931             :             {
    1932           0 :                 for ( j = 0; j < 3; j++ )
    1933             :                 {
    1934           0 :                     combinedOrientationDataLocal.Rmat[sf][i][j] = combinedOrientationDataLocal.Rmat[0][i][j];
    1935             :                 }
    1936             :             }
    1937             :         }
    1938             :     }
    1939             : 
    1940             :     /* copy LFE to tmpLfeBuffer and apply gain only once */
    1941           0 :     if ( hIntSetup->num_lfe > 0 && hIntSetup->index_lfe[0] != -1 )
    1942             :     {
    1943           0 :         mvr2r( output[hIntSetup->index_lfe[0]], tmpLfeBuffer, n_samples_to_render );
    1944           0 :         gain_lfe = ( ( pCrend != NULL ) && ( pCrend->hHrtfCrend != NULL ) ) ? pCrend->hHrtfCrend->gain_lfe : GAIN_LFE;
    1945           0 :         v_multc( tmpLfeBuffer, gain_lfe, tmpLfeBuffer, n_samples_to_render );
    1946             :     }
    1947             :     else
    1948             :     {
    1949           0 :         set_zero( tmpLfeBuffer, n_samples_to_render );
    1950             :     }
    1951             : 
    1952           0 :     for ( pos_idx = 0; pos_idx < pMultiBinPoseData->num_poses; ++pos_idx )
    1953             :     {
    1954             :         /* Update head positions */
    1955             :         IVAS_QUATERNION Quaternions_orig[MAX_PARAM_SPATIAL_SUBFRAMES], Quaternions_abs;
    1956           0 :         for ( i = 0; i < hCombinedOrientationData->num_subframes; i++ )
    1957             :         {
    1958           0 :             Quaternions_orig[i] = combinedOrientationDataLocal.Quaternions[i];
    1959           0 :             Quaternions_abs.w = -3.0f;
    1960           0 :             Quat2EulerDegree( combinedOrientationDataLocal.Quaternions[i], &Quaternions_abs.z, &Quaternions_abs.y, &Quaternions_abs.x ); /*order in Quat2Euler seems to be reversed ?*/
    1961             : 
    1962           0 :             Quaternions_abs.x += pMultiBinPoseData->relative_head_poses[pos_idx][0];
    1963           0 :             Quaternions_abs.y += pMultiBinPoseData->relative_head_poses[pos_idx][1];
    1964           0 :             Quaternions_abs.z += pMultiBinPoseData->relative_head_poses[pos_idx][2];
    1965           0 :             combinedOrientationDataLocal.Quaternions[i] = Quaternions_abs;
    1966           0 :             QuatToRotMat( combinedOrientationDataLocal.Quaternions[i], combinedOrientationDataLocal.Rmat[i] );
    1967             :         }
    1968             : 
    1969           0 :         pCombinedOrientationDataLocal = &combinedOrientationDataLocal;
    1970             : 
    1971           0 :         hTcBuffer->subframes_rendered = original_subframes_rendered;
    1972           0 :         hTcBuffer->slots_rendered = original_slots_rendered;
    1973             : 
    1974             :         /* update combined orientation access index */
    1975           0 :         ivas_combined_orientation_set_to_start_index( pCombinedOrientationDataLocal );
    1976             : 
    1977           0 :         for ( i = 0; i < 3; i++ )
    1978             :         {
    1979           0 :             mvr2r( hCombinedOrientationData->Rmat_prev[pos_idx][i], pCombinedOrientationDataLocal->Rmat_prev[0][i], 3 );
    1980             :         }
    1981             : 
    1982           0 :         if ( ( error = ivas_rend_crendProcessSubframe( pCrend, inConfig, outConfig, hDecoderConfig, pCombinedOrientationDataLocal,
    1983             :                                                        hIntSetup, hEFAPdata, hTcBuffer, p_tmpInputBuffer, p_tmpInputBuffer, n_samples_to_render, output_Fs, pos_idx ) ) != IVAS_ERR_OK )
    1984             :         {
    1985           0 :             return error;
    1986             :         }
    1987             : 
    1988           0 :         for ( i = 0; i < 3; i++ )
    1989             :         {
    1990           0 :             mvr2r( pCombinedOrientationDataLocal->Rmat_prev[0][i], hCombinedOrientationData->Rmat_prev[pos_idx][i], 3 );
    1991             :         }
    1992             : 
    1993           0 :         for ( i = 0; i < BINAURAL_CHANNELS; ++i )
    1994             :         {
    1995             :             /* accumulate LFE to output */
    1996           0 :             v_add( tmpInputBuffer[i], tmpLfeBuffer, tmpInputBuffer[i], n_samples_to_render );
    1997             : 
    1998             :             /* move to split bin output buffer */
    1999           0 :             mvr2r( tmpInputBuffer[i], tmpSplitBinBuffer[pos_idx * BINAURAL_CHANNELS + i], n_samples_to_render );
    2000             :         }
    2001             : 
    2002             :         /* overwrite rendered channels with input again for next iteration */
    2003           0 :         for ( i = 0; i < hIntSetup->nchan_out_woLFE; ++i )
    2004             :         {
    2005           0 :             mvr2r( input_f[i], tmpInputBuffer[i], n_samples_to_render );
    2006             :         }
    2007             : 
    2008             :         /* restore original headrotation data */
    2009           0 :         for ( i = 0; i < hCombinedOrientationData->num_subframes; i++ )
    2010             :         {
    2011           0 :             combinedOrientationDataLocal.Quaternions[i] = Quaternions_orig[i];
    2012             :         }
    2013             :     }
    2014             : 
    2015             :     /* copy split binaural rendered signals to final output */
    2016           0 :     for ( i = 0; i < BINAURAL_CHANNELS * pMultiBinPoseData->num_poses; ++i )
    2017             :     {
    2018           0 :         mvr2r( tmpSplitBinBuffer[i], output[i], n_samples_to_render );
    2019             :     }
    2020             : 
    2021             :     /* update main combined orientation access index */
    2022           0 :     ivas_combined_orientation_update_index( hCombinedOrientationData, n_samples_to_render );
    2023             : 
    2024           0 :     return IVAS_ERR_OK;
    2025             : }

Generated by: LCOV version 1.14