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 "libavutil/float_dsp.h"
00034 #include "avcodec.h"
00035 #include "dsputil.h"
00036 #include "fft.h"
00037 #include "mpeg4audio.h"
00038 #include "sbr.h"
00039 #include "fmtconvert.h"
00040
00041 #include <stdint.h>
00042
00043 #define MAX_CHANNELS 64
00044 #define MAX_ELEM_ID 16
00045
00046 #define TNS_MAX_ORDER 20
00047 #define MAX_LTP_LONG_SFB 40
00048
00049 enum RawDataBlockType {
00050 TYPE_SCE,
00051 TYPE_CPE,
00052 TYPE_CCE,
00053 TYPE_LFE,
00054 TYPE_DSE,
00055 TYPE_PCE,
00056 TYPE_FIL,
00057 TYPE_END,
00058 };
00059
00060 enum ExtensionPayloadID {
00061 EXT_FILL,
00062 EXT_FILL_DATA,
00063 EXT_DATA_ELEMENT,
00064 EXT_DYNAMIC_RANGE = 0xb,
00065 EXT_SBR_DATA = 0xd,
00066 EXT_SBR_DATA_CRC = 0xe,
00067 };
00068
00069 enum WindowSequence {
00070 ONLY_LONG_SEQUENCE,
00071 LONG_START_SEQUENCE,
00072 EIGHT_SHORT_SEQUENCE,
00073 LONG_STOP_SEQUENCE,
00074 };
00075
00076 enum BandType {
00077 ZERO_BT = 0,
00078 FIRST_PAIR_BT = 5,
00079 ESC_BT = 11,
00080 NOISE_BT = 13,
00081 INTENSITY_BT2 = 14,
00082 INTENSITY_BT = 15,
00083 };
00084
00085 #define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10)
00086
00087 enum ChannelPosition {
00088 AAC_CHANNEL_OFF = 0,
00089 AAC_CHANNEL_FRONT = 1,
00090 AAC_CHANNEL_SIDE = 2,
00091 AAC_CHANNEL_BACK = 3,
00092 AAC_CHANNEL_LFE = 4,
00093 AAC_CHANNEL_CC = 5,
00094 };
00095
00099 enum CouplingPoint {
00100 BEFORE_TNS,
00101 BETWEEN_TNS_AND_IMDCT,
00102 AFTER_IMDCT = 3,
00103 };
00104
00108 enum OCStatus {
00109 OC_NONE,
00110 OC_TRIAL_PCE,
00111 OC_TRIAL_FRAME,
00112 OC_GLOBAL_HDR,
00113 OC_LOCKED,
00114 };
00115
00116 typedef struct {
00117 MPEG4AudioConfig m4ac;
00118 uint8_t layout_map[MAX_ELEM_ID*4][3];
00119 int layout_map_tags;
00120 int channels;
00121 uint64_t channel_layout;
00122 enum OCStatus status;
00123 } OutputConfiguration;
00124
00128 typedef struct {
00129 float cor0;
00130 float cor1;
00131 float var0;
00132 float var1;
00133 float r0;
00134 float r1;
00135 } PredictorState;
00136
00137 #define MAX_PREDICTORS 672
00138
00139 #define SCALE_DIV_512 36
00140 #define SCALE_ONE_POS 140
00141 #define SCALE_MAX_POS 255
00142 #define SCALE_MAX_DIFF 60
00143 #define SCALE_DIFF_ZERO 60
00144 #define POW_SF2_ZERO 200
00145
00146
00149 typedef struct {
00150 int8_t present;
00151 int16_t lag;
00152 float coef;
00153 int8_t used[MAX_LTP_LONG_SFB];
00154 } LongTermPrediction;
00155
00159 typedef struct {
00160 uint8_t max_sfb;
00161 enum WindowSequence window_sequence[2];
00162 uint8_t use_kb_window[2];
00163 int num_window_groups;
00164 uint8_t group_len[8];
00165 LongTermPrediction ltp;
00166 const uint16_t *swb_offset;
00167 const uint8_t *swb_sizes;
00168 int num_swb;
00169 int num_windows;
00170 int tns_max_bands;
00171 int predictor_present;
00172 int predictor_initialized;
00173 int predictor_reset_group;
00174 uint8_t prediction_used[41];
00175 } IndividualChannelStream;
00176
00180 typedef struct {
00181 int present;
00182 int n_filt[8];
00183 int length[8][4];
00184 int direction[8][4];
00185 int order[8][4];
00186 float coef[8][4][TNS_MAX_ORDER];
00187 } TemporalNoiseShaping;
00188
00192 typedef struct {
00193 int pce_instance_tag;
00194 int dyn_rng_sgn[17];
00195 int dyn_rng_ctl[17];
00196 int exclude_mask[MAX_CHANNELS];
00197 int band_incr;
00198 int interpolation_scheme;
00199 int band_top[17];
00200 int prog_ref_level;
00203 } DynamicRangeControl;
00204
00205 typedef struct {
00206 int num_pulse;
00207 int start;
00208 int pos[4];
00209 int amp[4];
00210 } Pulse;
00211
00215 typedef struct {
00216 enum CouplingPoint coupling_point;
00217 int num_coupled;
00218 enum RawDataBlockType type[8];
00219 int id_select[8];
00220 int ch_select[8];
00223 float gain[16][120];
00224 } ChannelCoupling;
00225
00229 typedef struct {
00230 IndividualChannelStream ics;
00231 TemporalNoiseShaping tns;
00232 Pulse pulse;
00233 enum BandType band_type[128];
00234 int band_type_run_end[120];
00235 float sf[120];
00236 int sf_idx[128];
00237 uint8_t zeroes[128];
00238 DECLARE_ALIGNED(32, float, coeffs)[1024];
00239 DECLARE_ALIGNED(32, float, saved)[1024];
00240 DECLARE_ALIGNED(32, float, ret)[2048];
00241 DECLARE_ALIGNED(16, float, ltp_state)[3072];
00242 PredictorState predictor_state[MAX_PREDICTORS];
00243 } SingleChannelElement;
00244
00248 typedef struct {
00249
00250 int common_window;
00251 int ms_mode;
00252 uint8_t ms_mask[128];
00253
00254 SingleChannelElement ch[2];
00255
00256 ChannelCoupling coup;
00257 SpectralBandReplication sbr;
00258 } ChannelElement;
00259
00263 typedef struct {
00264 AVCodecContext *avctx;
00265 AVFrame frame;
00266
00267 int is_saved;
00268 DynamicRangeControl che_drc;
00269
00274 ChannelElement *che[4][MAX_ELEM_ID];
00275 ChannelElement *tag_che_map[4][MAX_ELEM_ID];
00276 int tags_mapped;
00284 DECLARE_ALIGNED(32, float, buf_mdct)[1024];
00291 FFTContext mdct;
00292 FFTContext mdct_small;
00293 FFTContext mdct_ltp;
00294 DSPContext dsp;
00295 FmtConvertContext fmt_conv;
00296 AVFloatDSPContext fdsp;
00297 int random_state;
00304 float *output_data[MAX_CHANNELS];
00305
00312 int enable_jp_dmono;
00313 int dmono_mode;
00314
00316 DECLARE_ALIGNED(32, float, temp)[128];
00317
00318 OutputConfiguration oc[2];
00319 int warned_num_aac_frames;
00320 } AACContext;
00321
00322 #endif