LCOV - code coverage report
Current view: top level - lib_dec - ivas_osba_dec.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ fec202a8f89be4a2f278a9fc377bfb58b58fab11 Lines: 56 85 65.9 %
Date: 2025-09-11 08:49:07 Functions: 6 6 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 "options.h"
      34             : #include <stdlib.h>
      35             : #include "ivas_cnst.h"
      36             : #include "ivas_prot.h"
      37             : #include "prot.h"
      38             : #include "ivas_prot_rend.h"
      39             : #include "ivas_rom_com.h"
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : #include "wmc_auto.h"
      44             : 
      45             : 
      46             : /*-------------------------------------------------------------------*
      47             :  * ivas_osba_data_open()
      48             :  *
      49             :  * Allocate and initialize SBA_ISM rendering handle
      50             :  *-------------------------------------------------------------------*/
      51             : 
      52         615 : ivas_error ivas_osba_data_open(
      53             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder handle  */
      54             : )
      55             : {
      56             :     SBA_ISM_DATA_HANDLE hSbaIsmData;
      57             :     int16_t i;
      58             : 
      59         615 :     if ( ( hSbaIsmData = (SBA_ISM_DATA_HANDLE) malloc( sizeof( SBA_ISM_DATA ) ) ) == NULL )
      60             :     {
      61           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OSBA data\n" ) );
      62             :     }
      63             : 
      64         615 :     hSbaIsmData->delayBuffer_nchan = st_ivas->nchan_ism;
      65         615 :     hSbaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES );
      66             : 
      67         615 :     if ( ( hSbaIsmData->delayBuffer = (float **) malloc( hSbaIsmData->delayBuffer_nchan * sizeof( float * ) ) ) == NULL )
      68             :     {
      69           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) );
      70             :     }
      71             : 
      72        2646 :     for ( i = 0; i < hSbaIsmData->delayBuffer_nchan; i++ )
      73             :     {
      74        2031 :         if ( ( hSbaIsmData->delayBuffer[i] = (float *) malloc( hSbaIsmData->delayBuffer_size * sizeof( float ) ) ) == NULL )
      75             :         {
      76           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) );
      77             :         }
      78        2031 :         set_zero( hSbaIsmData->delayBuffer[i], hSbaIsmData->delayBuffer_size );
      79             :     }
      80             : 
      81         615 :     st_ivas->hSbaIsmData = hSbaIsmData;
      82             : 
      83         615 :     return IVAS_ERR_OK;
      84             : }
      85             : 
      86             : 
      87             : /*-------------------------------------------------------------------*
      88             :  * ivas_osba_data_close()
      89             :  *
      90             :  * Deallocate SBA_ISM rendering handle
      91             :  *-------------------------------------------------------------------*/
      92             : 
      93        2424 : void ivas_osba_data_close(
      94             :     SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle    */
      95             : )
      96             : {
      97             :     int16_t i;
      98             : 
      99        2424 :     if ( hSbaIsmData == NULL || *hSbaIsmData == NULL )
     100             :     {
     101        1809 :         return;
     102             :     }
     103             : 
     104         615 :     if ( ( *hSbaIsmData )->delayBuffer != NULL )
     105             :     {
     106        2646 :         for ( i = 0; i < ( *hSbaIsmData )->delayBuffer_nchan; i++ )
     107             :         {
     108        2031 :             free( ( *hSbaIsmData )->delayBuffer[i] );
     109             :         }
     110         615 :         free( ( *hSbaIsmData )->delayBuffer );
     111         615 :         ( *hSbaIsmData )->delayBuffer = NULL;
     112             :     }
     113             : 
     114         615 :     free( *hSbaIsmData );
     115         615 :     *hSbaIsmData = NULL;
     116             : 
     117         615 :     return;
     118             : }
     119             : 
     120             : 
     121             : /*--------------------------------------------------------------------------*
     122             :  * ivas_osba_dirac_td_binaural_jbm()
     123             :  *
     124             :  * Binaural rendering in JBM OSBA format
     125             :  *--------------------------------------------------------------------------*/
     126             : 
     127       65385 : ivas_error ivas_osba_dirac_td_binaural_jbm(
     128             :     Decoder_Struct *st_ivas,      /* i/o: IVAS decoder structure                    */
     129             :     const uint16_t nSamplesAsked, /* i  : number of CLDFB slots requested           */
     130             :     uint16_t *nSamplesRendered,   /* o  : number of CLDFB slots rendered            */
     131             :     uint16_t *nSamplesAvailable,  /* o  : number of CLDFB slots still to render     */
     132             :     float *output_f[]             /* o  : rendered time signal                      */
     133             : )
     134             : {
     135             :     int16_t n;
     136             :     ivas_error error;
     137             :     float output_separated_objects[BINAURAL_CHANNELS][L_FRAME48k];
     138             :     float *p_sepobj[BINAURAL_CHANNELS];
     139             :     int16_t channel_offset;
     140             :     int16_t slot_idx_start;
     141             : 
     142       65385 :     slot_idx_start = st_ivas->hSpatParamRendCom->slots_rendered;
     143             : 
     144      196155 :     for ( n = 0; n < BINAURAL_CHANNELS; n++ )
     145             :     {
     146      130770 :         p_sepobj[n] = &output_separated_objects[n][0];
     147             :     }
     148             : 
     149       65385 :     channel_offset = st_ivas->nchan_ism;
     150             : 
     151       65385 :     if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, &output_f[channel_offset] ) ) != IVAS_ERR_OK )
     152             :     {
     153           0 :         return error;
     154             :     }
     155             : 
     156       65385 :     ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     157             : 
     158       65385 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     159           0 :     {
     160             :         int16_t slot_idx, num_cldfb_bands, b, nchan_transport_orig;
     161             :         int16_t cldfb_slots;
     162             :         float Cldfb_RealBuffer[CLDFB_NO_CHANNELS_MAX];
     163             :         float Cldfb_ImagBuffer[CLDFB_NO_CHANNELS_MAX];
     164             : 
     165           0 :         num_cldfb_bands = st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[0]->no_channels;
     166           0 :         nchan_transport_orig = st_ivas->nchan_transport;
     167           0 :         st_ivas->nchan_transport = st_ivas->nchan_ism;
     168             : 
     169           0 :         if ( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, output_f, *nSamplesRendered ) ) != IVAS_ERR_OK )
     170             :         {
     171           0 :             return error;
     172             :         }
     173             : 
     174           0 :         st_ivas->nchan_transport = nchan_transport_orig;
     175           0 :         cldfb_slots = *nSamplesRendered / num_cldfb_bands;
     176             : 
     177           0 :         for ( n = 0; n < st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS; ++n )
     178             :         {
     179           0 :             for ( slot_idx = 0; slot_idx < cldfb_slots; slot_idx++ )
     180             :             {
     181           0 :                 cldfbAnalysis_ts( &( output_f[n][num_cldfb_bands * slot_idx] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, num_cldfb_bands, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n] );
     182             : 
     183           0 :                 for ( b = 0; b < num_cldfb_bands; b++ )
     184             :                 {
     185           0 :                     st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[n][slot_idx_start + slot_idx][b] =
     186           0 :                         st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[n][slot_idx_start + slot_idx][b] +
     187           0 :                         Cldfb_RealBuffer[b];
     188           0 :                     st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[n][slot_idx_start + slot_idx][b] =
     189           0 :                         st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[n][slot_idx_start + slot_idx][b] +
     190           0 :                         Cldfb_ImagBuffer[b];
     191             :                 }
     192             :             }
     193             :         }
     194             :     }
     195             :     else
     196             :     {
     197       65385 :         if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK )
     198             :         {
     199           0 :             return error;
     200             :         }
     201             : 
     202      196155 :         for ( n = 0; n < BINAURAL_CHANNELS; n++ )
     203             :         {
     204             :             int16_t i;
     205    51664050 :             for ( i = 0; i < nSamplesAsked; i++ )
     206             :             {
     207    51533280 :                 output_f[n][i] = output_f[channel_offset + n][i] + p_sepobj[n][i];
     208             :             }
     209             :         }
     210             :     }
     211             : 
     212       65385 :     return IVAS_ERR_OK;
     213             : }
     214             : 
     215             : 
     216             : /*-------------------------------------------------------------------------*
     217             :  * ivas_osba_ism_metadata_dec()
     218             :  *
     219             :  * ISM metadata decoding in OSBA format.
     220             :  *-------------------------------------------------------------------------*/
     221             : 
     222       66246 : ivas_error ivas_osba_ism_metadata_dec(
     223             :     Decoder_Struct *st_ivas,       /* i/o: IVAS decoder structure            */
     224             :     const int32_t ism_total_brate, /* i  : ISM total bitrate                 */
     225             :     int16_t *nchan_ism,            /* o  : number of ISM separated channels  */
     226             :     int16_t nb_bits_metadata[]     /* o  : number of ISM metadata bits       */
     227             : )
     228             : {
     229             :     ivas_error error;
     230             :     int16_t nchan_transport_ism;
     231             : 
     232             :     /* set ISM parameters */
     233       66246 :     nchan_transport_ism = st_ivas->nchan_ism;
     234       66246 :     *nchan_ism = st_ivas->nchan_ism;
     235             : 
     236             :     /* decode ISM metadata */
     237       66246 :     if ( ( error = ivas_ism_metadata_dec( ism_total_brate, *nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, NULL, st_ivas->bfi,
     238       66246 :                                           nb_bits_metadata, st_ivas->ism_mode, st_ivas->hISMDTX, NULL, &st_ivas->ism_extmeta_active, &st_ivas->ism_extmeta_cnt, st_ivas->hCPE[0]->hCoreCoder[0] ) ) != IVAS_ERR_OK )
     239             :     {
     240           0 :         return error;
     241             :     }
     242             : 
     243       66246 :     return IVAS_ERR_OK;
     244             : }
     245             : 
     246             : /*-------------------------------------------------------------------------*
     247             :  * ivas_osba_render_sf()
     248             :  *
     249             :  * Object + SBA rendering process.
     250             :  *-------------------------------------------------------------------------*/
     251             : 
     252       58858 : ivas_error ivas_osba_render_sf(
     253             :     Decoder_Struct *st_ivas,         /* i/o: IVAS decoder handle                       */
     254             :     const uint16_t nSamplesAsked,    /* i  : number of CLDFB slots requested           */
     255             :     uint16_t *nSamplesRendered,      /* o  : number of CLDFB slots rendered            */
     256             :     uint16_t *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render     */
     257             :     float *p_output[]                /* o  : rendered time signal                      */
     258             : )
     259             : {
     260             :     int16_t n;
     261             :     float output_sba[MAX_OUTPUT_CHANNELS][L_FRAME48k];
     262             :     float *p_output_sba[MAX_OUTPUT_CHANNELS];
     263             :     ivas_error error;
     264             : 
     265     1000586 :     for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
     266             :     {
     267      941728 :         p_output_sba[n] = output_sba[n];
     268             :     }
     269             : 
     270       58858 :     if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output_sba ) ) != IVAS_ERR_OK )
     271             :     {
     272           0 :         return error;
     273             :     }
     274             : 
     275       58858 :     if ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM )
     276             :     {
     277       30858 :         ivas_ism_render_sf( st_ivas, st_ivas->renderer_type, p_output, *nSamplesRendered );
     278             :     }
     279             : 
     280      406290 :     for ( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     281             :     {
     282      347432 :         if ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM )
     283             :         {
     284      291432 :             v_add( p_output[n], p_output_sba[n], p_output[n], *nSamplesRendered );
     285             :         }
     286             :         else
     287             :         {
     288       56000 :             mvr2r( p_output_sba[n], p_output[n], *nSamplesRendered );
     289             :         }
     290             :     }
     291             : 
     292       58858 :     return IVAS_ERR_OK;
     293             : }
     294             : 
     295             : 
     296             : /*-------------------------------------------------------------------------*
     297             :  * ivas_osba_stereo_add_channels()
     298             :  *
     299             :  *
     300             :  *-------------------------------------------------------------------------*/
     301             : 
     302        9800 : void ivas_osba_stereo_add_channels(
     303             :     float *tc_f[],                    /* i  : transport channels                */
     304             :     float *output_f[],                /* i/o: output channels                   */
     305             :     const float gain,                 /* i  : gain bed value                    */
     306             :     const int16_t nchan_out,          /* i  : number of output channels         */
     307             :     const int16_t nchan_ism,          /* i  : number of ISM channels            */
     308             :     const int16_t n_samples_to_render /* i  : output frame length per channel   */
     309             : )
     310             : {
     311             :     int16_t n;
     312             : 
     313        9800 :     if ( gain != 1.0f && gain >= 0.0f )
     314           0 :     {
     315             :         int16_t i;
     316           0 :         for ( n = 0; n < nchan_out; n++ )
     317             :         {
     318           0 :             for ( i = 0; i < n_samples_to_render; i++ )
     319             :             {
     320           0 :                 output_f[n][i] += tc_f[n + nchan_ism][i] * gain;
     321             :             }
     322             :         }
     323             :     }
     324             :     else
     325             :     {
     326       29400 :         for ( n = 0; n < nchan_out; n++ )
     327             :         {
     328       19600 :             v_add( output_f[n], tc_f[n + nchan_ism], output_f[n], n_samples_to_render );
     329             :         }
     330             :     }
     331             : 
     332             : 
     333        9800 :     return;
     334             : }

Generated by: LCOV version 1.14