From bc4e57d7da104517213d33ff2667a9df6067cc7e Mon Sep 17 00:00:00 2001 From: Aaron Campbell Date: Thu, 24 May 2001 04:21:04 +0000 Subject: Fix fragment handling for SNDCTL_DSP_GETxSPACE ioctls; per NetBSD PR/12796. The kernel part of this fixes sound emulation for version 1.37c of the Linux binary of Snes9x (Super Nintendo emulator). The userland equivalent fix should allow espie to remove his local audio hacks in the squeak port. --- lib/libossaudio/ossaudio.c | 20 ++++++++++++++++---- lib/libossaudio/soundcard.h | 4 ++-- sys/compat/ossaudio/ossaudio.c | 26 ++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/lib/libossaudio/ossaudio.c b/lib/libossaudio/ossaudio.c index f2e967db299..bb58068c067 100644 --- a/lib/libossaudio/ossaudio.c +++ b/lib/libossaudio/ossaudio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ossaudio.c,v 1.2 1998/05/25 21:37:46 provos Exp $ */ +/* $OpenBSD: ossaudio.c,v 1.3 2001/05/24 04:21:03 aaron Exp $ */ /* $NetBSD: ossaudio.c,v 1.5 1998/03/23 00:39:18 augustss Exp $ */ /* @@ -333,15 +333,27 @@ audio_ioctl(int fd, unsigned long com, void *argp) INTARG = idat; break; case SNDCTL_DSP_GETOSPACE: + retval = ioctl(fd, AUDIO_GETINFO, &tmpinfo); + if (retval < 0) + return retval; + setblocksize(fd, &tmpinfo); + bufinfo.fragsize = tmpinfo.blocksize; + bufinfo.fragments = tmpinfo.hiwat - + (tmpinfo.play.seek + tmpinfo.blocksize - 1)/tmpinfo.blocksize; + bufinfo.fragstotal = tmpinfo.hiwat; + bufinfo.bytes = tmpinfo.hiwat * tmpinfo.blocksize - tmpinfo.play.seek; + *(struct audio_buf_info *)argp = bufinfo; + break; case SNDCTL_DSP_GETISPACE: retval = ioctl(fd, AUDIO_GETINFO, (caddr_t)&tmpinfo); if (retval < 0) return retval; setblocksize(fd, &tmpinfo); bufinfo.fragsize = tmpinfo.blocksize; - bufinfo.fragments = /* XXX */ - bufinfo.fragstotal = tmpinfo.play.buffer_size / bufinfo.fragsize; - bufinfo.bytes = tmpinfo.play.buffer_size; + bufinfo.fragments = tmpinfo.hiwat - + (tmpinfo.record.seek + tmpinfo.blocksize - 1)/tmpinfo.blocksize; + bufinfo.fragstotal = tmpinfo.hiwat; + bufinfo.bytes = tmpinfo.hiwat * tmpinfo.blocksize - tmpinfo.record.seek; *(struct audio_buf_info *)argp = bufinfo; break; case SNDCTL_DSP_NONBLOCK: diff --git a/lib/libossaudio/soundcard.h b/lib/libossaudio/soundcard.h index f5fbebee80c..746bd04a59c 100644 --- a/lib/libossaudio/soundcard.h +++ b/lib/libossaudio/soundcard.h @@ -1,4 +1,4 @@ -/* $OpenBSD: soundcard.h,v 1.4 1999/09/01 08:15:20 deraadt Exp $ */ +/* $OpenBSD: soundcard.h,v 1.5 2001/05/24 04:21:03 aaron Exp $ */ /* $NetBSD: soundcard.h,v 1.4 1997/10/29 20:23:27 augustss Exp $ */ /* @@ -48,7 +48,7 @@ #include #endif /* !_IOWR */ -#define SOUND_VERSION 0x030000 +#define SOUND_VERSION 0x030001 #define SNDCTL_DSP_RESET _IO ('P', 0) #define SNDCTL_DSP_SYNC _IO ('P', 1) diff --git a/sys/compat/ossaudio/ossaudio.c b/sys/compat/ossaudio/ossaudio.c index 873cf80a2dd..e61c0fd58eb 100644 --- a/sys/compat/ossaudio/ossaudio.c +++ b/sys/compat/ossaudio/ossaudio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ossaudio.c,v 1.4 2001/04/11 01:30:24 aaron Exp $ */ +/* $OpenBSD: ossaudio.c,v 1.5 2001/05/24 04:21:02 aaron Exp $ */ /* $NetBSD: ossaudio.c,v 1.23 1997/10/19 07:41:52 augustss Exp $ */ /* @@ -386,15 +386,33 @@ oss_ioctl_audio(p, uap, retval) return error; break; case OSS_SNDCTL_DSP_GETOSPACE: + error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, p); + if (error) + return error; + setblocksize(fp, &tmpinfo, p); + bufinfo.fragsize = tmpinfo.blocksize; + bufinfo.fragments = tmpinfo.hiwat - + (tmpinfo.play.seek + tmpinfo.blocksize - 1) / + tmpinfo.blocksize; + bufinfo.fragstotal = tmpinfo.hiwat; + bufinfo.bytes = + tmpinfo.hiwat * tmpinfo.blocksize - tmpinfo.play.seek; + error = copyout(&bufinfo, SCARG(uap, data), sizeof bufinfo); + if (error) + return error; + break; case OSS_SNDCTL_DSP_GETISPACE: error = ioctlf(fp, AUDIO_GETINFO, (caddr_t)&tmpinfo, p); if (error) return error; setblocksize(fp, &tmpinfo, p); bufinfo.fragsize = tmpinfo.blocksize; - bufinfo.fragments = /* XXX */ - bufinfo.fragstotal = tmpinfo.play.buffer_size / bufinfo.fragsize; - bufinfo.bytes = tmpinfo.play.buffer_size; + bufinfo.fragments = tmpinfo.hiwat - + (tmpinfo.record.seek + tmpinfo.blocksize - 1) / + tmpinfo.blocksize; + bufinfo.fragstotal = tmpinfo.hiwat; + bufinfo.bytes = + tmpinfo.hiwat * tmpinfo.blocksize - tmpinfo.record.seek; DPRINTF(("oss_sys_ioctl: SNDCTL_DSP_GETxSPACE = %d %d %d %d\n", bufinfo.fragsize, bufinfo.fragments, bufinfo.fragstotal, bufinfo.bytes)); -- cgit v1.2.3