From owner-freebsd-current Sun Apr 2 8: 9:21 2000 Delivered-To: freebsd-current@freebsd.org Received: from ipt2.iptelecom.net.ua (ipt2.iptelecom.net.ua [212.9.224.2]) by hub.freebsd.org (Postfix) with ESMTP id 07CFA37BD9E; Sun, 2 Apr 2000 08:09:13 -0700 (PDT) (envelope-from sobomax@altavista.net) Received: from altavista.net (dialup6-36.iptelecom.net.ua [212.9.227.100]) by ipt2.iptelecom.net.ua (8.9.3/8.9.3) with ESMTP id SAA04526; Sun, 2 Apr 2000 18:14:53 +0300 (EEST) Message-ID: <38E7631B.E06D3D70@altavista.net> Date: Sun, 02 Apr 2000 18:11:23 +0300 From: Maxim Sobolev Organization: Home, sweet home X-Mailer: Mozilla 4.72 [en] (Win98; I) X-Accept-Language: uk,ru,en MIME-Version: 1.0 To: MIHIRA Sanpei Yoshiro Cc: cg@FreeBSD.ORG, current@FreeBSD.ORG, multimedia@FreeBSD.ORG Subject: Buffering issues of the pcm audio driver (Was: cvs commit: src/sys/dev/sound/isa ess.c) References: <38E68B29.2055235C@altavista.net> <200004021437.XAA34730@lavender.yy.cs.keio.ac.jp> Content-Type: multipart/mixed; boundary="------------42AABDBF5E5B30EDD5BCA01F" Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG This is a multi-part message in MIME format. --------------42AABDBF5E5B30EDD5BCA01F Content-Type: text/plain; charset=x-user-defined Content-Transfer-Encoding: 7bit Hi, I've tried to track down sound issues of the SDL (Simple Direct Layer) library and found that current pcm buffering behaviour inconsistent with OSS specifications, which cause applications that require sophisticated sound control to misbehave on FreeBSD. There is two different buffers implemented in the pcm driver: one back-end, with size specified an a compile time (ranging from 4KB to 64KB on different chipsets), and one front-end size of which could be changed by the audio application at runtime. Problems arises when application tries to get current state of the audio buffer either by using select(), or by doing direct SNDCTL_DSP_GETOSPACE ioctl(). In both these cases current FreeBSD behaviour isn't consistent with OSS specs: - the SNDCTL_DSP_GETOSPACE ioctl() returns current state of the front buffer, while ignores much larger back buffer which usually absorbs all data sent to the pcm. Thus application using this ioctl() being fooled about how much data is in the audio buffers. - the select() call doesn't block until the whole back buffer will be filled, while according to specs it should block while fragsize*fragnumber amount of data already is in the buffers. Possible solution (from better to worse): 1. Fix select() support in the pcm driver to account effects of the two buffers. 2. Provide workaround to the SNDCTL_DSP_GETOSPACE to return largest free buffer space available in either front or back buffer. Thus aware applications would have a possibility to check how much data is in hardware buffers and behave accordingly. This will not violate OSS specs, as it is permitted to have this value larger than fragsize*fragments. See attached diffs. 3. Decrease size of the back buffers in all pcm drivers to a some reasonable value like 4KB. -Maxim --------------42AABDBF5E5B30EDD5BCA01F Content-Type: text/plain; charset=x-user-defined; name="dsp.c.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="dsp.c.diff" --- /usr/src/sys/dev/sound/pcm/dsp.c 2000/04/02 09:41:26 1.1 +++ /usr/src/sys/dev/sound/pcm/dsp.c 2000/04/02 09:49:56 @@ -467,8 +467,8 @@ chn_checkunderflow(wrch); while (chn_wrfeed(wrch) > 0); } - a->bytes = bs->fl; - a->fragments = a->bytes / wrch->blocksize2nd; + a->bytes = (bs->fl > b->fl ? bs->fl : b->fl); + a->fragments = bs->fl / wrch->blocksize2nd; a->fragstotal = bs->bufsize / wrch->blocksize2nd; a->fragsize = wrch->blocksize2nd; } --------------42AABDBF5E5B30EDD5BCA01F-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message