00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00030 #ifndef AVCODEC_AAC_H
00031 #define AVCODEC_AAC_H
00032
00033 #include "avcodec.h"
00034 #include "dsputil.h"
00035 #include "fft.h"
00036 #include "mpeg4audio.h"
00037 #include "sbr.h"
00038 #include "fmtconvert.h"
00039
00040 #include <stdint.h>
00041
00042 #define MAX_CHANNELS 64
00043 #define MAX_ELEM_ID 16
00044
00045 #define TNS_MAX_ORDER 20
00046 #define MAX_LTP_LONG_SFB 40
00047
00048 enum RawDataBlockType {
00049 TYPE_SCE,
00050 TYPE_CPE,
00051 TYPE_CCE,
00052 TYPE_LFE,
00053 TYPE_DSE,
00054 TYPE_PCE,
00055 TYPE_FIL,
00056 TYPE_END,
00057 };
00058
00059 enum ExtensionPayloadID {
00060 EXT_FILL,
00061 EXT_FILL_DATA,
00062 EXT_DATA_ELEMENT,
00063 EXT_DYNAMIC_RANGE = 0xb,
00064 EXT_SBR_DATA = 0xd,
00065 EXT_SBR_DATA_CRC = 0xe,
00066 };
00067
00068 enum WindowSequence {
00069 ONLY_LONG_SEQUENCE,
00070 LONG_START_SEQUENCE,
00071 EIGHT_SHORT_SEQUENCE,
00072 LONG_STOP_SEQUENCE,
00073 };
00074
00075 enum BandType {
00076 ZERO_BT = 0,
00077 FIRST_PAIR_BT = 5,
00078 ESC_BT = 11,
00079 NOISE_BT = 13,
00080 INTENSITY_BT2 = 14,
00081 INTENSITY_BT = 15,
00082 };
00083
00084 #define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10)
00085
00086 enum ChannelPosition {
00087 AAC_CHANNEL_FRONT = 1,
00088 AAC_CHANNEL_SIDE = 2,
00089 AAC_CHANNEL_BACK = 3,
00090 AAC_CHANNEL_LFE = 4,
00091 AAC_CHANNEL_CC = 5,
00092 };
00093
00097 enum CouplingPoint {
00098 BEFORE_TNS,
00099 BETWEEN_TNS_AND_IMDCT,
00100 AFTER_IMDCT = 3,
00101 };
00102
00106 enum OCStatus {
00107 OC_NONE,
00108 OC_TRIAL_PCE,
00109 OC_TRIAL_FRAME,
00110 OC_GLOBAL_HDR,
00111 OC_LOCKED,
00112 };
00113
00117 typedef struct {
00118 float cor0;
00119 float cor1;
00120 float var0;
00121 float var1;
00122 float r0;
00123 float r1;
00124 } PredictorState;
00125
00126 #define MAX_PREDICTORS 672
00127
00128 #define SCALE_DIV_512 36
00129 #define SCALE_ONE_POS 140
00130 #define SCALE_MAX_POS 255
00131 #define SCALE_MAX_DIFF 60
00132 #define SCALE_DIFF_ZERO 60
00133
00134
00137 typedef struct {
00138 int8_t present;
00139 int16_t lag;
00140 float coef;
00141 int8_t used[MAX_LTP_LONG_SFB];
00142 } LongTermPrediction;
00143
00147 typedef struct {
00148 uint8_t max_sfb;
00149 enum WindowSequence window_sequence[2];
00150 uint8_t use_kb_window[2];
00151 int num_window_groups;
00152 uint8_t group_len[8];
00153 LongTermPrediction ltp;
00154 const uint16_t *swb_offset;
00155 const uint8_t *swb_sizes;
00156 int num_swb;
00157 int num_windows;
00158 int tns_max_bands;
00159 int predictor_present;
00160 int predictor_initialized;
00161 int predictor_reset_group;
00162 uint8_t prediction_used[41];
00163 } IndividualChannelStream;
00164
00168 typedef struct {
00169 int present;
00170 int n_filt[8];
00171 int length[8][4];
00172 int direction[8][4];
00173 int order[8][4];
00174 float coef[8][4][TNS_MAX_ORDER];
00175 } TemporalNoiseShaping;
00176
00180 typedef struct {
00181 int pce_instance_tag;
00182 int dyn_rng_sgn[17];
00183 int dyn_rng_ctl[17];
00184 int exclude_mask[MAX_CHANNELS];
00185 int band_incr;
00186 int interpolation_scheme;
00187 int band_top[17];
00188 int prog_ref_level;
00191 } DynamicRangeControl;
00192
00193 typedef struct {
00194 int num_pulse;
00195 int start;
00196 int pos[4];
00197 int amp[4];
00198 } Pulse;
00199
00203 typedef struct {
00204 enum CouplingPoint coupling_point;
00205 int num_coupled;
00206 enum RawDataBlockType type[8];
00207 int id_select[8];
00208 int ch_select[8];
00211 float gain[16][120];
00212 } ChannelCoupling;
00213
00217 typedef struct {
00218 IndividualChannelStream ics;
00219 TemporalNoiseShaping tns;
00220 Pulse pulse;
00221 enum BandType band_type[128];
00222 int band_type_run_end[120];
00223 float sf[120];
00224 int sf_idx[128];
00225 uint8_t zeroes[128];
00226 DECLARE_ALIGNED(16, float, coeffs)[1024];
00227 DECLARE_ALIGNED(16, float, saved)[1024];
00228 DECLARE_ALIGNED(16, float, ret)[2048];
00229 DECLARE_ALIGNED(16, int16_t, ltp_state)[3072];
00230 PredictorState predictor_state[MAX_PREDICTORS];
00231 } SingleChannelElement;
00232
00236 typedef struct {
00237
00238 int common_window;
00239 int ms_mode;
00240 uint8_t ms_mask[128];
00241
00242 SingleChannelElement ch[2];
00243
00244 ChannelCoupling coup;
00245 SpectralBandReplication sbr;
00246 } ChannelElement;
00247
00251 typedef struct {
00252 AVCodecContext *avctx;
00253
00254 MPEG4AudioConfig m4ac;
00255
00256 int is_saved;
00257 DynamicRangeControl che_drc;
00258
00263 enum ChannelPosition che_pos[4][MAX_ELEM_ID];
00266 ChannelElement *che[4][MAX_ELEM_ID];
00267 ChannelElement *tag_che_map[4][MAX_ELEM_ID];
00268 int tags_mapped;
00275 DECLARE_ALIGNED(16, float, buf_mdct)[1024];
00282 FFTContext mdct;
00283 FFTContext mdct_small;
00284 FFTContext mdct_ltp;
00285 DSPContext dsp;
00286 FmtConvertContext fmt_conv;
00287 int random_state;
00294 float *output_data[MAX_CHANNELS];
00295 float sf_scale;
00296 int sf_offset;
00297
00299 DECLARE_ALIGNED(16, float, temp)[128];
00300
00301 enum OCStatus output_configured;
00302 } AACContext;
00303
00304 #endif