LCOV - code coverage report
Current view: top level - lib_rend - ivas_crend_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 798 1257 63.5 %
Date: 2025-08-23 01:22:27 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 <math.h>
      35             : #include "options.h"
      36             : #include "prot_fx.h"
      37             : #include "ivas_prot_rend_fx.h"
      38             : #include "ivas_cnst.h"
      39             : #include "ivas_rom_rend.h"
      40             : #include "ivas_rom_binaural_crend_head.h"
      41             : #include "ivas_stat_rend.h"
      42             : #include "lib_rend.h"
      43             : #include "ivas_prot_fx.h"
      44             : #include "wmc_auto.h"
      45             : #ifdef DEBUGGING
      46             : #include "debug.h"
      47             : #endif
      48             : 
      49             : #define float_to_fix( n, factor ) ( round( n * ( 1 << factor ) ) )
      50             : #define fix_to_float( n, factor ) ( (float) n / ( 1 << factor ) )
      51             : 
      52             : /*-------------------------------------------------------------------------
      53             :  * ivas_hrtf_init()
      54             :  *
      55             :  * Initialize hHrtf handle
      56             :  *------------------------------------------------------------------------*/
      57             : 
      58         548 : ivas_error ivas_hrtf_init(
      59             :     HRTFS_DATA *hHrtf /* i/o: HRTF handle     */
      60             : )
      61             : {
      62             :     Word16 i, j;
      63             : 
      64         548 :     IF( hHrtf == NULL )
      65             :     {
      66           0 :         return IVAS_ERR_WRONG_PARAMS;
      67             :     }
      68             : 
      69         548 :     hHrtf->latency_s_fx = 0;
      70         548 :     hHrtf->gain_lfe_fx = 0;
      71         548 :     hHrtf->max_num_ir = 0;
      72         548 :     hHrtf->max_num_iterations = 0;
      73         548 :     hHrtf->index_frequency_max_diffuse = 0;
      74         548 :     hHrtf->same_inv_diffuse_weight = 1;
      75         548 :     move16();
      76         548 :     move32();
      77         548 :     move16();
      78         548 :     move16();
      79         548 :     move16();
      80         548 :     move16();
      81             : 
      82        9316 :     FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
      83             :     {
      84       26304 :         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
      85             :         {
      86       17536 :             hHrtf->inv_diffuse_weight_fx[j][i] = 0;
      87       17536 :             move16();
      88       17536 :             hHrtf->num_iterations[i][j] = 0;
      89       17536 :             move16();
      90       17536 :             hHrtf->pIndex_frequency_max[i][j] = NULL;
      91       17536 :             hHrtf->pOut_to_bin_re_fx[i][j] = NULL;
      92       17536 :             hHrtf->pOut_to_bin_im_fx[i][j] = NULL;
      93             :         }
      94             :     }
      95             : 
      96        1644 :     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
      97             :     {
      98        1096 :         hHrtf->num_iterations_diffuse[j] = 0;
      99        1096 :         move16();
     100        1096 :         hHrtf->pIndex_frequency_max_diffuse[j] = NULL;
     101             : 
     102        1096 :         hHrtf->pOut_to_bin_diffuse_re_fx[j] = NULL;
     103        1096 :         hHrtf->pOut_to_bin_diffuse_im_fx[j] = NULL;
     104             :     }
     105             : 
     106         548 :     hHrtf->init_from_rom = 1;
     107         548 :     move16();
     108             : 
     109         548 :     return IVAS_ERR_OK;
     110             : }
     111             : 
     112             : /*-------------------------------------------------------------------------
     113             :  * ivas_hrtf_open()
     114             :  *
     115             :  * Open hHrtf handle
     116             :  *------------------------------------------------------------------------*/
     117         428 : static ivas_error ivas_hrtf_open(
     118             :     HRTFS_HANDLE *hHrtf_out /* o  : HRTF handle     */
     119             : )
     120             : {
     121             :     HRTFS_HANDLE hHrtf;
     122             :     ivas_error error;
     123             : 
     124         428 :     IF( *hHrtf_out == NULL )
     125             :     {
     126         428 :         IF( ( hHrtf = (HRTFS_HANDLE) malloc( sizeof( HRTFS_DATA ) ) ) == NULL )
     127             :         {
     128           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder\n" );
     129             :         }
     130             : 
     131         428 :         IF( NE_32( ( error = ivas_hrtf_init( hHrtf ) ), IVAS_ERR_OK ) )
     132             :         {
     133           0 :             return error;
     134             :         }
     135             : 
     136         428 :         *hHrtf_out = hHrtf;
     137             :     }
     138             :     ELSE
     139             :     {
     140           0 :         return IVAS_ERR_INTERNAL;
     141             :     }
     142             : 
     143         428 :     return IVAS_ERR_OK;
     144             : }
     145             : 
     146             : 
     147             : /*-------------------------------------------------------------------------
     148             :  * ivas_hrtf_close()
     149             :  *
     150             :  * Close hHrtf handle
     151             :  *------------------------------------------------------------------------*/
     152             : 
     153         428 : static void ivas_hrtf_close(
     154             :     HRTFS_HANDLE *hHrtf /* i/o: HRTF handle         */
     155             : )
     156             : {
     157         428 :     test();
     158         428 :     IF( hHrtf == NULL || *hHrtf == NULL )
     159             :     {
     160           0 :         return;
     161             :     }
     162             : 
     163         428 :     free( *hHrtf );
     164         428 :     *hHrtf = NULL;
     165             : 
     166         428 :     return;
     167             : }
     168             : /*-------------------------------------------------------------------------
     169             :  * initCrend_from_rom()
     170             :  *
     171             :  * Allocate and initialize crend renderer handle
     172             :  *------------------------------------------------------------------------*/
     173             : 
     174         428 : static ivas_error ivas_rend_initCrend_fx(
     175             :     CREND_WRAPPER *pCrend,
     176             :     const AUDIO_CONFIG inConfig,
     177             :     const AUDIO_CONFIG outConfig,
     178             :     HRTFS_CREND_HANDLE hSetOfHRTF,
     179             :     const Word32 output_Fs )
     180             : {
     181             :     Word16 i, j, tmp;
     182             :     Word16 nchan_in;
     183             :     IVAS_REND_AudioConfigType inConfigType;
     184             :     HRTFS_HANDLE hHrtf;
     185             :     ivas_error error;
     186             : 
     187         428 :     inConfigType = getAudioConfigType( inConfig );
     188         428 :     hHrtf = pCrend->hHrtfCrend;
     189             : 
     190             :     /* Do all error checks up front so that the nested if later is easier */
     191         428 :     test();
     192         428 :     IF( inConfigType != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED && NE_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
     193             :     {
     194           0 :         return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Encountered unsupported input config in Crend" );
     195             :     }
     196             : 
     197         428 :     test();
     198         428 :     test();
     199         428 :     if ( NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL ) && NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) && NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) && NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) && NE_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
     200             :     {
     201           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Encountered unsupported output type in Crend" );
     202             :     }
     203             : 
     204         428 :     IF( hHrtf == NULL )
     205             :     {
     206         428 :         IF( NE_32( ivas_hrtf_open( &hHrtf ), IVAS_ERR_OK ) )
     207             :         {
     208           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for HRTF handle" );
     209             :         }
     210             :     }
     211             : 
     212         428 :     IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) )
     213             :     {
     214           0 :         return error;
     215             :     }
     216         428 :     hHrtf->max_num_ir = nchan_in;
     217         428 :     move16();
     218             : 
     219         428 :     IF( hHrtf->max_num_ir <= 0 )
     220             :     {
     221           0 :         return IVAS_ERR_INTERNAL_FATAL;
     222             :     }
     223             : 
     224         428 :     test();
     225         428 :     test();
     226         428 :     test();
     227         428 :     test();
     228         428 :     test();
     229         428 :     test();
     230         428 :     test();
     231         428 :     test();
     232         428 :     test();
     233         428 :     test();
     234         428 :     test();
     235         428 :     test();
     236         428 :     test();
     237         428 :     test();
     238         428 :     test();
     239         428 :     IF( ( hSetOfHRTF == NULL ) ||
     240             :         ( ( hSetOfHRTF->hHRTF_hrir_combined == NULL ) && ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) && ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB ) ) ||
     241             :         ( ( hSetOfHRTF->hHRTF_hrir_combined == NULL ) && ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) && ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL ) ) ||
     242             :         ( ( hSetOfHRTF->hHRTF_brir_combined == NULL ) && ( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) && ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) ) ||
     243             :         ( ( hSetOfHRTF->hHRTF_hrir_foa == NULL ) && ( inConfig == IVAS_AUDIO_CONFIG_FOA ) ) ||
     244             :         ( ( hSetOfHRTF->hHRTF_hrir_hoa2 == NULL ) && ( inConfig == IVAS_AUDIO_CONFIG_HOA2 ) ) ||
     245             :         ( ( hSetOfHRTF->hHRTF_hrir_hoa3 == NULL ) && ( inConfig == IVAS_AUDIO_CONFIG_HOA3 ) ) )
     246             :     {
     247         400 :         hHrtf->init_from_rom = 1;
     248         400 :         move16();
     249         400 :         IF( EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) )
     250             :         {
     251         387 :             hHrtf->max_num_ir = sub( hHrtf->max_num_ir, 1 ); /* subtract LFE */
     252         387 :             move16();
     253         387 :             hHrtf->gain_lfe_fx = GAIN_LFE_FX; // Q14
     254         387 :             move16();
     255             : 
     256         387 :             IF( EQ_32( output_Fs, 48000 ) )
     257             :             {
     258         247 :                 IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     259             :                 {
     260         155 :                     hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx;                                     // Q31
     261         155 :                     hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_48kHz;                   // Q0
     262         155 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz; // Q0
     263             :                 }
     264             :                 ELSE
     265             :                 {
     266          92 :                     hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx;                                     // Q31
     267          92 :                     hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_48kHz;                   // Q0
     268          92 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz; // Q0
     269             :                 }
     270         247 :                 move32();
     271         247 :                 move16();
     272         247 :                 move16();
     273             : 
     274         741 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     275             :                 {
     276         494 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     277             :                     {
     278         310 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[j];             // Q0
     279         310 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[j]; // Q0
     280             : 
     281         310 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     282         310 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     283             :                     }
     284             :                     ELSE
     285             :                     {
     286         184 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[j];             // Q0
     287         184 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; // Q0
     288             : 
     289         184 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     290         184 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     291             :                     }
     292         494 :                     move32();
     293         494 :                     move32();
     294         494 :                     move16();
     295         494 :                     move16();
     296             :                 }
     297             :             }
     298         140 :             ELSE IF( EQ_32( output_Fs, 32000 ) )
     299             :             {
     300          75 :                 IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     301             :                 {
     302          75 :                     hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx;                                     // Q31
     303          75 :                     hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_32kHz;                   // Q0
     304          75 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz; // Q0
     305             :                 }
     306             :                 ELSE
     307             :                 {
     308           0 :                     hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx;                                     // Q31
     309           0 :                     hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_32kHz;                   // Q0
     310           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz; // Q0
     311             :                 }
     312          75 :                 move32();
     313          75 :                 move16();
     314          75 :                 move16();
     315             : 
     316         225 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     317             :                 {
     318         150 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     319             :                     {
     320         150 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[j];             // Q0
     321         150 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[j]; // Q0
     322             : 
     323         150 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31
     324         150 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31
     325             :                     }
     326             :                     ELSE
     327             :                     {
     328           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[j];             // Q0
     329           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; // Q0
     330             : 
     331           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31
     332           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31
     333             :                     }
     334         150 :                     move32();
     335         150 :                     move32();
     336         150 :                     move16();
     337         150 :                     move16();
     338             :                 }
     339             :             }
     340          65 :             ELSE IF( EQ_32( output_Fs, 16000 ) )
     341             :             {
     342          65 :                 IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     343             :                 {
     344           4 :                     hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; // Q31
     345           4 :                     hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_16kHz;
     346           4 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_16kHz;
     347             :                 }
     348             :                 ELSE
     349             :                 {
     350          61 :                     hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; // Q31
     351          61 :                     hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_16kHz;
     352          61 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_16kHz;
     353             :                 }
     354          65 :                 move32();
     355          65 :                 move16();
     356          65 :                 move16();
     357             : 
     358         195 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     359             :                 {
     360         130 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     361             :                     {
     362           8 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_16kHz[j];
     363           8 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[j];
     364             : 
     365           8 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     366           8 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     367             :                     }
     368             :                     ELSE
     369             :                     {
     370         122 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_16kHz[j];
     371         122 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     372             : 
     373         122 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     374         122 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     375             :                     }
     376         130 :                     move32();
     377         130 :                     move32();
     378         130 :                     move16();
     379         130 :                     move16();
     380             :                 }
     381             :             }
     382             :             ELSE
     383             :             {
     384           0 :                 return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     385             :             }
     386             : 
     387        3544 :             FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     388             :             {
     389        3157 :                 IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) )
     390             :                 {
     391         810 :                     tmp = channelIndex_CICP6[i];
     392             :                 }
     393        2347 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) )
     394             :                 {
     395          63 :                     tmp = channelIndex_CICP12[i];
     396             :                 }
     397        2284 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) )
     398             :                 {
     399         112 :                     tmp = channelIndex_CICP14[i];
     400             :                 }
     401        2172 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) )
     402             :                 {
     403         126 :                     tmp = channelIndex_CICP16[i];
     404             :                 }
     405        2046 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1_4 ) )
     406             :                 {
     407        2046 :                     tmp = channelIndex_CICP19[i];
     408             :                 }
     409             :                 ELSE
     410             :                 {
     411           0 :                     return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Channel configuration not specified!\n\n" );
     412             :                 }
     413        3157 :                 move16();
     414             : 
     415        3157 :                 IF( EQ_32( output_Fs, 48000 ) )
     416             :                 {
     417        5997 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     418             :                     {
     419        3998 :                         IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     420             :                         {
     421        2502 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz_fx[j][tmp];
     422        2502 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_48kHz[tmp][j];
     423        2502 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_48kHz[tmp][j];
     424             : 
     425        2502 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_48kHz_fx[tmp][j]; // Q29
     426        2502 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_48kHz_fx[tmp][j]; // Q29
     427             :                         }
     428             :                         ELSE
     429             :                         {
     430        1496 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz_fx[j][tmp];
     431        1496 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_48kHz[tmp][j];
     432        1496 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_48kHz[tmp][j];
     433             : 
     434        1496 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_48kHz_fx[tmp][j]; // Q29
     435        1496 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_48kHz_fx[tmp][j]; // Q29
     436             :                         }
     437        3998 :                         move32();
     438        3998 :                         move32();
     439        3998 :                         move16();
     440        3998 :                         move16();
     441             :                     }
     442             :                 }
     443        1158 :                 ELSE IF( EQ_32( output_Fs, 32000 ) )
     444             :                 {
     445        2475 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     446             :                     {
     447        1650 :                         IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     448             :                         {
     449        1650 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz_fx[j][tmp];
     450        1650 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_32kHz[tmp][j];
     451        1650 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_32kHz[tmp][j];
     452             : 
     453        1650 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_32kHz_fx[tmp][j]; // Q29
     454        1650 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_32kHz_fx[tmp][j]; // Q29
     455             :                         }
     456             :                         ELSE
     457             :                         {
     458           0 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz_fx[j][tmp];
     459           0 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_32kHz[tmp][j];
     460           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_32kHz[tmp][j];
     461             : 
     462           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_32kHz_fx[tmp][j]; // Q29
     463           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_32kHz_fx[tmp][j]; // Q29
     464             :                         }
     465        1650 :                         move32();
     466        1650 :                         move32();
     467        1650 :                         move16();
     468        1650 :                         move16();
     469             :                     }
     470             :                 }
     471         333 :                 ELSE IF( EQ_32( output_Fs, 16000 ) )
     472             :                 {
     473         999 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     474             :                     {
     475         666 :                         IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     476             :                         {
     477          56 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz_fx[j][tmp];
     478          56 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_16kHz[tmp][j];
     479          56 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_16kHz[tmp][j];
     480             : 
     481          56 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_16kHz_fx[tmp][j]; // Q29
     482          56 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_16kHz_fx[tmp][j]; // Q29
     483             :                         }
     484             :                         ELSE
     485             :                         {
     486         610 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz_fx[j][tmp];
     487         610 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_16kHz[tmp][j];
     488         610 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_16kHz[tmp][j];
     489             : 
     490         610 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_16kHz_fx[tmp][j]; // Q29
     491         610 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_16kHz_fx[tmp][j]; // Q29
     492             :                         }
     493         666 :                         move32();
     494         666 :                         move32();
     495         666 :                         move16();
     496         666 :                         move16();
     497             :                     }
     498             :                 }
     499             :                 ELSE
     500             :                 {
     501           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     502             :                 }
     503             :             }
     504             :         }
     505          13 :         ELSE IF( EQ_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
     506             :         {
     507          13 :             IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) )
     508             :             {
     509           5 :                 IF( EQ_32( output_Fs, 48000 ) )
     510             :                 {
     511           5 :                     hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31
     512           5 :                     hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_48kHz;
     513           5 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_48kHz;
     514           5 :                     move32();
     515           5 :                     move16();
     516           5 :                     move16();
     517             : 
     518          85 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     519             :                     {
     520         240 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     521             :                         {
     522         160 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz_fx[j][i]; // Q15
     523         160 :                             move16();
     524         160 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_48kHz[i][j];
     525         160 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_48kHz[i][j];
     526             : 
     527         160 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_48kHz_fx[i][j]; // Q29
     528         160 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_48kHz_fx[i][j]; // Q29
     529         160 :                             move32();
     530         160 :                             move32();
     531         160 :                             move16();
     532         160 :                             move16();
     533             :                         }
     534             :                     }
     535          15 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     536             :                     {
     537          10 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_48kHz[j];
     538          10 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     539             : 
     540          10 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     541          10 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     542          10 :                         move32();
     543          10 :                         move32();
     544          10 :                         move16();
     545          10 :                         move16();
     546             :                     }
     547             :                 }
     548           0 :                 ELSE IF( EQ_32( output_Fs, 32000 ) )
     549             :                 {
     550           0 :                     hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31
     551           0 :                     hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_32kHz;
     552           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_32kHz;
     553           0 :                     move32();
     554           0 :                     move16();
     555           0 :                     move16();
     556             : 
     557           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     558             :                     {
     559           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     560             :                         {
     561           0 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz_fx[j][i]; // Q15
     562           0 :                             move16();
     563           0 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_32kHz[i][j];
     564           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_32kHz[i][j];
     565             : 
     566           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_32kHz_fx[i][j]; // Q29
     567           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_32kHz_fx[i][j]; // Q29
     568           0 :                             move32();
     569           0 :                             move32();
     570           0 :                             move16();
     571           0 :                             move16();
     572             :                         }
     573             :                     }
     574             : 
     575           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     576             :                     {
     577           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_32kHz[j];
     578           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
     579             : 
     580           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31
     581           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31
     582           0 :                         move32();
     583           0 :                         move32();
     584           0 :                         move16();
     585           0 :                         move16();
     586             :                     }
     587             :                 }
     588           0 :                 ELSE IF( EQ_32( output_Fs, 16000 ) )
     589             :                 {
     590           0 :                     hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31
     591           0 :                     hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_16kHz;
     592           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_16kHz;
     593           0 :                     move32();
     594           0 :                     move16();
     595           0 :                     move16();
     596             : 
     597           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     598             :                     {
     599             : 
     600           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     601             :                         {
     602           0 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz_fx[j][i]; // Q15
     603           0 :                             move16();
     604           0 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_16kHz[i][j];
     605           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_16kHz[i][j];
     606             : 
     607           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_16kHz_fx[i][j]; // Q29
     608           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_16kHz_fx[i][j]; // Q29
     609           0 :                             move32();
     610           0 :                             move32();
     611           0 :                             move16();
     612           0 :                             move16();
     613             :                         }
     614             :                     }
     615             : 
     616           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     617             :                     {
     618           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_16kHz[j];
     619           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     620             : 
     621           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     622           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     623           0 :                         move32();
     624           0 :                         move32();
     625           0 :                         move16();
     626           0 :                         move16();
     627             :                     }
     628             :                 }
     629             :                 ELSE
     630             :                 {
     631           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     632             :                 }
     633             :             }
     634           8 :             ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) )
     635             :             {
     636           4 :                 IF( EQ_32( output_Fs, 48000 ) )
     637             :                 {
     638           4 :                     hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31
     639           4 :                     hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_48kHz;
     640           4 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_48kHz;
     641           4 :                     move32();
     642           4 :                     move16();
     643           4 :                     move16();
     644             : 
     645          40 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     646             :                     {
     647         108 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     648             :                         {
     649          72 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz_fx[j][i]; // Q15
     650          72 :                             move16();
     651          72 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_48kHz[i][j];
     652          72 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_48kHz[i][j];
     653             : 
     654          72 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_48kHz_fx[i][j]; // Q29
     655          72 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_48kHz_fx[i][j]; // Q29
     656          72 :                             move32();
     657          72 :                             move32();
     658          72 :                             move16();
     659          72 :                             move16();
     660             :                         }
     661             :                     }
     662          12 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     663             :                     {
     664           8 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_48kHz[j];
     665           8 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     666             : 
     667           8 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     668           8 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     669           8 :                         move32();
     670           8 :                         move32();
     671           8 :                         move16();
     672           8 :                         move16();
     673             :                     }
     674             :                 }
     675           0 :                 ELSE IF( EQ_32( output_Fs, 32000 ) )
     676             :                 {
     677           0 :                     hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31
     678           0 :                     hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_32kHz;
     679           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_32kHz;
     680           0 :                     move32();
     681           0 :                     move16();
     682           0 :                     move16();
     683             : 
     684           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     685             :                     {
     686           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     687             :                         {
     688           0 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz_fx[j][i]; // Q15
     689           0 :                             move16();
     690           0 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_32kHz[i][j];
     691           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_32kHz[i][j];
     692             : 
     693           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_32kHz_fx[i][j]; // Q29
     694           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_32kHz_fx[i][j]; // Q29
     695           0 :                             move32();
     696           0 :                             move32();
     697           0 :                             move16();
     698           0 :                             move16();
     699             :                         }
     700             :                     }
     701             : 
     702           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     703             :                     {
     704           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_32kHz[j];
     705           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
     706             : 
     707           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31
     708           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31
     709           0 :                         move32();
     710           0 :                         move32();
     711           0 :                         move16();
     712           0 :                         move16();
     713             :                     }
     714             :                 }
     715           0 :                 ELSE IF( EQ_32( output_Fs, 16000 ) )
     716             :                 {
     717           0 :                     hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31
     718           0 :                     hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_16kHz;
     719           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_16kHz;
     720           0 :                     move32();
     721           0 :                     move16();
     722           0 :                     move16();
     723             : 
     724           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     725             :                     {
     726           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     727             :                         {
     728           0 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz_fx[j][i]; // Q15
     729           0 :                             move16();
     730           0 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_16kHz[i][j];
     731           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_16kHz[i][j];
     732             : 
     733           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_16kHz_fx[i][j]; // Q29
     734           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_16kHz_fx[i][j]; // Q29
     735           0 :                             move32();
     736           0 :                             move32();
     737           0 :                             move16();
     738           0 :                             move16();
     739             :                         }
     740             :                     }
     741             : 
     742           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     743             :                     {
     744           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_16kHz[j];
     745           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     746             : 
     747           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     748           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     749           0 :                         move32();
     750           0 :                         move32();
     751           0 :                         move16();
     752           0 :                         move16();
     753             :                     }
     754             :                 }
     755             :                 ELSE
     756             :                 {
     757           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     758             :                 }
     759             :             }
     760           4 :             ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_FOA ) )
     761             :             {
     762           4 :                 IF( EQ_32( output_Fs, 48000 ) )
     763             :                 {
     764           4 :                     hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31
     765           4 :                     hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_48kHz;
     766           4 :                     hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_48kHz;
     767           4 :                     move32();
     768           4 :                     move16();
     769           4 :                     move16();
     770             : 
     771          20 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     772             :                     {
     773          48 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     774             :                         {
     775          32 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz_fx[j][i]; // Q15
     776          32 :                             move16();
     777          32 :                             hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_48kHz[i][j];
     778          32 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_48kHz[i][j];
     779             : 
     780          32 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_48kHz_fx[i][j]; // Q29
     781          32 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_48kHz_fx[i][j]; // Q29
     782          32 :                             move32();
     783          32 :                             move32();
     784          32 :                             move16();
     785          32 :                             move16();
     786             :                         }
     787             :                     }
     788          12 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     789             :                     {
     790           8 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_48kHz[j];
     791           8 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     792             : 
     793           8 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     794           8 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     795           8 :                         move32();
     796           8 :                         move32();
     797           8 :                         move16();
     798           8 :                         move16();
     799             :                     }
     800             :                 }
     801           0 :                 ELSE IF( EQ_32( output_Fs, 32000 ) )
     802             :                 {
     803           0 :                     hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31
     804           0 :                     hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_32kHz;
     805           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_32kHz;
     806           0 :                     move32();
     807           0 :                     move16();
     808           0 :                     move16();
     809             : 
     810           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     811             :                     {
     812           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     813             :                         {
     814           0 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz_fx[j][i]; // Q15
     815           0 :                             move16();
     816           0 :                             hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_32kHz[i][j];
     817           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_32kHz[i][j];
     818             : 
     819           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_32kHz_fx[i][j]; // Q29
     820           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_32kHz_fx[i][j]; // Q29
     821           0 :                             move32();
     822           0 :                             move32();
     823           0 :                             move16();
     824           0 :                             move16();
     825             :                         }
     826             :                     }
     827             : 
     828           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     829             :                     {
     830           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_32kHz[j];
     831           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
     832             : 
     833           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31
     834           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31
     835           0 :                         move32();
     836           0 :                         move32();
     837           0 :                         move16();
     838           0 :                         move16();
     839             :                     }
     840             :                 }
     841           0 :                 ELSE IF( EQ_32( output_Fs, 16000 ) )
     842             :                 {
     843           0 :                     hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31
     844           0 :                     hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_16kHz;
     845           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_16kHz;
     846           0 :                     move32();
     847           0 :                     move16();
     848           0 :                     move16();
     849             : 
     850           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     851             :                     {
     852           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     853             :                         {
     854           0 :                             hHrtf->inv_diffuse_weight_fx[j][i] = CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz_fx[j][i]; // Q15
     855           0 :                             move16();
     856           0 :                             hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_16kHz[i][j];
     857           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_16kHz[i][j];
     858             : 
     859           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_16kHz_fx[i][j]; // Q29
     860           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_16kHz_fx[i][j]; // Q29
     861           0 :                             move32();
     862           0 :                             move32();
     863           0 :                             move16();
     864           0 :                             move16();
     865             :                         }
     866             :                     }
     867             : 
     868           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     869             :                     {
     870           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_16kHz[j];
     871           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     872             : 
     873           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     874           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     875           0 :                         move32();
     876           0 :                         move32();
     877           0 :                         move16();
     878           0 :                         move16();
     879             :                     }
     880             :                 }
     881             :                 ELSE
     882             :                 {
     883           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     884             :                 }
     885             :             }
     886             :             ELSE
     887             :             {
     888           0 :                 return IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "Encountered unsupported input config in Crend" );
     889             :             }
     890             :         }
     891             :         ELSE
     892             :         {
     893           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL, "Unsupported renderer type in Crend" );
     894             :         }
     895             :     }
     896             :     ELSE
     897             :     {
     898          28 :         hHrtf->init_from_rom = 0;
     899          28 :         IF( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
     900             :         {
     901          28 :             hHrtf->max_num_ir = sub( hHrtf->max_num_ir, 1 ); /* subtract LFE */
     902          28 :             move16();
     903          28 :             hHrtf->gain_lfe_fx = GAIN_LFE_FX;
     904          28 :             move16();
     905             : 
     906          28 :             IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     907             :             {
     908          20 :                 IF( hSetOfHRTF->hHRTF_brir_combined == NULL )
     909             :                 {
     910           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Invalid command wrong output format" );
     911             :                 }
     912          20 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_brir_combined->latency_s_fx; // Q31
     913          20 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_brir_combined->max_num_iterations;
     914          20 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_brir_combined->index_frequency_max_diffuse;
     915             :             }
     916             :             ELSE
     917             :             {
     918           8 :                 IF( hSetOfHRTF->hHRTF_hrir_combined == NULL )
     919             :                 {
     920           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_OUTPUT_FORMAT, "Invalid command wrong output format" );
     921             :                 }
     922           8 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_combined->latency_s_fx; // Q31
     923           8 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_combined->max_num_iterations;
     924           8 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_combined->index_frequency_max_diffuse;
     925             :             }
     926          28 :             move32();
     927          28 :             move16();
     928          28 :             move16();
     929             : 
     930          84 :             FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     931             :             {
     932          56 :                 IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     933             :                 {
     934          40 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations_diffuse[j];
     935          40 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max_diffuse[j];
     936             : 
     937          40 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_re_fx[j]; // Q31
     938          40 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_im_fx[j]; // Q31
     939             :                 }
     940             :                 ELSE
     941             :                 {
     942          16 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_combined->num_iterations_diffuse[j];
     943          16 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_combined->pIndex_frequency_max_diffuse[j];
     944             : 
     945          16 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_re_fx[j]; // Q31
     946          16 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_im_fx[j]; // Q31
     947             :                 }
     948          56 :                 move32();
     949          56 :                 move32();
     950          56 :                 move16();
     951          56 :                 move16();
     952             :             }
     953             : 
     954         332 :             FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     955             :             {
     956         304 :                 IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) )
     957             :                 {
     958           0 :                     tmp = channelIndex_CICP6[i];
     959             :                 }
     960         304 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) )
     961             :                 {
     962           0 :                     tmp = channelIndex_CICP12[i];
     963             :                 }
     964         304 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) )
     965             :                 {
     966           0 :                     tmp = channelIndex_CICP14[i];
     967             :                 }
     968         304 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) )
     969             :                 {
     970          18 :                     tmp = channelIndex_CICP16[i];
     971             :                 }
     972         286 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1_4 ) )
     973             :                 {
     974         286 :                     tmp = channelIndex_CICP19[i];
     975             :                 }
     976             :                 ELSE
     977             :                 {
     978           0 :                     return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Channel configuration not specified!\n\n" );
     979             :                 }
     980         304 :                 move16();
     981         912 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     982             :                 {
     983         608 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     984             :                     {
     985         436 :                         hHrtf->inv_diffuse_weight_fx[j][i] = hSetOfHRTF->hHRTF_brir_combined->inv_diffuse_weight_fx[j][tmp];
     986         436 :                         move16();
     987         436 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations[tmp][j];
     988         436 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max[tmp][j];
     989             : 
     990         436 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_re_fx[tmp][j]; // Q29
     991         436 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_im_fx[tmp][j]; // Q29
     992             :                     }
     993             :                     ELSE
     994             :                     {
     995         172 :                         hHrtf->inv_diffuse_weight_fx[j][i] = hSetOfHRTF->hHRTF_hrir_combined->inv_diffuse_weight_fx[j][tmp];
     996         172 :                         move16();
     997         172 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_combined->num_iterations[tmp][j];
     998         172 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pIndex_frequency_max[tmp][j];
     999             : 
    1000         172 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_re_fx[tmp][j]; // Q29
    1001         172 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_im_fx[tmp][j]; // Q29
    1002             :                     }
    1003         608 :                     move32();
    1004         608 :                     move32();
    1005         608 :                     move16();
    1006         608 :                     move16();
    1007             :                 }
    1008             :             }
    1009             :         }
    1010           0 :         ELSE IF( EQ_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
    1011             :         {
    1012           0 :             IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) )
    1013             :             {
    1014           0 :                 IF( hSetOfHRTF->hHRTF_hrir_hoa3 == NULL )
    1015             :                 {
    1016           0 :                     return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Invalid function parameters " );
    1017             :                 }
    1018           0 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa3->latency_s_fx; // Q31
    1019           0 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa3->max_num_iterations;
    1020           0 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_hoa3->index_frequency_max_diffuse;
    1021           0 :                 move32();
    1022           0 :                 move16();
    1023           0 :                 move16();
    1024             : 
    1025           0 :                 FOR( i = 0; i < hHrtf->max_num_ir; i++ )
    1026             :                 {
    1027           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1028             :                     {
    1029           0 :                         hHrtf->inv_diffuse_weight_fx[j][i] = hSetOfHRTF->hHRTF_hrir_hoa3->inv_diffuse_weight_fx[j][i];
    1030           0 :                         move16();
    1031           0 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations[i][j];
    1032           0 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max[i][j];
    1033             : 
    1034           0 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_re_fx[i][j]; // Q29
    1035           0 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_im_fx[i][j]; // Q29
    1036           0 :                         move32();
    1037           0 :                         move32();
    1038           0 :                         move16();
    1039           0 :                         move16();
    1040             :                     }
    1041             :                 }
    1042           0 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1043             :                 {
    1044           0 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations_diffuse[j];
    1045           0 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max_diffuse[j];
    1046             : 
    1047           0 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_re_fx[j]; // Q31
    1048           0 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_im_fx[j]; // Q31
    1049           0 :                     move32();
    1050           0 :                     move32();
    1051           0 :                     move16();
    1052           0 :                     move16();
    1053             :                 }
    1054             :             }
    1055           0 :             ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) )
    1056             :             {
    1057           0 :                 IF( hSetOfHRTF->hHRTF_hrir_hoa2 == NULL )
    1058             :                 {
    1059           0 :                     return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Invalid function parameters " );
    1060             :                 }
    1061           0 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa2->latency_s_fx; // Q31
    1062           0 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa2->max_num_iterations;
    1063           0 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_hoa2->index_frequency_max_diffuse;
    1064           0 :                 move32();
    1065           0 :                 move16();
    1066           0 :                 move16();
    1067             : 
    1068           0 :                 FOR( i = 0; i < hHrtf->max_num_ir; i++ )
    1069             :                 {
    1070           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1071             :                     {
    1072           0 :                         hHrtf->inv_diffuse_weight_fx[j][i] = hSetOfHRTF->hHRTF_hrir_hoa2->inv_diffuse_weight_fx[j][i];
    1073           0 :                         move16();
    1074           0 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations[i][j];
    1075           0 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max[i][j];
    1076             : 
    1077           0 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_re_fx[i][j]; // Q29
    1078           0 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_im_fx[i][j]; // Q29
    1079           0 :                         move32();
    1080           0 :                         move32();
    1081           0 :                         move16();
    1082           0 :                         move16();
    1083             :                     }
    1084             :                 }
    1085           0 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1086             :                 {
    1087           0 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations_diffuse[j];
    1088           0 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max_diffuse[j];
    1089             : 
    1090           0 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_re_fx[j]; // Q31
    1091           0 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_im_fx[j]; // Q31
    1092           0 :                     move32();
    1093           0 :                     move32();
    1094           0 :                     move16();
    1095           0 :                     move16();
    1096             :                 }
    1097             :             }
    1098           0 :             ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_FOA ) )
    1099             :             {
    1100           0 :                 IF( hSetOfHRTF->hHRTF_hrir_foa == NULL )
    1101             :                 {
    1102           0 :                     return IVAS_ERROR( IVAS_ERR_UNEXPECTED_NULL_POINTER, "Invalid function parameters " );
    1103             :                 }
    1104           0 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_foa->latency_s_fx; // Q31
    1105           0 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_foa->max_num_iterations;
    1106           0 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_foa->index_frequency_max_diffuse;
    1107           0 :                 move32();
    1108           0 :                 move16();
    1109           0 :                 move16();
    1110             : 
    1111           0 :                 FOR( i = 0; i < hHrtf->max_num_ir; i++ )
    1112             :                 {
    1113           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1114             :                     {
    1115           0 :                         hHrtf->inv_diffuse_weight_fx[j][i] = hSetOfHRTF->hHRTF_hrir_foa->inv_diffuse_weight_fx[j][i];
    1116           0 :                         move16();
    1117             : 
    1118           0 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations[i][j];
    1119           0 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max[i][j];
    1120             : 
    1121           0 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_re_fx[i][j]; // Q29
    1122           0 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_im_fx[i][j]; // Q29
    1123           0 :                         move32();
    1124           0 :                         move32();
    1125           0 :                         move16();
    1126           0 :                         move16();
    1127             :                     }
    1128             :                 }
    1129           0 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1130             :                 {
    1131           0 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations_diffuse[j];
    1132           0 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max_diffuse[j];
    1133             : 
    1134           0 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_re_fx[j]; // Q31
    1135           0 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_im_fx[j]; // Q31
    1136           0 :                     move32();
    1137           0 :                     move32();
    1138           0 :                     move16();
    1139           0 :                     move16();
    1140             :                 }
    1141             :             }
    1142             :             ELSE
    1143             :             {
    1144           0 :                 return IVAS_ERROR( IVAS_ERR_INTERNAL, "Unsupported renderer type in Crend" );
    1145             :             }
    1146             :         }
    1147             :     }
    1148             : 
    1149         428 :     hHrtf->same_inv_diffuse_weight = 1;
    1150        4021 :     for ( i = 0; i < hHrtf->max_num_ir; i++ )
    1151             :     {
    1152        3593 :         if ( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR )
    1153             :         {
    1154        2322 :             if ( hHrtf->inv_diffuse_weight_fx[0][i] != hHrtf->inv_diffuse_weight_fx[1][i] )
    1155             :             {
    1156           0 :                 hHrtf->same_inv_diffuse_weight = 0;
    1157           0 :                 break;
    1158             :             }
    1159             :         }
    1160             :     }
    1161             : 
    1162         428 :     pCrend->hHrtfCrend = hHrtf;
    1163             : 
    1164         428 :     return IVAS_ERR_OK;
    1165             : }
    1166             : 
    1167             : /*-------------------------------------------------------------------------
    1168             :  * ivas_shoebox_data_init()
    1169             :  *
    1170             :  * Initialize shoebox_data_t handle
    1171             :  *------------------------------------------------------------------------*/
    1172             : 
    1173          16 : static ivas_error ivas_shoebox_data_init(
    1174             :     shoebox_data_t *hShoeboxData /* i/o: shoebox_data_t handle     */
    1175             : )
    1176             : {
    1177             :     Word16 i;
    1178             : 
    1179          16 :     IF( hShoeboxData == NULL )
    1180             :     {
    1181           0 :         return IVAS_ERR_WRONG_PARAMS;
    1182             :     }
    1183             : 
    1184        2416 :     FOR( i = 0; i < 150; i++ )
    1185             :     {
    1186        2400 :         hShoeboxData->data_fx[i] = 0;
    1187        2400 :         move32();
    1188             :     }
    1189          32 :     FOR( i = 0; i < 1; i++ )
    1190             :     {
    1191          16 :         hShoeboxData->size[i] = 0;
    1192          16 :         move16();
    1193             :     }
    1194          16 :     return IVAS_ERR_OK;
    1195             : }
    1196             : 
    1197             : /*-------------------------------------------------------------------------
    1198             :  * ivas_shoebox_output_init()
    1199             :  *
    1200             :  * Initialize shoebox_output_t handle
    1201             :  *------------------------------------------------------------------------*/
    1202           4 : static ivas_error ivas_shoebox_output_init(
    1203             :     shoebox_output_t *hShoeboxOutput /* i/o: shoebox_output_t handle     */
    1204             : )
    1205             : {
    1206             :     ivas_error error;
    1207             : 
    1208           4 :     IF( hShoeboxOutput == NULL )
    1209             :     {
    1210           0 :         return IVAS_ERR_WRONG_PARAMS;
    1211             :     }
    1212             : 
    1213           4 :     hShoeboxOutput->n_sources = 0;
    1214           4 :     hShoeboxOutput->n_ref = 0;
    1215           4 :     move16();
    1216           4 :     move16();
    1217             : 
    1218           4 :     IF( NE_32( ( error = ivas_shoebox_data_init( &hShoeboxOutput->times ) ), IVAS_ERR_OK ) )
    1219             :     {
    1220           0 :         return error;
    1221             :     }
    1222             : 
    1223           4 :     IF( NE_32( ( error = ivas_shoebox_data_init( &hShoeboxOutput->gains ) ), IVAS_ERR_OK ) )
    1224             :     {
    1225           0 :         return error;
    1226             :     }
    1227             : 
    1228           4 :     IF( NE_32( ( error = ivas_shoebox_data_init( &hShoeboxOutput->az_angle ) ), IVAS_ERR_OK ) )
    1229             :     {
    1230           0 :         return error;
    1231             :     }
    1232             : 
    1233           4 :     IF( NE_32( ( error = ivas_shoebox_data_init( &hShoeboxOutput->el_angle ) ), IVAS_ERR_OK ) )
    1234             :     {
    1235           0 :         return error;
    1236             :     }
    1237             : 
    1238           4 :     return IVAS_ERR_OK;
    1239             : }
    1240             : 
    1241             : 
    1242             : /*-------------------------------------------------------------------------
    1243             :  * ivas_shoebox_config_init()
    1244             :  *
    1245             :  * Initialize shoebox_config_t handle
    1246             :  *------------------------------------------------------------------------*/
    1247             : 
    1248           4 : static ivas_error ivas_shoebox_config_init_params(
    1249             :     shoebox_config_t *hShoeboxConfig /* i/o: shoebox_config_t handle     */
    1250             : )
    1251             : {
    1252             :     Word16 i;
    1253             : 
    1254           4 :     IF( hShoeboxConfig == NULL )
    1255             :     {
    1256           0 :         return IVAS_ERR_WRONG_PARAMS;
    1257             :     }
    1258             : 
    1259           4 :     hShoeboxConfig->room_L_fx = 0;
    1260           4 :     hShoeboxConfig->room_W_fx = 0;
    1261           4 :     hShoeboxConfig->room_H_fx = 0;
    1262           4 :     move32();
    1263           4 :     move32();
    1264           4 :     move32();
    1265          28 :     FOR( i = 0; i < IVAS_ROOM_ABS_COEFF; i++ )
    1266             :     {
    1267          24 :         hShoeboxConfig->abs_coeff_fx[i] = 0;
    1268          24 :         move32();
    1269             :     }
    1270          16 :     FOR( i = 0; i < 3; i++ )
    1271             :     {
    1272          12 :         hShoeboxConfig->list_orig_fx[i] = 0;
    1273          12 :         move32();
    1274             :     }
    1275           4 :     return IVAS_ERR_OK;
    1276             : }
    1277             : 
    1278             : 
    1279             : /*-------------------------------------------------------------------------
    1280             :  * ivas_shoebox_obj_init()
    1281             :  *
    1282             :  * Initialize shoebox_obj_t handle
    1283             :  *------------------------------------------------------------------------*/
    1284             : 
    1285           4 : static ivas_error ivas_shoebox_obj_init(
    1286             :     shoebox_obj_t *hShoeboxObj /* i/o: shoebox_obj_t handle     */
    1287             : )
    1288             : {
    1289             :     Word16 i;
    1290             :     ivas_error error;
    1291             : 
    1292           4 :     IF( hShoeboxObj == NULL )
    1293             :     {
    1294           0 :         return IVAS_ERR_WRONG_PARAMS;
    1295             :     }
    1296             : 
    1297           4 :     hShoeboxObj->isCartesian = 0;
    1298           4 :     hShoeboxObj->isRelative = 0;
    1299           4 :     hShoeboxObj->isZHeight = 0;
    1300           4 :     hShoeboxObj->isRadians = 0;
    1301           4 :     hShoeboxObj->MAX_SOURCES = 0;
    1302           4 :     hShoeboxObj->max_bands = 0;
    1303           4 :     hShoeboxObj->REF_ORDER = 0;
    1304           4 :     move16();
    1305           4 :     move16();
    1306           4 :     move16();
    1307           4 :     move16();
    1308           4 :     move16();
    1309           4 :     move16();
    1310           4 :     move16();
    1311         304 :     FOR( i = 0; i < 75; i++ )
    1312             :     {
    1313         300 :         hShoeboxObj->src_pos_fx[i] = 0;
    1314         300 :         move32();
    1315             :     }
    1316         104 :     FOR( i = 0; i < 25; i++ )
    1317             :     {
    1318         100 :         hShoeboxObj->src_dist_fx[i] = 0;
    1319         100 :         move32();
    1320             :     }
    1321          16 :     FOR( i = 0; i < 3; i++ )
    1322             :     {
    1323          12 :         hShoeboxObj->list_pos_fx[i] = 0;
    1324          12 :         move32();
    1325             :     }
    1326             : 
    1327           4 :     hShoeboxObj->nSrc = 0;
    1328           4 :     hShoeboxObj->radius_fx = 0;
    1329           4 :     hShoeboxObj->min_wall_dist_fx = 0;
    1330           4 :     hShoeboxObj->soundspeed_fx = 0;
    1331           4 :     hShoeboxObj->air_coeff_fx = 0;
    1332           4 :     move16();
    1333           4 :     move32();
    1334           4 :     move32();
    1335           4 :     move32();
    1336           4 :     move32();
    1337             : 
    1338           4 :     IF( NE_32( ( error = ivas_shoebox_config_init_params( &hShoeboxObj->cal ) ), IVAS_ERR_OK ) )
    1339             :     {
    1340           0 :         return error;
    1341             :     }
    1342             : 
    1343           4 :     return IVAS_ERR_OK;
    1344             : }
    1345             : 
    1346             : 
    1347             : /*-------------------------------------------------------------------------
    1348             :  * ivas_er_init_handle()
    1349             :  *
    1350             :  * Initialize early reflections handle
    1351             :  *------------------------------------------------------------------------*/
    1352             : 
    1353           4 : static ivas_error ivas_er_init_handle(
    1354             :     er_struct_t *reflections /* i/o: early reflections handle     */
    1355             : )
    1356             : {
    1357             :     Word16 i;
    1358             :     ivas_error error;
    1359           4 :     IF( reflections == NULL )
    1360             :     {
    1361           0 :         return IVAS_ERR_WRONG_PARAMS;
    1362             :     }
    1363           4 :     reflections->audio_config = IVAS_AUDIO_CONFIG_INVALID;
    1364           4 :     reflections->use_er = 0;
    1365           4 :     reflections->is_ready = 0;
    1366           4 :     reflections->circ_len = 0;
    1367           4 :     reflections->circ_insert = 0;
    1368           4 :     reflections->n_total_reflections = 0;
    1369           4 :     reflections->is_cartesian = 0;
    1370           4 :     reflections->is_relative = 0;
    1371           4 :     reflections->max_frame_size = 0;
    1372           4 :     reflections->output_Fs_fx = 0;
    1373           4 :     move16();
    1374           4 :     move16();
    1375           4 :     move16();
    1376           4 :     move16();
    1377           4 :     move16();
    1378           4 :     move16();
    1379           4 :     move16();
    1380           4 :     move32();
    1381           4 :     move32();
    1382           4 :     move32();
    1383         304 :     FOR( i = 0; i < 75; i++ )
    1384             :     {
    1385         300 :         reflections->source_positions_fx[i] = 0;
    1386         300 :         move16();
    1387             :     }
    1388          16 :     FOR( i = 0; i < 3; i++ )
    1389             :     {
    1390          12 :         reflections->user_origin_fx[i] = 0;
    1391          12 :         move32();
    1392          12 :         if ( EQ_16( i, 2 ) )
    1393             :         {
    1394           4 :             reflections->user_origin_fx[i] = ER_LIST_HEIGHT_FX; // Q22
    1395           4 :             move32();
    1396             :         }
    1397             :     }
    1398           4 :     reflections->circ_buffers = NULL;
    1399           4 :     reflections->closest_ch_idx = NULL;
    1400             : 
    1401           4 :     IF( NE_32( ( error = ivas_shoebox_output_init( &reflections->shoebox_data ) ), IVAS_ERR_OK ) )
    1402             :     {
    1403           0 :         return error;
    1404             :     }
    1405           4 :     IF( NE_32( ( error = ivas_shoebox_obj_init( &reflections->shoebox_lib ) ), IVAS_ERR_OK ) )
    1406             :     {
    1407           0 :         return error;
    1408             :     }
    1409           4 :     return IVAS_ERR_OK;
    1410             : }
    1411             : 
    1412             : /*-------------------------------------------------------------------------
    1413             :  * ivas_rend_initCrendWrapper()
    1414             :  *
    1415             :  * Allocate and initialize crend renderer handle
    1416             :  *------------------------------------------------------------------------*/
    1417             : 
    1418         428 : ivas_error ivas_rend_initCrendWrapper(
    1419             :     CREND_WRAPPER_HANDLE *pCrend,
    1420             :     const int16_t num_poses )
    1421             : {
    1422             :     Word16 i;
    1423             :     CREND_HANDLE hCrend;
    1424             :     Word16 pos_idx;
    1425             : 
    1426         428 :     IF( pCrend == NULL )
    1427             :     {
    1428           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" );
    1429             :     }
    1430             : 
    1431         428 :     IF( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL )
    1432             :     {
    1433           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" );
    1434             :     }
    1435             : 
    1436         428 :     ( *pCrend )->binaural_latency_ns = 0;
    1437         428 :     move32();
    1438         428 :     ( *pCrend )->hHrtfCrend = NULL;
    1439         428 :     ( *pCrend )->io_qfactor = 0;
    1440         428 :     move16();
    1441         428 :     ( *pCrend )->p_io_qfactor = &( *pCrend )->io_qfactor;
    1442             : 
    1443         856 :     FOR( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
    1444             :     {
    1445         428 :         hCrend = NULL;
    1446         428 :         IF( ( hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL )
    1447             :         {
    1448           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" );
    1449             :         }
    1450             : 
    1451         428 :         hCrend->lfe_delay_line_fx = NULL;
    1452             : 
    1453        7276 :         FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
    1454             :         {
    1455        6848 :             hCrend->freq_buffer_re_fx[i] = NULL;
    1456        6848 :             hCrend->freq_buffer_im_fx[i] = NULL;
    1457             :         }
    1458             : 
    1459        1284 :         FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
    1460             :         {
    1461         856 :             hCrend->prev_out_buffer_fx[i] = NULL;
    1462             :         }
    1463             : 
    1464         428 :         hCrend->hTrack = NULL;
    1465         428 :         hCrend->freq_buffer_re_diffuse_fx[0] = NULL;
    1466         428 :         hCrend->freq_buffer_re_diffuse_fx[1] = NULL;
    1467         428 :         hCrend->freq_buffer_im_diffuse_fx[0] = NULL;
    1468         428 :         hCrend->freq_buffer_im_diffuse_fx[1] = NULL;
    1469         428 :         hCrend->hReverb = NULL;
    1470         428 :         hCrend->reflections = NULL;
    1471         428 :         hCrend->delay_line_rw_index = 0;
    1472         428 :         hCrend->diffuse_delay_line_rw_index = 0;
    1473         428 :         move16();
    1474         428 :         move16();
    1475         428 :         hCrend->m_fYaw_fx = 0;
    1476         428 :         hCrend->m_fPitch_fx = 0;
    1477         428 :         hCrend->m_fRoll_fx = 0;
    1478         428 :         move32();
    1479         428 :         move32();
    1480         428 :         move32();
    1481             : 
    1482         428 :         ( *pCrend )->hCrend[pos_idx] = hCrend;
    1483             :     }
    1484             : 
    1485         428 :     return IVAS_ERR_OK;
    1486             : }
    1487             : 
    1488             : /*-------------------------------------------------------------------------
    1489             :  * ivas_rend_openMultiBinCrend()
    1490             :  *
    1491             :  * Allocate and initialize crend renderer handle
    1492             :  *------------------------------------------------------------------------*/
    1493             : 
    1494           0 : ivas_error ivas_rend_openMultiBinCrend(
    1495             :     CREND_WRAPPER_HANDLE *pCrend,
    1496             :     const AUDIO_CONFIG inConfig,
    1497             :     const AUDIO_CONFIG outConfig,
    1498             :     const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData,
    1499             :     const Word32 output_Fs )
    1500             : {
    1501             :     ivas_error error;
    1502             : 
    1503           0 :     if ( ( error = ivas_rend_openCrend( pCrend, inConfig, outConfig, NULL /*hRendCfg*/, NULL, NULL /* hHrtfStatistics */, output_Fs, pMultiBinPoseData->num_poses ) ) != IVAS_ERR_OK )
    1504             :     {
    1505           0 :         return error;
    1506             :     }
    1507             : 
    1508           0 :     return error;
    1509             : }
    1510             : 
    1511             : /*-------------------------------------------------------------------------
    1512             :  * ivas_rend_openCrend()
    1513             :  *
    1514             :  * Allocate and initialize crend renderer handle
    1515             :  *------------------------------------------------------------------------*/
    1516             : 
    1517         428 : ivas_error ivas_rend_openCrend(
    1518             :     CREND_WRAPPER_HANDLE *pCrend,
    1519             :     const AUDIO_CONFIG inConfig,
    1520             :     const AUDIO_CONFIG outConfig,
    1521             :     RENDER_CONFIG_DATA *hRendCfg,
    1522             :     HRTFS_CREND_HANDLE hSetOfHRTF,
    1523             :     HRTFS_STATISTICS_HANDLE hHrtfStatistics,
    1524             :     const Word32 output_Fs,
    1525             :     const Word16 num_poses )
    1526             : {
    1527             :     Word16 i, subframe_length;
    1528             :     Word32 max_total_ir_len;
    1529             :     HRTFS_HANDLE hHrtf;
    1530             :     CREND_HANDLE hCrend;
    1531             :     ivas_error error;
    1532             :     Word16 pos_idx;
    1533             : 
    1534         428 :     error = IVAS_ERR_OK;
    1535         428 :     move16();
    1536             : 
    1537         428 :     IF( ( error = ivas_rend_initCrendWrapper( pCrend, num_poses ) ) != IVAS_ERR_OK )
    1538             :     {
    1539           0 :         return error;
    1540             :     }
    1541             : 
    1542         428 :     subframe_length = extract_l( Mult_32_16( output_Fs, 164 ) ); /*( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES(i/o:164=(32768/FRAMES_PER_SEC)/MAX_PARAM_SPATIAL_SUBFRAMES*/
    1543             : 
    1544         428 :     IF( ( *pCrend )->hHrtfCrend == NULL )
    1545             :     {
    1546         428 :         IF( NE_32( ( error = ivas_rend_initCrend_fx( *pCrend, inConfig, outConfig, hSetOfHRTF, output_Fs ) ), IVAS_ERR_OK ) )
    1547             :         {
    1548           0 :             return error;
    1549             :         }
    1550             :     }
    1551             : 
    1552         856 :     for ( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
    1553             :     {
    1554         428 :         hCrend = ( *pCrend )->hCrend[pos_idx];
    1555         428 :         hHrtf = ( *pCrend )->hHrtfCrend;
    1556             : 
    1557         428 :         IF( hHrtf != NULL )
    1558             :         {
    1559         428 :             max_total_ir_len = L_mult0( hHrtf->max_num_iterations, subframe_length );
    1560             : 
    1561        4021 :             FOR( i = 0; i < hHrtf->max_num_ir; i++ )
    1562             :             {
    1563        3593 :                 IF( ( hCrend->freq_buffer_re_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1564             :                 {
    1565           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1566             :                 }
    1567        3593 :                 set_zero2_fx( hCrend->freq_buffer_re_fx[i], max_total_ir_len );
    1568             : 
    1569        3593 :                 IF( ( hCrend->freq_buffer_im_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1570             :                 {
    1571           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1572             :                 }
    1573        3593 :                 set_zero2_fx( hCrend->freq_buffer_im_fx[i], max_total_ir_len );
    1574             :             }
    1575             : 
    1576        1284 :             FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
    1577             :             {
    1578         856 :                 IF( ( hCrend->prev_out_buffer_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * subframe_length ) ) == NULL )
    1579             :                 {
    1580           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1581             :                 }
    1582         856 :                 set_zero_fx( hCrend->prev_out_buffer_fx[i], subframe_length );
    1583             :             }
    1584             : 
    1585         428 :             max_total_ir_len = L_mult0( (Word16) hHrtf->num_iterations_diffuse[0], subframe_length );
    1586             : 
    1587         428 :             IF( max_total_ir_len > 0 )
    1588             :             {
    1589         254 :                 IF( ( hCrend->freq_buffer_re_diffuse_fx[0] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1590             :                 {
    1591           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1592             :                 }
    1593         254 :                 IF( hHrtf->same_inv_diffuse_weight == 0 )
    1594             :                 {
    1595           0 :                     IF( ( hCrend->freq_buffer_re_diffuse_fx[1] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1596             :                     {
    1597           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1598             :                     }
    1599             :                 }
    1600             :                 ELSE
    1601             :                 {
    1602         254 :                     hCrend->freq_buffer_re_diffuse_fx[1] = NULL;
    1603             :                 }
    1604         254 :                 set_zero2_fx( hCrend->freq_buffer_re_diffuse_fx[0], max_total_ir_len );
    1605         254 :                 IF( hCrend->freq_buffer_re_diffuse_fx[1] != NULL )
    1606             :                 {
    1607           0 :                     set_zero2_fx( hCrend->freq_buffer_re_diffuse_fx[1], max_total_ir_len );
    1608             :                 }
    1609         254 :                 IF( ( hCrend->freq_buffer_im_diffuse_fx[0] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1610             :                 {
    1611           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1612             :                 }
    1613         254 :                 IF( hHrtf->same_inv_diffuse_weight == 0 )
    1614             :                 {
    1615           0 :                     IF( ( hCrend->freq_buffer_im_diffuse_fx[1] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1616             :                     {
    1617           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1618             :                     }
    1619             :                 }
    1620             :                 ELSE
    1621             :                 {
    1622         254 :                     hCrend->freq_buffer_im_diffuse_fx[1] = NULL;
    1623             :                 }
    1624         254 :                 set_zero2_fx( hCrend->freq_buffer_im_diffuse_fx[0], max_total_ir_len );
    1625         254 :                 IF( hCrend->freq_buffer_im_diffuse_fx[1] != NULL )
    1626             :                 {
    1627           0 :                     set_zero2_fx( hCrend->freq_buffer_im_diffuse_fx[1], max_total_ir_len );
    1628             :                 }
    1629             :             }
    1630             :             ELSE
    1631             :             {
    1632         174 :                 hCrend->freq_buffer_re_diffuse_fx[0] = NULL;
    1633         174 :                 hCrend->freq_buffer_im_diffuse_fx[0] = NULL;
    1634         174 :                 hCrend->freq_buffer_re_diffuse_fx[1] = NULL;
    1635         174 :                 hCrend->freq_buffer_im_diffuse_fx[1] = NULL;
    1636             :             }
    1637             : 
    1638         428 :             max_total_ir_len = add( extract_l( L_shr( L_add( L_shl( Mult_32_32( hHrtf->latency_s_fx, output_Fs ), 1 ), 1 ), 1 ) ), subframe_length ); /*(int16_t) ( hHrtf->latency_s * output_Fs + 0.5f ) + subframe_length;*/
    1639         428 :             IF( max_total_ir_len > 0 )
    1640             :             {
    1641         428 :                 IF( ( hCrend->lfe_delay_line_fx = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1642             :                 {
    1643           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1644             :                 }
    1645         428 :                 set_zero2_fx( hCrend->lfe_delay_line_fx, max_total_ir_len );
    1646             :             }
    1647             :             ELSE
    1648             :             {
    1649           0 :                 hCrend->lfe_delay_line_fx = NULL;
    1650             :             }
    1651             : 
    1652         428 :             IF( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
    1653             :             {
    1654         111 :                 IF( NE_32( ( error = ivas_reverb_open_fx( &( hCrend->hReverb ), hHrtfStatistics, hRendCfg, output_Fs ) ), IVAS_ERR_OK ) )
    1655             :                 {
    1656           0 :                     return error;
    1657             :                 }
    1658             : 
    1659         111 :                 IF( EQ_16( hRendCfg->roomAcoustics.use_er, 1 ) )
    1660             :                 {
    1661             : 
    1662             :                     /* Allocate memory for reflections */
    1663           4 :                     hCrend->reflections = (er_struct_t *) malloc( sizeof( er_struct_t ) );
    1664           4 :                     IF( !hCrend->reflections )
    1665             :                     {
    1666           0 :                         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections" );
    1667             :                     }
    1668           4 :                     IF( NE_32( ( error = ivas_er_init_handle( hCrend->reflections ) ), IVAS_ERR_OK ) )
    1669             :                     {
    1670           0 :                         return error;
    1671             :                     }
    1672             : 
    1673           4 :                     hCrend->reflections->use_er = hRendCfg->roomAcoustics.use_er;
    1674           4 :                     hCrend->reflections->lowComplexity = hRendCfg->roomAcoustics.lowComplexity;
    1675           4 :                     move16();
    1676           4 :                     move32();
    1677             : 
    1678             :                     /* Set sample rate and frame size */
    1679             : 
    1680           4 :                     hCrend->reflections->output_Fs_fx = output_Fs; // Q0
    1681           4 :                     move32();
    1682             : 
    1683           4 :                     hCrend->reflections->max_frame_size = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) );
    1684           4 :                     move32();
    1685             : 
    1686             :                     /* Init Shoebox */
    1687           4 :                     ivas_shoebox_config_init( &hCrend->reflections->shoebox_lib.cal, hRendCfg );
    1688             : 
    1689             :                     /* Init and compute Reflections */
    1690           4 :                     IF( NE_32( ( error = ivas_er_init( hCrend->reflections, inConfig ) ), IVAS_ERR_OK ) )
    1691             :                     {
    1692           0 :                         return error;
    1693             :                     }
    1694             :                 }
    1695             :                 ELSE
    1696             :                 {
    1697         107 :                     hCrend->reflections = NULL;
    1698             :                 }
    1699             :             }
    1700             :             ELSE
    1701             :             {
    1702         317 :                 hCrend->hReverb = NULL;
    1703             :             }
    1704             : 
    1705         428 :             ( *pCrend )->binaural_latency_ns = Mult_32_32( ( *pCrend )->hHrtfCrend->latency_s_fx, (Word32) 1000000000 );
    1706         428 :             move32();
    1707             :         }
    1708             : 
    1709         428 :         ( *pCrend )->hCrend[pos_idx] = hCrend;
    1710             :     }
    1711         428 :     return IVAS_ERR_OK;
    1712             : }
    1713             : 
    1714             : /*-------------------------------------------------------------------------
    1715             :  * ivas_rend_closeCrend()
    1716             :  *
    1717             :  * Deallocate Crend renderer handle
    1718             :  *------------------------------------------------------------------------*/
    1719             : 
    1720       40194 : void ivas_rend_closeCrend(
    1721             :     CREND_WRAPPER_HANDLE *pCrend,
    1722             :     const Word16 num_poses )
    1723             : {
    1724             :     Word16 i;
    1725             :     Word16 pos_idx;
    1726             :     CREND_HANDLE hCrend;
    1727             : 
    1728       40194 :     test();
    1729       40194 :     IF( pCrend == NULL || *pCrend == NULL )
    1730             :     {
    1731       39766 :         return;
    1732             :     }
    1733             : 
    1734         428 :     IF( ( *pCrend )->hHrtfCrend != NULL )
    1735             :     {
    1736         428 :         ivas_hrtf_close( &( *pCrend )->hHrtfCrend );
    1737             :     }
    1738             : 
    1739         856 :     FOR( pos_idx = 0; pos_idx < num_poses; pos_idx++ )
    1740             :     {
    1741         428 :         hCrend = ( *pCrend )->hCrend[pos_idx];
    1742         428 :         IF( hCrend != NULL )
    1743             :         {
    1744        7276 :             FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
    1745             :             {
    1746        6848 :                 IF( hCrend->freq_buffer_re_fx[i] != NULL )
    1747             :                 {
    1748        3593 :                     free( hCrend->freq_buffer_re_fx[i] );
    1749        3593 :                     hCrend->freq_buffer_re_fx[i] = NULL;
    1750             :                 }
    1751        6848 :                 IF( hCrend->freq_buffer_im_fx[i] != NULL )
    1752             :                 {
    1753        3593 :                     free( hCrend->freq_buffer_im_fx[i] );
    1754        3593 :                     hCrend->freq_buffer_im_fx[i] = NULL;
    1755             :                 }
    1756             :             }
    1757             : 
    1758        1284 :             FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
    1759             :             {
    1760         856 :                 IF( hCrend->prev_out_buffer_fx[i] != NULL )
    1761             :                 {
    1762         856 :                     free( hCrend->prev_out_buffer_fx[i] );
    1763         856 :                     hCrend->prev_out_buffer_fx[i] = NULL;
    1764             :                 }
    1765             :             }
    1766             : 
    1767         428 :             IF( hCrend->lfe_delay_line_fx != NULL )
    1768             :             {
    1769         428 :                 free( hCrend->lfe_delay_line_fx );
    1770         428 :                 hCrend->lfe_delay_line_fx = NULL;
    1771             :             }
    1772         428 :             IF( hCrend->freq_buffer_re_diffuse_fx[0] != NULL )
    1773             :             {
    1774         254 :                 free( hCrend->freq_buffer_re_diffuse_fx[0] );
    1775         254 :                 hCrend->freq_buffer_re_diffuse_fx[0] = NULL;
    1776             :             }
    1777             : 
    1778         428 :             IF( hCrend->freq_buffer_im_diffuse_fx[0] != NULL )
    1779             :             {
    1780         254 :                 free( hCrend->freq_buffer_im_diffuse_fx[0] );
    1781         254 :                 hCrend->freq_buffer_im_diffuse_fx[0] = NULL;
    1782             :             }
    1783             : 
    1784         428 :             IF( hCrend->freq_buffer_re_diffuse_fx[1] != NULL )
    1785             :             {
    1786           0 :                 free( hCrend->freq_buffer_re_diffuse_fx[1] );
    1787           0 :                 hCrend->freq_buffer_re_diffuse_fx[1] = NULL;
    1788             :             }
    1789             : 
    1790         428 :             IF( hCrend->freq_buffer_im_diffuse_fx[1] != NULL )
    1791             :             {
    1792           0 :                 free( hCrend->freq_buffer_im_diffuse_fx[1] );
    1793           0 :                 hCrend->freq_buffer_im_diffuse_fx[1] = NULL;
    1794             :             }
    1795         428 :             IF( hCrend->hTrack != NULL )
    1796             :             {
    1797           0 :                 free( hCrend->hTrack );
    1798           0 :                 hCrend->hTrack = NULL;
    1799             :             }
    1800             : 
    1801         428 :             ivas_reverb_close( &hCrend->hReverb );
    1802             : 
    1803         428 :             IF( hCrend->reflections != NULL )
    1804             :             {
    1805           4 :                 IF( hCrend->reflections->closest_ch_idx != NULL )
    1806             :                 {
    1807           4 :                     free( hCrend->reflections->closest_ch_idx );
    1808           4 :                     hCrend->reflections->closest_ch_idx = NULL;
    1809             :                 }
    1810           4 :                 IF( hCrend->reflections->circ_buffers != NULL )
    1811             :                 {
    1812           4 :                     free( hCrend->reflections->circ_buffers );
    1813           4 :                     hCrend->reflections->circ_buffers = NULL;
    1814             :                 }
    1815           4 :                 free( hCrend->reflections );
    1816           4 :                 hCrend->reflections = NULL;
    1817             :             }
    1818         428 :             free( hCrend );
    1819         428 :             hCrend = NULL;
    1820         428 :             ( *pCrend )->hCrend[pos_idx] = hCrend;
    1821             :         }
    1822             :     }
    1823             : 
    1824         428 :     free( *pCrend );
    1825         428 :     *pCrend = NULL;
    1826             : 
    1827         428 :     return;
    1828             : }
    1829             : 
    1830             : 
    1831             : /*-------------------------------------------------------------------------
    1832             :  * ivas_rend_closeCldfbRend()
    1833             :  *
    1834             :  * Close CLDFB based fastconv binaural renderer memories
    1835             :  *------------------------------------------------------------------------*/
    1836             : 
    1837           0 : void ivas_rend_closeCldfbRend(
    1838             :     CLDFB_REND_WRAPPER *pCldfbRend )
    1839             : {
    1840           0 :     IF( pCldfbRend->hCldfbRend->hInputSetup != NULL )
    1841             :     {
    1842           0 :         free( pCldfbRend->hCldfbRend->hInputSetup );
    1843           0 :         pCldfbRend->hCldfbRend->hInputSetup = NULL;
    1844             :     }
    1845             : 
    1846           0 :     ivas_binRenderer_close_fx( &pCldfbRend->hCldfbRend );
    1847           0 :     ivas_binaural_hrtf_close( &pCldfbRend->hHrtfFastConv );
    1848           0 :     ivas_HRTF_fastconv_binary_close_fx( &pCldfbRend->hHrtfFastConv );
    1849             : 
    1850           0 :     return;
    1851             : }
    1852             : 
    1853             : /*-----------------------------------------------------------------------------------------*
    1854             :  * Function ivas_rend_crendConvolver()
    1855             :  *
    1856             :  * Convolver block
    1857             :  *-----------------------------------------------------------------------------------------*/
    1858             : 
    1859      578167 : static ivas_error ivas_rend_crendConvolver(
    1860             :     const CREND_WRAPPER *pCrend,
    1861             :     AUDIO_CONFIG inConfig,
    1862             :     AUDIO_CONFIG outConfig,
    1863             :     Word32 *pcm_in[],  // Qx
    1864             :     Word32 *pcm_out[], // Qx
    1865             :     const Word32 output_Fs,
    1866             :     const Word16 i_ts,
    1867             :     const Word16 pos_idx )
    1868             : {
    1869             :     Word16 i, j, k, m;
    1870             :     Word16 subframe_length, idx_in;
    1871             :     Word16 lfe_idx_in;
    1872             :     Word32 offset, offset_in, offset_diffuse;
    1873             :     Word16 index_in;
    1874             :     Word16 nchan_in, nchan_out;
    1875             :     const Word32 *pIn;
    1876             :     Word32 *pFreq_buf_re, *pFreq_buf_im;
    1877             :     Word32 *pFreq_buf2_re, *pFreq_buf2_im;
    1878             :     const Word32 *pFreq_filt_re, *pFreq_filt_im;
    1879             :     Word32 pOut[L_FRAME48k * 2];
    1880             :     Word32 tmp_out_re[L_FRAME48k];
    1881             :     Word32 tmp_out_im[L_FRAME48k];
    1882             :     CREND_HANDLE hCrend;
    1883             :     ivas_error error;
    1884             : 
    1885      578167 :     hCrend = pCrend->hCrend[pos_idx];
    1886             : 
    1887      578167 :     IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) )
    1888             :     {
    1889           0 :         return error;
    1890             :     }
    1891             : 
    1892      578167 :     IF( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) )
    1893             :     {
    1894           0 :         return error;
    1895             :     }
    1896             : 
    1897             :     /* subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; */
    1898      578167 :     subframe_length = extract_l( Mpy_32_32_r( output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) );
    1899             : 
    1900      578167 :     lfe_idx_in = -1;
    1901      578167 :     move16();
    1902      578167 :     IF( EQ_32( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) )
    1903             :     {
    1904      529537 :         IF( NE_32( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
    1905             :         {
    1906      529537 :             lfe_idx_in = LFE_CHANNEL;
    1907      529537 :             move16();
    1908             :         }
    1909             :         ELSE
    1910             :         {
    1911           0 :             assert( 0 && "Custom LS not supported in CRend" );
    1912             :         }
    1913             :     }
    1914             : 
    1915      578167 :     offset = L_mult0( hCrend->delay_line_rw_index, subframe_length );                 /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */
    1916      578167 :     offset_diffuse = L_mult0( hCrend->diffuse_delay_line_rw_index, subframe_length ); /* subframe_length *( pCrend->hHrtfCrend->num_iterations_diffuse[0] - 1 ); */
    1917             : 
    1918      578167 :     IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    1919             :     {
    1920      397929 :         set32_fx( &hCrend->freq_buffer_re_diffuse_fx[0][offset_diffuse], 0, subframe_length );
    1921      397929 :         set32_fx( &hCrend->freq_buffer_im_diffuse_fx[0][offset_diffuse], 0, subframe_length );
    1922      397929 :         if ( pCrend->hHrtfCrend->same_inv_diffuse_weight == 0 )
    1923             :         {
    1924           0 :             set32_fx( &hCrend->freq_buffer_re_diffuse_fx[1][offset_diffuse], 0, subframe_length );
    1925           0 :             set32_fx( &hCrend->freq_buffer_im_diffuse_fx[1][offset_diffuse], 0, subframe_length );
    1926             :         }
    1927             :     }
    1928             : 
    1929      578167 :     i = 0;
    1930      578167 :     move16();
    1931     6869813 :     FOR( idx_in = 0; idx_in < nchan_in; idx_in++ )
    1932             :     {
    1933     6291646 :         pIn = &pcm_in[idx_in][i_ts * subframe_length];
    1934             : 
    1935     6291646 :         IF( NE_16( idx_in, lfe_idx_in ) )
    1936             :         {
    1937     5762109 :             IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    1938             :             {
    1939     4124019 :                 IF( pCrend->hHrtfCrend->same_inv_diffuse_weight )
    1940             :                 {
    1941     4124019 :                     pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[0][offset_diffuse];
    1942     4124019 :                     pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[0][offset_diffuse];
    1943     4124019 :                     pFreq_filt_re = &hCrend->freq_buffer_re_fx[i][offset];
    1944     4124019 :                     pFreq_filt_im = &hCrend->freq_buffer_im_fx[i][offset];
    1945             : 
    1946   408095926 :                     FOR( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ )
    1947             :                     {
    1948   403971907 :                         pFreq_buf_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[0][i] ), pFreq_buf_re[k] ); // Qx
    1949   403971907 :                         pFreq_buf_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[0][i] ), pFreq_buf_im[k] ); // Qx
    1950   403971907 :                         move32();
    1951   403971907 :                         move32();
    1952             :                     }
    1953             :                 }
    1954             :                 ELSE
    1955             :                 {
    1956           0 :                     pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[0][offset_diffuse];
    1957           0 :                     pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[0][offset_diffuse];
    1958           0 :                     pFreq_buf2_re = &hCrend->freq_buffer_re_diffuse_fx[1][offset_diffuse];
    1959           0 :                     pFreq_buf2_im = &hCrend->freq_buffer_im_diffuse_fx[1][offset_diffuse];
    1960           0 :                     pFreq_filt_re = &hCrend->freq_buffer_re_fx[i][offset];
    1961           0 :                     pFreq_filt_im = &hCrend->freq_buffer_im_fx[i][offset];
    1962             : 
    1963           0 :                     for ( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ )
    1964             :                     {
    1965           0 :                         pFreq_buf_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[0][i] ), pFreq_buf_re[k] ); // Qx
    1966           0 :                         pFreq_buf_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[0][i] ), pFreq_buf_im[k] ); // Qx
    1967           0 :                         move32();
    1968           0 :                         move32();
    1969           0 :                         pFreq_buf2_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[1][i] ), pFreq_buf2_re[k] ); // Qx
    1970           0 :                         pFreq_buf2_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[1][i] ), pFreq_buf2_im[k] ); // Qx
    1971           0 :                         move32();
    1972           0 :                         move32();
    1973             :                     }
    1974             :                 }
    1975             :             }
    1976     5762109 :             pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset]; // Qx
    1977     5762109 :             pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset]; // Qx
    1978             : 
    1979             : 
    1980     5762109 :             ivas_mdft_fx( pIn, pFreq_buf_re, pFreq_buf_im, subframe_length, subframe_length );
    1981             : #ifdef DEBUGGING
    1982             :             dbgwrite_txt( (const float *) pFreq_buf_re, subframe_length, "Fixed_pFreq_buf_re_mdft.txt", NULL );
    1983             :             dbgwrite_txt( (const float *) pFreq_buf_im, subframe_length, "Fixed_pFreq_buf_im_mdft.txt", NULL );
    1984             : #endif
    1985     5762109 :             i = add( i, 1 );
    1986             :         }
    1987             :     }
    1988             : 
    1989     1734501 :     FOR( j = 0; j < nchan_out; j++ )
    1990             :     {
    1991     1156334 :         set32_fx( tmp_out_re, 0, subframe_length );
    1992     1156334 :         set32_fx( tmp_out_im, 0, subframe_length );
    1993     1156334 :         i = 0;
    1994     1156334 :         move16();
    1995    13739626 :         FOR( idx_in = 0; idx_in < nchan_in; idx_in++ )
    1996             :         {
    1997    12583292 :             IF( NE_16( idx_in, lfe_idx_in ) )
    1998             :             {
    1999    11524218 :                 offset = 0;
    2000    11524218 :                 move16();
    2001   196271394 :                 FOR( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ )
    2002             :                 {
    2003   184747176 :                     index_in = add( add( hCrend->delay_line_rw_index, sub( pCrend->hHrtfCrend->max_num_iterations, pCrend->hHrtfCrend->num_iterations[i][j] ) ), add( m, 1 ) );
    2004   184747176 :                     index_in = index_in % ( pCrend->hHrtfCrend->max_num_iterations );
    2005   184747176 :                     move16();
    2006   184747176 :                     offset_in = L_mult0( index_in, subframe_length );
    2007             : 
    2008   184747176 :                     pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset_in];              // Qx
    2009   184747176 :                     pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset_in];              // Qx
    2010   184747176 :                     pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re_fx[i][j][offset]; // Q29
    2011   184747176 :                     pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im_fx[i][j][offset]; // Q29
    2012             : 
    2013 24683991662 :                     FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ )
    2014             :                     {
    2015 24499244486 :                         tmp_out_re[k] = L_add( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), tmp_out_re[k] ); // Qx - 2
    2016 24499244486 :                         tmp_out_im[k] = L_add( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), tmp_out_im[k] ); // Qx - 2
    2017 24499244486 :                         move32();
    2018 24499244486 :                         move32();
    2019             :                     }
    2020             : 
    2021   184747176 :                     offset = L_add( offset, k );
    2022             :                 }
    2023    11524218 :                 i = add( i, 1 );
    2024             :             }
    2025             :         }
    2026             : 
    2027     1156334 :         offset = 0;
    2028     1156334 :         move16();
    2029    32990654 :         FOR( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ )
    2030             :         {
    2031    31834320 :             index_in = add( hCrend->diffuse_delay_line_rw_index, add( m, 1 ) );
    2032    31834320 :             index_in = index_in % pCrend->hHrtfCrend->num_iterations_diffuse[0];
    2033    31834320 :             move16();
    2034    31834320 :             offset_diffuse = L_mult0( index_in, subframe_length );
    2035    31834320 :             if ( pCrend->hHrtfCrend->same_inv_diffuse_weight )
    2036             :             {
    2037    31834320 :                 pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[0][offset_diffuse];
    2038    31834320 :                 pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[0][offset_diffuse];
    2039             :             }
    2040             :             else
    2041             :             {
    2042           0 :                 pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[j][offset_diffuse];
    2043           0 :                 pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[j][offset_diffuse];
    2044             :             }
    2045    31834320 :             pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re_fx[j][offset]; // Q31
    2046    31834320 :             pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im_fx[j][offset]; // Q31
    2047  2327126460 :             FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ )
    2048             :             {
    2049  2295292140 :                 tmp_out_re[k] = L_add( L_shr( Msub_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_re[k] ), pFreq_buf_im[k], pFreq_filt_im[k] ), 2 ), tmp_out_re[k] ); // Qx - 2
    2050  2295292140 :                 tmp_out_im[k] = L_add( L_shr( Madd_32_32( Mpy_32_32( pFreq_buf_re[k], pFreq_filt_im[k] ), pFreq_buf_im[k], pFreq_filt_re[k] ), 2 ), tmp_out_im[k] ); // Qx - 2
    2051  2295292140 :                 move32();
    2052  2295292140 :                 move32();
    2053             :             }
    2054    31834320 :             offset = L_add( offset, k );
    2055    31834320 :             move32();
    2056             :         }
    2057             : 
    2058     1156334 :         ivas_imdft_fx( tmp_out_re, tmp_out_im, pOut, subframe_length );
    2059     1156334 :         scale_sig32( pOut, shl( subframe_length, 1 ), 2 );
    2060             : #ifdef DEBUGGING
    2061             :         dbgwrite_txt( (const float *) pOut, subframe_length << 1, "Fixed_imdft_out.txt", NULL );
    2062             : #endif
    2063     1156334 :         pFreq_buf_re = &pcm_out[j][i_ts * subframe_length];
    2064   275958894 :         FOR( k = 0; k < subframe_length; k++ )
    2065             :         {
    2066   274802560 :             pFreq_buf_re[k] = L_add( pOut[k], hCrend->prev_out_buffer_fx[j][k] ); // Qx
    2067   274802560 :             hCrend->prev_out_buffer_fx[j][k] = pOut[k + subframe_length];         // Qx
    2068   274802560 :             move32();
    2069   274802560 :             move32();
    2070             :         }
    2071             :     }
    2072             : 
    2073      578167 :     hCrend->delay_line_rw_index = add( hCrend->delay_line_rw_index, 1 );
    2074      578167 :     hCrend->delay_line_rw_index = hCrend->delay_line_rw_index % ( pCrend->hHrtfCrend->max_num_iterations );
    2075      578167 :     move16();
    2076      578167 :     move16();
    2077      578167 :     IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    2078             :     {
    2079      397929 :         hCrend->diffuse_delay_line_rw_index = add( hCrend->diffuse_delay_line_rw_index, 1 );
    2080      397929 :         hCrend->diffuse_delay_line_rw_index = hCrend->diffuse_delay_line_rw_index % ( pCrend->hHrtfCrend->num_iterations_diffuse[0] );
    2081      397929 :         move16();
    2082      397929 :         move16();
    2083             :     }
    2084             : 
    2085      578167 :     return IVAS_ERR_OK;
    2086             : }
    2087             : 
    2088             : 
    2089             : /*-----------------------------------------------------------------------------------------*
    2090             :  * Function ivas_rend_crendProcessSubframe()
    2091             :  *
    2092             :  *
    2093             :  *-----------------------------------------------------------------------------------------*/
    2094             : 
    2095      326724 : ivas_error ivas_rend_crendProcessSubframe(
    2096             :     const CREND_WRAPPER *pCrend,                                /* i/o: Crend wrapper handle                    */
    2097             :     const AUDIO_CONFIG inConfig,                                /* i  : input audio configuration               */
    2098             :     const AUDIO_CONFIG outConfig,                               /* i  : output audio configuration              */
    2099             :     const DECODER_CONFIG_HANDLE hDecoderConfig,                 /* i  : decoder config. structure               */
    2100             :     const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i  : combined orientation handle             */
    2101             :     const IVAS_OUTPUT_SETUP_HANDLE hIntSetup,                   /* i  : internal setup handle                   */
    2102             :     const EFAP_HANDLE hEFAPdata,                                /* i  : EFAP handle                             */
    2103             :     DECODER_TC_BUFFER_HANDLE hTcBuffer,                         /* i/o: JBM handle                              */
    2104             :     Word32 *input_f[],                                          /* i  : transport channels                   Qx */
    2105             :     Word32 *output[],                                           /* i/o: input/output audio channels          Qx */
    2106             :     const Word16 n_samples_to_render,                           /* i  : output frame length per channel         */
    2107             :     const Word32 output_Fs                                      /* i  : output sampling rate                    */
    2108             :     ,
    2109             :     const Word16 pos_idx )
    2110             : {
    2111             :     Word16 subframe_idx, subframe_len;
    2112             :     Word16 nchan_out, nchan_in, ch, first_sf, last_sf, slot_size, slots_to_render;
    2113             :     Word32 *tc_local_fx[MAX_OUTPUT_CHANNELS];
    2114             :     Word32 pcm_tmp_fx[BINAURAL_CHANNELS][L_FRAME48k];
    2115             :     Word32 *p_pcm_tmp_fx[BINAURAL_CHANNELS];
    2116             :     IVAS_REND_AudioConfigType inConfigType;
    2117             :     ivas_error error;
    2118             :     Word8 combinedOrientationEnabled;
    2119             :     CREND_HANDLE hCrend;
    2120      326724 :     hCrend = pCrend->hCrend[pos_idx];
    2121             : 
    2122      326724 :     combinedOrientationEnabled = 0;
    2123      326724 :     move16();
    2124      326724 :     IF( hCombinedOrientationData != NULL )
    2125             :     {
    2126        4150 :         if ( hCombinedOrientationData->enableCombinedOrientation[0] != 0 )
    2127             :         {
    2128        4150 :             combinedOrientationEnabled = 1;
    2129        4150 :             move16();
    2130             :         }
    2131             :     }
    2132             : 
    2133      326724 :     push_wmops( "ivas_rend_crendProcessSubframe" );
    2134      326724 :     inConfigType = getAudioConfigType( inConfig );
    2135             : 
    2136      326724 :     IF( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) )
    2137             :     {
    2138           0 :         return error;
    2139             :     }
    2140             : 
    2141      326724 :     IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) )
    2142             :     {
    2143           0 :         return error;
    2144             :     }
    2145             : 
    2146     3948412 :     FOR( ch = 0; ch < nchan_in; ch++ )
    2147             :     {
    2148     3621688 :         tc_local_fx[ch] = input_f[ch];
    2149             :     }
    2150      980172 :     FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    2151             :     {
    2152      653448 :         p_pcm_tmp_fx[ch] = pcm_tmp_fx[ch];
    2153             :     }
    2154             : 
    2155      326724 :     IF( hTcBuffer != NULL )
    2156             :     {
    2157       24180 :         slot_size = hTcBuffer->n_samples_granularity;
    2158       24180 :         move16();
    2159             : 
    2160             :         /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    2161       24180 :         slots_to_render = s_min( sub( hTcBuffer->num_slots, hTcBuffer->slots_rendered ), idiv1616( n_samples_to_render, slot_size ) );
    2162       24180 :         first_sf = hTcBuffer->subframes_rendered;
    2163       24180 :         move16();
    2164       24180 :         last_sf = first_sf;
    2165       24180 :         move16();
    2166             : 
    2167      118237 :         WHILE( slots_to_render > 0 )
    2168             :         {
    2169       94057 :             slots_to_render = sub( slots_to_render, hTcBuffer->subframe_nbslots[last_sf] );
    2170       94057 :             last_sf = add( last_sf, 1 );
    2171             :         }
    2172             : 
    2173       24180 :         subframe_len = -1; /* will be set later */
    2174       24180 :         move16();
    2175             :     }
    2176             :     ELSE
    2177             :     {
    2178             :         Word16 n_den, den, last_sf_tmp;
    2179             : 
    2180      302544 :         SWITCH( output_Fs )
    2181             :         {
    2182      302544 :             case 48000:
    2183      302544 :                 subframe_len = L_SUBFRAME_48k;
    2184      302544 :                 move16();
    2185      302544 :                 BREAK;
    2186           0 :             case 32000:
    2187           0 :                 subframe_len = L_SUBFRAME_32k;
    2188           0 :                 move16();
    2189           0 :                 BREAK;
    2190           0 :             case 16000:
    2191             :             default:
    2192           0 :                 subframe_len = L_SUBFRAME_16k;
    2193           0 :                 move16();
    2194           0 :                 BREAK;
    2195             :         }
    2196             : 
    2197      302544 :         first_sf = 0;
    2198      302544 :         move16();
    2199      302544 :         last_sf = idiv1616( n_samples_to_render, subframe_len );
    2200             : 
    2201      302544 :         n_den = norm_s( subframe_len );
    2202      302544 :         den = shl( subframe_len, n_den );
    2203      302544 :         last_sf_tmp = div_s( n_samples_to_render, den );
    2204      302544 :         last_sf = shr( last_sf_tmp, sub( 15, n_den ) );
    2205             :     }
    2206             : 
    2207      904891 :     FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    2208             :     {
    2209      578167 :         if ( hTcBuffer != NULL )
    2210             :         {
    2211       94057 :             subframe_len = imult1616( hTcBuffer->subframe_nbslots[subframe_idx], hTcBuffer->n_samples_granularity );
    2212             :         }
    2213             : 
    2214             :         /* Early Reflections */
    2215      578167 :         IF( hCrend->reflections != NULL )
    2216             :         {
    2217        5800 :             test();
    2218        5800 :             IF( EQ_32( hCrend->reflections->use_er, 1 ) && EQ_32( hCrend->reflections->is_ready, 1 ) )
    2219             :             {
    2220        5800 :                 IF( NE_32( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local_fx, inConfig ) ), IVAS_ERR_OK ) )
    2221             :                 {
    2222           0 :                     return error;
    2223             :                 }
    2224             :             }
    2225             :         }
    2226             : 
    2227      578167 :         test();
    2228      578167 :         IF( hDecoderConfig && combinedOrientationEnabled )
    2229             :         {
    2230             :             /* Rotation in SHD for:
    2231             :                 MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL
    2232             :                 SBA SPAR -> BINAURAL or BINAURAL_ROOM
    2233             :             */
    2234       16600 :             test();
    2235       16600 :             test();
    2236       16600 :             test();
    2237       16600 :             IF( EQ_32( inConfig, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) )
    2238             :             {
    2239         600 :                 rotateFrame_shd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, 0 );
    2240             :             }
    2241             :             /* Rotation in SD for MC -> BINAURAL_ROOM */
    2242       16000 :             ELSE IF( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup )
    2243             :             {
    2244       16000 :                 rotateFrame_sd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, hEFAPdata, 0 );
    2245             :             }
    2246             :         }
    2247             : 
    2248      578167 :         test();
    2249      578167 :         IF( EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
    2250             :         {
    2251      578167 :             IF( NE_32( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, tc_local_fx, p_pcm_tmp_fx, output_Fs, 0, pos_idx ) ), IVAS_ERR_OK ) )
    2252             :             {
    2253           0 :                 return error;
    2254             :             }
    2255             : 
    2256      578167 :             IF( pCrend->hCrend[0]->hReverb != NULL )
    2257             :             {
    2258      103880 :                 IF( NE_32( ( error = ivas_reverb_process_fx( pCrend->hCrend[pos_idx]->hReverb, inConfig, 1, tc_local_fx, p_pcm_tmp_fx, 0 ) ), IVAS_ERR_OK ) )
    2259             :                 {
    2260           0 :                     return error;
    2261             :                 }
    2262             :             }
    2263             : 
    2264     6869813 :             FOR( ch = 0; ch < nchan_in; ch++ )
    2265             :             {
    2266     6291646 :                 tc_local_fx[ch] += subframe_len;
    2267             :             }
    2268     1734501 :             FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    2269             :             {
    2270     1156334 :                 p_pcm_tmp_fx[ch] += subframe_len;
    2271             :             }
    2272             : 
    2273      578167 :             if ( hTcBuffer != NULL )
    2274             :             {
    2275       94057 :                 hTcBuffer->slots_rendered = add( hTcBuffer->subframe_nbslots[subframe_idx], hTcBuffer->slots_rendered );
    2276       94057 :                 move16();
    2277             :             }
    2278             :         }
    2279             :         ELSE
    2280             :         {
    2281           0 :             return IVAS_ERR_INVALID_INPUT_FORMAT;
    2282             :         }
    2283             : 
    2284             :         /* update combined orientation access index */
    2285      578167 :         ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_len );
    2286             :     }
    2287             : 
    2288      326724 :     IF( pCrend->hCrend[0]->hReverb != NULL )
    2289             :     {
    2290       57926 :         *pCrend->p_io_qfactor = sub( *pCrend->p_io_qfactor, 2 );
    2291       57926 :         move16();
    2292      573226 :         FOR( Word16 i = nchan_out; i < nchan_in; i++ )
    2293             :         {
    2294   208880100 :             FOR( Word16 j = 0; j < n_samples_to_render; j++ )
    2295             :             {
    2296   208364800 :                 output[i][j] = L_shr( output[i][j], 2 ); // Q = *pCrend->p_io_qfactor
    2297   208364800 :                 move32();
    2298             :             }
    2299             :         }
    2300             :     }
    2301             : 
    2302             :     /* move to output */
    2303      980172 :     FOR( ch = 0; ch < nchan_out; ch++ )
    2304             :     {
    2305      653448 :         MVR2R_WORD32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); // Qx
    2306             :     }
    2307             : 
    2308      326724 :     if ( hTcBuffer != NULL )
    2309             :     {
    2310       24180 :         hTcBuffer->subframes_rendered = last_sf;
    2311       24180 :         move16();
    2312             :     }
    2313             : 
    2314      326724 :     pop_wmops();
    2315             : 
    2316      326724 :     return IVAS_ERR_OK;
    2317             : }
    2318             : 
    2319             : 
    2320             : /*-----------------------------------------------------------------------------------------*
    2321             :  * Function ivas_rend_crend_ProcessSubframesSplitBin()
    2322             :  *
    2323             :  * Process call for IVAS Crend renderer
    2324             :  *-----------------------------------------------------------------------------------------*/
    2325             : 
    2326           0 : ivas_error ivas_rend_crendProcessSubframesSplitBin(
    2327             :     const CREND_WRAPPER *pCrend,  /* i/o: Crend wrapper handle                    */
    2328             :     const AUDIO_CONFIG inConfig,  /* i  : input audio configuration               */
    2329             :     const AUDIO_CONFIG outConfig, /* i  : output audio configuration              */
    2330             :     const MULTI_BIN_REND_POSE_DATA *pMultiBinPoseData,
    2331             :     const DECODER_CONFIG_HANDLE hDecoderConfig,                 /* i  : decoder config. structure               */
    2332             :     const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i  : combined orientation handle             */
    2333             :     const IVAS_OUTPUT_SETUP_HANDLE hIntSetup,                   /* i  : internal setup handle                   */
    2334             :     const EFAP_HANDLE hEFAPdata,                                /* i  : EFAP handle                             */
    2335             :     DECODER_TC_BUFFER_HANDLE hTcBuffer,                         /* i/o: JBM handle                              */
    2336             :     Word32 *input_f[],                                          /* i  : transport channels                      */
    2337             :     Word32 *output[],                                           /* i/o: input/output audio channels             */
    2338             :     const Word16 n_samples_to_render,                           /* i  : output frame length per channel         */
    2339             :     const Word32 output_Fs                                      /* i  : output sampling rate                    */
    2340             : )
    2341             : {
    2342             :     Word16 i, j;
    2343             :     Word16 sf;
    2344             :     Word16 pos_idx;
    2345             :     ivas_error error;
    2346             :     Word16 gain_lfe;
    2347             :     Word32 tmpLfeBuffer[L_FRAME48k];
    2348             :     Word16 original_subframes_rendered, original_slots_rendered;
    2349             :     Word32 tmpInputBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k];
    2350             :     Word32 *p_tmpInputBuffer[MAX_OUTPUT_CHANNELS];
    2351             :     Word32 tmpSplitBinBuffer[MAX_OUTPUT_CHANNELS][L_FRAME48k];
    2352             : 
    2353             :     COMBINED_ORIENTATION_DATA combinedOrientationDataLocal;
    2354             :     COMBINED_ORIENTATION_HANDLE pCombinedOrientationDataLocal;
    2355             : 
    2356             :     /* save current head positions */
    2357           0 :     pCombinedOrientationDataLocal = hCombinedOrientationData;
    2358           0 :     combinedOrientationDataLocal = *pCombinedOrientationDataLocal;
    2359           0 :     original_subframes_rendered = hTcBuffer->subframes_rendered;
    2360           0 :     move16();
    2361           0 :     original_slots_rendered = hTcBuffer->slots_rendered;
    2362           0 :     move16();
    2363             : 
    2364             :     /* copy input */
    2365           0 :     FOR( i = 0; i < hIntSetup->nchan_out_woLFE; ++i )
    2366             :     {
    2367           0 :         Copy32( input_f[i], tmpInputBuffer[i], n_samples_to_render );
    2368             :     }
    2369             : 
    2370           0 :     FOR( i = 0; i < MAX_OUTPUT_CHANNELS; ++i )
    2371             :     {
    2372           0 :         p_tmpInputBuffer[i] = tmpInputBuffer[i];
    2373           0 :         move32();
    2374             :     }
    2375             : 
    2376             :     /* save current head positions */
    2377           0 :     pCombinedOrientationDataLocal = hCombinedOrientationData;
    2378           0 :     combinedOrientationDataLocal = *pCombinedOrientationDataLocal;
    2379           0 :     move32();
    2380           0 :     move32();
    2381           0 :     IF( EQ_32( pMultiBinPoseData->poseCorrectionMode, ISAR_SPLIT_REND_POSE_CORRECTION_MODE_CLDFB ) )
    2382             :     {
    2383           0 :         FOR( sf = 1; sf < hCombinedOrientationData->num_subframes; ++sf )
    2384             :         {
    2385           0 :             Copy_Quat_fx( &combinedOrientationDataLocal.Quaternions[0], &combinedOrientationDataLocal.Quaternions[sf] );
    2386           0 :             FOR( i = 0; i < 3; i++ )
    2387             :             {
    2388           0 :                 FOR( j = 0; j < 3; j++ )
    2389             :                 {
    2390           0 :                     combinedOrientationDataLocal.Rmat_fx[sf][i][j] = combinedOrientationDataLocal.Rmat_fx[0][i][j];
    2391           0 :                     move32();
    2392             :                 }
    2393             :             }
    2394             :         }
    2395             :     }
    2396             : 
    2397             :     /* copy LFE to tmpLfeBuffer and apply gain only once */
    2398           0 :     IF( GT_16( hIntSetup->num_lfe, 0 ) && NE_16( hIntSetup->index_lfe[0], -1 ) )
    2399             :     {
    2400           0 :         Copy32( output[hIntSetup->index_lfe[0]], tmpLfeBuffer, n_samples_to_render );
    2401           0 :         gain_lfe = ( ( pCrend != NULL ) && ( pCrend->hHrtfCrend != NULL ) ) ? pCrend->hHrtfCrend->gain_lfe_fx : GAIN_LFE_FX;
    2402           0 :         v_multc_fixed_16( tmpLfeBuffer, gain_lfe, tmpLfeBuffer, n_samples_to_render ); // q_input_fx  - 1
    2403           0 :         Scale_sig32( tmpLfeBuffer, n_samples_to_render, 1 );                           // q_input_fx
    2404             :     }
    2405             :     ELSE
    2406             :     {
    2407           0 :         set32_fx( tmpLfeBuffer, 0, n_samples_to_render );
    2408             :     }
    2409             : 
    2410           0 :     FOR( pos_idx = 0; pos_idx < pMultiBinPoseData->num_poses; ++pos_idx )
    2411             :     {
    2412             :         /* Update head positions */
    2413             :         IVAS_QUATERNION Quaternions_orig[MAX_PARAM_SPATIAL_SUBFRAMES], Quaternions_abs;
    2414             : 
    2415           0 :         FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ )
    2416             :         {
    2417           0 :             Copy_Quat_fx( &combinedOrientationDataLocal.Quaternions[i], &Quaternions_orig[i] );
    2418           0 :             Quaternions_abs.w_fx = L_negate( 12582912 ); // Q22
    2419           0 :             move32();
    2420           0 :             modify_Quat_q_fx( &combinedOrientationDataLocal.Quaternions[i], &combinedOrientationDataLocal.Quaternions[i], Q22 );
    2421           0 :             Quat2EulerDegree_fx( combinedOrientationDataLocal.Quaternions[i], &Quaternions_abs.z_fx, &Quaternions_abs.y_fx, &Quaternions_abs.x_fx ); /*order in Quat2Euler seems to be reversed ?*/
    2422             : 
    2423           0 :             Quaternions_abs.x_fx = L_add( Quaternions_abs.x_fx, pMultiBinPoseData->relative_head_poses_fx[pos_idx][0] );
    2424           0 :             Quaternions_abs.y_fx = L_add( Quaternions_abs.y_fx, pMultiBinPoseData->relative_head_poses_fx[pos_idx][1] );
    2425           0 :             Quaternions_abs.z_fx = L_add( Quaternions_abs.z_fx, pMultiBinPoseData->relative_head_poses_fx[pos_idx][2] );
    2426           0 :             combinedOrientationDataLocal.Quaternions[i] = Quaternions_abs;
    2427           0 :             move32();
    2428           0 :             move32();
    2429           0 :             move32();
    2430           0 :             move32();
    2431           0 :             Euler2Quat_fx( deg2rad_fx( combinedOrientationDataLocal.Quaternions[i].x_fx ),
    2432             :                            deg2rad_fx( combinedOrientationDataLocal.Quaternions[i].y_fx ),
    2433             :                            deg2rad_fx( combinedOrientationDataLocal.Quaternions[i].z_fx ),
    2434           0 :                            &combinedOrientationDataLocal.Quaternions[i] );
    2435           0 :             modify_Quat_q_fx( &combinedOrientationDataLocal.Quaternions[i], &combinedOrientationDataLocal.Quaternions[i], Quaternions_orig[i].q_fact );
    2436           0 :             QuatToRotMat_fx( combinedOrientationDataLocal.Quaternions[i], combinedOrientationDataLocal.Rmat_fx[i] );
    2437           0 :             modify_Rmat_q_fx( combinedOrientationDataLocal.Rmat_fx[i], combinedOrientationDataLocal.Rmat_fx[i], sub( shl( Quaternions_orig[i].q_fact, 1 ), 32 ), Q30 );
    2438             :         }
    2439             : 
    2440             : 
    2441           0 :         pCombinedOrientationDataLocal = &combinedOrientationDataLocal;
    2442           0 :         move32();
    2443             : 
    2444           0 :         hTcBuffer->subframes_rendered = original_subframes_rendered;
    2445           0 :         hTcBuffer->slots_rendered = original_slots_rendered;
    2446           0 :         move16();
    2447           0 :         move16();
    2448             : 
    2449             :         /* update combined orientation access index */
    2450           0 :         ivas_combined_orientation_set_to_start_index( pCombinedOrientationDataLocal );
    2451             : 
    2452           0 :         FOR( i = 0; i < 3; i++ )
    2453             :         {
    2454           0 :             Copy32( hCombinedOrientationData->Rmat_prev_fx[pos_idx][i], pCombinedOrientationDataLocal->Rmat_prev_fx[0][i], 3 );
    2455             :         }
    2456             : 
    2457           0 :         IF( ( error = ivas_rend_crendProcessSubframe( pCrend, inConfig, outConfig, hDecoderConfig, pCombinedOrientationDataLocal,
    2458             :                                                       hIntSetup, hEFAPdata, hTcBuffer, p_tmpInputBuffer, p_tmpInputBuffer, n_samples_to_render, output_Fs, pos_idx ) ) != IVAS_ERR_OK )
    2459             :         {
    2460           0 :             return error;
    2461             :         }
    2462             : 
    2463           0 :         FOR( i = 0; i < 3; i++ )
    2464             :         {
    2465           0 :             Copy32( pCombinedOrientationDataLocal->Rmat_prev_fx[0][i], hCombinedOrientationData->Rmat_prev_fx[pos_idx][i], 3 );
    2466             :         }
    2467             : 
    2468           0 :         FOR( i = 0; i < BINAURAL_CHANNELS; ++i )
    2469             :         {
    2470             :             /* accumulate LFE to output */
    2471           0 :             v_add_fx( tmpInputBuffer[i], tmpLfeBuffer, tmpInputBuffer[i], n_samples_to_render );
    2472             : 
    2473             :             /* move to split bin output buffer */
    2474           0 :             Copy32( tmpInputBuffer[i], tmpSplitBinBuffer[add( i_mult( pos_idx, BINAURAL_CHANNELS ), i )], n_samples_to_render );
    2475             :         }
    2476             : 
    2477             :         /* overwrite rendered channels with input again for next iteration */
    2478           0 :         FOR( i = 0; i < hIntSetup->nchan_out_woLFE; ++i )
    2479             :         {
    2480           0 :             Copy32( output[i], tmpInputBuffer[i], n_samples_to_render );
    2481             :         }
    2482             : 
    2483             :         /* restore original headrotation data */
    2484           0 :         FOR( i = 0; i < hCombinedOrientationData->num_subframes; i++ )
    2485             :         {
    2486           0 :             Copy_Quat_fx( &Quaternions_orig[i], &combinedOrientationDataLocal.Quaternions[i] );
    2487             :         }
    2488             :     }
    2489             : 
    2490             :     /* copy split binaural rendered signals to final output */
    2491           0 :     FOR( i = 0; i < i_mult( BINAURAL_CHANNELS, pMultiBinPoseData->num_poses ); ++i )
    2492             :     {
    2493           0 :         Copy32( tmpSplitBinBuffer[i], output[i], n_samples_to_render );
    2494             :     }
    2495             : 
    2496             :     /* update main combined orientation access index */
    2497           0 :     ivas_combined_orientation_update_index( hCombinedOrientationData, n_samples_to_render );
    2498             : 
    2499           0 :     return IVAS_ERR_OK;
    2500             : }

Generated by: LCOV version 1.14