add upsampling for mono-channels

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@839 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Michael Gernoth 2005-03-08 17:03:08 +00:00
parent b8db8ae695
commit ffbb77466d

View File

@ -27,12 +27,13 @@
#include <ao/ao.h> #include <ao/ao.h>
#define MAX_QUEUE 10 #define MAX_QUEUE 10
#define WAVEOUTBUF 32 #define WAVEOUTBUF 64
int g_dsp_fd; int g_dsp_fd;
ao_device *o_device = NULL; ao_device *o_device = NULL;
int default_driver; int default_driver;
int g_samplerate; int g_samplerate;
int g_channels;
BOOL g_dsp_busy = False; BOOL g_dsp_busy = False;
static short g_samplewidth; static short g_samplewidth;
@ -54,6 +55,7 @@ wave_out_open(void)
format.bits = 16; format.bits = 16;
format.channels = 2; format.channels = 2;
g_channels = 2;
format.rate = 44100; format.rate = 44100;
g_samplerate = 44100; g_samplerate = 44100;
format.byte_format = AO_FMT_LITTLE; format.byte_format = AO_FMT_LITTLE;
@ -111,6 +113,7 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
format.bits = pwfx->wBitsPerSample; format.bits = pwfx->wBitsPerSample;
format.channels = pwfx->nChannels; format.channels = pwfx->nChannels;
g_channels = pwfx->nChannels;
format.rate = 44100; format.rate = 44100;
g_samplerate = pwfx->nSamplesPerSec; g_samplerate = pwfx->nSamplesPerSec;
format.byte_format = AO_FMT_LITTLE; format.byte_format = AO_FMT_LITTLE;
@ -184,18 +187,19 @@ wave_out_play(void)
if (g_samplerate == 22050) if (g_samplerate == 22050)
{ {
/* Resample to 44100 */ /* Resample to 44100 */
for (i = 0; (i < ((WAVEOUTBUF / 8) * (3 - g_samplewidth))) && (out->p < out->end); for (i = 0; (i < ((WAVEOUTBUF / 4) * (3 - g_samplewidth))) && (out->p < out->end);
i++) i++)
{ {
offset = i * 4 * g_samplewidth; if (g_channels == 2)
memcpy(&outbuf[0 * g_samplewidth + offset], out->p, g_samplewidth); offset = ((i * 2) - (i & 1)) * g_samplewidth;
memcpy(&outbuf[2 * g_samplewidth + offset], out->p, g_samplewidth); else
offset = (i * 2) * g_samplewidth;
memcpy(&outbuf[offset], out->p, g_samplewidth);
memcpy(&outbuf[g_channels * g_samplewidth + offset], out->p, g_samplewidth);
out->p += 2; out->p += 2;
memcpy(&outbuf[1 * g_samplewidth + offset], out->p, g_samplewidth); len += 2 * g_samplewidth;
memcpy(&outbuf[3 * g_samplewidth + offset], out->p, g_samplewidth);
out->p += 2;
len += 4 * g_samplewidth;
} }
} }
else else