Statistics
| Branch: | Revision:

ffmpeg / libavcodec / mpegaudio.h @ 3d929a60

History | View | Annotate | Download (5.81 KB)

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
23
 * mpeg audio declarations for both encoder and decoder.
24
 */
25

    
26
#ifndef AVCODEC_MPEGAUDIO_H
27
#define AVCODEC_MPEGAUDIO_H
28

    
29
#ifndef CONFIG_FLOAT
30
#   define CONFIG_FLOAT 0
31
#endif
32

    
33
#include "avcodec.h"
34
#include "get_bits.h"
35
#include "dsputil.h"
36
#include "dct.h"
37

    
38
#define CONFIG_AUDIO_NONSHORT 0
39

    
40
/* max frame size, in samples */
41
#define MPA_FRAME_SIZE 1152
42

    
43
/* max compressed frame size */
44
#define MPA_MAX_CODED_FRAME_SIZE 1792
45

    
46
#define MPA_MAX_CHANNELS 2
47

    
48
#define SBLIMIT 32 /* number of subbands */
49

    
50
#define MPA_STEREO  0
51
#define MPA_JSTEREO 1
52
#define MPA_DUAL    2
53
#define MPA_MONO    3
54

    
55
/* header + layer + bitrate + freq + lsf/mpeg25 */
56
#define SAME_HEADER_MASK \
57
   (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
58

    
59
#define MP3_MASK 0xFFFE0CCF
60

    
61
#ifndef FRAC_BITS
62
#define FRAC_BITS   23   /* fractional bits for sb_samples and dct */
63
#define WFRAC_BITS  16   /* fractional bits for window */
64
#endif
65

    
66
#define FRAC_ONE    (1 << FRAC_BITS)
67

    
68
#define FIX(a)   ((int)((a) * FRAC_ONE))
69

    
70
#if CONFIG_FLOAT
71
typedef float OUT_INT;
72
#define OUT_FMT AV_SAMPLE_FMT_FLT
73
#elif CONFIG_MPEGAUDIO_HP && CONFIG_AUDIO_NONSHORT
74
typedef int32_t OUT_INT;
75
#define OUT_MAX INT32_MAX
76
#define OUT_MIN INT32_MIN
77
#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
78
#define OUT_FMT AV_SAMPLE_FMT_S32
79
#else
80
typedef int16_t OUT_INT;
81
#define OUT_MAX INT16_MAX
82
#define OUT_MIN INT16_MIN
83
#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
84
#define OUT_FMT AV_SAMPLE_FMT_S16
85
#endif
86

    
87
#if CONFIG_FLOAT
88
#   define INTFLOAT float
89
typedef float MPA_INT;
90
#elif FRAC_BITS <= 15
91
#   define INTFLOAT int
92
typedef int16_t MPA_INT;
93
#else
94
#   define INTFLOAT int
95
typedef int32_t MPA_INT;
96
#endif
97

    
98
#define BACKSTEP_SIZE 512
99
#define EXTRABYTES 24
100

    
101
/* layer 3 "granule" */
102
typedef struct GranuleDef {
103
    uint8_t scfsi;
104
    int part2_3_length;
105
    int big_values;
106
    int global_gain;
107
    int scalefac_compress;
108
    uint8_t block_type;
109
    uint8_t switch_point;
110
    int table_select[3];
111
    int subblock_gain[3];
112
    uint8_t scalefac_scale;
113
    uint8_t count1table_select;
114
    int region_size[3]; /* number of huffman codes in each region */
115
    int preflag;
116
    int short_start, long_end; /* long/short band indexes */
117
    uint8_t scale_factors[40];
118
    INTFLOAT sb_hybrid[SBLIMIT * 18]; /* 576 samples */
119
} GranuleDef;
120

    
121
#define MPA_DECODE_HEADER \
122
    int frame_size; \
123
    int error_protection; \
124
    int layer; \
125
    int sample_rate; \
126
    int sample_rate_index; /* between 0 and 8 */ \
127
    int bit_rate; \
128
    int nb_channels; \
129
    int mode; \
130
    int mode_ext; \
131
    int lsf;
132

    
133
typedef struct MPADecodeHeader {
134
  MPA_DECODE_HEADER
135
} MPADecodeHeader;
136

    
137
typedef struct MPADecodeContext {
138
    MPA_DECODE_HEADER
139
    uint8_t last_buf[2*BACKSTEP_SIZE + EXTRABYTES];
140
    int last_buf_size;
141
    /* next header (used in free format parsing) */
142
    uint32_t free_format_next_header;
143
    GetBitContext gb;
144
    GetBitContext in_gb;
145
    DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2];
146
    int synth_buf_offset[MPA_MAX_CHANNELS];
147
    DECLARE_ALIGNED(16, INTFLOAT, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
148
    INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
149
    GranuleDef granules[2][2]; /* Used in Layer 3 */
150
    int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
151
    int dither_state;
152
    int error_recognition;
153
    AVCodecContext* avctx;
154
#if CONFIG_FLOAT
155
    DCTContext dct;
156
#endif
157
    void (*apply_window_mp3)(MPA_INT *synth_buf, MPA_INT *window,
158
                             int *dither_state, OUT_INT *samples, int incr);
159
} MPADecodeContext;
160

    
161
/* layer 3 huffman tables */
162
typedef struct HuffTable {
163
    int xsize;
164
    const uint8_t *bits;
165
    const uint16_t *codes;
166
} HuffTable;
167

    
168
int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
169
int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
170
extern MPA_INT ff_mpa_synth_window[];
171
void ff_mpa_synth_init(MPA_INT *window);
172
void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
173
                         MPA_INT *window, int *dither_state,
174
                         OUT_INT *samples, int incr,
175
                         INTFLOAT sb_samples[SBLIMIT]);
176

    
177
void ff_mpa_synth_init_float(MPA_INT *window);
178
void ff_mpa_synth_filter_float(MPADecodeContext *s,
179
                         MPA_INT *synth_buf_ptr, int *synth_buf_offset,
180
                         MPA_INT *window, int *dither_state,
181
                         OUT_INT *samples, int incr,
182
                         INTFLOAT sb_samples[SBLIMIT]);
183

    
184
void ff_mpegaudiodec_init_mmx(MPADecodeContext *s);
185
void ff_mpegaudiodec_init_altivec(MPADecodeContext *s);
186

    
187
/* fast header check for resync */
188
static inline int ff_mpa_check_header(uint32_t header){
189
    /* header */
190
    if ((header & 0xffe00000) != 0xffe00000)
191
        return -1;
192
    /* layer check */
193
    if ((header & (3<<17)) == 0)
194
        return -1;
195
    /* bit rate */
196
    if ((header & (0xf<<12)) == 0xf<<12)
197
        return -1;
198
    /* frequency */
199
    if ((header & (3<<10)) == 3<<10)
200
        return -1;
201
    return 0;
202
}
203

    
204
#endif /* AVCODEC_MPEGAUDIO_H */