Skip to content

Commit

Permalink
Merge pull request #86 from ittiam-systems/encoder_enhancements
Browse files Browse the repository at this point in the history
UniDrcv1 configuration support when DRC is enabled
  • Loading branch information
SanaAnjaneyulu authored May 7, 2024
2 parents 12e2e71 + b9598d0 commit ae307e4
Show file tree
Hide file tree
Showing 10 changed files with 675 additions and 140 deletions.
205 changes: 189 additions & 16 deletions encoder/drc_src/impd_drc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ IA_ERRORCODE impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_confi
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->drc_instructions_uni_drc_count, 0,
MAX_DRC_INSTRUCTIONS_COUNT);
for (i = 0; i < pstr_uni_drc_config->drc_instructions_uni_drc_count; i++) {
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_instructions_uni_drc[i].drc_set_id, 0,
MAX_DRC_SET_ID);
IMPD_DRC_BOUND_CHECK(
pstr_uni_drc_config->str_drc_instructions_uni_drc[i].additional_downmix_id_count, 0,
ADDITIONAL_DOWNMIX_ID_COUNT_MAX);
Expand Down Expand Up @@ -128,25 +130,42 @@ IA_ERRORCODE impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_confi
.start_sub_band_index,
0, STFT256_HOP_SIZE - 1);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i]
.str_gain_set_params[j].gain_params[k].width,
.str_gain_set_params[j]
.gain_params[k]
.width,
-MAX_FLT_VAL_DB, MAX_FLT_VAL_DB);
for (WORD32 m = 0; m < pstr_uni_drc_config->str_drc_coefficients_uni_drc[i]
.str_gain_set_params[j].gain_params[k].nb_points; m++) {
.str_gain_set_params[j]
.gain_params[k]
.nb_points;
m++) {
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i]
.str_gain_set_params[j].gain_params[k].gain_points[m].x,
.str_gain_set_params[j]
.gain_params[k]
.gain_points[m]
.x,
-MAX_FLT_VAL_DB, MAX_FLT_VAL_DB);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->str_drc_coefficients_uni_drc[i]
.str_gain_set_params[j].gain_params[k].gain_points[m].y,
.str_gain_set_params[j]
.gain_params[k]
.gain_points[m]
.y,
-MAX_FLT_VAL_DB, MAX_FLT_VAL_DB);
}
}
for (k = 0; k <
pstr_uni_drc_config->str_drc_coefficients_uni_drc[i].str_gain_set_params[j].band_count
- 1; k++) {
curr_start_subband_idx = pstr_uni_drc_config->str_drc_coefficients_uni_drc[i].
str_gain_set_params[j].gain_params[k].start_sub_band_index;
next_start_subband_idx = pstr_uni_drc_config->str_drc_coefficients_uni_drc[i].
str_gain_set_params[j].gain_params[k + 1].start_sub_band_index;
for (k = 0; k < pstr_uni_drc_config->str_drc_coefficients_uni_drc[i]
.str_gain_set_params[j]
.band_count -
1;
k++) {
curr_start_subband_idx = pstr_uni_drc_config->str_drc_coefficients_uni_drc[i]
.str_gain_set_params[j]
.gain_params[k]
.start_sub_band_index;
next_start_subband_idx = pstr_uni_drc_config->str_drc_coefficients_uni_drc[i]
.str_gain_set_params[j]
.gain_params[k + 1]
.start_sub_band_index;
/* It is assumed that the start index of a subband is greater than
the start index of its previous subbands for a multiband */
if (next_start_subband_idx <= curr_start_subband_idx) {
Expand Down Expand Up @@ -225,6 +244,160 @@ IA_ERRORCODE impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_confi
0, MAX_RELIABILITY_TYPE);
}
}

if (pstr_uni_drc_config->uni_drc_config_ext_present) {
ia_drc_uni_drc_config_ext_struct *pstr_uni_drc_config_ext =
&pstr_uni_drc_config->str_uni_drc_config_ext;
if (pstr_uni_drc_config_ext->downmix_instructions_v1_present) {
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->downmix_instructions_v1_count, 0,
DOWNMIX_INSTRUCTIONS_COUNT_MAX);
for (i = 0; i < pstr_uni_drc_config_ext->downmix_instructions_v1_count; i++) {
IMPD_DRC_BOUND_CHECK(
pstr_uni_drc_config_ext->str_downmix_instructions_v1[i].target_layout, 0,
MAX_TARGET_LAYOUT_COUNT);
IMPD_DRC_BOUND_CHECK(
pstr_uni_drc_config_ext->str_downmix_instructions_v1[i].target_ch_count, 0,
MAX_CHANNEL_COUNT);
}
}

