LCOV - code coverage report
Current view: top level - lib_com - ivas_ism_com.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 6c9ddc4024a9c0e1ecb8f643f114a84a0e26ec6b Lines: 213 223 95.5 %
Date: 2025-05-23 08:37:30 Functions: 11 11 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 <stdint.h>
      34             : #include "options.h"
      35             : #include "cnst.h"
      36             : #include "ivas_cnst.h"
      37             : #include "rom_com.h"
      38             : #include "prot.h"
      39             : #include "ivas_prot.h"
      40             : #include "ivas_stat_com.h"
      41             : #include "ivas_rom_com.h"
      42             : #ifdef DEBUGGING
      43             : #include "debug.h"
      44             : #endif
      45             : #include "wmc_auto.h"
      46             : 
      47             : 
      48             : /*-----------------------------------------------------------------------*
      49             :  * Local constants
      50             :  *-----------------------------------------------------------------------*/
      51             : 
      52             : #define BITS_ISM_INACTIVE ( BRATE_ISM_INACTIVE / FRAMES_PER_SEC )
      53             : 
      54             : #define BETA_ISM_LOW_IMP    0.6f
      55             : #define BETA_ISM_MEDIUM_IMP 0.8f
      56             : 
      57             : #define MAX_BRATE_TCX_32k 48000
      58             : 
      59             : 
      60             : /*-------------------------------------------------------------------*
      61             :  * bitbudget_to_brate()
      62             :  *
      63             :  * Convert bit-budget to bitrate
      64             :  *-------------------------------------------------------------------*/
      65             : 
      66     1689788 : void bitbudget_to_brate(
      67             :     const int16_t x[], /* i  : bitbudgets                          */
      68             :     int32_t y[],       /* o  : bitrates                            */
      69             :     const int16_t N    /* i  : number of entries to be converted   */
      70             : )
      71             : {
      72             :     int16_t i;
      73             : 
      74     6041222 :     for ( i = 0; i < N; i++ )
      75             :     {
      76     4351434 :         y[i] = FRAMES_PER_SEC * x[i];
      77             :     }
      78             : 
      79     1689788 :     return;
      80             : }
      81             : 
      82             : 
      83             : /*-------------------------------------------------------------------*
      84             :  * ivas_ism_config()
      85             :  *
      86             :  * Configure audio objects coding
      87             :  *-------------------------------------------------------------------*/
      88             : 
      89      429560 : ivas_error ivas_ism_config(
      90             :     const int32_t ism_total_brate,                     /* i  : ISM total bitrate               */
      91             :     const int16_t nchan_transport,                     /* i  : number of transport channels    */
      92             :     const int16_t nchan_ism,                           /* i  : number of objects               */
      93             :     ISM_METADATA_HANDLE hIsmMeta[],                    /* i/o: ISM metadata handles            */
      94             :     const int16_t ism_extended_metadata_flag,          /* i  : extended metadata flag          */
      95             :     const int16_t null_metadata_flag[MAX_NUM_OBJECTS], /* i  : NULL MD flag                    */
      96             :     const int16_t ism_imp[],                           /* i  : ISM importance flags            */
      97             :     int32_t element_brate[],                           /* o  : element bitrate per object      */
      98             :     int32_t total_brate[],                             /* o  : total bitrate per object        */
      99             :     int16_t nb_bits_metadata[],                        /* i/o: number of metadata bits         */
     100             :     const int16_t combined_format_flag                 /* i  : flag indicating combined format */
     101             : )
     102             : {
     103             :     int16_t ch;
     104             :     int16_t bits_element[MAX_NUM_OBJECTS], bits_CoreCoder[MAX_NUM_OBJECTS];
     105             :     int16_t bits_ism, bits_side;
     106      429560 :     int16_t limit_high = 0; /* just to avoid compilation warning */
     107             :     int16_t tmp;
     108             :     int16_t ism_metadata_flag_global;
     109             :     int16_t n_ISms;
     110             :     ivas_error error;
     111             : 
     112      429560 :     error = IVAS_ERR_OK;
     113      429560 :     if ( combined_format_flag )
     114             :     {
     115       21405 :         n_ISms = nchan_ism;
     116             :     }
     117             :     else
     118             :     {
     119      408155 :         n_ISms = nchan_transport;
     120             :     }
     121             : 
     122             :     /* initialization */
     123      429560 :     ism_metadata_flag_global = 0;
     124      429560 :     bits_side = 0;
     125      429560 :     if ( hIsmMeta != NULL )
     126             :     {
     127     1508829 :         for ( ch = 0; ch < n_ISms; ch++ )
     128             :         {
     129     1086027 :             ism_metadata_flag_global |= ism_imp[ch];
     130             :         }
     131             :     }
     132             : 
     133             :     /* decision about bitrates per channel */
     134      429560 :     if ( combined_format_flag )
     135             :     {
     136             :         /* combined format: decision about bitrates per channel - variable during the session (at one ivas_total_brate) */
     137       21405 :         bits_ism = (int16_t) ( ism_total_brate / FRAMES_PER_SEC );
     138       21405 :         set_s( bits_element, bits_ism / n_ISms, n_ISms );
     139       21405 :         bits_element[n_ISms - 1] += bits_ism % n_ISms;
     140             : 
     141             :         /* ISM common signaling bits are counted in MASA MD bit-budget */
     142             :     }
     143             :     else
     144             :     {
     145             :         /* ISM format: decision about bitrates per channel - constant during the session (at one ivas_total_brate) */
     146      408155 :         bits_ism = (int16_t) ( ism_total_brate / FRAMES_PER_SEC );
     147      408155 :         set_s( bits_element, bits_ism / n_ISms, n_ISms );
     148      408155 :         bits_element[n_ISms - 1] += bits_ism % n_ISms;
     149      408155 :         bitbudget_to_brate( bits_element, element_brate, n_ISms );
     150             : 
     151             :         /* count ISm common signaling bits */
     152      408155 :         if ( hIsmMeta != NULL )
     153             :         {
     154      402276 :             nb_bits_metadata[0] += n_ISms * ISM_METADATA_FLAG_BITS + nchan_ism;
     155             : 
     156      402276 :             if ( ism_total_brate >= ISM_EXTENDED_METADATA_BRATE )
     157             :             {
     158      229787 :                 nb_bits_metadata[0] += ISM_EXTENDED_METADATA_BITS;
     159             : 
     160      229787 :                 if ( ism_extended_metadata_flag )
     161             :                 {
     162       32214 :                     nb_bits_metadata[0] += ISM_METADATA_IS_NDP_BITS;
     163             :                 }
     164             :             }
     165             : 
     166     1446739 :             for ( ch = 0; ch < n_ISms; ch++ )
     167             :             {
     168     1044463 :                 if ( null_metadata_flag[ch] )
     169             :                 {
     170       18680 :                     nb_bits_metadata[0] += ISM_METADATA_MD_FLAG_BITS;
     171       18680 :                     nb_bits_metadata[0] += ISM_METADATA_FLAG_BITS;
     172             :                 }
     173             :                 else
     174             :                 {
     175     1025783 :                     if ( ism_imp[ch] == ISM_NO_META )
     176             :                     {
     177       26208 :                         nb_bits_metadata[0] += ISM_METADATA_MD_FLAG_BITS;
     178       26208 :                         nb_bits_metadata[0] += ISM_METADATA_INACTIVE_FLAG_BITS;
     179             :                     }
     180             :                 }
     181             :             }
     182             :         }
     183             :     }
     184             : 
     185             :     /* split metadata bitbudget equally between channels */
     186      429560 :     if ( nb_bits_metadata != NULL )
     187             :     {
     188      422802 :         bits_side = sum_s( nb_bits_metadata, n_ISms );
     189      422802 :         set_s( nb_bits_metadata, bits_side / n_ISms, n_ISms );
     190      422802 :         nb_bits_metadata[n_ISms - 1] += bits_side % n_ISms;
     191      422802 :         v_sub_s( bits_element, nb_bits_metadata, bits_CoreCoder, n_ISms );
     192      422802 :         bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );
     193             : 
     194      422802 :         mvs2s( nb_bits_metadata, nb_bits_metadata, n_ISms );
     195             :     }
     196             : 
     197             :     /* assign less CoreCoder bit-budget to inactive streams (at least one stream must be active) */
     198      429560 :     if ( ism_metadata_flag_global )
     199             :     {
     200             :         int16_t diff, n_higher, flag_higher[MAX_NUM_OBJECTS];
     201             : 
     202      422094 :         set_s( flag_higher, 1, MAX_NUM_OBJECTS );
     203             : 
     204      422094 :         diff = 0;
     205     1505685 :         for ( ch = 0; ch < n_ISms; ch++ )
     206             :         {
     207     1083591 :             if ( ism_imp[ch] == ISM_NO_META )
     208             :             {
     209       30784 :                 diff += bits_CoreCoder[ch] - BITS_ISM_INACTIVE;
     210       30784 :                 bits_CoreCoder[ch] = BITS_ISM_INACTIVE;
     211       30784 :                 flag_higher[ch] = 0;
     212             :             }
     213             :         }
     214             : 
     215      422094 :         n_higher = sum_s( flag_higher, n_ISms );
     216             : 
     217      422094 :         if ( diff > 0 && n_higher > 0 )
     218             :         {
     219       29148 :             tmp = diff / n_higher;
     220      136826 :             for ( ch = 0; ch < n_ISms; ch++ )
     221             :             {
     222      107678 :                 if ( flag_higher[ch] )
     223             :                 {
     224       76894 :                     bits_CoreCoder[ch] += tmp;
     225             :                 }
     226             :             }
     227             : 
     228       29148 :             tmp = diff % n_higher;
     229       29148 :             ch = 0;
     230       29552 :             while ( flag_higher[ch] == 0 )
     231             :             {
     232         404 :                 ch++;
     233             :             }
     234       29148 :             bits_CoreCoder[ch] += tmp;
     235             :         }
     236             : 
     237      422094 :         bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );
     238             : 
     239      422094 :         diff = 0;
     240     1505685 :         for ( ch = 0; ch < n_ISms; ch++ )
     241             :         {
     242             :             int16_t limit;
     243             : 
     244     1083591 :             limit = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC;
     245     1083591 :             if ( element_brate[ch] < MIN_BRATE_SWB_STEREO ) /* replicate function set_bw() -> check the coded audio band-width */
     246             :             {
     247      114342 :                 limit = MIN_BRATE_WB_BWE / FRAMES_PER_SEC;
     248             :             }
     249      969249 :             else if ( element_brate[ch] >= SCE_CORE_16k_LOW_LIMIT ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */
     250             :             {
     251             :                 /*limit = SCE_CORE_16k_LOW_LIMIT;*/
     252      748800 :                 limit = ( ACELP_16k_LOW_LIMIT + SWB_TBE_1k6 ) / FRAMES_PER_SEC;
     253             :             }
     254             : 
     255     1083591 :             if ( ism_imp[ch] == ISM_NO_META )
     256             :             {
     257       30784 :                 tmp = BITS_ISM_INACTIVE;
     258             :             }
     259     1052807 :             else if ( ism_imp[ch] == ISM_LOW_IMP )
     260             :             {
     261      116863 :                 tmp = (int16_t) ( BETA_ISM_LOW_IMP * bits_CoreCoder[ch] );
     262      116863 :                 tmp = max( limit, tmp );
     263             :             }
     264      935944 :             else if ( ism_imp[ch] == ISM_MEDIUM_IMP )
     265             :             {
     266      297807 :                 tmp = (int16_t) ( BETA_ISM_MEDIUM_IMP * bits_CoreCoder[ch] );
     267      297807 :                 tmp = max( limit, tmp );
     268             :             }
     269             :             else /* ism_imp[ch] == ISM_HIGH_IMP */
     270             :             {
     271      638137 :                 tmp = bits_CoreCoder[ch];
     272             :             }
     273             : 
     274     1083591 :             diff += bits_CoreCoder[ch] - tmp;
     275     1083591 :             bits_CoreCoder[ch] = tmp;
     276             :         }
     277             : 
     278      422094 :         if ( diff > 0 && n_higher > 0 )
     279             :         {
     280      255222 :             tmp = diff / n_higher;
     281      999616 :             for ( ch = 0; ch < n_ISms; ch++ )
     282             :             {
     283      744394 :                 if ( flag_higher[ch] )
     284             :                 {
     285      723011 :                     bits_CoreCoder[ch] += tmp;
     286             :                 }
     287             :             }
     288             : 
     289      255222 :             tmp = diff % n_higher;
     290      255222 :             ch = 0;
     291      255382 :             while ( flag_higher[ch] == 0 )
     292             :             {
     293         160 :                 ch++;
     294             :             }
     295      255222 :             bits_CoreCoder[ch] += tmp;
     296             :         }
     297             : 
     298             :         /* verify for the maximum bitrate @12.8kHz core */
     299      422094 :         diff = 0;
     300     1505685 :         for ( ch = 0; ch < n_ISms; ch++ )
     301             :         {
     302     1083591 :             limit_high = IVAS_512k / FRAMES_PER_SEC;
     303     1083591 :             if ( element_brate[ch] < SCE_CORE_16k_LOW_LIMIT ) /* replicate function set_ACELP_flag() -> it is not intended to switch the ACELP internal sampling rate within an object */
     304             :             {
     305      334791 :                 limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
     306             :             }
     307             : 
     308     1083591 :             tmp = (int16_t) min( bits_CoreCoder[ch], limit_high );
     309             : 
     310     1083591 :             diff += bits_CoreCoder[ch] - tmp;
     311     1083591 :             bits_CoreCoder[ch] = tmp;
     312             :         }
     313             : 
     314             :         /* limitation to avoid too high bitrate in one active TCX channel */
     315      422094 :         if ( element_brate[0] >= SCE_CORE_16k_LOW_LIMIT && element_brate[0] <= IVAS_32k )
     316             :         {
     317       97256 :             diff = 0;
     318       97256 :             limit_high = MAX_BRATE_TCX_32k / FRAMES_PER_SEC;
     319             : 
     320      385804 :             for ( ch = 0; ch < n_ISms; ch++ )
     321             :             {
     322      288548 :                 tmp = (int16_t) min( bits_CoreCoder[ch], limit_high );
     323             : 
     324      288548 :                 diff += bits_CoreCoder[ch] - tmp;
     325      288548 :                 bits_CoreCoder[ch] = tmp;
     326             :             }
     327             :         }
     328             : 
     329      422094 :         if ( diff > 0 )
     330             :         {
     331        2854 :             ch = 0;
     332        7324 :             for ( ch = 0; ch < n_ISms; ch++ )
     333             :             {
     334        7324 :                 if ( flag_higher[ch] == 0 )
     335             :                 {
     336        2854 :                     if ( diff > limit_high )
     337             :                     {
     338           0 :                         diff += bits_CoreCoder[ch] - limit_high;
     339           0 :                         bits_CoreCoder[ch] = limit_high;
     340             :                     }
     341             :                     else
     342             :                     {
     343        2854 :                         bits_CoreCoder[ch] += diff;
     344             : #ifdef DEBUGGING
     345             :                         if ( bits_CoreCoder[ch] == SID_2k40 / FRAMES_PER_SEC )
     346             :                         {
     347             :                             printf( "\nWarning: ISM bitbudget equal to SID!\n" );
     348             :                         }
     349             : #endif
     350             : 
     351        2854 :                         if ( combined_format_flag )
     352             :                         {
     353           0 :                             diff = 0;
     354             :                         }
     355        2854 :                         break;
     356             :                     }
     357             :                 }
     358             :             }
     359             :         }
     360             : 
     361      422094 :         if ( combined_format_flag )
     362             :         {
     363       20526 :             if ( diff > 0 )
     364             :             {
     365           0 :                 for ( ch = 0; ch < n_ISms; ch++ )
     366             :                 {
     367           0 :                     if ( ism_imp[ch] <= ISM_MEDIUM_IMP )
     368             :                     {
     369           0 :                         if ( diff > limit_high )
     370             :                         {
     371           0 :                             diff += bits_CoreCoder[ch] - limit_high;
     372           0 :                             bits_CoreCoder[ch] = limit_high;
     373             :                         }
     374             :                         else
     375             :                         {
     376           0 :                             bits_CoreCoder[ch] += diff;
     377           0 :                             break;
     378             :                         }
     379             :                     }
     380             :                 }
     381             :             }
     382             :         }
     383             : 
     384      422094 :         bitbudget_to_brate( bits_CoreCoder, total_brate, n_ISms );
     385             :     }
     386             : 
     387             : #ifdef DEBUGGING
     388             :     if ( nb_bits_metadata != NULL )
     389             :     {
     390             :         int32_t tmpL;
     391             :         tmpL = sum_l( total_brate, n_ISms ) + bits_side * FRAMES_PER_SEC;
     392             :         if ( ism_total_brate != tmpL )
     393             :         {
     394             :             return IVAS_ERROR( IVAS_ERR_INTERNAL_FATAL, "\nError: Mismatch in ISM bit-budget distribution. Exiting!\n" );
     395             :         }
     396             :     }
     397             : #endif
     398             : 
     399      429560 :     return error;
     400             : }
     401             : 
     402             : 
     403             : /*-------------------------------------------------------------------*
     404             :  * ivas_ism_reset_metadata()
     405             :  *
     406             :  * Reset ISM metadata parameters
     407             :  *-------------------------------------------------------------------*/
     408             : 
     409       25053 : void ivas_ism_reset_metadata(
     410             :     ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle     */
     411             : )
     412             : {
     413       25053 :     hIsmMeta->azimuth = 0.0f;
     414       25053 :     hIsmMeta->elevation = 0.0f;
     415       25053 :     hIsmMeta->yaw = 0.0f;
     416       25053 :     hIsmMeta->pitch = 0.0f;
     417       25053 :     hIsmMeta->radius = 1.0f;
     418       25053 :     hIsmMeta->ism_metadata_flag = 0;
     419       25053 :     hIsmMeta->non_diegetic_flag = 0;
     420             : 
     421       25053 :     hIsmMeta->edited_gain = 1.0f;
     422       25053 :     hIsmMeta->edited_azimuth = 0.0f;
     423       25053 :     hIsmMeta->edited_elevation = 0.0f;
     424       25053 :     hIsmMeta->edited_pitch = 0.0f;
     425       25053 :     hIsmMeta->edited_yaw = 0.0f;
     426       25053 :     hIsmMeta->edited_radius = 1.0f;
     427       25053 :     hIsmMeta->gain = 1.0f;
     428       25053 :     hIsmMeta->non_diegetic_flag = 0;
     429             : 
     430       25053 :     return;
     431             : }
     432             : 
     433             : 
     434             : /*-------------------------------------------------------------------*
     435             :  * ivas_ism_reset_metadata_API()
     436             :  *
     437             :  * Reset ISM metadata parameters
     438             :  *-------------------------------------------------------------------*/
     439             : 
     440        6000 : void ivas_ism_reset_metadata_API(
     441             :     ISM_METADATA_HANDLE hIsmMeta /* i/o: ISM metadata handle     */
     442             : )
     443             : {
     444        6000 :     ivas_ism_reset_metadata( hIsmMeta );
     445             : 
     446        6000 :     return;
     447             : }
     448             : 
     449             : 
     450             : /*-------------------------------------------------------------------*
     451             :  * ism_quant_meta()
     452             :  *
     453             :  * three-level uniform scalar quantizer for ISM metadata
     454             :  *-------------------------------------------------------------------*/
     455             : 
     456             : /*! r: index of the winning codeword */
     457      799655 : int16_t ism_quant_meta(
     458             :     const float val,           /* i  : scalar value to quantize        */
     459             :     float *valQ,               /* o  : quantized value                 */
     460             :     const float borders[],     /* i  : level borders                   */
     461             :     const float q_step,        /* i  : quantization step               */
     462             :     const float q_step_border, /* i  : quantization step at the border */
     463             :     const int16_t cbsize       /* i  : codebook size                   */
     464             : )
     465             : {
     466             :     int16_t idx, idx_start;
     467             :     float qlow, step;
     468             : 
     469      799655 :     if ( val <= borders[1] )
     470             :     {
     471       63486 :         qlow = borders[0];
     472       63486 :         idx_start = 0;
     473       63486 :         step = q_step_border;
     474             :     }
     475      736169 :     else if ( val <= borders[2] )
     476             :     {
     477      665785 :         qlow = borders[1];
     478      665785 :         idx_start = (int16_t) ( ( borders[1] - borders[0] ) / q_step_border );
     479      665785 :         step = q_step;
     480             :     }
     481             :     else
     482             :     {
     483       70384 :         qlow = borders[2];
     484       70384 :         idx_start = (int16_t) ( cbsize - 1 - ( borders[3] - borders[2] ) / q_step_border );
     485       70384 :         step = q_step_border;
     486             :     }
     487             : 
     488      799655 :     idx = idx_start + (int16_t) max( 0.f, min( cbsize - 1, ( ( val - qlow ) / step + 0.5f ) ) );
     489      799655 :     *valQ = ( idx - idx_start ) * step + qlow;
     490             : 
     491      799655 :     return idx;
     492             : }
     493             : 
     494             : 
     495             : /*-------------------------------------------------------------------*
     496             :  * ism_dequant_meta()
     497             :  *
     498             :  * three-level uniform scalar dequantizer for ISM metadata
     499             :  *-------------------------------------------------------------------*/
     500             : 
     501             : /*! r: dequantized value */
     502     2368797 : float ism_dequant_meta(
     503             :     const int16_t idx,         /* i  : quantizer index              */
     504             :     const float borders[],     /* i  : level borders                */
     505             :     const float q_step,        /* i  : quantization step               */
     506             :     const float q_step_border, /* i  : quantization step at the border */
     507             :     const int16_t cbsize       /* i  : codebook size                */
     508             : )
     509             : {
     510             :     int16_t idx_start;
     511             :     float qlow, step, valQ;
     512             : 
     513     2368797 :     if ( idx <= ( borders[1] - borders[0] ) / q_step_border )
     514             :     {
     515      240405 :         qlow = borders[0];
     516      240405 :         idx_start = 0;
     517      240405 :         step = q_step_border;
     518             :     }
     519     2128392 :     else if ( idx <= cbsize - 1 - ( borders[3] - borders[2] ) / q_step_border )
     520             :     {
     521     1965924 :         qlow = borders[1];
     522     1965924 :         idx_start = (int16_t) ( ( borders[1] - borders[0] ) / q_step_border );
     523     1965924 :         step = q_step;
     524             :     }
     525             :     else
     526             :     {
     527      162468 :         qlow = borders[2];
     528      162468 :         idx_start = (int16_t) ( cbsize - 1 - ( borders[3] - borders[2] ) / q_step_border );
     529      162468 :         step = q_step_border;
     530             :     }
     531             : 
     532     2368797 :     valQ = ( idx - idx_start ) * step + qlow;
     533             : 
     534     2368797 :     return valQ;
     535             : }
     536             : 
     537             : 
     538             : /*---------------------------------------------------------------
     539             :  * ivas_param_ism_config()
     540             :  *
     541             :  *
     542             :  * ---------------------------------------------------------------*/
     543             : 
     544        1280 : void ivas_param_ism_config(
     545             :     PARAM_ISM_CONFIG_HANDLE hParamIsm, /* i/o: IVAS Param ISM Config Structure      */
     546             :     const int16_t nchan_obj            /* i  : number of ISM channels               */
     547             : )
     548             : {
     549             :     int16_t i;
     550             : 
     551        1280 :     hParamIsm->nbands = MAX_PARAM_ISM_NBANDS;
     552             : 
     553       15360 :     for ( i = 0; i < hParamIsm->nbands; i++ )
     554             :     {
     555       14080 :         hParamIsm->nblocks[i] = MAX_PARAM_ISM_NBLOCKS;
     556             :     }
     557             : 
     558             :     /* for elevation zero compute the max azi quantization indices */
     559        6084 :     for ( i = 0; i < nchan_obj; i++ )
     560             :     {
     561        4804 :         hParamIsm->last_az_diff[i] = 0;
     562        4804 :         hParamIsm->last_az_sgn[i] = 1;
     563        4804 :         hParamIsm->last_el_diff[i] = 0;
     564        4804 :         hParamIsm->last_el_sgn[i] = 1;
     565             :     }
     566             : 
     567        1280 :     hParamIsm->last_dmx_gain = 1.0f;
     568        1280 :     set_f( hParamIsm->last_cardioid_left, 1.0f, MAX_NUM_OBJECTS );
     569             : 
     570        1280 :     return;
     571             : }
     572             : 
     573             : 
     574             : /*---------------------------------------------------------------
     575             :  * ivas_ism_mode_select()
     576             :  *
     577             :  * selects the ISM mode base on bitrate and number of objects
     578             :  * ---------------------------------------------------------------*/
     579             : 
     580             : /*! r : ISM format mode */
     581     1005709 : ISM_MODE ivas_ism_mode_select(
     582             :     const int16_t nchan_inp,       /* i  : number of input objects  */
     583             :     const int32_t ivas_total_brate /* i  : IVAS total bitrate       */
     584             : )
     585             : {
     586     1005709 :     ISM_MODE ism_mode = ISM_MODE_NONE;
     587             : 
     588     1005709 :     if ( nchan_inp > 2 && ivas_total_brate <= ACELP_32k )
     589             :     {
     590      200224 :         ism_mode = ISM_MODE_PARAM;
     591             :     }
     592             :     else
     593             :     {
     594      805485 :         ism_mode = ISM_MODE_DISC;
     595             :     }
     596             : 
     597     1005709 :     return ism_mode;
     598             : }
     599             : 
     600             : 
     601             : /*---------------------------------------------------------------
     602             :  * ivas_ism_metadata_close()
     603             :  *
     604             :  * Deallocate ISM metadata handles
     605             :  * ---------------------------------------------------------------*/
     606             : 
     607        3048 : void ivas_ism_metadata_close(
     608             :     ISM_METADATA_HANDLE hIsmMetaData[], /* i/o: object metadata handles             */
     609             :     const int16_t first_idx             /* i  : index of first handle to deallocate */
     610             : )
     611             : {
     612             :     int16_t n;
     613             : 
     614        3048 :     if ( hIsmMetaData == NULL || *hIsmMetaData == NULL )
     615             :     {
     616        1939 :         return;
     617             :     }
     618             : 
     619        5545 :     for ( n = first_idx; n < MAX_NUM_OBJECTS; n++ )
     620             :     {
     621        4436 :         if ( hIsmMetaData[n] != NULL )
     622             :         {
     623        3519 :             free( hIsmMetaData[n] );
     624        3519 :             hIsmMetaData[n] = NULL;
     625             :         }
     626             :     }
     627             : 
     628        1109 :     return;
     629             : }
     630             : 
     631             : 
     632             : /*-------------------------------------------------------------------*
     633             :  * update_last_metadata()
     634             :  *
     635             :  * Store last metadata values
     636             :  *-------------------------------------------------------------------*/
     637             : 
     638      524510 : void update_last_metadata(
     639             :     const int16_t nchan_ism,        /* i  : number of objects           */
     640             :     ISM_METADATA_HANDLE hIsmMeta[], /* i/o: ISM metadata handles        */
     641             :     const int16_t updt_flag[]       /* i  : last metadata update flag   */
     642             : )
     643             : {
     644             :     int16_t ch;
     645             : 
     646     2058747 :     for ( ch = 0; ch < nchan_ism; ch++ )
     647             :     {
     648     1534237 :         if ( updt_flag[ch] == 1 )
     649             :         {
     650     1528993 :             hIsmMeta[ch]->last_azimuth = hIsmMeta[ch]->azimuth;
     651     1528993 :             hIsmMeta[ch]->last_elevation = hIsmMeta[ch]->elevation;
     652             :         }
     653             :     }
     654             : 
     655      524510 :     return;
     656             : }
     657             : 
     658             : 
     659             : /*----------------------------------------------------------------*
     660             :  * ivas_get_ism_sid_quan_bitbudget()
     661             :  *
     662             :  * Set quantization bits based on the number of coded objects
     663             :  *----------------------------------------------------------------*/
     664             : 
     665        4664 : void ivas_get_ism_sid_quan_bitbudget(
     666             :     const int16_t nchan_ism,  /* i  : number of objects                 */
     667             :     int16_t *nBits_azimuth,   /* o  : number of Q bits for azimuth      */
     668             :     int16_t *nBits_elevation, /* o  : number of Q bits for elevation    */
     669             :     float *q_step,            /* o  : quantization step                 */
     670             :     float *q_step_border,     /* o  : quantization step at the border   */
     671             :     int16_t *nBits_coh,       /* o  : number of Q bits for coherence    */
     672             :     int16_t *nBits_sce_id     /* o  : number of Q bits for sce_id_dtx   */
     673             : )
     674             : {
     675        4664 :     *nBits_azimuth = ISM_DTX_AZI_BITS_HIGH;
     676        4664 :     *nBits_elevation = ISM_DTX_ELE_BITS_HIGH;
     677        4664 :     *q_step = ISM_Q_STEP_HIGH;
     678        4664 :     *q_step_border = ISM_Q_STEP_BORDER_HIGH;
     679        4664 :     *nBits_coh = ISM_DTX_COH_SCA_BITS;
     680        4664 :     *nBits_sce_id = 1;
     681             : 
     682        4664 :     if ( nchan_ism >= 3 )
     683             :     {
     684        2880 :         *nBits_azimuth = ISM_DTX_AZI_BITS_LOW;
     685        2880 :         *nBits_elevation = ISM_DTX_ELE_BITS_LOW;
     686        2880 :         *q_step = ISM_Q_STEP_LOW;
     687        2880 :         *q_step_border = ISM_Q_STEP_BORDER_LOW;
     688        2880 :         *nBits_sce_id = 2;
     689             :     }
     690             : 
     691        4664 :     return;
     692             : }

Generated by: LCOV version 1.14