LCOV - code coverage report
Current view: top level - lib_rend - ivas_sba_rendering.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 72 72 100.0 %
Date: 2025-05-23 08:37:30 Functions: 1 1 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             : /*-------------------------------------------------------------------*
      48             :  * ivas_sba_prototype_renderer()
      49             :  *
      50             :  * Render prototype audio signals using SBA mixing matrices
      51             :  *-------------------------------------------------------------------*/
      52             : 
      53      458604 : void ivas_sba_prototype_renderer(
      54             :     Decoder_Struct *st_ivas,                                       /* i/o: IVAS decoder struct               */
      55             :     float inRe[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i  : Input audio in CLDFB domain, real */
      56             :     float inIm[][CLDFB_SLOTS_PER_SUBFRAME][CLDFB_NO_CHANNELS_MAX], /* i  : Input audio in CLDFB domain, imag */
      57             :     const int16_t subframe                                         /* i  : Subframe to render                */
      58             : )
      59             : {
      60             :     float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS];
      61             :     SPAR_DEC_HANDLE hSpar;
      62             :     DECODER_CONFIG_HANDLE hDecoderConfig;
      63             :     int16_t num_spar_bands, spar_band;
      64             :     int16_t b, ts;
      65             :     int16_t num_cldfb_bands, numch_in, numch_out;
      66             :     int16_t cldfb_band;
      67             :     int16_t out_ch, in_ch;
      68             :     int16_t firstInCh, inChEnd, firstOutCh, outChEnd;
      69             :     int16_t slot_idx_start, md_idx;
      70             :     int16_t num_md_sub_frames;
      71             : 
      72      458604 :     num_md_sub_frames = ivas_get_spar_dec_md_num_subframes( st_ivas->sba_analysis_order, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->last_active_ivas_total_brate );
      73             : 
      74      458604 :     push_wmops( "ivas_sba_prototype_renderer" );
      75             : 
      76      458604 :     hSpar = st_ivas->hSpar;
      77      458604 :     hDecoderConfig = st_ivas->hDecoderConfig;
      78      458604 :     num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands;
      79             : 
      80      458604 :     num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands;
      81      458604 :     numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans;
      82      458604 :     numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans;
      83      458604 :     slot_idx_start = hSpar->slots_rendered;
      84             : 
      85      458604 :     if ( st_ivas->nchan_transport == 1 )
      86             :     {
      87      198798 :         firstInCh = 0;
      88      198798 :         inChEnd = 1;
      89      198798 :         firstOutCh = 0;
      90      198798 :         outChEnd = 1;
      91             :     }
      92             :     else /* 2 TC */
      93             :     {
      94      259806 :         firstInCh = 0;
      95      259806 :         inChEnd = 2;
      96      259806 :         firstOutCh = 1;
      97      259806 :         outChEnd = 2;
      98             :     }
      99             : 
     100             :     /* Apply mixing matrix */
     101     2287713 :     for ( ts = 0; ts < hSpar->subframe_nbslots[hSpar->subframes_rendered]; ts++ )
     102             :     {
     103             :         /* determine SPAR parameters for this time slot */
     104     1829109 :         md_idx = hSpar->render_to_md_map[ts + slot_idx_start];
     105     1829109 :         ivas_spar_get_parameters( hSpar, hDecoderConfig, md_idx, numch_out, numch_in, num_spar_bands, mixer_mat );
     106             : 
     107    81252129 :         for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ )
     108             :         {
     109             :             float out_re[IVAS_SPAR_MAX_CH];
     110             :             float out_im[IVAS_SPAR_MAX_CH];
     111             :             float cldfb_par;
     112    79423020 :             ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band;
     113             : 
     114   158846040 :             for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ )
     115             :             {
     116    79423020 :                 out_re[out_ch] = 0.0f;
     117    79423020 :                 out_im[out_ch] = 0.0f;
     118             : 
     119   203492700 :                 for ( in_ch = firstInCh; in_ch < inChEnd; in_ch++ )
     120             :                 {
     121   124069680 :                     if ( cldfb_band < CLDFB_PAR_WEIGHT_START_BAND ) /* tuning parameter, depends on how much SPAR Filters overlap for the CLDFB bands */
     122             :                     {
     123    20057436 :                         spar_band = bin2band->p_cldfb_map_to_spar_band[cldfb_band];
     124    20057436 :                         cldfb_par = mixer_mat[out_ch][in_ch][spar_band];
     125             :                     }
     126             :                     else
     127             :                     {
     128   104012244 :                         cldfb_par = 0.0f;
     129   600230748 :                         for ( spar_band = bin2band->p_spar_start_bands[cldfb_band]; spar_band < num_spar_bands; spar_band++ )
     130             :                         {
     131             :                             /* accumulate contributions from all SPAR bands */
     132   496218504 :                             cldfb_par += mixer_mat[out_ch][in_ch][spar_band] * bin2band->pp_cldfb_weights_per_spar_band[cldfb_band][spar_band];
     133             :                         }
     134             :                     }
     135             : 
     136   124069680 :                     out_re[out_ch] += inRe[in_ch][ts][cldfb_band] * cldfb_par;
     137   124069680 :                     out_im[out_ch] += inIm[in_ch][ts][cldfb_band] * cldfb_par;
     138             :                 }
     139             :             }
     140             : 
     141             :             /*update CLDFB data with the parameter-modified data*/
     142   158846040 :             for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ )
     143             :             {
     144    79423020 :                 inRe[out_ch][ts][cldfb_band] = out_re[out_ch];
     145    79423020 :                 inIm[out_ch][ts][cldfb_band] = out_im[out_ch];
     146             :             }
     147             :         }
     148             : 
     149             :         /* Update mixing matrices */
     150     1829109 :         if ( ( ( slot_idx_start + ts + 1 ) == hSpar->num_slots ) || ( ( md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME ) != ( hSpar->render_to_md_map[ts + slot_idx_start + 1] / JBM_CLDFB_SLOTS_IN_SUBFRAME ) ) )
     151             :         {
     152             :             /* we have crossed an unadapted parameter sf border, update previous mixing matrices */
     153      457260 :             int16_t md_sf = md_idx / JBM_CLDFB_SLOTS_IN_SUBFRAME;
     154      457260 :             md_sf = ( num_md_sub_frames == MAX_PARAM_SPATIAL_SUBFRAMES ) ? md_sf : 0;
     155      457260 :             hSpar->i_subframe++;
     156      457260 :             hSpar->i_subframe = min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES );
     157      457260 :             mvr2r( hSpar->hMdDec->mixer_mat_prev[1][0][0], hSpar->hMdDec->mixer_mat_prev[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS );
     158      457260 :             mvr2r( hSpar->hMdDec->mixer_mat_prev[2][0][0], hSpar->hMdDec->mixer_mat_prev[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS );
     159      457260 :             mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS );
     160      457260 :             mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS );
     161             : 
     162     2286300 :             for ( out_ch = 0; out_ch < numch_out; out_ch++ )
     163             :             {
     164     9145200 :                 for ( in_ch = 0; in_ch < numch_in; in_ch++ )
     165             :                 {
     166    94138176 :                     for ( b = 0; b < num_spar_bands; b++ )
     167             :                     {
     168    86822016 :                         hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + md_sf * IVAS_MAX_NUM_BANDS];
     169             :                     }
     170             :                 }
     171             :             }
     172             :         }
     173             :     }
     174             : 
     175             : 
     176             :     /* Create prototypes */
     177      458604 :     if ( st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC || st_ivas->renderer_type == RENDERER_BINAURAL_PARAMETRIC_ROOM )
     178             :     {
     179     2287713 :         for ( ts = 0; ts < hSpar->subframe_nbslots[subframe]; ts++ )
     180             :         {
     181     1829109 :             if ( st_ivas->nchan_transport == 1 ) /* Dual mono */
     182             :             {
     183      792870 :                 mvr2r( inRe[0][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX );
     184      792870 :                 mvr2r( inIm[0][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX );
     185             :             }
     186     1036239 :             else if ( st_ivas->nchan_transport == 2 ) /* Opposing cardioids */
     187             :             {
     188             :                 float temp_signal[CLDFB_NO_CHANNELS_MAX];
     189             : 
     190     1036239 :                 v_add( inRe[0][ts], inRe[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX );
     191     1036239 :                 v_sub( inRe[0][ts], inRe[1][ts], inRe[1][ts], CLDFB_NO_CHANNELS_MAX );
     192     1036239 :                 mvr2r( temp_signal, inRe[0][ts], CLDFB_NO_CHANNELS_MAX );
     193     1036239 :                 v_multc( inRe[0][ts], 0.5f, inRe[0][ts], CLDFB_NO_CHANNELS_MAX );
     194     1036239 :                 v_multc( inRe[1][ts], 0.5f, inRe[1][ts], CLDFB_NO_CHANNELS_MAX );
     195             : 
     196     1036239 :                 v_add( inIm[0][ts], inIm[1][ts], temp_signal, CLDFB_NO_CHANNELS_MAX );
     197     1036239 :                 v_sub( inIm[0][ts], inIm[1][ts], inIm[1][ts], CLDFB_NO_CHANNELS_MAX );
     198     1036239 :                 mvr2r( temp_signal, inIm[0][ts], CLDFB_NO_CHANNELS_MAX );
     199     1036239 :                 v_multc( inIm[0][ts], 0.5f, inIm[0][ts], CLDFB_NO_CHANNELS_MAX );
     200     1036239 :                 v_multc( inIm[1][ts], 0.5f, inIm[1][ts], CLDFB_NO_CHANNELS_MAX );
     201             :             }
     202             :         }
     203             :     }
     204             : 
     205      458604 :     hSpar->subframes_rendered++;
     206      458604 :     hSpar->slots_rendered += hSpar->subframe_nbslots[subframe];
     207      458604 :     pop_wmops();
     208             : 
     209      458604 :     return;
     210             : }

Generated by: LCOV version 1.14