aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-31 21:37:03 +0100
committerMax Kellermann <max@duempel.org>2013-02-01 13:47:24 +0100
commite6a91d291d74bb341b9f7e47ac576fa97533ceb1 (patch)
tree033cc53a3e0719f3faff52f97b8e71c2c0c82188
parentbf359727147aa8e2a1819065eaa68ad56713f4e4 (diff)
downloadmpd-e6a91d291d74bb341b9f7e47ac576fa97533ceb1.tar.gz
mpd-e6a91d291d74bb341b9f7e47ac576fa97533ceb1.tar.xz
mpd-e6a91d291d74bb341b9f7e47ac576fa97533ceb1.zip
PcmChannels: merge duplicate code with a template
Diffstat (limited to '')
-rw-r--r--src/PcmChannels.cxx47
1 files changed, 9 insertions, 38 deletions
diff --git a/src/PcmChannels.cxx b/src/PcmChannels.cxx
index 3b100e46f..eca6b2506 100644
--- a/src/PcmChannels.cxx
+++ b/src/PcmChannels.cxx
@@ -24,17 +24,17 @@
#include <assert.h>
+template<typename D, typename S>
static void
-pcm_convert_channels_16_1_to_2(int16_t *restrict dest,
- const int16_t *restrict src,
- const int16_t *restrict src_end)
+MonoToStereo(D dest, S src, S end)
{
- while (src < src_end) {
- int16_t value = *src++;
+ while (src != end) {
+ const auto value = *src++;
*dest++ = value;
*dest++ = value;
}
+
}
static void
@@ -88,7 +88,7 @@ pcm_convert_channels_16(struct pcm_buffer *buffer,
const int16_t *src_end = pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2)
- pcm_convert_channels_16_1_to_2(dest, src, src_end);
+ MonoToStereo(dest, src, src_end);
else if (src_channels == 2 && dest_channels == 1)
pcm_convert_channels_16_2_to_1(dest, src, src_end);
else if (dest_channels == 2)
@@ -101,19 +101,6 @@ pcm_convert_channels_16(struct pcm_buffer *buffer,
}
static void
-pcm_convert_channels_24_1_to_2(int32_t *restrict dest,
- const int32_t *restrict src,
- const int32_t *restrict src_end)
-{
- while (src < src_end) {
- int32_t value = *src++;
-
- *dest++ = value;
- *dest++ = value;
- }
-}
-
-static void
pcm_convert_channels_24_2_to_1(int32_t *restrict dest,
const int32_t *restrict src,
const int32_t *restrict src_end)
@@ -165,7 +152,7 @@ pcm_convert_channels_24(struct pcm_buffer *buffer,
pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2)
- pcm_convert_channels_24_1_to_2(dest, src, src_end);
+ MonoToStereo(dest, src, src_end);
else if (src_channels == 2 && dest_channels == 1)
pcm_convert_channels_24_2_to_1(dest, src, src_end);
else if (dest_channels == 2)
@@ -178,13 +165,6 @@ pcm_convert_channels_24(struct pcm_buffer *buffer,
}
static void
-pcm_convert_channels_32_1_to_2(int32_t *dest, const int32_t *src,
- const int32_t *src_end)
-{
- pcm_convert_channels_24_1_to_2(dest, src, src_end);
-}
-
-static void
pcm_convert_channels_32_2_to_1(int32_t *restrict dest,
const int32_t *restrict src,
const int32_t *restrict src_end)
@@ -235,7 +215,7 @@ pcm_convert_channels_32(struct pcm_buffer *buffer,
pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2)
- pcm_convert_channels_32_1_to_2(dest, src, src_end);
+ MonoToStereo(dest, src, src_end);
else if (src_channels == 2 && dest_channels == 1)
pcm_convert_channels_32_2_to_1(dest, src, src_end);
else if (dest_channels == 2)
@@ -248,15 +228,6 @@ pcm_convert_channels_32(struct pcm_buffer *buffer,
}
static void
-pcm_convert_channels_float_1_to_2(float *dest, const float *src,
- const float *src_end)
-{
- pcm_convert_channels_24_1_to_2((int32_t *)dest,
- (const int32_t *)src,
- (const int32_t *)src_end);
-}
-
-static void
pcm_convert_channels_float_2_to_1(float *restrict dest,
const float *restrict src,
const float *restrict src_end)
@@ -306,7 +277,7 @@ pcm_convert_channels_float(struct pcm_buffer *buffer,
const float *src_end = (const float *)pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2)
- pcm_convert_channels_float_1_to_2(dest, src, src_end);
+ MonoToStereo(dest, src, src_end);
else if (src_channels == 2 && dest_channels == 1)
pcm_convert_channels_float_2_to_1(dest, src, src_end);
else if (dest_channels == 2)