LCOV - code coverage report
Current view: top level - lib_dec - ivas_sba_rendering_internal.c (source / functions) Hit Total Coverage
Test: Coverage on main @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 146 154 94.8 %
Date: 2025-09-14 08:49:17 Functions: 7 7 100.0 %

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

Generated by: LCOV version 1.14