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 "bitstream.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 struct GranuleDef;
00092
00093 #define MPA_DECODE_HEADER \
00094 int frame_size; \
00095 int error_protection; \
00096 int layer; \
00097 int sample_rate; \
00098 int sample_rate_index; \
00099 int bit_rate; \
00100 int nb_channels; \
00101 int mode; \
00102 int mode_ext; \
00103 int lsf;
00104
00105 typedef struct MPADecodeHeader {
00106 MPA_DECODE_HEADER
00107 } MPADecodeHeader;
00108
00109 typedef struct MPADecodeContext {
00110 MPA_DECODE_HEADER
00111 DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
00112 int last_buf_size;
00113
00114 uint32_t free_format_next_header;
00115 GetBitContext gb;
00116 GetBitContext in_gb;
00117 DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
00118 int synth_buf_offset[MPA_MAX_CHANNELS];
00119 DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
00120 int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18];
00121 #ifdef DEBUG
00122 int frame_count;
00123 #endif
00124 void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
00125 int adu_mode;
00126 int dither_state;
00127 int error_recognition;
00128 AVCodecContext* avctx;
00129 } MPADecodeContext;
00130
00131
00132 typedef struct HuffTable {
00133 int xsize;
00134 const uint8_t *bits;
00135 const uint16_t *codes;
00136 } HuffTable;
00137
00138 int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
00139 int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
00140 void ff_mpa_synth_init(MPA_INT *window);
00141 void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
00142 MPA_INT *window, int *dither_state,
00143 OUT_INT *samples, int incr,
00144 int32_t sb_samples[SBLIMIT]);
00145
00146
00147 static inline int ff_mpa_check_header(uint32_t header){
00148
00149 if ((header & 0xffe00000) != 0xffe00000)
00150 return -1;
00151
00152 if ((header & (3<<17)) == 0)
00153 return -1;
00154
00155 if ((header & (0xf<<12)) == 0xf<<12)
00156 return -1;
00157
00158 if ((header & (3<<10)) == 3<<10)
00159 return -1;
00160 return 0;
00161 }
00162
00163 #endif