add initial support for multiple windows samplerates

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@834 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Michael Gernoth 2005-03-08 04:25:12 +00:00
parent 8191b7c1bd
commit d6a76fe8bc

View File

@ -31,6 +31,7 @@
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;
BOOL g_dsp_busy = False; BOOL g_dsp_busy = False;
static short g_samplewidth; static short g_samplewidth;
@ -53,6 +54,7 @@ wave_out_open(void)
format.bits = 16; format.bits = 16;
format.channels = 2; format.channels = 2;
format.rate = 44100; format.rate = 44100;
g_samplerate = 44100;
format.byte_format = AO_FMT_LITTLE; format.byte_format = AO_FMT_LITTLE;
o_device = ao_open_live(default_driver, &format, NULL); o_device = ao_open_live(default_driver, &format, NULL);
@ -93,9 +95,8 @@ wave_out_format_supported(WAVEFORMATEX * pwfx)
if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16)) if ((pwfx->wBitsPerSample != 8) && (pwfx->wBitsPerSample != 16))
return False; return False;
/* The only common denominator between libao output drivers is a sample-rate of /* The only common denominator between libao output drivers is a sample-rate of
44100, windows gives a max of 22050. we need to upsample that... 44100, we need to upsample 22050 to it */
TODO: support 11025, too */ if ((pwfx->nSamplesPerSec != 44100) && (pwfx->nSamplesPerSec != 22050))
if (pwfx->nSamplesPerSec != 22050)
return False; return False;
return True; return True;
@ -106,10 +107,10 @@ wave_out_set_format(WAVEFORMATEX * pwfx)
{ {
ao_sample_format format; ao_sample_format format;
printf("%d\n",pwfx->wBitsPerSample);
format.bits = pwfx->wBitsPerSample; format.bits = pwfx->wBitsPerSample;
format.channels = pwfx->nChannels; format.channels = pwfx->nChannels;
format.rate = 44100; format.rate = 44100;
g_samplerate = pwfx->nSamplesPerSec;
format.byte_format = AO_FMT_LITTLE; format.byte_format = AO_FMT_LITTLE;
g_samplewidth = pwfx->wBitsPerSample / 8; g_samplewidth = pwfx->wBitsPerSample / 8;
@ -163,10 +164,9 @@ wave_out_play(void)
{ {
struct audio_packet *packet; struct audio_packet *packet;
STREAM out; STREAM out;
unsigned char expanded[8]; unsigned char expanded[16];
int offset,len,i;
while (1)
{
if (queue_lo == queue_hi) if (queue_lo == queue_hi)
{ {
g_dsp_busy = 0; g_dsp_busy = 0;
@ -176,25 +176,40 @@ wave_out_play(void)
packet = &packet_queue[queue_lo]; packet = &packet_queue[queue_lo];
out = &packet->s; out = &packet->s;
/* Resample 22050 -> 44100 */ len = 0;
/* TODO: Do this for 11025, too... */
memcpy(&expanded[0],out->p,g_samplewidth); if (g_samplerate == 22050 )
memcpy(&expanded[2*g_samplewidth],out->p,g_samplewidth); {
out->p += 2; /* Resample to 44100 */
memcpy(&expanded[1*g_samplewidth],out->p,g_samplewidth); for(i=0; (i<(2*(3-g_samplewidth))) && (out->p < out->end); i++)
memcpy(&expanded[3*g_samplewidth],out->p,g_samplewidth); {
offset=i*4*g_samplewidth;
memcpy(&expanded[0*g_samplewidth+offset],out->p,g_samplewidth);
memcpy(&expanded[2*g_samplewidth+offset],out->p,g_samplewidth);
out->p += 2; out->p += 2;
ao_play(o_device, expanded, g_samplewidth*4); memcpy(&expanded[1*g_samplewidth+offset],out->p,g_samplewidth);
memcpy(&expanded[3*g_samplewidth+offset],out->p,g_samplewidth);
out->p += 2;
len += 4*g_samplewidth;
}
}
else
{
len = (16 > (out->end - out->p)) ? (out->end - out->p) : 16;
memcpy(expanded,out->p,len);
out->p += len;
}
ao_play(o_device, expanded, len);
if (out->p == out->end) if (out->p == out->end)
{ {
rdpsnd_send_completion(packet->tick, packet->index); rdpsnd_send_completion(packet->tick, packet->index);
free(out->data); free(out->data);
queue_lo = (queue_lo + 1) % MAX_QUEUE; queue_lo = (queue_lo + 1) % MAX_QUEUE;
} else { }
g_dsp_busy = 1; g_dsp_busy = 1;
return; return;
}
}
} }