aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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)