LCOV - code coverage report
Current view: top level - lib_com - ivas_spar_com_quant_util.c (source / functions) Hit Total Coverage
Test: Coverage on main @ 6baab0c613aa6c7100498ed7b93676aa8198a493 Lines: 116 118 98.3 %
Date: 2025-05-29 08:28:55 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /******************************************************************************************************
       2             : 
       3             :    (C) 2022-2025 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
       4             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
       5             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
       6             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
       7             :    contributors to this repository. All Rights Reserved.
       8             : 
       9             :    This software is protected by copyright law and by international treaties.
      10             :    The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
      11             :    Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
      12             :    Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
      13             :    Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
      14             :    contributors to this repository retain full ownership rights in their respective contributions in
      15             :    the software. This notice grants no license of any kind, including but not limited to patent
      16             :    license, nor is any license granted by implication, estoppel or otherwise.
      17             : 
      18             :    Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
      19             :    contributions.
      20             : 
      21             :    This software is provided "AS IS", without any express or implied warranties. The software is in the
      22             :    development stage. It is intended exclusively for experts who have experience with such software and
      23             :    solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
      24             :    and fitness for a particular purpose are hereby disclaimed and excluded.
      25             : 
      26             :    Any dispute, controversy or claim arising under or in relation to providing this software shall be
      27             :    submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
      28             :    accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
      29             :    the United Nations Convention on Contracts on the International Sales of Goods.
      30             : 
      31             : *******************************************************************************************************/
      32             : 
      33             : #include <stdint.h>
      34             : #include "options.h"
      35             : #ifdef DEBUGGING
      36             : #include "debug.h"
      37             : #endif
      38             : #include "math.h"
      39             : #include "prot.h"
      40             : #include "ivas_prot.h"
      41             : #include "ivas_rom_com.h"
      42             : #include <assert.h>
      43             : #include "wmc_auto.h"
      44             : 
      45             : /*-----------------------------------------------------------------------------------------*
      46             :  * Function ivas_quantise_real_values()
      47             :  *
      48             :  * Quantize real values
      49             :  *-----------------------------------------------------------------------------------------*/
      50    49129500 : void ivas_quantise_real_values(
      51             :     const float *values,
      52             :     const int16_t q_levels,
      53             :     const float min_value,
      54             :     const float max_value,
      55             :     int16_t *index,
      56             :     float *quant,
      57             :     const int16_t dim )
      58             : {
      59             :     int16_t i;
      60             :     float q_step, one_by_q_step;
      61    49129500 :     if ( q_levels == 1 )
      62             :     {
      63       44128 :         for ( i = 0; i < dim; i++ )
      64             :         {
      65       22064 :             quant[i] = 0;
      66       22064 :             index[i] = 0;
      67             :         }
      68             :     }
      69    49107436 :     else if ( q_levels && max_value != min_value )
      70    49107436 :     {
      71    49107436 :         q_step = ( max_value - min_value ) / ( q_levels - 1 );
      72    49107436 :         one_by_q_step = ( q_levels - 1 ) / ( max_value - min_value );
      73             :         float val;
      74   237272744 :         for ( i = 0; i < dim; i++ )
      75             :         {
      76   188165308 :             val = max( min_value, min( values[i], max_value ) );
      77   188165308 :             index[i] = (int16_t) round( one_by_q_step * val );
      78   188165308 :             quant[i] = index[i] * q_step;
      79             :         }
      80             :     }
      81             :     else
      82             :     {
      83           0 :         for ( i = 0; i < dim; i++ )
      84             :         {
      85           0 :             quant[i] = values[i];
      86             :         }
      87             :     }
      88    49129500 :     return;
      89             : }
      90             : 
      91             : 
      92             : /*-----------------------------------------------------------------------------------------*
      93             :  * Function ivas_spar_get_uniform_quant_strat()
      94             :  *
      95             :  * Sets the quant strat values
      96             :  *-----------------------------------------------------------------------------------------*/
      97      108422 : void ivas_spar_get_uniform_quant_strat(
      98             :     ivas_spar_md_com_cfg *pSpar_md_com_cfg,
      99             :     const int16_t table_idx )
     100             : {
     101             :     int16_t i;
     102      108422 :     int16_t active_w = ivas_spar_br_table_consts[table_idx].active_w;
     103             :     int16_t PQ_q_lvl, C_q_lvl, Pr_q_lvl, Pc_q_lvl;
     104             : 
     105      108422 :     pSpar_md_com_cfg->num_quant_strats = MAX_QUANT_STRATS;
     106             : 
     107      433688 :     for ( i = 0; i < pSpar_md_com_cfg->num_quant_strats; i++ )
     108             :     {
     109      325266 :         PQ_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][0];
     110      325266 :         C_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][1];
     111      325266 :         Pr_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][2];
     112      325266 :         Pc_q_lvl = ivas_spar_br_table_consts[table_idx].q_lvls[i][3];
     113             : 
     114      325266 :         if ( active_w )
     115             :         {
     116      108669 :             pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl;
     117      108669 :             pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl;
     118      108669 :             pSpar_md_com_cfg->quant_strat[i].PR.min = -1.2f;
     119      108669 :             pSpar_md_com_cfg->quant_strat[i].PR.max = 1.2f;
     120             : 
     121      108669 :             pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl;
     122      108669 :             pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl;
     123      108669 :             pSpar_md_com_cfg->quant_strat[i].C.min = -0.8f;
     124      108669 :             pSpar_md_com_cfg->quant_strat[i].C.max = 0.8f;
     125             : 
     126      108669 :             pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl;
     127      108669 :             pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl;
     128      108669 :             pSpar_md_com_cfg->quant_strat[i].P_r.min = 0;
     129      108669 :             pSpar_md_com_cfg->quant_strat[i].P_r.max = 0.8f;
     130             : 
     131      108669 :             pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl;
     132      108669 :             pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl;
     133      108669 :             pSpar_md_com_cfg->quant_strat[i].P_c.min = -0.8f;
     134      108669 :             pSpar_md_com_cfg->quant_strat[i].P_c.max = 0.8f;
     135             :         }
     136             :         else
     137             :         {
     138      216597 :             pSpar_md_com_cfg->quant_strat[i].PR.q_levels[0] = PQ_q_lvl;
     139      216597 :             pSpar_md_com_cfg->quant_strat[i].PR.q_levels[1] = PQ_q_lvl;
     140      216597 :             pSpar_md_com_cfg->quant_strat[i].PR.max = 1;
     141      216597 :             pSpar_md_com_cfg->quant_strat[i].PR.min = -1;
     142             : 
     143      216597 :             pSpar_md_com_cfg->quant_strat[i].C.q_levels[0] = C_q_lvl;
     144      216597 :             pSpar_md_com_cfg->quant_strat[i].C.q_levels[1] = C_q_lvl;
     145      216597 :             pSpar_md_com_cfg->quant_strat[i].C.max = 2;
     146      216597 :             pSpar_md_com_cfg->quant_strat[i].C.min = -2;
     147             : 
     148      216597 :             pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[0] = Pr_q_lvl;
     149      216597 :             pSpar_md_com_cfg->quant_strat[i].P_r.q_levels[1] = Pr_q_lvl;
     150      216597 :             pSpar_md_com_cfg->quant_strat[i].P_r.max = 1.0f;
     151      216597 :             pSpar_md_com_cfg->quant_strat[i].P_r.min = 0;
     152             : 
     153      216597 :             pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[0] = Pc_q_lvl;
     154      216597 :             pSpar_md_com_cfg->quant_strat[i].P_c.q_levels[1] = Pc_q_lvl;
     155      216597 :             pSpar_md_com_cfg->quant_strat[i].P_c.max = 0.5;
     156      216597 :             pSpar_md_com_cfg->quant_strat[i].P_c.min = -0.5;
     157             :         }
     158             :     }
     159             : 
     160      108422 :     return;
     161             : }
     162             : 
     163             : 
     164             : /*-----------------------------------------------------------------------------------------*
     165             :  * Function ivas_map_prior_coeffs_quant()
     166             :  *
     167             :  * Map prior coeffs
     168             :  *-----------------------------------------------------------------------------------------*/
     169             : 
     170     5152298 : void ivas_map_prior_coeffs_quant(
     171             :     ivas_spar_md_prev_t *pSpar_md_prior,
     172             :     ivas_spar_md_com_cfg *pSpar_md_cfg,
     173             :     const int16_t qsi,
     174             :     const int16_t nB )
     175             : {
     176             :     int16_t i, j;
     177             : 
     178     5152298 :     if ( qsi != pSpar_md_cfg->prev_quant_idx )
     179             :     {
     180       27876 :         ivas_quant_strat_t qs = pSpar_md_cfg->quant_strat[qsi];
     181       27876 :         ivas_quant_strat_t prev_qs = pSpar_md_cfg->quant_strat[pSpar_md_cfg->prev_quant_idx];
     182       27876 :         float one_by_q_lvl_PR = 1.0f / max( prev_qs.PR.q_levels[0] - 1, 1 );
     183       27876 :         float one_by_q_lvl_C = 1.0f / max( prev_qs.C.q_levels[0] - 1, 1 );
     184       27876 :         float one_by_q_lvl_P_r = 1.0f / max( prev_qs.P_r.q_levels[0] - 1, 1 );
     185      250884 :         for ( i = 0; i < nB; i++ )
     186             :         {
     187     2453088 :             for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ )
     188             :             {
     189     2230080 :                 pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = (int16_t) round( ( qs.PR.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j] * one_by_q_lvl_PR );
     190     2230080 :                 pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = (int16_t) round( ( qs.P_r.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j] * one_by_q_lvl_P_r );
     191             :             }
     192     4906176 :             for ( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ )
     193             :             {
     194     4683168 :                 pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = (int16_t) round( ( qs.C.q_levels[0] - 1 ) * pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j] * one_by_q_lvl_C );
     195             :             }
     196             :         }
     197             :     }
     198             :     else
     199             :     {
     200    46119798 :         for ( i = 0; i < nB; i++ )
     201             :         {
     202   450949136 :             for ( j = 0; j < IVAS_SPAR_MAX_CH - 1; j++ )
     203             :             {
     204   409953760 :                 pSpar_md_prior->band_coeffs_idx_mapped[i].pred_index_re[j] = pSpar_md_prior->band_coeffs_idx[i].pred_index_re[j];
     205   409953760 :                 pSpar_md_prior->band_coeffs_idx_mapped[i].decd_index_re[j] = pSpar_md_prior->band_coeffs_idx[i].decd_index_re[j];
     206             :             }
     207   901898272 :             for ( j = 0; j < IVAS_SPAR_MAX_C_COEFF; j++ )
     208             :             {
     209   860902896 :                 pSpar_md_prior->band_coeffs_idx_mapped[i].drct_index_re[j] = pSpar_md_prior->band_coeffs_idx[i].drct_index_re[j];
     210             :             }
     211             :         }
     212             :     }
     213             : 
     214     5152298 :     return;
     215             : }
     216             : 
     217             : 
     218             : /*-----------------------------------------------------------------------------------------*
     219             :  * Function ivas_spar_quant_dtx_init()
     220             :  *
     221             :  * Init SPAR MD with minmax vals
     222             :  *-----------------------------------------------------------------------------------------*/
     223             : 
     224       75918 : void ivas_spar_quant_dtx_init(
     225             :     ivas_spar_md_t *spar_md,
     226             :     float *min_max )
     227             : {
     228       75918 :     spar_md->min_max[0] = min_max[0];
     229       75918 :     spar_md->min_max[1] = min_max[1];
     230             : 
     231       75918 :     return;
     232             : }
     233             : 
     234             : 
     235             : /*-----------------------------------------------------------------------------------------*
     236             :  * Function ivas_copy_band_coeffs_idx_to_arr()
     237             :  *
     238             :  * Copy pred band coeffs to arr
     239             :  *-----------------------------------------------------------------------------------------*/
     240             : 
     241    37072040 : void ivas_copy_band_coeffs_idx_to_arr(
     242             :     ivas_band_coeffs_ind_t *pBands_idx,
     243             :     const int16_t nB,
     244             :     int16_t *pSymbol_re,
     245             :     ivas_cell_dim_t *pCell_dims,
     246             :     const ivas_coeffs_type_t coeff_type )
     247             : {
     248             :     int16_t i, len;
     249    37072040 :     int16_t *pPtr_idx = NULL;
     250             : 
     251   331762828 :     for ( i = 0; i < nB; i++ )
     252             :     {
     253   294690788 :         switch ( coeff_type )
     254             :         {
     255    74453820 :             case PRED_COEFF:
     256             :             {
     257    74453820 :                 pPtr_idx = pBands_idx[i].pred_index_re;
     258    74453820 :                 break;
     259             :             }
     260    74285984 :             case DRCT_COEFF:
     261             :             {
     262    74285984 :                 pPtr_idx = pBands_idx[i].drct_index_re;
     263    74285984 :                 break;
     264             :             }
     265    74283648 :             case DECD_COEFF:
     266             :             {
     267    74283648 :                 pPtr_idx = pBands_idx[i].decd_index_re;
     268    74283648 :                 break;
     269             :             }
     270    71667336 :             case DECX_COEFF:
     271             :             {
     272    71667336 :                 break;
     273             :             }
     274             :         }
     275   294690788 :         len = pCell_dims[i].dim1 * pCell_dims[i].dim2;
     276   294690788 :         if ( ( coeff_type != DECX_COEFF ) )
     277             :         {
     278   223023452 :             mvs2s( pPtr_idx, pSymbol_re, len );
     279   223023452 :             pSymbol_re += len;
     280             :         }
     281             :     }
     282             : 
     283             : 
     284    37072040 :     return;
     285             : }
     286             : 
     287             : 
     288             : /*-----------------------------------------------------------------------------------------*
     289             :  * Function ivas_clear_band_coeffs()
     290             :  *
     291             :  * clear band coeffs array in SPAR MD
     292             :  *-----------------------------------------------------------------------------------------*/
     293             : 
     294      165633 : void ivas_clear_band_coeffs(
     295             :     ivas_band_coeffs_t *pband_coeffs,
     296             :     const uint16_t num_bands )
     297             : {
     298             :     uint16_t i;
     299             : 
     300     2153229 :     for ( i = 0; i < num_bands; i++ )
     301             :     {
     302     1987596 :         set_zero( (float *) pband_coeffs[i].C_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
     303     1987596 :         set_zero( (float *) pband_coeffs[i].P_re, ( IVAS_SPAR_MAX_CH - 1 ) );
     304     1987596 :         set_zero( (float *) pband_coeffs[i].C_quant_re, ( IVAS_SPAR_MAX_CH - IVAS_SPAR_MAX_DMX_CHS ) * ( IVAS_SPAR_MAX_DMX_CHS - 1 ) );
     305     1987596 :         set_zero( (float *) pband_coeffs[i].P_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) );
     306     1987596 :         set_zero( pband_coeffs[i].pred_re, ( IVAS_SPAR_MAX_CH - 1 ) );
     307     1987596 :         set_zero( pband_coeffs[i].pred_quant_re, ( IVAS_SPAR_MAX_CH - 1 ) );
     308             :     }
     309             : 
     310      165633 :     return;
     311             : }
     312             : 
     313             : 
     314             : /*-----------------------------------------------------------------------------------------*
     315             :  * Function ivas_clear_band_coeff_idx()
     316             :  *
     317             :  * clear band coeffs index array in SPAR MD
     318             :  *-----------------------------------------------------------------------------------------*/
     319             : 
     320      277905 : void ivas_clear_band_coeff_idx(
     321             :     ivas_band_coeffs_ind_t *pband_coeff_idx,
     322             :     const uint16_t num_bands )
     323             : {
     324      277905 :     uint16_t i = 0;
     325             : 
     326     3612765 :     for ( i = 0; i < num_bands; i++ )
     327             :     {
     328     3334860 :         set_s( pband_coeff_idx[i].pred_index_re, 0, ( IVAS_SPAR_MAX_CH - 1 ) );
     329     3334860 :         set_s( pband_coeff_idx[i].drct_index_re, 0, IVAS_SPAR_MAX_C_COEFF );
     330     3334860 :         set_s( pband_coeff_idx[i].decd_index_re, 0, ( IVAS_SPAR_MAX_CH - 1 ) );
     331             :     }
     332             : 
     333      277905 :     return;
     334             : }

Generated by: LCOV version 1.14