aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-23 20:11:28 +0200
committerMax Kellermann <max@duempel.org>2008-10-23 20:11:28 +0200
commitec37633f1ceb43487a79513af625e1e43da3ffc7 (patch)
tree4b86599fbf7c312c2a84c9d00efef70c0607a28a /src
parent98e4817548ab18a696defb1db6bd74eafc3b7998 (diff)
downloadmpd-ec37633f1ceb43487a79513af625e1e43da3ffc7.tar.gz
mpd-ec37633f1ceb43487a79513af625e1e43da3ffc7.tar.xz
mpd-ec37633f1ceb43487a79513af625e1e43da3ffc7.zip
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().
Diffstat (limited to '')
-rw-r--r--src/pcm_utils.c23
1 files 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;
}