FFmpeg
mpegaudiodec_fixed.c
Go to the documentation of this file.
1 /*
2  * Fixed-point MPEG audio decoder
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 #include "config.h"
22 #include "config_components.h"
23 #include "libavutil/samplefmt.h"
24 
25 #define USE_FLOATS 0
26 
27 #include "codec_internal.h"
28 #include "mpegaudio.h"
29 
30 #define SHR(a,b) (((int)(a))>>(b))
31 /* WARNING: only correct for positive numbers */
32 #define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
33 #define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
34 #define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
35 #define MULH3(x, y, s) MULH((s)*(x), y)
36 #define MULLx(x, y, s) MULL((int)(x),(y),s)
37 #define RENAME(a) a ## _fixed
38 #define OUT_FMT AV_SAMPLE_FMT_S16
39 #define OUT_FMT_P AV_SAMPLE_FMT_S16P
40 
41 /* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274
42  * (float based mp1/mp2/mp3 decoders.) for how they were created. */
43 static const int32_t is_table[2][16] = {
44  { 0x000000, 0x1B0CB1, 0x2ED9EC, 0x400000, 0x512614, 0x64F34F, 0x800000 },
45  { 0x800000, 0x64F34F, 0x512614, 0x400000, 0x2ED9EC, 0x1B0CB1, 0x000000 }
46 };
47 
48 /* Antialiasing table. See commit ce4a29c066cddfc180979ed86396812f24337985
49  * (optimize antialias) for how they were created. */
50 static const int32_t csa_table[8][4] = {
51  { 0x36E129F8, 0xDF128056, 0x15F3AA4E, 0xA831565E },
52  { 0x386E75F2, 0xE1CF24A5, 0x1A3D9A97, 0xA960AEB3 },
53  { 0x3CC6B73A, 0xEBF19FA6, 0x28B856E0, 0xAF2AE86C },
54  { 0x3EEEA054, 0xF45B88BC, 0x334A2910, 0xB56CE868 },
55  { 0x3FB6905C, 0xF9F27F18, 0x39A90F74, 0xBA3BEEBC },
56  { 0x3FF23F20, 0xFD60D1E4, 0x3D531104, 0xBD6E92C4 },
57  { 0x3FFE5932, 0xFF175EE4, 0x3F15B816, 0xBF1905B2 },
58  { 0x3FFFE34A, 0xFFC3612F, 0x3FC34479, 0xBFC37DE5 }
59 };
60 
61 #include "mpegaudiodec_template.c"
62 
63 #if CONFIG_MP1_DECODER
64 const FFCodec ff_mp1_decoder = {
65  .p.name = "mp1",
66  .p.long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
67  .p.type = AVMEDIA_TYPE_AUDIO,
68  .p.id = AV_CODEC_ID_MP1,
69  .priv_data_size = sizeof(MPADecodeContext),
70  .init = decode_init,
72  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
74  .flush = flush,
75  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
78  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
79 };
80 #endif
81 #if CONFIG_MP2_DECODER
82 const FFCodec ff_mp2_decoder = {
83  .p.name = "mp2",
84  .p.long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
85  .p.type = AVMEDIA_TYPE_AUDIO,
86  .p.id = AV_CODEC_ID_MP2,
87  .priv_data_size = sizeof(MPADecodeContext),
88  .init = decode_init,
90  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
92  .flush = flush,
93  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
96  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
97 };
98 #endif
99 #if CONFIG_MP3_DECODER
100 const FFCodec ff_mp3_decoder = {
101  .p.name = "mp3",
102  .p.long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
103  .p.type = AVMEDIA_TYPE_AUDIO,
104  .p.id = AV_CODEC_ID_MP3,
105  .priv_data_size = sizeof(MPADecodeContext),
106  .init = decode_init,
108  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
110  .flush = flush,
111  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
114  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
115 };
116 #endif
117 #if CONFIG_MP3ADU_DECODER
118 const FFCodec ff_mp3adu_decoder = {
119  .p.name = "mp3adu",
120  .p.long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
121  .p.type = AVMEDIA_TYPE_AUDIO,
122  .p.id = AV_CODEC_ID_MP3ADU,
123  .priv_data_size = sizeof(MPADecodeContext),
124  .init = decode_init,
125  FF_CODEC_DECODE_CB(decode_frame_adu),
126  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
128  .flush = flush,
129  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
132  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
133 };
134 #endif
135 #if CONFIG_MP3ON4_DECODER
136 const FFCodec ff_mp3on4_decoder = {
137  .p.name = "mp3on4",
138  .p.long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
139  .p.type = AVMEDIA_TYPE_AUDIO,
140  .p.id = AV_CODEC_ID_MP3ON4,
141  .priv_data_size = sizeof(MP3On4DecodeContext),
142  .init = decode_init_mp3on4,
143  .close = decode_close_mp3on4,
144  FF_CODEC_DECODE_CB(decode_frame_mp3on4),
145  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
147  .flush = flush_mp3on4,
148  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
151 };
152 #endif
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:39
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition: 4xm.c:837
AV_CODEC_ID_MP3ON4
@ AV_CODEC_ID_MP3ON4
Definition: codec_id.h:439
FFCodec
Definition: codec_internal.h:112
MPADecodeContext
Definition: mpegaudiodec_template.c:76
AV_CODEC_ID_MP3ADU
@ AV_CODEC_ID_MP3ADU
Definition: codec_id.h:438
init
static int init
Definition: av_tx.c:47
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:116
samplefmt.h
AV_CODEC_ID_MP3
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: codec_id.h:426
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:254
mpegaudiodec_template.c
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CODEC_ID_MP2
@ AV_CODEC_ID_MP2
Definition: codec_id.h:425
flush
static void flush(AVCodecContext *avctx)
Definition: aacdec_template.c:606
ff_mp2_decoder
const FFCodec ff_mp2_decoder
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:109
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:116
codec_internal.h
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
ff_mp1_decoder
const FFCodec ff_mp1_decoder
ff_mp3_decoder
const FFCodec ff_mp3_decoder
is_table
static const int32_t is_table[2][16]
Definition: mpegaudiodec_fixed.c:43
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: codec_internal.h:31
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: 4xm.c:990
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
ff_mp3adu_decoder
const FFCodec ff_mp3adu_decoder
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:203
mpegaudio.h
int32_t
int32_t
Definition: audioconvert.c:56
AV_CODEC_ID_MP1
@ AV_CODEC_ID_MP1
Definition: codec_id.h:467
csa_table
static const int32_t csa_table[8][4]
Definition: mpegaudiodec_fixed.c:50
ff_mp3on4_decoder
const FFCodec ff_mp3on4_decoder