00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #ifndef FFMPEG_MPEGAUDIO_H
00027 #define FFMPEG_MPEGAUDIO_H
00028
00029 #include "avcodec.h"
00030 #include "bitstream.h"
00031 #include "dsputil.h"
00032
00033
00034 #define MPA_FRAME_SIZE 1152
00035
00036
00037 #define MPA_MAX_CODED_FRAME_SIZE 1792
00038
00039 #define MPA_MAX_CHANNELS 2
00040
00041 #define SBLIMIT 32
00042
00043 #define MPA_STEREO 0
00044 #define MPA_JSTEREO 1
00045 #define MPA_DUAL 2
00046 #define MPA_MONO 3
00047
00048
00049 #define SAME_HEADER_MASK \
00050 (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
00051
00052 #define MP3_MASK 0xFFFE0CCF
00053
00054
00055
00056
00057 #ifdef USE_HIGHPRECISION
00058 #define FRAC_BITS 23
00059 #define WFRAC_BITS 16
00060 #else
00061 #define FRAC_BITS 15
00062 #define WFRAC_BITS 14
00063 #endif
00064
00065 #define FRAC_ONE (1 << FRAC_BITS)
00066
00067 #define FIX(a) ((int)((a) * FRAC_ONE))
00068
00069 #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
00070 typedef int32_t OUT_INT;
00071 #define OUT_MAX INT32_MAX
00072 #define OUT_MIN INT32_MIN
00073 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
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 #endif
00080
00081 #if FRAC_BITS <= 15
00082 typedef int16_t MPA_INT;
00083 #else
00084 typedef int32_t MPA_INT;
00085 #endif
00086
00087 #define BACKSTEP_SIZE 512
00088 #define EXTRABYTES 24
00089
00090 struct GranuleDef;
00091
00092 typedef struct MPADecodeContext {
00093 DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
00094 int last_buf_size;
00095 int frame_size;
00096
00097 uint32_t free_format_next_header;
00098 int error_protection;
00099 int layer;
00100 int sample_rate;
00101 int sample_rate_index;
00102 int bit_rate;
00103 GetBitContext gb;
00104 GetBitContext in_gb;
00105 int nb_channels;
00106 int mode;
00107 int mode_ext;
00108 int lsf;
00109 DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
00110 int synth_buf_offset[MPA_MAX_CHANNELS];
00111 DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
00112 int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18];
00113 #ifdef DEBUG
00114 int frame_count;
00115 #endif
00116 void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
00117 int adu_mode;
00118 int dither_state;
00119 int error_resilience;
00120 AVCodecContext* avctx;
00121 } MPADecodeContext;
00122
00123
00124 typedef struct HuffTable {
00125 int xsize;
00126 const uint8_t *bits;
00127 const uint16_t *codes;
00128 } HuffTable;
00129
00130 int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
00131 int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
00132 void ff_mpa_synth_init(MPA_INT *window);
00133 void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
00134 MPA_INT *window, int *dither_state,
00135 OUT_INT *samples, int incr,
00136 int32_t sb_samples[SBLIMIT]);
00137
00138
00139 static inline int ff_mpa_check_header(uint32_t header){
00140
00141 if ((header & 0xffe00000) != 0xffe00000)
00142 return -1;
00143
00144 if ((header & (3<<17)) == 0)
00145 return -1;
00146
00147 if ((header & (0xf<<12)) == 0xf<<12)
00148 return -1;
00149
00150 if ((header & (3<<10)) == 3<<10)
00151 return -1;
00152 return 0;
00153 }
00154
00155 #endif