Commit b91d4661 authored by Michael Niedermayer's avatar Michael Niedermayer
Browse files

float based mp1/mp2/mp3 decoders.

Originally committed as revision 23095 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 495af353
......@@ -192,17 +192,28 @@ OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o
OBJS-$(CONFIG_MOTIONPIXELS_DECODER) += motionpixels.o
OBJS-$(CONFIG_MP1_DECODER) += mpegaudiodec.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MP1FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MP2_DECODER) += mpegaudiodec.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MP2_ENCODER) += mpegaudioenc.o mpegaudio.o \
mpegaudiodata.o
OBJS-$(CONFIG_MP2FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MP3ADU_DECODER) += mpegaudiodec.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MP3ADUFLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MP3ON4_DECODER) += mpegaudiodec.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o \
mpeg4audio.o
OBJS-$(CONFIG_MP3ON4FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o \
mpeg4audio.o
OBJS-$(CONFIG_MP3_DECODER) += mpegaudiodec.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MP3FLOAT_DECODER) += mpegaudiodec_float.o mpegaudiodecheader.o \
mpegaudio.o mpegaudiodata.o
OBJS-$(CONFIG_MPC7_DECODER) += mpc7.o mpc.o mpegaudiodec.o \
mpegaudiodecheader.o mpegaudio.o \
mpegaudiodata.o
......
......@@ -232,10 +232,15 @@ void avcodec_register_all(void)
REGISTER_DECODER (MACE6, mace6);
REGISTER_DECODER (MLP, mlp);
REGISTER_DECODER (MP1, mp1);
REGISTER_DECODER (MP1FLOAT, mp1float);
REGISTER_ENCDEC (MP2, mp2);
REGISTER_DECODER (MP2FLOAT, mp2float);
REGISTER_DECODER (MP3, mp3);
REGISTER_DECODER (MP3FLOAT, mp3float);
REGISTER_DECODER (MP3ADU, mp3adu);
REGISTER_DECODER (MP3ADUFLOAT, mp3adufloat);
REGISTER_DECODER (MP3ON4, mp3on4);
REGISTER_DECODER (MP3ON4FLOAT, mp3on4float);
REGISTER_DECODER (MPC7, mpc7);
REGISTER_DECODER (MPC8, mpc8);
REGISTER_ENCDEC (NELLYMOSER, nellymoser);
......
......@@ -26,6 +26,10 @@
#ifndef AVCODEC_MPEGAUDIO_H
#define AVCODEC_MPEGAUDIO_H
#ifndef CONFIG_FLOAT
# define CONFIG_FLOAT 0
#endif
#include "avcodec.h"
#include "get_bits.h"
#include "dsputil.h"
......@@ -65,7 +69,10 @@
#define FIX(a) ((int)((a) * FRAC_ONE))
#if CONFIG_MPEGAUDIO_HP && CONFIG_AUDIO_NONSHORT
#if CONFIG_FLOAT
typedef float OUT_INT;
#define OUT_FMT SAMPLE_FMT_FLT
#elif CONFIG_MPEGAUDIO_HP && CONFIG_AUDIO_NONSHORT
typedef int32_t OUT_INT;
#define OUT_MAX INT32_MAX
#define OUT_MIN INT32_MIN
......@@ -79,9 +86,14 @@ typedef int16_t OUT_INT;
#define OUT_FMT SAMPLE_FMT_S16
#endif
#if FRAC_BITS <= 15
#if CONFIG_FLOAT
# define INTFLOAT float
typedef float MPA_INT;
#elif FRAC_BITS <= 15
# define INTFLOAT int
typedef int16_t MPA_INT;
#else
# define INTFLOAT int
typedef int32_t MPA_INT;
#endif
......@@ -105,7 +117,7 @@ typedef struct GranuleDef {
int preflag;
int short_start, long_end; /* long/short band indexes */
uint8_t scale_factors[40];
int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */
INTFLOAT sb_hybrid[SBLIMIT * 18]; /* 576 samples */
} GranuleDef;
#define MPA_DECODE_HEADER \
......@@ -134,13 +146,12 @@ typedef struct MPADecodeContext {
GetBitContext in_gb;
DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2];
int synth_buf_offset[MPA_MAX_CHANNELS];
DECLARE_ALIGNED(16, int32_t, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
DECLARE_ALIGNED(16, INTFLOAT, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT];
INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
GranuleDef granules[2][2]; /* Used in Layer 3 */
#ifdef DEBUG
int frame_count;
#endif
void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
int dither_state;
int error_recognition;
......@@ -161,7 +172,13 @@ void ff_mpa_synth_init(MPA_INT *window);
void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
MPA_INT *window, int *dither_state,
OUT_INT *samples, int incr,
int32_t sb_samples[SBLIMIT]);
INTFLOAT sb_samples[SBLIMIT]);
void ff_mpa_synth_init_float(MPA_INT *window);
void ff_mpa_synth_filter_float(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
MPA_INT *window, int *dither_state,
OUT_INT *samples, int incr,
INTFLOAT sb_samples[SBLIMIT]);
/* fast header check for resync */
static inline int ff_mpa_check_header(uint32_t header){
......
......@@ -37,6 +37,8 @@ static int8_t table_4_3_exp[TABLE_4_3_SIZE];
static uint32_t table_4_3_value[TABLE_4_3_SIZE];
static uint32_t exp_table[512];
static uint32_t expval_table[512][16];
static float exp_table_float[512];
static float expval_table_float[512][16];
static void mpegaudio_tableinit(void)
{
......@@ -58,8 +60,10 @@ static void mpegaudio_tableinit(void)
for (value = 0; value < 16; value++) {
double f = (double)value * cbrtf(value) * pow(2, (exponent - 400) * 0.25 + FRAC_BITS + 5);
expval_table[exponent][value] = llrint(f);
expval_table_float[exponent][value] = f;
}
exp_table[exponent] = expval_table[exponent][1];
exp_table_float[exponent] = expval_table_float[exponent][1];
}
}
#endif /* CONFIG_HARDCODED_TABLES */
......
This diff is collapsed.
/*
* Float MPEG Audio decoder
* Copyright (c) 2010 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* 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.
*
* FFmpeg is distributed in the hope that it will be useful,
* 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
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define CONFIG_FLOAT 1
#include "mpegaudiodec.c"
#if CONFIG_MP1FLOAT_DECODER
AVCodec mp1float_decoder =
{
"mp1float",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_MP1,
sizeof(MPADecodeContext),
decode_init,
NULL,
NULL,
decode_frame,
CODEC_CAP_PARSE_ONLY,
.flush= flush,
.long_name= NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"),
};
#endif
#if CONFIG_MP2FLOAT_DECODER
AVCodec mp2float_decoder =
{
"mp2float",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_MP2,
sizeof(MPADecodeContext),
decode_init,
NULL,
NULL,
decode_frame,
CODEC_CAP_PARSE_ONLY,
.flush= flush,
.long_name= NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
};
#endif
#if CONFIG_MP3FLOAT_DECODER
AVCodec mp3float_decoder =
{
"mp3float",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_MP3,
sizeof(MPADecodeContext),
decode_init,
NULL,
NULL,
decode_frame,
CODEC_CAP_PARSE_ONLY,
.flush= flush,
.long_name= NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"),
};
#endif
#if CONFIG_MP3ADUFLOAT_DECODER
AVCodec mp3adufloat_decoder =
{
"mp3adufloat",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_MP3ADU,
sizeof(MPADecodeContext),
decode_init,
NULL,
NULL,
decode_frame_adu,
CODEC_CAP_PARSE_ONLY,
.flush= flush,
.long_name= NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"),
};
#endif
#if CONFIG_MP3ON4FLOAT_DECODER
AVCodec mp3on4float_decoder =
{
"mp3on4float",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_MP3ON4,
sizeof(MP3On4DecodeContext),
decode_init_mp3on4,
NULL,
decode_close_mp3on4,
decode_frame_mp3on4,
.flush= flush,
.long_name= NULL_IF_CONFIG_SMALL("MP3onMP4"),
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment