2013-11-19 23:47:39 +03:00
|
|
|
/*
|
|
|
|
* Fixed-point MPEG audio decoder
|
|
|
|
*
|
2013-11-24 07:12:07 +03:00
|
|
|
* This file is part of FFmpeg.
|
2013-11-19 23:47:39 +03:00
|
|
|
*
|
2013-11-24 07:12:07 +03:00
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2013-11-19 23:47:39 +03:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
2013-11-24 07:12:07 +03:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2013-11-19 23:47:39 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2013-11-24 07:12:07 +03:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2013-11-19 23:47:39 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2022-02-23 14:56:49 +02:00
|
|
|
#include "config_components.h"
|
2013-11-19 23:47:39 +03:00
|
|
|
#include "libavutil/samplefmt.h"
|
|
|
|
|
2013-12-03 21:55:12 +03:00
|
|
|
#define USE_FLOATS 0
|
2013-11-19 23:47:39 +03:00
|
|
|
|
2022-03-16 19:18:28 +02:00
|
|
|
#include "codec_internal.h"
|
2013-11-19 23:47:39 +03:00
|
|
|
#include "mpegaudio.h"
|
|
|
|
|
2017-02-20 14:42:33 +02:00
|
|
|
#define SHR(a,b) (((int)(a))>>(b))
|
2013-11-19 23:47:39 +03:00
|
|
|
/* WARNING: only correct for positive numbers */
|
|
|
|
#define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
|
|
|
|
#define FIXR(a) ((int)((a) * FRAC_ONE + 0.5))
|
|
|
|
#define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5))
|
|
|
|
#define MULH3(x, y, s) MULH((s)*(x), y)
|
2017-02-20 14:42:33 +02:00
|
|
|
#define MULLx(x, y, s) MULL((int)(x),(y),s)
|
2013-11-19 23:47:39 +03:00
|
|
|
#define RENAME(a) a ## _fixed
|
|
|
|
#define OUT_FMT AV_SAMPLE_FMT_S16
|
|
|
|
#define OUT_FMT_P AV_SAMPLE_FMT_S16P
|
|
|
|
|
2020-11-18 03:19:53 +02:00
|
|
|
/* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274
|
|
|
|
* (float based mp1/mp2/mp3 decoders.) for how they were created. */
|
|
|
|
static const int32_t is_table[2][16] = {
|
|
|
|
{ 0x000000, 0x1B0CB1, 0x2ED9EC, 0x400000, 0x512614, 0x64F34F, 0x800000 },
|
|
|
|
{ 0x800000, 0x64F34F, 0x512614, 0x400000, 0x2ED9EC, 0x1B0CB1, 0x000000 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Antialiasing table. See commit ce4a29c066cddfc180979ed86396812f24337985
|
|
|
|
* (optimize antialias) for how they were created. */
|
|
|
|
static const int32_t csa_table[8][4] = {
|
|
|
|
{ 0x36E129F8, 0xDF128056, 0x15F3AA4E, 0xA831565E },
|
|
|
|
{ 0x386E75F2, 0xE1CF24A5, 0x1A3D9A97, 0xA960AEB3 },
|
|
|
|
{ 0x3CC6B73A, 0xEBF19FA6, 0x28B856E0, 0xAF2AE86C },
|
|
|
|
{ 0x3EEEA054, 0xF45B88BC, 0x334A2910, 0xB56CE868 },
|
|
|
|
{ 0x3FB6905C, 0xF9F27F18, 0x39A90F74, 0xBA3BEEBC },
|
|
|
|
{ 0x3FF23F20, 0xFD60D1E4, 0x3D531104, 0xBD6E92C4 },
|
|
|
|
{ 0x3FFE5932, 0xFF175EE4, 0x3F15B816, 0xBF1905B2 },
|
|
|
|
{ 0x3FFFE34A, 0xFFC3612F, 0x3FC34479, 0xBFC37DE5 }
|
|
|
|
};
|
|
|
|
|
2013-11-19 23:47:39 +03:00
|
|
|
#include "mpegaudiodec_template.c"
|
|
|
|
|
|
|
|
#if CONFIG_MP1_DECODER
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_mp1_decoder = {
|
|
|
|
.p.name = "mp1",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
|
|
|
|
.p.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.p.id = AV_CODEC_ID_MP1,
|
2013-11-19 23:47:39 +03:00
|
|
|
.priv_data_size = sizeof(MPADecodeContext),
|
|
|
|
.init = decode_init,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(decode_frame),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
|
2020-09-09 23:12:32 +02:00
|
|
|
AV_CODEC_CAP_DR1,
|
2013-11-19 23:47:39 +03:00
|
|
|
.flush = flush,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
|
2013-11-19 23:47:39 +03:00
|
|
|
AV_SAMPLE_FMT_S16,
|
|
|
|
AV_SAMPLE_FMT_NONE },
|
2020-11-17 19:44:18 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
|
2013-11-19 23:47:39 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#if CONFIG_MP2_DECODER
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_mp2_decoder = {
|
|
|
|
.p.name = "mp2",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
|
|
|
|
.p.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.p.id = AV_CODEC_ID_MP2,
|
2013-11-19 23:47:39 +03:00
|
|
|
.priv_data_size = sizeof(MPADecodeContext),
|
|
|
|
.init = decode_init,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(decode_frame),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
|
2020-09-09 23:12:32 +02:00
|
|
|
AV_CODEC_CAP_DR1,
|
2013-11-19 23:47:39 +03:00
|
|
|
.flush = flush,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
|
2013-11-19 23:47:39 +03:00
|
|
|
AV_SAMPLE_FMT_S16,
|
|
|
|
AV_SAMPLE_FMT_NONE },
|
2020-11-17 19:44:18 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
|
2013-11-19 23:47:39 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#if CONFIG_MP3_DECODER
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_mp3_decoder = {
|
|
|
|
.p.name = "mp3",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
|
|
|
|
.p.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.p.id = AV_CODEC_ID_MP3,
|
2013-11-19 23:47:39 +03:00
|
|
|
.priv_data_size = sizeof(MPADecodeContext),
|
|
|
|
.init = decode_init,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(decode_frame),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
|
2020-09-09 23:12:32 +02:00
|
|
|
AV_CODEC_CAP_DR1,
|
2013-11-19 23:47:39 +03:00
|
|
|
.flush = flush,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
|
2013-11-19 23:47:39 +03:00
|
|
|
AV_SAMPLE_FMT_S16,
|
|
|
|
AV_SAMPLE_FMT_NONE },
|
2020-11-17 19:44:18 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
|
2013-11-19 23:47:39 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#if CONFIG_MP3ADU_DECODER
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_mp3adu_decoder = {
|
|
|
|
.p.name = "mp3adu",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
|
|
|
|
.p.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.p.id = AV_CODEC_ID_MP3ADU,
|
2013-11-19 23:47:39 +03:00
|
|
|
.priv_data_size = sizeof(MPADecodeContext),
|
|
|
|
.init = decode_init,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(decode_frame_adu),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
|
2020-09-09 23:12:32 +02:00
|
|
|
AV_CODEC_CAP_DR1,
|
2013-11-19 23:47:39 +03:00
|
|
|
.flush = flush,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
|
2013-11-19 23:47:39 +03:00
|
|
|
AV_SAMPLE_FMT_S16,
|
|
|
|
AV_SAMPLE_FMT_NONE },
|
2020-11-17 19:44:18 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
|
2013-11-19 23:47:39 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#if CONFIG_MP3ON4_DECODER
|
2022-03-16 22:09:54 +02:00
|
|
|
const FFCodec ff_mp3on4_decoder = {
|
|
|
|
.p.name = "mp3on4",
|
|
|
|
.p.long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
|
|
|
|
.p.type = AVMEDIA_TYPE_AUDIO,
|
|
|
|
.p.id = AV_CODEC_ID_MP3ON4,
|
2013-11-19 23:47:39 +03:00
|
|
|
.priv_data_size = sizeof(MP3On4DecodeContext),
|
|
|
|
.init = decode_init_mp3on4,
|
|
|
|
.close = decode_close_mp3on4,
|
2022-03-30 23:28:24 +02:00
|
|
|
FF_CODEC_DECODE_CB(decode_frame_mp3on4),
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
|
2020-09-09 23:12:32 +02:00
|
|
|
AV_CODEC_CAP_DR1,
|
2013-11-19 23:47:39 +03:00
|
|
|
.flush = flush_mp3on4,
|
2022-03-16 22:09:54 +02:00
|
|
|
.p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
|
2013-11-19 23:47:39 +03:00
|
|
|
AV_SAMPLE_FMT_NONE },
|
2020-11-17 19:44:18 +02:00
|
|
|
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
|
2013-11-19 23:47:39 +03:00
|
|
|
};
|
|
|
|
#endif
|