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 #define POW_SF2_ZERO 200
00134
00135
00138 typedef struct {
00139 int8_t present;
00140 int16_t lag;
00141 float coef;
00142 int8_t used[MAX_LTP_LONG_SFB];
00143 } LongTermPrediction;
00144
00148 typedef struct {
00149 uint8_t max_sfb;
00150 enum WindowSequence window_sequence[2];
00151 uint8_t use_kb_window[2];
00152 int num_window_groups;
00153 uint8_t group_len[8];
00154 LongTermPrediction ltp;
00155 const uint16_t *swb_offset;
00156 const uint8_t *swb_sizes;
00157 int num_swb;
00158 int num_windows;
00159 int tns_max_bands;
00160 int predictor_present;
00161 int predictor_initialized;
00162 int predictor_reset_group;
00163 uint8_t prediction_used[41];
00164 } IndividualChannelStream;
00165
00169 typedef struct {
00170 int present;
00171 int n_filt[8];
00172 int length[8][4];
00173 int direction[8][4];
00174 int order[8][4];
00175 float coef[8][4][TNS_MAX_ORDER];
00176 } TemporalNoiseShaping;
00177
00181 typedef struct {
00182 int pce_instance_tag;
00183 int dyn_rng_sgn[17];
00184 int dyn_rng_ctl[17];
00185 int exclude_mask[MAX_CHANNELS];
00186 int band_incr;
00187 int interpolation_scheme;
00188 int band_top[17];
00189 int prog_ref_level;
00192 } DynamicRangeControl;
00193
00194 typedef struct {
00195 int num_pulse;
00196 int start;
00197 int pos[4];
00198 int amp[4];
00199 } Pulse;
00200
00204 typedef struct {
00205 enum CouplingPoint coupling_point;
00206 int num_coupled;
00207 enum RawDataBlockType type[8];
00208 int id_select[8];
00209 int ch_select[8];
00212 float gain[16][120];
00213 } ChannelCoupling;
00214
00218 typedef struct {
00219 IndividualChannelStream ics;
00220 TemporalNoiseShaping tns;
00221 Pulse pulse;
00222 enum BandType band_type[128];
00223 int band_type_run_end[120];
00224 float sf[120];
00225 int sf_idx[128];
00226 uint8_t zeroes[128];
00227 DECLARE_ALIGNED(32, float, coeffs)[1024];
00228 DECLARE_ALIGNED(32, float, saved)[1024];
00229 DECLARE_ALIGNED(32, float, ret)[2048];
00230 DECLARE_ALIGNED(16, float, ltp_state)[3072];
00231 PredictorState predictor_state[MAX_PREDICTORS];
00232 } SingleChannelElement;
00233
00237 typedef struct {
00238
00239 int common_window;
00240 int ms_mode;
00241 uint8_t ms_mask[128];
00242
00243 SingleChannelElement ch[2];
00244
00245 ChannelCoupling coup;
00246 SpectralBandReplication sbr;
00247 } ChannelElement;
00248
00252 typedef struct {
00253 AVCodecContext *avctx;
00254 AVFrame frame;
00255
00256 MPEG4AudioConfig m4ac;
00257
00258 int is_saved;
00259 DynamicRangeControl che_drc;
00260
00265 enum ChannelPosition che_pos[4][MAX_ELEM_ID];
00268 ChannelElement *che[4][MAX_ELEM_ID];
00269 ChannelElement *tag_che_map[4][MAX_ELEM_ID];
00270 int tags_mapped;
00278 DECLARE_ALIGNED(32, float, buf_mdct)[1024];
00285 FFTContext mdct;
00286 FFTContext mdct_small;
00287 FFTContext mdct_ltp;
00288 DSPContext dsp;
00289 FmtConvertContext fmt_conv;
00290 int random_state;
00297 float *output_data[MAX_CHANNELS];
00298
00300 DECLARE_ALIGNED(32, float, temp)[128];
00301
00302 enum OCStatus output_configured;
00303 int warned_num_aac_frames;
00304 } AACContext;
00305
00306 #endif