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 @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 62 91 68.1 %
Date: 2025-05-23 08:37:30 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        2421 : void ivas_osba_data_close(
      94             :     SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle    */
      95             : )
      96             : {
      97             :     int16_t i;
      98             : 
      99        2421 :     if ( hSbaIsmData == NULL || *hSbaIsmData == NULL )
     100             :     {
     101        1806 :         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       72385 : 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       72385 :     slot_idx_start = st_ivas->hSpatParamRendCom->slots_rendered;
     143             : 
     144      217155 :     for ( n = 0; n < BINAURAL_CHANNELS; n++ )
     145             :     {
     146      144770 :         p_sepobj[n] = &output_separated_objects[n][0];
     147             :     }
     148             : 
     149       72385 :     channel_offset = st_ivas->nchan_ism;
     150             : 
     151       72385 :     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       72385 :     ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     157             : 
     158       72385 :     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 :                         ( 0.5f * st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural[n][slot_idx_start + slot_idx][b] ) +
     187           0 :                         ( 0.5f * Cldfb_RealBuffer[b] );
     188             : 
     189           0 :                     st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[n][slot_idx_start + slot_idx][b] =
     190           0 :                         ( 0.5f * st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural[n][slot_idx_start + slot_idx][b] ) +
     191           0 :                         ( 0.5f * Cldfb_ImagBuffer[b] );
     192             :                 }
     193             :             }
     194             :         }
     195             :     }
     196             :     else
     197             :     {
     198       72385 :         if ( ( error = ivas_td_binaural_renderer_sf( st_ivas, p_sepobj, *nSamplesRendered ) ) != IVAS_ERR_OK )
     199             :         {
     200           0 :             return error;
     201             :         }
     202             : 
     203      217155 :         for ( n = 0; n < BINAURAL_CHANNELS; n++ )
     204             :         {
     205             :             int16_t i;
     206    57438050 :             for ( i = 0; i < nSamplesAsked; i++ )
     207             :             {
     208    57293280 :                 output_f[n][i] = 0.5f * output_f[channel_offset + n][i] + 0.5f * p_sepobj[n][i];
     209             :             }
     210             :         }
     211             :     }
     212             : 
     213       72385 :     return IVAS_ERR_OK;
     214             : }
     215             : 
     216             : 
     217             : /*-------------------------------------------------------------------------*
     218             :  * ivas_osba_ism_metadata_dec()
     219             :  *
     220             :  * ISM metadata decoding in OSBA format.
     221             :  *-------------------------------------------------------------------------*/
     222             : 
     223       66246 : ivas_error ivas_osba_ism_metadata_dec(
     224             :     Decoder_Struct *st_ivas,       /* i/o: IVAS decoder structure            */
     225             :     const int32_t ism_total_brate, /* i  : ISM total bitrate                 */
     226             :     int16_t *nchan_ism,            /* o  : number of ISM separated channels  */
     227             :     int16_t nb_bits_metadata[]     /* o  : number of ISM metadata bits       */
     228             : )
     229             : {
     230             :     ivas_error error;
     231             :     int16_t nchan_transport_ism;
     232             : 
     233             :     /* set ISM parameters */
     234       66246 :     nchan_transport_ism = st_ivas->nchan_ism;
     235       66246 :     *nchan_ism = st_ivas->nchan_ism;
     236             : 
     237             :     /* decode ISM metadata */
     238       66246 :     if ( ( error = ivas_ism_metadata_dec( ism_total_brate, *nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, NULL, st_ivas->bfi,
     239       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 )
     240             :     {
     241           0 :         return error;
     242             :     }
     243             : 
     244       66246 :     return IVAS_ERR_OK;
     245             : }
     246             : 
     247             : /*-------------------------------------------------------------------------*
     248             :  * ivas_osba_render_sf()
     249             :  *
     250             :  * Object + SBA rendering process.
     251             :  *-------------------------------------------------------------------------*/
     252             : 
     253       51858 : ivas_error ivas_osba_render_sf(
     254             :     Decoder_Struct *st_ivas,         /* i/o: IVAS decoder handle                       */
     255             :     const uint16_t nSamplesAsked,    /* i  : number of CLDFB slots requested           */
     256             :     uint16_t *nSamplesRendered,      /* o  : number of CLDFB slots rendered            */
     257             :     uint16_t *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render     */
     258             :     float *p_output[]                /* o  : rendered time signal                      */
     259             : )
     260             : {
     261             :     int16_t n;
     262             :     float output_ism[MAX_OUTPUT_CHANNELS][L_FRAME48k];
     263             :     float *p_output_ism[MAX_OUTPUT_CHANNELS];
     264             :     ivas_error error;
     265             : 
     266      881586 :     for ( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
     267             :     {
     268      829728 :         p_output_ism[n] = &output_ism[n][0];
     269             :     }
     270             : 
     271       51858 :     if ( !st_ivas->hDecoderConfig->Opt_tsm )
     272             :     {
     273             :         int16_t tc_offset;
     274       42000 :         tc_offset = st_ivas->hTcBuffer->n_samples_rendered;
     275      168000 :         for ( n = 0; n < st_ivas->nchan_ism; n++ )
     276             :         {
     277      126000 :             mvr2r( &p_output[n][tc_offset], &output_ism[n][tc_offset], nSamplesAsked );
     278             :         }
     279             :     }
     280             : 
     281       51858 :     if ( ( error = ivas_sba_dec_render( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output ) ) != IVAS_ERR_OK )
     282             :     {
     283           0 :         return error;
     284             :     }
     285             : 
     286       51858 :     if ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM )
     287             :     {
     288       30858 :         ivas_ism_render_sf( st_ivas, st_ivas->renderer_type, p_output_ism, *nSamplesRendered );
     289             :     }
     290             : 
     291      385290 :     for ( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     292             :     {
     293      333432 :         if ( st_ivas->renderer_type != RENDERER_BINAURAL_FASTCONV_ROOM )
     294             :         {
     295      291432 :             v_add( p_output[n], p_output_ism[n], p_output[n], *nSamplesRendered );
     296             :         }
     297             : 
     298      333432 :         v_multc( p_output[n], 0.5f, p_output[n], *nSamplesRendered );
     299             :     }
     300             : 
     301       51858 :     return IVAS_ERR_OK;
     302             : }
     303             : 
     304             : 
     305             : /*-------------------------------------------------------------------------*
     306             :  * ivas_osba_stereo_add_channels()
     307             :  *
     308             :  *
     309             :  *-------------------------------------------------------------------------*/
     310             : 
     311        9800 : void ivas_osba_stereo_add_channels(
     312             :     float *tc_f[],                    /* i  : transport channels                */
     313             :     float *output_f[],                /* i/o: output channels                   */
     314             :     const float gain,                 /* i  : gain bed value                    */
     315             :     const int16_t nchan_out,          /* i  : number of output channels         */
     316             :     const int16_t nchan_ism,          /* i  : number of ISM channels            */
     317             :     const int16_t n_samples_to_render /* i  : output frame length per channel   */
     318             : )
     319             : {
     320             :     int16_t n;
     321             : 
     322        9800 :     if ( gain != 1.0f && gain >= 0.0f )
     323           0 :     {
     324             :         int16_t i;
     325           0 :         for ( n = 0; n < nchan_out; n++ )
     326             :         {
     327           0 :             for ( i = 0; i < n_samples_to_render; i++ )
     328             :             {
     329           0 :                 output_f[n][i] += tc_f[n + nchan_ism][i] * gain;
     330             :             }
     331             :         }
     332             :     }
     333             :     else
     334             :     {
     335       29400 :         for ( n = 0; n < nchan_out; n++ )
     336             :         {
     337       19600 :             v_add( output_f[n], tc_f[n + nchan_ism], output_f[n], n_samples_to_render );
     338             :         }
     339             :     }
     340             : 
     341       29400 :     for ( n = 0; n < nchan_out; n++ )
     342             :     {
     343       19600 :         v_multc( output_f[n], 0.5f, output_f[n], n_samples_to_render );
     344             :     }
     345             : 
     346        9800 :     return;
     347             : }

Generated by: LCOV version 1.14