LCOV - code coverage report
Current view: top level - lib_dec - ivas_sba_rendering_internal.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 146 154 94.8 %
Date: 2025-05-23 08:37:30 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       83988 : 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       83988 :     push_wmops( "ivas_sba2mc_cldfb" );
      79       83988 :     nb_channels_in = hInSetup.nchan_out_woLFE;
      80       83988 :     assert( ( nb_channels_in == 16 ) && ( nb_channels_out == 11 ) && "ivas_sba2mc_cldfb; only HOA3 to CICP19 is for now supported!" );
      81             : 
      82     1007856 :     for ( n = 0; n < nb_channels_out; n++ )
      83             :     {
      84      923868 :         set_zero( realOut[n], MAX_PARAM_SPATIAL_SUBFRAMES * nb_bands );
      85      923868 :         set_zero( imagOut[n], MAX_PARAM_SPATIAL_SUBFRAMES * nb_bands );
      86             : 
      87    15705756 :         for ( m = 0; m < nb_channels_in; m++ )
      88             :         {
      89    14781888 :             g = hoa_dec_mtx[SBA_NHARM_HOA3 * n + m];
      90    14781888 :             p_realOut = realOut[n];
      91    14781888 :             p_imagOut = imagOut[n];
      92             : 
      93    73909440 :             for ( iBlock = 0; iBlock < nb_timeslots; iBlock++ )
      94             :             {
      95    59127552 :                 p_real = RealBuffer[m][iBlock];
      96    59127552 :                 p_imag = ImagBuffer[m][iBlock];
      97  2508625152 :                 for ( iBand = 0; iBand < nb_bands; iBand++ )
      98             :                 {
      99  2449497600 :                     *p_realOut = *p_realOut + g * *( p_real++ );
     100  2449497600 :                     *p_imagOut = *p_imagOut + g * *( p_imag++ );
     101  2449497600 :                     p_realOut++;
     102  2449497600 :                     p_imagOut++;
     103             :                 }
     104             :             }
     105             :         }
     106             :     }
     107             : 
     108     1007856 :     for ( n = 0; n < nb_channels_out; n++ )
     109             :     {
     110      923868 :         p_realOut = realOut[n];
     111      923868 :         p_imagOut = imagOut[n];
     112             : 
     113     4619340 :         for ( iBlock = 0; iBlock < nb_timeslots; iBlock++ )
     114             :         {
     115     3695472 :             p_real = RealBuffer[n][iBlock];
     116     3695472 :             p_imag = ImagBuffer[n][iBlock];
     117   156789072 :             for ( iBand = 0; iBand < nb_bands; iBand++ )
     118             :             {
     119   153093600 :                 *( p_real++ ) = *p_realOut++;
     120   153093600 :                 *( p_imag++ ) = *p_imagOut++;
     121             :             }
     122             :         }
     123             :     }
     124             : 
     125       83988 :     pop_wmops();
     126       83988 :     return;
     127             : }
     128             : 
     129             : 
     130             : /*-------------------------------------------------------------------------*
     131             :  * ivas_mc2sba()
     132             :  *
     133             :  * MC signals transformed into SBA in TD domain
     134             :  *-------------------------------------------------------------------------*/
     135             : 
     136       50769 : 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       50769 :     assert( ( sba_order <= 3 ) && "Only order up to 3 is supported!" );
     153             :     /* Init*/
     154       50769 :     sba_num_chans = ( sba_order + 1 ) * ( sba_order + 1 );
     155      385425 :     for ( j = 0; j < sba_num_chans; j++ )
     156             :     {
     157      334656 :         set_zero( buffer_tmp[j], output_frame );
     158             :     }
     159             : 
     160             :     /* HOA encoding*/
     161       50769 :     idx_lfe = 0;
     162       50769 :     idx_in = 0;
     163      617997 :     for ( i = 0; i < hIntSetup.nchan_out_woLFE + hIntSetup.num_lfe; i++ )
     164             :     {
     165      567228 :         if ( ( hIntSetup.num_lfe > 0 ) && ( i == hIntSetup.index_lfe[idx_lfe] ) )
     166             :         {
     167       50769 :             if ( gain_lfe > 0.f )
     168             :             {
     169             :                 /* Add LFE to omni W with gain*/
     170      612767 :                 for ( k = 0; k < output_frame; k++ )
     171             :                 {
     172      611280 :                     buffer_tmp[0][k] += gain_lfe * in_buffer_td[i][k];
     173             :                 }
     174             :             }
     175             : 
     176       50769 :             if ( idx_lfe < ( hIntSetup.num_lfe - 1 ) )
     177             :             {
     178           0 :                 idx_lfe++;
     179             :             }
     180             :         }
     181             :         else
     182             :         {
     183      516459 :             azimuth = (int16_t) ( hIntSetup.ls_azimuth[idx_in] );
     184      516459 :             elevation = (int16_t) ( hIntSetup.ls_elevation[idx_in] );
     185      516459 :             idx_in++;
     186             : 
     187             :             /* get HOA response for direction (ACN/SN3D)*/
     188      516459 :             ivas_dirac_dec_get_response(
     189             :                 azimuth,
     190             :                 elevation,
     191             :                 gains,
     192             :                 sba_order );
     193             : 
     194     3525675 :             for ( j = 0; j < sba_num_chans; j++ )
     195             :             {
     196  1092079776 :                 for ( k = 0; k < output_frame; k++ )
     197             :                 {
     198  1089070560 :                     buffer_tmp[j][k] += gains[j] * in_buffer_td[i][k];
     199             :                 }
     200             :             }
     201             :         }
     202             :     }
     203             : 
     204      385425 :     for ( j = 0; j < sba_num_chans; j++ )
     205             :     {
     206      334656 :         mvr2r( buffer_tmp[j], buffer_td[j], output_frame );
     207             :     }
     208             : 
     209       50769 :     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      176169 : 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      176169 :     sba_num_chans = MAX_INTERN_CHANNELS;
     239             : 
     240     2994873 :     for ( idx_ch = 0; idx_ch < sba_num_chans; idx_ch++ )
     241             :     {
     242     2818704 :         set_zero( Cldfb_RealBuffer_tmp[idx_ch], CLDFB_NO_CHANNELS_MAX );
     243     2818704 :         set_zero( Cldfb_ImagBuffer_tmp[idx_ch], CLDFB_NO_CHANNELS_MAX );
     244             :     }
     245             : 
     246      176169 :     idx_lfe = 0;
     247      176169 :     idx_in = 0;
     248     1383921 :     for ( idx_ch = 0; idx_ch < hTransSetup.nchan_out_woLFE + hTransSetup.num_lfe; idx_ch++ )
     249             :     {
     250     1207752 :         if ( ( hTransSetup.num_lfe > 0 ) && ( idx_ch == hTransSetup.index_lfe[idx_lfe] ) )
     251             :         {
     252      176169 :             if ( gain_lfe > 0.f )
     253             :             {
     254             :                 /* Add LFE to Omni Channel i.e. W (Just first Band) */
     255      176169 :                 Cldfb_RealBuffer_tmp[0][0] += gain_lfe * Cldfb_RealBuffer[idx_ch][slot_idx][0];
     256      176169 :                 Cldfb_ImagBuffer_tmp[0][0] += gain_lfe * Cldfb_ImagBuffer[idx_ch][slot_idx][0];
     257             :             }
     258      176169 :             if ( idx_lfe < ( hTransSetup.num_lfe - 1 ) )
     259             :             {
     260           0 :                 idx_lfe++;
     261             :             }
     262             :         }
     263             :         else
     264             :         {
     265     1031583 :             gains = hoa_encoder + idx_in * sba_num_chans;
     266    17536911 :             for ( idx_out = 0; idx_out < sba_num_chans; idx_out++ )
     267             :             {
     268   875016048 :                 for ( idx_band = 0; idx_band < nBands; idx_band++ )
     269             :                 {
     270   858510720 :                     Cldfb_RealBuffer_tmp[idx_out][idx_band] += ( *gains ) * Cldfb_RealBuffer[idx_ch][slot_idx][idx_band];
     271   858510720 :                     Cldfb_ImagBuffer_tmp[idx_out][idx_band] += ( *gains ) * Cldfb_ImagBuffer[idx_ch][slot_idx][idx_band];
     272             :                 }
     273    16505328 :                 gains++;
     274             :             }
     275     1031583 :             idx_in++;
     276             :         }
     277             :     }
     278             : 
     279     2994873 :     for ( idx_ch = 0; idx_ch < sba_num_chans; idx_ch++ )
     280             :     {
     281     2818704 :         mvr2r( Cldfb_RealBuffer_tmp[idx_ch], Cldfb_RealBuffer[idx_ch][slot_idx], nBands );
     282     2818704 :         mvr2r( Cldfb_ImagBuffer_tmp[idx_ch], Cldfb_ImagBuffer[idx_ch][slot_idx], nBands );
     283             :     }
     284             : 
     285      176169 :     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      471039 : 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      471039 :     nchan_remapped = st_ivas->nchan_transport;
     309      471039 :     if ( nchan_remapped == 3 )
     310             :     {
     311             : 
     312       98208 :         nchan_remapped++;
     313             : 
     314       98208 :         if ( nchan_remapped == 4 )
     315             :         {
     316             :             /*For planar A-format channel 2 and 3 are identical -> Z=0*/
     317       98208 :             mvr2r( sba_data[2], sba_data[3], output_frame );
     318             :         }
     319             :     }
     320             : 
     321      471039 :     if ( st_ivas->nchan_transport >= 3 )
     322             :     {
     323      221715 :         int16_t i = 0;
     324             :         float temp;
     325             : 
     326             :         /*convert WYXZ downmix to WYZX*/
     327   182151315 :         for ( i = 0; i < output_frame; i++ )
     328             :         {
     329   181929600 :             temp = sba_data[2][i];
     330   181929600 :             sba_data[2][i] = sba_data[3][i];
     331   181929600 :             sba_data[3][i] = temp;
     332   181929600 :             if ( st_ivas->nchan_transport == 3 )
     333             :             {
     334    78012480 :                 sba_data[2][i] = 0;
     335             :             }
     336             :         }
     337             :     }
     338             : 
     339      471039 :     return ( nchan_remapped );
     340             : }
     341             : 
     342             : 
     343             : /*-------------------------------------------------------------------------*
     344             :  * ivas_ism2sba_sf()
     345             :  *
     346             :  * ISM transformed into SBA in TD domain.
     347             :  *-------------------------------------------------------------------------*/
     348             : 
     349       49129 : 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       49129 :     assert( ( sba_order <= 3 ) && "Only order up to 3 is supported!" );
     365       49129 :     assert( hIsmRendererData != NULL && "hIsmRendererData not allocated!" );
     366             : 
     367             :     /* Init*/
     368       49129 :     sba_num_chans = ( sba_order + 1 ) * ( sba_order + 1 );
     369      529425 :     for ( j = 0; j < sba_num_chans; j++ )
     370             :     {
     371      480296 :         set_zero( buffer_tmp[j], n_samples_to_render );
     372             :     }
     373             : 
     374      204888 :     for ( i = 0; i < num_objects; i++ )
     375             :     {
     376     1710999 :         for ( j = 0; j < sba_num_chans; j++ )
     377             :         {
     378     1555240 :             g2 = hIsmRendererData->interpolator + offset;
     379     1555240 :             tc = buffer_in[i];
     380     1555240 :             out = buffer_tmp[j];
     381     1555240 :             gain = hIsmRendererData->gains[i][j];
     382     1555240 :             prev_gain = hIsmRendererData->prev_gains[i][j];
     383   550982920 :             for ( k = 0; k < n_samples_to_render; k++ )
     384             :             {
     385   549427680 :                 g1 = 1.0f - *g2;
     386   549427680 :                 *( out++ ) += ( ( *( g2++ ) ) * gain + g1 * prev_gain ) * ( *( tc++ ) );
     387             :             }
     388             :         }
     389             :     }
     390             : 
     391      529425 :     for ( j = 0; j < sba_num_chans; j++ )
     392             :     {
     393      480296 :         mvr2r( buffer_tmp[j], buffer_out[j], n_samples_to_render );
     394             :     }
     395             : 
     396       49129 :     return;
     397             : }
     398             : 
     399             : 
     400             : /*-------------------------------------------------------------------*
     401             :  * ivas_sba_linear_renderer()
     402             :  *
     403             :  * Linear rendering for SBA format
     404             :  *-------------------------------------------------------------------*/
     405             : 
     406      402894 : 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      402894 :     error = IVAS_ERR_OK;
     420             : 
     421             :     /* Number of channels of HOA depends of transport format which is mixed order xH1V*/
     422      402894 :     nchan_hoa = nchan_in;
     423             : 
     424      402894 :     if ( nchan_in == 6 ) /*2H1V*/
     425             :     {
     426           0 :         nchan_hoa = 9;
     427             :     }
     428      402894 :     else if ( nchan_in == 8 ) /*3H1V*/
     429             :     {
     430           0 :         nchan_hoa = 16;
     431             :     }
     432             : 
     433      402894 :     switch ( output_config )
     434             :     {
     435      382650 :         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      382650 :             for ( i = nchan_hoa; i < output_setup.nchan_out_woLFE; i++ )
     439             :             {
     440           0 :                 set_zero( output_f[i], output_frame );
     441             :             }
     442      382650 :             break;
     443       20244 :         case IVAS_AUDIO_CONFIG_EXTERNAL:
     444      236898 :             for ( i = output_setup.nchan_out_woLFE - 1; i >= nchan_ism; i-- )
     445             :             {
     446      216654 :                 mvr2r( output_f[i - nchan_ism], output_f[i], output_frame );
     447             :             }
     448       20244 :             for ( ; i >= 0; i-- )
     449             :             {
     450           0 :                 set_zero( output_f[i], output_frame );
     451             :             }
     452       20244 :             break;
     453           0 :         default:
     454           0 :             return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "Error: illegal output configuration, Exiting.\n" );
     455             :     }
     456             : 
     457      402894 :     return error;
     458             : }
     459             : 
     460             : 
     461             : /*-------------------------------------------------------------------*
     462             :  * ivas_sba_mix_matrix_determiner()
     463             :  *
     464             :  * Determine SBA mixing matrices
     465             :  *-------------------------------------------------------------------*/
     466             : 
     467      114315 : 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      293394 :     for ( ch = 0; ch < nchan_remapped; ch++ )
     482             :     {
     483   124243719 :         for ( i = 0; i < output_frame; i++ )
     484             :         {
     485   124064640 :             temp = output[ch][i];
     486   124064640 :             temp = floorf( temp + 0.5f );
     487             : 
     488   124064640 :             if ( temp > MAX16B_FLT )
     489             :             {
     490          21 :                 temp = MAX16B_FLT;
     491             :             }
     492   124064619 :             else if ( temp < ( -1.0f * PCM16_TO_FLT_FAC ) )
     493             :             {
     494           3 :                 temp = ( -1.0f * PCM16_TO_FLT_FAC );
     495             :             }
     496   124064640 :             temp *= ( 1.0f / PCM16_TO_FLT_FAC );
     497   124064640 :             output[ch][i] = temp;
     498             :         }
     499             :     }
     500             : 
     501             :     /* AGC */
     502      114315 :     nchan_transport = hSpar->hMdDec->spar_md_cfg.nchan_transport;
     503      114315 :     nchan_out = nchan_transport;
     504      114315 :     ivas_agc_dec_process( hSpar->hAgcDec, output, output, nchan_transport, output_frame );
     505             : 
     506             :     /* Convert numeric range back */
     507      293394 :     for ( ch = 0; ch < nchan_out; ch++ )
     508             :     {
     509   124243719 :         for ( i = 0; i < output_frame; i++ )
     510             :         {
     511   124064640 :             output[ch][i] = output[ch][i] * PCM16_TO_FLT_FAC;
     512             :         }
     513             :     }
     514             : 
     515             :     /* Mixing matrix determiner */
     516      114315 :     num_bands_out = hSpar->hFbMixer->pFb->filterbank_num_bands;
     517      114315 :     ivas_spar_dec_gen_umx_mat( hSpar->hMdDec, nchan_transport, num_bands_out, bfi, num_md_sub_frames );
     518             : 
     519      114315 :     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