From 9c28d403b453f43624430622adcf365c692e95f6 Mon Sep 17 00:00:00 2001 From: rtyag Date: Thu, 7 Jul 2022 17:38:19 +1000 Subject: [PATCH] SBA bitexact ROM and RAM optimizations, function/file names cleanup, issues 6, 10, 17, 20 --- lib_com/ivas_cnst.h | 46 +++ lib_com/ivas_dirac_com.c | 8 + lib_com/ivas_entropy_coder_common.c | 362 ++++++++++++++++++++ lib_com/ivas_fb_mixer.c | 67 ++++ lib_com/ivas_prot.h | 160 +++++++++ lib_com/ivas_rom_com.c | 511 ++++++++++++++++++++++++++++ lib_com/ivas_rom_com.h | 10 + lib_com/ivas_spar_com.c | 46 +++ lib_com/ivas_spar_com_quant_util.c | 19 ++ lib_com/ivas_spar_foa_br_dist.c | 12 + lib_com/ivas_stat_com.h | 34 ++ lib_com/options.h | 1 + lib_dec/ivas_dec.c | 5 + lib_dec/ivas_entropy_decoder.c | 6 + lib_dec/ivas_init_dec.c | 41 +++ lib_dec/ivas_masa_dec.c | 8 + lib_dec/ivas_sba_dec.c | 4 + lib_dec/ivas_sba_rendering.c | 62 ++++ lib_dec/ivas_sce_dec.c | 4 + lib_dec/ivas_spar_decoder.c | 115 +++++++ lib_dec/ivas_spar_foa_dec.c | 194 +++++++++++ lib_dec/ivas_spar_foa_md_dec.c | 346 ++++++++++++++++++- lib_dec/ivas_stat_dec.h | 44 +++ lib_enc/ivas_dirac_enc.c | 5 + lib_enc/ivas_entropy_coder.c | 4 + lib_enc/ivas_sce_enc.c | 4 + lib_enc/ivas_spar_encoder.c | 123 +++++++ lib_enc/ivas_spar_foa_enc.c | 54 +++ lib_enc/ivas_spar_foa_md_enc.c | 215 ++++++++++++ lib_enc/ivas_stat_enc.h | 54 +++ 30 files changed, 2563 insertions(+), 1 deletion(-) diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index f7f69ae3ea..d36bf05de0 100644 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -947,6 +947,7 @@ typedef enum #define SPAR_SID_BITS_TAR_PER_BAND 18 +#ifndef FIX_SBA_CLEAN_UP_OPT typedef enum { WYXZ = 0, @@ -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 @@ -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 diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index a7e3680ba9..76d7650953 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -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 { @@ -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 { diff --git a/lib_com/ivas_entropy_coder_common.c b/lib_com/ivas_entropy_coder_common.c index 6e71b44d0a..5fb3f76977 100644 --- a/lib_com/ivas_entropy_coder_common.c +++ b/lib_com/ivas_entropy_coder_common.c @@ -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" @@ -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 diff --git a/lib_com/ivas_fb_mixer.c b/lib_com/ivas_fb_mixer.c index e9032d274d..0827c24b59 100644 --- a/lib_com/ivas_fb_mixer.c +++ b/lib_com/ivas_fb_mixer.c @@ -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 ) @@ -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 ) { @@ -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 ) { @@ -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]; @@ -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; } @@ -949,6 +987,7 @@ 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]; @@ -964,6 +1003,26 @@ static int16_t ivas_calculate_abs_fr( }*/ } } +#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]; + 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; + }*/ + } + } + } +#endif return num_active_bands; } @@ -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 { @@ -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 } } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index b297a7e727..a1b26ac2e1 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -3803,11 +3803,19 @@ int16_t ivas_get_spar_num_TCs( const int16_t sba_order /* i : IVAS SBA order */ ); +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_spar_set_bitrate_config( ivas_spar_foa_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ const int16_t table_idx, /* i : config. table index */ const int16_t num_bands /* i : number of bands */ ); +#else +void ivas_spar_set_bitrate_config( + ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ + const int16_t table_idx, /* i : config. table index */ + const int16_t num_bands /* i : number of bands */ +); +#endif #ifdef FIX_I1_113 void ivas_spar_bitrate_dist( @@ -3826,6 +3834,7 @@ void ivas_imdct( const float *pIn, float *pOut, const int16_t length ); void ivas_itda( const float *re, float *pOut, const int16_t length ); /* FOA module */ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_error ivas_spar_foa_enc_open( ivas_spar_foa_enc_state_t **hSparFoa, /* i/o: SPAR FOA encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ @@ -3862,6 +3871,22 @@ void ivas_spar_foa_dec_close( ivas_spar_foa_dec_state_t **hSparFoa, /* i/o: SPAR FOA decoder handle */ const int32_t output_Fs /* i : output sampling rate */ ); +#else +ivas_error ivas_spar_enc_process( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + const int16_t front_vad_flag, /* i : front-VAD decision */ + float ppPcm_in[][L_FRAME48k] /* i/o: input/transport audio channels */ +); + +void ivas_spar_get_cldfb_gains( + SPAR_DEC_HANDLE hSpar, + HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, + HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, + const DECODER_CONFIG_HANDLE hDecoderConfig +); +#endif /* !r: 1 if prediction residual channel */ int16_t ivas_is_res_channel( @@ -3869,6 +3894,7 @@ int16_t ivas_is_res_channel( const int16_t nchan_transport /* i : number of transport channels (1-4) */ ); +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_spar_foa_dec_upmixer( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ float output[][L_FRAME48k], /* i/o: input/output audio channels */ @@ -3893,6 +3919,32 @@ ivas_error ivas_spar_foa_md_enc_process( BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const int16_t dtx_silence_mode ); +#else +void ivas_spar_dec_upmixer( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float output[][L_FRAME48k], /* i/o: input/output audio channels */ + const int16_t nchan_internal, /* i : number of internal channels */ + const int16_t output_frame /* i : output frame length */ +); + +/* FOA MD module */ +ivas_error ivas_spar_md_enc_open( + ivas_spar_md_enc_state_t **hMdEnc, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +); + +void ivas_spar_md_enc_close( + ivas_spar_md_enc_state_t **hMdEnc /* i/o: SPAR MD encoder handle */ +); + +ivas_error ivas_spar_md_enc_process( + ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + ivas_spar_md_enc_in_buf_t *pIn_buf, + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + const int16_t dtx_silence_mode +); +#endif void ivas_compute_spar_params( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], @@ -3905,7 +3957,11 @@ void ivas_compute_spar_params( const int16_t num_ch, const int16_t bands_bw, const int16_t active_w, +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_com_cfg *hSparCfg, +#else + ivas_spar_md_com_cfg *hSparCfg, +#endif ivas_spar_md_t *hSparMd, float *pWscale, const int16_t from_dirac @@ -3919,7 +3975,11 @@ void ivas_create_fullr_dmx_mat( const int16_t start_band, const int16_t end_band, const int16_t active_w, +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_com_cfg *hMdCfg +#else + ivas_spar_md_com_cfg *hMdCfg +#endif ); void ivas_calc_c_p_coeffs( @@ -3942,7 +4002,11 @@ void ivas_get_spar_md_from_dirac( const int16_t n_ts, float ***mixer_mat, ivas_spar_md_t *hSpar_md, +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_com_cfg *hSpar_md_cfg, +#else + ivas_spar_md_com_cfg *hSpar_md_cfg, +#endif const int16_t start_band, const int16_t end_band, const int16_t order, @@ -3950,6 +4014,7 @@ void ivas_get_spar_md_from_dirac( float Wscale_d[IVAS_MAX_NUM_BANDS] ); +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_error ivas_spar_foa_md_dec_open( ivas_spar_foa_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ @@ -4015,6 +4080,73 @@ void ivas_spar_foa_dec_gen_umx_mat( const int16_t num_bands_out, /* i : number of output bands */ const int16_t bfi /* i : bad frame indicator */ ); +#else +ivas_error ivas_spar_md_dec_open( + ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t num_channels /* i : number of internal channels */ +); + +void ivas_spar_md_dec_close( + ivas_spar_md_dec_state_t **hMdDec /* i/o: SPAR MD decoder handle */ +); + +void ivas_spar_dec_MD( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0 /* i/o: decoder state structure - for bitstream handling*/ +); + +void ivas_spar_get_parameters( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR FOA decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t ts, /* i : time slot index */ + const int16_t num_ch_out, /* i : number of channels out */ + const int16_t num_ch_in, /* i : number of channels in */ + const int16_t num_spar_bands, /* i : number of SPAR bands */ + float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] /* o : mixing matrix */ +); + +ivas_error ivas_spar_md_dec_init( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t num_channels /* i : number of internal channels */ +); + +void ivas_spar_md_dec_process( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t sba_order /* i : SBA order */ +); + +void ivas_spar_to_dirac( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t dtx_vad, /* i : DTX frame flag */ + const int16_t num_bands_out /* i : number of output bands */ +); + +void ivas_spar_update_md_hist( + ivas_spar_md_dec_state_t *hMdDec /* i/o: SPAR MD decoder handle */ +); + +void ivas_spar_smooth_md_dtx( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_bands_out /* i : number of output bands */ +); + +void ivas_spar_setup_md_smoothing( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_bands_out /* i : number of output bands */ +); + +void ivas_spar_dec_gen_umx_mat( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t bfi /* i : bad frame indicator */ +); +#endif /* Covariance module */ ivas_error ivas_spar_covar_enc_open( @@ -4234,13 +4366,20 @@ int16_t ivas_get_bits_to_encode( ); void ivas_huffman_encode( ivas_huffman_cfg_t *huff_cfg, int16_t in, int16_t *hcode, int16_t *hlen ); +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_huff_coeffs_enc_init( ivas_huff_coeffs_t *pHuff_coeffs, const int16_t table_idx ); void ivas_arith_coeffs_enc_init( ivas_arith_coeffs_t *pArith_coeffs, ivas_spar_foa_md_com_cfg *pSpar_cfg, const int16_t table_idx ); +#else +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 ); +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 ); +#endif void 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, ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, const int16_t any_diff); ivas_error ivas_huffman_decode( ivas_huffman_cfg_t *huff_cfg, Decoder_State *st0, int16_t *dec_out ); void ivas_arith_decode_cmplx_cell_array( ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, Decoder_State *st0, ivas_cell_dim_t *pCell_dims, int16_t *pDo_diff, const int16_t nB, int16_t *pSymbol_re, int16_t *pSymbol_re_old ); +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_arith_coeffs_dec_init( ivas_arith_coeffs_t *pArith_coeffs, ivas_spar_foa_md_com_cfg *pSpar_cfg, const int16_t table_idx ); void ivas_huff_coeffs_dec_init( ivas_huff_coeffs_t *pHuff_coeffs, ivas_spar_foa_md_com_cfg *pSpar_cfg, const int16_t table_idx ); +#endif void ivas_ari_start_decoding_14bits_ext_1_lfe( Decoder_State *st, Tastat *s, int16_t *extra_bits_read ); uint16_t ivas_ari_decode_14bits_bit_ext_1_lfe( Decoder_State *st, Tastat *s, const uint16_t *cum_freq, int16_t *extra_bits_read ); @@ -4250,6 +4389,11 @@ void ivas_ari_encode_14bits_ext( BSTR_ENC_HANDLE hBstr, Tastat *s, int32_t symbo void ivas_wrap_arround( int16_t *pArr, const int16_t min_val, const int16_t max_val, const int16_t length ); void ivas_get_cum_freq_model( const int16_t *pFreq_model, const int16_t length, int16_t *pCum_freq_model ); +#ifdef FIX_SBA_CLEAN_UP_OPT +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 ivas_map_num_drct_r_to_idx( const int16_t num_quant_points_drct_r ); +int16_t ivas_map_num_decd_r_to_idx( const int16_t num_quant_points_decd_r ); +#endif /* Quantization utilities */ void ivas_quantise_real_values( @@ -4263,22 +4407,38 @@ void ivas_quantise_real_values( const int16_t dim2 ); +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_spar_foa_get_uniform_quant_strat( ivas_spar_foa_md_com_cfg *pSpar_md_com_cfg, const int16_t table_idx ); +#else +void ivas_spar_get_uniform_quant_strat( + ivas_spar_md_com_cfg *pSpar_md_com_cfg, + const int16_t table_idx +); +#endif void ivas_spar_quant_dtx_init( ivas_spar_md_t *spar_md, float *min_max ); +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_map_prior_coeffs_quant( ivas_spar_md_prev_t *pSpar_md_prior, ivas_spar_foa_md_com_cfg *pSpar_md_cfg, const int16_t qsi, const int16_t nB ); +#else +void ivas_map_prior_coeffs_quant( + ivas_spar_md_prev_t *pSpar_md_prior, + ivas_spar_md_com_cfg *pSpar_md_cfg, + const int16_t qsi, + const int16_t nB +); +#endif void ivas_copy_band_coeffs_idx_to_arr( ivas_band_coeffs_ind_t *pBands_idx, diff --git a/lib_com/ivas_rom_com.c b/lib_com/ivas_rom_com.c index dd078e2dd7..63fed2c134 100644 --- a/lib_com/ivas_rom_com.c +++ b/lib_com/ivas_rom_com.c @@ -957,6 +957,401 @@ const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN] = }; + +#ifdef FIX_SBA_CLEAN_UP_OPT +const ivas_freq_models_t ivas_arith_pred_r_consts[TOTAL_PRED_QUANT_STRATS_ARITH] = +{ + /* entry for 1 quantization points */ + { + /* pred_R real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* pred_R real : values for general and differential */ + { 0 },{ 0 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 7 quantization points for br_table_idx >= 2 */ + { + /* pred_R real */ + { + { 0,546,1092,2184,8740,2184,1092,546, }, + { 0,1779,2116,2516,3562,2516,2116,1779, }, + { 0,1848,2614,5229,2614,1848,1307,924, }, + { 0,924,1307,1848,2614,5229,2614,1848, }, + }, + /* pred_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* pred_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 15 quantization points for br_table_idx >= 2 */ + { + /* pred_R real */ + { + { 0,32,64,128,257,514,1028,2056,8226,2056,1028,514,257,128,64,32, }, + { 0,565,672,799,950,1130,1344,1598,2268,1598,1344,1130,950,799,672,565, }, + { 0,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353,250,176, }, + { 0,176,250,353,500,707,1000,1414,2000,4010,2000,1414,1000,707,500,353, }, + }, + /* pred_R real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, }, + }, + /* pred_R real : values for general and differential */ + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 21 quantization points for br_table_idx >= 2 */ + { + /* pred_R real */ + { + { 0,4,8,16,32,64,128,256,512,1024,2049,8198,2049,1024,512,256,128,64,32,16,8,4, }, + { 0,292,348,414,492,585,696,828,984,1171,1392,1980,1392,1171,984,828,696,585,492,414,348,292, }, + { 0,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119,84,59, }, + { 0,59,84,119,168,238,336,476,673,952,1346,1904,3817,1904,1346,952,673,476,336,238,168,119, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 31 quantization points */ + { + /* pred real */ + { + { 0,1,1,1,1,2,4,8,16,32,64,128,256,512,1024,2048,8188,2048,1024,512,256,128,64,32,16,8,4,2,1,1,1,1, }, + { 0,110,131,156,186,221,263,313,373,443,527,627,746,887,1055,1255,1798,1255,1055,887,746,627,527,443,373,313,263,221,186,156,131,110, }, + { 0,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20,14,10, }, + { 0,10,14,20,29,41,58,82,116,164,233,329,466,659,932,1318,1864,3738,1864,1318,932,659,466,329,233,164,116,82,58,41,29,20, } + }, + /* pred real differential */ + { + { 0,1,1,1,1,1,1,1,1,1,3,12,39,125,397,1260,12694,1260,397,125,39,12,3,1,1,1,1,1,1,1,1,1, }, + { 0,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1, }, + { 0,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1,1,1, }, + { 0,1,1,1,2,3,6,11,20,37,66,117,210,374,667,1189,2118,6740,2118,1189,667,374,210,117,66,37,20,11,6,3,2,1, } + }, + /* pred real : values for general and differential */ + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + { -15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 }, + /* pred real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 7 quantization points for br_table_idx < 2 */ + { + /* pred_R real */ + { + { 0,327,778,1851,10472,1851,778,327, }, + { 0,1057,1630,2514,5982,2514,1630,1057, }, + { 0,1668,2572,6122,2572,1668,1081,701, }, + { 0,701,1081,1668,2572,6122,2572,1668, }, + }, + /* pred_R real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* pred_R real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 15 quantization points for br_table_idx < 2 */ + { + /* pred real */ + { + { 0,9,23,56,133,318,757,1800,10192,1800,757,318,133,56,23,9, }, + { 0,156,240,371,573,883,1363,2102,5008,2102,1363,883,573,371,240,156, }, + { 0,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241,156,101, }, + { 0,101,156,241,372,575,886,1367,2109,5027,2109,1367,886,575,372,241, } + }, + /* pred real differential */ + { + { 0,1,3,12,39,125,397,1260,12710,1260,397,125,39,12,3,1, }, + { 0,66,119,212,378,674,1201,2140,6804,2140,1201,674,378,212,119,66, }, + { 0,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119,67,37, }, + { 0,37,67,119,212,379,675,1203,2144,6816,2144,1203,675,379,212,119, } + }, + /* pred real : values for general and differential */ + {-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7}, + { -7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7 }, + /* pred real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 21 quantization points for br_table_idx < 2 */ + { + /* pred_R real */ + { + { 0,1,1,4,9,23,56,133,318,756,1799,10184,1799,756,318,133,56,23,9,4,1,1, }, + { 0,41,64,98,152,234,362,558,861,1329,2049,4888,2049,1329,861,558,362,234,152,98,64,41, }, + { 0,64,98,152,235,362,559,862,1330,2051,4891,2051,1330,862,559,362,235,152,98,64,41,26, }, + { 0,26,41,64,98,152,235,362,559,862,1330,2051,4891,2051,1330,862,559,362,235,152,98,64, }, + }, + /* pred_R real differential */ + { + { 0,1,1,1,1,3,12,39,125,397,1260,12704,1260,397,125,39,12,3,1,1,1,1, }, + { 0,11,20,37,66,118,210,375,668,1191,2122,6748,2122,1191,668,375,210,118,66,37,20,11, }, + { 0,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20,11,6, }, + { 0,6,11,20,37,66,118,210,375,668,1191,2123,6751,2123,1191,668,375,210,118,66,37,20, }, + }, + /* pred_R real : values for general and differential */ + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + { -10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10 }, + /* pred_R real : num dyn models for general and differential */ + 4, 4 + } +}; + + const ivas_freq_models_t ivas_arith_drct_r_consts[TOTAL_DRCT_QUANT_STRATS] = +{ + /* entry for 1 quantization points */ + { + /* drct real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* drct real : values for general and differential */ + {0},{ 0 }, + /* drct real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 7 quantization points */ + { /* drct real */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,988,1244,1568,1976,2489,3136,4983, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* drct real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, }, + }, + /* drct real : values for general and differential */ + { -3,-2,-1,0,1,2,3 },{ -3,-2,-1,0,1,2,3 }, + /* drct real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 9 quantization points */ + { + /* drct real */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,573,722,909,1146,1444,1819,2292,2888,4591, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* drct real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, } + }, + /* drct real : values for general and differential */ + { -4,-3,-2,-1,0,1,2,3,4 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* drct real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 11 quantization points */ + { + /* drct real */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,343,433,546,687,866,1092,1375,1733,2184,2751,4374, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* drct real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* drct real : values for general and differential */ + { -5,-4,-3,-2,-1,0,1,2,3,4,5 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* drct real : num dyn models for general and differential */ + 4, 4 + } +}; + + const ivas_freq_models_t ivas_arith_decd_r_consts[TOTAL_DECD_QUANT_STRATS] = +{ + /* entry for 1 quantization points */ + { + /* decd real */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd real differential */ + { + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + { 0,16384, }, + }, + /* decd real : values for general and differential */ + { 0 },{ 0 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 3 quantization points */ + { + /* decd real */ + { + { 0,11917,2978,1489, }, + { 0,8840,4419,3125, }, + { 0,4567,7250,4567, }, + { 0,5203,5978,5203, }, + }, + /* decd real differential */ + { + { 0,1356,13672,1356, }, + { 0,3166,10052,3166, }, + { 0,10984,3459,1941, }, + { 0,1941,3459,10984, }, + }, + /* decd real : values for general and differential */ + { 0,1,2 },{-1,0,1}, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 5 quantization points */ + { + /* decd real */ + { + { 0,11157,2788,1394,697,348, }, + { 0,7186,3592,2540,1796,1270, }, + { 0,2512,3166,5028,3166,2512, }, + { 0,3048,3267,3754,3267,3048, }, + }, + /* decd real differential */ + { + { 0,406,1289,12994,1289,406, }, + { 0,1460,2601,8262,2601,1460, }, + { 0,2707,8599,2707,1519,852, }, + { 0,852,1519,2707,8599,2707, }, + }, + /* decd real : values for general and differential */ + { 0,1,2,3,4 },{ -2,-1,0,1,2 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 7 quantization points */ + { + /* decd real */ + { + { 0,10983,2744,1372,686,343,171,85, }, + { 0,6573,3285,2322,1642,1161,821,580, }, + { 0,1603,2020,2546,4046,2546,2020,1603, }, + { 0,2111,2262,2425,2788,2425,2262,2111, }, + }, + /* decd real differential */ + { + { 0,125,399,1269,12798,1269,399,125, }, + { 0,744,1327,2365,7512,2365,1327,744, }, + { 0,1354,2413,7664,2413,1354,760,426, }, + { 0,426,760,1354,2413,7664,2413,1354, } + }, + /* decd real : values for general and differential */ + { 0,1,2,3,4,5,6 },{ -3,-2,-1,0,1,2,3 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 9 quantization points */ + { /* decd real */ + { + { 0,10941,2734,1367,683,341,170,85,42,21, }, + { 0,6305,3150,2227,1575,1113,787,556,393,278, }, + { 0,1101,1388,1749,2203,3502,2203,1749,1388,1101, }, + { 0,1587,1701,1824,1955,2250,1955,1824,1701,1587, }, + }, + /* decd real differential */ + { + { 0,39,125,397,1263,12736,1263,397,125,39, }, + { 0,397,708,1262,2250,7150,2250,1262,708,397, }, + { 0,716,1276,2274,7225,2274,1276,716,402,225, }, + { 0,225,402,716,1276,2274,7225,2274,1276,716, } + }, + /* decd real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8 },{ -4,-3,-2,-1,0,1,2,3,4 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + }, + /* entry for 11 quantization points */ + { + /* decd real */ + { + { 0,10932,2731,1365,682,341,170,85,42,21,10,5, }, + { 0,6181,3086,2182,1543,1091,771,545,385,272,192,136, }, + { 0,790,995,1254,1580,1991,3164,1991,1580,1254,995,790, }, + { 0,1254,1344,1441,1544,1655,1908,1655,1544,1441,1344,1254, }, + }, + /* decd real differential */ + { + { 0,12,39,125,397,1261,12716,1261,397,125,39,12, }, + { 0,217,387,689,1229,2190,6960,2190,1229,689,387,217, }, + { 0,389,694,1236,2203,7000,2203,1236,694,389,218,122, }, + { 0,122,218,389,694,1236,2203,7000,2203,1236,694,389, }, + }, + /* decd real : values for general and differential */ + { 0,1,2,3,4,5,6,7,8,9,10 },{ -5,-4,-3,-2,-1,0,1,2,3,4,5 }, + /* decd real : num dyn models for general and differential */ + 4, 4 + } +}; +#else const ivas_arith_consts_t ivas_arith_consts[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_STRATS] = { /* tbl_idx 0 -- 24.4kbps FOA */ @@ -4451,7 +4846,122 @@ const ivas_arith_consts_t ivas_arith_consts[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_ST }, }; +#endif + +#ifdef FIX_SBA_CLEAN_UP_OPT +const ivas_huff_models_t ivas_huff_pred_r_consts[TOTAL_PRED_QUANT_STRATS_HUFF] = +{ + /* entry for 1 quantization points for br_table_idx */ + {{{ 0 }}, {{ 0 }}}, + /* entry for 7 quantization points for br_table_idx */ + { + /* pred_R codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + /* pred_R differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 }, }, + }, + /* entry for 15 quantization points for br_table_idx */ + { + /* pred_r codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5, 4, 4 },{ -4, 4, 5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 }, + { 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 } }, + /* pred_r differential codebook */ + { { -7,4,2 },{ -6,4,3 },{ -5, 4, 4 },{ -4, 4, 5 },{ -3,4,6 },{ -2,4,7 },{ -1,4,8 }, + { 0,3,0 },{ 1,4,9 },{ 2,4,10 },{ 3,4,11 },{ 4,4,12 },{ 5,4,13 },{ 6,4,14 },{ 7,4,15 } }, + }, + /* entry for 21 quantization points for br_table_idx=0 */ + { + /* pred_r codebook */ + { {-10,5,22},{-9,5,23},{-8,5,24},{-7,5,25},{-6,5,26}, { -5, 4, 0 },{ -4, 4, 1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 }, + { 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{6,5,27},{7,5,28},{8,5,29},{9,5,30},{10,5,31} }, + /* pred_r differential codebook */ + { { -10,5,22 },{ -9,5,23 },{ -8,5,24 },{ -7,5,25 },{ -6,5,26 },{ -5, 4, 0 },{ -4, 4, 1 },{ -3,4,2 },{ -2,4,3 },{ -1,4,4 }, + { 0,4,5 },{ 1,4,6 },{ 2,4,7 },{ 3,4,8 },{ 4,4,9 },{ 5,4,10 },{ 6,5,27 },{ 7,5,28 },{ 8,5,29 },{ 9,5,30 },{ 10,5,31 } }, + }, + + /* entry for 31 quantization points for br_table_idx>0 */ + { + /* pred_r codebook */ + { {-15,5,2},{-14,5,3},{-13,5,4},{-12,5,5},{-11,5,6}, { -10,5,7 },{ -9,5,8 },{ -8,5,9 }, + { -7,5,10 },{ -6,5,11 },{ -5, 5, 12 },{ -4, 5, 13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 }, + { 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 }, + { 8,5,24 },{ 9,5,25 },{ 10,5,26 },{11,5,27},{12,5,28},{13,5,29},{14,5,30},{15,5,31} }, + /* pred_r differential codebook */ + { { -15,5,2 },{ -14,5,3 },{ -13,5,4 },{ -12,5,5 },{ -11,5,6 },{ -10,5,7 },{ -9,5,8 },{ -8,5,9 }, + { -7,5,10 },{ -6,5,11 },{ -5, 5, 12 },{ -4, 5, 13 },{ -3,5,14 },{ -2,5,15 },{ -1,5,16 }, + { 0,4,0 },{ 1,5,17 },{ 2,5,18 },{ 3,5,19 },{ 4,5,20 },{ 5,5,21 },{ 6,5,22 },{ 7,5,23 }, + { 8,5,24 },{ 9,5,25 },{ 10,5,26 },{ 11,5,27 },{ 12,5,28 },{ 13,5,29 },{ 14,5,30 },{ 15,5,31 } }, + }, + }; + + const ivas_huff_models_t ivas_huff_drct_r_consts[TOTAL_DRCT_QUANT_STRATS] = +{ + /* entry for 1 quantization points */ + {{{ 0 }}, {{ 0 }}}, + /* entry for 7 quantization points */ + { + /* drct_r codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 } }, + /* drct_r differential codebook */ + { { -3,3,2 },{ -2,3,3 },{ -1,3,4 },{ 0,2,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 } }, + }, + /* entry for 9 quantization points */ + { + /* drct_r codebook */ + { { -4, 4, 14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 } }, + /* drct_r differential codebook */ + { { -4, 4, 14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 } }, + }, + /* entry for 11 quantization points */ + { + /* drct_r codebook */ + { { -5, 4, 10 },{ -4, 4, 11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 } }, + /* drct_r differential codebook */ + { { -5, 4, 10 },{ -4, 4, 11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 } }, + }, +}; +const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS] = +{ + /* entry for 1 quantization points */ + {{{ 0 }}, {{ 0 }}}, + /* entry for 3 quantization points */ + { + /* decd_r codebook */ + { { 0, 2, 2 },{ 1, 1, 0 },{ 2,2,3 } }, + /* decd_r differential codebook */ + { { -1, 2, 2 },{ 0, 1, 0 },{ 1,2,3 } }, + }, + /* entry for 5 quantization points */ + { + /* decd_r codebook */ + { { 0,3,6 },{ 1,2,0 },{ 2,2,1 },{ 3,2,2 },{ 4,3,7 } }, + /* decd_r differential codebook */ + { { -2,3,6 },{ -1,2,0 },{ 0,2,1 },{ 1,2,2 },{ 2,3,7 } }, + }, + /* entry for 7 quantization points */ + { + /* decd_r */ + { { 0, 3, 2 },{ 1, 3, 3 },{ 2,3,4 },{ 3,3,0 },{ 4,3,5 },{ 5,3,6 },{ 6,3,7 } }, + /* decd_r codebook differential codebook */ + { { -3, 3, 2 },{ -2, 3, 3 },{ -1,3,4 },{ 0,3,0 },{ 1,3,5 },{ 2,3,6 },{ 3,3,7 } }, + }, + /* entry for 9 quantization points */ + { + /* decd_r codebook */ + { { 0, 4, 14 },{ 1,3,0 },{ 2,3,1 },{ 3,3,2 },{ 4,3,3 },{ 5,3,4 },{ 6,3,5 },{ 7,3,6 },{ 8,4,15 } }, + /* decd_r differential codebook */ + { { -4, 4, 14 },{ -3,3,0 },{ -2,3,1 },{ -1,3,2 },{ 0,3,3 },{ 1,3,4 },{ 2,3,5 },{ 3,3,6 },{ 4,4,15 } }, + }, + /* entry for 11 quantization points */ + { + /* decd_r codebook */ + { { 0, 4, 10 },{ 1, 4, 11 },{ 2,4,12 },{ 3,3,0 },{ 4,3,1 },{ 5,3,2 },{ 6,3,3 },{ 7,3,4 },{ 8,4,13 },{ 9,4,14 },{ 10,4,15 } }, + /* decd_r differential codebook */ + { { -5, 4, 10 },{ -4, 4, 11 },{ -3,4,12 },{ -2,3,0 },{ -1,3,1 },{ 0,3,2 },{ 1,3,3 },{ 2,3,4 },{ 3,4,13 },{ 4,4,14 },{ 5,4,15 } }, + }, +}; +#else const ivas_huff_consts_t ivas_huff_const[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_STRATS] = { /* tbl_idx 0 -- 24.4kbps FOA */ @@ -5387,6 +5897,7 @@ const ivas_huff_consts_t ivas_huff_const[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_STRAT }, }, }; +#endif /* DTX quantization and bitstream constants */ diff --git a/lib_com/ivas_rom_com.h b/lib_com/ivas_rom_com.h index 1415ae9f3e..0b64eabf7a 100644 --- a/lib_com/ivas_rom_com.h +++ b/lib_com/ivas_rom_com.h @@ -170,9 +170,19 @@ extern const int16_t DirAC_block_grouping_5ms_MDFT[MAX_PARAM_SPATIAL_SUBFRAMES + * SPAR ROM tables *------------------------------------------------------------------------------------------*/ +#ifdef FIX_SBA_CLEAN_UP_OPT +extern const ivas_freq_models_t ivas_arith_pred_r_consts[TOTAL_PRED_QUANT_STRATS_ARITH]; +extern const ivas_freq_models_t ivas_arith_drct_r_consts[TOTAL_DRCT_QUANT_STRATS]; +extern const ivas_freq_models_t ivas_arith_decd_r_consts[TOTAL_DECD_QUANT_STRATS]; +extern const ivas_huff_models_t ivas_huff_pred_r_consts[TOTAL_PRED_QUANT_STRATS_HUFF]; +extern const ivas_huff_models_t ivas_huff_drct_r_consts[TOTAL_DRCT_QUANT_STRATS]; +extern const ivas_huff_models_t ivas_huff_decd_r_consts[TOTAL_DECD_QUANT_STRATS]; +#endif extern const ivas_spar_br_table_t ivas_spar_br_table_consts[IVAS_SPAR_BR_TABLE_LEN]; +#ifndef FIX_SBA_CLEAN_UP_OPT extern const ivas_arith_consts_t ivas_arith_consts[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_STRATS]; extern const ivas_huff_consts_t ivas_huff_const[IVAS_SPAR_BR_TABLE_LEN][MAX_QUANT_STRATS]; +#endif extern const int16_t remix_order_set[1][IVAS_SPAR_MAX_CH]; extern const int16_t keep_planar[IVAS_SPAR_MAX_CH - FOA_CHANNELS]; extern const int16_t HOA_keep_ind[IVAS_SPAR_MAX_CH]; diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index ad0873624e..7e1939aabc 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -695,6 +695,7 @@ static void ivas_get_Wscaling_factor( * Calculation of downmix matrix *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_create_fullr_dmx_mat( float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], @@ -704,6 +705,17 @@ void ivas_create_fullr_dmx_mat( const int16_t end_band, const int16_t active_w, ivas_spar_foa_md_com_cfg *hMdCfg ) +#else +void ivas_create_fullr_dmx_mat( + float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + float ***mixer_mat, + const int16_t in_chans, + const int16_t start_band, + const int16_t end_band, + const int16_t active_w, + ivas_spar_md_com_cfg *hMdCfg ) +#endif { int16_t i, j, k, b; const int16_t *order; @@ -1522,6 +1534,7 @@ static int16_t ivas_is_mat_inv( * *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_compute_spar_params( float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], @@ -1537,6 +1550,23 @@ void ivas_compute_spar_params( ivas_spar_md_t *hSparMd, float *pWscale, const int16_t from_dirac ) +#else +void ivas_compute_spar_params( + float *pppCov_mat_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], + float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS], + const int16_t i_ts, + float ***mixer_mat, + const int16_t start_band, + const int16_t end_band, + const int16_t dtx_vad, + const int16_t num_ch, + const int16_t bands_bw, + const int16_t active_w, + ivas_spar_md_com_cfg *hSparCfg, + ivas_spar_md_t *hSparMd, + float *pWscale, + const int16_t from_dirac ) +#endif { float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; int16_t b, i, ndm; @@ -1630,6 +1660,7 @@ void ivas_compute_spar_params( * *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_get_spar_md_from_dirac( float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], @@ -1643,6 +1674,21 @@ void ivas_get_spar_md_from_dirac( const int16_t order, const int16_t dtx_vad, float Wscale_d[IVAS_MAX_NUM_BANDS] ) +#else +void ivas_get_spar_md_from_dirac( + float azi_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + float ele_dirac[IVAS_MAX_NUM_BANDS][MAX_PARAM_SPATIAL_SUBFRAMES], + float diffuseness[IVAS_MAX_NUM_BANDS], + const int16_t n_ts, + float ***mixer_mat, + ivas_spar_md_t *hSpar_md, + ivas_spar_md_com_cfg *hSpar_md_cfg, + const int16_t start_band, + const int16_t end_band, + const int16_t order, + const int16_t dtx_vad, + float Wscale_d[IVAS_MAX_NUM_BANDS] ) +#endif { int16_t num_ch, band, i, j; int16_t block, ch; diff --git a/lib_com/ivas_spar_com_quant_util.c b/lib_com/ivas_spar_com_quant_util.c index 4725488338..c8e8a4e92e 100644 --- a/lib_com/ivas_spar_com_quant_util.c +++ b/lib_com/ivas_spar_com_quant_util.c @@ -130,6 +130,7 @@ void ivas_quantise_real_values( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_get_uniform_quant_strat() * @@ -139,6 +140,16 @@ void ivas_quantise_real_values( void ivas_spar_foa_get_uniform_quant_strat( ivas_spar_foa_md_com_cfg *pSpar_md_com_cfg, const int16_t table_idx ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_get_uniform_quant_strat() + * + * Sets the quant strat values + *-----------------------------------------------------------------------------------------*/ +void ivas_spar_get_uniform_quant_strat( + ivas_spar_md_com_cfg *pSpar_md_com_cfg, + const int16_t table_idx ) +#endif { int16_t i; int16_t active_w = ivas_spar_br_table_consts[table_idx].active_w; @@ -209,11 +220,19 @@ void ivas_spar_foa_get_uniform_quant_strat( * Map prior coeffs *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_map_prior_coeffs_quant( ivas_spar_md_prev_t *pSpar_md_prior, ivas_spar_foa_md_com_cfg *pSpar_md_cfg, const int16_t qsi, const int16_t nB ) +#else +void ivas_map_prior_coeffs_quant( + ivas_spar_md_prev_t *pSpar_md_prior, + ivas_spar_md_com_cfg *pSpar_md_cfg, + const int16_t qsi, + const int16_t nB ) +#endif { int16_t i, j; diff --git a/lib_com/ivas_spar_foa_br_dist.c b/lib_com/ivas_spar_foa_br_dist.c index 607ebc56ab..46db9de8e0 100644 --- a/lib_com/ivas_spar_foa_br_dist.c +++ b/lib_com/ivas_spar_foa_br_dist.c @@ -50,11 +50,19 @@ * Set SPAR bitrate config *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_spar_set_bitrate_config( ivas_spar_foa_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ const int16_t table_idx, /* i : config. table index */ const int16_t num_bands /* i : number of bands */ ) +#else +void ivas_spar_set_bitrate_config( + ivas_spar_md_com_cfg *pSpar_md_cfg, /* i/o: SPAR MD config. handle */ + const int16_t table_idx, /* i : config. table index */ + const int16_t num_bands /* i : number of bands */ +) +#endif { int32_t ivas_total_brate; int16_t i, total_bits, max_bits, code, length; @@ -69,7 +77,11 @@ void ivas_spar_set_bitrate_config( pSpar_md_cfg->active_w = ivas_spar_br_table_consts[table_idx].active_w; pSpar_md_cfg->agc_bits_ch_idx = ivas_spar_br_table_consts[table_idx].agc_bits_ch_idx; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_get_uniform_quant_strat( pSpar_md_cfg, table_idx ); +#else + ivas_spar_get_uniform_quant_strat( pSpar_md_cfg, table_idx ); +#endif if ( pSpar_md_cfg->quant_strat->C.q_levels[0] == 0 || pSpar_md_cfg->quant_strat->C.q_levels[1] == 0 || pSpar_md_cfg->quant_strat->PR.q_levels[0] == 0 || pSpar_md_cfg->quant_strat->PR.q_levels[1] == 0 || pSpar_md_cfg->quant_strat->P_c.q_levels[0] == 0 || pSpar_md_cfg->quant_strat->P_c.q_levels[1] == 0 || pSpar_md_cfg->quant_strat->P_r.q_levels[0] == 0 || pSpar_md_cfg->quant_strat->P_r.q_levels[1] == 0 ) { diff --git a/lib_com/ivas_stat_com.h b/lib_com/ivas_stat_com.h index cd5fff8afc..36a1d939d4 100644 --- a/lib_com/ivas_stat_com.h +++ b/lib_com/ivas_stat_com.h @@ -187,7 +187,11 @@ typedef struct ivas_band_coeffs_ind_t typedef struct ivas_spar_md_t { +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_band_coeffs_t band_coeffs[IVAS_MAX_NUM_BANDS * MAX_PARAM_SPATIAL_SUBFRAMES]; +#else + ivas_band_coeffs_t *band_coeffs; +#endif ivas_band_coeffs_ind_t band_coeffs_idx[IVAS_MAX_NUM_BANDS]; int16_t num_bands; float min_max[2]; @@ -220,6 +224,7 @@ typedef struct ivas_quant_strat_t } ivas_quant_strat_t; +#ifndef FIX_SBA_CLEAN_UP_OPT typedef struct ivas_spar_foa_md_com_cfg { int16_t max_freq_per_chan[IVAS_SPAR_MAX_CH]; @@ -241,6 +246,29 @@ typedef struct ivas_spar_foa_md_com_cfg int16_t num_umx_chs; } ivas_spar_foa_md_com_cfg; +#else +typedef struct ivas_spar_md_com_cfg +{ + int16_t max_freq_per_chan[IVAS_SPAR_MAX_CH]; + int16_t num_dmx_chans_per_band[IVAS_MAX_NUM_BANDS]; + int16_t num_decorr_per_band[IVAS_MAX_NUM_BANDS]; + int16_t active_w; + int16_t remix_unmix_order; + ivas_quant_strat_t quant_strat[MAX_QUANT_STRATS]; + int16_t gen_bs; + int16_t quant_strat_bits; + int16_t nchan_transport; + int16_t num_quant_strats; + int16_t prior_strat; + int16_t tgt_bits_per_blk; + int16_t max_bits_per_blk; + int16_t prev_quant_idx; + int16_t agc_bits_ch_idx; + int16_t planarCP; + int16_t num_umx_chs; + +} ivas_spar_md_com_cfg; +#endif /* arithmetic coder structures */ @@ -269,6 +297,7 @@ typedef struct ivas_huff_models_t } ivas_huff_models_t; +#ifndef FIX_SBA_CLEAN_UP_OPT typedef struct ivas_arith_consts_t { ivas_freq_models_t pred_r; @@ -282,6 +311,7 @@ typedef struct ivas_huff_const_t ivas_huff_models_t drct_r; ivas_huff_models_t decd_r; } ivas_huff_consts_t; +#endif /* Entropy coder structures */ typedef struct ivas_huffman_cfg_t @@ -381,7 +411,11 @@ typedef struct ivas_spar_br_table_t int16_t bwidth; int16_t fpcs; int16_t nchan_transport; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_pmx_strings_t dmx_str; +#else + ivas_spar_pmx_strings_t dmx_str; +#endif int16_t active_w; int16_t tmode; int32_t evs_brs[FOA_CHANNELS][3]; diff --git a/lib_com/options.h b/lib_com/options.h index 4266697886..f99ede07d2 100644 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -150,6 +150,7 @@ #define FIX_1_CUSTOM_LS /* fix bug 1-ivas-internal-error-in-decoder-for-custom-loudspeaker-format-with-sba-input-at-24-4kbps */ #define FIX_TDREND_STANDALONE /* Fix for TD standalone renderer (broken after update of hHrtfTD pointer and addition of hRenderConfig */ #define FIX_MDCT_KERNEL_RATE_SWITCHING_PLC /* force kernel that can handle ACELP -> TCX transition frame lengths for transition frames in decoder */ +#define FIX_SBA_CLEAN_UP_OPT /* Fix for tickets #6, #10, #17 and #20 */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ diff --git a/lib_dec/ivas_dec.c b/lib_dec/ivas_dec.c index c669a281a4..7527209028 100644 --- a/lib_dec/ivas_dec.c +++ b/lib_dec/ivas_dec.c @@ -243,8 +243,13 @@ ivas_error ivas_dec( if ( ( st_ivas->hQMetaData != NULL ) && ( SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ) ) { st = ( st_ivas->nSCE > 0 ) ? st_ivas->hSCE[0]->hCoreCoder[0] : st_ivas->hCPE[0]->hCoreCoder[0]; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_dirac_dec_read_BS( ivas_total_brate, st, st_ivas->hDirAC, st_ivas->hQMetaData, &nb_bits_metadata[0], st_ivas->sba_mode, st_ivas->hSpar->hSparFoa->dirac_to_spar_md_bands ); +#else + ivas_dirac_dec_read_BS( ivas_total_brate, st, st_ivas->hDirAC, st_ivas->hQMetaData, &nb_bits_metadata[0], + st_ivas->sba_mode, st_ivas->hSpar->dirac_to_spar_md_bands ); +#endif } if ( ( error = ivas_spar_dec( st_ivas, nb_bits_metadata ) ) != IVAS_ERR_OK ) { diff --git a/lib_dec/ivas_entropy_decoder.c b/lib_dec/ivas_entropy_decoder.c index 52eadafc2a..d26b9af819 100644 --- a/lib_dec/ivas_entropy_decoder.c +++ b/lib_dec/ivas_entropy_decoder.c @@ -50,6 +50,7 @@ static int16_t ivas_huffman_code_bits_present( const int16_t *codebook, const int16_t code, const int16_t bits, const int16_t len ); +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_arith_dec_init() * @@ -92,6 +93,7 @@ static void ivas_arith_dec_init( return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -192,6 +194,7 @@ static void ivas_arithCoder_decode_array_diff( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_huffman_dec_init_min_max_len() * @@ -224,6 +227,7 @@ static void ivas_huffman_dec_init_min_max_len( return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -496,6 +500,7 @@ void ivas_arith_decode_cmplx_cell_array( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_arith_coeffs_dec_init() * @@ -558,3 +563,4 @@ void ivas_huff_coeffs_dec_init( return; } +#endif diff --git a/lib_dec/ivas_init_dec.c b/lib_dec/ivas_init_dec.c index 7237269106..b631bc1964 100644 --- a/lib_dec/ivas_init_dec.c +++ b/lib_dec/ivas_init_dec.c @@ -874,14 +874,23 @@ ivas_error ivas_init_decoder( } for ( k = 0; k < DIRAC_MAX_NBANDS; k++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT st_ivas->hSpar->hSparFoa->dirac_to_spar_md_bands[k] = st_ivas->hDirAC->dirac_to_spar_md_bands[k]; +#else + st_ivas->hSpar->dirac_to_spar_md_bands[k] = st_ivas->hDirAC->dirac_to_spar_md_bands[k]; +#endif } +#ifndef FIX_SBA_CLEAN_UP_OPT st_ivas->hSpar->hSparFoa->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; +#else + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; +#endif } else { int16_t band_grouping[IVAS_MAX_NUM_BANDS + 1]; +#ifndef FIX_SBA_CLEAN_UP_OPT st_ivas->hSpar->hSparFoa->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); ivas_dirac_config_bands( @@ -892,6 +901,18 @@ ivas_error ivas_init_decoder( st_ivas->hQMetaData->useLowerBandRes, st_ivas->hSpar->hSparFoa->enc_param_start_band, 0 ); +#else + st_ivas->hSpar->enc_param_start_band = min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); + + ivas_dirac_config_bands( + band_grouping, + IVAS_MAX_NUM_BANDS, + (int16_t) ( st_ivas->hDecoderConfig->output_Fs * INV_CLDFB_BANDWIDTH + 0.5f ), + st_ivas->hSpar->dirac_to_spar_md_bands, + st_ivas->hQMetaData->useLowerBandRes, + st_ivas->hSpar->enc_param_start_band, + 0 ); +#endif } } else @@ -1359,7 +1380,11 @@ ivas_error ivas_init_decoder( /* CLDFB Interpolation weights */ if ( st_ivas->ivas_format == SBA_FORMAT && st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_get_cldfb_gains( st_ivas->hSpar->hSparFoa, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); +#else + ivas_spar_get_cldfb_gains( st_ivas->hSpar, st_ivas->cldfbAnaDec[0], st_ivas->cldfbSynDec[0], hDecoderConfig ); +#endif } /*-----------------------------------------------------------------* @@ -1851,7 +1876,11 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_DIRAC: if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifndef FIX_SBA_CLEAN_UP_OPT *numCldfbAnalyses = st_ivas->hSpar->hSparFoa->hFbMixer->fb_cfg->num_in_chans; +#else + *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; +#endif if ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) @@ -1860,7 +1889,11 @@ void ivas_init_dec_get_num_cldfb_instances( } else if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA ) { +#ifndef FIX_SBA_CLEAN_UP_OPT *numCldfbSyntheses = st_ivas->hSpar->hSparFoa->hFbMixer->fb_cfg->num_out_chans; +#else + *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; +#endif } else { @@ -1910,7 +1943,11 @@ void ivas_init_dec_get_num_cldfb_instances( case RENDERER_BINAURAL_FASTCONV_ROOM: if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifndef FIX_SBA_CLEAN_UP_OPT *numCldfbAnalyses = st_ivas->hSpar->hSparFoa->hFbMixer->fb_cfg->num_in_chans; +#else + *numCldfbAnalyses = st_ivas->hSpar->hFbMixer->fb_cfg->num_in_chans; +#endif if ( st_ivas->hOutSetup.is_loudspeaker_setup && st_ivas->renderer_type == RENDERER_DIRAC ) { @@ -1918,7 +1955,11 @@ void ivas_init_dec_get_num_cldfb_instances( } else if ( st_ivas->hDecoderConfig->output_config == AUDIO_CONFIG_FOA ) { +#ifndef FIX_SBA_CLEAN_UP_OPT *numCldfbSyntheses = st_ivas->hSpar->hSparFoa->hFbMixer->fb_cfg->num_out_chans; +#else + *numCldfbSyntheses = st_ivas->hSpar->hFbMixer->fb_cfg->num_out_chans; +#endif } else { diff --git a/lib_dec/ivas_masa_dec.c b/lib_dec/ivas_masa_dec.c index 0e2c68f385..77756b1630 100644 --- a/lib_dec/ivas_masa_dec.c +++ b/lib_dec/ivas_masa_dec.c @@ -1150,7 +1150,11 @@ void ivas_spar_param_to_masa_param_mapping( { for ( j = 0; j < FOA_CHANNELS; j++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT mixer_mat_sf_bands_real[sf][band][i][j] = st_ivas->hSpar->hSparFoa->hMdDec->mixer_mat_prev[mixer_mat_index][i][j][band]; +#else + mixer_mat_sf_bands_real[sf][band][i][j] = st_ivas->hSpar->hMdDec->mixer_mat_prev[mixer_mat_index][i][j][band]; +#endif } } } @@ -1164,7 +1168,11 @@ void ivas_spar_param_to_masa_param_mapping( { for ( j = 0; j < FOA_CHANNELS; j++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT mixer_mat_sf_bands_real[sf][band][i][j] = st_ivas->hSpar->hSparFoa->hMdDec->mixer_mat[i][j][band + mixer_mat_index * IVAS_MAX_NUM_BANDS]; +#else + mixer_mat_sf_bands_real[sf][band][i][j] = st_ivas->hSpar->hMdDec->mixer_mat[i][j][band + mixer_mat_index * IVAS_MAX_NUM_BANDS]; +#endif } } } diff --git a/lib_dec/ivas_sba_dec.c b/lib_dec/ivas_sba_dec.c index 5802dae2b3..e0e55002fe 100644 --- a/lib_dec/ivas_sba_dec.c +++ b/lib_dec/ivas_sba_dec.c @@ -511,7 +511,11 @@ ivas_error ivas_sba_dec_reconfigure( { int16_t sba_order_internal; sba_order_internal = min( st_ivas->sba_order, IVAS_MAX_SBA_ORDER ); +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->hSparFoa->core_nominal_brate, st_ivas->sid_format ); +#else + ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->hSpar->core_nominal_brate, st_ivas->sid_format ); +#endif if ( ( error = ivas_dirac_sba_config( st_ivas->hQMetaData, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &st_ivas->element_mode_init, st_ivas->hDecoderConfig->ivas_total_brate, st_ivas->sba_order, st_ivas->sba_planar, st_ivas->sba_mode, IVAS_MAX_NUM_BANDS - SPAR_DIRAC_SPLIT_START_BAND ) ) != IVAS_ERR_OK ) diff --git a/lib_dec/ivas_sba_rendering.c b/lib_dec/ivas_sba_rendering.c index 8883e8d78f..25bf71d906 100644 --- a/lib_dec/ivas_sba_rendering.c +++ b/lib_dec/ivas_sba_rendering.c @@ -250,7 +250,11 @@ void ivas_sba_upmixer_renderer( } /* Upmixer */ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_upmixer( st_ivas, output, nchan_internal, output_frame ); +#else + ivas_spar_dec_upmixer( st_ivas, output, nchan_internal, output_frame ); +#endif /* Renderer */ if ( st_ivas->hDirAC != NULL && st_ivas->renderer_type == RENDERER_DIRAC ) @@ -301,7 +305,11 @@ void ivas_sba_mix_matrix_determiner( { int16_t i, ch; float temp; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_state_t *pState; +#else + SPAR_DEC_HANDLE pState; +#endif int16_t num_bands_out, nchan_transport, nchan_out; /* Convert numeric range */ @@ -326,7 +334,11 @@ void ivas_sba_mix_matrix_determiner( } /* AGC */ +#ifndef FIX_SBA_CLEAN_UP_OPT pState = st_ivas->hSpar->hSparFoa; +#else + pState = st_ivas->hSpar; +#endif nchan_transport = pState->hMdDec->spar_md_cfg.nchan_transport; nchan_out = nchan_transport; ivas_agc_dec_process( pState->hAgcDec, output, output, nchan_transport, output_frame ); @@ -342,7 +354,11 @@ void ivas_sba_mix_matrix_determiner( /* Mixing matrix determiner */ num_bands_out = pState->hFbMixer->pFb->filterbank_num_bands; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_gen_umx_mat( pState->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi ); +#else + ivas_spar_dec_gen_umx_mat( pState->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi ); +#endif wmops_sub_end(); @@ -365,7 +381,11 @@ void ivas_sba_prototype_renderer( ) { float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_state_t *hSparFoa; +#else + SPAR_DEC_HANDLE hSpar; +#endif DECODER_CONFIG_HANDLE hDecoderConfig; int16_t num_spar_bands, spar_band; int16_t b, ts; @@ -377,16 +397,30 @@ void ivas_sba_prototype_renderer( wmops_sub_start( "ivas_sba_prototype_renderer" ); +#ifndef FIX_SBA_CLEAN_UP_OPT hSparFoa = st_ivas->hSpar->hSparFoa; +#else + hSpar = st_ivas->hSpar; +#endif hDecoderConfig = st_ivas->hDecoderConfig; +#ifndef FIX_SBA_CLEAN_UP_OPT num_spar_bands = hSparFoa->hFbMixer->pFb->filterbank_num_bands; +#else + num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; +#endif firstSlot = firstSubframe * ( CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ); slotEnd = ( firstSubframe + nSubframes ) * ( CLDFB_NO_COL_MAX / MAX_PARAM_SPATIAL_SUBFRAMES ); +#ifndef FIX_SBA_CLEAN_UP_OPT num_cldfb_bands = hSparFoa->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; numch_in = hSparFoa->hFbMixer->fb_cfg->num_in_chans; numch_out = hSparFoa->hFbMixer->fb_cfg->num_out_chans; +#else + num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; +#endif if ( st_ivas->nchan_transport == 1 ) { @@ -407,14 +441,22 @@ void ivas_sba_prototype_renderer( for ( ts = firstSlot; ts < slotEnd; ts++ ) { /* determine SPAR parameters for this time slot */ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_get_parameters( hSparFoa, hDecoderConfig, ts, numch_out, numch_in, num_spar_bands, mixer_mat ); +#else + ivas_spar_get_parameters( hSpar, hDecoderConfig, ts, numch_out, numch_in, num_spar_bands, mixer_mat ); +#endif for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { float out_re[IVAS_SPAR_MAX_CH]; float out_im[IVAS_SPAR_MAX_CH]; float cldfb_par; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_fb_bin_to_band_data_t *bin2band = &hSparFoa->hFbMixer->pFb->fb_bin_to_band; +#else + ivas_fb_bin_to_band_data_t *bin2band = &hSpar->hFbMixer->pFb->fb_bin_to_band; +#endif for ( out_ch = firstOutCh; out_ch < outChEnd; out_ch++ ) { @@ -455,6 +497,7 @@ void ivas_sba_prototype_renderer( if ( ( ( ts + 1 ) % MAX_PARAM_SPATIAL_SUBFRAMES ) == 0 ) { sf_idx = ts / MAX_PARAM_SPATIAL_SUBFRAMES; +#ifndef FIX_SBA_CLEAN_UP_OPT hSparFoa->i_subframe++; hSparFoa->i_subframe = min( hSparFoa->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); mvr2r( hSparFoa->hMdDec->mixer_mat_prev[1][0][0], hSparFoa->hMdDec->mixer_mat_prev[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); @@ -472,6 +515,25 @@ void ivas_sba_prototype_renderer( } } } +#else + hSpar->i_subframe++; + hSpar->i_subframe = min( hSpar->i_subframe, MAX_PARAM_SPATIAL_SUBFRAMES ); + mvr2r( hSpar->hMdDec->mixer_mat_prev[1][0][0], hSpar->hMdDec->mixer_mat_prev[0][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + mvr2r( hSpar->hMdDec->mixer_mat_prev[2][0][0], hSpar->hMdDec->mixer_mat_prev[1][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + mvr2r( hSpar->hMdDec->mixer_mat_prev[3][0][0], hSpar->hMdDec->mixer_mat_prev[2][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + mvr2r( hSpar->hMdDec->mixer_mat_prev[4][0][0], hSpar->hMdDec->mixer_mat_prev[3][0][0], IVAS_MAX_FB_MIXER_OUT_CH * IVAS_MAX_FB_MIXER_IN_CH * IVAS_MAX_NUM_BANDS ); + + for ( out_ch = 0; out_ch < numch_out; out_ch++ ) + { + for ( in_ch = 0; in_ch < numch_in; in_ch++ ) + { + for ( b = 0; b < num_spar_bands; b++ ) + { + hSpar->hMdDec->mixer_mat_prev[4][out_ch][in_ch][b] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][b + sf_idx * IVAS_MAX_NUM_BANDS]; + } + } + } +#endif } } diff --git a/lib_dec/ivas_sce_dec.c b/lib_dec/ivas_sce_dec.c index e14754567e..fbcf859c30 100644 --- a/lib_dec/ivas_sce_dec.c +++ b/lib_dec/ivas_sce_dec.c @@ -153,7 +153,11 @@ ivas_error ivas_sce_dec( } else if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifndef FIX_SBA_CLEAN_UP_OPT st->bits_frame_nominal = (int16_t) ( st_ivas->hSpar->hSparFoa->core_nominal_brate / FRAMES_PER_SEC ); +#else + st->bits_frame_nominal = (int16_t) ( st_ivas->hSpar->core_nominal_brate / FRAMES_PER_SEC ); +#endif } else { diff --git a/lib_dec/ivas_spar_decoder.c b/lib_dec/ivas_spar_decoder.c index d4e79296fb..3316da9af0 100644 --- a/lib_dec/ivas_spar_decoder.c +++ b/lib_dec/ivas_spar_decoder.c @@ -59,6 +59,11 @@ ivas_error ivas_spar_dec_open( SPAR_DEC_HANDLE hSpar; ivas_error error; int16_t sba_order_internal, num_channels_internal; +#ifdef FIX_SBA_CLEAN_UP_OPT + IVAS_FB_CFG *fb_cfg; + int16_t i, j, b, active_w_mixing; + int32_t output_Fs; +#endif error = IVAS_ERR_OK; @@ -75,16 +80,91 @@ ivas_error ivas_spar_dec_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR decoder" ); } +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( error = ivas_spar_foa_dec_open( &hSpar->hSparFoa, st_ivas->hDecoderConfig, num_channels_internal ) ) != IVAS_ERR_OK ) { return error; } +#else + output_Fs = st_ivas->hDecoderConfig->output_Fs; + + /* TD decorr. */ + if ( ( error = ivas_spar_td_decorr_dec_open( &hSpar->hTdDecorr, output_Fs, num_channels_internal, 1 ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* MD handle */ +#ifndef FIX_SBA_CLEAN_UP_OPT + if ( ( error = ivas_spar_foa_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + if ( ( error = ivas_spar_md_dec_open( &hSpar->hMdDec, st_ivas->hDecoderConfig, num_channels_internal ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + hSpar->hMdDec->td_decorr_flag = 1; + hSpar->hMdDec->table_idx = -1; + + /* set FB config. */ + active_w_mixing = -1; + if ( ( error = ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, num_channels_internal, num_channels_internal, active_w_mixing, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + fb_cfg->pcm_offset = NS2SA( output_Fs, DELAY_FB_1_NS + IVAS_ENC_DELAY_NS + IVAS_DEC_DELAY_NS ); + fb_cfg->remix_order = remix_order_set[hSpar->hMdDec->spar_md_cfg.remix_unmix_order]; + + /* FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &hSpar->hFbMixer, output_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* AGC */ + if ( ( error = ivas_spar_agc_dec_open( &hSpar->hAgcDec, output_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* PCA */ + if ( ( hSpar->hPCA = (PCA_DEC_STATE *) count_malloc( sizeof( PCA_DEC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for PCA decoder" ); + } + + init_pca_dec( hSpar->hPCA ); + + /* mixer_mat intitialization */ + for ( i = 0; i < num_channels_internal; i++ ) + { + for ( j = 0; j < num_channels_internal; j++ ) + { + for ( b = 0; b < IVAS_MAX_NUM_BANDS; b++ ) + { + hSpar->hMdDec->mixer_mat[i][j][b] = 0.0f; + for ( int16_t i_ts = 0; i_ts < ( MAX_PARAM_SPATIAL_SUBFRAMES + 1 ); i_ts++ ) + { + hSpar->hMdDec->mixer_mat_prev[i_ts][i][j][b] = 0.0f; + } + } + } + } + hSpar->i_subframe = 0; +#endif /*-----------------------------------------------------------------* * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->hSparFoa->core_nominal_brate, st_ivas->sid_format ); +#else + ivas_spar_config( st_ivas->hDecoderConfig->ivas_total_brate, sba_order_internal, &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, st_ivas->sid_format ); +#endif switch ( sba_order_internal ) { @@ -118,11 +198,42 @@ void ivas_spar_dec_close( const int32_t output_Fs /* i : output sampling rate */ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT /* SPAR FOA handle */ ivas_spar_foa_dec_close( &hSpar->hSparFoa, output_Fs ); count_free( hSpar ); hSpar = NULL; +#else + if ( hSpar != NULL ) + { + /* MD handle */ +#ifndef FIX_SBA_CLEAN_UP_OPT + ivas_spar_foa_md_dec_close( &hSpar->hMdDec ); +#else + ivas_spar_md_dec_close( &hSpar->hMdDec ); +#endif + + /* Covar. State handle */ + ivas_spar_td_decorr_dec_close( &hSpar->hTdDecorr ); + + + /* FB mixer handle */ + ivas_FB_mixer_close( &hSpar->hFbMixer, output_Fs ); + + /* AGC */ + ivas_spar_agc_dec_close( &hSpar->hAgcDec ); + + /* PCA */ + if ( hSpar->hPCA != NULL ) + { + count_free( hSpar->hPCA ); + hSpar->hPCA = NULL; + } + count_free( hSpar ); + hSpar = NULL; + } +#endif return; } @@ -169,7 +280,11 @@ ivas_error ivas_spar_dec( st0->bits_frame = min( MAX_BITS_METADATA, last_bit_pos + 1 ); st0->total_brate = hDecoderConfig->ivas_total_brate; /* to avoid BER detect */ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_MD( st_ivas, st0 ); +#else + ivas_spar_dec_MD( st_ivas, st0 ); +#endif *nb_bits_read = st0->next_bit_pos + nb_bits_read_orig; st0->bit_stream = bit_stream_orig; diff --git a/lib_dec/ivas_spar_foa_dec.c b/lib_dec/ivas_spar_foa_dec.c index 0a2a61c83e..0106af6f4d 100644 --- a/lib_dec/ivas_spar_foa_dec.c +++ b/lib_dec/ivas_spar_foa_dec.c @@ -185,11 +185,19 @@ static void matrix_inverse( * *---------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_spar_get_cldfb_gains( ivas_spar_foa_dec_state_t *hSparFoa, HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, const DECODER_CONFIG_HANDLE hDecoderConfig ) +#else +void ivas_spar_get_cldfb_gains( + SPAR_DEC_HANDLE hSpar, + HANDLE_CLDFB_FILTER_BANK cldfbAnaDec0, + HANDLE_CLDFB_FILTER_BANK cldfbSynDec0, + const DECODER_CONFIG_HANDLE hDecoderConfig ) +#endif { float output_Fs = (float) hDecoderConfig->output_Fs; int16_t pt_len, stride, num_cldfb_bands, decfb_delay; @@ -216,10 +224,17 @@ void ivas_spar_get_cldfb_gains( encfb_delay = NS2SA( output_Fs, IVAS_FB_ENC_DELAY_NS ); decfb_delay = NS2SA( output_Fs, IVAS_FB_DEC_DELAY_NS ); +#ifndef FIX_SBA_CLEAN_UP_OPT cf_start = (int16_t) hSparFoa->hFbMixer->cross_fade_start_offset - encfb_delay + decfb_delay; /* time domain after CLDFB synthesis*/ cf_end = (int16_t) hSparFoa->hFbMixer->cross_fade_end_offset - encfb_delay + decfb_delay; cf_len = cf_end - cf_start; weights = hSparFoa->hFbMixer->cldfb_cross_fade; +#else + cf_start = (int16_t) hSpar->hFbMixer->cross_fade_start_offset - encfb_delay + decfb_delay; /* time domain after CLDFB synthesis*/ + cf_end = (int16_t) hSpar->hFbMixer->cross_fade_end_offset - encfb_delay + decfb_delay; + cf_len = cf_end - cf_start; + weights = hSpar->hFbMixer->cldfb_cross_fade; +#endif cf_cldfb_start = (int16_t) ceil( ( cf_start - decfb_delay / 2 ) / (float) stride - 0.5f ); cf_cldfb_end = (int16_t) ( ( cf_start - decfb_delay / 2 + cf_len ) / (float) stride - 0.5f ); @@ -233,16 +248,26 @@ void ivas_spar_get_cldfb_gains( set_f( tgt, 0, ( 3 - 1 ) * CLDFB_NO_CHANNELS_MAX + 10 * CLDFB_NO_CHANNELS_MAX ); cf_start_s = ( cf_start - decfb_delay / 2 ) / output_Fs; +#ifndef FIX_SBA_CLEAN_UP_OPT cf_len_s = hSparFoa->hFbMixer->cross_fade_end_offset / output_Fs - hSparFoa->hFbMixer->cross_fade_start_offset / output_Fs; +#else + cf_len_s = hSpar->hFbMixer->cross_fade_end_offset / output_Fs - hSpar->hFbMixer->cross_fade_start_offset / output_Fs; +#endif for ( ts = 0; ts < CLDFB_NO_COL_MAX; ts++ ) { weights[ts] = ( ( ( ts + 0.5f ) * stride / output_Fs ) - cf_start_s ) / cf_len_s; weights[ts] = max( min( weights[ts], 1.0f ), 0.0f ); } +#ifndef FIX_SBA_CLEAN_UP_OPT hSparFoa->hFbMixer->cldfb_cross_fade_start = cf_cldfb_start; hSparFoa->hFbMixer->cldfb_cross_fade_end = cf_cldfb_end; hSparFoa->hFbMixer->cldfb_latency = decfb_delay; +#else + hSpar->hFbMixer->cldfb_cross_fade_start = cf_cldfb_start; + hSpar->hFbMixer->cldfb_cross_fade_end = cf_cldfb_end; + hSpar->hFbMixer->cldfb_latency = decfb_delay; +#endif if ( num_cf_slots > 3 || pt_len > 10 * CLDFB_NO_CHANNELS_MAX || stride > CLDFB_NO_CHANNELS_MAX || split_band == IVAS_MAX_NUM_BANDS ) { @@ -255,7 +280,11 @@ void ivas_spar_get_cldfb_gains( for ( sample = 0; sample < cf_len; sample++ ) { /* increasing window function */ +#ifndef FIX_SBA_CLEAN_UP_OPT tgt[tmp_idx++] = hSparFoa->hFbMixer->pFilterbank_cross_fade[sample]; +#else + tgt[tmp_idx++] = hSpar->hFbMixer->pFilterbank_cross_fade[sample]; +#endif } for ( ; tmp_idx < num_samples; tmp_idx++ ) @@ -354,6 +383,7 @@ void ivas_spar_get_cldfb_gains( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*------------------------------------------------------------------------- * ivas_spar_foa_dec_open() * @@ -489,6 +519,7 @@ void ivas_spar_foa_dec_close( return; } +#endif /*---------------------------------------------------------------------* @@ -521,6 +552,7 @@ int16_t ivas_is_res_channel( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-------------------------------------------------------------------* * ivas_spar_foa_dec_MD() * @@ -531,13 +563,31 @@ void ivas_spar_foa_dec_MD( Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ Decoder_State *st0 /* i/o: decoder state structure - for bitstream handling*/ ) +#else +/*-------------------------------------------------------------------* + * ivas_spar_dec_MD() + * + * IVAS SPAR MD decoder + *-------------------------------------------------------------------*/ + +void ivas_spar_dec_MD( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0 /* i/o: decoder state structure - for bitstream handling*/ +) +#endif { int16_t num_channels, table_idx, num_bands_out, bfi, sba_order; int32_t ivas_total_brate; DECODER_CONFIG_HANDLE hDecoderConfig = st_ivas->hDecoderConfig; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_state_t *pState = st_ivas->hSpar->hSparFoa; wmops_sub_start( "ivas_spar_foa_dec_MD" ); +#else + SPAR_DEC_HANDLE pState = st_ivas->hSpar; + + wmops_sub_start( "ivas_spar_dec_MD" ); +#endif /*---------------------------------------------------------------------* * Initialization @@ -564,7 +614,11 @@ void ivas_spar_foa_dec_MD( pState->hMdDec->table_idx = table_idx; pState->hTdDecorr->ducking_flag = ivas_spar_br_table_consts[table_idx].td_ducking; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_init( pState->hMdDec, hDecoderConfig, num_channels ); +#else + ivas_spar_md_dec_init( pState->hMdDec, hDecoderConfig, num_channels ); +#endif } } @@ -573,7 +627,11 @@ void ivas_spar_foa_dec_MD( * Decode MD *---------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_process( st_ivas, st0, num_bands_out, sba_order ); +#else + ivas_spar_md_dec_process( st_ivas, st0, num_bands_out, sba_order ); +#endif /*---------------------------------------------------------------------* * read PCA bits @@ -603,6 +661,7 @@ void ivas_spar_foa_dec_MD( * MD smoothing *---------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT if ( st0->m_old_frame_type == ZERO_FRAME && ivas_total_brate == IVAS_SID_5k && st0->prev_bfi == 0 && pState->hMdDec->spar_md_cfg.nchan_transport == 1 ) { ivas_spar_foa_setup_md_smoothing( pState->hMdDec, num_bands_out ); @@ -611,12 +670,26 @@ void ivas_spar_foa_dec_MD( { ivas_spar_foa_update_md_hist( pState->hMdDec ); } +#else + if ( st0->m_old_frame_type == ZERO_FRAME && ivas_total_brate == IVAS_SID_5k && st0->prev_bfi == 0 && pState->hMdDec->spar_md_cfg.nchan_transport == 1 ) + { + ivas_spar_setup_md_smoothing( pState->hMdDec, num_bands_out ); + } + else + { + ivas_spar_update_md_hist( pState->hMdDec ); + } +#endif } else { if ( !bfi ) { +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_smooth_md_dtx( pState->hMdDec, num_bands_out ); +#else + ivas_spar_smooth_md_dtx( pState->hMdDec, num_bands_out ); +#endif } set_s( pState->hMdDec->valid_bands, 0, IVAS_MAX_NUM_BANDS ); @@ -633,6 +706,7 @@ void ivas_spar_foa_dec_MD( * *-------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static float ivas_spar_get_cldfb_slot_gain( ivas_spar_foa_dec_state_t *hSparFoa, /* i/o: SPAR FOA decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ @@ -640,8 +714,21 @@ static float ivas_spar_get_cldfb_slot_gain( int16_t *time_slot_idx0, int16_t *time_slot_idx1, float *weight_lowfreq ) +#else +static float ivas_spar_get_cldfb_slot_gain( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR FOA decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t time_slot_idx, + int16_t *time_slot_idx0, + int16_t *time_slot_idx1, + float *weight_lowfreq ) +#endif { +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_state_t *pState = hSparFoa; +#else + SPAR_DEC_HANDLE pState = hSpar; +#endif float weight; float output_Fs, encfb_delay, decfb_delay; float xfade_start_ns; @@ -663,7 +750,11 @@ static float ivas_spar_get_cldfb_slot_gain( if ( split_band < IVAS_MAX_NUM_BANDS ) { +#ifndef FIX_SBA_CLEAN_UP_OPT if ( hSparFoa->i_subframe > 3 ) +#else + if ( hSpar->i_subframe > 3 ) +#endif { weight = (float) ( time_slot_idx % MAX_PARAM_SPATIAL_SUBFRAMES ) / (float) MAX_PARAM_SPATIAL_SUBFRAMES; } @@ -692,6 +783,7 @@ static float ivas_spar_get_cldfb_slot_gain( * *-------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_spar_get_parameters( ivas_spar_foa_dec_state_t *hSparFoa, /* i/o: SPAR FOA decoder handle */ const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ @@ -700,12 +792,26 @@ void ivas_spar_get_parameters( const int16_t num_ch_in, const int16_t num_spar_bands, float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) +#else +void ivas_spar_get_parameters( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR FOA decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t ts, + const int16_t num_ch_out, + const int16_t num_ch_in, + const int16_t num_spar_bands, + float par_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS] ) +#endif { int16_t spar_band, out_ch, in_ch; float weight, weight_20ms; int16_t ts0, ts1, split_band; +#ifndef FIX_SBA_CLEAN_UP_OPT weight = ivas_spar_get_cldfb_slot_gain( hSparFoa, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms ); +#else + weight = ivas_spar_get_cldfb_slot_gain( hSpar, hDecoderConfig, ts, &ts0, &ts1, &weight_20ms ); +#endif split_band = SPAR_DIRAC_SPLIT_START_BAND; for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) @@ -714,11 +820,19 @@ void ivas_spar_get_parameters( { for ( in_ch = 0; in_ch < num_ch_in; in_ch++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT if ( split_band < IVAS_MAX_NUM_BANDS /* 20ms cross-fade for Transport channels in all frequency bands */ && ( 0 == ivas_is_res_channel( out_ch, hSparFoa->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/ ) +#else + if ( split_band < IVAS_MAX_NUM_BANDS + /* 20ms cross-fade for Transport channels in all frequency bands */ + && ( 0 == ivas_is_res_channel( out_ch, hSpar->hMdDec->spar_md_cfg.nchan_transport ) ) /* sub-frame processing for missing channels in all frequency bands*/ + ) +#endif { +#ifndef FIX_SBA_CLEAN_UP_OPT if ( hSparFoa->i_subframe > 3 ) { par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSparFoa->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + @@ -728,12 +842,29 @@ void ivas_spar_get_parameters( { par_mat[out_ch][in_ch][spar_band] = hSparFoa->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; } +#else + if ( hSpar->i_subframe > 3 ) + { + par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight ) * hSpar->hMdDec->mixer_mat_prev[ts0][out_ch][in_ch][spar_band] + + weight * hSpar->hMdDec->mixer_mat_prev[ts1][out_ch][in_ch][spar_band]; + } + else + { + par_mat[out_ch][in_ch][spar_band] = hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; + } +#endif } else { +#ifndef FIX_SBA_CLEAN_UP_OPT /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSparFoa->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSparFoa->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; +#else + /* 20ms Transport channel reconstruction with matching encoder/decoder processing */ + int16_t prev_idx = SPAR_DIRAC_SPLIT_START_BAND < IVAS_MAX_NUM_BANDS ? 1 : 0; /* if SPAR_DIRAC_SPLIT_START_BAND == IVAS_MAX_NUM_BANDS, then the sub-frame mixer_mat delay line is not active */ + par_mat[out_ch][in_ch][spar_band] = ( 1.0f - weight_20ms ) * hSpar->hMdDec->mixer_mat_prev[prev_idx][out_ch][in_ch][spar_band] + weight_20ms * hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band]; +#endif } } } @@ -749,12 +880,21 @@ void ivas_spar_get_parameters( * *-------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_spar_get_skip_mat( ivas_spar_foa_dec_state_t *hSparFoa, /* i/o: SPAR FOA decoder handle */ const int16_t num_ch_out, const int16_t num_ch_in, const int16_t num_spar_bands, int16_t skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ) +#else +static void ivas_spar_get_skip_mat( + SPAR_DEC_HANDLE hSpar, /* i/o: SPAR FOA decoder handle */ + const int16_t num_ch_out, + const int16_t num_ch_in, + const int16_t num_spar_bands, + int16_t skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH] ) +#endif { int16_t spar_band, out_ch, in_ch; int16_t i_ts, skip_flag; @@ -770,7 +910,11 @@ static void ivas_spar_get_skip_mat( { for ( spar_band = 0; spar_band < num_spar_bands; spar_band++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT if ( hSparFoa->hMdDec->mixer_mat_prev[1 + i_ts][out_ch][in_ch][spar_band] != 0.0f || hSparFoa->hMdDec->mixer_mat[out_ch][in_ch][spar_band + i_ts * MAX_PARAM_SPATIAL_SUBFRAMES] != 0.0f ) +#else + if ( hSpar->hMdDec->mixer_mat_prev[1 + i_ts][out_ch][in_ch][spar_band] != 0.0f || hSpar->hMdDec->mixer_mat[out_ch][in_ch][spar_band + i_ts * MAX_PARAM_SPATIAL_SUBFRAMES] != 0.0f ) +#endif { skip_flag = 0; break; @@ -790,6 +934,7 @@ static void ivas_spar_get_skip_mat( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-------------------------------------------------------------------* * ivas_spar_foa_dec_upmixer() * @@ -802,6 +947,20 @@ void ivas_spar_foa_dec_upmixer( const int16_t nchan_internal, /* i : number of internal channels */ const int16_t output_frame /* i : output frame length */ ) +#else +/*-------------------------------------------------------------------* + * ivas_spar_foa_dec_upmixer() + * + * IVAS SPAR FOA upmixer + *-------------------------------------------------------------------*/ + +void ivas_spar_dec_upmixer( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + float output[][L_FRAME48k], /* i/o: input/output audio channels */ + const int16_t nchan_internal, /* i : number of internal channels */ + const int16_t output_frame /* i : output frame length */ +) +#endif { int16_t cldfb_band, num_cldfb_bands, numch_in, numch_out; float *cldfb_in_ts_re[MAX_OUTPUT_CHANNELS][CLDFB_NO_COL_MAX]; @@ -815,19 +974,38 @@ void ivas_spar_foa_dec_upmixer( float mixer_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH][IVAS_MAX_NUM_BANDS]; int16_t b_skip_mat[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; DECODER_CONFIG_HANDLE hDecoderConfig; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_state_t *pState, *hSparFoa; +#else + SPAR_DEC_HANDLE pState, hSpar; +#endif +#ifndef FIX_SBA_CLEAN_UP_OPT wmops_sub_start( "ivas_spar_foa_dec_upmixer" ); +#else + wmops_sub_start( "ivas_spar_dec_upmixer" ); +#endif +#ifndef FIX_SBA_CLEAN_UP_OPT hSparFoa = st_ivas->hSpar->hSparFoa; pState = hSparFoa; +#else + hSpar = st_ivas->hSpar; + pState = hSpar; +#endif hDecoderConfig = st_ivas->hDecoderConfig; num_bands_out = pState->hFbMixer->pFb->filterbank_num_bands; nchan_transport = pState->hMdDec->spar_md_cfg.nchan_transport; +#ifndef FIX_SBA_CLEAN_UP_OPT num_cldfb_bands = hSparFoa->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; numch_in = hSparFoa->hFbMixer->fb_cfg->num_in_chans; numch_out = hSparFoa->hFbMixer->fb_cfg->num_out_chans; +#else + num_cldfb_bands = hSpar->hFbMixer->pFb->fb_bin_to_band.num_cldfb_bands; + numch_in = hSpar->hFbMixer->fb_cfg->num_in_chans; + numch_out = hSpar->hFbMixer->fb_cfg->num_out_chans; +#endif #ifdef DEBUG_SPAR_FOA if ( fFb_pcm != NULL ) @@ -963,18 +1141,30 @@ void ivas_spar_foa_dec_upmixer( * Gen umx mat *---------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_gen_umx_mat( pState->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi ); +#else + ivas_spar_dec_gen_umx_mat( pState->hMdDec, nchan_transport, num_bands_out, st_ivas->bfi ); +#endif /*---------------------------------------------------------------------* * CLDFB Processing and Synthesis *---------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT num_spar_bands = hSparFoa->hFbMixer->pFb->filterbank_num_bands; +#else + num_spar_bands = hSpar->hFbMixer->pFb->filterbank_num_bands; +#endif /* apply parameters */ /* determine if we can skip certain data */ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_get_skip_mat( hSparFoa, numch_out, numch_in, num_spar_bands, b_skip_mat ); /* this can be precomputed based on bitrate and format*/ +#else + ivas_spar_get_skip_mat( hSpar, numch_out, numch_in, num_spar_bands, b_skip_mat ); /* this can be precomputed based on bitrate and format*/ +#endif #ifdef FIX_1_CUSTOM_LS numch_out_dirac = st_ivas->hDecoderConfig->nchan_out; @@ -1001,7 +1191,11 @@ void ivas_spar_foa_dec_upmixer( for ( ts = 0; ts < MAX_PARAM_SPATIAL_SUBFRAMES; ts++ ) { /* determine SPAR parameters for this time slots */ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_get_parameters( hSparFoa, hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat ); +#else + ivas_spar_get_parameters( hSpar, st_ivas->hDecoderConfig, ts + i_sf * MAX_PARAM_SPATIAL_SUBFRAMES, numch_out, numch_in, num_spar_bands, mixer_mat ); +#endif for ( cldfb_band = 0; cldfb_band < num_cldfb_bands; cldfb_band++ ) { diff --git a/lib_dec/ivas_spar_foa_md_dec.c b/lib_dec/ivas_spar_foa_md_dec.c index 861a0fbb46..79007c54f7 100644 --- a/lib_dec/ivas_spar_foa_md_dec.c +++ b/lib_dec/ivas_spar_foa_md_dec.c @@ -64,11 +64,19 @@ static const int16_t ivas_spar_dec_plc_spatial_target[IVAS_SPAR_MAX_CH] = { 1, 0 * Static functions declaration *------------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_get_spar_matrices( ivas_spar_foa_md_dec_state_t *pState, const int16_t num_bands_out, const int16_t n_ts, const int16_t bw, const int16_t dtx_vad, const int16_t nB, const int16_t sba_order ); static void ivas_decode_arith_bs( ivas_spar_foa_md_dec_state_t *pState, Decoder_State *st, const uint16_t qsi, const int16_t nB, const int16_t bands_bw, int16_t *pDo_diff, const int16_t freq_diff, const int16_t planarCP ); static void ivas_decode_huffman_bs( ivas_spar_foa_md_dec_state_t *pState, Decoder_State *st, const uint16_t qsi, const int16_t nB, const int16_t bands_bw, const int16_t planarCP ); +#else +static void ivas_get_spar_matrices( ivas_spar_md_dec_state_t *pState, const int16_t num_bands_out, const int16_t n_ts, const int16_t bw, const int16_t dtx_vad, const int16_t nB, const int16_t sba_order ); + +static void ivas_decode_arith_bs( ivas_spar_md_dec_state_t *pState, Decoder_State *st, const uint16_t qsi, const int16_t nB, const int16_t bands_bw, int16_t *pDo_diff, const int16_t freq_diff, const int16_t planarCP ); + +static void ivas_decode_huffman_bs( ivas_spar_md_dec_state_t *pState, Decoder_State *st, const uint16_t qsi, const int16_t nB, const int16_t bands_bw, const int16_t planarCP ); +#endif static void ivas_fill_band_coeffs_idx( ivas_band_coeffs_ind_t *pBands_idx, const int16_t nB, int16_t *pSymbol_re, ivas_cell_dim_t *pCell_dims, ivas_coeffs_type_t coeff_type, const int16_t planarCP ); @@ -76,19 +84,32 @@ static void ivas_get_band_idx_from_differential( ivas_spar_md_t *pSpar_md, const static void ivas_mat_col_rearrange( float in_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], const int16_t order[IVAS_SPAR_MAX_CH], const int16_t i_ts, float ***mixer_mat, const int16_t bands, const int16_t num_ch ); +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_spar_foa_dec_compute_ramp_down_post_matrix( ivas_spar_foa_md_dec_state_t *pState, const int16_t num_bands, const int16_t bfi ); +#else +static void ivas_spar_dec_compute_ramp_down_post_matrix( ivas_spar_md_dec_state_t *pState, const int16_t num_bands, const int16_t bfi ); +#endif static void ivas_spar_md_fill_invalid_bands( ivas_spar_dec_matrices_t *pSpar_coeffs, ivas_spar_dec_matrices_t *pSpar_coeffs_prev, int16_t *valid_bands, int16_t *base_band_age, const int16_t num_bands, const int16_t sba_order ); +#ifndef FIX_SBA_CLEAN_UP_OPT static ivas_error ivas_spar_foa_set_dec_config( ivas_spar_foa_md_dec_state_t *pState, const int16_t nchan_transport, float *pFC ); +#else +static ivas_error ivas_spar_set_dec_config( ivas_spar_md_dec_state_t *pState, const int16_t nchan_transport, float *pFC ); +#endif static void ivas_parse_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, Decoder_State *st, const int16_t bw, const int16_t num_bands, int16_t *num_dmx_per_band, int16_t *num_dec_per_band ); static ivas_error ivas_deindex_real_index( int16_t **index, const int16_t q_levels, const float min_value, const float max_value, float **quant, const int16_t num_ch, const int16_t dim2 ); +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_spar_foa_dec_parse_md_bs( ivas_spar_foa_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t use_planar_coeff, const int16_t sba_inactive_mode ); +#else +static void ivas_spar_foa_dec_parse_md_bs( ivas_spar_md_dec_state_t *hMdDec, Decoder_State *st, int16_t *nB, int16_t *bands_bw, int16_t *dtx_vad, const int32_t ivas_total_brate, const int16_t use_planar_coeff, const int16_t sba_inactive_mode ); +#endif +#ifndef FIX_SBA_CLEAN_UP_OPT /*------------------------------------------------------------------------- * ivas_spar_foa_md_dec_matrix_open() * @@ -99,9 +120,27 @@ static ivas_error ivas_spar_foa_md_dec_matrix_open( ivas_spar_foa_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_channels /* i : number of internal channels */ ) +#else +/*------------------------------------------------------------------------- + * ivas_spar_md_dec_matrix_open() + * + * Allocate and initialize SPAR MD decoder matrices + *------------------------------------------------------------------------*/ + +static ivas_error ivas_spar_md_dec_matrix_open( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_channels /* i : number of internal channels */ +) +#endif { int16_t i, j; +#ifdef FIX_SBA_CLEAN_UP_OPT + if ( ( hMdDec->spar_md.band_coeffs = (ivas_band_coeffs_t *) count_malloc( IVAS_MAX_NUM_BANDS * MAX_PARAM_SPATIAL_SUBFRAMES * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); + } +#endif if ( ( hMdDec->mixer_mat = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); @@ -171,10 +210,17 @@ static ivas_error ivas_spar_foa_md_dec_matrix_open( } for ( j = 0; j < num_channels; j++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( hMdDec->spar_coeffs_prev.C_re[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } +#else + if ( ( hMdDec->spar_coeffs_prev.C_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } +#endif } } @@ -190,10 +236,17 @@ static ivas_error ivas_spar_foa_md_dec_matrix_open( } for ( j = 0; j < num_channels; j++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( hMdDec->spar_coeffs_prev.P_re[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } +#else + if ( ( hMdDec->spar_coeffs_prev.P_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } +#endif } } @@ -209,10 +262,17 @@ static ivas_error ivas_spar_foa_md_dec_matrix_open( } for ( j = 0; j < num_channels; j++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( hMdDec->spar_coeffs_tar.C_re[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } +#else + if ( ( hMdDec->spar_coeffs_tar.C_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } +#endif } } @@ -228,10 +288,17 @@ static ivas_error ivas_spar_foa_md_dec_matrix_open( } for ( j = 0; j < num_channels; j++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( hMdDec->spar_coeffs_tar.P_re[i][j] = (float *) count_malloc( MAX_PARAM_SPATIAL_SUBFRAMES * IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); } +#else + if ( ( hMdDec->spar_coeffs_tar.P_re[i][j] = (float *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( float ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); + } +#endif } } @@ -239,6 +306,7 @@ static ivas_error ivas_spar_foa_md_dec_matrix_open( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*------------------------------------------------------------------------- * ivas_spar_foa_md_dec_open() * @@ -250,28 +318,66 @@ ivas_error ivas_spar_foa_md_dec_open( const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t num_channels /* i : number of internal channels */ ) +#else +/*------------------------------------------------------------------------- + * ivas_spar_md_dec_open() + * + * Allocate and initialize SPAR MD decoder handle + *------------------------------------------------------------------------*/ + +ivas_error ivas_spar_md_dec_open( + ivas_spar_md_dec_state_t **hMdDec_out, /* i/o: SPAR MD decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t num_channels /* i : number of internal channels */ +) +#endif { +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_state_t *hMdDec; +#else + ivas_spar_md_dec_state_t *hMdDec; +#endif ivas_error error; error = IVAS_ERR_OK; +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( hMdDec = (ivas_spar_foa_md_dec_state_t *) count_malloc( sizeof( ivas_spar_foa_md_dec_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD decoder" ); } +#else + if ( ( hMdDec = (ivas_spar_md_dec_state_t *) count_malloc( sizeof( ivas_spar_md_dec_state_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD decoder" ); + } +#endif +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( error = ivas_spar_foa_md_dec_matrix_open( hMdDec, num_channels ) ) != IVAS_ERR_OK ) { return error; } +#else + if ( ( error = ivas_spar_md_dec_matrix_open( hMdDec, num_channels ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif hMdDec->table_idx = 0; /* just to initialize state variables*/ +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( error = ivas_spar_foa_md_dec_init( hMdDec, hDecoderConfig, num_channels ) ) != IVAS_ERR_OK ) { return error; } +#else + if ( ( error = ivas_spar_md_dec_init( hMdDec, hDecoderConfig, num_channels ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif *hMdDec_out = hMdDec; @@ -285,13 +391,27 @@ ivas_error ivas_spar_foa_md_dec_open( * Deallocate SPAR MD decoder matrices *------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_spar_foa_md_dec_matrix_close( ivas_spar_foa_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ const int16_t num_channels /* i : number of internal channels */ ) +#else +static void ivas_spar_foa_md_dec_matrix_close( + ivas_spar_md_dec_state_t *hMdDecoder, /* i/o: SPAR MD decoder handle */ + const int16_t num_channels /* i : number of internal channels */ +) +#endif { int16_t i, j; +#ifdef FIX_SBA_CLEAN_UP_OPT + if ( hMdDecoder->spar_md.band_coeffs != NULL ) + { + count_free( hMdDecoder->spar_md.band_coeffs ); + hMdDecoder->spar_md.band_coeffs = NULL; + } +#endif if ( hMdDecoder->mixer_mat != NULL ) { for ( i = 0; i < num_channels; i++ ) @@ -387,6 +507,7 @@ static void ivas_spar_foa_md_dec_matrix_close( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*------------------------------------------------------------------------- * ivas_spar_foa_md_dec_close() * @@ -396,8 +517,23 @@ static void ivas_spar_foa_md_dec_matrix_close( void ivas_spar_foa_md_dec_close( ivas_spar_foa_md_dec_state_t **hMdDec /* i/o: SPAR MD decoder handle */ ) +#else +/*------------------------------------------------------------------------- + * ivas_spar_md_dec_close() + * + * Deallocate SPAR MD decoder handle + *------------------------------------------------------------------------*/ + +void ivas_spar_md_dec_close( + ivas_spar_md_dec_state_t **hMdDec /* i/o: SPAR MD decoder handle */ +) +#endif { +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_state_t *hMdDecoder; +#else + ivas_spar_md_dec_state_t *hMdDecoder; +#endif int16_t num_channels; hMdDecoder = *hMdDec; @@ -415,6 +551,7 @@ void ivas_spar_foa_md_dec_close( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_md_dec_init() * @@ -426,11 +563,28 @@ ivas_error ivas_spar_foa_md_dec_init( const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ const int16_t num_channels /* i : number of internal channels */ ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_md_dec_init() + * + * Init call for md dec process + *-----------------------------------------------------------------------------------------*/ + +ivas_error ivas_spar_md_dec_init( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const DECODER_CONFIG_HANDLE hDecoderConfig, /* i : configuration structure */ + const int16_t num_channels /* i : number of internal channels */ +) +#endif { int16_t i, j, k; int16_t nchan_transport; float pFC[IVAS_MAX_NUM_BANDS], PR_minmax[2]; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_state_t *pState = hMdDec; +#else + ivas_spar_md_dec_state_t *pState = hMdDec; +#endif pState->spar_md_cfg.gen_bs = 1; ivas_spar_set_bitrate_config( &pState->spar_md_cfg, pState->table_idx, min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ) ); @@ -443,7 +597,11 @@ ivas_error ivas_spar_foa_md_dec_init( pFC[i] = ivas_fb_fcs_12band_1ms[i] * hDecoderConfig->output_Fs * 0.5f; } +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_set_dec_config( pState, nchan_transport, pFC ); +#else + ivas_spar_set_dec_config( pState, nchan_transport, pFC ); +#endif if ( nchan_transport != 2 && ( ( pState->spar_md_cfg.remix_unmix_order == 2 ) || ( pState->spar_md_cfg.remix_unmix_order == 1 ) ) ) { @@ -455,8 +613,13 @@ ivas_error ivas_spar_foa_md_dec_init( PR_minmax[1] = pState->spar_md_cfg.quant_strat[0].PR.max; ivas_spar_quant_dtx_init( &pState->spar_md, PR_minmax ); +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_arith_coeffs_dec_init( &pState->arith_coeffs, &pState->spar_md_cfg, pState->table_idx ); ivas_huff_coeffs_dec_init( &pState->huff_coeffs, &pState->spar_md_cfg, pState->table_idx ); +#else + ivas_spar_arith_coeffs_com_init( &pState->arith_coeffs, &pState->spar_md_cfg, pState->table_idx, DEC ); + ivas_spar_huff_coeffs_com_init( &pState->huff_coeffs, &pState->spar_md_cfg, pState->table_idx, DEC ); +#endif pState->spar_md_cfg.prev_quant_idx = -1; @@ -528,6 +691,7 @@ ivas_error ivas_spar_foa_md_dec_init( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_set_dec_config() * @@ -538,6 +702,18 @@ static ivas_error ivas_spar_foa_set_dec_config( ivas_spar_foa_md_dec_state_t *pState, const int16_t nchan_transport, float *pFC ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_set_dec_config() + * + * Set configuration for SPAR md dec + *-----------------------------------------------------------------------------------------*/ + +static ivas_error ivas_spar_set_dec_config( + ivas_spar_md_dec_state_t *pState, + const int16_t nchan_transport, + float *pFC ) +#endif { int16_t i, j, nchan, dmx_ch; @@ -591,6 +767,7 @@ static ivas_error ivas_spar_foa_set_dec_config( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_md_dec_process() * @@ -603,9 +780,31 @@ void ivas_spar_foa_md_dec_process( const int16_t num_bands_out, /* i : number of output bands */ const int16_t sba_order /* i : Ambisonic (SBA) order */ ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_foa_md_dec_process() + * + * SPAR FOA Meta Data decoder process + *-----------------------------------------------------------------------------------------*/ + +void ivas_spar_md_dec_process( + Decoder_Struct *st_ivas, /* i/o: IVAS decoder handle */ + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ +) +#endif { int16_t j, b, bw, dtx_vad, nB, i_ts; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_state_t *hMdDec = st_ivas->hSpar->hSparFoa->hMdDec; +#else +#ifndef FIX_SBA_CLEAN_UP_OPT + ivas_spar_foa_md_dec_state_t *hMdDec = st_ivas->hSpar->hMdDec; +#else + ivas_spar_md_dec_state_t *hMdDec = st_ivas->hSpar->hMdDec; +#endif +#endif ivas_spar_foa_dec_parse_md_bs( hMdDec, st0, &nB, &bw, &dtx_vad, st_ivas->hDecoderConfig->ivas_total_brate, ivas_spar_br_table_consts[hMdDec->table_idx].usePlanarCoeff, @@ -676,6 +875,7 @@ void ivas_spar_foa_md_dec_process( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_smooth_md_dtx() * @@ -688,10 +888,28 @@ void ivas_spar_foa_smooth_md_dtx( ivas_spar_foa_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out /* i : number of output bands */ ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_foa_smooth_md_dtx() + * + * Smooth MD during no data frame during DTX + *-----------------------------------------------------------------------------------------*/ +#ifdef SPAR_HOA_DBG +/* NOTE: No changes here as DTX only operates below 160kbps */ +#endif +void ivas_spar_smooth_md_dtx( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_bands_out /* i : number of output bands */ +) +#endif { int16_t j, k, b; int16_t dmx_ch; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_state_t *pState = hMdDec; +#else + ivas_spar_md_dec_state_t *pState = hMdDec; +#endif float ramp, tar, prev, new_val; ramp = (float) pState->dtx_md_smoothing_cntr / IVAS_DEFAULT_DTX_CNG_RAMP; @@ -756,6 +974,7 @@ void ivas_spar_foa_smooth_md_dtx( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_setup_md_smoothing() * @@ -766,6 +985,18 @@ void ivas_spar_foa_setup_md_smoothing( ivas_spar_foa_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t num_bands_out /* i : number of output bands */ ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_setup_md_smoothing() + * + * Set up smoothing of SPAR MD when SID update frame is received + *-----------------------------------------------------------------------------------------*/ + +void ivas_spar_setup_md_smoothing( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t num_bands_out /* i : number of output bands */ +) +#endif { /* copy the coeffs */ int16_t num_channels, i, j, k; @@ -816,20 +1047,35 @@ void ivas_spar_foa_setup_md_smoothing( } } +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_smooth_md_dtx( hMdDec, num_bands_out ); +#else + ivas_spar_smooth_md_dtx( hMdDec, num_bands_out ); +#endif return; } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* - * Function ivas_spar_foa_update_md_hist() + * Function ivas_spar_update_md_hist() * * Update previous and target MD *-----------------------------------------------------------------------------------------*/ void ivas_spar_foa_update_md_hist( ivas_spar_foa_md_dec_state_t *hMdDec ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_update_md_hist() + * + * Update previous and target MD + *-----------------------------------------------------------------------------------------*/ + +void ivas_spar_update_md_hist( + ivas_spar_md_dec_state_t *hMdDec ) +#endif { int16_t num_channels, i, j, k; @@ -889,6 +1135,7 @@ void ivas_spar_foa_update_md_hist( * Get SPAR matrices *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_get_spar_matrices( ivas_spar_foa_md_dec_state_t *pState, const int16_t num_bands_out, @@ -897,6 +1144,16 @@ static void ivas_get_spar_matrices( const int16_t dtx_vad, const int16_t nB, const int16_t sba_order ) +#else +static void ivas_get_spar_matrices( + ivas_spar_md_dec_state_t *pState, + const int16_t num_bands_out, + const int16_t n_ts, + const int16_t bw, + const int16_t dtx_vad, + const int16_t nB, + const int16_t sba_order ) +#endif { int16_t numch_out, num_bands, dmx_ch; int16_t i, j, k, m, b, i_ts, active_w; @@ -1278,6 +1535,7 @@ static void ivas_mat_col_rearrange( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_dec_gen_umx_mat() * @@ -1290,11 +1548,29 @@ void ivas_spar_foa_dec_gen_umx_mat( const int16_t num_bands_out, /* i : number of output bands */ const int16_t bfi /* i : bad frame indicator */ ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_dec_gen_umx_mat() + * + * generates upmix matrix + *-----------------------------------------------------------------------------------------*/ + +void ivas_spar_dec_gen_umx_mat( + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t nchan_transport, /* i : number of transport channels */ + const int16_t num_bands_out, /* i : number of output bands */ + const int16_t bfi /* i : bad frame indicator */ +) +#endif { int16_t i, j, b, i_ts; int16_t fb_ducking_flag = 0; int16_t num_out_ch = hMdDec->spar_md_cfg.num_umx_chs; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_state_t *pState = hMdDec; +#else + ivas_spar_md_dec_state_t *pState = hMdDec; +#endif for ( i_ts = 0; i_ts < MAX_PARAM_SPATIAL_SUBFRAMES; i_ts++ ) { @@ -1358,12 +1634,17 @@ void ivas_spar_foa_dec_gen_umx_mat( }*/ #endif +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_dec_compute_ramp_down_post_matrix( pState, num_bands_out, bfi ); +#else + ivas_spar_dec_compute_ramp_down_post_matrix( pState, num_bands_out, bfi ); +#endif return; } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_dec_parse_md_bs() * @@ -1379,11 +1660,32 @@ static void ivas_spar_foa_dec_parse_md_bs( const int32_t ivas_total_brate, const int16_t use_planar_coeff, const int16_t sba_inactive_mode ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_foa_dec_parse_md_bs() + * + * Parses MD bitstream + *-----------------------------------------------------------------------------------------*/ + +static void ivas_spar_foa_dec_parse_md_bs( + ivas_spar_md_dec_state_t *hMdDec, + Decoder_State *st0, + int16_t *nB, + int16_t *bands_bw, + int16_t *dtx_vad, + const int32_t ivas_total_brate, + const int16_t use_planar_coeff, + const int16_t sba_inactive_mode ) +#endif { int16_t i, j, k, num_bands; uint16_t qsi; ivas_quant_strat_t qs; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_state_t *pState = hMdDec; +#else + ivas_spar_md_dec_state_t *pState = hMdDec; +#endif int16_t strat, freq_diff, no_ec; int16_t do_diff[IVAS_MAX_NUM_BANDS]; int16_t planarCP = 0; @@ -1727,7 +2029,11 @@ static void ivas_spar_foa_dec_parse_md_bs( *-----------------------------------------------------------------------------------------*/ static void ivas_decode_arith_bs( +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_dec_state_t *pState, +#else + ivas_spar_md_dec_state_t *pState, +#endif Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ const uint16_t qsi, const int16_t nB, @@ -2004,6 +2310,7 @@ static void ivas_fill_band_coeffs_idx( * decode bitstream with huffman decoder *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_decode_huffman_bs( ivas_spar_foa_md_dec_state_t *pState, Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ @@ -2011,6 +2318,15 @@ static void ivas_decode_huffman_bs( const int16_t nB, const int16_t bands_bw, const int16_t planarCP ) +#else +static void ivas_decode_huffman_bs( + ivas_spar_md_dec_state_t *pState, + Decoder_State *st0, /* i/o: decoder state structure - for bitstream handling*/ + const uint16_t qsi, + const int16_t nB, + const int16_t bands_bw, + const int16_t planarCP ) +#endif { int16_t i, j; @@ -2187,6 +2503,7 @@ static void ivas_spar_md_fill_invalid_bands( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_dec_compute_ramp_down_post_matrix() * @@ -2198,6 +2515,19 @@ static void ivas_spar_foa_dec_compute_ramp_down_post_matrix( ivas_spar_foa_md_dec_state_t *pState, const int16_t num_bands_out, const int16_t bfi ) +#else +/*-----------------------------------------------------------------------------------------* +* Function ivas_spar_dec_compute_ramp_down_post_matrix() +* +* ivas_spar_dec_compute_ramp_down_post_matrix + +*-----------------------------------------------------------------------------------------*/ + +static void ivas_spar_dec_compute_ramp_down_post_matrix( + ivas_spar_md_dec_state_t *pState, + const int16_t num_bands_out, + const int16_t bfi ) +#endif { int16_t num_in_ch, num_out_ch, i, j, b; @@ -2493,12 +2823,21 @@ static ivas_error ivas_deindex_real_index( * *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT void ivas_spar_to_dirac( Decoder_Struct *st_ivas, ivas_spar_foa_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ const int16_t dtx_vad, /* i : DTX frame flag */ const int16_t num_bands_out /* i : number of output bands */ ) +#else +void ivas_spar_to_dirac( + Decoder_Struct *st_ivas, + ivas_spar_md_dec_state_t *hMdDec, /* i/o: SPAR MD decoder handle */ + const int16_t dtx_vad, /* i : DTX frame flag */ + const int16_t num_bands_out /* i : number of output bands */ +) +#endif { DIRAC_DEC_HANDLE hDirAC; int16_t start_band, end_band, band, qmf_band_start, qmf_band_end; @@ -2530,8 +2869,13 @@ void ivas_spar_to_dirac( end_band = min( num_bands_out, SPAR_DIRAC_SPLIT_START_BAND ); hDirAC = st_ivas->hDirAC; +#ifndef FIX_SBA_CLEAN_UP_OPT dirac_to_spar_md_bands = st_ivas->hSpar->hSparFoa->dirac_to_spar_md_bands; enc_param_start_band = st_ivas->hSpar->hSparFoa->enc_param_start_band; +#else + dirac_to_spar_md_bands = st_ivas->hSpar->dirac_to_spar_md_bands; + enc_param_start_band = st_ivas->hSpar->enc_param_start_band; +#endif if ( hDirAC != NULL ) { diff --git a/lib_dec/ivas_stat_dec.h b/lib_dec/ivas_stat_dec.h index a9ba163265..e7875d7c29 100644 --- a/lib_dec/ivas_stat_dec.h +++ b/lib_dec/ivas_stat_dec.h @@ -788,6 +788,7 @@ typedef struct ivas_spar_dec_matrices_t } ivas_spar_dec_matrices_t; +#ifndef FIX_SBA_CLEAN_UP_OPT typedef struct ivas_spar_foa_md_dec_state_t { ivas_spar_md_t spar_md; @@ -812,6 +813,32 @@ typedef struct ivas_spar_foa_md_dec_state_t int16_t dtx_vad; } ivas_spar_foa_md_dec_state_t; +#else +typedef struct ivas_spar_md_dec_state_t +{ + ivas_spar_md_t spar_md; + ivas_spar_md_prev_t spar_md_prev; + ivas_spar_dec_matrices_t spar_coeffs; + ivas_spar_dec_matrices_t spar_coeffs_prev; + ivas_spar_dec_matrices_t spar_coeffs_tar; + int16_t dtx_md_smoothing_cntr; + int16_t valid_bands[IVAS_MAX_NUM_BANDS]; + int16_t base_band_age[IVAS_MAX_NUM_BANDS]; + int16_t spar_plc_num_lost_frames; + int16_t num_decorr; + int16_t td_decorr_flag; + int16_t spar_plc_enable_fadeout_flag; + float ***mixer_mat; + /*TODO : reuse hFbMixer->prior_mixer for this as that buffer is unused in decoder with FB_HARMONIZATION*/ + float mixer_mat_prev[MAX_PARAM_SPATIAL_SUBFRAMES + 1][IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH][IVAS_MAX_NUM_BANDS]; + ivas_spar_md_com_cfg spar_md_cfg; + ivas_arith_coeffs_t arith_coeffs; + ivas_huff_coeffs_t huff_coeffs; + int16_t table_idx; + int16_t dtx_vad; + +} ivas_spar_md_dec_state_t; +#endif /* AGC structure */ @@ -866,6 +893,7 @@ typedef struct } PCA_DEC_STATE; /* SPAR FOA structures */ +#ifndef FIX_SBA_CLEAN_UP_OPT typedef struct ivas_spar_foa_dec_state_t { ivas_td_decorr_state_t *hTdDecorr; @@ -887,6 +915,22 @@ typedef struct ivas_spar_dec_lib_t ivas_spar_foa_dec_state_t *hSparFoa; } SPAR_DEC_DATA, *SPAR_DEC_HANDLE; +#else +/* main SPAR decoder structure */ +typedef struct ivas_spar_dec_lib_t +{ + ivas_td_decorr_state_t *hTdDecorr; + ivas_spar_md_dec_state_t *hMdDec; + IVAS_FB_MIXER_HANDLE hFbMixer; + int16_t AGC_flag; + ivas_agc_dec_state_t *hAgcDec; + PCA_DEC_STATE *hPCA; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t enc_param_start_band; + int32_t core_nominal_brate; /* Nominal bitrate for core coding */ + int32_t i_subframe; +} SPAR_DEC_DATA, *SPAR_DEC_HANDLE; +#endif /*----------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_dirac_enc.c b/lib_enc/ivas_dirac_enc.c index 207a745627..6ca568f7db 100644 --- a/lib_enc/ivas_dirac_enc.c +++ b/lib_enc/ivas_dirac_enc.c @@ -181,8 +181,13 @@ ivas_error ivas_dirac_enc_open( if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { +#ifndef FIX_SBA_CLEAN_UP_OPT mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->hSparFoa->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); st_ivas->hSpar->hSparFoa->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; +#else + mvs2s( st_ivas->hDirAC->dirac_to_spar_md_bands, st_ivas->hSpar->dirac_to_spar_md_bands, DIRAC_MAX_NBANDS ); + st_ivas->hSpar->enc_param_start_band = st_ivas->hDirAC->hConfig->enc_param_start_band; +#endif } return error; diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index 3236e528a9..4ab6256852 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -55,6 +55,7 @@ extern FILE *fModels_data; #define IVAS_MAX_ENCODED_BITS ( 150 ) +#ifndef FIX_SBA_CLEAN_UP_OPT /*---------------------------------------------------------------------------------------- - * * Function ivas_arith_enc_init() * @@ -154,6 +155,7 @@ static void ivas_arith_enc_init( return; } +#endif /*-----------------------------------------------------------------------------------------* @@ -352,6 +354,7 @@ void ivas_huffman_encode( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_arith_coeffs_enc_init() * @@ -404,6 +407,7 @@ void ivas_huff_coeffs_enc_init( return; } +#endif /*-----------------------------------------------------------------------------------------* diff --git a/lib_enc/ivas_sce_enc.c b/lib_enc/ivas_sce_enc.c index a8a43ccf2b..9c0fcf3edd 100644 --- a/lib_enc/ivas_sce_enc.c +++ b/lib_enc/ivas_sce_enc.c @@ -155,7 +155,11 @@ ivas_error ivas_sce_enc( } else if ( st_ivas->hSpar != NULL ) { +#ifndef FIX_SBA_CLEAN_UP_OPT st->bits_frame_nominal = (int16_t) ( st_ivas->hSpar->hSparFoa->core_nominal_brate / FRAMES_PER_SEC ); +#else + st->bits_frame_nominal = (int16_t) ( st_ivas->hSpar->core_nominal_brate / FRAMES_PER_SEC ); +#endif } else { diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index fd80a4d6db..04bb15e255 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -55,6 +55,12 @@ ivas_error ivas_spar_enc_open( { SPAR_ENC_HANDLE hSpar; ENCODER_CONFIG_HANDLE hEncoderConfig; +#ifdef FIX_SBA_CLEAN_UP_OPT + IVAS_FB_CFG *fb_cfg; + int16_t nchan_inp, nchan_transport, sba_order_internal; + int16_t table_idx, active_w_mixing; + int32_t input_Fs, ivas_total_brate; +#endif ivas_error error; hEncoderConfig = st_ivas->hEncoderConfig; @@ -69,17 +75,92 @@ ivas_error ivas_spar_enc_open( return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR encoder" ); } +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( error = ivas_spar_foa_enc_open( &hSpar->hSparFoa, hEncoderConfig ) ) != IVAS_ERR_OK ) { return error; } +#else + input_Fs = hEncoderConfig->input_Fs; + + sba_order_internal = min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ); + nchan_inp = ivas_sba_get_nchan_metadata( sba_order_internal ); + assert( nchan_inp <= hEncoderConfig->nchan_inp ); + ivas_total_brate = hEncoderConfig->ivas_total_brate; + nchan_transport = ivas_get_spar_num_TCs( hEncoderConfig->ivas_total_brate, sba_order_internal ); + + // bw = ivas_get_bw_idx_from_sample_rate(pCfg->input_Fs); + table_idx = ivas_get_spar_table_idx( ivas_total_brate, sba_order_internal, SPAR_CONFIG_BW, NULL, NULL ); + // ivas_set_bitrate_config(&pState->hMdEnc->spar_md_cfg, table_idx); + + /* MD handle */ +#ifndef FIX_SBA_CLEAN_UP_OPT + if ( ( error = ivas_spar_foa_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig ) ) != IVAS_ERR_OK ) + { + return error; + } +#else + if ( ( error = ivas_spar_md_enc_open( &( hSpar->hMdEnc ), hEncoderConfig ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif + + /* set FB config. */ + active_w_mixing = ivas_spar_br_table_consts[table_idx].active_w; // VE: this parameter is different between enc and dec + ivas_fb_set_cfg( &fb_cfg, SBA_FORMAT, SBA_MODE_SPAR, nchan_inp, nchan_transport, active_w_mixing, input_Fs ); + fb_cfg->remix_order = remix_order_set[hSpar->hMdEnc->spar_md_cfg.remix_unmix_order]; + + /* FB mixer handle */ + if ( ( error = ivas_FB_mixer_open( &( hSpar->hFbMixer ), input_Fs, fb_cfg ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Covariance handle */ + if ( ( error = ivas_spar_covar_enc_open( &( hSpar->hCovEnc ), hSpar->hFbMixer->pFb, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* Transient Detector handle */ + if ( ( error = ivas_spar_transient_det_open( &( hSpar->hTranDet ), input_Fs ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* AGC */ + if ( ( error = ivas_spar_agc_enc_open( &hSpar->hAgcEnc, input_Fs, nchan_inp ) ) != IVAS_ERR_OK ) + { + return error; + } + + /* PCA */ + hSpar->hPCA = NULL; + if ( hEncoderConfig->Opt_PCA_ON ) + { + if ( ( hSpar->hPCA = (PCA_ENC_STATE *) count_malloc( sizeof( PCA_ENC_STATE ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR PCA encoder" ); + } + init_pca_enc( hSpar->hPCA ); + } + + /* initializations */ + hSpar->hMdEnc->table_idx = -1; +#endif /*-----------------------------------------------------------------* * Configuration - set SPAR high-level parameters *-----------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_config( hEncoderConfig->ivas_total_brate, min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ), &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->hSparFoa->core_nominal_brate, -1 ); +#else + ivas_spar_config( hEncoderConfig->ivas_total_brate, min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ), + &st_ivas->nchan_transport, &st_ivas->nSCE, &st_ivas->nCPE, &hSpar->core_nominal_brate, -1 ); +#endif if ( st_ivas->nchan_transport == 1 ) { @@ -148,6 +229,9 @@ void ivas_spar_enc_close( const int16_t nchan_inp /* i : number of input channels */ ) { +#ifdef FIX_SBA_CLEAN_UP_OPT + int16_t num_chans; +#endif if ( hSpar != NULL ) { /* core-coder-VAD handle */ @@ -164,7 +248,39 @@ void ivas_spar_enc_close( hSpar->hFrontVad = NULL; } +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_enc_close( &hSpar->hSparFoa, input_Fs, nchan_inp ); +#else + + num_chans = hSpar->hFbMixer->fb_cfg->num_in_chans; + assert( num_chans <= nchan_inp ); + + /* MD handle */ +#ifndef FIX_SBA_CLEAN_UP_OPT + ivas_spar_foa_md_enc_close( &hSpar->hMdEnc ); +#else + ivas_spar_md_enc_close( &hSpar->hMdEnc ); +#endif + + /* Covar. State handle */ + ivas_spar_covar_enc_close( &hSpar->hCovEnc, num_chans ); + + /* FB mixer handle */ + ivas_FB_mixer_close( &hSpar->hFbMixer, input_Fs ); + + /* Trans Det handle */ + ivas_spar_transient_det_close( &hSpar->hTranDet ); + + /* AGC */ + ivas_spar_agc_enc_close( &hSpar->hAgcEnc ); + + /* PCA */ + if ( hSpar->hPCA != NULL ) + { + count_free( hSpar->hPCA ); + hSpar->hPCA = NULL; + } +#endif count_free( hSpar ); hSpar = NULL; @@ -215,10 +331,17 @@ ivas_error ivas_spar_enc( ivas_sba_zero_vert_comp( data_f, hEncoderConfig->sba_order, hEncoderConfig->sba_planar, input_frame ); } +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( error = ivas_spar_foa_enc_process( st_ivas, hEncoderConfig, hMetaData, st_ivas->hSpar->front_vad_flag, data_f ) ) != IVAS_ERR_OK ) { return error; } +#else + if ( ( error = ivas_spar_enc_process( st_ivas, hEncoderConfig, hMetaData, st_ivas->hSpar->front_vad_flag, data_f ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif if ( hEncoderConfig->sba_planar ) { diff --git a/lib_enc/ivas_spar_foa_enc.c b/lib_enc/ivas_spar_foa_enc.c index 691adc0b1b..32c2b01a7b 100644 --- a/lib_enc/ivas_spar_foa_enc.c +++ b/lib_enc/ivas_spar_foa_enc.c @@ -49,6 +49,7 @@ extern FILE *fFb_out[4]; #endif +#ifndef FIX_SBA_CLEAN_UP_OPT /*------------------------------------------------------------------------- * ivas_spar_foa_enc_open() * @@ -190,8 +191,10 @@ void ivas_spar_foa_enc_close( return; } +#endif +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_enc_get_windowed_fr() * @@ -205,6 +208,21 @@ static void ivas_spar_foa_enc_get_windowed_fr( const int16_t input_frame, const int16_t nchan_inp, const int16_t num_past_samples ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_enc_get_windowed_fr() + * + * Get windowed FRs + *-----------------------------------------------------------------------------------------*/ + +static void ivas_spar_enc_get_windowed_fr( + IVAS_FB_MIXER_HANDLE hFbMixer, + float *pIn_blocks[IVAS_SPAR_MAX_CH], + ivas_enc_cov_handler_in_buf_t *pCov_in_buf, + const int16_t input_frame, + const int16_t nchan_inp, + const int16_t num_past_samples ) +#endif { int16_t i, j, rev_offset; @@ -255,6 +273,7 @@ static void ivas_spar_foa_enc_get_windowed_fr( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_enc_process() * @@ -268,6 +287,21 @@ ivas_error ivas_spar_foa_enc_process( const int16_t front_vad_flag, /* i : front-VAD decision */ float data_f[][L_FRAME48k] /* i/o: input/transport audio channels */ ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_enc_process() + * + * Process call for SPAR FOA encoder + *-----------------------------------------------------------------------------------------*/ + +ivas_error ivas_spar_enc_process( + Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + const int16_t front_vad_flag, /* i : front-VAD decision */ + float data_f[][L_FRAME48k] /* i/o: input/transport audio channels */ +) +#endif { float pcm_tmp[IVAS_SPAR_MAX_CH][L_FRAME48k * 2]; float *p_pcm_tmp[IVAS_SPAR_MAX_CH]; @@ -277,13 +311,21 @@ ivas_error ivas_spar_foa_enc_process( ivas_enc_cov_handler_in_buf_t cov_in_buf; float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; float *cov_dtx_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_enc_in_buf_t md_in_buf; +#else + ivas_spar_md_enc_in_buf_t md_in_buf; +#endif int16_t nchan_inp, nchan_transport, bwidth, sba_order; int16_t table_idx; int16_t in_out_mixer_map[IVAS_MAX_FB_MIXER_OUT_CH][IVAS_MAX_SPAR_FB_MIXER_IN_CH]; ivas_error error; const int16_t *order; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_enc_state_t *pState = st_ivas->hSpar->hSparFoa; +#else + SPAR_ENC_HANDLE pState = st_ivas->hSpar; +#endif IVAS_QMETADATA_HANDLE hQMetaData = st_ivas->hQMetaData; int16_t ts, l_ts, orig_dirac_bands, num_del_samples; float *ppIn_FR_real[IVAS_SPAR_MAX_CH], *ppIn_FR_imag[IVAS_SPAR_MAX_CH]; @@ -544,7 +586,11 @@ ivas_error ivas_spar_foa_enc_process( md_in_buf.dtx_vad = dtx_vad; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_enc_process( pState->hMdEnc, hEncoderConfig, &md_in_buf, hMetaData, dtx_silence_mode ); +#else + ivas_spar_md_enc_process( pState->hMdEnc, hEncoderConfig, &md_in_buf, hMetaData, dtx_silence_mode ); +#endif if ( st_ivas->sba_mode == SBA_MODE_SPAR ) { @@ -555,12 +601,20 @@ ivas_error ivas_spar_foa_enc_process( int16_t d_start_band, d_end_band; int16_t dirac_band_idx; +#ifndef FIX_SBA_CLEAN_UP_OPT d_start_band = st_ivas->hSpar->hSparFoa->enc_param_start_band; +#else + d_start_band = st_ivas->hSpar->enc_param_start_band; +#endif d_end_band = IVAS_MAX_NUM_BANDS; for ( b = d_start_band; b < d_end_band; b++ ) { +#ifndef FIX_SBA_CLEAN_UP_OPT dirac_band_idx = st_ivas->hSpar->hSparFoa->dirac_to_spar_md_bands[b] - d_start_band; +#else + dirac_band_idx = st_ivas->hSpar->dirac_to_spar_md_bands[b] - d_start_band; +#endif for ( i_ts = 0; i_ts < hQMetaData->q_direction->cfg.nblocks; i_ts++ ) { azi_dirac[b][i_ts] = hQMetaData->q_direction->band_data[dirac_band_idx].azimuth[i_ts]; diff --git a/lib_enc/ivas_spar_foa_md_enc.c b/lib_enc/ivas_spar_foa_md_enc.c index a3416c360f..a05345faa9 100644 --- a/lib_enc/ivas_spar_foa_md_enc.c +++ b/lib_enc/ivas_spar_foa_md_enc.c @@ -87,14 +87,23 @@ static void ivas_band_mixer( float *cov_re[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH], static void ivas_get_band_differential_index( ivas_band_coeffs_ind_t *pBand_idx, const int16_t q_levels[2], const int16_t one_sided, const int16_t nB, const int16_t complex_cov, const int16_t dim, const ivas_coeffs_type_t coeff_type ); +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_get_huffman_coded_bs( ivas_spar_foa_md_enc_state_t *pState, BSTR_ENC_HANDLE hMetaData, const int16_t nB, const int16_t qsi, const int16_t planarCP ); static void ivas_get_arith_coded_bs( ivas_spar_foa_md_enc_state_t *pState, BSTR_ENC_HANDLE hMetaData, const int16_t *pDo_diff, const int16_t bands_bw, const int16_t nB, const int16_t qsi, const int16_t planarCP ); static ivas_error ivas_spar_foa_set_enc_config( ivas_spar_foa_md_enc_state_t *pState, int16_t *max_freq_per_chan, const int16_t nchan_transport, float *pFC, const int16_t nchan_inp ); +#else +static void ivas_get_huffman_coded_bs( ivas_spar_md_enc_state_t *pState, BSTR_ENC_HANDLE hMetaData, const int16_t nB, const int16_t qsi, const int16_t planarCP ); + +static void ivas_get_arith_coded_bs( ivas_spar_md_enc_state_t *pState, BSTR_ENC_HANDLE hMetaData, const int16_t *pDo_diff, const int16_t bands_bw, const int16_t nB, const int16_t qsi, const int16_t planarCP ); + +static ivas_error ivas_spar_set_enc_config( ivas_spar_md_enc_state_t *pState, int16_t *max_freq_per_chan, const int16_t nchan_transport, float *pFC, const int16_t nchan_inp ); +#endif static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[MAX_QUANT_STRATS], const int16_t dmx_switch, const int16_t dtx_vad ); +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_store_prior_coeffs( ivas_spar_foa_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t bands_bw, const int16_t strat, const int16_t dtx_vad, const int16_t qsi ); static void ivas_write_parameter_bitstream( ivas_spar_foa_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); @@ -103,6 +112,16 @@ static ivas_error ivas_spar_foa_md_enc_init( ivas_spar_foa_md_enc_state_t *pStat static void ivas_spar_foa_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, float **ppValues, const int16_t ndm, int16_t **ppIndex, const int16_t dim1, float **ppQuant ); +#else +static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t bands_bw, const int16_t strat, const int16_t dtx_vad, const int16_t qsi ); + +static void ivas_write_parameter_bitstream( ivas_spar_md_enc_state_t *hMdEnc, const int16_t nB, const int16_t bands_bw, BSTR_ENC_HANDLE hMetaData, const int32_t ivas_total_brate, const int16_t dtx_silence_mode, const int16_t strat, const int16_t qsi, const int16_t planarCP ); + +static ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *pState, const ENCODER_CONFIG_HANDLE hEncoderConfig ); + +static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, float **ppValues, const int16_t ndm, int16_t **ppIndex, const int16_t dim1, float **ppQuant ); +#endif + static void ivas_quant_p_per_band_dtx( float **ppP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float **ppP_out, const int16_t num_ch ); static void ivas_write_parameter_bitstream_dtx( ivas_spar_md_t *pSpar_md, BSTR_ENC_HANDLE hMetaData, int16_t *num_dmx, int16_t *num_dec, const int16_t num_bands ); @@ -114,6 +133,7 @@ static void ivas_quant_c_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_c static void ivas_quant_pred_coeffs_per_band( ivas_band_coeffs_t *pband_coeffs, ivas_band_coeffs_ind_t *pBand_coeffs_idx, ivas_quant_strat_t *pQs, const int16_t num_ch ); +#ifndef FIX_SBA_CLEAN_UP_OPT /*------------------------------------------------------------------------- * ivas_spar_foa_md_enc_open() * @@ -124,21 +144,50 @@ ivas_error ivas_spar_foa_md_enc_open( ivas_spar_foa_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ ) +#else +/*------------------------------------------------------------------------- + * ivas_spar_md_enc_open() + * + * Allocate and initialize SPAR MD encoder handle + *------------------------------------------------------------------------*/ + +ivas_error ivas_spar_md_enc_open( + ivas_spar_md_enc_state_t **hMdEnc_in, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +) +#endif { +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_enc_state_t *hMdEnc; +#else + ivas_spar_md_enc_state_t *hMdEnc; +#endif ivas_error error; int16_t num_channels, i, j, order; order = min( hEncoderConfig->sba_order, IVAS_MAX_SBA_ORDER ); error = IVAS_ERR_OK; +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( hMdEnc = (ivas_spar_foa_md_enc_state_t *) count_malloc( sizeof( ivas_spar_foa_md_enc_state_t ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); } +#else + if ( ( hMdEnc = (ivas_spar_md_enc_state_t *) count_malloc( sizeof( ivas_spar_md_enc_state_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder" ); + } +#endif num_channels = 2 * order + 2; +#ifdef FIX_SBA_CLEAN_UP_OPT + if ( ( hMdEnc->spar_md.band_coeffs = (ivas_band_coeffs_t *) count_malloc( IVAS_MAX_NUM_BANDS * sizeof( ivas_band_coeffs_t ) ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for band_coeffs in SPAR MD" ); + } +#endif if ( ( hMdEnc->mixer_mat = (float ***) count_malloc( num_channels * sizeof( float ** ) ) ) == NULL ) { return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD matrix" ); @@ -215,10 +264,17 @@ ivas_error ivas_spar_foa_md_enc_open( } } +#ifndef FIX_SBA_CLEAN_UP_OPT if ( ( error = ivas_spar_foa_md_enc_init( hMdEnc, hEncoderConfig ) ) != IVAS_ERR_OK ) { return error; } +#else + if ( ( error = ivas_spar_md_enc_init( hMdEnc, hEncoderConfig ) ) != IVAS_ERR_OK ) + { + return error; + } +#endif *hMdEnc_in = hMdEnc; @@ -226,6 +282,7 @@ ivas_error ivas_spar_foa_md_enc_open( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*------------------------------------------------------------------------- * ivas_spar_foa_md_enc_close() * @@ -235,13 +292,35 @@ ivas_error ivas_spar_foa_md_enc_open( void ivas_spar_foa_md_enc_close( ivas_spar_foa_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ ) +#else +/*------------------------------------------------------------------------- + * ivas_spar_md_enc_close() + * + * Deallocate SPAR MD encoder handle + *------------------------------------------------------------------------*/ + +void ivas_spar_md_enc_close( + ivas_spar_md_enc_state_t **hMdEnc_in /* i/o: SPAR MD encoder handle */ +) +#endif { int16_t num_channels, i, j; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_enc_state_t *hMdEnc; +#else + ivas_spar_md_enc_state_t *hMdEnc; +#endif hMdEnc = *hMdEnc_in; num_channels = hMdEnc->num_umx_ch; +#ifdef FIX_SBA_CLEAN_UP_OPT + if ( hMdEnc->spar_md.band_coeffs != NULL ) + { + count_free( hMdEnc->spar_md.band_coeffs ); + hMdEnc->spar_md.band_coeffs = NULL; + } +#endif if ( hMdEnc->mixer_mat != NULL ) { for ( i = 0; i < num_channels; i++ ) @@ -307,6 +386,7 @@ void ivas_spar_foa_md_enc_close( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_md_enc_init() * @@ -317,6 +397,18 @@ static ivas_error ivas_spar_foa_md_enc_init( ivas_spar_foa_md_enc_state_t *pState, /* o : MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_md_enc_init() + * + * Init call for md gen process + *-----------------------------------------------------------------------------------------*/ + +static ivas_error ivas_spar_md_enc_init( + ivas_spar_md_enc_state_t *pState, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig /* i : configuration structure */ +) +#endif { float pFC[IVAS_MAX_NUM_BANDS]; int16_t table_idx; @@ -339,7 +431,11 @@ static ivas_error ivas_spar_foa_md_enc_init( pFC[i] = ivas_fb_fcs_12band_1ms[i] * hEncoderConfig->input_Fs * 0.5f; } +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_set_enc_config( pState, pState->spar_md_cfg.max_freq_per_chan, pState->spar_md_cfg.nchan_transport, pFC, num_channels ); +#else + ivas_spar_set_enc_config( pState, pState->spar_md_cfg.max_freq_per_chan, pState->spar_md_cfg.nchan_transport, pFC, num_channels ); +#endif /* if(pState->spar_md_cfg.quant_strat[0].C.q_levels[0] == 0 || pState->spar_md_cfg.quant_strat[0].C.q_levels[1] == 0 || pState->spar_md_cfg.quant_strat[0].PR.q_levels[0] == 0 || pState->spar_md_cfg.quant_strat[0].PR.q_levels[1] == 0 @@ -359,8 +455,13 @@ static ivas_error ivas_spar_foa_md_enc_init( return IVAS_ERR_INTERNAL; } +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_arith_coeffs_enc_init( &pState->arith_coeffs, &pState->spar_md_cfg, table_idx ); ivas_huff_coeffs_enc_init( &pState->huff_coeffs, table_idx ); +#else + ivas_spar_arith_coeffs_com_init( &pState->arith_coeffs, &pState->spar_md_cfg, table_idx, ENC ); + ivas_spar_huff_coeffs_com_init( &pState->huff_coeffs, NULL, table_idx, ENC ); +#endif if ( hEncoderConfig->Opt_DTX_ON == 1 ) { @@ -405,6 +506,7 @@ static ivas_error ivas_spar_foa_md_enc_init( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_set_enc_config() * @@ -417,6 +519,20 @@ static ivas_error ivas_spar_foa_set_enc_config( const int16_t nchan_transport, float *pFC, const int16_t nchan_inp ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_set_enc_config() + * + * Set configuration for SPAR FOA md gen + *-----------------------------------------------------------------------------------------*/ + +static ivas_error ivas_spar_set_enc_config( + ivas_spar_md_enc_state_t *pState, + int16_t *max_freq_per_chan, + const int16_t nchan_transport, + float *pFC, + const int16_t nchan_inp ) +#endif { int16_t i, j; int16_t tmp_dmx_ch; @@ -460,11 +576,19 @@ static ivas_error ivas_spar_foa_set_enc_config( * Band limit downmix matrix *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_band_limit_dmx_matrix( ivas_spar_foa_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const int16_t num_ch, const int16_t num_bands, const int16_t bands_bw ) +#else +static void ivas_band_limit_dmx_matrix( + ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ + const int16_t num_ch, + const int16_t num_bands, + const int16_t bands_bw ) +#endif { int16_t i, j, b, ndm; @@ -491,12 +615,21 @@ static void ivas_band_limit_dmx_matrix( * Band mixing downmix matrix *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_band_mixing( ivas_spar_foa_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ const int16_t num_ch, const int16_t num_bands, const int16_t nchan_transport, const int16_t upmixed_bands ) +#else +static void ivas_band_mixing( + ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ + const int16_t num_ch, + const int16_t num_bands, + const int16_t nchan_transport, + const int16_t upmixed_bands ) +#endif { int16_t i, j, k, b; int16_t red_band_fact; @@ -554,6 +687,7 @@ static void write_metadata_buffer( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_md_enc_process() * @@ -566,6 +700,20 @@ ivas_error ivas_spar_foa_md_enc_process( ivas_spar_foa_md_enc_in_buf_t *pIn_buf, BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ const int16_t dtx_silence_mode ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_md_enc_process() + * + * SPAR FoA Meta Data generation process + *-----------------------------------------------------------------------------------------*/ + +ivas_error ivas_spar_md_enc_process( + ivas_spar_md_enc_state_t *hMdEnc, /* i/o: SPAR MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + ivas_spar_md_enc_in_buf_t *pIn_buf, + BSTR_ENC_HANDLE hMetaData, /* i/o: MetaData handle */ + const int16_t dtx_silence_mode ) +#endif { float pred_coeffs_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; float dm_fv_re[IVAS_SPAR_MAX_CH - 1][IVAS_MAX_NUM_BANDS]; @@ -582,7 +730,11 @@ ivas_error ivas_spar_foa_md_enc_process( BSTR_ENC_DATA hMetaData_tmp; Indice ind_list_tmp[MAX_BITS_METADATA]; // IVAS_fmToDo: size to be optimized float Wscale[IVAS_MAX_NUM_BANDS]; +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_md_enc_state_t *pState = hMdEnc; +#else + ivas_spar_md_enc_state_t *pState = hMdEnc; +#endif int16_t num_quant_strats = pState->spar_md_cfg.num_quant_strats; #ifdef DEBUG_SPAR_FOA int16_t count; @@ -859,7 +1011,11 @@ ivas_error ivas_spar_foa_md_enc_process( pState->spar_md.band_coeffs[b].pred_quant_re[i] = 0; } +#ifndef FIX_SBA_CLEAN_UP_OPT ivas_spar_foa_quant_pred_coeffs_dtx( &pState->spar_md, ppPred_re, ndm, ppPred_idx, num_ch - 1, ppPred_quant ); +#else + ivas_spar_quant_pred_coeffs_dtx( &pState->spar_md, ppPred_re, ndm, ppPred_idx, num_ch - 1, ppPred_quant ); +#endif } } @@ -1174,6 +1330,7 @@ static void ivas_band_mixer( * Write MD parameters into bitstream *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_write_parameter_bitstream( ivas_spar_foa_md_enc_state_t *hMdEnc, const int16_t nB, @@ -1184,6 +1341,18 @@ static void ivas_write_parameter_bitstream( const int16_t strat, const int16_t qsi, const int16_t planarCP ) +#else +static void ivas_write_parameter_bitstream( + ivas_spar_md_enc_state_t *hMdEnc, + const int16_t nB, + const int16_t bands_bw, + BSTR_ENC_HANDLE hMetaData, + const int32_t ivas_total_brate, + const int16_t dtx_silence_mode, + const int16_t strat, + const int16_t qsi, + const int16_t planarCP ) +#endif { int16_t no_ec, i; int16_t do_diff[IVAS_MAX_NUM_BANDS]; @@ -1281,12 +1450,21 @@ static void ivas_write_parameter_bitstream( * Generate huffman coded bitstream *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_get_huffman_coded_bs( ivas_spar_foa_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, const int16_t nB, const int16_t qsi, const int16_t planarCP ) +#else +static void ivas_get_huffman_coded_bs( + ivas_spar_md_enc_state_t *hMdEnc, + BSTR_ENC_HANDLE hMetaData, + const int16_t nB, + const int16_t qsi, + const int16_t planarCP ) +#endif { int16_t i, j; @@ -1354,6 +1532,7 @@ static void ivas_get_huffman_coded_bs( * Generate arithmetic coded bitstream *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_get_arith_coded_bs( ivas_spar_foa_md_enc_state_t *hMdEnc, BSTR_ENC_HANDLE hMetaData, @@ -1362,6 +1541,16 @@ static void ivas_get_arith_coded_bs( const int16_t nB, const int16_t qsi, const int16_t planarCP ) +#else +static void ivas_get_arith_coded_bs( + ivas_spar_md_enc_state_t *hMdEnc, + BSTR_ENC_HANDLE hMetaData, + const int16_t *pDo_diff, + const int16_t bands_bw, + const int16_t nB, + const int16_t qsi, + const int16_t planarCP ) +#endif { int16_t i, any_diff; ivas_cell_dim_t pred_cell_dims[IVAS_MAX_NUM_BANDS]; @@ -1519,6 +1708,7 @@ static void ivas_select_next_strat( * Store prior coeffs *-----------------------------------------------------------------------------------------*/ +#ifndef FIX_SBA_CLEAN_UP_OPT static void ivas_store_prior_coeffs( ivas_spar_foa_md_enc_state_t *hMdEnc, const int16_t num_bands, @@ -1526,6 +1716,15 @@ static void ivas_store_prior_coeffs( const int16_t strat, const int16_t dtx_vad, const int16_t qsi ) +#else +static void ivas_store_prior_coeffs( + ivas_spar_md_enc_state_t *hMdEnc, + const int16_t num_bands, + const int16_t bands_bw, + const int16_t strat, + const int16_t dtx_vad, + const int16_t qsi ) +#endif { int16_t i, j, b; @@ -1561,6 +1760,7 @@ static void ivas_store_prior_coeffs( } +#ifndef FIX_SBA_CLEAN_UP_OPT /*-----------------------------------------------------------------------------------------* * Function ivas_spar_foa_quant_pred_coeffs_dtx() * @@ -1574,6 +1774,21 @@ static void ivas_spar_foa_quant_pred_coeffs_dtx( int16_t **ppIndex, const int16_t dim1, float **ppQuant ) +#else +/*-----------------------------------------------------------------------------------------* + * Function ivas_spar_quant_pred_coeffs_dtx() + * + * Calculate quantization pred coeffs + *-----------------------------------------------------------------------------------------*/ + +static void ivas_spar_quant_pred_coeffs_dtx( + ivas_spar_md_t *pSpar_md, + float **ppValues, + const int16_t ndm, + int16_t **ppIndex, + const int16_t dim1, + float **ppQuant ) +#endif { int16_t i; int16_t q_lvl; diff --git a/lib_enc/ivas_stat_enc.h b/lib_enc/ivas_stat_enc.h index f158d1174d..a063b4e705 100644 --- a/lib_enc/ivas_stat_enc.h +++ b/lib_enc/ivas_stat_enc.h @@ -636,6 +636,7 @@ typedef struct ivas_enc_cov_handler_in_buf_t } ivas_enc_cov_handler_in_buf_t; +#ifndef FIX_SBA_CLEAN_UP_OPT /* SPAR FOA MD structures */ typedef struct ivas_spar_foa_md_enc_state_t { @@ -662,6 +663,35 @@ typedef struct ivas_spar_foa_md_enc_in_buf_t int16_t dtx_vad; } ivas_spar_foa_md_enc_in_buf_t; +#else +/* SPAR MD structures */ +typedef struct ivas_spar_md_enc_state_t +{ + ivas_spar_md_t spar_md; + ivas_spar_md_prev_t spar_md_prior; + int16_t num_umx_ch; + int16_t num_decorr; + + float ***mixer_mat; + float ***cov_real; + float ***cov_dtx_real; + float ***mixer_mat_local; + ivas_spar_md_com_cfg spar_md_cfg; + ivas_arith_coeffs_t arith_coeffs; + ivas_huff_coeffs_t huff_coeffs; + int16_t table_idx; + +} ivas_spar_md_enc_state_t; + + +typedef struct ivas_spar_md_enc_in_buf_t +{ + float *cov_real[IVAS_SPAR_MAX_CH][IVAS_SPAR_MAX_CH]; + int16_t num_bands; + int16_t dtx_vad; + +} ivas_spar_md_enc_in_buf_t; +#endif /* PCA structure */ @@ -679,6 +709,7 @@ typedef struct /* SPAR FOA structures */ +#ifndef FIX_SBA_CLEAN_UP_OPT typedef struct ivas_spar_foa_enc_state_t { ivas_spar_foa_md_enc_state_t *hMdEnc; @@ -692,9 +723,11 @@ typedef struct ivas_spar_foa_enc_state_t int32_t core_nominal_brate; /* Nominal bitrate for core coding */ } ivas_spar_foa_enc_state_t; +#endif /* SPAR main structure */ +#ifndef FIX_SBA_CLEAN_UP_OPT typedef struct ivas_spar_enc_lib_t { ivas_spar_foa_enc_state_t *hSparFoa; @@ -707,6 +740,27 @@ typedef struct ivas_spar_enc_lib_t int16_t force_front_vad; } SPAR_ENC_DATA, *SPAR_ENC_HANDLE; +#else +typedef struct ivas_spar_enc_lib_t +{ + ivas_spar_md_enc_state_t *hMdEnc; + IVAS_FB_MIXER_HANDLE hFbMixer; + ivas_enc_cov_handler_state_t *hCovEnc; + ivas_trans_det_state_t *hTranDet; + ivas_agc_enc_state_t *hAgcEnc; + int16_t dirac_to_spar_md_bands[DIRAC_MAX_NBANDS]; + int16_t enc_param_start_band; + PCA_ENC_STATE *hPCA; + int32_t core_nominal_brate; /* Nominal bitrate for core coding */ + FRONT_VAD_ENC_HANDLE hFrontVad; /* front-VAD handle */ + ENC_CORE_HANDLE hCoreCoderVAD; /* core-coder handle for front-VAD module */ + + int16_t front_vad_flag; + int16_t front_vad_dtx_flag; + int16_t force_front_vad; + +} SPAR_ENC_DATA, *SPAR_ENC_HANDLE; +#endif /*----------------------------------------------------------------------------------* -- GitLab