Loading lib_com/ivas_cnst.h +46 −0 Original line number Diff line number Diff line Loading @@ -947,6 +947,7 @@ typedef enum #define SPAR_SID_BITS_TAR_PER_BAND 18 #ifndef FIX_SBA_CLEAN_UP_OPT typedef enum { WYXZ = 0, Loading @@ -955,6 +956,16 @@ typedef enum WZ, WYiX, } ivas_spar_foa_pmx_strings_t; #else typedef enum { WYXZ = 0, WY = 0, WX, WZ, WYiX, } ivas_spar_pmx_strings_t; #endif #define NUM_MD_Q_COEFS_SET 4 Loading Loading @@ -1025,6 +1036,41 @@ typedef enum PCA_MODE_INACTIVE = 1 } ivas_pca_bypass_mode; #ifdef FIX_SBA_CLEAN_UP_OPT enum { PRED_Q_1 = 0, PRED_Q_7, PRED_Q_15, PRED_Q_21, PRED_Q_31, PRED_Q_7_ACTIVE_W, TOTAL_PRED_QUANT_STRATS_HUFF = 5, PRED_Q_15_ACTIVE_W, PRED_Q_21_ACTIVE_W, TOTAL_PRED_QUANT_STRATS_ARITH }; enum { DRCT_Q_1 = 0, DRCT_Q_7, DRCT_Q_9, DRCT_Q_11, TOTAL_DRCT_QUANT_STRATS }; enum { DECD_Q_1 = 0, DECD_Q_3, DECD_Q_5, DECD_Q_7, DECD_Q_9, DECD_Q_11, TOTAL_DECD_QUANT_STRATS }; #endif /*----------------------------------------------------------------------------------* * MASA constants Loading lib_com/ivas_dirac_com.c +8 −0 Original line number Diff line number Diff line Loading @@ -92,7 +92,11 @@ ivas_error ivas_dirac_config( sba_mode = ( (Encoder_Struct *) st_ivas )->sba_mode; if ( ( (Encoder_Struct *) st_ivas )->hSpar != NULL ) { #ifndef FIX_SBA_CLEAN_UP_OPT hFbMdft = ( (Encoder_Struct *) st_ivas )->hSpar->hSparFoa->hFbMixer; #else hFbMdft = ( (Encoder_Struct *) st_ivas )->hSpar->hFbMixer; #endif } else { Loading @@ -117,7 +121,11 @@ ivas_error ivas_dirac_config( sba_mode = ( (Decoder_Struct *) st_ivas )->sba_mode; if ( ( (Decoder_Struct *) st_ivas )->hSpar != NULL ) { #ifndef FIX_SBA_CLEAN_UP_OPT hFbMdft = ( (Decoder_Struct *) st_ivas )->hSpar->hSparFoa->hFbMixer; #else hFbMdft = ( (Decoder_Struct *) st_ivas )->hSpar->hFbMixer; #endif } else { Loading lib_com/ivas_entropy_coder_common.c +362 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,11 @@ #include "debug.h" #endif #include "ivas_prot.h" #ifdef FIX_SBA_CLEAN_UP_OPT #include "ivas_rom_com.h" #include "math.h" #include "prot.h" #endif #include "wmops.h" Loading Loading @@ -91,3 +96,360 @@ void ivas_get_cum_freq_model( return; } #ifdef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_map_num_pred_r_to_idx() * * 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 ) { int16_t pred_r_to_idx = -1; if ( active_w_flag == 0 ) { switch ( num_quant_points_pred_r ) { case 1: pred_r_to_idx = PRED_Q_1; break; case 7: pred_r_to_idx = PRED_Q_7; break; case 15: pred_r_to_idx = PRED_Q_15; break; case 21: pred_r_to_idx = PRED_Q_21; break; case 31: pred_r_to_idx = PRED_Q_31; break; default: assert( "Forbidden value for prediction quantization strategy index" ); break; } } else { switch ( num_quant_points_pred_r ) { case 7: pred_r_to_idx = PRED_Q_7_ACTIVE_W; break; case 15: pred_r_to_idx = PRED_Q_15_ACTIVE_W; break; case 21: pred_r_to_idx = PRED_Q_21_ACTIVE_W; break; default: assert( "Forbidden value for prediction quantization strategy index" ); break; } } return pred_r_to_idx; } /*-----------------------------------------------------------------------------------------* * Function ivas_map_num_drct_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 ) { int16_t drct_r_to_idx = -1; switch ( num_quant_points_drct_r ) { case 1: drct_r_to_idx = DRCT_Q_1; break; case 7: drct_r_to_idx = DRCT_Q_7; break; case 9: drct_r_to_idx = DRCT_Q_9; break; case 11: drct_r_to_idx = DRCT_Q_11; break; default: assert( "Forbidden value for DRCT quantization strategy index" ); break; } return drct_r_to_idx; } /*-----------------------------------------------------------------------------------------* * Function ivas_map_num_decd_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 ) { int16_t decd_r_to_idx = -1; switch ( num_quant_points_decd_r ) { case 1: decd_r_to_idx = DECD_Q_1; break; case 3: decd_r_to_idx = DECD_Q_3; break; case 5: decd_r_to_idx = DECD_Q_5; break; case 7: decd_r_to_idx = DECD_Q_7; break; case 9: decd_r_to_idx = DECD_Q_9; break; case 11: decd_r_to_idx = DECD_Q_11; break; default: assert( "Forbidden value for DECD quantization strategy index" ); break; } return decd_r_to_idx; } /*---------------------------------------------------------------------------------------- - * * Function ivas_spar_arith_com_init() * * arith coder init *---------------------------------------------------------------------------------------- - */ static void ivas_spar_arith_com_init( ivas_arith_t *pArith, const ivas_freq_models_t *pFreq_models, ivas_arith_t *pArith_diff, const int16_t q_levels, int16_t codec_mode ) { int16_t i, j; 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 ( codec_mode == ENC ) { float sum = 0; for ( i = 1; i < pArith->range + 1; i++ ) { sum += pArith->pFreq_model[i]; } for ( i = 1; i < pArith->range + 1; i++ ) { pArith->saved_dist_arr[0][i - 1] = log2f( max( 1e-10f, pArith->pFreq_model[i] ) ); pArith->saved_dist_arr[0][i - 1] -= log2f( max( 1e-10f, sum ) ); } for ( j = 0; j < pArith->num_models - 1; j++ ) { sum = 0; for ( i = 1; i < pArith->range + 1; i++ ) { sum += pArith->pAlt_freq_models[j][i]; } for ( i = 1; i < pArith->range + 1; i++ ) { pArith->saved_dist_arr[j + 1][i - 1] = log2f( max( 1e-10f, pArith->pAlt_freq_models[j][i] ) ); pArith->saved_dist_arr[j + 1][i - 1] -= log2f( max( 1e-10f, sum ) ); } } } 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 ( codec_mode == ENC ) { float sum = 0; for ( i = 1; i < pArith_diff->range + 1; i++ ) { sum += pArith_diff->pFreq_model[i]; } for ( i = 1; i < pArith_diff->range + 1; i++ ) { pArith_diff->saved_dist_arr[0][i - 1] = log2f( max( 1e-10f, pArith_diff->pFreq_model[i] ) ); pArith_diff->saved_dist_arr[0][i - 1] -= log2f( max( 1e-10f, sum ) ); } for ( j = 0; j < pArith_diff->num_models - 1; j++ ) { sum = 0; for ( i = 1; i < pArith_diff->range + 1; i++ ) { sum += pArith_diff->pAlt_freq_models[j][i]; } for ( i = 1; i < pArith_diff->range + 1; i++ ) { pArith_diff->saved_dist_arr[j + 1][i - 1] = log2f( max( 1e-10f, pArith_diff->pAlt_freq_models[j][i] ) ); pArith_diff->saved_dist_arr[j + 1][i - 1] -= log2f( max( 1e-10f, sum ) ); } } } return; } /*-----------------------------------------------------------------------------------------* * Function ivas_spar_arith_coeffs_com_init() * * Init for Arithm. coding *-----------------------------------------------------------------------------------------*/ 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, int16_t codec_mode ) { int16_t i; int16_t pred_r_index, drct_r_index, decd_r_index; int16_t num_quant_points_pred_r; int16_t num_quant_points_drct_r; int16_t num_quant_points_decd_r; 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 ); 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], codec_mode ); 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 ); 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], codec_mode ); 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 ); 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], codec_mode ); } return; } /*-----------------------------------------------------------------------------------------* * Function ivas_huffman_dec_init_min_max_len() * * Find min and max length in codebook and finalize initialization of ivas_huffman_cfg_t. *-----------------------------------------------------------------------------------------*/ 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; 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++ ) { code_len = codebook[1]; if ( p_huff_cfg->min_len > code_len ) { p_huff_cfg->min_len = code_len; } if ( p_huff_cfg->max_len < code_len ) { p_huff_cfg->max_len = code_len; } codebook = codebook + 3; } return; } /*-----------------------------------------------------------------------------------------* * Function ivas_spar_huff_coeffs_com_init() * * Init for Huffman decoding *-----------------------------------------------------------------------------------------*/ 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, int16_t codec_mode) { int16_t i; int16_t pred_r_index, drct_r_index, decd_r_index; int16_t num_quant_points_pred_r; int16_t num_quant_points_drct_r; int16_t num_quant_points_decd_r; ivas_huffman_cfg_t *p_huff_cfg; 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 ( codec_mode == 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 ); } p_huff_cfg = &pHuff_coeffs->drct_huff_re[i]; 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 ( codec_mode == 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 ); } p_huff_cfg = &pHuff_coeffs->decd_huff_re[i]; 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 ( codec_mode == 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 ); } } return; } #endif lib_com/ivas_fb_mixer.c +67 −0 Original line number Diff line number Diff line Loading @@ -276,6 +276,7 @@ ivas_error ivas_FB_mixer_open( ivas_get_active_bins( &pActive_bins_per_band, &pActive_bins_per_band_abs, &pStart_offset, &pStart_offset_abs, sampling_rate ); #ifndef FIX_SBA_CLEAN_UP_OPT for ( i = 0; i < num_bands; i++ ) { if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) count_malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL ) Loading @@ -283,6 +284,18 @@ ivas_error ivas_FB_mixer_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } } #else if ( fb_cfg->active_w_mixing != -1 ) { for ( i = 0; i < num_bands; i++ ) { if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) count_malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } } } #endif if ( sampling_rate != 48000 ) { Loading Loading @@ -416,11 +429,22 @@ void ivas_FB_mixer_close( { num_bands = hFbMixer->pFb->filterbank_num_bands; #ifndef FIX_SBA_CLEAN_UP_OPT for ( i = 0; i < num_bands; i++ ) { count_free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] ); hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = NULL; } #else if ( fb_cfg->active_w_mixing != -1 ) { for ( i = 0; i < num_bands; i++ ) { count_free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] ); hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = NULL; } } #endif if ( sampling_rate != 48000 ) { Loading Loading @@ -792,9 +816,16 @@ void ivas_fb_mixer_get_in_out_mapping( * Function to calculate number of active bands *-----------------------------------------------------------------------------------------*/ #ifndef FIX_SBA_CLEAN_UP_OPT static int16_t ivas_calculate_abs_fr( ivas_filterbank_t *pFb, const int32_t sampling_rate ) #else static int16_t ivas_calculate_abs_fr( ivas_filterbank_t *pFb, const int32_t sampling_rate, const int16_t alloc_fb_resp ) #endif { int16_t frame_len; float ppFilterbank_FRs_s[L_FRAME48k]; Loading Loading @@ -932,10 +963,17 @@ static int16_t ivas_calculate_abs_fr( temp = 0; } #ifndef FIX_SBA_CLEAN_UP_OPT if ( j < ( abs_active_bins + abs_start_offset ) && j >= abs_start_offset ) { pFb->fb_bin_to_band.pFb_bin_to_band[i][idx++] = temp; } #else if ( j < ( abs_active_bins + abs_start_offset ) && j >= abs_start_offset && alloc_fb_resp != -1 ) { pFb->fb_bin_to_band.pFb_bin_to_band[i][idx++] = temp; } #endif ppFilterbank_FRs_s[j] += temp; } Loading @@ -949,6 +987,25 @@ static int16_t ivas_calculate_abs_fr( } } #ifndef FIX_SBA_CLEAN_UP_OPT for ( j = 0; j < bands; j++ ) { int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; int16_t abs_start_offset = pFb->fb_bin_to_band.pFb_start_bin_per_band[j]; for ( i = 0; i < abs_active_bins; i++ ) { pFb->fb_bin_to_band.pFb_bin_to_band[j][i] /= ppFilterbank_FRs_s[i + abs_start_offset]; /*if(pFb->fb_bin_to_band.pFb_bin_to_band[j][i] > 0.5f) { num_active_bands = j + 1; break; }*/ } } #else if ( alloc_fb_resp != -1 ) { for ( j = 0; j < bands; j++ ) { int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; Loading @@ -964,6 +1021,8 @@ static int16_t ivas_calculate_abs_fr( }*/ } } } #endif return num_active_bands; } Loading Loading @@ -1105,7 +1164,11 @@ static ivas_error ivas_filterbank_setup( offset += pFb->fb_consts.pFilterbank_bins_per_band[j]; } #ifndef FIX_SBA_CLEAN_UP_OPT ivas_calculate_abs_fr( pFb, sampling_rate ); #else ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing ); #endif } else { Loading Loading @@ -1156,7 +1219,11 @@ static ivas_error ivas_filterbank_setup( pFb->fb_consts.ppFilterbank_FRs[1][j] = (const float *) pFb->fb_consts.ppFilterbank_FRs_non48k[1][j]; } #ifndef FIX_SBA_CLEAN_UP_OPT ivas_calculate_abs_fr( pFb, sampling_rate ); #else ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing ); #endif } } Loading lib_com/ivas_prot.h +160 −0 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
lib_com/ivas_cnst.h +46 −0 Original line number Diff line number Diff line Loading @@ -947,6 +947,7 @@ typedef enum #define SPAR_SID_BITS_TAR_PER_BAND 18 #ifndef FIX_SBA_CLEAN_UP_OPT typedef enum { WYXZ = 0, Loading @@ -955,6 +956,16 @@ typedef enum WZ, WYiX, } ivas_spar_foa_pmx_strings_t; #else typedef enum { WYXZ = 0, WY = 0, WX, WZ, WYiX, } ivas_spar_pmx_strings_t; #endif #define NUM_MD_Q_COEFS_SET 4 Loading Loading @@ -1025,6 +1036,41 @@ typedef enum PCA_MODE_INACTIVE = 1 } ivas_pca_bypass_mode; #ifdef FIX_SBA_CLEAN_UP_OPT enum { PRED_Q_1 = 0, PRED_Q_7, PRED_Q_15, PRED_Q_21, PRED_Q_31, PRED_Q_7_ACTIVE_W, TOTAL_PRED_QUANT_STRATS_HUFF = 5, PRED_Q_15_ACTIVE_W, PRED_Q_21_ACTIVE_W, TOTAL_PRED_QUANT_STRATS_ARITH }; enum { DRCT_Q_1 = 0, DRCT_Q_7, DRCT_Q_9, DRCT_Q_11, TOTAL_DRCT_QUANT_STRATS }; enum { DECD_Q_1 = 0, DECD_Q_3, DECD_Q_5, DECD_Q_7, DECD_Q_9, DECD_Q_11, TOTAL_DECD_QUANT_STRATS }; #endif /*----------------------------------------------------------------------------------* * MASA constants Loading
lib_com/ivas_dirac_com.c +8 −0 Original line number Diff line number Diff line Loading @@ -92,7 +92,11 @@ ivas_error ivas_dirac_config( sba_mode = ( (Encoder_Struct *) st_ivas )->sba_mode; if ( ( (Encoder_Struct *) st_ivas )->hSpar != NULL ) { #ifndef FIX_SBA_CLEAN_UP_OPT hFbMdft = ( (Encoder_Struct *) st_ivas )->hSpar->hSparFoa->hFbMixer; #else hFbMdft = ( (Encoder_Struct *) st_ivas )->hSpar->hFbMixer; #endif } else { Loading @@ -117,7 +121,11 @@ ivas_error ivas_dirac_config( sba_mode = ( (Decoder_Struct *) st_ivas )->sba_mode; if ( ( (Decoder_Struct *) st_ivas )->hSpar != NULL ) { #ifndef FIX_SBA_CLEAN_UP_OPT hFbMdft = ( (Decoder_Struct *) st_ivas )->hSpar->hSparFoa->hFbMixer; #else hFbMdft = ( (Decoder_Struct *) st_ivas )->hSpar->hFbMixer; #endif } else { Loading
lib_com/ivas_entropy_coder_common.c +362 −0 Original line number Diff line number Diff line Loading @@ -36,6 +36,11 @@ #include "debug.h" #endif #include "ivas_prot.h" #ifdef FIX_SBA_CLEAN_UP_OPT #include "ivas_rom_com.h" #include "math.h" #include "prot.h" #endif #include "wmops.h" Loading Loading @@ -91,3 +96,360 @@ void ivas_get_cum_freq_model( return; } #ifdef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_map_num_pred_r_to_idx() * * 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 ) { int16_t pred_r_to_idx = -1; if ( active_w_flag == 0 ) { switch ( num_quant_points_pred_r ) { case 1: pred_r_to_idx = PRED_Q_1; break; case 7: pred_r_to_idx = PRED_Q_7; break; case 15: pred_r_to_idx = PRED_Q_15; break; case 21: pred_r_to_idx = PRED_Q_21; break; case 31: pred_r_to_idx = PRED_Q_31; break; default: assert( "Forbidden value for prediction quantization strategy index" ); break; } } else { switch ( num_quant_points_pred_r ) { case 7: pred_r_to_idx = PRED_Q_7_ACTIVE_W; break; case 15: pred_r_to_idx = PRED_Q_15_ACTIVE_W; break; case 21: pred_r_to_idx = PRED_Q_21_ACTIVE_W; break; default: assert( "Forbidden value for prediction quantization strategy index" ); break; } } return pred_r_to_idx; } /*-----------------------------------------------------------------------------------------* * Function ivas_map_num_drct_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 ) { int16_t drct_r_to_idx = -1; switch ( num_quant_points_drct_r ) { case 1: drct_r_to_idx = DRCT_Q_1; break; case 7: drct_r_to_idx = DRCT_Q_7; break; case 9: drct_r_to_idx = DRCT_Q_9; break; case 11: drct_r_to_idx = DRCT_Q_11; break; default: assert( "Forbidden value for DRCT quantization strategy index" ); break; } return drct_r_to_idx; } /*-----------------------------------------------------------------------------------------* * Function ivas_map_num_decd_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 ) { int16_t decd_r_to_idx = -1; switch ( num_quant_points_decd_r ) { case 1: decd_r_to_idx = DECD_Q_1; break; case 3: decd_r_to_idx = DECD_Q_3; break; case 5: decd_r_to_idx = DECD_Q_5; break; case 7: decd_r_to_idx = DECD_Q_7; break; case 9: decd_r_to_idx = DECD_Q_9; break; case 11: decd_r_to_idx = DECD_Q_11; break; default: assert( "Forbidden value for DECD quantization strategy index" ); break; } return decd_r_to_idx; } /*---------------------------------------------------------------------------------------- - * * Function ivas_spar_arith_com_init() * * arith coder init *---------------------------------------------------------------------------------------- - */ static void ivas_spar_arith_com_init( ivas_arith_t *pArith, const ivas_freq_models_t *pFreq_models, ivas_arith_t *pArith_diff, const int16_t q_levels, int16_t codec_mode ) { int16_t i, j; 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 ( codec_mode == ENC ) { float sum = 0; for ( i = 1; i < pArith->range + 1; i++ ) { sum += pArith->pFreq_model[i]; } for ( i = 1; i < pArith->range + 1; i++ ) { pArith->saved_dist_arr[0][i - 1] = log2f( max( 1e-10f, pArith->pFreq_model[i] ) ); pArith->saved_dist_arr[0][i - 1] -= log2f( max( 1e-10f, sum ) ); } for ( j = 0; j < pArith->num_models - 1; j++ ) { sum = 0; for ( i = 1; i < pArith->range + 1; i++ ) { sum += pArith->pAlt_freq_models[j][i]; } for ( i = 1; i < pArith->range + 1; i++ ) { pArith->saved_dist_arr[j + 1][i - 1] = log2f( max( 1e-10f, pArith->pAlt_freq_models[j][i] ) ); pArith->saved_dist_arr[j + 1][i - 1] -= log2f( max( 1e-10f, sum ) ); } } } 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 ( codec_mode == ENC ) { float sum = 0; for ( i = 1; i < pArith_diff->range + 1; i++ ) { sum += pArith_diff->pFreq_model[i]; } for ( i = 1; i < pArith_diff->range + 1; i++ ) { pArith_diff->saved_dist_arr[0][i - 1] = log2f( max( 1e-10f, pArith_diff->pFreq_model[i] ) ); pArith_diff->saved_dist_arr[0][i - 1] -= log2f( max( 1e-10f, sum ) ); } for ( j = 0; j < pArith_diff->num_models - 1; j++ ) { sum = 0; for ( i = 1; i < pArith_diff->range + 1; i++ ) { sum += pArith_diff->pAlt_freq_models[j][i]; } for ( i = 1; i < pArith_diff->range + 1; i++ ) { pArith_diff->saved_dist_arr[j + 1][i - 1] = log2f( max( 1e-10f, pArith_diff->pAlt_freq_models[j][i] ) ); pArith_diff->saved_dist_arr[j + 1][i - 1] -= log2f( max( 1e-10f, sum ) ); } } } return; } /*-----------------------------------------------------------------------------------------* * Function ivas_spar_arith_coeffs_com_init() * * Init for Arithm. coding *-----------------------------------------------------------------------------------------*/ 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, int16_t codec_mode ) { int16_t i; int16_t pred_r_index, drct_r_index, decd_r_index; int16_t num_quant_points_pred_r; int16_t num_quant_points_drct_r; int16_t num_quant_points_decd_r; 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 ); 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], codec_mode ); 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 ); 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], codec_mode ); 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 ); 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], codec_mode ); } return; } /*-----------------------------------------------------------------------------------------* * Function ivas_huffman_dec_init_min_max_len() * * Find min and max length in codebook and finalize initialization of ivas_huffman_cfg_t. *-----------------------------------------------------------------------------------------*/ 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; 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++ ) { code_len = codebook[1]; if ( p_huff_cfg->min_len > code_len ) { p_huff_cfg->min_len = code_len; } if ( p_huff_cfg->max_len < code_len ) { p_huff_cfg->max_len = code_len; } codebook = codebook + 3; } return; } /*-----------------------------------------------------------------------------------------* * Function ivas_spar_huff_coeffs_com_init() * * Init for Huffman decoding *-----------------------------------------------------------------------------------------*/ 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, int16_t codec_mode) { int16_t i; int16_t pred_r_index, drct_r_index, decd_r_index; int16_t num_quant_points_pred_r; int16_t num_quant_points_drct_r; int16_t num_quant_points_decd_r; ivas_huffman_cfg_t *p_huff_cfg; 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 ( codec_mode == 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 ); } p_huff_cfg = &pHuff_coeffs->drct_huff_re[i]; 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 ( codec_mode == 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 ); } p_huff_cfg = &pHuff_coeffs->decd_huff_re[i]; 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 ( codec_mode == 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 ); } } return; } #endif
lib_com/ivas_fb_mixer.c +67 −0 Original line number Diff line number Diff line Loading @@ -276,6 +276,7 @@ ivas_error ivas_FB_mixer_open( ivas_get_active_bins( &pActive_bins_per_band, &pActive_bins_per_band_abs, &pStart_offset, &pStart_offset_abs, sampling_rate ); #ifndef FIX_SBA_CLEAN_UP_OPT for ( i = 0; i < num_bands; i++ ) { if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) count_malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL ) Loading @@ -283,6 +284,18 @@ ivas_error ivas_FB_mixer_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } } #else if ( fb_cfg->active_w_mixing != -1 ) { for ( i = 0; i < num_bands; i++ ) { if ( ( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = (float *) count_malloc( sizeof( float ) * pActive_bins_per_band_abs[i] ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for FB mixer encoder" ); } } } #endif if ( sampling_rate != 48000 ) { Loading Loading @@ -416,11 +429,22 @@ void ivas_FB_mixer_close( { num_bands = hFbMixer->pFb->filterbank_num_bands; #ifndef FIX_SBA_CLEAN_UP_OPT for ( i = 0; i < num_bands; i++ ) { count_free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] ); hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = NULL; } #else if ( fb_cfg->active_w_mixing != -1 ) { for ( i = 0; i < num_bands; i++ ) { count_free( hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] ); hFbMixer->pFb->fb_bin_to_band.pFb_bin_to_band[i] = NULL; } } #endif if ( sampling_rate != 48000 ) { Loading Loading @@ -792,9 +816,16 @@ void ivas_fb_mixer_get_in_out_mapping( * Function to calculate number of active bands *-----------------------------------------------------------------------------------------*/ #ifndef FIX_SBA_CLEAN_UP_OPT static int16_t ivas_calculate_abs_fr( ivas_filterbank_t *pFb, const int32_t sampling_rate ) #else static int16_t ivas_calculate_abs_fr( ivas_filterbank_t *pFb, const int32_t sampling_rate, const int16_t alloc_fb_resp ) #endif { int16_t frame_len; float ppFilterbank_FRs_s[L_FRAME48k]; Loading Loading @@ -932,10 +963,17 @@ static int16_t ivas_calculate_abs_fr( temp = 0; } #ifndef FIX_SBA_CLEAN_UP_OPT if ( j < ( abs_active_bins + abs_start_offset ) && j >= abs_start_offset ) { pFb->fb_bin_to_band.pFb_bin_to_band[i][idx++] = temp; } #else if ( j < ( abs_active_bins + abs_start_offset ) && j >= abs_start_offset && alloc_fb_resp != -1 ) { pFb->fb_bin_to_band.pFb_bin_to_band[i][idx++] = temp; } #endif ppFilterbank_FRs_s[j] += temp; } Loading @@ -949,6 +987,25 @@ static int16_t ivas_calculate_abs_fr( } } #ifndef FIX_SBA_CLEAN_UP_OPT for ( j = 0; j < bands; j++ ) { int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; int16_t abs_start_offset = pFb->fb_bin_to_band.pFb_start_bin_per_band[j]; for ( i = 0; i < abs_active_bins; i++ ) { pFb->fb_bin_to_band.pFb_bin_to_band[j][i] /= ppFilterbank_FRs_s[i + abs_start_offset]; /*if(pFb->fb_bin_to_band.pFb_bin_to_band[j][i] > 0.5f) { num_active_bands = j + 1; break; }*/ } } #else if ( alloc_fb_resp != -1 ) { for ( j = 0; j < bands; j++ ) { int16_t abs_active_bins = pFb->fb_bin_to_band.pFb_active_bins_per_band[j]; Loading @@ -964,6 +1021,8 @@ static int16_t ivas_calculate_abs_fr( }*/ } } } #endif return num_active_bands; } Loading Loading @@ -1105,7 +1164,11 @@ static ivas_error ivas_filterbank_setup( offset += pFb->fb_consts.pFilterbank_bins_per_band[j]; } #ifndef FIX_SBA_CLEAN_UP_OPT ivas_calculate_abs_fr( pFb, sampling_rate ); #else ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing ); #endif } else { Loading Loading @@ -1156,7 +1219,11 @@ static ivas_error ivas_filterbank_setup( pFb->fb_consts.ppFilterbank_FRs[1][j] = (const float *) pFb->fb_consts.ppFilterbank_FRs_non48k[1][j]; } #ifndef FIX_SBA_CLEAN_UP_OPT ivas_calculate_abs_fr( pFb, sampling_rate ); #else ivas_calculate_abs_fr( pFb, sampling_rate, pCfg->active_w_mixing ); #endif } } Loading
lib_com/ivas_prot.h +160 −0 File changed.Preview size limit exceeded, changes collapsed. Show changes