9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* pc audio buffer bug
@ 1997-02-09 22:35 rsc
  0 siblings, 0 replies; 2+ messages in thread
From: rsc @ 1997-02-09 22:35 UTC (permalink / raw)


There is a small bug in the buffer handling
in the PC devaudio (Soundblaster) driver.
Basically, if you open /dev/audio for writing,
partially fill a buffer, and then close /dev/audio,
the buffer doesn't get played.  You notice this
with smallish sound files, because nothing gets
played at all when the sound file is less than one
buffer in size.

My fix is to add 
	int omode;
	Buf *b;

at the beginning of 
/sys/src/9/pc/devaudio.c:/^audioclose
and in the case Qaudio that follows, insert
	omode = audio.amode;
before audio.amode = Aclosed;

Then, before the while(audio.active), insert
	if(omode == Awrite && audio.filling != 0) {
		print("flush...");
		b = audio.filling;
		audio.filling = 0;
		memset(b->virt+audio.curcount, 0, Bufsize-audio.curcount);
		swab(b->virt);
		putbuf(&audio.full, b);
		pokeaudio();
	}

I would post a diff, but I've hacked up devaudio.c
too much.  Just looking at the code for other 
architectures, it appears that next/devaudio.c also
suffers from this bug, while indigo3k/devaudio.c
does not.

Russ




^ permalink raw reply	[flat|nested] 2+ messages in thread

* pc audio buffer bug
@ 1997-02-10  9:52 David
  0 siblings, 0 replies; 2+ messages in thread
From: David @ 1997-02-10  9:52 UTC (permalink / raw)


> There is a small bug in the buffer handling
> in the PC devaudio (Soundblaster) driver.
> Basically, if you open /dev/audio for writing,
> partially fill a buffer, and then close /dev/audio,
> the buffer doesn't get played.  You notice this
> with smallish sound files, because nothing gets
> played at all when the sound file is less than one
> buffer in size.

I seem to recall that there was another bug.  I can't remember
if I posted my fix for it or not.  The problem was that you could
fill up several buffers, but still get no audio, because you hadn't
filled enough buffers to start the dma going.

It looks like Russ's patch comes close to fixing this bug as well
(by virtue of the call to pokeaudio()).  But if the combined writes
to /dev/audio are a multiple of Bufsize, then it won't be called,
because audio.filling == 0.

My fix to this second bug was to change the while loop in
audioclose() to be

	do
		waitaudio();
	while (audio.active);

and change waitaudio() by adding the lines

	if (audio.active == 0)
		return;

before the tsleep().

I'm a bit concerned that I may have `done bad' -- my solution
can result in redundant commands being sent to the 'blaster
(``start! stop!'') if there's no outstanding data.  But it was, after
all, a quick hack so I could get back to the more important
work of playing with Csound :-)




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-02-10  9:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-02-09 22:35 pc audio buffer bug rsc
1997-02-10  9:52 David

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).