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

Generated by: LCOV version 1.14