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.
This commit is contained in:
Max Kellermann 2008-10-12 12:02:52 +02:00
parent 52949453df
commit c0ecce5498

View File

@ -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);