Commit e6a91d29 authored by Max Kellermann's avatar Max Kellermann

PcmChannels: merge duplicate code with a template

parent bf359727
...@@ -24,17 +24,17 @@ ...@@ -24,17 +24,17 @@
#include <assert.h> #include <assert.h>
template<typename D, typename S>
static void static void
pcm_convert_channels_16_1_to_2(int16_t *restrict dest, MonoToStereo(D dest, S src, S end)
const int16_t *restrict src,
const int16_t *restrict src_end)
{ {
while (src < src_end) { while (src != end) {
int16_t value = *src++; const auto value = *src++;
*dest++ = value; *dest++ = value;
*dest++ = value; *dest++ = value;
} }
} }
static void static void
...@@ -88,7 +88,7 @@ pcm_convert_channels_16(struct pcm_buffer *buffer, ...@@ -88,7 +88,7 @@ pcm_convert_channels_16(struct pcm_buffer *buffer,
const int16_t *src_end = pcm_end_pointer(src, src_size); const int16_t *src_end = pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2) 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) else if (src_channels == 2 && dest_channels == 1)
pcm_convert_channels_16_2_to_1(dest, src, src_end); pcm_convert_channels_16_2_to_1(dest, src, src_end);
else if (dest_channels == 2) else if (dest_channels == 2)
...@@ -101,19 +101,6 @@ pcm_convert_channels_16(struct pcm_buffer *buffer, ...@@ -101,19 +101,6 @@ pcm_convert_channels_16(struct pcm_buffer *buffer,
} }
static void 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, pcm_convert_channels_24_2_to_1(int32_t *restrict dest,
const int32_t *restrict src, const int32_t *restrict src,
const int32_t *restrict src_end) const int32_t *restrict src_end)
...@@ -165,7 +152,7 @@ pcm_convert_channels_24(struct pcm_buffer *buffer, ...@@ -165,7 +152,7 @@ pcm_convert_channels_24(struct pcm_buffer *buffer,
pcm_end_pointer(src, src_size); pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2) 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) else if (src_channels == 2 && dest_channels == 1)
pcm_convert_channels_24_2_to_1(dest, src, src_end); pcm_convert_channels_24_2_to_1(dest, src, src_end);
else if (dest_channels == 2) else if (dest_channels == 2)
...@@ -178,13 +165,6 @@ pcm_convert_channels_24(struct pcm_buffer *buffer, ...@@ -178,13 +165,6 @@ pcm_convert_channels_24(struct pcm_buffer *buffer,
} }
static void 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, pcm_convert_channels_32_2_to_1(int32_t *restrict dest,
const int32_t *restrict src, const int32_t *restrict src,
const int32_t *restrict src_end) const int32_t *restrict src_end)
...@@ -235,7 +215,7 @@ pcm_convert_channels_32(struct pcm_buffer *buffer, ...@@ -235,7 +215,7 @@ pcm_convert_channels_32(struct pcm_buffer *buffer,
pcm_end_pointer(src, src_size); pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2) 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) else if (src_channels == 2 && dest_channels == 1)
pcm_convert_channels_32_2_to_1(dest, src, src_end); pcm_convert_channels_32_2_to_1(dest, src, src_end);
else if (dest_channels == 2) else if (dest_channels == 2)
...@@ -248,15 +228,6 @@ pcm_convert_channels_32(struct pcm_buffer *buffer, ...@@ -248,15 +228,6 @@ pcm_convert_channels_32(struct pcm_buffer *buffer,
} }
static void 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, pcm_convert_channels_float_2_to_1(float *restrict dest,
const float *restrict src, const float *restrict src,
const float *restrict src_end) const float *restrict src_end)
...@@ -306,7 +277,7 @@ pcm_convert_channels_float(struct pcm_buffer *buffer, ...@@ -306,7 +277,7 @@ pcm_convert_channels_float(struct pcm_buffer *buffer,
const float *src_end = (const float *)pcm_end_pointer(src, src_size); const float *src_end = (const float *)pcm_end_pointer(src, src_size);
if (src_channels == 1 && dest_channels == 2) 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) else if (src_channels == 2 && dest_channels == 1)
pcm_convert_channels_float_2_to_1(dest, src, src_end); pcm_convert_channels_float_2_to_1(dest, src, src_end);
else if (dest_channels == 2) else if (dest_channels == 2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment