LCOV - code coverage report
Current view: top level - lib_rend - ivas_crend_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 768 1129 68.0 %
Date: 2025-05-03 01:55:50 Functions: 15 15 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <stdint.h>
      34             : #include <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         518 : ivas_error ivas_hrtf_init(
      59             :     HRTFS_DATA *hHrtf /* i/o: HRTF handle     */
      60             : )
      61             : {
      62             :     Word16 i, j;
      63             : 
      64         518 :     IF( hHrtf == NULL )
      65             :     {
      66           0 :         return IVAS_ERR_WRONG_PARAMS;
      67             :     }
      68             : 
      69         518 :     hHrtf->latency_s_fx = 0;
      70         518 :     hHrtf->gain_lfe_fx = 0;
      71         518 :     hHrtf->max_num_ir = 0;
      72         518 :     hHrtf->max_num_iterations = 0;
      73         518 :     hHrtf->index_frequency_max_diffuse = 0;
      74         518 :     move32();
      75         518 :     move16();
      76         518 :     move16();
      77         518 :     move16();
      78         518 :     move16();
      79             : 
      80        8806 :     FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
      81             :     {
      82        8288 :         hHrtf->inv_diffuse_weight_fx[i] = 0;
      83        8288 :         move16();
      84       24864 :         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
      85             :         {
      86       16576 :             hHrtf->num_iterations[i][j] = 0;
      87       16576 :             move16();
      88       16576 :             hHrtf->pIndex_frequency_max[i][j] = NULL;
      89       16576 :             hHrtf->pOut_to_bin_re_fx[i][j] = NULL;
      90       16576 :             hHrtf->pOut_to_bin_im_fx[i][j] = NULL;
      91             :         }
      92             :     }
      93             : 
      94        1554 :     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
      95             :     {
      96        1036 :         hHrtf->num_iterations_diffuse[j] = 0;
      97        1036 :         move16();
      98        1036 :         hHrtf->pIndex_frequency_max_diffuse[j] = NULL;
      99             : 
     100        1036 :         hHrtf->pOut_to_bin_diffuse_re_fx[j] = NULL;
     101        1036 :         hHrtf->pOut_to_bin_diffuse_im_fx[j] = NULL;
     102             :     }
     103             : 
     104         518 :     return IVAS_ERR_OK;
     105             : }
     106             : 
     107             : /*-------------------------------------------------------------------------
     108             :  * ivas_hrtf_open()
     109             :  *
     110             :  * Open hHrtf handle
     111             :  *------------------------------------------------------------------------*/
     112         403 : static ivas_error ivas_hrtf_open(
     113             :     HRTFS_HANDLE *hHrtf_out /* o  : HRTF handle     */
     114             : )
     115             : {
     116             :     HRTFS_HANDLE hHrtf;
     117             :     ivas_error error;
     118             : 
     119         403 :     IF( *hHrtf_out == NULL )
     120             :     {
     121         403 :         IF( ( hHrtf = (HRTFS_HANDLE) malloc( sizeof( HRTFS_DATA ) ) ) == NULL )
     122             :         {
     123           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder\n" );
     124             :         }
     125             : 
     126         403 :         IF( NE_32( ( error = ivas_hrtf_init( hHrtf ) ), IVAS_ERR_OK ) )
     127             :         {
     128           0 :             return error;
     129             :         }
     130             : 
     131         403 :         *hHrtf_out = hHrtf;
     132             :     }
     133             :     ELSE
     134             :     {
     135           0 :         return IVAS_ERR_INTERNAL;
     136             :     }
     137             : 
     138         403 :     return IVAS_ERR_OK;
     139             : }
     140             : 
     141             : 
     142             : /*-------------------------------------------------------------------------
     143             :  * ivas_hrtf_close()
     144             :  *
     145             :  * Close hHrtf handle
     146             :  *------------------------------------------------------------------------*/
     147             : 
     148         403 : static void ivas_hrtf_close(
     149             :     HRTFS_HANDLE *hHrtf /* i/o: HRTF handle         */
     150             : )
     151             : {
     152         403 :     test();
     153         403 :     IF( hHrtf == NULL || *hHrtf == NULL )
     154             :     {
     155           0 :         return;
     156             :     }
     157             : 
     158         403 :     free( *hHrtf );
     159         403 :     *hHrtf = NULL;
     160             : 
     161         403 :     return;
     162             : }
     163             : /*-------------------------------------------------------------------------
     164             :  * initCrend_from_rom()
     165             :  *
     166             :  * Allocate and initialize crend renderer handle
     167             :  *------------------------------------------------------------------------*/
     168             : 
     169         403 : static ivas_error ivas_rend_initCrend_fx(
     170             :     CREND_WRAPPER *pCrend,
     171             :     const AUDIO_CONFIG inConfig,
     172             :     const AUDIO_CONFIG outConfig,
     173             :     HRTFS_CREND_HANDLE hSetOfHRTF,
     174             :     const Word32 output_Fs )
     175             : {
     176             :     Word16 i, j, tmp;
     177             :     Word16 nchan_in;
     178             :     IVAS_REND_AudioConfigType inConfigType;
     179             :     HRTFS_HANDLE hHrtf;
     180             :     ivas_error error;
     181             : 
     182         403 :     inConfigType = getAudioConfigType( inConfig );
     183         403 :     hHrtf = pCrend->hHrtfCrend;
     184             : 
     185             :     /* Do all error checks up front so that the nested if later is easier */
     186         403 :     test();
     187         403 :     IF( inConfigType != IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED && NE_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
     188             :     {
     189           0 :         return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Encountered unsupported input config in Crend" );
     190             :     }
     191             : 
     192         403 :     test();
     193         403 :     test();
     194         403 :     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 ) )
     195             :     {
     196           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Encountered unsupported output type in Crend" );
     197             :     }
     198             : 
     199         403 :     IF( hHrtf == NULL )
     200             :     {
     201         403 :         IF( NE_32( ivas_hrtf_open( &hHrtf ), IVAS_ERR_OK ) )
     202             :         {
     203           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Could not allocate memory for HRTF handle" );
     204             :         }
     205             :     }
     206             : 
     207         403 :     IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) )
     208             :     {
     209           0 :         return error;
     210             :     }
     211         403 :     hHrtf->max_num_ir = nchan_in;
     212         403 :     move16();
     213             : 
     214         403 :     IF( hHrtf->max_num_ir <= 0 )
     215             :     {
     216           0 :         return IVAS_ERR_INTERNAL_FATAL;
     217             :     }
     218             : 
     219         403 :     IF( hSetOfHRTF == NULL )
     220             :     {
     221         375 :         IF( EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) )
     222             :         {
     223         362 :             hHrtf->max_num_ir = sub( hHrtf->max_num_ir, 1 ); /* subtract LFE */
     224         362 :             move16();
     225         362 :             hHrtf->gain_lfe_fx = GAIN_LFE_FX; // Q14
     226         362 :             move16();
     227             : 
     228         362 :             IF( EQ_32( output_Fs, 48000 ) )
     229             :             {
     230         222 :                 IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     231             :                 {
     232         155 :                     hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx;                                     // Q31
     233         155 :                     hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_48kHz;                   // Q0
     234         155 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_48kHz; // Q0
     235             :                 }
     236             :                 ELSE
     237             :                 {
     238          67 :                     hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx;                                     // Q31
     239          67 :                     hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_48kHz;                   // Q0
     240          67 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_48kHz; // Q0
     241             :                 }
     242         222 :                 move32();
     243         222 :                 move16();
     244         222 :                 move16();
     245             : 
     246         666 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     247             :                 {
     248         444 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     249             :                     {
     250         310 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_48kHz[j];             // Q0
     251         310 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_48kHz[j]; // Q0
     252             : 
     253         310 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     254         310 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     255             :                     }
     256             :                     ELSE
     257             :                     {
     258         134 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_48kHz[j];             // Q0
     259         134 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_48kHz[j]; // Q0
     260             : 
     261         134 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     262         134 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     263             :                     }
     264         444 :                     move32();
     265         444 :                     move32();
     266         444 :                     move16();
     267         444 :                     move16();
     268             :                 }
     269             :             }
     270         140 :             ELSE IF( EQ_32( output_Fs, 32000 ) )
     271             :             {
     272          75 :                 IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     273             :                 {
     274          75 :                     hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx;                                     // Q31
     275          75 :                     hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_32kHz;                   // Q0
     276          75 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_32kHz; // Q0
     277             :                 }
     278             :                 ELSE
     279             :                 {
     280           0 :                     hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx;                                     // Q31
     281           0 :                     hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_32kHz;                   // Q0
     282           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_32kHz; // Q0
     283             :                 }
     284          75 :                 move32();
     285          75 :                 move16();
     286          75 :                 move16();
     287             : 
     288         225 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     289             :                 {
     290         150 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     291             :                     {
     292         150 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_32kHz[j];             // Q0
     293         150 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_32kHz[j]; // Q0
     294             : 
     295         150 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31
     296         150 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31
     297             :                     }
     298             :                     ELSE
     299             :                     {
     300           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_32kHz[j];             // Q0
     301           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_32kHz[j]; // Q0
     302             : 
     303           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31
     304           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31
     305             :                     }
     306         150 :                     move32();
     307         150 :                     move32();
     308         150 :                     move16();
     309         150 :                     move16();
     310             :                 }
     311             :             }
     312          65 :             ELSE IF( EQ_32( output_Fs, 16000 ) )
     313             :             {
     314          65 :                 IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     315             :                 {
     316           4 :                     hHrtf->latency_s_fx = CRendBin_Combined_BRIR_latency_s_fx; // Q31
     317           4 :                     hHrtf->max_num_iterations = CRendBin_Combined_BRIR_max_num_iterations_16kHz;
     318           4 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_BRIR_index_frequency_max_diffuse_16kHz;
     319             :                 }
     320             :                 ELSE
     321             :                 {
     322          61 :                     hHrtf->latency_s_fx = CRendBin_Combined_HRIR_latency_s_fx; // Q31
     323          61 :                     hHrtf->max_num_iterations = CRendBin_Combined_HRIR_max_num_iterations_16kHz;
     324          61 :                     hHrtf->index_frequency_max_diffuse = CRendBin_Combined_HRIR_index_frequency_max_diffuse_16kHz;
     325             :                 }
     326          65 :                 move32();
     327          65 :                 move16();
     328          65 :                 move16();
     329             : 
     330         195 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     331             :                 {
     332         130 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     333             :                     {
     334           8 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_BRIR_num_iterations_diffuse_16kHz[j];
     335           8 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_BRIR_pIndex_frequency_max_diffuse_16kHz[j];
     336             : 
     337           8 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     338           8 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_BRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     339             :                     }
     340             :                     ELSE
     341             :                     {
     342         122 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_Combined_HRIR_num_iterations_diffuse_16kHz[j];
     343         122 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_Combined_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     344             : 
     345         122 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     346         122 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_Combined_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     347             :                     }
     348         130 :                     move32();
     349         130 :                     move32();
     350         130 :                     move16();
     351         130 :                     move16();
     352             :                 }
     353             :             }
     354             :             ELSE
     355             :             {
     356           0 :                 return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     357             :             }
     358             : 
     359        3394 :             FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     360             :             {
     361        3032 :                 IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) )
     362             :                 {
     363         685 :                     tmp = channelIndex_CICP6[i];
     364             :                 }
     365        2347 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) )
     366             :                 {
     367          63 :                     tmp = channelIndex_CICP12[i];
     368             :                 }
     369        2284 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) )
     370             :                 {
     371         112 :                     tmp = channelIndex_CICP14[i];
     372             :                 }
     373        2172 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) )
     374             :                 {
     375         126 :                     tmp = channelIndex_CICP16[i];
     376             :                 }
     377        2046 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1_4 ) )
     378             :                 {
     379        2046 :                     tmp = channelIndex_CICP19[i];
     380             :                 }
     381             :                 ELSE
     382             :                 {
     383           0 :                     return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Channel configuration not specified!\n\n" );
     384             :                 }
     385        3032 :                 move16();
     386             : 
     387        3032 :                 IF( EQ_32( output_Fs, 48000 ) )
     388             :                 {
     389        1874 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     390             :                     {
     391        1251 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_48kHz_fx[tmp]; // Q15
     392             :                     }
     393             :                     ELSE
     394             :                     {
     395         623 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_48kHz_fx[tmp]; // Q15
     396             :                     }
     397        1874 :                     move16();
     398             : 
     399        5622 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     400             :                     {
     401        3748 :                         IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     402             :                         {
     403        2502 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_48kHz[tmp][j];
     404        2502 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_48kHz[tmp][j];
     405             : 
     406        2502 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_48kHz_fx[tmp][j]; // Q29
     407        2502 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_48kHz_fx[tmp][j]; // Q29
     408             :                         }
     409             :                         ELSE
     410             :                         {
     411        1246 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_48kHz[tmp][j];
     412        1246 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_48kHz[tmp][j];
     413             : 
     414        1246 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_48kHz_fx[tmp][j]; // Q29
     415        1246 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_48kHz_fx[tmp][j]; // Q29
     416             :                         }
     417        3748 :                         move32();
     418        3748 :                         move32();
     419        3748 :                         move16();
     420        3748 :                         move16();
     421             :                     }
     422             :                 }
     423        1158 :                 ELSE IF( EQ_32( output_Fs, 32000 ) )
     424             :                 {
     425         825 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     426             :                     {
     427         825 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_32kHz_fx[tmp]; // Q15
     428             :                     }
     429             :                     ELSE
     430             :                     {
     431           0 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_32kHz_fx[tmp]; // Q15
     432             :                     }
     433         825 :                     move16();
     434             : 
     435        2475 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     436             :                     {
     437        1650 :                         IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     438             :                         {
     439        1650 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_32kHz[tmp][j];
     440        1650 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_32kHz[tmp][j];
     441             : 
     442        1650 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_32kHz_fx[tmp][j]; // Q29
     443        1650 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_32kHz_fx[tmp][j]; // Q29
     444             :                         }
     445             :                         ELSE
     446             :                         {
     447           0 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_32kHz[tmp][j];
     448           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_32kHz[tmp][j];
     449             : 
     450           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_32kHz_fx[tmp][j]; // Q29
     451           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_32kHz_fx[tmp][j]; // Q29
     452             :                         }
     453        1650 :                         move32();
     454        1650 :                         move32();
     455        1650 :                         move16();
     456        1650 :                         move16();
     457             :                     }
     458             :                 }
     459         333 :                 ELSE IF( EQ_32( output_Fs, 16000 ) )
     460             :                 {
     461         333 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     462             :                     {
     463          28 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_BRIR_inv_diffuse_weight_16kHz_fx[tmp]; // Q15
     464             :                     }
     465             :                     ELSE
     466             :                     {
     467         305 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_Combined_HRIR_inv_diffuse_weight_16kHz_fx[tmp]; // Q15
     468             :                     }
     469         333 :                     move16();
     470             : 
     471         999 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     472             :                     {
     473         666 :                         IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     474             :                         {
     475          56 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_BRIR_num_iterations_16kHz[tmp][j];
     476          56 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_BRIR_pIndex_frequency_max_16kHz[tmp][j];
     477             : 
     478          56 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_BRIR_coeff_re_16kHz_fx[tmp][j]; // Q29
     479          56 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_BRIR_coeff_im_16kHz_fx[tmp][j]; // Q29
     480             :                         }
     481             :                         ELSE
     482             :                         {
     483         610 :                             hHrtf->num_iterations[i][j] = CRendBin_Combined_HRIR_num_iterations_16kHz[tmp][j];
     484         610 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_Combined_HRIR_pIndex_frequency_max_16kHz[tmp][j];
     485             : 
     486         610 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_Combined_HRIR_coeff_re_16kHz_fx[tmp][j]; // Q29
     487         610 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_Combined_HRIR_coeff_im_16kHz_fx[tmp][j]; // Q29
     488             :                         }
     489         666 :                         move32();
     490         666 :                         move32();
     491         666 :                         move16();
     492         666 :                         move16();
     493             :                     }
     494             :                 }
     495             :                 ELSE
     496             :                 {
     497           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     498             :                 }
     499             :             }
     500             :         }
     501          13 :         ELSE IF( EQ_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
     502             :         {
     503          13 :             IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) )
     504             :             {
     505           5 :                 IF( EQ_32( output_Fs, 48000 ) )
     506             :                 {
     507           5 :                     hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31
     508           5 :                     hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_48kHz;
     509           5 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_48kHz;
     510           5 :                     move32();
     511           5 :                     move16();
     512           5 :                     move16();
     513             : 
     514          85 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     515             :                     {
     516          80 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_48kHz_fx[i]; // Q15
     517          80 :                         move16();
     518             : 
     519         240 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     520             :                         {
     521         160 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_48kHz[i][j];
     522         160 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_48kHz[i][j];
     523             : 
     524         160 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_48kHz_fx[i][j]; // Q29
     525         160 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_48kHz_fx[i][j]; // Q29
     526         160 :                             move32();
     527         160 :                             move32();
     528         160 :                             move16();
     529         160 :                             move16();
     530             :                         }
     531             :                     }
     532          15 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     533             :                     {
     534          10 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_48kHz[j];
     535          10 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     536             : 
     537          10 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     538          10 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     539          10 :                         move32();
     540          10 :                         move32();
     541          10 :                         move16();
     542          10 :                         move16();
     543             :                     }
     544             :                 }
     545           0 :                 ELSE IF( EQ_32( output_Fs, 32000 ) )
     546             :                 {
     547           0 :                     hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31
     548           0 :                     hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_32kHz;
     549           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_32kHz;
     550           0 :                     move32();
     551           0 :                     move16();
     552           0 :                     move16();
     553             : 
     554           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     555             :                     {
     556           0 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_32kHz_fx[i]; // Q15
     557           0 :                         move16();
     558             : 
     559           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     560             :                         {
     561           0 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_32kHz[i][j];
     562           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_32kHz[i][j];
     563             : 
     564           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_32kHz_fx[i][j]; // Q29
     565           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_32kHz_fx[i][j]; // Q29
     566           0 :                             move32();
     567           0 :                             move32();
     568           0 :                             move16();
     569           0 :                             move16();
     570             :                         }
     571             :                     }
     572             : 
     573           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     574             :                     {
     575           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_32kHz[j];
     576           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
     577             : 
     578           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31
     579           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31
     580           0 :                         move32();
     581           0 :                         move32();
     582           0 :                         move16();
     583           0 :                         move16();
     584             :                     }
     585             :                 }
     586           0 :                 ELSE IF( EQ_32( output_Fs, 16000 ) )
     587             :                 {
     588           0 :                     hHrtf->latency_s_fx = CRendBin_HOA3_HRIR_latency_s_fx; // Q31
     589           0 :                     hHrtf->max_num_iterations = CRendBin_HOA3_HRIR_max_num_iterations_16kHz;
     590           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA3_HRIR_index_frequency_max_diffuse_16kHz;
     591           0 :                     move32();
     592           0 :                     move16();
     593           0 :                     move16();
     594             : 
     595           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     596             :                     {
     597           0 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA3_HRIR_inv_diffuse_weight_16kHz_fx[i]; // Q15
     598           0 :                         move16();
     599             : 
     600           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     601             :                         {
     602           0 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA3_HRIR_num_iterations_16kHz[i][j];
     603           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_16kHz[i][j];
     604             : 
     605           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA3_HRIR_coeff_re_16kHz_fx[i][j]; // Q29
     606           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA3_HRIR_coeff_im_16kHz_fx[i][j]; // Q29
     607           0 :                             move32();
     608           0 :                             move32();
     609           0 :                             move16();
     610           0 :                             move16();
     611             :                         }
     612             :                     }
     613             : 
     614           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     615             :                     {
     616           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA3_HRIR_num_iterations_diffuse_16kHz[j];
     617           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA3_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     618             : 
     619           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     620           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA3_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     621           0 :                         move32();
     622           0 :                         move32();
     623           0 :                         move16();
     624           0 :                         move16();
     625             :                     }
     626             :                 }
     627             :                 ELSE
     628             :                 {
     629           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     630             :                 }
     631             :             }
     632           8 :             ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) )
     633             :             {
     634           4 :                 IF( EQ_32( output_Fs, 48000 ) )
     635             :                 {
     636           4 :                     hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31
     637           4 :                     hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_48kHz;
     638           4 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_48kHz;
     639           4 :                     move32();
     640           4 :                     move16();
     641           4 :                     move16();
     642             : 
     643          40 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     644             :                     {
     645          36 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_48kHz_fx[i]; // Q15
     646          36 :                         move16();
     647             : 
     648         108 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     649             :                         {
     650          72 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_48kHz[i][j];
     651          72 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_48kHz[i][j];
     652             : 
     653          72 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_48kHz_fx[i][j]; // Q29
     654          72 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_48kHz_fx[i][j]; // Q29
     655          72 :                             move32();
     656          72 :                             move32();
     657          72 :                             move16();
     658          72 :                             move16();
     659             :                         }
     660             :                     }
     661          12 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     662             :                     {
     663           8 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_48kHz[j];
     664           8 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     665             : 
     666           8 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     667           8 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     668           8 :                         move32();
     669           8 :                         move32();
     670           8 :                         move16();
     671           8 :                         move16();
     672             :                     }
     673             :                 }
     674           0 :                 ELSE IF( EQ_32( output_Fs, 32000 ) )
     675             :                 {
     676           0 :                     hHrtf->latency_s_fx = CRendBin_HOA2_HRIR_latency_s_fx; // Q31
     677           0 :                     hHrtf->max_num_iterations = CRendBin_HOA2_HRIR_max_num_iterations_32kHz;
     678           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_HOA2_HRIR_index_frequency_max_diffuse_32kHz;
     679           0 :                     move32();
     680           0 :                     move16();
     681           0 :                     move16();
     682             : 
     683           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     684             :                     {
     685           0 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_32kHz_fx[i]; // Q15
     686           0 :                         move16();
     687             : 
     688           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     689             :                         {
     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 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_HOA2_HRIR_inv_diffuse_weight_16kHz_fx[i]; // Q15
     727           0 :                         move16();
     728             : 
     729           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     730             :                         {
     731           0 :                             hHrtf->num_iterations[i][j] = CRendBin_HOA2_HRIR_num_iterations_16kHz[i][j];
     732           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_16kHz[i][j];
     733             : 
     734           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_HOA2_HRIR_coeff_re_16kHz_fx[i][j]; // Q29
     735           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_HOA2_HRIR_coeff_im_16kHz_fx[i][j]; // Q29
     736           0 :                             move32();
     737           0 :                             move32();
     738           0 :                             move16();
     739           0 :                             move16();
     740             :                         }
     741             :                     }
     742             : 
     743           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     744             :                     {
     745           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_HOA2_HRIR_num_iterations_diffuse_16kHz[j];
     746           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_HOA2_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     747             : 
     748           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     749           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_HOA2_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     750           0 :                         move32();
     751           0 :                         move32();
     752           0 :                         move16();
     753           0 :                         move16();
     754             :                     }
     755             :                 }
     756             :                 ELSE
     757             :                 {
     758           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     759             :                 }
     760             :             }
     761           4 :             ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_FOA ) )
     762             :             {
     763           4 :                 IF( EQ_32( output_Fs, 48000 ) )
     764             :                 {
     765           4 :                     hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31
     766           4 :                     hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_48kHz;
     767           4 :                     hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_48kHz;
     768           4 :                     move32();
     769           4 :                     move16();
     770           4 :                     move16();
     771             : 
     772          20 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     773             :                     {
     774          16 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_48kHz_fx[i]; // Q15
     775          16 :                         move16();
     776             : 
     777          48 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     778             :                         {
     779          32 :                             hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_48kHz[i][j];
     780          32 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_48kHz[i][j];
     781             : 
     782          32 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_48kHz_fx[i][j]; // Q29
     783          32 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_48kHz_fx[i][j]; // Q29
     784          32 :                             move32();
     785          32 :                             move32();
     786          32 :                             move16();
     787          32 :                             move16();
     788             :                         }
     789             :                     }
     790          12 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     791             :                     {
     792           8 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_48kHz[j];
     793           8 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_48kHz[j];
     794             : 
     795           8 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_48kHz_fx[j]; // Q31
     796           8 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_48kHz_fx[j]; // Q31
     797           8 :                         move32();
     798           8 :                         move32();
     799           8 :                         move16();
     800           8 :                         move16();
     801             :                     }
     802             :                 }
     803           0 :                 ELSE IF( EQ_32( output_Fs, 32000 ) )
     804             :                 {
     805           0 :                     hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31
     806           0 :                     hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_32kHz;
     807           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_32kHz;
     808           0 :                     move32();
     809           0 :                     move16();
     810           0 :                     move16();
     811             : 
     812           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     813             :                     {
     814           0 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_32kHz_fx[i]; // Q15
     815           0 :                         move16();
     816             : 
     817           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     818             :                         {
     819           0 :                             hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_32kHz[i][j];
     820           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_32kHz[i][j];
     821             : 
     822           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_32kHz_fx[i][j]; // Q29
     823           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_32kHz_fx[i][j]; // Q29
     824           0 :                             move32();
     825           0 :                             move32();
     826           0 :                             move16();
     827           0 :                             move16();
     828             :                         }
     829             :                     }
     830             : 
     831           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     832             :                     {
     833           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_32kHz[j];
     834           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_32kHz[j];
     835             : 
     836           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_32kHz_fx[j]; // Q31
     837           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_32kHz_fx[j]; // Q31
     838           0 :                         move32();
     839           0 :                         move32();
     840           0 :                         move16();
     841           0 :                         move16();
     842             :                     }
     843             :                 }
     844           0 :                 ELSE IF( EQ_32( output_Fs, 16000 ) )
     845             :                 {
     846           0 :                     hHrtf->latency_s_fx = CRendBin_FOA_HRIR_latency_s_fx; // Q31
     847           0 :                     hHrtf->max_num_iterations = CRendBin_FOA_HRIR_max_num_iterations_16kHz;
     848           0 :                     hHrtf->index_frequency_max_diffuse = CRendBin_FOA_HRIR_index_frequency_max_diffuse_16kHz;
     849           0 :                     move32();
     850           0 :                     move16();
     851           0 :                     move16();
     852             : 
     853           0 :                     FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     854             :                     {
     855           0 :                         hHrtf->inv_diffuse_weight_fx[i] = CRendBin_FOA_HRIR_inv_diffuse_weight_16kHz_fx[i]; // Q15
     856           0 :                         move16();
     857             : 
     858           0 :                         FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     859             :                         {
     860           0 :                             hHrtf->num_iterations[i][j] = CRendBin_FOA_HRIR_num_iterations_16kHz[i][j];
     861           0 :                             hHrtf->pIndex_frequency_max[i][j] = CRendBin_FOA_HRIR_pIndex_frequency_max_16kHz[i][j];
     862             : 
     863           0 :                             hHrtf->pOut_to_bin_re_fx[i][j] = CRendBin_FOA_HRIR_coeff_re_16kHz_fx[i][j]; // Q29
     864           0 :                             hHrtf->pOut_to_bin_im_fx[i][j] = CRendBin_FOA_HRIR_coeff_im_16kHz_fx[i][j]; // Q29
     865           0 :                             move32();
     866           0 :                             move32();
     867           0 :                             move16();
     868           0 :                             move16();
     869             :                         }
     870             :                     }
     871             : 
     872           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     873             :                     {
     874           0 :                         hHrtf->num_iterations_diffuse[j] = CRendBin_FOA_HRIR_num_iterations_diffuse_16kHz[j];
     875           0 :                         hHrtf->pIndex_frequency_max_diffuse[j] = CRendBin_FOA_HRIR_pIndex_frequency_max_diffuse_16kHz[j];
     876             : 
     877           0 :                         hHrtf->pOut_to_bin_diffuse_re_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_re_16kHz_fx[j]; // Q31
     878           0 :                         hHrtf->pOut_to_bin_diffuse_im_fx[j] = CRendBin_FOA_HRIR_coeff_diffuse_im_16kHz_fx[j]; // Q31
     879           0 :                         move32();
     880           0 :                         move32();
     881           0 :                         move16();
     882           0 :                         move16();
     883             :                     }
     884             :                 }
     885             :                 ELSE
     886             :                 {
     887           0 :                     return IVAS_ERROR( IVAS_ERR_INVALID_SAMPLING_RATE, "Encountered Unsupported sampling rate in Crend" );
     888             :                 }
     889             :             }
     890             :             ELSE
     891             :             {
     892           0 :                 return IVAS_ERROR( IVAS_ERR_INVALID_INPUT_FORMAT, "Encountered unsupported input config in Crend" );
     893             :             }
     894             :         }
     895             :         ELSE
     896             :         {
     897           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL, "Unsupported renderer type in Crend" );
     898             :         }
     899             :     }
     900             :     ELSE
     901             :     {
     902          28 :         IF( inConfigType == IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED )
     903             :         {
     904          28 :             hHrtf->max_num_ir = sub( hHrtf->max_num_ir, 1 ); /* subtract LFE */
     905          28 :             move16();
     906          28 :             hHrtf->gain_lfe_fx = GAIN_LFE_FX;
     907          28 :             move16();
     908             : 
     909          28 :             IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     910             :             {
     911          20 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_brir_combined->latency_s_fx; // Q31
     912          20 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_brir_combined->max_num_iterations;
     913          20 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_brir_combined->index_frequency_max_diffuse;
     914             :             }
     915             :             ELSE
     916             :             {
     917           8 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_combined->latency_s_fx; // Q31
     918           8 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_combined->max_num_iterations;
     919           8 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_combined->index_frequency_max_diffuse;
     920             :             }
     921          28 :             move32();
     922          28 :             move16();
     923          28 :             move16();
     924             : 
     925          84 :             FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     926             :             {
     927          56 :                 IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     928             :                 {
     929          40 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations_diffuse[j];
     930          40 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max_diffuse[j];
     931             : 
     932          40 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_re_fx[j]; // Q31
     933          40 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_diffuse_im_fx[j]; // Q31
     934             :                 }
     935             :                 ELSE
     936             :                 {
     937          16 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_combined->num_iterations_diffuse[j];
     938          16 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_combined->pIndex_frequency_max_diffuse[j];
     939             : 
     940          16 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_re_fx[j]; // Q31
     941          16 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_diffuse_im_fx[j]; // Q31
     942             :                 }
     943          56 :                 move32();
     944          56 :                 move32();
     945          56 :                 move16();
     946          56 :                 move16();
     947             :             }
     948             : 
     949         332 :             FOR( i = 0; i < hHrtf->max_num_ir; i++ )
     950             :             {
     951         304 :                 IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1 ) )
     952             :                 {
     953           0 :                     tmp = channelIndex_CICP6[i];
     954             :                 }
     955         304 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1 ) )
     956             :                 {
     957           0 :                     tmp = channelIndex_CICP12[i];
     958             :                 }
     959         304 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_2 ) )
     960             :                 {
     961           0 :                     tmp = channelIndex_CICP14[i];
     962             :                 }
     963         304 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_5_1_4 ) )
     964             :                 {
     965          18 :                     tmp = channelIndex_CICP16[i];
     966             :                 }
     967         286 :                 ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_7_1_4 ) )
     968             :                 {
     969         286 :                     tmp = channelIndex_CICP19[i];
     970             :                 }
     971             :                 ELSE
     972             :                 {
     973           0 :                     return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: Channel configuration not specified!\n\n" );
     974             :                 }
     975         304 :                 move16();
     976             : 
     977         304 :                 IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     978             :                 {
     979         218 :                     hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_brir_combined->inv_diffuse_weight_fx[tmp]; // Q15
     980             :                 }
     981             :                 ELSE
     982             :                 {
     983          86 :                     hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_combined->inv_diffuse_weight_fx[tmp]; // Q15
     984             :                 }
     985         304 :                 move16();
     986             : 
     987         912 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
     988             :                 {
     989         608 :                     IF( EQ_16( outConfig, IVAS_AUDIO_CONFIG_BINAURAL_ROOM_IR ) )
     990             :                     {
     991         436 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_brir_combined->num_iterations[tmp][j];
     992         436 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_brir_combined->pIndex_frequency_max[tmp][j];
     993             : 
     994         436 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_re_fx[tmp][j]; // Q29
     995         436 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_brir_combined->pOut_to_bin_im_fx[tmp][j]; // Q29
     996             :                     }
     997             :                     ELSE
     998             :                     {
     999         172 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_combined->num_iterations[tmp][j];
    1000         172 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pIndex_frequency_max[tmp][j];
    1001             : 
    1002         172 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_re_fx[tmp][j]; // Q29
    1003         172 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_combined->pOut_to_bin_im_fx[tmp][j]; // Q29
    1004             :                     }
    1005         608 :                     move32();
    1006         608 :                     move32();
    1007         608 :                     move16();
    1008         608 :                     move16();
    1009             :                 }
    1010             :             }
    1011             :         }
    1012           0 :         ELSE IF( EQ_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
    1013             :         {
    1014           0 :             IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) )
    1015             :             {
    1016           0 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa3->latency_s_fx; // Q31
    1017           0 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa3->max_num_iterations;
    1018           0 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_hoa3->index_frequency_max_diffuse;
    1019           0 :                 move32();
    1020           0 :                 move16();
    1021           0 :                 move16();
    1022             : 
    1023           0 :                 FOR( i = 0; i < hHrtf->max_num_ir; i++ )
    1024             :                 {
    1025           0 :                     hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa3->inv_diffuse_weight_fx[i]; // Q31
    1026           0 :                     move16();
    1027             : 
    1028           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1029             :                     {
    1030           0 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations[i][j];
    1031           0 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max[i][j];
    1032             : 
    1033           0 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_re_fx[i][j]; // Q29
    1034           0 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_im_fx[i][j]; // Q29
    1035           0 :                         move32();
    1036           0 :                         move32();
    1037           0 :                         move16();
    1038           0 :                         move16();
    1039             :                     }
    1040             :                 }
    1041           0 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1042             :                 {
    1043           0 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->num_iterations_diffuse[j];
    1044           0 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pIndex_frequency_max_diffuse[j];
    1045             : 
    1046           0 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_re_fx[j]; // Q31
    1047           0 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa3->pOut_to_bin_diffuse_im_fx[j]; // Q31
    1048           0 :                     move32();
    1049           0 :                     move32();
    1050           0 :                     move16();
    1051           0 :                     move16();
    1052             :                 }
    1053             :             }
    1054           0 :             ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) )
    1055             :             {
    1056           0 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_hoa2->latency_s_fx; // Q31
    1057           0 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_hoa2->max_num_iterations;
    1058           0 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_hoa2->index_frequency_max_diffuse;
    1059           0 :                 move32();
    1060           0 :                 move16();
    1061           0 :                 move16();
    1062             : 
    1063           0 :                 FOR( i = 0; i < hHrtf->max_num_ir; i++ )
    1064             :                 {
    1065           0 :                     hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_hoa2->inv_diffuse_weight_fx[i]; // Q15
    1066           0 :                     move16();
    1067             : 
    1068           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1069             :                     {
    1070           0 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations[i][j];
    1071           0 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max[i][j];
    1072             : 
    1073           0 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_re_fx[i][j]; // Q29
    1074           0 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_im_fx[i][j]; // Q29
    1075           0 :                         move32();
    1076           0 :                         move32();
    1077           0 :                         move16();
    1078           0 :                         move16();
    1079             :                     }
    1080             :                 }
    1081           0 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1082             :                 {
    1083           0 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->num_iterations_diffuse[j];
    1084           0 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pIndex_frequency_max_diffuse[j];
    1085             : 
    1086           0 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_re_fx[j]; // Q31
    1087           0 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_hoa2->pOut_to_bin_diffuse_im_fx[j]; // Q31
    1088           0 :                     move32();
    1089           0 :                     move32();
    1090           0 :                     move16();
    1091           0 :                     move16();
    1092             :                 }
    1093             :             }
    1094           0 :             ELSE IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_FOA ) )
    1095             :             {
    1096           0 :                 hHrtf->latency_s_fx = hSetOfHRTF->hHRTF_hrir_foa->latency_s_fx; // Q31
    1097           0 :                 hHrtf->max_num_iterations = hSetOfHRTF->hHRTF_hrir_foa->max_num_iterations;
    1098           0 :                 hHrtf->index_frequency_max_diffuse = hSetOfHRTF->hHRTF_hrir_foa->index_frequency_max_diffuse;
    1099           0 :                 move32();
    1100           0 :                 move16();
    1101           0 :                 move16();
    1102             : 
    1103           0 :                 FOR( i = 0; i < hHrtf->max_num_ir; i++ )
    1104             :                 {
    1105           0 :                     hHrtf->inv_diffuse_weight_fx[i] = hSetOfHRTF->hHRTF_hrir_foa->inv_diffuse_weight_fx[i]; // Q31
    1106           0 :                     move16();
    1107             : 
    1108           0 :                     FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1109             :                     {
    1110           0 :                         hHrtf->num_iterations[i][j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations[i][j];
    1111           0 :                         hHrtf->pIndex_frequency_max[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max[i][j];
    1112             : 
    1113           0 :                         hHrtf->pOut_to_bin_re_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_re_fx[i][j]; // Q29
    1114           0 :                         hHrtf->pOut_to_bin_im_fx[i][j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_im_fx[i][j]; // Q29
    1115           0 :                         move32();
    1116           0 :                         move32();
    1117           0 :                         move16();
    1118           0 :                         move16();
    1119             :                     }
    1120             :                 }
    1121           0 :                 FOR( j = 0; j < BINAURAL_CHANNELS; j++ )
    1122             :                 {
    1123           0 :                     hHrtf->num_iterations_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->num_iterations_diffuse[j];
    1124           0 :                     hHrtf->pIndex_frequency_max_diffuse[j] = hSetOfHRTF->hHRTF_hrir_foa->pIndex_frequency_max_diffuse[j];
    1125             : 
    1126           0 :                     hHrtf->pOut_to_bin_diffuse_re_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_re_fx[j]; // Q31
    1127           0 :                     hHrtf->pOut_to_bin_diffuse_im_fx[j] = hSetOfHRTF->hHRTF_hrir_foa->pOut_to_bin_diffuse_im_fx[j]; // Q31
    1128           0 :                     move32();
    1129           0 :                     move32();
    1130           0 :                     move16();
    1131           0 :                     move16();
    1132             :                 }
    1133             :             }
    1134             :             ELSE
    1135             :             {
    1136           0 :                 return IVAS_ERROR( IVAS_ERR_INTERNAL, "Unsupported renderer type in Crend" );
    1137             :             }
    1138             :         }
    1139             :     }
    1140             : 
    1141         403 :     pCrend->hHrtfCrend = hHrtf;
    1142             : 
    1143         403 :     return IVAS_ERR_OK;
    1144             : }
    1145             : 
    1146             : /*-------------------------------------------------------------------------
    1147             :  * ivas_shoebox_data_init()
    1148             :  *
    1149             :  * Initialize shoebox_data_t handle
    1150             :  *------------------------------------------------------------------------*/
    1151             : 
    1152          12 : static ivas_error ivas_shoebox_data_init(
    1153             :     shoebox_data_t *hShoeboxData /* i/o: shoebox_data_t handle     */
    1154             : )
    1155             : {
    1156             :     Word16 i;
    1157             : 
    1158          12 :     IF( hShoeboxData == NULL )
    1159             :     {
    1160           0 :         return IVAS_ERR_WRONG_PARAMS;
    1161             :     }
    1162             : 
    1163        1812 :     FOR( i = 0; i < 150; i++ )
    1164             :     {
    1165        1800 :         hShoeboxData->data_fx[i] = 0;
    1166        1800 :         move32();
    1167             :     }
    1168          24 :     FOR( i = 0; i < 1; i++ )
    1169             :     {
    1170          12 :         hShoeboxData->size[i] = 0;
    1171          12 :         move16();
    1172             :     }
    1173          12 :     return IVAS_ERR_OK;
    1174             : }
    1175             : 
    1176             : /*-------------------------------------------------------------------------
    1177             :  * ivas_shoebox_output_init()
    1178             :  *
    1179             :  * Initialize shoebox_output_t handle
    1180             :  *------------------------------------------------------------------------*/
    1181           3 : static ivas_error ivas_shoebox_output_init(
    1182             :     shoebox_output_t *hShoeboxOutput /* i/o: shoebox_output_t handle     */
    1183             : )
    1184             : {
    1185             :     ivas_error error;
    1186             : 
    1187           3 :     IF( hShoeboxOutput == NULL )
    1188             :     {
    1189           0 :         return IVAS_ERR_WRONG_PARAMS;
    1190             :     }
    1191             : 
    1192           3 :     hShoeboxOutput->n_sources = 0;
    1193           3 :     hShoeboxOutput->n_ref = 0;
    1194           3 :     move16();
    1195           3 :     move16();
    1196             : 
    1197           3 :     IF( NE_32( ( error = ivas_shoebox_data_init( &hShoeboxOutput->times ) ), IVAS_ERR_OK ) )
    1198             :     {
    1199           0 :         return error;
    1200             :     }
    1201             : 
    1202           3 :     IF( NE_32( ( error = ivas_shoebox_data_init( &hShoeboxOutput->gains ) ), IVAS_ERR_OK ) )
    1203             :     {
    1204           0 :         return error;
    1205             :     }
    1206             : 
    1207           3 :     IF( NE_32( ( error = ivas_shoebox_data_init( &hShoeboxOutput->az_angle ) ), IVAS_ERR_OK ) )
    1208             :     {
    1209           0 :         return error;
    1210             :     }
    1211             : 
    1212           3 :     IF( NE_32( ( error = ivas_shoebox_data_init( &hShoeboxOutput->el_angle ) ), IVAS_ERR_OK ) )
    1213             :     {
    1214           0 :         return error;
    1215             :     }
    1216             : 
    1217           3 :     return IVAS_ERR_OK;
    1218             : }
    1219             : 
    1220             : 
    1221             : /*-------------------------------------------------------------------------
    1222             :  * ivas_shoebox_config_init()
    1223             :  *
    1224             :  * Initialize shoebox_config_t handle
    1225             :  *------------------------------------------------------------------------*/
    1226             : 
    1227           3 : static ivas_error ivas_shoebox_config_init_params(
    1228             :     shoebox_config_t *hShoeboxConfig /* i/o: shoebox_config_t handle     */
    1229             : )
    1230             : {
    1231             :     Word16 i;
    1232             : 
    1233           3 :     IF( hShoeboxConfig == NULL )
    1234             :     {
    1235           0 :         return IVAS_ERR_WRONG_PARAMS;
    1236             :     }
    1237             : 
    1238           3 :     hShoeboxConfig->room_L_fx = 0;
    1239           3 :     hShoeboxConfig->room_W_fx = 0;
    1240           3 :     hShoeboxConfig->room_H_fx = 0;
    1241           3 :     move32();
    1242           3 :     move32();
    1243           3 :     move32();
    1244          21 :     FOR( i = 0; i < IVAS_ROOM_ABS_COEFF; i++ )
    1245             :     {
    1246          18 :         hShoeboxConfig->abs_coeff_fx[i] = 0;
    1247          18 :         move32();
    1248             :     }
    1249          12 :     FOR( i = 0; i < 3; i++ )
    1250             :     {
    1251           9 :         hShoeboxConfig->list_orig_fx[i] = 0;
    1252           9 :         move32();
    1253             :     }
    1254           3 :     return IVAS_ERR_OK;
    1255             : }
    1256             : 
    1257             : 
    1258             : /*-------------------------------------------------------------------------
    1259             :  * ivas_shoebox_obj_init()
    1260             :  *
    1261             :  * Initialize shoebox_obj_t handle
    1262             :  *------------------------------------------------------------------------*/
    1263             : 
    1264           3 : static ivas_error ivas_shoebox_obj_init(
    1265             :     shoebox_obj_t *hShoeboxObj /* i/o: shoebox_obj_t handle     */
    1266             : )
    1267             : {
    1268             :     Word16 i;
    1269             :     ivas_error error;
    1270             : 
    1271           3 :     IF( hShoeboxObj == NULL )
    1272             :     {
    1273           0 :         return IVAS_ERR_WRONG_PARAMS;
    1274             :     }
    1275             : 
    1276           3 :     hShoeboxObj->isCartesian = 0;
    1277           3 :     hShoeboxObj->isRelative = 0;
    1278           3 :     hShoeboxObj->isZHeight = 0;
    1279           3 :     hShoeboxObj->isRadians = 0;
    1280           3 :     hShoeboxObj->MAX_SOURCES = 0;
    1281           3 :     hShoeboxObj->max_bands = 0;
    1282           3 :     hShoeboxObj->REF_ORDER = 0;
    1283           3 :     move16();
    1284           3 :     move16();
    1285           3 :     move16();
    1286           3 :     move16();
    1287           3 :     move16();
    1288           3 :     move16();
    1289           3 :     move16();
    1290         228 :     FOR( i = 0; i < 75; i++ )
    1291             :     {
    1292         225 :         hShoeboxObj->src_pos_fx[i] = 0;
    1293         225 :         move32();
    1294             :     }
    1295          78 :     FOR( i = 0; i < 25; i++ )
    1296             :     {
    1297          75 :         hShoeboxObj->src_dist_fx[i] = 0;
    1298          75 :         move32();
    1299             :     }
    1300          12 :     FOR( i = 0; i < 3; i++ )
    1301             :     {
    1302           9 :         hShoeboxObj->list_pos_fx[i] = 0;
    1303           9 :         move32();
    1304             :     }
    1305             : 
    1306           3 :     hShoeboxObj->nSrc = 0;
    1307           3 :     hShoeboxObj->radius_fx = 0;
    1308           3 :     hShoeboxObj->min_wall_dist_fx = 0;
    1309           3 :     hShoeboxObj->soundspeed_fx = 0;
    1310           3 :     hShoeboxObj->air_coeff_fx = 0;
    1311           3 :     move16();
    1312           3 :     move32();
    1313           3 :     move32();
    1314           3 :     move32();
    1315           3 :     move32();
    1316             : 
    1317           3 :     IF( NE_32( ( error = ivas_shoebox_config_init_params( &hShoeboxObj->cal ) ), IVAS_ERR_OK ) )
    1318             :     {
    1319           0 :         return error;
    1320             :     }
    1321             : 
    1322           3 :     return IVAS_ERR_OK;
    1323             : }
    1324             : 
    1325             : 
    1326             : /*-------------------------------------------------------------------------
    1327             :  * ivas_er_init_handle()
    1328             :  *
    1329             :  * Initialize early reflections handle
    1330             :  *------------------------------------------------------------------------*/
    1331             : 
    1332           3 : static ivas_error ivas_er_init_handle(
    1333             :     er_struct_t *reflections /* i/o: early reflections handle     */
    1334             : )
    1335             : {
    1336             :     Word16 i;
    1337             :     ivas_error error;
    1338           3 :     IF( reflections == NULL )
    1339             :     {
    1340           0 :         return IVAS_ERR_WRONG_PARAMS;
    1341             :     }
    1342           3 :     reflections->audio_config = IVAS_AUDIO_CONFIG_INVALID;
    1343           3 :     reflections->use_er = 0;
    1344           3 :     reflections->is_ready = 0;
    1345           3 :     reflections->circ_len = 0;
    1346           3 :     reflections->circ_insert = 0;
    1347           3 :     reflections->n_total_reflections = 0;
    1348           3 :     reflections->is_cartesian = 0;
    1349           3 :     reflections->is_relative = 0;
    1350           3 :     reflections->max_frame_size = 0;
    1351           3 :     reflections->output_Fs_fx = 0;
    1352           3 :     move16();
    1353           3 :     move16();
    1354           3 :     move16();
    1355           3 :     move16();
    1356           3 :     move16();
    1357           3 :     move16();
    1358           3 :     move16();
    1359           3 :     move32();
    1360           3 :     move32();
    1361           3 :     move32();
    1362         228 :     FOR( i = 0; i < 75; i++ )
    1363             :     {
    1364         225 :         reflections->source_positions_fx[i] = 0;
    1365         225 :         move16();
    1366             :     }
    1367          12 :     FOR( i = 0; i < 3; i++ )
    1368             :     {
    1369           9 :         reflections->user_origin_fx[i] = 0;
    1370           9 :         move32();
    1371           9 :         if ( EQ_16( i, 2 ) )
    1372             :         {
    1373           3 :             reflections->user_origin_fx[i] = ER_LIST_HEIGHT_FX; // Q22
    1374           3 :             move32();
    1375             :         }
    1376             :     }
    1377           3 :     reflections->circ_buffers = NULL;
    1378           3 :     reflections->closest_ch_idx = NULL;
    1379             : 
    1380           3 :     IF( NE_32( ( error = ivas_shoebox_output_init( &reflections->shoebox_data ) ), IVAS_ERR_OK ) )
    1381             :     {
    1382           0 :         return error;
    1383             :     }
    1384           3 :     IF( NE_32( ( error = ivas_shoebox_obj_init( &reflections->shoebox_lib ) ), IVAS_ERR_OK ) )
    1385             :     {
    1386           0 :         return error;
    1387             :     }
    1388           3 :     return IVAS_ERR_OK;
    1389             : }
    1390             : 
    1391             : /*-------------------------------------------------------------------------
    1392             :  * ivas_rend_initCrendWrapper()
    1393             :  *
    1394             :  * Allocate and initialize crend renderer handle
    1395             :  *------------------------------------------------------------------------*/
    1396             : 
    1397         403 : ivas_error ivas_rend_initCrendWrapper(
    1398             :     CREND_WRAPPER_HANDLE *pCrend )
    1399             : {
    1400             :     Word16 i;
    1401             :     CREND_HANDLE hCrend;
    1402             : 
    1403         403 :     IF( pCrend == NULL )
    1404             :     {
    1405           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" );
    1406             :     }
    1407             : 
    1408         403 :     IF( ( *pCrend = (CREND_WRAPPER_HANDLE) malloc( sizeof( CREND_WRAPPER ) ) ) == NULL )
    1409             :     {
    1410           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend Wrapper\n" );
    1411             :     }
    1412             : 
    1413         403 :     ( *pCrend )->binaural_latency_ns = 0;
    1414         403 :     move32();
    1415         403 :     ( *pCrend )->hHrtfCrend = NULL;
    1416             : 
    1417             :     {
    1418         403 :         hCrend = NULL;
    1419         403 :         IF( ( hCrend = (CREND_HANDLE) malloc( sizeof( CREND_DATA ) ) ) == NULL )
    1420             :         {
    1421           0 :             return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for renderer handle" );
    1422             :         }
    1423             : 
    1424         403 :         hCrend->lfe_delay_line_fx = NULL;
    1425             : 
    1426        6851 :         FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
    1427             :         {
    1428        6448 :             hCrend->freq_buffer_re_fx[i] = NULL;
    1429        6448 :             hCrend->freq_buffer_im_fx[i] = NULL;
    1430             :         }
    1431             : 
    1432        1209 :         FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
    1433             :         {
    1434         806 :             hCrend->prev_out_buffer_fx[i] = NULL;
    1435             :         }
    1436             : 
    1437         403 :         hCrend->hTrack = NULL;
    1438         403 :         hCrend->freq_buffer_re_diffuse_fx = NULL;
    1439         403 :         hCrend->freq_buffer_im_diffuse_fx = NULL;
    1440         403 :         hCrend->hReverb = NULL;
    1441         403 :         hCrend->reflections = NULL;
    1442         403 :         hCrend->delay_line_rw_index = 0;
    1443         403 :         hCrend->diffuse_delay_line_rw_index = 0;
    1444         403 :         move16();
    1445         403 :         move16();
    1446         403 :         hCrend->m_fYaw_fx = 0;
    1447         403 :         hCrend->m_fPitch_fx = 0;
    1448         403 :         hCrend->m_fRoll_fx = 0;
    1449         403 :         move32();
    1450         403 :         move32();
    1451         403 :         move32();
    1452             : 
    1453         403 :         ( *pCrend )->hCrend = hCrend;
    1454             :     }
    1455             : 
    1456         403 :     return IVAS_ERR_OK;
    1457             : }
    1458             : 
    1459             : 
    1460             : /*-------------------------------------------------------------------------
    1461             :  * ivas_rend_openCrend()
    1462             :  *
    1463             :  * Allocate and initialize crend renderer handle
    1464             :  *------------------------------------------------------------------------*/
    1465             : 
    1466         403 : ivas_error ivas_rend_openCrend(
    1467             :     CREND_WRAPPER_HANDLE *pCrend,
    1468             :     const AUDIO_CONFIG inConfig,
    1469             :     const AUDIO_CONFIG outConfig,
    1470             :     RENDER_CONFIG_DATA *hRendCfg,
    1471             :     HRTFS_CREND_HANDLE hSetOfHRTF,
    1472             :     const Word32 output_Fs )
    1473             : {
    1474             :     Word16 i, subframe_length;
    1475             :     Word16 max_total_ir_len;
    1476             :     HRTFS_HANDLE hHrtf;
    1477             :     CREND_HANDLE hCrend;
    1478             :     ivas_error error;
    1479             : 
    1480         403 :     error = IVAS_ERR_OK;
    1481         403 :     move16();
    1482             : 
    1483         403 :     IF( NE_32( ( error = ivas_rend_initCrendWrapper( pCrend ) ), IVAS_ERR_OK ) )
    1484             :     {
    1485           0 :         return error;
    1486             :     }
    1487             : 
    1488         403 :     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*/
    1489             : 
    1490         403 :     IF( ( *pCrend )->hHrtfCrend == NULL ){
    1491         403 :         IF( NE_32( ( error = ivas_rend_initCrend_fx( *pCrend, inConfig, outConfig, hSetOfHRTF, output_Fs ) ), IVAS_ERR_OK ) ){
    1492           0 :             return error;
    1493             : }
    1494             : }
    1495             : 
    1496             : {
    1497         403 :     hCrend = ( *pCrend )->hCrend;
    1498         403 :     hHrtf = ( *pCrend )->hHrtfCrend;
    1499             : 
    1500         403 :     IF( hHrtf != NULL )
    1501             :     {
    1502         403 :         max_total_ir_len = imult1616( hHrtf->max_num_iterations, subframe_length );
    1503             : 
    1504        3871 :         FOR( i = 0; i < hHrtf->max_num_ir; i++ )
    1505             :         {
    1506        3468 :             IF( ( hCrend->freq_buffer_re_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1507             :             {
    1508           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1509             :             }
    1510        3468 :             set_zero_fx( hCrend->freq_buffer_re_fx[i], max_total_ir_len );
    1511        3468 :             IF( ( hCrend->freq_buffer_im_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1512             :             {
    1513           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1514             :             }
    1515        3468 :             set_zero_fx( hCrend->freq_buffer_im_fx[i], max_total_ir_len );
    1516             :         }
    1517             : 
    1518        1209 :         FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
    1519             :         {
    1520         806 :             IF( ( hCrend->prev_out_buffer_fx[i] = (Word32 *) malloc( sizeof( Word32 ) * subframe_length ) ) == NULL )
    1521             :             {
    1522           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1523             :             }
    1524         806 :             set_zero_fx( hCrend->prev_out_buffer_fx[i], subframe_length );
    1525             :         }
    1526             : 
    1527         403 :         max_total_ir_len = imult1616( (Word16) hHrtf->num_iterations_diffuse[0], subframe_length );
    1528             : 
    1529         403 :         IF( max_total_ir_len > 0 )
    1530             :         {
    1531         254 :             IF( ( hCrend->freq_buffer_re_diffuse_fx = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1532             :             {
    1533           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1534             :             }
    1535         254 :             set_zero_fx( hCrend->freq_buffer_re_diffuse_fx, max_total_ir_len );
    1536         254 :             IF( ( hCrend->freq_buffer_im_diffuse_fx = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1537             :             {
    1538           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1539             :             }
    1540         254 :             set_zero_fx( hCrend->freq_buffer_im_diffuse_fx, max_total_ir_len );
    1541             :         }
    1542             :         ELSE
    1543             :         {
    1544         149 :             hCrend->freq_buffer_re_diffuse_fx = NULL;
    1545         149 :             hCrend->freq_buffer_im_diffuse_fx = NULL;
    1546             :         }
    1547             : 
    1548         403 :         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;*/
    1549         403 :         IF( max_total_ir_len > 0 )
    1550             :         {
    1551         403 :             IF( ( hCrend->lfe_delay_line_fx = (Word32 *) malloc( sizeof( Word32 ) * max_total_ir_len ) ) == NULL )
    1552             :             {
    1553           0 :                 return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend" );
    1554             :             }
    1555         403 :             set_zero_fx( hCrend->lfe_delay_line_fx, max_total_ir_len );
    1556             :         }
    1557             :         ELSE
    1558             :         {
    1559           0 :             hCrend->lfe_delay_line_fx = NULL;
    1560             :         }
    1561             : 
    1562         403 :         IF( outConfig == IVAS_AUDIO_CONFIG_BINAURAL_ROOM_REVERB )
    1563             :         {
    1564         110 :             IF( NE_32( ( error = ivas_reverb_open_fx( &( hCrend->hReverb ), inConfig, ( *pCrend )->hHrtfCrend, NULL, hRendCfg, output_Fs ) ), IVAS_ERR_OK ) )
    1565             :             {
    1566           0 :                 return error;
    1567             :             }
    1568             : 
    1569         110 :             IF( EQ_16( hRendCfg->roomAcoustics.use_er, 1 ) )
    1570             :             {
    1571             : 
    1572             :                 /* Allocate memory for reflections */
    1573           3 :                 hCrend->reflections = (er_struct_t *) malloc( sizeof( er_struct_t ) );
    1574           3 :                 IF( !hCrend->reflections )
    1575             :                 {
    1576           0 :                     return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Early Reflections" );
    1577             :                 }
    1578           3 :                 IF( NE_32( ( error = ivas_er_init_handle( hCrend->reflections ) ), IVAS_ERR_OK ) )
    1579             :                 {
    1580           0 :                     return error;
    1581             :                 }
    1582             : 
    1583           3 :                 hCrend->reflections->use_er = hRendCfg->roomAcoustics.use_er;
    1584           3 :                 hCrend->reflections->lowComplexity = hRendCfg->roomAcoustics.lowComplexity;
    1585           3 :                 move16();
    1586           3 :                 move32();
    1587             : 
    1588             :                 /* Set sample rate and frame size */
    1589             : 
    1590           3 :                 hCrend->reflections->output_Fs_fx = output_Fs; // Q0
    1591           3 :                 move32();
    1592             : 
    1593           3 :                 hCrend->reflections->max_frame_size = extract_l( Mult_32_16( output_Fs, INV_FRAME_PER_SEC_Q15 ) );
    1594           3 :                 move32();
    1595             : 
    1596             :                 /* Init Shoebox */
    1597           3 :                 ivas_shoebox_config_init( &hCrend->reflections->shoebox_lib.cal, hRendCfg );
    1598             : 
    1599             :                 /* Init and compute Reflections */
    1600           3 :                 IF( NE_32( ( error = ivas_er_init( hCrend->reflections, inConfig ) ), IVAS_ERR_OK ) )
    1601             :                 {
    1602           0 :                     return error;
    1603             :                 }
    1604             :             }
    1605             :             ELSE
    1606             :             {
    1607         107 :                 hCrend->reflections = NULL;
    1608             :             }
    1609             :         }
    1610             :         ELSE
    1611             :         {
    1612         293 :             hCrend->hReverb = NULL;
    1613             :         }
    1614             : 
    1615         403 :         ( *pCrend )->binaural_latency_ns = Mult_32_32( ( *pCrend )->hHrtfCrend->latency_s_fx, (Word32) 1000000000 );
    1616         403 :         move32();
    1617             :     }
    1618             : 
    1619         403 :     ( *pCrend )->hCrend = hCrend;
    1620             : }
    1621         403 : return IVAS_ERR_OK;
    1622             : }
    1623             : 
    1624             : /*-------------------------------------------------------------------------
    1625             :  * ivas_rend_closeCrend()
    1626             :  *
    1627             :  * Deallocate Crend renderer handle
    1628             :  *------------------------------------------------------------------------*/
    1629             : 
    1630       40121 : void ivas_rend_closeCrend(
    1631             :     CREND_WRAPPER_HANDLE *pCrend )
    1632             : {
    1633             :     Word16 i;
    1634             :     CREND_HANDLE hCrend;
    1635             : 
    1636       40121 :     test();
    1637       40121 :     IF( pCrend == NULL || *pCrend == NULL )
    1638             :     {
    1639       39718 :         return;
    1640             :     }
    1641             : 
    1642         403 :     IF( ( *pCrend )->hHrtfCrend != NULL )
    1643             :     {
    1644         403 :         ivas_hrtf_close( &( *pCrend )->hHrtfCrend );
    1645             :     }
    1646             : 
    1647             :     {
    1648         403 :         hCrend = ( *pCrend )->hCrend;
    1649         403 :         IF( hCrend != NULL )
    1650             :         {
    1651        6851 :             FOR( i = 0; i < MAX_INTERN_CHANNELS; i++ )
    1652             :             {
    1653        6448 :                 IF( hCrend->freq_buffer_re_fx[i] != NULL )
    1654             :                 {
    1655        3468 :                     free( hCrend->freq_buffer_re_fx[i] );
    1656        3468 :                     hCrend->freq_buffer_re_fx[i] = NULL;
    1657             :                 }
    1658        6448 :                 IF( hCrend->freq_buffer_im_fx[i] != NULL )
    1659             :                 {
    1660        3468 :                     free( hCrend->freq_buffer_im_fx[i] );
    1661        3468 :                     hCrend->freq_buffer_im_fx[i] = NULL;
    1662             :                 }
    1663             :             }
    1664             : 
    1665        1209 :             FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
    1666             :             {
    1667         806 :                 IF( hCrend->prev_out_buffer_fx[i] != NULL )
    1668             :                 {
    1669         806 :                     free( hCrend->prev_out_buffer_fx[i] );
    1670         806 :                     hCrend->prev_out_buffer_fx[i] = NULL;
    1671             :                 }
    1672             :             }
    1673             : 
    1674         403 :             IF( hCrend->lfe_delay_line_fx != NULL )
    1675             :             {
    1676         403 :                 free( hCrend->lfe_delay_line_fx );
    1677         403 :                 hCrend->lfe_delay_line_fx = NULL;
    1678             :             }
    1679             : 
    1680         403 :             IF( hCrend->freq_buffer_re_diffuse_fx != NULL )
    1681             :             {
    1682         254 :                 free( hCrend->freq_buffer_re_diffuse_fx );
    1683         254 :                 hCrend->freq_buffer_re_diffuse_fx = NULL;
    1684             :             }
    1685         403 :             IF( hCrend->freq_buffer_im_diffuse_fx != NULL )
    1686             :             {
    1687         254 :                 free( hCrend->freq_buffer_im_diffuse_fx );
    1688         254 :                 hCrend->freq_buffer_im_diffuse_fx = NULL;
    1689             :             }
    1690         403 :             IF( hCrend->hTrack != NULL )
    1691             :             {
    1692           0 :                 free( hCrend->hTrack );
    1693           0 :                 hCrend->hTrack = NULL;
    1694             :             }
    1695             : 
    1696         403 :             ivas_reverb_close( &hCrend->hReverb );
    1697             : 
    1698         403 :             IF( hCrend->reflections != NULL )
    1699             :             {
    1700           3 :                 IF( hCrend->reflections->closest_ch_idx != NULL )
    1701             :                 {
    1702           3 :                     free( hCrend->reflections->closest_ch_idx );
    1703           3 :                     hCrend->reflections->closest_ch_idx = NULL;
    1704             :                 }
    1705           3 :                 IF( hCrend->reflections->circ_buffers != NULL )
    1706             :                 {
    1707           3 :                     free( hCrend->reflections->circ_buffers );
    1708           3 :                     hCrend->reflections->circ_buffers = NULL;
    1709             :                 }
    1710           3 :                 free( hCrend->reflections );
    1711           3 :                 hCrend->reflections = NULL;
    1712             :             }
    1713         403 :             free( hCrend );
    1714         403 :             hCrend = NULL;
    1715         403 :             ( *pCrend )->hCrend = hCrend;
    1716             :         }
    1717             :     }
    1718             : 
    1719         403 :     free( *pCrend );
    1720         403 :     *pCrend = NULL;
    1721             : 
    1722         403 :     return;
    1723             : }
    1724             : 
    1725             : 
    1726             : /*-----------------------------------------------------------------------------------------*
    1727             :  * Function ivas_rend_crendConvolver()
    1728             :  *
    1729             :  * Convolver block
    1730             :  *-----------------------------------------------------------------------------------------*/
    1731             : 
    1732      572159 : static ivas_error ivas_rend_crendConvolver(
    1733             :     const CREND_WRAPPER *pCrend,
    1734             :     AUDIO_CONFIG inConfig,
    1735             :     AUDIO_CONFIG outConfig,
    1736             :     Word32 *pcm_in[],  // Qx
    1737             :     Word32 *pcm_out[], // Qx
    1738             :     const Word32 output_Fs,
    1739             :     const Word16 i_ts )
    1740             : {
    1741             :     Word16 i, j, k, m;
    1742             :     Word16 subframe_length, idx_in;
    1743             :     Word16 lfe_idx_in;
    1744             :     Word16 offset, offset_in, offset_diffuse;
    1745             :     Word16 nchan_in, nchan_out;
    1746             :     const Word32 *pIn;
    1747             :     Word32 *pFreq_buf_re, *pFreq_buf_im;
    1748             :     const Word32 *pFreq_filt_re, *pFreq_filt_im;
    1749             :     Word32 pOut[L_FRAME48k * 2];
    1750             :     Word32 tmp_out_re[L_FRAME48k];
    1751             :     Word32 tmp_out_im[L_FRAME48k];
    1752             :     CREND_HANDLE hCrend;
    1753             :     ivas_error error;
    1754             : 
    1755             : 
    1756      572159 :     hCrend = pCrend->hCrend;
    1757             : 
    1758      572159 :     IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) )
    1759             :     {
    1760           0 :         return error;
    1761             :     }
    1762             : 
    1763      572159 :     IF( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) )
    1764             :     {
    1765           0 :         return error;
    1766             :     }
    1767             : 
    1768             :     /* subframe_length = (int16_t) ( output_Fs / FRAMES_PER_SEC ) / MAX_PARAM_SPATIAL_SUBFRAMES; */
    1769      572159 :     subframe_length = extract_l( Mpy_32_32_r( output_Fs, 10737418 /* 1 / ( FRAMES_PER_SEC * MAX_PARAM_SPATIAL_SUBFRAMES ) in Q31 */ ) );
    1770             : 
    1771      572159 :     lfe_idx_in = -1;
    1772      572159 :     move16();
    1773      572159 :     IF( EQ_32( getAudioConfigType( inConfig ), IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) )
    1774             :     {
    1775      523529 :         IF( NE_32( inConfig, IVAS_AUDIO_CONFIG_LS_CUSTOM ) )
    1776             :         {
    1777      523529 :             lfe_idx_in = LFE_CHANNEL;
    1778      523529 :             move16();
    1779             :         }
    1780             :         ELSE
    1781             :         {
    1782           0 :             assert( 0 && "Custom LS not supported in CRend" );
    1783             :         }
    1784             :     }
    1785             : 
    1786      572159 :     offset = imult1616( hCrend->delay_line_rw_index, subframe_length );                 /* subframe_length * ( pCrend->hHrtfCrend->max_num_iterations - 1 ); */
    1787      572159 :     offset_diffuse = imult1616( hCrend->diffuse_delay_line_rw_index, subframe_length ); /* subframe_length *( pCrend->hHrtfCrend->num_iterations_diffuse[0] - 1 ); */
    1788             : 
    1789      572159 :     IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    1790             :     {
    1791      397929 :         set32_fx( &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse], 0, subframe_length );
    1792      397929 :         set32_fx( &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse], 0, subframe_length );
    1793             :     }
    1794             : 
    1795      572159 :     i = 0;
    1796      572159 :     move16();
    1797     6827757 :     FOR( idx_in = 0; idx_in < nchan_in; idx_in++ )
    1798             :     {
    1799     6255598 :         pIn = &pcm_in[idx_in][i_ts * subframe_length];
    1800             : 
    1801     6255598 :         IF( NE_16( idx_in, lfe_idx_in ) )
    1802             :         {
    1803     5732069 :             IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    1804             :             {
    1805     4124019 :                 pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse]; // Qx
    1806     4124019 :                 pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse]; // Qx
    1807     4124019 :                 pFreq_filt_re = &hCrend->freq_buffer_re_fx[i][offset];             // Qx
    1808     4124019 :                 pFreq_filt_im = &hCrend->freq_buffer_im_fx[i][offset];             // Qx
    1809   408095926 :                 FOR( k = 0; k < pCrend->hHrtfCrend->index_frequency_max_diffuse; k++ )
    1810             :                 {
    1811   403971907 :                     pFreq_buf_re[k] = L_add( Mpy_32_16_r( pFreq_filt_re[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_re[k] ); // Qx
    1812   403971907 :                     pFreq_buf_im[k] = L_add( Mpy_32_16_r( pFreq_filt_im[k], pCrend->hHrtfCrend->inv_diffuse_weight_fx[i] ), pFreq_buf_im[k] ); // Qx
    1813   403971907 :                     move32();
    1814   403971907 :                     move32();
    1815             :                 }
    1816             :             }
    1817     5732069 :             pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset]; // Qx
    1818     5732069 :             pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset]; // Qx
    1819             : 
    1820             : 
    1821     5732069 :             ivas_mdft_fx( pIn, pFreq_buf_re, pFreq_buf_im, subframe_length, subframe_length );
    1822             : #ifdef DEBUGGING
    1823             :             dbgwrite_txt( (const float *) pFreq_buf_re, subframe_length, "Fixed_pFreq_buf_re_mdft.txt", NULL );
    1824             :             dbgwrite_txt( (const float *) pFreq_buf_im, subframe_length, "Fixed_pFreq_buf_im_mdft.txt", NULL );
    1825             : #endif
    1826     5732069 :             i = add( i, 1 );
    1827             :         }
    1828             :     }
    1829             : 
    1830     1716477 :     FOR( j = 0; j < nchan_out; j++ )
    1831             :     {
    1832     1144318 :         set32_fx( tmp_out_re, 0, subframe_length );
    1833     1144318 :         set32_fx( tmp_out_im, 0, subframe_length );
    1834     1144318 :         i = 0;
    1835     1144318 :         move16();
    1836    13655514 :         FOR( idx_in = 0; idx_in < nchan_in; idx_in++ )
    1837             :         {
    1838    12511196 :             IF( NE_16( idx_in, lfe_idx_in ) )
    1839             :             {
    1840    11464138 :                 offset = 0;
    1841    11464138 :                 move16();
    1842   196151234 :                 FOR( m = 0; m < pCrend->hHrtfCrend->num_iterations[i][j]; m++ )
    1843             :                 {
    1844   184687096 :                     offset_in = add( add( hCrend->delay_line_rw_index, sub( pCrend->hHrtfCrend->max_num_iterations, pCrend->hHrtfCrend->num_iterations[i][j] ) ), add( m, 1 ) );
    1845   184687096 :                     offset_in = offset_in % ( pCrend->hHrtfCrend->max_num_iterations );
    1846   184687096 :                     move16();
    1847   184687096 :                     offset_in = imult1616( offset_in, subframe_length );
    1848   184687096 :                     pFreq_buf_re = &hCrend->freq_buffer_re_fx[i][offset_in];              // Qx
    1849   184687096 :                     pFreq_buf_im = &hCrend->freq_buffer_im_fx[i][offset_in];              // Qx
    1850   184687096 :                     pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_re_fx[i][j][offset]; // Q29
    1851   184687096 :                     pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_im_fx[i][j][offset]; // Q29
    1852             : 
    1853 24669251982 :                     FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max[i][j][m]; k++ )
    1854             :                     {
    1855 24484564886 :                         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
    1856 24484564886 :                         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
    1857 24484564886 :                         move32();
    1858 24484564886 :                         move32();
    1859             :                     }
    1860   184687096 :                     offset = add( offset, k );
    1861             :                 }
    1862    11464138 :                 i = add( i, 1 );
    1863             :             }
    1864             :         }
    1865             : 
    1866     1144318 :         offset = 0;
    1867     1144318 :         move16();
    1868    32978638 :         FOR( m = 0; m < pCrend->hHrtfCrend->num_iterations_diffuse[j]; m++ )
    1869             :         {
    1870    31834320 :             offset_diffuse = add( hCrend->diffuse_delay_line_rw_index, add( m, 1 ) );
    1871    31834320 :             offset_diffuse = offset_diffuse % pCrend->hHrtfCrend->num_iterations_diffuse[0];
    1872    31834320 :             move16();
    1873    31834320 :             offset_diffuse = imult1616( offset_diffuse, subframe_length );
    1874    31834320 :             pFreq_buf_re = &hCrend->freq_buffer_re_diffuse_fx[offset_diffuse];         // Qx
    1875    31834320 :             pFreq_buf_im = &hCrend->freq_buffer_im_diffuse_fx[offset_diffuse];         // Qx
    1876    31834320 :             pFreq_filt_re = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_re_fx[j][offset]; // Q31
    1877    31834320 :             pFreq_filt_im = &pCrend->hHrtfCrend->pOut_to_bin_diffuse_im_fx[j][offset]; // Q31
    1878  2327184060 :             FOR( k = 0; k < pCrend->hHrtfCrend->pIndex_frequency_max_diffuse[j][m]; k++ )
    1879             :             {
    1880  2295349740 :                 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
    1881  2295349740 :                 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
    1882  2295349740 :                 move32();
    1883  2295349740 :                 move32();
    1884             :             }
    1885    31834320 :             offset = add( offset, k );
    1886             :         }
    1887             : 
    1888     1144318 :         ivas_imdft_fx( tmp_out_re, tmp_out_im, pOut, subframe_length );
    1889     1144318 :         scale_sig32( pOut, shl( subframe_length, 1 ), 2 );
    1890             : #ifdef DEBUGGING
    1891             :         dbgwrite_txt( (const float *) pOut, subframe_length << 1, "Fixed_imdft_out.txt", NULL );
    1892             : #endif
    1893     1144318 :         pFreq_buf_re = &pcm_out[j][i_ts * subframe_length];
    1894   273063038 :         FOR( k = 0; k < subframe_length; k++ )
    1895             :         {
    1896   271918720 :             pFreq_buf_re[k] = L_add( pOut[k], hCrend->prev_out_buffer_fx[j][k] ); // Qx
    1897   271918720 :             hCrend->prev_out_buffer_fx[j][k] = pOut[k + subframe_length];         // Qx
    1898   271918720 :             move32();
    1899   271918720 :             move32();
    1900             :         }
    1901             :     }
    1902             : 
    1903      572159 :     hCrend->delay_line_rw_index = add( hCrend->delay_line_rw_index, 1 );
    1904      572159 :     hCrend->delay_line_rw_index = hCrend->delay_line_rw_index % ( pCrend->hHrtfCrend->max_num_iterations );
    1905      572159 :     move16();
    1906      572159 :     move16();
    1907      572159 :     IF( pCrend->hHrtfCrend->num_iterations_diffuse[0] > 0 )
    1908             :     {
    1909      397929 :         hCrend->diffuse_delay_line_rw_index = add( hCrend->diffuse_delay_line_rw_index, 1 );
    1910      397929 :         hCrend->diffuse_delay_line_rw_index = hCrend->diffuse_delay_line_rw_index % ( pCrend->hHrtfCrend->num_iterations_diffuse[0] );
    1911      397929 :         move16();
    1912      397929 :         move16();
    1913             :     }
    1914             : 
    1915      572159 :     return IVAS_ERR_OK;
    1916             : }
    1917             : 
    1918             : /*-----------------------------------------------------------------------------------------*
    1919             :  * Function ivas_rend_crend_Process()
    1920             :  *
    1921             :  * Process call for IVAS Crend renderer
    1922             :  *-----------------------------------------------------------------------------------------*/
    1923             : 
    1924      302544 : ivas_error ivas_rend_crendProcess(
    1925             :     const CREND_WRAPPER *pCrend,
    1926             :     const AUDIO_CONFIG inConfig,
    1927             :     const AUDIO_CONFIG outConfig,
    1928             :     DECODER_CONFIG_HANDLE hDecoderConfig,
    1929             :     COMBINED_ORIENTATION_HANDLE hCombinedOrientationData,
    1930             :     IVAS_OUTPUT_SETUP_HANDLE hIntSetup,
    1931             :     EFAP_HANDLE hEFAPdata,
    1932             :     Word32 *output_fx[], /* i/o: input/output audio channels   Qx  */
    1933             :     const Word32 output_Fs,
    1934             :     const Word16 num_subframes /* i  : number of subframes to render */
    1935             : )
    1936             : {
    1937             :     Word16 i, subframe_idx, subframe_len;
    1938             :     Word16 nchan_out;
    1939             :     Word32 pcm_tmp_fx[BINAURAL_CHANNELS][L_FRAME48k];
    1940             :     Word32 *p_pcm_tmp_fx[BINAURAL_CHANNELS];
    1941             :     IVAS_REND_AudioConfigType inConfigType;
    1942             :     Word8 combinedOrientationEnabled;
    1943             :     ivas_error error;
    1944             :     CREND_HANDLE hCrend;
    1945             : 
    1946      302544 :     hCrend = pCrend->hCrend;
    1947             : 
    1948      302544 :     combinedOrientationEnabled = 0;
    1949      302544 :     move16();
    1950      302544 :     IF( hCombinedOrientationData != NULL )
    1951             :     {
    1952           0 :         FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ )
    1953             :         {
    1954           0 :             IF( hCombinedOrientationData->enableCombinedOrientation[subframe_idx] != 0 )
    1955             :             {
    1956           0 :                 combinedOrientationEnabled = 1;
    1957           0 :                 move16();
    1958           0 :                 BREAK;
    1959             :             }
    1960             :         }
    1961             :     }
    1962             : 
    1963      302544 :     push_wmops( "ivas_rend_crendProcess" );
    1964      302544 :     inConfigType = getAudioConfigType( inConfig );
    1965             : 
    1966      302544 :     IF( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) )
    1967             :     {
    1968           0 :         return error;
    1969             :     }
    1970      302544 :     subframe_len = L_SUBFRAME_48k;
    1971      302544 :     move16();
    1972      302544 :     SWITCH( output_Fs )
    1973             :     {
    1974      302544 :         case 48000:
    1975      302544 :             subframe_len = L_SUBFRAME_48k;
    1976      302544 :             move16();
    1977      302544 :             BREAK;
    1978           0 :         case 32000:
    1979           0 :             subframe_len = L_SUBFRAME_32k;
    1980           0 :             move16();
    1981           0 :             BREAK;
    1982           0 :         case 16000:
    1983           0 :             subframe_len = L_SUBFRAME_16k;
    1984           0 :             move16();
    1985           0 :             BREAK;
    1986           0 :         case 8000:
    1987           0 :             subframe_len = L_SUBFRAME_8k;
    1988           0 :             move16();
    1989           0 :             BREAK;
    1990           0 :         default:
    1991           0 :             BREAK;
    1992             :     }
    1993             : 
    1994      907632 :     FOR( i = 0; i < BINAURAL_CHANNELS; i++ )
    1995             :     {
    1996      605088 :         p_pcm_tmp_fx[i] = pcm_tmp_fx[i];
    1997      605088 :         move32();
    1998             :     }
    1999             : 
    2000      786654 :     FOR( subframe_idx = 0; subframe_idx < num_subframes; subframe_idx++ )
    2001             :     {
    2002             :         /* Early Reflections */
    2003      484110 :         IF( hCrend->reflections != NULL )
    2004             :         {
    2005           0 :             test();
    2006           0 :             IF( EQ_16( hCrend->reflections->use_er, 1 ) && EQ_16( hCrend->reflections->is_ready, 1 ) )
    2007             :             {
    2008           0 :                 IF( NE_32( ( error = ivas_er_process( hCrend->reflections, subframe_len, subframe_idx, output_fx, inConfig ) ), IVAS_ERR_OK ) )
    2009             :                 {
    2010           0 :                     return error;
    2011             :                 }
    2012             :             }
    2013             :         }
    2014             : 
    2015      484110 :         test();
    2016      484110 :         IF( hDecoderConfig && combinedOrientationEnabled )
    2017             :         {
    2018             :             /* Orientation tracking */
    2019             : 
    2020             :             /* Rotation in SHD for:
    2021             :                 MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL
    2022             :                 SBA SPAR -> BINAURAL or BINAURAL_ROOM
    2023             :             */
    2024           0 :             test();
    2025           0 :             test();
    2026           0 :             test();
    2027           0 :             IF( EQ_16( inConfig, IVAS_AUDIO_CONFIG_FOA ) || EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_16( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) )
    2028             :             {
    2029           0 :                 rotateFrame_shd( hCombinedOrientationData, output_fx, subframe_len, *hIntSetup, subframe_idx );
    2030             :             }
    2031             :             /* Rotation in SD for MC -> BINAURAL_ROOM */
    2032           0 :             ELSE IF( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup )
    2033             :             {
    2034           0 :                 rotateFrame_sd( hCombinedOrientationData, output_fx, subframe_len, *hIntSetup, hEFAPdata, subframe_idx );
    2035             :             }
    2036             :         }
    2037      484110 :         test();
    2038      484110 :         IF( EQ_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || EQ_16( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
    2039             :         {
    2040             : 
    2041      484110 :             IF( NE_32( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, output_fx, p_pcm_tmp_fx, output_Fs, subframe_idx ) ), IVAS_ERR_OK ) )
    2042             :             {
    2043           0 :                 return error;
    2044             :             }
    2045             : 
    2046      484110 :             IF( hCrend->hReverb != NULL )
    2047             :             {
    2048       85240 :                 IF( NE_32( ( error = ivas_reverb_process_fx( pCrend->hCrend->hReverb, inConfig, 1, output_fx, p_pcm_tmp_fx, subframe_idx ) ), IVAS_ERR_OK ) )
    2049             :                 {
    2050           0 :                     return error;
    2051             :                 }
    2052             :             }
    2053             : 
    2054             :             /* update combined orientation access index */
    2055      484110 :             ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_len );
    2056             :         }
    2057             :         ELSE
    2058             :         {
    2059           0 :             return IVAS_ERR_INVALID_INPUT_FORMAT;
    2060             :         }
    2061             :     }
    2062             :     /* move to output */
    2063      907632 :     FOR( i = 0; i < nchan_out; i++ )
    2064             :     {
    2065      605088 :         MVR2R_WORD32( pcm_tmp_fx[i], output_fx[i], imult1616( num_subframes, subframe_len ) );
    2066             :     }
    2067             : 
    2068      302544 :     pop_wmops();
    2069      302544 :     return IVAS_ERR_OK;
    2070             : }
    2071             : 
    2072             : /*-----------------------------------------------------------------------------------------*
    2073             :  * Function ivas_rend_crendProcessSubframe()
    2074             :  *
    2075             :  *
    2076             :  *-----------------------------------------------------------------------------------------*/
    2077             : 
    2078       22678 : ivas_error ivas_rend_crendProcessSubframe(
    2079             :     const CREND_WRAPPER *pCrend,                                /* i/o: Crend wrapper handle                    */
    2080             :     const AUDIO_CONFIG inConfig,                                /* i  : input audio configuration               */
    2081             :     const AUDIO_CONFIG outConfig,                               /* i  : output audio configuration              */
    2082             :     const DECODER_CONFIG_HANDLE hDecoderConfig,                 /* i  : decoder config. structure               */
    2083             :     const COMBINED_ORIENTATION_HANDLE hCombinedOrientationData, /* i  : combined orientation handle             */
    2084             :     const IVAS_OUTPUT_SETUP_HANDLE hIntSetup,                   /* i  : internal setup handle                   */
    2085             :     const EFAP_HANDLE hEFAPdata,                                /* i  : EFAP handle                             */
    2086             :     DECODER_TC_BUFFER_HANDLE hTcBuffer,                         /* i/o: JBM handle                              */
    2087             :     Word32 *input_f[],                                          /* i  : transport channels                   Qx */
    2088             :     Word32 *output[],                                           /* i/o: input/output audio channels          Qx */
    2089             :     const Word16 n_samples_to_render,                           /* i  : output frame length per channel         */
    2090             :     const Word32 output_Fs                                      /* i  : output sampling rate                    */
    2091             : )
    2092             : {
    2093             :     Word16 subframe_idx, subframe_len;
    2094             :     Word16 nchan_out, nchan_in, ch, first_sf, last_sf, slot_size, slots_to_render;
    2095             :     Word32 *tc_local_fx[MAX_OUTPUT_CHANNELS];
    2096             :     Word32 pcm_tmp_fx[BINAURAL_CHANNELS][L_FRAME48k];
    2097             :     Word32 *p_pcm_tmp_fx[BINAURAL_CHANNELS];
    2098             :     IVAS_REND_AudioConfigType inConfigType;
    2099             :     ivas_error error;
    2100             :     Word8 combinedOrientationEnabled;
    2101             :     CREND_HANDLE hCrend;
    2102       22678 :     hCrend = pCrend->hCrend;
    2103             : 
    2104       22678 :     combinedOrientationEnabled = 0;
    2105       22678 :     move16();
    2106       22678 :     IF( hCombinedOrientationData != NULL )
    2107             :     {
    2108        4150 :         if ( hCombinedOrientationData->enableCombinedOrientation[0] != 0 )
    2109             :         {
    2110        4150 :             combinedOrientationEnabled = 1;
    2111        4150 :             move16();
    2112             :         }
    2113             :     }
    2114             : 
    2115       22678 :     push_wmops( "ivas_rend_crendProcessSubframe" );
    2116       22678 :     inConfigType = getAudioConfigType( inConfig );
    2117             : 
    2118       22678 :     IF( NE_32( ( error = getAudioConfigNumChannels( outConfig, &nchan_out ) ), IVAS_ERR_OK ) )
    2119             :     {
    2120           0 :         return error;
    2121             :     }
    2122             : 
    2123       22678 :     IF( NE_32( ( error = getAudioConfigNumChannels( inConfig, &nchan_in ) ), IVAS_ERR_OK ) )
    2124             :     {
    2125           0 :         return error;
    2126             :     }
    2127             : 
    2128      233854 :     FOR( ch = 0; ch < nchan_in; ch++ )
    2129             :     {
    2130      211176 :         tc_local_fx[ch] = input_f[ch];
    2131             :     }
    2132       68034 :     FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    2133             :     {
    2134       45356 :         p_pcm_tmp_fx[ch] = pcm_tmp_fx[ch];
    2135             :     }
    2136       22678 :     slot_size = hTcBuffer->n_samples_granularity;
    2137       22678 :     move16();
    2138             : 
    2139             :     /* loop for synthesis, assume we always have to render in multiples of 5ms subframes with spills */
    2140       22678 :     slots_to_render = s_min( sub( hTcBuffer->num_slots, hTcBuffer->slots_rendered ), idiv1616( n_samples_to_render, slot_size ) );
    2141       22678 :     first_sf = hTcBuffer->subframes_rendered;
    2142       22678 :     move16();
    2143       22678 :     last_sf = first_sf;
    2144       22678 :     move16();
    2145             : 
    2146      110727 :     WHILE( slots_to_render > 0 )
    2147             :     {
    2148       88049 :         slots_to_render = sub( slots_to_render, hTcBuffer->subframe_nbslots[last_sf] );
    2149       88049 :         last_sf = add( last_sf, 1 );
    2150             :     }
    2151      110727 :     FOR( subframe_idx = first_sf; subframe_idx < last_sf; subframe_idx++ )
    2152             :     {
    2153       88049 :         subframe_len = imult1616( hTcBuffer->subframe_nbslots[subframe_idx], hTcBuffer->n_samples_granularity );
    2154             :         /* Early Reflections */
    2155       88049 :         IF( hCrend->reflections != NULL )
    2156             :         {
    2157        1800 :             test();
    2158        1800 :             IF( EQ_32( hCrend->reflections->use_er, 1 ) && EQ_32( hCrend->reflections->is_ready, 1 ) )
    2159             :             {
    2160        1800 :                 IF( NE_32( ( error = ivas_er_process( hCrend->reflections, subframe_len, 0, tc_local_fx, inConfig ) ), IVAS_ERR_OK ) )
    2161             :                 {
    2162           0 :                     return error;
    2163             :                 }
    2164             :             }
    2165             :         }
    2166             : 
    2167       88049 :         test();
    2168       88049 :         IF( hDecoderConfig && combinedOrientationEnabled )
    2169             :         {
    2170             :             /* Rotation in SHD for:
    2171             :                 MC with elevation (5_1_2 / 5_1_4 / 7_1_4) -> BINAURAL
    2172             :                 SBA SPAR -> BINAURAL or BINAURAL_ROOM
    2173             :             */
    2174       16600 :             test();
    2175       16600 :             test();
    2176       16600 :             test();
    2177       16600 :             IF( EQ_32( inConfig, IVAS_AUDIO_CONFIG_FOA ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA2 ) || EQ_32( inConfig, IVAS_AUDIO_CONFIG_HOA3 ) )
    2178             :             {
    2179         600 :                 rotateFrame_shd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, 0 );
    2180             :             }
    2181             :             /* Rotation in SD for MC -> BINAURAL_ROOM */
    2182       16000 :             ELSE IF( ( hIntSetup != NULL ) && hIntSetup->is_loudspeaker_setup )
    2183             :             {
    2184       16000 :                 rotateFrame_sd( hCombinedOrientationData, tc_local_fx, subframe_len, *hIntSetup, hEFAPdata, 0 );
    2185             :             }
    2186             :         }
    2187             : 
    2188       88049 :         test();
    2189       88049 :         IF( EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_CHANNEL_BASED ) || EQ_32( inConfigType, IVAS_REND_AUDIO_CONFIG_TYPE_AMBISONICS ) )
    2190             :         {
    2191             : 
    2192       88049 :             IF( NE_32( ( error = ivas_rend_crendConvolver( pCrend, inConfig, outConfig, tc_local_fx, p_pcm_tmp_fx, output_Fs, 0 ) ), IVAS_ERR_OK ) )
    2193             : 
    2194             :             {
    2195           0 :                 return error;
    2196             :             }
    2197             : 
    2198       88049 :             IF( pCrend->hCrend->hReverb != NULL )
    2199             :             {
    2200       14640 :                 IF( NE_32( ( error = ivas_reverb_process_fx( pCrend->hCrend->hReverb, inConfig, 1, tc_local_fx, p_pcm_tmp_fx, 0 ) ), IVAS_ERR_OK ) )
    2201             :                 {
    2202           0 :                     return error;
    2203             :                 }
    2204             :             }
    2205      900797 :             FOR( ch = 0; ch < nchan_in; ch++ )
    2206             :             {
    2207      812748 :                 tc_local_fx[ch] += subframe_len;
    2208             :             }
    2209      264147 :             FOR( ch = 0; ch < BINAURAL_CHANNELS; ch++ )
    2210             :             {
    2211      176098 :                 p_pcm_tmp_fx[ch] += subframe_len;
    2212             :             }
    2213       88049 :             hTcBuffer->slots_rendered = add( hTcBuffer->subframe_nbslots[subframe_idx], hTcBuffer->slots_rendered );
    2214       88049 :             move16();
    2215             :         }
    2216             :         ELSE
    2217             :         {
    2218           0 :             return IVAS_ERR_INVALID_INPUT_FORMAT;
    2219             :         }
    2220             :         /* update combined orientation access index */
    2221       88049 :         ivas_combined_orientation_update_index( hCombinedOrientationData, subframe_len );
    2222             :     }
    2223       22678 :     IF( pCrend->hCrend->hReverb != NULL )
    2224             :     {
    2225        3660 :         *pCrend->p_io_qfactor = sub( *pCrend->p_io_qfactor, 2 );
    2226        3660 :         move16();
    2227       24300 :         FOR( Word16 i = nchan_out; i < nchan_in; i++ )
    2228             :         {
    2229    16097440 :             FOR( Word16 j = 0; j < n_samples_to_render; j++ )
    2230             :             {
    2231    16076800 :                 output[i][j] = L_shr( output[i][j], 2 ); // Q = *pCrend->p_io_qfactor
    2232    16076800 :                 move32();
    2233             :             }
    2234             :         }
    2235             :     }
    2236             :     /* move to output */
    2237       68034 :     FOR( ch = 0; ch < nchan_out; ch++ )
    2238             :     {
    2239       45356 :         MVR2R_WORD32( pcm_tmp_fx[ch], output[ch], n_samples_to_render ); // Qx
    2240             :     }
    2241             : 
    2242       22678 :     hTcBuffer->subframes_rendered = last_sf;
    2243       22678 :     move16();
    2244       22678 :     pop_wmops();
    2245             : 
    2246       22678 :     return IVAS_ERR_OK;
    2247             : }

Generated by: LCOV version 1.14