]> rtime.felk.cvut.cz Git - frescor/ffmpeg.git/blob - libavcodec/mpegaudio.h
dont set the sampling rate just because 1 mp3 packet header says so (fixes playback...
[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 /* max frame size, in samples */
27 #define MPA_FRAME_SIZE 1152
28
29 /* max compressed frame size */
30 #define MPA_MAX_CODED_FRAME_SIZE 1792
31
32 #define MPA_MAX_CHANNELS 2
33
34 #define SBLIMIT 32 /* number of subbands */
35
36 #define MPA_STEREO  0
37 #define MPA_JSTEREO 1
38 #define MPA_DUAL    2
39 #define MPA_MONO    3
40
41 /* header + layer + bitrate + freq + lsf/mpeg25 */
42 #define SAME_HEADER_MASK \
43    (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
44
45 /* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
46    audio decoder */
47
48 #ifdef USE_HIGHPRECISION
49 #define FRAC_BITS   23   /* fractional bits for sb_samples and dct */
50 #define WFRAC_BITS  16   /* fractional bits for window */
51 #else
52 #define FRAC_BITS   15   /* fractional bits for sb_samples and dct */
53 #define WFRAC_BITS  14   /* fractional bits for window */
54 #endif
55
56 #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
57 typedef int32_t OUT_INT;
58 #define OUT_MAX INT32_MAX
59 #define OUT_MIN INT32_MIN
60 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
61 #else
62 typedef int16_t OUT_INT;
63 #define OUT_MAX INT16_MAX
64 #define OUT_MIN INT16_MIN
65 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
66 #endif
67
68 #if FRAC_BITS <= 15
69 typedef int16_t MPA_INT;
70 #else
71 typedef int32_t MPA_INT;
72 #endif
73
74 int l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
75 int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
76 void ff_mpa_synth_init(MPA_INT *window);
77 void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
78                          MPA_INT *window, int *dither_state,
79                          OUT_INT *samples, int incr,
80                          int32_t sb_samples[SBLIMIT]);
81
82 extern const uint16_t mpa_bitrate_tab[2][3][15];
83 extern const uint16_t mpa_freq_tab[3];
84 extern const unsigned char *alloc_tables[5];
85 extern const double enwindow[512];
86 extern const int sblimit_table[5];
87 extern const int quant_steps[17];
88 extern const int quant_bits[17];
89 extern const int32_t mpa_enwindow[257];
90
91 /* fast header check for resync */
92 static inline int ff_mpa_check_header(uint32_t header){
93     /* header */
94     if ((header & 0xffe00000) != 0xffe00000)
95         return -1;
96     /* layer check */
97     if ((header & (3<<17)) == 0)
98         return -1;
99     /* bit rate */
100     if ((header & (0xf<<12)) == 0xf<<12)
101         return -1;
102     /* frequency */
103     if ((header & (3<<10)) == 3<<10)
104         return -1;
105     return 0;
106 }