Statistics
| Branch: | Revision:

ffmpeg / libavcodec / mpegaudio.h @ 4bd8e17c

History | View | Annotate | Download (4.14 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 mpegaudio.h
23
 * mpeg audio declarations for both encoder and decoder.
24
 */
25

    
26
#ifndef MPEGAUDIO_H
27
#define MPEGAUDIO_H
28

    
29
#include "bitstream.h"
30
#include "dsputil.h"
31

    
32
/* max frame size, in samples */
33
#define MPA_FRAME_SIZE 1152
34

    
35
/* max compressed frame size */
36
#define MPA_MAX_CODED_FRAME_SIZE 1792
37

    
38
#define MPA_MAX_CHANNELS 2
39

    
40
#define SBLIMIT 32 /* number of subbands */
41

    
42
#define MPA_STEREO  0
43
#define MPA_JSTEREO 1
44
#define MPA_DUAL    2
45
#define MPA_MONO    3
46

    
47
/* header + layer + bitrate + freq + lsf/mpeg25 */
48
#define SAME_HEADER_MASK \
49
   (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
50

    
51
#define MP3_MASK 0xFFFE0CCF
52

    
53
/* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
54
   audio decoder */
55

    
56
#ifdef USE_HIGHPRECISION
57
#define FRAC_BITS   23   /* fractional bits for sb_samples and dct */
58
#define WFRAC_BITS  16   /* fractional bits for window */
59
#else
60
#define FRAC_BITS   15   /* fractional bits for sb_samples and dct */
61
#define WFRAC_BITS  14   /* fractional bits for window */
62
#endif
63

    
64
#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
65
typedef int32_t OUT_INT;
66
#define OUT_MAX INT32_MAX
67
#define OUT_MIN INT32_MIN
68
#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
69
#else
70
typedef int16_t OUT_INT;
71
#define OUT_MAX INT16_MAX
72
#define OUT_MIN INT16_MIN
73
#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
74
#endif
75

    
76
#if FRAC_BITS <= 15
77
typedef int16_t MPA_INT;
78
#else
79
typedef int32_t MPA_INT;
80
#endif
81

    
82
#define BACKSTEP_SIZE 512
83
#define EXTRABYTES 24
84

    
85
struct GranuleDef;
86

    
87
typedef struct MPADecodeContext {
88
    DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
89
    int last_buf_size;
90
    int frame_size;
91
    /* next header (used in free format parsing) */
92
    uint32_t free_format_next_header;
93
    int error_protection;
94
    int layer;
95
    int sample_rate;
96
    int sample_rate_index; /* between 0 and 8 */
97
    int bit_rate;
98
    GetBitContext gb;
99
    GetBitContext in_gb;
100
    int nb_channels;
101
    int mode;
102
    int mode_ext;
103
    int lsf;
104
    DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
105
    int synth_buf_offset[MPA_MAX_CHANNELS];
106
    DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
107
    int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
108
#ifdef DEBUG
109
    int frame_count;
110
#endif
111
    void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
112
    int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
113
    int dither_state;
114
    int error_resilience;
115
    AVCodecContext* avctx;
116
} MPADecodeContext;
117

    
118
int l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
119
int mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
120
void ff_mpa_synth_init(MPA_INT *window);
121
void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
122
                         MPA_INT *window, int *dither_state,
123
                         OUT_INT *samples, int incr,
124
                         int32_t sb_samples[SBLIMIT]);
125

    
126
/* fast header check for resync */
127
static inline int ff_mpa_check_header(uint32_t header){
128
    /* header */
129
    if ((header & 0xffe00000) != 0xffe00000)
130
        return -1;
131
    /* layer check */
132
    if ((header & (3<<17)) == 0)
133
        return -1;
134
    /* bit rate */
135
    if ((header & (0xf<<12)) == 0xf<<12)
136
        return -1;
137
    /* frequency */
138
    if ((header & (3<<10)) == 3<<10)
139
        return -1;
140
    return 0;
141
}
142

    
143
#endif /* MPEGAUDIO_H */