LCOV - code coverage report
Current view: top level - lib_dec - ivas_osba_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main enc/dec/rend @ 3b2f07138c61dcf997bbf4165d0882f794b2995f Lines: 58 65 89.2 %
Date: 2025-05-03 01:55:50 Functions: 5 5 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 "prot_fx.h"
      37             : #include "ivas_prot_rend_fx.h"
      38             : #include "ivas_rom_com.h"
      39             : #include "wmc_auto.h"
      40             : #include "ivas_prot_fx.h"
      41             : 
      42             : 
      43             : /*-------------------------------------------------------------------*
      44             :  * ivas_osba_data_open()
      45             :  *
      46             :  * Allocate and initialize SBA_ISM rendering handle
      47             :  *-------------------------------------------------------------------*/
      48             : 
      49          88 : ivas_error ivas_osba_data_open_fx(
      50             :     Decoder_Struct *st_ivas /* i/o: IVAS decoder handle  */
      51             : )
      52             : {
      53             :     SBA_ISM_DATA_HANDLE hSbaIsmData;
      54             :     Word16 i;
      55             : 
      56          88 :     IF( ( hSbaIsmData = (SBA_ISM_DATA_HANDLE) malloc( sizeof( SBA_ISM_DATA ) ) ) == NULL )
      57             :     {
      58           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for OSBA data\n" ) );
      59             :     }
      60             : 
      61          88 :     hSbaIsmData->delayBuffer_nchan = st_ivas->nchan_ism;
      62          88 :     move16();
      63          88 :     hSbaIsmData->delayBuffer_size = shr( div_l( st_ivas->hDecoderConfig->output_Fs, 50 / 2 ), 2 /* / MAX_PARAM_SPATIAL_SUBFRAMES*/ );
      64          88 :     move16();
      65             : 
      66          88 :     IF( ( hSbaIsmData->delayBuffer_fx = (Word32 **) malloc( hSbaIsmData->delayBuffer_nchan * sizeof( Word32 * ) ) ) == NULL )
      67             :     {
      68           0 :         return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) );
      69             :     }
      70             : 
      71         382 :     FOR( i = 0; i < hSbaIsmData->delayBuffer_nchan; i++ )
      72             :     {
      73         294 :         IF( ( hSbaIsmData->delayBuffer_fx[i] = (Word32 *) malloc( hSbaIsmData->delayBuffer_size * sizeof( Word32 ) ) ) == NULL )
      74             :         {
      75           0 :             return ( IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Cannot allocate memory for OSBA delay buffer \n" ) );
      76             :         }
      77         294 :         set_zero_fx( hSbaIsmData->delayBuffer_fx[i], hSbaIsmData->delayBuffer_size );
      78             :     }
      79             : 
      80          88 :     st_ivas->hSbaIsmData = hSbaIsmData;
      81             : 
      82          88 :     return IVAS_ERR_OK;
      83             : }
      84             : 
      85             : 
      86             : /*-------------------------------------------------------------------*
      87             :  * ivas_osba_data_close()
      88             :  *
      89             :  * Deallocate SBA_ISM rendering handle
      90             :  *-------------------------------------------------------------------*/
      91             : 
      92         676 : void ivas_osba_data_close_fx(
      93             :     SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle    */
      94             : )
      95             : {
      96             :     Word16 i;
      97             : 
      98         676 :     test();
      99         676 :     IF( hSbaIsmData == NULL || *hSbaIsmData == NULL )
     100             :     {
     101         588 :         return;
     102             :     }
     103             : 
     104          88 :     IF( ( *hSbaIsmData )->delayBuffer_fx != NULL )
     105             :     {
     106         382 :         FOR( i = 0; i < ( *hSbaIsmData )->delayBuffer_nchan; i++ )
     107             :         {
     108         294 :             free( ( *hSbaIsmData )->delayBuffer_fx[i] );
     109             :         }
     110          88 :         free( ( *hSbaIsmData )->delayBuffer_fx );
     111          88 :         ( *hSbaIsmData )->delayBuffer_fx = NULL;
     112             :     }
     113             : 
     114          88 :     free( *hSbaIsmData );
     115          88 :     *hSbaIsmData = NULL;
     116             : 
     117          88 :     return;
     118             : }
     119             : 
     120             : 
     121             : /*--------------------------------------------------------------------------*
     122             :  * ivas_osba_dirac_td_binaural_jbm()
     123             :  *
     124             :  * Binaural rendering in JBM OSBA format
     125             :  *--------------------------------------------------------------------------*/
     126             : 
     127        4689 : ivas_error ivas_osba_dirac_td_binaural_jbm_fx(
     128             :     Decoder_Struct *st_ivas,     /* i/o: IVAS decoder structure                    */
     129             :     const UWord16 nSamplesAsked, /* i  : number of CLDFB slots requested           */
     130             :     UWord16 *nSamplesRendered,   /* o  : number of CLDFB slots rendered            */
     131             :     UWord16 *nSamplesAvailable,  /* o  : number of CLDFB slots still to render     */
     132             :     Word32 *output_fx[]          /* o  : rendered time signal                      Q11*/
     133             : )
     134             : {
     135             :     Word16 n;
     136             :     ivas_error error;
     137             :     Word32 output_separated_objects_fx[BINAURAL_CHANNELS][L_FRAME48k]; // VE2SB: TBV
     138             :     Word32 *p_sepobj_fx[BINAURAL_CHANNELS];
     139             :     Word16 channel_offset;
     140             : 
     141       14067 :     FOR( Word16 i = 0; i < BINAURAL_CHANNELS; i++ )
     142             :     {
     143        9378 :         set32_fx( output_separated_objects_fx[i], 0, L_FRAME48k );
     144             :     }
     145             : 
     146       14067 :     FOR( n = 0; n < BINAURAL_CHANNELS; n++ )
     147             :     {
     148        9378 :         p_sepobj_fx[n] = &output_separated_objects_fx[n][0];
     149             :     }
     150             : 
     151        4689 :     channel_offset = st_ivas->nchan_ism;
     152        4689 :     move16();
     153             : 
     154        4689 :     IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, &output_fx[channel_offset] ) ), IVAS_ERR_OK ) )
     155             :     {
     156           0 :         return error;
     157             :     }
     158             : 
     159        4689 :     IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
     160             :     {
     161           0 :         return error;
     162             :     }
     163             : 
     164       14067 :     FOR( n = 0; n < BINAURAL_CHANNELS; n++ )
     165             :     {
     166             :         Word16 i;
     167     8864898 :         FOR( i = 0; i < nSamplesAsked; i++ )
     168             :         {
     169     8855520 :             output_fx[n][i] = L_add( L_shr( output_fx[channel_offset + n][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) );
     170     8855520 :             move32();
     171             :         }
     172             :     }
     173        4689 :     return IVAS_ERR_OK;
     174             : }
     175             : 
     176             : 
     177             : /*-------------------------------------------------------------------------*
     178             :  * ivas_osba_ism_metadata_dec()
     179             :  *
     180             :  * ISM metadata decoding in OSBA format.
     181             :  *-------------------------------------------------------------------------*/
     182             : 
     183       13100 : ivas_error ivas_osba_ism_metadata_dec_fx(
     184             :     Decoder_Struct *st_ivas,      /* i/o: IVAS decoder structure            */
     185             :     const Word32 ism_total_brate, /* i  : ISM total bitrate                 */
     186             :     Word16 *nchan_ism,            /* o  : number of ISM separated channels  */
     187             :     Word16 nb_bits_metadata[]     /* o  : number of ISM metadata bits       */
     188             : )
     189             : {
     190             :     ivas_error error;
     191             :     Word16 nchan_transport_ism;
     192             : 
     193             :     /* set ISM parameters */
     194       13100 :     nchan_transport_ism = st_ivas->nchan_ism;
     195       13100 :     move16();
     196       13100 :     *nchan_ism = st_ivas->nchan_ism;
     197       13100 :     move16();
     198             : 
     199             :     /* decode ISM metadata */
     200       13100 :     IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ism_total_brate, *nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, NULL, st_ivas->bfi,
     201             :                                                    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] ) ),
     202             :                IVAS_ERR_OK ) )
     203             :     {
     204           0 :         return error;
     205             :     }
     206             : 
     207       13100 :     return IVAS_ERR_OK;
     208             : }
     209             : 
     210             : 
     211             : /*-------------------------------------------------------------------------*
     212             :  * ivas_osba_render_sf()
     213             :  *
     214             :  * Object + SBA rendering process.
     215             :  *-------------------------------------------------------------------------*/
     216             : 
     217        4000 : ivas_error ivas_osba_render_sf_fx(
     218             :     Decoder_Struct *st_ivas,        /* i/o: IVAS decoder handle                       */
     219             :     const UWord16 nSamplesAsked,    /* i  : number of CLDFB slots requested           */
     220             :     UWord16 *nSamplesRendered,      /* o  : number of CLDFB slots rendered            */
     221             :     UWord16 *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render     */
     222             :     Word32 *p_output[]              /* o  : rendered time signal                      Q11*/
     223             : )
     224             : {
     225             :     Word16 n;
     226             :     Word32 output_ism[MAX_OUTPUT_CHANNELS][L_FRAME48k];
     227             :     Word32 *p_output_ism[MAX_OUTPUT_CHANNELS];
     228             :     ivas_error error;
     229             : 
     230       68000 :     FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
     231             :     {
     232       64000 :         p_output_ism[n] = &output_ism[n][0];
     233             :     }
     234             : 
     235       16000 :     FOR( n = 0; n < st_ivas->nchan_ism; n++ )
     236             :     {
     237       12000 :         v_shr( p_output[n], Q11 - Q11, output_ism[n], nSamplesAsked ); // Q11
     238             :     }
     239             : 
     240        4000 :     IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output ) ), IVAS_ERR_OK ) )
     241             :     {
     242           0 :         return error;
     243             :     }
     244             : 
     245        4000 :     IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
     246             :     {
     247        2000 :         ivas_ism_render_sf_fx( st_ivas, p_output_ism, *nSamplesRendered );
     248             :     }
     249             : 
     250       32000 :     FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     251             :     {
     252       28000 :         IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
     253             :         {
     254       24000 :             v_add_fixed( p_output[n], p_output_ism[n], p_output[n], *nSamplesRendered, 1 ); // takes care of downscaling by 0.5f
     255             :         }
     256             :         ELSE
     257             :         {
     258        4000 :             scale_sig32( p_output[n], *nSamplesRendered, -1 );
     259             :         }
     260             :     }
     261             : 
     262        4000 :     return IVAS_ERR_OK;
     263             : }

Generated by: LCOV version 1.14