summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Campbell <aaron@cvs.openbsd.org>2001-05-24 04:21:04 +0000
committerAaron Campbell <aaron@cvs.openbsd.org>2001-05-24 04:21:04 +0000
commitbc4e57d7da104517213d33ff2667a9df6067cc7e (patch)
tree5ab157ea155c2daf824669190c8b828e3e3d176b
parent69f4177de66487b35e389c85a72f83874c873f36 (diff)
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.
-rw-r--r--lib/libossaudio/ossaudio.c20
-rw-r--r--lib/libossaudio/soundcard.h4
-rw-r--r--sys/compat/ossaudio/ossaudio.c26
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 <sys/ioccom.h>
#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));