2 * Fixed-point MPEG audio decoder
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 #include "libavutil/samplefmt.h"
26 #include "mpegaudio.h"
28 #define SHR(a,b) (((int)(a))>>(b))
29 /* WARNING: only correct for positive numbers */
30 #define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
31 #define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
32 #define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
33 #define MULH3(x, y, s) MULH((s)*(x), y)
34 #define MULLx(x, y, s) MULL((int)(x),(y),s)
35 #define RENAME(a) a ## _fixed
36 #define OUT_FMT AV_SAMPLE_FMT_S16
37 #define OUT_FMT_P AV_SAMPLE_FMT_S16P
39 /* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274
40 * (float based mp1/mp2/mp3 decoders.) for how they were created. */
41 static const int32_t is_table[2][16] = {
42 { 0x000000, 0x1B0CB1, 0x2ED9EC, 0x400000, 0x512614, 0x64F34F, 0x800000 },
43 { 0x800000, 0x64F34F, 0x512614, 0x400000, 0x2ED9EC, 0x1B0CB1, 0x000000 }
46 /* Antialiasing table. See commit ce4a29c066cddfc180979ed86396812f24337985
47 * (optimize antialias) for how they were created. */
48 static const int32_t csa_table[8][4] = {
49 { 0x36E129F8, 0xDF128056, 0x15F3AA4E, 0xA831565E },
50 { 0x386E75F2, 0xE1CF24A5, 0x1A3D9A97, 0xA960AEB3 },
51 { 0x3CC6B73A, 0xEBF19FA6, 0x28B856E0, 0xAF2AE86C },
52 { 0x3EEEA054, 0xF45B88BC, 0x334A2910, 0xB56CE868 },
53 { 0x3FB6905C, 0xF9F27F18, 0x39A90F74, 0xBA3BEEBC },
54 { 0x3FF23F20, 0xFD60D1E4, 0x3D531104, 0xBD6E92C4 },
55 { 0x3FFE5932, 0xFF175EE4, 0x3F15B816, 0xBF1905B2 },
56 { 0x3FFFE34A, 0xFFC3612F, 0x3FC34479, 0xBFC37DE5 }
59 #include "mpegaudiodec_template.c"
61 #if CONFIG_MP1_DECODER
62 AVCodec ff_mp1_decoder = {
64 .long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
65 .type = AVMEDIA_TYPE_AUDIO,
66 .id = AV_CODEC_ID_MP1,
67 .priv_data_size = sizeof(MPADecodeContext),
69 .decode = decode_frame,
70 .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
73 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
76 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
79 #if CONFIG_MP2_DECODER
80 AVCodec ff_mp2_decoder = {
82 .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
83 .type = AVMEDIA_TYPE_AUDIO,
84 .id = AV_CODEC_ID_MP2,
85 .priv_data_size = sizeof(MPADecodeContext),
87 .decode = decode_frame,
88 .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
91 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
94 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
97 #if CONFIG_MP3_DECODER
98 AVCodec ff_mp3_decoder = {
100 .long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
101 .type = AVMEDIA_TYPE_AUDIO,
102 .id = AV_CODEC_ID_MP3,
103 .priv_data_size = sizeof(MPADecodeContext),
105 .decode = decode_frame,
106 .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
109 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
111 AV_SAMPLE_FMT_NONE },
112 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
115 #if CONFIG_MP3ADU_DECODER
116 AVCodec ff_mp3adu_decoder = {
118 .long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
119 .type = AVMEDIA_TYPE_AUDIO,
120 .id = AV_CODEC_ID_MP3ADU,
121 .priv_data_size = sizeof(MPADecodeContext),
123 .decode = decode_frame_adu,
124 .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
127 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
129 AV_SAMPLE_FMT_NONE },
130 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
133 #if CONFIG_MP3ON4_DECODER
134 AVCodec ff_mp3on4_decoder = {
136 .long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
137 .type = AVMEDIA_TYPE_AUDIO,
138 .id = AV_CODEC_ID_MP3ON4,
139 .priv_data_size = sizeof(MP3On4DecodeContext),
140 .init = decode_init_mp3on4,
141 .close = decode_close_mp3on4,
142 .decode = decode_frame_mp3on4,
143 .capabilities = AV_CODEC_CAP_CHANNEL_CONF |
145 .flush = flush_mp3on4,
146 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
147 AV_SAMPLE_FMT_NONE },
148 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,