Skip to content

Commit

Permalink
Encoder enhancements (#84)
Browse files Browse the repository at this point in the history
Tests done: smoke test
  • Loading branch information
akshayragir833 authored Mar 29, 2024
1 parent d880b2f commit da04d9d
Show file tree
Hide file tree
Showing 9 changed files with 233 additions and 77 deletions.
21 changes: 13 additions & 8 deletions encoder/drc_src/impd_drc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
var = MAX(var, lower_bound); \
}

static IA_ERRORCODE impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_config) {
IA_ERRORCODE impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_config) {
LOOPIDX i, j, k;
WORD32 curr_start_subband_idx, next_start_subband_idx;
ia_drc_uni_drc_config_struct *pstr_uni_drc_config = &pstr_inp_config->str_uni_drc_config;
Expand Down Expand Up @@ -280,11 +280,6 @@ IA_ERRORCODE impd_drc_enc_init(VOID *pstr_drc_state, VOID *ptr_drc_scratch,
pstr_drc_state_local->bit_buf_base_out,
sizeof(pstr_drc_state_local->bit_buf_base_out), 1);

err_code = impd_drc_validate_config_params(pstr_inp_config);
if (err_code) {
return err_code;
}

err_code = impd_drc_gain_enc_init(
&pstr_drc_state_local->str_gain_enc, &pstr_inp_config->str_uni_drc_config,
&pstr_inp_config->str_enc_loudness_info_set, pstr_inp_config->str_enc_params.frame_size,
Expand All @@ -302,13 +297,23 @@ IA_ERRORCODE impd_drc_enc_init(VOID *pstr_drc_state, VOID *ptr_drc_scratch,
return IA_EXHEAACE_CONFIG_FATAL_DRC_INVALID_CONFIG;
}

err_code = impd_drc_write_uni_drc_config(pstr_drc_state_local, &bit_count);
err_code = impd_drc_write_uni_drc_config(pstr_drc_state_local, &bit_count, 1);
if (err_code & IA_FATAL_ERROR) {
return err_code;
}

pstr_drc_state_local->drc_config_data_size_bit = bit_count;

// Loudness info set
if (pstr_drc_state_local->str_gain_enc.str_uni_drc_config.loudness_info_set_present == 1){
bit_count = 0;
err_code = impd_drc_write_loudness_info_set(
pstr_drc_state, &pstr_drc_state_local->str_bit_buf_cfg_ext, &bit_count, 1);
if (err_code & IA_FATAL_ERROR) {
return (err_code);
}
pstr_drc_state_local->drc_config_ext_data_size_bit = bit_count;
}

return err_code;
}

Expand Down
4 changes: 3 additions & 1 deletion encoder/drc_src/impd_drc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ IA_ERRORCODE impd_drc_enc_init(VOID *pstr_drc_state, VOID *ptr_drc_scratch,
IA_ERRORCODE impd_drc_enc(VOID *pstr_drc_state, FLOAT32 **pptr_input, UWORD32 inp_offset,
WORD32 *ptr_bits_written, VOID *pstr_scratch);

IA_ERRORCODE impd_loudness_info_init(VOID *pstr_drc_state, ia_drc_input_config *pstr_inp_config);
IA_ERRORCODE impd_loudness_info_init(VOID *pstr_drc_state, ia_drc_input_config *pstr_inp_config);

IA_ERRORCODE impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_config);
11 changes: 7 additions & 4 deletions encoder/drc_src/impd_drc_common_enc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@
#define MAX_CHANNEL_COUNT (8)
#define MAX_BAND_COUNT (8)
#define MAX_SEQUENCE_COUNT (8)
#define MAX_MEASUREMENT_COUNT (8)
#define MAX_MEASUREMENT_COUNT (15)
#define MAX_DOWNMIX_INSTRUCTION_COUNT (16)
#define MAX_DRC_COEFF_COUNT (8)
#define MAX_DRC_COEFF_COUNT (7)
#define MAX_DRC_INSTRUCTIONS_COUNT (MAX_DOWNMIX_INSTRUCTION_COUNT + 16)
#define MAX_LOUDNESS_INFO_COUNT (7)
#define MAX_LOUDNESS_INFO_COUNT (MAX_DOWNMIX_INSTRUCTION_COUNT + 16)
#define MAX_AUDIO_CODEC_FRAME_SIZE (2048)
#define MAX_DRC_CODEC_FRAME_SIZE (MAX_AUDIO_CODEC_FRAME_SIZE / 8)
#define MAX_NODE_COUNT (MAX_DRC_CODEC_FRAME_SIZE)
#define MAX_CHANNEL_GROUP_COUNT (MAX_SEQUENCE_COUNT)
#define MAX_ADDITIONAL_DOWNMIX_ID (8)
#define MAX_ADDITIONAL_DOWNMIX_ID (7)
#define DELAY_MODE_REGULAR_DELAY (0)
#define MAX_EXT_COUNT (2)
#define MAX_GAIN_POINTS (256)
#define MAX_DRC_INSTRUCTIONS_BASIC_COUNT (15)

#define UNIDRC_GAIN_EXT_TERM (0x0)
#define UNIDRC_LOUD_EXT_TERM (0x0)
Expand Down Expand Up @@ -72,6 +73,8 @@
#define SUBBAND_DOMAIN (2)
#define SLOPE_FACTOR_DB_TO_LINEAR (0.1151f) /* ln(10) / 20 */

#define MAX_DRC_CONFIG_SIZE_EXPECTED (14336) /* 14 KB*/

#ifndef MIN
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
Expand Down
9 changes: 5 additions & 4 deletions encoder/drc_src/impd_drc_enc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ IA_ERRORCODE impd_drc_encode_uni_drc_gain(ia_drc_gain_enc_struct *pstr_gain_enc,
IA_ERRORCODE impd_drc_write_loudness_info_set_extension(
ia_drc_enc_state *pstr_drc_state, ia_bit_buf_struct *it_bit_buf,
ia_drc_loudness_info_set_extension_struct *pstr_loudness_info_set_extension,
WORD32 *ptr_bit_cnt);
WORD32 *ptr_bit_cnt, FLAG write_bs);

IA_ERRORCODE impd_drc_write_uni_drc_config(ia_drc_enc_state *pstr_drc_state, WORD32 *ptr_bit_cnt);
IA_ERRORCODE impd_drc_write_uni_drc_config(ia_drc_enc_state *pstr_drc_state, WORD32 *ptr_bit_cnt,
FLAG write_bs);

VOID impd_drc_write_uni_drc_gain(ia_drc_enc_state *pstr_drc_state, WORD32 *ptr_bit_cnt);

IA_ERRORCODE impd_drc_write_measured_loudness_info(ia_drc_enc_state *pstr_drc_state);

IA_ERRORCODE impd_drc_write_loudness_info_set(ia_drc_enc_state *pstr_drc_state,
ia_bit_buf_struct *it_bit_buf,
WORD32 *ptr_bit_cnt);
ia_bit_buf_struct *it_bit_buf, WORD32 *ptr_bit_cnt,
FLAG write_bs);
59 changes: 31 additions & 28 deletions encoder/drc_src/impd_drc_mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,8 @@ static VOID impd_drc_write_split_drc_characteristic(
it_bit_buf, pstr_split_characteristic->characteristic_node_count - 1, 2);

