LCOV - code coverage report
Current view: top level - lib_com - ivas_mc_param_com.c (source / functions) Hit Total Coverage
Test: Coverage on main -- conformance test test_26252.py @ a21f94bc6bac334fe001a5bad2f7b32b79038097 Lines: 152 169 89.9 %
Date: 2025-11-01 05:07:43 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        1932 : 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        6097 :     for ( cur_idx = 0; cur_idx < PARAM_MC_NUM_CONFIGS; cur_idx++ )
      69             :     {
      70        6097 :         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        1932 :             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         641 : 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         641 :     set_s( hMetadataPMC->coding_band_mapping, 0, PARAM_MC_MAX_PARAMETER_BANDS );
      98             : 
      99             :     /* set coding scheme */
     100         641 :     ivas_param_mc_set_coding_scheme( mc_ls_setup, ivas_total_brate, hMetadataPMC );
     101             : 
     102             :     /* get configuration index */
     103         641 :     config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_brate );
     104         641 :     if ( config_index == PARAM_MC_NUM_CONFIGS )
     105             :     {
     106           0 :         assert( 0 && "ParamMC configuration index not found!" );
     107             :     }
     108             : 
     109             :     /* Band Grouping */
     110         641 :     if ( hMetadataPMC->num_parameter_bands == 20 )
     111             :     {
     112           6 :         mvs2s( param_mc_coding_band_mapping_20, hMetadataPMC->coding_band_mapping, 20 );
     113             :     }
     114         635 :     else if ( hMetadataPMC->num_parameter_bands == 14 )
     115             :     {
     116         331 :         mvs2s( param_mc_coding_band_mapping_14, hMetadataPMC->coding_band_mapping, 14 );
     117             :     }
     118         304 :     else if ( hMetadataPMC->num_parameter_bands == 10 )
     119             :     {
     120         304 :         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         641 :     hMetadataPMC->icc_mapping_conf = ivas_param_mc_conf[config_index].icc_mapping_conf;
     128         641 :     hMetadataPMC->ild_mapping_conf = ivas_param_mc_conf[config_index].ild_mapping_conf;
     129         641 :     hMetadataPMC->ild_factors = ivas_param_mc_conf[config_index].ild_factors;
     130             : 
     131             :     /* init remaining flags and indices */
     132         641 :     hMetadataPMC->param_frame_idx = 0;
     133         641 :     hMetadataPMC->bAttackPresent = 0;
     134         641 :     hMetadataPMC->attackIndex = 0;
     135         641 :     hMetadataPMC->lfe_on = 1;
     136             : 
     137             :     /* set coded bwidth to FB at the beginning */
     138         641 :     hMetadataPMC->coded_bwidth = FB;
     139         641 :     hMetadataPMC->last_coded_bwidth = FB;
     140             : 
     141         641 :     ivas_param_mc_set_coded_bands( hMetadataPMC );
     142             : 
     143         641 :     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         922 : 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         922 :     switch ( hMetadataPMC->num_parameter_bands )
     162             :     {
     163           9 :         case 20:
     164           9 :             hMetadataPMC->nbands_coded = param_mc_bands_coded_20[hMetadataPMC->coded_bwidth];
     165           9 :             break;
     166         473 :         case 14:
     167         473 :             hMetadataPMC->nbands_coded = param_mc_bands_coded_14[hMetadataPMC->coded_bwidth];
     168         473 :             break;
     169         440 :         case 10:
     170         440 :             hMetadataPMC->nbands_coded = param_mc_bands_coded_10[hMetadataPMC->coded_bwidth];
     171             :     }
     172             : 
     173             :     /* set number of bands per parameter frame set */
     174        2766 :     for ( i = 0; i < PARAM_MC_PARAMETER_FRAMES; i++ )
     175             :     {
     176        1844 :         hMetadataPMC->nbands_in_param_frame[i] = 0;
     177             :     }
     178             : 
     179       11918 :     for ( i = 0; i < hMetadataPMC->nbands_coded; i++ )
     180             :     {
     181       10996 :         hMetadataPMC->nbands_in_param_frame[hMetadataPMC->coding_band_mapping[i]]++;
     182             :     }
     183             : 
     184         922 :     return;
     185             : }
     186             : 
     187             : 
     188             : /*-------------------------------------------------------------------------
     189             :  * ivas_param_mc_getNumTransportChannels()
     190             :  *
     191             :  *
     192             :  *------------------------------------------------------------------------*/
     193             : 
     194             : /* r  : number of IVAS transport channels */
     195         650 : 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         650 :     config_index = ivas_param_mc_get_configuration_index( mc_ls_setup, ivas_total_bitrate );
     204             : 
     205         650 :     nchan_transport = ivas_param_mc_conf[config_index].num_transport_chan;
     206             : 
     207         650 :     return nchan_transport;
     208             : }
     209             : 
     210             : 
     211             : /*-------------------------------------------------------------------------
     212             :  * ivas_param_mc_get_num_param_bands()
     213             :  *
     214             :  *
     215             :  *------------------------------------------------------------------------*/
     216             : 
     217         641 : 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         641 :     num_parameter_bands = 0;
     225             : 
     226             :     /* parameter bands */
     227         641 :     switch ( mc_ls_setup )
     228             :     {
     229         539 :         case MC_LS_SETUP_5_1:
     230             :             switch ( ivas_total_brate )
     231             :             {
     232         294 :                 case IVAS_48k:
     233         294 :                     num_parameter_bands = 10;
     234         294 :                     break;
     235         245 :                 case IVAS_64k:
     236             :                 case IVAS_80k:
     237         245 :                     num_parameter_bands = 14;
     238         245 :                     break;
     239           0 :                 default:
     240           0 :                     assert( 0 && "PARAM_MC: bitrate for CICP6 not supported!" );
     241             :             }
     242         539 :             break;
     243             : 
     244          26 :         case MC_LS_SETUP_7_1:
     245             :             switch ( ivas_total_brate )
     246             :             {
     247           6 :                 case IVAS_48k:
     248           6 :                     num_parameter_bands = 10;
     249           6 :                     break;
     250          16 :                 case IVAS_64k:
     251             :                 case IVAS_80k:
     252          16 :                     num_parameter_bands = 14;
     253          16 :                     break;
     254           4 :                 case IVAS_96k:
     255           4 :                     num_parameter_bands = 20;
     256           4 :                     break;
     257             :             }
     258          26 :             break;
     259          22 :         case MC_LS_SETUP_5_1_2:
     260             :             switch ( ivas_total_brate )
     261             :             {
     262           4 :                 case IVAS_48k:
     263           4 :                     num_parameter_bands = 10;
     264           4 :                     break;
     265          16 :                 case IVAS_64k:
     266             :                 case IVAS_80k:
     267          16 :                     num_parameter_bands = 14;
     268          16 :                     break;
     269           2 :                 case IVAS_96k:
     270           2 :                     num_parameter_bands = 20;
     271           2 :                     break;
     272             :             }
     273          22 :             break;
     274           0 :         case MC_LS_SETUP_5_1_4:
     275             :             switch ( ivas_total_brate )
     276             :             {
     277           0 :                 case IVAS_96k:
     278           0 :                     num_parameter_bands = 14;
     279           0 :                     break;
     280           0 :                 case IVAS_128k:
     281           0 :                     num_parameter_bands = 20;
     282           0 :                     break;
     283             :             }
     284           0 :             break;
     285          54 :         case MC_LS_SETUP_7_1_4:
     286             :             switch ( ivas_total_brate )
     287             :             {
     288          54 :                 case IVAS_128k:
     289          54 :                     num_parameter_bands = 14;
     290          54 :                     break;
     291             :             }
     292          54 :             break;
     293           0 :         default:
     294           0 :             assert( 0 && "PARAM_MC: channel configuration not supportet!" );
     295             :     }
     296             : 
     297         641 :     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         641 : 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         641 :     switch ( mc_ls_setup )
     319             :     {
     320         539 :         case MC_LS_SETUP_5_1:
     321             :             /* ICC */
     322         539 :             hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp6_48_16bits[0];
     323         539 :             hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp6_48_16bits[0];
     324         539 :             hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp6_48_16bits[0];
     325         539 :             hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp6_48_16bits[0];
     326         539 :             hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
     327         539 :             hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
     328         539 :             hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
     329             :             /* ILD */
     330         539 :             hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp6_48_16bits[0];
     331         539 :             hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp6_48_16bits[0];
     332         539 :             hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp6_48_16bits[0];
     333         539 :             hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp6_48_16bits[0];
     334         539 :             hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
     335         539 :             hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
     336         539 :             hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
     337         539 :             break;
     338          26 :         case MC_LS_SETUP_7_1:
     339             :             /* ICC */
     340          26 :             hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp12_48_16bits[0];
     341          26 :             hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp12_48_16bits[0];
     342          26 :             hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp12_48_16bits[0];
     343          26 :             hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp12_48_16bits[0];
     344          26 :             hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
     345          26 :             hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
     346          26 :             hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
     347             :             /* ILD */
     348          26 :             hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp12_48_16bits[0];
     349          26 :             hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp12_48_16bits[0];
     350          26 :             hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp12_48_16bits[0];
     351          26 :             hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp12_48_16bits[0];
     352          26 :             hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
     353          26 :             hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
     354          26 :             hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
     355          26 :             break;
     356          22 :         case MC_LS_SETUP_5_1_2:
     357             :             /* ICC */
     358          22 :             hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_cicp14_48_16bits[0];
     359          22 :             hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_cicp14_48_16bits[0];
     360          22 :             hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_cicp14_48_16bits[0];
     361          22 :             hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_cicp14_48_16bits[0];
     362          22 :             hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
     363          22 :             hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
     364          22 :             hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
     365             :             /* ILD */
     366          22 :             hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_cicp14_48_16bits[0];
     367          22 :             hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_cicp14_48_16bits[0];
     368          22 :             hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_cicp14_48_16bits[0];
     369          22 :             hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_cicp14_48_16bits[0];
     370          22 :             hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
     371          22 :             hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
     372          22 :             hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
     373          22 :             break;
     374          54 :         case MC_LS_SETUP_5_1_4:
     375             :         case MC_LS_SETUP_7_1_4:
     376             :             /* ICC */
     377          54 :             hMetadataPMC->icc_coding.cum_freq = &ivas_param_mc_cum_freq_icc_combined_48_16bits[0];
     378          54 :             hMetadataPMC->icc_coding.sym_freq = &ivas_param_mc_sym_freq_icc_combined_48_16bits[0];
     379          54 :             hMetadataPMC->icc_coding.cum_freq_delta = &ivas_param_mc_cum_freq_icc_delta_combined_48_16bits[0];
     380          54 :             hMetadataPMC->icc_coding.sym_freq_delta = &ivas_param_mc_sym_freq_icc_delta_combined_48_16bits[0];
     381          54 :             hMetadataPMC->icc_coding.quantizer = &ivas_param_mc_quant_icc[0];
     382          54 :             hMetadataPMC->icc_coding.quantizer_size = PARAM_MC_SZ_ICC_QUANTIZER;
     383          54 :             hMetadataPMC->icc_coding.uni_bits = PARAM_MC_NUM_BITS_ICC_SCALAR_QUANT;
     384             :             /* ILD */
     385          54 :             hMetadataPMC->ild_coding.cum_freq = &ivas_param_mc_cum_freq_ild_combined_48_16bits[0];
     386          54 :             hMetadataPMC->ild_coding.sym_freq = &ivas_param_mc_sym_freq_ild_combined_48_16bits[0];
     387          54 :             hMetadataPMC->ild_coding.cum_freq_delta = &ivas_param_mc_cum_freq_ild_delta_combined_48_16bits[0];
     388          54 :             hMetadataPMC->ild_coding.sym_freq_delta = &ivas_param_mc_sym_freq_ild_delta_combined_48_16bits[0];
     389          54 :             hMetadataPMC->ild_coding.quantizer = &ivas_param_mc_quant_ild_5d1_48[0];
     390          54 :             hMetadataPMC->ild_coding.quantizer_size = PARAM_MC_SZ_ILD_QUANTIZER_4BITS;
     391          54 :             hMetadataPMC->ild_coding.uni_bits = PARAM_MC_NUM_BITS_ILD_SCALAR_QUANT;
     392          54 :             break;
     393           0 :         default:
     394           0 :             assert( 0 && "PARAM_MC: channel configuration not supported!" );
     395             :     }
     396             : 
     397         641 :     hMetadataPMC->num_parameter_bands = ivas_param_mc_get_num_param_bands( mc_ls_setup, ivas_total_brate );
     398             : 
     399         641 :     return;
     400             : }

Generated by: LCOV version 1.14