LCOV - code coverage report
Current view: top level - lib_rend - ivas_hrtf.c (source / functions) Hit Total Coverage
Test: Coverage on main -- conformance test test_26252.py @ efe53129c9ed87a5067dd0a8fb9dca41db9c4add Lines: 130 142 91.5 %
Date: 2026-02-12 06:30:15 Functions: 15 15 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2026 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 <stdint.h>
      34             : #include "options.h"
      35             : #include "prot.h"
      36             : #include "ivas_prot_rend.h"
      37             : #include "ivas_error.h"
      38             : #include "wmc_auto.h"
      39             : #include "ivas_prot.h"
      40             : 
      41             : 
      42             : /*-----------------------------------------------------------------------*
      43             :  * ivas_HRTF_td_binary_open()
      44             :  *
      45             :  * Allocate HRTF binary handle for TD renderer
      46             :  *-----------------------------------------------------------------------*/
      47             : 
      48         162 : ivas_error ivas_HRTF_td_binary_open(
      49             :     TDREND_HRFILT_FiltSet_t **hHrtfTD )
      50             : {
      51             :     /* Allocate HR filter set for headphones configuration */
      52         162 :     *hHrtfTD = (TDREND_HRFILT_FiltSet_t *) malloc( sizeof( TDREND_HRFILT_FiltSet_t ) );
      53         162 :     if ( *hHrtfTD == NULL )
      54             :     {
      55           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary!" );
      56             :     }
      57             : 
      58         162 :     set_c( (int8_t *) ( *hHrtfTD ), 0, (int32_t) sizeof( TDREND_HRFILT_FiltSet_t ) );
      59             : 
      60         162 :     return IVAS_ERR_OK;
      61             : }
      62             : 
      63             : 
      64             : /*-------------------------------------------------------------------*
      65             :  * ivas_HRTF_binary_close()
      66             :  *
      67             :  * Close HRTF binary handle for TD renderer
      68             :  *-------------------------------------------------------------------*/
      69             : 
      70        3017 : void ivas_HRTF_td_binary_close(
      71             :     TDREND_HRFILT_FiltSet_t **hHrtfTD )
      72             : {
      73        3017 :     if ( hHrtfTD == NULL || *hHrtfTD == NULL )
      74             :     {
      75        2855 :         return;
      76             :     }
      77             : 
      78             :     int16_t i;
      79             : 
      80         162 :     if ( ( *hHrtfTD )->ModelParams.modelROM )
      81             :     {
      82           0 :         BSplineModelEvalDealloc( &( *hHrtfTD )->ModelParams, &( *hHrtfTD )->ModelEval );
      83             :     }
      84             :     else
      85             :     {
      86         162 :         if ( ( *hHrtfTD )->ModelParams.UseItdModel )
      87             :         {
      88         162 :             free( ( *hHrtfTD )->ModelParamsITD.elevKSeq_dyn );
      89         162 :             free( ( *hHrtfTD )->ModelParamsITD.azimKSeq_dyn );
      90         162 :             free( ( *hHrtfTD )->ModelParamsITD.W_dyn );
      91         162 :             free( ( *hHrtfTD )->ModelParamsITD.azimBsShape_dyn );
      92         162 :             free( ( *hHrtfTD )->ModelParamsITD.elevBsShape_dyn );
      93         162 :             free( ( *hHrtfTD )->ModelParamsITD.azimBsLen_dyn );
      94         162 :             free( ( *hHrtfTD )->ModelParamsITD.azimBsStart_dyn );
      95         162 :             free( ( *hHrtfTD )->ModelParamsITD.elevBsLen_dyn );
      96         162 :             free( ( *hHrtfTD )->ModelParamsITD.elevBsStart_dyn );
      97             :         }
      98         162 :         free( ( *hHrtfTD )->ModelParams.elevKSeq_dyn );
      99         162 :         free( ( *hHrtfTD )->ModelParams.azim_start_idx_dyn );
     100         162 :         free( ( *hHrtfTD )->ModelParams.azimDim3_dyn );
     101         162 :         free( ( *hHrtfTD )->ModelParams.AlphaL_dyn );
     102         162 :         free( ( *hHrtfTD )->ModelParams.AlphaR_dyn );
     103         162 :         free( ( *hHrtfTD )->ModelParams.azimSegSamples_dyn );
     104             : 
     105         162 :         free( ( *hHrtfTD )->ModelParams.azimShapeIdx_dyn );
     106         162 :         free( ( *hHrtfTD )->ModelParams.azimShapeSampFactor_dyn );
     107         162 :         free( ( *hHrtfTD )->ModelParams.elevBsLen_dyn );
     108         162 :         free( ( *hHrtfTD )->ModelParams.elevBsStart_dyn );
     109         162 :         free( ( *hHrtfTD )->ModelParams.elevBsShape_dyn );
     110             : 
     111         324 :         for ( i = 0; i < ( *hHrtfTD )->ModelParams.num_unique_azim_splines; i++ )
     112             :         {
     113         162 :             free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn[i] );
     114             :         }
     115         162 :         free( ( *hHrtfTD )->ModelParams.azimBsShape_dyn );
     116             : 
     117         162 :         free( (void *) ( *hHrtfTD )->ModelParams.azimBsShape ); /* void* cast needed to please both gcc and Visual studio compilers. Deallocating const float** should be fine and gcc agrees, but Visual studio complains. */
     118        2592 :         for ( i = 0; i < ( *hHrtfTD )->ModelParams.elevDim3; i++ )
     119             :         {
     120        2430 :             free( ( *hHrtfTD )->ModelParams.azimKSeq[i] );
     121             :         }
     122         162 :         free( ( *hHrtfTD )->ModelParams.azimKSeq );
     123             : 
     124         162 :         free( ( *hHrtfTD )->ModelParams.EL_dyn );
     125         162 :         free( ( *hHrtfTD )->ModelParams.ER_dyn );
     126             : 
     127         162 :         free( ( *hHrtfTD )->ModelEval.hrfModL );
     128         162 :         free( ( *hHrtfTD )->ModelEval.hrfModR );
     129             :     }
     130             : 
     131         162 :     free( *hHrtfTD );
     132         162 :     *hHrtfTD = NULL;
     133             : 
     134         162 :     return;
     135             : }
     136             : 
     137             : /*-----------------------------------------------------------------------*
     138             :  * ivas_HRTF_CRend_binary_open()
     139             :  *
     140             :  * Allocate HRTF binary handle for Crend renderer
     141             :  *-----------------------------------------------------------------------*/
     142             : 
     143          28 : ivas_error ivas_HRTF_CRend_binary_open(
     144             :     HRTFS_CREND_DATA **hHrtfCrend )
     145             : {
     146             :     ivas_error error;
     147             : 
     148          28 :     if ( ( *hHrtfCrend = (HRTFS_CREND_HANDLE) malloc( sizeof( HRTFS_CREND_DATA ) ) ) == NULL )
     149             :     {
     150           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for Crend HRTFS Handle\n" );
     151             :     }
     152             : 
     153          28 :     if ( ( error = ivas_Crend_hrtf_init( *hHrtfCrend ) ) != IVAS_ERR_OK )
     154             :     {
     155           0 :         return error;
     156             :     }
     157             : 
     158          28 :     return IVAS_ERR_OK;
     159             : }
     160             : 
     161             : 
     162             : /*-----------------------------------------------------------------------*
     163             :  * ivas_HRTF_binary_open_buffers_int16()
     164             :  *
     165             :  * Allocate buffer with dynamic length for HRTF binary tables
     166             :  *-----------------------------------------------------------------------*/
     167             : 
     168        1782 : ivas_error ivas_HRTF_binary_open_buffers_int16(
     169             :     int16_t **buffer,       /* o  : buffer to allocate      */
     170             :     const uint32_t mem_size /* i  : size of buffer          */
     171             : )
     172             : {
     173        1782 :     *buffer = (int16_t *) malloc( mem_size );
     174             : 
     175        1782 :     if ( *buffer == NULL )
     176             :     {
     177           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" );
     178             :     }
     179             : 
     180        1782 :     return IVAS_ERR_OK;
     181             : }
     182             : 
     183             : 
     184             : /*-----------------------------------------------------------------------*
     185             :  * ivas_HRTF_binary_open_buffers_uint16()
     186             :  *
     187             :  * Allocate buffer with dynamic length for HRTF binary tables
     188             :  *-----------------------------------------------------------------------*/
     189             : 
     190         880 : ivas_error ivas_HRTF_binary_open_buffers_uint16(
     191             :     uint16_t **buffer,      /* o  : buffer to allocate      */
     192             :     const uint32_t mem_size /* i  : size of buffer          */
     193             : )
     194             : {
     195         880 :     *buffer = (uint16_t *) malloc( mem_size );
     196             : 
     197         880 :     if ( *buffer == NULL )
     198             :     {
     199           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" );
     200             :     }
     201             : 
     202         880 :     return IVAS_ERR_OK;
     203             : }
     204             : 
     205             : 
     206             : /*-----------------------------------------------------------------------*
     207             :  * ivas_HRTF_binary_open_buffers_float()
     208             :  *
     209             :  * Allocate buffer with dynamic length for HRTF binary tables
     210             :  *-----------------------------------------------------------------------*/
     211             : 
     212        6467 : ivas_error ivas_HRTF_binary_open_buffers_float(
     213             :     float **buffer,         /* o  : buffer to allocate      */
     214             :     const uint32_t mem_size /* i  : size of buffer          */
     215             : )
     216             : {
     217        6467 :     *buffer = (float *) malloc( mem_size );
     218             : 
     219        6467 :     if ( *buffer == NULL )
     220             :     {
     221           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" );
     222             :     }
     223             : 
     224        6467 :     return IVAS_ERR_OK;
     225             : }
     226             : 
     227             : 
     228             : /*-----------------------------------------------------------------------*
     229             :  * ivas_HRTF_binary_open_buffers_float_ptr()
     230             :  *
     231             :  * Allocate buffer with dynamic length for HRTF binary tables
     232             :  *-----------------------------------------------------------------------*/
     233             : 
     234         324 : ivas_error ivas_HRTF_binary_open_buffers_float_ptr(
     235             :     float ***buffer,        /* o  : buffer to allocate      */
     236             :     const uint32_t mem_size /* i  : size of buffer          */
     237             : )
     238             : {
     239         324 :     *buffer = (float **) malloc( mem_size );
     240             : 
     241         324 :     if ( *buffer == NULL )
     242             :     {
     243           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" );
     244             :     }
     245             : 
     246         324 :     return IVAS_ERR_OK;
     247             : }
     248             : 
     249             : 
     250             : /*-----------------------------------------------------------------------*
     251             :  * ivas_HRTF_binary_open_buffers_float_ptr()
     252             :  *
     253             :  * Allocate buffer with dynamic length for HRTF binary tables
     254             :  *-----------------------------------------------------------------------*/
     255             : 
     256         162 : ivas_error ivas_HRTF_binary_open_buffers_float_ptr_const(
     257             :     const float ***buffer,  /* o  : buffer to allocate      */
     258             :     const uint32_t mem_size /* i  : size of buffer          */
     259             : )
     260             : {
     261         162 :     *buffer = (const float **) malloc( mem_size );
     262             : 
     263         162 :     if ( *buffer == NULL )
     264             :     {
     265           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for HRTF binary data\n" );
     266             :     }
     267             : 
     268         162 :     return IVAS_ERR_OK;
     269             : }
     270             : 
     271             : 
     272             : /*-------------------------------------------------------------------*
     273             :  * ivas_HRTF_CRend_binary_close()
     274             :  *
     275             :  * Close HRTF CRend binary handle for Crend renderer
     276             :  *-------------------------------------------------------------------*/
     277             : 
     278        2997 : void ivas_HRTF_CRend_binary_close(
     279             :     HRTFS_CREND_DATA **hHrtfCrend )
     280             : {
     281             :     uint16_t i, j;
     282             : 
     283        2997 :     if ( *hHrtfCrend == NULL || hHrtfCrend == NULL )
     284             :     {
     285        2969 :         return;
     286             :     }
     287             : 
     288         476 :     for ( i = 0; i < MAX_INTERN_CHANNELS; i++ )
     289             :     {
     290        1344 :         for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     291             :         {
     292         896 :             if ( ( *hHrtfCrend )->pIndex_frequency_max[i][j] != NULL )
     293             :             {
     294         840 :                 free( ( *hHrtfCrend )->pIndex_frequency_max_dyn[i][j] );
     295             :             }
     296         896 :             if ( ( *hHrtfCrend )->pOut_to_bin_re[i][j] != NULL )
     297             :             {
     298         840 :                 free( ( *hHrtfCrend )->pOut_to_bin_re_dyn[i][j] );
     299             :             }
     300         896 :             if ( ( *hHrtfCrend )->pOut_to_bin_im[i][j] != NULL )
     301             :             {
     302         840 :                 free( ( *hHrtfCrend )->pOut_to_bin_im_dyn[i][j] );
     303             :             }
     304             :         }
     305             :     }
     306          84 :     for ( j = 0; j < BINAURAL_CHANNELS; j++ )
     307             :     {
     308          56 :         if ( ( *hHrtfCrend )->pIndex_frequency_max_diffuse[j] != NULL )
     309             :         {
     310          40 :             free( ( *hHrtfCrend )->pIndex_frequency_max_diffuse_dyn[j] );
     311             :         }
     312          56 :         if ( ( *hHrtfCrend )->pOut_to_bin_diffuse_re[j] != NULL )
     313             :         {
     314          40 :             free( ( *hHrtfCrend )->pOut_to_bin_diffuse_re_dyn[j] );
     315             :         }
     316          56 :         if ( ( *hHrtfCrend )->pOut_to_bin_diffuse_im[j] != NULL )
     317             :         {
     318          40 :             free( ( *hHrtfCrend )->pOut_to_bin_diffuse_im_dyn[j] );
     319             :         }
     320             :     }
     321             : 
     322          28 :     free( *hHrtfCrend );
     323          28 :     *hHrtfCrend = NULL;
     324             : 
     325          28 :     return;
     326             : }
     327             : 
     328             : 
     329             : /*-----------------------------------------------------------------------*
     330             :  * ivas_HRTF_fastconv_binary_open()
     331             :  *
     332             :  * Allocate HRTF binary handle for FASTCONV renderer
     333             :  *-----------------------------------------------------------------------*/
     334             : 
     335          68 : ivas_error ivas_HRTF_fastconv_binary_open(
     336             :     HRTFS_FASTCONV **hHrtfFastConv )
     337             : {
     338          68 :     *hHrtfFastConv = (HRTFS_FASTCONV *) malloc( sizeof( HRTFS_FASTCONV ) );
     339          68 :     if ( *hHrtfFastConv == NULL )
     340             :     {
     341           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FASTCONV HRTF tables!" );
     342             :     }
     343             : 
     344          68 :     ivas_init_binaural_hrtf( *hHrtfFastConv );
     345             : 
     346          68 :     return IVAS_ERR_OK;
     347             : }
     348             : 
     349             : 
     350             : /*-----------------------------------------------------------------------*
     351             :  * ivas_HRTF_fastconv_binary_close()
     352             :  *
     353             :  * Close HRTF binary handle for FASTCONV renderer
     354             :  *-----------------------------------------------------------------------*/
     355             : 
     356        2955 : void ivas_HRTF_fastconv_binary_close(
     357             :     HRTFS_FASTCONV **hHrtfFastConv )
     358             : {
     359        2955 :     if ( hHrtfFastConv == NULL || *hHrtfFastConv == NULL )
     360             :     {
     361        2513 :         return;
     362             :     }
     363             : 
     364             :     /* Fastconv HRTF memories */
     365         442 :     ivas_binaural_hrtf_close( hHrtfFastConv );
     366             : 
     367         442 :     free( *hHrtfFastConv );
     368         442 :     *hHrtfFastConv = NULL;
     369             : 
     370         442 :     return;
     371             : }
     372             : 
     373             : 
     374             : /*-----------------------------------------------------------------------*
     375             :  * ivas_HRTF_parambin_binary_open()
     376             :  *
     377             :  * Allocate HRTF binary handle for parametric binauralizer
     378             :  *-----------------------------------------------------------------------*/
     379             : 
     380          90 : ivas_error ivas_HRTF_parambin_binary_open(
     381             :     HRTFS_PARAMBIN **hHrtfParambin )
     382             : {
     383          90 :     *hHrtfParambin = (HRTFS_PARAMBIN *) malloc( sizeof( HRTFS_PARAMBIN ) );
     384          90 :     if ( *hHrtfParambin == NULL )
     385             :     {
     386           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for parametric binauralizer HRTF tables!" );
     387             :     }
     388             : 
     389          90 :     set_c( (int8_t *) ( *hHrtfParambin ), 0, (int32_t) sizeof( HRTFS_PARAMBIN ) );
     390             : 
     391          90 :     return IVAS_ERR_OK;
     392             : }
     393             : 
     394             : 
     395             : /*-----------------------------------------------------------------------*
     396             :  * ivas_HRTF_parambin_binary_close()
     397             :  *
     398             :  * Close HRTF binary handle for parametric binauralizer
     399             :  *-----------------------------------------------------------------------*/
     400             : 
     401        2949 : void ivas_HRTF_parambin_binary_close(
     402             :     HRTFS_PARAMBIN **hHrtfParambin )
     403             : {
     404        2949 :     if ( hHrtfParambin == NULL || *hHrtfParambin == NULL )
     405             :     {
     406        2096 :         return;
     407             :     }
     408             : 
     409         853 :     free( *hHrtfParambin );
     410         853 :     *hHrtfParambin = NULL;
     411             : 
     412         853 :     return;
     413             : }
     414             : 
     415             : /*-----------------------------------------------------------------------*
     416             :  * ivas_HRTF_statistics_binary_open()
     417             :  *
     418             :  * Allocate HRTF binary handle for statistics handler
     419             :  *-----------------------------------------------------------------------*/
     420             : 
     421           3 : ivas_error ivas_HRTF_statistics_binary_open(
     422             :     HRTFS_STATISTICS **hHrtfStatistics )
     423             : {
     424           3 :     *hHrtfStatistics = (HRTFS_STATISTICS *) malloc( sizeof( HRTFS_STATISTICS ) );
     425           3 :     if ( *hHrtfStatistics == NULL )
     426             :     {
     427           0 :         return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for statistics HRTF tables!" );
     428             :     }
     429             : 
     430           3 :     set_c( (int8_t *) ( *hHrtfStatistics ), 0, (int32_t) sizeof( HRTFS_STATISTICS ) );
     431             : 
     432           3 :     return IVAS_ERR_OK;
     433             : }
     434             : 
     435             : 
     436             : /*-----------------------------------------------------------------------*
     437             :  * ivas_HRTF_statistics_close()
     438             :  *
     439             :  * Close HRTF binary handle for statistics handler
     440             :  *-----------------------------------------------------------------------*/
     441             : 
     442        2595 : void ivas_HRTF_statistics_binary_close(
     443             :     HRTFS_STATISTICS **hHrtfStatistics )
     444             : {
     445        2595 :     if ( hHrtfStatistics == NULL || *hHrtfStatistics == NULL )
     446             :     {
     447        2368 :         return;
     448             :     }
     449             : 
     450         227 :     if ( ( hHrtfStatistics != NULL ) && ( *hHrtfStatistics != NULL ) && ( ( *hHrtfStatistics )->fromROM == FALSE ) )
     451             :     {
     452           3 :         if ( ( *hHrtfStatistics )->average_energy_l_dyn != NULL )
     453             :         {
     454           3 :             free( ( *hHrtfStatistics )->average_energy_l_dyn );
     455             :         }
     456           3 :         if ( ( *hHrtfStatistics )->average_energy_r_dyn != NULL )
     457             :         {
     458           3 :             free( ( *hHrtfStatistics )->average_energy_r_dyn );
     459             :         }
     460           3 :         if ( ( *hHrtfStatistics )->inter_aural_coherence_dyn != NULL )
     461             :         {
     462           3 :             free( ( *hHrtfStatistics )->inter_aural_coherence_dyn );
     463             :         }
     464             :     }
     465             : 
     466         227 :     free( *hHrtfStatistics );
     467         227 :     *hHrtfStatistics = NULL;
     468             : 
     469         227 :     return;
     470             : }

Generated by: LCOV version 1.14