Added an SDL2 OpenBSD sndio(7) audio target.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 07 Jul 2013 02:03:07 -0400
changeset 7367d6eabafa8776
parent 7366 38c6f26bb010
child 7368 0e12e09df086
Added an SDL2 OpenBSD sndio(7) audio target.
CMakeLists.txt
cmake/sdlchecks.cmake
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
src/audio/SDL_audio.c
src/audio/sndio/SDL_sndioaudio.c
src/audio/sndio/SDL_sndioaudio.h
     1.1 --- a/CMakeLists.txt	Sun Jul 07 02:04:19 2013 -0400
     1.2 +++ b/CMakeLists.txt	Sun Jul 07 02:03:07 2013 -0400
     1.3 @@ -203,6 +203,7 @@
     1.4  set_option(ARTS                "Support the Analog Real Time Synthesizer" ${UNIX_SYS})
     1.5  dep_option(ARTS_SHARED         "Dynamically load aRts audio support" ON "ARTS" OFF)
     1.6  set_option(NAS                 "Support the NAS audio API" ${UNIX_SYS})
     1.7 +set_option(SNDIO               "Support the sndio audio API" ${UNIX_SYS})
     1.8  set_option(RPATH               "Use an rpath when linking SDL" ${UNIX_SYS})
     1.9  set_option(CLOCK_GETTIME       "Use clock_gettime() instead of gettimeofday()" OFF)
    1.10  set_option(INPUT_TSLIB         "Use the Touchscreen library for input" ${UNIX_SYS})
    1.11 @@ -621,6 +622,7 @@
    1.12      CheckESD()
    1.13      CheckARTS()
    1.14      CheckNAS()
    1.15 +    CheckSNDIO()
    1.16      CheckFusionSound()
    1.17    endif(SDL_AUDIO)
    1.18  
     2.1 --- a/cmake/sdlchecks.cmake	Sun Jul 07 02:04:19 2013 -0400
     2.2 +++ b/cmake/sdlchecks.cmake	Sun Jul 07 02:03:07 2013 -0400
     2.3 @@ -226,6 +226,37 @@
     2.4  endmacro(CheckNAS)
     2.5  
     2.6  # Requires:
     2.7 +# - n/a
     2.8 +# Optional:
     2.9 +# - SNDIO_SHARED opt
    2.10 +# - HAVE_DLOPEN opt
    2.11 +macro(CheckSNDIO)
    2.12 +  if(SNDIO)
    2.13 +    # TODO: set include paths properly, so the sndio headers are found
    2.14 +    check_include_file(sndio.h HAVE_SNDIO_H)
    2.15 +    find_library(D_SNDIO_LIB audio)
    2.16 +    if(HAVE_SNDIO_H AND D_SNDIO_LIB)
    2.17 +      set(HAVE_SNDIO TRUE)
    2.18 +      file(GLOB SNDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sndio/*.c)
    2.19 +      set(SOURCE_FILES ${SOURCE_FILES} ${SNDIO_SOURCES})
    2.20 +      set(SDL_AUDIO_DRIVER_SNDIO 1)
    2.21 +      if(SNDIO_SHARED)
    2.22 +        if(NOT HAVE_DLOPEN)
    2.23 +          message_warn("You must have SDL_LoadObject() support for dynamic sndio loading")
    2.24 +        else()
    2.25 +          get_filename_component(F_SNDIO_LIB ${D_SNDIO_LIB} NAME)
    2.26 +          set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${F_SNDIO_LIB}\"")
    2.27 +          set(HAVE_SNDIO_SHARED TRUE)
    2.28 +        endif(NOT HAVE_DLOPEN)
    2.29 +      else(SNDIO_SHARED)
    2.30 +        list(APPEND EXTRA_LIBS ${D_SNDIO_LIB})
    2.31 +      endif(SNDIO_SHARED)
    2.32 +      set(HAVE_SDL_AUDIO TRUE)
    2.33 +    endif(HAVE_SNDIO_H AND D_SNDIO_LIB)
    2.34 +  endif(SNDIO)
    2.35 +endmacro(CheckSNDIO)
    2.36 +
    2.37 +# Requires:
    2.38  # - PkgCheckModules
    2.39  # Optional:
    2.40  # - FUSIONSOUND_SHARED opt
     3.1 --- a/configure.in	Sun Jul 07 02:04:19 2013 -0400
     3.2 +++ b/configure.in	Sun Jul 07 02:03:07 2013 -0400
     3.3 @@ -910,6 +910,52 @@
     3.4      fi
     3.5  }
     3.6  
     3.7 +dnl See if the sndio audio interface is supported
     3.8 +CheckSNDIO()
     3.9 +{
    3.10 +    AC_ARG_ENABLE(sndio,
    3.11 +AC_HELP_STRING([--enable-sndio], [support the sndio audio API [[default=yes]]]),
    3.12 +                  , enable_sndio=yes)
    3.13 +    if test x$enable_audio = xyes -a x$enable_sndio = xyes; then
    3.14 +        AC_CHECK_HEADER(sndio.h, have_sndio_hdr=yes)
    3.15 +        AC_CHECK_LIB(sndio, sio_open, have_sndio_lib=yes)
    3.16 +
    3.17 +        AC_MSG_CHECKING(for sndio audio support)
    3.18 +        have_sndio=no
    3.19 +
    3.20 +        if test x$have_sndio_hdr = xyes -a x$have_sndio_lib = xyes; then
    3.21 +            have_sndio=yes
    3.22 +            SNDIO_LIBS="-lsndio"
    3.23 +        fi
    3.24 +
    3.25 +        AC_MSG_RESULT($have_sndio)
    3.26 +
    3.27 +        if test x$have_sndio = xyes; then
    3.28 +            AC_ARG_ENABLE(sndio-shared,
    3.29 +AC_HELP_STRING([--enable-sndio-shared], [dynamically load sndio audio support [[default=yes]]]),
    3.30 +                          , enable_sndio_shared=yes)
    3.31 +            sndio_lib=[`find_lib "libsndio.so.*" "$SNDIO_LIBS" | sed 's/.*\/\(.*\)/\1/; q'`]
    3.32 +
    3.33 +            if test x$have_loadso != xyes && \
    3.34 +               test x$enable_sndio_shared = xyes; then
    3.35 +                AC_MSG_WARN([You must have SDL_LoadObject() support for dynamic sndio loading])
    3.36 +            fi
    3.37 +            if test x$have_loadso = xyes && \
    3.38 +               test x$enable_sndio_shared = xyes && test x$sndio_lib != x; then
    3.39 +                echo "-- dynamic libsndio -> $sndio_lib"
    3.40 +                AC_DEFINE_UNQUOTED(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC, "$sndio_lib", [ ])
    3.41 +            else
    3.42 +                EXTRA_LDFLAGS="$EXTRA_LDFLAGS $SNDIO_LIBS"
    3.43 +            fi
    3.44 +
    3.45 +            AC_DEFINE(SDL_AUDIO_DRIVER_SNDIO, 1, [ ])
    3.46 +            SOURCES="$SOURCES $srcdir/src/audio/sndio/*.c"
    3.47 +            EXTRA_CFLAGS="$EXTRA_CFLAGS $SNDIO_CFLAGS"
    3.48 +            have_audio=yes
    3.49 +        fi
    3.50 +    fi
    3.51 +}
    3.52 +
    3.53  dnl rcg07142001 See if the user wants the disk writer audio driver...
    3.54  CheckDiskAudio()
    3.55  {
    3.56 @@ -2262,6 +2308,7 @@
    3.57          CheckARTSC
    3.58          CheckESD
    3.59          CheckNAS
    3.60 +        CheckSNDIO
    3.61          CheckX11
    3.62          CheckDirectFB
    3.63          CheckFusionSound
     4.1 --- a/include/SDL_config.h.cmake	Sun Jul 07 02:04:19 2013 -0400
     4.2 +++ b/include/SDL_config.h.cmake	Sun Jul 07 02:03:07 2013 -0400
     4.3 @@ -195,6 +195,8 @@
     4.4  #cmakedefine SDL_AUDIO_DRIVER_ESD_DYNAMIC @SDL_AUDIO_DRIVER_ESD_DYNAMIC@
     4.5  #cmakedefine SDL_AUDIO_DRIVER_NAS @SDL_AUDIO_DRIVER_NAS@
     4.6  #cmakedefine SDL_AUDIO_DRIVER_NAS_DYNAMIC @SDL_AUDIO_DRIVER_NAS_DYNAMIC@
     4.7 +#cmakedefine SDL_AUDIO_DRIVER_SNDIO @SDL_AUDIO_DRIVER_SNDIO@
     4.8 +#cmakedefine SDL_AUDIO_DRIVER_SNDIO_DYNAMIC @SDL_AUDIO_DRIVER_SNDIO_DYNAMIC@
     4.9  #cmakedefine SDL_AUDIO_DRIVER_OSS @SDL_AUDIO_DRIVER_OSS@
    4.10  #cmakedefine SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H @SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H@
    4.11  #cmakedefine SDL_AUDIO_DRIVER_PAUDIO @SDL_AUDIO_DRIVER_PAUDIO@
     5.1 --- a/include/SDL_config.h.in	Sun Jul 07 02:04:19 2013 -0400
     5.2 +++ b/include/SDL_config.h.in	Sun Jul 07 02:03:07 2013 -0400
     5.3 @@ -199,6 +199,8 @@
     5.4  #undef SDL_AUDIO_DRIVER_ESD_DYNAMIC
     5.5  #undef SDL_AUDIO_DRIVER_NAS
     5.6  #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC
     5.7 +#undef SDL_AUDIO_DRIVER_SNDIO
     5.8 +#undef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
     5.9  #undef SDL_AUDIO_DRIVER_OSS
    5.10  #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
    5.11  #undef SDL_AUDIO_DRIVER_PAUDIO
     6.1 --- a/src/audio/SDL_audio.c	Sun Jul 07 02:04:19 2013 -0400
     6.2 +++ b/src/audio/SDL_audio.c	Sun Jul 07 02:03:07 2013 -0400
     6.3 @@ -67,6 +67,7 @@
     6.4  extern AudioBootStrap FUSIONSOUND_bootstrap;
     6.5  extern AudioBootStrap ANDROIDAUD_bootstrap;
     6.6  extern AudioBootStrap PSPAUD_bootstrap;
     6.7 +extern AudioBootStrap SNDIO_bootstrap;
     6.8  
     6.9  /* Available audio drivers */
    6.10  static const AudioBootStrap *const bootstrap[] = {
    6.11 @@ -76,6 +77,9 @@
    6.12  #if SDL_AUDIO_DRIVER_ALSA
    6.13      &ALSA_bootstrap,
    6.14  #endif
    6.15 +#if SDL_AUDIO_DRIVER_SNDIO
    6.16 +    &SNDIO_bootstrap,
    6.17 +#endif
    6.18  #if SDL_AUDIO_DRIVER_BSD
    6.19      &BSD_AUDIO_bootstrap,
    6.20  #endif
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/audio/sndio/SDL_sndioaudio.c	Sun Jul 07 02:03:07 2013 -0400
     7.3 @@ -0,0 +1,327 @@
     7.4 +/*
     7.5 +  Simple DirectMedia Layer
     7.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     7.7 +
     7.8 +  This software is provided 'as-is', without any express or implied
     7.9 +  warranty.  In no event will the authors be held liable for any damages
    7.10 +  arising from the use of this software.
    7.11 +
    7.12 +  Permission is granted to anyone to use this software for any purpose,
    7.13 +  including commercial applications, and to alter it and redistribute it
    7.14 +  freely, subject to the following restrictions:
    7.15 +
    7.16 +  1. The origin of this software must not be misrepresented; you must not
    7.17 +     claim that you wrote the original software. If you use this software
    7.18 +     in a product, an acknowledgment in the product documentation would be
    7.19 +     appreciated but is not required.
    7.20 +  2. Altered source versions must be plainly marked as such, and must not be
    7.21 +     misrepresented as being the original software.
    7.22 +  3. This notice may not be removed or altered from any source distribution.
    7.23 +*/
    7.24 +
    7.25 +#include "SDL_config.h"
    7.26 +
    7.27 +#if SDL_AUDIO_DRIVER_SNDIO
    7.28 +
    7.29 +/* OpenBSD sndio target */
    7.30 +
    7.31 +#if HAVE_STDIO_H
    7.32 +#include <stdio.h>
    7.33 +#endif
    7.34 +
    7.35 +#ifdef HAVE_SIGNAL_H
    7.36 +#include <signal.h>
    7.37 +#endif
    7.38 +
    7.39 +#include <unistd.h>
    7.40 +
    7.41 +#include "SDL_audio.h"
    7.42 +#include "../SDL_audiomem.h"
    7.43 +#include "../SDL_audio_c.h"
    7.44 +#include "SDL_sndioaudio.h"
    7.45 +
    7.46 +#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
    7.47 +#include "SDL_loadso.h"
    7.48 +#endif
    7.49 +
    7.50 +static struct sio_hdl * (*SNDIO_sio_open)(const char *, unsigned int, int);
    7.51 +static void (*SNDIO_sio_close)(struct sio_hdl *);
    7.52 +static int (*SNDIO_sio_setpar)(struct sio_hdl *, struct sio_par *);
    7.53 +static int (*SNDIO_sio_getpar)(struct sio_hdl *, struct sio_par *);
    7.54 +static int (*SNDIO_sio_start)(struct sio_hdl *);
    7.55 +static int (*SNDIO_sio_stop)(struct sio_hdl *);
    7.56 +static size_t (*SNDIO_sio_read)(struct sio_hdl *, void *, size_t);
    7.57 +static size_t (*SNDIO_sio_write)(struct sio_hdl *, const void *, size_t);
    7.58 +static void (*SNDIO_sio_initpar)(struct sio_par *);
    7.59 +
    7.60 +#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
    7.61 +static const char *sndio_library = SDL_AUDIO_DRIVER_SNDIO_DYNAMIC;
    7.62 +static void *sndio_handle = NULL;
    7.63 +
    7.64 +static int
    7.65 +load_sndio_sym(const char *fn, void **addr)
    7.66 +{
    7.67 +    *addr = SDL_LoadFunction(sndio_handle, fn);
    7.68 +    if (*addr == NULL) {
    7.69 +        /* Don't call SDL_SetError(): SDL_LoadFunction already did. */
    7.70 +        return 0;
    7.71 +    }
    7.72 +
    7.73 +    return 1;
    7.74 +}
    7.75 +
    7.76 +/* cast funcs to char* first, to please GCC's strict aliasing rules. */
    7.77 +#define SDL_SNDIO_SYM(x) \
    7.78 +    if (!load_sndio_sym(#x, (void **) (char *) &SNDIO_##x)) return -1
    7.79 +#else
    7.80 +#define SDL_SNDIO_SYM(x) SNDIO_##x = x
    7.81 +#endif
    7.82 +
    7.83 +static int
    7.84 +load_sndio_syms(void)
    7.85 +{
    7.86 +    SDL_SNDIO_SYM(sio_open);
    7.87 +    SDL_SNDIO_SYM(sio_close);
    7.88 +    SDL_SNDIO_SYM(sio_setpar);
    7.89 +    SDL_SNDIO_SYM(sio_getpar);
    7.90 +    SDL_SNDIO_SYM(sio_start);
    7.91 +    SDL_SNDIO_SYM(sio_stop);
    7.92 +    SDL_SNDIO_SYM(sio_read);
    7.93 +    SDL_SNDIO_SYM(sio_write);
    7.94 +    SDL_SNDIO_SYM(sio_initpar);
    7.95 +    return 0;
    7.96 +}
    7.97 +
    7.98 +#undef SDL_SNDIO_SYM
    7.99 +
   7.100 +#ifdef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC
   7.101 +
   7.102 +static void
   7.103 +UnloadSNDIOLibrary(void)
   7.104 +{
   7.105 +    if (sndio_handle != NULL) {
   7.106 +        SDL_UnloadObject(sndio_handle);
   7.107 +        sndio_handle = NULL;
   7.108 +    }
   7.109 +}
   7.110 +
   7.111 +static int
   7.112 +LoadSNDIOLibrary(void)
   7.113 +{
   7.114 +    int retval = 0;
   7.115 +    if (sndio_handle == NULL) {
   7.116 +        sndio_handle = SDL_LoadObject(sndio_library);
   7.117 +        if (sndio_handle == NULL) {
   7.118 +            retval = -1;
   7.119 +            /* Don't call SDL_SetError(): SDL_LoadObject already did. */
   7.120 +        } else {
   7.121 +            retval = load_sndio_syms();
   7.122 +            if (retval < 0) {
   7.123 +                UnloadSNDIOLibrary();
   7.124 +            }
   7.125 +        }
   7.126 +    }
   7.127 +    return retval;
   7.128 +}
   7.129 +
   7.130 +#else
   7.131 +
   7.132 +static void
   7.133 +UnloadSNDIOLibrary(void)
   7.134 +{
   7.135 +}
   7.136 +
   7.137 +static int
   7.138 +LoadSNDIOLibrary(void)
   7.139 +{
   7.140 +    load_sndio_syms();
   7.141 +    return 0;
   7.142 +}
   7.143 +
   7.144 +#endif /* SDL_AUDIO_DRIVER_SNDIO_DYNAMIC */
   7.145 +
   7.146 +
   7.147 +
   7.148 +
   7.149 +static void
   7.150 +SNDIO_WaitDevice(_THIS)
   7.151 +{
   7.152 +    /* no-op; sio_write() blocks if necessary. */
   7.153 +}
   7.154 +
   7.155 +static void
   7.156 +SNDIO_PlayDevice(_THIS)
   7.157 +{
   7.158 +    const int written = sio_write(this->hidden->dev, this->hidden->mixbuf, this->hidden->mixlen);
   7.159 +
   7.160 +    /* If we couldn't write, assume fatal error for now */
   7.161 +    if ( written == 0 ) {
   7.162 +        this->enabled = 0;
   7.163 +    }
   7.164 +#ifdef DEBUG_AUDIO
   7.165 +    fprintf(stderr, "Wrote %d bytes of audio data\n", written);
   7.166 +#endif
   7.167 +}
   7.168 +
   7.169 +static Uint8 *
   7.170 +SNDIO_GetDeviceBuf(_THIS)
   7.171 +{
   7.172 +    return this->hidden->mixbuf;
   7.173 +}
   7.174 +
   7.175 +static void
   7.176 +SNDIO_WaitDone(_THIS)
   7.177 +{
   7.178 +    sio_stop(this->hidden->dev);
   7.179 +}
   7.180 +
   7.181 +static void
   7.182 +SNDIO_CloseDevice(_THIS)
   7.183 +{
   7.184 +    if (this->hidden != NULL) {
   7.185 +        if (this->hidden->mixbuf != NULL) {
   7.186 +            SDL_FreeAudioMem(this->hidden->mixbuf);
   7.187 +            this->hidden->mixbuf = NULL;
   7.188 +        }
   7.189 +        if ( this->hidden->dev != NULL ) {
   7.190 +            sio_close(this->hidden->dev);
   7.191 +            this->hidden->dev = NULL;
   7.192 +        }
   7.193 +        SDL_free(this->hidden);
   7.194 +        this->hidden = NULL;
   7.195 +    }
   7.196 +}
   7.197 +
   7.198 +static int
   7.199 +SNDIO_OpenDevice(_THIS, const char *devname, int iscapture)
   7.200 +{
   7.201 +    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
   7.202 +    struct sio_par par;
   7.203 +    int status;
   7.204 +
   7.205 +    this->hidden = (struct SDL_PrivateAudioData *)
   7.206 +        SDL_malloc(sizeof(*this->hidden));
   7.207 +    if (this->hidden == NULL) {
   7.208 +        return SDL_OutOfMemory();
   7.209 +    }
   7.210 +    SDL_memset(this->hidden, 0, sizeof(*this->hidden));
   7.211 +
   7.212 +    this->hidden->mixlen = this->spec.size;
   7.213 +
   7.214 +    /* !!! FIXME: SIO_DEVANY can be a specific device... */
   7.215 +    if ((this->hidden->dev = sio_open(0 /*SIO_DEVANY*/, SIO_PLAY, 0)) == NULL) {
   7.216 +        SNDIO_CloseDevice(this);
   7.217 +        return SDL_SetError("sio_open() failed");
   7.218 +    }
   7.219 +
   7.220 +    sio_initpar(&par);
   7.221 +
   7.222 +    par.rate = this->spec.freq;
   7.223 +    par.pchan = this->spec.channels;
   7.224 +    par.round = this->spec.samples;
   7.225 +    par.appbufsz = par.round * 2;
   7.226 +
   7.227 +    /* Try for a closest match on audio format */
   7.228 +    status = -1;
   7.229 +    while (test_format && (status < 0)) {
   7.230 +        if (!SDL_AUDIO_ISFLOAT(test_format)) {
   7.231 +            par.le = SDL_AUDIO_ISLITTLEENDIAN(test_format) ? 1 : 0;
   7.232 +            par.sig = SDL_AUDIO_ISSIGNED(test_format) ? 1 : 0;
   7.233 +            par.bits = SDL_AUDIO_BITSIZE(test_format);
   7.234 +
   7.235 +            if (sio_setpar(this->hidden->dev, &par) == 1) {
   7.236 +                status = 0;
   7.237 +                break;
   7.238 +            }
   7.239 +        }
   7.240 +        test_format = SDL_NextAudioFormat();
   7.241 +    }
   7.242 +
   7.243 +    if (status < 0) {
   7.244 +        SNDIO_CloseDevice(this);
   7.245 +        return SDL_SetError("sndio: Couldn't find any hardware audio formats");
   7.246 +    }
   7.247 +
   7.248 +    if (sio_getpar(this->hidden->dev, &par) == 0) {
   7.249 +        SNDIO_CloseDevice(this);
   7.250 +        return SDL_SetError("sio_getpar() failed");
   7.251 +    }
   7.252 +
   7.253 +    if ((par.bits == 32) && (par.sig) && (par.le))
   7.254 +        this->spec.format = AUDIO_S32LSB;
   7.255 +    else if ((par.bits == 32) && (par.sig) && (!par.le))
   7.256 +        this->spec.format = AUDIO_S32MSB;
   7.257 +    else if ((par.bits == 16) && (par.sig) && (par.le))
   7.258 +        this->spec.format = AUDIO_S16LSB;
   7.259 +    else if ((par.bits == 16) && (par.sig) && (!par.le))
   7.260 +        this->spec.format = AUDIO_S16MSB;
   7.261 +    else if ((par.bits == 16) && (!par.sig) && (par.le))
   7.262 +        this->spec.format = AUDIO_U16LSB;
   7.263 +    else if ((par.bits == 16) && (!par.sig) && (!par.le))
   7.264 +        this->spec.format = AUDIO_U16MSB;
   7.265 +    else if ((par.bits == 8) && (par.sig))
   7.266 +        this->spec.format = AUDIO_S8;
   7.267 +    else if ((par.bits == 8) && (!par.sig))
   7.268 +        this->spec.format = AUDIO_U8;
   7.269 +    else {
   7.270 +        SNDIO_CloseDevice(this);
   7.271 +        return SDL_SetError("sndio: Got unsupported hardware audio format.");
   7.272 +    }
   7.273 +
   7.274 +    this->spec.freq = par.rate;
   7.275 +    this->spec.channels = par.pchan;
   7.276 +    this->spec.samples = par.round;
   7.277 +
   7.278 +    /* Calculate the final parameters for this audio specification */
   7.279 +    SDL_CalculateAudioSpec(&this->spec);
   7.280 +
   7.281 +    /* Allocate mixing buffer */
   7.282 +    this->hidden->mixlen = this->spec.size;
   7.283 +    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
   7.284 +    if (this->hidden->mixbuf == NULL) {
   7.285 +        SNDIO_CloseDevice(this);
   7.286 +        return SDL_OutOfMemory();
   7.287 +    }
   7.288 +    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->hidden->mixlen);
   7.289 +
   7.290 +    if (!sio_start(this->hidden->dev)) {
   7.291 +        return SDL_SetError("sio_start() failed");
   7.292 +    }
   7.293 +
   7.294 +    /* We're ready to rock and roll. :-) */
   7.295 +    return 0;
   7.296 +}
   7.297 +
   7.298 +static void
   7.299 +SNDIO_Deinitialize(void)
   7.300 +{
   7.301 +    UnloadSNDIOLibrary();
   7.302 +}
   7.303 +
   7.304 +static int
   7.305 +SNDIO_Init(SDL_AudioDriverImpl * impl)
   7.306 +{
   7.307 +    if (LoadSNDIOLibrary() < 0) {
   7.308 +        return 0;
   7.309 +    }
   7.310 +
   7.311 +    /* Set the function pointers */
   7.312 +    impl->OpenDevice = SNDIO_OpenDevice;
   7.313 +    impl->WaitDevice = SNDIO_WaitDevice;
   7.314 +    impl->PlayDevice = SNDIO_PlayDevice;
   7.315 +    impl->GetDeviceBuf = SNDIO_GetDeviceBuf;
   7.316 +    impl->WaitDone = SNDIO_WaitDone;
   7.317 +    impl->CloseDevice = SNDIO_CloseDevice;
   7.318 +    impl->Deinitialize = SNDIO_Deinitialize;
   7.319 +    impl->OnlyHasDefaultOutputDevice = 1;  /* !!! FIXME: sndio can handle multiple devices. */
   7.320 +
   7.321 +    return 1;   /* this audio target is available. */
   7.322 +}
   7.323 +
   7.324 +AudioBootStrap SNDIO_bootstrap = {
   7.325 +    "sndio", "OpenBSD sndio", SNDIO_Init, 0
   7.326 +};
   7.327 +
   7.328 +#endif /* SDL_AUDIO_DRIVER_SNDIO */
   7.329 +
   7.330 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/audio/sndio/SDL_sndioaudio.h	Sun Jul 07 02:03:07 2013 -0400
     8.3 @@ -0,0 +1,45 @@
     8.4 +/*
     8.5 +  Simple DirectMedia Layer
     8.6 +  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
     8.7 +
     8.8 +  This software is provided 'as-is', without any express or implied
     8.9 +  warranty.  In no event will the authors be held liable for any damages
    8.10 +  arising from the use of this software.
    8.11 +
    8.12 +  Permission is granted to anyone to use this software for any purpose,
    8.13 +  including commercial applications, and to alter it and redistribute it
    8.14 +  freely, subject to the following restrictions:
    8.15 +
    8.16 +  1. The origin of this software must not be misrepresented; you must not
    8.17 +     claim that you wrote the original software. If you use this software
    8.18 +     in a product, an acknowledgment in the product documentation would be
    8.19 +     appreciated but is not required.
    8.20 +  2. Altered source versions must be plainly marked as such, and must not be
    8.21 +     misrepresented as being the original software.
    8.22 +  3. This notice may not be removed or altered from any source distribution.
    8.23 +*/
    8.24 +#include "SDL_config.h"
    8.25 +
    8.26 +#ifndef _SDL_sndioaudio_h
    8.27 +#define _SDL_sndioaudio_h
    8.28 +
    8.29 +#include <sndio.h>
    8.30 +
    8.31 +#include "../SDL_sysaudio.h"
    8.32 +
    8.33 +/* Hidden "this" pointer for the audio functions */
    8.34 +#define _THIS   SDL_AudioDevice *this
    8.35 +
    8.36 +struct SDL_PrivateAudioData
    8.37 +{
    8.38 +    /* The audio device handle */
    8.39 +    struct sio_hdl *dev;
    8.40 +
    8.41 +    /* Raw mixing buffer */
    8.42 +    Uint8 *mixbuf;
    8.43 +    int mixlen;
    8.44 +};
    8.45 +
    8.46 +#endif /* _SDL_sndioaudio_h */
    8.47 +
    8.48 +/* vi: set ts=4 sw=4 expandtab: */