FFmpeg
mpegaudiodec_float.c
Go to the documentation of this file.
1 /*
2  * Float MPEG Audio decoder
3  * Copyright (c) 2010 Michael Niedermayer
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "config.h"
23 #include "config_components.h"
24 #include "libavutil/samplefmt.h"
25 
26 #define USE_FLOATS 1
27 
28 #include "codec_internal.h"
29 #include "mpegaudio.h"
30 
31 #define SHR(a,b) ((a)*(1.0f/(1<<(b))))
32 #define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5))
33 #define FIXR(x) ((float)(x))
34 #define FIXHR(x) ((float)(x))
35 #define MULH3(x, y, s) ((s)*(y)*(x))
36 #define MULLx(x, y, s) ((y)*(x))
37 #define RENAME(a) a ## _float
38 #define OUT_FMT AV_SAMPLE_FMT_FLT
39 #define OUT_FMT_P AV_SAMPLE_FMT_FLTP
40 
41 /* Intensity stereo table. See commit b91d46614df189e7905538e7f5c4ed9c7ed0d274
42  * (float based mp1/mp2/mp3 decoders.) for how they were created. */
43 static const float is_table[2][16] = {
44  { 0.000000000000000000e+00, 2.113248705863952637e-01, 3.660253882408142090e-01,
45  5.000000000000000000e-01, 6.339746117591857910e-01, 7.886751294136047363e-01,
46  1.000000000000000000e+00 },
47  { 1.000000000000000000e+00, 7.886751294136047363e-01, 6.339746117591857910e-01,
48  5.000000000000000000e-01, 3.660253882408142090e-01, 2.113248705863952637e-01,
49  0.000000000000000000e+00 }
50 };
51 
52 /* Antialiasing table. See commit 6f1ec38ce2193d3d4cacd87edb452c6d7ba751ec
53  * (mpegaudio: clean up compute_antialias() definition) for how they were
54  * created. */
55 static const float csa_table[8][4] = {
56  { 8.574929237365722656e-01, -5.144957900047302246e-01,
57  3.429971337318420410e-01, -1.371988654136657715e+00 },
58  { 8.817420005798339844e-01, -4.717319905757904053e-01,
59  4.100100100040435791e-01, -1.353474020957946777e+00 },
60  { 9.496286511421203613e-01, -3.133774697780609131e-01,
61  6.362511515617370605e-01, -1.263006091117858887e+00 },
62  { 9.833145737648010254e-01, -1.819131970405578613e-01,
63  8.014013767242431641e-01, -1.165227770805358887e+00 },
64  { 9.955177903175354004e-01, -9.457419067621231079e-02,
65  9.009436368942260742e-01, -1.090092062950134277e+00 },
66  { 9.991605877876281738e-01, -4.096558317542076111e-02,
67  9.581949710845947266e-01, -1.040126085281372070e+00 },
68  { 9.998992085456848145e-01, -1.419856864959001541e-02,
69  9.857006072998046875e-01, -1.014097809791564941e+00 },
70  { 9.999931454658508301e-01, -3.699974622577428818e-03,
71  9.962931871414184570e-01, -1.003693103790283203e+00 }
72 };
73 
74 #include "mpegaudiodec_template.c"
75 
76 #if CONFIG_MP1FLOAT_DECODER
78  .p.name = "mp1float",
79  .p.long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
80  .p.type = AVMEDIA_TYPE_AUDIO,
81  .p.id = AV_CODEC_ID_MP1,
82  .priv_data_size = sizeof(MPADecodeContext),
83  .init = decode_init,
85  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
87  .flush = flush,
88  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
91  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
92 };
93 #endif
94 #if CONFIG_MP2FLOAT_DECODER
96  .p.name = "mp2float",
97  .p.long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
98  .p.type = AVMEDIA_TYPE_AUDIO,
99  .p.id = AV_CODEC_ID_MP2,
100  .priv_data_size = sizeof(MPADecodeContext),
101  .init = decode_init,
103  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
105  .flush = flush,
106  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
109  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
110 };
111 #endif
112 #if CONFIG_MP3FLOAT_DECODER
114  .p.name = "mp3float",
115  .p.long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
116  .p.type = AVMEDIA_TYPE_AUDIO,
117  .p.id = AV_CODEC_ID_MP3,
118  .priv_data_size = sizeof(MPADecodeContext),
119  .init = decode_init,
121  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
123  .flush = flush,
124  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
127  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
128 };
129 #endif
130 #if CONFIG_MP3ADUFLOAT_DECODER
132  .p.name = "mp3adufloat",
133  .p.long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
134  .p.type = AVMEDIA_TYPE_AUDIO,
135  .p.id = AV_CODEC_ID_MP3ADU,
136  .priv_data_size = sizeof(MPADecodeContext),
137  .init = decode_init,
138  FF_CODEC_DECODE_CB(decode_frame_adu),
139  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
141  .flush = flush,
142  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
145  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
146 };
147 #endif
148 #if CONFIG_MP3ON4FLOAT_DECODER
150  .p.name = "mp3on4float",
151  .p.long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"),
152  .p.type = AVMEDIA_TYPE_AUDIO,
153  .p.id = AV_CODEC_ID_MP3ON4,
154  .priv_data_size = sizeof(MP3On4DecodeContext),
155  .init = decode_init_mp3on4,
156  .close = decode_close_mp3on4,
157  FF_CODEC_DECODE_CB(decode_frame_mp3on4),
158  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
160  .flush = flush_mp3on4,
161  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
164 };
165 #endif
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
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
ff_mp3on4float_decoder
const FFCodec ff_mp3on4float_decoder
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
csa_table
static const float csa_table[8][4]
Definition: mpegaudiodec_float.c:55
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_mp2float_decoder
const FFCodec ff_mp2float_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:117
codec_internal.h
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
ff_mp1float_decoder
const FFCodec ff_mp1float_decoder
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
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:203
ff_mp3adufloat_decoder
const FFCodec ff_mp3adufloat_decoder
mpegaudio.h
ff_mp3float_decoder
const FFCodec ff_mp3float_decoder
is_table
static const float is_table[2][16]
Definition: mpegaudiodec_float.c:43
AV_CODEC_ID_MP1
@ AV_CODEC_ID_MP1
Definition: codec_id.h:467
AV_SAMPLE_FMT_FLT
@ AV_SAMPLE_FMT_FLT
float
Definition: samplefmt.h:60