2 * copyright (c) 2001 Fabrice Bellard
4 * This file is part of FFmpeg.
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.
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.
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
22 * @file libavcodec/mpegaudio.h
23 * mpeg audio declarations for both encoder and decoder.
26 #ifndef AVCODEC_MPEGAUDIO_H
27 #define AVCODEC_MPEGAUDIO_H
33 #define CONFIG_AUDIO_NONSHORT 0
35 /* max frame size, in samples */
36 #define MPA_FRAME_SIZE 1152
38 /* max compressed frame size */
39 #define MPA_MAX_CODED_FRAME_SIZE 1792
41 #define MPA_MAX_CHANNELS 2
43 #define SBLIMIT 32 /* number of subbands */
50 /* header + layer + bitrate + freq + lsf/mpeg25 */
51 #define SAME_HEADER_MASK \
52 (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
54 #define MP3_MASK 0xFFFE0CCF
56 #if CONFIG_MPEGAUDIO_HP
57 #define FRAC_BITS 23 /* fractional bits for sb_samples and dct */
58 #define WFRAC_BITS 16 /* fractional bits for window */
60 #define FRAC_BITS 15 /* fractional bits for sb_samples and dct */
61 #define WFRAC_BITS 14 /* fractional bits for window */
64 #define FRAC_ONE (1 << FRAC_BITS)
66 #define FIX(a) ((int)((a) * FRAC_ONE))
68 #if CONFIG_MPEGAUDIO_HP && CONFIG_AUDIO_NONSHORT
69 typedef int32_t OUT_INT
;
70 #define OUT_MAX INT32_MAX
71 #define OUT_MIN INT32_MIN
72 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
73 #define OUT_FMT SAMPLE_FMT_S32
75 typedef int16_t OUT_INT
;
76 #define OUT_MAX INT16_MAX
77 #define OUT_MIN INT16_MIN
78 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
79 #define OUT_FMT SAMPLE_FMT_S16
83 typedef int16_t MPA_INT
;
85 typedef int32_t MPA_INT
;
88 #define BACKSTEP_SIZE 512
91 /* layer 3 "granule" */
92 typedef struct GranuleDef
{
97 int scalefac_compress
;
101 int subblock_gain
[3];
102 uint8_t scalefac_scale
;
103 uint8_t count1table_select
;
104 int region_size
[3]; /* number of huffman codes in each region */
106 int short_start
, long_end
; /* long/short band indexes */
107 uint8_t scale_factors
[40];
108 int32_t sb_hybrid
[SBLIMIT
* 18]; /* 576 samples */
111 #define MPA_DECODE_HEADER \
113 int error_protection; \
116 int sample_rate_index; /* between 0 and 8 */ \
123 typedef struct MPADecodeHeader
{
127 typedef struct MPADecodeContext
{
129 uint8_t last_buf
[2*BACKSTEP_SIZE
+ EXTRABYTES
];
131 /* next header (used in free format parsing) */
132 uint32_t free_format_next_header
;
135 DECLARE_ALIGNED_16(MPA_INT
, synth_buf
[MPA_MAX_CHANNELS
][512 * 2]);
136 int synth_buf_offset
[MPA_MAX_CHANNELS
];
137 DECLARE_ALIGNED_16(int32_t, sb_samples
[MPA_MAX_CHANNELS
][36][SBLIMIT
]);
138 int32_t mdct_buf
[MPA_MAX_CHANNELS
][SBLIMIT
* 18]; /* previous samples, for layer 3 MDCT */
139 GranuleDef granules
[2][2]; /* Used in Layer 3 */
143 void (*compute_antialias
)(struct MPADecodeContext
*s
, struct GranuleDef
*g
);
144 int adu_mode
; ///< 0 for standard mp3, 1 for adu formatted mp3
146 int error_recognition
;
147 AVCodecContext
* avctx
;
150 /* layer 3 huffman tables */
151 typedef struct HuffTable
{
154 const uint16_t *codes
;
157 int ff_mpa_l2_select_table(int bitrate
, int nb_channels
, int freq
, int lsf
);
158 int ff_mpa_decode_header(AVCodecContext
*avctx
, uint32_t head
, int *sample_rate
, int *channels
, int *frame_size
, int *bitrate
);
159 extern MPA_INT ff_mpa_synth_window
[];
160 void ff_mpa_synth_init(MPA_INT
*window
);
161 void ff_mpa_synth_filter(MPA_INT
*synth_buf_ptr
, int *synth_buf_offset
,
162 MPA_INT
*window
, int *dither_state
,
163 OUT_INT
*samples
, int incr
,
164 int32_t sb_samples
[SBLIMIT
]);
166 /* fast header check for resync */
167 static inline int ff_mpa_check_header(uint32_t header
){
169 if ((header
& 0xffe00000) != 0xffe00000)
172 if ((header
& (3<<17)) == 0)
175 if ((header
& (0xf<<12)) == 0xf<<12)
178 if ((header
& (3<<10)) == 3<<10)
183 #endif /* AVCODEC_MPEGAUDIO_H */