From ec37633f1ceb43487a79513af625e1e43da3ffc7 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 23 Oct 2008 20:11:28 +0200 Subject: pcm_utils: generic pcm_convert_size() implementation The old pcm_convert_size() ignored most of the destination format, e.g. it did not check its sample size, and assumed it is 16 bit. Simplify and universalize it by using audio_format_frame_size(). --- src/pcm_utils.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/pcm_utils.c b/src/pcm_utils.c index 63685e0b2..7fa95aa5e 100644 --- a/src/pcm_utils.c +++ b/src/pcm_utils.c @@ -343,33 +343,14 @@ size_t pcm_convert_size(const struct audio_format *inFormat, size_t src_size, { const double ratio = (double)outFormat->sample_rate / (double)inFormat->sample_rate; - const int shift = 2 * outFormat->channels; size_t dest_size = src_size; /* no partial frames allowed */ assert((src_size % audio_format_frame_size(inFormat)) == 0); - switch (inFormat->bits) { - case 8: - dest_size <<= 1; - break; - case 16: - break; - case 24: - dest_size = (dest_size / 4) * 2; - break; - default: - FATAL("only 8 or 16 bits are supported for conversion!\n"); - } - - if (inFormat->channels != outFormat->channels) { - dest_size /= inFormat->channels; - dest_size *= outFormat->channels; - } - - dest_size /= shift; + dest_size /= audio_format_frame_size(inFormat); dest_size = floor(0.5 + (double)dest_size * ratio); - dest_size *= shift; + dest_size *= audio_format_frame_size(outFormat); return dest_size; } -- cgit v1.2.3