for (idx = 1; idx <= pstr_split_characteristic->characteristic_node_count; idx++) {
bs_node_level_delta = (WORD32)(
floor(fabs(pstr_split_characteristic->node_level[idx] - bs_node_level_previous) +
bs_node_level_delta = (WORD32)(floor(fabs(pstr_split_characteristic->node_level[idx] -
bs_node_level_previous) +
0.5f) -
1);

Expand Down Expand Up @@ -2510,7 +2510,8 @@ static IA_ERRORCODE impd_drc_write_eq_instructions(
static IA_ERRORCODE impd_drc_write_uni_drc_config_extn(
ia_drc_enc_state *pstr_drc_state, ia_drc_gain_enc_struct *pstr_gain_enc,
ia_drc_uni_drc_config_struct *pstr_uni_drc_config,
ia_drc_uni_drc_config_ext_struct *pstr_uni_drc_config_ext, WORD32 *ptr_bit_cnt) {
ia_drc_uni_drc_config_ext_struct *pstr_uni_drc_config_ext, WORD32 *ptr_bit_cnt,
FLAG write_bs) {
IA_ERRORCODE err_code = IA_NO_ERROR;
LOOPIDX idx;
WORD32 version;
Expand All @@ -2519,10 +2520,15 @@ static IA_ERRORCODE impd_drc_write_uni_drc_config_extn(
WORD32 bit_cnt_local = 0, bit_cnt_local_ext = 0;
WORD32 *scratch_used = &pstr_drc_state->drc_scratch_used;
VOID *ptr_scratch = &pstr_drc_state->drc_scratch_mem;
ia_bit_buf_struct *it_bit_buf = &pstr_drc_state->str_bit_buf_cfg;
ia_bit_buf_struct *ptr_bit_buf_ext = &pstr_drc_state->str_bit_buf_cfg_ext;
ia_bit_buf_struct *it_bit_buf = NULL;
ia_bit_buf_struct *ptr_bit_buf_ext = NULL;

iusace_reset_bit_buffer(ptr_bit_buf_ext);
if (write_bs) {
it_bit_buf = &pstr_drc_state->str_bit_buf_cfg;
ptr_bit_buf_ext = &pstr_drc_state->str_bit_buf_cfg_ext;

iusace_reset_bit_buffer(ptr_bit_buf_ext);
}

bit_cnt_local += iusace_write_bits_buf(
it_bit_buf, pstr_uni_drc_config_ext->uni_drc_config_ext_type[counter], 4);
Expand Down Expand Up @@ -2755,7 +2761,7 @@ static IA_ERRORCODE impd_drc_write_uni_drc_config_extn(
IA_ERRORCODE impd_drc_write_loudness_info_set_extension(
ia_drc_enc_state *pstr_drc_state, ia_bit_buf_struct *it_bit_buf,
ia_drc_loudness_info_set_extension_struct *pstr_loudness_info_set_extension,
WORD32 *ptr_bit_cnt) {
WORD32 *ptr_bit_cnt, FLAG write_bs) {
IA_ERRORCODE err_code = IA_NO_ERROR;
LOOPIDX idx;
WORD32 counter = 0, version = 1;
Expand All @@ -2764,9 +2770,13 @@ IA_ERRORCODE impd_drc_write_loudness_info_set_extension(
WORD32 bit_cnt_local_tmp = 0;
ia_drc_loudness_info_set_ext_eq_struct *pstr_loudness_info_set_ext_eq =
&pstr_loudness_info_set_extension->str_loudness_info_set_ext_eq;
ia_bit_buf_struct *ptr_bit_buf_tmp = &pstr_drc_state->str_bit_buf_cfg_tmp;
ia_bit_buf_struct *ptr_bit_buf_tmp = NULL;

iusace_reset_bit_buffer(ptr_bit_buf_tmp);
if (write_bs) {
ptr_bit_buf_tmp = &pstr_drc_state->str_bit_buf_cfg_tmp;

iusace_reset_bit_buffer(ptr_bit_buf_tmp);
}

bit_cnt_local += iusace_write_bits_buf(
it_bit_buf, pstr_loudness_info_set_extension->loudness_info_set_ext_type[counter], 4);
Expand Down Expand Up @@ -2850,8 +2860,8 @@ IA_ERRORCODE impd_drc_write_loudness_info_set_extension(
}

IA_ERRORCODE impd_drc_write_loudness_info_set(ia_drc_enc_state *pstr_drc_state,
ia_bit_buf_struct *it_bit_buf,
WORD32 *ptr_bit_cnt) {
ia_bit_buf_struct *it_bit_buf, WORD32 *ptr_bit_cnt,
FLAG write_bs) {
IA_ERRORCODE err_code = IA_NO_ERROR;
LOOPIDX idx;
WORD32 version = 0;
Expand Down Expand Up @@ -2888,7 +2898,7 @@ IA_ERRORCODE impd_drc_write_loudness_info_set(ia_drc_enc_state *pstr_drc_state,
if (pstr_loudness_info_set->loudness_info_set_ext_present) {
err_code = impd_drc_write_loudness_info_set_extension(
pstr_drc_state, it_bit_buf, &pstr_loudness_info_set->str_loudness_info_set_extension,
&bit_cnt_local);
&bit_cnt_local, write_bs);
if (err_code) {
return err_code;
}
Expand All @@ -2899,17 +2909,21 @@ IA_ERRORCODE impd_drc_write_loudness_info_set(ia_drc_enc_state *pstr_drc_state,
return err_code;
}

IA_ERRORCODE impd_drc_write_uni_drc_config(ia_drc_enc_state *pstr_drc_state,
WORD32 *ptr_bit_cnt) {
IA_ERRORCODE impd_drc_write_uni_drc_config(ia_drc_enc_state *pstr_drc_state, WORD32 *ptr_bit_cnt,
FLAG write_bs) {
IA_ERRORCODE err_code = IA_NO_ERROR;
LOOPIDX idx;
WORD32 version = 0;
WORD32 bit_cnt_local = 0;
VOID *ptr_scratch = pstr_drc_state->drc_scratch_mem;
ia_bit_buf_struct *it_bit_buf = &pstr_drc_state->str_bit_buf_cfg;
ia_bit_buf_struct *it_bit_buf = NULL;
ia_drc_gain_enc_struct *pstr_gain_enc = &pstr_drc_state->str_gain_enc;
ia_drc_uni_drc_config_struct *pstr_uni_drc_config = &(pstr_gain_enc->str_uni_drc_config);

if (write_bs) {
it_bit_buf = &pstr_drc_state->str_bit_buf_cfg;
}

bit_cnt_local += iusace_write_bits_buf(it_bit_buf, pstr_uni_drc_config->sample_rate_present, 1);

if (1 == pstr_uni_drc_config->sample_rate_present) {
Expand Down Expand Up @@ -2983,21 +2997,10 @@ IA_ERRORCODE impd_drc_write_uni_drc_config(ia_drc_enc_state *pstr_drc_state,
if (pstr_uni_drc_config->uni_drc_config_ext_present) {
err_code = impd_drc_write_uni_drc_config_extn(
pstr_drc_state, pstr_gain_enc, pstr_uni_drc_config,
&(pstr_uni_drc_config->str_uni_drc_config_ext), &bit_cnt_local);
if (err_code & IA_FATAL_ERROR) {
return (err_code);
}
}

// Loudness info set
if (pstr_uni_drc_config->loudness_info_set_present == 1) {
ia_bit_buf_struct *it_bit_buf_lis = &pstr_drc_state->str_bit_buf_cfg_ext;
WORD32 bit_cnt_lis = 0;
err_code = impd_drc_write_loudness_info_set(pstr_drc_state, it_bit_buf_lis, &bit_cnt_lis);
&(pstr_uni_drc_config->str_uni_drc_config_ext), &bit_cnt_local, write_bs);
if (err_code & IA_FATAL_ERROR) {
return (err_code);
}
pstr_drc_state->drc_config_ext_data_size_bit = bit_cnt_lis;
}

*ptr_bit_cnt += bit_cnt_local;
Expand All @@ -3010,7 +3013,7 @@ IA_ERRORCODE impd_drc_write_measured_loudness_info(ia_drc_enc_state *pstr_drc_st
IA_ERRORCODE err_code = IA_NO_ERROR;
ia_bit_buf_struct *it_bit_buf_lis = &pstr_drc_state->str_bit_buf_cfg_ext;
WORD32 bit_cnt_lis = 0;
err_code = impd_drc_write_loudness_info_set(pstr_drc_state, it_bit_buf_lis, &bit_cnt_lis);
err_code = impd_drc_write_loudness_info_set(pstr_drc_state, it_bit_buf_lis, &bit_cnt_lis, 1);
if (err_code & IA_FATAL_ERROR) {
return (err_code);
}
Expand Down
2 changes: 1 addition & 1 deletion encoder/drc_src/impd_drc_uni_drc.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ typedef struct {
WORD32 uni_drc_config_ext_present;
ia_drc_uni_drc_config_ext_struct str_uni_drc_config_ext;
ia_drc_coefficients_basic_struct str_drc_coefficients_basic[MAX_DRC_COEFF_COUNT];
ia_drc_instructions_basic_struct str_drc_instructions_basic[MAX_DRC_INSTRUCTIONS_COUNT];
ia_drc_instructions_basic_struct str_drc_instructions_basic[MAX_DRC_INSTRUCTIONS_BASIC_COUNT];
ia_drc_coefficients_uni_drc_struct str_drc_coefficients_uni_drc[MAX_DRC_COEFF_COUNT];
ia_drc_instructions_uni_drc str_drc_instructions_uni_drc[MAX_DRC_INSTRUCTIONS_COUNT];
ia_drc_channel_layout_struct str_channel_layout;
Expand Down
7 changes: 4 additions & 3 deletions encoder/iusace_enc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,12 +635,13 @@ IA_ERRORCODE iusace_enc_init(ia_usac_encoder_config_struct *ptr_usac_config,

err_code = impd_drc_enc_init(&usac_data->str_drc_state, pstr_state->str_scratch.drc_scratch,
&ptr_usac_config->str_drc_cfg);
if (err_code == IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_GAIN_POINTS) {
ptr_usac_config->use_drc_element = 0;
}
if (err_code & IA_FATAL_ERROR) {
return err_code;
}
if (err_code) {
ptr_usac_config->use_drc_element = 0;
err_code = IA_NO_ERROR;
}

if (ptr_usac_config->use_drc_element) {
ia_usac_enc_element_config_struct *pstr_usac_elem_config =
Expand Down
Loading

0 comments on commit da04d9d

Please sign in to comment.