00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef AVCODEC_MPEGAUDIO_H
00027 #define AVCODEC_MPEGAUDIO_H
00028
00029 #ifndef CONFIG_FLOAT
00030 # define CONFIG_FLOAT 0
00031 #endif
00032
00033 #include "avcodec.h"
00034 #include "get_bits.h"
00035 #include "dsputil.h"
00036 #include "fft.h"
00037
00038 #define CONFIG_AUDIO_NONSHORT 0
00039
00040
00041 #define MPA_FRAME_SIZE 1152
00042
00043
00044 #define MPA_MAX_CODED_FRAME_SIZE 1792
00045
00046 #define MPA_MAX_CHANNELS 2
00047
00048 #define SBLIMIT 32
00049
00050 #define MPA_STEREO 0
00051 #define MPA_JSTEREO 1
00052 #define MPA_DUAL 2
00053 #define MPA_MONO 3
00054
00055
00056 #define SAME_HEADER_MASK \
00057 (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
00058
00059 #define MP3_MASK 0xFFFE0CCF
00060
00061 #if CONFIG_MPEGAUDIO_HP
00062 #define FRAC_BITS 23
00063 #define WFRAC_BITS 16
00064 #else
00065 #define FRAC_BITS 15
00066 #define WFRAC_BITS 14
00067 #endif
00068
00069 #define FRAC_ONE (1 << FRAC_BITS)
00070
00071 #define FIX(a) ((int)((a) * FRAC_ONE))
00072
00073 #if CONFIG_FLOAT
00074 typedef float OUT_INT;
00075 #define OUT_FMT AV_SAMPLE_FMT_FLT
00076 #elif CONFIG_MPEGAUDIO_HP && CONFIG_AUDIO_NONSHORT
00077 typedef int32_t OUT_INT;
00078 #define OUT_MAX INT32_MAX
00079 #define OUT_MIN INT32_MIN
00080 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
00081 #define OUT_FMT AV_SAMPLE_FMT_S32
00082 #else
00083 typedef int16_t OUT_INT;
00084 #define OUT_MAX INT16_MAX
00085 #define OUT_MIN INT16_MIN
00086 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
00087 #define OUT_FMT AV_SAMPLE_FMT_S16
00088 #endif
00089
00090 #if CONFIG_FLOAT
00091 # define INTFLOAT float
00092 typedef float MPA_INT;
00093 #elif FRAC_BITS <= 15
00094 # define INTFLOAT int
00095 typedef int16_t MPA_INT;
00096 #else
00097 # define INTFLOAT int
00098 typedef int32_t MPA_INT;
00099 #endif
00100
00101 #define BACKSTEP_SIZE 512
00102 #define EXTRABYTES 24
00103
00104
00105 typedef struct GranuleDef {
00106 uint8_t scfsi;
00107 int part2_3_length;
00108 int big_values;
00109 int global_gain;
00110 int scalefac_compress;
00111 uint8_t block_type;
00112 uint8_t switch_point;
00113 int table_select[3];
00114 int subblock_gain[3];
00115 uint8_t scalefac_scale;
00116 uint8_t count1table_select;
00117 int region_size[3];
00118 int preflag;
00119 int short_start, long_end;
00120 uint8_t scale_factors[40];
00121 INTFLOAT sb_hybrid[SBLIMIT * 18];
00122 } GranuleDef;
00123
00124 #define MPA_DECODE_HEADER \
00125 int frame_size; \
00126 int error_protection; \
00127 int layer; \
00128 int sample_rate; \
00129 int sample_rate_index; \
00130 int bit_rate; \
00131 int nb_channels; \
00132 int mode; \
00133 int mode_ext; \
00134 int lsf;
00135
00136 typedef struct MPADecodeHeader {
00137 MPA_DECODE_HEADER
00138 } MPADecodeHeader;
00139
00140 typedef struct MPADecodeContext {
00141 MPA_DECODE_HEADER
00142 uint8_t last_buf[2*BACKSTEP_SIZE + EXTRABYTES];
00143 int last_buf_size;
00144
00145 uint32_t free_format_next_header;
00146 GetBitContext gb;
00147 GetBitContext in_gb;
00148 DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2];
00149 int synth_buf_offset[MPA_MAX_CHANNELS];
00150 DECLARE_ALIGNED(16, INTFLOAT, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
00151 INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18];
00152 GranuleDef granules[2][2];
00153 #ifdef DEBUG
00154 int frame_count;
00155 #endif
00156 int adu_mode;
00157 int dither_state;
00158 int error_recognition;
00159 AVCodecContext* avctx;
00160 #if CONFIG_FLOAT
00161 DCTContext dct;
00162 #endif
00163 void (*apply_window_mp3)(MPA_INT *synth_buf, MPA_INT *window,
00164 int *dither_state, OUT_INT *samples, int incr);
00165 } MPADecodeContext;
00166
00167
00168 typedef struct HuffTable {
00169 int xsize;
00170 const uint8_t *bits;
00171 const uint16_t *codes;
00172 } HuffTable;
00173
00174 int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
00175 int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
00176 extern MPA_INT ff_mpa_synth_window[];
00177 void ff_mpa_synth_init(MPA_INT *window);
00178 void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
00179 MPA_INT *window, int *dither_state,
00180 OUT_INT *samples, int incr,
00181 INTFLOAT sb_samples[SBLIMIT]);
00182
00183 void ff_mpa_synth_init_float(MPA_INT *window);
00184 void ff_mpa_synth_filter_float(MPADecodeContext *s,
00185 MPA_INT *synth_buf_ptr, int *synth_buf_offset,
00186 MPA_INT *window, int *dither_state,
00187 OUT_INT *samples, int incr,
00188 INTFLOAT sb_samples[SBLIMIT]);
00189
00190 void ff_mpegaudiodec_init_mmx(MPADecodeContext *s);
00191 void ff_mpegaudiodec_init_altivec(MPADecodeContext *s);
00192
00193
00194 static inline int ff_mpa_check_header(uint32_t header){
00195
00196 if ((header & 0xffe00000) != 0xffe00000)
00197 return -1;
00198
00199 if ((header & (3<<17)) == 0)
00200 return -1;
00201
00202 if ((header & (0xf<<12)) == 0xf<<12)
00203 return -1;
00204
00205 if ((header & (3<<10)) == 3<<10)
00206 return -1;
00207 return 0;
00208 }
00209
00210 #endif