diff --git a/lib_com/ivas_cnst.h b/lib_com/ivas_cnst.h index d314be3154d6d856524a74143b06ce9c3ef79255..78db889104b0c544790d2bafa22f50d212c56479 100755 --- a/lib_com/ivas_cnst.h +++ b/lib_com/ivas_cnst.h @@ -1005,13 +1005,13 @@ typedef enum #define IVAS_SPAR_HOA3_NP_CHS 8 /* number of higher order non-planar channels */ -#define SPAR_NUM_CODING_STRAT_BITS ( 3 ) +#define SPAR_NUM_CODING_STRAT_BITS 3 /* AGC constants */ #define AGC_BITS_PER_CH 3 #define AGC_EMAX 0 #define AGC_SIGNALLING_BITS 1 -#define IVAS_SPAR_ARITH_OVERSHOOT_BITS (16) +#define IVAS_SPAR_ARITH_OVERSHOOT_BITS 16 /* Common SPAR metadata constants */ #define IVAS_ACTIVEW_DM_F_SCALE 0.5f diff --git a/lib_com/ivas_dirac_com.c b/lib_com/ivas_dirac_com.c index 1cd2aa3ab904a428f67c04833677804e6e3c6e5e..90ed71875a52fbb5613b299dc41a5913ebfc8dfa 100644 --- a/lib_com/ivas_dirac_com.c +++ b/lib_com/ivas_dirac_com.c @@ -312,12 +312,18 @@ void ivas_dirac_config_bands( return; } +/*-------------------------------------------------------------------* + * ivas_sba_get_max_md_bits() + * + * Return maximum SBA DirAC metadata bit-budget and nominal bit-budget + *-------------------------------------------------------------------*/ + void ivas_get_dirac_sba_max_md_bits( const int32_t sba_total_brate, int16_t *bits_frame_nominal, int16_t *metadata_max_bits, int16_t *qmetadata_max_bit_req, - int16_t nbands ) + const int16_t nbands ) { if ( sba_total_brate <= IVAS_13k2 ) { @@ -375,6 +381,7 @@ void ivas_get_dirac_sba_max_md_bits( return; } + /*------------------------------------------------------------------------- * ivas_dirac_sba_config() * @@ -448,12 +455,7 @@ ivas_error ivas_dirac_sba_config( return error; } } - ivas_get_dirac_sba_max_md_bits( - sba_total_brate, - &hQMetaData->bits_frame_nominal, - &hQMetaData->metadata_max_bits, - &hQMetaData->qmetadata_max_bit_req, - hQMetaData->q_direction[0].cfg.nbands ); + ivas_get_dirac_sba_max_md_bits( sba_total_brate, &hQMetaData->bits_frame_nominal, &hQMetaData->metadata_max_bits, &hQMetaData->qmetadata_max_bit_req, hQMetaData->q_direction[0].cfg.nbands ); return error; } diff --git a/lib_com/ivas_prot.h b/lib_com/ivas_prot.h index cfd5e5925ad872ea2c363061f84e3d4e299b5dff..b12e9afb9517615155cb222a67036a640514cfe2 100644 --- a/lib_com/ivas_prot.h +++ b/lib_com/ivas_prot.h @@ -110,17 +110,21 @@ ivas_error mct_enc_reconfigure( Encoder_Struct *st_ivas, /* i/o: IVAS encoder structure */ const uint16_t b_nchan_change /* i : flag indicating different channel count */ ); + ivas_error ivas_spar_md_enc_init ( - ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ - const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ - const int16_t sba_order /* i : Ambisonic (SBA) order */ + ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ + const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ + const int16_t sba_order /* i : Ambisonic (SBA) order */ ); + ivas_error ivas_sba_enc_reconfigure( Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ ); +/*! r: maximum SBA metadata bit-budget */ int16_t ivas_sba_get_max_md_bits( - Encoder_Struct *st_ivas ); + Encoder_Struct *st_ivas /* i/o: IVAS encoder structure */ +); void destroy_sce_enc( SCE_ENC_HANDLE hSCE /* i/o: SCE encoder structure */ @@ -3526,10 +3530,10 @@ void ivas_dirac_enc_close( ); void ivas_dirac_enc( - DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ - IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ - BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ - float data_f[][L_FRAME48k], /* i/o: SBA channels */ + DIRAC_ENC_HANDLE hDirAC, /* i/o: encoder DirAC handle */ + IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ + BSTR_ENC_HANDLE hMetaData, /* i/o: Metadata bitstream handle */ + float data_f[][L_FRAME48k], /* i/o: SBA channels */ float **ppIn_FR_real, /* o : real freq domain values */ float **ppIn_FR_imag, /* o : imag freq domain values */ const int16_t input_frame, /* i : input frame length */ @@ -3557,7 +3561,8 @@ void ivas_get_dirac_sba_max_md_bits( int16_t *bits_frame_nominal, int16_t *metadata_max_bits, int16_t *qmetadata_max_bit_req, - int16_t nbands ); + const int16_t nbands +); ivas_error ivas_dirac_sba_config( IVAS_QMETADATA_HANDLE hQMetaData, /* i/o: q_metadata handle */ @@ -4349,8 +4354,7 @@ int16_t ivas_get_sba_num_TCs( 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 */ - , + const int16_t num_bands, /* i : number of bands */ const int16_t dirac2spar_md_flag, const int16_t enc_flag, const int16_t pca_flag, @@ -4863,27 +4867,111 @@ int16_t ivas_get_bits_to_encode( int32_t val ); -void ivas_huffman_encode( ivas_huffman_cfg_t *huff_cfg, int16_t in, int16_t *hcode, int16_t *hlen ); -void ivas_spar_huff_coeffs_com_init( ivas_huff_coeffs_t *pHuff_coeffs, ivas_spar_md_com_cfg *pSpar_cfg, const int16_t table_idx, const int16_t enc_dec ); -void ivas_spar_arith_coeffs_com_init( ivas_arith_coeffs_t *pArith_coeffs, ivas_spar_md_com_cfg *pSpar_cfg, const int16_t table_idx, const int16_t enc_dec ); +void ivas_huffman_encode( + ivas_huffman_cfg_t *huff_cfg, + int16_t in, + int16_t *hcode, + int16_t *hlen +); + +void ivas_spar_huff_coeffs_com_init( + ivas_huff_coeffs_t *pHuff_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const int16_t table_idx, + const int16_t enc_dec +); + +void ivas_spar_arith_coeffs_com_init( + ivas_arith_coeffs_t *pArith_coeffs, + ivas_spar_md_com_cfg *pSpar_cfg, + const int16_t table_idx, + const int16_t enc_dec +); + int16_t 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 - , int32_t wc_strat_arith -); -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 ); - -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 ); -void ivas_ari_done_decoding_14bits_ext_1_lfe( Decoder_State *st, const int16_t extra_bits_read ); -void ivas_ari_done_encoding_14bits( BSTR_ENC_HANDLE hBstr, Tastat *s ); -void ivas_ari_encode_14bits_ext( BSTR_ENC_HANDLE hBstr, Tastat *s, int32_t symbol, const uint16_t *cum_freq ); - -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 ); -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 ); + + 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 + , + const int16_t wc_strat_arith +); + +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 +); + +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 +); + +void ivas_ari_done_decoding_14bits_ext_1_lfe( + Decoder_State *st, + const int16_t extra_bits_read +); + +void ivas_ari_done_encoding_14bits( + BSTR_ENC_HANDLE hBstr, Tastat *s +); + +void ivas_ari_encode_14bits_ext( + BSTR_ENC_HANDLE hBstr, + Tastat *s, + int32_t symbol, + const uint16_t *cum_freq +); + +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 +); + +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 +); /* Quantization utilities */ void ivas_quantise_real_values( diff --git a/lib_com/ivas_spar_com.c b/lib_com/ivas_spar_com.c index d00b802cd72d312cb5b74b8813b2fb3cc7144612..1128b085179dfcccdec40f6c9d34ead6f37cbf23 100644 --- a/lib_com/ivas_spar_com.c +++ b/lib_com/ivas_spar_com.c @@ -2125,8 +2125,7 @@ int16_t ivas_get_bits_to_encode( 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 */ - , + const int16_t num_bands, /* i : number of bands */ const int16_t dirac2spar_md_flag, const int16_t enc_flag, const int16_t pca_flag, @@ -2142,6 +2141,7 @@ void ivas_spar_set_bitrate_config( int16_t n_input, n_dmx, n_dec; int16_t quant_strat; int16_t bands_bw; + pSpar_md_cfg->nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; for ( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) @@ -2180,6 +2180,7 @@ void ivas_spar_set_bitrate_config( pSpar_md_cfg->tgt_bits_per_blk -= md_coding_bits_header; pSpar_md_cfg->max_bits_per_blk -= md_coding_bits_header; + if ( ivas_total_brate < IVAS_24k4 ) { bands_bw = 2; @@ -2261,6 +2262,7 @@ void ivas_spar_set_bitrate_config( } pSpar_md_cfg->max_md_bits_spar = pSpar_md_cfg->max_bits_per_blk + agc_bits + pca_bits; } + return; } diff --git a/lib_dec/ivas_spar_md_dec.c b/lib_dec/ivas_spar_md_dec.c old mode 100644 new mode 100755 index 9ef40b928eb6dfd9179724e97318c459dc4ef5fc..abf3c1a72c3bf59c49f4cd25546f326d021567c6 --- a/lib_dec/ivas_spar_md_dec.c +++ b/lib_dec/ivas_spar_md_dec.c @@ -486,9 +486,8 @@ ivas_error ivas_spar_md_dec_init( ivas_sba_get_spar_hoa_ch_ind( num_channels, hDecoderConfig->ivas_total_brate, hMdDec->HOA_md_ind ); hMdDec->spar_md.num_bands = ( hMdDec->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : min( IVAS_MAX_NUM_BANDS, SPAR_DIRAC_SPLIT_START_BAND ); - ivas_spar_set_bitrate_config( &hMdDec->spar_md_cfg, hMdDec->table_idx, hMdDec->spar_md.num_bands, - hMdDec->spar_hoa_dirac2spar_md_flag, - 0, 0, 0 ); + + ivas_spar_set_bitrate_config( &hMdDec->spar_md_cfg, hMdDec->table_idx, hMdDec->spar_md.num_bands, hMdDec->spar_hoa_dirac2spar_md_flag, 0, 0, 0 ); nchan_transport = hMdDec->spar_md_cfg.nchan_transport; diff --git a/lib_enc/ivas_entropy_coder.c b/lib_enc/ivas_entropy_coder.c index 32e55d85b7097771d3dd1816845dac0e732a7b4a..4f45d0cc7e108fc410691acc9a078329889e9292 100644 --- a/lib_enc/ivas_entropy_coder.c +++ b/lib_enc/ivas_entropy_coder.c @@ -43,12 +43,6 @@ #include #include "wmc_auto.h" -/*------------------------------------------------------------------------------------------* - * Local constants - *------------------------------------------------------------------------------------------*/ - -#define IVAS_MAX_ENCODED_BITS ( 150 ) - /*-----------------------------------------------------------------------------------------* * Function ivas_get_dyn_freq_model() @@ -65,7 +59,7 @@ static ivas_error ivas_get_dyn_freq_model( { float curr_dist[IVAS_MAX_QUANT_LEVELS]; int16_t i, n[IVAS_MAX_QUANT_LEVELS + 1], model_idx; - float curr_bps = 0, curr_bps_min = 0, curr_bps_new = 0; + float curr_bps, curr_bps_min, curr_bps_new; int16_t range = pArith->range; int16_t m, offset = -pArith->vals[0]; ivas_error error; @@ -82,6 +76,7 @@ static ivas_error ivas_get_dyn_freq_model( n[pInput[i] + offset] += 1; } + curr_bps = 0; for ( i = 0; i < range; i++ ) { curr_dist[i] = (float) n[i]; @@ -128,12 +123,13 @@ static ivas_error ivas_get_dyn_freq_model( * * Arith encoding of an array of symbols *-----------------------------------------------------------------------------------------*/ + static int16_t ivas_arith_encode_array( int16_t *pInput, ivas_arith_t *pArith, BSTR_ENC_HANDLE hMetaData, const int16_t in_len, - int32_t wc_strat_arith ) + const int16_t wc_strat_arith ) { int16_t model_index, i, ind; int16_t *pCum_freq = NULL; @@ -148,6 +144,7 @@ static int16_t ivas_arith_encode_array( { return -1; } + push_next_indice( hMetaData, model_index, pArith->dyn_model_bits ); } else @@ -174,6 +171,7 @@ static int16_t ivas_arith_encode_array( return -1; } } + return 0; } @@ -183,13 +181,14 @@ static int16_t ivas_arith_encode_array( * * Differential arith encoding *-----------------------------------------------------------------------------------------*/ + static int16_t ivas_arithCoder_encode_array_diff( ivas_arith_t *pArith_diff, int16_t *pIn_new, int16_t *pIn_old_scratch, const int16_t length, BSTR_ENC_HANDLE hMetaData, - int32_t wc_strat_arith ) + const int16_t wc_strat_arith ) { int16_t n; int16_t arith_result; @@ -203,8 +202,7 @@ static int16_t ivas_arithCoder_encode_array_diff( ivas_wrap_arround( pIn_old_scratch, pArith_diff->vals[0], pArith_diff->vals[pArith_diff->range - 1], length ); - arith_result = ivas_arith_encode_array( pIn_old_scratch, pArith_diff, hMetaData, length, - wc_strat_arith ); + arith_result = ivas_arith_encode_array( pIn_old_scratch, pArith_diff, hMetaData, length, wc_strat_arith ); if ( arith_result < 0 ) { return -1; @@ -244,13 +242,14 @@ void ivas_huffman_encode( * * Arithmetic encode a cell array *-----------------------------------------------------------------------------------------*/ + static int16_t arith_encode_cell_array( ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, const int16_t nB, ivas_arith_t *pArith, int16_t *pSymbol, - int32_t wc_strat_arith ) + const int16_t wc_strat_arith ) { int16_t total_symbol_len = 0; int16_t i; @@ -267,8 +266,7 @@ static int16_t arith_encode_cell_array( { if ( pArith->range > 1 ) { - arith_result = ivas_arith_encode_array( pSymbol, pArith, hMetaData, total_symbol_len, - wc_strat_arith ); + arith_result = ivas_arith_encode_array( pSymbol, pArith, hMetaData, total_symbol_len, wc_strat_arith ); if ( arith_result < 0 ) { return -1; @@ -285,6 +283,7 @@ static int16_t arith_encode_cell_array( * * Arithmetic encode a cell array - differential *-----------------------------------------------------------------------------------------*/ + static int16_t arith_encode_cell_array_diff( const ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, @@ -292,7 +291,7 @@ static int16_t arith_encode_cell_array_diff( ivas_arith_t *pArith_diff, int16_t *pSymbol_old, int16_t *pSymbol, - int32_t wc_strat_arith ) + const int16_t wc_strat_arith ) { int16_t i, total_symbol_len; int16_t arith_result; @@ -309,8 +308,7 @@ static int16_t arith_encode_cell_array_diff( { if ( pArith_diff->range > 1 ) { - arith_result = ivas_arithCoder_encode_array_diff( pArith_diff, pSymbol, pSymbol_old, total_symbol_len, hMetaData, - wc_strat_arith ); + arith_result = ivas_arithCoder_encode_array_diff( pArith_diff, pSymbol, pSymbol_old, total_symbol_len, hMetaData, wc_strat_arith ); if ( arith_result < 0 ) { return -1; @@ -327,6 +325,7 @@ static int16_t arith_encode_cell_array_diff( * * Arithmetic encode a cell array *-----------------------------------------------------------------------------------------*/ + int16_t ivas_arith_encode_cmplx_cell_array( ivas_arith_t *pArith_re, ivas_arith_t *pArith_re_diff, @@ -337,7 +336,7 @@ int16_t ivas_arith_encode_cmplx_cell_array( ivas_cell_dim_t *pCell_dims, BSTR_ENC_HANDLE hMetaData, const int16_t any_diff, - int32_t wc_strat_arith ) + const int16_t wc_strat_arith ) { int16_t input_old[IVAS_MAX_INPUT_LEN]; int16_t input_new[IVAS_MAX_INPUT_LEN]; @@ -411,15 +410,13 @@ int16_t ivas_arith_encode_cmplx_cell_array( }*/ #endif - arith_result = arith_encode_cell_array( cell_dim, hMetaData, nB, pArith_re, input, - wc_strat_arith ); + arith_result = arith_encode_cell_array( cell_dim, hMetaData, nB, pArith_re, input, wc_strat_arith ); if ( arith_result < 0 ) { return -1; } - arith_result = arith_encode_cell_array_diff( cell_dim_diff, hMetaData, nB, pArith_re_diff, input_old, input_new, - wc_strat_arith ); + arith_result = arith_encode_cell_array_diff( cell_dim_diff, hMetaData, nB, pArith_re_diff, input_old, input_new, wc_strat_arith ); if ( arith_result < 0 ) { return -1; @@ -427,14 +424,12 @@ int16_t ivas_arith_encode_cmplx_cell_array( } else { - arith_result = arith_encode_cell_array( pCell_dims, hMetaData, nB, pArith_re, pSymbol_re, - wc_strat_arith ); + arith_result = arith_encode_cell_array( pCell_dims, hMetaData, nB, pArith_re, pSymbol_re, wc_strat_arith ); if ( arith_result < 0 ) { return -1; } } - return 0; } diff --git a/lib_enc/ivas_sba_enc.c b/lib_enc/ivas_sba_enc.c index 1d6256b021e29becd2ca43dc40396037f3c329d6..53e2a62a14efbebdd8b2c8a86b3d6c21826a41db 100644 --- a/lib_enc/ivas_sba_enc.c +++ b/lib_enc/ivas_sba_enc.c @@ -248,6 +248,7 @@ ivas_error ivas_sba_enc_reconfigure( } } hSpar->enc_param_start_band = hDirAC->hConfig->enc_param_start_band; + /*-----------------------------------------------------------------* * Allocate, initialize, and configure SCE/CPE/MCT handles *-----------------------------------------------------------------*/ @@ -261,11 +262,20 @@ ivas_error ivas_sba_enc_reconfigure( return error; } +/*-------------------------------------------------------------------* + * ivas_sba_get_max_md_bits() + * + * Return maximum SBA metadata bit-budget + *-------------------------------------------------------------------*/ + +/*! r: maximum SBA metadata bit-budget */ int16_t ivas_sba_get_max_md_bits( - Encoder_Struct *st_ivas ) + Encoder_Struct *st_ivas /* i/o: Encoder struct */ +) { int16_t max_md_bits; int16_t max_bits; + if ( ivas_get_hodirac_flag( st_ivas->hEncoderConfig->ivas_total_brate, st_ivas->sba_analysis_order ) ) { max_bits = 2000; @@ -274,10 +284,12 @@ int16_t ivas_sba_get_max_md_bits( { max_bits = 500; } + max_md_bits = min( st_ivas->hQMetaData->metadata_max_bits + 1, max_bits ); // TODO: remove 500 once max MD bits has been defined at all bitrates in DirAC if ( st_ivas->hEncoderConfig->ivas_format == SBA_FORMAT ) { max_md_bits += st_ivas->hSpar->hMdEnc->spar_md_cfg.max_md_bits_spar; } + return max_md_bits; } diff --git a/lib_enc/ivas_spar_encoder.c b/lib_enc/ivas_spar_encoder.c index 2731fdaf407f7ca8ffd8d0287424dc1c63cf4ed5..c5be41e0609caaebfae8b724b1dada3f6b6a4545 100644 --- a/lib_enc/ivas_spar_encoder.c +++ b/lib_enc/ivas_spar_encoder.c @@ -427,8 +427,7 @@ static ivas_error ivas_spar_enc_process( input_frame = (int16_t) ( input_Fs / FRAMES_PER_SEC ); sba_order = min( st_ivas->sba_analysis_order, IVAS_MAX_SBA_ORDER ); - nchan_inp = ivas_sba_get_nchan_metadata( sba_order, - hEncoderConfig->ivas_total_brate ); + nchan_inp = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); assert( nchan_inp <= hEncoderConfig->nchan_inp ); int16_t active_w_vlbr; @@ -544,6 +543,7 @@ static ivas_error ivas_spar_enc_process( hSpar->AGC_Enable ); } } + /*-----------------------------------------------------------------------------------------* * Covariance process *-----------------------------------------------------------------------------------------*/ diff --git a/lib_enc/ivas_spar_md_enc.c b/lib_enc/ivas_spar_md_enc.c index 2776f6576532428af78edec0ed6170f8d70509b8..47491f6a783ad08c836d56174660d5335f109aed 100644 --- a/lib_enc/ivas_spar_md_enc.c +++ b/lib_enc/ivas_spar_md_enc.c @@ -81,6 +81,7 @@ static void ivas_select_next_strat( ivas_strats_t prior_strat, ivas_strats_t cs[ static void ivas_store_prior_coeffs( ivas_spar_md_enc_state_t *hMdEnc, const int16_t num_bands, const int16_t strat, const int16_t dtx_vad, const int16_t qsi ); static void ivas_write_spar_md_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 strat, const int16_t qsi, const int16_t planarCP ); + static void ivas_spar_quant_pred_coeffs_dtx( ivas_spar_md_t *pSpar_md, const float *pValues, const int16_t ndm, int16_t *pIndex, const int16_t dim1, float *pQuant ); static void ivas_quant_p_per_band_dtx( float *pP_mat, const int16_t num_dec, const int16_t num_dmx, int16_t *ppIdx_pd, float *pP_out, const int16_t num_ch ); @@ -301,6 +302,7 @@ void ivas_spar_md_enc_close( * * SPAR MD encoder initialization *-----------------------------------------------------------------------------------------*/ + ivas_error ivas_spar_md_enc_init( ivas_spar_md_enc_state_t *hMdEnc, /* o : MD encoder handle */ const ENCODER_CONFIG_HANDLE hEncoderConfig, /* i : configuration structure */ @@ -313,15 +315,12 @@ ivas_error ivas_spar_md_enc_init( int16_t num_channels, i, j, k; ivas_sba_get_spar_hoa_md_flag( sba_order, hEncoderConfig->ivas_total_brate, &hMdEnc->spar_hoa_md_flag, &hMdEnc->spar_hoa_dirac2spar_md_flag ); - num_channels = ivas_sba_get_nchan_metadata( sba_order, - hEncoderConfig->ivas_total_brate ); + num_channels = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); ivas_sba_get_spar_hoa_ch_ind( num_channels, hEncoderConfig->ivas_total_brate, hMdEnc->HOA_md_ind ); table_idx = ivas_get_spar_table_idx( hEncoderConfig->ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); - ivas_spar_set_bitrate_config( &hMdEnc->spar_md_cfg, table_idx, - ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, - hMdEnc->spar_hoa_dirac2spar_md_flag, - 1, hEncoderConfig->Opt_PCA_ON, + ivas_spar_set_bitrate_config( &hMdEnc->spar_md_cfg, table_idx, ( hMdEnc->spar_hoa_md_flag ) ? IVAS_MAX_NUM_BANDS : SPAR_DIRAC_SPLIT_START_BAND, + hMdEnc->spar_hoa_dirac2spar_md_flag, 1, hEncoderConfig->Opt_PCA_ON, #ifndef DEBUG_AGC_ENCODER_CMD_OPTION ivas_agc_enc_get_flag( ivas_spar_br_table_consts[table_idx].nchan_transport ) #else @@ -593,11 +592,13 @@ ivas_error ivas_spar_md_enc_process( /*extra 16 bits for arithmetic coder as overshoot check is after a symbol is written*/ md_indices_allocated = hMdEnc->spar_md_cfg.max_bits_per_blk + IVAS_SPAR_ARITH_OVERSHOOT_BITS; - ind_list_tmp = (Indice *) malloc( sizeof( Indice ) * md_indices_allocated ); + if ( ( ind_list_tmp = (Indice *) malloc( sizeof( Indice ) * md_indices_allocated ) ) == NULL ) + { + return IVAS_ERROR( IVAS_ERR_FAILED_ALLOC, "Can not allocate memory for SPAR MD encoder indices" ); + } num_quant_strats = hMdEnc->spar_md_cfg.num_quant_strats; - num_ch = ivas_sba_get_nchan_metadata( sba_order, - hEncoderConfig->ivas_total_brate ); + num_ch = ivas_sba_get_nchan_metadata( sba_order, hEncoderConfig->ivas_total_brate ); active_w = hMdEnc->spar_md_cfg.active_w; nchan_transport = hMdEnc->spar_md_cfg.nchan_transport; @@ -962,7 +963,9 @@ ivas_error ivas_spar_md_enc_process( if ( strat != NO_STRAT ) { reset_indices_enc( &hMetaData_tmp, md_indices_allocated ); + ivas_write_spar_md_bitstream( hMdEnc, num_bands, bands_bw, &hMetaData_tmp, hEncoderConfig->ivas_total_brate, strat, qsi, planarCP ); + /*write to main buffer if its a valid bitstream*/ if ( hMetaData_tmp.nb_bits_tot > 0 ) { @@ -976,13 +979,11 @@ ivas_error ivas_spar_md_enc_process( ); code_strat = strat; } + if ( hMetaData->nb_bits_tot - bit_pos_start + ( ( ( hEncoderConfig->ivas_total_brate == IVAS_256k ) && ( sba_order == SBA_FOA_ORDER ) ) ? 1 : 0 ) <= hMdEnc->spar_md_cfg.tgt_bits_per_blk ) { - - { - packed_ok = 1; - break; - } + packed_ok = 1; + break; } } } @@ -1004,6 +1005,7 @@ ivas_error ivas_spar_md_enc_process( } } +#ifdef DEBUGGING if ( dtx_vad == 1 ) { assert( packed_ok == 1 ); @@ -1012,6 +1014,8 @@ ivas_error ivas_spar_md_enc_process( { assert( qsi == 0 ); } +#endif + /* Reuse mixer matrix values for unsent bands */ if ( ( hEncoderConfig->ivas_total_brate < IVAS_24k4 ) && ( code_strat > 3 ) ) { @@ -1427,15 +1431,12 @@ static void ivas_write_spar_md_bitstream( if ( no_ec == 1 ) { entropy_coding_result = - ivas_get_huffman_coded_bs( hMdEnc, hMetaData, nB, qsi, planarCP, - bands_bw ); + ivas_get_huffman_coded_bs( hMdEnc, hMetaData, nB, qsi, planarCP, bands_bw ); } else { entropy_coding_result = - ivas_get_arith_coded_bs( hMdEnc, hMetaData, do_diff, bands_bw, nB, qsi, planarCP, - strat, - ivas_total_brate ); + ivas_get_arith_coded_bs( hMdEnc, hMetaData, do_diff, bands_bw, nB, qsi, planarCP, strat, ivas_total_brate ); } if ( entropy_coding_result < 0 ) @@ -1656,8 +1657,7 @@ static int16_t ivas_get_arith_coded_bs( } arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.pred_arith_re[qsi], &hMdEnc->arith_coeffs.pred_arith_re_diff[qsi], pDo_diff, nB, - symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff, - hMdEnc->spar_md_cfg.max_bits_per_blk ); + symbol_arr_re, symbol_arr_old_re, pred_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); if ( arith_result < 0 ) { return -1; @@ -1704,14 +1704,12 @@ static int16_t ivas_get_arith_coded_bs( } arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.drct_arith_re[qsi], &hMdEnc->arith_coeffs.drct_arith_re_diff[qsi], pDo_diff, nB, - symbol_arr_re, symbol_arr_old_re, drct_cell_dims, hMetaData, any_diff, - hMdEnc->spar_md_cfg.max_bits_per_blk ); + symbol_arr_re, symbol_arr_old_re, drct_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); if ( arith_result < 0 ) { return -1; } - ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, decd_cell_dims, DECD_COEFF, planarCP ); if ( any_diff == 1 ) @@ -1727,14 +1725,12 @@ static int16_t ivas_get_arith_coded_bs( } } arith_result = ivas_arith_encode_cmplx_cell_array( &hMdEnc->arith_coeffs.decd_arith_re[qsi], &hMdEnc->arith_coeffs.decd_arith_re_diff[qsi], pDo_diff, nB, - symbol_arr_re, symbol_arr_old_re, decd_cell_dims, hMetaData, any_diff, - hMdEnc->spar_md_cfg.max_bits_per_blk ); + symbol_arr_re, symbol_arr_old_re, decd_cell_dims, hMetaData, any_diff, hMdEnc->spar_md_cfg.max_bits_per_blk ); if ( arith_result < 0 ) { return -1; } - ivas_copy_band_coeffs_idx_to_arr( hMdEnc->spar_md.band_coeffs_idx, nB, symbol_arr_re, decx_cell_dims, DECX_COEFF, planarCP ); if ( any_diff == 1 )