diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2011-04-25 13:59:28 +0400 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2011-04-25 18:51:27 +0400 |
commit | 4c7ad768e1356edd7addc6af2c3f0d3ca90ac408 (patch) | |
tree | 2ebf23399f1162121c682d10d910c74c10514bff /libavcodec/ac3dec.c | |
parent | 5e9de76f54e54d1c4e1f060f4e93e73cd7706828 (diff) |
ac3dec: allow selecting float output at runtime.
Diffstat (limited to 'libavcodec/ac3dec.c')
-rw-r--r-- | libavcodec/ac3dec.c | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index b2e4f81704..431f67dc23 100644 --- a/libavcodec/ac3dec.c +++ b/libavcodec/ac3dec.c @@ -185,14 +185,6 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) ff_fmt_convert_init(&s->fmt_conv, avctx); av_lfg_init(&s->dith_state, 0); - /* ffdshow custom code */ -#if CONFIG_AUDIO_FLOAT - s->mul_bias = 1.0f; -#else - /* set scale value for float to int16 conversion */ - s->mul_bias = 32767.0f; -#endif - /* allow downmixing to stereo or mono */ if (avctx->channels > 0 && avctx->request_channels > 0 && avctx->request_channels < avctx->channels && @@ -201,12 +193,14 @@ static av_cold int ac3_decode_init(AVCodecContext *avctx) } s->downmixed = 1; - /* ffdshow custom code */ -#if CONFIG_AUDIO_FLOAT - avctx->sample_fmt = AV_SAMPLE_FMT_FLT; -#else - avctx->sample_fmt = AV_SAMPLE_FMT_S16; -#endif + if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) { + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + s->mul_bias = 1.0f; + } else { + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + /* set scale value for float to int16 conversion */ + s->mul_bias = 32767.0f; + } return 0; } @@ -1301,12 +1295,8 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; AC3DecodeContext *s = avctx->priv_data; - /* ffdshow custom code */ -#if CONFIG_AUDIO_FLOAT - float *out_samples = (float *)data; -#else + float *out_samples_flt = (float *)data; int16_t *out_samples = (int16_t *)data; -#endif int blk, ch, err; const uint8_t *channel_map; const float *output[AC3_MAX_CHANNELS]; @@ -1412,15 +1402,16 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, av_log(avctx, AV_LOG_ERROR, "error decoding the audio block\n"); err = 1; } - /* ffdshow custom code */ -#if CONFIG_AUDIO_FLOAT - float_interleave_noscale(out_samples, output, 256, s->out_channels); -#else - s->fmt_conv.float_to_int16_interleave(out_samples, output, 256, s->out_channels); -#endif - out_samples += 256 * s->out_channels; + if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) { + float_interleave_noscale(out_samples_flt, output, 256, s->out_channels); + out_samples_flt += 256 * s->out_channels; + } else { + s->fmt_conv.float_to_int16_interleave(out_samples, output, 256, s->out_channels); + out_samples += 256 * s->out_channels; + } } - *data_size = s->num_blocks * 256 * avctx->channels * sizeof (out_samples[0]); /* ffdshow custom code */ + *data_size = s->num_blocks * 256 * avctx->channels; + *data_size *= avctx->sample_fmt == AV_SAMPLE_FMT_FLT ? sizeof(*out_samples_flt) : sizeof(*out_samples); return FFMIN(buf_size, s->frame_size); } |