audio: rename bsd target to netbsd.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 24 May 2017 19:56:59 -0400
changeset 1102825cd7fe50180
parent 11027 0bd1fbe480e0
child 11029 938d2ced5244
audio: rename bsd target to netbsd.

Apparently this is no longer a generic BSD audio target, and hasn't been for
years, so rename it for NetBSD.
CMakeLists.txt
configure
configure.in
include/SDL_config.h.cmake
include/SDL_config.h.in
src/audio/SDL_audio.c
src/audio/SDL_audiodev.c
src/audio/SDL_sysaudio.h
src/audio/bsd/SDL_bsdaudio.c
src/audio/bsd/SDL_bsdaudio.h
src/audio/netbsd/SDL_netbsdaudio.c
src/audio/netbsd/SDL_netbsdaudio.h
     1.1 --- a/CMakeLists.txt	Wed May 24 13:28:13 2017 -0400
     1.2 +++ b/CMakeLists.txt	Wed May 24 19:56:59 2017 -0400
     1.3 @@ -855,10 +855,10 @@
     1.4          file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
     1.5          set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
     1.6          set(HAVE_SDL_AUDIO TRUE)
     1.7 -    elseif(NETBSD OR OPENBSD)
     1.8 -        set(SDL_AUDIO_DRIVER_BSD 1)
     1.9 -        file(GLOB BSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/bsd/*.c)
    1.10 -        set(SOURCE_FILES ${SOURCE_FILES} ${BSD_AUDIO_SOURCES})
    1.11 +    elseif(NETBSD)
    1.12 +        set(SDL_AUDIO_DRIVER_NETBSD 1)
    1.13 +        file(GLOB NETBSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/netbsd/*.c)
    1.14 +        set(SOURCE_FILES ${SOURCE_FILES} ${NETBSD_AUDIO_SOURCES})
    1.15          set(HAVE_SDL_AUDIO TRUE)
    1.16      elseif(AIX)
    1.17          set(SDL_AUDIO_DRIVER_PAUDIO 1)
     2.1 --- a/configure	Wed May 24 13:28:13 2017 -0400
     2.2 +++ b/configure	Wed May 24 19:56:59 2017 -0400
     2.3 @@ -745,7 +745,6 @@
     2.4  docdir
     2.5  oldincludedir
     2.6  includedir
     2.7 -runstatedir
     2.8  localstatedir
     2.9  sharedstatedir
    2.10  sysconfdir
    2.11 @@ -917,7 +916,6 @@
    2.12  sysconfdir='${prefix}/etc'
    2.13  sharedstatedir='${prefix}/com'
    2.14  localstatedir='${prefix}/var'
    2.15 -runstatedir='${localstatedir}/run'
    2.16  includedir='${prefix}/include'
    2.17  oldincludedir='/usr/include'
    2.18  docdir='${datarootdir}/doc/${PACKAGE}'
    2.19 @@ -1170,15 +1168,6 @@
    2.20    | -silent | --silent | --silen | --sile | --sil)
    2.21      silent=yes ;;
    2.22  
    2.23 -  -runstatedir | --runstatedir | --runstatedi | --runstated \
    2.24 -  | --runstate | --runstat | --runsta | --runst | --runs \
    2.25 -  | --run | --ru | --r)
    2.26 -    ac_prev=runstatedir ;;
    2.27 -  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
    2.28 -  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
    2.29 -  | --run=* | --ru=* | --r=*)
    2.30 -    runstatedir=$ac_optarg ;;
    2.31 -
    2.32    -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
    2.33      ac_prev=sbindir ;;
    2.34    -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
    2.35 @@ -1316,7 +1305,7 @@
    2.36  for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
    2.37  		datadir sysconfdir sharedstatedir localstatedir includedir \
    2.38  		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
    2.39 -		libdir localedir mandir runstatedir
    2.40 +		libdir localedir mandir
    2.41  do
    2.42    eval ac_val=\$$ac_var
    2.43    # Remove trailing slashes.
    2.44 @@ -1469,7 +1458,6 @@
    2.45    --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
    2.46    --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
    2.47    --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
    2.48 -  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
    2.49    --libdir=DIR            object code libraries [EPREFIX/lib]
    2.50    --includedir=DIR        C header files [PREFIX/include]
    2.51    --oldincludedir=DIR     C header files for non-gcc [/usr/include]
    2.52 @@ -23318,9 +23306,9 @@
    2.53              ;;
    2.54              netbsd)  # Don't use this on OpenBSD, it's busted.
    2.55  
    2.56 -$as_echo "#define SDL_AUDIO_DRIVER_BSD 1" >>confdefs.h
    2.57 -
    2.58 -                SOURCES="$SOURCES $srcdir/src/audio/bsd/*.c"
    2.59 +$as_echo "#define SDL_AUDIO_DRIVER_NETBSD 1" >>confdefs.h
    2.60 +
    2.61 +                SOURCES="$SOURCES $srcdir/src/audio/netbsd/*.c"
    2.62                  have_audio=yes
    2.63              ;;
    2.64              aix)
     3.1 --- a/configure.in	Wed May 24 13:28:13 2017 -0400
     3.2 +++ b/configure.in	Wed May 24 19:56:59 2017 -0400
     3.3 @@ -3074,8 +3074,8 @@
     3.4                  have_audio=yes
     3.5              ;;
     3.6              netbsd)  # Don't use this on OpenBSD, it's busted.
     3.7 -                AC_DEFINE(SDL_AUDIO_DRIVER_BSD, 1, [ ])
     3.8 -                SOURCES="$SOURCES $srcdir/src/audio/bsd/*.c"
     3.9 +                AC_DEFINE(SDL_AUDIO_DRIVER_NETBSD, 1, [ ])
    3.10 +                SOURCES="$SOURCES $srcdir/src/audio/netbsd/*.c"
    3.11                  have_audio=yes
    3.12              ;;
    3.13              aix)
     4.1 --- a/include/SDL_config.h.cmake	Wed May 24 13:28:13 2017 -0400
     4.2 +++ b/include/SDL_config.h.cmake	Wed May 24 19:56:59 2017 -0400
     4.3 @@ -210,7 +210,7 @@
     4.4  #cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO @SDL_AUDIO_DRIVER_PULSEAUDIO@
     4.5  #cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC @SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC@
     4.6  #cmakedefine SDL_AUDIO_DRIVER_HAIKU @SDL_AUDIO_DRIVER_HAIKU@
     4.7 -#cmakedefine SDL_AUDIO_DRIVER_BSD @SDL_AUDIO_DRIVER_BSD@
     4.8 +#cmakedefine SDL_AUDIO_DRIVER_NETBSD @SDL_AUDIO_DRIVER_NETBSD@
     4.9  #cmakedefine SDL_AUDIO_DRIVER_COREAUDIO @SDL_AUDIO_DRIVER_COREAUDIO@
    4.10  #cmakedefine SDL_AUDIO_DRIVER_DISK @SDL_AUDIO_DRIVER_DISK@
    4.11  #cmakedefine SDL_AUDIO_DRIVER_DUMMY @SDL_AUDIO_DRIVER_DUMMY@
     5.1 --- a/include/SDL_config.h.in	Wed May 24 13:28:13 2017 -0400
     5.2 +++ b/include/SDL_config.h.in	Wed May 24 19:56:59 2017 -0400
     5.3 @@ -209,7 +209,7 @@
     5.4  #undef SDL_AUDIO_DRIVER_PULSEAUDIO
     5.5  #undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
     5.6  #undef SDL_AUDIO_DRIVER_HAIKU
     5.7 -#undef SDL_AUDIO_DRIVER_BSD
     5.8 +#undef SDL_AUDIO_DRIVER_NETBSD
     5.9  #undef SDL_AUDIO_DRIVER_COREAUDIO
    5.10  #undef SDL_AUDIO_DRIVER_DISK
    5.11  #undef SDL_AUDIO_DRIVER_DUMMY
     6.1 --- a/src/audio/SDL_audio.c	Wed May 24 13:28:13 2017 -0400
     6.2 +++ b/src/audio/SDL_audio.c	Wed May 24 19:56:59 2017 -0400
     6.3 @@ -44,8 +44,8 @@
     6.4  #if SDL_AUDIO_DRIVER_SNDIO
     6.5      &SNDIO_bootstrap,
     6.6  #endif
     6.7 -#if SDL_AUDIO_DRIVER_BSD
     6.8 -    &BSD_AUDIO_bootstrap,
     6.9 +#if SDL_AUDIO_DRIVER_NETBSD
    6.10 +    &NETBSDAUDIO_bootstrap,
    6.11  #endif
    6.12  #if SDL_AUDIO_DRIVER_OSS
    6.13      &DSP_bootstrap,
     7.1 --- a/src/audio/SDL_audiodev.c	Wed May 24 13:28:13 2017 -0400
     7.2 +++ b/src/audio/SDL_audiodev.c	Wed May 24 19:56:59 2017 -0400
     7.3 @@ -22,7 +22,7 @@
     7.4  
     7.5  /* Get the name of the audio device we use for output */
     7.6  
     7.7 -#if SDL_AUDIO_DRIVER_BSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
     7.8 +#if SDL_AUDIO_DRIVER_NETBSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
     7.9  
    7.10  #include <fcntl.h>
    7.11  #include <sys/types.h>
     8.1 --- a/src/audio/SDL_sysaudio.h	Wed May 24 13:28:13 2017 -0400
     8.2 +++ b/src/audio/SDL_sysaudio.h	Wed May 24 19:56:59 2017 -0400
     8.3 @@ -183,7 +183,7 @@
     8.4  extern AudioBootStrap PULSEAUDIO_bootstrap;
     8.5  extern AudioBootStrap ALSA_bootstrap;
     8.6  extern AudioBootStrap SNDIO_bootstrap;
     8.7 -extern AudioBootStrap BSD_AUDIO_bootstrap;
     8.8 +extern AudioBootStrap NETBSDAUDIO_bootstrap;
     8.9  extern AudioBootStrap DSP_bootstrap;
    8.10  extern AudioBootStrap QSAAUDIO_bootstrap;
    8.11  extern AudioBootStrap SUNAUDIO_bootstrap;
     9.1 --- a/src/audio/bsd/SDL_bsdaudio.c	Wed May 24 13:28:13 2017 -0400
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,418 +0,0 @@
     9.4 -/*
     9.5 -  Simple DirectMedia Layer
     9.6 -  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     9.7 -
     9.8 -  This software is provided 'as-is', without any express or implied
     9.9 -  warranty.  In no event will the authors be held liable for any damages
    9.10 -  arising from the use of this software.
    9.11 -
    9.12 -  Permission is granted to anyone to use this software for any purpose,
    9.13 -  including commercial applications, and to alter it and redistribute it
    9.14 -  freely, subject to the following restrictions:
    9.15 -
    9.16 -  1. The origin of this software must not be misrepresented; you must not
    9.17 -     claim that you wrote the original software. If you use this software
    9.18 -     in a product, an acknowledgment in the product documentation would be
    9.19 -     appreciated but is not required.
    9.20 -  2. Altered source versions must be plainly marked as such, and must not be
    9.21 -     misrepresented as being the original software.
    9.22 -  3. This notice may not be removed or altered from any source distribution.
    9.23 -*/
    9.24 -#include "../../SDL_internal.h"
    9.25 -
    9.26 -#if SDL_AUDIO_DRIVER_BSD
    9.27 -
    9.28 -/*
    9.29 - * Driver for native OpenBSD/NetBSD audio(4).
    9.30 - * vedge@vedge.com.ar.
    9.31 - */
    9.32 -
    9.33 -#include <errno.h>
    9.34 -#include <unistd.h>
    9.35 -#include <fcntl.h>
    9.36 -#include <sys/time.h>
    9.37 -#include <sys/ioctl.h>
    9.38 -#include <sys/stat.h>
    9.39 -#include <sys/types.h>
    9.40 -#include <sys/audioio.h>
    9.41 -
    9.42 -#include "SDL_timer.h"
    9.43 -#include "SDL_audio.h"
    9.44 -#include "../SDL_audio_c.h"
    9.45 -#include "../SDL_audiodev_c.h"
    9.46 -#include "SDL_bsdaudio.h"
    9.47 -
    9.48 -/* Use timer for synchronization */
    9.49 -/* #define USE_TIMER_SYNC */
    9.50 -
    9.51 -/* #define DEBUG_AUDIO */
    9.52 -/* #define DEBUG_AUDIO_STREAM */
    9.53 -
    9.54 -
    9.55 -static void
    9.56 -BSDAUDIO_DetectDevices(void)
    9.57 -{
    9.58 -    SDL_EnumUnixAudioDevices(0, NULL);
    9.59 -}
    9.60 -
    9.61 -
    9.62 -static void
    9.63 -BSDAUDIO_Status(_THIS)
    9.64 -{
    9.65 -#ifdef DEBUG_AUDIO
    9.66 -    /* *INDENT-OFF* */
    9.67 -    audio_info_t info;
    9.68 -    const audio_prinfo *prinfo;
    9.69 -
    9.70 -    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
    9.71 -        fprintf(stderr, "AUDIO_GETINFO failed.\n");
    9.72 -        return;
    9.73 -    }
    9.74 -
    9.75 -    prinfo = this->iscapture ? &info.play : &info.record;
    9.76 -
    9.77 -    fprintf(stderr, "\n"
    9.78 -            "[%s info]\n"
    9.79 -            "buffer size	:   %d bytes\n"
    9.80 -            "sample rate	:   %i Hz\n"
    9.81 -            "channels	:   %i\n"
    9.82 -            "precision	:   %i-bit\n"
    9.83 -            "encoding	:   0x%x\n"
    9.84 -            "seek		:   %i\n"
    9.85 -            "sample count	:   %i\n"
    9.86 -            "EOF count	:   %i\n"
    9.87 -            "paused		:   %s\n"
    9.88 -            "error occured	:   %s\n"
    9.89 -            "waiting		:   %s\n"
    9.90 -            "active		:   %s\n"
    9.91 -            "",
    9.92 -            this->iscapture ? "record" : "play",
    9.93 -            prinfo->buffer_size,
    9.94 -            prinfo->sample_rate,
    9.95 -            prinfo->channels,
    9.96 -            prinfo->precision,
    9.97 -            prinfo->encoding,
    9.98 -            prinfo->seek,
    9.99 -            prinfo->samples,
   9.100 -            prinfo->eof,
   9.101 -            prinfo->pause ? "yes" : "no",
   9.102 -            prinfo->error ? "yes" : "no",
   9.103 -            prinfo->waiting ? "yes" : "no",
   9.104 -            prinfo->active ? "yes" : "no");
   9.105 -
   9.106 -    fprintf(stderr, "\n"
   9.107 -            "[audio info]\n"
   9.108 -            "monitor_gain	:   %i\n"
   9.109 -            "hw block size	:   %d bytes\n"
   9.110 -            "hi watermark	:   %i\n"
   9.111 -            "lo watermark	:   %i\n"
   9.112 -            "audio mode	:   %s\n"
   9.113 -            "",
   9.114 -            info.monitor_gain,
   9.115 -            info.blocksize,
   9.116 -            info.hiwat, info.lowat,
   9.117 -            (info.mode == AUMODE_PLAY) ? "PLAY"
   9.118 -            : (info.mode = AUMODE_RECORD) ? "RECORD"
   9.119 -            : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
   9.120 -    /* *INDENT-ON* */
   9.121 -#endif /* DEBUG_AUDIO */
   9.122 -}
   9.123 -
   9.124 -
   9.125 -/* This function waits until it is possible to write a full sound buffer */
   9.126 -static void
   9.127 -BSDAUDIO_WaitDevice(_THIS)
   9.128 -{
   9.129 -#ifndef USE_BLOCKING_WRITES     /* Not necessary when using blocking writes */
   9.130 -    /* See if we need to use timed audio synchronization */
   9.131 -    if (this->hidden->frame_ticks) {
   9.132 -        /* Use timer for general audio synchronization */
   9.133 -        Sint32 ticks;
   9.134 -
   9.135 -        ticks = ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
   9.136 -        if (ticks > 0) {
   9.137 -            SDL_Delay(ticks);
   9.138 -        }
   9.139 -    } else {
   9.140 -        /* Use select() for audio synchronization */
   9.141 -        fd_set fdset;
   9.142 -        struct timeval timeout;
   9.143 -
   9.144 -        FD_ZERO(&fdset);
   9.145 -        FD_SET(this->hidden->audio_fd, &fdset);
   9.146 -        timeout.tv_sec = 10;
   9.147 -        timeout.tv_usec = 0;
   9.148 -#ifdef DEBUG_AUDIO
   9.149 -        fprintf(stderr, "Waiting for audio to get ready\n");
   9.150 -#endif
   9.151 -        if (select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, &timeout)
   9.152 -            <= 0) {
   9.153 -            const char *message =
   9.154 -                "Audio timeout - buggy audio driver? (disabled)";
   9.155 -            /* In general we should never print to the screen,
   9.156 -               but in this case we have no other way of letting
   9.157 -               the user know what happened.
   9.158 -             */
   9.159 -            fprintf(stderr, "SDL: %s\n", message);
   9.160 -            SDL_OpenedAudioDeviceDisconnected(this);
   9.161 -            /* Don't try to close - may hang */
   9.162 -            this->hidden->audio_fd = -1;
   9.163 -#ifdef DEBUG_AUDIO
   9.164 -            fprintf(stderr, "Done disabling audio\n");
   9.165 -#endif
   9.166 -        }
   9.167 -#ifdef DEBUG_AUDIO
   9.168 -        fprintf(stderr, "Ready!\n");
   9.169 -#endif
   9.170 -    }
   9.171 -#endif /* !USE_BLOCKING_WRITES */
   9.172 -}
   9.173 -
   9.174 -static void
   9.175 -BSDAUDIO_PlayDevice(_THIS)
   9.176 -{
   9.177 -    int written, p = 0;
   9.178 -
   9.179 -    /* Write the audio data, checking for EAGAIN on broken audio drivers */
   9.180 -    do {
   9.181 -        written = write(this->hidden->audio_fd,
   9.182 -                        &this->hidden->mixbuf[p], this->hidden->mixlen - p);
   9.183 -
   9.184 -        if (written > 0)
   9.185 -            p += written;
   9.186 -        if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
   9.187 -            /* Non recoverable error has occurred. It should be reported!!! */
   9.188 -            perror("audio");
   9.189 -            break;
   9.190 -        }
   9.191 -
   9.192 -#ifdef DEBUG_AUDIO
   9.193 -        fprintf(stderr, "Wrote %d bytes of audio data\n", written);
   9.194 -#endif
   9.195 -
   9.196 -        if (p < this->hidden->mixlen
   9.197 -            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
   9.198 -            SDL_Delay(1);       /* Let a little CPU time go by */
   9.199 -        }
   9.200 -    } while (p < this->hidden->mixlen);
   9.201 -
   9.202 -    /* If timer synchronization is enabled, set the next write frame */
   9.203 -    if (this->hidden->frame_ticks) {
   9.204 -        this->hidden->next_frame += this->hidden->frame_ticks;
   9.205 -    }
   9.206 -
   9.207 -    /* If we couldn't write, assume fatal error for now */
   9.208 -    if (written < 0) {
   9.209 -        SDL_OpenedAudioDeviceDisconnected(this);
   9.210 -    }
   9.211 -}
   9.212 -
   9.213 -static Uint8 *
   9.214 -BSDAUDIO_GetDeviceBuf(_THIS)
   9.215 -{
   9.216 -    return (this->hidden->mixbuf);
   9.217 -}
   9.218 -
   9.219 -
   9.220 -static int
   9.221 -BSDAUDIO_CaptureFromDevice(_THIS, void *_buffer, int buflen)
   9.222 -{
   9.223 -    Uint8 *buffer = (Uint8 *) _buffer;
   9.224 -    int br, p = 0;
   9.225 -
   9.226 -    /* Write the audio data, checking for EAGAIN on broken audio drivers */
   9.227 -    do {
   9.228 -        br = read(this->hidden->audio_fd, buffer + p, buflen - p);
   9.229 -        if (br > 0)
   9.230 -            p += br;
   9.231 -        if (br == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
   9.232 -            /* Non recoverable error has occurred. It should be reported!!! */
   9.233 -            perror("audio");
   9.234 -            return p ? p : -1;
   9.235 -        }
   9.236 -
   9.237 -#ifdef DEBUG_AUDIO
   9.238 -        fprintf(stderr, "Captured %d bytes of audio data\n", br);
   9.239 -#endif
   9.240 -
   9.241 -        if (p < buflen
   9.242 -            || ((br < 0) && ((errno == 0) || (errno == EAGAIN)))) {
   9.243 -            SDL_Delay(1);       /* Let a little CPU time go by */
   9.244 -        }
   9.245 -    } while (p < buflen);
   9.246 -}
   9.247 -
   9.248 -static void
   9.249 -BSDAUDIO_FlushCapture(_THIS)
   9.250 -{
   9.251 -    audio_info_t info;
   9.252 -    size_t remain;
   9.253 -    Uint8 buf[512];
   9.254 -
   9.255 -    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
   9.256 -        return;  /* oh well. */
   9.257 -    }
   9.258 -
   9.259 -    remain = (size_t) (info.record.samples * (SDL_AUDIO_BITSIZE(this->spec.format) / 8));
   9.260 -    while (remain > 0) {
   9.261 -        const size_t len = SDL_min(sizeof (buf), remain);
   9.262 -        const int br = read(this->hidden->audio_fd, buf, len);
   9.263 -        if (br <= 0) {
   9.264 -            return;  /* oh well. */
   9.265 -        }
   9.266 -        remain -= br;
   9.267 -    }
   9.268 -}
   9.269 -
   9.270 -static void
   9.271 -BSDAUDIO_CloseDevice(_THIS)
   9.272 -{
   9.273 -    if (this->hidden->audio_fd >= 0) {
   9.274 -        close(this->hidden->audio_fd);
   9.275 -    }
   9.276 -    SDL_free(this->hidden->mixbuf);
   9.277 -    SDL_free(this->hidden);
   9.278 -}
   9.279 -
   9.280 -static int
   9.281 -BSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
   9.282 -{
   9.283 -    const int flags = iscapture ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT;
   9.284 -    SDL_AudioFormat format = 0;
   9.285 -    audio_info_t info;
   9.286 -    audio_prinfo *prinfo = iscapture ? &info.play : &info.record;
   9.287 -
   9.288 -    /* We don't care what the devname is...we'll try to open anything. */
   9.289 -    /*  ...but default to first name in the list... */
   9.290 -    if (devname == NULL) {
   9.291 -        devname = SDL_GetAudioDeviceName(0, iscapture);
   9.292 -        if (devname == NULL) {
   9.293 -            return SDL_SetError("No such audio device");
   9.294 -        }
   9.295 -    }
   9.296 -
   9.297 -    /* Initialize all variables that we clean on shutdown */
   9.298 -    this->hidden = (struct SDL_PrivateAudioData *)
   9.299 -        SDL_malloc((sizeof *this->hidden));
   9.300 -    if (this->hidden == NULL) {
   9.301 -        return SDL_OutOfMemory();
   9.302 -    }
   9.303 -    SDL_zerop(this->hidden);
   9.304 -
   9.305 -    /* Open the audio device */
   9.306 -    this->hidden->audio_fd = open(devname, flags, 0);
   9.307 -    if (this->hidden->audio_fd < 0) {
   9.308 -        return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
   9.309 -    }
   9.310 -
   9.311 -    AUDIO_INITINFO(&info);
   9.312 -
   9.313 -    /* Calculate the final parameters for this audio specification */
   9.314 -    SDL_CalculateAudioSpec(&this->spec);
   9.315 -
   9.316 -    /* Set to play mode */
   9.317 -    info.mode = iscapture ? AUMODE_RECORD : AUMODE_PLAY;
   9.318 -    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
   9.319 -        return SDL_SetError("Couldn't put device into play mode");
   9.320 -    }
   9.321 -
   9.322 -    AUDIO_INITINFO(&info);
   9.323 -    for (format = SDL_FirstAudioFormat(this->spec.format);
   9.324 -         format; format = SDL_NextAudioFormat()) {
   9.325 -        switch (format) {
   9.326 -        case AUDIO_U8:
   9.327 -            prinfo->encoding = AUDIO_ENCODING_ULINEAR;
   9.328 -            prinfo->precision = 8;
   9.329 -            break;
   9.330 -        case AUDIO_S8:
   9.331 -            prinfo->encoding = AUDIO_ENCODING_SLINEAR;
   9.332 -            prinfo->precision = 8;
   9.333 -            break;
   9.334 -        case AUDIO_S16LSB:
   9.335 -            prinfo->encoding = AUDIO_ENCODING_SLINEAR_LE;
   9.336 -            prinfo->precision = 16;
   9.337 -            break;
   9.338 -        case AUDIO_S16MSB:
   9.339 -            prinfo->encoding = AUDIO_ENCODING_SLINEAR_BE;
   9.340 -            prinfo->precision = 16;
   9.341 -            break;
   9.342 -        case AUDIO_U16LSB:
   9.343 -            prinfo->encoding = AUDIO_ENCODING_ULINEAR_LE;
   9.344 -            prinfo->precision = 16;
   9.345 -            break;
   9.346 -        case AUDIO_U16MSB:
   9.347 -            prinfo->encoding = AUDIO_ENCODING_ULINEAR_BE;
   9.348 -            prinfo->precision = 16;
   9.349 -            break;
   9.350 -        default:
   9.351 -            continue;
   9.352 -        }
   9.353 -
   9.354 -        if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
   9.355 -            break;
   9.356 -        }
   9.357 -    }
   9.358 -
   9.359 -    if (!format) {
   9.360 -        return SDL_SetError("No supported encoding for 0x%x", this->spec.format);
   9.361 -    }
   9.362 -
   9.363 -    this->spec.format = format;
   9.364 -
   9.365 -    AUDIO_INITINFO(&info);
   9.366 -    prinfo->channels = this->spec.channels;
   9.367 -    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
   9.368 -        this->spec.channels = 1;
   9.369 -    }
   9.370 -    AUDIO_INITINFO(&info);
   9.371 -    prinfo->sample_rate = this->spec.freq;
   9.372 -    info.blocksize = this->spec.size;
   9.373 -    info.hiwat = 5;
   9.374 -    info.lowat = 3;
   9.375 -    (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
   9.376 -    (void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
   9.377 -    this->spec.freq = prinfo->sample_rate;
   9.378 -
   9.379 -    if (!iscapture) {
   9.380 -        /* Allocate mixing buffer */
   9.381 -        this->hidden->mixlen = this->spec.size;
   9.382 -        this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
   9.383 -        if (this->hidden->mixbuf == NULL) {
   9.384 -            return SDL_OutOfMemory();
   9.385 -        }
   9.386 -        SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
   9.387 -    }
   9.388 -
   9.389 -    BSDAUDIO_Status(this);
   9.390 -
   9.391 -    /* We're ready to rock and roll. :-) */
   9.392 -    return 0;
   9.393 -}
   9.394 -
   9.395 -static int
   9.396 -BSDAUDIO_Init(SDL_AudioDriverImpl * impl)
   9.397 -{
   9.398 -    /* Set the function pointers */
   9.399 -    impl->DetectDevices = BSDAUDIO_DetectDevices;
   9.400 -    impl->OpenDevice = BSDAUDIO_OpenDevice;
   9.401 -    impl->PlayDevice = BSDAUDIO_PlayDevice;
   9.402 -    impl->WaitDevice = BSDAUDIO_WaitDevice;
   9.403 -    impl->GetDeviceBuf = BSDAUDIO_GetDeviceBuf;
   9.404 -    impl->CloseDevice = BSDAUDIO_CloseDevice;
   9.405 -    impl->CaptureFromDevice = BSDAUDIO_CaptureFromDevice;
   9.406 -    impl->FlushCapture = BSDAUDIO_FlushCapture;
   9.407 -
   9.408 -    impl->HasCaptureSupport = SDL_TRUE;
   9.409 -    impl->AllowsArbitraryDeviceNames = 1;
   9.410 -
   9.411 -    return 1;   /* this audio target is available. */
   9.412 -}
   9.413 -
   9.414 -
   9.415 -AudioBootStrap BSD_AUDIO_bootstrap = {
   9.416 -    "bsd", "BSD audio", BSDAUDIO_Init, 0
   9.417 -};
   9.418 -
   9.419 -#endif /* SDL_AUDIO_DRIVER_BSD */
   9.420 -
   9.421 -/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/audio/bsd/SDL_bsdaudio.h	Wed May 24 13:28:13 2017 -0400
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,51 +0,0 @@
    10.4 -/*
    10.5 -  Simple DirectMedia Layer
    10.6 -  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
    10.7 -
    10.8 -  This software is provided 'as-is', without any express or implied
    10.9 -  warranty.  In no event will the authors be held liable for any damages
   10.10 -  arising from the use of this software.
   10.11 -
   10.12 -  Permission is granted to anyone to use this software for any purpose,
   10.13 -  including commercial applications, and to alter it and redistribute it
   10.14 -  freely, subject to the following restrictions:
   10.15 -
   10.16 -  1. The origin of this software must not be misrepresented; you must not
   10.17 -     claim that you wrote the original software. If you use this software
   10.18 -     in a product, an acknowledgment in the product documentation would be
   10.19 -     appreciated but is not required.
   10.20 -  2. Altered source versions must be plainly marked as such, and must not be
   10.21 -     misrepresented as being the original software.
   10.22 -  3. This notice may not be removed or altered from any source distribution.
   10.23 -*/
   10.24 -#include "../../SDL_internal.h"
   10.25 -
   10.26 -#ifndef _SDL_bsdaudio_h
   10.27 -#define _SDL_bsdaudio_h
   10.28 -
   10.29 -#include "../SDL_sysaudio.h"
   10.30 -
   10.31 -#define _THIS   SDL_AudioDevice *this
   10.32 -
   10.33 -struct SDL_PrivateAudioData
   10.34 -{
   10.35 -    /* The file descriptor for the audio device */
   10.36 -    int audio_fd;
   10.37 -
   10.38 -    /* The parent process id, to detect when application quits */
   10.39 -    pid_t parent;
   10.40 -
   10.41 -    /* Raw mixing buffer */
   10.42 -    Uint8 *mixbuf;
   10.43 -    int mixlen;
   10.44 -
   10.45 -    /* Support for audio timing using a timer, in addition to select() */
   10.46 -    float frame_ticks;
   10.47 -    float next_frame;
   10.48 -};
   10.49 -
   10.50 -#define FUDGE_TICKS 10      /* The scheduler overhead ticks per frame */
   10.51 -
   10.52 -#endif /* _SDL_bsdaudio_h */
   10.53 -
   10.54 -/* vi: set ts=4 sw=4 expandtab: */
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/audio/netbsd/SDL_netbsdaudio.c	Wed May 24 19:56:59 2017 -0400
    11.3 @@ -0,0 +1,418 @@
    11.4 +/*
    11.5 +  Simple DirectMedia Layer
    11.6 +  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
    11.7 +
    11.8 +  This software is provided 'as-is', without any express or implied
    11.9 +  warranty.  In no event will the authors be held liable for any damages
   11.10 +  arising from the use of this software.
   11.11 +
   11.12 +  Permission is granted to anyone to use this software for any purpose,
   11.13 +  including commercial applications, and to alter it and redistribute it
   11.14 +  freely, subject to the following restrictions:
   11.15 +
   11.16 +  1. The origin of this software must not be misrepresented; you must not
   11.17 +     claim that you wrote the original software. If you use this software
   11.18 +     in a product, an acknowledgment in the product documentation would be
   11.19 +     appreciated but is not required.
   11.20 +  2. Altered source versions must be plainly marked as such, and must not be
   11.21 +     misrepresented as being the original software.
   11.22 +  3. This notice may not be removed or altered from any source distribution.
   11.23 +*/
   11.24 +#include "../../SDL_internal.h"
   11.25 +
   11.26 +#if SDL_AUDIO_DRIVER_NETBSD
   11.27 +
   11.28 +/*
   11.29 + * Driver for native NetBSD audio(4).
   11.30 + * vedge@vedge.com.ar.
   11.31 + */
   11.32 +
   11.33 +#include <errno.h>
   11.34 +#include <unistd.h>
   11.35 +#include <fcntl.h>
   11.36 +#include <sys/time.h>
   11.37 +#include <sys/ioctl.h>
   11.38 +#include <sys/stat.h>
   11.39 +#include <sys/types.h>
   11.40 +#include <sys/audioio.h>
   11.41 +
   11.42 +#include "SDL_timer.h"
   11.43 +#include "SDL_audio.h"
   11.44 +#include "../SDL_audio_c.h"
   11.45 +#include "../SDL_audiodev_c.h"
   11.46 +#include "SDL_bsdaudio.h"
   11.47 +
   11.48 +/* Use timer for synchronization */
   11.49 +/* #define USE_TIMER_SYNC */
   11.50 +
   11.51 +/* #define DEBUG_AUDIO */
   11.52 +/* #define DEBUG_AUDIO_STREAM */
   11.53 +
   11.54 +
   11.55 +static void
   11.56 +NETBSDAUDIO_DetectDevices(void)
   11.57 +{
   11.58 +    SDL_EnumUnixAudioDevices(0, NULL);
   11.59 +}
   11.60 +
   11.61 +
   11.62 +static void
   11.63 +NETBSDAUDIO_Status(_THIS)
   11.64 +{
   11.65 +#ifdef DEBUG_AUDIO
   11.66 +    /* *INDENT-OFF* */
   11.67 +    audio_info_t info;
   11.68 +    const audio_prinfo *prinfo;
   11.69 +
   11.70 +    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
   11.71 +        fprintf(stderr, "AUDIO_GETINFO failed.\n");
   11.72 +        return;
   11.73 +    }
   11.74 +
   11.75 +    prinfo = this->iscapture ? &info.play : &info.record;
   11.76 +
   11.77 +    fprintf(stderr, "\n"
   11.78 +            "[%s info]\n"
   11.79 +            "buffer size	:   %d bytes\n"
   11.80 +            "sample rate	:   %i Hz\n"
   11.81 +            "channels	:   %i\n"
   11.82 +            "precision	:   %i-bit\n"
   11.83 +            "encoding	:   0x%x\n"
   11.84 +            "seek		:   %i\n"
   11.85 +            "sample count	:   %i\n"
   11.86 +            "EOF count	:   %i\n"
   11.87 +            "paused		:   %s\n"
   11.88 +            "error occured	:   %s\n"
   11.89 +            "waiting		:   %s\n"
   11.90 +            "active		:   %s\n"
   11.91 +            "",
   11.92 +            this->iscapture ? "record" : "play",
   11.93 +            prinfo->buffer_size,
   11.94 +            prinfo->sample_rate,
   11.95 +            prinfo->channels,
   11.96 +            prinfo->precision,
   11.97 +            prinfo->encoding,
   11.98 +            prinfo->seek,
   11.99 +            prinfo->samples,
  11.100 +            prinfo->eof,
  11.101 +            prinfo->pause ? "yes" : "no",
  11.102 +            prinfo->error ? "yes" : "no",
  11.103 +            prinfo->waiting ? "yes" : "no",
  11.104 +            prinfo->active ? "yes" : "no");
  11.105 +
  11.106 +    fprintf(stderr, "\n"
  11.107 +            "[audio info]\n"
  11.108 +            "monitor_gain	:   %i\n"
  11.109 +            "hw block size	:   %d bytes\n"
  11.110 +            "hi watermark	:   %i\n"
  11.111 +            "lo watermark	:   %i\n"
  11.112 +            "audio mode	:   %s\n"
  11.113 +            "",
  11.114 +            info.monitor_gain,
  11.115 +            info.blocksize,
  11.116 +            info.hiwat, info.lowat,
  11.117 +            (info.mode == AUMODE_PLAY) ? "PLAY"
  11.118 +            : (info.mode = AUMODE_RECORD) ? "RECORD"
  11.119 +            : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
  11.120 +    /* *INDENT-ON* */
  11.121 +#endif /* DEBUG_AUDIO */
  11.122 +}
  11.123 +
  11.124 +
  11.125 +/* This function waits until it is possible to write a full sound buffer */
  11.126 +static void
  11.127 +NETBSDAUDIO_WaitDevice(_THIS)
  11.128 +{
  11.129 +#ifndef USE_BLOCKING_WRITES     /* Not necessary when using blocking writes */
  11.130 +    /* See if we need to use timed audio synchronization */
  11.131 +    if (this->hidden->frame_ticks) {
  11.132 +        /* Use timer for general audio synchronization */
  11.133 +        Sint32 ticks;
  11.134 +
  11.135 +        ticks = ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
  11.136 +        if (ticks > 0) {
  11.137 +            SDL_Delay(ticks);
  11.138 +        }
  11.139 +    } else {
  11.140 +        /* Use select() for audio synchronization */
  11.141 +        fd_set fdset;
  11.142 +        struct timeval timeout;
  11.143 +
  11.144 +        FD_ZERO(&fdset);
  11.145 +        FD_SET(this->hidden->audio_fd, &fdset);
  11.146 +        timeout.tv_sec = 10;
  11.147 +        timeout.tv_usec = 0;
  11.148 +#ifdef DEBUG_AUDIO
  11.149 +        fprintf(stderr, "Waiting for audio to get ready\n");
  11.150 +#endif
  11.151 +        if (select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, &timeout)
  11.152 +            <= 0) {
  11.153 +            const char *message =
  11.154 +                "Audio timeout - buggy audio driver? (disabled)";
  11.155 +            /* In general we should never print to the screen,
  11.156 +               but in this case we have no other way of letting
  11.157 +               the user know what happened.
  11.158 +             */
  11.159 +            fprintf(stderr, "SDL: %s\n", message);
  11.160 +            SDL_OpenedAudioDeviceDisconnected(this);
  11.161 +            /* Don't try to close - may hang */
  11.162 +            this->hidden->audio_fd = -1;
  11.163 +#ifdef DEBUG_AUDIO
  11.164 +            fprintf(stderr, "Done disabling audio\n");
  11.165 +#endif
  11.166 +        }
  11.167 +#ifdef DEBUG_AUDIO
  11.168 +        fprintf(stderr, "Ready!\n");
  11.169 +#endif
  11.170 +    }
  11.171 +#endif /* !USE_BLOCKING_WRITES */
  11.172 +}
  11.173 +
  11.174 +static void
  11.175 +NETBSDAUDIO_PlayDevice(_THIS)
  11.176 +{
  11.177 +    int written, p = 0;
  11.178 +
  11.179 +    /* Write the audio data, checking for EAGAIN on broken audio drivers */
  11.180 +    do {
  11.181 +        written = write(this->hidden->audio_fd,
  11.182 +                        &this->hidden->mixbuf[p], this->hidden->mixlen - p);
  11.183 +
  11.184 +        if (written > 0)
  11.185 +            p += written;
  11.186 +        if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
  11.187 +            /* Non recoverable error has occurred. It should be reported!!! */
  11.188 +            perror("audio");
  11.189 +            break;
  11.190 +        }
  11.191 +
  11.192 +#ifdef DEBUG_AUDIO
  11.193 +        fprintf(stderr, "Wrote %d bytes of audio data\n", written);
  11.194 +#endif
  11.195 +
  11.196 +        if (p < this->hidden->mixlen
  11.197 +            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
  11.198 +            SDL_Delay(1);       /* Let a little CPU time go by */
  11.199 +        }
  11.200 +    } while (p < this->hidden->mixlen);
  11.201 +
  11.202 +    /* If timer synchronization is enabled, set the next write frame */
  11.203 +    if (this->hidden->frame_ticks) {
  11.204 +        this->hidden->next_frame += this->hidden->frame_ticks;
  11.205 +    }
  11.206 +
  11.207 +    /* If we couldn't write, assume fatal error for now */
  11.208 +    if (written < 0) {
  11.209 +        SDL_OpenedAudioDeviceDisconnected(this);
  11.210 +    }
  11.211 +}
  11.212 +
  11.213 +static Uint8 *
  11.214 +NETBSDAUDIO_GetDeviceBuf(_THIS)
  11.215 +{
  11.216 +    return (this->hidden->mixbuf);
  11.217 +}
  11.218 +
  11.219 +
  11.220 +static int
  11.221 +NETBSDAUDIO_CaptureFromDevice(_THIS, void *_buffer, int buflen)
  11.222 +{
  11.223 +    Uint8 *buffer = (Uint8 *) _buffer;
  11.224 +    int br, p = 0;
  11.225 +
  11.226 +    /* Write the audio data, checking for EAGAIN on broken audio drivers */
  11.227 +    do {
  11.228 +        br = read(this->hidden->audio_fd, buffer + p, buflen - p);
  11.229 +        if (br > 0)
  11.230 +            p += br;
  11.231 +        if (br == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
  11.232 +            /* Non recoverable error has occurred. It should be reported!!! */
  11.233 +            perror("audio");
  11.234 +            return p ? p : -1;
  11.235 +        }
  11.236 +
  11.237 +#ifdef DEBUG_AUDIO
  11.238 +        fprintf(stderr, "Captured %d bytes of audio data\n", br);
  11.239 +#endif
  11.240 +
  11.241 +        if (p < buflen
  11.242 +            || ((br < 0) && ((errno == 0) || (errno == EAGAIN)))) {
  11.243 +            SDL_Delay(1);       /* Let a little CPU time go by */
  11.244 +        }
  11.245 +    } while (p < buflen);
  11.246 +}
  11.247 +
  11.248 +static void
  11.249 +NETBSDAUDIO_FlushCapture(_THIS)
  11.250 +{
  11.251 +    audio_info_t info;
  11.252 +    size_t remain;
  11.253 +    Uint8 buf[512];
  11.254 +
  11.255 +    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
  11.256 +        return;  /* oh well. */
  11.257 +    }
  11.258 +
  11.259 +    remain = (size_t) (info.record.samples * (SDL_AUDIO_BITSIZE(this->spec.format) / 8));
  11.260 +    while (remain > 0) {
  11.261 +        const size_t len = SDL_min(sizeof (buf), remain);
  11.262 +        const int br = read(this->hidden->audio_fd, buf, len);
  11.263 +        if (br <= 0) {
  11.264 +            return;  /* oh well. */
  11.265 +        }
  11.266 +        remain -= br;
  11.267 +    }
  11.268 +}
  11.269 +
  11.270 +static void
  11.271 +NETBSDAUDIO_CloseDevice(_THIS)
  11.272 +{
  11.273 +    if (this->hidden->audio_fd >= 0) {
  11.274 +        close(this->hidden->audio_fd);
  11.275 +    }
  11.276 +    SDL_free(this->hidden->mixbuf);
  11.277 +    SDL_free(this->hidden);
  11.278 +}
  11.279 +
  11.280 +static int
  11.281 +NETBSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
  11.282 +{
  11.283 +    const int flags = iscapture ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT;
  11.284 +    SDL_AudioFormat format = 0;
  11.285 +    audio_info_t info;
  11.286 +    audio_prinfo *prinfo = iscapture ? &info.play : &info.record;
  11.287 +
  11.288 +    /* We don't care what the devname is...we'll try to open anything. */
  11.289 +    /*  ...but default to first name in the list... */
  11.290 +    if (devname == NULL) {
  11.291 +        devname = SDL_GetAudioDeviceName(0, iscapture);
  11.292 +        if (devname == NULL) {
  11.293 +            return SDL_SetError("No such audio device");
  11.294 +        }
  11.295 +    }
  11.296 +
  11.297 +    /* Initialize all variables that we clean on shutdown */
  11.298 +    this->hidden = (struct SDL_PrivateAudioData *)
  11.299 +        SDL_malloc((sizeof *this->hidden));
  11.300 +    if (this->hidden == NULL) {
  11.301 +        return SDL_OutOfMemory();
  11.302 +    }
  11.303 +    SDL_zerop(this->hidden);
  11.304 +
  11.305 +    /* Open the audio device */
  11.306 +    this->hidden->audio_fd = open(devname, flags, 0);
  11.307 +    if (this->hidden->audio_fd < 0) {
  11.308 +        return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
  11.309 +    }
  11.310 +
  11.311 +    AUDIO_INITINFO(&info);
  11.312 +
  11.313 +    /* Calculate the final parameters for this audio specification */
  11.314 +    SDL_CalculateAudioSpec(&this->spec);
  11.315 +
  11.316 +    /* Set to play mode */
  11.317 +    info.mode = iscapture ? AUMODE_RECORD : AUMODE_PLAY;
  11.318 +    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
  11.319 +        return SDL_SetError("Couldn't put device into play mode");
  11.320 +    }
  11.321 +
  11.322 +    AUDIO_INITINFO(&info);
  11.323 +    for (format = SDL_FirstAudioFormat(this->spec.format);
  11.324 +         format; format = SDL_NextAudioFormat()) {
  11.325 +        switch (format) {
  11.326 +        case AUDIO_U8:
  11.327 +            prinfo->encoding = AUDIO_ENCODING_ULINEAR;
  11.328 +            prinfo->precision = 8;
  11.329 +            break;
  11.330 +        case AUDIO_S8:
  11.331 +            prinfo->encoding = AUDIO_ENCODING_SLINEAR;
  11.332 +            prinfo->precision = 8;
  11.333 +            break;
  11.334 +        case AUDIO_S16LSB:
  11.335 +            prinfo->encoding = AUDIO_ENCODING_SLINEAR_LE;
  11.336 +            prinfo->precision = 16;
  11.337 +            break;
  11.338 +        case AUDIO_S16MSB:
  11.339 +            prinfo->encoding = AUDIO_ENCODING_SLINEAR_BE;
  11.340 +            prinfo->precision = 16;
  11.341 +            break;
  11.342 +        case AUDIO_U16LSB:
  11.343 +            prinfo->encoding = AUDIO_ENCODING_ULINEAR_LE;
  11.344 +            prinfo->precision = 16;
  11.345 +            break;
  11.346 +        case AUDIO_U16MSB:
  11.347 +            prinfo->encoding = AUDIO_ENCODING_ULINEAR_BE;
  11.348 +            prinfo->precision = 16;
  11.349 +            break;
  11.350 +        default:
  11.351 +            continue;
  11.352 +        }
  11.353 +
  11.354 +        if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
  11.355 +            break;
  11.356 +        }
  11.357 +    }
  11.358 +
  11.359 +    if (!format) {
  11.360 +        return SDL_SetError("No supported encoding for 0x%x", this->spec.format);
  11.361 +    }
  11.362 +
  11.363 +    this->spec.format = format;
  11.364 +
  11.365 +    AUDIO_INITINFO(&info);
  11.366 +    prinfo->channels = this->spec.channels;
  11.367 +    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
  11.368 +        this->spec.channels = 1;
  11.369 +    }
  11.370 +    AUDIO_INITINFO(&info);
  11.371 +    prinfo->sample_rate = this->spec.freq;
  11.372 +    info.blocksize = this->spec.size;
  11.373 +    info.hiwat = 5;
  11.374 +    info.lowat = 3;
  11.375 +    (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
  11.376 +    (void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
  11.377 +    this->spec.freq = prinfo->sample_rate;
  11.378 +
  11.379 +    if (!iscapture) {
  11.380 +        /* Allocate mixing buffer */
  11.381 +        this->hidden->mixlen = this->spec.size;
  11.382 +        this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
  11.383 +        if (this->hidden->mixbuf == NULL) {
  11.384 +            return SDL_OutOfMemory();
  11.385 +        }
  11.386 +        SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
  11.387 +    }
  11.388 +
  11.389 +    NETBSDAUDIO_Status(this);
  11.390 +
  11.391 +    /* We're ready to rock and roll. :-) */
  11.392 +    return 0;
  11.393 +}
  11.394 +
  11.395 +static int
  11.396 +NETBSDAUDIO_Init(SDL_AudioDriverImpl * impl)
  11.397 +{
  11.398 +    /* Set the function pointers */
  11.399 +    impl->DetectDevices = NETBSDAUDIO_DetectDevices;
  11.400 +    impl->OpenDevice = NETBSDAUDIO_OpenDevice;
  11.401 +    impl->PlayDevice = NETBSDAUDIO_PlayDevice;
  11.402 +    impl->WaitDevice = NETBSDAUDIO_WaitDevice;
  11.403 +    impl->GetDeviceBuf = NETBSDAUDIO_GetDeviceBuf;
  11.404 +    impl->CloseDevice = NETBSDAUDIO_CloseDevice;
  11.405 +    impl->CaptureFromDevice = NETBSDAUDIO_CaptureFromDevice;
  11.406 +    impl->FlushCapture = NETBSDAUDIO_FlushCapture;
  11.407 +
  11.408 +    impl->HasCaptureSupport = SDL_TRUE;
  11.409 +    impl->AllowsArbitraryDeviceNames = 1;
  11.410 +
  11.411 +    return 1;   /* this audio target is available. */
  11.412 +}
  11.413 +
  11.414 +
  11.415 +AudioBootStrap NETBSDAUDIO_bootstrap = {
  11.416 +    "netbsd", "NetBSD audio", NETBSDAUDIO_Init, 0
  11.417 +};
  11.418 +
  11.419 +#endif /* SDL_AUDIO_DRIVER_NETBSD */
  11.420 +
  11.421 +/* vi: set ts=4 sw=4 expandtab: */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/audio/netbsd/SDL_netbsdaudio.h	Wed May 24 19:56:59 2017 -0400
    12.3 @@ -0,0 +1,51 @@
    12.4 +/*
    12.5 +  Simple DirectMedia Layer
    12.6 +  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
    12.7 +
    12.8 +  This software is provided 'as-is', without any express or implied
    12.9 +  warranty.  In no event will the authors be held liable for any damages
   12.10 +  arising from the use of this software.
   12.11 +
   12.12 +  Permission is granted to anyone to use this software for any purpose,
   12.13 +  including commercial applications, and to alter it and redistribute it
   12.14 +  freely, subject to the following restrictions:
   12.15 +
   12.16 +  1. The origin of this software must not be misrepresented; you must not
   12.17 +     claim that you wrote the original software. If you use this software
   12.18 +     in a product, an acknowledgment in the product documentation would be
   12.19 +     appreciated but is not required.
   12.20 +  2. Altered source versions must be plainly marked as such, and must not be
   12.21 +     misrepresented as being the original software.
   12.22 +  3. This notice may not be removed or altered from any source distribution.
   12.23 +*/
   12.24 +#include "../../SDL_internal.h"
   12.25 +
   12.26 +#ifndef _SDL_bsdaudio_h
   12.27 +#define _SDL_bsdaudio_h
   12.28 +
   12.29 +#include "../SDL_sysaudio.h"
   12.30 +
   12.31 +#define _THIS   SDL_AudioDevice *this
   12.32 +
   12.33 +struct SDL_PrivateAudioData
   12.34 +{
   12.35 +    /* The file descriptor for the audio device */
   12.36 +    int audio_fd;
   12.37 +
   12.38 +    /* The parent process id, to detect when application quits */
   12.39 +    pid_t parent;
   12.40 +
   12.41 +    /* Raw mixing buffer */
   12.42 +    Uint8 *mixbuf;
   12.43 +    int mixlen;
   12.44 +
   12.45 +    /* Support for audio timing using a timer, in addition to select() */
   12.46 +    float frame_ticks;
   12.47 +    float next_frame;
   12.48 +};
   12.49 +
   12.50 +#define FUDGE_TICKS 10      /* The scheduler overhead ticks per frame */
   12.51 +
   12.52 +#endif /* _SDL_bsdaudio_h */
   12.53 +
   12.54 +/* vi: set ts=4 sw=4 expandtab: */