LCOV - code coverage report
Current view: top level - lib_dec - ivas_osba_dec_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main @ da9cc8ead0679b4682d329fdff98cf1616159273 Lines: 63 108 58.3 %
Date: 2025-10-13 22:24:20 Functions: 5 6 83.3 %

          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         769 : void ivas_osba_data_close_fx(
      93             :     SBA_ISM_DATA_HANDLE *hSbaIsmData /* i/o: OSBA rendering handle    */
      94             : )
      95             : {
      96             :     Word16 i;
      97             : 
      98         769 :     test();
      99         769 :     IF( hSbaIsmData == NULL || *hSbaIsmData == NULL )
     100             :     {
     101         592 :         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        9250 :     ivas_combined_orientation_set_to_start_index( st_ivas->hCombinedOrientationData );
     164        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 ) )
     165           0 :     {
     166             :         Word16 slot_idx, num_cldfb_bands, b, nchan_transport_orig;
     167             :         Word16 cldfb_slots;
     168             :         Word32 Cldfb_RealBuffer[CLDFB_NO_CHANNELS_MAX];
     169             :         Word32 Cldfb_ImagBuffer[CLDFB_NO_CHANNELS_MAX];
     170           0 :         Word16 q_cldfb, q_in = 11;
     171           0 :         move16();
     172             : 
     173           0 :         num_cldfb_bands = st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[0]->no_channels;
     174           0 :         move16();
     175           0 :         nchan_transport_orig = st_ivas->nchan_transport;
     176           0 :         move16();
     177           0 :         st_ivas->nchan_transport = st_ivas->nchan_ism;
     178           0 :         move16();
     179           0 :         IF( ( error = ivas_td_binaural_renderer_sf_splitBinaural( st_ivas, output_fx, *nSamplesRendered ) ) != IVAS_ERR_OK )
     180             :         {
     181           0 :             return error;
     182             :         }
     183           0 :         st_ivas->nchan_transport = nchan_transport_orig;
     184           0 :         move16();
     185           0 :         cldfb_slots = *nSamplesRendered / num_cldfb_bands;
     186             : 
     187           0 :         FOR( n = 0; n < i_mult( st_ivas->hSplitBinRend->splitrend.multiBinPoseData.num_poses, BINAURAL_CHANNELS ); ++n )
     188             :         {
     189           0 :             q_cldfb = q_in;
     190           0 :             Scale_sig32( st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->cldfb_state_fx,
     191           0 :                          sub( st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->p_filter_length, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->no_channels ),
     192           0 :                          sub( q_cldfb, st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->Q_cldfb_state ) );
     193           0 :             st_ivas->hSplitBinRend->splitrend.hCldfbHandles->cldfbAna[n]->Q_cldfb_state = q_cldfb;
     194           0 :             FOR( slot_idx = 0; slot_idx < cldfb_slots; slot_idx++ )
     195             :             {
     196           0 :                 q_cldfb = q_in;
     197           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 );
     198             : 
     199           0 :                 Scale_sig32( Cldfb_RealBuffer, num_cldfb_bands, sub( Q6, q_cldfb ) );
     200           0 :                 Scale_sig32( Cldfb_ImagBuffer, num_cldfb_bands, sub( Q6, q_cldfb ) );
     201           0 :                 FOR( b = 0; b < num_cldfb_bands; b++ )
     202             :                 {
     203           0 :                     st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[n][slot_idx_start + slot_idx][b] =
     204           0 :                         L_add( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_RealBuffer_Binaural_fx[n][add( slot_idx_start, slot_idx )][b], Cldfb_RealBuffer[b] );
     205           0 :                     move32();
     206             : 
     207           0 :                     st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[n][slot_idx_start + slot_idx][b] =
     208           0 :                         L_add( st_ivas->hSplitBinRend->hMultiBinCldfbData->Cldfb_ImagBuffer_Binaural_fx[n][add( slot_idx_start, slot_idx )][b], Cldfb_ImagBuffer[b] );
     209           0 :                     move32();
     210             :                 }
     211             :             }
     212             :         }
     213             :     }
     214             :     else
     215             :     {
     216        9250 :         IF( NE_32( ( error = ivas_td_binaural_renderer_sf_fx( st_ivas, p_sepobj_fx, *nSamplesRendered ) ), IVAS_ERR_OK ) )
     217             :         {
     218           0 :             return error;
     219             :         }
     220             : 
     221       27750 :         FOR( n = 0; n < BINAURAL_CHANNELS; n++ )
     222             :         {
     223             :             Word16 i;
     224    16522100 :             FOR( i = 0; i < nSamplesAsked; i++ )
     225             :             {
     226    16503600 :                 output_fx[n][i] = L_add( output_fx[channel_offset + n][i], p_sepobj_fx[n][i] );
     227    16503600 :                 move32();
     228             :             }
     229             :         }
     230             :     }
     231        9250 :     return IVAS_ERR_OK;
     232             : }
     233             : 
     234             : 
     235             : /*-------------------------------------------------------------------------*
     236             :  * ivas_osba_ism_metadata_dec()
     237             :  *
     238             :  * ISM metadata decoding in OSBA format.
     239             :  *-------------------------------------------------------------------------*/
     240             : 
     241       19680 : ivas_error ivas_osba_ism_metadata_dec_fx(
     242             :     Decoder_Struct *st_ivas,      /* i/o: IVAS decoder structure            */
     243             :     const Word32 ism_total_brate, /* i  : ISM total bitrate                 */
     244             :     Word16 *nchan_ism,            /* o  : number of ISM separated channels  */
     245             :     Word16 nb_bits_metadata[]     /* o  : number of ISM metadata bits       */
     246             : )
     247             : {
     248             :     ivas_error error;
     249             :     Word16 nchan_transport_ism;
     250             : 
     251             :     /* set ISM parameters */
     252       19680 :     nchan_transport_ism = st_ivas->nchan_ism;
     253       19680 :     move16();
     254       19680 :     *nchan_ism = st_ivas->nchan_ism;
     255       19680 :     move16();
     256             : 
     257             :     /* decode ISM metadata */
     258       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,
     259             :                                                    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] ) ),
     260             :                IVAS_ERR_OK ) )
     261             :     {
     262           0 :         return error;
     263             :     }
     264             : 
     265       19680 :     return IVAS_ERR_OK;
     266             : }
     267             : 
     268             : 
     269             : /*-------------------------------------------------------------------------*
     270             :  * ivas_osba_render_sf()
     271             :  *
     272             :  * Object + SBA rendering process.
     273             :  *-------------------------------------------------------------------------*/
     274             : 
     275        6000 : ivas_error ivas_osba_render_sf_fx(
     276             :     Decoder_Struct *st_ivas,        /* i/o: IVAS decoder handle                       */
     277             :     const UWord16 nSamplesAsked,    /* i  : number of CLDFB slots requested           */
     278             :     UWord16 *nSamplesRendered,      /* o  : number of CLDFB slots rendered            */
     279             :     UWord16 *nSamplesAvailableNext, /* o  : number of CLDFB slots still to render     */
     280             :     Word32 *p_output[]              /* o  : rendered time signal                      Q11*/
     281             : )
     282             : {
     283             :     Word16 n;
     284             :     Word32 output_ism[MAX_OUTPUT_CHANNELS][L_FRAME48k];
     285             :     Word32 *p_output_ism[MAX_OUTPUT_CHANNELS];
     286             :     ivas_error error;
     287             : 
     288      102000 :     FOR( n = 0; n < MAX_OUTPUT_CHANNELS; n++ )
     289             :     {
     290       96000 :         p_output_ism[n] = &output_ism[n][0];
     291             :     }
     292             : 
     293        6000 :     if ( !st_ivas->hDecoderConfig->Opt_tsm )
     294             :     {
     295             :         int16_t tc_offset;
     296        6000 :         tc_offset = st_ivas->hTcBuffer->n_samples_rendered;
     297       24000 :         for ( n = 0; n < st_ivas->nchan_ism; n++ )
     298             :         {
     299       18000 :             v_shr( &p_output[n][tc_offset], Q11 - Q11, &output_ism[n][tc_offset], nSamplesAsked ); // Q11
     300             :         }
     301             :     }
     302             : 
     303        6000 :     IF( NE_32( ( error = ivas_sba_dec_render_fx( st_ivas, nSamplesAsked, nSamplesRendered, nSamplesAvailableNext, p_output ) ), IVAS_ERR_OK ) )
     304             :     {
     305           0 :         return error;
     306             :     }
     307             : 
     308        6000 :     IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
     309             :     {
     310        3000 :         ivas_ism_render_sf_fx( st_ivas, st_ivas->renderer_type, p_output_ism, *nSamplesRendered );
     311             :     }
     312             : 
     313       48000 :     FOR( n = 0; n < st_ivas->hDecoderConfig->nchan_out; n++ )
     314             :     {
     315       42000 :         IF( NE_32( st_ivas->renderer_type, RENDERER_BINAURAL_FASTCONV_ROOM ) )
     316             :         {
     317       36000 :             v_add_fixed_no_hdrm( p_output[n], p_output_ism[n], p_output[n], *nSamplesRendered );
     318             :         }
     319             :     }
     320             : 
     321        6000 :     return IVAS_ERR_OK;
     322             : }
     323             : 
     324             : 
     325             : /*-------------------------------------------------------------------------*
     326             :  * ivas_osba_stereo_add_channels()
     327             :  *
     328             :  *
     329             :  *-------------------------------------------------------------------------*/
     330             : 
     331           0 : void ivas_osba_stereo_add_channels_fx(
     332             :     Word32 *tc_fx[],                  /* i  : transport channels                */
     333             :     Word32 *output_fx[],              /* i/o: output channels                   */
     334             :     const Word16 gain,                /* i  : gain bed value        Q11         */
     335             :     const Word16 nchan_out,           /* i  : number of output channels         */
     336             :     const Word16 nchan_ism,           /* i  : number of ISM channels            */
     337             :     const UWord16 n_samples_to_render /* i  : output frame length per channel   */
     338             : )
     339             : {
     340             :     Word16 n;
     341             : 
     342             : #if 0
     343             :     IF ( ism_mode == ISM_SBA_MODE_DISC )
     344             :     {
     345             : #endif
     346           0 :     IF( NE_16( gain, ONE_IN_Q11 ) )
     347             :     {
     348           0 :         assert( 0 && "Object editing is not implemented in the BASOP code!" );
     349             :     }
     350             :     ELSE
     351             :     {
     352           0 :         FOR( n = 0; n < nchan_out; n++ )
     353             :         {
     354           0 :             v_add_fixed_no_hdrm( output_fx[n], tc_fx[n + nchan_ism], output_fx[n], n_samples_to_render );
     355             :         }
     356             :     }
     357             : #if 0
     358             :     }
     359             :     ELSE
     360             :     {
     361             :         FOR( n = 0; n < nchan_out; n++ )
     362             :         {
     363             :             v_add_fixed_no_hdrm( output_fx[n], tc_fx[n + nchan_ism], output_fx[n], n_samples_to_render );
     364             :         }
     365             :     }
     366             : #endif
     367             : 
     368           0 :     return;
     369             : }

Generated by: LCOV version 1.14