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 typedef enum { 23 ID_SCE = 0, /*Single Channel Element*/ 24 ID_CPE, /*Channel Pair Element*/ 25 ID_CCE, /*Coupling channel Element*/ 26 ID_LFE, /*Low frequency Effect Channel*/ 27 ID_DSE, 28 ID_PCE, /*Program Config. Element*/ 29 ID_FIL, /*Fill element*/ 30 ID_END /*End of block*/ 31 } ixheaace_element_type; 32 33 typedef enum { 34 FRONT_CENTER = 0, 35 FRONT_LEFT_RIGHT, 36 BACK_LEFT_RIGHT, 37 REAR_CENTER, 38 LFE_CHANNEL, 39 COUPLING_CH, 40 } ELEMENT_NAME; 41 42 typedef enum { FRAME_LEN_BYTES_MODULO = 1, FRAME_LEN_BYTES_INT = 2 } FRAME_LEN_RESULT_MODE; 43 44 typedef struct { 45 ixheaace_element_type el_type; 46 WORD32 instance_tag; 47 WORD32 n_channels_in_el; 48 WORD32 channel_index[IXHEAACE_MAX_CH_IN_BS_ELE]; 49 } ixheaace_element_info; 50 51 typedef struct { 52 WORD32 padding_rest; 53 } ixheaace_padding; 54 55 /* Quantizing & coding stage */ 56 57 typedef struct { 58 ixheaace_element_info *pstr_element_info; 59 WORD32 max_bits; /* maximum number of bits in reservoir */ 60 WORD32 average_bits; /* average number of bits we should use */ 61 WORD32 bit_res; 62 FLOAT32 mean_pe; 63 WORD32 ch_bitrate; 64 WORD32 inv_quant; 65 FLOAT32 max_bit_fac; 66 WORD32 bitrate; 67 ixheaace_padding padding; 68 } ixheaace_qc_init; 69 70 #define RED_EXP_VAL 0.25f 71 #define INV_RED_EXP_VAL (1.0f / RED_EXP_VAL) 72 #define MIN_SNR_LIMIT 0.8f 73 74 #define MAX_SCF_DELTA 60 75 76 #define LOG2_1 1.442695041f 77 #define C1_SF -69.33295f /* -16/3*log(MAX_QUANT+0.5-logCon)/log(2) */ 78 #define C2_SF 5.77078f /* 4/log(2) */ 79 80 #define PE_C1 3.0f /* log(8.0)/log(2) */ 81 #define PE_C2 1.3219281f /* log(2.5)/log(2) */ 82 #define PE_C3 0.5593573f /* 1-C2/C1 */ 83 84 #define TRANSPORT_BITS (208) 85 86 #define MAX_GAIN_INDEX_AAC (128) 87 #define MIN_GAIN_INDEX_AAC (-128) 88 #define SCF_COUNT_LIMIT_AAC (1) 89 90 typedef struct { 91 WORD16 *quant_spec; 92 UWORD16 *max_val_in_sfb; 93 WORD16 *scalefactor; 94 WORD32 global_gain; 95 WORD32 grouping_mask; 96 ixheaace_section_data section_data; 97 WORD32 win_shape; 98 } ixheaace_qc_out_channel; 99 100 typedef struct { 101 WORD32 static_bits_used; /* for verification purposes */ 102 WORD32 dyn_bits_used; /* for verification purposes */ 103 FLOAT32 pe; 104 WORD32 anc_bits_used; 105 WORD32 fill_bits; 106 } ixheaace_qc_out_element; 107 108 typedef struct { 109 ixheaace_qc_out_channel *qc_channel[IXHEAACE_MAX_CH_IN_BS_ELE]; 110 ixheaace_qc_out_element qc_element; 111 WORD32 tot_static_bits_used; /* for verification purposes */ 112 WORD32 tot_dyn_bits_used; /* for verification purposes */ 113 WORD32 tot_anc_bits_used; /* for verification purposes */ 114 WORD32 total_fill_bits; 115 WORD32 align_bits; 116 WORD32 bit_res_tot; 117 WORD32 average_bits_tot; 118 } ixheaace_qc_out; 119 120 typedef struct { 121 WORD32 ch_bitrate; 122 WORD32 average_bits; /* brutto -> look pstr_ancillary.h */ 123 WORD32 max_bits; 124 WORD32 bit_res_level; 125 WORD32 max_bit_res_bits; 126 WORD32 relative_bits; /* Bits relative to total Bits*/ 127 WORD32 carry_bits; /* Bits carried over from prev. frame */ 128 } ixheaace_element_bits; 129 130 typedef struct { 131 WORD32 *shared_buffer_2; 132 } ixheaace_qc_scratch; 133 134 typedef struct { 135 /* this is basically struct ixheaace_qc_init */ 136 WORD32 average_bits_tot; 137 WORD32 max_bits_tot; 138 WORD32 glob_stat_bits; 139 WORD32 num_channels; 140 WORD32 bit_res_tot; 141 WORD32 quality_level; 142 ixheaace_padding padding; 143 ixheaace_element_bits element_bits; 144 FLOAT32 max_bit_fac; 145 ia_adj_thr_state_struct str_adj_thr; 146 WORD32 side_info_tab_long[MAXIMUM_SCALE_FACTOR_BAND_LONG + 1]; 147 WORD32 side_info_tab_short[MAXIMUM_SCALE_FACTOR_BAND_SHORT + 1]; 148 ixheaace_qc_scratch qc_scr; 149 } ixheaace_qc_state; 150 151 typedef struct { 152 FLOAT32 exp_spec[FRAME_LEN_1024]; 153 FLOAT32 mdct_spec_float[FRAME_LEN_1024]; 154 FLOAT32 sfb_form_fac[IXHEAACE_MAX_CH_IN_BS_ELE][MAXIMUM_GROUPED_SCALE_FACTOR_BAND]; 155 FLOAT32 sfb_num_relevant_lines[IXHEAACE_MAX_CH_IN_BS_ELE][MAXIMUM_GROUPED_SCALE_FACTOR_BAND]; 156 FLOAT32 sfb_ld_energy[IXHEAACE_MAX_CH_IN_BS_ELE][MAXIMUM_GROUPED_SCALE_FACTOR_BAND]; 157 } ixheaace_qc_stack; 158