tested with the example programs in audio/freealut and with games/warzone2100. patches for those following shortly.
-- [email protected] SDF Public Access UNIX System - http://sdf.lonestar.org Index: Makefile =================================================================== RCS file: /cvs/ports/audio/openal/Makefile,v retrieving revision 1.11 diff -N -u -p Makefile --- Makefile 14 Oct 2009 14:27:34 -0000 1.11 +++ Makefile 11 Dec 2009 09:16:06 -0000 @@ -3,7 +3,7 @@ COMMENT= cross-platform 3D audio API DISTNAME= openal-0.0.8 -PKGNAME= ${DISTNAME}p3 +PKGNAME= ${DISTNAME}p4 CATEGORIES= audio SHARED_LIBS += openal 1.0 # .0.0 @@ -14,7 +14,7 @@ PERMIT_PACKAGE_CDROM= Yes PERMIT_PACKAGE_FTP= Yes PERMIT_DISTFILES_CDROM= Yes PERMIT_DISTFILES_FTP= Yes -WANTLIB= m +WANTLIB= m sndio MASTER_SITES= http://openbsd.dead-parrot.de/distfiles/ Index: patches/patch-admin_pkgconfig_openal-config_in =================================================================== RCS file: /cvs/ports/audio/openal/patches/patch-admin_pkgconfig_openal-config_in,v retrieving revision 1.1 diff -N -u -p patches/patch-admin_pkgconfig_openal-config_in --- patches/patch-admin_pkgconfig_openal-config_in 10 Oct 2009 22:51:48 -0000 1.1 +++ /dev/null 11 Dec 2009 07:35:14 -0000 @@ -1,15 +0,0 @@ -$OpenBSD: patch-admin_pkgconfig_openal-config_in,v 1.1 2009/10/10 22:51:48 sthen Exp $ ---- admin/pkgconfig/openal-config.in.orig Fri Oct 9 22:54:00 2009 -+++ admin/pkgconfig/openal-config.in Fri Oct 9 22:54:16 2009 -@@ -9,9 +9,9 @@ PACKAGE_VERSION="@PACKAGE_VERSION@" - # PTHREAD_CFLAGS="@PTHREAD_CFLAGS@" - # PTHREAD_LIBS="@PTHREAD_LIBS@" - --openal_dynamic_ldflags="-lopenal" -+openal_dynamic_ldflags="-lopenal -lossaudio" - # TODO: configure should provide the following... --openal_static_ldflags="-lopenal" -+openal_static_ldflags="-lopenal -lossaudio" - - prefix_set=no - echo_prefix=no Index: patches/patch-admin_pkgconfig_openal_pc_in =================================================================== RCS file: /cvs/ports/audio/openal/patches/patch-admin_pkgconfig_openal_pc_in,v retrieving revision 1.2 diff -N -u -p patches/patch-admin_pkgconfig_openal_pc_in --- patches/patch-admin_pkgconfig_openal_pc_in 10 Oct 2009 22:51:48 -0000 1.2 +++ patches/patch-admin_pkgconfig_openal_pc_in 11 Dec 2009 09:16:06 -0000 @@ -1,14 +1,12 @@ $OpenBSD: patch-admin_pkgconfig_openal_pc_in,v 1.2 2009/10/10 22:51:48 sthen Exp $ ---- admin/pkgconfig/openal.pc.in.orig Sat Feb 11 04:36:55 2006 -+++ admin/pkgconfig/openal.pc.in Fri Oct 9 20:29:07 2009 -@@ -5,8 +5,8 @@ included...@includedir@ +--- admin/pkgconfig/openal.pc.in.orig Sat Feb 11 01:36:55 2006 ++++ admin/pkgconfig/openal.pc.in Thu Dec 10 12:48:42 2009 +@@ -5,7 +5,7 @@ included...@includedir@ Name: OpenAL Description: OpenAL is a cross-platform 3D audio API. -Requires: @requirements@ +Requires: Version: @PACKAGE_VERSION@ --Libs: -L${libdir} -lopenal -+Libs: -L${libdir} -lopenal -lossaudio + Libs: -L${libdir} -lopenal Cflags: -I${includedir} - Index: patches/patch-src_Makefile_in =================================================================== RCS file: patches/patch-src_Makefile_in diff -N -u -p patches/patch-src_Makefile_in --- /dev/null 11 Dec 2009 02:16:06 -0000 +++ patches/patch-src_Makefile_in 11 Dec 2009 09:16:06 -0000 @@ -0,0 +1,12 @@ +$OpenBSD$ +--- src/Makefile.in.orig Thu Dec 10 15:19:02 2009 ++++ src/Makefile.in Thu Dec 10 15:21:15 2009 +@@ -465,7 +465,7 @@ libopenal_la_CFLAGS = $(WARNINGCFLAGS) $(OPTIMIZATIONC + libopenal_la_LDFLAGS = -no-undefined $(PROFILINGLDFLAGS) + + # We use sin and friends, so we might need -lm, autoconf takes care of this. +-libopenal_la_LIBADD = $(LIBM) $(asm_ldadd) ++libopenal_la_LIBADD = $(LIBM) $(asm_ldadd) -lsndio + SUBDIRS = $(X86_SUBDIR) + all: all-recursive + Index: patches/patch-src_backends_alc_backend_bsd_c =================================================================== RCS file: /cvs/ports/audio/openal/patches/patch-src_backends_alc_backend_bsd_c,v retrieving revision 1.1 diff -N -u -p patches/patch-src_backends_alc_backend_bsd_c --- patches/patch-src_backends_alc_backend_bsd_c 30 Oct 2006 23:31:37 -0000 1.1 +++ patches/patch-src_backends_alc_backend_bsd_c 11 Dec 2009 09:16:06 -0000 @@ -1,51 +1,496 @@ $OpenBSD: patch-src_backends_alc_backend_bsd_c,v 1.1 2006/10/30 23:31:37 steven Exp $ ---- src/backends/alc_backend_bsd.c.orig Thu Jan 5 16:11:20 2006 -+++ src/backends/alc_backend_bsd.c Thu Oct 26 21:51:24 2006 -@@ -10,14 +10,16 @@ - #include "al_siteconfig.h" +--- src/backends/alc_backend_bsd.c.orig Thu Jan 5 07:11:20 2006 ++++ src/backends/alc_backend_bsd.c Thu Dec 10 15:15:51 2009 +@@ -7,22 +7,29 @@ + * bsd. + * + */ +-#include "al_siteconfig.h" - #include <AL/al.h> -+#include <AL/alext.h> +-#include <AL/al.h> ++#include <sys/types.h> ++#include <sys/ioctl.h> ++#include <sys/audioio.h> ++#include <sys/select.h> ++#include <sys/stat.h> ++#include <sys/time.h> ++#include <sys/mman.h> ++ #include <assert.h> #include <fcntl.h> -#include <sys/soundcard.h> -+#include <soundcard.h> ++#include <poll.h> ++#include <sndio.h> #include <stdio.h> #include <stdlib.h> #include <string.h> - #include <sys/ioctl.h> - #include <sys/mman.h> -+#include <sys/select.h> - #include <sys/stat.h> - #include <sys/time.h> - #include <sys/types.h> -@@ -112,7 +114,7 @@ static int AL2BSDFMT(int fmt) - * - */ +-#include <sys/ioctl.h> +-#include <sys/mman.h> +-#include <sys/stat.h> +-#include <sys/time.h> +-#include <sys/types.h> + #include <unistd.h> + ++#include "al_siteconfig.h" ++ ++#include <AL/al.h> ++#include <AL/alext.h> ++ + #include "backends/alc_backend.h" + + /* is this right? */ +@@ -32,62 +39,63 @@ + #include "al_debug.h" + #include "alc/alc_context.h" + +-#ifdef WORDS_BIGENDIAN +-#define AFMT_S16 AFMT_S16_BE +-#else +-#define AFMT_S16 AFMT_S16_LE +-#endif /* WORDS_BIGENDIAN */ + + static int grab_mixerfd(void); + static int alcChannel_to_dsp_channel(ALuint alcc); + +-/* /dev/dsp variables */ +-static fd_set dsp_fd_set; +-static int dsp_fd = -1; /* /dev/dsp file descriptor */ ++enum { ++ BSD_MIX_MASTER = 0, ++ BSD_MIX_CD, ++ BSD_MIX_DAC ++}; ++ ++/* variables */ ++struct pollfd pfd; ++struct sio_par par; + static int mixer_fd = -1; /* /dev/mixer file descriptor */ + + /* convert the format channel from /dev/dsp to openal format */ +-static int BSD2ALFMT(int fmt, int channels) { +- switch(fmt) { +- case AFMT_U8: +- switch(channels) ++static int BSD2ALFMT(struct sio_par *par) { ++ if (par->bits == 8 && par->sig == 0) { ++ switch(par->pchan) + { + case 1: return AL_FORMAT_MONO8; + case 2: return AL_FORMAT_STEREO8; + default: return -1; + } +- break; +- case AFMT_S16: +- switch(channels) ++ } else if (par->bits == 16 && par->sig == 1) { ++ switch(par->pchan) + { + case 1: return AL_FORMAT_MONO16; + case 2: return AL_FORMAT_STEREO16; + default: return -1; + } +- break; +- default: ++ } else { + #ifdef DEBUG_MAXIMUS + fprintf(stderr, "unsupported dsp format\n"); + #endif + return -1; +- break; +- } ++ } + + return -1; + } + + /* convert the format channel from openal to /dev/dsp format */ +-static int AL2BSDFMT(int fmt) ++static int AL2BSDFMT(int fmt, struct sio_par *par) + { + switch(fmt) + { + case AL_FORMAT_MONO16: + case AL_FORMAT_STEREO16: +- return AFMT_S16; ++ par->bits = 16; ++ par->sig = 1; ++ return 1; + break; + case AL_FORMAT_MONO8: + case AL_FORMAT_STEREO8: +- return AFMT_U8; ++ par->bits = 16; ++ par->sig = 1; ++ return 1; + break; + default: + #ifdef DEBUG_MAXIMUS +@@ -99,57 +107,30 @@ static int AL2BSDFMT(int fmt) + return -1; + } + +-/* +- * +- * Format of divisor is bit field where: +- * +- * +- * MSHW LSHW +- * [ some big value | x ] +- * +- * where x is translated into 2^x, and used as the +- * dma buffer size. +- * +- */ ++ static void *grab_write_native(void) { - const char *dsppath = "/dev/dsp"; -+ const char *dsppath = "/dev/audio"; - int divisor = _alSpot(_AL_DEF_BUFSIZ) | (2<<16); +- int divisor = _alSpot(_AL_DEF_BUFSIZ) | (2<<16); ++ struct sio_hdl *hdl; - dsp_fd = open(dsppath, O_WRONLY | O_NONBLOCK); -@@ -146,9 +148,11 @@ int grab_mixerfd(void) { - mixer_fd = open("/dev/mixer", O_WRONLY | O_NONBLOCK); +- dsp_fd = open(dsppath, O_WRONLY | O_NONBLOCK); ++ hdl = sio_open(NULL, SIO_PLAY, 0); - if(mixer_fd > 0) { -+#if 0 - if(fcntl(mixer_fd, F_SETFL, ~O_NONBLOCK) == -1) { - perror("fcntl"); - } -+#endif +- if(dsp_fd < 0) { +- perror("open /dev/dsp"); ++ if (hdl == NULL) { ++ fprintf(stderr, "opening sndio device failed"); + return NULL; + } +- if(fcntl(dsp_fd, F_SETFL, ~O_NONBLOCK) == -1) { +- perror("fcntl"); +- } +- +- if(ioctl(dsp_fd, SNDCTL_DSP_SETFRAGMENT, &divisor) < 0) { +- perror("ioctl SETFRAGMENT"); +- } +- +- FD_ZERO(&dsp_fd_set); +- FD_SET(dsp_fd, &dsp_fd_set); +- + /* now get mixer_fd */ + mixer_fd = grab_mixerfd(); + + #ifdef DEBUG +- fprintf(stderr, "Got /dev/dsp\n"); ++ fprintf(stderr, "Got audio device\n"); + #endif +- return &dsp_fd; ++ return hdl; + } + + int grab_mixerfd(void) { +- mixer_fd = open("/dev/mixer", O_WRONLY | O_NONBLOCK); ++ mixer_fd = open("/dev/mixer", O_WRONLY); + +- if(mixer_fd > 0) { +- if(fcntl(mixer_fd, F_SETFL, ~O_NONBLOCK) == -1) { +- perror("fcntl"); +- } +- ++ if(mixer_fd >= 0) { return mixer_fd; } else { -@@ -210,7 +214,7 @@ void release_native(void *handle) { + perror("open /dev/mixer"); +@@ -159,19 +140,18 @@ int grab_mixerfd(void) { + } - handle_fd = *(int *) handle; + void native_blitbuffer(void *handle, void *dataptr, int bytes_to_write) { +- struct timeval tv = { 1, 0 }; /* wait 1 sec max */ + int iterator = 0; + int err; +- int fd; ++ int nfds; -- if(ioctl(handle_fd, SNDCTL_DSP_RESET) < 0) { -+ if(ioctl(handle_fd, SNDCTL_DSP_RESET, NULL) < 0) { + if(handle == NULL) { + return; + } + +- fd = *(int *) handle; ++ nfds = sio_pollfd(handle, &pfd, POLLOUT); + +- for(iterator = bytes_to_write; iterator > 0; ) { +- if(select(fd + 1, NULL, &dsp_fd_set, NULL, &tv) == 0) { ++ for (iterator = bytes_to_write; iterator > 0; ) { ++ if (poll(&pfd, nfds, 1000) == 0) { + /* timeout occured, don't try and write */ #ifdef DEBUG_MAXIMUS - fprintf(stderr, "Couldn't reset dsp\n"); + fprintf(stderr, "native_blitbuffer: timeout occured\n"); +@@ -179,18 +159,15 @@ void native_blitbuffer(void *handle, void *dataptr, in + return; + } + +- FD_ZERO(&dsp_fd_set); +- FD_SET(fd, &dsp_fd_set); +- + assert(iterator > 0); + assert(iterator <= bytes_to_write); + +- err = write(fd, ++ err = sio_write(handle, + (char *) dataptr + bytes_to_write - iterator, + iterator); +- if(err < 0) { ++ if (err == 0) { + #ifdef DEBUG_MAXIMUS +- perror("write"); ++ fprintf(stderr, "sio_write returned 0"); #endif + return; + } +@@ -202,111 +179,125 @@ void native_blitbuffer(void *handle, void *dataptr, in + } + + void release_native(void *handle) { +- int handle_fd; + + if(handle == NULL) { + return; + } + +- handle_fd = *(int *) handle; +- +- if(ioctl(handle_fd, SNDCTL_DSP_RESET) < 0) { +-#ifdef DEBUG_MAXIMUS +- fprintf(stderr, "Couldn't reset dsp\n"); +-#endif +- } +- +- ioctl(handle_fd, SNDCTL_DSP_SYNC, NULL); +- if((close(handle_fd) < 0) || (close(mixer_fd) < 0)) { ++ sio_close(handle); ++ if (close(mixer_fd) < 0) { + return; + } + +- *(int *) handle = -1; +- mixer_fd = -1; ++ handle = NULL; ++ mixer_fd = -1; + + return; + } + + ALfloat get_nativechannel(UNUSED(void *handle), ALuint channel) { +- int retval = 0; ++ mixer_ctrl_t ctrl; ++ int retval; + + channel = alcChannel_to_dsp_channel(channel); + +- if(ioctl(mixer_fd, MIXER_READ(channel), &retval) < 0) { ++ ctrl.dev = channel; ++ ctrl.type = AUDIO_MIXER_VALUE; ++ ctrl.un.value.num_channels = 2; ++ ++ if (ioctl(mixer_fd, AUDIO_MIXER_READ, &ctrl) < 0) { + return -1; + } + +- return (retval >> 8) / 100.0; ++ retval = (ctrl.un.value.level[0] + ctrl.un.value.level[1]) / 2; ++ ++ return retval / 255.0; + } + + +-/* +- * Okay: +- * +- * Set audio channel expects an integer, in the range of +- * 0 - 100. But wait! It expects the integer to be +- * partitioned into a 16bit empty, L/R channel pair (high bits left, +- * low bits right), each 8 bit pair in the range 0 - 100. +- * +- * Kludgey, and obviously not the right way to do this +- */ + int set_nativechannel(UNUSED(void *handle), ALuint channel, ALfloat volume) { +- int unnormalizedvolume; ++ mixer_ctrl_t ctrl; + +- unnormalizedvolume = volume * 100; +- unnormalizedvolume <<= 8; +- unnormalizedvolume += (volume * 100); +- + channel = alcChannel_to_dsp_channel(channel); + +- if(ioctl(mixer_fd, MIXER_WRITE(channel), &unnormalizedvolume) < 0) { ++ ctrl.dev = channel; ++ ctrl.type = AUDIO_MIXER_VALUE; ++ ctrl.un.value.num_channels = 2; ++ ctrl.un.value.level[0] = ctrl.un.value.level[1] = volume * 255; ++ ++ if (ioctl(mixer_fd, AUDIO_MIXER_WRITE, &ctrl) < 0) { + return -1; + } + + return 0; + } + +-/* convert the mixer channel from ALC to /dev/mixer format */ +-static int alcChannel_to_dsp_channel(ALuint alcc) { +- switch(alcc) { +- case ALC_CHAN_MAIN_LOKI: return SOUND_MIXER_VOLUME; +- case ALC_CHAN_CD_LOKI: return SOUND_MIXER_CD; +- case ALC_CHAN_PCM_LOKI: return SOUND_MIXER_PCM; +- default: return -1; +- } + +- return -1; +-} ++int find_mixer_dev(int dev) { ++ mixer_devinfo_t devi; ++ int inputs, outputs; + +-void pause_nativedevice(void *handle) { +- int fd; ++ inputs = outputs = -1; + +- if(handle == NULL) { +- return; ++ devi.index = 0; ++ while (ioctl(mixer_fd, AUDIO_MIXER_DEVINFO, &devi) != -1) { ++ if (devi.type == AUDIO_MIXER_CLASS) { ++ if (strncmp(devi.label.name, AudioCinputs, MAX_AUDIO_DEV_LEN) == 0) ++ inputs = devi.index; ++ else if (strncmp(devi.label.name, AudioCoutputs, MAX_AUDIO_DEV_LEN) == 0) ++ outputs = devi.index; ++ } ++ if (inputs != -1 && outputs != -1) ++ break; ++ devi.index++; + } + +- fd = *(int *) handle; +- +- if(ioctl(fd, SNDCTL_DSP_POST, 0) == -1) { +- perror("ioctl"); ++ while (ioctl(mixer_fd, AUDIO_MIXER_DEVINFO, &devi) != -1) { ++ if (devi.type == AUDIO_MIXER_VALUE) { ++ switch (dev) { ++ case BSD_MIX_MASTER: ++ if (devi.mixer_class == outputs && ++ strncmp(devi.label.name, AudioNmaster, MAX_AUDIO_DEV_LEN) == 0) ++ return devi.index; ++ break; ++ case BSD_MIX_CD: ++ if (devi.mixer_class == inputs && ++ strncmp(devi.label.name, AudioNcd, MAX_AUDIO_DEV_LEN) == 0) ++ return devi.index; ++ break; ++ case BSD_MIX_DAC: ++ if (devi.mixer_class == inputs && ++ strncmp(devi.label.name, AudioNdac, MAX_AUDIO_DEV_LEN) == 0) ++ return devi.index; ++ break; ++ default: ++ break; ++ } ++ } + } +- +- return; ++ return -1; + } + +-void resume_nativedevice(void *handle) { +- int fd; + +- if(handle == NULL) { +- return; ++/* convert the mixer channel from ALC to /dev/mixer format */ ++static int alcChannel_to_dsp_channel(ALuint alcc) { ++ switch(alcc) { ++ case ALC_CHAN_MAIN_LOKI: return find_mixer_dev(BSD_MIX_MASTER); ++ case ALC_CHAN_CD_LOKI: return find_mixer_dev(BSD_MIX_CD); ++ case ALC_CHAN_PCM_LOKI: return find_mixer_dev(BSD_MIX_DAC); ++ default: return -1; + } + +- fd = *(int *) handle; ++ return -1; ++} + +- if(ioctl(fd, SNDCTL_DSP_POST, 0) == -1) { +- perror("ioctl"); +- } ++void pause_nativedevice(UNUSED(void *handle)) { ++ /* nothing to do here */ ++ return; ++} + ++void resume_nativedevice(UNUSED(void *handle)) { ++ /* nothing to do here */ + return; + } + +@@ -317,52 +308,41 @@ ALsizei capture_nativedevice(UNUSED(void *handle), + return 0; + } + +-static ALboolean set_write_native(UNUSED(void *handle), +- UNUSED(unsigned int *bufsiz), ++static ALboolean set_write_native(void *handle, ++ unsigned int *bufsiz, + ALenum *fmt, + unsigned int *speed) { ++ + ALuint channels = _alGetChannelsFromFormat(*fmt); + +- if(dsp_fd < 0) { ++ if (handle == NULL) { + return AL_FALSE; + } + +- *fmt = AL2BSDFMT(*fmt); ++ sio_initpar(&par); + +- /* reset card defaults */ +- if(ioctl(dsp_fd, SNDCTL_DSP_RESET, NULL) < 0) { +-#ifdef DEBUG_MAXIMUS +- perror("set_devsp reset ioctl"); +-#endif ++ if (AL2BSDFMT(*fmt, &par) < 0) { ++ fprintf(stderr, "AL2BSDFMT failed\n"); + return AL_FALSE; + } ++ par.rate = *speed; ++ par.pchan = channels; + +- if(ioctl(dsp_fd, SNDCTL_DSP_SPEED, speed) < 0) { +-#ifdef DEBUG_MAXIMUS +- fprintf(stderr, "speed %d\n", *speed); +- perror("set_devsp speed ioctl"); +-#endif +- return AL_FALSE; +- } ++ par.appbufsz = *bufsiz / SIO_BPS(par.bits); + +- if(ioctl(dsp_fd, SNDCTL_DSP_SETFMT, fmt) < 0) { +-#ifdef DEBUG_MAXIMUS +- fprintf(stderr, "fmt %d\n", *fmt); +- perror("set_devsp format ioctl"); +-#endif ++ if (!sio_setpar(handle, &par) || !sio_getpar(handle, &par)) { ++ fprintf(stderr, "could not set audio parameters\n"); + return AL_FALSE; + } + +- if(ioctl(dsp_fd, SOUND_PCM_WRITE_CHANNELS, &channels)) { +-#ifdef DEBUG_MAXIMUS +- fprintf(stderr, "channels %d\n", channels); +- perror("set_devsp channels ioctl"); +-#endif ++ if (!sio_start(handle)) { ++ fprintf(stderr, "could not start audio\n"); + return AL_FALSE; + } + +- +- *fmt = BSD2ALFMT(*fmt, channels); ++ *fmt = BSD2ALFMT(&par); ++ *speed = par.rate; ++ *bufsiz = par.appbufsz * par.bps; + + return AL_TRUE; + }
