Good idea, renaming OpenBSD audio to BSD audio.
authorSam Lantinga <slouken@libsdl.org>
Tue, 21 Mar 2006 09:33:54 +0000
changeset 156712b6d331d82a
parent 1566 5bc2a95f9dcf
child 1568 1f3f39f9cfcf
Good idea, renaming OpenBSD audio to BSD audio.
configure.in
include/SDL_config.h.in
src/audio/SDL_audio.c
src/audio/SDL_audiodev.c
src/audio/SDL_sysaudio.h
src/audio/bsd/.cvsignore
src/audio/bsd/SDL_bsdaudio.c
src/audio/bsd/SDL_bsdaudio.h
src/audio/openbsd/.cvsignore
src/audio/openbsd/SDL_openbsdaudio.c
src/audio/openbsd/SDL_openbsdaudio.h
     1.1 --- a/configure.in	Tue Mar 21 09:24:10 2006 +0000
     1.2 +++ b/configure.in	Tue Mar 21 09:33:54 2006 +0000
     1.3 @@ -2001,8 +2001,8 @@
     1.4                  have_audio=yes
     1.5              ;;
     1.6              netbsd|openbsd)
     1.7 -                AC_DEFINE(SDL_AUDIO_DRIVER_OPENBSD)
     1.8 -                SOURCES="$SOURCES $srcdir/src/audio/openbsd/*.c"
     1.9 +                AC_DEFINE(SDL_AUDIO_DRIVER_BSD)
    1.10 +                SOURCES="$SOURCES $srcdir/src/audio/bsd/*.c"
    1.11                  have_audio=yes
    1.12              ;;
    1.13              aix)
     2.1 --- a/include/SDL_config.h.in	Tue Mar 21 09:24:10 2006 +0000
     2.2 +++ b/include/SDL_config.h.in	Tue Mar 21 09:33:54 2006 +0000
     2.3 @@ -167,7 +167,7 @@
     2.4  #undef SDL_AUDIO_DRIVER_MINT
     2.5  #undef SDL_AUDIO_DRIVER_MMEAUDIO
     2.6  #undef SDL_AUDIO_DRIVER_NAS
     2.7 -#undef SDL_AUDIO_DRIVER_OPENBSD
     2.8 +#undef SDL_AUDIO_DRIVER_BSD
     2.9  #undef SDL_AUDIO_DRIVER_OSS
    2.10  #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
    2.11  #undef SDL_AUDIO_DRIVER_PAUD
     3.1 --- a/src/audio/SDL_audio.c	Tue Mar 21 09:24:10 2006 +0000
     3.2 +++ b/src/audio/SDL_audio.c	Tue Mar 21 09:33:54 2006 +0000
     3.3 @@ -36,8 +36,8 @@
     3.4  
     3.5  /* Available audio drivers */
     3.6  static AudioBootStrap *bootstrap[] = {
     3.7 -#if SDL_AUDIO_DRIVER_OPENBSD
     3.8 -	&OPENBSD_AUDIO_bootstrap,
     3.9 +#if SDL_AUDIO_DRIVER_BSD
    3.10 +	&BSD_AUDIO_bootstrap,
    3.11  #endif
    3.12  #if SDL_AUDIO_DRIVER_OSS
    3.13  	&DSP_bootstrap,
     4.1 --- a/src/audio/SDL_audiodev.c	Tue Mar 21 09:24:10 2006 +0000
     4.2 +++ b/src/audio/SDL_audiodev.c	Tue Mar 21 09:33:54 2006 +0000
     4.3 @@ -23,7 +23,7 @@
     4.4  
     4.5  /* Get the name of the audio device we use for output */
     4.6  
     4.7 -#if SDL_AUDIO_DRIVER_OPENBSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
     4.8 +#if SDL_AUDIO_DRIVER_BSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
     4.9  
    4.10  #include <fcntl.h>
    4.11  #include <sys/types.h>
     5.1 --- a/src/audio/SDL_sysaudio.h	Tue Mar 21 09:24:10 2006 +0000
     5.2 +++ b/src/audio/SDL_sysaudio.h	Tue Mar 21 09:33:54 2006 +0000
     5.3 @@ -100,8 +100,8 @@
     5.4  	SDL_AudioDevice *(*create)(int devindex);
     5.5  } AudioBootStrap;
     5.6  
     5.7 -#if SDL_AUDIO_DRIVER_OPENBSD
     5.8 -extern AudioBootStrap OPENBSD_AUDIO_bootstrap;
     5.9 +#if SDL_AUDIO_DRIVER_BSD
    5.10 +extern AudioBootStrap BSD_AUDIO_bootstrap;
    5.11  #endif
    5.12  #if SDL_AUDIO_DRIVER_OSS
    5.13  extern AudioBootStrap DSP_bootstrap;
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/audio/bsd/.cvsignore	Tue Mar 21 09:33:54 2006 +0000
     6.3 @@ -0,0 +1,6 @@
     6.4 +Makefile.in
     6.5 +Makefile
     6.6 +.libs
     6.7 +*.o
     6.8 +*.lo
     6.9 +*.la
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/audio/bsd/SDL_bsdaudio.c	Tue Mar 21 09:33:54 2006 +0000
     7.3 @@ -0,0 +1,404 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997-2004 Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Library General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Library General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Library General Public
    7.19 +    License along with this library; if not, write to the Free
    7.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@libsdl.org
    7.24 +*/
    7.25 +#include "SDL_config.h"
    7.26 +
    7.27 +/*
    7.28 + * Driver for native OpenBSD/NetBSD audio(4).
    7.29 + * vedge@vedge.com.ar.
    7.30 + */
    7.31 +
    7.32 +#include <errno.h>
    7.33 +#include <unistd.h>
    7.34 +#include <fcntl.h>
    7.35 +#include <sys/time.h>
    7.36 +#include <sys/ioctl.h>
    7.37 +#include <sys/stat.h>
    7.38 +#include <sys/types.h>
    7.39 +#include <sys/audioio.h>
    7.40 +
    7.41 +#include "SDL_timer.h"
    7.42 +#include "SDL_audio.h"
    7.43 +#include "../SDL_audiomem.h"
    7.44 +#include "../SDL_audio_c.h"
    7.45 +#include "../SDL_audiodev_c.h"
    7.46 +#include "SDL_openbsdaudio.h"
    7.47 +
    7.48 +/* The tag name used by NetBSD/OpenBSD audio */
    7.49 +#ifdef __NetBSD__
    7.50 +#define BSD_AUDIO_DRIVER_NAME         "netbsd"
    7.51 +#define BSD_AUDIO_DRIVER_DESC         "Native NetBSD audio"
    7.52 +#else
    7.53 +#define BSD_AUDIO_DRIVER_NAME         "openbsd"
    7.54 +#define BSD_AUDIO_DRIVER_DESC         "Native OpenBSD audio"
    7.55 +#endif
    7.56 +
    7.57 +/* Open the audio device for playback, and don't block if busy */
    7.58 +/* #define USE_BLOCKING_WRITES */
    7.59 +
    7.60 +/* Use timer for synchronization */
    7.61 +/* #define USE_TIMER_SYNC */
    7.62 +
    7.63 +/* #define DEBUG_AUDIO */
    7.64 +/* #define DEBUG_AUDIO_STREAM */
    7.65 +
    7.66 +#ifdef USE_BLOCKING_WRITES
    7.67 +#define OPEN_FLAGS	O_WRONLY
    7.68 +#else
    7.69 +#define OPEN_FLAGS	(O_WRONLY|O_NONBLOCK)
    7.70 +#endif
    7.71 +
    7.72 +/* Audio driver functions */
    7.73 +static void OBSD_WaitAudio(_THIS);
    7.74 +static int OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec);
    7.75 +static void OBSD_PlayAudio(_THIS);
    7.76 +static Uint8 *OBSD_GetAudioBuf(_THIS);
    7.77 +static void OBSD_CloseAudio(_THIS);
    7.78 +
    7.79 +#ifdef DEBUG_AUDIO
    7.80 +static void OBSD_Status(_THIS);
    7.81 +#endif
    7.82 +
    7.83 +/* Audio driver bootstrap functions */
    7.84 +
    7.85 +static int
    7.86 +Audio_Available(void)
    7.87 +{
    7.88 +    int fd;
    7.89 +    int available;
    7.90 +
    7.91 +    available = 0;
    7.92 +    fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
    7.93 +    if(fd >= 0) {
    7.94 +	available = 1;
    7.95 +	close(fd);
    7.96 +    }
    7.97 +    return(available);
    7.98 +}
    7.99 +
   7.100 +static void
   7.101 +Audio_DeleteDevice(SDL_AudioDevice *device)
   7.102 +{
   7.103 +    SDL_free(device->hidden);
   7.104 +    SDL_free(device);
   7.105 +}
   7.106 +
   7.107 +static SDL_AudioDevice
   7.108 +*Audio_CreateDevice(int devindex)
   7.109 +{
   7.110 +    SDL_AudioDevice *this;
   7.111 +
   7.112 +    /* Initialize all variables that we clean on shutdown */
   7.113 +    this = (SDL_AudioDevice*)SDL_malloc(sizeof(SDL_AudioDevice));
   7.114 +    if(this) {
   7.115 +	SDL_memset(this, 0, (sizeof *this));
   7.116 +	this->hidden =
   7.117 +	    (struct SDL_PrivateAudioData*)SDL_malloc((sizeof *this->hidden));
   7.118 +    }
   7.119 +    if((this == NULL) || (this->hidden == NULL)) {
   7.120 +	SDL_OutOfMemory();
   7.121 +	if(this) SDL_free(this);
   7.122 +	return(0);
   7.123 +    }
   7.124 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   7.125 +    audio_fd = -1;
   7.126 +
   7.127 +    /* Set the function pointers */
   7.128 +    this->OpenAudio = OBSD_OpenAudio;
   7.129 +    this->WaitAudio = OBSD_WaitAudio;
   7.130 +    this->PlayAudio = OBSD_PlayAudio;
   7.131 +    this->GetAudioBuf = OBSD_GetAudioBuf;
   7.132 +    this->CloseAudio = OBSD_CloseAudio;
   7.133 +
   7.134 +    this->free = Audio_DeleteDevice;
   7.135 +    
   7.136 +    return this;
   7.137 +}
   7.138 +
   7.139 +AudioBootStrap OPENBSD_AUDIO_bootstrap = {
   7.140 +	BSD_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
   7.141 +	Audio_Available, Audio_CreateDevice
   7.142 +};
   7.143 +
   7.144 +/* This function waits until it is possible to write a full sound buffer */
   7.145 +static void
   7.146 +OBSD_WaitAudio(_THIS)
   7.147 +{
   7.148 +#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
   7.149 +	/* See if we need to use timed audio synchronization */
   7.150 +	if ( frame_ticks ) {
   7.151 +		/* Use timer for general audio synchronization */
   7.152 +		Sint32 ticks;
   7.153 +
   7.154 +		ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS;
   7.155 +		if ( ticks > 0 ) {
   7.156 +			SDL_Delay(ticks);
   7.157 +		}
   7.158 +	} else {
   7.159 +		/* Use select() for audio synchronization */
   7.160 +		fd_set fdset;
   7.161 +		struct timeval timeout;
   7.162 +
   7.163 +		FD_ZERO(&fdset);
   7.164 +		FD_SET(audio_fd, &fdset);
   7.165 +		timeout.tv_sec = 10;
   7.166 +		timeout.tv_usec = 0;
   7.167 +#ifdef DEBUG_AUDIO
   7.168 +		fprintf(stderr, "Waiting for audio to get ready\n");
   7.169 +#endif
   7.170 +		if ( select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0 ) {
   7.171 +			const char *message =
   7.172 +			"Audio timeout - buggy audio driver? (disabled)";
   7.173 +			/* In general we should never print to the screen,
   7.174 +			   but in this case we have no other way of letting
   7.175 +			   the user know what happened.
   7.176 +			*/
   7.177 +			fprintf(stderr, "SDL: %s\n", message);
   7.178 +			this->enabled = 0;
   7.179 +			/* Don't try to close - may hang */
   7.180 +			audio_fd = -1;
   7.181 +#ifdef DEBUG_AUDIO
   7.182 +			fprintf(stderr, "Done disabling audio\n");
   7.183 +#endif
   7.184 +		}
   7.185 +#ifdef DEBUG_AUDIO
   7.186 +		fprintf(stderr, "Ready!\n");
   7.187 +#endif
   7.188 +	}
   7.189 +#endif /* !USE_BLOCKING_WRITES */
   7.190 +}
   7.191 +
   7.192 +static void
   7.193 +OBSD_PlayAudio(_THIS)
   7.194 +{
   7.195 +	int written, p=0;
   7.196 +
   7.197 +	/* Write the audio data, checking for EAGAIN on broken audio drivers */
   7.198 +	do {
   7.199 +		written = write(audio_fd, &mixbuf[p], mixlen-p);
   7.200 +		if (written>0)
   7.201 +		   p += written;
   7.202 +		if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR)
   7.203 +		{
   7.204 +		   /* Non recoverable error has occurred. It should be reported!!! */
   7.205 +		   perror("audio");
   7.206 +		   break;
   7.207 +		}
   7.208 +
   7.209 +		if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) {
   7.210 +			SDL_Delay(1);	/* Let a little CPU time go by */
   7.211 +		}
   7.212 +	} while ( p < written );
   7.213 +
   7.214 +	/* If timer synchronization is enabled, set the next write frame */
   7.215 +	if ( frame_ticks ) {
   7.216 +		next_frame += frame_ticks;
   7.217 +	}
   7.218 +
   7.219 +	/* If we couldn't write, assume fatal error for now */
   7.220 +	if ( written < 0 ) {
   7.221 +		this->enabled = 0;
   7.222 +	}
   7.223 +#ifdef DEBUG_AUDIO
   7.224 +	fprintf(stderr, "Wrote %d bytes of audio data\n", written);
   7.225 +#endif
   7.226 +}
   7.227 +
   7.228 +static Uint8
   7.229 +*OBSD_GetAudioBuf(_THIS)
   7.230 +{
   7.231 +    return(mixbuf);
   7.232 +}
   7.233 +
   7.234 +static void
   7.235 +OBSD_CloseAudio(_THIS)
   7.236 +{
   7.237 +    if(mixbuf != NULL) {
   7.238 +	SDL_FreeAudioMem(mixbuf);
   7.239 +	mixbuf = NULL;
   7.240 +    }
   7.241 +    if(audio_fd >= 0) {
   7.242 +	close(audio_fd);
   7.243 +	audio_fd = -1;
   7.244 +    }
   7.245 +}
   7.246 +
   7.247 +#ifdef DEBUG_AUDIO
   7.248 +void
   7.249 +OBSD_Status(_THIS)
   7.250 +{
   7.251 +    audio_info_t info;
   7.252 +
   7.253 +    if(ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
   7.254 +	fprintf(stderr,"AUDIO_GETINFO failed.\n");
   7.255 +	return;
   7.256 +    }
   7.257 +
   7.258 +    fprintf(stderr,"\n"
   7.259 +"[play/record info]\n"
   7.260 +"buffer size	:   %d bytes\n"
   7.261 +"sample rate	:   %i Hz\n"
   7.262 +"channels	:   %i\n"
   7.263 +"precision	:   %i-bit\n"
   7.264 +"encoding	:   0x%x\n"
   7.265 +"seek		:   %i\n"
   7.266 +"sample count	:   %i\n"
   7.267 +"EOF count	:   %i\n"
   7.268 +"paused		:   %s\n"
   7.269 +"error occured	:   %s\n"
   7.270 +"waiting		:   %s\n"
   7.271 +"active		:   %s\n"
   7.272 +"",
   7.273 +    info.play.buffer_size,
   7.274 +    info.play.sample_rate,
   7.275 +    info.play.channels,
   7.276 +    info.play.precision,
   7.277 +    info.play.encoding,
   7.278 +    info.play.seek,
   7.279 +    info.play.samples,
   7.280 +    info.play.eof,
   7.281 +    info.play.pause ? "yes" : "no",
   7.282 +    info.play.error ? "yes" : "no",
   7.283 +    info.play.waiting ? "yes" : "no",
   7.284 +    info.play.active ? "yes": "no");
   7.285 +
   7.286 +    fprintf(stderr,"\n"
   7.287 +"[audio info]\n"
   7.288 +"monitor_gain	:   %i\n"
   7.289 +"hw block size	:   %d bytes\n"
   7.290 +"hi watermark	:   %i\n"
   7.291 +"lo watermark	:   %i\n"
   7.292 +"audio mode	:   %s\n"
   7.293 +"",  
   7.294 +    info.monitor_gain,
   7.295 +    info.blocksize,
   7.296 +    info.hiwat, info.lowat,
   7.297 +    (info.mode == AUMODE_PLAY) ? "PLAY"
   7.298 +    : (info.mode = AUMODE_RECORD) ? "RECORD"
   7.299 +    : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL"
   7.300 +    : "?"));
   7.301 +}
   7.302 +#endif /* DEBUG_AUDIO */
   7.303 +
   7.304 +static int
   7.305 +OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec)
   7.306 +{
   7.307 +    char audiodev[64];
   7.308 +    Uint16 format;
   7.309 +    audio_info_t info;
   7.310 +
   7.311 +    AUDIO_INITINFO(&info);
   7.312 +    
   7.313 +    /* Calculate the final parameters for this audio specification */
   7.314 +    SDL_CalculateAudioSpec(spec);
   7.315 +
   7.316 +#ifdef USE_TIMER_SYNC
   7.317 +    frame_ticks = 0.0;
   7.318 +#endif
   7.319 +
   7.320 +    /* Open the audio device */
   7.321 +    audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
   7.322 +    if(audio_fd < 0) {
   7.323 +	SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
   7.324 +	return(-1);
   7.325 +    }
   7.326 +    
   7.327 +    /* Set to play mode */
   7.328 +    info.mode = AUMODE_PLAY;
   7.329 +    if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
   7.330 +	SDL_SetError("Couldn't put device into play mode");
   7.331 +	return(-1);
   7.332 +    }
   7.333 +    
   7.334 +    mixbuf = NULL;
   7.335 +    AUDIO_INITINFO(&info);
   7.336 +    for (format = SDL_FirstAudioFormat(spec->format); 
   7.337 +    	format; format = SDL_NextAudioFormat())
   7.338 +    {
   7.339 +	switch(format) {
   7.340 +	case AUDIO_U8:
   7.341 +	    info.play.encoding = AUDIO_ENCODING_ULINEAR;
   7.342 +	    info.play.precision = 8;
   7.343 +	    break;
   7.344 +	case AUDIO_S8:
   7.345 +	    info.play.encoding = AUDIO_ENCODING_SLINEAR;
   7.346 +	    info.play.precision = 8;
   7.347 +	    break;
   7.348 +	case AUDIO_S16LSB:
   7.349 +	    info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
   7.350 +	    info.play.precision = 16;
   7.351 +	    break;
   7.352 +	case AUDIO_S16MSB:
   7.353 +	    info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
   7.354 +	    info.play.precision = 16;
   7.355 +	    break;
   7.356 +	case AUDIO_U16LSB:
   7.357 +	    info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
   7.358 +	    info.play.precision = 16;
   7.359 +	    break;
   7.360 +	case AUDIO_U16MSB:
   7.361 +	    info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
   7.362 +	    info.play.precision = 16;
   7.363 +	    break;
   7.364 +	default:
   7.365 +	    continue;
   7.366 +	}
   7.367 +	if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0)
   7.368 +	    break;
   7.369 +    }
   7.370 +
   7.371 +    if(!format) {
   7.372 +	SDL_SetError("No supported encoding for 0x%x", spec->format);
   7.373 +	return(-1);
   7.374 +    }
   7.375 +
   7.376 +    spec->format = format;
   7.377 +
   7.378 +    AUDIO_INITINFO(&info);
   7.379 +    info.play.channels = spec->channels;
   7.380 +    if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1)
   7.381 +    	spec->channels = 1;
   7.382 +    AUDIO_INITINFO(&info);
   7.383 +    info.play.sample_rate = spec->freq;
   7.384 +    info.blocksize = spec->size;
   7.385 +    info.hiwat = 5;
   7.386 +    info.lowat = 3;
   7.387 +    (void)ioctl(audio_fd, AUDIO_SETINFO, &info);
   7.388 +    (void)ioctl(audio_fd, AUDIO_GETINFO, &info);
   7.389 +    spec->freq  = info.play.sample_rate;
   7.390 +    /* Allocate mixing buffer */
   7.391 +    mixlen = spec->size;
   7.392 +    mixbuf = (Uint8*)SDL_AllocAudioMem(mixlen);
   7.393 +    if(mixbuf == NULL) {
   7.394 +	return(-1);
   7.395 +    }
   7.396 +    SDL_memset(mixbuf, spec->silence, spec->size);
   7.397 +    
   7.398 +    /* Get the parent process id (we're the parent of the audio thread) */
   7.399 +    parent = getpid();
   7.400 +
   7.401 +#ifdef DEBUG_AUDIO
   7.402 +    OBSD_Status(this);
   7.403 +#endif
   7.404 +
   7.405 +    /* We're ready to rock and roll. :-) */
   7.406 +    return(0);
   7.407 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/audio/bsd/SDL_bsdaudio.h	Tue Mar 21 09:33:54 2006 +0000
     8.3 @@ -0,0 +1,58 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2004 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@libsdl.org
    8.24 +*/
    8.25 +#include "SDL_config.h"
    8.26 +
    8.27 +#ifndef _SDL_openbsdaudio_h
    8.28 +#define _SDL_openbsdaudio_h
    8.29 +
    8.30 +#include "../SDL_sysaudio.h"
    8.31 +
    8.32 +#define _THIS	SDL_AudioDevice *this
    8.33 +
    8.34 +struct SDL_PrivateAudioData
    8.35 +{
    8.36 +    /* The file descriptor for the audio device */
    8.37 +    int audio_fd;
    8.38 +
    8.39 +    /* The parent process id, to detect when application quits */
    8.40 +    pid_t parent;
    8.41 +
    8.42 +    /* Raw mixing buffer */
    8.43 +    Uint8 *mixbuf;
    8.44 +    int    mixlen;
    8.45 +
    8.46 +    /* Support for audio timing using a timer, in addition to select() */
    8.47 +    float frame_ticks;
    8.48 +    float next_frame;
    8.49 +};
    8.50 +
    8.51 +#define FUDGE_TICKS	10	/* The scheduler overhead ticks per frame */
    8.52 +
    8.53 +/* Old variable names */
    8.54 +#define audio_fd		(this->hidden->audio_fd)
    8.55 +#define parent			(this->hidden->parent)
    8.56 +#define mixbuf			(this->hidden->mixbuf)
    8.57 +#define mixlen			(this->hidden->mixlen)
    8.58 +#define frame_ticks		(this->hidden->frame_ticks)
    8.59 +#define next_frame		(this->hidden->next_frame)
    8.60 +
    8.61 +#endif /* _SDL_openbsdaudio_h */
     9.1 --- a/src/audio/openbsd/.cvsignore	Tue Mar 21 09:24:10 2006 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,6 +0,0 @@
     9.4 -Makefile.in
     9.5 -Makefile
     9.6 -.libs
     9.7 -*.o
     9.8 -*.lo
     9.9 -*.la
    10.1 --- a/src/audio/openbsd/SDL_openbsdaudio.c	Tue Mar 21 09:24:10 2006 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,406 +0,0 @@
    10.4 -/*
    10.5 -    SDL - Simple DirectMedia Layer
    10.6 -    Copyright (C) 1997-2004 Sam Lantinga
    10.7 -
    10.8 -    This library is free software; you can redistribute it and/or
    10.9 -    modify it under the terms of the GNU Library General Public
   10.10 -    License as published by the Free Software Foundation; either
   10.11 -    version 2 of the License, or (at your option) any later version.
   10.12 -
   10.13 -    This library is distributed in the hope that it will be useful,
   10.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10.16 -    Library General Public License for more details.
   10.17 -
   10.18 -    You should have received a copy of the GNU Library General Public
   10.19 -    License along with this library; if not, write to the Free
   10.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.21 -
   10.22 -    Sam Lantinga
   10.23 -    slouken@libsdl.org
   10.24 -*/
   10.25 -#include "SDL_config.h"
   10.26 -
   10.27 -/*
   10.28 - * Driver for native OpenBSD audio(4).
   10.29 - * vedge@vedge.com.ar.
   10.30 - */
   10.31 -
   10.32 -#include <errno.h>
   10.33 -#include <unistd.h>
   10.34 -#include <fcntl.h>
   10.35 -#include <sys/time.h>
   10.36 -#include <sys/ioctl.h>
   10.37 -#include <sys/stat.h>
   10.38 -#include <sys/types.h>
   10.39 -#include <sys/audioio.h>
   10.40 -
   10.41 -#include "SDL_timer.h"
   10.42 -#include "SDL_audio.h"
   10.43 -#include "../SDL_audiomem.h"
   10.44 -#include "../SDL_audio_c.h"
   10.45 -#include "../SDL_audiodev_c.h"
   10.46 -#include "SDL_openbsdaudio.h"
   10.47 -
   10.48 -/* The tag name used by NetBSD/OpenBSD audio */
   10.49 -#ifdef __NETBSD__
   10.50 -#define OBSD_DRIVER_NAME         "netbsd"
   10.51 -#else
   10.52 -#define OBSD_DRIVER_NAME         "openbsd"
   10.53 -#endif
   10.54 -
   10.55 -/* Open the audio device for playback, and don't block if busy */
   10.56 -/* #define USE_BLOCKING_WRITES */
   10.57 -
   10.58 -/* Use timer for synchronization */
   10.59 -/* #define USE_TIMER_SYNC */
   10.60 -
   10.61 -/* #define DEBUG_AUDIO */
   10.62 -/* #define DEBUG_AUDIO_STREAM */
   10.63 -
   10.64 -#ifdef USE_BLOCKING_WRITES
   10.65 -#define OPEN_FLAGS	O_WRONLY
   10.66 -#else
   10.67 -#define OPEN_FLAGS	(O_WRONLY|O_NONBLOCK)
   10.68 -#endif
   10.69 -
   10.70 -/* Audio driver functions */
   10.71 -static void OBSD_WaitAudio(_THIS);
   10.72 -static int OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec);
   10.73 -static void OBSD_PlayAudio(_THIS);
   10.74 -static Uint8 *OBSD_GetAudioBuf(_THIS);
   10.75 -static void OBSD_CloseAudio(_THIS);
   10.76 -
   10.77 -#ifdef DEBUG_AUDIO
   10.78 -static void OBSD_Status(_THIS);
   10.79 -#endif
   10.80 -
   10.81 -/* Audio driver bootstrap functions */
   10.82 -
   10.83 -static int
   10.84 -Audio_Available(void)
   10.85 -{
   10.86 -    int fd;
   10.87 -    int available;
   10.88 -
   10.89 -    available = 0;
   10.90 -    fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
   10.91 -    if(fd >= 0) {
   10.92 -	available = 1;
   10.93 -	close(fd);
   10.94 -    }
   10.95 -    return(available);
   10.96 -}
   10.97 -
   10.98 -static void
   10.99 -Audio_DeleteDevice(SDL_AudioDevice *device)
  10.100 -{
  10.101 -    SDL_free(device->hidden);
  10.102 -    SDL_free(device);
  10.103 -}
  10.104 -
  10.105 -static SDL_AudioDevice
  10.106 -*Audio_CreateDevice(int devindex)
  10.107 -{
  10.108 -    SDL_AudioDevice *this;
  10.109 -
  10.110 -    /* Initialize all variables that we clean on shutdown */
  10.111 -    this = (SDL_AudioDevice*)SDL_malloc(sizeof(SDL_AudioDevice));
  10.112 -    if(this) {
  10.113 -	SDL_memset(this, 0, (sizeof *this));
  10.114 -	this->hidden =
  10.115 -	    (struct SDL_PrivateAudioData*)SDL_malloc((sizeof *this->hidden));
  10.116 -    }
  10.117 -    if((this == NULL) || (this->hidden == NULL)) {
  10.118 -	SDL_OutOfMemory();
  10.119 -	if(this) SDL_free(this);
  10.120 -	return(0);
  10.121 -    }
  10.122 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
  10.123 -    audio_fd = -1;
  10.124 -
  10.125 -    /* Set the function pointers */
  10.126 -    this->OpenAudio = OBSD_OpenAudio;
  10.127 -    this->WaitAudio = OBSD_WaitAudio;
  10.128 -    this->PlayAudio = OBSD_PlayAudio;
  10.129 -    this->GetAudioBuf = OBSD_GetAudioBuf;
  10.130 -    this->CloseAudio = OBSD_CloseAudio;
  10.131 -
  10.132 -    this->free = Audio_DeleteDevice;
  10.133 -    
  10.134 -    return this;
  10.135 -}
  10.136 -
  10.137 -AudioBootStrap OPENBSD_AUDIO_bootstrap = {
  10.138 -#ifdef __NETBSD__
  10.139 -	OBSD_DRIVER_NAME, "Native NetBSD audio",
  10.140 -#else
  10.141 -	OBSD_DRIVER_NAME, "Native OpenBSD audio",
  10.142 -#endif
  10.143 -	Audio_Available, Audio_CreateDevice
  10.144 -};
  10.145 -
  10.146 -/* This function waits until it is possible to write a full sound buffer */
  10.147 -static void
  10.148 -OBSD_WaitAudio(_THIS)
  10.149 -{
  10.150 -#ifndef USE_BLOCKING_WRITES /* Not necessary when using blocking writes */
  10.151 -	/* See if we need to use timed audio synchronization */
  10.152 -	if ( frame_ticks ) {
  10.153 -		/* Use timer for general audio synchronization */
  10.154 -		Sint32 ticks;
  10.155 -
  10.156 -		ticks = ((Sint32)(next_frame - SDL_GetTicks()))-FUDGE_TICKS;
  10.157 -		if ( ticks > 0 ) {
  10.158 -			SDL_Delay(ticks);
  10.159 -		}
  10.160 -	} else {
  10.161 -		/* Use select() for audio synchronization */
  10.162 -		fd_set fdset;
  10.163 -		struct timeval timeout;
  10.164 -
  10.165 -		FD_ZERO(&fdset);
  10.166 -		FD_SET(audio_fd, &fdset);
  10.167 -		timeout.tv_sec = 10;
  10.168 -		timeout.tv_usec = 0;
  10.169 -#ifdef DEBUG_AUDIO
  10.170 -		fprintf(stderr, "Waiting for audio to get ready\n");
  10.171 -#endif
  10.172 -		if ( select(audio_fd+1, NULL, &fdset, NULL, &timeout) <= 0 ) {
  10.173 -			const char *message =
  10.174 -			"Audio timeout - buggy audio driver? (disabled)";
  10.175 -			/* In general we should never print to the screen,
  10.176 -			   but in this case we have no other way of letting
  10.177 -			   the user know what happened.
  10.178 -			*/
  10.179 -			fprintf(stderr, "SDL: %s\n", message);
  10.180 -			this->enabled = 0;
  10.181 -			/* Don't try to close - may hang */
  10.182 -			audio_fd = -1;
  10.183 -#ifdef DEBUG_AUDIO
  10.184 -			fprintf(stderr, "Done disabling audio\n");
  10.185 -#endif
  10.186 -		}
  10.187 -#ifdef DEBUG_AUDIO
  10.188 -		fprintf(stderr, "Ready!\n");
  10.189 -#endif
  10.190 -	}
  10.191 -#endif /* !USE_BLOCKING_WRITES */
  10.192 -}
  10.193 -
  10.194 -static void
  10.195 -OBSD_PlayAudio(_THIS)
  10.196 -{
  10.197 -	int written, p=0;
  10.198 -
  10.199 -	/* Write the audio data, checking for EAGAIN on broken audio drivers */
  10.200 -	do {
  10.201 -		written = write(audio_fd, &mixbuf[p], mixlen-p);
  10.202 -		if (written>0)
  10.203 -		   p += written;
  10.204 -		if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR)
  10.205 -		{
  10.206 -		   /* Non recoverable error has occurred. It should be reported!!! */
  10.207 -		   perror("audio");
  10.208 -		   break;
  10.209 -		}
  10.210 -
  10.211 -		if ( p < written || ((written < 0) && ((errno == 0) || (errno == EAGAIN))) ) {
  10.212 -			SDL_Delay(1);	/* Let a little CPU time go by */
  10.213 -		}
  10.214 -	} while ( p < written );
  10.215 -
  10.216 -	/* If timer synchronization is enabled, set the next write frame */
  10.217 -	if ( frame_ticks ) {
  10.218 -		next_frame += frame_ticks;
  10.219 -	}
  10.220 -
  10.221 -	/* If we couldn't write, assume fatal error for now */
  10.222 -	if ( written < 0 ) {
  10.223 -		this->enabled = 0;
  10.224 -	}
  10.225 -#ifdef DEBUG_AUDIO
  10.226 -	fprintf(stderr, "Wrote %d bytes of audio data\n", written);
  10.227 -#endif
  10.228 -}
  10.229 -
  10.230 -static Uint8
  10.231 -*OBSD_GetAudioBuf(_THIS)
  10.232 -{
  10.233 -    return(mixbuf);
  10.234 -}
  10.235 -
  10.236 -static void
  10.237 -OBSD_CloseAudio(_THIS)
  10.238 -{
  10.239 -    if(mixbuf != NULL) {
  10.240 -	SDL_FreeAudioMem(mixbuf);
  10.241 -	mixbuf = NULL;
  10.242 -    }
  10.243 -    if(audio_fd >= 0) {
  10.244 -	close(audio_fd);
  10.245 -	audio_fd = -1;
  10.246 -    }
  10.247 -}
  10.248 -
  10.249 -#ifdef DEBUG_AUDIO
  10.250 -void
  10.251 -OBSD_Status(_THIS)
  10.252 -{
  10.253 -    audio_info_t info;
  10.254 -
  10.255 -    if(ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
  10.256 -	fprintf(stderr,"AUDIO_GETINFO failed.\n");
  10.257 -	return;
  10.258 -    }
  10.259 -
  10.260 -    fprintf(stderr,"\n"
  10.261 -"[play/record info]\n"
  10.262 -"buffer size	:   %d bytes\n"
  10.263 -"sample rate	:   %i Hz\n"
  10.264 -"channels	:   %i\n"
  10.265 -"precision	:   %i-bit\n"
  10.266 -"encoding	:   0x%x\n"
  10.267 -"seek		:   %i\n"
  10.268 -"sample count	:   %i\n"
  10.269 -"EOF count	:   %i\n"
  10.270 -"paused		:   %s\n"
  10.271 -"error occured	:   %s\n"
  10.272 -"waiting		:   %s\n"
  10.273 -"active		:   %s\n"
  10.274 -"",
  10.275 -    info.play.buffer_size,
  10.276 -    info.play.sample_rate,
  10.277 -    info.play.channels,
  10.278 -    info.play.precision,
  10.279 -    info.play.encoding,
  10.280 -    info.play.seek,
  10.281 -    info.play.samples,
  10.282 -    info.play.eof,
  10.283 -    info.play.pause ? "yes" : "no",
  10.284 -    info.play.error ? "yes" : "no",
  10.285 -    info.play.waiting ? "yes" : "no",
  10.286 -    info.play.active ? "yes": "no");
  10.287 -
  10.288 -    fprintf(stderr,"\n"
  10.289 -"[audio info]\n"
  10.290 -"monitor_gain	:   %i\n"
  10.291 -"hw block size	:   %d bytes\n"
  10.292 -"hi watermark	:   %i\n"
  10.293 -"lo watermark	:   %i\n"
  10.294 -"audio mode	:   %s\n"
  10.295 -"",  
  10.296 -    info.monitor_gain,
  10.297 -    info.blocksize,
  10.298 -    info.hiwat, info.lowat,
  10.299 -    (info.mode == AUMODE_PLAY) ? "PLAY"
  10.300 -    : (info.mode = AUMODE_RECORD) ? "RECORD"
  10.301 -    : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL"
  10.302 -    : "?"));
  10.303 -}
  10.304 -#endif /* DEBUG_AUDIO */
  10.305 -
  10.306 -static int
  10.307 -OBSD_OpenAudio(_THIS, SDL_AudioSpec *spec)
  10.308 -{
  10.309 -    char audiodev[64];
  10.310 -    Uint16 format;
  10.311 -    audio_info_t info;
  10.312 -
  10.313 -    AUDIO_INITINFO(&info);
  10.314 -    
  10.315 -    /* Calculate the final parameters for this audio specification */
  10.316 -    SDL_CalculateAudioSpec(spec);
  10.317 -
  10.318 -#ifdef USE_TIMER_SYNC
  10.319 -    frame_ticks = 0.0;
  10.320 -#endif
  10.321 -
  10.322 -    /* Open the audio device */
  10.323 -    audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
  10.324 -    if(audio_fd < 0) {
  10.325 -	SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
  10.326 -	return(-1);
  10.327 -    }
  10.328 -    
  10.329 -    /* Set to play mode */
  10.330 -    info.mode = AUMODE_PLAY;
  10.331 -    if(ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
  10.332 -	SDL_SetError("Couldn't put device into play mode");
  10.333 -	return(-1);
  10.334 -    }
  10.335 -    
  10.336 -    mixbuf = NULL;
  10.337 -    AUDIO_INITINFO(&info);
  10.338 -    for (format = SDL_FirstAudioFormat(spec->format); 
  10.339 -    	format; format = SDL_NextAudioFormat())
  10.340 -    {
  10.341 -	switch(format) {
  10.342 -	case AUDIO_U8:
  10.343 -	    info.play.encoding = AUDIO_ENCODING_ULINEAR;
  10.344 -	    info.play.precision = 8;
  10.345 -	    break;
  10.346 -	case AUDIO_S8:
  10.347 -	    info.play.encoding = AUDIO_ENCODING_SLINEAR;
  10.348 -	    info.play.precision = 8;
  10.349 -	    break;
  10.350 -	case AUDIO_S16LSB:
  10.351 -	    info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
  10.352 -	    info.play.precision = 16;
  10.353 -	    break;
  10.354 -	case AUDIO_S16MSB:
  10.355 -	    info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
  10.356 -	    info.play.precision = 16;
  10.357 -	    break;
  10.358 -	case AUDIO_U16LSB:
  10.359 -	    info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
  10.360 -	    info.play.precision = 16;
  10.361 -	    break;
  10.362 -	case AUDIO_U16MSB:
  10.363 -	    info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
  10.364 -	    info.play.precision = 16;
  10.365 -	    break;
  10.366 -	default:
  10.367 -	    continue;
  10.368 -	}
  10.369 -	if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0)
  10.370 -	    break;
  10.371 -    }
  10.372 -
  10.373 -    if(!format) {
  10.374 -	SDL_SetError("No supported encoding for 0x%x", spec->format);
  10.375 -	return(-1);
  10.376 -    }
  10.377 -
  10.378 -    spec->format = format;
  10.379 -
  10.380 -    AUDIO_INITINFO(&info);
  10.381 -    info.play.channels = spec->channels;
  10.382 -    if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1)
  10.383 -    	spec->channels = 1;
  10.384 -    AUDIO_INITINFO(&info);
  10.385 -    info.play.sample_rate = spec->freq;
  10.386 -    info.blocksize = spec->size;
  10.387 -    info.hiwat = 5;
  10.388 -    info.lowat = 3;
  10.389 -    (void)ioctl(audio_fd, AUDIO_SETINFO, &info);
  10.390 -    (void)ioctl(audio_fd, AUDIO_GETINFO, &info);
  10.391 -    spec->freq  = info.play.sample_rate;
  10.392 -    /* Allocate mixing buffer */
  10.393 -    mixlen = spec->size;
  10.394 -    mixbuf = (Uint8*)SDL_AllocAudioMem(mixlen);
  10.395 -    if(mixbuf == NULL) {
  10.396 -	return(-1);
  10.397 -    }
  10.398 -    SDL_memset(mixbuf, spec->silence, spec->size);
  10.399 -    
  10.400 -    /* Get the parent process id (we're the parent of the audio thread) */
  10.401 -    parent = getpid();
  10.402 -
  10.403 -#ifdef DEBUG_AUDIO
  10.404 -    OBSD_Status(this);
  10.405 -#endif
  10.406 -
  10.407 -    /* We're ready to rock and roll. :-) */
  10.408 -    return(0);
  10.409 -}
    11.1 --- a/src/audio/openbsd/SDL_openbsdaudio.h	Tue Mar 21 09:24:10 2006 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,58 +0,0 @@
    11.4 -/*
    11.5 -    SDL - Simple DirectMedia Layer
    11.6 -    Copyright (C) 1997-2004 Sam Lantinga
    11.7 -
    11.8 -    This library is free software; you can redistribute it and/or
    11.9 -    modify it under the terms of the GNU Library General Public
   11.10 -    License as published by the Free Software Foundation; either
   11.11 -    version 2 of the License, or (at your option) any later version.
   11.12 -
   11.13 -    This library is distributed in the hope that it will be useful,
   11.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 -    Library General Public License for more details.
   11.17 -
   11.18 -    You should have received a copy of the GNU Library General Public
   11.19 -    License along with this library; if not, write to the Free
   11.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.21 -
   11.22 -    Sam Lantinga
   11.23 -    slouken@libsdl.org
   11.24 -*/
   11.25 -#include "SDL_config.h"
   11.26 -
   11.27 -#ifndef _SDL_openbsdaudio_h
   11.28 -#define _SDL_openbsdaudio_h
   11.29 -
   11.30 -#include "../SDL_sysaudio.h"
   11.31 -
   11.32 -#define _THIS	SDL_AudioDevice *this
   11.33 -
   11.34 -struct SDL_PrivateAudioData
   11.35 -{
   11.36 -    /* The file descriptor for the audio device */
   11.37 -    int audio_fd;
   11.38 -
   11.39 -    /* The parent process id, to detect when application quits */
   11.40 -    pid_t parent;
   11.41 -
   11.42 -    /* Raw mixing buffer */
   11.43 -    Uint8 *mixbuf;
   11.44 -    int    mixlen;
   11.45 -
   11.46 -    /* Support for audio timing using a timer, in addition to select() */
   11.47 -    float frame_ticks;
   11.48 -    float next_frame;
   11.49 -};
   11.50 -
   11.51 -#define FUDGE_TICKS	10	/* The scheduler overhead ticks per frame */
   11.52 -
   11.53 -/* Old variable names */
   11.54 -#define audio_fd		(this->hidden->audio_fd)
   11.55 -#define parent			(this->hidden->parent)
   11.56 -#define mixbuf			(this->hidden->mixbuf)
   11.57 -#define mixlen			(this->hidden->mixlen)
   11.58 -#define frame_ticks		(this->hidden->frame_ticks)
   11.59 -#define next_frame		(this->hidden->next_frame)
   11.60 -
   11.61 -#endif /* _SDL_openbsdaudio_h */