LCOV - code coverage report
Current view: top level - lib_dec - ivas_osba_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 633e3f2e309758d10805ef21e0436356fe719b7a Lines: 68 108 63.0 %
Date: 2025-08-23 01:22:27 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 "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         177 : 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         177 :     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         177 :     hSbaIsmData->delayBuffer_nchan = st_ivas->nchan_ism;
      62         177 :     move16();
      63         177 :     hSbaIsmData->delayBuffer_size = shr( div_l( st_ivas->hDecoderConfig->output_Fs, 50 / 2 ), 2 /* / MAX_PARAM_SPATIAL_SUBFRAMES*/ );
      64         177 :     move16();
      65             : 
      66         177 :     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         769 :     FOR( i = 0; i < hSbaIsmData->delayBuffer_nchan; i++ )
      72             :     {
      73         592 :         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         592 :         set_zero_fx( hSbaIsmData->delayBuffer_fx[i], hSbaIsmData->delayBuffer_size );
      78             :     }
      79             : 
      80         177 :     st_ivas->hSbaIsmData = hSbaIsmData;
      81             : 
      82         177 :     return IVAS_ERR_OK;
      83             : }
      84             : 
      85             : 
      86             : /*-------------------------------------------------------------------*
      87             :  * ivas_osba_data_close()
      88             :  *
      89             :  * Deallocate SBA_ISM rendering handle
      90             :  *-------------------------------------------------------------------*/
      91             : 
      92         768 : void ivas_osba_data_close_fx(
      93             :     SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle    */
      94             : )
      95             : {
      96             :     Word16 i;
      97             : 
      98         768 :     test();
      99         768 :     IF( hSbaIsmData == NULL || *hSbaIsmData == NULL )
     100             :     {
     101         591 :         return;
     102             :     }
     103             : 
     104         177 :     IF( ( *hSbaIsmData )->delayBuffer_fx != NULL )
     105             :     {
     106         769 :         FOR( i = 0; i < ( *hSbaIsmData )->delayBuffer_nchan; i++ )
     107             :         {
     108         592 :             free( ( *hSbaIsmData )->delayBuffer_fx[i] );
     109             :         }
     110         177 :         free( ( *hSbaIsmData )->delayBuffer_fx );
     111         177 :         ( *hSbaIsmData )->delayBuffer_fx = NULL;
     112             :     }
     113             : 
     114         177 :     free( *hSbaIsmData );
     115         177 :     *hSbaIsmData = NULL;
     116             : 
     117         177 :     return;
     118             : }
     119             : 
     120             : 
     121             : /*--------------------------------------------------------------------------*
     122             :  * ivas_osba_dirac_td_binaural_jbm()
     123             :  *
     124             :  * Binaural rendering in JBM OSBA format
     125             :  *--------------------------------------------------------------------------*/
     126             : 
     127        9250 : 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             :     Word16 slot_idx_start;
     141             : 
     142        9250 :     slot_idx_start = st_ivas->hSpatParamRendCom->slots_rendered;
     143        9250 :     move16();
     144             : 
     145       27750 :     FOR( Word16 i = 0; i < BINAURAL_CHANNELS; i++ )
     146             :     {
     147       18500 :         set32_fx( output_separated_objects_fx[i], 0, L_FRAME48k );
     148             :     }
     149             : 
     150       27750 :     FOR( n = 0; n < BINAURAL_CHANNELS; n++ )
     151             :     {
     152       18500 :         p_sepobj_fx[n] = &output_separated_objects_fx[n][0];
     153             :     }
     154             : 
     155        9250 :     channel_offset = st_ivas->nchan_ism;
     156        9250 :     move16();
     157             : 
     158        9250 :     IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailable, &output_fx[channel_offset] ) ), IVAS_ERR_OK ) )
     159             :     {
     160           0 :         return error;
     161             :     }
     162             : 
     163             : #ifdef NONBE_FIX_ISM_XOVER_BR
     164        9250 :     ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     165             : #endif
     166        9250 :     IF( EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_CODED ) || EQ_16( st_ivas->hDecoderConfig->output_config, IVAS_AUDIO_CONFIG_BINAURAL_SPLIT_PCM ) )
     167           0 :     {
     168             :         Word16 slot_idx, num_cldfb_bands, b, nchan_transport_orig;
     169             :         Word16 cldfb_slots;
     170             :         Word32 Cldfb_RealBuffer[CLDFB_NO_CHANNELS_MAX];
     171             :         Word32 Cldfb_ImagBuffer[CLDFB_NO_CHANNELS_MAX];
     172           0 :         Word16 q_cldfb, q_in = 11;
     173           0 :         move16();
     174             : 
     175           0 :         num_cldfb_bands = st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[0]->no_channels;
     176           0 :         move16();
     177           0 :         nchan_transport_orig = st_ivas->nchan_transport;
     178           0 :         move16();
     179           0 :         st_ivas->nchan_transport = st_ivas->nchan_ism;
     180           0 :         move16();
     181           0 :         IF( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK )
     182             :         {
     183           0 :             return error;
     184             :         }
     185           0 :         st_ivas->nchan_transport = nchan_transport_orig;
     186           0 :         move16();
     187           0 :         cldfb_slots = *nSamplesRendered / num_cldfb_bands;
     188             : 
     189           0 :         FOR( n = 0; n < i_mult( st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses, BINAURAL_CHANNELS ); ++n )
     190             :         {
     191           0 :             q_cldfb = q_in;
     192           0 :             Scale_sig32( st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->cldfb_state_fx,
     193           0 :                          sub( st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->p_filter_length, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->no_channels ),
     194           0 :                          sub( q_cldfb, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->Q_cldfb_state ) );
     195           0 :             st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->Q_cldfb_state = q_cldfb;
     196           0 :             FOR( slot_idx = 0; slot_idx < cldfb_slots; slot_idx++ )
     197             :             {
     198           0 :                 q_cldfb = q_in;
     199           0 :                 cldfbAnalysis_ts_fx_fixed_q( &( output_fx[n][num_cldfb_bands * slot_idx] ), Cldfb_RealBuffer, Cldfb_ImagBuffer, num_cldfb_bands, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n], &q_cldfb );
     200             : 
     201           0 :                 Scale_sig32( Cldfb_RealBuffer, num_cldfb_bands, sub( Q6, q_cldfb ) );
     202           0 :                 Scale_sig32( Cldfb_ImagBuffer, num_cldfb_bands, sub( Q6, q_cldfb ) );
     203           0 :                 FOR( b = 0; b < num_cldfb_bands; b++ )
     204             :                 {
     205           0 :                     st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[n][slot_idx_start + slot_idx][b] =
     206             : #ifdef NONBE_1894_OSBA_SCALING
     207           0 :                         L_add( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[n][add( slot_idx_start, slot_idx )][b], Cldfb_RealBuffer[b] );
     208             : #else
     209             :                         L_add( L_shr( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[n][add( slot_idx_start, slot_idx )][b], 1 ),
     210             :                                L_shr( Cldfb_RealBuffer[b], 1 ) );
     211             : #endif
     212           0 :                     move32();
     213             : 
     214           0 :                     st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[n][slot_idx_start + slot_idx][b] =
     215             : #ifdef NONBE_1894_OSBA_SCALING
     216           0 :                         L_add( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[n][add( slot_idx_start, slot_idx )][b], Cldfb_ImagBuffer[b] );
     217             : #else
     218             :                         L_add( L_shr( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[n][add( slot_idx_start, slot_idx )][b], 1 ),
     219             :                                L_shr( Cldfb_ImagBuffer[b], 1 ) );
     220             : #endif
     221           0 :                     move32();
     222             :                 }
     223             :             }
     224             :         }
     225             :     }
     226             :     else
     227             :     {
     228        9250 :         IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
     229             :         {
     230           0 :             return error;
     231             :         }
     232             : 
     233       27750 :         FOR( n = 0; n < BINAURAL_CHANNELS; n++ )
     234             :         {
     235             :             Word16 i;
     236    16522100 :             FOR( i = 0; i < nSamplesAsked; i++ )
     237             :             {
     238             : #ifdef NONBE_1894_OSBA_SCALING
     239    16503600 :                 output_fx[n][i] = L_add( output_fx[channel_offset + n][i], p_sepobj_fx[n][i] );
     240             : #else
     241             :                 output_fx[n][i] = L_add( L_shr( output_fx[channel_offset + n][i], 1 ), L_shr( p_sepobj_fx[n][i], 1 ) );
     242             : #endif
     243    16503600 :                 move32();
     244             :             }
     245             :         }
     246             :     }
     247        9250 :     return IVAS_ERR_OK;
     248             : }
     249             : 
     250             : 
     251             : /*-------------------------------------------------------------------------*
     252             :  * ivas_osba_ism_metadata_dec()
     253             :  *
     254             :  * ISM metadata decoding in OSBA format.
     255             :  *-------------------------------------------------------------------------*/
     256             : 
     257       19680 : ivas_error ivas_osba_ism_metadata_dec_fx(
     258             :     Decoder_Struct *st_ivas,      /* i/o: IVAS decoder structure            */
     259             :     const Word32 ism_total_brate, /* i  : ISM total bitrate                 */
     260             :     Word16 *nchan_ism,            /* o  : number of ISM separated channels  */
     261             :     Word16 nb_bits_metadata[]     /* o  : number of ISM metadata bits       */
     262             : )
     263             : {
     264             :     ivas_error error;
     265             :     Word16 nchan_transport_ism;
     266             : 
     267             :     /* set ISM parameters */
     268       19680 :     nchan_transport_ism = st_ivas->nchan_ism;
     269       19680 :     move16();
     270       19680 :     *nchan_ism = st_ivas->nchan_ism;
     271       19680 :     move16();
     272             : 
     273             :     /* decode ISM metadata */
     274       19680 :     IF( NE_32( ( error = ivas_ism_metadata_dec_fx( ism_total_brate, *nchan_ism, &nchan_transport_ism, st_ivas->hIsmMetaData, NULL, st_ivas->bfi,
     275             :                                                    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] ) ),
     276             :                IVAS_ERR_OK ) )
     277             :     {
     278           0 :         return error;
     279             :     }
     280             : 
     281       19680 :     return IVAS_ERR_OK;
     282             : }
     283             : 
     284             : 
     285             : /*-------------------------------------------------------------------------*
     286             :  * ivas_osba_render_sf()
     287             :  *
     288             :  * Object + SBA rendering process.
     289             :  *-------------------------------------------------------------------------*/
     290             : 
     291        6000 : ivas_error ivas_osba_render_sf_fx(
     292             :     Decoder_Struct *st_ivas,        /* i/o: IVAS decoder handle                       */
     293             :     const UWord16 nSamplesAsked,    /* i  : number of CLDFB slots requested           */
     294             :     UWord16 *nSamplesRendered,      /* o  : number of CLDFB slots rendered            */
     295             :     UWord16 *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render     */
     296             :     Word32 *p_output[]              /* o  : rendered time signal                      Q11*/
     297             : )
     298             : {
     299             :     Word16 n;
     300             :     Word32 output_ism[MAX_OUTPUT_CHANNELS][L_FRAME48k];
     301             :     Word32 *p_output_ism[MAX_OUTPUT_CHANNELS];
     302             :     ivas_error error;
     303             : 
     304      102000 :     FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
     305             :     {
     306       96000 :         p_output_ism[n] = &output_ism[n][0];
     307             :     }
     308             : 
     309        6000 :     if ( !st_ivas->hDecoderConfig->Opt_tsm )
     310             :     {
     311             :         int16_t tc_offset;
     312        6000 :         tc_offset = st_ivas->hTcBuffer->n_samples_rendered;
     313       24000 :         for ( n = 0; n < st_ivas->nchan_ism; n++ )
     314             :         {
     315       18000 :             v_shr( &p_output[n][tc_offset], Q11 - Q11, &output_ism[n][tc_offset], nSamplesAsked ); // Q11
     316             :         }
     317             :     }
     318             : 
     319        6000 :     IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output ) ), IVAS_ERR_OK ) )
     320             :     {
     321           0 :         return error;
     322             :     }
     323             : 
     324        6000 :     IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
     325             :     {
     326        3000 :         ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output_ism, *nSamplesRendered );
     327             :     }
     328             : 
     329       48000 :     FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     330             :     {
     331       42000 :         IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
     332             :         {
     333             : #ifndef NONBE_1894_OSBA_SCALING
     334             :             v_add_fixed( p_output[n], p_output_ism[n], p_output[n], *nSamplesRendered, 1 ); // takes care of downscaling by 0.5f
     335             : #else
     336       36000 :             v_add_fixed_no_hdrm( p_output[n], p_output_ism[n], p_output[n], *nSamplesRendered );
     337             : #endif
     338             :         }
     339             : #ifndef NONBE_1894_OSBA_SCALING
     340             :         ELSE
     341             :         {
     342             :             scale_sig32( p_output[n], *nSamplesRendered, -1 );
     343             :         }
     344             : #endif
     345             :     }
     346             : 
     347        6000 :     return IVAS_ERR_OK;
     348             : }
     349             : 
     350             : 
     351             : #ifdef NONBE_1894_OSBA_SCALING
     352             : /*-------------------------------------------------------------------------*
     353             :  * ivas_osba_stereo_add_channels()
     354             :  *
     355             :  *
     356             :  *-------------------------------------------------------------------------*/
     357             : 
     358        1400 : void ivas_osba_stereo_add_channels_fx(
     359             :     Word32 *tc_fx[],                  /* i  : transport channels                */
     360             :     Word32 *output_fx[],              /* i/o: output channels                   */
     361             :     const Word16 gain,                /* i  : gain bed value        Q11         */
     362             :     const Word16 nchan_out,           /* i  : number of output channels         */
     363             :     const Word16 nchan_ism,           /* i  : number of ISM channels            */
     364             :     const UWord16 n_samples_to_render /* i  : output frame length per channel   */
     365             : )
     366             : {
     367             :     Word16 n;
     368             : 
     369             : #if 0
     370             :     IF ( ism_mode == ISM_SBA_MODE_DISC )
     371             :     {
     372             : #endif
     373        1400 :     IF( NE_16( gain, ONE_IN_Q11 ) )
     374             :     {
     375           0 :         assert( 0 && "Object editing is not implemented in the BASOP code!" );
     376             :     }
     377             :     ELSE
     378             :     {
     379        4200 :         FOR( n = 0; n < nchan_out; n++ )
     380             :         {
     381        2800 :             v_add_fixed_no_hdrm( output_fx[n], tc_fx[n + nchan_ism], output_fx[n], n_samples_to_render );
     382             :         }
     383             :     }
     384             : #if 0
     385             :     }
     386             :     ELSE
     387             :     {
     388             :         FOR( n = 0; n < nchan_out; n++ )
     389             :         {
     390             :             v_add_fixed_no_hdrm( output_fx[n], tc_fx[n + nchan_ism], output_fx[n], n_samples_to_render );
     391             :         }
     392             :     }
     393             : #endif
     394             : 
     395        1400 :     return;
     396             : }
     397             : #endif

Generated by: LCOV version 1.14