diff --git a/encoder/ixheaace_api.c b/encoder/ixheaace_api.c index 749cac6..57923d4 100644 --- a/encoder/ixheaace_api.c +++ b/encoder/ixheaace_api.c @@ -2262,6 +2262,7 @@ static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, iaace_scratch *pstr_aac_scratch; WORD8 *ptr_spectral_band_replication_scratch; UWORD32 core_sample_rate; + WORD32 use_single_rate; ixheaace_state_struct *pstr_enc_state = pstr_api_struct->pstr_state; ixheaace_audio_specific_config_struct *pstr_asc = &pstr_enc_state->audio_specific_config; @@ -2311,6 +2312,7 @@ static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, case AOT_SBR: case AOT_PS: pstr_api_struct->pstr_state->buffer_offset = INPUT_DELAY_LC; + use_single_rate = 0; break; case AOT_AAC_LD: @@ -2319,6 +2321,7 @@ static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, } else { pstr_api_struct->pstr_state->buffer_offset = INPUT_DELAY_LD_512; } + use_single_rate = 0; break; case AOT_AAC_ELD: @@ -2327,6 +2330,7 @@ static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, } else { pstr_api_struct->pstr_state->buffer_offset = INPUT_DELAY_ELD_512; } + use_single_rate = 1; break; } pstr_api_struct->pstr_state->downsample[ele_idx] = 0; @@ -2337,9 +2341,6 @@ static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, pstr_aac_config->native_sample_rate = pstr_api_struct->config[ele_idx].native_sample_rate; pstr_aac_config->num_in_channels = pstr_api_struct->config[ele_idx].i_channels; pstr_aac_config->num_out_channels = pstr_api_struct->config[ele_idx].chmode_nchannels; - if (pstr_api_struct->config[ele_idx].aac_classic == 0) { - pstr_aac_config->core_sample_rate = pstr_aac_config->core_sample_rate / 2; - } if (pstr_api_struct->pstr_state->mps_enable) { switch (pstr_api_struct->pstr_state->mps_tree_config) { case TREE_212: @@ -2347,6 +2348,9 @@ static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, case TREE_5152: pstr_aac_config->num_out_channels = 1; core_ch = 1; + if (use_single_rate) { + use_single_rate = pstr_api_struct->pstr_state->mps_tree_config != TREE_212 || pstr_aac_config->core_sample_rate < 27713; + } break; case TREE_525: @@ -2355,6 +2359,9 @@ static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, break; } } + if (pstr_api_struct->config[ele_idx].aac_classic == 0 && !use_single_rate) { + pstr_aac_config->core_sample_rate = pstr_aac_config->core_sample_rate / 2; + } if (pstr_api_struct->config[ele_idx].use_parametric_stereo) { pstr_api_struct->config[ele_idx].chmode_nchannels = 2; @@ -2490,6 +2497,7 @@ static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, spectral_band_replication_config.crc_sbr = 0; spectral_band_replication_config.parametric_coding = 1; spectral_band_replication_config.is_esbr = pstr_api_struct->config[0].esbr_flag; + spectral_band_replication_config.is_single_rate = use_single_rate; if (pstr_api_struct->pstr_state->aot == AOT_AAC_ELD) { spectral_band_replication_config.is_ld_sbr = 1; spectral_band_replication_config.sbr_codec = ELD_SBR; @@ -2568,10 +2576,14 @@ static IA_ERRORCODE ia_enhaacplus_enc_init(ixheaace_api_struct *pstr_api_struct, ixheaace_adjust_sbr_settings( &spectral_band_replication_config, pstr_aac_config->bit_rate, - pstr_aac_config->num_out_channels, core_sample_rate, AACENC_TRANS_FAC, 24000, + pstr_aac_config->num_out_channels, use_single_rate ? pstr_aac_config->sample_rate : core_sample_rate, AACENC_TRANS_FAC, 24000, pstr_api_struct->spectral_band_replication_tabs.ptr_qmf_tab, pstr_api_struct->pstr_state->aot, (pstr_api_struct->config[0].ccfl_idx == SBR_4_1)); + if (spectral_band_replication_config.is_single_rate && !spectral_band_replication_config.is_single_rate_found) { + return IA_EXHEAACE_INIT_FATAL_AACPLUS_NOT_AVAIL; + } + if (pstr_api_struct->config[ele_idx].element_type != ID_LFE) { /* open SBR PART, set core bandwidth */ error = ixheaace_env_open( diff --git a/encoder/ixheaace_sbr_freq_scaling.c b/encoder/ixheaace_sbr_freq_scaling.c index 3df4e07..d81e428 100644 --- a/encoder/ixheaace_sbr_freq_scaling.c +++ b/encoder/ixheaace_sbr_freq_scaling.c @@ -19,6 +19,7 @@ */ #include +#include #include "ixheaac_type_def.h" #include "ixheaac_constants.h" #include "ixheaace_error_codes.h" @@ -379,6 +380,7 @@ WORD32 ixheaace_get_sbr_stop_freq_raw(WORD32 stop_freq, WORD32 qmf_bands, WORD32 } result = ixheaace_get_stop_freq(fs, stop_freq); + printf("stop freq compute: %d\n", result); result = (result * fs / qmf_bands + 1) >> 1; @@ -390,11 +392,13 @@ WORD32 ixheaace_get_downsampled_stop_freq(WORD32 stop_freq, WORD32 qmf_bands, WO WORD32 sbr_ratio_idx, ixheaace_sbr_codec_type sbr_codec) { WORD32 new_stop_freq; - WORD32 stop_freq_downsampled = fs / 4; + WORD32 stop_freq_downsampled = fs / 2; WORD32 result; WORD32 k0; WORD32 k2; + printf("fs: %d, sr: %d, sf: %d\n", fs, stop_freq_downsampled, ixheaace_get_sbr_stop_freq_raw(stop_freq, qmf_bands, fs)); + while (stop_freq && ixheaace_get_sbr_stop_freq_raw(stop_freq, qmf_bands, fs) > stop_freq_downsampled) { stop_freq--; } @@ -402,7 +406,7 @@ WORD32 ixheaace_get_downsampled_stop_freq(WORD32 stop_freq, WORD32 qmf_bands, WO new_stop_freq = ixheaace_get_sbr_stop_freq_raw(stop_freq, qmf_bands, fs); if (new_stop_freq > stop_freq_downsampled) return -1; - result = ixheaace_find_start_and_stop_band(fs, qmf_bands / 2, start_freq, stop_freq, + result = ixheaace_find_start_and_stop_band(fs, qmf_bands, start_freq, stop_freq, sample_rate_mode, &k0, &k2, sbr_ratio_idx, sbr_codec); if (result != IA_NO_ERROR) return -1; diff --git a/encoder/ixheaace_sbr_main.c b/encoder/ixheaace_sbr_main.c index 273446f..e8ed775 100644 --- a/encoder/ixheaace_sbr_main.c +++ b/encoder/ixheaace_sbr_main.c @@ -18,6 +18,7 @@ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore */ +#include #include #include "ixheaac_type_def.h" @@ -225,7 +226,7 @@ static IA_ERRORCODE ixheaace_create_env_channel( start_index = 576; err_code = ixheaace_create_ton_corr_param_extr( - ch, &pstr_env->str_ton_corr, pstr_sbr_cfg->sample_freq, 64, params->sbr_xpos_ctrl, + ch, &pstr_env->str_ton_corr, pstr_sbr_cfg->sample_freq, params->is_single_rate ? 32 : 64, params->sbr_xpos_ctrl, pstr_sbr_cfg->ptr_freq_band_tab[LOW_RES][0], pstr_sbr_cfg->ptr_v_k_master, pstr_sbr_cfg->num_master, params->ana_max_level, pstr_sbr_cfg->ptr_freq_band_tab, pstr_sbr_cfg->num_scf, pstr_sbr_hdr->sbr_noise_bands, params->use_speech_config, @@ -253,7 +254,7 @@ static IA_ERRORCODE ixheaace_create_env_channel( if (tran_fc == 0) { tran_fc = ixheaac_min32(5000, ixheaace_get_sbr_start_freq_raw(pstr_sbr_hdr->sbr_start_freq, - 64, pstr_sbr_cfg->sample_freq)); + params->is_single_rate ? 32 : 64, pstr_sbr_cfg->sample_freq)); } tran_fc = (tran_fc * 4 * 64 / pstr_sbr_cfg->sample_freq + 1) >> 1; @@ -516,12 +517,15 @@ VOID ixheaace_adjust_sbr_settings(const ixheaace_pstr_sbr_cfg pstr_config, UWORD } if (pstr_config->is_single_rate) { - downsample_stop = ixheaace_get_downsampled_stop_freq(pstr_config->stop_freq, IXHEAACE_QMF_CHANNELS, fs_core, + printf("he-aac: single rate start: %d\n", pstr_config->start_freq); + printf("he-aac: single rate stop: %d\n", pstr_config->stop_freq); + downsample_stop = ixheaace_get_downsampled_stop_freq(pstr_config->stop_freq, IXHEAACE_QMF_CHANNELS / 2, fs_core, pstr_config->start_freq, IXHEAACE_SINGLE_RATE, pstr_config->sbr_ratio_idx, pstr_config->sbr_codec); if (downsample_stop >= 0) { pstr_config->is_single_rate_found = 1; pstr_config->stop_freq = downsample_stop; + printf("he-aac: single rate downsampled: %d\n", pstr_config->stop_freq); } } @@ -980,7 +984,7 @@ ixheaace_env_open(ixheaace_pstr_sbr_enc *pstr_env_encoder, ixheaace_pstr_sbr_cfg pstr_env_enc->str_sbr_cfg.stereo_mode = (params->codec_settings.num_channels == 2) ? params->stereo_mode : IXHEAACE_SBR_MODE_MONO; - if (params->codec_settings.sample_freq <= 24000 || !params->is_ld_sbr) { + if (!params->is_single_rate) { pstr_env_enc->str_sbr_hdr.sample_rate_mode = IXHEAACE_DUAL_RATE; if (params->sbr_codec == USAC_SBR) { pstr_env_enc->str_sbr_cfg.sample_freq = 2 * params->codec_settings.sample_freq; @@ -1056,7 +1060,7 @@ ixheaace_env_open(ixheaace_pstr_sbr_enc *pstr_env_encoder, ixheaace_pstr_sbr_cfg pstr_env_enc->str_sbr_cfg.use_parametric_coding = params->parametric_coding; err_code = ia_enhaacplus_enc_update_freq_band_tab( - &pstr_env_enc->str_sbr_cfg, &pstr_env_enc->str_sbr_hdr, IXHEAACE_QMF_CHANNELS); + &pstr_env_enc->str_sbr_cfg, &pstr_env_enc->str_sbr_hdr, params->is_single_rate ? IXHEAACE_QMF_CHANNELS / 2 : IXHEAACE_QMF_CHANNELS); if (err_code) { return err_code; }