Statistics
| Branch: | Revision:

ffmpeg / libavcodec / mpegaudio.h @ 84dc2d8a

History | View | Annotate | Download (5.2 KB)

1 04d7f601 Diego Biurrun
/*
2
 * copyright (c) 2001 Fabrice Bellard
3
 *
4 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
5
 *
6
 * FFmpeg is free software; you can redistribute it and/or
7 04d7f601 Diego Biurrun
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
10 04d7f601 Diego Biurrun
 *
11 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
12 04d7f601 Diego Biurrun
 * 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 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
18 04d7f601 Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
21 983e3246 Michael Niedermayer
/**
22 bad5537e Diego Biurrun
 * @file libavcodec/mpegaudio.h
23 983e3246 Michael Niedermayer
 * mpeg audio declarations for both encoder and decoder.
24
 */
25 2456e28d Fabrice Bellard
26 98790382 Stefano Sabatini
#ifndef AVCODEC_MPEGAUDIO_H
27
#define AVCODEC_MPEGAUDIO_H
28 4bd8e17c Aurelien Jacobs
29 08aa2c9b Aurelien Jacobs
#include "avcodec.h"
30 9106a698 Stefano Sabatini
#include "get_bits.h"
31 4bd8e17c Aurelien Jacobs
#include "dsputil.h"
32
33 8b192330 Aurelien Jacobs
#define CONFIG_AUDIO_NONSHORT 0
34
35 2456e28d Fabrice Bellard
/* max frame size, in samples */
36 115329f1 Diego Biurrun
#define MPA_FRAME_SIZE 1152
37 de6d9b64 Fabrice Bellard
38
/* max compressed frame size */
39 2456e28d Fabrice Bellard
#define MPA_MAX_CODED_FRAME_SIZE 1792
40 de6d9b64 Fabrice Bellard
41
#define MPA_MAX_CHANNELS 2
42
43
#define SBLIMIT 32 /* number of subbands */
44
45 2456e28d Fabrice Bellard
#define MPA_STEREO  0
46
#define MPA_JSTEREO 1
47
#define MPA_DUAL    2
48
#define MPA_MONO    3
49
50 a7a85899 Michael Niedermayer
/* header + layer + bitrate + freq + lsf/mpeg25 */
51
#define SAME_HEADER_MASK \
52
   (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
53
54 b57eed12 Aurelien Jacobs
#define MP3_MASK 0xFFFE0CCF
55
56 0f6a659d Diego Biurrun
#if CONFIG_MPEGAUDIO_HP
57 d9b1c197 Roberto Togni
#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 c2d08dc0 Måns Rullgård
#define FRAC_ONE    (1 << FRAC_BITS)
65
66
#define FIX(a)   ((int)((a) * FRAC_ONE))
67
68 0f6a659d Diego Biurrun
#if CONFIG_MPEGAUDIO_HP && CONFIG_AUDIO_NONSHORT
69 d9b1c197 Roberto Togni
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 49cdad8d Aurelien Jacobs
#define OUT_FMT SAMPLE_FMT_S32
74 d9b1c197 Roberto Togni
#else
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 49cdad8d Aurelien Jacobs
#define OUT_FMT SAMPLE_FMT_S16
80 d9b1c197 Roberto Togni
#endif
81
82
#if FRAC_BITS <= 15
83
typedef int16_t MPA_INT;
84
#else
85
typedef int32_t MPA_INT;
86
#endif
87
88 4bd8e17c Aurelien Jacobs
#define BACKSTEP_SIZE 512
89
#define EXTRABYTES 24
90
91 c9023405 Vitor Sessak
/* layer 3 "granule" */
92
typedef struct GranuleDef {
93
    uint8_t scfsi;
94
    int part2_3_length;
95
    int big_values;
96
    int global_gain;
97
    int scalefac_compress;
98
    uint8_t block_type;
99
    uint8_t switch_point;
100
    int table_select[3];
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 */
105
    int preflag;
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 */
109
} GranuleDef;
110 4bd8e17c Aurelien Jacobs
111 cf92cec7 Andreas Öman
#define MPA_DECODE_HEADER \
112
    int frame_size; \
113
    int error_protection; \
114
    int layer; \
115
    int sample_rate; \
116
    int sample_rate_index; /* between 0 and 8 */ \
117
    int bit_rate; \
118
    int nb_channels; \
119
    int mode; \
120
    int mode_ext; \
121
    int lsf;
122
123
typedef struct MPADecodeHeader {
124
  MPA_DECODE_HEADER
125
} MPADecodeHeader;
126
127 4bd8e17c Aurelien Jacobs
typedef struct MPADecodeContext {
128 cf92cec7 Andreas Öman
    MPA_DECODE_HEADER
129 20e7c8ae Måns Rullgård
    uint8_t last_buf[2*BACKSTEP_SIZE + EXTRABYTES];
130 4bd8e17c Aurelien Jacobs
    int last_buf_size;
131
    /* next header (used in free format parsing) */
132
    uint32_t free_format_next_header;
133
    GetBitContext gb;
134
    GetBitContext in_gb;
135 84dc2d8a Måns Rullgård
    DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2];
136 4bd8e17c Aurelien Jacobs
    int synth_buf_offset[MPA_MAX_CHANNELS];
137 84dc2d8a Måns Rullgård
    DECLARE_ALIGNED(16, int32_t, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
138 4bd8e17c Aurelien Jacobs
    int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
139 c9023405 Vitor Sessak
    GranuleDef granules[2][2]; /* Used in Layer 3 */
140 4bd8e17c Aurelien Jacobs
#ifdef DEBUG
141
    int frame_count;
142
#endif
143
    void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
144
    int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
145
    int dither_state;
146 047599a4 Michael Niedermayer
    int error_recognition;
147 4bd8e17c Aurelien Jacobs
    AVCodecContext* avctx;
148
} MPADecodeContext;
149
150 c2d08dc0 Måns Rullgård
/* layer 3 huffman tables */
151
typedef struct HuffTable {
152
    int xsize;
153
    const uint8_t *bits;
154
    const uint16_t *codes;
155
} HuffTable;
156
157 08aa2c9b Aurelien Jacobs
int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
158 c96bd212 Michael Niedermayer
int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate);
159 9adcccde Reimar Döffinger
extern MPA_INT ff_mpa_synth_window[];
160 d9b1c197 Roberto Togni
void ff_mpa_synth_init(MPA_INT *window);
161
void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
162 bb270c08 Diego Biurrun
                         MPA_INT *window, int *dither_state,
163 d9b1c197 Roberto Togni
                         OUT_INT *samples, int incr,
164
                         int32_t sb_samples[SBLIMIT]);
165 de6d9b64 Fabrice Bellard
166 a7a85899 Michael Niedermayer
/* fast header check for resync */
167
static inline int ff_mpa_check_header(uint32_t header){
168
    /* header */
169
    if ((header & 0xffe00000) != 0xffe00000)
170
        return -1;
171
    /* layer check */
172
    if ((header & (3<<17)) == 0)
173
        return -1;
174
    /* bit rate */
175
    if ((header & (0xf<<12)) == 0xf<<12)
176
        return -1;
177
    /* frequency */
178
    if ((header & (3<<10)) == 3<<10)
179
        return -1;
180
    return 0;
181
}
182 4bd8e17c Aurelien Jacobs
183 98790382 Stefano Sabatini
#endif /* AVCODEC_MPEGAUDIO_H */