LCOV - code coverage report
Current view: top level - lib_dec - ivas_sba_rendering_internal.c (source / functions) Hit Total Coverage
Test: Coverage on main -- merged total coverage @ 0c62f5312a76f89f3e6d6ab9a8d50516c9ab4059 Lines: 146 160 91.2 %
Date: 2025-12-17 10:49:08 Functions: 7 8 87.5 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <stdint.h>
      34             : #include "options.h"
      35             : #include "prot.h"
      36             : #include "ivas_prot.h"
      37             : #include "ivas_prot_rend.h"
      38             : #include "ivas_stat_dec.h"
      39             : #include "ivas_cnst.h"
      40             : #include <math.h>
      41             : #ifdef DEBUGGING
      42             : #include "debug.h"
      43             : #endif
      44             : #include "wmc_auto.h"
      45             : 
      46             : 
      47             : #ifdef DEBUG_MODE_DIRAC
      48             : /*-----------------------------------------------------------------------*
      49             :  * Local function prototypes
      50             :  *-----------------------------------------------------------------------*/
      51             : 
      52             : static void debug_mode_dirac( float output[MAX_OUTPUT_CHANNELS][L_FRAME48k], const int16_t nchan_transport, const int16_t output_frame );
      53             : #endif
      54             : 
      55             : 
      56             : /*-------------------------------------------------------------------------*
      57             :  * ivas_sba2MC_cldfb()
      58             :  *
      59             :  * SBA signals transformed into MC in CLDFB domain
      60             :  *-------------------------------------------------------------------------*/
      61             : 
      62      871272 : void ivas_sba2mc_cldfb(
      63             :     IVAS_OUTPUT_SETUP hInSetup,                                             /* i  : Format of input layout        */
      64             :     float RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb real part               */
      65             :     float ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: cldfb imag part               */
      66             :     const int16_t nb_channels_out,                                          /* i  : nb of output channels         */
      67             :     const int16_t nb_bands,                                                 /* i  : nb of CLDFB bands to process  */
      68             :     const int16_t nb_timeslots,                                             /* i  : number of time slots to process */
      69             :     const float *hoa_dec_mtx                                                /* i  : HOA decoding mtx              */
      70             : )
      71             : {
      72             :     int16_t iBlock, iBand, n, m;
      73             :     float realOut[16][MAX_PARAM_SPATIAL_SUBFRAMES * CLDFB_NO_CHANNELS_MAX], imagOut[16][MAX_PARAM_SPATIAL_SUBFRAMES * CLDFB_NO_CHANNELS_MAX];
      74             :     float g;
      75             :     float *p_real, *p_imag, *p_realOut, *p_imagOut;
      76             :     int16_t nb_channels_in;
      77             : 
      78      871272 :     push_wmops( "ivas_sba2mc_cldfb" );
      79      871272 :     nb_channels_in = hInSetup.nchan_out_woLFE;
      80      871272 :     assert( ( nb_channels_in == 16 ) && ( nb_channels_out == 11 ) && "ivas_sba2mc_cldfb; only HOA3 to CICP19 is for now supported!" );
      81             : 
      82    10455264 :     for ( n = 0; n < nb_channels_out; n++ )
      83             :     {
      84     9583992 :         set_zero( realOut[n], MAX_PARAM_SPATIAL_SUBFRAMES * nb_bands );
      85     9583992 :         set_zero( imagOut[n], MAX_PARAM_SPATIAL_SUBFRAMES * nb_bands );
      86             : 
      87   162927864 :         for ( m = 0; m < nb_channels_in; m++ )
      88             :         {
      89   153343872 :             g = hoa_dec_mtx[SBA_NHARM_HOA3 * n + m];
      90   153343872 :             p_realOut = realOut[n];
      91   153343872 :             p_imagOut = imagOut[n];
      92             : 
      93   766719360 :             for ( iBlock = 0; iBlock < nb_timeslots; iBlock++ )
      94             :             {
      95   613375488 :                 p_real = RealBuffer[m][iBlock];
      96   613375488 :                 p_imag = ImagBuffer[m][iBlock];
      97 25761043968 :                 for ( iBand = 0; iBand < nb_bands; iBand++ )
      98             :                 {
      99 25147668480 :                     *p_realOut = *p_realOut + g * *( p_real++ );
     100 25147668480 :                     *p_imagOut = *p_imagOut + g * *( p_imag++ );
     101 25147668480 :                     p_realOut++;
     102 25147668480 :                     p_imagOut++;
     103             :                 }
     104             :             }
     105             :         }
     106             :     }
     107             : 
     108    10455264 :     for ( n = 0; n < nb_channels_out; n++ )
     109             :     {
     110     9583992 :         p_realOut = realOut[n];
     111     9583992 :         p_imagOut = imagOut[n];
     112             : 
     113    47919960 :         for ( iBlock = 0; iBlock < nb_timeslots; iBlock++ )
     114             :         {
     115    38335968 :             p_real = RealBuffer[n][iBlock];
     116    38335968 :             p_imag = ImagBuffer[n][iBlock];
     117  1610065248 :             for ( iBand = 0; iBand < nb_bands; iBand++ )
     118             :             {
     119  1571729280 :                 *( p_real++ ) = *p_realOut++;
     120  1571729280 :                 *( p_imag++ ) = *p_imagOut++;
     121             :             }
     122             :         }
     123             :     }
     124             : 
     125      871272 :     pop_wmops();
     126      871272 :     return;
     127             : }
     128             : 
     129             : 
     130             : /*-------------------------------------------------------------------------*
     131             :  * ivas_mc2sba()
     132             :  *
     133             :  * MC signals transformed into SBA in TD domain
     134             :  *-------------------------------------------------------------------------*/
     135             : 
     136      586086 : void ivas_mc2sba(
     137             :     IVAS_OUTPUT_SETUP hIntSetup, /* i  : Format of decoder output                         */
     138             :     float *in_buffer_td[],       /* i  : MC signals (on input) and the HOA3 (on output)   */
     139             :     float *buffer_td[],          /* i/o: MC signals (on input) and the HOA3 (on output)   */
     140             :     const int16_t output_frame,  /* i  : output frame length per channel                  */
     141             :     const int16_t sba_order,     /* i  : Ambisonic (SBA) order                            */
     142             :     const float gain_lfe         /* i  : gain for LFE, 0 = ignore LFE                     */
     143             : )
     144             : {
     145             :     int16_t i, j, k;
     146             :     int16_t idx_lfe, idx_in;
     147             :     float buffer_tmp[16][L_FRAME48k];
     148             :     float gains[16];
     149             :     int16_t azimuth, elevation;
     150             :     int16_t sba_num_chans;
     151             : 
     152      586086 :     assert( ( sba_order <= 3 ) && "Only order up to 3 is supported!" );
     153             :     /* Init*/
     154      586086 :     sba_num_chans = ( sba_order + 1 ) * ( sba_order + 1 );
     155     6105718 :     for ( j = 0; j < sba_num_chans; j++ )
     156             :     {
     157     5519632 :         set_zero( buffer_tmp[j], output_frame );
     158             :     }
     159             : 
     160             :     /* HOA encoding*/
     161      586086 :     idx_lfe = 0;
     162      586086 :     idx_in = 0;
     163     7029906 :     for ( i = 0; i < hIntSetup.nchan_out_woLFE + hIntSetup.num_lfe; i++ )
     164             :     {
     165     6443820 :         if ( ( hIntSetup.num_lfe > 0 ) && ( i == hIntSetup.index_lfe[idx_lfe] ) )
     166             :         {
     167      586086 :             if ( gain_lfe > 0.f )
     168             :             {
     169             :                 /* Add LFE to omni W with gain*/
     170    43966682 :                 for ( k = 0; k < output_frame; k++ )
     171             :                 {
     172    43876320 :                     buffer_tmp[0][k] += gain_lfe * in_buffer_td[i][k];
     173             :                 }
     174             :             }
     175             : 
     176      586086 :             if ( idx_lfe < ( hIntSetup.num_lfe - 1 ) )
     177             :             {
     178           0 :                 idx_lfe++;
     179             :             }
     180             :         }
     181             :         else
     182             :         {
     183     5857734 :             azimuth = (int16_t) ( hIntSetup.ls_azimuth[idx_in] );
     184     5857734 :             elevation = (int16_t) ( hIntSetup.ls_elevation[idx_in] );
     185     5857734 :             idx_in++;
     186             : 
     187             :             /* get HOA response for direction (ACN/SN3D)*/
     188     5857734 :             ivas_dirac_dec_get_response(
     189             :                 azimuth,
     190             :                 elevation,
     191             :                 gains,
     192             :                 sba_order );
     193             : 
     194    58410326 :             for ( j = 0; j < sba_num_chans; j++ )
     195             :             {
     196 23468359952 :                 for ( k = 0; k < output_frame; k++ )
     197             :                 {
     198 23415807360 :                     buffer_tmp[j][k] += gains[j] * in_buffer_td[i][k];
     199             :                 }
     200             :             }
     201             :         }
     202             :     }
     203             : 
     204     6105718 :     for ( j = 0; j < sba_num_chans; j++ )
     205             :     {
     206     5519632 :         mvr2r( buffer_tmp[j], buffer_td[j], output_frame );
     207             :     }
     208             : 
     209      586086 :     return;
     210             : }
     211             : 
     212             : 
     213             : /*-------------------------------------------------------------------------*
     214             :  * ivas_stereo2sba()
     215             :  *
     216             :  * stereo signal is transformed into SBA in TD domain
     217             :  *-------------------------------------------------------------------------*/
     218             : 
     219           0 : void ivas_stereo2sba(
     220             :     float *input_f[],          /* i  : core-coder transport stereo channels */
     221             :     float *output_f[],         /* o  : SBA output channels                  */
     222             :     const int16_t output_frame /* i  : output frame length per channel      */
     223             : )
     224             : {
     225             :     int16_t n;
     226             :     float tmp;
     227             : 
     228           0 :     for ( n = 0; n < output_frame; n++ )
     229             :     {
     230           0 :         tmp = input_f[0][n];
     231           0 :         output_f[0][n] = 0.5f * ( tmp + input_f[1][n] ); /* W = 0.5 * ( L + R ) */
     232           0 :         output_f[1][n] = 0.5f * ( tmp - input_f[1][n] ); /* Y = 0.5 * ( L - R ) */
     233             :     }
     234             : 
     235           0 :     return;
     236             : }
     237             : 
     238             : 
     239             : /*-------------------------------------------------------------------------*
     240             :  * ivas_param_mc_mc2sba_cldfb()
     241             :  *
     242             :  * MC signals transformed into SBA in CLDFB domain
     243             :  * used for binaural rendering with head rotation
     244             :  *-------------------------------------------------------------------------*/
     245             : 
     246     3276041 : void ivas_param_mc_mc2sba_cldfb(
     247             :     IVAS_OUTPUT_SETUP hTransSetup,                                                /* i  : transported MC Format                                       */
     248             :     float *hoa_encoder,                                                           /* i  : HOA3 encoder for the transported MC format                  */
     249             :     const int16_t slot_idx,                                                       /* i  : current slot in the subframe                                */
     250             :     float Cldfb_RealBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */
     251             :     float Cldfb_ImagBuffer[][MAX_PARAM_SPATIAL_SUBFRAMES][CLDFB_NO_CHANNELS_MAX], /* i/o: Contains the MC signals (on input) and the HOA3 (on output) */
     252             :     const int16_t nBands,                                                         /* i  : number of synth CLDFB bands                                 */
     253             :     const float gain_lfe                                                          /* i  : gain applied to LFE                                        */
     254             : )
     255             : {
     256             :     int16_t idx_ch, idx_band;
     257             :     int16_t idx_lfe, idx_in, idx_out;
     258             :     float Cldfb_RealBuffer_tmp[MAX_INTERN_CHANNELS][CLDFB_NO_CHANNELS_MAX];
     259             :     float Cldfb_ImagBuffer_tmp[MAX_INTERN_CHANNELS][CLDFB_NO_CHANNELS_MAX];
     260             :     float *gains;
     261             :     int16_t sba_num_chans;
     262             : 
     263             :     /* Init*/
     264     3276041 :     sba_num_chans = MAX_INTERN_CHANNELS;
     265             : 
     266    55692697 :     for ( idx_ch = 0; idx_ch < sba_num_chans; idx_ch++ )
     267             :     {
     268    52416656 :         set_zero( Cldfb_RealBuffer_tmp[idx_ch], CLDFB_NO_CHANNELS_MAX );
     269    52416656 :         set_zero( Cldfb_ImagBuffer_tmp[idx_ch], CLDFB_NO_CHANNELS_MAX );
     270             :     }
     271             : 
     272     3276041 :     idx_lfe = 0;
     273     3276041 :     idx_in = 0;
     274    31903753 :     for ( idx_ch = 0; idx_ch < hTransSetup.nchan_out_woLFE + hTransSetup.num_lfe; idx_ch++ )
     275             :     {
     276    28627712 :         if ( ( hTransSetup.num_lfe > 0 ) && ( idx_ch == hTransSetup.index_lfe[idx_lfe] ) )
     277             :         {
     278     3276041 :             if ( gain_lfe > 0.f )
     279             :             {
     280             :                 /* Add LFE to Omni Channel i.e. W (Just first Band) */
     281     3276041 :                 Cldfb_RealBuffer_tmp[0][0] += gain_lfe * Cldfb_RealBuffer[idx_ch][slot_idx][0];
     282     3276041 :                 Cldfb_ImagBuffer_tmp[0][0] += gain_lfe * Cldfb_ImagBuffer[idx_ch][slot_idx][0];
     283             :             }
     284     3276041 :             if ( idx_lfe < ( hTransSetup.num_lfe - 1 ) )
     285             :             {
     286           0 :                 idx_lfe++;
     287             :             }
     288             :         }
     289             :         else
     290             :         {
     291    25351671 :             gains = hoa_encoder + idx_in * sba_num_chans;
     292   430978407 :             for ( idx_out = 0; idx_out < sba_num_chans; idx_out++ )
     293             :             {
     294 20897410416 :                 for ( idx_band = 0; idx_band < nBands; idx_band++ )
     295             :                 {
     296 20491783680 :                     Cldfb_RealBuffer_tmp[idx_out][idx_band] += ( *gains ) * Cldfb_RealBuffer[idx_ch][slot_idx][idx_band];
     297 20491783680 :                     Cldfb_ImagBuffer_tmp[idx_out][idx_band] += ( *gains ) * Cldfb_ImagBuffer[idx_ch][slot_idx][idx_band];
     298             :                 }
     299   405626736 :                 gains++;
     300             :             }
     301    25351671 :             idx_in++;
     302             :         }
     303             :     }
     304             : 
     305    55692697 :     for ( idx_ch = 0; idx_ch < sba_num_chans; idx_ch++ )
     306             :     {
     307    52416656 :         mvr2r( Cldfb_RealBuffer_tmp[idx_ch], Cldfb_RealBuffer[idx_ch][slot_idx], nBands );
     308    52416656 :         mvr2r( Cldfb_ImagBuffer_tmp[idx_ch], Cldfb_ImagBuffer[idx_ch][slot_idx], nBands );
     309             :     }
     310             : 
     311     3276041 :     return;
     312             : }
     313             : 
     314             : 
     315             : /*-------------------------------------------------------------------*
     316             :  * ivas_sba_remapTCs()
     317             :  *
     318             :  * Get TCs from Ambisonics signal in ACN
     319             :  *-------------------------------------------------------------------*/
     320             : 
     321             : /*! r: SBA DirAC stereo flag */
     322     9550341 : int16_t ivas_sba_remapTCs(
     323             :     float *sba_data[],         /* i/o: SBA signals                  */
     324             :     Decoder_Struct *st_ivas,   /* i/o: decoder struct               */
     325             :     const int16_t output_frame /* i  : frame length                 */
     326             : )
     327             : {
     328             :     int16_t nchan_remapped;
     329             : 
     330             : #ifdef DEBUG_MODE_DIRAC
     331             :     debug_mode_dirac( sba_data, st_ivas->nchan_transport, output_frame );
     332             : #endif
     333             : 
     334     9550341 :     nchan_remapped = st_ivas->nchan_transport;
     335     9550341 :     if ( nchan_remapped == 3 )
     336             :     {
     337             : 
     338     1814093 :         nchan_remapped++;
     339             : 
     340     1814093 :         if ( nchan_remapped == 4 )
     341             :         {
     342             :             /*For planar A-format channel 2 and 3 are identical -> Z=0*/
     343     1814093 :             mvr2r( sba_data[2], sba_data[3], output_frame );
     344             :         }
     345             :     }
     346             : 
     347     9550341 :     if ( st_ivas->nchan_transport >= 3 )
     348             :     {
     349     4181288 :         int16_t i = 0;
     350             :         float temp;
     351             : 
     352             :         /*convert WYXZ downmix to WYZX*/
     353  3175294888 :         for ( i = 0; i < output_frame; i++ )
     354             :         {
     355  3171113600 :             temp = sba_data[2][i];
     356  3171113600 :             sba_data[2][i] = sba_data[3][i];
     357  3171113600 :             sba_data[3][i] = temp;
     358  3171113600 :             if ( st_ivas->nchan_transport == 3 )
     359             :             {
     360  1339027200 :                 sba_data[2][i] = 0;
     361             :             }
     362             :         }
     363             :     }
     364             : 
     365     9550341 :     return ( nchan_remapped );
     366             : }
     367             : 
     368             : 
     369             : /*-------------------------------------------------------------------------*
     370             :  * ivas_ism2sba_sf()
     371             :  *
     372             :  * ISM transformed into SBA in TD domain.
     373             :  *-------------------------------------------------------------------------*/
     374             : 
     375      508560 : void ivas_ism2sba_sf(
     376             :     float *buffer_in[],                   /* i  : TC buffer                       */
     377             :     float *buffer_out[],                  /* o  : TD signal buffers               */
     378             :     ISM_RENDERER_HANDLE hIsmRendererData, /* i/o: renderer data                   */
     379             :     const int16_t num_objects,            /* i  : number of objects               */
     380             :     const int16_t n_samples_to_render,    /* i  : output frame length per channel */
     381             :     const int16_t offset,                 /* i  : offset for the interpolatr      */
     382             :     const int16_t sba_order               /* i  : Ambisonic (SBA) order           */
     383             : )
     384             : {
     385             :     int16_t i, j, k;
     386             :     float g1, *g2, *tc, *out, gain, prev_gain;
     387             :     float buffer_tmp[HOA3_CHANNELS][L_FRAME48k];
     388             :     int16_t sba_num_chans;
     389             : 
     390      508560 :     assert( ( sba_order <= 3 ) && "Only order up to 3 is supported!" );
     391      508560 :     assert( hIsmRendererData != NULL && "hIsmRendererData not allocated!" );
     392             : 
     393             :     /* Init*/
     394      508560 :     sba_num_chans = ( sba_order + 1 ) * ( sba_order + 1 );
     395     5538650 :     for ( j = 0; j < sba_num_chans; j++ )
     396             :     {
     397     5030090 :         set_zero( buffer_tmp[j], n_samples_to_render );
     398             :     }
     399             : 
     400     2041338 :     for ( i = 0; i < num_objects; i++ )
     401             :     {
     402    17014856 :         for ( j = 0; j < sba_num_chans; j++ )
     403             :         {
     404    15482078 :             g2 = hIsmRendererData->interpolator + offset;
     405    15482078 :             tc = buffer_in[i];
     406    15482078 :             out = buffer_tmp[j];
     407    15482078 :             gain = hIsmRendererData->gains[i][j];
     408    15482078 :             prev_gain = hIsmRendererData->prev_gains[i][j];
     409  6660917678 :             for ( k = 0; k < n_samples_to_render; k++ )
     410             :             {
     411  6645435600 :                 g1 = 1.0f - *g2;
     412  6645435600 :                 *( out++ ) += ( ( *( g2++ ) ) * gain + g1 * prev_gain ) * ( *( tc++ ) );
     413             :             }
     414             :         }
     415             :     }
     416             : 
     417     5538650 :     for ( j = 0; j < sba_num_chans; j++ )
     418             :     {
     419     5030090 :         mvr2r( buffer_tmp[j], buffer_out[j], n_samples_to_render );
     420             :     }
     421             : 
     422      508560 :     return;
     423             : }
     424             : 
     425             : 
     426             : /*-------------------------------------------------------------------*
     427             :  * ivas_sba_linear_renderer()
     428             :  *
     429             :  * Linear rendering for SBA format
     430             :  *-------------------------------------------------------------------*/
     431             : 
     432    10135128 : ivas_error ivas_sba_linear_renderer(
     433             :     float *output_f[],                   /* i/o: synthesized core-coder transport channels/DirAC output  */
     434             :     const int16_t output_frame,          /* i  : output frame length per channel                         */
     435             :     const int16_t nchan_in,              /* i  : number of input ambisonics channels                     */
     436             :     const int16_t nchan_ism,             /* i  : number of objects                                      */
     437             :     const AUDIO_CONFIG output_config,    /* i  : output audio configuration                              */
     438             :     const IVAS_OUTPUT_SETUP output_setup /* i  : output format setup                                     */
     439             : )
     440             : {
     441             :     int16_t i;
     442             :     int16_t nchan_hoa;
     443             :     ivas_error error;
     444             : 
     445    10135128 :     error = IVAS_ERR_OK;
     446             : 
     447             :     /* Number of channels of HOA depends of transport format which is mixed order xH1V*/
     448    10135128 :     nchan_hoa = nchan_in;
     449             : 
     450    10135128 :     if ( nchan_in == 6 ) /*2H1V*/
     451             :     {
     452           0 :         nchan_hoa = 9;
     453             :     }
     454    10135128 :     else if ( nchan_in == 8 ) /*3H1V*/
     455             :     {
     456           0 :         nchan_hoa = 16;
     457             :     }
     458             : 
     459    10135128 :     switch ( output_config )
     460             :     {
     461     9741174 :         case IVAS_AUDIO_CONFIG_FOA:  /* Ambisonics output, order: 1 */
     462             :         case IVAS_AUDIO_CONFIG_HOA2: /* Ambisonics output, order: 2 */
     463             :         case IVAS_AUDIO_CONFIG_HOA3: /* Ambisonics output, order: 3 */
     464     9741174 :             for ( i = nchan_hoa; i < output_setup.nchan_out_woLFE; i++ )
     465             :             {
     466           0 :                 set_zero( output_f[i], output_frame );
     467             :             }
     468     9741174 :             break;
     469      393954 :         case IVAS_AUDIO_CONFIG_EXTERNAL:
     470     4387708 :             for ( i = output_setup.nchan_out_woLFE - 1; i >= nchan_ism; i-- )
     471             :             {
     472     3993754 :                 mvr2r( output_f[i - nchan_ism], output_f[i], output_frame );
     473             :             }
     474      393954 :             for ( ; i >= 0; i-- )
     475             :             {
     476           0 :                 set_zero( output_f[i], output_frame );
     477             :             }
     478      393954 :             break;
     479           0 :         default:
     480           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: illegal output configuration, Exiting.\n" );
     481             :     }
     482             : 
     483    10135128 :     return error;
     484             : }
     485             : 
     486             : 
     487             : /*-------------------------------------------------------------------*
     488             :  * ivas_sba_mix_matrix_determiner()
     489             :  *
     490             :  * Determine SBA mixing matrices
     491             :  *-------------------------------------------------------------------*/
     492             : 
     493     1615196 : void ivas_sba_mix_matrix_determiner(
     494             :     SPAR_DEC_HANDLE hSpar,          /* i/o: SPAR decoder handle                 */
     495             :     float *output[],                /* i/o: transport/output audio channels     */
     496             :     const int16_t bfi,              /* i  : BFI flag                            */
     497             :     const int16_t nchan_remapped,   /* i  : num channels after remapping of TCs */
     498             :     const int16_t output_frame,     /* i  : output frame length                 */
     499             :     const int16_t num_md_sub_frames /* i  : number of subframes in mixing matrix*/
     500             : )
     501             : {
     502             :     int16_t i, ch;
     503             :     float temp;
     504             :     int16_t num_bands_out, nchan_transport, nchan_out;
     505             : 
     506             :     /* Convert numeric range */
     507     4116581 :     for ( ch = 0; ch < nchan_remapped; ch++ )
     508             :     {
     509  1737292745 :         for ( i = 0; i < output_frame; i++ )
     510             :         {
     511  1734791360 :             temp = output[ch][i];
     512  1734791360 :             temp = floorf( temp + 0.5f );
     513             : 
     514  1734791360 :             if ( temp > MAX16B_FLT )
     515             :             {
     516         913 :                 temp = MAX16B_FLT;
     517             :             }
     518  1734790447 :             else if ( temp < ( -1.0f * PCM16_TO_FLT_FAC ) )
     519             :             {
     520         697 :                 temp = ( -1.0f * PCM16_TO_FLT_FAC );
     521             :             }
     522  1734791360 :             temp *= ( 1.0f / PCM16_TO_FLT_FAC );
     523  1734791360 :             output[ch][i] = temp;
     524             :         }
     525             :     }
     526             : 
     527             :     /* AGC */
     528     1615196 :     nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
     529     1615196 :     nchan_out = nchan_transport;
     530     1615196 :     ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame );
     531             : 
     532             :     /* Convert numeric range back */
     533     4116581 :     for ( ch = 0; ch < nchan_out; ch++ )
     534             :     {
     535  1737292745 :         for ( i = 0; i < output_frame; i++ )
     536             :         {
     537  1734791360 :             output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC;
     538             :         }
     539             :     }
     540             : 
     541             :     /* Mixing matrix determiner */
     542     1615196 :     num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands;
     543     1615196 :     ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames );
     544             : 
     545     1615196 :     return;
     546             : }
     547             : 
     548             : 
     549             : #ifdef DEBUG_MODE_DIRAC
     550             : /*-----------------------------------------------------------------------*
     551             :  * Debugging function
     552             :  *-----------------------------------------------------------------------*/
     553             : 
     554             : static void debug_mode_dirac(
     555             :     float output[MAX_OUTPUT_CHANNELS][L_FRAME48k],
     556             :     const int16_t nchan_transport,
     557             :     const int16_t output_frame )
     558             : {
     559             :     int16_t i, n;
     560             :     int16_t tmp[L_FRAME48k];
     561             :     char file_name[50] = { 0 };
     562             : 
     563             : #ifdef DEBUG_MODE_DIRAC_NOCORE
     564             :     for ( n = 0; n < nchan_transport; n++ )
     565             :     {
     566             :         sprintf( file_name, "./res/ivas_dirac_enc_%d.%d.pcm", n, (int16_t) ( output_frame * 0.05 ) );
     567             :         dbgread( tmp, sizeof( int16_t ), output_frame, file_name );
     568             :         for ( i = 0; i < output_frame; i++ )
     569             :         {
     570             :             output[n][i] = (float) ( tmp[i] );
     571             :         }
     572             :     }
     573             : #else
     574             :     for ( n = 0; n < nchan_transport; n++ )
     575             :     {
     576             :         for ( i = 0; i < output_frame; i++ )
     577             :         {
     578             :             tmp[i] = (int16_t) ( output[n][i] + 0.5f );
     579             :         }
     580             : 
     581             :         sprintf( file_name, "./res/ivas_dirac_dec_%d.%d.pcm", n, (int16_t) ( output_frame * 0.05 ) );
     582             :         dbgwrite( tmp, sizeof( int16_t ), output_frame, 1, file_name );
     583             :     }
     584             : #endif
     585             : 
     586             :     return;
     587             : }
     588             : #endif

Generated by: LCOV version 1.14