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 @ 9ddacaa85e9af3c6e72d1664bd6065cbc5f14284 Lines: 68 80 85.0 %
Date: 2025-10-20 07:00:55 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       14843 : 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       14843 :     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       14843 :     hSbaIsmData->delayBuffer_nchan = st_ivas->nchan_ism;
      65       14843 :     hSbaIsmData->delayBuffer_size = (int16_t) ( ( st_ivas->hDecoderConfig->output_Fs / 50 ) / MAX_PARAM_SPATIAL_SUBFRAMES );
      66             : 
      67       14843 :     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       51614 :     for ( i = 0; i < hSbaIsmData->delayBuffer_nchan; i++ )
      73             :     {
      74       36771 :         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       36771 :         set_zero( hSbaIsmData->delayBuffer[i], hSbaIsmData->delayBuffer_size );
      79             :     }
      80             : 
      81       14843 :     st_ivas->hSbaIsmData = hSbaIsmData;
      82             : 
      83       14843 :     return IVAS_ERR_OK;
      84             : }
      85             : 
      86             : 
      87             : /*-------------------------------------------------------------------*
      88             :  * ivas_osba_data_close()
      89             :  *
      90             :  * Deallocate SBA_ISM rendering handle
      91             :  *-------------------------------------------------------------------*/
      92             : 
      93       88772 : void ivas_osba_data_close(
      94             :     SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle    */
      95             : )
      96             : {
      97             :     int16_t i;
      98             : 
      99       88772 :     if ( hSbaIsmData == NULL || *hSbaIsmData == NULL )
     100             :     {
     101       73929 :         return;
     102             :     }
     103             : 
     104       14843 :     if ( ( *hSbaIsmData )->delayBuffer != NULL )
     105             :     {
     106       51614 :         for ( i = 0; i < ( *hSbaIsmData )->delayBuffer_nchan; i++ )
     107             :         {
     108       36771 :             free( ( *hSbaIsmData )->delayBuffer[i] );
     109             :         }
     110       14843 :         free( ( *hSbaIsmData )->delayBuffer );
     111       14843 :         ( *hSbaIsmData )->delayBuffer = NULL;
     112             :     }
     113             : 
     114       14843 :     free( *hSbaIsmData );
     115       14843 :     *hSbaIsmData = NULL;
     116             : 
     117       14843 :     return;
     118             : }
     119             : 
     120             : 
     121             : /*--------------------------------------------------------------------------*
     122             :  * ivas_osba_dirac_td_binaural_jbm()
     123             :  *
     124             :  * Binaural rendering in JBM OSBA format
     125             :  *--------------------------------------------------------------------------*/
     126             : 
     127      242529 : 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             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
     141             :     float *re, *im;
     142             : #else
     143             :     int16_t slot_idx_start;
     144             : 
     145             :     slot_idx_start = st_ivas->hSpatParamRendCom->slots_rendered;
     146             : #endif
     147             : 
     148      727587 :     for ( n = 0; n < BINAURAL_CHANNELS; n++ )
     149             :     {
     150      485058 :         p_sepobj[n] = &output_separated_objects[n][0];
     151             :     }
     152             : 
     153      242529 :     channel_offset = st_ivas->nchan_ism;
     154             : 
     155      242529 :     if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, &output_f[channel_offset] ) ) != IVAS_ERR_OK )
     156             :     {
     157           0 :         return error;
     158             :     }
     159             : 
     160      242529 :     ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     161             : 
     162      242529 :     if ( st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED || st_ivas->hDecoderConfig->output_config == IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM )
     163       49396 :     {
     164             :         int16_t slot_idx, num_cldfb_bands, nchan_transport_orig;
     165             : #ifndef FIX_1119_SPLIT_RENDERING_VOIP
     166             :         int16_t b;
     167             : #endif
     168             :         int16_t cldfb_slots;
     169             :         float Cldfb_RealBuffer[CLDFB_NO_CHANNELS_MAX];
     170             :         float Cldfb_ImagBuffer[CLDFB_NO_CHANNELS_MAX];
     171             : 
     172       49396 :         num_cldfb_bands = st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[0]->no_channels;
     173       49396 :         nchan_transport_orig = st_ivas->nchan_transport;
     174       49396 :         st_ivas->nchan_transport = st_ivas->nchan_ism;
     175             : 
     176       49396 :         if ( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, output_f, *nSamplesRendered ) ) != IVAS_ERR_OK )
     177             :         {
     178           0 :             return error;
     179             :         }
     180             : 
     181       49396 :         st_ivas->nchan_transport = nchan_transport_orig;
     182       49396 :         cldfb_slots = *nSamplesRendered / num_cldfb_bands;
     183             : 
     184      454140 :         for ( n = 0; n < st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses * BINAURAL_CHANNELS; ++n )
     185             :         {
     186     6243088 :             for ( slot_idx = 0; slot_idx < cldfb_slots; slot_idx++ )
     187             :             {
     188     5838344 :                 cldfbAnalysis_ts( &( output_f[n][num_cldfb_bands * slot_idx] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, num_cldfb_bands, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n] );
     189             : 
     190             : #ifdef FIX_1119_SPLIT_RENDERING_VOIP
     191     5838344 :                 ivas_CLDFB_RINGBUF_GetByIdx( st_ivas->hSplitBinRend->hMultiBinCldfbData[n], &re, &im, slot_idx - cldfb_slots );
     192     5838344 :                 v_add( re, Cldfb_RealBuffer, re, num_cldfb_bands );
     193     5838344 :                 v_add( im, Cldfb_ImagBuffer, im, num_cldfb_bands );
     194             : #else
     195             :                 for ( b = 0; b < num_cldfb_bands; b++ )
     196             :                 {
     197             :                     st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[n][slot_idx_start + slot_idx][b] =
     198             :                         st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[n][slot_idx_start + slot_idx][b] +
     199             :                         Cldfb_RealBuffer[b];
     200             :                     st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[n][slot_idx_start + slot_idx][b] =
     201             :                         st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[n][slot_idx_start + slot_idx][b] +
     202             :                         Cldfb_ImagBuffer[b];
     203             :                 }
     204             : #endif
     205             :             }
     206             :         }
     207             :     }
     208             :     else
     209             :     {
     210      193133 :         if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK )
     211             :         {
     212           0 :             return error;
     213             :         }
     214             : 
     215      579399 :         for ( n = 0; n < BINAURAL_CHANNELS; n++ )
     216             :         {
     217             :             int16_t i;
     218   216716986 :             for ( i = 0; i < nSamplesAsked; i++ )
     219             :             {
     220   216330720 :                 output_f[n][i] = output_f[channel_offset + n][i] + p_sepobj[n][i];
     221             :             }
     222             :         }
     223             :     }
     224             : 
     225      242529 :     return IVAS_ERR_OK;
     226             : }
     227             : 
     228             : 
     229             : /*-------------------------------------------------------------------------*
     230             :  * ivas_osba_ism_metadata_dec()
     231             :  *
     232             :  * ISM metadata decoding in OSBA format.
     233             :  *-------------------------------------------------------------------------*/
     234             : 
     235      763186 : ivas_error ivas_osba_ism_metadata_dec(
     236             :     Decoder_Struct *st_ivas,       /* i/o: IVAS decoder structure            */
     237             :     const int32_t ism_total_brate, /* i  : ISM total bitrate                 */
     238             :     int16_t *nchan_ism,            /* o  : number of ISM separated channels  */
     239             :     int16_t nb_bits_metadata[]     /* o  : number of ISM metadata bits       */
     240             : )
     241             : {
     242             :     ivas_error error;
     243             :     int16_t nchan_transport_ism;
     244             : 
     245             :     /* set ISM parameters */
     246      763186 :     nchan_transport_ism = st_ivas->nchan_ism;
     247      763186 :     *nchan_ism = st_ivas->nchan_ism;
     248             : 
     249             :     /* decode ISM metadata */
     250      763186 :     if ( ( error = ivas_ism_metadata_dec( ism_total_brate, *nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, NULL, st_ivas->bfi,
     251      763186 :                                           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 )
     252             :     {
     253           0 :         return error;
     254             :     }
     255             : 
     256      763186 :     return IVAS_ERR_OK;
     257             : }
     258             : 
     259             : /*-------------------------------------------------------------------------*
     260             :  * ivas_osba_render_sf()
     261             :  *
     262             :  * Object + SBA rendering process.
     263             :  *-------------------------------------------------------------------------*/
     264             : 
     265      456244 : ivas_error ivas_osba_render_sf(
     266             :     Decoder_Struct *st_ivas,         /* i/o: IVAS decoder handle                       */
     267             :     const uint16_t nSamplesAsked,    /* i  : number of CLDFB slots requested           */
     268             :     uint16_t *nSamplesRendered,      /* o  : number of CLDFB slots rendered            */
     269             :     uint16_t *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render     */
     270             :     float *p_output[]                /* o  : rendered time signal                      */
     271             : )
     272             : {
     273             :     int16_t n;
     274             :     float output_sba[MAX_OUTPUT_CHANNELS][L_FRAME48k];
     275             :     float *p_output_sba[MAX_OUTPUT_CHANNELS];
     276             :     ivas_error error;
     277             : 
     278     7756148 :     for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
     279             :     {
     280     7299904 :         p_output_sba[n] = output_sba[n];
     281             :     }
     282             : 
     283      456244 :     if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output_sba ) ) != IVAS_ERR_OK )
     284             :     {
     285           0 :         return error;
     286             :     }
     287             : 
     288      456244 :     if ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM )
     289             :     {
     290      365370 :         ivas_ism_render_sf( st_ivas, st_ivas->renderer_type, p_output, *nSamplesRendered );
     291             :     }
     292             : 
     293     3981846 :     for ( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     294             :     {
     295     3525602 :         if ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM )
     296             :         {
     297     3343854 :             v_add( p_output[n], p_output_sba[n], p_output[n], *nSamplesRendered );
     298             :         }
     299             :         else
     300             :         {
     301      181748 :             mvr2r( p_output_sba[n], p_output[n], *nSamplesRendered );
     302             :         }
     303             :     }
     304             : 
     305      456244 :     return IVAS_ERR_OK;
     306             : }
     307             : 
     308             : 
     309             : /*-------------------------------------------------------------------------*
     310             :  * ivas_osba_stereo_add_channels()
     311             :  *
     312             :  *
     313             :  *-------------------------------------------------------------------------*/
     314             : 
     315       51614 : void ivas_osba_stereo_add_channels(
     316             :     float *tc_f[],                    /* i  : transport channels                */
     317             :     float *output_f[],                /* i/o: output channels                   */
     318             :     const float gain,                 /* i  : gain bed value                    */
     319             :     const int16_t nchan_out,          /* i  : number of output channels         */
     320             :     const int16_t nchan_ism,          /* i  : number of ISM channels            */
     321             :     const int16_t n_samples_to_render /* i  : output frame length per channel   */
     322             : )
     323             : {
     324             :     int16_t n;
     325             : 
     326       51614 :     if ( gain != 1.0f && gain >= 0.0f )
     327           0 :     {
     328             :         int16_t i;
     329           0 :         for ( n = 0; n < nchan_out; n++ )
     330             :         {
     331           0 :             for ( i = 0; i < n_samples_to_render; i++ )
     332             :             {
     333           0 :                 output_f[n][i] += tc_f[n + nchan_ism][i] * gain;
     334             :             }
     335             :         }
     336             :     }
     337             :     else
     338             :     {
     339      154842 :         for ( n = 0; n < nchan_out; n++ )
     340             :         {
     341      103228 :             v_add( output_f[n], tc_f[n + nchan_ism], output_f[n], n_samples_to_render );
     342             :         }
     343             :     }
     344             : 
     345             : 
     346       51614 :     return;
     347             : }

Generated by: LCOV version 1.14