aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-12 12:02:52 +0200
committerMax Kellermann <max@duempel.org>2008-10-12 12:02:52 +0200
commitc0ecce54981a3c3b9cca29604b54620c63517129 (patch)
treef58d6d6661410a86144c7bc9367469bf603603b9
parent52949453dfbe685d38df6f7992f6fc38d3a20088 (diff)
downloadmpd-c0ecce54981a3c3b9cca29604b54620c63517129.tar.gz
mpd-c0ecce54981a3c3b9cca29604b54620c63517129.tar.xz
mpd-c0ecce54981a3c3b9cca29604b54620c63517129.zip
pcm_utils: support converting N channels to stereo
Convert any number of channels to stereo. In fact, this isn't really stereo, it's rater mono blown up to stereo. This patch should only make it possible to play 5.1 files at all; "real" conversion to stereo should be implemented, but for now, this is better than nothing.
Diffstat (limited to '')
-rw-r--r--src/pcm_utils.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index 52f9294b7..cb6f93f63 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -385,6 +385,29 @@ pcm_convert_channels_2_to_1(int16_t *dest, const int16_t *src,
}
}
+static void
+pcm_convert_channels_n_to_2(int16_t *dest,
+ unsigned src_channels, const int16_t *src,
+ unsigned num_frames)
+{
+ unsigned c;
+
+ assert(src_channels > 0);
+
+ while (num_frames-- > 0) {
+ int32_t sum = 0;
+ int16_t value;
+
+ for (c = 0; c < src_channels; ++c)
+ sum += *src++;
+ value = sum / (int)src_channels;
+
+ /* XXX this is actually only mono ... */
+ *dest++ = value;
+ *dest++ = value;
+ }
+}
+
static const int16_t *
pcm_convertChannels(int8_t dest_channels,
int8_t src_channels, const int16_t *src,
@@ -406,6 +429,9 @@ pcm_convertChannels(int8_t dest_channels,
pcm_convert_channels_1_to_2(buf, src, num_frames);
else if (src_channels == 2 && dest_channels == 1)
pcm_convert_channels_2_to_1(buf, src, num_frames);
+ else if (dest_channels == 2)
+ pcm_convert_channels_n_to_2(buf, src_channels, src,
+ num_frames);
else {
ERROR("conversion %u->%u channels is not supported\n",
src_channels, dest_channels);