Hi Daper,
I would like to ask, what does it mean this code convering mono->stereo.
/* Double the channels from */
static char *mono_to_stereo (const char *mono, const size_t size,
const long format)
{
int Bps = sfmt_Bps (format);
size_t i;
char *stereo;
stereo = (char *)xmalloc (size * 2);
for (i = 0; i < size; i += Bps) {
memcpy (stereo + (i * 2), mono + i, Bps);
memcpy (stereo + (i * 2 + Bps), mono + i, Bps);
}
return stereo;
}
I'm playing with pulseaudio and made this function duplicating stereo to 4 channel sound. But it seems very silly to me. Why is Bps added to second channel in mono_to_stereo? How would you construct general stereo to n-channels function? Do I have to split the stereo into separate channels and duplicate them?
Like stereo-> ch1,ch2
Quad-> f_left ch1, r_left ch1
Quad-> f_right ch2, r_right ch2
/* Quad the channels from */
static char *stereo_to_quad (const char *stereo, const size_t size,
const long format)
{
int Bps = sfmt_Bps (format);
size_t i;
char *quad;
quad = (char *)xmalloc (size * 2);
for (i = 0; i < size; i += Bps) {
memcpy (quad + (i * 2), stereo + i, Bps);
memcpy (quad + (i * 2 + Bps), stereo + i, Bps);
}
return quad;
}
Thanks