if (pstr_uni_drc_config_ext->drc_coeffs_and_instructions_uni_drc_v1_present) {
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->drc_coefficients_uni_drc_v1_count, 0,
DRC_COEFFICIENTS_UNIDRC_V1_COUNT_MAX);
for (i = 0; i < pstr_uni_drc_config_ext->drc_coefficients_uni_drc_v1_count; i++) {
IMPD_DRC_BOUND_CHECK(
pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i].gain_set_count, 0,
GAIN_SET_COUNT_MAX);
for (j = 0;
j < pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i].gain_set_count;
j++) {
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_coding_profile,
0, MAX_GAIN_CODING_PROFILE);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.band_count,
0, MAX_BAND_COUNT);
for (k = 0; k < pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.band_count;
k++) {
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k]
.nb_points,
0, MAX_GAIN_POINTS);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k]
.drc_characteristic,
0, MAX_DRC_CHARACTERISTIC_VALUE);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k]
.crossover_freq_index,
0, MAX_CROSSOVER_FREQ_INDEX);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k]
.start_sub_band_index,
0, STFT256_HOP_SIZE - 1);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k]
.width,
-MAX_FLT_VAL_DB, MAX_FLT_VAL_DB);
for (WORD32 m = 0; m < pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k]
.nb_points;
m++) {
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k]
.gain_points[m]
.x,
-MAX_FLT_VAL_DB, MAX_FLT_VAL_DB);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k]
.gain_points[m]
.y,
-MAX_FLT_VAL_DB, MAX_FLT_VAL_DB);
}
}
for (k = 0; k < pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.band_count -
1;
k++) {
curr_start_subband_idx = pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k]
.start_sub_band_index;
next_start_subband_idx = pstr_uni_drc_config_ext->str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.gain_params[k + 1]
.start_sub_band_index;
/* It is assumed that the start index of a subband is greater than
the start index of its previous subbands for a multiband */
if (next_start_subband_idx <= curr_start_subband_idx) {
return IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_SUBBAND_INDEX;
}
}
}
}

IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->drc_instructions_uni_drc_v1_count, 0,
DRC_INSTRUCTIONS_UNIDRC_V1_COUNT_MAX);
for (i = 0; i < pstr_uni_drc_config_ext->drc_instructions_uni_drc_v1_count; i++) {
IMPD_DRC_BOUND_CHECK(
pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].drc_set_id, 0,
MAX_DRC_SET_ID);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i]
.additional_downmix_id_count,
0, MAX_ADDITIONAL_DOWNMIX_ID);
IMPD_DRC_BOUND_CHECK(
pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].drc_location, 0,
MAX_DRC_LOCATION);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i]
.drc_set_target_loudness_value_upper,
MIN_DRC_TARGET_LOUDNESS, 0);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i]
.drc_set_target_loudness_value_lower,
MIN_DRC_TARGET_LOUDNESS, 0);
for (j = 0; j < MAX_CHANNEL_COUNT; j++) {
IMPD_DRC_BOUND_CHECK(
pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].gain_set_index[j], 0,
GAIN_SET_COUNT_MAX - 1);
}
IMPD_DRC_BOUND_CHECK(
pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].num_drc_channel_groups, 0,
MAX_CHANNEL_GROUP_COUNT);
for (j = 0;
j <
pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].num_drc_channel_groups;
j++) {
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i]
.str_gain_modifiers[j]
.attenuation_scaling[0],
0, MAX_ATTENUATION_SCALING);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i]
.str_gain_modifiers[j]
.amplification_scaling[0],
0, MAX_AMPLIFICATION_SCALING);
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i]
.str_gain_modifiers[j]
.gain_offset[0],
MIN_DRC_GAIN_OFFSET, MAX_DRC_GAIN_OFFSET);
}
IMPD_DRC_BOUND_CHECK(
pstr_uni_drc_config_ext->str_drc_instructions_uni_drc_v1[i].limiter_peak_target,
MIN_LIMITER_PEAK_TARGET, 0.0f);
}
}
}
return IA_NO_ERROR;
}

