Commit a3a5f4d6 authored by Michael Niedermayer's avatar Michael Niedermayer

support 32bit output for the mpeg audio decoder

Originally committed as revision 3910 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent b696d2a6
...@@ -17,7 +17,7 @@ extern "C" { ...@@ -17,7 +17,7 @@ extern "C" {
#define FFMPEG_VERSION_INT 0x000409 #define FFMPEG_VERSION_INT 0x000409
#define FFMPEG_VERSION "0.4.9-pre1" #define FFMPEG_VERSION "0.4.9-pre1"
#define LIBAVCODEC_BUILD 4738 #define LIBAVCODEC_BUILD 4739
#define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT
#define LIBAVCODEC_VERSION FFMPEG_VERSION #define LIBAVCODEC_VERSION FFMPEG_VERSION
...@@ -224,6 +224,9 @@ enum PixelFormat { ...@@ -224,6 +224,9 @@ enum PixelFormat {
/* currently unused, may be used if 24/32 bits samples ever supported */ /* currently unused, may be used if 24/32 bits samples ever supported */
enum SampleFormat { enum SampleFormat {
SAMPLE_FMT_S16 = 0, ///< signed 16 bits SAMPLE_FMT_S16 = 0, ///< signed 16 bits
SAMPLE_FMT_S32, ///< signed 32 bits
SAMPLE_FMT_FLT, ///< float
SAMPLE_FMT_DBL, ///< double
}; };
/* in bytes */ /* in bytes */
...@@ -734,10 +737,7 @@ typedef struct AVCodecContext { ...@@ -734,10 +737,7 @@ typedef struct AVCodecContext {
/** /**
* pixel format, see PIX_FMT_xxx. * pixel format, see PIX_FMT_xxx.
* - encoding: FIXME: used by ffmpeg to decide whether an pix_fmt * - encoding: set by user.
* conversion is in order. This only works for
* codecs with one supported pix_fmt, we should
* do something for a generic case as well.
* - decoding: set by lavc. * - decoding: set by lavc.
*/ */
enum PixelFormat pix_fmt; enum PixelFormat pix_fmt;
...@@ -769,7 +769,13 @@ typedef struct AVCodecContext { ...@@ -769,7 +769,13 @@ typedef struct AVCodecContext {
/* audio only */ /* audio only */
int sample_rate; ///< samples per sec int sample_rate; ///< samples per sec
int channels; int channels;
int sample_fmt; ///< sample format, currenly unused
/**
* audio sample format.
* - encoding: set by user.
* - decoding: set by lavc.
*/
enum SampleFormat sample_fmt; ///< sample format, currenly unused
/* the following data should not be initialized */ /* the following data should not be initialized */
int frame_size; ///< in samples, initialized when calling 'init' int frame_size; ///< in samples, initialized when calling 'init'
......
...@@ -48,6 +48,18 @@ ...@@ -48,6 +48,18 @@
#define WFRAC_BITS 14 /* fractional bits for window */ #define WFRAC_BITS 14 /* fractional bits for window */
#endif #endif
#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
typedef int32_t OUT_INT;
#define OUT_MAX INT32_MAX
#define OUT_MIN INT32_MIN
#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
#else
typedef int16_t OUT_INT;
#define OUT_MAX INT16_MAX
#define OUT_MIN INT16_MIN
#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
#endif
#define FRAC_ONE (1 << FRAC_BITS) #define FRAC_ONE (1 << FRAC_BITS)
#define MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS) #define MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> FRAC_BITS)
...@@ -324,6 +336,12 @@ static int decode_init(AVCodecContext * avctx) ...@@ -324,6 +336,12 @@ static int decode_init(AVCodecContext * avctx)
static int init=0; static int init=0;
int i, j, k; int i, j, k;
#if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
avctx->sample_fmt= SAMPLE_FMT_S32;
#else
avctx->sample_fmt= SAMPLE_FMT_S16;
#endif
if(avctx->antialias_algo == FF_AA_INT) if(avctx->antialias_algo == FF_AA_INT)
s->compute_antialias= compute_antialias_integer; s->compute_antialias= compute_antialias_integer;
else else
...@@ -748,8 +766,6 @@ static void dct32(int32_t *out, int32_t *tab) ...@@ -748,8 +766,6 @@ static void dct32(int32_t *out, int32_t *tab)
out[31] = tab[31]; out[31] = tab[31];
} }
#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
#if FRAC_BITS <= 15 #if FRAC_BITS <= 15
static inline int round_sample(int *sum) static inline int round_sample(int *sum)
...@@ -757,10 +773,10 @@ static inline int round_sample(int *sum) ...@@ -757,10 +773,10 @@ static inline int round_sample(int *sum)
int sum1; int sum1;
sum1 = (*sum) >> OUT_SHIFT; sum1 = (*sum) >> OUT_SHIFT;
*sum &= (1<<OUT_SHIFT)-1; *sum &= (1<<OUT_SHIFT)-1;
if (sum1 < -32768) if (sum1 < OUT_MIN)
sum1 = -32768; sum1 = OUT_MIN;
else if (sum1 > 32767) else if (sum1 > OUT_MAX)
sum1 = 32767; sum1 = OUT_MAX;
return sum1; return sum1;
} }
...@@ -791,10 +807,10 @@ static inline int round_sample(int64_t *sum) ...@@ -791,10 +807,10 @@ static inline int round_sample(int64_t *sum)
int sum1; int sum1;
sum1 = (int)((*sum) >> OUT_SHIFT); sum1 = (int)((*sum) >> OUT_SHIFT);
*sum &= (1<<OUT_SHIFT)-1; *sum &= (1<<OUT_SHIFT)-1;
if (sum1 < -32768) if (sum1 < OUT_MIN)
sum1 = -32768; sum1 = OUT_MIN;
else if (sum1 > 32767) else if (sum1 > OUT_MAX)
sum1 = 32767; sum1 = OUT_MAX;
return sum1; return sum1;
} }
...@@ -867,14 +883,14 @@ void ff_mpa_synth_init(MPA_INT *window) ...@@ -867,14 +883,14 @@ void ff_mpa_synth_init(MPA_INT *window)
/* XXX: optimize by avoiding ring buffer usage */ /* XXX: optimize by avoiding ring buffer usage */
void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
MPA_INT *window, int *dither_state, MPA_INT *window, int *dither_state,
int16_t *samples, int incr, OUT_INT *samples, int incr,
int32_t sb_samples[SBLIMIT]) int32_t sb_samples[SBLIMIT])
{ {
int32_t tmp[32]; int32_t tmp[32];
register MPA_INT *synth_buf; register MPA_INT *synth_buf;
register const MPA_INT *w, *w2, *p; register const MPA_INT *w, *w2, *p;
int j, offset, v; int j, offset, v;
int16_t *samples2; OUT_INT *samples2;
#if FRAC_BITS <= 15 #if FRAC_BITS <= 15
int sum, sum2; int sum, sum2;
#else #else
...@@ -2455,10 +2471,10 @@ static int mp_decode_layer3(MPADecodeContext *s) ...@@ -2455,10 +2471,10 @@ static int mp_decode_layer3(MPADecodeContext *s)
} }
static int mp_decode_frame(MPADecodeContext *s, static int mp_decode_frame(MPADecodeContext *s,
short *samples) OUT_INT *samples)
{ {
int i, nb_frames, ch; int i, nb_frames, ch;
short *samples_ptr; OUT_INT *samples_ptr;
init_get_bits(&s->gb, s->inbuf + HEADER_SIZE, init_get_bits(&s->gb, s->inbuf + HEADER_SIZE,
(s->inbuf_ptr - s->inbuf - HEADER_SIZE)*8); (s->inbuf_ptr - s->inbuf - HEADER_SIZE)*8);
...@@ -2505,7 +2521,7 @@ static int mp_decode_frame(MPADecodeContext *s, ...@@ -2505,7 +2521,7 @@ static int mp_decode_frame(MPADecodeContext *s,
#ifdef DEBUG #ifdef DEBUG
s->frame_count++; s->frame_count++;
#endif #endif
return nb_frames * 32 * sizeof(short) * s->nb_channels; return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels;
} }
static int decode_frame(AVCodecContext * avctx, static int decode_frame(AVCodecContext * avctx,
...@@ -2516,7 +2532,7 @@ static int decode_frame(AVCodecContext * avctx, ...@@ -2516,7 +2532,7 @@ static int decode_frame(AVCodecContext * avctx,
uint32_t header; uint32_t header;
uint8_t *buf_ptr; uint8_t *buf_ptr;
int len, out_size; int len, out_size;
short *out_samples = data; OUT_INT *out_samples = data;
buf_ptr = buf; buf_ptr = buf;
while (buf_size > 0) { while (buf_size > 0) {
...@@ -2674,7 +2690,7 @@ static int decode_frame_adu(AVCodecContext * avctx, ...@@ -2674,7 +2690,7 @@ static int decode_frame_adu(AVCodecContext * avctx,
MPADecodeContext *s = avctx->priv_data; MPADecodeContext *s = avctx->priv_data;
uint32_t header; uint32_t header;
int len, out_size; int len, out_size;
short *out_samples = data; OUT_INT *out_samples = data;
len = buf_size; len = buf_size;
......
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