]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blob - libavcodec/mpegaudio.h
remove dependency of mpeg audio encoder over mpeg audio decoder
[frescor/ffmpeg.git] / libavcodec / mpegaudio.h
1 /*
2  * copyright (c) 2001 Fabrice Bellard
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file mpegaudio.h
23  * mpeg audio declarations for both encoder and decoder.
24  */
25
26 #ifndef MPEGAUDIO_H
27 #define MPEGAUDIO_H
28
29 #include "avcodec.h"
30 #include "bitstream.h"
31 #include "dsputil.h"
32
33 /* max frame size, in samples */
34 #define MPA_FRAME_SIZE 1152
35
36 /* max compressed frame size */
37 #define MPA_MAX_CODED_FRAME_SIZE 1792
38
39 #define MPA_MAX_CHANNELS 2
40
41 #define SBLIMIT 32 /* number of subbands */
42
43 #define MPA_STEREO  0
44 #define MPA_JSTEREO 1
45 #define MPA_DUAL    2
46 #define MPA_MONO    3
47
48 /* header + layer + bitrate + freq + lsf/mpeg25 */
49 #define SAME_HEADER_MASK \
50    (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
51
52 #define MP3_MASK 0xFFFE0CCF
53
54 /* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
55    audio decoder */
56
57 #ifdef USE_HIGHPRECISION
58 #define FRAC_BITS   23   /* fractional bits for sb_samples and dct */
59 #define WFRAC_BITS  16   /* fractional bits for window */
60 #else
61 #define FRAC_BITS   15   /* fractional bits for sb_samples and dct */
62 #define WFRAC_BITS  14   /* fractional bits for window */
63 #endif
64
65 #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
66 typedef int32_t OUT_INT;
67 #define OUT_MAX INT32_MAX
68 #define OUT_MIN INT32_MIN
69 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
70 #else
71 typedef int16_t OUT_INT;
72 #define OUT_MAX INT16_MAX
73 #define OUT_MIN INT16_MIN
74 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
75 #endif
76
77 #if FRAC_BITS <= 15
78 typedef int16_t MPA_INT;
79 #else
80 typedef int32_t MPA_INT;
81 #endif
82
83 #define BACKSTEP_SIZE 512
84 #define EXTRABYTES 24
85
86 struct GranuleDef;
87
88 typedef struct MPADecodeContext {
89     DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
90     int last_buf_size;
91     int frame_size;
92     /* next header (used in free format parsing) */
93     uint32_t free_format_next_header;
94     int error_protection;
95     int layer;
96     int sample_rate;
97     int sample_rate_index; /* between 0 and 8 */
98     int bit_rate;
99     GetBitContext gb;
100     GetBitContext in_gb;
101     int nb_channels;
102     int mode;
103     int mode_ext;
104     int lsf;
105     DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
106     int synth_buf_offset[MPA_MAX_CHANNELS];
107     DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
108     int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
109 #ifdef DEBUG
110     int frame_count;
111 #endif
112     void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
113     int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
114     int dither_state;
115     int error_resilience;
116     AVCodecContext* avctx;
117 } MPADecodeContext;
118
119 int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
120 int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
121 void ff_mpa_synth_init(MPA_INT *window);
122 void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
123                          MPA_INT *window, int *dither_state,
124                          OUT_INT *samples, int incr,
125                          int32_t sb_samples[SBLIMIT]);
126
127 /* fast header check for resync */
128 static inline int ff_mpa_check_header(uint32_t header){
129     /* header */
130     if ((header & 0xffe00000) != 0xffe00000)
131         return -1;
132     /* layer check */
133     if ((header & (3<<17)) == 0)
134         return -1;
135     /* bit rate */
136     if ((header & (0xf<<12)) == 0xf<<12)
137         return -1;
138     /* frequency */
139     if ((header & (3<<10)) == 3<<10)
140         return -1;
141     return 0;
142 }
143
144 #endif /* MPEGAUDIO_H */