Updates to Sun audio support (from Michael Gernoth).

git-svn-id: svn://svn.code.sf.net/p/rdesktop/code/trunk/rdesktop@476 423420c4-83ab-492f-b58f-81f9feb106b5
This commit is contained in:
Matt Chapman 2003-10-04 12:24:56 +00:00
parent 5b021f9561
commit 35d5c8dcbb
2 changed files with 43 additions and 18 deletions

2
configure vendored
View File

@ -242,7 +242,7 @@ if [ -f /usr/include/sys/soundcard.h ]; then
echo echo
echo "SOUNDOBJ = rdpsnd.o rdpsnd_oss.o" >>Makeconf echo "SOUNDOBJ = rdpsnd.o rdpsnd_oss.o" >>Makeconf
cflags="$cflags -DWITH_RDPSND" cflags="$cflags -DWITH_RDPSND"
elif [ -f /usr/include/sys/audio.h ]; then elif [ -f /usr/include/sys/audioio.h ]; then
echo Sound support enabled: Sun echo Sound support enabled: Sun
echo echo
echo "SOUNDOBJ = rdpsnd.o rdpsnd_sun.o" >>Makeconf echo "SOUNDOBJ = rdpsnd.o rdpsnd_sun.o" >>Makeconf

View File

@ -25,13 +25,14 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/audio.h> #include <sys/audioio.h>
#include <stropts.h> #include <stropts.h>
#define MAX_QUEUE 10 #define MAX_QUEUE 10
int g_dsp_fd; int g_dsp_fd;
BOOL g_dsp_busy; BOOL g_dsp_busy;
static BOOL reopened;
static BOOL swapaudio; static BOOL swapaudio;
static short samplewidth; static short samplewidth;
@ -45,7 +46,12 @@ static unsigned int queue_hi, queue_lo;
BOOL BOOL
wave_out_open(void) wave_out_open(void)
{ {
char *dsp_dev = "/dev/audio"; char *dsp_dev = getenv("AUDIODEV");
if ( dsp_dev == NULL )
{
dsp_dev="/dev/audio";
}
if ((g_dsp_fd = open(dsp_dev, O_WRONLY|O_NONBLOCK)) == -1) if ((g_dsp_fd = open(dsp_dev, O_WRONLY|O_NONBLOCK)) == -1)
{ {
@ -53,16 +59,27 @@ wave_out_open(void)
return False; return False;
} }
/* Non-blocking so that user interface is responsive */ /* Non-blocking so that user interface is responsive */
fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL)|O_NONBLOCK); fcntl(g_dsp_fd, F_SETFL, fcntl(g_dsp_fd, F_GETFL)|O_NONBLOCK);
queue_lo = queue_hi = 0; queue_lo = queue_hi = 0;
reopened = True;
return True; return True;
} }
void void
wave_out_close(void) wave_out_close(void)
{ {
/* Ack all remaining packets */
while ( queue_lo != queue_hi )
{
rdpsnd_send_completion(packet_queue[queue_lo].tick, packet_queue[queue_lo].index);
free(packet_queue[queue_lo].s.data);
queue_lo = (queue_lo + 1) % MAX_QUEUE;
}
/* Flush the audiobuffer */
ioctl(g_dsp_fd,I_FLUSH,FLUSHW); ioctl(g_dsp_fd,I_FLUSH,FLUSHW);
close(g_dsp_fd); close(g_dsp_fd);
} }
@ -94,13 +111,14 @@ wave_out_set_format(WAVEFORMATEX *pwfx)
if (pwfx->wBitsPerSample == 8) if (pwfx->wBitsPerSample == 8)
{ {
info.play.encoding = AUDIO_ENCODING_LINEAR8; info.play.encoding = AUDIO_ENCODING_LINEAR8;
samplewidth=1; samplewidth = 1;
} }
else if (pwfx->wBitsPerSample == 16) else if (pwfx->wBitsPerSample == 16)
{ {
info.play.encoding = AUDIO_ENCODING_LINEAR; info.play.encoding = AUDIO_ENCODING_LINEAR;
samplewidth = 2;
/* Do we need to swap the 16bit values? (Are we BigEndian) */
swapaudio = !(*(uint8 *) (&test)); swapaudio = !(*(uint8 *) (&test));
samplewidth=2;
} }
if (pwfx->nChannels == 1 ) if (pwfx->nChannels == 1 )
@ -110,7 +128,7 @@ wave_out_set_format(WAVEFORMATEX *pwfx)
else if (pwfx->nChannels == 2 ) else if (pwfx->nChannels == 2 )
{ {
info.play.channels = AUDIO_CHANNELS_STEREO; info.play.channels = AUDIO_CHANNELS_STEREO;
samplewidth*=2; samplewidth *= 2;
} }
info.play.sample_rate = pwfx->nSamplesPerSec; info.play.sample_rate = pwfx->nSamplesPerSec;
@ -165,11 +183,20 @@ wave_out_play(void)
STREAM out; STREAM out;
static BOOL swapped = False; static BOOL swapped = False;
static BOOL sentcompletion = True; static BOOL sentcompletion = True;
static int samplecnt; static uint32 samplecnt = 0;
static int numsamples; static uint32 numsamples;
while (1) while (1)
{ {
if ( reopened )
{
/* Device was just (re)openend */
samplecnt = 0;
swapped = False;
sentcompletion = True;
reopened = False;
}
if (queue_lo == queue_hi) if (queue_lo == queue_hi)
{ {
g_dsp_busy = 0; g_dsp_busy = 0;
@ -179,6 +206,7 @@ wave_out_play(void)
packet = &packet_queue[queue_lo]; packet = &packet_queue[queue_lo];
out = &packet->s; out = &packet->s;
/* Swap the current packet, but only once */
if ( swapaudio && ! swapped ) if ( swapaudio && ! swapped )
{ {
for ( i = 0; i < out->end - out->p; i+=2 ) for ( i = 0; i < out->end - out->p; i+=2 )
@ -192,19 +220,13 @@ wave_out_play(void)
if ( sentcompletion ) if ( sentcompletion )
{ {
if (ioctl(g_dsp_fd, AUDIO_GETINFO, &info) == -1)
{
perror("AUDIO_GETINFO");
return;
}
samplecnt=info.play.samples;
sentcompletion = False; sentcompletion = False;
numsamples = (out->end-out->p)/samplewidth; numsamples = (out->end - out->p)/samplewidth;
} }
len=0; len=0;
if ( out->end - out->p != 0 ) if ( out->end != out->p )
{ {
len = write(g_dsp_fd, out->p, out->end - out->p); len = write(g_dsp_fd, out->p, out->end - out->p);
if (len == -1) if (len == -1)
@ -224,8 +246,11 @@ wave_out_play(void)
perror("AUDIO_GETINFO"); perror("AUDIO_GETINFO");
return; return;
} }
if ( info.play.samples >= samplecnt+(numsamples)*0.9 )
/* Ack the packet, if we have played at least 70% */
if ( info.play.samples >= samplecnt+((numsamples*7)/10) )
{ {
samplecnt += numsamples;
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;