Expand Down Expand Up @@ -304,8 +477,9 @@ IA_ERRORCODE impd_drc_enc_init(VOID *pstr_drc_state, VOID *ptr_drc_scratch,
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){
if (pstr_drc_state_local->str_gain_enc.str_uni_drc_config.loudness_info_set_present == 1) {
bit_count = 0;
iusace_reset_bit_buffer(&pstr_drc_state_local->str_bit_buf_cfg_ext);
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) {
Expand All @@ -322,12 +496,11 @@ IA_ERRORCODE impd_loudness_info_init(VOID *pstr_drc_state, ia_drc_input_config *
ia_drc_enc_state *pstr_drc_state_local = pstr_drc_state;

iusace_create_bit_buffer(&pstr_drc_state_local->str_bit_buf_cfg_ext,
pstr_drc_state_local->bit_buf_base_cfg_ext,
sizeof(pstr_drc_state_local->bit_buf_base_cfg_ext), 1);
pstr_drc_state_local->bit_buf_base_cfg_ext,
sizeof(pstr_drc_state_local->bit_buf_base_cfg_ext), 1);

memcpy(&pstr_drc_state_local->str_gain_enc.str_loudness_info_set,
&pstr_inp_config->str_enc_loudness_info_set,
sizeof(ia_drc_loudness_info_set_struct));
&pstr_inp_config->str_enc_loudness_info_set, sizeof(ia_drc_loudness_info_set_struct));

err_code = impd_drc_write_measured_loudness_info(pstr_drc_state_local);
return err_code;
Expand Down
12 changes: 10 additions & 2 deletions encoder/drc_src/impd_drc_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,16 @@ IA_ERRORCODE impd_drc_gain_enc_init(ia_drc_gain_enc_struct *pstr_gain_enc,
all_band_gain_count += pstr_drc_coefficients_uni_drc->str_gain_set_params[i].band_count;
}
pstr_gain_enc->n_sequences = all_band_gain_count;
} else {
pstr_gain_enc->n_sequences = pstr_drc_coefficients_uni_drc_v1->gain_sequence_count;
}
else {
for (i = 0; i < pstr_uni_drc_config_ext->drc_coefficients_uni_drc_v1_count; i++) {
WORD32 all_band_gain_count = 0;
for (j = 0; j < pstr_drc_coefficients_uni_drc_v1[i].gain_set_count; j++) {
all_band_gain_count += pstr_drc_coefficients_uni_drc_v1[i].str_gain_set_params[j].band_count;
}
pstr_drc_coefficients_uni_drc_v1[i].gain_sequence_count = all_band_gain_count;
pstr_gain_enc->n_sequences += all_band_gain_count;
}
}

