Loading lib_com/ivas_cnst.h +2 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,8 @@ typedef enum #define IVAS_FORMAT_SIGNALING_NBITS 2 /* number of bits for signaling the IVAS format */ #define IVAS_FORMAT_SIGNALING_NBITS_SBA ( IVAS_FORMAT_SIGNALING_NBITS + 1 ) #ifdef ARITH_HUFF_CODER_CHANGES #define IVAS_SBA_SIGNALING_OVERHEAD IVAS_FORMAT_SIGNALING_NBITS_SBA + SBA_ORDER_BITS + SBA_PLANAR_BITS + AGC_SIGNALLING_BITS + SPAR_NUM_CODING_STRAT_BITS //#define IVAS_SBA_SIGNALING_OVERHEAD IVAS_FORMAT_SIGNALING_NBITS_SBA + SBA_ORDER_BITS + SBA_PLANAR_BITS + AGC_SIGNALLING_BITS + SPAR_NUM_CODING_STRAT_BITS #define IVAS_SBA_SIGNALING_OVERHEAD 600 #endif Loading lib_com/ivas_prot.h +9 −1 Original line number Diff line number Diff line Loading @@ -3925,6 +3925,11 @@ 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 */ #ifdef ARITH_HUFF_CODER_CHANGES , const int16_t enc_flag ,const int16_t Opt_PCA_ON #endif ); void ivas_spar_bitrate_dist( Loading Loading @@ -4011,6 +4016,9 @@ ivas_error ivas_spar_md_enc_process( const int16_t dtx_vad, const int16_t nchan_inp, const int16_t sba_order /* i : Ambisonic (SBA) order */ #ifdef ARITH_HUFF_CODER_CHANGES , int16_t max_md_bit_dirac #endif ); void ivas_compute_spar_params( Loading lib_com/ivas_spar_com.c +68 −47 Original line number Diff line number Diff line Loading @@ -2094,12 +2094,25 @@ 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 */ #ifdef ARITH_HUFF_CODER_CHANGES , const int16_t enc_flag, const int16_t Opt_PCA_ON #endif ) { int32_t ivas_total_brate; int16_t i, total_bits, max_bits, code, length; int16_t sba_order; int16_t md_coding_bits_header; #ifdef ARITH_HUFF_CODER_CHANGES int16_t bits_PR, bits_C, bits_P = 0; int16_t wc_coarse_strat = 0; int16_t n_input, n_dmx, n_dec = 0; int16_t table_idx_val, quant_strat = 0; int16_t table_cal_wc = 0; int16_t val = 0; #endif pSpar_md_cfg->nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; for ( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) Loading Loading @@ -2145,56 +2158,64 @@ 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; /*rtyag: IMO this is where we should have the check and compute worst case MD bits what we want to check is if (pSpar_md_cfg->max_bits_per_blk - md_coding_bits_header >= base2(PR_bits_perband + P_bits_perband + C_bits_perband)*num_bands) if above condition is not true then assert(0); Here, we dont really need to account for AGC or PCA as we have been taking AGC and PCA bits from core coder always. pSpar_md_cfg->max_bits_per_blk is what you should use to bail out of arith/huff coder during processing. When it comes to reporting the max MD bits for bitstream indices allocation then that should be what we write in hMetaData handle in worst case i.e. pSpar_md_cfg->max_bits_per_blk + AGC max bits + PCA max bits + DirAC max bits AGC bits can be computed as if(hSpar->AGC_Enable) #ifdef ARITH_HUFF_CODER_CHANGES if ( enc_flag) { /*calculate the worst case strat vlaue*/ table_idx_val = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); if ( ( ivas_spar_br_table_consts[table_idx].q_lvls[2][0] == 1 && ivas_spar_br_table_consts[table_idx].q_lvls[2][1] == 1 && ivas_spar_br_table_consts[table_idx].q_lvls[2][2] == 1 && ivas_spar_br_table_consts[table_idx].q_lvls[2][3] == 1 ) ) { AGC_bits = (ndmx == 1)?AGC_BITS_PER_CH : AGC_SIGNALLING_BITS + AGC_BITS_PER_CH*ndmx quant_strat = QUANT_STRAT_0; } else { AGC_bits = AGC_SIGNALLING_BITS quant_strat = QUANT_STRAT_2; } /*worst case table calculated value*/ for ( i = 0; i < ivas_spar_br_table_consts[table_idx_val].nchan_transport; i++ ) { table_cal_wc += ivas_spar_br_table_consts[table_idx_val].core_brs[i][1]; } table_cal_wc = ( ivas_total_brate - table_cal_wc ) / FRAMES_PER_SEC; n_input = ivas_sba_get_nchan_metadata( sba_order ); n_dmx = ivas_spar_br_table_consts[table_idx_val].nchan_transport; n_dec = n_input - n_dmx; bits_PR = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx_val].q_lvls[quant_strat][0] ) ) * ( n_input - 1 ); bits_C = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx_val].q_lvls[quant_strat][1] ) ) * ( ( n_dmx - 1 ) * n_dec ); bits_P = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx_val].q_lvls[quant_strat][2] ) ) * ( n_dec ); wc_coarse_strat = bits_PR + bits_C + bits_P; wc_coarse_strat = ( ( wc_coarse_strat * IVAS_MAX_NUM_BANDS ) * FRAMES_PER_SEC + ( IVAS_SBA_SIGNALING_OVERHEAD ) ) / FRAMES_PER_SEC; pSpar_md_cfg->max_md_bits_sba = wc_coarse_strat; PCA bits can be computed as if (hEncoderConfig->Opt_PCA_ON ) if ( Opt_PCA_ON ) { PCA_bits = 1 + IVAS_PCA_QBITS + IVAS_PCA_QBITS - 1; pSpar_md_cfg->PCA_val = 1 + IVAS_PCA_QBITS + IVAS_PCA_QBITS - 1; } else { if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER ) { PCA_bits = 1; pSpar_md_cfg->PCA_val = 1; } else { PCA_bits = 0; pSpar_md_cfg->PCA_val = 0; } } for dirac_bits, try using min(hQMetaData->metadata_max_bits+1, 500); (note: 500 is a temp value, actual value will come from FhG. If you see self test failure with 500 then increase it in steps of 100 until you see BE results) */ if ( wc_coarse_strat > table_cal_wc ) { assert( 0 ); } if ( pSpar_md_cfg->max_bits_per_blk - md_coding_bits_header < wc_coarse_strat ) { // assert( 0 ); } } #endif return; } Loading lib_com/ivas_stat_com.h +10 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,9 @@ #include "typedef.h" #include "cnst.h" #include "ivas_cnst.h" #ifdef ARITH_HUFF_CODER_CHANGES #include "stat_enc.h" #endif /*----------------------------------------------------------------------------------* Loading Loading @@ -239,6 +242,13 @@ typedef struct ivas_spar_md_com_cfg int16_t agc_bits_ch_idx; int16_t planarCP; int16_t num_umx_chs; #ifdef ARITH_HUFF_CODER_CHANGES int16_t max_md_bits_sba; int16_t WC_value; Indice *wc_coarse_strat_buff; int16_t AGC_status; int16_t PCA_val; #endif } ivas_spar_md_com_cfg; Loading lib_com/options.h +1 −1 Original line number Diff line number Diff line Loading @@ -170,7 +170,7 @@ #define FIX_350_MASA_DELAY_COMP /* Nokia: Issue 350: MASA audio/meta delay compensation */ #define FIX_372_LIB_REND_VALIDATE_IO /* FhG: Issue 372: IVAS_rend segfaults with unsupported I/O configs - add validation checks of I/O config */ #define ARITH_HUFF_CODER_CHANGES #define ARITH_HUFF_CODER_CHANGES /* DLB: Optimization of metadata memory for Huffman and arithmetic coders */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif Loading
lib_com/ivas_cnst.h +2 −1 Original line number Diff line number Diff line Loading @@ -80,7 +80,8 @@ typedef enum #define IVAS_FORMAT_SIGNALING_NBITS 2 /* number of bits for signaling the IVAS format */ #define IVAS_FORMAT_SIGNALING_NBITS_SBA ( IVAS_FORMAT_SIGNALING_NBITS + 1 ) #ifdef ARITH_HUFF_CODER_CHANGES #define IVAS_SBA_SIGNALING_OVERHEAD IVAS_FORMAT_SIGNALING_NBITS_SBA + SBA_ORDER_BITS + SBA_PLANAR_BITS + AGC_SIGNALLING_BITS + SPAR_NUM_CODING_STRAT_BITS //#define IVAS_SBA_SIGNALING_OVERHEAD IVAS_FORMAT_SIGNALING_NBITS_SBA + SBA_ORDER_BITS + SBA_PLANAR_BITS + AGC_SIGNALLING_BITS + SPAR_NUM_CODING_STRAT_BITS #define IVAS_SBA_SIGNALING_OVERHEAD 600 #endif Loading
lib_com/ivas_prot.h +9 −1 Original line number Diff line number Diff line Loading @@ -3925,6 +3925,11 @@ 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 */ #ifdef ARITH_HUFF_CODER_CHANGES , const int16_t enc_flag ,const int16_t Opt_PCA_ON #endif ); void ivas_spar_bitrate_dist( Loading Loading @@ -4011,6 +4016,9 @@ ivas_error ivas_spar_md_enc_process( const int16_t dtx_vad, const int16_t nchan_inp, const int16_t sba_order /* i : Ambisonic (SBA) order */ #ifdef ARITH_HUFF_CODER_CHANGES , int16_t max_md_bit_dirac #endif ); void ivas_compute_spar_params( Loading
lib_com/ivas_spar_com.c +68 −47 Original line number Diff line number Diff line Loading @@ -2094,12 +2094,25 @@ 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 */ #ifdef ARITH_HUFF_CODER_CHANGES , const int16_t enc_flag, const int16_t Opt_PCA_ON #endif ) { int32_t ivas_total_brate; int16_t i, total_bits, max_bits, code, length; int16_t sba_order; int16_t md_coding_bits_header; #ifdef ARITH_HUFF_CODER_CHANGES int16_t bits_PR, bits_C, bits_P = 0; int16_t wc_coarse_strat = 0; int16_t n_input, n_dmx, n_dec = 0; int16_t table_idx_val, quant_strat = 0; int16_t table_cal_wc = 0; int16_t val = 0; #endif pSpar_md_cfg->nchan_transport = ivas_spar_br_table_consts[table_idx].nchan_transport; for ( i = 0; i < pSpar_md_cfg->nchan_transport; i++ ) Loading Loading @@ -2145,56 +2158,64 @@ 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; /*rtyag: IMO this is where we should have the check and compute worst case MD bits what we want to check is if (pSpar_md_cfg->max_bits_per_blk - md_coding_bits_header >= base2(PR_bits_perband + P_bits_perband + C_bits_perband)*num_bands) if above condition is not true then assert(0); Here, we dont really need to account for AGC or PCA as we have been taking AGC and PCA bits from core coder always. pSpar_md_cfg->max_bits_per_blk is what you should use to bail out of arith/huff coder during processing. When it comes to reporting the max MD bits for bitstream indices allocation then that should be what we write in hMetaData handle in worst case i.e. pSpar_md_cfg->max_bits_per_blk + AGC max bits + PCA max bits + DirAC max bits AGC bits can be computed as if(hSpar->AGC_Enable) #ifdef ARITH_HUFF_CODER_CHANGES if ( enc_flag) { /*calculate the worst case strat vlaue*/ table_idx_val = ivas_get_spar_table_idx( ivas_total_brate, sba_order, SPAR_CONFIG_BW, NULL, NULL ); if ( ( ivas_spar_br_table_consts[table_idx].q_lvls[2][0] == 1 && ivas_spar_br_table_consts[table_idx].q_lvls[2][1] == 1 && ivas_spar_br_table_consts[table_idx].q_lvls[2][2] == 1 && ivas_spar_br_table_consts[table_idx].q_lvls[2][3] == 1 ) ) { AGC_bits = (ndmx == 1)?AGC_BITS_PER_CH : AGC_SIGNALLING_BITS + AGC_BITS_PER_CH*ndmx quant_strat = QUANT_STRAT_0; } else { AGC_bits = AGC_SIGNALLING_BITS quant_strat = QUANT_STRAT_2; } /*worst case table calculated value*/ for ( i = 0; i < ivas_spar_br_table_consts[table_idx_val].nchan_transport; i++ ) { table_cal_wc += ivas_spar_br_table_consts[table_idx_val].core_brs[i][1]; } table_cal_wc = ( ivas_total_brate - table_cal_wc ) / FRAMES_PER_SEC; n_input = ivas_sba_get_nchan_metadata( sba_order ); n_dmx = ivas_spar_br_table_consts[table_idx_val].nchan_transport; n_dec = n_input - n_dmx; bits_PR = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx_val].q_lvls[quant_strat][0] ) ) * ( n_input - 1 ); bits_C = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx_val].q_lvls[quant_strat][1] ) ) * ( ( n_dmx - 1 ) * n_dec ); bits_P = (int16_t) ceilf( log2f( ivas_spar_br_table_consts[table_idx_val].q_lvls[quant_strat][2] ) ) * ( n_dec ); wc_coarse_strat = bits_PR + bits_C + bits_P; wc_coarse_strat = ( ( wc_coarse_strat * IVAS_MAX_NUM_BANDS ) * FRAMES_PER_SEC + ( IVAS_SBA_SIGNALING_OVERHEAD ) ) / FRAMES_PER_SEC; pSpar_md_cfg->max_md_bits_sba = wc_coarse_strat; PCA bits can be computed as if (hEncoderConfig->Opt_PCA_ON ) if ( Opt_PCA_ON ) { PCA_bits = 1 + IVAS_PCA_QBITS + IVAS_PCA_QBITS - 1; pSpar_md_cfg->PCA_val = 1 + IVAS_PCA_QBITS + IVAS_PCA_QBITS - 1; } else { if ( ivas_total_brate == PCA_BRATE && sba_order == SBA_FOA_ORDER ) { PCA_bits = 1; pSpar_md_cfg->PCA_val = 1; } else { PCA_bits = 0; pSpar_md_cfg->PCA_val = 0; } } for dirac_bits, try using min(hQMetaData->metadata_max_bits+1, 500); (note: 500 is a temp value, actual value will come from FhG. If you see self test failure with 500 then increase it in steps of 100 until you see BE results) */ if ( wc_coarse_strat > table_cal_wc ) { assert( 0 ); } if ( pSpar_md_cfg->max_bits_per_blk - md_coding_bits_header < wc_coarse_strat ) { // assert( 0 ); } } #endif return; } Loading
lib_com/ivas_stat_com.h +10 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,9 @@ #include "typedef.h" #include "cnst.h" #include "ivas_cnst.h" #ifdef ARITH_HUFF_CODER_CHANGES #include "stat_enc.h" #endif /*----------------------------------------------------------------------------------* Loading Loading @@ -239,6 +242,13 @@ typedef struct ivas_spar_md_com_cfg int16_t agc_bits_ch_idx; int16_t planarCP; int16_t num_umx_chs; #ifdef ARITH_HUFF_CODER_CHANGES int16_t max_md_bits_sba; int16_t WC_value; Indice *wc_coarse_strat_buff; int16_t AGC_status; int16_t PCA_val; #endif } ivas_spar_md_com_cfg; Loading
lib_com/options.h +1 −1 Original line number Diff line number Diff line Loading @@ -170,7 +170,7 @@ #define FIX_350_MASA_DELAY_COMP /* Nokia: Issue 350: MASA audio/meta delay compensation */ #define FIX_372_LIB_REND_VALIDATE_IO /* FhG: Issue 372: IVAS_rend segfaults with unsupported I/O configs - add validation checks of I/O config */ #define ARITH_HUFF_CODER_CHANGES #define ARITH_HUFF_CODER_CHANGES /* DLB: Optimization of metadata memory for Huffman and arithmetic coders */ /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif