xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_sbr_def.h (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
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 #pragma once
21 
22 #define IXHEAACE_MAX_CH_IN_BS_ELE (2)
23 
24 #define INPUT_LEN_DOWNSAMPLE (2048)
25 #define UPSAMPLE_FAC (3)
26 #define DOWNSAMPLE_FAC_2_1 (2)
27 #define DOWNSAMPLE_FAC_4_1 (4)
28 
29 /* Constants */
30 #define MAX_FLT_VAL (3.402823466e+38F)
31 #define MIN_FLT_VAL (1.175494351e-38F)
32 
33 #define EPS (1e-18)
34 #define LOG2 (0.69314718056f)
35 #define RELAXATION (1e-6f)
36 
37 #define SBR_NOISE_FLOOR_OFFSET (6)
38 #define SBR_INV_LOG_2 (1.442695041f)
39 #define SBR_EPS (1e-18)
40 
41 #define SBR_DECAY_GUIDE_DIFF (0.5f)
42 #define SBR_THR_DIFF_GUIDE (1.26f)
43 #define SBR_THR_DIFF (25.0f)
44 #define SBR_THR_TONE (15.0f)
45 #define SBR_INV_THR_TONE (1.0f / 15.0f)
46 #define SBR_THR_TONE_GUIDE (1.26f)
47 #define SBR_DECAY_GUIDE_ORIG (0.3f)
48 #define SBR_THR_SFM_SBR (0.3f)
49 #define SBR_THR_SFM_ORG (0.1f)
50 #define SBR_MAX_COMP (2)
51 #define SBR_TONALITY_QUOTA (0.1f)
52 #define SBR_DIFF_QUOTA (0.75f)
53 #define SBR_TON_MEAN_P0009 (0.000976562f)
54 #define SBR_TON_MEAN_101P59 (101.5936673f)
55 
56 #define MAXIMUM_NOISE_ENVELOPES (2)
57 #define MAXIMUM_NUM_NOISE_COEFFS (5)
58 #define MAXIMUM_NUM_NOISE_VALUES (MAXIMUM_NOISE_ENVELOPES * MAXIMUM_NUM_NOISE_COEFFS)
59 #define MAXIMUM_ENVELOPES_HEAAC (5)
60 #define MAXIMUM_FREQ_COEFFS_HEAAC (48)
61 #define MAXIMUM_FREQ_COEFFS_LE32KHZ (48)
62 #define MAXIMUM_FREQ_COEFFS_EQ44KHZ (35)
63 #define MAXIMUM_FREQ_COEFFS_GE48KHZ (32)
64 #define MAXIMUM_NUM_ENV_VALUES_HEAAC (MAXIMUM_FREQ_COEFFS_HEAAC * MAXIMUM_ENVELOPES_HEAAC)
65 
66 #define IXHEAACE_QMF_CHANNELS (64)
67 #define QMF_FILTER_LENGTH (640)
68 #define CLD_FILTER_LENGTH (640)
69 #define IXHEAACE_QMF_TIME_SLOTS (32)
70 
71 #define NO_OF_ESTIMATES (4)
72 #define NO_OF_ESTIMATES_ELD (3)
73 
74 #define QMF_TIME_SLOTS_USAC_4_1 (64)
75 #define MAX_QMF_TIME_SLOTS (64)
76 #define MAXIMUM_FREQ_COEFFS_USAC (56)
77 #define MAXIMUM_ENVELOPES_USAC (8)
78 #define MAXIMUM_NUM_ENV_VALUES_USAC (MAXIMUM_FREQ_COEFFS_USAC * MAXIMUM_ENVELOPES_USAC)
79 
80 #if MAXIMUM_FREQ_COEFFS_HEAAC > MAXIMUM_FREQ_COEFFS_USAC
81 #define MAXIMUM_FREQ_COEFFS (MAXIMUM_FREQ_COEFFS_HEAAC)
82 #else
83 #define MAXIMUM_FREQ_COEFFS (MAXIMUM_FREQ_COEFFS_USAC)
84 #endif
85 #if MAXIMUM_ENVELOPES_HEAAC > MAXIMUM_ENVELOPES_USAC
86 #define IXHEAACE_MAX_ENV (MAXIMUM_ENVELOPES_HEAAC)
87 #else
88 #define IXHEAACE_MAX_ENV (MAXIMUM_ENVELOPES_USAC)
89 #endif
90 
91 #if MAXIMUM_NUM_ENV_VALUES_HEAAC > MAXIMUM_NUM_ENV_VALUES_HEAAC
92 #define MAXIMUM_NUM_ENVELOPE_VALUES (MAXIMUM_NUM_ENV_VALUES_HEAAC)
93 #else
94 #define MAXIMUM_NUM_ENVELOPE_VALUES (MAXIMUM_NUM_ENV_VALUES_USAC)
95 #endif
96 
97 #define LOW_RES (0)
98 #define HIGH_RES (1)
99 
100 #define LO (0)
101 #define HI (1)
102 
103 #define SI_SBR_PROTOCOL_VERSION_ID (0)
104 
105 #define SBR_XPOS_CTRL_DEFAULT (2)
106 
107 #define SBR_FREQ_SCALE_DEFAULT (2)
108 #define SBR_ALTER_SCALE_DEFAULT (1)
109 #define SBR_NOISE_BANDS_DEFAULT (2)
110 
111 #define SBR_LIMITER_BANDS_DEFAULT (2)
112 #define SBR_LIMITER_GAINS_DEFAULT (2)
113 #define SBR_INTERPOL_FREQ_DEFAULT (1)
114 #define SBR_SMOOTHING_LENGTH_DEFAULT (0)
115 
116 /* ESBR resampler Size*/
117 #define ESBR_RESAMP_SAMPLES (4096)
118 
119 /* spectral_band_replication_header */
120 #define SI_SBR_AMP_RES_BITS (1)
121 #define SI_SBR_COUPLING_BITS (1)
122 #define SI_SBR_START_FREQ_BITS (4)
123 #define SI_SBR_STOP_FREQ_BITS (4)
124 #define SI_SBR_XOVER_BAND_BITS (3)
125 #define SI_SBR_RESERVED_BITS (2)
126 #define SI_SBR_HEADER_EXTRA_1_BITS (1)
127 #define SI_SBR_HEADER_EXTRA_2_BITS (1)
128 #define SI_SBR_FREQ_SCALE_BITS (2)
129 #define SI_SBR_ALTER_SCALE_BITS (1)
130 #define SI_SBR_NOISE_BANDS_BITS (2)
131 
132 #define SBR_START_FREQ_OFFSET_TBL_LEN (1 << SI_SBR_START_FREQ_BITS)
133 #define SBR_STOP_FREQ_OFFSET_TBL_LEN (14)
134 
135 #define SI_SBR_LIMITER_BANDS_BITS (2)
136 #define SI_SBR_LIMITER_GAINS_BITS (2)
137 #define SI_SBR_INTERPOL_FREQ_BITS (1)
138 #define SI_SBR_SMOOTHING_LENGTH_BITS (1)
139 
140 /* spectral_band_replication_grid */
141 #define SBR_CLA_BITS (2)
142 #define SBR_ENV_BITS (2)
143 #define SBR_PVC_NOISE_POSITION_BITS (4)
144 #define SBR_PVC_VAR_LEN_HF_BITS (1)
145 
146 #define SBR_ABS_BITS (2)
147 #define SBR_NUM_BITS (2)
148 #define SBR_REL_BITS (2)
149 #define SBR_RES_BITS (1)
150 #define SBR_DIR_BITS (1)
151 #define LDSBR_CLA_BITS (1)
152 
153 /* spectral_band_replication_data */
154 
155 #define SI_SBR_INVF_MODE_BITS (2)
156 
157 #define SI_SBR_START_ENV_BITS_AMP_RES_3_0 (6)
158 #define SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_3_0 (5)
159 #define SI_SBR_START_NOISE_BITS_AMP_RES_3_0 (5)
160 #define SI_SBR_START_NOISE_BITS_BALANCE_AMP_RES_3_0 (5)
161 
162 #define SI_SBR_START_ENV_BITS_AMP_RES_1_5 (7)
163 #define SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_1_5 (6)
164 
165 #define SI_SBR_EXTENDED_DATA_BITS (1)
166 #define SI_SBR_EXTENSION_SIZE_BITS (4)
167 #define SI_SBR_EXTENSION_ESC_COUNT_BITS (8)
168 #define SI_SBR_EXTENSION_ID_BITS (2)
169 
170 #define SBR_EXTENDED_DATA_MAX_CNT (15 + 255)
171 
172 #define EXTENSION_ID_PS_CODING (2)
173 #define EXTENSION_ID_ESBR_CODING (3)
174 #define IXHEAACE_MPS_EXT_LDSAC_DATA (0x09)
175 /* Envelope coding constants */
176 #define FREQ (0)
177 #define TIME (1)
178 
179 /* huffman tables */
180 #define CODE_BCK_SCF_LAV10 (60)
181 #define CODE_BCK_SCF_LAV11 (31)
182 #define CODE_BCK_SCF_LAV_BALANCE11 (12)
183 #define CODE_BCK_SCF_LAV_BALANCE10 (24)
184 
185 #define USAC_SBR_RATIO_NO_SBR (0)
186 #define USAC_SBR_RATIO_INDEX_2_1 (3)
187 #define USAC_SBR_RATIO_INDEX_8_3 (2)
188 #define USAC_SBR_RATIO_INDEX_4_1 (1)
189 
190 #define USAC_SBR_DOWNSAMPLE_RATIO_2_1 (2)
191 #define USAC_SBR_DOWNSAMPLE_RATIO_4_1 (4)
192 
193 #define IXHEAACE_DISTANCE_CEIL_VALUE (5000000)
194 
195 typedef enum {
196   IXHEAACE_XPOS_MDCT,
197   IXHEAACE_XPOS_MDCT_CROSS,
198   IXHEAACE_XPOS_LC,
199   IXHEAACE_XPOS_RESERVED,
200   IXHEAACE_XPOS_SWITCHED
201 } ixheaace_sbr_xpos_mode;
202 
203 typedef enum { FREQ_RES_LOW, FREQ_RES_HIGH } ixheaace_freq_res;
204 
205 typedef enum {
206   IXHEAACE_SBR_MODE_MONO,
207   IXHEAACE_SBR_MODE_LEFT_RIGHT,
208   SBR_COUPLING,
209   IXHEAACE_SBR_MODE_SWITCH_LRC
210 } ixheaace_sbr_stereo_mode;
211 
212 typedef enum { HEAAC_SBR, ELD_SBR, USAC_SBR } ixheaace_sbr_codec_type;
213