if (pstr_gain_enc->n_sequences > IMPD_DRCMAX_NSEQ) {
Expand Down
7 changes: 4 additions & 3 deletions encoder/drc_src/impd_drc_mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ static VOID impd_drc_write_gain_params(ia_bit_buf_struct *it_bit_buf, const WORD
}
} else {
WORD32 index_present;
WORD32 gain_sequence_index_last = -100;
WORD32 gain_sequence_index_last = -1;
for (idx = 0; idx < band_count; idx++) {
if (pstr_gain_params[idx].gain_sequence_index == gain_sequence_index_last + 1) {
index_present = 0;
Expand Down Expand Up @@ -2747,10 +2747,11 @@ static IA_ERRORCODE impd_drc_write_uni_drc_config_extn(
}
break;
}
bit_cnt_local += iusace_write_bits_buf(
it_bit_buf, pstr_uni_drc_config_ext->uni_drc_config_ext_type[counter], 4);

counter++;

bit_cnt_local += iusace_write_bits_buf(
it_bit_buf, pstr_uni_drc_config_ext->uni_drc_config_ext_type[counter], 4);
}

*ptr_bit_cnt += bit_cnt_local;
Expand Down
2 changes: 2 additions & 0 deletions encoder/drc_src/impd_drc_uni_drc.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#define SPLIT_CHARACTERISTIC_COUNT_MAX 8 /* reduced size */
#define SHAPE_FILTER_COUNT_MAX 8 /* reduced size */
#define ADDITIONAL_DOWNMIX_ID_COUNT_MAX MAX_ADDITIONAL_DOWNMIX_ID
#define MAX_TARGET_LAYOUT_COUNT 127
#define ADDITIONAL_DRC_SET_ID_COUNT_MAX 16
#define ADDITIONAL_EQ_SET_ID_COUNT_MAX 8
#define LOUD_EQ_GAIN_MAX_SEQUENCE_COUNT 4
Expand Down Expand Up @@ -110,6 +111,7 @@
#define COMPLEXITY_W_PARAM_LIM_FILT 4.5f
#define COMPLEXITY_W_PARAM_DRC_ATTACK 136.0f

#define MAX_DRC_SET_ID (63)
#define MAX_DRC_LOCATION (4)
#define MIN_DRC_TARGET_LOUDNESS (-63)
#define MAX_ATTENUATION_SCALING (1.875f)
Expand Down
17 changes: 15 additions & 2 deletions encoder/ixheaace_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ static IA_ERRORCODE ixheaace_set_config_params(ixheaace_api_struct *pstr_api_str
pstr_drc_cfg->str_uni_drc_config.str_channel_layout.base_ch_count =
pstr_input_config->i_channels;
pstr_drc_cfg->str_enc_params.sample_rate = pstr_input_config->i_samp_freq;
pstr_drc_cfg->str_enc_params.domain = TIME_DOMAIN;
pstr_drc_cfg->str_uni_drc_config.sample_rate = pstr_drc_cfg->str_enc_params.sample_rate;
for (WORD32 i = 0; i < pstr_drc_cfg->str_uni_drc_config.drc_coefficients_uni_drc_count;
i++) {
Expand All @@ -1019,6 +1020,18 @@ static IA_ERRORCODE ixheaace_set_config_params(ixheaace_api_struct *pstr_api_str
impd_drc_get_delta_t_min(pstr_drc_cfg->str_uni_drc_config.sample_rate);
}
}
for (WORD32 i = 0; i < pstr_drc_cfg->str_uni_drc_config.str_uni_drc_config_ext
.drc_coefficients_uni_drc_v1_count; i++) {
for (WORD32 j = 0;
j < pstr_drc_cfg->str_uni_drc_config.str_uni_drc_config_ext
.str_drc_coefficients_uni_drc_v1[i].gain_set_count; j++) {
pstr_drc_cfg->str_uni_drc_config.str_uni_drc_config_ext
.str_drc_coefficients_uni_drc_v1[i]
.str_gain_set_params[j]
.delta_tmin =
impd_drc_get_delta_t_min(pstr_drc_cfg->str_uni_drc_config.sample_rate);
}
}

pstr_usac_config->str_drc_cfg = *pstr_drc_cfg;
pstr_usac_config->str_drc_cfg.str_enc_params.frame_size = pstr_usac_config->drc_frame_size;
Expand Down Expand Up @@ -1472,7 +1485,6 @@ static VOID ixheaace_fill_mem_tabs(ixheaace_api_struct *pstr_api_struct, WORD32
}

static WORD32 get_drc_config_size(ixheaace_api_struct *pstr_api_struct,
ixheaace_output_config *ptr_out_cfg,
ixheaace_input_config *ptr_in_cfg) {
WORD32 bit_count = 0;
WORD32 total_byte_cnt = 0;
Expand All @@ -1490,6 +1502,7 @@ static WORD32 get_drc_config_size(ixheaace_api_struct *pstr_api_struct,
pstr_drc_state->str_gain_enc.str_uni_drc_config = pstr_in_drc_cfg->str_uni_drc_config;
pstr_drc_state->drc_scratch_mem =
pstr_api_struct->pstr_state->str_usac_enc_data.str_scratch.ptr_scratch_buf;
pstr_drc_state->str_gain_enc.base_ch_count = ptr_in_cfg->i_channels;

//uniDrc payload size
impd_drc_write_uni_drc_config(pstr_drc_state, &bit_count, 0);
Expand All @@ -1513,7 +1526,7 @@ static IA_ERRORCODE ixheaace_alloc_and_assign_mem(ixheaace_api_struct *pstr_api_
if (i_idx == IA_ENHAACPLUSENC_OUTPUT_IDX &&
pstr_api_struct->config[0].usac_config.use_drc_element) {
WORD32 drc_config_size_expected =
get_drc_config_size(pstr_api_struct, ptr_out_cfg, ptr_in_cfg);
get_drc_config_size(pstr_api_struct, ptr_in_cfg);
if (drc_config_size_expected > MAX_DRC_CONFIG_SIZE_EXPECTED) {
return IA_EXHEAACE_CONFIG_FATAL_DRC_INVALID_CONFIG;
}
Expand Down
Loading

0 comments on commit ae307e4

Please sign in to comment.