LCOV - code coverage report
Current view: top level - lib_com - ivas_mc_param_com.c (source / functions) Hit Total Coverage
Test: Coverage on main -- merged total coverage @ 9b04ec3cb36f5e8dc438cf854fa3e349998fa1e9 Lines: 160 169 94.7 %
Date: 2025-10-31 05:45:46 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <assert.h>
      34             : #include <stdint.h>
      35             : #include <math.h>
      36             : #include "options.h"
      37             : #include "ivas_cnst.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 function prototypes
      50             :  *------------------------------------------------------------------------*/
      51             : 
      52             : static void ivas_param_mc_set_coding_scheme( const MC_LS_SETUP mc_ls_setup, const int32_t ivas_total_brate, HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC );
      53             : 
      54             : 
      55             : /*-------------------------------------------------------------------------
      56             :  * ivas_param_mc_get_configuration_index()
      57             :  *
      58             :  *
      59             :  *------------------------------------------------------------------------*/
      60             : 
      61       64870 : uint16_t ivas_param_mc_get_configuration_index(
      62             :     const MC_LS_SETUP mc_ls_setup, /* i  : MC ls setup              */
      63             :     const int32_t ivas_total_brate /* i  : IVAS total bitrate       */
      64             : )
      65             : {
      66             :     uint16_t cur_idx;
      67             : 
      68      346441 :     for ( cur_idx = 0; cur_idx < PARAM_MC_NUM_CONFIGS; cur_idx++ )
      69             :     {
      70      346441 :         if ( ivas_param_mc_conf[cur_idx].mc_ls_setup == mc_ls_setup && ivas_param_mc_conf[cur_idx].ivas_total_brate == ivas_total_brate )
      71             :         {
      72       64870 :             return cur_idx;
      73             :         }
      74             :     }
      75             : #ifdef DEBUGGING
      76             :     assert( 0 && "No Parametric MC configuration for this bitrate/channel setup!" );
      77             : #endif
      78           0 :     return PARAM_MC_NUM_CONFIGS;
      79             : }
      80             : 
      81             : 
      82             : /*-------------------------------------------------------------------------
      83             :  * ivas_param_mc_metadata_open()
      84             :  *
      85             :  * Parametric MC parameter coding state open function
      86             :  *------------------------------------------------------------------------*/
      87             : 
      88       21216 : void ivas_param_mc_metadata_open(
      89             :     const MC_LS_SETUP mc_ls_setup,             /* i  : MC ls setup                                         */
      90             :     const int32_t ivas_total_brate,            /* i  : IVAS total bitrate                                  */
      91             :     HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* o  : handle for the Parametric MC parameter coding state */
      92             : )
      93             : {
      94             :     uint16_t config_index;
      95             : 
      96             :     /* get coding band mappings */
      97       21216 :     set_s( hMetadataPMC->coding_band_mapping, 0, PARAM_MC_MAX_PARAMETER_BANDS );
      98             : 
      99             :     /* set coding scheme */
     100       21216 :     ivas_param_mc_set_coding_scheme( mc_ls_setup, ivas_total_brate, hMetadataPMC );
     101             : 
     102             :     /* get configuration index */
     103       21216 :     config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate );
     104       21216 :     if ( config_index == PARAM_MC_NUM_CONFIGS )
     105             :     {
     106           0 :         assert( 0 && "ParamMC configuration index not found!" );
     107             :     }
     108             : 
     109             :     /* Band Grouping */
     110       21216 :     if ( hMetadataPMC->num_parameter_bands == 20 )
     111             :     {
     112        1943 :         mvs2s( param_mc_coding_band_mapping_20, hMetadataPMC->coding_band_mapping, 20 );
     113             :     }
     114       19273 :     else if ( hMetadataPMC->num_parameter_bands == 14 )
     115             :     {
     116       11093 :         mvs2s( param_mc_coding_band_mapping_14, hMetadataPMC->coding_band_mapping, 14 );
     117             :     }
     118        8180 :     else if ( hMetadataPMC->num_parameter_bands == 10 )
     119             :     {
     120        8180 :         mvs2s( param_mc_coding_band_mapping_10, hMetadataPMC->coding_band_mapping, 10 );
     121             :     }
     122             :     else
     123             :     {
     124           0 :         assert( 0 && "nbands must be 20 or 14!" );
     125             :     }
     126             : 
     127       21216 :     hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf;
     128       21216 :     hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf;
     129       21216 :     hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors;
     130             : 
     131             :     /* init remaining flags and indices */
     132       21216 :     hMetadataPMC->param_frame_idx = 0;
     133       21216 :     hMetadataPMC->bAttackPresent = 0;
     134       21216 :     hMetadataPMC->attackIndex = 0;
     135       21216 :     hMetadataPMC->lfe_on = 1;
     136             : 
     137             :     /* set coded bwidth to FB at the beginning */
     138       21216 :     hMetadataPMC->coded_bwidth = FB;
     139       21216 :     hMetadataPMC->last_coded_bwidth = FB;
     140             : 
     141       21216 :     ivas_param_mc_set_coded_bands( hMetadataPMC );
     142             : 
     143       21216 :     return;
     144             : }
     145             : 
     146             : 
     147             : /*-------------------------------------------------------------------------
     148             :  * ivas_param_mc_set_coded_bands()
     149             :  *
     150             :  * Parametric MC: set number of actually coded parameters bands based on the
     151             :  *                coded band width
     152             :  *------------------------------------------------------------------------*/
     153             : 
     154       34349 : void ivas_param_mc_set_coded_bands(
     155             :     HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: handle for the Parametric MC parameter coding state */
     156             : )
     157             : {
     158             :     int16_t i;
     159             : 
     160             :     /* set number of coded bands*/
     161       34349 :     switch ( hMetadataPMC->num_parameter_bands )
     162             :     {
     163        3586 :         case 20:
     164        3586 :             hMetadataPMC->nbands_coded = param_mc_bands_coded_20[hMetadataPMC->coded_bwidth];
     165        3586 :             break;
     166       18059 :         case 14:
     167       18059 :             hMetadataPMC->nbands_coded = param_mc_bands_coded_14[hMetadataPMC->coded_bwidth];
     168       18059 :             break;
     169       12704 :         case 10:
     170       12704 :             hMetadataPMC->nbands_coded = param_mc_bands_coded_10[hMetadataPMC->coded_bwidth];
     171             :     }
     172             : 
     173             :     /* set number of bands per parameter frame set */
     174      103047 :     for ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ )
     175             :     {
     176       68698 :         hMetadataPMC->nbands_in_param_frame[i] = 0;
     177             :     }
     178             : 
     179      468993 :     for ( i = 0; i < hMetadataPMC->nbands_coded; i++ )
     180             :     {
     181      434644 :         hMetadataPMC->nbands_in_param_frame[hMetadataPMC->coding_band_mapping[i]]++;
     182             :     }
     183             : 
     184       34349 :     return;
     185             : }
     186             : 
     187             : 
     188             : /*-------------------------------------------------------------------------
     189             :  * ivas_param_mc_getNumTransportChannels()
     190             :  *
     191             :  *
     192             :  *------------------------------------------------------------------------*/
     193             : 
     194             : /* r  : number of IVAS transport channels */
     195       22438 : int16_t ivas_param_mc_getNumTransportChannels(
     196             :     const int32_t ivas_total_bitrate, /* i  : IVAS total bitrate        */
     197             :     const MC_LS_SETUP mc_ls_setup     /* i  : MC ls setup               */
     198             : )
     199             : {
     200             :     int16_t nchan_transport;
     201             :     int16_t config_index;
     202             : 
     203       22438 :     config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_bitrate );
     204             : 
     205       22438 :     nchan_transport = ivas_param_mc_conf[config_index].num_transport_chan;
     206             : 
     207       22438 :     return nchan_transport;
     208             : }
     209             : 
     210             : 
     211             : /*-------------------------------------------------------------------------
     212             :  * ivas_param_mc_get_num_param_bands()
     213             :  *
     214             :  *
     215             :  *------------------------------------------------------------------------*/
     216             : 
     217       21216 : static int16_t ivas_param_mc_get_num_param_bands(
     218             :     const MC_LS_SETUP mc_ls_setup, /* i  : MC ls setup                      */
     219             :     const int32_t ivas_total_brate /* i  : IVAS total bitrate               */
     220             : )
     221             : {
     222             :     int16_t num_parameter_bands;
     223             : 
     224       21216 :     num_parameter_bands = 0;
     225             : 
     226             :     /* parameter bands */
     227       21216 :     switch ( mc_ls_setup )
     228             :     {
     229       11856 :         case MC_LS_SETUP_5_1:
     230             :             switch ( ivas_total_brate )
     231             :             {
     232        6741 :                 case IVAS_48k:
     233        6741 :                     num_parameter_bands = 10;
     234        6741 :                     break;
     235        5115 :                 case IVAS_64k:
     236             :                 case IVAS_80k:
     237        5115 :                     num_parameter_bands = 14;
     238        5115 :                     break;
     239           0 :                 default:
     240           0 :                     assert( 0 && "PARAM_MC: bitrate for CICP6 not supported!" );
     241             :             }
     242       11856 :             break;
     243             : 
     244        3369 :         case MC_LS_SETUP_7_1:
     245             :             switch ( ivas_total_brate )
     246             :             {
     247         841 :                 case IVAS_48k:
     248         841 :                     num_parameter_bands = 10;
     249         841 :                     break;
     250        1589 :                 case IVAS_64k:
     251             :                 case IVAS_80k:
     252        1589 :                     num_parameter_bands = 14;
     253        1589 :                     break;
     254         939 :                 case IVAS_96k:
     255         939 :                     num_parameter_bands = 20;
     256         939 :                     break;
     257             :             }
     258        3369 :             break;
     259        2361 :         case MC_LS_SETUP_5_1_2:
     260             :             switch ( ivas_total_brate )
     261             :             {
     262         598 :                 case IVAS_48k:
     263         598 :                     num_parameter_bands = 10;
     264         598 :                     break;
     265        1094 :                 case IVAS_64k:
     266             :                 case IVAS_80k:
     267        1094 :                     num_parameter_bands = 14;
     268        1094 :                     break;
     269         669 :                 case IVAS_96k:
     270         669 :                     num_parameter_bands = 20;
     271         669 :                     break;
     272             :             }
     273        2361 :             break;
     274         666 :         case MC_LS_SETUP_5_1_4:
     275             :             switch ( ivas_total_brate )
     276             :             {
     277         331 :                 case IVAS_96k:
     278         331 :                     num_parameter_bands = 14;
     279         331 :                     break;
     280         335 :                 case IVAS_128k:
     281         335 :                     num_parameter_bands = 20;
     282         335 :                     break;
     283             :             }
     284         666 :             break;
     285        2964 :         case MC_LS_SETUP_7_1_4:
     286             :             switch ( ivas_total_brate )
     287             :             {
     288        2964 :                 case IVAS_128k:
     289        2964 :                     num_parameter_bands = 14;
     290        2964 :                     break;
     291             :             }
     292        2964 :             break;
     293           0 :         default:
     294           0 :             assert( 0 && "PARAM_MC: channel configuration not supportet!" );
     295             :     }
     296             : 
     297       21216 :     return num_parameter_bands;
     298             : }
     299             : 
     300             : 
     301             : /*-------------------------------------------------------------------------
     302             :  * Local functions
     303             :  *------------------------------------------------------------------------*/
     304             : 
     305             : /*-------------------------------------------------------------------------
     306             :  * ivas_param_mc_set_coding_scheme()
     307             :  *
     308             :  * set Parametric MC parameter coding tables based on format and bitrate
     309             :  *------------------------------------------------------------------------*/
     310             : 
     311       21216 : static void ivas_param_mc_set_coding_scheme(
     312             :     const MC_LS_SETUP mc_ls_setup,             /* i  : MC ls setup                      */
     313             :     const int32_t ivas_total_brate,            /* i  : IVAS total bitrate               */
     314             :     HANDLE_IVAS_PARAM_MC_METADATA hMetadataPMC /* i/o: Parametric MC metadata handle    */
     315             : )
     316             : {
     317             :     /* quantizer and coding tables */
     318       21216 :     switch ( mc_ls_setup )
     319             :     {
     320       11856 :         case MC_LS_SETUP_5_1:
     321             :             /* ICC */
     322       11856 :             hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp6_48_16bits[0];
     323       11856 :             hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp6_48_16bits[0];
     324       11856 :             hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[0];
     325       11856 :             hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0];
     326       11856 :             hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
     327       11856 :             hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
     328       11856 :             hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
     329             :             /* ILD */
     330       11856 :             hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp6_48_16bits[0];
     331       11856 :             hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp6_48_16bits[0];
     332       11856 :             hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0];
     333       11856 :             hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0];
     334       11856 :             hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
     335       11856 :             hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
     336       11856 :             hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
     337       11856 :             break;
     338        3369 :         case MC_LS_SETUP_7_1:
     339             :             /* ICC */
     340        3369 :             hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp12_48_16bits[0];
     341        3369 :             hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp12_48_16bits[0];
     342        3369 :             hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0];
     343        3369 :             hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0];
     344        3369 :             hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
     345        3369 :             hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
     346        3369 :             hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
     347             :             /* ILD */
     348        3369 :             hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp12_48_16bits[0];
     349        3369 :             hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp12_48_16bits[0];
     350        3369 :             hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0];
     351        3369 :             hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0];
     352        3369 :             hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
     353        3369 :             hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
     354        3369 :             hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
     355        3369 :             break;
     356        2361 :         case MC_LS_SETUP_5_1_2:
     357             :             /* ICC */
     358        2361 :             hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp14_48_16bits[0];
     359        2361 :             hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp14_48_16bits[0];
     360        2361 :             hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0];
     361        2361 :             hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0];
     362        2361 :             hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
     363        2361 :             hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
     364        2361 :             hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
     365             :             /* ILD */
     366        2361 :             hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp14_48_16bits[0];
     367        2361 :             hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp14_48_16bits[0];
     368        2361 :             hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0];
     369        2361 :             hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0];
     370        2361 :             hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
     371        2361 :             hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
     372        2361 :             hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
     373        2361 :             break;
     374        3630 :         case MC_LS_SETUP_5_1_4:
     375             :         case MC_LS_SETUP_7_1_4:
     376             :             /* ICC */
     377        3630 :             hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_combined_48_16bits[0];
     378        3630 :             hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_combined_48_16bits[0];
     379        3630 :             hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0];
     380        3630 :             hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0];
     381        3630 :             hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
     382        3630 :             hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
     383        3630 :             hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
     384             :             /* ILD */
     385        3630 :             hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_combined_48_16bits[0];
     386        3630 :             hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_combined_48_16bits[0];
     387        3630 :             hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0];
     388        3630 :             hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0];
     389        3630 :             hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
     390        3630 :             hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
     391        3630 :             hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
     392        3630 :             break;
     393           0 :         default:
     394           0 :             assert( 0 && "PARAM_MC: channel configuration not supported!" );
     395             :     }
     396             : 
     397       21216 :     hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands( mc_ls_setup, ivas_total_brate );
     398             : 
     399       21216 :     return;
     400             : }

Generated by: LCOV version 1.14