• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/mpegaudio.h

Go to the documentation of this file.
00001 /*
00002  * copyright (c) 2001 Fabrice Bellard
00003  *
00004  * This file is part of FFmpeg.
00005  *
00006  * FFmpeg is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * FFmpeg is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with FFmpeg; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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 /* max frame size, in samples */
00036 #define MPA_FRAME_SIZE 1152
00037 
00038 /* max compressed frame size */
00039 #define MPA_MAX_CODED_FRAME_SIZE 1792
00040 
00041 #define MPA_MAX_CHANNELS 2
00042 
00043 #define SBLIMIT 32 /* number of subbands */
00044 
00045 #define MPA_STEREO  0
00046 #define MPA_JSTEREO 1
00047 #define MPA_DUAL    2
00048 #define MPA_MONO    3
00049 
00050 /* header + layer + bitrate + freq + lsf/mpeg25 */
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   /* fractional bits for sb_samples and dct */
00058 #define WFRAC_BITS  16   /* fractional bits for window */
00059 #else
00060 #define FRAC_BITS   15   /* fractional bits for sb_samples and dct */
00061 #define WFRAC_BITS  14   /* fractional bits for window */
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; /* between 0 and 8 */ \
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     /* next header (used in free format parsing) */
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]; /* previous samples, for layer 3 MDCT */
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 /* layer 3 huffman tables */
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 /* fast header check for resync */
00147 static inline int ff_mpa_check_header(uint32_t header){
00148     /* header */
00149     if ((header & 0xffe00000) != 0xffe00000)
00150         return -1;
00151     /* layer check */
00152     if ((header & (3<<17)) == 0)
00153         return -1;
00154     /* bit rate */
00155     if ((header & (0xf<<12)) == 0xf<<12)
00156         return -1;
00157     /* frequency */
00158     if ((header & (3<<10)) == 3<<10)
00159         return -1;
00160     return 0;
00161 }
00162 
00163 #endif /* AVCODEC_MPEGAUDIO_H */

Generated on Sat Feb 16 2013 09:23:13 for ffmpeg by  doxygen 1.7.1