diff --git a/lib_com/cnst.h b/lib_com/cnst.h index 5933e0418ccf95ef87f28d1c98761ae08afc3ceb..ac0a4bf82783b396c484002683a8264514f866aa 100644 --- a/lib_com/cnst.h +++ b/lib_com/cnst.h @@ -1248,6 +1248,7 @@ enum #define WINDECAY16 410 #define N16_CORE_SW 90 #define N_ZERO_8 45 +#define N_ZERO_BY_FS 9216 /* == N_ZERO_MDCT_NS / FRAME_SIZE_NS in Q15 */ #define SWITCH_OVERLAP_8k 15 /* == NS2SA(8000, SWITCH_GAP_LENGTH_NS) - NS2SA(8000, 10000000.0f - N_ZERO_MDCT_NS) */ #define SWITCH_GAP_LENGTH_8k 50 diff --git a/lib_com/ivas_entropy_coder_common.c b/lib_com/ivas_entropy_coder_common.c index 7696932cb033e3cc78967ac444a04d6c61efcdc9..2f3eacb5b21d68632c281ce95fdc3d6c0ed258ff 100644 --- a/lib_com/ivas_entropy_coder_common.c +++ b/lib_com/ivas_entropy_coder_common.c @@ -46,22 +46,22 @@ *-----------------------------------------------------------------------------------------*/ void ivas_wrap_arround( - int16_t *pArr, - const int16_t min_val, - const int16_t max_val, - const int16_t length ) + Word16 *pArr, + const Word16 min_val, + const Word16 max_val, + const Word16 length ) { - int16_t i; + Word16 i; - for ( i = 0; i < length; i++ ) + FOR ( i = 0; i < length; i++ ) { - if ( pArr[i] < min_val ) + IF ( LT_16(pArr[i], min_val) ) { - pArr[i] = max_val - min_val + pArr[i] + 1; + pArr[i] = add(sub(max_val, min_val), add( pArr[i], 1)); } - if ( pArr[i] > max_val ) + IF ( GT_16(pArr[i], max_val) ) { - pArr[i] = min_val + pArr[i] - max_val - 1; + pArr[i] = sub(add(min_val, pArr[i]), add(max_val, 1)); } } @@ -76,17 +76,17 @@ void ivas_wrap_arround( *-----------------------------------------------------------------------------------------*/ void ivas_get_cum_freq_model( - const int16_t *pFreq_model, - const int16_t length, - int16_t *pCum_freq_model ) + const Word16 *pFreq_model, + const Word16 length, + Word16 *pCum_freq_model ) { - int16_t i; + Word16 i; pCum_freq_model[length] = 0; - for ( i = length; i > 0; i-- ) + FOR ( i = length; i > 0; i-- ) { - pCum_freq_model[i - 1] = pCum_freq_model[i] + pFreq_model[i]; + pCum_freq_model[i - 1] = add(pCum_freq_model[i], pFreq_model[i]); } return; @@ -99,51 +99,51 @@ void ivas_get_cum_freq_model( * Map the ivas_arith_pred_r_consts and ivas_huff_pred_r_consts tables *-----------------------------------------------------------------------------------------*/ -int16_t ivas_map_num_pred_r_to_idx( - const int16_t num_quant_points_pred_r, - const int16_t active_w_flag ) +Word16 ivas_map_num_pred_r_to_idx( + const Word16 num_quant_points_pred_r, + const Word16 active_w_flag ) { - int16_t pred_r_to_idx = -1; - if ( active_w_flag == 0 ) + Word16 pred_r_to_idx = -1; + IF ( EQ_16(active_w_flag, 0) ) { - switch ( num_quant_points_pred_r ) + SWITCH ( num_quant_points_pred_r ) { case 1: pred_r_to_idx = PRED_Q_1; - break; + BREAK; case 7: pred_r_to_idx = PRED_Q_7; - break; + BREAK; case 15: pred_r_to_idx = PRED_Q_15; - break; + BREAK; case 21: pred_r_to_idx = PRED_Q_21; - break; + BREAK; case 31: pred_r_to_idx = PRED_Q_31; - break; + BREAK; default: assert( !"Forbidden value for prediction quantization strategy index" ); - break; + BREAK; } } - else + ELSE { - switch ( num_quant_points_pred_r ) + SWITCH ( num_quant_points_pred_r ) { case 7: pred_r_to_idx = PRED_Q_7_ACTIVE_W; - break; + BREAK; case 15: pred_r_to_idx = PRED_Q_15_ACTIVE_W; - break; + BREAK; case 21: pred_r_to_idx = PRED_Q_21_ACTIVE_W; - break; + BREAK; default: assert( !"Forbidden value for prediction quantization strategy index" ); - break; + BREAK; } } @@ -157,27 +157,27 @@ int16_t ivas_map_num_pred_r_to_idx( * Map the ivas_arith_drct_r_consts and ivas_huff_drct_r_consts tables *-----------------------------------------------------------------------------------------*/ -int16_t ivas_map_num_drct_r_to_idx( - const int16_t num_quant_points_drct_r ) +Word16 ivas_map_num_drct_r_to_idx( + const Word16 num_quant_points_drct_r ) { - int16_t drct_r_to_idx = -1; - switch ( num_quant_points_drct_r ) + Word16 drct_r_to_idx = -1; + SWITCH ( num_quant_points_drct_r ) { case 1: drct_r_to_idx = DRCT_Q_1; - break; + BREAK; case 7: drct_r_to_idx = DRCT_Q_7; - break; + BREAK; case 9: drct_r_to_idx = DRCT_Q_9; - break; + BREAK; case 11: drct_r_to_idx = DRCT_Q_11; - break; + BREAK; default: assert( !"Forbidden value for DRCT quantization strategy index" ); - break; + BREAK; } return drct_r_to_idx; } @@ -189,39 +189,40 @@ int16_t ivas_map_num_drct_r_to_idx( * Map the ivas_arith_decd_r_consts and ivas_huff_decd_r_consts tables *-----------------------------------------------------------------------------------------*/ -int16_t ivas_map_num_decd_r_to_idx( - const int16_t num_quant_points_decd_r ) +Word16 ivas_map_num_decd_r_to_idx( + const Word16 num_quant_points_decd_r ) { - int16_t decd_r_to_idx = -1; - switch ( num_quant_points_decd_r ) + Word16 decd_r_to_idx = -1; + SWITCH ( num_quant_points_decd_r ) { case 1: decd_r_to_idx = DECD_Q_1; - break; + BREAK; case 3: decd_r_to_idx = DECD_Q_3; - break; + BREAK; case 5: decd_r_to_idx = DECD_Q_5; - break; + BREAK; case 7: decd_r_to_idx = DECD_Q_7; - break; + BREAK; case 9: decd_r_to_idx = DECD_Q_9; - break; + BREAK; case 11: decd_r_to_idx = DECD_Q_11; - break; + BREAK; default: assert( !"Forbidden value for DECD quantization strategy index" ); - break; + BREAK; } return decd_r_to_idx; } +#ifndef IVAS_FLOAT_FIXED /*---------------------------------------------------------------------------------------- - * * Function ivas_spar_arith_com_init() * @@ -328,8 +329,151 @@ static void ivas_spar_arith_com_init( return; } +#else +/*---------------------------------------------------------------------------------------- - * + * Function ivas_spar_arith_com_init_fx() + * + * arith coder init + *---------------------------------------------------------------------------------------- - */ + +static void ivas_spar_arith_com_init_fx( + ivas_arith_t *pArith, + const ivas_freq_models_t *pFreq_models, + ivas_arith_t *pArith_diff, + const Word16 q_levels, + const Word16 enc_dec ) +{ + Word16 i, j; + Word16 sum, log2_int, log2_frac; + Word32 tmp32, log2_int32, L_tmp2; + + pArith->vals = pFreq_models->vals; + pArith->range = q_levels; + pArith->num_models = pFreq_models->num_models; + pArith->dyn_model_bits = ivas_get_bits_to_encode( pArith->num_models - 1 ); + pArith->pFreq_model = pFreq_models->freq_model[0]; + + ivas_get_cum_freq_model( pArith->pFreq_model, pArith->range, pArith->cum_freq[0] ); + + FOR ( i = 0; i < pArith->num_models - 1; i++ ) + { + pArith->pAlt_freq_models[i] = pFreq_models->freq_model[i + 1]; + ivas_get_cum_freq_model( pArith->pAlt_freq_models[i], pArith->range, pArith->cum_freq[i + 1] ); + } + IF ( EQ_16(enc_dec, ENC) ) + { + sum = 0; + FOR ( i = 1; i < pArith->range + 1; i++ ) + { + sum = add(sum, pArith->pFreq_model[i]); + } + log2_int = norm_s(sum); + tmp32 = L_deposit_h( shl( sum, log2_int ) ); + log2_frac = Log2_norm_lc(tmp32); + log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); + L_tmp2 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ + FOR ( i = 1; i < pArith->range + 1; i++ ) + { + Word32 L_tmp1; + log2_int = norm_s(pArith->pFreq_model[i]); + tmp32 = L_deposit_h( shl( pArith->pFreq_model[i], log2_int ) ); + log2_frac = Log2_norm_lc(tmp32); + log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); + L_tmp1 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ + pArith->saved_dist_arr[0][i - 1] = L_sub(L_tmp1, L_tmp2); + } + FOR ( j = 0; j < pArith->num_models - 1; j++ ) + { + sum = 0; + FOR ( i = 1; i < pArith->range + 1; i++ ) + { + sum = add(sum, pArith->pAlt_freq_models[j][i]); + } + log2_int = norm_s(sum); + tmp32 = L_deposit_h( shl( sum, log2_int ) ); + log2_frac = Log2_norm_lc(tmp32); + log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); + L_tmp2 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ + FOR ( i = 1; i < pArith->range + 1; i++ ) + { + Word32 L_tmp1; + log2_int = norm_s(pArith->pAlt_freq_models[j][i]); + tmp32 = L_deposit_h( shl( pArith->pAlt_freq_models[j][i], log2_int ) ); + log2_frac = Log2_norm_lc(tmp32); + log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); + L_tmp1 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ + pArith->saved_dist_arr[j + 1][i - 1] = L_sub(L_tmp1, L_tmp2); + } + } + } + + pArith_diff->vals = pFreq_models->diff_vals; + pArith_diff->range = q_levels; + pArith_diff->num_models = pFreq_models->diff_num_models; + pArith_diff->dyn_model_bits = ivas_get_bits_to_encode( pArith_diff->num_models - 1 ); + pArith_diff->pFreq_model = pFreq_models->diff_freq_model[0]; + + ivas_get_cum_freq_model( pArith_diff->pFreq_model, pArith_diff->range, pArith_diff->cum_freq[0] ); + + FOR ( i = 0; i < pArith_diff->num_models - 1; i++ ) + { + pArith_diff->pAlt_freq_models[i] = pFreq_models->diff_freq_model[i + 1]; + ivas_get_cum_freq_model( pArith_diff->pAlt_freq_models[i], pArith_diff->range, pArith_diff->cum_freq[i + 1] ); + } + + IF ( EQ_16(enc_dec, ENC) ) + { + sum = 0; + FOR ( i = 1; i < pArith_diff->range + 1; i++ ) + { + sum = add(sum, pArith_diff->pFreq_model[i]); + } + log2_int = norm_s(sum); + tmp32 = L_deposit_h( shl( sum, log2_int ) ); + log2_frac = Log2_norm_lc(tmp32); + log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); + L_tmp2 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ + FOR ( i = 1; i < pArith_diff->range + 1; i++ ) + { + Word32 L_tmp1; + log2_int = norm_s(pArith_diff->pFreq_model[i]); + tmp32 = L_deposit_h( shl( pArith_diff->pFreq_model[i], log2_int ) ); + log2_frac = Log2_norm_lc(tmp32); + log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); + L_tmp1 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ + pArith_diff->saved_dist_arr[0][i - 1] = L_sub(L_tmp1, L_tmp2); + } + + FOR ( j = 0; j < pArith_diff->num_models - 1; j++ ) + { + sum = 0; + FOR ( i = 1; i < pArith_diff->range + 1; i++ ) + { + sum = add(sum, pArith_diff->pAlt_freq_models[j][i]); + } + log2_int = norm_s(sum); + tmp32 = L_deposit_h( shl( sum, log2_int ) ); + log2_frac = Log2_norm_lc(tmp32); + log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); + L_tmp2 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ + FOR ( i = 1; i < pArith_diff->range + 1; i++ ) + { + Word32 L_tmp1; + log2_int = norm_s(pArith_diff->pAlt_freq_models[j][i]); + tmp32 = L_deposit_h( shl( pArith_diff->pAlt_freq_models[j][i], log2_int ) ); + log2_frac = Log2_norm_lc(tmp32); + log2_int32 = L_shl((Word32)sub(sub(30,log2_int),16), 15); + L_tmp1 = L_add(log2_int32, (Word32)log2_frac); /* Q15 */ + pArith_diff->saved_dist_arr[j + 1][i - 1] = L_sub(L_tmp1, L_tmp2); + } + } + } + + return; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_spar_arith_coeffs_com_init() * @@ -339,28 +483,41 @@ static void ivas_spar_arith_com_init( void ivas_spar_arith_coeffs_com_init( ivas_arith_coeffs_t *pArith_coeffs, ivas_spar_md_com_cfg *pSpar_cfg, - const int16_t table_idx, - const int16_t enc_dec ) + const Word16 table_idx, + const Word16 enc_dec ) { - int16_t i, pred_r_index, drct_r_index, decd_r_index; - int16_t num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r; + Word16 i, pred_r_index, drct_r_index, decd_r_index; + Word16 num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r; - for ( i = 0; i < MAX_QUANT_STRATS; i++ ) + FOR ( i = 0; i < MAX_QUANT_STRATS; i++ ) { num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */ pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, ivas_spar_br_table_consts[table_idx].active_w ); +#ifdef IVAS_FLOAT_FIXED + ivas_spar_arith_com_init_fx( &pArith_coeffs->pred_arith_re[i], &ivas_arith_pred_r_consts[pred_r_index], + &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec ); +#else ivas_spar_arith_com_init( &pArith_coeffs->pred_arith_re[i], &ivas_arith_pred_r_consts[pred_r_index], &pArith_coeffs->pred_arith_re_diff[i], pSpar_cfg->quant_strat[i].PR.q_levels[0], enc_dec ); - +#endif num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */ drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r ); +#ifdef IVAS_FLOAT_FIXED + ivas_spar_arith_com_init_fx( &pArith_coeffs->drct_arith_re[i], &ivas_arith_drct_r_consts[drct_r_index], + &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec ); +#else ivas_spar_arith_com_init( &pArith_coeffs->drct_arith_re[i], &ivas_arith_drct_r_consts[drct_r_index], &pArith_coeffs->drct_arith_re_diff[i], pSpar_cfg->quant_strat[i].C.q_levels[0], enc_dec ); - +#endif num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */ decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r ); +#ifdef IVAS_FLOAT_FIXED + ivas_spar_arith_com_init_fx( &pArith_coeffs->decd_arith_re[i], &ivas_arith_decd_r_consts[decd_r_index], + &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec ); +#else ivas_spar_arith_com_init( &pArith_coeffs->decd_arith_re[i], &ivas_arith_decd_r_consts[decd_r_index], &pArith_coeffs->decd_arith_re_diff[i], pSpar_cfg->quant_strat[i].P_r.q_levels[0], enc_dec ); +#endif } return; @@ -376,22 +533,22 @@ void ivas_spar_arith_coeffs_com_init( static void ivas_huffman_dec_init_min_max_len( ivas_huffman_cfg_t *p_huff_cfg ) { - int16_t i, code_len; - const int16_t *codebook; + Word16 i, code_len; + const Word16 *codebook; codebook = p_huff_cfg->codebook; p_huff_cfg->min_len = p_huff_cfg->sym_len; p_huff_cfg->max_len = 0; - for ( i = 0; i < p_huff_cfg->sym_len; i++ ) + FOR ( i = 0; i < p_huff_cfg->sym_len; i++ ) { code_len = codebook[1]; - if ( p_huff_cfg->min_len > code_len ) + IF ( GT_16(p_huff_cfg->min_len, code_len) ) { p_huff_cfg->min_len = code_len; } - if ( p_huff_cfg->max_len < code_len ) + IF ( LT_16(p_huff_cfg->max_len, code_len) ) { p_huff_cfg->max_len = code_len; } @@ -411,20 +568,20 @@ static void ivas_huffman_dec_init_min_max_len( void ivas_spar_huff_coeffs_com_init( ivas_huff_coeffs_t *pHuff_coeffs, ivas_spar_md_com_cfg *pSpar_cfg, - const int16_t table_idx, - const int16_t enc_dec ) + const Word16 table_idx, + const Word16 enc_dec ) { - int16_t i, pred_r_index, drct_r_index, decd_r_index; - int16_t num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r; + Word16 i, pred_r_index, drct_r_index, decd_r_index; + Word16 num_quant_points_pred_r, num_quant_points_drct_r, num_quant_points_decd_r; ivas_huffman_cfg_t *p_huff_cfg; - for ( i = 0; i < MAX_QUANT_STRATS; i++ ) + FOR ( i = 0; i < MAX_QUANT_STRATS; i++ ) { p_huff_cfg = &pHuff_coeffs->pred_huff_re[i]; num_quant_points_pred_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][0]; /* 0: pred_r */ pred_r_index = ivas_map_num_pred_r_to_idx( num_quant_points_pred_r, 0 ); p_huff_cfg->codebook = &ivas_huff_pred_r_consts[pred_r_index].code_book[0][0]; - if ( enc_dec == DEC ) + IF ( EQ_16(enc_dec, DEC) ) { p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].PR.q_levels[0]; ivas_huffman_dec_init_min_max_len( p_huff_cfg ); @@ -434,7 +591,7 @@ void ivas_spar_huff_coeffs_com_init( num_quant_points_drct_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][1]; /* 1: drct_r */ drct_r_index = ivas_map_num_drct_r_to_idx( num_quant_points_drct_r ); p_huff_cfg->codebook = &ivas_huff_drct_r_consts[drct_r_index].code_book[0][0]; - if ( enc_dec == DEC ) + IF ( EQ_16(enc_dec, DEC) ) { p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].C.q_levels[0]; ivas_huffman_dec_init_min_max_len( p_huff_cfg ); @@ -444,7 +601,7 @@ void ivas_spar_huff_coeffs_com_init( num_quant_points_decd_r = ivas_spar_br_table_consts[table_idx].q_lvls[i][2]; /* 2: decd_r */ decd_r_index = ivas_map_num_decd_r_to_idx( num_quant_points_decd_r ); p_huff_cfg->codebook = &ivas_huff_decd_r_consts[decd_r_index].code_book[0][0]; - if ( enc_dec == DEC ) + IF ( EQ_16(enc_dec, DEC) ) { p_huff_cfg->sym_len = pSpar_cfg->quant_strat[i].P_r.q_levels[0]; ivas_huffman_dec_init_min_max_len( p_huff_cfg ); diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index f34610c11e8424edc109164767f24f46011ca7be..965c727c82f41bf8bf85d659519324d80f09ee1c 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -291,8 +291,11 @@ typedef struct ivas_arith_t int16_t cum_freq[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; int16_t range; int16_t num_models; +#ifdef IVAS_FLOAT_FIXED + Word32 saved_dist_arr[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; +#else float saved_dist_arr[IVAS_NUM_PROB_MODELS][IVAS_MAX_QUANT_LEVELS]; - +#endif } ivas_arith_t; typedef struct ivas_arith_coeffs_t diff --git a/lib_com/lsp_conv_poly_fx.c b/lib_com/lsp_conv_poly_fx.c index 81a8ad1e0981e1ed64cbcc2cfeee8124e1cbfa39..5a54c093c979f6af31e911bf859dd9e08544fc5a 100644 --- a/lib_com/lsp_conv_poly_fx.c +++ b/lib_com/lsp_conv_poly_fx.c @@ -2,7 +2,6 @@ EVS Codec 3GPP TS26.452 Aug 12, 2021. Version 16.3.0 ====================================================================================*/ - #include #include "options.h" #include "cnst.h" @@ -12,7 +11,6 @@ #ifdef IVAS_FLOAT_FIXED #include "prot_fx2.h" -#endif /*-------------------------------------------------------------------* * Local constants @@ -904,3 +902,4 @@ static void cheb2poly_fx( return; } +#endif \ No newline at end of file diff --git a/lib_com/options.h b/lib_com/options.h index 74f67ad9e7f9b1a20c9244338f38e62ccefd714f..179fd9aeba3d78d5a9fb5d543136a70c003927d3 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -87,6 +87,7 @@ #define NONBE_FIX_849_OMASA_BFI_CRASH /* VA: issue 849: fix OMASA 2TC and FEC crashes */ #define IVAS_FLOAT_FIXED +//#define DUMPS_ENABLED /* ##################### End NON-BE switches ########################### */ /* ################## End DEVELOPMENT switches ######################### */ diff --git a/lib_com/prot_fx2.h b/lib_com/prot_fx2.h index 8e8fc01755941a4a8747575213d3bb221e39fad5..aa7563a4ffeadd1c4a434d6e04c689deb777a2b8 100644 --- a/lib_com/prot_fx2.h +++ b/lib_com/prot_fx2.h @@ -3031,4 +3031,14 @@ void tcxInvertWindowGrouping( const Word16 bfi ); +void window_ola_ext_fx( + const Word32 *ImdstOut, /* i : input */ + Word32 *auOut, /* o : output audio */ + Word32 *OldauOut, /* i/o: audio from previous frame */ + const Word16 L, /* i : length */ + const Word16 right_mode, + const Word16 left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const UWord16 kernel_type /* i : transform kernel type */ +); + #endif \ No newline at end of file diff --git a/lib_com/window_ola_fx.c b/lib_com/window_ola_fx.c index 348f1fe764a85cb7ad1bb8054642a743415ae8df..4726fc81ef21817827737de05e76056ff2d45b83 100644 --- a/lib_com/window_ola_fx.c +++ b/lib_com/window_ola_fx.c @@ -507,143 +507,141 @@ void window_ola_fx( return; } -#ifdef IVAS_CODE /*-------------------------------------------------------------------* - * window_ola_ext() + * window_ola_ext_fx() * * *-------------------------------------------------------------------*/ -void window_ola_ext( - const float* ImdstOut, /* i : input */ - float* auOut, /* o : output audio */ - float* OldauOut, /* i/o: audio from previous frame */ - const int16_t L, /* i : length */ - const int16_t right_mode, - const int16_t left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ - const uint16_t kernel_type /* i : transform kernel type */ +void window_ola_ext_fx( + const Word32 *ImdstOut, /* i : input */ + Word32 *auOut, /* o : output audio */ + Word32 *OldauOut, /* i/o: audio from previous frame */ + const Word16 L, /* i : length */ + const Word16 right_mode, + const Word16 left_mode, /* i : window overlap of current frame (0: full, 2: none, or 3: half) */ + const UWord16 kernel_type /* i : transform kernel type */ ) { - const float sign_left = (kernel_type & 1 ? 1.f : -1.f); - const float sign_right = (kernel_type >= MDCT_II ? -1.f : 1.f); - int16_t i, decimate, decay; - int16_t n, n16, windecay48, windecay16; - float win_right[R2_48]; - float win_int_left[R1_16]; - float win_left[R1_48]; - float win_int_right[R2_16]; - float* paout; - - n = (int16_t)((float)L * N_ZERO_MDCT_NS / FRAME_SIZE_NS); - n16 = (int16_t)((float)L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS); - windecay48 = (int16_t)(2 * ((float)L_FRAME48k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_48; - windecay16 = (int16_t)(2 * ((float)L_FRAME16k * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_16; + const Word16 sign_left = ( kernel_type & 1 ? MAX_16 : negate( MAX_16 ) ); + const Word16 sign_right = ( kernel_type >= MDCT_II ? negate( MAX_16 ) : MAX_16 ); + Word16 i, decimate, decay; + Word16 n, n16, windecay48, windecay16; + Word16 win_right[R2_48]; + Word16 win_int_left[R1_16]; + Word16 win_left[R1_48]; + Word16 win_int_right[R2_16]; + Word32 *paout; + + n = shr( mult( shl( L, Q5 ), N_ZERO_BY_FS ), Q5 ); + n16 = N16_CORE_SW; + windecay48 = WINDECAY48; + windecay16 = WINDECAY16; decimate = 1; decay = 0; - tcx_get_windows_mode1_flt(left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L); + tcx_get_windows_mode1( left_mode, right_mode, win_left, win_right, win_int_left, win_int_right, L ); - if (L == L_FRAME32k || L == L_FRAME16k) + IF( EQ_16( L, L_FRAME32k ) || EQ_16( L, L_FRAME16k ) ) { decimate = 3; decay = 1; } - else if (L == L_FRAME8k) + ELSE IF( EQ_16( L, L_FRAME8k ) ) { decimate = 6; decay = 2; } - else if (L == 512) + ELSE IF( EQ_16( L, 512 ) ) { - windecay48 = (int16_t)(2 * ((float)512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_25; + windecay48 = WINDECAY48_256; decimate = 1; decay = 0; } - else if (L == 256) + ELSE IF( EQ_16( L, 256 ) ) { - windecay48 = (int16_t)(2 * ((float)512 * N_ZERO_MDCT_NS / FRAME_SIZE_NS)) + R1_25; + windecay48 = WINDECAY48_256; decimate = 2; decay = 0; } paout = auOut - n; - if (L == L_FRAME32k) + IF( EQ_16( L, L_FRAME32k ) ) { - for (i = n; i < L / 2; i += 2) + FOR( i = n; i < shr( L, 1 ); i += 2 ) { - paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[(2 * L_FRAME16k - (n16 + (i - n) / 2)) * decimate - 1 - decay - windecay48] + OldauOut[i]; - paout[i + 1] = sign_right * ImdstOut[L / 2 + i + 1] * win_int_right[2 * L_FRAME16k - (n16 + (i - n) / 2) - 1 - windecay16] + OldauOut[i + 1]; + paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[shr( L, 1 ) + i], sign_right ), win_right[( 2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) ) * decimate - 1 - decay - windecay48] ), OldauOut[i] ); + paout[i + 1] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[shr( L, 1 ) + i + 1], sign_right ), win_int_right[2 * L_FRAME16k - ( n16 + ( i - n ) / 2 ) - 1 - windecay16] ), OldauOut[i + 1] ); } - for (i = 0; i < L / 2 - n; i += 2) + FOR( i = 0; i < shr( L, 1 ) - n; i += 2 ) { - paout[L / 2 + i + 1] = -ImdstOut[L - 1 - (i + 1)] * win_right[(3 * L_FRAME16k / 2 - 1 - i / 2) * decimate + decay - windecay48] + OldauOut[i + L / 2 + 1]; - paout[L / 2 + i] = -ImdstOut[L - 1 - i] * win_int_right[(3 * L_FRAME16k / 2 - 1 - i / 2) - windecay16] + OldauOut[i + L / 2]; + paout[shr( L, 1 ) + i + 1] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[L - 1 - ( i + 1 )] ), win_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) * decimate + decay - windecay48] ), OldauOut[i + shr( L, 1 ) + 1] ); + paout[shr( L, 1 ) + i] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[L - 1 - i] ), win_int_right[( 3 * L_FRAME16k / 2 - 1 - i / 2 ) - windecay16] ), OldauOut[i + shr( L, 1 )] ); } - for (i = L / 2 - n; i < L / 2; i += 2) + FOR( i = sub( shr( L, 1 ), n ); i < shr( L, 1 ); i += 2 ) { - paout[L / 2 + i + 1] = -ImdstOut[L - 1 - (i + 1)] + OldauOut[i + L / 2 + 1]; - paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2]; + paout[shr( L, 1 ) + i + 1] = L_add_sat( L_negate( ImdstOut[L - 1 - ( i + 1 )] ), OldauOut[i + shr( L, 1 ) + 1] ); + paout[shr( L, 1 ) + i] = L_add_sat( L_negate( ImdstOut[L - 1 - i] ), OldauOut[i + shr( L, 1 )] ); } - for (i = 0; i < L / 2; i += 2) + FOR( i = 0; i < shr( L, 1 ); i += 2 ) { - OldauOut[L / 2 + i + 1] = sign_left * ImdstOut[i + 1] * win_left[(L_FRAME16k / 2 - i / 2 - 1) * decimate + decay]; - OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_int_left[(L_FRAME16k / 2 - i / 2 - 1)]; + OldauOut[shr( L, 1 ) + i + 1] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i + 1], sign_left ), win_left[( L_FRAME16k / 2 - i / 2 - 1 ) * decimate + decay] ); + OldauOut[shr( L, 1 ) + i] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_int_left[( L_FRAME16k / 2 - i / 2 - 1 )] ); } - for (i = n; i < L / 2; i += 2) + FOR( i = n; i < shr( L, 1 ); i += 2 ) { - OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[(L_FRAME16k - i / 2) * decimate - decay - 1]; - OldauOut[i + 1] = -ImdstOut[L / 2 - 1 - (i + 1)] * win_int_left[L_FRAME16k - (i / 2) - 1]; + OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[shr( L, 1 ) - 1 - i] ), win_left[( L_FRAME16k - i / 2 ) * decimate - decay - 1] ); + OldauOut[i + 1] = Mpy_32_16_1( L_negate( ImdstOut[shr( L, 1 ) - 1 - ( i + 1 )] ), win_int_left[L_FRAME16k - i / 2 - 1] ); } } - else + ELSE { - for (i = n; i < L / 2; i++) + FOR( i = n; i < shr( L, 1 ); i++ ) { - paout[i] = sign_right * ImdstOut[L / 2 + i] * win_right[(2 * L - i) * decimate - 1 - decay - windecay48] + OldauOut[i]; + paout[i] = L_add_sat( Mpy_32_16_1( Mpy_32_16_1( ImdstOut[shr( L, 1 ) + i], sign_right ), win_right[( 2 * L - i ) * decimate - 1 - decay - windecay48] ), OldauOut[i] ); } - for (i = 0; i < L / 2 - n; i++) + FOR( i = 0; i < shr( L, 1 ) - n; i++ ) { - paout[L / 2 + i] = -ImdstOut[L - 1 - i] * win_right[(3 * L / 2 - 1 - i) * decimate + decay - windecay48] + OldauOut[i + L / 2]; + paout[shr( L, 1 ) + i] = L_add_sat( Mpy_32_16_1( L_negate( ImdstOut[L - 1 - i] ), win_right[( 3 * shr( L, 1 ) - 1 - i ) * decimate + decay - windecay48] ), OldauOut[i + shr( L, 1 )] ); } - for (i = L / 2 - n; i < L / 2; i++) + FOR( i = sub( shr( L, 1 ), n ); i < shr( L, 1 ); i++ ) { - paout[L / 2 + i] = -ImdstOut[L - 1 - i] + OldauOut[i + L / 2]; + paout[shr( L, 1 ) + i] = L_add_sat( L_negate( ImdstOut[L - 1 - i] ), OldauOut[i + shr( L, 1 )] ); } - for (i = 0; i < L / 2; i++) + FOR( i = 0; i < shr( L, 1 ); i++ ) { - OldauOut[L / 2 + i] = sign_left * ImdstOut[i] * win_left[(L / 2 - i - 1) * decimate + decay]; + OldauOut[shr( L, 1 ) + i] = Mpy_32_16_1( Mpy_32_16_1( ImdstOut[i], sign_left ), win_left[( shr( L, 1 ) - i - 1 ) * decimate + decay] ); } - for (i = n; i < L / 2; i++) + FOR( i = n; i < shr( L, 1 ); i++ ) { - OldauOut[i] = -ImdstOut[L / 2 - 1 - i] * win_left[(L - i) * decimate - decay - 1]; + OldauOut[i] = Mpy_32_16_1( L_negate( ImdstOut[shr( L, 1 ) - 1 - i] ), win_left[( L - i ) * decimate - decay - 1] ); } } - for (i = 0; i < n; i++) + FOR( i = 0; i < n; i++ ) { - OldauOut[i] = -ImdstOut[L / 2 - 1 - i]; + OldauOut[i] = L_negate( ImdstOut[shr( L, 1 ) - 1 - i] ); } - for (i = 0; i < n; i++) + FOR( i = 0; i < n; i++ ) { paout[L + i] = OldauOut[i]; } return; } -#endif diff --git a/lib_dec/dec_tcx.c b/lib_dec/dec_tcx.c index 1920b6f3cd66f82bd3f03a690d6adf03788e00e0..f82956be9776f61d57647c971d51eb88a674304b 100644 --- a/lib_dec/dec_tcx.c +++ b/lib_dec/dec_tcx.c @@ -44,6 +44,9 @@ #include "cnst.h" #include "wmc_auto.h" #include "ivas_rom_com.h" +#ifndef IVAS_FLOAT_FIXED_UNIT_TESTING +#include "debug.h" +#endif // !IVAS_FLOAT_FIXED_UNIT_TESTING /*-----------------------------------------------------------------* @@ -488,7 +491,32 @@ void IMDCT( edxt( x, xn_buf + overlap / 2 + nz, L_frame, kernel_type, TRUE ); } v_multc( xn_buf + overlap / 2 + nz, (float) sqrt( (float) L_frame / NORM_MDCT_FACTOR ), tmp, L_frame ); +#ifndef IVAS_FLOAT_FIXED_UNIT_TESTING window_ola_ext( tmp, xn_buf, old_out, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, kernel_type ); +#ifdef DUMPS_ENABLED + dbgwrite_txt( xn_buf, L_frame + ( L_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ), "xn_buf_float.txt", NULL ); + dbgwrite_txt( old_out, L_frame, "old_out_float.txt", NULL ); +#endif +#else + Word32 xn_buf_fx[1200] = { 0 }, tmp_fx[1200], old_out_fx[1200]; + for ( int i = 0; i < L_frame; i++ ) + { + old_out_fx[i] = old_out[i] * ( 1 << Q15 ); + tmp_fx[i] = tmp[i] * ( 1 << Q15 ); + } + + window_ola_ext_fx( tmp_fx, xn_buf_fx, old_out_fx, L_frame, hTcxCfg->tcx_last_overlap_mode, hTcxCfg->tcx_curr_overlap_mode, kernel_type ); + + for ( int i = 0; i < L_frame; i++ ) + { + old_out[i] = (float) old_out_fx[i] / ( 1 << Q15 ); + xn_buf[i] = (float) xn_buf_fx[i] / ( 1 << Q15 ); + } +#ifdef DUMPS_ENABLED + dbgwrite_txt( xn_buf, L_frame + ( L_frame * N_ZERO_MDCT_NS / FRAME_SIZE_NS ), "xn_buf_fixed.txt", NULL ); + dbgwrite_txt( old_out, L_frame, "old_out_fixed.txt", NULL ); +#endif +#endif // IVAS_FLOAT_FIXED_UNIT_TESTING } else { diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index e118c72712c574be77f72c411f120ddff7ea9505..0e793ed3feca6471126d2b36dd2679352db99f6f 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -40,7 +40,7 @@ #include #include "wmc_auto.h" - +#ifndef IVAS_FLOAT_FIXED /*-----------------------------------------------------------------------------------------* * Function ivas_get_dyn_freq_model() * @@ -80,7 +80,9 @@ static ivas_error ivas_get_dyn_freq_model( curr_bps -= ( curr_dist[i] * pArith->saved_dist_arr[0][i] ); } curr_bps_min = curr_bps; - +#ifdef DUMPS_ENABLED + dbgwrite_txt(&curr_bps_min, 1, "float_curr_bps_min.txt", NULL); +#endif model_idx = 0; for ( m = 0; m < pArith->num_models - 1; m++ ) @@ -90,7 +92,9 @@ static ivas_error ivas_get_dyn_freq_model( { curr_bps_new -= ( curr_dist[i] * pArith->saved_dist_arr[m + 1][i] ); } - +#ifdef DUMPS_ENABLED + dbgwrite_txt(&curr_bps_new, 1, "float_curr_bps_new.txt", NULL); +#endif if ( curr_bps_new < curr_bps_min ) { model_idx = m; @@ -113,57 +117,142 @@ static ivas_error ivas_get_dyn_freq_model( return error; } +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_get_dyn_freq_model_fx() + * + * Chooses frequency model dynamically + *-----------------------------------------------------------------------------------------*/ +static ivas_error ivas_get_dyn_freq_model_fx( + Word16 *pInput, + const Word16 length, + Word16 *model_index, + ivas_arith_t *pArith, + Word16 **ppCum_freq ) +{ + Word32 curr_dist[IVAS_MAX_QUANT_LEVELS]; + Word16 i, n[IVAS_MAX_QUANT_LEVELS + 1], model_idx; + Word32 curr_bps, curr_bps_min, curr_bps_new; + Word16 range = pArith->range; + Word16 m, offset = -pArith->vals[0]; + ivas_error error; + error = IVAS_ERR_OK; +FOR(i=0;isaved_dist_arr[0][i]); + } + curr_bps_min = curr_bps; +#ifdef DUMPS_ENABLED + { + float a = curr_bps_min/32768.0f; + dbgwrite_txt(&a, 1, "fixed_curr_bps_min.txt", NULL); + } +#endif + model_idx = 0; + + FOR ( m = 0; m < pArith->num_models - 1; m++ ) + { + curr_bps_new = 0; + FOR ( i = 0; i < range; i++ ) + { + curr_bps_new = L_sub(curr_bps_new, (curr_dist[i] * pArith->saved_dist_arr[m + 1][i] )); + } +#ifdef DUMPS_ENABLED + { + float a = curr_bps_new/32768.0f; + dbgwrite_txt(&a, 1, "fixed_curr_bps_new.txt", NULL); + } +#endif + IF ( LT_32(curr_bps_new, curr_bps_min) ) + { + model_idx = m; + curr_bps_min = curr_bps_new; + } + } + + IF ( LT_32(curr_bps_min, curr_bps) ) + { + *ppCum_freq = pArith->cum_freq[model_idx + 1]; + model_idx = add(model_idx, 1); + } + ELSE + { + model_idx = 0; + *ppCum_freq = pArith->cum_freq[0]; + } + + *model_index = model_idx; + + return error; +} +#endif /*-----------------------------------------------------------------------------------------* * Function ivas_arith_encode_array() * * Arith encoding of an array of symbols *-----------------------------------------------------------------------------------------*/ -static int16_t ivas_arith_encode_array( - int16_t *pInput, +static Word16 ivas_arith_encode_array( + Word16 *pInput, ivas_arith_t *pArith, BSTR_ENC_HANDLE hMetaData, - const int16_t in_len, - const int16_t wc_strat_arith ) + const Word16 in_len, + const Word16 wc_strat_arith ) { - int16_t model_index, i, ind; - int16_t *pCum_freq = NULL; + Word16 model_index, i, ind; + Word16 *pCum_freq = NULL; Tastat as; - if ( in_len > 0 && pArith->range > 1 ) + IF ( GT_16(in_len, 0) && GT_16(pArith->range, 1) ) { - if ( pArith->dyn_model_bits > 0 ) + IF ( GT_16(pArith->dyn_model_bits, 0) ) { +#ifdef IVAS_FLOAT_FIXED + ivas_get_dyn_freq_model_fx( pInput, in_len, &model_index, pArith, &pCum_freq ); +#else ivas_get_dyn_freq_model( pInput, in_len, &model_index, pArith, &pCum_freq ); - if ( ( hMetaData->nb_bits_tot + pArith->dyn_model_bits ) > wc_strat_arith ) +#endif + IF ( GT_16(add( hMetaData->nb_bits_tot, pArith->dyn_model_bits ), wc_strat_arith )) { return -1; } push_next_indice( hMetaData, model_index, pArith->dyn_model_bits ); } - else + ELSE { pCum_freq = pArith->cum_freq[0]; } ari_start_encoding_14bits( &as ); - for ( i = 0; i < in_len; i++ ) + FOR ( i = 0; i < in_len; i++ ) { - ind = pInput[i] - pArith->vals[0]; + ind = sub(pInput[i], pArith->vals[0]); - ivas_ari_encode_14bits_ext( hMetaData, &as, ind, (const uint16_t *) pCum_freq ); - if ( hMetaData->nb_bits_tot > wc_strat_arith ) + ivas_ari_encode_14bits_ext( hMetaData, &as, ind, (const UWord16 *) pCum_freq ); + IF ( GT_16(hMetaData->nb_bits_tot, wc_strat_arith )) { return -1; } } ivas_ari_done_encoding_14bits( hMetaData, &as ); - if ( hMetaData->nb_bits_tot > wc_strat_arith ) + IF ( GT_16(hMetaData->nb_bits_tot, wc_strat_arith )) { return -1; } @@ -179,28 +268,28 @@ static int16_t ivas_arith_encode_array( * Differential arith encoding *-----------------------------------------------------------------------------------------*/ -static int16_t ivas_arithCoder_encode_array_diff( +static Word16 ivas_arithCoder_encode_array_diff( ivas_arith_t *pArith_diff, - int16_t *pIn_new, - int16_t *pIn_old_scratch, - const int16_t length, + Word16 *pIn_new, + Word16 *pIn_old_scratch, + const Word16 length, BSTR_ENC_HANDLE hMetaData, - const int16_t wc_strat_arith ) + const Word16 wc_strat_arith ) { - int16_t n; - int16_t arith_result; + Word16 n; + Word16 arith_result; - if ( length > 0 ) + IF ( GT_16(length, 0 )) { - for ( n = 0; n < length; n++ ) + FOR ( n = 0; n < length; n++ ) { - pIn_old_scratch[n] = pIn_new[n] - pIn_old_scratch[n]; + pIn_old_scratch[n] = sub(pIn_new[n], pIn_old_scratch[n]); } ivas_wrap_arround( pIn_old_scratch, pArith_diff->vals[0], pArith_diff->vals[pArith_diff->range - 1], length ); arith_result = ivas_arith_encode_array( pIn_old_scratch, pArith_diff, hMetaData, length, wc_strat_arith ); - if ( arith_result < 0 ) + IF ( LT_16(arith_result, 0 )) { return -1; } @@ -218,12 +307,12 @@ static int16_t ivas_arithCoder_encode_array_diff( void ivas_huffman_encode( ivas_huffman_cfg_t *huff_cfg, - int16_t in, - int16_t *hcode, - int16_t *hlen ) + Word16 in, + Word16 *hcode, + Word16 *hlen ) { - int16_t min_sym_val; - const int16_t *codebook; + Word16 min_sym_val; + const Word16 *codebook; min_sym_val = huff_cfg->codebook[0]; @@ -241,31 +330,31 @@ void ivas_huffman_encode( * Arithmetic encode a cell array *-----------------------------------------------------------------------------------------*/ -static int16_t arith_encode_cell_array( +static Word16 arith_encode_cell_array( ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, - const int16_t nB, + const Word16 nB, ivas_arith_t *pArith, - int16_t *pSymbol, - const int16_t wc_strat_arith ) + Word16 *pSymbol, + const Word16 wc_strat_arith ) { - int16_t total_symbol_len = 0; - int16_t i; - int16_t arith_result; + Word16 total_symbol_len = 0; + Word16 i; + Word16 arith_result; - for ( i = 0; i < nB; i++ ) + FOR ( i = 0; i < nB; i++ ) { total_symbol_len += ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); } - assert( total_symbol_len <= ( IVAS_MAX_INPUT_LEN ) ); + assert( LE_16(total_symbol_len, ( IVAS_MAX_INPUT_LEN ) )); - if ( total_symbol_len > 0 ) + IF ( GT_16(total_symbol_len, 0 )) { - if ( pArith->range > 1 ) + IF ( GT_16(pArith->range, 1 )) { arith_result = ivas_arith_encode_array( pSymbol, pArith, hMetaData, total_symbol_len, wc_strat_arith ); - if ( arith_result < 0 ) + IF ( LT_16(arith_result, 0 )) { return -1; } @@ -282,32 +371,32 @@ static int16_t arith_encode_cell_array( * Arithmetic encode a cell array - differential *-----------------------------------------------------------------------------------------*/ -static int16_t arith_encode_cell_array_diff( +static Word16 arith_encode_cell_array_diff( const ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, - int16_t nB, + Word16 nB, ivas_arith_t *pArith_diff, - int16_t *pSymbol_old, - int16_t *pSymbol, - const int16_t wc_strat_arith ) + Word16 *pSymbol_old, + Word16 *pSymbol, + const Word16 wc_strat_arith ) { - int16_t i, total_symbol_len; - int16_t arith_result; + Word16 i, total_symbol_len; + Word16 arith_result; total_symbol_len = 0; - for ( i = 0; i < nB; i++ ) + FOR ( i = 0; i < nB; i++ ) { total_symbol_len += ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); } - assert( total_symbol_len <= ( IVAS_MAX_INPUT_LEN ) ); + assert( LE_16(total_symbol_len, ( IVAS_MAX_INPUT_LEN )) ); - if ( total_symbol_len > 0 ) + IF ( GT_16(total_symbol_len, 0 )) { - if ( pArith_diff->range > 1 ) + IF ( GT_16(pArith_diff->range, 1 )) { arith_result = ivas_arithCoder_encode_array_diff( pArith_diff, pSymbol, pSymbol_old, total_symbol_len, hMetaData, wc_strat_arith ); - if ( arith_result < 0 ) + IF ( LT_16(arith_result, 0 )) { return -1; } @@ -324,37 +413,37 @@ static int16_t arith_encode_cell_array_diff( * Arithmetic encode a cell array *-----------------------------------------------------------------------------------------*/ -int16_t ivas_arith_encode_cmplx_cell_array( +Word16 ivas_arith_encode_cmplx_cell_array( ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, - const int16_t *pDo_diff, - const int16_t nB, - int16_t *pSymbol_re, - int16_t *pSymbol_old_re, + const Word16 *pDo_diff, + const Word16 nB, + Word16 *pSymbol_re, + Word16 *pSymbol_old_re, ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, - const int16_t any_diff, - const int16_t wc_strat_arith ) + const Word16 any_diff, + const Word16 wc_strat_arith ) { - int16_t input_old[IVAS_MAX_INPUT_LEN]; - int16_t input_new[IVAS_MAX_INPUT_LEN]; - int16_t input[IVAS_MAX_INPUT_LEN]; + Word16 input_old[IVAS_MAX_INPUT_LEN]; + Word16 input_new[IVAS_MAX_INPUT_LEN]; + Word16 input[IVAS_MAX_INPUT_LEN]; ivas_cell_dim_t cell_dim[IVAS_MAX_NUM_BANDS], cell_dim_diff[IVAS_MAX_NUM_BANDS]; - int16_t len, idx, i, j, idx1; - int16_t total_len; - int16_t arith_result; + Word16 len, idx, i, j, idx1; + Word16 total_len; + Word16 arith_result; idx1 = 0; - if ( any_diff == 1 ) + IF ( EQ_16(any_diff, 1 )) { idx = 0; total_len = 0; - for ( i = 0; i < nB; i++ ) + FOR ( i = 0; i < nB; i++ ) { len = ( pCell_dims[i].dim1 * pCell_dims[i].dim2 ); - if ( pDo_diff[i] != 0 ) + IF ( NE_16(pDo_diff[i] , 0 )) { - for ( j = 0; j < len; j++ ) + FOR ( j = 0; j < len; j++ ) { input_old[idx] = pSymbol_old_re[total_len + j]; input_new[idx++] = pSymbol_re[total_len + j]; @@ -364,9 +453,9 @@ int16_t ivas_arith_encode_cmplx_cell_array( cell_dim[i].dim1 = 0; cell_dim[i].dim2 = 0; } - else + ELSE { - for ( j = 0; j < len; j++ ) + FOR ( j = 0; j < len; j++ ) { input[idx1++] = pSymbol_re[total_len + j]; } @@ -375,25 +464,25 @@ int16_t ivas_arith_encode_cmplx_cell_array( cell_dim[i].dim1 = pCell_dims[i].dim1; cell_dim[i].dim2 = pCell_dims[i].dim2; } - total_len += len; + total_len = add(total_len, len); } arith_result = arith_encode_cell_array( cell_dim, hMetaData, nB, pArith_re, input, wc_strat_arith ); - if ( arith_result < 0 ) + IF ( LT_16(arith_result, 0 )) { return -1; } arith_result = arith_encode_cell_array_diff( cell_dim_diff, hMetaData, nB, pArith_re_diff, input_old, input_new, wc_strat_arith ); - if ( arith_result < 0 ) + IF ( LT_16(arith_result, 0 )) { return -1; } } - else + ELSE { arith_result = arith_encode_cell_array( pCell_dims, hMetaData, nB, pArith_re, pSymbol_re, wc_strat_arith ); - if ( arith_result < 0 ) + IF ( LT_16(arith_result, 0 )) { return -1; }