LCOV - code coverage report
Current view: top level - lib_com - ivas_entropy_coder_common_fx.c (source / functions) Hit Total Coverage
Test: Coverage on main -- dec/rend @ 4c82f1d24d39d0296b18d775f18a006f4c7d024b Lines: 198 276 71.7 %
Date: 2025-05-17 01:59:02 Functions: 9 9 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             : #include "ivas_rom_com.h"
      36             : #include "math.h"
      37             : #include "prot_fx.h"
      38             : #include "wmc_auto.h"
      39             : #include "ivas_prot_fx.h"
      40             : 
      41             : 
      42             : /*-----------------------------------------------------------------------------------------*
      43             :  * Function ivas_wrap_arround)
      44             :  *
      45             :  * wrap around
      46             :  *-----------------------------------------------------------------------------------------*/
      47             : 
      48      223962 : void ivas_wrap_arround_fx(
      49             :     Word16 *pArr,
      50             :     const Word16 min_val,
      51             :     const Word16 max_val,
      52             :     const Word16 length )
      53             : {
      54             :     Word16 i;
      55             : 
      56     3095748 :     FOR( i = 0; i < length; i++ )
      57             :     {
      58     2871786 :         IF( LT_16( pArr[i], min_val ) )
      59             :         {
      60         311 :             pArr[i] = add( sub( max_val, min_val ), add( pArr[i], 1 ) );
      61         311 :             move16();
      62             :         }
      63     2871786 :         IF( GT_16( pArr[i], max_val ) )
      64             :         {
      65         890 :             pArr[i] = sub( add( min_val, pArr[i] ), add( max_val, 1 ) );
      66         890 :             move16();
      67             :         }
      68             :     }
      69             : 
      70      223962 :     return;
      71             : }
      72             : 
      73             : 
      74             : /*-----------------------------------------------------------------------------------------*
      75             :  * Function ivas_get_cum_freq_model()
      76             :  *
      77             :  * get cumulative frequency model
      78             :  *-----------------------------------------------------------------------------------------*/
      79             : 
      80      127008 : void ivas_get_cum_freq_model_fx(
      81             :     const Word16 *pFreq_model,
      82             :     const Word16 length,
      83             :     Word16 *pCum_freq_model )
      84             : {
      85             :     Word16 i;
      86             : 
      87      127008 :     pCum_freq_model[length] = 0;
      88      127008 :     move16();
      89             : 
      90     1184480 :     FOR( i = length; i > 0; i-- )
      91             :     {
      92     1057472 :         pCum_freq_model[i - 1] = add( pCum_freq_model[i], pFreq_model[i] );
      93     1057472 :         move16();
      94             :     }
      95             : 
      96      127008 :     return;
      97             : }
      98             : 
      99             : 
     100             : /*-----------------------------------------------------------------------------------------*
     101             :  * Function ivas_map_num_pred_r_to_idx()
     102             :  *
     103             :  * Map the ivas_arith_pred_r_consts and ivas_huff_pred_r_consts tables
     104             :  *-----------------------------------------------------------------------------------------*/
     105             : 
     106       10584 : Word16 ivas_map_num_pred_r_to_idx_fx(
     107             :     const Word16 num_quant_points_pred_r,
     108             :     const Word16 active_w_flag )
     109             : {
     110       10584 :     Word16 pred_r_to_idx = -1;
     111       10584 :     move16();
     112       10584 :     IF( active_w_flag == 0 )
     113             :     {
     114        8655 :         SWITCH( num_quant_points_pred_r )
     115             :         {
     116        1260 :             case 1:
     117        1260 :                 pred_r_to_idx = PRED_Q_1;
     118        1260 :                 move16();
     119        1260 :                 BREAK;
     120         642 :             case 7:
     121         642 :                 pred_r_to_idx = PRED_Q_7;
     122         642 :                 move16();
     123         642 :                 BREAK;
     124        2694 :             case 15:
     125        2694 :                 pred_r_to_idx = PRED_Q_15;
     126        2694 :                 move16();
     127        2694 :                 BREAK;
     128        3429 :             case 21:
     129        3429 :                 pred_r_to_idx = PRED_Q_21;
     130        3429 :                 move16();
     131        3429 :                 BREAK;
     132         630 :             case 31:
     133         630 :                 pred_r_to_idx = PRED_Q_31;
     134         630 :                 move16();
     135         630 :                 BREAK;
     136           0 :             default:
     137           0 :                 assert( !"Forbidden value for prediction quantization strategy index" );
     138             :                 BREAK;
     139             :         }
     140             :     }
     141             :     ELSE
     142             :     {
     143        1929 :         SWITCH( num_quant_points_pred_r )
     144             :         {
     145         486 :             case 7:
     146         486 :                 pred_r_to_idx = PRED_Q_7_ACTIVE_W;
     147         486 :                 move16();
     148         486 :                 BREAK;
     149        1286 :             case 15:
     150        1286 :                 pred_r_to_idx = PRED_Q_15_ACTIVE_W;
     151        1286 :                 move16();
     152        1286 :                 BREAK;
     153         157 :             case 21:
     154         157 :                 pred_r_to_idx = PRED_Q_21_ACTIVE_W;
     155         157 :                 move16();
     156         157 :                 BREAK;
     157           0 :             default:
     158           0 :                 assert( !"Forbidden value for prediction quantization strategy index" );
     159             :                 BREAK;
     160             :         }
     161             :     }
     162             : 
     163       10584 :     return pred_r_to_idx;
     164             : }
     165             : 
     166             : 
     167             : /*-----------------------------------------------------------------------------------------*
     168             :  * Function ivas_map_num_drct_r_to_idx()
     169             :  *
     170             :  * Map the ivas_arith_drct_r_consts and ivas_huff_drct_r_consts tables
     171             :  *-----------------------------------------------------------------------------------------*/
     172             : 
     173       10584 : Word16 ivas_map_num_drct_r_to_idx_fx(
     174             :     const Word16 num_quant_points_drct_r )
     175             : {
     176       10584 :     Word16 drct_r_to_idx = -1;
     177       10584 :     move16();
     178       10584 :     SWITCH( num_quant_points_drct_r )
     179             :     {
     180        5268 :         case 1:
     181        5268 :             drct_r_to_idx = DRCT_Q_1;
     182        5268 :             move16();
     183        5268 :             BREAK;
     184        3284 :         case 7:
     185        3284 :             drct_r_to_idx = DRCT_Q_7;
     186        3284 :             move16();
     187        3284 :             BREAK;
     188         908 :         case 9:
     189         908 :             drct_r_to_idx = DRCT_Q_9;
     190         908 :             move16();
     191         908 :             BREAK;
     192        1124 :         case 11:
     193        1124 :             drct_r_to_idx = DRCT_Q_11;
     194        1124 :             move16();
     195        1124 :             BREAK;
     196           0 :         default:
     197           0 :             assert( !"Forbidden value for DRCT quantization strategy index" );
     198             :             BREAK;
     199             :     }
     200       10584 :     return drct_r_to_idx;
     201             : }
     202             : 
     203             : 
     204             : /*-----------------------------------------------------------------------------------------*
     205             :  * Function ivas_map_num_decd_r_to_idx()
     206             :  *
     207             :  * Map the ivas_arith_decd_r_consts and ivas_huff_decd_r_consts tables
     208             :  *-----------------------------------------------------------------------------------------*/
     209             : 
     210       10584 : Word16 ivas_map_num_decd_r_to_idx_fx(
     211             :     const Word16 num_quant_points_decd_r )
     212             : {
     213       10584 :     Word16 decd_r_to_idx = -1;
     214       10584 :     move16();
     215       10584 :     SWITCH( num_quant_points_decd_r )
     216             :     {
     217        1410 :         case 1:
     218        1410 :             decd_r_to_idx = DECD_Q_1;
     219        1410 :             move16();
     220        1410 :             BREAK;
     221        3118 :         case 3:
     222        3118 :             decd_r_to_idx = DECD_Q_3;
     223        3118 :             move16();
     224        3118 :             BREAK;
     225        3380 :         case 5:
     226        3380 :             decd_r_to_idx = DECD_Q_5;
     227        3380 :             move16();
     228        3380 :             BREAK;
     229         850 :         case 7:
     230         850 :             decd_r_to_idx = DECD_Q_7;
     231         850 :             move16();
     232         850 :             BREAK;
     233         908 :         case 9:
     234         908 :             decd_r_to_idx = DECD_Q_9;
     235         908 :             move16();
     236         908 :             BREAK;
     237         918 :         case 11:
     238         918 :             decd_r_to_idx = DECD_Q_11;
     239         918 :             move16();
     240         918 :             BREAK;
     241           0 :         default:
     242           0 :             assert( !"Forbidden value for DECD quantization strategy index" );
     243             :             BREAK;
     244             :     }
     245             : 
     246       10584 :     return decd_r_to_idx;
     247             : }
     248             : 
     249             : 
     250             : /*---------------------------------------------------------------------------------------- - *
     251             :  * Function ivas_spar_arith_com_init()
     252             :  *
     253             :  * arith coder init
     254             :  *---------------------------------------------------------------------------------------- - */
     255             : 
     256       15876 : static void ivas_spar_arith_com_init_fx(
     257             :     ivas_arith_t *pArith,
     258             :     const ivas_freq_models_t *pFreq_models,
     259             :     ivas_arith_t *pArith_diff,
     260             :     const Word16 q_levels,
     261             :     const Word16 enc_dec )
     262             : {
     263             :     Word16 i, j;
     264             :     Word16 sum, log2_int, log2_frac;
     265             :     Word32 tmp32, log2_int32, L_tmp1, L_tmp2;
     266             : 
     267       15876 :     pArith->vals = pFreq_models->vals;
     268       15876 :     pArith->range = q_levels;
     269       15876 :     move16();
     270       15876 :     pArith->num_models = pFreq_models->num_models;
     271       15876 :     move16();
     272       15876 :     pArith->dyn_model_bits = ivas_get_bits_to_encode( pArith->num_models - 1 );
     273       15876 :     move16();
     274       15876 :     pArith->pFreq_model = pFreq_models->freq_model[0];
     275             : 
     276       15876 :     ivas_get_cum_freq_model_fx( pArith->pFreq_model, pArith->range, pArith->cum_freq[0] );
     277             : 
     278       63504 :     FOR( i = 0; i < pArith->num_models - 1; i++ )
     279             :     {
     280       47628 :         pArith->pAlt_freq_models[i] = pFreq_models->freq_model[i + 1];
     281       47628 :         ivas_get_cum_freq_model_fx( pArith->pAlt_freq_models[i], pArith->range, pArith->cum_freq[i + 1] );
     282             :     }
     283             : 
     284       15876 :     IF( enc_dec == ENC )
     285             :     {
     286           0 :         sum = 0;
     287           0 :         move16();
     288           0 :         FOR( i = 1; i < pArith->range + 1; i++ )
     289             :         {
     290           0 :             sum = add( sum, pArith->pFreq_model[i] );
     291             :         }
     292           0 :         log2_int = norm_s( sum );
     293           0 :         tmp32 = L_deposit_h( shl( sum, log2_int ) );
     294           0 :         log2_frac = Log2_norm_lc( tmp32 );
     295           0 :         log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 );
     296           0 :         L_tmp2 = L_add( log2_int32, log2_frac ); /* Q15 */
     297           0 :         FOR( i = 1; i < pArith->range + 1; i++ )
     298             :         {
     299           0 :             log2_int = norm_s( pArith->pFreq_model[i] );
     300           0 :             tmp32 = L_deposit_h( shl( pArith->pFreq_model[i], log2_int ) );
     301           0 :             log2_frac = Log2_norm_lc( tmp32 );
     302           0 :             log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 );
     303           0 :             L_tmp1 = L_add( log2_int32, log2_frac ); /* Q15 */
     304           0 :             pArith->saved_dist_arr[0][i - 1] = L_sub( L_tmp1, L_tmp2 );
     305           0 :             move32();
     306             :         }
     307             : 
     308           0 :         FOR( j = 0; j < pArith->num_models - 1; j++ )
     309             :         {
     310           0 :             sum = 0;
     311           0 :             move16();
     312           0 :             FOR( i = 1; i < pArith->range + 1; i++ )
     313             :             {
     314           0 :                 sum = add( sum, pArith->pAlt_freq_models[j][i] );
     315             :             }
     316           0 :             log2_int = norm_s( sum );
     317           0 :             tmp32 = L_deposit_h( shl( sum, log2_int ) );
     318           0 :             log2_frac = Log2_norm_lc( tmp32 );
     319           0 :             log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 );
     320           0 :             L_tmp2 = L_add( log2_int32, log2_frac ); /* Q15 */
     321           0 :             FOR( i = 1; i < pArith->range + 1; i++ )
     322             :             {
     323           0 :                 log2_int = norm_s( pArith->pAlt_freq_models[j][i] );
     324           0 :                 tmp32 = L_deposit_h( shl( pArith->pAlt_freq_models[j][i], log2_int ) );
     325           0 :                 log2_frac = Log2_norm_lc( tmp32 );
     326           0 :                 log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 );
     327           0 :                 L_tmp1 = L_add( log2_int32, log2_frac ); /* Q15 */
     328           0 :                 pArith->saved_dist_arr[j + 1][i - 1] = L_sub( L_tmp1, L_tmp2 );
     329           0 :                 move32();
     330             :             }
     331             :         }
     332             :     }
     333             : 
     334       15876 :     pArith_diff->vals = pFreq_models->diff_vals;
     335       15876 :     pArith_diff->range = q_levels;
     336       15876 :     move16();
     337       15876 :     pArith_diff->num_models = pFreq_models->diff_num_models;
     338       15876 :     move16();
     339       15876 :     pArith_diff->dyn_model_bits = ivas_get_bits_to_encode( pArith_diff->num_models - 1 );
     340       15876 :     move16();
     341       15876 :     pArith_diff->pFreq_model = pFreq_models->diff_freq_model[0];
     342             : 
     343       15876 :     ivas_get_cum_freq_model_fx( pArith_diff->pFreq_model, pArith_diff->range, pArith_diff->cum_freq[0] );
     344             : 
     345       63504 :     FOR( i = 0; i < pArith_diff->num_models - 1; i++ )
     346             :     {
     347       47628 :         pArith_diff->pAlt_freq_models[i] = pFreq_models->diff_freq_model[i + 1];
     348       47628 :         ivas_get_cum_freq_model_fx( pArith_diff->pAlt_freq_models[i], pArith_diff->range, pArith_diff->cum_freq[i + 1] );
     349             :     }
     350             : 
     351       15876 :     IF( enc_dec == ENC )
     352             :     {
     353           0 :         sum = 0;
     354           0 :         move16();
     355           0 :         FOR( i = 1; i < pArith_diff->range + 1; i++ )
     356             :         {
     357           0 :             sum = add( sum, pArith_diff->pFreq_model[i] );
     358             :         }
     359           0 :         log2_int = norm_s( sum );
     360           0 :         tmp32 = L_deposit_h( shl( sum, log2_int ) );
     361           0 :         log2_frac = Log2_norm_lc( tmp32 );
     362           0 :         log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 );
     363           0 :         L_tmp2 = L_add( log2_int32, log2_frac ); /* Q15 */
     364           0 :         FOR( i = 1; i < pArith_diff->range + 1; i++ )
     365             :         {
     366           0 :             log2_int = norm_s( pArith_diff->pFreq_model[i] );
     367           0 :             tmp32 = L_deposit_h( shl( pArith_diff->pFreq_model[i], log2_int ) );
     368           0 :             log2_frac = Log2_norm_lc( tmp32 );
     369           0 :             log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 );
     370           0 :             L_tmp1 = L_add( log2_int32, log2_frac ); /* Q15 */
     371           0 :             pArith_diff->saved_dist_arr[0][i - 1] = L_sub( L_tmp1, L_tmp2 );
     372           0 :             move32();
     373             :         }
     374             : 
     375           0 :         FOR( j = 0; j < pArith_diff->num_models - 1; j++ )
     376             :         {
     377           0 :             sum = 0;
     378           0 :             move16();
     379           0 :             FOR( i = 1; i < pArith_diff->range + 1; i++ )
     380             :             {
     381           0 :                 sum = add( sum, pArith_diff->pAlt_freq_models[j][i] );
     382             :             }
     383           0 :             log2_int = norm_s( sum );
     384           0 :             tmp32 = L_deposit_h( shl( sum, log2_int ) );
     385           0 :             log2_frac = Log2_norm_lc( tmp32 );
     386           0 :             log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 );
     387           0 :             L_tmp2 = L_add( log2_int32, log2_frac ); /* Q15 */
     388           0 :             FOR( i = 1; i < pArith_diff->range + 1; i++ )
     389             :             {
     390           0 :                 log2_int = norm_s( pArith_diff->pAlt_freq_models[j][i] );
     391           0 :                 tmp32 = L_deposit_h( shl( pArith_diff->pAlt_freq_models[j][i], log2_int ) );
     392           0 :                 log2_frac = Log2_norm_lc( tmp32 );
     393           0 :                 log2_int32 = L_shl( sub( sub( 30, log2_int ), 16 ), 15 );
     394           0 :                 L_tmp1 = L_add( log2_int32, log2_frac ); /* Q15 */
     395           0 :                 pArith_diff->saved_dist_arr[j + 1][i - 1] = L_sub( L_tmp1, L_tmp2 );
     396           0 :                 move32();
     397             :             }
     398             :         }
     399             :     }
     400             : 
     401       15876 :     return;
     402             : }
     403             : 
     404             : 
     405             : /*-----------------------------------------------------------------------------------------*
     406             :  * Function ivas_spar_arith_coeffs_com_init()
     407             :  *
     408             :  * Init for Arithm. coding
     409             :  *-----------------------------------------------------------------------------------------*/
     410             : 
     411        1764 : void ivas_spar_arith_coeffs_com_init_fx(
     412             :     ivas_arith_coeffs_t *pArith_coeffs,
     413             :     ivas_spar_md_com_cfg *pSpar_cfg,
     414             :     const Word16 table_idx,
     415             :     const Word16 enc_dec )
     416             : {
     417             :     Word16 i, pred_r_index, drct_r_index, decd_r_index;
     418             :     Word16 num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r;
     419             : 
     420        7056 :     FOR( i = 0; i < MAX_QUANT_STRATS; i++ )
     421             :     {
     422        5292 :         num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */
     423        5292 :         move16();
     424        5292 :         pred_r_index = ivas_map_num_pred_r_to_idx_fx( num_quant_points_pred_r, ivas_spar_br_table_consts[table_idx].active_w );
     425        5292 :         ivas_spar_arith_com_init_fx( &pArith_coeffs->pred_arith_re[i], &ivas_arith_pred_r_consts[pred_r_index],
     426        5292 :                                      &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec );
     427             : 
     428        5292 :         num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */
     429        5292 :         move16();
     430        5292 :         drct_r_index = ivas_map_num_drct_r_to_idx_fx( num_quant_points_drct_r );
     431        5292 :         ivas_spar_arith_com_init_fx( &pArith_coeffs->drct_arith_re[i], &ivas_arith_drct_r_consts[drct_r_index],
     432        5292 :                                      &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec );
     433             : 
     434        5292 :         num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */
     435        5292 :         move16();
     436        5292 :         decd_r_index = ivas_map_num_decd_r_to_idx_fx( num_quant_points_decd_r );
     437        5292 :         ivas_spar_arith_com_init_fx( &pArith_coeffs->decd_arith_re[i], &ivas_arith_decd_r_consts[decd_r_index],
     438        5292 :                                      &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec );
     439             :     }
     440             : 
     441        1764 :     return;
     442             : }
     443             : 
     444             : 
     445             : /*-----------------------------------------------------------------------------------------*
     446             :  * Function ivas_huffman_dec_init_min_max_len()
     447             :  *
     448             :  * Find min and max length in codebook and finalize initialization of ivas_huffman_cfg_t.
     449             :  *-----------------------------------------------------------------------------------------*/
     450             : 
     451       15876 : static void ivas_huffman_dec_init_min_max_len_fx(
     452             :     ivas_huffman_cfg_t *p_huff_cfg )
     453             : {
     454             :     Word16 i, code_len;
     455             :     const Word16 *codebook;
     456             : 
     457       15876 :     codebook = p_huff_cfg->codebook;
     458             : 
     459       15876 :     p_huff_cfg->min_len = p_huff_cfg->sym_len;
     460       15876 :     move16();
     461       15876 :     p_huff_cfg->max_len = 0;
     462       15876 :     move16();
     463             : 
     464      148060 :     FOR( i = 0; i < p_huff_cfg->sym_len; i++ )
     465             :     {
     466      132184 :         code_len = codebook[1];
     467      132184 :         move16();
     468      132184 :         if ( GT_16( p_huff_cfg->min_len, code_len ) )
     469             :         {
     470       27358 :             p_huff_cfg->min_len = code_len;
     471       27358 :             move16();
     472             :         }
     473      132184 :         if ( LT_16( p_huff_cfg->max_len, code_len ) )
     474             :         {
     475       11907 :             p_huff_cfg->max_len = code_len;
     476       11907 :             move16();
     477             :         }
     478      132184 :         codebook = codebook + 3;
     479             :     }
     480             : 
     481       15876 :     return;
     482             : }
     483             : 
     484             : 
     485             : /*-----------------------------------------------------------------------------------------*
     486             :  * Function ivas_spar_huff_coeffs_com_init()
     487             :  *
     488             :  * Init for Huffman decoding
     489             :  *-----------------------------------------------------------------------------------------*/
     490             : 
     491        1764 : void ivas_spar_huff_coeffs_com_init_fx(
     492             :     ivas_huff_coeffs_t *pHuff_coeffs,
     493             :     ivas_spar_md_com_cfg *pSpar_cfg,
     494             :     const Word16 table_idx,
     495             :     const Word16 enc_dec )
     496             : {
     497             :     Word16 i, pred_r_index, drct_r_index, decd_r_index;
     498             :     Word16 num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r;
     499             :     ivas_huffman_cfg_t *p_huff_cfg;
     500             : 
     501        7056 :     FOR( i = 0; i < MAX_QUANT_STRATS; i++ )
     502             :     {
     503        5292 :         p_huff_cfg = &pHuff_coeffs->pred_huff_re[i];
     504        5292 :         num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */
     505        5292 :         move16();
     506        5292 :         pred_r_index = ivas_map_num_pred_r_to_idx_fx( num_quant_points_pred_r, 0 );
     507        5292 :         p_huff_cfg->codebook = &ivas_huff_pred_r_consts[pred_r_index].code_book[0][0];
     508        5292 :         IF( EQ_16( enc_dec, DEC ) )
     509             :         {
     510        5292 :             p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].PR.q_levels[0];
     511        5292 :             move16();
     512        5292 :             ivas_huffman_dec_init_min_max_len_fx( p_huff_cfg );
     513             :         }
     514             : 
     515        5292 :         p_huff_cfg = &pHuff_coeffs->drct_huff_re[i];
     516        5292 :         num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */
     517        5292 :         move16();
     518        5292 :         drct_r_index = ivas_map_num_drct_r_to_idx_fx( num_quant_points_drct_r );
     519        5292 :         p_huff_cfg->codebook = &ivas_huff_drct_r_consts[drct_r_index].code_book[0][0];
     520        5292 :         IF( EQ_16( enc_dec, DEC ) )
     521             :         {
     522        5292 :             p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].C.q_levels[0];
     523        5292 :             move16();
     524        5292 :             ivas_huffman_dec_init_min_max_len_fx( p_huff_cfg );
     525             :         }
     526             : 
     527        5292 :         p_huff_cfg = &pHuff_coeffs->decd_huff_re[i];
     528        5292 :         num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */
     529        5292 :         move16();
     530        5292 :         decd_r_index = ivas_map_num_decd_r_to_idx_fx( num_quant_points_decd_r );
     531        5292 :         p_huff_cfg->codebook = &ivas_huff_decd_r_consts[decd_r_index].code_book[0][0];
     532        5292 :         IF( EQ_16( enc_dec, DEC ) )
     533             :         {
     534        5292 :             p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].P_r.q_levels[0];
     535        5292 :             move16();
     536        5292 :             ivas_huffman_dec_init_min_max_len_fx( p_huff_cfg );
     537             :         }
     538             :     }
     539             : 
     540        1764 :     return;
     541             : }

Generated by: LCOV version 1.14