1 /****************************************************************************** 2 * * 3 * Copyright (C) 2023 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ***************************************************************************** 18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19 */ 20 21 #pragma once 22 23 #define IXHEAACE_MAX_PAYLOAD_SIZE (256) 24 25 enum { MONO = 1, STEREO = 2 }; 26 27 typedef struct { 28 WORD32 bit_rate; 29 WORD32 num_channels; 30 WORD32 sample_freq; 31 WORD32 trans_fac; 32 WORD32 standard_bitrate; 33 } ixheaace_str_codec_param; 34 35 typedef struct ixheaace_str_sbr_cfg { 36 ixheaace_str_codec_param codec_settings; 37 WORD32 send_header_data_time; 38 WORD32 crc_sbr; 39 WORD32 detect_missing_harmonics; 40 WORD32 parametric_coding; 41 42 WORD32 tran_thr; 43 WORD32 noise_floor_offset; 44 UWORD32 use_speech_config; 45 46 WORD32 sbr_data_extra; 47 WORD32 amp_res; 48 WORD32 ana_max_level; 49 WORD32 tran_fc; 50 WORD32 tran_det_mode; 51 WORD32 spread; 52 WORD32 stat; 53 WORD32 e; 54 ixheaace_sbr_stereo_mode stereo_mode; 55 WORD32 delta_t_across_frames; 56 FLOAT32 df_edge_1st_env; 57 FLOAT32 df_edge_incr; 58 59 WORD32 sbr_invf_mode; 60 WORD32 sbr_xpos_mode; 61 WORD32 sbr_xpos_ctrl; 62 WORD32 sbr_xpos_lvl; 63 WORD32 start_freq; 64 WORD32 stop_freq; 65 66 WORD32 use_ps; 67 WORD32 ps_mode; 68 69 WORD32 freq_scale; 70 WORD32 alter_scale; 71 WORD32 sbr_noise_bands; 72 73 WORD32 sbr_limiter_bands; 74 WORD32 sbr_limiter_gains; 75 WORD32 sbr_interpol_freq; 76 WORD32 sbr_smoothing_length; 77 WORD32 frame_flag_480; 78 WORD32 frame_flag_960; 79 WORD32 is_ld_sbr; 80 WORD32 is_esbr; 81 WORD32 sbr_pvc_rate; 82 WORD32 sbr_ratio_idx; 83 WORD32 sbr_pvc_active; 84 WORD32 sbr_harmonic; 85 WORD32 hq_esbr; 86 ixheaace_sbr_codec_type sbr_codec; 87 WORD32 use_low_freq_res; 88 } ixheaace_str_sbr_cfg, *ixheaace_pstr_sbr_cfg; 89 90 typedef struct ixheaace_str_sbr_enc *ixheaace_pstr_sbr_enc; 91 92 UWORD32 93 ixheaace_is_sbr_setting_available(UWORD32 bitrate, UWORD32 num_output_channels, 94 UWORD32 sample_rate_input, UWORD32 *sample_rate_core, 95 ixheaace_str_qmf_tabs *ptr_qmf_tab, WORD32 aot); 96 97 UWORD32 ixheaace_sbr_limit_bitrate(UWORD32 bit_rate, UWORD32 num_channels, 98 UWORD32 core_sample_rate, ixheaace_str_qmf_tabs *ptr_qmf_tab, 99 WORD32 aot); 100 101 VOID ixheaace_adjust_sbr_settings(const ixheaace_pstr_sbr_cfg pstr_config, UWORD32 bit_rate, 102 UWORD32 num_channels, UWORD32 fs_core, UWORD32 trans_fac, 103 UWORD32 standard_bitrate, ixheaace_str_qmf_tabs *ptr_qmf_tab, 104 WORD32 aot); 105 106 VOID ixheaace_initialize_sbr_defaults(ixheaace_pstr_sbr_cfg pstr_config); 107 108 IA_ERRORCODE 109 ixheaace_env_open(ixheaace_pstr_sbr_enc *pstr_env_encoder, ixheaace_pstr_sbr_cfg params, 110 WORD32 *core_bandwidth, WORD8 *spectral_band_replication_scratch_ptr, 111 ixheaace_str_sbr_tabs *pstr_sbr_tab, ixheaace_pstr_sbr_hdr_data *sbr_config); 112 113 VOID ixheaace_env_close(ixheaace_pstr_sbr_enc pstr_env_encoder); 114 115 WORD32 116 ixheaace_sbr_get_stop_freq_raw(ixheaace_pstr_sbr_enc ptr_env); 117 118 IA_ERRORCODE 119 ixheaace_env_encode_frame(ixheaace_pstr_sbr_enc ptr_env_encoder, FLOAT32 *samples, 120 FLOAT32 *core_buffer, UWORD32 time_sn_stride, UWORD8 *num_anc_bytes, 121 UWORD8 *anc_data, ixheaace_str_sbr_tabs *pstr_sbr_tab, 122 ixheaace_comm_tables *common_tab, UWORD8 *mps_data, WORD32 mps_bits, 123 WORD32 flag_framelength_small, WORD32 *usac_stat_bits); 124 125 VOID ixheaace_sbr_set_scratch_ptr(ixheaace_pstr_sbr_enc h_env_enc, VOID *scr); 126 WORD32 ixheaace_sbr_enc_pers_size(WORD32 num_chan, WORD32 use_ps, WORD32 harmonic_sbr); 127 WORD32 ixheaace_sbr_enc_scr_size(VOID); 128 129 VOID ixheaace_set_usac_sbr_params(ixheaace_pstr_sbr_enc h_env_enc, WORD32 usac_indep_flag, 130 WORD32 sbr_pre_proc, WORD32 sbr_pvc_active, WORD32 sbr_pvc_mode, 131 WORD32 inter_tes_active, WORD32 sbr_harmonic, 132 WORD32 sbr_patching_mode); 133 134 FLOAT32 *ixheaace_get_hbe_resample_buffer(ixheaace_pstr_sbr_enc h_env_enc); 135 136 IA_ERRORCODE ixheaace_extract_sbr_envelope(FLOAT32 *ptr_in_time, FLOAT32 *ptr_core_buf, 137 UWORD32 time_sn_stride, 138 ixheaace_pstr_sbr_enc pstr_env_enc, 139 ixheaace_str_sbr_tabs *ptr_sbr_tab, 140 ixheaace_comm_tables *pstr_com_tab, 141 WORD32 flag_framelength_small); 142 VOID ia_enhaacplus_enc_init_sbr_tabs(ixheaace_str_sbr_tabs *pstr_sbr_tabs); 143 VOID ia_enhaacplus_enc_get_shared_bufs(VOID *scr, WORD32 **shared_buf1, WORD32 **shared_buf2, 144 WORD32 **shared_buf3, WORD8 **shared_buf4, 145 WORD32 aacenc_blocksize); 146 VOID ia_enhaacplus_enc_get_scratch_bufs(VOID *scr, FLOAT32 **shared_buf1_ring, 147 FLOAT32 **shared_buf2_ring);