aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-18 02:08:00 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-11-18 02:08:00 +0000
commite6fc6686b645f9fccaefb3cee563571344ec7b2e (patch)
tree73c3905e1fb2cc11b30be7d583bb500e2cef452d
parent68809fee6a051e4729360a217320da6fec700578 (diff)
parent49819412af46be1657ff041ca632d281acf9efac (diff)
downloadlibxaac-android14-qpr2-s1-release.tar.gz
Change-Id: Ie58f8858306c59dae920e0c0b10f11021553a504
-rw-r--r--.github/workflows/cifuzz.yml27
-rw-r--r--.github/workflows/cmake.yml23
-rw-r--r--Android.bp15
-rw-r--r--METADATA10
-rw-r--r--decoder/drc_src/impd_drc_selection_process_drcset_selection.c2
-rw-r--r--decoder/drc_src/impd_drc_static_payload.c3
-rw-r--r--decoder/generic/ixheaacd_function_selector_generic.c4
-rw-r--r--decoder/generic/ixheaacd_qmf_dec_generic.c2
-rw-r--r--decoder/ixheaacd_api.c9
-rw-r--r--decoder/ixheaacd_basic_funcs.c6
-rw-r--r--decoder/ixheaacd_bitbuffer.c14
-rw-r--r--decoder/ixheaacd_config.h4
-rw-r--r--decoder/ixheaacd_create.c4
-rw-r--r--decoder/ixheaacd_env_calc.c11
-rw-r--r--decoder/ixheaacd_env_extr.c7
-rw-r--r--decoder/ixheaacd_esbr_envcal.c81
-rw-r--r--decoder/ixheaacd_huff_code_reorder.c6
-rw-r--r--decoder/ixheaacd_imdct.c18
-rw-r--r--decoder/ixheaacd_ld_mps_config.c14
-rw-r--r--decoder/ixheaacd_lpc_dec.c2
-rw-r--r--decoder/ixheaacd_mps_bitdec.c321
-rw-r--r--decoder/ixheaacd_mps_decorr.c6
-rw-r--r--decoder/ixheaacd_mps_parse.c12
-rw-r--r--decoder/ixheaacd_mps_res_block.c6
-rw-r--r--decoder/ixheaacd_mps_res_pns_js_thumb.c2
-rw-r--r--decoder/ixheaacd_pns_js_thumb.c3
-rw-r--r--decoder/ixheaacd_sbr_dec.c11
-rw-r--r--decoder/ixheaacd_sbrdec_lpfuncs.c22
-rw-r--r--decoder/ixheaacd_sbrdecoder.c4
-rw-r--r--decoder/ixheaacd_stereo.c6
-rw-r--r--decoder/ixheaacd_tcx_fwd_mdct.c2
-rw-r--r--encoder/drc_src/impd_drc_api.c42
-rw-r--r--encoder/drc_src/impd_drc_enc.c4
-rw-r--r--encoder/drc_src/impd_drc_gain_calculator.c165
-rw-r--r--encoder/drc_src/impd_drc_gain_enc.c6
-rw-r--r--encoder/iusace_enc_main.c46
-rw-r--r--encoder/iusace_fd_enc.h3
-rw-r--r--encoder/iusace_fd_fac.c18
-rw-r--r--encoder/iusace_fd_qc_adjthr.h5
-rw-r--r--encoder/iusace_fft.c6
-rw-r--r--encoder/iusace_lpd_enc.c3
-rw-r--r--encoder/iusace_main.h3
-rw-r--r--encoder/iusace_psy_utils.c8
-rw-r--r--encoder/iusace_tcx_enc.c14
-rw-r--r--encoder/iusace_tns_usac.c7
-rw-r--r--encoder/iusace_windowing.c11
-rw-r--r--encoder/ixheaace_aac_constants.h3
-rw-r--r--encoder/ixheaace_adjust_threshold.c36
-rw-r--r--encoder/ixheaace_api.c279
-rw-r--r--encoder/ixheaace_api_defs.h3
-rw-r--r--encoder/ixheaace_asc_write.c4
-rw-r--r--encoder/ixheaace_basic_ops.c30
-rw-r--r--encoder/ixheaace_bits_count.c12
-rw-r--r--encoder/ixheaace_bits_count.h6
-rw-r--r--encoder/ixheaace_common_utils.h3
-rw-r--r--encoder/ixheaace_cplx_pred.c7
-rw-r--r--encoder/ixheaace_enc_init.c13
-rw-r--r--encoder/ixheaace_enc_main.c6
-rw-r--r--encoder/ixheaace_enc_main.h3
-rw-r--r--encoder/ixheaace_error_codes.h20
-rw-r--r--encoder/ixheaace_fd_enc.c6
-rw-r--r--encoder/ixheaace_fd_mdct.c3
-rw-r--r--encoder/ixheaace_fd_qc_adjthr.c39
-rw-r--r--encoder/ixheaace_fd_quant.c29
-rw-r--r--encoder/ixheaace_hybrid_init.c4
-rw-r--r--encoder/ixheaace_mps_nlc_enc.c8
-rw-r--r--encoder/ixheaace_mps_sac_nlc_enc.h2
-rw-r--r--encoder/ixheaace_nf.c19
-rw-r--r--encoder/ixheaace_ps_enc_init.c27
-rw-r--r--encoder/ixheaace_qc_data.h4
-rw-r--r--encoder/ixheaace_qc_main_hp.c39
-rw-r--r--encoder/ixheaace_qc_util.c18
-rw-r--r--encoder/ixheaace_qc_util.h13
-rw-r--r--encoder/ixheaace_sbr_code_envelope.c3
-rw-r--r--encoder/ixheaace_sbr_code_envelope_lp.c3
-rw-r--r--encoder/ixheaace_sbr_env_est.c27
-rw-r--r--encoder/ixheaace_sbr_env_est_init.c2
-rw-r--r--encoder/ixheaace_sbr_freq_scaling.c24
-rw-r--r--encoder/ixheaace_sbr_freq_scaling.h2
-rw-r--r--encoder/ixheaace_sbr_main.c2
-rw-r--r--encoder/ixheaace_sbr_missing_harmonics_det.c9
-rw-r--r--encoder/ixheaace_sbr_noise_floor_est.c2
-rw-r--r--encoder/ixheaace_sbr_ps_enc.h2
-rw-r--r--encoder/ixheaace_sbr_qmf_enc.c14
-rw-r--r--encoder/ixheaace_sbr_qmf_enc.h4
-rw-r--r--encoder/ixheaace_sbr_qmf_enc_init.c1
-rw-r--r--encoder/ixheaace_sbr_ton_corr.c2
-rw-r--r--encoder/ixheaace_sbr_ton_corr_hp.c11
-rw-r--r--encoder/ixheaace_sbr_tran_det.c12
-rw-r--r--encoder/ixheaace_sbr_write_bitstream.c2
-rw-r--r--encoder/ixheaace_sf_estimation.c5
-rw-r--r--encoder/ixheaace_stereo_preproc.c6
-rw-r--r--encoder/ixheaace_stereo_preproc.h2
-rw-r--r--encoder/ixheaace_struct_def.h2
-rw-r--r--encoder/ixheaace_tns.c8
-rw-r--r--encoder/ixheaace_tns_func.h2
-rw-r--r--encoder/ixheaace_tns_hp.c6
-rw-r--r--encoder/ixheaace_tns_params.c4
-rw-r--r--encoder/ixheaace_write_adts_adif.c6
-rw-r--r--encoder/ixheaace_write_bitstream.c12
-rwxr-xr-xfuzzer/ossfuzz.sh12
-rw-r--r--fuzzer/xaac_dec_fuzzer.cpp6
-rw-r--r--fuzzer/xaac_enc_fuzzer.cpp17
-rw-r--r--test/Android.bp1
-rw-r--r--test/encoder/ixheaace_error.c36
-rw-r--r--test/encoder/ixheaace_wav_reader.c57
-rw-r--r--test/encoder/ixheaace_wave_read.h30
-rw-r--r--test/encoder/xaacenc.cmake3
108 files changed, 1280 insertions, 691 deletions
diff --git a/.github/workflows/cifuzz.yml b/.github/workflows/cifuzz.yml
new file mode 100644
index 0000000..31e5b59
--- /dev/null
+++ b/.github/workflows/cifuzz.yml
@@ -0,0 +1,27 @@
+name: CIFuzz
+on: [pull_request]
+jobs:
+ Fuzzing:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ sanitizer: [address, memory]
+ steps:
+ - name: Build Fuzzers
+ id: build
+ uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
+ with:
+ oss-fuzz-project-name: 'libxaac'
+ language: c++
+ - name: Run Fuzzers
+ uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
+ with:
+ oss-fuzz-project-name: 'libxaac'
+ language: c++
+ fuzz-seconds: 600
+ - name: Upload Crash
+ uses: actions/upload-artifact@v3
+ if: failure() && steps.build.outcome == 'success'
+ with:
+ name: artifacts
+ path: ./out/artifacts
diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml
new file mode 100644
index 0000000..0ec6d70
--- /dev/null
+++ b/.github/workflows/cmake.yml
@@ -0,0 +1,23 @@
+name: CMake
+
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+
+env:
+ BUILD_TYPE: Release
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v3
+
+ - name: Configure CMake
+ run: cmake -B ${{github.workspace}}/out -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
+
+ - name: Build
+ run: cmake --build ${{github.workspace}}/out --config ${{env.BUILD_TYPE}}
diff --git a/Android.bp b/Android.bp
index 0969ce6..6d5344b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -338,6 +338,19 @@ cc_library_static {
"decoder/x86_64/ixheaacd_function_selector_x86_64.c",
],
},
+
+ riscv64: {
+ cflags: [
+ ],
+
+ local_include_dirs: [
+ ],
+
+ srcs: [
+ "decoder/generic/ixheaacd_qmf_dec_generic.c",
+ "decoder/generic/ixheaacd_function_selector_generic.c",
+ ],
+ },
},
}
@@ -511,4 +524,4 @@ cc_library_static {
},
}
-subdirs = ["test"] \ No newline at end of file
+subdirs = ["test"]
diff --git a/METADATA b/METADATA
index a5ace9a..b99da5f 100644
--- a/METADATA
+++ b/METADATA
@@ -1,3 +1,7 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update libxaac
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
+
name: "libxaac"
description: "Android fork of the xaac library."
third_party {
@@ -5,11 +9,11 @@ third_party {
type: GIT
value: "https://github.com/ittiam-systems/libxaac.git"
}
- version: "v0.1.7"
+ version: "v0.1.9"
license_type: NOTICE
last_upgrade_date {
year: 2023
- month: 8
- day: 10
+ month: 10
+ day: 26
}
}
diff --git a/decoder/drc_src/impd_drc_selection_process_drcset_selection.c b/decoder/drc_src/impd_drc_selection_process_drcset_selection.c
index 676878b..153e2f5 100644
--- a/decoder/drc_src/impd_drc_selection_process_drcset_selection.c
+++ b/decoder/drc_src/impd_drc_selection_process_drcset_selection.c
@@ -723,7 +723,7 @@ WORD32 impd_drc_set_preselection(
WORD32 peak_info_count;
WORD32 eq_set_id_Peak[16];
FLOAT32 signal_peak_level[16];
- WORD32 explicit_peak_information_present[16];
+ WORD32 explicit_peak_information_present[16] = { 0 };
ia_uni_drc_coeffs_struct* str_p_loc_drc_coefficients_uni_drc = NULL;
ia_drc_instructions_struct* str_drc_instruction_str = NULL;
diff --git a/decoder/drc_src/impd_drc_static_payload.c b/decoder/drc_src/impd_drc_static_payload.c
index 3c08adb..54e5162 100644
--- a/decoder/drc_src/impd_drc_static_payload.c
+++ b/decoder/drc_src/impd_drc_static_payload.c
@@ -731,7 +731,8 @@ WORD32 impd_parse_ch_layout(ia_bit_buf_struct* it_bit_buff,
channel_layout->base_channel_count = impd_read_bits_buf(it_bit_buff, 7);
if (it_bit_buff->error) return it_bit_buff->error;
- if (channel_layout->base_channel_count > MAX_CHANNEL_COUNT)
+ if ((channel_layout->base_channel_count > MAX_CHANNEL_COUNT) ||
+ (channel_layout->base_channel_count == 0))
return (UNEXPECTED_ERROR);
if (ia_drc_params_struct->lfe_channel_map_count != -1 &&
channel_layout->base_channel_count !=
diff --git a/decoder/generic/ixheaacd_function_selector_generic.c b/decoder/generic/ixheaacd_function_selector_generic.c
index 36eedb0..16e4f09 100644
--- a/decoder/generic/ixheaacd_function_selector_generic.c
+++ b/decoder/generic/ixheaacd_function_selector_generic.c
@@ -77,6 +77,10 @@ VOID(*ixheaacd_covariance_matrix_calc_960)
(WORD32 *, ia_lpp_trans_cov_matrix *,
WORD32, WORD32) = &ixheaacd_covariance_matrix_calc_dec_960;
+VOID(*ixheaacd_aac_ld_dec_rearrange_960)
+(WORD32 *ip, WORD32 *op, WORD32 mdct_len_2,
+ WORD16 *re_arr_tab) = &ixheaacd_dec_rearrange_short;
+
VOID(*ixheaacd_covariance_matrix_calc_2)
(ia_lpp_trans_cov_matrix *, WORD32 *, WORD32,
WORD16) = &ixheaacd_covariance_matrix_calc_2_dec;
diff --git a/decoder/generic/ixheaacd_qmf_dec_generic.c b/decoder/generic/ixheaacd_qmf_dec_generic.c
index ff1e958..e3e8e4a 100644
--- a/decoder/generic/ixheaacd_qmf_dec_generic.c
+++ b/decoder/generic/ixheaacd_qmf_dec_generic.c
@@ -597,7 +597,7 @@ VOID ixheaacd_cplx_anal_qmffilt(const WORD16 *time_sample_buf,
WORD32 i, k;
WORD32 num_time_slots = qmf_bank->num_time_slots;
- WORD32 analysis_buffer[4 * NO_ANALYSIS_CHANNELS];
+ WORD32 analysis_buffer[4 * NO_ANALYSIS_CHANNELS] = { 0 };
WORD16 *filter_states = qmf_bank->core_samples_buffer;
WORD16 *fp1, *fp2, *tmp;
diff --git a/decoder/ixheaacd_api.c b/decoder/ixheaacd_api.c
index 1f0b7cd..9f60ef7 100644
--- a/decoder/ixheaacd_api.c
+++ b/decoder/ixheaacd_api.c
@@ -3042,9 +3042,14 @@ IA_ERRORCODE ixheaacd_dec_execute(
p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_ELD &&
p_state_enhaacplus_dec->audio_object_type != AOT_ER_AAC_LC)) {
jmp_buf local;
- ret_val = setjmp(local);
+
+ if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal == 1) {
+ ret_val = setjmp(local);
+ }
if (ret_val == 0) {
- p_obj_exhaacplus_dec->p_state_aac->ptr_bit_stream->xaac_jmp_buf = &local;
+ if (p_obj_exhaacplus_dec->aac_config.ui_err_conceal == 1) {
+ p_obj_exhaacplus_dec->p_state_aac->ptr_bit_stream->xaac_jmp_buf = &local;
+ }
error_code = ixheaacd_get_element_index_tag(
p_obj_exhaacplus_dec, ch_idx1, &ch_idx, &channel,
p_obj_exhaacplus_dec->aac_config.element_instance_order, total_elements, element_used,
diff --git a/decoder/ixheaacd_basic_funcs.c b/decoder/ixheaacd_basic_funcs.c
index a0f0c77..0326875 100644
--- a/decoder/ixheaacd_basic_funcs.c
+++ b/decoder/ixheaacd_basic_funcs.c
@@ -39,9 +39,15 @@ VOID ixheaacd_fix_mant_exp_add(WORD16 op1_mant, WORD16 op1_exp, WORD16 op2_mant,
WORD32 new_exp;
new_exp = op1_exp - op2_exp;
if (new_exp < 0) {
+ if (new_exp < -31) {
+ new_exp = -31;
+ }
op1_mant = op1_mant >> (-new_exp);
new_exp = op2_exp;
} else {
+ if (new_exp > 31) {
+ new_exp = 31;
+ }
op2_mant = op2_mant >> new_exp;
new_exp = op1_exp;
}
diff --git a/decoder/ixheaacd_bitbuffer.c b/decoder/ixheaacd_bitbuffer.c
index 762b102..033e817 100644
--- a/decoder/ixheaacd_bitbuffer.c
+++ b/decoder/ixheaacd_bitbuffer.c
@@ -178,6 +178,13 @@ VOID ixheaacd_aac_read_byte_corr1(UWORD8 **ptr_read_next, WORD32 *ptr_bit_pos,
v++;
}
}
+
+ if (bits_consumed > (31 - temp_bit_count)) {
+ if ((p_bit_buf_end != NULL) && (p_bit_buf_end < v)) {
+ bits_consumed = 31 - temp_bit_count;
+ }
+ }
+
*ptr_bit_pos = bits_consumed + temp_bit_count;
*ptr_read_next = v;
return;
@@ -198,6 +205,13 @@ VOID ixheaacd_aac_read_byte_corr(UWORD8 **ptr_read_next, WORD32 *ptr_bit_pos,
} else {
bits_consumed += 8;
}
+
+ if (bits_consumed > 31) {
+ if (p_bit_buf_end < v) {
+ bits_consumed = 31;
+ }
+ }
+
*ptr_bit_pos = bits_consumed;
*ptr_read_next = v;
return;
diff --git a/decoder/ixheaacd_config.h b/decoder/ixheaacd_config.h
index 59bacf0..aa3a871 100644
--- a/decoder/ixheaacd_config.h
+++ b/decoder/ixheaacd_config.h
@@ -68,6 +68,8 @@
(MAX_OUTPUT_CHANNELS * (1 << MAX_ARBITRARY_TREE_LEVELS))
#define MAX_ARBITRARY_TREE_INDEX ((1 << (MAX_ARBITRARY_TREE_LEVELS + 1)) - 1)
+#define MAX_RES_SAMP_FREQ_IDX 11
+
typedef UWORD8 UINT8;
typedef UWORD32 UINT32;
@@ -144,7 +146,7 @@ typedef struct {
UINT32 bs_arbitrary_downmix_residual_sampling_freq_index;
UINT32 bs_arbitrary_downmix_residual_frames_per_spatial_frame;
- UINT32 bs_arbitrary_downmix_residual_bands;
+ WORD32 bs_arbitrary_downmix_residual_bands;
UINT32 num_out_chan_AT;
UINT32 num_ott_boxes_AT;
diff --git a/decoder/ixheaacd_create.c b/decoder/ixheaacd_create.c
index 918d84f..4866fe1 100644
--- a/decoder/ixheaacd_create.c
+++ b/decoder/ixheaacd_create.c
@@ -394,7 +394,9 @@ WORD32 ixheaacd_dec_data_init(VOID *handle,
&usac_data->ccfl, &usac_data->output_samples,
&pstr_frame_data->str_layer.sample_rate_layer,
&layer_config->samp_frequency_index);
-
+ if (!pstr_frame_data->str_layer.sample_rate_layer) {
+ return -1;
+ }
pstr_stream_config->sampling_frequency =
pstr_frame_data->str_layer.sample_rate_layer;
pstr_stream_config->samp_frequency_index = layer_config->samp_frequency_index;
diff --git a/decoder/ixheaacd_env_calc.c b/decoder/ixheaacd_env_calc.c
index 6c02362..9d52e25 100644
--- a/decoder/ixheaacd_env_calc.c
+++ b/decoder/ixheaacd_env_calc.c
@@ -462,10 +462,17 @@ VOID ixheaacd_conv_ergtoamplitude_dec(WORD32 bands, WORD16 noise_e,
shift = (noise_e - noise_level_mant[2 * k + 1]);
shift = (shift - 4);
- if (shift > 0)
+ if (shift > 0) {
+ if (shift > 31) {
+ shift = 31;
+ }
noise_level_mant[2 * k] = (noise_level_mant[2 * k] >> shift);
- else
+ } else {
+ if (shift < -31) {
+ shift = -31;
+ }
noise_level_mant[2 * k] = (noise_level_mant[2 * k] << -shift);
+ }
}
}
diff --git a/decoder/ixheaacd_env_extr.c b/decoder/ixheaacd_env_extr.c
index f809b0d..5d64a19 100644
--- a/decoder/ixheaacd_env_extr.c
+++ b/decoder/ixheaacd_env_extr.c
@@ -1666,6 +1666,9 @@ WORD32 ixheaacd_pvc_time_freq_grid_info(
} else {
tmp = ixheaacd_read_bits_buf(it_bit_buff, 2);
ptr_frame_data->var_len = tmp + 1;
+ if (ptr_frame_data->var_len > 3) {
+ return -1;
+ }
}
var_len = ptr_frame_data->var_len;
@@ -1678,6 +1681,10 @@ WORD32 ixheaacd_pvc_time_freq_grid_info(
pvc_time_border[0] = 0;
bs_freq_res[0] = 0;
+ if (ptr_frame_data->prev_sbr_mode == 0) {
+ pvc_time_border[0] = time_border[0];
+ }
+
if (bs_noise_pos == 0) {
time_border[1] = 16 + var_len;
pvc_time_border[1] = 16;
diff --git a/decoder/ixheaacd_esbr_envcal.c b/decoder/ixheaacd_esbr_envcal.c
index ee9efc6..4c401e4 100644
--- a/decoder/ixheaacd_esbr_envcal.c
+++ b/decoder/ixheaacd_esbr_envcal.c
@@ -150,6 +150,7 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
WORD32 band_loop_end;
WORD32 rate = upsamp_4_flag ? 4 : 2;
+ FLOAT64 guard = 1e-17;
if (ldmps_present == 1) rate = 1;
@@ -328,11 +329,13 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
c++;
}
- if (!int_mode) {
+ if (!int_mode && ui != li) {
for (nrg = 0, k = c - (ui - li); k < c; k++) {
nrg += nrg_est_pvc[k][t];
}
nrg /= (ui - li);
+ } else {
+ nrg = 0;
}
c -= (ui - li);
@@ -349,7 +352,7 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
nrg_tone_pvc[c][t] = 0.0f;
tmp = frame_data->qmapped_pvc[c][t] /
- (1 + frame_data->qmapped_pvc[c][t]);
+ (1 + frame_data->qmapped_pvc[c][t] + guard);
if (flag) {
nrg_gain_pvc[c][t] = (FLOAT32)sqrt(nrg_ref_pvc[c][t] * tmp /
@@ -359,15 +362,16 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
(harmonics[c] && (t >= frame_data->sine_position ||
(*harm_flag_prev)[c + sub_band_start]))
? sqrt(nrg_ref_pvc[c][t] * tmp /
- frame_data->qmapped_pvc[c][t])
+ (frame_data->qmapped_pvc[c][t] + guard))
: nrg_tone_pvc[c][t]);
- nrg_tone_pvc[c][t] = (FLOAT32)(
- ((*harm_flag_varlen)[c] &&
- (t >= frame_data->sin_start_for_cur_top ||
- (*harm_flag_varlen_prev)[c + sub_band_start]))
- ? sqrt(nrg_ref_pvc[c][t] * tmp / prev_env_noise_level[o])
- : nrg_tone_pvc[c][t]);
+ nrg_tone_pvc[c][t] =
+ (FLOAT32)(((*harm_flag_varlen)[c] &&
+ (t >= frame_data->sin_start_for_cur_top ||
+ (*harm_flag_varlen_prev)[c + sub_band_start]))
+ ? sqrt(nrg_ref_pvc[c][t] * tmp /
+ (prev_env_noise_level[o] + guard))
+ : nrg_tone_pvc[c][t]);
} else {
if (noise_absc_flag) {
@@ -376,7 +380,7 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
} else {
nrg_gain_pvc[c][t] = (FLOAT32)sqrt(
nrg_ref_pvc[c][t] * tmp /
- ((nrg_est_pvc[c][t] + 1) * frame_data->qmapped_pvc[c][t]));
+ ((nrg_est_pvc[c][t] + 1) * (frame_data->qmapped_pvc[c][t] + guard)));
}
}
@@ -400,7 +404,7 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
k < (*lim_table)[limiter_band][c + 1]; k++) {
if (g_max <= nrg_gain_pvc[k][t]) {
noise_level_pvc[k][t] =
- noise_level_pvc[k][t] * (g_max / nrg_gain_pvc[k][t]);
+ (FLOAT32)(noise_level_pvc[k][t] * (g_max / (nrg_gain_pvc[k][t] + guard)));
nrg_gain_pvc[k][t] = g_max;
}
@@ -452,11 +456,13 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
c++;
}
- if (!int_mode) {
+ if (!int_mode && ui != li) {
for (nrg = 0, k = c - (ui - li); k < c; k++) {
nrg += nrg_est_pvc[k][t];
}
nrg /= (ui - li);
+ } else {
+ nrg = 0;
}
c -= (ui - li);
@@ -473,7 +479,7 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
nrg_tone_pvc[c][t] = 0.0f;
tmp = frame_data->qmapped_pvc[c][t] /
- (1 + frame_data->qmapped_pvc[c][t]);
+ (1 + frame_data->qmapped_pvc[c][t] + guard);
if (flag) {
nrg_gain_pvc[c][t] = (FLOAT32)sqrt(nrg_ref_pvc[c][t] * tmp /
@@ -483,7 +489,7 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
(harmonics[c] && (t >= frame_data->sine_position ||
(*harm_flag_prev)[c + sub_band_start]))
? sqrt(nrg_ref_pvc[c][t] * tmp /
- frame_data->qmapped_pvc[c][t])
+ (frame_data->qmapped_pvc[c][t] + guard))
: nrg_tone_pvc[c][t]);
} else {
if (noise_absc_flag) {
@@ -492,7 +498,7 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
} else {
nrg_gain_pvc[c][t] = (FLOAT32)sqrt(
nrg_ref_pvc[c][t] * tmp /
- ((nrg_est_pvc[c][t] + 1) * frame_data->qmapped_pvc[c][t]));
+ ((nrg_est_pvc[c][t] + 1) * (frame_data->qmapped_pvc[c][t] + guard)));
}
}
@@ -517,7 +523,8 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
k < (*lim_table)[limiter_band][c + 1]; k++) {
if (g_max <= nrg_gain_pvc[k][t]) {
noise_level_pvc[k][t] =
- noise_level_pvc[k][t] * (g_max / nrg_gain_pvc[k][t]);
+ (FLOAT32)(noise_level_pvc[k][t] *
+ (g_max / (nrg_gain_pvc[k][t] + guard)));
nrg_gain_pvc[k][t] = g_max;
}
@@ -644,29 +651,41 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
ui = freq_band_table[p_frame_info->freq_res[i]][j + 1];
ui2 = frame_data->pstr_sbr_header->pstr_freq_band_data
->freq_band_tbl_noise[o + 1];
- for (flag = 0, k = li; k < ui; k++) {
- for (nrg = 0, l = rate * p_frame_info->border_vec[i];
- l < rate * p_frame_info->border_vec[i + 1]; l++) {
- nrg += (input_real[l][k] * input_real[l][k]) +
- (input_imag[l][k] * input_imag[l][k]);
+
+ if (p_frame_info->border_vec[i] >= p_frame_info->border_vec[i + 1]) {
+ for (flag = 0, k = li; k < ui; k++) {
+ flag = (harmonics[c] &&
+ (i >= trans_env || (*harm_flag_prev)[c + sub_band_start]))
+ ? 1
+ : flag;
+ nrg_est[c++] = 0;
+ }
+ } else {
+ for (flag = 0, k = li; k < ui; k++) {
+ for (nrg = 0, l = rate * p_frame_info->border_vec[i];
+ l < rate * p_frame_info->border_vec[i + 1]; l++) {
+ nrg += (input_real[l][k] * input_real[l][k]) +
+ (input_imag[l][k] * input_imag[l][k]);
+ }
+ flag = (harmonics[c] &&
+ (i >= trans_env || (*harm_flag_prev)[c + sub_band_start]))
+ ? 1
+ : flag;
+ nrg_est[c++] = nrg / (rate * p_frame_info->border_vec[i + 1] -
+ rate * p_frame_info->border_vec[i]);
}
- flag = (harmonics[c] &&
- (i >= trans_env || (*harm_flag_prev)[c + sub_band_start]))
- ? 1
- : flag;
- nrg_est[c++] = nrg / (rate * p_frame_info->border_vec[i + 1] -
- rate * p_frame_info->border_vec[i]);
}
- if (!int_mode) {
+ if (!int_mode && ui != li) {
for (nrg = 0, k = c - (ui - li); k < c; k++) {
nrg += nrg_est[k];
}
nrg /= (ui - li);
+ } else {
+ nrg = 0;
}
c -= (ui - li);
for (k = 0; k < ui - li; k++) {
- FLOAT64 guard = 1e-17;
o = (k + li >= ui2) ? o + 1 : o;
if (o >= MAX_NOISE_COEFFS) {
if (ec_flag)
@@ -680,7 +699,7 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
nrg_est[c] = (!int_mode) ? nrg : nrg_est[c];
nrg_tone[c] = 0;
tmp = noise_floor[next * num_nf_bands + o] /
- (1 + noise_floor[next * num_nf_bands + o]);
+ (1 + noise_floor[next * num_nf_bands + o] + guard);
if (flag) {
nrg_gain[c] = (FLOAT32)sqrt(nrg_ref[c] * tmp / (nrg_est[c] + 1));
nrg_tone[c] = (FLOAT32)(
@@ -717,7 +736,7 @@ WORD32 ixheaacd_sbr_env_calc(ia_sbr_frame_info_data_struct *frame_data, FLOAT32
for (k = (*lim_table)[limiter_band][c];
k < (*lim_table)[limiter_band][c + 1]; k++) {
if (g_max <= nrg_gain[k]) {
- noise_level[k] = noise_level[k] * (g_max / nrg_gain[k]);
+ noise_level[k] = (FLOAT32)(noise_level[k] * (g_max / (nrg_gain[k] + guard)));
nrg_gain[k] = g_max;
}
}
diff --git a/decoder/ixheaacd_huff_code_reorder.c b/decoder/ixheaacd_huff_code_reorder.c
index a9d6ffd..8ca6061 100644
--- a/decoder/ixheaacd_huff_code_reorder.c
+++ b/decoder/ixheaacd_huff_code_reorder.c
@@ -675,7 +675,7 @@ static PLATFORM_INLINE UWORD16 *ixheaacd_huff_dec_pair_hcr_pcw(
ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word,
it_bit_buff->ptr_bit_buf_end);
}
-
+ *bit_pos = max(0, *bit_pos);
read_word1 = *read_word << *bit_pos;
ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
idx_table);
@@ -814,7 +814,7 @@ static PLATFORM_INLINE UWORD16 *ixheaacd_huff_dec_quad_hcr_pcw(
ixheaacd_aac_read_byte_corr(&ptr_read_next, bit_pos, read_word,
it_bit_buff->ptr_bit_buf_end);
}
-
+ *bit_pos = max(0, *bit_pos);
read_word1 = *read_word << *bit_pos;
ixheaacd_huffman_decode(read_word1, &index, &length, code_book_tbl,
idx_table);
@@ -944,7 +944,7 @@ static UWORD16 *ixheaacd_huff_dec_word_hcr_pcw(
ixheaacd_aac_read_byte_corr1(&ptr_read_next, bit_pos, read_word,
it_bit_buff->ptr_bit_buf_end);
}
-
+ *bit_pos = max(0, *bit_pos);
read_word1 = *read_word << *bit_pos;
ixheaacd_huff_sfb_table(read_word1, &index, &length, code_book_tbl,
idx_table);
diff --git a/decoder/ixheaacd_imdct.c b/decoder/ixheaacd_imdct.c
index c8d17de..bb32c7c 100644
--- a/decoder/ixheaacd_imdct.c
+++ b/decoder/ixheaacd_imdct.c
@@ -392,6 +392,9 @@ static IA_ERRORCODE ixheaacd_fd_imdct_short(ia_usac_data_struct *usac_data,
ixheaacd_normalize(p_in_ibuffer, max_shift - 1, ixheaacd_drc_offset->n_long);
shiftp += max_shift - 1;
+ if ((shiftp - shift_olap) > 31) {
+ shiftp = 31 + shift_olap;
+ }
err_code = ixheaacd_calc_window(&window_short, ixheaacd_drc_offset->n_short,
window_select, usac_data->ec_flag);
if (err_code == -1) return err_code;
@@ -518,6 +521,9 @@ static IA_ERRORCODE ixheaacd_fd_imdct_long(ia_usac_data_struct *usac_data,
ixheaacd_calc_max_spectralline(p_in_ibuffer, ixheaacd_drc_offset->n_long);
ixheaacd_normalize(p_in_ibuffer, max_shift - 1, ixheaacd_drc_offset->n_long);
shiftp += max_shift - 1;
+ if ((shiftp - shift_olap) > 31) {
+ shiftp = 31 + shift_olap;
+ }
switch (window_sequence) {
case ONLY_LONG_SEQUENCE:
@@ -553,10 +559,18 @@ static IA_ERRORCODE ixheaacd_fd_imdct_long(ia_usac_data_struct *usac_data,
}
for (i = 0; i < ixheaacd_drc_offset->n_long / 2; i++) {
- p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 + i] =
+ if (shiftp > shift_olap) {
+ p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 + i] =
ixheaac_negate32_sat(p_in_ibuffer[i]) >> (shiftp - shift_olap);
- p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 - i - 1] =
+ p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 - i - 1] =
ixheaac_negate32_sat(p_in_ibuffer[i]) >> (shiftp - shift_olap);
+ }
+ else {
+ p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 + i] =
+ ixheaac_negate32_sat(p_in_ibuffer[i]) >> (shift_olap - shiftp);
+ p_overlap_ibuffer[ixheaacd_drc_offset->n_long / 2 - i - 1] =
+ ixheaac_negate32_sat(p_in_ibuffer[i]) >> (shift_olap - shiftp);
+ }
}
ixheaacd_scale_down_adj(p_out_ibuffer, p_out_ibuffer,
diff --git a/decoder/ixheaacd_ld_mps_config.c b/decoder/ixheaacd_ld_mps_config.c
index 1da3472..162b876 100644
--- a/decoder/ixheaacd_ld_mps_config.c
+++ b/decoder/ixheaacd_ld_mps_config.c
@@ -85,6 +85,9 @@ static IA_ERRORCODE ixheaacd_ld_spatial_extension_config(
config->bs_residual_sampling_freq_index =
ixheaacd_read_bits_buf(it_bit_buff, 4);
+ if (config->bs_residual_sampling_freq_index > MAX_RES_SAMP_FREQ_IDX) {
+ return IA_FATAL_ERROR;
+ }
config->bs_residual_frames_per_spatial_frame =
ixheaacd_read_bits_buf(it_bit_buff, 2);
@@ -97,6 +100,10 @@ static IA_ERRORCODE ixheaacd_ld_spatial_extension_config(
if (config->bs_residual_present[j]) {
config->bs_residual_bands_ld_mps[j] =
ixheaacd_read_bits_buf(it_bit_buff, 5);
+ if (config->bs_residual_bands_ld_mps[j] > MAX_PARAMETER_BANDS)
+ {
+ return IA_FATAL_ERROR;
+ }
}
}
break;
@@ -106,10 +113,17 @@ static IA_ERRORCODE ixheaacd_ld_spatial_extension_config(
config->bs_arbitrary_downmix_residual_sampling_freq_index =
ixheaacd_read_bits_buf(it_bit_buff, 4);
+ if (config->bs_arbitrary_downmix_residual_sampling_freq_index > MAX_RES_SAMP_FREQ_IDX) {
+ return IA_FATAL_ERROR;
+ }
config->bs_arbitrary_downmix_residual_frames_per_spatial_frame =
ixheaacd_read_bits_buf(it_bit_buff, 2);
config->bs_arbitrary_downmix_residual_bands =
ixheaacd_read_bits_buf(it_bit_buff, 5);
+ if (config->bs_arbitrary_downmix_residual_bands >=
+ ixheaacd_freq_res_table[config->bs_freq_res]) {
+ return IA_FATAL_ERROR;
+ }
break;
diff --git a/decoder/ixheaacd_lpc_dec.c b/decoder/ixheaacd_lpc_dec.c
index c43cef5..6f5a711 100644
--- a/decoder/ixheaacd_lpc_dec.c
+++ b/decoder/ixheaacd_lpc_dec.c
@@ -60,7 +60,7 @@ VOID ixheaacd_lsf_weight_2st_flt(FLOAT32 *lsfq, FLOAT32 *w, WORD32 mode) {
}
for (i = 0; i < ORDER; i++) {
- w[i] = (FLOAT32)(factor_table[mode] / (FREQ_DIV / sqrt(d[i] * d[i + 1])));
+ w[i] = (FLOAT32)((factor_table[mode] * sqrt(d[i] * d[i + 1])) / FREQ_DIV);
}
return;
diff --git a/decoder/ixheaacd_mps_bitdec.c b/decoder/ixheaacd_mps_bitdec.c
index ffc43f6..d8a10e4 100644
--- a/decoder/ixheaacd_mps_bitdec.c
+++ b/decoder/ixheaacd_mps_bitdec.c
@@ -47,12 +47,32 @@
#include "ixheaacd_mps_mdct_2_qmf.h"
#include "ixheaac_sbr_const.h"
-static WORD32 ixheaacd_mps_bound_check(WORD32 var, WORD32 lower_bound, WORD32 upper_bound) {
+static const WORD32 ixheaacd_freq_res_table[] = {0, 28, 20, 14, 10, 7, 5, 4};
+
+static WORD32 ixheaacd_bound_check(WORD32 var, WORD32 lower_bound, WORD32 upper_bound) {
var = min(var, upper_bound);
var = max(var, lower_bound);
return var;
}
+static VOID ixheaacd_mps_check_index_bounds(
+ WORD32 output_idx_data[][MAX_PARAMETER_SETS][MAX_PARAMETER_BANDS],
+ WORD32 num_parameter_sets, WORD32 start_band, WORD32 stop_band,
+ WORD32 param_type, WORD32 xtt_idx) {
+ WORD32 i, band;
+ for (i = 0; i < num_parameter_sets; i++) {
+ for (band = start_band; band < stop_band; band++) {
+ if (param_type == CLD) {
+ output_idx_data[xtt_idx][i][band] =
+ ixheaacd_bound_check(output_idx_data[xtt_idx][i][band], -15, 15);
+ } else if (param_type == ICC) {
+ output_idx_data[xtt_idx][i][band] =
+ ixheaacd_bound_check(output_idx_data[xtt_idx][i][band], 0, 7);
+ }
+ }
+ }
+}
+
static IA_ERRORCODE ixheaacd_parse_extension_config(
ia_mps_spatial_bs_config_struct *config, WORD32 num_ott_boxes, WORD32 num_ttt_boxes,
WORD32 num_out_chan, WORD32 bits_available, ia_bit_buf_struct *it_bit_buff,
@@ -84,12 +104,19 @@ static IA_ERRORCODE ixheaacd_parse_extension_config(
config->bs_residual_coding = 1;
temp = ixheaacd_read_bits_buf(it_bit_buff, 6);
config->bs_residual_sampling_freq_index = (temp >> 2) & FOUR_BIT_MASK;
+ if (config->bs_residual_sampling_freq_index > MAX_RES_SAMP_FREQ_IDX) {
+ return IA_FATAL_ERROR;
+ }
config->bs_residual_frames_per_spatial_frame = temp & TWO_BIT_MASK;
for (i = 0; i < num_ott_boxes + num_ttt_boxes; i++) {
config->bs_residual_present[i] = ixheaacd_read_bits_buf(it_bit_buff, 1);
if (config->bs_residual_present[i]) {
config->bs_residual_bands[i] = ixheaacd_read_bits_buf(it_bit_buff, 5);
+ if (config->bs_residual_bands[i] > MAX_PARAMETER_BANDS)
+ {
+ return IA_FATAL_ERROR;
+ }
}
}
break;
@@ -99,9 +126,16 @@ static IA_ERRORCODE ixheaacd_parse_extension_config(
temp = ixheaacd_read_bits_buf(it_bit_buff, 11);
config->bs_arbitrary_downmix_residual_sampling_freq_index = (temp >> 7) & FOUR_BIT_MASK;
+ if (config->bs_arbitrary_downmix_residual_sampling_freq_index > MAX_RES_SAMP_FREQ_IDX) {
+ return IA_FATAL_ERROR;
+ }
config->bs_arbitrary_downmix_residual_frames_per_spatial_frame =
(temp >> 5) & TWO_BIT_MASK;
config->bs_arbitrary_downmix_residual_bands = temp & FIVE_BIT_MASK;
+ if (config->bs_arbitrary_downmix_residual_bands >=
+ ixheaacd_freq_res_table[config->bs_freq_res]) {
+ return IA_FATAL_ERROR;
+ }
break;
@@ -524,7 +558,7 @@ static WORD32 ixheaacd_decode_icc_diff_code(ia_bit_buf_struct *it_bit_buff) {
return value;
}
-static VOID ixheaacd_parse_residual_data(ia_heaac_mps_state_struct *pstr_mps_state) {
+static IA_ERRORCODE ixheaacd_parse_residual_data(ia_heaac_mps_state_struct *pstr_mps_state) {
WORD32 ich, ch;
WORD32 rfpsf;
WORD32 ps;
@@ -547,6 +581,7 @@ static VOID ixheaacd_parse_residual_data(ia_heaac_mps_state_struct *pstr_mps_sta
WORD32 *p_res_mdct = pstr_mps_state->array_struct->res_mdct;
ia_bit_buf_struct *mps_bit_buf = pstr_mps_state->ptr_mps_bit_buff;
+ WORD16 error_code = IA_NO_ERROR;
for (ich = 0; ich < loop_counter; ich++) {
ch = ich;
@@ -567,8 +602,15 @@ static VOID ixheaacd_parse_residual_data(ia_heaac_mps_state_struct *pstr_mps_sta
}
p_mdct_res = p_res_mdct;
for (rfpsf = 0; rfpsf < residual_frames_per_spatial_frame; rfpsf++) {
- ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1,
- aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ error_code =
+ ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1,
+ aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ } else
+ return error_code;
+ }
if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
ixheaacd_res_ctns_apply(
pstr_mps_state->p_aac_decoder_channel_info[0],
@@ -584,8 +626,15 @@ static VOID ixheaacd_parse_residual_data(ia_heaac_mps_state_struct *pstr_mps_sta
if ((pstr_mps_state->p_aac_decoder_channel_info[0]->ics_info.window_sequence ==
EIGHT_SHORT_SEQUENCE) &&
((upd_qmf == UPD_QMF_18) || (upd_qmf == UPD_QMF_24) || (upd_qmf == UPD_QMF_30))) {
- ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1,
- aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ error_code =
+ ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1,
+ aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ } else
+ return error_code;
+ }
if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
ixheaacd_res_ctns_apply(
pstr_mps_state->p_aac_decoder_channel_info[0],
@@ -601,6 +650,7 @@ static VOID ixheaacd_parse_residual_data(ia_heaac_mps_state_struct *pstr_mps_sta
p_res_mdct += RFX2XMDCTCOEF;
}
+ return IA_NO_ERROR;
}
static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *pstr_mps_state) {
@@ -694,7 +744,13 @@ static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *ps
switch (sac_ext_type) {
case EXT_TYPE_0:
- ixheaacd_parse_residual_data(pstr_mps_state);
+ error_code = ixheaacd_parse_residual_data(pstr_mps_state);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ } else
+ return error_code;
+ }
break;
case EXT_TYPE_1:
@@ -728,8 +784,15 @@ static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *ps
if (channel_grouping[gr] == 1) {
for (fr = 0; fr < arbdmx_frames_per_spatial_frame; fr++) {
- ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1,
- aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ error_code =
+ ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info,
+ 1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ } else
+ return error_code;
+ }
if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
ixheaacd_res_ctns_apply(
pstr_mps_state->p_aac_decoder_channel_info[0],
@@ -747,8 +810,15 @@ static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *ps
EIGHT_SHORT_SEQUENCE) &&
((arbdmx_upd_qmf == UPD_QMF_18) || (arbdmx_upd_qmf == UPD_QMF_24) ||
(arbdmx_upd_qmf == UPD_QMF_30))) {
- ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info,
- 1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ error_code = ixheaacd_res_read_ics(
+ mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, aac_tables_ptr,
+ pstr_mps_state->tot_sf_bands_ls);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ } else
+ return error_code;
+ }
if (1 ==
pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
ixheaacd_res_ctns_apply(
@@ -778,8 +848,15 @@ static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *ps
return IA_XHEAAC_MPS_DEC_EXE_FATAL_NONZERO_BIT;
}
- ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1,
- aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ error_code =
+ ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info,
+ 1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ } else
+ return error_code;
+ }
if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
ixheaacd_res_ctns_apply(
@@ -795,8 +872,15 @@ static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *ps
(pstr_mps_state->p_aac_decoder_channel_info[0]->p_spectral_coefficient[i]);
}
- ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1,
- aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ error_code =
+ ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info,
+ 1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ } else
+ return error_code;
+ }
if (1 == pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
ixheaacd_res_ctns_apply(
@@ -821,8 +905,15 @@ static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *ps
return IA_XHEAAC_MPS_DEC_EXE_FATAL_NONZERO_BIT;
}
- ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info,
- 1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ error_code = ixheaacd_res_read_ics(
+ mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, aac_tables_ptr,
+ pstr_mps_state->tot_sf_bands_ls);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ } else
+ return error_code;
+ }
if (1 ==
pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
@@ -837,8 +928,15 @@ static IA_ERRORCODE ixheaacd_parse_extension_frame(ia_heaac_mps_state_struct *ps
->p_spectral_coefficient[i]);
}
- ixheaacd_res_read_ics(mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info,
- 1, aac_tables_ptr, pstr_mps_state->tot_sf_bands_ls);
+ error_code = ixheaacd_res_read_ics(
+ mps_bit_buf, pstr_mps_state->p_aac_decoder_channel_info, 1, aac_tables_ptr,
+ pstr_mps_state->tot_sf_bands_ls);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ } else
+ return error_code;
+ }
if (1 ==
pstr_mps_state->p_aac_decoder_channel_info[0]->tns_data.tns_data_present)
@@ -1126,7 +1224,14 @@ IA_ERRORCODE ixheaacd_parse_frame(ia_heaac_mps_state_struct *pstr_mps_state) {
}
ixheaacd_byte_align(mps_bit_buf, &alignment_bits);
- ixheaacd_parse_extension_frame(pstr_mps_state);
+ error_code = ixheaacd_parse_extension_frame(pstr_mps_state);
+ if (error_code) {
+ if (pstr_mps_state->ec_flag) {
+ pstr_mps_state->frame_ok = 0;
+ }
+ else
+ return error_code;
+ }
for (i = 0; i < num_ott_boxes; i++) {
for (ps = 0; ps < num_parameter_sets; ps++) {
@@ -1495,18 +1600,9 @@ static IA_ERRORCODE ixheaacd_map_index_data(
}
}
- for (ps = 0; ps < num_parameter_sets; ps++) {
- for (band = start_band; band < stop_band; band++) {
- if (param_type == CLD) {
- output_idx_data[xtt_idx][ps][band] =
- ixheaacd_mps_bound_check(output_idx_data[xtt_idx][ps][band], -15, 15);
- } else if (param_type == ICC)
- {
- output_idx_data[xtt_idx][ps][band] =
- ixheaacd_mps_bound_check(output_idx_data[xtt_idx][ps][band], 0, 7);
- }
- }
- }
+ ixheaacd_mps_check_index_bounds(output_idx_data, num_parameter_sets, start_band,
+ stop_band, param_type, xtt_idx);
+
if (extend_frame) {
for (band = start_band; band < stop_band; band++) {
output_data[xtt_idx][num_parameter_sets][band] =
@@ -1585,8 +1681,10 @@ static VOID ixheaacd_map_data_to_28_bands(
return;
}
-static VOID ixheaacd_decode_and_map_frame_ott(ia_heaac_mps_state_struct *pstr_mps_state) {
- ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
+static IA_ERRORCODE ixheaacd_decode_and_map_frame_ott(ia_heaac_mps_state_struct *pstr_mps_state)
+{
+ IA_ERRORCODE error_code = IA_NO_ERROR;
+ ia_mps_dec_spatial_bs_frame_struct *p_cur_bs;
ia_heaac_mps_state_struct *curr_state = pstr_mps_state;
ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
ia_mps_dec_bitdec_tables_struct *bitdec_table =
@@ -1638,87 +1736,100 @@ static VOID ixheaacd_decode_and_map_frame_ott(ia_heaac_mps_state_struct *pstr_mp
switch (curr_state->tree_config) {
case TREE_5151:
i = 0;
-
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, tot_db, ott_vs_tot_db_fc, ott_vs_tot_db_s, bitdec_table, free_scratch);
+ if (error_code) return error_code;
i = 1;
-
- ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
+ error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, ott_vs_tot_db_fc, ott_vs_tot_db_f, ott_vs_tot_db_c,
bitdec_table, free_scratch);
+ if (error_code) return error_code;
i = 2;
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, ott_vs_tot_db_s, tmp1, tmp2, bitdec_table, free_scratch);
+ if (error_code) return error_code;
i = 3;
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, ott_vs_tot_db_f, tmp1, tmp2, bitdec_table, free_scratch);
+ if (error_code) return error_code;
i = 4;
- ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
+ error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, tot_db, tmp1, tmp2, bitdec_table, free_scratch);
+ if (error_code) return error_code;
break;
case TREE_5152:
i = 0;
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, tot_db, ott_vs_tot_db_lr, ott_vs_tot_db_c, bitdec_table, free_scratch);
+ if (error_code) return error_code;
+
i = 1;
- ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
+ error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, ott_vs_tot_db_lr, ott_vs_tot_db_l, ott_vs_tot_db_r,
bitdec_table, free_scratch);
+ if (error_code) return error_code;
+
i = 2;
- ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
+ error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, tot_db, tmp1, tmp2, bitdec_table, free_scratch);
+ if (error_code) return error_code;
+
i = 3;
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, ott_vs_tot_db_l, tmp1, tmp2, bitdec_table, free_scratch);
+ if (error_code) return error_code;
+
i = 4;
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld, p_cur_bs->ott_cld_idx,
p_cur_bs->cmp_ott_cld_idx, NULL, i, p_cur_bs->ott_cld_idx_prev, i, CLD, 0,
b_ott_bands[i], ott_cld_default[i], parameter_sets, param_slot, extend_frame,
quant_mode, ott_vs_tot_db_r, tmp1, tmp2, bitdec_table, free_scratch);
+ if (error_code) return error_code;
break;
default:
for (i = 0; i < num_ott_boxes; i++) {
- ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
+ error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, i,
p_cur_bs->ott_cld_idx_prev, i, CLD, 0, b_ott_bands[i],
ott_cld_default[i], parameter_sets, param_slot, extend_frame,
(curr_state->tree_config == TREE_525) ? 0 : quant_mode, NULL,
NULL, NULL, bitdec_table, free_scratch);
+ if (error_code) return error_code;
}
break;
}
@@ -1742,23 +1853,25 @@ static VOID ixheaacd_decode_and_map_frame_ott(ia_heaac_mps_state_struct *pstr_mp
for (ott_idx = 0; ott_idx < num_ott_boxes; ott_idx++) {
if (curr_state->ott_mode_lfe[ott_idx] == 0) {
- ixheaacd_map_index_data(&p_cur_bs->icc_lossless_data, p_aux_struct->ott_icc,
+ error_code = ixheaacd_map_index_data(&p_cur_bs->icc_lossless_data, p_aux_struct->ott_icc,
p_cur_bs->ott_icc_idx, p_cur_bs->cmp_ott_icc_idx,
p_cur_bs->ott_icc_diff_idx, ott_idx, p_cur_bs->ott_icc_idx_prev,
0, ICC, 0, b_ott_bands[ott_idx], curr_state->icc_default,
parameter_sets, param_slot, extend_frame, quant_mode, NULL, NULL,
NULL, bitdec_table, free_scratch);
+ if (error_code) return error_code;
}
}
} else {
for (ott_idx = 0; ott_idx < num_ott_boxes; ott_idx++) {
if (curr_state->ott_mode_lfe[ott_idx] == 0) {
- ixheaacd_map_index_data(&p_cur_bs->icc_lossless_data, p_aux_struct->ott_icc,
+ error_code = ixheaacd_map_index_data(&p_cur_bs->icc_lossless_data, p_aux_struct->ott_icc,
p_cur_bs->ott_icc_idx, p_cur_bs->cmp_ott_icc_idx,
p_cur_bs->ott_icc_diff_idx, ott_idx, p_cur_bs->ott_icc_idx_prev,
ott_idx, ICC, 0, b_ott_bands[ott_idx], curr_state->icc_default,
parameter_sets, param_slot, extend_frame, quant_mode, NULL, NULL,
NULL, bitdec_table, free_scratch);
+ if (error_code) return error_code;
}
}
}
@@ -1779,11 +1892,13 @@ static VOID ixheaacd_decode_and_map_frame_ott(ia_heaac_mps_state_struct *pstr_mp
}
}
}
- return;
+ return error_code;
}
-static VOID ixheaacd_decode_and_map_frame_ttt(ia_heaac_mps_state_struct *pstr_mps_state) {
- ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
+static IA_ERRORCODE ixheaacd_decode_and_map_frame_ttt(ia_heaac_mps_state_struct *pstr_mps_state)
+{
+ IA_ERRORCODE error_code = IA_NO_ERROR;
+ ia_mps_dec_spatial_bs_frame_struct *p_cur_bs;
ia_mps_dec_bitdec_tables_struct *bitdec_table =
pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr;
ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
@@ -1807,33 +1922,36 @@ static VOID ixheaacd_decode_and_map_frame_ttt(ia_heaac_mps_state_struct *pstr_mp
p_aux_struct->ttt_config[j][i].start_band < p_aux_struct->ttt_config[j][i].stop_band;
j++) {
if (p_aux_struct->ttt_config[j][i].mode < 2) {
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cpc_lossless_data, p_aux_struct->ttt_cpc_1, p_cur_bs->ttt_cpc_1_idx,
p_cur_bs->cmp_ttt_cpc_1_idx, NULL, i, p_cur_bs->ttt_cpc_1_idx_prev,
offset + 4 * i + 2 * j, CPC, p_aux_struct->ttt_config[j][i].bitstream_start_band,
p_aux_struct->ttt_config[j][i].bitstream_stop_band, pstr_mps_state->cpc_default,
pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame,
pstr_mps_state->quant_mode, NULL, NULL, NULL, bitdec_table, free_scratch);
+ if (error_code) return error_code;
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cpc_lossless_data, p_aux_struct->ttt_cpc_2, p_cur_bs->ttt_cpc_2_idx,
p_cur_bs->cmp_ttt_cpc_2_idx, NULL, i, p_cur_bs->ttt_cpc_2_idx_prev,
offset + 4 * i + 1 + 2 * j, CPC, p_aux_struct->ttt_config[j][i].bitstream_start_band,
p_aux_struct->ttt_config[j][i].bitstream_stop_band, pstr_mps_state->cpc_default,
pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame,
pstr_mps_state->quant_mode, NULL, NULL, NULL, bitdec_table, free_scratch);
+ if (error_code) return error_code;
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->icc_lossless_data, p_aux_struct->ttt_icc, p_cur_bs->ttt_icc_idx,
p_cur_bs->cmp_ttt_icc_idx, NULL, i, p_cur_bs->ttt_icc_idx_prev,
offset + 4 * i + 2 * j, ICC, p_aux_struct->ttt_config[j][i].bitstream_start_band,
p_aux_struct->ttt_config[j][i].bitstream_stop_band, pstr_mps_state->icc_default,
pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame,
pstr_mps_state->quant_mode, NULL, NULL, NULL, bitdec_table, free_scratch);
+ if (error_code) return error_code;
}
else {
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cld_lossless_data, p_aux_struct->ttt_cld_1, p_cur_bs->ttt_cld_1_idx,
p_cur_bs->cmp_ttt_cld_1_idx, NULL, i, p_cur_bs->ttt_cld_1_idx_prev,
offset + 4 * i + 2 * j, CLD, p_aux_struct->ttt_config[j][i].bitstream_start_band,
@@ -1841,8 +1959,9 @@ static VOID ixheaacd_decode_and_map_frame_ttt(ia_heaac_mps_state_struct *pstr_mp
pstr_mps_state->ttt_cld_1_default[i], pstr_mps_state->num_parameter_sets, param_slot,
pstr_mps_state->extend_frame, pstr_mps_state->quant_mode, NULL, NULL, NULL,
bitdec_table, free_scratch);
+ if (error_code) return error_code;
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&p_cur_bs->cld_lossless_data, p_aux_struct->ttt_cld_2, p_cur_bs->ttt_cld_2_idx,
p_cur_bs->cmp_ttt_cld_2_idx, NULL, i, p_cur_bs->ttt_cld_2_idx_prev,
offset + 4 * i + 1 + 2 * j, CLD, p_aux_struct->ttt_config[j][i].bitstream_start_band,
@@ -1850,6 +1969,7 @@ static VOID ixheaacd_decode_and_map_frame_ttt(ia_heaac_mps_state_struct *pstr_mp
pstr_mps_state->ttt_cld_2_default[i], pstr_mps_state->num_parameter_sets, param_slot,
pstr_mps_state->extend_frame, pstr_mps_state->quant_mode, NULL, NULL, NULL,
bitdec_table, free_scratch);
+ if (error_code) return error_code;
}
if (pstr_mps_state->up_mix_type == 2) {
@@ -1870,6 +1990,7 @@ static VOID ixheaacd_decode_and_map_frame_ttt(ia_heaac_mps_state_struct *pstr_mp
}
}
}
+ return error_code;
}
static VOID ixheaacd_decode_and_map_frame_smg(ia_heaac_mps_state_struct *pstr_mps_state) {
@@ -1976,7 +2097,9 @@ static VOID ixheaacd_decode_and_map_frame_smg(ia_heaac_mps_state_struct *pstr_mp
return;
}
-static VOID ixheaacd_decode_and_map_frame_arbdmx(ia_heaac_mps_state_struct *pstr_mps_state) {
+static IA_ERRORCODE ixheaacd_decode_and_map_frame_arbdmx(
+ ia_heaac_mps_state_struct *pstr_mps_state) {
+ IA_ERRORCODE error_code = IA_NO_ERROR;
ia_mps_dec_spatial_bs_frame_struct *frame = pstr_mps_state->bs_frame;
ia_mps_dec_bitdec_tables_struct *bitdec_table =
pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr;
@@ -1988,12 +2111,13 @@ static VOID ixheaacd_decode_and_map_frame_arbdmx(ia_heaac_mps_state_struct *pstr
VOID *scratch = pstr_mps_state->mps_scratch_mem_v;
for (ch = 0; ch < pstr_mps_state->num_input_channels; ch++) {
- ixheaacd_map_index_data(
+ error_code = ixheaacd_map_index_data(
&frame->cld_lossless_data, p_aux_struct->arbdmx_gain, frame->arbdmx_gain_idx,
frame->cmp_arbdmx_gain_idx, NULL, ch, frame->arbdmx_gain_idx_prev, offset + ch, CLD, 0,
pstr_mps_state->bitstream_parameter_bands, pstr_mps_state->arbdmx_gain_default,
pstr_mps_state->num_parameter_sets, param_slot, pstr_mps_state->extend_frame, 0, NULL,
NULL, NULL, bitdec_table, scratch);
+ if (error_code) return error_code;
p_aux_struct->arbdmx_residual_abs[ch] = frame->bs_arbitrary_downmix_residual_abs[ch];
p_aux_struct->arbdmx_alpha_upd_set[ch] =
@@ -2013,9 +2137,12 @@ static VOID ixheaacd_decode_and_map_frame_arbdmx(ia_heaac_mps_state_struct *pstr
}
}
}
+ return error_code;
}
-static VOID ixheaacd_decode_and_map_frame_arb_tree(ia_heaac_mps_state_struct *pstr_mps_state) {
+static IA_ERRORCODE ixheaacd_decode_and_map_frame_arb_tree(
+ ia_heaac_mps_state_struct *pstr_mps_state) {
+ IA_ERRORCODE error_code = IA_NO_ERROR;
ia_mps_dec_spatial_bs_frame_struct *p_cur_bs = pstr_mps_state->bs_frame;
ia_mps_spatial_bs_config_struct *p_config = &(pstr_mps_state->bs_config);
ia_mps_dec_auxilary_struct *p_aux_struct = pstr_mps_state->aux_struct;
@@ -2027,17 +2154,20 @@ static VOID ixheaacd_decode_and_map_frame_arb_tree(ia_heaac_mps_state_struct *ps
WORD32 i;
for (i = 0; i < p_config->num_ott_boxes_at; i++) {
- ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
+ error_code = ixheaacd_map_index_data(&p_cur_bs->cld_lossless_data, p_aux_struct->ott_cld,
p_cur_bs->ott_cld_idx, p_cur_bs->cmp_ott_cld_idx, NULL, offset + i,
p_cur_bs->ott_cld_idx_prev, offset + i, CLD, 0,
p_config->bs_ott_bands_at[i], p_config->bs_ott_default_cld_at[i],
pstr_mps_state->num_parameter_sets, param_slot,
pstr_mps_state->extend_frame, pstr_mps_state->quant_mode, NULL, NULL,
NULL, pstr_mps_state->ia_mps_dec_mps_table.bitdec_table_ptr, scratch);
+ if (error_code) return error_code;
}
+ return error_code;
}
IA_ERRORCODE ixheaacd_decode_frame(ia_heaac_mps_state_struct *pstr_mps_state) {
+ IA_ERRORCODE error_code = IA_NO_ERROR;
ia_mps_spatial_bs_config_struct *p_bs_config = &pstr_mps_state->bs_config;
WORD32 *param_slot = pstr_mps_state->aux_struct->param_slot;
@@ -2055,16 +2185,77 @@ IA_ERRORCODE ixheaacd_decode_frame(ia_heaac_mps_state_struct *pstr_mps_state) {
}
}
- ixheaacd_decode_and_map_frame_ott(pstr_mps_state);
- ixheaacd_decode_and_map_frame_ttt(pstr_mps_state);
+ error_code = ixheaacd_decode_and_map_frame_ott(pstr_mps_state);
+ if (error_code)
+ {
+ if (pstr_mps_state->ec_flag)
+ {
+ pstr_mps_state->frame_ok = 0;
+ for (WORD32 idx = 0; idx < MAX_NUM_OTT; idx++)
+ {
+ ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ott_cld_idx,
+ pstr_mps_state->num_parameter_sets, 0, pstr_mps_state->bitstream_ott_bands[idx],
+ CLD, idx);
+ ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ott_icc_idx,
+ pstr_mps_state->num_parameter_sets, 0, pstr_mps_state->bitstream_ott_bands[idx],
+ ICC, idx);
+ }
+ }
+ else
+ return error_code;
+ }
+
+ error_code = ixheaacd_decode_and_map_frame_ttt(pstr_mps_state);
+ if (error_code)
+ {
+ if (pstr_mps_state->ec_flag)
+ {
+ pstr_mps_state->frame_ok = 0;
+ ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ttt_icc_idx,
+ pstr_mps_state->num_parameter_sets, 0, MAX_PARAMETER_BANDS,
+ ICC, 0);
+ }
+ else
+ return error_code;
+ }
ixheaacd_decode_and_map_frame_smg(pstr_mps_state);
if (p_bs_config->arbitrary_tree != 0) {
- ixheaacd_decode_and_map_frame_arb_tree(pstr_mps_state);
+ error_code = ixheaacd_decode_and_map_frame_arb_tree(pstr_mps_state);
+ if (error_code)
+ {
+ if (pstr_mps_state->ec_flag)
+ {
+ pstr_mps_state->frame_ok = 0;
+ for (WORD32 idx = 0; idx < MAX_NUM_OTT; idx++)
+ {
+ ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->ott_cld_idx,
+ pstr_mps_state->num_parameter_sets, 0, MAX_PARAMETER_BANDS,
+ CLD, idx);
+ }
+ }
+ else
+ return error_code;
+ }
}
if (pstr_mps_state->arbitrary_downmix != 0) {
- ixheaacd_decode_and_map_frame_arbdmx(pstr_mps_state);
+ error_code = ixheaacd_decode_and_map_frame_arbdmx(pstr_mps_state);
+ if (error_code)
+ {
+ if (pstr_mps_state->ec_flag)
+ {
+ pstr_mps_state->frame_ok = 0;
+ for (WORD32 idx = 0; idx < MAX_INPUT_CHANNELS_MPS; idx++)
+ {
+ ixheaacd_mps_check_index_bounds(pstr_mps_state->bs_frame->arbdmx_gain_idx,
+ pstr_mps_state->num_parameter_sets, 0, MAX_PARAMETER_BANDS,
+ CLD, idx);
+ }
+ }
+ else
+ return error_code;
+ }
}
if (pstr_mps_state->extend_frame) {
diff --git a/decoder/ixheaacd_mps_decorr.c b/decoder/ixheaacd_mps_decorr.c
index 00a0271..910f03a 100644
--- a/decoder/ixheaacd_mps_decorr.c
+++ b/decoder/ixheaacd_mps_decorr.c
@@ -684,6 +684,9 @@ static VOID ixheaacd_ducker_apply_71(
if (ixheaacd_mps_comp(temp3, temp_1, &qtemp, qtemp1)) {
temp_2 = ixheaacd_mps_div_32(temp3, temp_1, &qtemp2);
qtemp2 = qtemp2 + qtemp - qtemp1;
+ if (temp_1 == 0) {
+ qtemp2 = qtemp;
+ }
temp3 = (qtemp2) > 28 ? MAX_32 : 4 << qtemp2;
if (temp_2 > temp3) {
@@ -837,6 +840,9 @@ static VOID ixheaacd_ducker_apply(
if (ixheaacd_mps_comp(temp3, temp_1, &qtemp, qtemp1)) {
temp_2 = ixheaacd_mps_div_32(temp3, temp_1, &qtemp2);
qtemp2 = qtemp2 + qtemp - qtemp1;
+ if (temp_1 == 0) {
+ qtemp2 = qtemp;
+ }
temp3 = qtemp2 > 28 ? MAX_32 : 4 << qtemp2;
if (temp_2 > temp3) {
diff --git a/decoder/ixheaacd_mps_parse.c b/decoder/ixheaacd_mps_parse.c
index 398b88a..83ffdf3 100644
--- a/decoder/ixheaacd_mps_parse.c
+++ b/decoder/ixheaacd_mps_parse.c
@@ -445,11 +445,21 @@ IA_ERRORCODE ixheaacd_mps_frame_parsing(ia_mps_dec_state_struct *self,
bits_param_slot = 6;
if (bs_frame_type) {
+ WORD32 prev_param_slot = -1;
for (i = 0; i < self->num_parameter_sets; i++) {
self->param_slots[i] = ixheaacd_read_bits_buf(bitstream, bits_param_slot);
+
+ if (prev_param_slot >= self->param_slots[i] || self->param_slots[i] >= self->time_slots) {
+ return IA_FATAL_ERROR;
+ }
+ prev_param_slot = self->param_slots[i];
}
} else {
- self->param_slots[0] = self->time_slots - 1;
+ for (i = 0; i < self->num_parameter_sets; i++) {
+ self->param_slots[i] = (((self->time_slots * (i + 1)) + self->num_parameter_sets - 1) /
+ self->num_parameter_sets) -
+ 1;
+ }
}
if (!usac_independency_flag) {
diff --git a/decoder/ixheaacd_mps_res_block.c b/decoder/ixheaacd_mps_res_block.c
index 986d895..e3000a5 100644
--- a/decoder/ixheaacd_mps_res_block.c
+++ b/decoder/ixheaacd_mps_res_block.c
@@ -123,6 +123,7 @@ static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word1(
sign_ret_val = *h;
}
bit_pos += ((sign_ret_val & 0x7fff) >> 11);
+ bit_pos = min(bit_pos, 31);
value = sign_ret_val & (0x07FF);
}
out1 = (value & 0x3E0) >> 5;
@@ -303,6 +304,7 @@ static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word1_lb(
sign_ret_val = *h;
}
bit_pos += ((sign_ret_val & 0x7fff) >> 11);
+ bit_pos = min(bit_pos, 31);
value = sign_ret_val & (0x07FF);
}
@@ -479,6 +481,7 @@ static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word2_4(
sign_ret_val = *h;
}
bit_pos += ((sign_ret_val & 0x7fff) >> 11);
+ bit_pos = min(bit_pos, 31);
value = sign_ret_val & (0x07FF);
if (sign) {
@@ -559,6 +562,7 @@ static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word2_4_lb(
sign_ret_val = *h;
}
bit_pos += ((sign_ret_val & 0x7fff) >> 11);
+ bit_pos = min(bit_pos, 31);
value = sign_ret_val & (0x07FF);
@@ -729,6 +733,7 @@ static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word2_2(
sign_ret_val = *h;
}
bit_pos += ((sign_ret_val & 0x7fff) >> 11);
+ bit_pos = min(bit_pos, 31);
value = sign_ret_val & (0x07FF);
if (sign) {
@@ -802,6 +807,7 @@ static PLATFORM_INLINE WORD ixheaacd_res_c_block_decode_huff_word2_2_lb(
sign_ret_val = *h;
}
bit_pos += ((sign_ret_val & 0x7fff) >> 11);
+ bit_pos = min(bit_pos, 31);
value = sign_ret_val & (0x07FF);
}
diff --git a/decoder/ixheaacd_mps_res_pns_js_thumb.c b/decoder/ixheaacd_mps_res_pns_js_thumb.c
index f7301a8..d86707c 100644
--- a/decoder/ixheaacd_mps_res_pns_js_thumb.c
+++ b/decoder/ixheaacd_mps_res_pns_js_thumb.c
@@ -99,7 +99,7 @@ VOID ixheaacd_res_ctns_apply(ia_mps_dec_residual_channel_info_struct *p_aac_deco
for (index = 0; index < ind_len; index++) {
ia_mps_dec_residual_filter_struct *filter = &p_tns_data->filter[window][index];
- if (filter->order <= 0) continue;
+ if (filter->order <= 0 || filter->order > MAX_ORDER_LONG) continue;
ixheaacd_res_tns_decode_coeffs_32x16(filter, (WORD16 *)coeff_parc, aac_tables_ptr);
diff --git a/decoder/ixheaacd_pns_js_thumb.c b/decoder/ixheaacd_pns_js_thumb.c
index e6ba987..c39b3f2 100644
--- a/decoder/ixheaacd_pns_js_thumb.c
+++ b/decoder/ixheaacd_pns_js_thumb.c
@@ -101,6 +101,9 @@ VOID ixheaacd_gen_rand_vec(WORD32 scale, WORD shift, WORD32 *ptr_spec_coef,
spec = ptr_spec_coef;
+ if (shift < -31) {
+ shift = -31;
+ }
for (sfb = 0; sfb <= sfb_width; sfb++) {
*spec = ixheaac_shr32_dir_sat_limit(ixheaac_mult32_shl_sat(*spec, scale),
shift);
diff --git a/decoder/ixheaacd_sbr_dec.c b/decoder/ixheaacd_sbr_dec.c
index 787e3a7..bccc772 100644
--- a/decoder/ixheaacd_sbr_dec.c
+++ b/decoder/ixheaacd_sbr_dec.c
@@ -1281,16 +1281,17 @@ WORD32 ixheaacd_sbr_dec(
{
WORD32 num = op_delay;
- WORD32 *p_loc_qmf_real = ptr_sbr_dec->ptr_sbr_overlap_buf;
- WORD32 *p_loc_qmf_real_1 = &p_arr_qmf_buf_real[no_bins][0];
+ if (audio_object_type != AOT_ER_AAC_ELD) {
+ WORD32 *p_loc_qmf_real = ptr_sbr_dec->ptr_sbr_overlap_buf;
+ WORD32 *p_loc_qmf_real_1 = &p_arr_qmf_buf_real[no_bins][0];
+ memcpy(p_loc_qmf_real, p_loc_qmf_real_1,
+ sizeof(WORD32) * NO_SYNTHESIS_CHANNELS * num);
+ }
if (!low_pow_flag) {
num = num << 1;
}
- memcpy(p_loc_qmf_real, p_loc_qmf_real_1,
- sizeof(WORD32) * NO_SYNTHESIS_CHANNELS * num);
-
if (ldmps_present == 1) {
memmove(&ptr_sbr_dec->mps_qmf_buf_real[0][0],
&ptr_sbr_dec->mps_qmf_buf_real[ptr_sbr_dec->str_codec_qmf_bank
diff --git a/decoder/ixheaacd_sbrdec_lpfuncs.c b/decoder/ixheaacd_sbrdec_lpfuncs.c
index d828d2f..a14a869 100644
--- a/decoder/ixheaacd_sbrdec_lpfuncs.c
+++ b/decoder/ixheaacd_sbrdec_lpfuncs.c
@@ -933,23 +933,25 @@ VOID ixheaacd_pre_processing(FLOAT32 ptr_src_buf_real[][64],
FLOAT32 poly_coeff[4];
FLOAT32 mean_enrg = 0;
FLOAT32 low_env_slope[64];
- FLOAT32 low_env[64];
+ FLOAT32 low_env[64] = {0};
FLOAT32 a0;
FLOAT32 a1;
FLOAT32 a2;
FLOAT32 a3;
- for (k = 0; k < num_bands; k++) {
- FLOAT32 temp = 0;
- for (i = start_sample; i < end_sample; i++) {
- temp += ptr_src_buf_real[i][k] * ptr_src_buf_real[i][k] +
- ptr_src_buf_imag[i][k] * ptr_src_buf_imag[i][k];
+ if (num_bands != 0 && end_sample != start_sample) {
+ for (k = 0; k < num_bands; k++) {
+ FLOAT32 temp = 0;
+ for (i = start_sample; i < end_sample; i++) {
+ temp += ptr_src_buf_real[i][k] * ptr_src_buf_real[i][k] +
+ ptr_src_buf_imag[i][k] * ptr_src_buf_imag[i][k];
+ }
+ temp /= (end_sample - start_sample);
+ low_env[k] = (FLOAT32)(10 * log10(temp + 1));
+ mean_enrg = mean_enrg + low_env[k];
}
- temp /= (end_sample - start_sample);
- low_env[k] = (FLOAT32)(10 * log10(temp + 1));
- mean_enrg = mean_enrg + low_env[k];
+ mean_enrg /= num_bands;
}
- mean_enrg /= num_bands;
ixheaacd_polyfit(num_bands, low_env, poly_coeff);
diff --git a/decoder/ixheaacd_sbrdecoder.c b/decoder/ixheaacd_sbrdecoder.c
index e67e073..6f336fa 100644
--- a/decoder/ixheaacd_sbrdecoder.c
+++ b/decoder/ixheaacd_sbrdecoder.c
@@ -615,6 +615,7 @@ IA_ERRORCODE ixheaacd_applysbr(
if (stereo) {
frame_status = ixheaacd_sbr_read_cpe(ptr_header_data[0], ptr_frame_data, it_bit_buff,
self->pstr_sbr_tables, audio_object_type);
+ if (usac_flag && (frame_status == 0)) return -1;
if (frame_status < 0) return frame_status;
} else {
if (ps_enable) {
@@ -630,6 +631,7 @@ IA_ERRORCODE ixheaacd_applysbr(
frame_status = ixheaacd_sbr_read_sce(
ptr_header_data[k], ptr_frame_data[k], self->pstr_ps_stereo_dec, it_bit_buff,
self->pstr_sbr_tables, audio_object_type, ec_flag);
+ if (usac_flag && (frame_status == 0)) return -1;
if (frame_status < 0) return frame_status;
if (ec_flag && self->pstr_ps_stereo_dec != NULL) {
ixheaacd_copy_prev_ps_params(self->pstr_ps_stereo_dec, &self->str_ps_config_prev,
@@ -644,7 +646,7 @@ IA_ERRORCODE ixheaacd_applysbr(
}
ptr_header_data[k]->enh_sbr_ps =
((self->enh_sbr_ps) | (ptr_header_data[0]->channel_mode == PS_STEREO));
- if (audio_object_type != AOT_ER_AAC_ELD) {
+ if ((audio_object_type != AOT_ER_AAC_ELD) && (audio_object_type != AOT_USAC)) {
WORD32 total_bits_read;
total_bits_read = ixheaacd_no_bits_read(it_bit_buff);
if (total_bits_read > (ptr_bit_str_ele->size_payload << 3) ||
diff --git a/decoder/ixheaacd_stereo.c b/decoder/ixheaacd_stereo.c
index 2f880f6..586f4c2 100644
--- a/decoder/ixheaacd_stereo.c
+++ b/decoder/ixheaacd_stereo.c
@@ -202,8 +202,14 @@ VOID ixheaacd_intensity_stereo_process(
shift_val = shift_val + scf_exp;
if (shift_val < 0) {
+ if (shift_val < -31) {
+ shift_val = -31;
+ }
temp = ixheaac_shl32_sat(temp, -shift_val);
} else {
+ if (shift_val > 31) {
+ shift_val = 31;
+ }
temp = ixheaac_shr32(temp, shift_val);
}
*r_spec++ = temp;
diff --git a/decoder/ixheaacd_tcx_fwd_mdct.c b/decoder/ixheaacd_tcx_fwd_mdct.c
index 267af0d..3fd55e8 100644
--- a/decoder/ixheaacd_tcx_fwd_mdct.c
+++ b/decoder/ixheaacd_tcx_fwd_mdct.c
@@ -165,7 +165,7 @@ VOID ixheaacd_lpc_to_td(FLOAT32 *coeff, WORD32 order, FLOAT32 *gains, WORD32 lg)
for (i = 0; i < size_n / 2; i++) {
gains[i] =
- (FLOAT32)(1.0f / sqrt(data_r[i] * data_r[i] + data_i[i] * data_i[i]));
+ (FLOAT32)(1.0f / (sqrt(data_r[i] * data_r[i] + data_i[i] * data_i[i]) + FLT_EPSILON));
}
return;
diff --git a/encoder/drc_src/impd_drc_api.c b/encoder/drc_src/impd_drc_api.c
index 84e97d5..4218903 100644
--- a/encoder/drc_src/impd_drc_api.c
+++ b/encoder/drc_src/impd_drc_api.c
@@ -40,8 +40,9 @@
var = MAX(var, lower_bound); \
}
-static VOID impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_config) {
+static 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;
ia_drc_loudness_info_set_struct *pstr_enc_loudness_info_set =
&pstr_inp_config->str_enc_loudness_info_set;
@@ -126,6 +127,19 @@ static VOID impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_config
.start_sub_band_index,
0, STFT256_HOP_SIZE - 1);
}
+ 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) {
+ return IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_SUBBAND_INDEX;
+ }
+ }
}
}
IMPD_DRC_BOUND_CHECK(pstr_uni_drc_config->downmix_instructions_count, 0,
@@ -198,6 +212,7 @@ static VOID impd_drc_validate_config_params(ia_drc_input_config *pstr_inp_config
0, MAX_RELIABILITY_TYPE);
}
}
+ return IA_NO_ERROR;
}
static IA_ERRORCODE impd_drc_validate_drc_instructions(
@@ -233,14 +248,6 @@ IA_ERRORCODE impd_drc_enc_init(VOID *pstr_drc_state, VOID *ptr_drc_scratch,
WORD32 bit_count = 0;
ia_drc_enc_state *pstr_drc_state_local = pstr_drc_state;
-#ifdef ENABLE_SET_JUMP
- jmp_buf drc_enc_init_jmp_buf;
- err_code = setjmp(drc_enc_init_jmp_buf);
- if (err_code != IA_NO_ERROR) {
- return IA_EXHEAACE_INIT_FATAL_DRC_INSUFFICIENT_WRITE_BUFFER_SIZE;
- }
-#endif // ENABLE_SET_JUMP
-
pstr_drc_state_local->drc_scratch_mem = ptr_drc_scratch;
pstr_drc_state_local->drc_scratch_used = 0;
@@ -260,24 +267,19 @@ 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);
-#ifdef ENABLE_SET_JUMP
- pstr_drc_state_local->str_bit_buf_cfg.impd_drc_jmp_buf = &drc_enc_init_jmp_buf;
- pstr_drc_state_local->str_bit_buf_cfg_ext.impd_drc_jmp_buf = &drc_enc_init_jmp_buf;
- pstr_drc_state_local->str_bit_buf_cfg_tmp.impd_drc_jmp_buf = &drc_enc_init_jmp_buf;
- pstr_drc_state_local->str_bit_buf_out.impd_drc_jmp_buf = &drc_enc_init_jmp_buf;
-#endif // ENABLE_SET_JUMP
-
- impd_drc_validate_config_params(pstr_inp_config);
+ 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,
pstr_inp_config->str_enc_params.sample_rate, pstr_inp_config->str_enc_params.delay_mode,
pstr_inp_config->str_enc_params.domain);
- if (err_code & IA_FATAL_ERROR) {
- return IA_EXHEAACE_CONFIG_FATAL_DRC_INVALID_CONFIG;
+ if (err_code) {
+ return err_code;
}
-
pstr_drc_state_local->str_enc_params = pstr_inp_config->str_enc_params;
pstr_drc_state_local->str_uni_drc_config = pstr_inp_config->str_uni_drc_config;
pstr_drc_state_local->str_enc_gain_extension = pstr_inp_config->str_enc_gain_extension;
diff --git a/encoder/drc_src/impd_drc_enc.c b/encoder/drc_src/impd_drc_enc.c
index 823b9b6..7e835f7 100644
--- a/encoder/drc_src/impd_drc_enc.c
+++ b/encoder/drc_src/impd_drc_enc.c
@@ -192,7 +192,7 @@ IA_ERRORCODE impd_drc_gain_enc_init(ia_drc_gain_enc_struct *pstr_gain_enc,
for (l = 0; l < pstr_gain_set_params->band_count; l++) {
err_code = impd_drc_stft_drc_gain_calc_init(pstr_gain_enc, 0, j, l);
- if (err_code & IA_FATAL_ERROR) {
+ if (err_code) {
return err_code;
}
pstr_gain_enc->str_drc_stft_gain_handle[0][j][l].ch_idx = ch_idx;
@@ -205,7 +205,7 @@ IA_ERRORCODE impd_drc_gain_enc_init(ia_drc_gain_enc_struct *pstr_gain_enc,
pstr_gain_enc->str_drc_compand[0][j].initial_volume = 0.0f;
err_code = impd_drc_td_drc_gain_calc_init(pstr_gain_enc, 0, j);
- if (err_code & IA_FATAL_ERROR) {
+ if (err_code) {
return err_code;
}
pstr_gain_enc->str_drc_compand[0][j].ch_idx = ch_idx;
diff --git a/encoder/drc_src/impd_drc_gain_calculator.c b/encoder/drc_src/impd_drc_gain_calculator.c
index 24514c3..5a1305a 100644
--- a/encoder/drc_src/impd_drc_gain_calculator.c
+++ b/encoder/drc_src/impd_drc_gain_calculator.c
@@ -18,6 +18,7 @@
* Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
#include <math.h>
+#include <float.h>
#include "ixheaac_type_def.h"
#include "ixheaac_error_standards.h"
#include "ixheaace_error_codes.h"
@@ -45,6 +46,7 @@
#include "impd_drc_gain_enc.h"
#include "impd_drc_struct_def.h"
#include "impd_drc_enc.h"
+#include "ixheaace_common_utils.h"
static VOID impd_drc_compand_update_volume(ia_drc_compand_chan_param_struct *pstr_channel_param,
FLOAT64 in_value) {
@@ -67,7 +69,12 @@ static FLOAT64 impd_drc_compand_get_volume(ia_drc_compand_struct *pstr_drc_compa
return pstr_drc_compand->out_min_lin;
}
- in_log = log(in_lin);
+ if (fabs(in_lin) <= FLT_EPSILON) {
+ in_log = log(FLT_EPSILON);
+ }
+ else {
+ in_log = log(fabs(in_lin));
+ }
for (idx = 1; idx < pstr_drc_compand->nb_segments; idx++) {
if (in_log <= pstr_drc_compand->str_segment[idx].x) {
@@ -121,8 +128,6 @@ IA_ERRORCODE impd_drc_td_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_gai
pstr_drc_compand =
&pstr_drc_gain_enc->str_drc_compand[drc_coefficients_uni_drc_idx][gain_set_idx];
- pstr_drc_compand->nb_segments = (pstr_drc_compand->nb_points + 4) * 2;
-
for (i = 0; i < pstr_drc_compand->nb_points; i++) {
if (i && pstr_drc_compand->str_segment[2 * ((i - 1) + 1)].x >
pstr_drc_compand->str_segment[2 * ((i) + 1)].x) {
@@ -161,6 +166,7 @@ IA_ERRORCODE impd_drc_td_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_gai
}
}
+ pstr_drc_compand->nb_segments = num_points * 2;
for (i = 0; i < pstr_drc_compand->nb_segments; i += 2) {
pstr_drc_compand->str_segment[i].y += pstr_drc_compand->gain_db;
pstr_drc_compand->str_segment[i].x *= M_LN10_DIV_20;
@@ -168,35 +174,33 @@ IA_ERRORCODE impd_drc_td_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_gai
}
for (i = 4; i < pstr_drc_compand->nb_segments; i += 2) {
+ FLOAT64 num = 0.0;
+ FLOAT64 den = 0.0f;
+
+ num = pstr_drc_compand->str_segment[i - 2].y - pstr_drc_compand->str_segment[i - 4].y;
+ den = pstr_drc_compand->str_segment[i - 2].x - pstr_drc_compand->str_segment[i - 4].x;
+ length = hypot(num, den);
+ if (length < FLT_EPSILON) {
+ return IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_GAIN_POINTS;
+ }
pstr_drc_compand->str_segment[i - 4].a = 0;
- pstr_drc_compand->str_segment[i - 4].b =
- (pstr_drc_compand->str_segment[i - 2].y - pstr_drc_compand->str_segment[i - 4].y) /
- (pstr_drc_compand->str_segment[i - 2].x - pstr_drc_compand->str_segment[i - 4].x);
-
- pstr_drc_compand->str_segment[i - 2].a = 0;
- pstr_drc_compand->str_segment[i - 2].b =
- (pstr_drc_compand->str_segment[i].y - pstr_drc_compand->str_segment[i - 2].y) /
- (pstr_drc_compand->str_segment[i].x - pstr_drc_compand->str_segment[i - 2].x);
-
- theta =
- atan2(pstr_drc_compand->str_segment[i - 2].y - pstr_drc_compand->str_segment[i - 4].y,
- pstr_drc_compand->str_segment[i - 2].x - pstr_drc_compand->str_segment[i - 4].x);
- length =
- hypot(pstr_drc_compand->str_segment[i - 2].x - pstr_drc_compand->str_segment[i - 4].x,
- pstr_drc_compand->str_segment[i - 2].y - pstr_drc_compand->str_segment[i - 4].y);
-
+ pstr_drc_compand->str_segment[i - 4].b = ixheaace_div64(num, den);
+ theta = atan2(num, den);
r = MIN(radius, length);
pstr_drc_compand->str_segment[i - 3].x =
pstr_drc_compand->str_segment[i - 2].x - r * cos(theta);
pstr_drc_compand->str_segment[i - 3].y =
pstr_drc_compand->str_segment[i - 2].y - r * sin(theta);
- theta =
- atan2(pstr_drc_compand->str_segment[i].y - pstr_drc_compand->str_segment[i - 2].y,
- pstr_drc_compand->str_segment[i - 0].x - pstr_drc_compand->str_segment[i - 2].x);
- length = hypot(pstr_drc_compand->str_segment[i].x - pstr_drc_compand->str_segment[i - 2].x,
- pstr_drc_compand->str_segment[i].y - pstr_drc_compand->str_segment[i - 2].y);
-
+ num = pstr_drc_compand->str_segment[i].y - pstr_drc_compand->str_segment[i - 2].y;
+ den = pstr_drc_compand->str_segment[i].x - pstr_drc_compand->str_segment[i - 2].x;
+ length = hypot(num, den);
+ if (length < FLT_EPSILON) {
+ return IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_GAIN_POINTS;
+ }
+ pstr_drc_compand->str_segment[i - 2].a = 0;
+ pstr_drc_compand->str_segment[i - 2].b = ixheaace_div64(num, den);
+ theta = atan2(num, den);
r = MIN(radius, length / 2);
x = pstr_drc_compand->str_segment[i - 2].x + r * cos(theta);
y = pstr_drc_compand->str_segment[i - 2].y + r * sin(theta);
@@ -213,9 +217,14 @@ IA_ERRORCODE impd_drc_td_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_gai
out_1 = cy - pstr_drc_compand->str_segment[i - 3].y;
inp_2 = pstr_drc_compand->str_segment[i - 2].x - pstr_drc_compand->str_segment[i - 3].x;
out_2 = pstr_drc_compand->str_segment[i - 2].y - pstr_drc_compand->str_segment[i - 3].y;
- pstr_drc_compand->str_segment[i - 3].a = (out_2 / inp_2 - out_1 / inp_1) / (inp_2 - inp_1);
- pstr_drc_compand->str_segment[i - 3].b =
- out_1 / inp_1 - pstr_drc_compand->str_segment[i - 3].a * inp_1;
+
+ num = (out_2 * inp_1) - (inp_2 * out_1);
+ den = (inp_2 - inp_1) * inp_1 * inp_2;
+ pstr_drc_compand->str_segment[i - 3].a = ixheaace_div64(num, den);
+
+ num = out_1 - (pstr_drc_compand->str_segment[i - 3].a * inp_1 * inp_1);
+ den = inp_1;
+ pstr_drc_compand->str_segment[i - 3].b = ixheaace_div64(num, den);
}
pstr_drc_compand->str_segment[i - 3].x = 0;
pstr_drc_compand->str_segment[i - 3].y = pstr_drc_compand->str_segment[i - 3].y;
@@ -325,7 +334,7 @@ IA_ERRORCODE impd_drc_stft_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_g
WORD32 gain_set_idx, WORD32 band_idx) {
ULOOPIDX i, j;
UWORD32 num_points;
- FLOAT32 width_e;
+ FLOAT32 width_e, tmp;
FLOAT64 g1, g2;
FLOAT64 x, y, cx, cy, r;
FLOAT64 inp_1, inp_2, out_1, out_2, theta, len;
@@ -343,8 +352,6 @@ IA_ERRORCODE impd_drc_stft_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_g
width_e = (FLOAT32)(pstr_drc_stft_gain_handle->width_db * M_LN10_DIV_20);
- pstr_drc_stft_gain_handle->nb_segments = (pstr_drc_stft_gain_handle->nb_points + 4) * 2;
-
for (i = 0; i < pstr_drc_stft_gain_handle->nb_points; i++) {
if (i && pstr_drc_stft_gain_handle->str_segment[2 * ((i - 1) + 1)].x >
pstr_drc_stft_gain_handle->str_segment[2 * (i + 1)].x) {
@@ -384,7 +391,7 @@ IA_ERRORCODE impd_drc_stft_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_g
pstr_drc_stft_gain_handle->str_segment[2 * (j + 1)];
}
}
-
+ pstr_drc_stft_gain_handle->nb_segments = num_points * 2;
for (i = 0; i < pstr_drc_stft_gain_handle->nb_segments; i += 2) {
pstr_drc_stft_gain_handle->str_segment[i].y += pstr_drc_stft_gain_handle->gain_db;
pstr_drc_stft_gain_handle->str_segment[i].x *= M_LN10_DIV_20;
@@ -392,42 +399,39 @@ IA_ERRORCODE impd_drc_stft_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_g
}
for (i = 4; i < pstr_drc_stft_gain_handle->nb_segments; i += 2) {
+ FLOAT64 denominator;
+ FLOAT64 numerator;
+
+ denominator = pstr_drc_stft_gain_handle->str_segment[i - 2].x -
+ pstr_drc_stft_gain_handle->str_segment[i - 4].x;
+ numerator = pstr_drc_stft_gain_handle->str_segment[i - 2].y -
+ pstr_drc_stft_gain_handle->str_segment[i - 4].y;
+ len = hypot(denominator , numerator);
+ if (len < FLT_EPSILON) {
+ return IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_GAIN_POINTS;
+ }
pstr_drc_stft_gain_handle->str_segment[i - 4].a = 0;
- pstr_drc_stft_gain_handle->str_segment[i - 4].b =
- (pstr_drc_stft_gain_handle->str_segment[i - 2].y -
- pstr_drc_stft_gain_handle->str_segment[i - 4].y) /
- (pstr_drc_stft_gain_handle->str_segment[i - 2].x -
- pstr_drc_stft_gain_handle->str_segment[i - 4].x);
+ pstr_drc_stft_gain_handle->str_segment[i - 4].b = ixheaace_div64(numerator, denominator);
+ theta = atan2(numerator, denominator);
+ r = MIN(width_e / (2.0f * cos(theta)), len / 2);
- pstr_drc_stft_gain_handle->str_segment[i - 2].a = 0;
- pstr_drc_stft_gain_handle->str_segment[i - 2].b =
- (pstr_drc_stft_gain_handle->str_segment[i].y -
- pstr_drc_stft_gain_handle->str_segment[i - 2].y) /
- (pstr_drc_stft_gain_handle->str_segment[i].x -
- pstr_drc_stft_gain_handle->str_segment[i - 2].x);
-
- theta = atan2(pstr_drc_stft_gain_handle->str_segment[i - 2].y -
- pstr_drc_stft_gain_handle->str_segment[i - 4].y,
- pstr_drc_stft_gain_handle->str_segment[i - 2].x -
- pstr_drc_stft_gain_handle->str_segment[i - 4].x);
- len = hypot(pstr_drc_stft_gain_handle->str_segment[i - 2].x -
- pstr_drc_stft_gain_handle->str_segment[i - 4].x,
- pstr_drc_stft_gain_handle->str_segment[i - 2].y -
- pstr_drc_stft_gain_handle->str_segment[i - 4].y);
- r = MIN(width_e / (2.0f * cos(theta)), len);
pstr_drc_stft_gain_handle->str_segment[i - 3].x =
- pstr_drc_stft_gain_handle->str_segment[i - 2].x - r * cos(theta);
+ pstr_drc_stft_gain_handle->str_segment[i - 2].x - r * cos(theta);
pstr_drc_stft_gain_handle->str_segment[i - 3].y =
- pstr_drc_stft_gain_handle->str_segment[i - 2].y - r * sin(theta);
-
- theta = atan2(pstr_drc_stft_gain_handle->str_segment[i].y -
- pstr_drc_stft_gain_handle->str_segment[i - 2].y,
- pstr_drc_stft_gain_handle->str_segment[i].x -
- pstr_drc_stft_gain_handle->str_segment[i - 2].x);
- len = hypot(pstr_drc_stft_gain_handle->str_segment[i].x -
- pstr_drc_stft_gain_handle->str_segment[i - 2].x,
- pstr_drc_stft_gain_handle->str_segment[i].y -
- pstr_drc_stft_gain_handle->str_segment[i - 2].y);
+ pstr_drc_stft_gain_handle->str_segment[i - 2].y - r * sin(theta);
+
+ denominator = pstr_drc_stft_gain_handle->str_segment[i].x -
+ pstr_drc_stft_gain_handle->str_segment[i - 2].x;
+ numerator = pstr_drc_stft_gain_handle->str_segment[i].y -
+ pstr_drc_stft_gain_handle->str_segment[i - 2].y;
+ len = hypot(denominator, numerator);
+ if (len < FLT_EPSILON) {
+ return IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_GAIN_POINTS;
+ }
+ pstr_drc_stft_gain_handle->str_segment[i - 2].a = 0;
+ pstr_drc_stft_gain_handle->str_segment[i - 2].b = ixheaace_div64(numerator, denominator);
+
+ theta = atan2(numerator, denominator);
r = MIN(width_e / (2.0f * cos(theta)), len / 2);
x = pstr_drc_stft_gain_handle->str_segment[i - 2].x + r * cos(theta);
y = pstr_drc_stft_gain_handle->str_segment[i - 2].y + r * sin(theta);
@@ -448,10 +452,13 @@ IA_ERRORCODE impd_drc_stft_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_g
pstr_drc_stft_gain_handle->str_segment[i - 3].x;
out_2 = pstr_drc_stft_gain_handle->str_segment[i - 2].y -
pstr_drc_stft_gain_handle->str_segment[i - 3].y;
- pstr_drc_stft_gain_handle->str_segment[i - 3].a =
- (out_2 / inp_2 - out_1 / inp_1) / (inp_2 - inp_1);
- pstr_drc_stft_gain_handle->str_segment[i - 3].b =
- out_1 / inp_1 - pstr_drc_stft_gain_handle->str_segment[i - 3].a * inp_1;
+ numerator = (out_2 * inp_1) - (inp_2 * out_1);
+ denominator = (inp_2 - inp_1) * inp_2 * inp_1;
+ pstr_drc_stft_gain_handle->str_segment[i - 3].a = ixheaace_div64(numerator, denominator);
+
+ numerator = out_1 - (pstr_drc_stft_gain_handle->str_segment[i - 3].a * inp_1 * inp_1);
+ denominator = inp_1;
+ pstr_drc_stft_gain_handle->str_segment[i - 3].b = ixheaace_div64(numerator, denominator);
}
pstr_drc_stft_gain_handle->str_segment[i - 3].x = 0;
pstr_drc_stft_gain_handle->str_segment[i - 3].y =
@@ -470,13 +477,23 @@ IA_ERRORCODE impd_drc_stft_drc_gain_calc_init(ia_drc_gain_enc_struct *pstr_drc_g
pstr_drc_stft_gain_handle->yl_z1[i] = 0.0f;
}
- pstr_drc_stft_gain_handle->alpha_a =
- expf(-1.0f / ((pstr_drc_stft_gain_handle->attack_ms / (FLOAT32)STFT256_HOP_SIZE) *
- (FLOAT32)pstr_drc_gain_enc->sample_rate * 0.001f));
+ tmp = (pstr_drc_stft_gain_handle->attack_ms / STFT256_HOP_SIZE) *
+ pstr_drc_gain_enc->sample_rate * 0.001f;
+ if ((fabs(tmp) < FLT_EPSILON) && (tmp >= 0.0f)) {
+ pstr_drc_stft_gain_handle->alpha_a = 0;
+ }
+ else {
+ pstr_drc_stft_gain_handle->alpha_a = expf(ixheaace_div32(-1.0f, tmp));
+ }
- pstr_drc_stft_gain_handle->alpha_r =
- expf(-1.0f / ((pstr_drc_stft_gain_handle->release_ms / (FLOAT32)STFT256_HOP_SIZE) *
- (FLOAT32)pstr_drc_gain_enc->sample_rate * 0.001f));
+ tmp = (pstr_drc_stft_gain_handle->release_ms / STFT256_HOP_SIZE) *
+ pstr_drc_gain_enc->sample_rate * 0.001f;
+ if ((fabs(tmp) < FLT_EPSILON) && (tmp >= 0.0f)) {
+ pstr_drc_stft_gain_handle->alpha_r = 0;
+ }
+ else {
+ pstr_drc_stft_gain_handle->alpha_r = expf(ixheaace_div32(-1.0f, tmp));
+ }
return IA_NO_ERROR;
}
diff --git a/encoder/drc_src/impd_drc_gain_enc.c b/encoder/drc_src/impd_drc_gain_enc.c
index fd10488..3ea9cf4 100644
--- a/encoder/drc_src/impd_drc_gain_enc.c
+++ b/encoder/drc_src/impd_drc_gain_enc.c
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <string.h>
#include <math.h>
+#include <float.h>
#include "ixheaac_type_def.h"
#include "ixheaac_error_standards.h"
#include "ixheaace_error_codes.h"
@@ -44,6 +45,7 @@
#include "ixheaace_sbr_header.h"
#include "ixheaace_config.h"
#include "iusace_config.h"
+#include "ixheaace_common_utils.h"
static FLOAT32 impd_drc_limit_drc_gain(const WORD32 gain_coding_profile, const FLOAT32 gain) {
FLOAT32 limited_drc_gain;
@@ -128,7 +130,7 @@ static VOID impd_drc_check_overshoot(const WORD32 t_gain_step, const FLOAT32 gai
FLOAT32 k1, k2;
FLOAT32 slope_norm = 1.0f / (FLOAT32)time_delta_min;
FLOAT32 margin = 0.2f;
- FLOAT32 step_inv_2 = 2.0f / t_gain_step;
+ FLOAT32 step_inv_2 = ixheaace_div32(2.0f, (FLOAT32)t_gain_step);
*overshoot_left = FALSE;
*overshoot_right = FALSE;
@@ -180,7 +182,7 @@ static VOID impd_drc_check_overshoot(const WORD32 t_gain_step, const FLOAT32 gai
}
if ((!*overshoot_left) && (!*overshoot_right)) {
- t_gain_step_inv = 1.0f / (FLOAT32)t_gain_step;
+ t_gain_step_inv = ixheaace_div32(1.0f, (FLOAT32)t_gain_step);
t_gain_step_inv_2 = t_gain_step_inv * t_gain_step_inv;
k1 = (gain_right - gain_left) * t_gain_step_inv_2;
k2 = norm_slope_1 + norm_slope_0;
diff --git a/encoder/iusace_enc_main.c b/encoder/iusace_enc_main.c
index 027756e..fa2a0ac 100644
--- a/encoder/iusace_enc_main.c
+++ b/encoder/iusace_enc_main.c
@@ -78,6 +78,7 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
@@ -92,7 +93,6 @@
#include "ixheaace_sbr_ton_corr.h"
#include "iusace_esbr_pvc.h"
#include "iusace_esbr_inter_tes.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr.h"
#include "ixheaace_sbr_cmondata.h"
#include "ixheaace_sbr_crc.h"
@@ -507,7 +507,7 @@ WORD32 iusace_limitbitrate(WORD32 core_sample_rate, WORD32 frame_len, WORD32 num
IA_ERRORCODE iusace_enc_init(ia_usac_encoder_config_struct *ptr_usac_config,
ixheaace_audio_specific_config_struct *pstr_asc,
ia_usac_data_struct *pstr_state) {
- WORD32 err_code = 0;
+ IA_ERRORCODE err_code = IA_NO_ERROR;
WORD32 i, j, k, idx, i_ch;
UWORD32 elem_idx = 0;
ia_usac_data_struct *usac_data = (pstr_state);
@@ -557,20 +557,25 @@ 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;
}
- ia_usac_enc_element_config_struct *pstr_usac_elem_config =
+ if (ptr_usac_config->use_drc_element) {
+ ia_usac_enc_element_config_struct *pstr_usac_elem_config =
&(pstr_asc_usac_config->str_usac_element_config[pstr_asc_usac_config->num_elements]);
- pstr_asc_usac_config->usac_element_type[pstr_asc_usac_config->num_elements] = ID_USAC_EXT;
- pstr_usac_elem_config->usac_ext_ele_type = ID_EXT_ELE_UNI_DRC;
- pstr_usac_elem_config->usac_ext_ele_dflt_len_present = 0;
- pstr_usac_elem_config->usac_ext_ele_payload_present = 0;
- pstr_usac_elem_config->drc_config_data = usac_data->str_drc_state.bit_buf_base_cfg;
- pstr_usac_elem_config->usac_ext_ele_cfg_len =
+ pstr_asc_usac_config->usac_element_type[pstr_asc_usac_config->num_elements] = ID_USAC_EXT;
+ pstr_usac_elem_config->usac_ext_ele_type = ID_EXT_ELE_UNI_DRC;
+ pstr_usac_elem_config->usac_ext_ele_dflt_len_present = 0;
+ pstr_usac_elem_config->usac_ext_ele_payload_present = 0;
+ pstr_usac_elem_config->drc_config_data = usac_data->str_drc_state.bit_buf_base_cfg;
+ pstr_usac_elem_config->usac_ext_ele_cfg_len =
(usac_data->str_drc_state.drc_config_data_size_bit + 7) >> 3;
- pstr_asc_usac_config->num_elements++;
+ pstr_asc_usac_config->num_elements++;
+ }
}
if (ptr_usac_config->use_drc_element) // For Loudness
{
@@ -620,7 +625,7 @@ IA_ERRORCODE iusace_enc_init(ia_usac_encoder_config_struct *ptr_usac_config,
case ID_USAC_EXT:
break;
default:
- return -1;
+ return IA_EXHEAACE_INIT_FATAL_USAC_INVALID_ELEMENT_TYPE;
}
}
@@ -640,7 +645,7 @@ IA_ERRORCODE iusace_enc_init(ia_usac_encoder_config_struct *ptr_usac_config,
case ID_USAC_EXT:
break;
default:
- return -1;
+ return IA_EXHEAACE_INIT_FATAL_USAC_INVALID_ELEMENT_TYPE;
}
usac_data->str_qc_main.str_qc_data[ch_idx].num_ch = 1;
@@ -769,12 +774,14 @@ IA_ERRORCODE iusace_enc_init(ia_usac_encoder_config_struct *ptr_usac_config,
usac_data->pstr_tns_info[i_ch]->max_sfb_long =
usac_data->str_psy_mod.str_psy_long_config[ch_idx].sfb_count;
- if (iusace_tns_init(ptr_usac_config->core_sample_rate,
+ err_code = iusace_tns_init(ptr_usac_config->core_sample_rate,
usac_data->str_qc_main.str_qc_data[ch_idx].ch_bitrate /
usac_data->str_qc_main.str_qc_data[ch_idx].num_ch,
usac_data->pstr_tns_info[i_ch],
- usac_data->str_qc_main.str_qc_data[ch_idx].num_ch))
- return -1;
+ usac_data->str_qc_main.str_qc_data[ch_idx].num_ch);
+ if (err_code) {
+ return err_code;
+ }
}
}
}
@@ -934,7 +941,8 @@ IA_ERRORCODE ixheaace_usac_encode(FLOAT32 **ptr_input,
ia_usac_data_struct *pstr_state,
ixheaace_audio_specific_config_struct *pstr_asc,
ia_bit_buf_struct *pstr_it_bit_buff,
- ixheaace_pstr_sbr_enc ptr_env_encoder, FLOAT32 **pp_drc_inp) {
+ ixheaace_pstr_sbr_enc ptr_env_encoder, FLOAT32 **pp_drc_inp,
+ WORD32 *is_quant_spec_zero, WORD32 *is_gain_limited) {
IA_ERRORCODE err = IA_NO_ERROR;
WORD32 i_ch, i, k;
ia_usac_data_struct *ptr_usac_data = pstr_state;
@@ -1026,7 +1034,7 @@ IA_ERRORCODE ixheaace_usac_encode(FLOAT32 **ptr_input,
ptr_usac_data->core_mode_next[i_ch] = CORE_MODE_TD;
break;
default:
- return (-1);
+ return IA_EXHEAACE_INIT_FATAL_USAC_INVALID_CODEC_MODE;
}
if (ptr_usac_data->core_mode[i_ch] == CORE_MODE_TD) {
for (i = 0; i < ptr_usac_config->ccfl; i++) {
@@ -1287,7 +1295,7 @@ IA_ERRORCODE ixheaace_usac_encode(FLOAT32 **ptr_input,
: ((ptr_usac_data->core_mode[ch_offset] == CORE_MODE_FD))) {
err = iusace_fd_encode(pstr_sfb_prms, usac_independency_flg, ptr_usac_data, ptr_usac_config,
pstr_it_bit_buff, nr_core_coder_channels, ch_offset, elem_idx,
- &bits_written);
+ &bits_written, is_quant_spec_zero, is_gain_limited);
if (err) {
return err;
@@ -1334,5 +1342,5 @@ IA_ERRORCODE ixheaace_usac_encode(FLOAT32 **ptr_input,
ptr_usac_data->available_bitreservoir_bits = ptr_usac_data->max_bitreservoir_bits;
}
- return 0;
+ return err;
}
diff --git a/encoder/iusace_fd_enc.h b/encoder/iusace_fd_enc.h
index 396f017..9f8b00d 100644
--- a/encoder/iusace_fd_enc.h
+++ b/encoder/iusace_fd_enc.h
@@ -23,4 +23,5 @@ IA_ERRORCODE iusace_fd_encode(ia_sfb_params_struct *pstr_sfb_prms, WORD32 usac_i
ia_usac_data_struct *pstr_usac_data,
ia_usac_encoder_config_struct *pstr_usac_config,
ia_bit_buf_struct *pstr_it_bit_buff, WORD32 nr_core_coder_ch,
- WORD32 chn, WORD32 ele_id, WORD32 *bit_written);
+ WORD32 chn, WORD32 ele_id, WORD32 *bit_written,
+ WORD32 *is_quant_spec_zero, WORD32* is_gain_limited);
diff --git a/encoder/iusace_fd_fac.c b/encoder/iusace_fd_fac.c
index d4c5ff9..27824a3 100644
--- a/encoder/iusace_fd_fac.c
+++ b/encoder/iusace_fd_fac.c
@@ -173,7 +173,7 @@ IA_ERRORCODE iusace_fd_fac(WORD32 *sfb_offsets, WORD32 sfb_active, FLOAT64 *orig
FLOAT32 *zir_sig = NULL;
FLOAT32 *lpc_coeffs_q = NULL;
WORD32 index;
- WORD32 low_pass_line;
+ WORD32 low_pass_line = 0;
WORD32 fac_len;
FLOAT64 *left_fac_time_data = pstr_scratch->p_left_fac_time_data;
FLOAT32 *left_fac_timedata_flt = pstr_scratch->p_left_fac_timedata_flt;
@@ -185,13 +185,17 @@ IA_ERRORCODE iusace_fd_fac(WORD32 *sfb_offsets, WORD32 sfb_active, FLOAT64 *orig
*num_fac_bits = 0;
- if (window_sequence == EIGHT_SHORT_SEQUENCE)
- fac_len = (pstr_acelp->len_frame / 16);
- else
- fac_len = (pstr_acelp->len_frame / 8);
+ if (last_subfr_was_acelp || next_frm_lpd)
+ {
+ if (window_sequence == EIGHT_SHORT_SEQUENCE)
+ fac_len = (pstr_acelp->len_frame / 16);
+ else
+ fac_len = (pstr_acelp->len_frame / 8);
+
+ low_pass_line = (WORD32)(sfb_offsets[sfb_active] * fac_len /
+ (FLOAT32)pstr_acelp->len_frame);
+ }
- low_pass_line = (WORD32)((FLOAT32)sfb_offsets[sfb_active] * (FLOAT32)fac_len /
- (FLOAT32)pstr_acelp->len_frame);
if (last_subfr_was_acelp) {
FLOAT32 *tmp_lp_res = pstr_scratch->ptr_tmp_lp_res;
FLOAT32 lpc_coeffs[ORDER + 1];
diff --git a/encoder/iusace_fd_qc_adjthr.h b/encoder/iusace_fd_qc_adjthr.h
index dd90b72..b7310dc 100644
--- a/encoder/iusace_fd_qc_adjthr.h
+++ b/encoder/iusace_fd_qc_adjthr.h
@@ -46,6 +46,11 @@
#define BITS_SPEND_RATIO_LONG (MIN_TO_MAX_SPEND_BITS_LONG / CLIP_SPEND_LO_TO_HI_LONG)
#define BITS_SPEND_RATIO_SHORT (MIN_TO_MAX_SPEND_BITS_SHORT / CLIP_SPEND_LO_TO_HI_SHORT)
+#define MAX_GAIN_INDEX (128)
+#define MIN_GAIN_INDEX (-128)
+#define SCF_COUNT_LIMIT_ONE (1)
+#define SCF_COUNT_LIMIT_THREE (3)
+
typedef struct {
FLOAT32 *sfb_ld_energy;
FLOAT32 *sfb_lines;
diff --git a/encoder/iusace_fft.c b/encoder/iusace_fft.c
index 0365f11..d17d208 100644
--- a/encoder/iusace_fft.c
+++ b/encoder/iusace_fft.c
@@ -45,6 +45,8 @@
#include "ixheaace_aac_constants.h"
#include "ixheaac_basic_ops32.h"
#include "ixheaace_common_utils.h"
+#include "ixheaac_error_standards.h"
+#include "ixheaace_error_codes.h"
#define DIG_REV(i, m, j) \
do { \
@@ -909,7 +911,7 @@ IA_ERRORCODE iusace_fft_based_mdct(FLOAT64 *ptr_in, FLOAT64 *ptr_out, WORD32 npo
sin_ptr = iusace_pre_post_twid_sin_2048;
break;
default:
- return -1;
+ return IA_EXHEAACE_EXE_FATAL_USAC_INVALID_WINDOW_LENGTH;
}
/* pre-twiddle */
@@ -921,7 +923,7 @@ IA_ERRORCODE iusace_fft_based_mdct(FLOAT64 *ptr_in, FLOAT64 *ptr_out, WORD32 npo
/* post-twiddle */
iusace_calc_post_twid_enc(ptr_out, ptr_scratch1, npoints << 1, cos_ptr, sin_ptr, tx_flag);
- return 0;
+ return IA_NO_ERROR;
}
VOID iusace_complex_fft_2048(FLOAT32 *ptr_x, FLOAT32 *scratch_fft) {
diff --git a/encoder/iusace_lpd_enc.c b/encoder/iusace_lpd_enc.c
index 190771e..2ff2977 100644
--- a/encoder/iusace_lpd_enc.c
+++ b/encoder/iusace_lpd_enc.c
@@ -54,6 +54,7 @@
#include "iusace_lpd_rom.h"
#include "iusace_lpd.h"
#include "iusace_func_prototypes.h"
+#include "ixheaac_error_standards.h"
VOID iusace_init_td_data(ia_usac_td_encoder_struct *st, WORD32 len_frame) {
WORD32 len_window;
@@ -809,5 +810,5 @@ IA_ERRORCODE iusace_lpd_frm_enc(ia_usac_data_struct *usac_data, WORD32 *mod_out,
td_encoder->prev_mode = (WORD16)mode[3];
memcpy(mod_out, mode, 4 * sizeof(WORD32));
- return 0;
+ return IA_NO_ERROR;
}
diff --git a/encoder/iusace_main.h b/encoder/iusace_main.h
index bf8b9e5..dcacb14 100644
--- a/encoder/iusace_main.h
+++ b/encoder/iusace_main.h
@@ -111,7 +111,8 @@ IA_ERRORCODE iusace_quantize_spec(ia_sfb_params_struct *pstr_sfb_prms,
WORD32 usac_independancy_flag, WORD32 num_chans,
ia_usac_data_struct *ptr_usac_data,
ia_usac_encoder_config_struct *ptr_usac_config, WORD32 chn,
- WORD32 ele_id);
+ WORD32 ele_id, WORD32 *is_quant_spec_zero,
+ WORD32 *is_gain_limited);
IA_ERRORCODE iusace_grouping(ia_sfb_params_struct *pstr_sfb_prms, WORD32 num_chans,
ia_usac_data_struct *ptr_usac_data,
diff --git a/encoder/iusace_psy_utils.c b/encoder/iusace_psy_utils.c
index bb03c15..8c0d040 100644
--- a/encoder/iusace_psy_utils.c
+++ b/encoder/iusace_psy_utils.c
@@ -45,6 +45,8 @@
#include "iusace_psy_utils.h"
#include "iusace_fd_qc_util.h"
#include "iusace_fd_qc_adjthr.h"
+#include "ixheaac_error_standards.h"
+#include "ixheaace_error_codes.h"
extern ia_sfb_info_struct iusace_sfb_info_1024[12];
extern ia_sfb_info_struct iusace_sfb_info_768[12];
@@ -508,12 +510,12 @@ IA_ERRORCODE iusace_sfb_params_init(WORD32 sample_rate, WORD32 frame_len, WORD32
} else if (sample_rate >= 92017) {
sampling_rate_mapped = 96000;
} else {
- return -1;
+ return IA_EXHEAACE_INIT_FATAL_USAC_INVALID_CORE_SAMPLE_RATE;
}
while (ptr_sr_info->sample_rate != sampling_rate_mapped) {
if (ptr_sr_info->sample_rate == -1) {
- return -1;
+ return IA_EXHEAACE_INIT_FATAL_USAC_INVALID_CORE_SAMPLE_RATE;
}
ptr_sr_info++;
}
@@ -546,5 +548,5 @@ IA_ERRORCODE iusace_sfb_params_init(WORD32 sample_rate, WORD32 frame_len, WORD32
break;
}
- return 0;
+ return IA_NO_ERROR;
}
diff --git a/encoder/iusace_tcx_enc.c b/encoder/iusace_tcx_enc.c
index e2ec7f8..b3268a4 100644
--- a/encoder/iusace_tcx_enc.c
+++ b/encoder/iusace_tcx_enc.c
@@ -157,18 +157,18 @@ UWORD32 iusace_rounded_sqrt(UWORD32 pos_num) {
return value;
}
-static VOID iusace_noise_shaping(FLOAT32 *rr, WORD32 lg, FLOAT32 *gain1, FLOAT32 *gain2) {
+static VOID iusace_noise_shaping(FLOAT32 *rr, WORD32 lg, WORD32 M, FLOAT32 *gain1,
+ FLOAT32 *gain2) {
WORD32 i, k;
FLOAT32 r, r_prev, g1, g2, a = 0, b = 0;
- k = lg / FDNS_RESOLUTION;
+ k = lg/M;
r_prev = 0;
for (i = 0; i < lg; i++) {
if ((i % k) == 0) {
g1 = gain1[i / k];
g2 = gain2[i / k];
-
a = 2.0f * g1 * g2 / (g1 + g2);
b = (g2 - g1) / (g1 + g2);
}
@@ -182,11 +182,11 @@ static VOID iusace_noise_shaping(FLOAT32 *rr, WORD32 lg, FLOAT32 *gain1, FLOAT32
return;
}
-static VOID iusace_pre_shaping(FLOAT32 *rr, WORD32 lg, FLOAT32 *gain1, FLOAT32 *gain2) {
+static VOID iusace_pre_shaping(FLOAT32 *rr, WORD32 lg, WORD32 M, FLOAT32 *gain1, FLOAT32 *gain2) {
WORD32 i, k;
FLOAT32 r, r_prev, g1, g2, a = 0, b = 0;
- k = lg / FDNS_RESOLUTION;
+ k = lg / M;
r_prev = 0;
for (i = 0; i < lg; i++) {
@@ -439,7 +439,7 @@ VOID iusace_tcx_fac_encode(ia_usac_data_struct *usac_data, FLOAT32 *lpc_coeffs,
iusace_lpc_mdct(lp_flt_coeffs, gain2, ((FDNS_RESOLUTION * len_subfrm) / LEN_FRAME) << 1,
pstr_scratch);
- iusace_pre_shaping(x, lg, gain1, gain2);
+ iusace_pre_shaping(x, lg, ((FDNS_RESOLUTION * len_subfrm) / LEN_FRAME), gain1, gain2);
for (i = 0; i < lg; i++) {
x_tmp[i] = x[i];
@@ -584,7 +584,7 @@ VOID iusace_tcx_fac_encode(ia_usac_data_struct *usac_data, FLOAT32 *lpc_coeffs,
params[0] = index;
- iusace_noise_shaping(x, lg, gain1, gain2);
+ iusace_noise_shaping(x, lg, ((FDNS_RESOLUTION * len_subfrm) / LEN_FRAME), gain1, gain2);
iusace_tcx_imdct(x, xn_buf, (2 * fac_length), frame_len - (2 * fac_length), (2 * fac_length),
pstr_scratch);
diff --git a/encoder/iusace_tns_usac.c b/encoder/iusace_tns_usac.c
index cb62a4f..22a72a6 100644
--- a/encoder/iusace_tns_usac.c
+++ b/encoder/iusace_tns_usac.c
@@ -30,6 +30,8 @@
#include "ixheaac_basic_ops32.h"
#include "ixheaac_basic_ops40.h"
#include "ixheaac_basic_ops.h"
+#include "ixheaac_error_standards.h"
+#include "ixheaace_error_codes.h"
static const WORD32 iusace_tns_supported_sampling_rates[13] = {
96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 0};
@@ -92,6 +94,7 @@ static VOID iusace_calc_gauss_win(FLOAT64 *ptr_win, const WORD32 length, const W
IA_ERRORCODE iusace_tns_init(WORD32 sampling_rate, WORD32 bit_rate, ia_tns_info *tns_info,
WORD32 num_channels) {
+ IA_ERRORCODE err_code = IA_NO_ERROR;
WORD32 fs_index = 0;
WORD32 lpc_stop_freq = 16000;
WORD32 lpc_start_freq_long = 2500, lpc_start_freq_short = 3750;
@@ -127,7 +130,7 @@ IA_ERRORCODE iusace_tns_init(WORD32 sampling_rate, WORD32 bit_rate, ia_tns_info
*/
while (sampling_rate != iusace_tns_supported_sampling_rates[fs_index]) {
if (!iusace_tns_supported_sampling_rates[fs_index]) {
- return -1;
+ return IA_EXHEAACE_INIT_FATAL_USAC_INVALID_CORE_SAMPLE_RATE;
}
fs_index++;
}
@@ -159,7 +162,7 @@ IA_ERRORCODE iusace_tns_init(WORD32 sampling_rate, WORD32 bit_rate, ia_tns_info
iusace_calc_gauss_win(tns_info->win_short, tns_info->tns_max_order_short + 1, sampling_rate,
EIGHT_SHORT_SEQUENCE, tns_info->tns_time_res_short);
- return 0;
+ return err_code;
}
VOID iusace_tns_filter(WORD32 length, FLOAT64 *spec, ia_tns_filter_data *filter,
diff --git a/encoder/iusace_windowing.c b/encoder/iusace_windowing.c
index 4bed683..a770686 100644
--- a/encoder/iusace_windowing.c
+++ b/encoder/iusace_windowing.c
@@ -19,11 +19,12 @@
*/
#include <string.h>
-
+#include "ixheaac_error_standards.h"
#include "ixheaac_type_def.h"
#include "iusace_cnst.h"
#include "iusace_block_switch_const.h"
#include "iusace_rom.h"
+#include "ixheaace_error_codes.h"
IA_ERRORCODE iusace_calc_window(FLOAT64 **win, WORD32 win_sz, WORD32 win_sel) {
switch (win_sel) {
@@ -48,7 +49,7 @@ IA_ERRORCODE iusace_calc_window(FLOAT64 **win, WORD32 win_sz, WORD32 win_sel) {
*win = (FLOAT64 *)iusace_sine_win_1024;
break;
default:
- return -1;
+ return IA_EXHEAACE_EXE_FATAL_USAC_INVALID_WINDOW_LENGTH;
break;
}
break;
@@ -73,16 +74,16 @@ IA_ERRORCODE iusace_calc_window(FLOAT64 **win, WORD32 win_sz, WORD32 win_sel) {
*win = (FLOAT64 *)iusace_kbd_win1024;
break;
default:
- return -1;
+ return IA_EXHEAACE_EXE_FATAL_USAC_INVALID_WINDOW_LENGTH;
break;
}
break;
default:
- return -1;
+ return IA_EXHEAACE_EXE_FATAL_USAC_INVALID_WINDOW_SHAPE;
break;
}
- return 0;
+ return IA_NO_ERROR;
}
VOID iusace_windowing_long(FLOAT64 *ptr_overlap, FLOAT64 *ptr_win_long, FLOAT64 *ptr_win_buf,
diff --git a/encoder/ixheaace_aac_constants.h b/encoder/ixheaace_aac_constants.h
index 40e779a..8c96a2f 100644
--- a/encoder/ixheaace_aac_constants.h
+++ b/encoder/ixheaace_aac_constants.h
@@ -118,4 +118,5 @@ typedef struct {
#define MIN_NUM_CORE_CODER_CHANNELS (1)
/*-------------------------- defines --------------------------------------*/
-#define BUFFERSIZE 1024 /* anc data */ \ No newline at end of file
+#define BUFFERSIZE 1024 /* anc data */
+#define MAX_GAIN_INDEX (128) \ No newline at end of file
diff --git a/encoder/ixheaace_adjust_threshold.c b/encoder/ixheaace_adjust_threshold.c
index 670a33e..9e4e91c 100644
--- a/encoder/ixheaace_adjust_threshold.c
+++ b/encoder/ixheaace_adjust_threshold.c
@@ -18,6 +18,7 @@
* Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
+#include <float.h>
#include <math.h>
#include <stdlib.h>
@@ -261,10 +262,13 @@ static FLOAT32 iaace_bitres_calc_bitfac(const WORD32 bitres_bits, const WORD32 m
ia_adj_thr_elem_struct *pstr_adj_the_elem) {
ia_bitres_param_struct *pstr_bitres_params;
FLOAT32 pex;
- FLOAT32 fill_lvl;
+ FLOAT32 fill_lvl = 0.0f;
FLOAT32 bit_save, bit_spend, bitres_factor;
- fill_lvl = (FLOAT32)bitres_bits / (FLOAT32)max_bitres_bits;
+ if (max_bitres_bits) {
+ fill_lvl = (FLOAT32)bitres_bits / max_bitres_bits;
+ }
+
if (win_seq != SHORT_WINDOW) {
pstr_bitres_params = &(pstr_adj_thr_state->str_bitres_params_long);
} else {
@@ -281,8 +285,11 @@ static FLOAT32 iaace_bitres_calc_bitfac(const WORD32 bitres_bits, const WORD32 m
(FLOAT32)1.0f - bit_save +
((bit_spend + bit_save) / (pstr_adj_the_elem->pe_max - pstr_adj_the_elem->pe_min)) *
(pex - pstr_adj_the_elem->pe_min);
- bitres_factor = MIN(bitres_factor,
- (FLOAT32)1.0f - (FLOAT32)0.3f + (FLOAT32)bitres_bits / (FLOAT32)avg_bits);
+ if (avg_bits)
+ {
+ bitres_factor = MIN(bitres_factor,
+ (FLOAT32)1.0f - (FLOAT32)0.3f + (FLOAT32)bitres_bits / (FLOAT32)avg_bits);
+ }
bitres_factor = MIN(bitres_factor, max_bit_fac);
@@ -851,7 +858,7 @@ static VOID iaace_adapt_thr_to_pe(
FLOAT32 const_part, const_part_no_ah;
FLOAT32 num_active_lines, num_active_lines_no_ah;
FLOAT32 desired_pe_no_ah;
- FLOAT32 avg_thr_exp, redval;
+ FLOAT32 redval = 0.0f;
WORD32 ah_flag[IXHEAACE_MAX_CH_IN_BS_ELE][MAXIMUM_GROUPED_SCALE_FACTOR_BAND];
FLOAT32 thr_exp[IXHEAACE_MAX_CH_IN_BS_ELE][MAXIMUM_GROUPED_SCALE_FACTOR_BAND];
WORD32 iteration;
@@ -863,13 +870,14 @@ static VOID iaace_adapt_thr_to_pe(
no_red_pe = pstr_qs_pe_data->pe;
const_part = pstr_qs_pe_data->const_part;
num_active_lines = pstr_qs_pe_data->num_active_lines;
- avg_thr_exp =
- (FLOAT32)pow(2.0f, (const_part - no_red_pe) / (INV_RED_EXP_VAL * num_active_lines));
- redval = (FLOAT32)pow(2.0f, (const_part - desired_pe) / (INV_RED_EXP_VAL * num_active_lines)) -
- avg_thr_exp;
- redval = MAX(0.0f, redval);
-
- iaace_reduce_thr(pstr_psy_out, ah_flag, thr_exp, redval, num_channels, chn);
+ if (num_active_lines > FLT_EPSILON) {
+ FLOAT32 avg_thr_exp =
+ (FLOAT32)pow(2.0f, (const_part - no_red_pe) / (INV_RED_EXP_VAL * num_active_lines));
+ redval = (FLOAT32)pow(2.0f, (const_part - desired_pe) / (INV_RED_EXP_VAL * num_active_lines))
+ - avg_thr_exp;
+ redval = MAX(0.0f, redval);
+ iaace_reduce_thr(pstr_psy_out, ah_flag, thr_exp, redval, num_channels, chn);
+ }
iaace_calc_sfb_pe_data(pstr_qs_pe_data, pstr_psy_out, num_channels, chn);
red_pe = pstr_qs_pe_data->pe;
@@ -881,8 +889,8 @@ static VOID iaace_adapt_thr_to_pe(
desired_pe_no_ah = MAX(desired_pe - (red_pe - red_pe_no_ah), 0);
- if (num_active_lines_no_ah > 0) {
- avg_thr_exp = (FLOAT32)pow(
+ if (num_active_lines_no_ah > FLT_EPSILON) {
+ FLOAT32 avg_thr_exp = (FLOAT32)pow(
2.0f, (const_part_no_ah - red_pe_no_ah) / (INV_RED_EXP_VAL * num_active_lines_no_ah));
redval += (FLOAT32)pow(2.0f, (const_part_no_ah - desired_pe_no_ah) /
(INV_RED_EXP_VAL * num_active_lines_no_ah)) -
diff --git a/encoder/ixheaace_api.c b/encoder/ixheaace_api.c
index 731f594..4bc7ddd 100644
--- a/encoder/ixheaace_api.c
+++ b/encoder/ixheaace_api.c
@@ -137,13 +137,9 @@
#include "ixheaace_write_adts_adif.h"
-/* Ensure all memory are aligned */
-#define IXHEAACE_ALIGN_MEMORY(address, alignment) \
- ((WORD8 *)((address + (alignment - 1)) & ~(alignment - 1)))
-
static WORD32 iusace_scratch_size(VOID) {
WORD32 scr_size;
- scr_size = USACE_MAX_SCR_SIZE;
+ scr_size = IXHEAACE_GET_SIZE_ALIGNED(USACE_MAX_SCR_SIZE, BYTE_ALIGN_8);
return scr_size;
}
@@ -151,25 +147,40 @@ static WORD32 iusace_calc_pers_buf_sizes(ixheaace_api_struct *pstr_api_struct) {
WORD32 pers_size = 0;
ia_usac_encoder_config_struct *pstr_config = &pstr_api_struct->config[0].usac_config;
- pers_size += pstr_config->channels * sizeof(FLOAT32 *);
- pers_size += pstr_config->channels * sizeof(FLOAT32 *);
- pers_size += pstr_config->channels * sizeof(FLOAT32 *);
- pers_size += pstr_config->channels * sizeof(FLOAT32 *);
+ pers_size += IXHEAACE_GET_SIZE_ALIGNED(pstr_config->channels * sizeof(FLOAT32 *), BYTE_ALIGN_8);
+ pers_size += IXHEAACE_GET_SIZE_ALIGNED(pstr_config->channels * sizeof(FLOAT32 *), BYTE_ALIGN_8);
+ pers_size += IXHEAACE_GET_SIZE_ALIGNED(pstr_config->channels * sizeof(FLOAT32 *), BYTE_ALIGN_8);
+ pers_size += IXHEAACE_GET_SIZE_ALIGNED(pstr_config->channels * sizeof(FLOAT32 *), BYTE_ALIGN_8);
- pers_size += ((2 * pstr_config->ccfl) * sizeof(FLOAT32) * pstr_config->channels);
- pers_size += ((2 * pstr_config->drc_frame_size) * sizeof(FLOAT32) * pstr_config->channels);
+ pers_size +=
+ (IXHEAACE_GET_SIZE_ALIGNED((2 * pstr_config->ccfl * sizeof(FLOAT32)), BYTE_ALIGN_8) *
+ pstr_config->channels);
+ pers_size += (IXHEAACE_GET_SIZE_ALIGNED((2 * pstr_config->drc_frame_size * sizeof(FLOAT32)),
+ BYTE_ALIGN_8) *
+ pstr_config->channels);
- pers_size += 2 * pstr_config->ccfl * sizeof(FLOAT64) * pstr_config->channels;
+ pers_size +=
+ (IXHEAACE_GET_SIZE_ALIGNED((2 * pstr_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8) *
+ pstr_config->channels);
- pers_size += pstr_config->ccfl * sizeof(FLOAT64) * pstr_config->channels;
+ pers_size += (IXHEAACE_GET_SIZE_ALIGNED((pstr_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8) *
+ pstr_config->channels);
- pers_size += 2 * pstr_config->ccfl * sizeof(FLOAT64) * pstr_config->channels;
+ pers_size +=
+ (IXHEAACE_GET_SIZE_ALIGNED((2 * pstr_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8) *
+ pstr_config->channels);
- pers_size += 3 * pstr_config->ccfl * sizeof(FLOAT64) * pstr_config->channels;
+ pers_size +=
+ (IXHEAACE_GET_SIZE_ALIGNED((3 * pstr_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8) *
+ pstr_config->channels);
- if (pstr_config->tns_select != 0) pers_size += sizeof(ia_tns_info) * pstr_config->channels;
+ if (pstr_config->tns_select != 0) {
+ pers_size +=
+ (IXHEAACE_GET_SIZE_ALIGNED(sizeof(ia_tns_info), BYTE_ALIGN_8) * pstr_config->channels);
+ }
- pers_size += sizeof(ia_usac_td_encoder_struct) * pstr_config->channels;
+ pers_size += (IXHEAACE_GET_SIZE_ALIGNED(sizeof(ia_usac_td_encoder_struct), BYTE_ALIGN_8) *
+ pstr_config->channels);
return pers_size;
}
@@ -407,8 +418,8 @@ static VOID ia_enhaacplus_enc_allocate_bitrate_between_channels(
}
}
-static WORD32 ixheaace_validate_channel_mask(WORD32 ch_mask, WORD32 num_ch) {
- if (0 == ch_mask) return 0;
+static IA_ERRORCODE ixheaace_validate_channel_mask(WORD32 ch_mask, WORD32 num_ch) {
+ IA_ERRORCODE err_code = IA_NO_ERROR;
// If ch_mask not supported, return error
WORD32 temp_mask;
switch (num_ch) {
@@ -435,10 +446,33 @@ static WORD32 ixheaace_validate_channel_mask(WORD32 ch_mask, WORD32 num_ch) {
temp_mask = 0;
break;
}
- if (ch_mask == temp_mask) {
- return 0;
- } else {
- return -1;
+ if (ch_mask != temp_mask) {
+ err_code = IA_EXHEAACE_CONFIG_FATAL_CHANNELS_MASK;
+ }
+ return err_code;
+}
+
+static VOID ixheaace_set_default_channel_mask(WORD32 *ch_mask, WORD32 num_ch) {
+ switch (num_ch) {
+ case 1:
+ *ch_mask = CH_MASK_CENTER_FRONT;
+ break;
+ case 2:
+ *ch_mask = CH_MASK_LEFT_RIGHT_FRONT;
+ break;
+ case 3:
+ *ch_mask = (CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT);
+ break;
+ case 4:
+ *ch_mask = (CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT | CH_MASK_REAR_CENTER);
+ break;
+ case 5:
+ *ch_mask = (CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT | CH_MASK_LEFT_RIGHT_BACK);
+ break;
+ case 6:
+ *ch_mask =
+ (CH_MASK_CENTER_FRONT | CH_MASK_LEFT_RIGHT_FRONT | CH_MASK_LEFT_RIGHT_BACK | CH_MASK_LFE);
+ break;
}
}
@@ -669,11 +703,6 @@ static VOID ixheaace_validate_config_params(ixheaace_input_config *pstr_input_co
}
{
- if (pstr_input_config->i_samp_freq > 64000) {
- pstr_input_config->codec_mode = USAC_ONLY_FD;
- pstr_input_config->ccfl_idx = NO_SBR_CCFL_1024;
- pstr_input_config->esbr_flag = 0;
- }
if ((pstr_input_config->codec_mode == USAC_SWITCHED ||
pstr_input_config->codec_mode == USAC_ONLY_TD) &&
pstr_input_config->i_samp_freq > 24000) {
@@ -997,7 +1026,11 @@ static IA_ERRORCODE ixheaace_set_config_params(ixheaace_api_struct *pstr_api_str
pstr_api_struct->config[0].aac_config.bit_rate = pstr_input_config->i_bitrate;
pstr_api_struct->config[0].use_parametric_stereo = 0;
}
- if (pstr_input_config->i_channels_mask != 0) {
+ if (pstr_input_config->i_channels_mask == 0) {
+ ixheaace_set_default_channel_mask(&pstr_input_config->i_channels_mask,
+ pstr_input_config->i_channels);
+ }
+ if (pstr_api_struct->config[0].aac_config.dual_mono != 1) {
if (pstr_input_config->aot != AOT_AAC_ELD || (pstr_input_config->i_use_mps != 1)) {
WORD32 num_bs_elements, chan_config[MAXIMUM_BS_ELE], element_type[MAXIMUM_BS_ELE],
element_slot[MAXIMUM_BS_ELE], element_instance_tag[MAXIMUM_BS_ELE],
@@ -1038,7 +1071,7 @@ static IA_ERRORCODE ixheaace_set_config_params(ixheaace_api_struct *pstr_api_str
}
}
}
- } else if (pstr_api_struct->config[0].aac_config.dual_mono) {
+ } else {
WORD32 num_bs_elements;
WORD32 bitrate[MAXIMUM_BS_ELE];
@@ -1134,40 +1167,46 @@ static VOID ixheaace_fill_mem_tabs(ixheaace_api_struct *pstr_api_struct, WORD32
pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_PERSIST_IDX];
{
pstr_mem_info->ui_size =
- sizeof(ixheaace_state_struct) + iusace_calc_pers_buf_sizes(pstr_api_struct);
+ IXHEAACE_GET_SIZE_ALIGNED(sizeof(ixheaace_state_struct), BYTE_ALIGN_8) +
+ iusace_calc_pers_buf_sizes(pstr_api_struct);
if (pstr_api_struct->config[0].usac_config.sbr_enable) {
pstr_mem_info->ui_size += ixheaace_sbr_enc_pers_size(
2, 0, pstr_api_struct->config[0].usac_config.sbr_harmonic);
}
- pstr_mem_info->ui_size += 2 *
- ia_enhaacplus_enc_sizeof_delay_buffer(
- 0, AOT_USAC, pstr_api_struct->config[0].ccfl_idx,
- sizeof(pstr_api_struct->pstr_state->inp_delay[0]),
- pstr_api_struct->config[0].use_mps) *
- pstr_api_struct->config[0].num_bs_elements;
+ offset_size = 2 *
+ ia_enhaacplus_enc_sizeof_delay_buffer(
+ 0, AOT_USAC, pstr_api_struct->config[0].ccfl_idx,
+ sizeof(pstr_api_struct->pstr_state->inp_delay[0]),
+ pstr_api_struct->config[0].use_mps) *
+ pstr_api_struct->config[0].num_bs_elements;
+ pstr_mem_info->ui_size += IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
if (pstr_api_struct->config[0].use_mps) {
- pstr_mem_info->ui_size +=
+ offset_size =
(MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal_mps[0]);
+ pstr_mem_info->ui_size += IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
- pstr_mem_info->ui_size +=
+ offset_size =
(MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0]);
+ pstr_mem_info->ui_size += IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
- pstr_mem_info->ui_size += sizeof(ixheaace_mps_212_memory_struct) + 7;
+ pstr_mem_info->ui_size +=
+ IXHEAACE_GET_SIZE_ALIGNED(sizeof(ixheaace_mps_212_memory_struct), BYTE_ALIGN_8);
}
if (1 == pstr_api_struct->config[0].usac_config.sbr_enable) {
- pstr_mem_info->ui_size +=
+ offset_size =
(MAX_FRAME_LEN * (1 << fac_downsample) + MAX_DS_8_1_FILTER_DELAY + INPUT_DELAY) *
MAX_CHANNELS * sizeof(pstr_mem_info->ui_size);
+ pstr_mem_info->ui_size += IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
}
if ((2 != pstr_api_struct->config[0].usac_config.channels) &&
(1 == pstr_api_struct->config[0].usac_config.sbr_enable)) {
- pstr_mem_info->ui_size +=
- (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal[0]);
+ offset_size = (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal[0]);
+ pstr_mem_info->ui_size += IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
}
}
- pstr_mem_info->ui_alignment = 8;
+ pstr_mem_info->ui_alignment = BYTE_ALIGN_8;
pstr_mem_info->ui_type = IA_MEMTYPE_PERSIST;
pstr_mem_info->ui_placement[0] = 0;
pstr_mem_info->ui_placement[1] = 0;
@@ -1187,7 +1226,7 @@ static VOID ixheaace_fill_mem_tabs(ixheaace_api_struct *pstr_api_struct, WORD32
pstr_mem_info->ui_size = usac_scr_size;
}
- pstr_mem_info->ui_alignment = 8;
+ pstr_mem_info->ui_alignment = BYTE_ALIGN_8;
pstr_mem_info->ui_type = IA_MEMTYPE_SCRATCH;
pstr_mem_info->ui_placement[0] = 0;
pstr_mem_info->ui_placement[1] = 0;
@@ -1220,7 +1259,8 @@ static VOID ixheaace_fill_mem_tabs(ixheaace_api_struct *pstr_api_struct, WORD32
}
}
- pstr_mem_info->ui_alignment = 8; /* As input is used as scratch memory internally */
+ pstr_mem_info->ui_alignment =
+ BYTE_ALIGN_8; /* As input is used as scratch memory internally */
pstr_mem_info->ui_type = IA_MEMTYPE_INPUT;
pstr_mem_info->ui_placement[0] = 0;
pstr_mem_info->ui_placement[1] = 0;
@@ -1233,7 +1273,7 @@ static VOID ixheaace_fill_mem_tabs(ixheaace_api_struct *pstr_api_struct, WORD32
{
pstr_mem_info = &pstr_api_struct->pstr_mem_info[IA_ENHAACPLUSENC_OUTPUT_IDX];
pstr_mem_info->ui_size = (MAXIMUM_CHANNEL_BITS_1024 / BYTE_NUMBIT) * num_channel;
- pstr_mem_info->ui_alignment = 8;
+ pstr_mem_info->ui_alignment = BYTE_ALIGN_8;
pstr_mem_info->ui_type = IA_MEMTYPE_OUTPUT;
pstr_mem_info->ui_placement[0] = 0;
pstr_mem_info->ui_placement[1] = 0;
@@ -1449,8 +1489,9 @@ static IA_ERRORCODE ixheaace_alloc_and_assign_mem(ixheaace_api_struct *pstr_api_
pstr_state->ptr_in_buf = (FLOAT32 **)((WORD8 *)pstr_state + offset_size);
- p_offset =
- (WORD8 *)pstr_state->ptr_in_buf + (pstr_usac_config->channels * sizeof(FLOAT32 *));
+ offset_size = pstr_usac_config->channels * sizeof(FLOAT32 *);
+ p_offset = (WORD8 *)pstr_state->ptr_in_buf +
+ IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
// Input delay
pstr_state->inp_delay = (FLOAT32 *)(p_offset);
@@ -1461,110 +1502,109 @@ static IA_ERRORCODE ixheaace_alloc_and_assign_mem(ixheaace_api_struct *pstr_api_
sizeof(pstr_state->inp_delay[0]), pstr_api_struct->config[0].use_mps) *
pstr_api_struct->config[0].num_bs_elements;
memset(pstr_state->inp_delay, 0, inp_delay_size);
- p_offset += inp_delay_size;
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED(inp_delay_size, BYTE_ALIGN_8);
if (1 == pstr_usac_config->sbr_enable) {
if (2 != pstr_usac_config->channels) {
pstr_api_struct->pstr_state->time_signal = (FLOAT32 *)(p_offset);
memset(pstr_api_struct->pstr_state->time_signal, 0,
(MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal[0]));
- p_offset += (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal[0]);
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
+ offset_size =
+ (MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal[0]);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
}
pstr_api_struct->pstr_state->spectral_band_replication_enc_pers_mem[0] =
(struct ixheaace_str_sbr_enc *)p_offset;
p_offset = p_offset + ixheaace_sbr_enc_pers_size(pstr_usac_config->channels, 0,
pstr_usac_config->sbr_harmonic);
-
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
}
if (1 == pstr_api_struct->config[0].use_mps) {
pstr_api_struct->pstr_state->time_signal_mps = (FLOAT32 *)(p_offset);
memset(pstr_api_struct->pstr_state->time_signal_mps, 0,
(MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal_mps[0]));
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
- p_offset +=
+ offset_size =
(MAX_INPUT_SAMPLES) * sizeof(pstr_api_struct->pstr_state->time_signal_mps[0]);
-
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
pstr_api_struct->pstr_state->mps_bs = (UWORD8 *)(p_offset);
memset(pstr_api_struct->pstr_state->mps_bs, 0,
(MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0]));
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
- p_offset += (MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0]);
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
+ offset_size =
+ (MAX_MPS_BS_PAYLOAD_SIZE) * sizeof(pstr_api_struct->pstr_state->mps_bs[0]);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
pstr_api_struct->pstr_state->mps_pers_mem = (ixheaace_mps_212_memory_struct *)p_offset;
- p_offset += sizeof(ixheaace_mps_212_memory_struct);
-
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
+ p_offset +=
+ IXHEAACE_GET_SIZE_ALIGNED(sizeof(ixheaace_mps_212_memory_struct), BYTE_ALIGN_8);
} else {
pstr_api_struct->pstr_state->mps_bs = NULL;
}
if (1 == pstr_usac_config->use_drc_element) {
pstr_state->pp_drc_in_buf = (FLOAT32 **)((WORD8 *)p_offset);
- p_offset += pstr_usac_config->channels * sizeof(pstr_state->pp_drc_in_buf[0]);
+ offset_size = pstr_usac_config->channels * sizeof(pstr_state->pp_drc_in_buf[0]);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED(offset_size, BYTE_ALIGN_8);
p_temp = p_offset;
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
+
for (i = 0; i < pstr_usac_config->channels; i++) {
- pstr_state->pp_drc_in_buf[i] = (FLOAT32 *)p_offset;
- p_offset +=
- pstr_usac_config->drc_frame_size * sizeof(pstr_state->pp_drc_in_buf[0][0]) * 2;
+ pstr_state->pp_drc_in_buf[i] = (FLOAT32 *)(p_offset);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED(
+ (pstr_usac_config->drc_frame_size * sizeof(pstr_state->pp_drc_in_buf[0][0]) * 2),
+ BYTE_ALIGN_8);
}
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
memset(p_temp, 0, (p_offset - p_temp));
}
p_temp = p_offset;
for (i = 0; i < pstr_usac_config->channels; i++) {
- pstr_state->ptr_in_buf[i] = (FLOAT32 *)p_offset;
- p_offset += pstr_usac_config->ccfl * sizeof(FLOAT32) * 2;
+ pstr_state->ptr_in_buf[i] = (FLOAT32 *)(p_offset);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED((pstr_usac_config->ccfl * sizeof(FLOAT32) * 2),
+ BYTE_ALIGN_8);
}
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
memset(p_temp, 0, (p_offset - p_temp));
p_temp = p_offset;
+ offset_size = 0;
for (i = 0; i < pstr_usac_config->channels; i++) {
- pstr_usac_enc_data->ptr_time_data[i] = (FLOAT64 *)p_offset;
- p_offset += 2 * (pstr_usac_config->ccfl) * sizeof(FLOAT64);
+ pstr_usac_enc_data->ptr_time_data[i] = (FLOAT64 *)(p_offset);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED((2 * (pstr_usac_config->ccfl) * sizeof(FLOAT64)),
+ BYTE_ALIGN_8);
}
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
+
for (i = 0; i < pstr_usac_config->channels; i++) {
- pstr_usac_enc_data->ptr_look_ahead_time_data[i] = (FLOAT64 *)p_offset;
- p_offset += pstr_usac_config->ccfl * sizeof(FLOAT64);
+ pstr_usac_enc_data->ptr_look_ahead_time_data[i] = (FLOAT64 *)(p_offset);
+ p_offset +=
+ IXHEAACE_GET_SIZE_ALIGNED((pstr_usac_config->ccfl * sizeof(FLOAT64)), BYTE_ALIGN_8);
}
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
+
for (i = 0; i < pstr_usac_config->channels; i++) {
- pstr_usac_enc_data->spectral_line_vector[i] = (FLOAT64 *)p_offset;
- p_offset += 2 * pstr_usac_config->ccfl * sizeof(FLOAT64);
+ pstr_usac_enc_data->spectral_line_vector[i] = (FLOAT64 *)(p_offset);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED((2 * pstr_usac_config->ccfl * sizeof(FLOAT64)),
+ BYTE_ALIGN_8);
}
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
+
for (i = 0; i < pstr_usac_config->channels; i++) {
- pstr_usac_enc_data->ptr_2frame_time_data[i] = (FLOAT64 *)p_offset;
- p_offset += 3 * pstr_usac_config->ccfl * sizeof(FLOAT64);
+ pstr_usac_enc_data->ptr_2frame_time_data[i] = (FLOAT64 *)(p_offset);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED((3 * pstr_usac_config->ccfl * sizeof(FLOAT64)),
+ BYTE_ALIGN_8);
}
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
memset(p_temp, 0, p_offset - p_temp);
if (pstr_usac_config->tns_select != 0) {
p_temp = p_offset;
for (i = 0; i < pstr_usac_config->channels; i++) {
- pstr_usac_enc_data->pstr_tns_info[i] = (ia_tns_info *)p_offset;
- p_offset += sizeof(ia_tns_info);
+ pstr_usac_enc_data->pstr_tns_info[i] = (ia_tns_info *)(p_offset);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED(sizeof(ia_tns_info), BYTE_ALIGN_8);
}
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
memset(p_temp, 0, p_offset - p_temp);
}
p_temp = p_offset;
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
for (i = 0; i < pstr_usac_config->channels; i++) {
- pstr_usac_enc_data->td_encoder[i] = (ia_usac_td_encoder_struct *)p_offset;
- p_offset += sizeof(ia_usac_td_encoder_struct);
+ pstr_usac_enc_data->td_encoder[i] = (ia_usac_td_encoder_struct *)(p_offset);
+ p_offset += IXHEAACE_GET_SIZE_ALIGNED(sizeof(ia_usac_td_encoder_struct), BYTE_ALIGN_8);
}
memset(p_temp, 0, p_offset - p_temp);
} else {
@@ -1640,7 +1680,6 @@ static IA_ERRORCODE ixheaace_alloc_and_assign_mem(ixheaace_api_struct *pstr_api_
p_offset +
ixheaace_sbr_enc_pers_size(
num_aac_chan, pstr_api_struct->config[ele_idx].use_parametric_stereo, 0);
- p_offset = IXHEAACE_ALIGN_MEMORY((SIZE_T)p_offset, 8);
}
}
}
@@ -1905,7 +1944,7 @@ static IA_ERRORCODE ia_usac_enc_init(ixheaace_api_struct *pstr_api_struct, WORD3
error = iusace_enc_init(pstr_usac_config, &pstr_api_struct->pstr_state->audio_specific_config,
&pstr_api_struct->pstr_state->str_usac_enc_data);
- if (error) {
+ if (error & IA_FATAL_ERROR) {
return error;
}
@@ -1913,9 +1952,6 @@ static IA_ERRORCODE ia_usac_enc_init(ixheaace_api_struct *pstr_api_struct, WORD3
pstr_ia_asc_bit_buf = iusace_create_bit_buffer(
&(pstr_api_struct->pstr_state->str_bit_buf), pstr_api_struct->pp_mem[IA_MEMTYPE_OUTPUT],
pstr_api_struct->pstr_mem_info[IA_MEMTYPE_OUTPUT].ui_size, 1);
-#ifdef ENABLE_SET_JUMP
- pstr_ia_asc_bit_buf->iusace_jmp_buf = &api_init_jmp_buf;
-#endif
if (pstr_usac_config->sbr_enable) {
pstr_api_struct->pstr_state->audio_specific_config.str_usac_config.str_usac_element_config
->stereo_config_index = (pstr_api_struct->pstr_state->mps_enable == 1) ? 2 : 0;
@@ -2686,7 +2722,8 @@ static IA_ERRORCODE ia_enhaacplus_enc_execute(ixheaace_api_struct *pstr_api_stru
&(pstr_api_struct->pstr_state->bit_stream), flag_last_element,
write_program_config_element, i_num_coup_channels, i_channels_mask, ele_idx,
total_fill_bits, total_channels, aot, pstr_api_struct->config->adts_flag,
- num_bs_elements);
+ num_bs_elements, &pstr_api_struct->pstr_state->is_quant_spec_zero,
+ &pstr_api_struct->pstr_state->is_gain_limited);
if (error != IA_NO_ERROR) {
return error;
}
@@ -2726,14 +2763,6 @@ static IA_ERRORCODE ia_enhaacplus_enc_execute(ixheaace_api_struct *pstr_api_stru
static IA_ERRORCODE iusace_process(ixheaace_api_struct *pstr_api_struct) {
IA_ERRORCODE error = IA_NO_ERROR;
WORD32 idx;
-#ifdef ENABLE_SET_JUMP
- jmp_buf api_execute_jmp_buf;
- error = setjmp(api_execute_jmp_buf);
- if (error != IA_NO_ERROR) {
- return IA_EXHEAACE_EXE_NONFATAL_USAC_INSUFFICIENT_WRITE_BUFFER_SIZE;
- }
-#endif // ENABLE_SET_JUMP
-
WORD32 write_off_set = 0;
WORD32 core_coder_frame_length;
WORD32 usac_independency_flg;
@@ -3067,7 +3096,8 @@ static IA_ERRORCODE iusace_process(ixheaace_api_struct *pstr_api_struct) {
&(pstr_api_struct->pstr_state->num_anc_data_bytes[0][0]),
pstr_api_struct->pstr_state->anc_data_bytes[0],
&(pstr_api_struct->spectral_band_replication_tabs), &(pstr_api_struct->common_tabs),
- &(mps_extension_payload.p_data[0]), mps_extension_payload.data_size, 0, NULL);
+ &(mps_extension_payload.p_data[0]), mps_extension_payload.data_size, 0,
+ &pstr_api_struct->pstr_state->str_usac_enc_data.num_sbr_bits);
if (error != IA_NO_ERROR) {
return error;
}
@@ -3222,16 +3252,15 @@ static IA_ERRORCODE iusace_process(ixheaace_api_struct *pstr_api_struct) {
iusace_create_bit_buffer(pstr_it_bit_buff, pstr_api_struct->pp_mem[IA_MEMTYPE_OUTPUT],
pstr_api_struct->pstr_mem_info[IA_MEMTYPE_OUTPUT].ui_size, 1);
if (pstr_it_bit_buff == NULL) {
- return -1;
+ return IA_EXHEAACE_INIT_FATAL_USAC_BITBUFFER_INIT_FAILED;
}
-#ifdef ENABLE_SET_JUMP
- pstr_it_bit_buff->iusace_jmp_buf = &api_execute_jmp_buf;
-#endif
error =
ixheaace_usac_encode(pstr_api_struct->pstr_state->ptr_in_buf, pstr_config,
&pstr_api_struct->pstr_state->str_usac_enc_data,
&pstr_api_struct->pstr_state->audio_specific_config, pstr_it_bit_buff,
- pstr_sbr_encoder, pstr_api_struct->pstr_state->pp_drc_in_buf);
+ pstr_sbr_encoder, pstr_api_struct->pstr_state->pp_drc_in_buf,
+ &pstr_api_struct->pstr_state->is_quant_spec_zero,
+ &pstr_api_struct->pstr_state->is_gain_limited);
if (error) return error;
padding_bits = 8 - (pstr_it_bit_buff->cnt_bits & 7);
@@ -3270,6 +3299,7 @@ static IA_ERRORCODE iusace_process(ixheaace_api_struct *pstr_api_struct) {
write_off_set * sizeof(ptr_input_buffer[0]));
}
}
+
return IA_NO_ERROR;
}
IA_ERRORCODE ixheaace_get_lib_id_strings(pVOID pv_output) {
@@ -3500,10 +3530,11 @@ IA_ERRORCODE ixheaace_init(pVOID pstr_obj_ixheaace, pVOID pv_input, pVOID pv_out
if (error) {
return error;
}
+
pstr_output_config->input_size =
frame_length * channels * (pstr_api_struct->config[0].usac_config.ui_pcm_wd_sz >> 3);
- if (pstr_input_config->use_drc_element) {
+ if (pstr_api_struct->config[0].usac_config.use_drc_element) {
ia_drc_input_config *pstr_drc_cfg = (ia_drc_input_config *)(pstr_input_config->pv_drc_cfg);
memcpy(pstr_drc_cfg, &pstr_api_struct->config[0].usac_config.str_drc_cfg,
sizeof(ia_drc_input_config));
@@ -3533,7 +3564,13 @@ IA_ERRORCODE ixheaace_init(pVOID pstr_obj_ixheaace, pVOID pv_input, pVOID pv_out
pstr_output_config->header_samp_freq =
pstr_api_struct->config[0].usac_config.native_sample_rate;
pstr_output_config->audio_profile = AUDIO_PROFILE_USAC_L2;
+ if (pstr_input_config->use_drc_element !=
+ pstr_api_struct->config[0].usac_config.use_drc_element) {
+ error = IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_GAIN_POINTS;
+ }
+ pstr_input_config->use_drc_element = pstr_api_struct->config[0].usac_config.use_drc_element;
}
+
pstr_api_struct->pstr_state->ui_init_done = 1;
pstr_output_config->i_out_bytes = pstr_api_struct->pstr_state->i_out_bytes;
@@ -3547,7 +3584,7 @@ IA_ERRORCODE ixheaace_create(pVOID pv_input, pVOID pv_output) {
if (!err_code) {
err_code = ixheaace_init(pstr_out_cfg->pv_ia_process_api_obj, pv_input, pv_output);
}
- if (err_code) {
+ if (err_code & IA_FATAL_ERROR) {
IXHEAACE_MEM_FREE(pv_output);
}
return err_code;
@@ -3559,16 +3596,28 @@ IA_ERRORCODE ixheaace_process(pVOID pstr_obj_ixheaace, pVOID pv_input, pVOID pv_
(VOID) pv_input;
ixheaace_api_struct *pstr_api_struct = (ixheaace_api_struct *)pstr_obj_ixheaace;
ixheaace_output_config *pstr_output_config = (ixheaace_output_config *)pv_output;
-
+ pstr_api_struct->pstr_state->is_quant_spec_zero = 0;
+ pstr_api_struct->pstr_state->is_gain_limited = 0;
if (!pstr_api_struct->usac_en) {
for (ele_idx = 0; ele_idx < pstr_api_struct->config[0].num_bs_elements; ele_idx++) {
error = ia_enhaacplus_enc_execute(pstr_api_struct, ele_idx);
}
+ if ((error == IA_NO_ERROR) && (pstr_api_struct->pstr_state->is_quant_spec_zero)) {
+ error = IA_EXHEAACE_EXE_NONFATAL_QUANTIZATION_SPECTRUM_ZERO;
+ }
+ if ((error == IA_NO_ERROR) && (pstr_api_struct->pstr_state->is_gain_limited)) {
+ error = IA_EXHEAACE_EXE_NONFATAL_QUANTIZATION_INSUFFICIENT_BITRES;
+ }
} else {
error = iusace_process(pstr_api_struct);
+ if ((error == IA_NO_ERROR) && (pstr_api_struct->pstr_state->is_quant_spec_zero)) {
+ error = IA_EXHEAACE_EXE_NONFATAL_USAC_QUANTIZATION_SPECTRUM_ZERO;
+ }
+ if ((error == IA_NO_ERROR) && (pstr_api_struct->pstr_state->is_gain_limited)) {
+ error = IA_EXHEAACE_EXE_NONFATAL_USAC_QUANTIZATION_INSUFFICIENT_BITRES;
+ }
}
pstr_output_config->i_out_bytes = pstr_api_struct->pstr_state->i_out_bytes;
-
return error;
}
diff --git a/encoder/ixheaace_api_defs.h b/encoder/ixheaace_api_defs.h
index 3160077..3c2164d 100644
--- a/encoder/ixheaace_api_defs.h
+++ b/encoder/ixheaace_api_defs.h
@@ -43,4 +43,5 @@ IA_ERRORCODE ixheaace_usac_encode(FLOAT32 **ptr_input,
ia_usac_data_struct *pstr_state,
ixheaace_audio_specific_config_struct *pstr_asc,
ia_bit_buf_struct *pstr_it_bit_buff,
- ixheaace_pstr_sbr_enc ptr_env_encoder, FLOAT32 **ptr_drc_inp);
+ ixheaace_pstr_sbr_enc ptr_env_encoder, FLOAT32 **ptr_drc_inp,
+ WORD32 *is_quant_spec_zero, WORD32 *is_gain_restricted);
diff --git a/encoder/ixheaace_asc_write.c b/encoder/ixheaace_asc_write.c
index bc28857..436ef57 100644
--- a/encoder/ixheaace_asc_write.c
+++ b/encoder/ixheaace_asc_write.c
@@ -45,6 +45,7 @@
#include "ixheaace_aac_constants.h"
#include "ixheaace_sbr_def.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_error_codes.h"
static WORD32 ixheaace_spatial_specific_config(ia_bit_buf_struct *pstr_it_bit_buff,
ia_aace_config_struct *pstr_eld_config) {
@@ -232,8 +233,7 @@ static WORD32 iusace_encoder_config(ia_bit_buf_struct *pstr_it_bit_buff,
bit_cnt += iusace_ext_element_config(pstr_it_bit_buff, pstr_usac_enc_conf);
break;
default:
- return -1;
- ;
+ return IA_EXHEAACE_INIT_FATAL_USAC_INVALID_ELEMENT_TYPE;
break;
}
}
diff --git a/encoder/ixheaace_basic_ops.c b/encoder/ixheaace_basic_ops.c
index c18b430..a49458e 100644
--- a/encoder/ixheaace_basic_ops.c
+++ b/encoder/ixheaace_basic_ops.c
@@ -18,6 +18,8 @@
* Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
+#include <float.h>
+#include <math.h>
#include "ixheaac_type_def.h"
#include "ixheaac_constants.h"
#include "ixheaace_aac_constants.h"
@@ -33,3 +35,31 @@ WORD ia_enhaacplus_enc_norm32_arr(const WORD32 *word32_arr, LOOPINDEX n) {
}
return (ixheaac_pnorm32(max_bits));
}
+
+FLOAT32 ixheaace_div32(FLOAT32 num, FLOAT32 den) {
+ if (fabs(den) < FLT_EPSILON) {
+ if (den < 0.0f) {
+ return -num;
+ }
+ else {
+ return num;
+ }
+ }
+ else {
+ return num / den;
+ }
+}
+
+FLOAT64 ixheaace_div64(FLOAT64 num, FLOAT64 den) {
+ if (fabs(den) < FLT_EPSILON) {
+ if (den < 0.0) {
+ return -num;
+ }
+ else {
+ return num;
+ }
+ }
+ else {
+ return num / den;
+ }
+}
diff --git a/encoder/ixheaace_bits_count.c b/encoder/ixheaace_bits_count.c
index da938ef..6e5fa69 100644
--- a/encoder/ixheaace_bits_count.c
+++ b/encoder/ixheaace_bits_count.c
@@ -936,19 +936,13 @@ VOID ia_enhaacplus_enc_code_values(WORD16 *ptr_values, WORD32 width, WORD32 code
}
}
-WORD32 ia_enhaacplus_enc_code_scale_factor_delta(WORD32 delta,
- ixheaace_bit_buf_handle h_bitstream,
- ixheaace_huffman_tables *pstr_huffman_tbl) {
+VOID ia_enhaacplus_enc_code_scale_factor_delta(WORD32 delta,
+ ixheaace_bit_buf_handle h_bitstream,
+ ixheaace_huffman_tables *pstr_huffman_tbl) {
WORD32 code_word, code_length;
- if (abs32(delta) > CODE_BCK_SCF_LAV) {
- return (1);
- }
-
code_word = pstr_huffman_tbl->huff_ctabscf[delta + CODE_BCK_SCF_LAV];
code_length = pstr_huffman_tbl->huff_ltabscf[delta + CODE_BCK_SCF_LAV];
ixheaace_write_bits(h_bitstream, code_word, (UWORD8)code_length);
-
- return (0);
}
diff --git a/encoder/ixheaace_bits_count.h b/encoder/ixheaace_bits_count.h
index ee20d36..70b5fe3 100644
--- a/encoder/ixheaace_bits_count.h
+++ b/encoder/ixheaace_bits_count.h
@@ -93,9 +93,9 @@ VOID ia_enhaacplus_enc_code_values(WORD16 *ptr_values, WORD32 width, WORD32 code
ixheaace_bit_buf_handle pstr_bitstream,
ixheaace_huffman_tables *pstr_huffman_tbl);
-WORD32 ia_enhaacplus_enc_code_scale_factor_delta(WORD32 scalefactor,
- ixheaace_bit_buf_handle h_bitstream,
- ixheaace_huffman_tables *pstr_huffman_tbl);
+VOID ia_enhaacplus_enc_code_scale_factor_delta(WORD32 scalefactor,
+ ixheaace_bit_buf_handle h_bitstream,
+ ixheaace_huffman_tables *pstr_huffman_tbl);
VOID ia_enhaacplus_enc_count1_2_3_4_5_6_7_8_9_10_11(const WORD16 *values, const WORD32 width,
WORD32 *bitcnt,
diff --git a/encoder/ixheaace_common_utils.h b/encoder/ixheaace_common_utils.h
index 282ae74..9609f18 100644
--- a/encoder/ixheaace_common_utils.h
+++ b/encoder/ixheaace_common_utils.h
@@ -37,3 +37,6 @@
#define C75 (-0.3408728838f) //(2 * sin(u) - sin(2 * u) + sin(3 * u)) / 3;
#define C76 (0.5339693427f) //(sin(u) - 2 * sin(2 * u) - sin(3 * u)) / 3;
#define C77 (-0.8748422265f) //(sin(u) + sin(2 * u) + 2 * sin(3 * u)) / 3;
+
+FLOAT32 ixheaace_div32(FLOAT32 num, FLOAT32 den);
+FLOAT64 ixheaace_div64(FLOAT64 num, FLOAT64 den);
diff --git a/encoder/ixheaace_cplx_pred.c b/encoder/ixheaace_cplx_pred.c
index 703941e..a9f3646 100644
--- a/encoder/ixheaace_cplx_pred.c
+++ b/encoder/ixheaace_cplx_pred.c
@@ -20,7 +20,7 @@
#include <math.h>
#include <string.h>
-
+#include <float.h>
#include "iusace_type_def.h"
#include "ixheaac_error_standards.h"
#include "ixheaace_error_codes.h"
@@ -51,6 +51,7 @@
#include "ixheaace_asc_write.h"
#include "iusace_main.h"
#include "iusace_rom.h"
+#include "ixheaace_common_utils.h"
static VOID iusace_compute_pred_coef(WORD32 num_lines, WORD32 complex_coef,
FLOAT64 *ptr_spec_mdct_dmx, FLOAT64 *ptr_spec_mdst_dmx,
@@ -371,8 +372,8 @@ static IA_ERRORCODE iusace_cplx_pred_main(
for (i = 0; i < pstr_usac_config->ccfl; i++) {
nrg_res += (FLOAT32)(ptr_spec_mdct_res[i] * ptr_spec_mdct_res[i]);
}
- pred_gain =
- 10.f * log10f((*pred_dir == 0 ? nrg_side : nrg_mid) / nrg_res); /* Prediction gain in dB */
+ pred_gain = 10.f * log10f(ixheaace_div32((*pred_dir == 0 ? nrg_side : nrg_mid), nrg_res));
+ /* Prediction gain in dB */
if (pred_gain > 20.f) /* Retain complex prediction */
{
diff --git a/encoder/ixheaace_enc_init.c b/encoder/ixheaace_enc_init.c
index 4a8eae2..c744297 100644
--- a/encoder/ixheaace_enc_init.c
+++ b/encoder/ixheaace_enc_init.c
@@ -296,11 +296,14 @@ IA_ERRORCODE ia_enhaacplus_enc_aac_enc_open(iexheaac_encoder_str **ppstr_exheaac
break;
}
- error = (config.num_in_channels < 1 || config.num_out_channels > IXHEAACE_MAX_CH_IN_BS_ELE ||
- config.num_out_channels < 1 || config.num_in_channels < config.num_out_channels ||
- (config.bit_rate != 0 && (config.bit_rate / config.num_out_channels < 8000 ||
- config.bit_rate / config.num_out_channels > 576000)));
-
+ if ((config.num_in_channels < 1) || (config.num_out_channels > IXHEAACE_MAX_CH_IN_BS_ELE) ||
+ (config.num_out_channels < 1) || (config.num_in_channels < config.num_out_channels)) {
+ return IA_EXHEAACE_INIT_FATAL_INVALID_NUM_CHANNELS_IN_ELE;
+ }
+ if ((config.bit_rate != 0) && ((config.bit_rate / config.num_out_channels < 8000) ||
+ (config.bit_rate / config.num_out_channels > 576000))) {
+ error = IA_EXHEAACE_INIT_FATAL_BITRATE_NOT_SUPPORTED;
+ }
if (error != IA_NO_ERROR) {
return error;
}
diff --git a/encoder/ixheaace_enc_main.c b/encoder/ixheaace_enc_main.c
index 3e813fe..1c25924 100644
--- a/encoder/ixheaace_enc_main.c
+++ b/encoder/ixheaace_enc_main.c
@@ -65,7 +65,8 @@ IA_ERRORCODE ia_enhaacplus_enc_aac_core_encode(
WORD32 *num_out_bytes, ixheaace_aac_tables *pstr_aac_tabs, VOID *ptr_bit_stream_handle,
VOID *ptr_bit_stream, FLAG flag_last_element, WORD32 *write_program_config_element,
WORD32 i_num_coup_channels, WORD32 i_channels_mask, WORD32 ele_idx, WORD32 *total_fill_bits,
- WORD32 total_channels, WORD32 aot, WORD32 adts_flag, WORD32 num_bs_elements) {
+ WORD32 total_channels, WORD32 aot, WORD32 adts_flag, WORD32 num_bs_elements,
+ WORD32 *is_quant_spec_zero, WORD32 *is_gain_limited) {
IA_ERRORCODE err_code = IA_NO_ERROR;
iexheaac_encoder_str *pstr_aac_encoder = pstr_aac_enc[ele_idx];
ixheaace_element_info *pstr_element_info = &pstr_aac_encoder->element_info;
@@ -173,7 +174,8 @@ IA_ERRORCODE ia_enhaacplus_enc_aac_core_encode(
pstr_aac_encoder->qc_out.qc_channel[pstr_element_info->channel_index[0]],
&pstr_aac_encoder->qc_out.qc_element, MIN(anc_data_bytes_left, anc_data_bytes),
pstr_aac_tabs, adts_flag, aot, stat_bits_flag, flag_last_element, frame_len_long,
- pstr_aac_encoder->pstr_aac_scratch->shared_buffer5);
+ pstr_aac_encoder->pstr_aac_scratch->shared_buffer5, is_quant_spec_zero,
+ is_gain_limited);
if (err_code != IA_NO_ERROR) {
return err_code;
diff --git a/encoder/ixheaace_enc_main.h b/encoder/ixheaace_enc_main.h
index c7997ce..3dd377e 100644
--- a/encoder/ixheaace_enc_main.h
+++ b/encoder/ixheaace_enc_main.h
@@ -108,7 +108,8 @@ IA_ERRORCODE ia_enhaacplus_enc_aac_core_encode(
WORD32 *num_out_bytes, ixheaace_aac_tables *pstr_aac_tables, VOID *ptr_bit_stream_handle,
VOID *ptr_bit_stream, FLAG flag_last_element, WORD32 *write_program_config_element,
WORD32 i_num_coup_channels, WORD32 i_channels_mask, WORD32 ele_idx, WORD32 *total_fill_bits,
- WORD32 total_channels, WORD32 aot, WORD32 adts_flag, WORD32 num_bs_elements);
+ WORD32 total_channels, WORD32 aot, WORD32 adts_flag, WORD32 num_bs_elements,
+ WORD32 *is_quant_spec_zero, WORD32 *is_gain_limited);
VOID ia_enhaacplus_enc_set_shared_bufs(iaace_scratch *scr, WORD32 **shared_buf1,
WORD32 **shared_buf2, WORD32 **shared_buf3,
diff --git a/encoder/ixheaace_error_codes.h b/encoder/ixheaace_error_codes.h
index 12de2c9..b8ab469 100644
--- a/encoder/ixheaace_error_codes.h
+++ b/encoder/ixheaace_error_codes.h
@@ -99,6 +99,9 @@ typedef enum {
/*****************************************************************************/
/* Non Fatal Errors */
+ //DRC
+ IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_GAIN_POINTS = 0x00001300,
+ IA_EXHEAACE_EXE_NONFATAL_USAC_INVALID_SUBBAND_INDEX,
/* Fatal Errors */
// AAC Profiles
@@ -113,6 +116,7 @@ typedef enum {
IA_EXHEAACE_INIT_FATAL_NUM_CHANNELS_NOT_SUPPORTED,
IA_EXHEAACE_INIT_FATAL_INVALID_NUM_CHANNELS_IN_ELE,
IA_EXHEAACE_INIT_FATAL_SFB_TABLE_INIT_FAILED,
+ IA_EXHEAACE_INIT_FATAL_TNS_CONFIG_INIT_FAILED,
// MPS
IA_EXHEAACE_INIT_FATAL_MPS_INIT_FAILED = 0xFFFF9100,
@@ -120,6 +124,10 @@ typedef enum {
// USAC
IA_EXHEAACE_INIT_FATAL_USAC_RESAMPLER_INIT_FAILED = 0xFFFF9200,
IA_EXHEAACE_INIT_FATAL_USAC_BITRES_SIZE_TOO_SMALL,
+ IA_EXHEAACE_INIT_FATAL_USAC_INVALID_CORE_SAMPLE_RATE,
+ IA_EXHEAACE_INIT_FATAL_USAC_INVALID_ELEMENT_TYPE,
+ IA_EXHEAACE_INIT_FATAL_USAC_BITBUFFER_INIT_FAILED,
+ IA_EXHEAACE_INIT_FATAL_USAC_INVALID_CODEC_MODE,
// DRC
IA_EXHEAACE_INIT_FATAL_DRC_INVALID_CHANNEL_INDEX = 0xFFFF9300,
@@ -132,19 +140,24 @@ typedef enum {
IA_EXHEAACE_INIT_FATAL_SBR_INVALID_BUFFER_LENGTH,
IA_EXEHAACE_INIT_FATAL_SBR_NOISE_BAND_NOT_SUPPORTED,
+ // PS
+ IA_EXHEAACE_INIT_FATAL_PS_INIT_FAILED = 0xFFFF9500,
+
/*****************************************************************************/
/* Class 3: Execution Errors */
/*****************************************************************************/
/* Non Fatal Errors */
// AAC Profiles
-
+ IA_EXHEAACE_EXE_NONFATAL_QUANTIZATION_SPECTRUM_ZERO = 0x00001800,
+ IA_EXHEAACE_EXE_NONFATAL_QUANTIZATION_INSUFFICIENT_BITRES,
// MPS
IA_EXHEAACE_EXE_NONFATAL_MPS_ENCODE_ERROR = 0x00001900,
IA_EXHEAACE_EXE_NONFATAL_MPS_INVALID_DATA_BANDS,
// USAC
-
+ IA_EXHEAACE_EXE_NONFATAL_USAC_QUANTIZATION_SPECTRUM_ZERO = 0x00001A00,
+ IA_EXHEAACE_EXE_NONFATAL_USAC_QUANTIZATION_INSUFFICIENT_BITRES,
// DRC
// ESBR
@@ -199,6 +212,9 @@ typedef enum {
IA_EXHEAACE_EXE_FATAL_USAC_INVALID_NUM_CHANNEL,
IA_EXHEAACE_EXE_FATAL_USAC_INVALID_BIT_RSVR_LVL,
IA_EXHEAACE_EXE_FATAL_USAC_INVALID_MAPPING,
+ IA_EXHEAACE_EXE_FATAL_USAC_INVALID_WINDOW_TYPE,
+ IA_EXHEAACE_EXE_FATAL_USAC_INVALID_WINDOW_LENGTH,
+ IA_EXHEAACE_EXE_FATAL_USAC_INVALID_WINDOW_SHAPE,
// DRC
diff --git a/encoder/ixheaace_fd_enc.c b/encoder/ixheaace_fd_enc.c
index 34556e9..264460c 100644
--- a/encoder/ixheaace_fd_enc.c
+++ b/encoder/ixheaace_fd_enc.c
@@ -56,7 +56,8 @@ IA_ERRORCODE iusace_fd_encode(ia_sfb_params_struct *pstr_sfb_prms, WORD32 usac_i
ia_usac_data_struct *pstr_usac_data,
ia_usac_encoder_config_struct *pstr_usac_config,
ia_bit_buf_struct *pstr_it_bit_buff, WORD32 nr_core_coder_ch,
- WORD32 chn, WORD32 ele_id, WORD32 *bit_written) {
+ WORD32 chn, WORD32 ele_id, WORD32 *bit_written,
+ WORD32 *is_quant_spec_zero, WORD32 *is_gain_limited) {
iusace_scratch_mem *pstr_scratch = &pstr_usac_data->str_scratch;
IA_ERRORCODE err_code = 0;
WORD32 i_ch, idx = 0;
@@ -94,7 +95,8 @@ IA_ERRORCODE iusace_fd_encode(ia_sfb_params_struct *pstr_sfb_prms, WORD32 usac_i
}
err_code = iusace_quantize_spec(pstr_sfb_prms, usac_independancy_flag, nr_core_coder_ch,
- pstr_usac_data, pstr_usac_config, chn, ele_id);
+ pstr_usac_data, pstr_usac_config, chn, ele_id,
+ is_quant_spec_zero, is_gain_limited);
if (err_code) return err_code;
for (i_ch = chn; i_ch < chn + nr_core_coder_ch; i_ch++) {
diff --git a/encoder/ixheaace_fd_mdct.c b/encoder/ixheaace_fd_mdct.c
index 2ef6b74..bb53fa7 100644
--- a/encoder/ixheaace_fd_mdct.c
+++ b/encoder/ixheaace_fd_mdct.c
@@ -52,6 +52,7 @@
#include "ixheaace_asc_write.h"
#include "iusace_main.h"
#include "iusace_windowing.h"
+#include "ixheaac_error_standards.h"
static IA_ERRORCODE iusace_fd_mdct_short(ia_usac_data_struct *pstr_usac_data,
ia_usac_encoder_config_struct *pstr_usac_config,
@@ -196,7 +197,7 @@ static IA_ERRORCODE iusace_fd_mdct_long(ia_usac_data_struct *pstr_usac_data,
return err_code_2;
}
- return 0;
+ return IA_NO_ERROR;
}
WORD32 iusace_fd_mdct(ia_usac_data_struct *pstr_usac_data,
diff --git a/encoder/ixheaace_fd_qc_adjthr.c b/encoder/ixheaace_fd_qc_adjthr.c
index d07bb58..8e7def0 100644
--- a/encoder/ixheaace_fd_qc_adjthr.c
+++ b/encoder/ixheaace_fd_qc_adjthr.c
@@ -22,6 +22,7 @@
#include <math.h>
#include <stdlib.h>
#include <limits.h>
+#include <float.h>
#include "iusace_type_def.h"
#include "ixheaac_error_standards.h"
#include "ixheaace_error_codes.h"
@@ -201,10 +202,12 @@ static FLOAT32 iusace_bitres_calc_bitfac(const WORD32 bitres_bits, const WORD32
const WORD32 avg_bits, const FLOAT32 max_bit_fac,
ia_adj_thr_elem_struct *pstr_adj_thr_elem) {
FLOAT32 pex;
- FLOAT32 fill_lvl;
+ FLOAT32 fill_lvl = 0.0f;
FLOAT32 bit_save, bit_spend, bitres_factor;
- fill_lvl = (FLOAT32)bitres_bits / (FLOAT32)max_bitres_bits;
+ if (max_bitres_bits) {
+ fill_lvl = (FLOAT32)bitres_bits / max_bitres_bits;
+ }
if (win_seq != EIGHT_SHORT_SEQUENCE) {
fill_lvl = MAX(fill_lvl, CLIP_SAVE_LO_LONG);
@@ -795,7 +798,7 @@ static IA_ERRORCODE iusace_adapt_thr_to_pe(ia_psy_mod_out_data_struct *pstr_psy_
FLOAT32 const_part, const_part_no_ah;
FLOAT32 nactive_lines, nactive_lines_no_ah;
FLOAT32 desired_pe_no_ah;
- FLOAT32 avg_thr_exp, redval;
+ FLOAT32 redval = 0.0f;
WORD32 *ah_flag[2];
WORD32 iteration;
for (WORD32 i = 0; i < 2; i++) {
@@ -815,12 +818,14 @@ static IA_ERRORCODE iusace_adapt_thr_to_pe(ia_psy_mod_out_data_struct *pstr_psy_
no_red_pe = pstr_qs_pe_data->pe;
const_part = pstr_qs_pe_data->const_part;
nactive_lines = pstr_qs_pe_data->num_active_lines;
- avg_thr_exp = (FLOAT32)pow(2.0f, (const_part - no_red_pe) / (INV_RED_EXP_VAL * nactive_lines));
- redval = (FLOAT32)pow(2.0f, (const_part - desired_pe) / (INV_RED_EXP_VAL * nactive_lines)) -
- avg_thr_exp;
- redval = MAX(0.0f, redval);
-
- iusace_reduce_thr(pstr_psy_out, ah_flag, thr_exp, redval, num_channels, chn);
+ if (nactive_lines > FLT_EPSILON) {
+ FLOAT32 avg_thr_exp = (FLOAT32)pow(2.0f, (const_part - no_red_pe) /
+ (INV_RED_EXP_VAL * nactive_lines));
+ redval = (FLOAT32)pow(2.0f, (const_part - desired_pe) / (INV_RED_EXP_VAL * nactive_lines)) -
+ avg_thr_exp;
+ redval = MAX(0.0f, redval);
+ iusace_reduce_thr(pstr_psy_out, ah_flag, thr_exp, redval, num_channels, chn);
+ }
iusace_calc_sfb_pe_data(pstr_qs_pe_data, pstr_psy_out, num_channels, chn);
red_pe = pstr_qs_pe_data->pe;
@@ -831,8 +836,8 @@ static IA_ERRORCODE iusace_adapt_thr_to_pe(ia_psy_mod_out_data_struct *pstr_psy_
pstr_qs_pe_data, ah_flag, pstr_psy_out, num_channels, chn);
desired_pe_no_ah = MAX(desired_pe - (red_pe - red_pe_no_ah), 0);
- if (nactive_lines_no_ah > 0) {
- avg_thr_exp = (FLOAT32)pow(
+ if (nactive_lines_no_ah > FLT_EPSILON) {
+ FLOAT32 avg_thr_exp = (FLOAT32)pow(
2.0f, (const_part_no_ah - red_pe_no_ah) / (INV_RED_EXP_VAL * nactive_lines_no_ah));
redval += (FLOAT32)pow(2.0f, (const_part_no_ah - desired_pe_no_ah) /
(INV_RED_EXP_VAL * nactive_lines_no_ah)) -
@@ -1171,7 +1176,7 @@ static WORD16 iusace_improve_scf(FLOAT32 *ptr_spec, FLOAT32 *ptr_exp_spec, WORD1
count = 0;
- while ((sfb_dist > (1.25 * threshold)) && (count++ < 3)) {
+ while ((sfb_dist > (1.25 * threshold)) && (count++ < SCF_COUNT_LIMIT_THREE)) {
scf++;
sfb_dist =
@@ -1189,7 +1194,8 @@ static WORD16 iusace_improve_scf(FLOAT32 *ptr_spec, FLOAT32 *ptr_exp_spec, WORD1
scf = estimated_scf;
sfb_dist = best_sfb_dist;
- while ((sfb_dist > (1.25 * threshold)) && (count++ < 1) && (scf > min_scf)) {
+ while ((sfb_dist > (1.25 * threshold)) && (count++ < SCF_COUNT_LIMIT_ONE) &&
+ (scf > min_scf)) {
scf--;
sfb_dist =
@@ -1209,7 +1215,7 @@ static WORD16 iusace_improve_scf(FLOAT32 *ptr_spec, FLOAT32 *ptr_exp_spec, WORD1
FLOAT32 allowed_sfb_dist = MIN(sfb_dist * 1.25f, threshold);
WORD32 count;
- for (count = 0; count < 3; count++) {
+ for (count = 0; count < SCF_COUNT_LIMIT_THREE; count++) {
scf++;
sfb_dist =
@@ -1604,14 +1610,15 @@ VOID iusace_estimate_scfs_chan(ia_psy_mod_out_data_struct *pstr_psy_out,
min_sf_max_quant[i] = MIN_SHRT_VAL;
if ((max_spec > 0.0) && (energy > thresh) && (p_sfb_form_factor[i] != MIN_FLT_VAL)) {
- energy_part = (FLOAT32)log10(p_sfb_form_factor[i]);
+ energy_part = (FLOAT32)log10(p_sfb_form_factor[i] + FLT_EPSILON);
thr_part = (FLOAT32)log10(6.75 * thresh + MIN_FLT_VAL);
scf_float = 8.8585f * (thr_part - energy_part);
scf_int = (WORD16)floor(scf_float);
min_sf_max_quant[i] = (WORD16)ceil(C1_SF + C2_SF * log(max_spec));
scf_int = MAX(scf_int, min_sf_max_quant[i]);
-
+ scf_int = MAX(scf_int, MIN_GAIN_INDEX);
+ scf_int = MIN(scf_int, (MAX_GAIN_INDEX - SCF_COUNT_LIMIT_THREE));
for (j = 0; j < ptr_psy_out->sfb_offsets[i + 1] - ptr_psy_out->sfb_offsets[i]; j++) {
ptr_exp_spec[ptr_psy_out->sfb_offsets[i] + j] =
(FLOAT32)(ptr_psy_out->ptr_spec_coeffs[ptr_psy_out->sfb_offsets[i] + j]);
diff --git a/encoder/ixheaace_fd_quant.c b/encoder/ixheaace_fd_quant.c
index 799f832..4be4670 100644
--- a/encoder/ixheaace_fd_quant.c
+++ b/encoder/ixheaace_fd_quant.c
@@ -56,6 +56,7 @@
#include "iusace_block_switch_const.h"
#include "iusace_rom.h"
#include "ixheaace_cplx_pred.h"
+#include "ixheaace_aac_constants.h"
static WORD32 iusace_window_shape[5] = {WIN_SEL_1, WIN_SEL_0, WIN_SEL_0, WIN_SEL_1, WIN_SEL_0};
@@ -395,7 +396,7 @@ IA_ERRORCODE iusace_grouping(ia_sfb_params_struct *pstr_sfb_prms, WORD32 num_cha
}
pstr_sfb_prms->grouped_sfb_offset[ch][i] = k;
} else {
- return -1;
+ return IA_EXHEAACE_EXE_FATAL_USAC_INVALID_WINDOW_TYPE;
}
}
@@ -437,14 +438,15 @@ IA_ERRORCODE iusace_grouping(ia_sfb_params_struct *pstr_sfb_prms, WORD32 num_cha
}
}
}
- return 0;
+ return IA_NO_ERROR;
}
IA_ERRORCODE iusace_quantize_spec(ia_sfb_params_struct *pstr_sfb_prms,
WORD32 usac_independancy_flag, WORD32 num_chans,
ia_usac_data_struct *ptr_usac_data,
ia_usac_encoder_config_struct *ptr_usac_config, WORD32 chn,
- WORD32 ele_id) {
+ WORD32 ele_id, WORD32 *is_quant_spec_zero,
+ WORD32 *is_gain_limited) {
IA_ERRORCODE err_code;
WORD32 i = 0, sfb;
WORD32 j = 0;
@@ -473,6 +475,7 @@ IA_ERRORCODE iusace_quantize_spec(ia_sfb_params_struct *pstr_sfb_prms,
WORD32 *ptr_num_sfb = pstr_sfb_prms->num_sfb;
WORD32 *ptr_num_window_groups = pstr_sfb_prms->num_window_groups;
WORD32 bitres_bits, bitres_diff;
+ WORD32 gain;
memset(num_scfs, 0, 2 * sizeof(num_scfs[0]));
@@ -531,7 +534,7 @@ IA_ERRORCODE iusace_quantize_spec(ia_sfb_params_struct *pstr_sfb_prms,
idx = 0;
for (ch = chn; ch < chn + num_chans; ch++) {
iterations = 0;
-
+ gain = 0;
for (kk = 0; kk < ptr_usac_config->ccfl; kk++) {
ptr_exp_spec[kk] = (FLOAT32)pstr_psy_out[ch].ptr_spec_coeffs[kk];
ptr_mdct_spec_float[kk] = (FLOAT32)pstr_psy_out[ch].ptr_spec_coeffs[kk];
@@ -544,6 +547,7 @@ IA_ERRORCODE iusace_quantize_spec(ia_sfb_params_struct *pstr_sfb_prms,
sfb_offs += pstr_psy_out[ch].sfb_per_group) {
for (sfb = 0; sfb < pstr_psy_out[ch].max_sfb_per_grp; sfb++) {
WORD32 scalefactor = pstr_qc_out->str_qc_out_chan[idx].scalefactor[sfb + sfb_offs];
+ gain = MAX(gain, pstr_qc_out->str_qc_out_chan[idx].global_gain - scalefactor);
iusace_quantize_lines(
pstr_qc_out->str_qc_out_chan[idx].global_gain - scalefactor,
pstr_psy_out[ch].sfb_offsets[sfb_offs + sfb + 1] -
@@ -600,15 +604,26 @@ IA_ERRORCODE iusace_quantize_spec(ia_sfb_params_struct *pstr_sfb_prms,
if (max_bits > max_ch_dyn_bits[idx]) {
constraints_fulfilled = 0;
}
- if (!constraints_fulfilled) {
- pstr_qc_out->str_qc_out_chan[idx].global_gain++;
- }
if (quant_spec_is_zero == 1) {
constraints_fulfilled = 1;
+ /*Bit consuption is exceding bit reservoir, there is no scope left for bit consumption
+ reduction, as spectrum is zero. Hence breaking the quantization loop. */
if (iterations > 0) {
+ *is_quant_spec_zero = 1;
max_bits = max_ch_dyn_bits[idx];
}
}
+ if ((gain == MAX_GAIN_INDEX) && (constraints_fulfilled == 0)) {
+ /* Bit consuption is exceding bit reservoir, there is no scope left for bit consumption
+ reduction, as gain has reached the maximum value. Hence breaking the quantization
+ loop. */
+ constraints_fulfilled = 1;
+ *is_gain_limited = 1;
+ max_bits = max_ch_dyn_bits[idx];
+ }
+ if (!constraints_fulfilled) {
+ pstr_qc_out->str_qc_out_chan[idx].global_gain++;
+ }
iterations++;
} while (!constraints_fulfilled);
diff --git a/encoder/ixheaace_hybrid_init.c b/encoder/ixheaace_hybrid_init.c
index 22e7b13..e88ab23 100644
--- a/encoder/ixheaace_hybrid_init.c
+++ b/encoder/ixheaace_hybrid_init.c
@@ -21,7 +21,7 @@
#include <string.h>
#include "ixheaac_type_def.h"
-
+#include "ixheaac_error_standards.h"
#include "ixheaace_common_rom.h"
#include "ixheaace_sbr_def.h"
#include "ixheaace_resampler.h"
@@ -61,5 +61,5 @@ ixheaace_create_hybrid_filter_bank(ixheaace_pstr_hybrid pstr_hybrid, FLOAT32 **p
}
*pptr_flt = ptr_flt;
- return 0;
+ return IA_NO_ERROR;
}
diff --git a/encoder/ixheaace_mps_nlc_enc.c b/encoder/ixheaace_mps_nlc_enc.c
index 4f5dae7..1a5254c 100644
--- a/encoder/ixheaace_mps_nlc_enc.c
+++ b/encoder/ixheaace_mps_nlc_enc.c
@@ -1581,13 +1581,13 @@ IA_ERRORCODE ixheaace_mps_212_ec_data_single_enc(
return IA_NO_ERROR;
}
-WORD32 ixheaace_mps_515_ec_data_pair_enc(ixheaace_bit_buf_handle pstr_bit_buf,
+VOID ixheaace_mps_515_ec_data_pair_enc(ixheaace_bit_buf_handle pstr_bit_buf,
WORD32 pp_in_data[][MAXBANDS],
WORD32 p_in_data[MAXBANDS], WORD32 data_type,
WORD32 set_idx, WORD32 start_band, WORD32 data_bands,
WORD32 pair_flag, WORD32 coarse_flag,
WORD32 independency_flag) {
- WORD32 dummy = 0, reset = 0;
+ WORD32 dummy = 0;
WORD32 quant_levels = 0, quant_offset = 0, num_pcm_val = 0;
WORD32 split_lsb_flag = 0;
@@ -1666,7 +1666,7 @@ WORD32 ixheaace_mps_515_ec_data_pair_enc(ixheaace_bit_buf_handle pstr_bit_buf,
break;
default:
- return 0;
+ return;
}
memcpy(a_data_hist, p_in_data + start_band, sizeof(WORD32) * data_bands);
@@ -1910,5 +1910,5 @@ WORD32 ixheaace_mps_515_ec_data_pair_enc(ixheaace_bit_buf_handle pstr_bit_buf,
}
}
- return reset;
+ return;
}
diff --git a/encoder/ixheaace_mps_sac_nlc_enc.h b/encoder/ixheaace_mps_sac_nlc_enc.h
index 257e8bd..ff7c6aa 100644
--- a/encoder/ixheaace_mps_sac_nlc_enc.h
+++ b/encoder/ixheaace_mps_sac_nlc_enc.h
@@ -19,7 +19,7 @@
*/
#pragma once
-WORD32 ixheaace_mps_515_ec_data_pair_enc(ixheaace_bit_buf_handle strm,
+VOID ixheaace_mps_515_ec_data_pair_enc(ixheaace_bit_buf_handle strm,
WORD32 aa_in_data[][MAXBANDS],
WORD32 a_history[MAXBANDS], WORD32 data_type,
WORD32 set_idx, WORD32 start_band, WORD32 data_bands,
diff --git a/encoder/ixheaace_nf.c b/encoder/ixheaace_nf.c
index 00e67a1..0a9de9b 100644
--- a/encoder/ixheaace_nf.c
+++ b/encoder/ixheaace_nf.c
@@ -18,6 +18,7 @@
* Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
+#include <float.h>
#include <string.h>
#include <math.h>
#include "iusace_cnst.h"
@@ -37,6 +38,7 @@ static VOID iusace_noise_filling_limiter(FLOAT64 *energy, FLOAT64 *ptr_spec,
FLOAT64 *ptr_highest_tone) {
WORD32 n, i;
FLOAT64 tone_energy;
+ FLOAT64 tot_tone_energy = 0.0;
if (!n0_by_4) return;
if (cntr <= n0_by_4) return;
@@ -59,7 +61,18 @@ static VOID iusace_noise_filling_limiter(FLOAT64 *energy, FLOAT64 *ptr_spec,
}
}
/* remove the contribution of the highest_tone components */
- for (n = 0; n < n0_by_4; n++) *energy -= ptr_highest_tone[n];
+ for (n = 0; n < n0_by_4; n++) tot_tone_energy += ptr_highest_tone[n];
+
+ FLOAT64 diff = *energy - tot_tone_energy;
+ //If the difference is within 1% of total energy, no need to send any energy
+ if (diff < 0.01*(*energy))
+ {
+ *energy = 0.0;
+ }
+ else
+ {
+ *energy = diff;
+ }
/* add the average component energy */
*energy += n0_by_4 * (*energy) / (cntr - n0_by_4);
@@ -119,8 +132,8 @@ VOID iusace_noise_filling(WORD32 *noise_level, WORD32 *noise_offset, FLOAT64 *pt
/* Remove highest (tonal) contributions */
iusace_noise_filling_limiter(&energy, &ptr_quant_spec[offset],
- pstr_quant_info->quant_degroup, n0 / 4, ptr_sfb_offset, sfb,
- n0, ptr_scratch_buf);
+ &pstr_quant_info->quant_degroup[offset], n0 / 4,
+ ptr_sfb_offset, sfb, n0, ptr_scratch_buf);
if (band_quantized_to_zero == 0) {
e_sfb_on += energy;
diff --git a/encoder/ixheaace_ps_enc_init.c b/encoder/ixheaace_ps_enc_init.c
index b4ba882..c055184 100644
--- a/encoder/ixheaace_ps_enc_init.c
+++ b/encoder/ixheaace_ps_enc_init.c
@@ -19,7 +19,7 @@
*/
#include <string.h>
-
+#include "ixheaac_error_standards.h"
#include "ixheaac_type_def.h"
#include "ixheaace_sbr_def.h"
#include "ixheaace_resampler.h"
@@ -30,7 +30,7 @@
#include "ixheaace_sbr_ps_enc.h"
#include "ixheaac_constants.h"
#include "ixheaace_aac_constants.h"
-
+#include "ixheaace_error_codes.h"
#include "ixheaace_bitbuffer.h"
WORD32 ixheaace_get_ps_mode(WORD32 bitrate) {
@@ -43,24 +43,23 @@ WORD32 ixheaace_get_ps_mode(WORD32 bitrate) {
return ps_mode;
}
-WORD32
+IA_ERRORCODE
ixheaace_create_ps_enc(ixheaace_pstr_ps_enc pstr_ps_enc, WORD32 ps_mode,
FLOAT32 *ptr_common_buffer, FLOAT32 *ptr_common_buffer2,
FLOAT32 *ptr_ps_buf3) {
WORD32 i;
- WORD32 err;
+ IA_ERRORCODE err = IA_NO_ERROR;
FLOAT32 *ptr1, *ptr2, *ptr3, *ptr4;
+ if (pstr_ps_enc == NULL) {
+ return IA_EXHEAACE_INIT_FATAL_PS_INIT_FAILED;
+ }
ptr1 = &ptr_common_buffer2[IXHEAACE_QMF_TIME_SLOTS * IXHEAACE_QMF_CHANNELS];
ptr2 = pstr_ps_enc->ps_buf2;
ptr3 = ptr_ps_buf3;
ptr4 = &ptr_common_buffer[5 * NO_OF_ESTIMATES * MAXIMUM_FREQ_COEFFS];
- if (pstr_ps_enc == NULL) {
- return 1;
- }
-
pstr_ps_enc->ps_mode = ps_mode;
pstr_ps_enc->b_prev_zero_iid = 0;
pstr_ps_enc->b_prev_zero_icc = 0;
@@ -93,14 +92,14 @@ ixheaace_create_ps_enc(ixheaace_pstr_ps_enc pstr_ps_enc, WORD32 ps_mode,
err = ixheaace_create_hybrid_filter_bank(pstr_ps_enc->ptr_hybrid_left, &ptr4);
- if (err != 0) {
- return 1;
+ if (err) {
+ return err;
}
err = ixheaace_create_hybrid_filter_bank(pstr_ps_enc->ptr_hybrid_right, &ptr4);
- if (err != 0) {
- return 1;
+ if (err) {
+ return err;
}
for (i = 0; i < NUMBER_OF_SUBSAMPLES; i++) {
@@ -189,7 +188,7 @@ ixheaace_create_ps_enc(ixheaace_pstr_ps_enc pstr_ps_enc, WORD32 ps_mode,
if ((pstr_ps_enc->hist_qmf_left_real == NULL) || (pstr_ps_enc->hist_qmf_left_imag == NULL) ||
(pstr_ps_enc->hist_qmf_right_real == NULL) || (pstr_ps_enc->hist_qmf_right_imag == NULL)) {
- return 1;
+ return IA_EXHEAACE_INIT_FATAL_PS_INIT_FAILED;
}
for (i = 0; i < pstr_ps_enc->iid_icc_bins; i++) {
@@ -207,5 +206,5 @@ ixheaace_create_ps_enc(ixheaace_pstr_ps_enc pstr_ps_enc, WORD32 ps_mode,
pstr_ps_enc->ps_bit_buf.ptr_write_next =
pstr_ps_enc->ps_bit_buf.ptr_bit_buf_base + pstr_ps_enc->bit_buf_write_offset;
- return 0;
+ return err;
}
diff --git a/encoder/ixheaace_qc_data.h b/encoder/ixheaace_qc_data.h
index 02979c4..4f099a3 100644
--- a/encoder/ixheaace_qc_data.h
+++ b/encoder/ixheaace_qc_data.h
@@ -83,6 +83,10 @@ typedef struct {
#define TRANSPORT_BITS (208)
+#define MAX_GAIN_INDEX_AAC (128)
+#define MIN_GAIN_INDEX_AAC (-128)
+#define SCF_COUNT_LIMIT_AAC (1)
+
typedef struct {
WORD16 *quant_spec;
UWORD16 *max_val_in_sfb;
diff --git a/encoder/ixheaace_qc_main_hp.c b/encoder/ixheaace_qc_main_hp.c
index d531b9b..0eae6e6 100644
--- a/encoder/ixheaace_qc_main_hp.c
+++ b/encoder/ixheaace_qc_main_hp.c
@@ -74,9 +74,13 @@ IA_ERRORCODE ia_enhaacplus_enc_qc_main(
ixheaace_qc_out_channel pstr_qc_out_ch[IXHEAACE_MAX_CH_IN_BS_ELE],
ixheaace_qc_out_element *pstr_qc_out_element, WORD32 ancillary_data_bytes,
ixheaace_aac_tables *pstr_aac_tables, WORD32 adts_flag, WORD32 aot, WORD32 stat_bits_flag,
- WORD32 flag_last_element, WORD32 frame_len_long, WORD8 *ptr_scratch) {
+ WORD32 flag_last_element, WORD32 frame_len_long, WORD8 *ptr_scratch,
+ WORD32 *is_quant_spec_zero, WORD32 *is_gain_limited) {
IA_ERRORCODE err_code;
WORD32 ch;
+ WORD32 i = 0;
+ WORD32 k = 0;
+ WORD32 j = 0;
WORD32 iterations = 0;
WORD32 constraints_fulfilled;
WORD32 ch_dyn_bits;
@@ -86,6 +90,7 @@ IA_ERRORCODE ia_enhaacplus_enc_qc_main(
ptr_scratch += sizeof(ixheaace_qc_stack);
ia_adj_thr_elem_struct *pstr_adj_thr_elem = &pstr_qc_state->str_adj_thr.str_adj_thr_ele;
+ WORD32 gain;
if (pstr_el_bits->bit_res_level < 0) {
return IA_EXHEAACE_EXE_FATAL_INVALID_BIT_RES_LEVEL;
@@ -139,6 +144,7 @@ IA_ERRORCODE ia_enhaacplus_enc_qc_main(
are fulfilled */
WORD32 spec_idx, sfb_offs, sfb;
iterations = 0;
+ gain = 0;
for (spec_idx = 0; spec_idx < frame_len_long; spec_idx++) {
ptr_stack->exp_spec[spec_idx] = (FLOAT32)psy_out_ch[ch].ptr_spec_coeffs[spec_idx];
ptr_stack->mdct_spec_float[spec_idx] = (FLOAT32)psy_out_ch[ch].ptr_spec_coeffs[spec_idx];
@@ -146,11 +152,13 @@ IA_ERRORCODE ia_enhaacplus_enc_qc_main(
do {
WORD32 max_val;
constraints_fulfilled = 1;
+ WORD32 quant_spec_is_zero = 1;
if (iterations > 0) {
for (sfb_offs = 0; sfb_offs < psy_out_ch[ch].sfb_count;
sfb_offs += psy_out_ch[ch].sfb_per_group) {
for (sfb = 0; sfb < psy_out_ch[ch].max_sfb_per_grp; sfb++) {
WORD32 scalefactor = pstr_qc_out_ch[ch].scalefactor[sfb + sfb_offs];
+ gain = MAX(gain, pstr_qc_out_ch[ch].global_gain - scalefactor);
iaace_quantize_lines(
pstr_qc_out_ch[ch].global_gain - scalefactor,
psy_out_ch[ch].sfb_offsets[sfb_offs + sfb + 1] -
@@ -171,6 +179,17 @@ IA_ERRORCODE ia_enhaacplus_enc_qc_main(
constraints_fulfilled = 0;
}
+ for (k = 0; ((k < psy_out_ch[ch].sfb_count) && (quant_spec_is_zero));
+ k += psy_out_ch[ch].sfb_per_group) {
+ for (i = 0; ((i < psy_out_ch[ch].max_sfb_per_grp) && (quant_spec_is_zero)); i++) {
+ for (j = psy_out_ch[ch].sfb_offsets[i+k]; j < psy_out_ch[ch].sfb_offsets[i+k+1]; j++) {
+ if (pstr_qc_out_ch[ch].quant_spec[j] != 0) {
+ quant_spec_is_zero = 0;
+ break;
+ }
+ }
+ }
+ }
err_code = ia_enhaacplus_enc_dyn_bitcount(
pstr_qc_out_ch[ch].quant_spec, pstr_qc_out_ch[ch].max_val_in_sfb,
pstr_qc_out_ch[ch].scalefactor, psy_out_ch[ch].window_sequence,
@@ -188,10 +207,26 @@ IA_ERRORCODE ia_enhaacplus_enc_qc_main(
constraints_fulfilled = 0;
}
+ if (quant_spec_is_zero == 1) {
+ constraints_fulfilled = 1;
+ /*Bit consuption is exceding bit reservoir, there is no scope left for bit consumption
+ reduction, as spectrum is zero. Hence breaking the quantization loop. */
+ if (iterations > 0) {
+ *is_quant_spec_zero = 1;
+ ch_dyn_bits = max_ch_dyn_bits[ch];
+ }
+ }
+ if ((gain == MAX_GAIN_INDEX) && (constraints_fulfilled == 0)) {
+ /* Bit consuption is exceding bit reservoir, there is no scope left for bit consumption
+ reduction, as gain has reached the maximum value. Hence breaking the quantization
+ loop. */
+ constraints_fulfilled = 1;
+ *is_gain_limited = 1;
+ ch_dyn_bits = max_ch_dyn_bits[ch];
+ }
if (!constraints_fulfilled) {
pstr_qc_out_ch[ch].global_gain++;
}
-
iterations++;
} while (!constraints_fulfilled);
diff --git a/encoder/ixheaace_qc_util.c b/encoder/ixheaace_qc_util.c
index 7f21837..0cd022b 100644
--- a/encoder/ixheaace_qc_util.c
+++ b/encoder/ixheaace_qc_util.c
@@ -111,9 +111,9 @@ static WORD32 ia_enhaacplus_enc_frame_padding(WORD32 bit_rate, WORD32 sample_rat
return padding_on;
}
-WORD32 ia_enhaacplus_enc_qc_out_new(ixheaace_qc_out *pstr_qc_out, WORD32 num_channels,
- WORD32 *ptr_shared_buffer1, WORD32 *ptr_shared_buffer3,
- WORD32 long_frame_len)
+IA_ERRORCODE ia_enhaacplus_enc_qc_out_new(ixheaace_qc_out *pstr_qc_out, WORD32 num_channels,
+ WORD32 *ptr_shared_buffer1, WORD32 *ptr_shared_buffer3,
+ WORD32 long_frame_len)
{
WORD32 i;
@@ -140,18 +140,20 @@ WORD32 ia_enhaacplus_enc_qc_out_new(ixheaace_qc_out *pstr_qc_out, WORD32 num_cha
sizeof(*pstr_qc_out->qc_channel[i]->scalefactor) * MAXIMUM_GROUPED_SCALE_FACTOR_BAND);
}
- return (pstr_qc_out == NULL);
+ if (pstr_qc_out == NULL) {
+ return IA_EXHEAACE_INIT_FATAL_AAC_INIT_FAILED;
+ }
+ return IA_NO_ERROR;
}
-WORD32 ia_enhaacplus_enc_qc_new(ixheaace_qc_state *pstr_qc_state, WORD32 *ptr_shared_buffer_2,
- WORD32 long_frame_len
-
+IA_ERRORCODE ia_enhaacplus_enc_qc_new(ixheaace_qc_state *pstr_qc_state,
+ WORD32 *ptr_shared_buffer_2, WORD32 long_frame_len
) {
memset(pstr_qc_state, 0, sizeof(ixheaace_qc_state));
pstr_qc_state->qc_scr.shared_buffer_2 =
(ptr_shared_buffer_2 + long_frame_len * IXHEAACE_MAX_CH_IN_BS_ELE + 16);
- return (0);
+ return IA_NO_ERROR;
}
IA_ERRORCODE ia_enhaacplus_enc_qc_init(ixheaace_qc_state *pstr_qc_state, WORD32 aot,
diff --git a/encoder/ixheaace_qc_util.h b/encoder/ixheaace_qc_util.h
index 0db1dd7..6e971cd 100644
--- a/encoder/ixheaace_qc_util.h
+++ b/encoder/ixheaace_qc_util.h
@@ -20,12 +20,12 @@
#pragma once
-WORD32 ia_enhaacplus_enc_qc_out_new(ixheaace_qc_out *pstr_qc_out, WORD32 num_channels,
- WORD32 *ptr_shared_buffer1, WORD32 *ptr_shared_buffer3,
- WORD32 frame_len_long);
+IA_ERRORCODE ia_enhaacplus_enc_qc_out_new(ixheaace_qc_out *pstr_qc_out, WORD32 num_channels,
+ WORD32 *ptr_shared_buffer1, WORD32 *ptr_shared_buffer3,
+ WORD32 frame_len_long);
-WORD32 ia_enhaacplus_enc_qc_new(ixheaace_qc_state *pstr_qc_state, WORD32 *ptr_shared_buffer_2,
- WORD32 frame_len_long);
+IA_ERRORCODE ia_enhaacplus_enc_qc_new(ixheaace_qc_state *pstr_qc_state,
+ WORD32 *ptr_shared_buffer_2, WORD32 frame_len_long);
IA_ERRORCODE ia_enhaacplus_enc_qc_init(ixheaace_qc_state *pstr_qc_state, WORD32 aot,
ixheaace_qc_init *pstr_init, FLAG flag_framelength_small);
@@ -37,7 +37,8 @@ IA_ERRORCODE ia_enhaacplus_enc_qc_main(
ixheaace_qc_out_channel pstr_qc_out_ch[IXHEAACE_MAX_CH_IN_BS_ELE],
ixheaace_qc_out_element *pstr_qc_out_element, WORD32 ancillary_data_bytes,
ixheaace_aac_tables *pstr_aac_tables, WORD32 adts_flag, WORD32 aot, WORD32 stat_bits_flag,
- WORD32 flag_last_element, WORD32 frame_len_long, WORD8 *ptr_scratch);
+ WORD32 flag_last_element, WORD32 frame_len_long, WORD8 *ptr_scratch,
+ WORD32 *is_quant_spec_zero, WORD32 *is_gain_limited);
VOID ia_enhaacplus_enc_update_bit_reservoir(ixheaace_qc_state *pstr_qc_kernel,
ixheaace_qc_out *pstr_qc_out);
diff --git a/encoder/ixheaace_sbr_code_envelope.c b/encoder/ixheaace_sbr_code_envelope.c
index 827ce00..ce12800 100644
--- a/encoder/ixheaace_sbr_code_envelope.c
+++ b/encoder/ixheaace_sbr_code_envelope.c
@@ -36,12 +36,11 @@
#include "ixheaace_common_rom.h"
#include "ixheaace_sbr_main.h"
#include "ixheaace_sbr_frame_info_gen.h"
-
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_code_envelope.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_env_est.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_missing_harmonics_det.h"
#include "ixheaace_sbr_inv_filtering_estimation.h"
#include "ixheaace_sbr_noise_floor_est.h"
diff --git a/encoder/ixheaace_sbr_code_envelope_lp.c b/encoder/ixheaace_sbr_code_envelope_lp.c
index c452715..95c9adf 100644
--- a/encoder/ixheaace_sbr_code_envelope_lp.c
+++ b/encoder/ixheaace_sbr_code_envelope_lp.c
@@ -36,12 +36,11 @@
#include "ixheaace_common_rom.h"
#include "ixheaace_sbr_main.h"
#include "ixheaace_sbr_frame_info_gen.h"
-
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_code_envelope.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_env_est.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_missing_harmonics_det.h"
#include "ixheaace_sbr_inv_filtering_estimation.h"
#include "ixheaace_sbr_noise_floor_est.h"
diff --git a/encoder/ixheaace_sbr_env_est.c b/encoder/ixheaace_sbr_env_est.c
index 75d588e..7f3cc83 100644
--- a/encoder/ixheaace_sbr_env_est.c
+++ b/encoder/ixheaace_sbr_env_est.c
@@ -38,12 +38,12 @@
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
#include "ixheaace_sbr_env_est.h"
#include "ixheaace_sbr_code_envelope.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_main.h"
#include "ixheaace_sbr_missing_harmonics_det.h"
#include "ixheaace_sbr_inv_filtering_estimation.h"
@@ -70,12 +70,12 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
#include "ixheaace_sbr_env_est.h"
#include "ixheaace_sbr_code_envelope.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_psy_const.h"
#include "ixheaace_tns.h"
#include "ixheaace_tns_params.h"
@@ -719,10 +719,12 @@ static IA_ERRORCODE ixheaace_update_esbr_ext_data(
static VOID ixheaace_update_harmonic_sbr_data(
WORD32 transient_info[][3], WORD32 coupling,
- struct ixheaace_str_sbr_env_data *pstr_sbr_env_left,
- struct ixheaace_str_sbr_env_data *pstr_sbr_env_right, WORD32 num_channels) {
+ ixheaace_pstr_enc_channel *pstr_enc_ch, WORD32 num_channels) {
WORD32 bin, bin1;
+ struct ixheaace_str_sbr_env_data *pstr_sbr_env_left = NULL;
+ struct ixheaace_str_sbr_env_data *pstr_sbr_env_right = NULL;
if (1 == num_channels) {
+ pstr_sbr_env_left = &pstr_enc_ch[0]->enc_env_data;
bin = pstr_sbr_env_left->sbr_pitchin_bins;
if (transient_info[0][1] != 0) {
pstr_sbr_env_left->sbr_preprocessing = 1;
@@ -748,6 +750,8 @@ static VOID ixheaace_update_harmonic_sbr_data(
pstr_sbr_env_left->sbr_patching_mode = 1;
}
} else {
+ pstr_sbr_env_left = &pstr_enc_ch[0]->enc_env_data;
+ pstr_sbr_env_right = &pstr_enc_ch[1]->enc_env_data;
pstr_sbr_env_left->sbr_coupling = coupling;
pstr_sbr_env_right->sbr_coupling = coupling;
bin = pstr_sbr_env_left->sbr_pitchin_bins;
@@ -1813,8 +1817,11 @@ IA_ERRORCODE ixheaace_extract_sbr_envelope(FLOAT32 *ptr_in_time, FLOAT32 *ptr_co
ixheaace_sbr_stereo_mode stereo_mode = pstr_sbr_cfg->stereo_mode;
struct ixheaace_str_sbr_env_data *pstr_env_0 = &(pstr_env_ch[0]->enc_env_data);
- struct ixheaace_str_sbr_env_data *pstr_env_1 = &(pstr_env_ch[1]->enc_env_data);
+ struct ixheaace_str_sbr_env_data *pstr_env_1 = NULL;
+ if (num_channels > 1) {
+ pstr_env_1 = &(pstr_env_ch[1]->enc_env_data);
+ }
ixheaace_freq_res res[MAXIMUM_NUM_NOISE_VALUES];
WORD32 *ptr_v_tuning;
WORD32 v_tuning_lc_sbr[6] = {0, 2, 4, 0, 0, 0};
@@ -1834,7 +1841,7 @@ IA_ERRORCODE ixheaace_extract_sbr_envelope(FLOAT32 *ptr_in_time, FLOAT32 *ptr_co
(WORD32 *)pstr_env_ch[0]->str_sbr_extract_env.ptr_r_buffer[0];
WORD32 max_quant_error;
- ixheaace_str_esbr_bs_data str_esbr = { 0 };
+ ixheaace_str_esbr_bs_data str_esbr = {0};
WORD32 samp_ratio_fac = DOWNSAMPLE_FAC_2_1;
if ((pstr_env_enc->str_sbr_cfg.sbr_codec == USAC_SBR) &&
(pstr_env_enc->str_sbr_cfg.sbr_ratio_idx == USAC_SBR_RATIO_INDEX_4_1)) {
@@ -2124,9 +2131,8 @@ IA_ERRORCODE ixheaace_extract_sbr_envelope(FLOAT32 *ptr_in_time, FLOAT32 *ptr_co
pstr_sbr_extract_env->ptr_y_buffer + pstr_sbr_extract_env->y_buffer_write_offset,
pstr_sbr_extract_env->ptr_r_buffer, pstr_sbr_extract_env->ptr_i_buffer,
pstr_sbr_cfg->is_ld_sbr, pstr_env_ch[ch]->str_sbr_qmf.num_time_slots, samp_ratio_fac,
- pstr_hbe_enc->qmf_buf_real, pstr_hbe_enc->qmf_buf_imag,
- (IXHEAACE_OP_DELAY_OFFSET + IXHEAACE_ESBR_HBE_DELAY_OFFSET + IXHEAACE_SBR_HF_ADJ_OFFSET),
- pstr_sbr_hdr->sbr_harmonic);
+ pstr_hbe_enc, (IXHEAACE_OP_DELAY_OFFSET + IXHEAACE_ESBR_HBE_DELAY_OFFSET +
+ IXHEAACE_SBR_HF_ADJ_OFFSET), pstr_sbr_hdr->sbr_harmonic);
ixheaace_calculate_tonality_quotas(
&pstr_env_ch[ch]->str_ton_corr, pstr_sbr_extract_env->ptr_r_buffer,
@@ -2880,8 +2886,7 @@ IA_ERRORCODE ixheaace_extract_sbr_envelope(FLOAT32 *ptr_in_time, FLOAT32 *ptr_co
if ((pstr_sbr_cfg->sbr_codec == USAC_SBR) && (pstr_sbr_hdr->sbr_harmonic)) {
ixheaace_update_harmonic_sbr_data(transient_info, pstr_sbr_hdr->coupling,
- &pstr_env_ch[0]->enc_env_data,
- &pstr_env_ch[1]->enc_env_data, num_channels);
+ &pstr_env_ch[0], num_channels);
}
if (num_channels == 2) {
WORD32 num_bits;
diff --git a/encoder/ixheaace_sbr_env_est_init.c b/encoder/ixheaace_sbr_env_est_init.c
index a369760..19e0713 100644
--- a/encoder/ixheaace_sbr_env_est_init.c
+++ b/encoder/ixheaace_sbr_env_est_init.c
@@ -35,12 +35,12 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
#include "ixheaace_sbr_env_est.h"
#include "ixheaace_sbr_code_envelope.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_main.h"
#include "ixheaace_sbr_missing_harmonics_det.h"
#include "ixheaace_sbr_inv_filtering_estimation.h"
diff --git a/encoder/ixheaace_sbr_freq_scaling.c b/encoder/ixheaace_sbr_freq_scaling.c
index 71b879c..bf7bafa 100644
--- a/encoder/ixheaace_sbr_freq_scaling.c
+++ b/encoder/ixheaace_sbr_freq_scaling.c
@@ -292,21 +292,7 @@ ixheaace_get_sbr_start_freq_raw(WORD32 start_freq, WORD32 qmf_bands, WORD32 fs)
result = (result * fs / qmf_bands + 1) >> 1;
- return (result);
-}
-
-WORD32 ixheaace_get_sbr_stop_freq_raw(WORD32 stop_freq, WORD32 qmf_bands, WORD32 fs) {
- WORD32 result;
-
- if ((stop_freq < 0) || (stop_freq > 13)) {
- return -1;
- }
-
- result = ixheaace_get_stop_freq(fs, stop_freq);
-
- result = (result * fs / qmf_bands + 1) >> 1;
-
- return (result);
+ return result;
}
static WORD32 ixheaace_number_of_bands(WORD32 b_p_o, WORD32 start, WORD32 stop,
@@ -584,6 +570,14 @@ ixheaace_update_freq_scale(UWORD8 *ptr_k_master, WORD32 *ptr_num_bands, const WO
return IA_EXHEAACE_INIT_FATAL_SBR_INVALID_NUM_BANDS;
}
+ if (sbr_rate == IXHEAACE_QUAD_RATE) {
+ for (i = 1; i < *ptr_num_bands; i++) {
+ if (!(ptr_k_master[i] - ptr_k_master[i - 1] <= k0 - 2)) {
+ return IA_EXHEAACE_INIT_FATAL_SBR_INVALID_NUM_BANDS;
+ }
+ }
+ }
+
return err_code;
}
diff --git a/encoder/ixheaace_sbr_freq_scaling.h b/encoder/ixheaace_sbr_freq_scaling.h
index 1a04a35..fe107e1 100644
--- a/encoder/ixheaace_sbr_freq_scaling.h
+++ b/encoder/ixheaace_sbr_freq_scaling.h
@@ -43,5 +43,3 @@ ixheaace_find_start_and_stop_band(const WORD32 sampling_freq, const WORD32 num_c
ixheaace_sbr_codec_type sbr_codec);
WORD32 ixheaace_get_sbr_start_freq_raw(WORD32 start_freq, WORD32 qmf_bands, WORD32 fs);
-
-WORD32 ixheaace_get_sbr_stop_freq_raw(WORD32 stop_freq, WORD32 qmf_bands, WORD32 fs);
diff --git a/encoder/ixheaace_sbr_main.c b/encoder/ixheaace_sbr_main.c
index 3de7d91..62919f2 100644
--- a/encoder/ixheaace_sbr_main.c
+++ b/encoder/ixheaace_sbr_main.c
@@ -40,12 +40,12 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
#include "ixheaace_sbr_env_est.h"
#include "ixheaace_sbr_code_envelope.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_psy_const.h"
#include "ixheaace_tns.h"
#include "ixheaace_tns_params.h"
diff --git a/encoder/ixheaace_sbr_missing_harmonics_det.c b/encoder/ixheaace_sbr_missing_harmonics_det.c
index 5171650..5527e4a 100644
--- a/encoder/ixheaace_sbr_missing_harmonics_det.c
+++ b/encoder/ixheaace_sbr_missing_harmonics_det.c
@@ -20,7 +20,7 @@
#include <string.h>
#include <math.h>
-
+#include <float.h>
#include "ixheaac_type_def.h"
#include "ixheaac_constants.h"
#include "ixheaac_error_standards.h"
@@ -35,12 +35,12 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
#include "ixheaace_sbr_env_est.h"
#include "ixheaace_sbr_code_envelope.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_main.h"
#include "ixheaace_sbr_missing_harmonics_det.h"
#include "ixheaace_sbr_inv_filtering_estimation.h"
@@ -50,6 +50,7 @@
#include "iusace_esbr_pvc.h"
#include "iusace_esbr_inter_tes.h"
#include "ixheaace_sbr.h"
+#include "ixheaace_common_utils.h"
static VOID ia_enhaacplus_enc_diff(FLOAT32 *ptr_tonal_orig, FLOAT32 *ptr_diff_map_2_scfb,
const UWORD8 *ptr_freq_band_tab, WORD32 n_scfb,
@@ -538,7 +539,7 @@ static VOID ia_enhaacplus_enc_calculate_comp_vector(
comp_val = SBR_MAX_COMP;
}
- if ((FLOAT32)1.0f / ptr_diff[max_pos_est][i - 1] >
+ if (ixheaace_div32((FLOAT32)1.0f, ptr_diff[max_pos_est][i - 1]) >
(SBR_DIFF_QUOTA * ptr_diff[max_pos_est][i])) {
ptr_env_compensation[i - 1] = -1 * comp_val;
}
@@ -549,7 +550,7 @@ static VOID ia_enhaacplus_enc_calculate_comp_vector(
comp_val = SBR_MAX_COMP;
}
- if ((FLOAT32)1.0f / ptr_diff[max_pos_est][i + 1] >
+ if (ixheaace_div32((FLOAT32)1.0f, ptr_diff[max_pos_est][i + 1]) >
(SBR_DIFF_QUOTA * ptr_diff[max_pos_est][i])) {
ptr_env_compensation[i + 1] = comp_val;
}
diff --git a/encoder/ixheaace_sbr_noise_floor_est.c b/encoder/ixheaace_sbr_noise_floor_est.c
index 573790b..c5fcd99 100644
--- a/encoder/ixheaace_sbr_noise_floor_est.c
+++ b/encoder/ixheaace_sbr_noise_floor_est.c
@@ -36,12 +36,12 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
#include "ixheaace_sbr_env_est.h"
#include "ixheaace_sbr_code_envelope.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_main.h"
#include "ixheaace_sbr_missing_harmonics_det.h"
#include "ixheaace_sbr_inv_filtering_estimation.h"
diff --git a/encoder/ixheaace_sbr_ps_enc.h b/encoder/ixheaace_sbr_ps_enc.h
index 0c43c39..58c00a5 100644
--- a/encoder/ixheaace_sbr_ps_enc.h
+++ b/encoder/ixheaace_sbr_ps_enc.h
@@ -90,7 +90,7 @@ typedef struct ixheaace_ps_enc *ixheaace_pstr_ps_enc;
WORD32 ixheaace_get_ps_mode(WORD32 bit_rate);
-WORD32
+IA_ERRORCODE
ixheaace_create_ps_enc(ixheaace_pstr_ps_enc pstr_ps_enc, WORD32 ps_mode,
FLOAT32 *ptr_common_buffer, FLOAT32 *ptr_common_buffer2,
FLOAT32 *ptr_ps_buf3);
diff --git a/encoder/ixheaace_sbr_qmf_enc.c b/encoder/ixheaace_sbr_qmf_enc.c
index 71a79fd..281ba31 100644
--- a/encoder/ixheaace_sbr_qmf_enc.c
+++ b/encoder/ixheaace_sbr_qmf_enc.c
@@ -27,7 +27,7 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
-
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_hybrid.h"
@@ -944,9 +944,7 @@ VOID ixheaace_sbr_analysis_filtering(const FLOAT32 *ptr_time_in, WORD32 time_sn_
VOID ixheaace_get_energy_from_cplx_qmf(
FLOAT32 **ptr_energy_vals, FLOAT32 **ptr_real_values, FLOAT32 **ptr_imag_values,
WORD32 is_ld_sbr, WORD32 num_time_slots, WORD32 samp_ratio_fac,
- FLOAT32 qmf_buf_real[IXHEAACE_TIMESLOT_BUFFER_SIZE + 2 * 32][IXHEAACE_NUM_QMF_SYNTH_CHANNELS],
- FLOAT32 qmf_buf_imag[IXHEAACE_TIMESLOT_BUFFER_SIZE + 2 * 32][IXHEAACE_NUM_QMF_SYNTH_CHANNELS],
- WORD32 op_delay, WORD32 harmonic_sbr)
+ ixheaace_str_hbe_enc *pstr_hbe_enc, WORD32 op_delay, WORD32 harmonic_sbr)
{
WORD32 j, k;
@@ -958,8 +956,12 @@ VOID ixheaace_get_energy_from_cplx_qmf(
FLOAT32 *ptr_energy_val = &ptr_energy_vals[0][0];
FLOAT32 *ptr_real = &ptr_real_values[0][0];
FLOAT32 *ptr_imag = &ptr_imag_values[0][0];
- FLOAT32 *ptr_hbe_real = &qmf_buf_real[op_delay][0];
- FLOAT32 *ptr_hbe_imag = &qmf_buf_imag[op_delay][0];
+ FLOAT32 *ptr_hbe_real = NULL;
+ FLOAT32 *ptr_hbe_imag = NULL;
+ if (harmonic_sbr == 1) {
+ ptr_hbe_real = &pstr_hbe_enc->qmf_buf_real[op_delay][0];
+ ptr_hbe_imag = &pstr_hbe_enc->qmf_buf_imag[op_delay][0];
+ }
k = (num_time_slots - 1);
while (k >= 0) {
for (j = 63; j >= 0; j--) {
diff --git a/encoder/ixheaace_sbr_qmf_enc.h b/encoder/ixheaace_sbr_qmf_enc.h
index 024c342..5a1dcd6 100644
--- a/encoder/ixheaace_sbr_qmf_enc.h
+++ b/encoder/ixheaace_sbr_qmf_enc.h
@@ -70,9 +70,7 @@ VOID ixheaace_create_qmf_bank(ixheaace_pstr_sbr_qmf_filter_bank pstr_sbr_qmf_han
VOID ixheaace_get_energy_from_cplx_qmf(
FLOAT32 **ptr_energy_vals, FLOAT32 **ptr_real_values, FLOAT32 **ptr_imag_values,
WORD32 is_ld_sbr, WORD32 num_time_slots, WORD32 samp_ratio_fac,
- FLOAT32 qmf_buf_real[IXHEAACE_TIMESLOT_BUFFER_SIZE + 2 * 32][IXHEAACE_NUM_QMF_SYNTH_CHANNELS],
- FLOAT32 qmf_buf_imag[IXHEAACE_TIMESLOT_BUFFER_SIZE + 2 * 32][IXHEAACE_NUM_QMF_SYNTH_CHANNELS],
- WORD32 op_delay, WORD32 harmonic_sbr);
+ ixheaace_str_hbe_enc *pstr_hbe_enc, WORD32 op_delay, WORD32 harmonic_sbr);
VOID ixheaace_enc_synthesis_qmf_filtering(FLOAT32 **ptr_sbr_re, FLOAT32 **ptr_sbr_im,
FLOAT32 *time_float,
diff --git a/encoder/ixheaace_sbr_qmf_enc_init.c b/encoder/ixheaace_sbr_qmf_enc_init.c
index 0348fff..c0c40e0 100644
--- a/encoder/ixheaace_sbr_qmf_enc_init.c
+++ b/encoder/ixheaace_sbr_qmf_enc_init.c
@@ -26,6 +26,7 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_hybrid.h"
diff --git a/encoder/ixheaace_sbr_ton_corr.c b/encoder/ixheaace_sbr_ton_corr.c
index ca623fa..6f2fc06 100644
--- a/encoder/ixheaace_sbr_ton_corr.c
+++ b/encoder/ixheaace_sbr_ton_corr.c
@@ -34,12 +34,12 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
#include "ixheaace_sbr_env_est.h"
#include "ixheaace_sbr_code_envelope.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_main.h"
#include "ixheaace_sbr_missing_harmonics_det.h"
#include "ixheaace_sbr_inv_filtering_estimation.h"
diff --git a/encoder/ixheaace_sbr_ton_corr_hp.c b/encoder/ixheaace_sbr_ton_corr_hp.c
index 9f285fd..1bcd3c8 100644
--- a/encoder/ixheaace_sbr_ton_corr_hp.c
+++ b/encoder/ixheaace_sbr_ton_corr_hp.c
@@ -18,6 +18,7 @@
* Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
*/
+#include <math.h>
#include <string.h>
#include "ixheaac_type_def.h"
@@ -33,12 +34,12 @@
#include "ixheaace_resampler.h"
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
#include "ixheaace_sbr_env_est.h"
#include "ixheaace_sbr_code_envelope.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_main.h"
#include "ixheaace_sbr_missing_harmonics_det.h"
#include "ixheaace_sbr_inv_filtering_estimation.h"
@@ -49,7 +50,7 @@
#include "ixheaace_sbr.h"
#include "ixheaace_sbr_misc.h"
-#include <math.h>
+#include "ixheaace_common_utils.h"
static VOID ixheaace_calc_auto_corr_second_order(ixheaace_acorr_coeffs *pstr_ac,
FLOAT32 **ptr_real, FLOAT32 **ptr_imag,
@@ -178,11 +179,7 @@ VOID ixheaace_calculate_tonality_quotas(ixheaace_pstr_sbr_ton_corr_est pstr_ton_
if (r00r) {
FLOAT32 tmp =
-(alphar[0] * r01r + alphai[0] * r01i + alphar[1] * r02r + alphai[1] * r02i) / (r00r);
- FLOAT32 denum = 1.0f - tmp;
- if (fabs(denum) < EPS) {
- denum = (FLOAT32)EPS;
- }
- ptr_quota_mtx[time_index][r] = (FLOAT32)(tmp / denum);
+ ptr_quota_mtx[time_index][r] = (FLOAT32)ixheaace_div32(tmp, 1.0f - tmp);
} else {
ptr_quota_mtx[time_index][r] = 0;
}
diff --git a/encoder/ixheaace_sbr_tran_det.c b/encoder/ixheaace_sbr_tran_det.c
index cf9bce4..a18ba9e 100644
--- a/encoder/ixheaace_sbr_tran_det.c
+++ b/encoder/ixheaace_sbr_tran_det.c
@@ -52,7 +52,7 @@ static IA_ERRORCODE ixheaace_spectral_change(FLOAT32 *ptr_energies[16], FLOAT32
FLOAT32 pos_wt = (0.5f - (FLOAT32)len1 / (FLOAT32)(len1 + len2));
pos_wt = 1.0f - 4.0f * pos_wt * pos_wt;
- if ((is_ld_sbr) && (total_energy == 0.0f)) {
+ if (total_energy < SBR_EPS) {
*ptr_delta = 0.0f;
return IA_NO_ERROR;
}
@@ -72,8 +72,14 @@ static IA_ERRORCODE ixheaace_spectral_change(FLOAT32 *ptr_energies[16], FLOAT32
for (i = border; i < stop; i++) {
energy_2[j] += ptr_energies[i][j];
}
- delta = (float)fabs(log(energy_2[j] / energy_1[j] * len_ratio));
- delta_sum += (float)(sqrt((energy_1[j] + energy_2[j]) / total_energy) * delta);
+ if (energy_1[j] <= EPS) {
+ energy_1[j] = (FLOAT32)len1;
+ }
+ if (energy_2[j] <= EPS) {
+ energy_2[j] = (FLOAT32)len2;
+ }
+ delta = (FLOAT32)fabs(log((energy_2[j] / energy_1[j]) * len_ratio));
+ delta_sum += (FLOAT32)(sqrt((energy_1[j] + energy_2[j]) / total_energy) * delta);
}
*ptr_delta = delta_sum * pos_wt;
diff --git a/encoder/ixheaace_sbr_write_bitstream.c b/encoder/ixheaace_sbr_write_bitstream.c
index 5482382..1fa53f0 100644
--- a/encoder/ixheaace_sbr_write_bitstream.c
+++ b/encoder/ixheaace_sbr_write_bitstream.c
@@ -33,12 +33,12 @@
#include "ixheaace_sbr_rom.h"
#include "ixheaace_common_rom.h"
#include "ixheaace_bitbuffer.h"
+#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_qmf_enc.h"
#include "ixheaace_sbr_tran_det.h"
#include "ixheaace_sbr_frame_info_gen.h"
#include "ixheaace_sbr_env_est.h"
#include "ixheaace_sbr_code_envelope.h"
-#include "ixheaace_sbr_hbe.h"
#include "ixheaace_sbr_main.h"
#include "ixheaace_sbr_missing_harmonics_det.h"
#include "ixheaace_sbr_inv_filtering_estimation.h"
diff --git a/encoder/ixheaace_sf_estimation.c b/encoder/ixheaace_sf_estimation.c
index 89435d5..cbd67d0 100644
--- a/encoder/ixheaace_sf_estimation.c
+++ b/encoder/ixheaace_sf_estimation.c
@@ -284,7 +284,7 @@ static WORD16 iaace_improve_scf(FLOAT32 *ptr_spec, FLOAT32 *ptr_exp_spec, WORD16
FLOAT32 allowed_sfb_dist = MIN(sfb_dist * 1.25f, threshold);
WORD32 count;
- for (count = 1; count >= 0; count--) {
+ for (count = SCF_COUNT_LIMIT_AAC; count >= 0; count--) {
scf++;
sfb_dist = iaace_calc_sfb_dist(ptr_spec, ptr_exp_spec, ptr_quant_spec_temp, sfb_width, scf);
@@ -683,7 +683,8 @@ VOID iaace_estimate_scfs_chan(
scf_int = (WORD16)floor(scf_float);
min_sf_max_quant[i] = (WORD16)floor(C1_SF + C2_SF * log(max_spec));
scf_int = MAX(scf_int, min_sf_max_quant[i]);
-
+ scf_int = MAX(scf_int, MIN_GAIN_INDEX_AAC);
+ scf_int = MIN(scf_int, (MAX_GAIN_INDEX_AAC - SCF_COUNT_LIMIT_AAC));
for (j = 0; j < pstr_psy_out_chan->sfb_offsets[i + 1] - pstr_psy_out_chan->sfb_offsets[i];
j++) {
ptr_exp_spec[pstr_psy_out_chan->sfb_offsets[i] + j] = (FLOAT32)(
diff --git a/encoder/ixheaace_stereo_preproc.c b/encoder/ixheaace_stereo_preproc.c
index 644f5b1..a14fe7e 100644
--- a/encoder/ixheaace_stereo_preproc.c
+++ b/encoder/ixheaace_stereo_preproc.c
@@ -43,11 +43,11 @@
#include "ixheaace_adjust_threshold_data.h"
#include "ixheaace_dynamic_bits.h"
#include "ixheaace_qc_data.h"
-
+#include "ixheaac_error_standards.h"
#include "ixheaace_stereo_preproc.h"
#include "ixheaace_common_utils.h"
-WORD32 iaace_init_stereo_pre_processing(ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,
+IA_ERRORCODE iaace_init_stereo_pre_processing(ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,
WORD32 no_channels, WORD32 bit_rate, WORD32 sample_rate,
FLOAT32 used_scf_ratio) {
FLOAT32 bpf = bit_rate * 1024.0f / sample_rate;
@@ -96,7 +96,7 @@ WORD32 iaace_init_stereo_pre_processing(ixheaace_stereo_pre_pro_pstr pstr_stereo
tmp * (pstr_stereo_pre_pro)->stereo_attenuation_max;
}
- return 0;
+ return IA_NO_ERROR;
}
VOID iaace_apply_stereo_preproc(ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,
diff --git a/encoder/ixheaace_stereo_preproc.h b/encoder/ixheaace_stereo_preproc.h
index 60fd52f..9ecb046 100644
--- a/encoder/ixheaace_stereo_preproc.h
+++ b/encoder/ixheaace_stereo_preproc.h
@@ -50,7 +50,7 @@ typedef struct {
typedef ixheaace_stereo_pre_pro_struct *ixheaace_stereo_pre_pro_pstr;
-WORD32 iaace_init_stereo_pre_processing(ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,
+IA_ERRORCODE iaace_init_stereo_pre_processing(ixheaace_stereo_pre_pro_pstr pstr_stereo_pre_pro,
WORD32 no_channels, WORD32 bit_rate, WORD32 sample_rate,
FLOAT32 used_scf_ratio);
diff --git a/encoder/ixheaace_struct_def.h b/encoder/ixheaace_struct_def.h
index d1b921a..4f0c3c7 100644
--- a/encoder/ixheaace_struct_def.h
+++ b/encoder/ixheaace_struct_def.h
@@ -104,6 +104,8 @@ typedef struct ixheaace_state_struct {
ia_bit_buf_struct str_bit_buf;
ixheaace_mps_212_memory_struct *mps_pers_mem;
ixheaace_mps_515_memory_struct *mps_515_pers_mem;
+ WORD32 is_quant_spec_zero;
+ WORD32 is_gain_limited;
} ixheaace_state_struct;
typedef struct ixheaace_api_struct {
diff --git a/encoder/ixheaace_tns.c b/encoder/ixheaace_tns.c
index 2babda6..288c460 100644
--- a/encoder/ixheaace_tns.c
+++ b/encoder/ixheaace_tns.c
@@ -291,7 +291,7 @@ static VOID ia_enhaacplus_enc_index_to_parcor(
}
}
-WORD32 ia_enhaacplus_enc_tns_encode(ixheaace_temporal_noise_shaping_params *pstr_tns_info,
+VOID ia_enhaacplus_enc_tns_encode(ixheaace_temporal_noise_shaping_params *pstr_tns_info,
ixheaace_temporal_noise_shaping_data *pstr_tns_data,
WORD32 num_sfb,
ixheaace_temporal_noise_shaping_config tns_config,
@@ -304,7 +304,7 @@ WORD32 ia_enhaacplus_enc_tns_encode(ixheaace_temporal_noise_shaping_params *pstr
if (block_type != SHORT_WINDOW) {
if (pstr_tns_data->data_raw.tns_data_long.sub_block_info.tns_active == 0) {
pstr_tns_info->tns_active[sub_blk_num] = 0;
- return 0;
+ return;
} else {
ia_enhaacplus_enc_parcor_to_index(
pstr_tns_data->data_raw.tns_data_long.sub_block_info.parcor, &pstr_tns_info->coef[0],
@@ -347,7 +347,7 @@ WORD32 ia_enhaacplus_enc_tns_encode(ixheaace_temporal_noise_shaping_params *pstr
if (pstr_tns_data->data_raw.tns_data_short.sub_block_info[sub_blk_num].tns_active == 0) {
pstr_tns_info->tns_active[sub_blk_num] = 0;
- return 0;
+ return;
} else {
ia_enhaacplus_enc_parcor_to_index(
pstr_tns_data->data_raw.tns_data_short.sub_block_info[sub_blk_num].parcor,
@@ -384,7 +384,7 @@ WORD32 ia_enhaacplus_enc_tns_encode(ixheaace_temporal_noise_shaping_params *pstr
}
}
- return 0;
+ return;
}
VOID ia_enhaacplus_enc_apply_tns_mult_table_to_ratios(WORD32 start_cb, WORD32 stop_cb,
diff --git a/encoder/ixheaace_tns_func.h b/encoder/ixheaace_tns_func.h
index cbd73d8..0105ef2 100644
--- a/encoder/ixheaace_tns_func.h
+++ b/encoder/ixheaace_tns_func.h
@@ -45,7 +45,7 @@ VOID ia_enhaacplus_enc_tns_sync(ixheaace_temporal_noise_shaping_data *pstr_tns_d
const ixheaace_temporal_noise_shaping_config tns_config,
const WORD32 sub_blk_num, const WORD32 block_type);
-WORD32 ia_enhaacplus_enc_tns_encode(ixheaace_temporal_noise_shaping_params *pstr_tns_info,
+VOID ia_enhaacplus_enc_tns_encode(ixheaace_temporal_noise_shaping_params *pstr_tns_info,
ixheaace_temporal_noise_shaping_data *pstr_tns_data,
WORD32 num_sfb,
ixheaace_temporal_noise_shaping_config tns_config,
diff --git a/encoder/ixheaace_tns_hp.c b/encoder/ixheaace_tns_hp.c
index eea00f7..d93bf6c 100644
--- a/encoder/ixheaace_tns_hp.c
+++ b/encoder/ixheaace_tns_hp.c
@@ -57,11 +57,7 @@ VOID ia_enhaacplus_enc_calc_weighted_spectrum(FLOAT32 *ptr_spectrum, FLOAT32 *pt
for (sfb = lpc_start_band; sfb < lpc_stop_band; sfb++) {
FLOAT32 sfb_nrg_tmp = ptr_sfb_energy[sfb];
- if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS || aot == AOT_AAC_ELD) {
- ptr_tns_sfb_mean[sfb] = 1 / ((FLOAT32)sqrt(sfb_nrg_tmp) + 1e-30f);
- } else if (aot == AOT_AAC_LD) {
- ptr_tns_sfb_mean[sfb] = 1 / (FLOAT32)sqrt(sfb_nrg_tmp);
- }
+ ptr_tns_sfb_mean[sfb] = 1 / ((FLOAT32)sqrt(sfb_nrg_tmp) + 1e-30f);
}
sfb = lpc_start_band;
diff --git a/encoder/ixheaace_tns_params.c b/encoder/ixheaace_tns_params.c
index 3a165fa..c63bb27 100644
--- a/encoder/ixheaace_tns_params.c
+++ b/encoder/ixheaace_tns_params.c
@@ -43,7 +43,9 @@ ia_enhaacplus_enc_get_tns_param(
const ixheaace_temporal_noise_shaping_info_tab *pstr_tns_info_tab, WORD32 size) {
UWORD32 i;
- if (pstr_tns_config_tab == NULL) return 1;
+ if (pstr_tns_config_tab == NULL) {
+ return IA_EXHEAACE_INIT_FATAL_TNS_CONFIG_INIT_FAILED;
+ }
pstr_tns_config_tab->thresh_on = -1;
diff --git a/encoder/ixheaace_write_adts_adif.c b/encoder/ixheaace_write_adts_adif.c
index e7f080d..2cda5bb 100644
--- a/encoder/ixheaace_write_adts_adif.c
+++ b/encoder/ixheaace_write_adts_adif.c
@@ -35,7 +35,7 @@
#include "ixheaac_basic_ops.h"
#include "ixheaace_common_utils.h"
-static WORD32 ia_enhaacplus_enc_putbit(ixheaace_bitstream_params *pstr_bitstream, UWORD32 data,
+static VOID ia_enhaacplus_enc_putbit(ixheaace_bitstream_params *pstr_bitstream, UWORD32 data,
WORD32 num_bit) {
WORD32 num, max_num, curr_num;
WORD32 num_used, idx;
@@ -43,7 +43,7 @@ static WORD32 ia_enhaacplus_enc_putbit(ixheaace_bitstream_params *pstr_bitstream
WORD32 current_bitstream_bit;
UWORD8 *bitstream_data;
- if (num_bit == 0) return 0;
+ if (num_bit == 0) return;
current_bitstream_bit = pstr_bitstream->current_bit;
bitstream_data = pstr_bitstream->data;
@@ -99,8 +99,6 @@ static WORD32 ia_enhaacplus_enc_putbit(ixheaace_bitstream_params *pstr_bitstream
pstr_bitstream->current_bit = current_bitstream_bit;
pstr_bitstream->num_bit = current_bitstream_bit;
-
- return 0;
}
static WORD16 ia_enhaacplus_enc_get_sample_rate_index(WORD32 sample_rate) {
diff --git a/encoder/ixheaace_write_bitstream.c b/encoder/ixheaace_write_bitstream.c
index 5b33976..9851f26 100644
--- a/encoder/ixheaace_write_bitstream.c
+++ b/encoder/ixheaace_write_bitstream.c
@@ -185,7 +185,7 @@ static WORD32 ia_enhaacplus_enc_encode_section_data(
return (ia_enhaacplus_enc_get_bits_available(pstr_bit_stream_handle) - dbg_val);
}
-static WORD32 ia_enhaacplus_enc_code_scale_factor_delta_lav(WORD32 delta,
+static VOID ia_enhaacplus_enc_code_scale_factor_delta_lav(WORD32 delta,
ixheaace_bit_buf_handle ptr_bitstream,
const UWORD16 *ptr_pltabscf,
const UWORD32 *ptr_pctabscf) {
@@ -195,8 +195,6 @@ static WORD32 ia_enhaacplus_enc_code_scale_factor_delta_lav(WORD32 delta,
code_length = ptr_pltabscf[delta];
ixheaace_write_bits(ptr_bitstream, code_word, (UWORD8)code_length);
-
- return 0;
}
static WORD32 ia_enhaacplus_enc_encode_scalefactor_data(
UWORD16 *ptr_max_val_in_sfb, ixheaace_section_data *pstr_section_data, WORD16 *ptr_scalefac,
@@ -220,10 +218,8 @@ static WORD32 ia_enhaacplus_enc_encode_scalefactor_data(
last_val_scf = ptr_scalefac[j];
}
- if (ia_enhaacplus_enc_code_scale_factor_delta_lav(delta_scf, pstr_bit_stream_handle,
- ptr_pltabscf, ptr_pctabscf)) {
- return 1;
- }
+ ia_enhaacplus_enc_code_scale_factor_delta_lav(delta_scf, pstr_bit_stream_handle,
+ ptr_pltabscf, ptr_pctabscf);
}
}
}
@@ -767,7 +763,7 @@ IA_ERRORCODE ia_enhaacplus_enc_write_bitstream(
} break;
default:
- return 1;
+ return IA_EXHEAACE_INIT_FATAL_INVALID_ELEMENT_TYPE;
} /* switch */
diff --git a/fuzzer/ossfuzz.sh b/fuzzer/ossfuzz.sh
index 1467d26..237e061 100755
--- a/fuzzer/ossfuzz.sh
+++ b/fuzzer/ossfuzz.sh
@@ -17,6 +17,12 @@
test "${SRC}" != "" || exit 1
test "${WORK}" != "" || exit 1
+#Opt out of shift sanitizer in undefined sanitizer
+if [[ $SANITIZER = *undefined* ]]; then
+ CFLAGS="$CFLAGS -fno-sanitize=shift"
+ CXXFLAGS="$CXXFLAGS -fno-sanitize=shift"
+fi
+
# Build libxaac
build_dir=$WORK/build
rm -rf ${build_dir}
@@ -24,8 +30,10 @@ mkdir -p ${build_dir}
pushd ${build_dir}
cmake $SRC/libxaac
-make -j$(nproc) xaac_dec_fuzzer
+make -j$(nproc) xaac_dec_fuzzer xaac_enc_fuzzer
cp ${build_dir}/xaac_dec_fuzzer $OUT/
+cp ${build_dir}/xaac_enc_fuzzer $OUT/
popd
-cp $SRC/libxaac/fuzzer/xaac_dec_fuzzer.dict $OUT/xaac_dec_fuzzer.dict
+cp $SRC/libxaac/fuzzer/xaac_dec_fuzzer.dict $OUT/
+cp $SRC/libxaac/fuzzer/xaac_enc_fuzzer.dict $OUT/
diff --git a/fuzzer/xaac_dec_fuzzer.cpp b/fuzzer/xaac_dec_fuzzer.cpp
index 6c760d2..3cd6749 100644
--- a/fuzzer/xaac_dec_fuzzer.cpp
+++ b/fuzzer/xaac_dec_fuzzer.cpp
@@ -845,6 +845,7 @@ IA_ERRORCODE Codec::setXAACDRCInfo(int32_t drcCut, int32_t drcBoost,
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
int status;
+ int num_proc_iterations = 0;
if (size < 1) return 0;
Codec* codec = new Codec();
bool isADTS = false;
@@ -863,6 +864,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
data += bytesConsumed;
status = codec->decodeXAACStream((uint8_t*)data, size, &bytesConsumed,
&numOutBytes);
+ num_proc_iterations++;
+ /* Stop processing after 500 frames */
+ if (num_proc_iterations > 500)
+ break;
+
/* If decoder doesn't consume any bytes, advance by 4 bytes */
if (0 == bytesConsumed) bytesConsumed = 4;
}
diff --git a/fuzzer/xaac_enc_fuzzer.cpp b/fuzzer/xaac_enc_fuzzer.cpp
index d598db4..252d898 100644
--- a/fuzzer/xaac_enc_fuzzer.cpp
+++ b/fuzzer/xaac_enc_fuzzer.cpp
@@ -356,6 +356,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
pWORD8 pb_inp_buf = NULL;
WORD32 input_size = 0;
+ WORD32 num_proc_iterations = 0;
/* ******************************************************************/
/* The API config structure */
@@ -381,8 +382,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (err_code) {
if (pstr_drc_cfg) {
free(pstr_drc_cfg);
+ pstr_drc_cfg = NULL;
+ }
+ /* Fatal error code */
+ if (err_code & 0x80000000) {
+ ixheaace_delete((pVOID)pstr_out_cfg);
+ return 0;
}
- return 0;
}
pv_ia_process_api_obj = pstr_out_cfg->pv_ia_process_api_obj;
@@ -400,11 +406,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
while (fuzzed_data.remaining_bytes()) {
if (fuzzed_data.ConsumeBool()) {
std::vector<WORD8> inputVec = fuzzed_data.ConsumeBytes<WORD8>(input_size);
- memcpy(pb_inp_buf, inputVec.data(), inputVec.size());
+ if (inputVec.size()) {
+ memcpy(pb_inp_buf, inputVec.data(), inputVec.size());
+ }
} else {
memset(pb_inp_buf, fuzzed_data.ConsumeIntegral<WORD8>(), input_size);
}
ixheaace_process(pv_ia_process_api_obj, (pVOID)pstr_in_cfg, (pVOID)pstr_out_cfg);
+ num_proc_iterations++;
+
+ /* Stop processing after 500 frames */
+ if (num_proc_iterations > 500)
+ break;
}
ixheaace_delete((pVOID)pstr_out_cfg);
diff --git a/test/Android.bp b/test/Android.bp
index 61dd091..61a7c83 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -61,7 +61,6 @@ cc_test {
"encoder/impd_drc_user_config.c",
"encoder/ixheaace_error.c",
"encoder/ixheaace_testbench.c",
- "encoder/ixheaace_wav_reader.c",
],
static_libs: ["libxaacenc"],
diff --git a/test/encoder/ixheaace_error.c b/test/encoder/ixheaace_error.c
index 3861665..81cdd96 100644
--- a/test/encoder/ixheaace_error.c
+++ b/test/encoder/ixheaace_error.c
@@ -82,6 +82,9 @@ pWORD8 ppb_ia_enhaacplus_enc_drc_config_fatal[IA_MAX_ERROR_SUB_CODE] = {
pWORD8 ppb_ia_enhaacplus_enc_mps_init_non_fatal[IA_MAX_ERROR_SUB_CODE] = {NULL};
+pWORD8 ppb_ia_enhaacplus_enc_drc_init_non_fatal[IA_MAX_ERROR_SUB_CODE] = {
+ (pWORD8) "Invalid DRC gain points", (pWORD8) "Invalid start subband index" };
+
/* Fatal Errors */
pWORD8 ppb_ia_enhaacplus_enc_init_fatal[IA_MAX_ERROR_SUB_CODE] = {
@@ -95,13 +98,16 @@ pWORD8 ppb_ia_enhaacplus_enc_init_fatal[IA_MAX_ERROR_SUB_CODE] = {
(pWORD8) "Invalid element type",
(pWORD8) "Number of channels not supported",
(pWORD8) "Invalid number of channels in element",
- (pWORD8) "Scale factor band initalization failed"};
+ (pWORD8) "Scale factor band initalization failed",
+ (pWORD8) "TNS configuration initalization failed" };
pWORD8 ppb_ia_enhaacplus_enc_mps_init_fatal[IA_MAX_ERROR_SUB_CODE] = {
(pWORD8) "MPS Initialization failed"};
pWORD8 ppb_ia_enhaacplus_enc_usac_init_fatal[IA_MAX_ERROR_SUB_CODE] = {
- (pWORD8) "Resampler initialization failed", (pWORD8) "Insufficient bit-reservoir size"};
+ (pWORD8) "Resampler initialization failed", (pWORD8) "Insufficient bit-reservoir size",
+ (pWORD8) "Invalid core sample rate", (pWORD8) "Invalid element type",
+ (pWORD8) "Bitbuffer initialization failed", (pWORD8) "Invalid codec mode"};
pWORD8 ppb_ia_enhaacplus_enc_drc_init_fatal[IA_MAX_ERROR_SUB_CODE] = {
(pWORD8) "Invalid channel index"};
@@ -111,14 +117,24 @@ pWORD8 ppb_ia_enhaacplus_enc_sbr_init_fatal[IA_MAX_ERROR_SUB_CODE] = {
(pWORD8) "Invalid frequency coefficients", (pWORD8) "Invalid number of bands",
(pWORD8) "Invalid buffer length", (pWORD8) "SBR noise band not supported"};
+pWORD8 ppb_ia_enhaacplus_enc_ps_init_fatal[IA_MAX_ERROR_SUB_CODE] = {
+ (pWORD8) "PS Initialization failed" };
+
/*****************************************************************************/
/* Class 2: Execution Errors
*****************************************************************************/
/* Non Fatal Errors */
+pWORD8 ppb_ia_enhaacplus_enc_aac_exe_non_fatal[IA_MAX_ERROR_SUB_CODE] = {
+ (pWORD8) "Quantization zero spectrum detected",
+ (pWORD8) "Insufficient bit reservoir for non zero spectrum"};
pWORD8 ppb_ia_enhaacplus_enc_mps_exe_non_fatal[IA_MAX_ERROR_SUB_CODE] = {
(pWORD8) "Encoding Failed", (pWORD8) "Invalid MPS data bands"};
+pWORD8 ppb_ia_enhaacplus_enc_usac_exe_non_fatal[IA_MAX_ERROR_SUB_CODE] = {
+ (pWORD8) "Quantization zero spectrum detected",
+ (pWORD8) "Insufficient bit reservoir for non zero spectrum"};
+
pWORD8 ppb_ia_enhaacplus_enc_esbr_exe_non_fatal[IA_MAX_ERROR_SUB_CODE] = {
(pWORD8) "Invalid bandwidth index encountered",
(pWORD8) "Invalid number of patches",
@@ -170,6 +186,9 @@ pWORD8 ppb_ia_enhaacplus_enc_usac_exe_fatal[IA_MAX_ERROR_SUB_CODE] = {
(pWORD8) "Invalid number of channels",
(pWORD8) "Invalid bit reservoir level",
(pWORD8) "Invalid mapping",
+ (pWORD8) "Invalid window type",
+ (pWORD8) "Invalid window length",
+ (pWORD8) "Invalid window shape",
};
/*****************************************************************************/
@@ -221,7 +240,7 @@ VOID ia_enhaacplus_enc_error_handler_init() {
ppb_ia_enhaacplus_enc_config_non_fatal;
ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[0][1][1] =
ppb_ia_enhaacplus_enc_mps_config_non_fatal;
- ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[0][1][2] =
+ ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[0][1][3] =
ppb_ia_enhaacplus_enc_drc_config_non_fatal;
ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[1][1][0] =
ppb_ia_enhaacplus_enc_config_fatal;
@@ -241,6 +260,8 @@ VOID ia_enhaacplus_enc_error_handler_init() {
ppb_ia_enhaacplus_enc_drc_init_fatal;
ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[1][2][4] =
ppb_ia_enhaacplus_enc_sbr_init_fatal;
+ ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[1][2][5] =
+ ppb_ia_enhaacplus_enc_ps_init_fatal;
ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[0][3][1] =
ppb_ia_enhaacplus_enc_mps_exe_non_fatal;
ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[0][3][4] =
@@ -251,6 +272,12 @@ VOID ia_enhaacplus_enc_error_handler_init() {
ppb_ia_enhaacplus_enc_mps_exe_fatal;
ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[1][3][2] =
ppb_ia_enhaacplus_enc_usac_exe_fatal;
+ ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[0][3][0] =
+ ppb_ia_enhaacplus_enc_aac_exe_non_fatal;
+ ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[0][3][2] =
+ ppb_ia_enhaacplus_enc_usac_exe_non_fatal;
+ ia_enhaacplus_enc_error_info.ppppb_error_msg_pointers[0][2][3] =
+ ppb_ia_enhaacplus_enc_drc_init_non_fatal;
}
IA_ERRORCODE ia_error_handler(ia_error_info_struct *p_mod_err_info, WORD8 *pb_context,
@@ -292,6 +319,9 @@ IA_ERRORCODE ia_error_handler(ia_error_info_struct *p_mod_err_info, WORD8 *pb_co
case 4:
printf("SBR/eSBR ");
break;
+ case 5:
+ printf("Parametric Stereo ");
+ break;
default:
break;
}
diff --git a/test/encoder/ixheaace_wav_reader.c b/test/encoder/ixheaace_wav_reader.c
deleted file mode 100644
index bae8b8b..0000000
--- a/test/encoder/ixheaace_wav_reader.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/******************************************************************************
- * *
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *****************************************************************************
- * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
- */
-
-#include "ixheaac_type_def.h"
-#include "ixheaace_wave_read.h"
-
-WORD32 ia_enhaacplus_enc_get_wav_info(UWORD8 *inptr, wav_file_info *wav_info) {
- UWORD8 *wav_hdr = inptr;
- WORD8 data_start[4];
- WORD16 num_ch;
- UWORD16 f_samp;
-
- if (wav_hdr[0] != 'R' && wav_hdr[1] != 'I' && wav_hdr[2] != 'F' && wav_hdr[3] != 'F') {
- return 0;
- }
-
- if (wav_hdr[20] != 01 && wav_hdr[21] != 00) {
- return 0;
- }
- num_ch = (WORD16)((UWORD8)wav_hdr[23] * 256 + (UWORD8)wav_hdr[22]);
- f_samp = ((UWORD8)wav_hdr[27] * 256 * 256 * 256);
- f_samp += ((UWORD8)wav_hdr[26] * 256 * 256);
- f_samp += ((UWORD8)wav_hdr[25] * 256);
- f_samp += ((UWORD8)wav_hdr[24]);
-
- wav_info->num_channels = num_ch;
- wav_info->sample_rate = f_samp;
-
- data_start[0] = wav_hdr[36];
- data_start[1] = wav_hdr[37];
- data_start[2] = wav_hdr[38];
- data_start[3] = wav_hdr[39];
-
- if (!(data_start[0] == 'd' && data_start[1] == 'a' && data_start[2] == 't' &&
- data_start[3] == 'a')) {
- return 0;
- }
-
- return 1;
-}
diff --git a/test/encoder/ixheaace_wave_read.h b/test/encoder/ixheaace_wave_read.h
deleted file mode 100644
index 1f35916..0000000
--- a/test/encoder/ixheaace_wave_read.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/******************************************************************************
- * *
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *****************************************************************************
- * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
- */
-
-#pragma once
-typedef struct {
- WORD32 valid;
- WORD32 bits_per_sample;
- WORD32 sample_rate;
- WORD32 num_channels;
- long num_samples;
- WORD32 is_little_endian;
- WORD32 use_wave_ext;
-} wav_file_info;
diff --git a/test/encoder/xaacenc.cmake b/test/encoder/xaacenc.cmake
index 713d357..a7930d2 100644
--- a/test/encoder/xaacenc.cmake
+++ b/test/encoder/xaacenc.cmake
@@ -1,8 +1,7 @@
list(APPEND XAACENC_SRCS
"${XAAC_ROOT}/test/encoder/impd_drc_user_config.c"
"${XAAC_ROOT}/test/encoder/ixheaace_error.c"
- "${XAAC_ROOT}/test/encoder/ixheaace_testbench.c"
- "${XAAC_ROOT}/test/encoder/ixheaace_wav_reader.c")
+ "${XAAC_ROOT}/test/encoder/ixheaace_testbench.c")
set(LIBXAACENC_INCLUDES ${XAAC_ROOT}/encoder
${XAAC_ROOT}/test/encoder