LCOV - code coverage report
Current view: top level - lib_com - ivas_omasa_com.c (source / functions) Hit Total Coverage
Test: Coverage on main -- short test vectors @ 867217ee32c8e8cd2cf5aae69e60c58e00160b49 Lines: 176 183 96.2 %
Date: 2025-12-13 06:47:12 Functions: 8 8 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 "ivas_prot.h"
      37             : #include "prot.h"
      38             : #include "ivas_rom_com.h"
      39             : #include <math.h>
      40             : #ifdef DEBUGGING
      41             : #include "debug.h"
      42             : #endif
      43             : 
      44             : /*---------------------------------------------------------------
      45             :  * Local constants
      46             :  *---------------------------------------------------------------*/
      47             : 
      48             : #define GAMMA_ISM_LOW_IMP    0.8f
      49             : #define GAMMA_ISM_MEDIUM_IMP 1.2f
      50             : #define GAMMA_ISM_HIGH_IMP   1.4f
      51             : 
      52             : #define GAMMA_ISM_LOW_IMP2    0.9f
      53             : #define GAMMA_ISM_MEDIUM_IMP2 1.2f
      54             : #define GAMMA_ISM_HIGH_IMP2   1.35f
      55             : 
      56             : #define GAMMA_ISM_LOW_IMP3    0.85f
      57             : #define GAMMA_ISM_MEDIUM_IMP3 1.15f
      58             : #define GAMMA_ISM_HIGH_IMP3   1.3f
      59             : 
      60             : #define GAMMA_ISM_LOW_IMP4    0.8f
      61             : #define GAMMA_ISM_MEDIUM_IMP4 1.0f
      62             : #define GAMMA_ISM_HIGH_IMP4   1.2f
      63             : 
      64             : #define PAN_MAX_DEG           30.0f
      65             : #define ONE_OVER_PAN_STEP_DEG 10.0f
      66             : #define SIN_LS_ANGLE          0.5f /* sinf( 30.0f * PI_OVER_180 ) */
      67             : 
      68             : 
      69             : /*---------------------------------------------------------------
      70             :  * ivas_omasa_ism_mode_select()
      71             :  *
      72             :  * selects the ISM mode base on IVAS total bit-rate and
      73             :  * the number of objects in the combined ISM MASA format mode
      74             :  * ---------------------------------------------------------------*/
      75             : 
      76             : /*! r : ISM format mode */
      77     1155262 : ISM_MODE ivas_omasa_ism_mode_select(
      78             :     const int32_t ivas_total_brate, /* i  : IVAS total bitrate      */
      79             :     const int16_t nchan_ism         /* i  : number of input ISM's   */
      80             : )
      81             : {
      82     1155262 :     ISM_MODE ism_mode = ISM_MODE_NONE;
      83             : 
      84     1155262 :     switch ( nchan_ism )
      85             :     {
      86      285680 :         case 1:
      87      285680 :             if ( ivas_total_brate >= IVAS_24k4 )
      88             :             {
      89      274439 :                 ism_mode = ISM_MASA_MODE_DISC;
      90             :             }
      91             :             else
      92             :             {
      93       11241 :                 ism_mode = ISM_MODE_NONE;
      94             :             }
      95      285680 :             break;
      96      218576 :         case 2:
      97      218576 :             if ( ivas_total_brate >= IVAS_48k )
      98             :             {
      99      183434 :                 ism_mode = ISM_MASA_MODE_DISC;
     100             :             }
     101       35142 :             else if ( ivas_total_brate >= IVAS_32k )
     102             :             {
     103       30834 :                 ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ;
     104             :             }
     105             :             else
     106             :             {
     107        4308 :                 ism_mode = ISM_MODE_NONE;
     108             :             }
     109      218576 :             break;
     110      260886 :         case 3:
     111      260886 :             if ( ivas_total_brate >= IVAS_96k )
     112             :             {
     113      134523 :                 ism_mode = ISM_MASA_MODE_DISC;
     114             :             }
     115      126363 :             else if ( ivas_total_brate >= IVAS_64k )
     116             :             {
     117       50088 :                 ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ;
     118             :             }
     119       76275 :             else if ( ivas_total_brate >= IVAS_32k )
     120             :             {
     121       68395 :                 ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ;
     122             :             }
     123             :             else
     124             :             {
     125        7880 :                 ism_mode = ISM_MODE_NONE;
     126             :             }
     127      260886 :             break;
     128      390120 :         case 4:
     129      390120 :             if ( ivas_total_brate >= IVAS_128k )
     130             :             {
     131      161674 :                 ism_mode = ISM_MASA_MODE_DISC;
     132             :             }
     133      228446 :             else if ( ivas_total_brate >= IVAS_64k )
     134             :             {
     135      110891 :                 ism_mode = ISM_MASA_MODE_PARAM_ONE_OBJ;
     136             :             }
     137      117555 :             else if ( ivas_total_brate >= IVAS_32k )
     138             :             {
     139       99954 :                 ism_mode = ISM_MASA_MODE_MASA_ONE_OBJ;
     140             :             }
     141             :             else
     142             :             {
     143       17601 :                 ism_mode = ISM_MODE_NONE;
     144             :             }
     145      390120 :             break;
     146             :     }
     147             : 
     148     1155262 :     return ism_mode;
     149             : }
     150             : 
     151             : 
     152             : /*---------------------------------------------------------------
     153             :  * ivas_set_omasa_TC()
     154             :  *
     155             :  * set number of transport channels in OMASA format
     156             :  * ---------------------------------------------------------------*/
     157             : 
     158       33696 : void ivas_set_omasa_TC(
     159             :     const ISM_MODE ism_mode, /* i  : ISM mode                   */
     160             :     const int16_t nchan_ism, /* i  : number of input ISMs       */
     161             :     int16_t *nSCE,           /* o  : number of SCEs             */
     162             :     int16_t *nCPE            /* o  : number of CPEs             */
     163             : )
     164             : {
     165       33696 :     switch ( ism_mode )
     166             :     {
     167       13898 :         case ISM_MASA_MODE_MASA_ONE_OBJ:
     168             :         case ISM_MASA_MODE_PARAM_ONE_OBJ:
     169       13898 :             *nCPE = 1;
     170       13898 :             *nSCE = 1;
     171       13898 :             break;
     172       10432 :         case ISM_MASA_MODE_DISC:
     173       10432 :             *nCPE = 1;
     174       10432 :             *nSCE = nchan_ism;
     175       10432 :             break;
     176        9366 :         case ISM_MODE_NONE:
     177        9366 :             *nCPE = 1;
     178        9366 :             *nSCE = 0;
     179        9366 :             break;
     180           0 :         default:
     181           0 :             break;
     182             :     }
     183             : 
     184       33696 :     return;
     185             : }
     186             : 
     187             : 
     188             : /*---------------------------------------------------------------
     189             :  * ivas_interformat_brate()
     190             :  *
     191             :  * Bit-budget distribution in case of combined-format coding
     192             :  * ---------------------------------------------------------------*/
     193             : 
     194             : /*! r: adjusted bitrate */
     195     1170048 : int32_t ivas_interformat_brate(
     196             :     const ISM_MODE ism_mode,     /* i  : ISM mode                           */
     197             :     const int16_t nchan_ism,     /* i  : number of ISM channels             */
     198             :     const int32_t element_brate, /* i  : element bitrate                    */
     199             :     const int16_t ism_imp,       /* i  : ISM importance flag                */
     200             :     const int16_t limit_flag     /* i  : flag to limit the bitrate increase */
     201             : )
     202             : {
     203             :     int32_t element_brate_out;
     204             :     int16_t nBits, limit_low, limit_high;
     205             : 
     206     1170048 :     nBits = (int16_t) ( element_brate / FRAMES_PER_SEC );
     207             : 
     208     1170048 :     if ( ism_imp == ISM_INACTIVE_IMP )
     209             :     {
     210        1586 :         nBits = BITS_ISM_INACTIVE;
     211             :     }
     212             :     else
     213             :     {
     214     1168462 :         if ( ism_mode == ISM_MASA_MODE_DISC && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate <= 24000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) ) /* for border case in DISC mode */
     215             :         {
     216      140573 :             if ( limit_flag == 1 && ( ( nchan_ism == 4 && element_brate == 24000 ) || ( nchan_ism == 3 && element_brate == 20000 ) || ( nchan_ism == 2 && element_brate <= 11000 ) ) )
     217             :             {
     218       87826 :                 return element_brate;
     219             :             }
     220             : 
     221       52747 :             if ( ism_imp == ISM_LOW_IMP )
     222             :             {
     223        8807 :                 nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP4 );
     224             :             }
     225       43940 :             else if ( ism_imp == ISM_MEDIUM_IMP )
     226             :             {
     227       12179 :                 nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP4 );
     228       12179 :                 if ( limit_flag == -1 )
     229             :                 {
     230           0 :                     nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 );
     231             :                 }
     232             :             }
     233             :             else /* ISM_HIGH_IMP */
     234             :             {
     235       31761 :                 nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 );
     236       31761 :                 if ( limit_flag == -1 )
     237             :                 {
     238           0 :                     nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 );
     239             :                 }
     240             :             }
     241             :         }
     242     1027889 :         else if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ ||
     243      813234 :                   ( ism_mode == ISM_MASA_MODE_DISC && element_brate == 9600 ) /* this condition corresponds to the ivas_total_brate = 24400 and 1 object */
     244             :         )
     245             :         {
     246      132450 :             if ( ism_mode == ISM_MASA_MODE_PARAM_ONE_OBJ && element_brate == IVAS_13k2 )
     247             :             {
     248       18748 :                 if ( ism_imp == ISM_LOW_IMP )
     249             :                 {
     250        1740 :                     nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 );
     251             :                 }
     252       17008 :                 else if ( ism_imp == ISM_MEDIUM_IMP )
     253             :                 {
     254        4092 :                     nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 );
     255             :                 }
     256             :                 else /* ISM_HIGH_IMP */
     257             :                 {
     258       12916 :                     nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP4 );
     259             :                 }
     260             :             }
     261             :             else
     262             :             {
     263      113702 :                 if ( ism_imp == ISM_LOW_IMP )
     264             :                 {
     265        6782 :                     nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP3 );
     266             :                 }
     267      106920 :                 else if ( ism_imp == ISM_MEDIUM_IMP )
     268             :                 {
     269       27903 :                     nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP3 );
     270             :                 }
     271             :                 else /* ISM_HIGH_IMP */
     272             :                 {
     273       79017 :                     nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 );
     274             :                 }
     275             :             }
     276             :         }
     277      895439 :         else if ( ism_mode == ISM_MASA_MODE_MASA_ONE_OBJ && element_brate == 16000 )
     278             :         {
     279       40152 :             if ( ism_imp == ISM_LOW_IMP )
     280             :             {
     281        3560 :                 nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP );
     282             :             }
     283       36592 :             else if ( ism_imp == ISM_MEDIUM_IMP )
     284             :             {
     285       11552 :                 nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP );
     286             :             }
     287             :             else /* ISM_HIGH_IMP */
     288             :             {
     289       25040 :                 nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP3 );
     290             :             }
     291             :         }
     292             :         else
     293             :         {
     294      855287 :             if ( ism_imp == ISM_LOW_IMP )
     295             :             {
     296       75930 :                 nBits = (int16_t) ( nBits * GAMMA_ISM_LOW_IMP );
     297             :             }
     298      779357 :             else if ( ism_imp == ISM_MEDIUM_IMP )
     299             :             {
     300      226671 :                 nBits = (int16_t) ( nBits * GAMMA_ISM_MEDIUM_IMP );
     301             :             }
     302             :             else /* ISM_HIGH_IMP */
     303             :             {
     304      552686 :                 nBits = (int16_t) ( nBits * GAMMA_ISM_HIGH_IMP );
     305             :             }
     306             :         }
     307             :     }
     308             : 
     309     1082222 :     limit_low = MIN_BRATE_SWB_BWE / FRAMES_PER_SEC;
     310     1082222 :     if ( ism_imp == ISM_INACTIVE_IMP )
     311             :     {
     312        1586 :         limit_low = BITS_ISM_INACTIVE;
     313             :     }
     314     1080636 :     else if ( element_brate >= SCE_CORE_16k_LOW_LIMIT )
     315             :     {
     316      842632 :         limit_low = SCE_CORE_16k_LOW_LIMIT / FRAMES_PER_SEC;
     317             :     }
     318             : 
     319     1082222 :     limit_high = IVAS_512k / FRAMES_PER_SEC;
     320     1082222 :     if ( element_brate < SCE_CORE_16k_LOW_LIMIT )
     321             :     {
     322      239242 :         limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
     323             :     }
     324             : 
     325     1082222 :     nBits = check_bounds_s( nBits, limit_low, limit_high );
     326             : 
     327     1082222 :     element_brate_out = nBits * FRAMES_PER_SEC;
     328             : 
     329     1082222 :     return element_brate_out;
     330             : }
     331             : 
     332             : 
     333             : /*---------------------------------------------------------------
     334             :  * ivas_combined_format_brate_sanity()
     335             :  *
     336             :  * Sanity check in combined format coding
     337             :  * ---------------------------------------------------------------*/
     338             : 
     339       15467 : void ivas_combined_format_brate_sanity(
     340             :     const int32_t element_brate,       /* i  : element bitrate                */
     341             :     const int16_t core,                /* i  : core                           */
     342             :     const int32_t total_brate,         /* i  : total bitrate                  */
     343             :     int32_t *core_brate,               /* i/o: core bitrate                   */
     344             :     int16_t *inactive_coder_type_flag, /* o  : inactive coder_type flag       */
     345             :     int16_t *diff_nBits                /* o  : number of differential bits    */
     346             : )
     347             : {
     348             :     int16_t limit_high, nBits;
     349             :     int32_t brate_diff;
     350             : 
     351       15467 :     brate_diff = total_brate - *core_brate;
     352             : 
     353             :     /* sanity check: at lowest IVAS bit-rates and one ISM channel coded by
     354             :     low-rate core-coder mode, it can happen that the CPE (MASA) bit-budget
     355             :     for ACELP core-coding @12.8 kHz is too high */
     356             : 
     357       15467 :     if ( element_brate < ACELP_12k8_HIGH_LIMIT )
     358             :     {
     359        6861 :         limit_high = ACELP_12k8_HIGH_LIMIT / FRAMES_PER_SEC;
     360        6861 :         nBits = (int16_t) ( *core_brate / FRAMES_PER_SEC );
     361             : 
     362        6861 :         *diff_nBits = nBits - limit_high;
     363        6861 :         if ( *diff_nBits > 0 )
     364             :         {
     365          56 :             if ( core == TCX_20_CORE || core == TCX_10_CORE )
     366             :             {
     367           0 :                 *diff_nBits = 0;
     368             :             }
     369             :             else /* ACELP core */
     370             :             {
     371          56 :                 *core_brate -= ( *diff_nBits * FRAMES_PER_SEC );
     372             :             }
     373             :         }
     374             :     }
     375             : 
     376             :     /*-----------------------------------------------------------------*
     377             :      * set inactive coder_type flag in ACELP core
     378             :      *-----------------------------------------------------------------*/
     379             : 
     380       15467 :     if ( core == ACELP_CORE )
     381             :     {
     382        9057 :         *inactive_coder_type_flag = 0; /* AVQ by default */
     383        9057 :         if ( *core_brate + brate_diff <= MAX_GSC_INACTIVE_BRATE )
     384             :         {
     385        5484 :             *inactive_coder_type_flag = 1; /* GSC */
     386             :         }
     387             :     }
     388             : 
     389       15467 :     return;
     390             : }
     391             : 
     392             : 
     393             : /*---------------------------------------------------------------
     394             :  * bits_index_ism_ratio()
     395             :  *
     396             :  *
     397             :  * ---------------------------------------------------------------*/
     398             : 
     399             : /*!r : number of bits for ISM ratio index */
     400       90759 : int16_t bits_index_ism_ratio(
     401             :     const int16_t nchan_ism /* i  : number of objects    */
     402             : )
     403             : {
     404             :     int16_t bits_index;
     405             : 
     406       90759 :     bits_index = 0;
     407       90759 :     if ( nchan_ism == 2 )
     408             :     {
     409       13077 :         bits_index = 3;
     410             :     }
     411       77682 :     else if ( nchan_ism == 3 )
     412             :     {
     413       23195 :         bits_index = 6;
     414             :     }
     415       54487 :     else if ( nchan_ism == 4 )
     416             :     {
     417       54487 :         bits_index = 7;
     418             :     }
     419             :     else
     420             :     {
     421           0 :         assert( ( nchan_ism >= 2 && nchan_ism <= 4 ) && "Wrong number of objects for MASA_ISM." );
     422             :     }
     423             : 
     424       90759 :     return bits_index;
     425             : }
     426             : 
     427             : 
     428             : /*---------------------------------------------------------------
     429             :  * calculate_nbits_meta()
     430             :  *
     431             :  *
     432             :  * ---------------------------------------------------------------*/
     433             : 
     434       98973 : void calculate_nbits_meta(
     435             :     const int16_t nchan_ism,
     436             :     float q_energy_ratio_ism[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS][MAX_NUM_OBJECTS],
     437             :     float masa_to_total_energy_ratio[MAX_PARAM_SPATIAL_SUBFRAMES][MASA_FREQUENCY_BANDS],
     438             :     const int16_t numSf,
     439             :     const int16_t numCodingBands,
     440             :     int16_t *bits_ism,
     441             :     const int16_t idx_sep_obj,
     442             :     const int16_t ism_imp )
     443             : {
     444             :     int16_t sf, band, obj;
     445             :     float priority[MAX_NUM_OBJECTS], max_p;
     446             : 
     447       98973 :     if ( nchan_ism > 1 )
     448             :     {
     449       98973 :         set_f( priority, 0.0f, nchan_ism );
     450      417090 :         for ( sf = 0; sf < numSf; sf++ )
     451             :         {
     452     1971075 :             for ( band = 0; band < numCodingBands; band++ )
     453             :             {
     454     7649166 :                 for ( obj = 0; obj < nchan_ism; obj++ )
     455             :                 {
     456     5996208 :                     priority[obj] = max( priority[obj], ( q_energy_ratio_ism[sf][band][obj] * ( 1 - masa_to_total_energy_ratio[sf][band] ) ) );
     457             :                 }
     458             :             }
     459             :         }
     460             :     }
     461             :     else
     462             :     {
     463           0 :         priority[0] = 1;
     464             :     }
     465             : 
     466             :     /* decide parameters for ISM metadata quantization */
     467       98973 :     maximum( priority, nchan_ism, &max_p );
     468      439634 :     for ( obj = 0; obj < nchan_ism; obj++ )
     469             :     {
     470      340661 :         if ( obj == idx_sep_obj )
     471             :         {
     472       98973 :             if ( ism_imp == 3 )
     473             :             {
     474       67818 :                 priority[obj] = 1;
     475             :             }
     476       31155 :             else if ( ism_imp == 2 )
     477             :             {
     478       24355 :                 priority[obj] = ( 1 + max_p ) * 0.5f;
     479             :             }
     480             :             else
     481             :             {
     482        6800 :                 priority[obj] = max_p;
     483             :             }
     484             :         }
     485      340661 :         bits_ism[obj] = bits_direction_masa[0] - (int16_t) ( ( 1 - ( (int16_t) ( priority[obj] * 1000.0f ) ) * 0.001f ) * 6 );
     486             :     }
     487             : 
     488       98973 :     return;
     489             : }
     490             : 
     491             : 
     492             : /*---------------------------------------------------------------
     493             :  * ivas_get_stereo_panning_gains()
     494             :  *
     495             :  *
     496             :  *---------------------------------------------------------------*/
     497             : 
     498      639906 : void ivas_get_stereo_panning_gains(
     499             :     const float aziDeg,
     500             :     const float eleDeg,
     501             :     float panningGains[2] )
     502             : {
     503             :     float aziPlusEle, aziMinusEle, y;
     504             : 
     505             :     /* use identity sin(A+B) + sin(A−B) = 2 sinA cosB */
     506      639906 :     aziPlusEle = aziDeg + eleDeg;
     507      639906 :     aziMinusEle = aziDeg - eleDeg;
     508             : 
     509             :     /* wrap into -180..+180 */
     510      689739 :     while ( aziPlusEle > 180.0f )
     511             :     {
     512       49833 :         aziPlusEle -= 360.0f;
     513             :     }
     514      668959 :     while ( aziPlusEle < -180.0f )
     515             :     {
     516       29053 :         aziPlusEle += 360.0f;
     517             :     }
     518      679640 :     while ( aziMinusEle > 180.0f )
     519             :     {
     520       39734 :         aziMinusEle -= 360.0f;
     521             :     }
     522      662108 :     while ( aziMinusEle < -180.0f )
     523             :     {
     524       22202 :         aziMinusEle += 360.0f;
     525             :     }
     526             : 
     527             :     /* compute Y-coordinate corresponding to the azimuth and elevation: y = sin(azi) * cos(ele) = (sin(azi+ele) + sin(azi-ele)) / 2 */
     528      639906 :     y = ( sinf( aziPlusEle * PI_OVER_180 ) + sinf( aziMinusEle * PI_OVER_180 ) ) * 0.5f;
     529             : 
     530      639906 :     if ( y >= SIN_LS_ANGLE )
     531             :     { /* Left side */
     532      129501 :         panningGains[0] = 1.0f;
     533      129501 :         panningGains[1] = 0.0f;
     534             :     }
     535      510405 :     else if ( y <= -SIN_LS_ANGLE )
     536             :     { /* Right side */
     537      124961 :         panningGains[0] = 0.0f;
     538      124961 :         panningGains[1] = 1.0f;
     539             :     }
     540             :     else /* Tangent panning law */
     541             :     {
     542             :         /* from sin(angle) to index assuming range -30..+30 degrees with 0.1-degree spacing */
     543             :         float angleDeg, pos;
     544             :         int16_t idx;
     545             : 
     546             :         /* Convert azi and ele to an azi value of the cone of confusion */
     547      385444 :         angleDeg = asinf( y ) * _180_OVER_PI;
     548      385444 :         angleDeg = fmaxf( fminf( angleDeg, PAN_MAX_DEG ), -PAN_MAX_DEG );
     549             : 
     550             :         /* compute the panning gains from the mapped azimuth using a look-up table */
     551      385444 :         pos = ( angleDeg + PAN_MAX_DEG ) * ONE_OVER_PAN_STEP_DEG; /* ideal floating index */
     552      385444 :         idx = (int16_t) roundf( pos );
     553             : 
     554      385444 :         idx = max( 0, min( idx, OMASA_PAN_TBL_LEN - 1 ) );
     555             : 
     556      385444 :         panningGains[0] = ivas_tan_panning_gain_tbl[idx];
     557      385444 :         panningGains[1] = ivas_tan_panning_gain_tbl[OMASA_PAN_TBL_LEN - 1 - idx];
     558             :     }
     559             : 
     560      639906 :     return;
     561             : }
     562             : 
     563             : 
     564             : /*---------------------------------------------------------------
     565             :  * calculate_brate_limit_flag()
     566             :  *
     567             :  *
     568             :  *---------------------------------------------------------------*/
     569             : 
     570             : /*! r: limitation flag */
     571      447696 : int16_t calculate_brate_limit_flag(
     572             :     const int16_t ism_imp[], /* i  : ISM importance flags   */
     573             :     const int16_t nchan_ism  /* i  : number of objects      */
     574             : )
     575             : {
     576             :     int16_t n;
     577             :     int16_t brate_limit_flag;
     578             :     int16_t nzeros;
     579             : 
     580      447696 :     brate_limit_flag = 0;
     581      447696 :     nzeros = 0;
     582     1420343 :     for ( n = 0; n < nchan_ism; n++ )
     583             :     {
     584      972647 :         brate_limit_flag += ism_imp[n];
     585      972647 :         if ( ism_imp[n] == 0 )
     586             :         {
     587         655 :             nzeros++;
     588             :         }
     589             :     }
     590             : 
     591      447696 :     if ( brate_limit_flag >= (int16_t) ( nchan_ism * 2.5f ) )
     592             :     {
     593      380144 :         brate_limit_flag = 1;
     594             :     }
     595             :     else
     596             :     {
     597       67552 :         if ( nzeros / (float) nchan_ism >= 0.5f )
     598             :         {
     599         307 :             brate_limit_flag = -1; /* there is no limitation, on the contrary */
     600             :         }
     601             :     }
     602             : 
     603      447696 :     return brate_limit_flag;
     604             : }

Generated by: LCOV version 1.14