I enabled using a separate thread for sounds by default. it's possible that the audio block size would be large enough that X events would be blocked for too long and timeout, returning an error. but having the sound handled in a different thread this does not happen.
imo, seems to overall work better than when it was using audio(4). please test. -- jake...@sdf.lonestar.org SDF Public Access UNIX System - http://sdf.lonestar.org Index: Makefile =================================================================== RCS file: /cvs/ports/emulators/snes9x/Makefile,v retrieving revision 1.10 diff -N -u -p Makefile --- Makefile 10 Aug 2009 06:31:09 -0000 1.10 +++ Makefile 19 Apr 2010 06:22:18 -0000 @@ -3,7 +3,7 @@ COMMENT= emulates the Super Nintendo Entertainment System DISTNAME= snes9x-1.51-src -PKGNAME= ${DISTNAME:S/-src//}p0 +PKGNAME= ${DISTNAME:S/-src//}p1 CATEGORIES= emulators games HOMEPAGE= http://www.snes9x.com/ @@ -14,7 +14,8 @@ PERMIT_PACKAGE_FTP= Yes PERMIT_DISTFILES_CDROM= No PERMIT_DISTFILES_FTP= Yes -WANTLIB+= X11 Xext Xxf86dga Xxf86vm c m pthread pthread-stubs stdc++ xcb z +WANTLIB+= X11 Xext Xxf86dga Xxf86vm c m pthread pthread-stubs sndio \ + stdc++ xcb z MASTER_SITES= http://vincent.grigorieff.free.fr/snes9x/ \ http://files.ipherswipsite.com/snes9x/ @@ -31,8 +32,8 @@ AUTOCONF_VERSION= 2.59 USE_X11= Yes USE_GMAKE= Yes CONFIGURE_STYLE=autoconf no-autoheader -CONFIGURE_ENV= OPTFLAGS="${CXXFLAGS} -I${LOCALBASE}/include/libpng" \ - LIBS="-L${LOCALBASE}/lib" +CONFIGURE_ENV= OPTFLAGS="${CXXFLAGS} -I${LOCALBASE}/include/libpng -DUSE_SNDIO" \ + LIBS="-L${LOCALBASE}/lib -lsndio" NO_REGRESS= Yes Index: patches/patch-Makefile_in =================================================================== RCS file: patches/patch-Makefile_in diff -N -u -p patches/patch-Makefile_in --- /dev/null 19 Apr 2010 00:22:18 -0000 +++ patches/patch-Makefile_in 19 Apr 2010 06:22:18 -0000 @@ -0,0 +1,12 @@ +$OpenBSD$ +--- Makefile.in.orig Thu Jan 14 18:00:24 2010 ++++ Makefile.in Thu Jan 14 18:00:42 2010 +@@ -133,7 +133,7 @@ endif + + ifdef THREAD_SOUND + CPUDEFINES += -DUSE_THREADS +-EXTRALIBS += -lpthread ++EXTRALIBS += -pthread + endif + + ifdef GLIDE Index: patches/patch-snes9x_cpp =================================================================== RCS file: patches/patch-snes9x_cpp diff -N -u -p patches/patch-snes9x_cpp --- /dev/null 19 Apr 2010 00:22:18 -0000 +++ patches/patch-snes9x_cpp 19 Apr 2010 06:22:18 -0000 @@ -0,0 +1,12 @@ +$OpenBSD$ +--- snes9x.cpp.orig Sun Apr 18 22:15:16 2010 ++++ snes9x.cpp Sun Apr 18 22:16:04 2010 +@@ -1160,7 +1160,7 @@ void S9xLoadConfigFiles(char **argv, int argc){ + Settings.InterpolatedSound = TRUE; + } + #ifdef USE_THREADS +- Settings.ThreadSound=conf.GetBool("Sound::ThreadSound", false); ++ Settings.ThreadSound=conf.GetBool("Sound::ThreadSound", true); + #endif + if(conf.Exists("Sound::AltDecode")){ + Settings.AltSampleDecode=conf.GetInt("Sound::AltDecode", 1); Index: patches/patch-soundux_h =================================================================== RCS file: /cvs/ports/emulators/snes9x/patches/patch-soundux_h,v retrieving revision 1.1 diff -N -u -p patches/patch-soundux_h --- patches/patch-soundux_h 9 Sep 2007 15:17:06 -0000 1.1 +++ patches/patch-soundux_h 19 Apr 2010 06:22:18 -0000 @@ -1,12 +1,23 @@ $OpenBSD: patch-soundux_h,v 1.1 2007/09/09 15:17:06 fgsch Exp $ ---- soundux.h.orig Thu Sep 6 13:10:15 2007 -+++ soundux.h Thu Sep 6 13:10:30 2007 -@@ -220,7 +220,7 @@ typedef struct { +--- soundux.h.orig Sat Apr 28 17:51:22 2007 ++++ soundux.h Thu Jan 14 12:02:20 2010 +@@ -206,6 +206,9 @@ enum + #define ENV_MAX 0x7FF + #define ENV_SHIFT 4 + ++#ifdef USE_SNDIO ++#include <sndio.h> ++#endif + #ifdef __sgi + #include <audio.h> + #endif /* __sgi */ +@@ -220,6 +223,9 @@ typedef struct { int stereo; // stereo or mono bool8 sixteen_bit; // 16bit or 8bit sample bool8 encoded; // ** port specific --#ifdef __sun -+#if defined(__sun) || defined(__OpenBSD__) ++#ifdef USE_SNDIO ++ struct sio_hdl *hdl; // ** port specific ++#endif + #ifdef __sun int last_eof; // ** port specific #endif - #ifdef __sgi Index: patches/patch-unix_unix_cpp =================================================================== RCS file: /cvs/ports/emulators/snes9x/patches/patch-unix_unix_cpp,v retrieving revision 1.1 diff -N -u -p patches/patch-unix_unix_cpp --- patches/patch-unix_unix_cpp 9 Sep 2007 15:17:06 -0000 1.1 +++ patches/patch-unix_unix_cpp 19 Apr 2010 06:22:18 -0000 @@ -1,27 +1,19 @@ $OpenBSD: patch-unix_unix_cpp,v 1.1 2007/09/09 15:17:06 fgsch Exp $ ---- unix/unix.cpp.orig Sun Apr 29 01:51:08 2007 -+++ unix/unix.cpp Thu Sep 6 14:59:46 2007 -@@ -210,6 +210,10 @@ pthread_mutex_t mutex; - #endif - #endif +--- unix/unix.cpp.orig Sat Apr 28 17:51:08 2007 ++++ unix/unix.cpp Sun Apr 18 23:21:09 2010 +@@ -185,9 +185,11 @@ + #include <ctype.h> + #include <dirent.h> -+#if !defined(NOSOUND) && defined(__OpenBSD__) -+#include <sys/audioio.h> -+#endif -+ - //Breaks sol9 and probably others. - //#if defined(__sun) && defined(__GNUC__) - //typedef void (*SIG_PF)(); -@@ -264,7 +268,7 @@ void ReadJoysticks (); - #define CONFIGURABLE_SOUND_DEVICE - char *sound_device = "/dev/dsp"; ++#ifndef USE_SNDIO + #ifdef HAVE_SYS_IOCTL_H + # include <sys/ioctl.h> #endif --#if !defined(NOSOUND) && defined (__sun) -+#if !defined(NOSOUND) && (defined(__sun) || defined(__OpenBSD__)) - #define CONFIGURABLE_SOUND_DEVICE - char *sound_device = "/dev/audio"; - #endif -@@ -285,7 +289,7 @@ const char *rom_dir="." SLASH_STR "roms"; ++#endif + + #ifdef USE_THREADS + #include <pthread.h> +@@ -285,7 +287,7 @@ const char *rom_dir="." SLASH_STR "roms"; const char *inc_format="%03d"; //FIXME: I see no reason not to configureenable this for all Unixen @@ -30,72 +22,108 @@ $OpenBSD: patch-unix_unix_cpp,v 1.1 2007/09/09 15:17:0 static void sigbrkhandler(int) { CPU.Flags |= DEBUG_MODE_FLAG; -@@ -1653,10 +1657,14 @@ void S9xUnixProcessSound (void) +@@ -1846,8 +1848,70 @@ bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int } #endif --#if !defined(NOSOUND) && defined(__sun) -+#if !defined(NOSOUND) && (defined(__sun) || defined(__OpenBSD__)) - static int Rates[8] = - { -+#if defined(__sun) - 0, 8000, 11025, 16000, 22050, 32000, 37800, 44100 -+#else ++#if !defined(NOSOUND) && defined(USE_SNDIO) ++static int Rates[8] = ++{ + 0, 8000, 11025, 16000, 22050, 32000, 44100, 48000 -+#endif - }; ++}; - static int BufferSizes [8] = -@@ -1712,6 +1720,7 @@ bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int - so.playback_rate, so.buffer_size, so.sixteen_bit ? "yes" : "no", - so.stereo ? "yes" : "no", so.encoded ? "yes" : "no"); - -+ S9xSetPlaybackRate (so.playback_rate); - return (TRUE); - } - #endif -@@ -1847,7 +1856,7 @@ bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int - #endif - - -#if !defined(NOSOUND) && (defined (__linux) || defined (__sun)) -+#if !defined(NOSOUND) && (defined (__linux) || defined (__sun) || defined(__OpenBSD__)) ++static int BufferSizes[8] = ++{ ++ 0, 256, 256, 256, 512, 512, 1024, 1024 ++}; ++ ++bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size) ++{ ++ /* sndio version */ ++ struct sio_par par; ++ long bs; ++ ++ if ((so.hdl = sio_open(NULL, SIO_PLAY, 0)) == NULL) { ++ printf("failed to open sndio device\n"); ++ return (FALSE); ++ } ++ ++ sio_initpar(&par); ++ par.rate = Rates[mode & 7]; ++ par.pchan = stereo ? 2 : 1; ++ par.bits = 16; ++ par.sig = 1; ++ par.le = SIO_LE_NATIVE; ++ par.round = BufferSizes[mode & 7]; ++ par.appbufsz = par.round * 3; ++ ++ if (!sio_setpar(so.hdl, &par) || !sio_getpar(so.hdl, &par)) { ++ printf("failed setting audio parameters\n"); ++ return (FALSE); ++ } ++ ++ if ((par.pchan != 1 && par.pchan != 2) || (par.bits != 8 && par.bits != 16)) { ++ printf("failed to match supported audio channels and/or bit-depth\n"); ++ return (FALSE); ++ } ++ so.playback_rate = par.rate; ++ so.sixteen_bit = par.bits == 16; ++ so.stereo = par.pchan == 2 ? 1 : 0; ++ bs = par.round * par.pchan * par.bps; ++ so.buffer_size = 1 << log2(bs); ++ if (so.buffer_size > MAX_BUFFER_SIZE) ++ so.buffer_size = MAX_BUFFER_SIZE; ++ ++ S9xSetPlaybackRate(so.playback_rate); ++ ++ if (!sio_start(so.hdl)) { ++ printf("failed to start sndio\n"); ++ return (FALSE); ++ } ++ ++ printf("Sound Device: Rate: %d, Buffer size: %d, 16-bit: %s, Stereo: %s\n", ++ so.playback_rate, so.buffer_size, so.sixteen_bit ? "yes" : "no", ++ so.stereo ? "yes" : "no"); ++ ++ return TRUE; ++} ++#endif ++ ++#if !defined(NOSOUND) && (defined (__linux) || defined (__sun) || defined(USE_SNDIO)) void S9xUnixProcessSound (void) { } -@@ -1890,7 +1899,7 @@ void *S9xProcessSound (void *) +@@ -1890,7 +1954,7 @@ void *S9xProcessSound (void *) } #endif -#if !defined(NOSOUND) && (defined (__linux) || defined (__sun)) -+#if !defined(NOSOUND) && (defined (__linux) || defined (__sun) || defined(__OpenBSD__)) ++#if !defined(NOSOUND) && (defined (__linux) || defined (__sun) || defined(USE_SNDIO)) void S9xGenerateSound () { /* Linux and Sun versions */ -@@ -2009,7 +2018,7 @@ void *S9xProcessSound (void *) - #endif +@@ -2102,7 +2166,11 @@ void *S9xProcessSound (void *) + } + if(I == 0) break; - #endif --#ifdef __sun -+#if defined(__sun) || defined(__OpenBSD__) - audio_info_t audio; - if (!Settings.ThreadSound) - { -@@ -2121,7 +2130,7 @@ void *S9xProcessSound (void *) - } while (Settings.ThreadSound); - #endif - --#ifdef __sun -+#if defined(__sun) || defined(__OpenBSD__) - if (!Settings.ThreadSound) - write (so.sound_fd, NULL, 0); - #endif -@@ -2130,7 +2139,7 @@ void *S9xProcessSound (void *) - } - #endif - --#if !defined(NOSOUND) && defined(__sun) -+#if !defined(NOSOUND) && (defined(__sun) || defined(__OpenBSD__)) - uint8 int2ulaw(int ch) - { - int mask; ++#ifdef USE_SNDIO ++ I = sio_write (so.hdl, (char *) Buf + byte_offset, I); ++#else + I = write (so.sound_fd, (char *) Buf + byte_offset, I); ++#endif + if (I > 0) + { + bytes_to_write -= I; +@@ -2110,7 +2178,11 @@ void *S9xProcessSound (void *) + byte_offset &= SOUND_BUFFER_SIZE_MASK; /* wrap */ + } + /* give up if an unrecoverable error happened */ ++#ifdef USE_SNDIO ++ if(I == 0 && sio_eof(so.hdl)) break; ++#else + if(I < 0 && errno != EINTR) break; ++#endif + } + /* All data sent. */ + } Index: pkg/PLIST =================================================================== RCS file: /cvs/ports/emulators/snes9x/pkg/PLIST,v retrieving revision 1.3 diff -N -u -p pkg/PLIST --- pkg/PLIST 9 Sep 2007 15:17:06 -0000 1.3 +++ pkg/PLIST 19 Apr 2010 06:22:18 -0000 @@ -1,5 +1,5 @@ @comment $OpenBSD: PLIST,v 1.3 2007/09/09 15:17:06 fgsch Exp $ -bin/snes9x +...@bin bin/snes9x share/doc/snes9x/ share/doc/snes9x/changes.txt share/doc/snes9x/control-inputs.txt