• 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 "get_bits.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 /* layer 3 "granule" */
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]; /* number of huffman codes in each region */
00105     int preflag;
00106     int short_start, long_end; /* long/short band indexes */
00107     uint8_t scale_factors[40];
00108     int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */
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; /* between 0 and 8 */ \
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     /* next header (used in free format parsing) */
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]; /* previous samples, for layer 3 MDCT */
00139     GranuleDef granules[2][2]; /* Used in Layer 3 */
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 /* layer 3 huffman tables */
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 /* fast header check for resync */
00167 static inline int ff_mpa_check_header(uint32_t header){
00168     /* header */
00169     if ((header & 0xffe00000) != 0xffe00000)
00170         return -1;
00171     /* layer check */
00172     if ((header & (3<<17)) == 0)
00173         return -1;
00174     /* bit rate */
00175     if ((header & (0xf<<12)) == 0xf<<12)
00176         return -1;
00177     /* frequency */
00178     if ((header & (3<<10)) == 3<<10)
00179         return -1;
00180     return 0;
00181 }
00182 
00183 #endif /* AVCODEC_MPEGAUDIO_H */

Generated on Fri Sep 16 2011 17:17:40 for FFmpeg by  doxygen 1.7.1