Added native OpenBSD audio driver (thanks vedge!)
authorSam Lantinga <slouken@lokigames.com>
Sat, 26 May 2001 16:58:37 +0000
changeset 373ad7157c6cfa
parent 36 13ee9f4834ea
child 38 80139f9b90d8
Added native OpenBSD audio driver (thanks vedge!)
README.OpenBSD
configure.in
docs.html
src/audio/Makefile.am
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/openbsd/Makefile.am
src/audio/openbsd/SDL_openbsdaudio.c
src/audio/openbsd/SDL_openbsdaudio.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/README.OpenBSD	Sat May 26 16:58:37 2001 +0000
     1.3 @@ -0,0 +1,81 @@
     1.4 +=============================================================
     1.5 +Using the Simple DirectMedia Layer with OpenBSD 2.9 and later
     1.6 +=============================================================
     1.7 +
     1.8 +Author: 
     1.9 +Peter Valchev <pvalchev@openbsd.org>
    1.10 +  
    1.11 +=======
    1.12 +Install 
    1.13 +=======
    1.14 +There is an OpenBSD port for SDL and various other tools.  Using
    1.15 +this port is recommended, since it contains all the needed patches
    1.16 +and configure arguments nicely organized in several FLAVORS you
    1.17 +can pick from.  If you're unfamiliar with the OpenBSD ports system
    1.18 +please visit:
    1.19 +http://www.openbsd.org/ports.html
    1.20 +http://www.openbsd.org/anoncvs.html
    1.21 +
    1.22 +You should have a precompiled binary package on your OpenBSD 2.9
    1.23 +or later CD-ROM, which you can easily add with pkg_add(1).
    1.24 +
    1.25 +If for whatever reason you're unable to take the advantage of the
    1.26 +created port, or you want to stick with the newest fresh SDL from
    1.27 +the current CVS repository, here are some hints of what has left
    1.28 +unresolved and needs to be disabled/changed.
    1.29 +
    1.30 +To build SDL with OSS + esound:
    1.31 +
    1.32 +1. ./configure --disable-joystick \
    1.33 +	--disable-pthread-sem \
    1.34 +	--disable-nasm \
    1.35 +	--enable-esd \
    1.36 +	--enable-oss \
    1.37 +	--disable-arts \
    1.38 +	--disable-video-opengl
    1.39 +
    1.40 +OR
    1.41 +
    1.42 +To build SDL with native audio + esound (remove --disable-esd otherwise):
    1.43 +1. ./configure --disable-joystick \
    1.44 +	--disable-pthread-sem \
    1.45 +	--disable-nasm \
    1.46 +	--enable-openbsdaudio \
    1.47 +	--enable-esd \
    1.48 +	--disable-arts \
    1.49 +	--disable-video-opengl
    1.50 +
    1.51 +If you need arts or GL, omit the responding --disable lines.  In the
    1.52 +port, they're disabled by default, you need to specify flavors to
    1.53 +make use of them.
    1.54 +
    1.55 +2. gmake    # Yeah, GNU make is required, install the package 
    1.56 +3. sudo gmake install
    1.57 +
    1.58 +=========
    1.59 +Todo List 
    1.60 +=========
    1.61 +
    1.62 +Feedback is always welcome with anything you may find useful and
    1.63 +you can suggest.
    1.64 +For now, the following things have to be worked on:
    1.65 +
    1.66 +1. The native audio should be widely tested and will eventually
    1.67 +become the default.  At that moment I have not received any 
    1.68 +feedback which should explain its current condition.
    1.69 +
    1.70 +2. There are occurences of dynamic loading of drivers in the OpenGL
    1.71 +code section, and our a.out architectures need an underscore prefixed
    1.72 +to symbol names.  Some solution to that may be a good thing.  I can
    1.73 +fix it theoretically, but unfortunately I do not have the needed 
    1.74 +hardware/configuration to test it.  If you bump into that, email me.
    1.75 +
    1.76 +===================
    1.77 +Contact Information
    1.78 +===================
    1.79 +Everybody is welcome to give me any suggestions and to report bugs
    1.80 +(as well as fixing them ;-)  You can contact me by email:
    1.81 +Peter Valchev <pvalchev@openbsd.org>
    1.82 +
    1.83 +$Id$
    1.84 +
     2.1 --- a/configure.in	Wed May 23 23:35:10 2001 +0000
     2.2 +++ b/configure.in	Sat May 26 16:58:37 2001 +0000
     2.3 @@ -278,6 +278,19 @@
     2.4      fi
     2.5  }
     2.6  
     2.7 +dnl Check whether we want to use OpenBSD native audio or not
     2.8 +CheckOPENBSDAUDIO()
     2.9 +{
    2.10 +    AC_ARG_ENABLE(openbsdaudio,
    2.11 +[  --enable-openbsdaudio   OpenBSD native audio support [default=no]],
    2.12 +                  , enable_openbsdaudio=no)
    2.13 +    if test x$enable_audio = xyes -a x$enable_openbsdaudio = xyes; then
    2.14 +        SYSTEM_LIBS="$SYSTEM_LIBS $ESD_LIBS"
    2.15 +        AUDIO_SUBDIRS="$AUDIO_SUBDIRS openbsd"
    2.16 +        AUDIO_DRIVERS="$AUDIO_DRIVERS openbsd/libaudio_openbsd.la"
    2.17 +    fi
    2.18 +}
    2.19 +
    2.20  dnl Find the ESD includes and libraries
    2.21  CheckESD()
    2.22  {
    2.23 @@ -1275,7 +1288,6 @@
    2.24          ;;
    2.25      *-*-openbsd*)
    2.26          ARCH=openbsd
    2.27 -        CFLAGS="$CFLAGS -Dunix"
    2.28          CheckDummyVideo
    2.29          CheckNASM
    2.30          CheckOSS
    2.31 @@ -1289,10 +1301,7 @@
    2.32          # Set up files for the main() stub
    2.33          COPY_ARCH_SRC(src/main, linux, SDL_main.c)
    2.34          # Set up files for the audio library
    2.35 -        if test x$enable_audio = xyes; then
    2.36 -            AUDIO_SUBDIRS="$AUDIO_SUBDIRS sun"
    2.37 -            AUDIO_DRIVERS="$AUDIO_DRIVERS sun/libaudio_sun.la"
    2.38 -        fi
    2.39 +        CheckOPENBSDAUDIO
    2.40          # Set up files for the joystick library
    2.41          # (No joystick support yet)
    2.42          if test x$enable_joystick = xyes; then
    2.43 @@ -1322,6 +1331,8 @@
    2.44          if test x$enable_timers = xyes; then
    2.45              COPY_ARCH_SRC(src/timer, linux, SDL_systimer.c)
    2.46          fi
    2.47 +        # OpenBSD does not define "unix"
    2.48 +        CFLAGS="$CFLAGS -Dunix"
    2.49          ;;
    2.50      *-*-sysv5*)
    2.51          ARCH=sysv5
    2.52 @@ -1882,7 +1893,7 @@
    2.53  fi
    2.54  
    2.55  if test $ARCH = openbsd; then
    2.56 -  SDL_RLD_FLAGS="-Wl,-R\${exec_prefix}/lib -Wl,-R\${X11BASE}/lib"
    2.57 +  SDL_RLD_FLAGS="-L${X11BASE}/lib -Wl,-rpath,\${exec_prefix}/lib -Wl,-rpath,${X11BASE}/lib"
    2.58  fi
    2.59  
    2.60  dnl Output the video drivers we use
    2.61 @@ -1947,6 +1958,7 @@
    2.62  src/audio/macrom/Makefile
    2.63  src/audio/nas/Makefile
    2.64  src/audio/nto/Makefile
    2.65 +src/audio/openbsd/Makefile
    2.66  src/audio/paudio/Makefile
    2.67  src/audio/sun/Makefile
    2.68  src/audio/ums/Makefile
     3.1 --- a/docs.html	Wed May 23 23:35:10 2001 +0000
     3.2 +++ b/docs.html	Sat May 26 16:58:37 2001 +0000
     3.3 @@ -16,6 +16,7 @@
     3.4  Major changes since SDL 1.0.0:
     3.5  </H2>
     3.6  <UL>
     3.7 +	<LI> 1.2.1: Added native OpenBSD audio driver (thanks vedge!)
     3.8  	<LI> 1.2.1: Added detection of Open Sound System on Solaris x86
     3.9  	<LI> 1.2.1: Added initial support for Nano-X (thanks Hsieh-Fu!)
    3.10  	<LI> 1.2.1: Fixed endian detection on IA64 architectures (thanks Bill!)
     4.1 --- a/src/audio/Makefile.am	Wed May 23 23:35:10 2001 +0000
     4.2 +++ b/src/audio/Makefile.am	Sat May 26 16:58:37 2001 +0000
     4.3 @@ -6,7 +6,7 @@
     4.4  # Define which subdirectories need to be built
     4.5  SUBDIRS = @AUDIO_SUBDIRS@
     4.6  DIST_SUBDIRS = alsa arts baudio dma dmedia dsp esd macrom nas nto \
     4.7 -               paudio sun ums windib windx5
     4.8 +               openbsd paudio sun ums windib windx5
     4.9  
    4.10  DRIVERS = @AUDIO_DRIVERS@
    4.11  
     5.1 --- a/src/audio/SDL_audio.c	Wed May 23 23:35:10 2001 +0000
     5.2 +++ b/src/audio/SDL_audio.c	Sat May 26 16:58:37 2001 +0000
     5.3 @@ -47,6 +47,9 @@
     5.4  #ifdef ALSA_SUPPORT
     5.5  	&ALSA_bootstrap,
     5.6  #endif
     5.7 +#ifdef __OpenBSD__
     5.8 +	&OBSD_bootstrap;
     5.9 +#endif
    5.10  #if (defined(unix) && !defined(__CYGWIN32__)) && \
    5.11      !defined(OSS_SUPPORT) && !defined(ALSA_SUPPORT)
    5.12  	&AUDIO_bootstrap,
     6.1 --- a/src/audio/SDL_sysaudio.h	Wed May 23 23:35:10 2001 +0000
     6.2 +++ b/src/audio/SDL_sysaudio.h	Sat May 26 16:58:37 2001 +0000
     6.3 @@ -106,6 +106,9 @@
     6.4  #ifdef ALSA_SUPPORT
     6.5  extern AudioBootStrap ALSA_bootstrap;
     6.6  #endif
     6.7 +#ifdef __OpenBSD__
     6.8 +extern AudioBootStrap OBSD_bootstrap;
     6.9 +#endif
    6.10  #if (defined(unix) && !defined(__CYGWIN32__)) && \
    6.11      !defined(OSS_SUPPORT) && !defined(ALSA_SUPPORT)
    6.12  extern AudioBootStrap AUDIO_bootstrap;
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/audio/openbsd/Makefile.am	Sat May 26 16:58:37 2001 +0000
     7.3 @@ -0,0 +1,9 @@
     7.4 +
     7.5 +## Makefile.am for SDL using the native OpenBSD sound driver
     7.6 +
     7.7 +noinst_LTLIBRARIES = libaudio_openbsd.la
     7.8 +libaudio_openbsd_la_SOURCES = $(SRCS)
     7.9 +
    7.10 +# The SDL audio driver sources
    7.11 +SRCS =	SDL_openbsdaudio.c	\
    7.12 +	SDL_openbsdaudio.h
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/audio/openbsd/SDL_openbsdaudio.c	Sat May 26 16:58:37 2001 +0000
     8.3 @@ -0,0 +1,408 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Library General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Library General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Library General Public
    8.19 +    License along with this library; if not, write to the Free
    8.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@devolution.com
    8.24 +*/
    8.25 +
    8.26 +/*
    8.27 + * Driver for native OpenBSD audio(4).
    8.28 + * vedge@vedge.com.ar.
    8.29 + */
    8.30 +
    8.31 +#include <stdlib.h>
    8.32 +#include <stdio.h>
    8.33 +#include <string.h>
    8.34 +#include <errno.h>
    8.35 +#include <unistd.h>
    8.36 +#include <fcntl.h>
    8.37 +#include <signal.h>
    8.38 +#include <sys/time.h>
    8.39 +#include <sys/ioctl.h>
    8.40 +#include <sys/stat.h>
    8.41 +#include <sys/types.h>
    8.42 +#include <sys/audioio.h>
    8.43 +
    8.44 +#include "SDL_audio.h"
    8.45 +#include "SDL_error.h"
    8.46 +#include "SDL_audiomem.h"
    8.47 +#include "SDL_audio_c.h"
    8.48 +#include "SDL_timer.h"
    8.49 +#include "SDL_audiodev_c.h"
    8.50 +#include "SDL_openbsdaudio.h"
    8.51 +
    8.52 +/* The tag name used by OpenBSD audio */
    8.53 +#define OBSD_DRIVER_NAME         "openbsd"
    8.54 +
    8.55 +/* Open the audio device for playback, and don't block if busy */
    8.56 +/* #define USE_BLOCKING_WRITES */
    8.57 +
    8.58 +/* Use timer for synchronization */
    8.59 +/* #define USE_TIMER_SYNC */
    8.60 +
    8.61 +/* #define DEBUG_AUDIO */
    8.62 +/* #define DEBUG_AUDIO_STREAM */
    8.63 +
    8.64 +#ifdef USE_BLOCKING_WRITES
    8.65 +#define OPEN_FLAGS	O_WRONLY
    8.66 +#else
    8.67 +#define OPEN_FLAGS	(O_WRONLY|O_NONBLOCK)
    8.68 +#endif
    8.69 +
    8.70 +/* Audio driver functions */
    8.71 +static void OBSD_WaitAudio(_THIS);
    8.72 +static int OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec);
    8.73 +static void OBSD_PlayAudio(_THIS);
    8.74 +static Uint8 *OBSD_GetAudioBuf(_THIS);
    8.75 +static void OBSD_CloseAudio(_THIS);
    8.76 +
    8.77 +#ifdef DEBUG_AUDIO
    8.78 +static void OBSD_Status(_THIS);
    8.79 +#endif
    8.80 +
    8.81 +/* Audio driver bootstrap functions */
    8.82 +
    8.83 +static int
    8.84 +Audio_Available(void)
    8.85 +{
    8.86 +    int fd;
    8.87 +    int available;
    8.88 +
    8.89 +    available = 0;
    8.90 +    fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
    8.91 +    if(fd >= 0) {
    8.92 +	available = 1;
    8.93 +	close(fd);
    8.94 +    }
    8.95 +    return(available);
    8.96 +}
    8.97 +
    8.98 +static void
    8.99 +Audio_DeleteDevice(SDL_AudioDevice *device)
   8.100 +{
   8.101 +    free(device->hidden);
   8.102 +    free(device);
   8.103 +}
   8.104 +
   8.105 +static SDL_AudioDevice
   8.106 +*Audio_CreateDevice(int devindex)
   8.107 +{
   8.108 +    SDL_AudioDevice *this;
   8.109 +
   8.110 +    /* Initialize all variables that we clean on shutdown */
   8.111 +    this = (SDL_AudioDevice*)malloc(sizeof(SDL_AudioDevice));
   8.112 +    if(this) {
   8.113 +	memset(this, 0, (sizeof *this));
   8.114 +	this->hidden =
   8.115 +	    (struct SDL_PrivateAudioData*)malloc((sizeof *this->hidden));
   8.116 +    }
   8.117 +    if((this == NULL) || (this->hidden == NULL)) {
   8.118 +	SDL_OutOfMemory();
   8.119 +	if(this) free(this);
   8.120 +	return(0);
   8.121 +    }
   8.122 +    memset(this->hidden, 0, (sizeof *this->hidden));
   8.123 +    audio_fd = -1;
   8.124 +
   8.125 +    /* Set the function pointers */
   8.126 +    this->OpenAudio = OBSD_OpenAudio;
   8.127 +    this->WaitAudio = OBSD_WaitAudio;
   8.128 +    this->PlayAudio = OBSD_PlayAudio;
   8.129 +    this->GetAudioBuf = OBSD_GetAudioBuf;
   8.130 +    this->CloseAudio = OBSD_CloseAudio;
   8.131 +
   8.132 +    this->free = Audio_DeleteDevice;
   8.133 +    
   8.134 +    return this;
   8.135 +}
   8.136 +
   8.137 +AudioBootStrap OBSD_bootstrap = {
   8.138 +	OBSD_DRIVER_NAME, "Native OpenBSD audio",
   8.139 +	Audio_Available, Audio_CreateDevice
   8.140 +};
   8.141 +
   8.142 +/* This function waits until it is possible to write a full sound buffer */
   8.143 +static void
   8.144 +OBSD_WaitAudio(_THIS)
   8.145 +{
   8.146 +#ifndef USE_BLOCKING_WRITES
   8.147 +    fd_set fdset;
   8.148 +
   8.149 +    /* Check to see if the thread-parent process is still alive */
   8.150 +    {
   8.151 +	static int cnt = 0;
   8.152 +	/* Note that this only works with thread implementations 
   8.153 +	   that use a different process id for each thread. */
   8.154 +	if(parent && (((++cnt)%10) == 0)) { /* Check every 10 loops */
   8.155 +	    if(kill(parent, 0) < 0)
   8.156 +		this->enabled = 0;
   8.157 +	}
   8.158 +    }
   8.159 +
   8.160 +#ifdef USE_TIMER_SYNC
   8.161 +    /* See if we need to use timed audio synchronization */
   8.162 +    if(frame_ticks)
   8.163 +    {
   8.164 +	/* Use timer for general audio synchronization */
   8.165 +	Sint32 ticks;
   8.166 +
   8.167 +	ticks = ((Sint32)(next_frame - SDL_GetTicks())) - FUDGE_TICKS;
   8.168 +	if(ticks > 0)
   8.169 +	    SDL_Delay(ticks);
   8.170 +    }
   8.171 +    else
   8.172 +#endif /* USE_TIMER_SYNC */
   8.173 +    {
   8.174 +	/* Use select() for audio synchronization */
   8.175 +	struct timeval timeout;
   8.176 +	FD_ZERO(&fdset);
   8.177 +	FD_SET(audio_fd, &fdset);
   8.178 +	timeout.tv_sec = 10;
   8.179 +	timeout.tv_usec = 0;
   8.180 +	
   8.181 +#if defined(DEBUG_AUDIO_STREAM) && defined(DEBUG_AUDIO_STREAM)
   8.182 +	OBSD_Status(this);
   8.183 +#endif
   8.184 +	if(select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0)
   8.185 +	{
   8.186 +	    const char *message =
   8.187 +		"Audio timeout - buggy audio driver? (disabled)";
   8.188 +	    fprintf(stderr, "SDL: %s\n", message);
   8.189 +	    this->enabled = 0;
   8.190 +	    audio_fd = -1;
   8.191 +	}
   8.192 +    }
   8.193 +#endif /* !USE_BLOCKING_WRITES */
   8.194 +
   8.195 +}
   8.196 +
   8.197 +static void
   8.198 +OBSD_PlayAudio(_THIS)
   8.199 +{
   8.200 +    int written;
   8.201 +
   8.202 +    /* Write the audio data, checking for EAGAIN on broken audio drivers */
   8.203 +    do
   8.204 +    {
   8.205 +	written = write(audio_fd, mixbuf, mixlen);
   8.206 +	if((written < 0) && ((errno == 0) || (errno == EAGAIN)))
   8.207 +	    SDL_Delay(1);
   8.208 +    }
   8.209 +    while((written < 0) &&
   8.210 +	((errno == 0) || (errno == EAGAIN) || (errno == EINTR)));
   8.211 +
   8.212 +#ifdef USE_TIMER_SYNC
   8.213 +    if(frame_ticks)
   8.214 +	next_frame += frame_ticks;
   8.215 +#endif
   8.216 +
   8.217 +    /* If we couldn't write, assume fatal error for now */
   8.218 +    if(written < 0)
   8.219 +	this->enabled = 0;
   8.220 +
   8.221 +#ifdef DEBUG_AUDIO_STREAM
   8.222 +    fprintf(stderr, "Wrote %d bytes of audio data\n", written);
   8.223 +#endif
   8.224 +}
   8.225 +
   8.226 +static Uint8
   8.227 +*OBSD_GetAudioBuf(_THIS)
   8.228 +{
   8.229 +    return(mixbuf);
   8.230 +}
   8.231 +
   8.232 +static void
   8.233 +OBSD_CloseAudio(_THIS)
   8.234 +{
   8.235 +    if(mixbuf != NULL) {
   8.236 +	SDL_FreeAudioMem(mixbuf);
   8.237 +	mixbuf = NULL;
   8.238 +    }
   8.239 +    if(audio_fd >= 0) {
   8.240 +	close(audio_fd);
   8.241 +	audio_fd = -1;
   8.242 +    }
   8.243 +}
   8.244 +
   8.245 +#ifdef DEBUG_AUDIO
   8.246 +void
   8.247 +OBSD_Status(_THIS)
   8.248 +{
   8.249 +    audio_info_t info;
   8.250 +
   8.251 +    if(ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
   8.252 +	fprintf(stderr,"AUDIO_GETINFO failed.\n");
   8.253 +	return;
   8.254 +    }
   8.255 +
   8.256 +    fprintf(stderr,"
   8.257 +[play/record info]
   8.258 +buffer size	:   %d bytes
   8.259 +sample rate	:   %i Hz
   8.260 +channels	:   %i
   8.261 +precision	:   %i-bit
   8.262 +encoding	:   0x%x
   8.263 +seek		:   %i
   8.264 +sample count	:   %i
   8.265 +EOF count	:   %i
   8.266 +paused		:   %s
   8.267 +error occured	:   %s
   8.268 +waiting		:   %s
   8.269 +active		:   %s
   8.270 +",
   8.271 +    info.play.buffer_size,
   8.272 +    info.play.sample_rate,
   8.273 +    info.play.channels,
   8.274 +    info.play.precision,
   8.275 +    info.play.encoding,
   8.276 +    info.play.seek,
   8.277 +    info.play.samples,
   8.278 +    info.play.eof,
   8.279 +    info.play.pause ? "yes" : "no",
   8.280 +    info.play.error ? "yes" : "no",
   8.281 +    info.play.waiting ? "yes" : "no",
   8.282 +    info.play.active ? "yes": "no");
   8.283 +
   8.284 +    fprintf(stderr,"
   8.285 +[audio info]
   8.286 +monitor_gain	:   %i
   8.287 +hw block size	:   %d bytes
   8.288 +hi watermark	:   %i
   8.289 +lo watermark	:   %i
   8.290 +audio mode	:   %s
   8.291 +",  
   8.292 +    info.monitor_gain,
   8.293 +    info.blocksize,
   8.294 +    info.hiwat, info.lowat,
   8.295 +    (info.mode == AUMODE_PLAY) ? "PLAY"
   8.296 +    : (info.mode = AUMODE_RECORD) ? "RECORD"
   8.297 +    : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL"
   8.298 +    : "???"));
   8.299 +}
   8.300 +#endif /* DEBUG_AUDIO */
   8.301 +
   8.302 +static int
   8.303 +OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec)
   8.304 +{
   8.305 +    char audiodev[64];
   8.306 +    Uint16 setenc;
   8.307 +    audio_encoding_t enc;
   8.308 +    audio_info_t info;
   8.309 +
   8.310 +    AUDIO_INITINFO(&info);
   8.311 +    
   8.312 +    /* Calculate the final parameters for this audio specification */
   8.313 +    SDL_CalculateAudioSpec(spec);
   8.314 +
   8.315 +#ifdef USE_TIMER_SYNC
   8.316 +    frame_ticks = 0.0;
   8.317 +#endif
   8.318 +
   8.319 +    /* Open the audio device */
   8.320 +    audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
   8.321 +    if(audio_fd < 0) {
   8.322 +	SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
   8.323 +	return(-1);
   8.324 +    }
   8.325 +    
   8.326 +    /* Set to play mode */
   8.327 +    info.mode = AUMODE_PLAY;
   8.328 +    if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
   8.329 +	SDL_SetError("Couldn't put device into play mode");
   8.330 +	return(-1);
   8.331 +    }
   8.332 +    
   8.333 +    mixbuf = NULL;
   8.334 +    setenc = 0;
   8.335 +
   8.336 +    for(enc.index = 0; (ioctl(audio_fd, AUDIO_GETENC, &enc)>=0)
   8.337 +	&& (enc.encoding != setenc); enc.index++)
   8.338 +    {
   8.339 +	switch(spec->format)
   8.340 +	{
   8.341 +	    case AUDIO_U8:	/* 8-bit unsigned linear */
   8.342 +		setenc = AUDIO_ENCODING_PCM8;
   8.343 +		break;
   8.344 +	    case AUDIO_S8:	/* 8-bit signed linear */
   8.345 +		setenc = AUDIO_ENCODING_SLINEAR;
   8.346 +		break;
   8.347 +	    case AUDIO_U16LSB:  /* 16-bit unsigned linear, LSB */
   8.348 +		setenc = AUDIO_ENCODING_ULINEAR_LE;
   8.349 +		break;
   8.350 +	    case AUDIO_U16MSB:  /* 16-bit unsigned linear, MSB */
   8.351 +		setenc = AUDIO_ENCODING_ULINEAR_BE;
   8.352 +		break;
   8.353 +	    case AUDIO_S16LSB:  /* 16-bit signed linear, LSB */
   8.354 +		setenc = AUDIO_ENCODING_SLINEAR_LE;
   8.355 +		break;
   8.356 +	    case AUDIO_S16MSB:  /* 16-bit signed linear, MSB */
   8.357 +		setenc = AUDIO_ENCODING_SLINEAR_BE;
   8.358 +		break;
   8.359 +	}
   8.360 +#ifdef DEBUG_AUDIO
   8.361 +	fprintf(stderr,"encoding #%i: \"%s\" %i-bit (0x%x) flags=%i...\n",
   8.362 +	    enc.index, enc.name, enc.precision, enc.encoding, enc.flags);
   8.363 +#endif
   8.364 +    }
   8.365 +
   8.366 +    if(!setenc) {
   8.367 +	SDL_SetError("No supported encoding for 0x%x", spec->format);
   8.368 +	return(-1);
   8.369 +    }
   8.370 +
   8.371 +    /* Set audio encoding */
   8.372 +    info.play.encoding = enc.encoding;
   8.373 +    info.play.precision = enc.precision;
   8.374 +    if((ioctl(audio_fd, AUDIO_SETINFO, &info) < 0)) {
   8.375 +	SDL_SetError("Couldn't set encoding to 0x%x %i-bit",
   8.376 +	    enc.encoding, enc.precision);
   8.377 +	return(-1);
   8.378 +    }
   8.379 +
   8.380 +    /* Set audio channels */
   8.381 +    info.play.channels = spec->channels;
   8.382 +    if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
   8.383 +	info.play.channels = (spec->channels > 1);
   8.384 +	ioctl(audio_fd, AUDIO_SETINFO, &info);
   8.385 +    }
   8.386 +
   8.387 +    /* Set the sample rate */
   8.388 +    info.play.sample_rate = spec->freq;
   8.389 +    if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
   8.390 +	SDL_SetError("Couldn't set sample rate to %i Hz", spec->freq);
   8.391 +	return(-1);
   8.392 +    }
   8.393 +
   8.394 +    /* Allocate mixing buffer */
   8.395 +    mixlen = spec->size;
   8.396 +    mixbuf = (Uint8*)SDL_AllocAudioMem(mixlen);
   8.397 +    if(mixbuf == NULL) {
   8.398 +	return(-1);
   8.399 +    }
   8.400 +    memset(mixbuf, spec->silence, spec->size);
   8.401 +    
   8.402 +    /* Get the parent process id (we're the parent of the audio thread) */
   8.403 +    parent = getpid();
   8.404 +
   8.405 +#ifdef DEBUG_AUDIO
   8.406 +    OBSD_Status(this);
   8.407 +#endif
   8.408 +
   8.409 +    /* We're ready to rock and roll. :-) */
   8.410 +    return(0);
   8.411 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/audio/openbsd/SDL_openbsdaudio.h	Sat May 26 16:58:37 2001 +0000
     9.3 @@ -0,0 +1,57 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Library General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Library General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Library General Public
    9.19 +    License along with this library; if not, write to the Free
    9.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@devolution.com
    9.24 +*/
    9.25 +
    9.26 +#ifndef _SDL_openbsdaudio_h
    9.27 +#define _SDL_openbsdaudio_h
    9.28 +
    9.29 +#include "SDL_sysaudio.h"
    9.30 +
    9.31 +#define _THIS	SDL_AudioDevice *this
    9.32 +
    9.33 +struct SDL_PrivateAudioData
    9.34 +{
    9.35 +    /* The file descriptor for the audio device */
    9.36 +    int audio_fd;
    9.37 +
    9.38 +    /* The parent process id, to detect when application quits */
    9.39 +    pid_t parent;
    9.40 +
    9.41 +    /* Raw mixing buffer */
    9.42 +    Uint8 *mixbuf;
    9.43 +    int    mixlen;
    9.44 +
    9.45 +    /* Support for audio timing using a timer, in addition to select() */
    9.46 +    float frame_ticks;
    9.47 +    float next_frame;
    9.48 +};
    9.49 +
    9.50 +#define FUDGE_TICKS	10	/* The scheduler overhead ticks per frame */
    9.51 +
    9.52 +/* Old variable names */
    9.53 +#define audio_fd		(this->hidden->audio_fd)
    9.54 +#define parent			(this->hidden->parent)
    9.55 +#define mixbuf			(this->hidden->mixbuf)
    9.56 +#define mixlen			(this->hidden->mixlen)
    9.57 +#define frame_ticks		(this->hidden->frame_ticks)
    9.58 +#define next_frame		(this->hidden->next_frame)
    9.59 +
    9.60 +#endif /* _SDL_openbsdaudio_h */