From 2c1fb48318436a7e7872acdf4ffd81817f7fab52 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 14 Nov 2009 23:22:14 +0100 Subject: [PATCH] decoder/audiofile: moved code to audiofile_setup_sample_format() --- src/decoder/audiofile_plugin.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/decoder/audiofile_plugin.c b/src/decoder/audiofile_plugin.c index 058f87813..4ef471f46 100644 --- a/src/decoder/audiofile_plugin.c +++ b/src/decoder/audiofile_plugin.c @@ -101,6 +101,25 @@ setup_virtual_fops(struct input_stream *stream) return vf; } +static uint8_t +audiofile_setup_sample_format(AFfilehandle af_fp) +{ + int fs, bits; + + afGetSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits); + if (!audio_valid_sample_format(bits)) { + g_debug("input file has %d bit samples, converting to 16", + bits); + bits = 16; + } + + afSetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, + AF_SAMPFMT_TWOSCOMP, bits); + afGetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits); + + return bits; +} + static void audiofile_stream_decode(struct decoder *decoder, struct input_stream *is) { @@ -129,16 +148,7 @@ audiofile_stream_decode(struct decoder *decoder, struct input_stream *is) return; } - afGetSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits); - if (!audio_valid_sample_format(bits)) { - g_debug("input file has %d bit samples, converting to 16", - bits); - bits = 16; - } - - afSetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, - AF_SAMPFMT_TWOSCOMP, bits); - afGetVirtualSampleFormat(af_fp, AF_DEFAULT_TRACK, &fs, &bits); + bits = audiofile_setup_sample_format(af_fp); if (!audio_format_init_checked(&audio_format, afGetRate(af_fp, AF_DEFAULT_TRACK),