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