[Commits] SDL: audio: rename bsd target to netbsd.

libsdl.org revision control commits-owner at libsdl.org
Wed May 24 16:59:56 PDT 2017


details:   https://hg.libsdl.org/SDL/rev/25cd7fe50180
changeset: 11028:25cd7fe50180
user:      Ryan C. Gordon <icculus at icculus.org>
date:      Wed May 24 19:56:59 2017 -0400
description:
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.

diffstat:

 CMakeLists.txt                     |    8 +-
 configure                          |   20 +-
 configure.in                       |    4 +-
 include/SDL_config.h.cmake         |    2 +-
 include/SDL_config.h.in            |    2 +-
 src/audio/SDL_audio.c              |    4 +-
 src/audio/SDL_audiodev.c           |    2 +-
 src/audio/SDL_sysaudio.h           |    2 +-
 src/audio/bsd/SDL_bsdaudio.c       |  418 -------------------------------------
 src/audio/bsd/SDL_bsdaudio.h       |   51 ----
 src/audio/netbsd/SDL_netbsdaudio.c |  418 +++++++++++++++++++++++++++++++++++++
 src/audio/netbsd/SDL_netbsdaudio.h |   51 ++++
 12 files changed, 485 insertions(+), 497 deletions(-)

diffs (1113 lines):

diff -r 0bd1fbe480e0 -r 25cd7fe50180 CMakeLists.txt
--- a/CMakeLists.txt	Wed May 24 13:28:13 2017 -0400
+++ b/CMakeLists.txt	Wed May 24 19:56:59 2017 -0400
@@ -855,10 +855,10 @@
         file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
         set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
         set(HAVE_SDL_AUDIO TRUE)
-    elseif(NETBSD OR OPENBSD)
-        set(SDL_AUDIO_DRIVER_BSD 1)
-        file(GLOB BSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/bsd/*.c)
-        set(SOURCE_FILES ${SOURCE_FILES} ${BSD_AUDIO_SOURCES})
+    elseif(NETBSD)
+        set(SDL_AUDIO_DRIVER_NETBSD 1)
+        file(GLOB NETBSD_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/netbsd/*.c)
+        set(SOURCE_FILES ${SOURCE_FILES} ${NETBSD_AUDIO_SOURCES})
         set(HAVE_SDL_AUDIO TRUE)
     elseif(AIX)
         set(SDL_AUDIO_DRIVER_PAUDIO 1)
diff -r 0bd1fbe480e0 -r 25cd7fe50180 configure
--- a/configure	Wed May 24 13:28:13 2017 -0400
+++ b/configure	Wed May 24 19:56:59 2017 -0400
@@ -745,7 +745,6 @@
 docdir
 oldincludedir
 includedir
-runstatedir
 localstatedir
 sharedstatedir
 sysconfdir
@@ -917,7 +916,6 @@
 sysconfdir='${prefix}/etc'
 sharedstatedir='${prefix}/com'
 localstatedir='${prefix}/var'
-runstatedir='${localstatedir}/run'
 includedir='${prefix}/include'
 oldincludedir='/usr/include'
 docdir='${datarootdir}/doc/${PACKAGE}'
@@ -1170,15 +1168,6 @@
   | -silent | --silent | --silen | --sile | --sil)
     silent=yes ;;
 
-  -runstatedir | --runstatedir | --runstatedi | --runstated \
-  | --runstate | --runstat | --runsta | --runst | --runs \
-  | --run | --ru | --r)
-    ac_prev=runstatedir ;;
-  -runstatedir=* | --runstatedir=* | --runstatedi=* | --runstated=* \
-  | --runstate=* | --runstat=* | --runsta=* | --runst=* | --runs=* \
-  | --run=* | --ru=* | --r=*)
-    runstatedir=$ac_optarg ;;
-
   -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
     ac_prev=sbindir ;;
   -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
@@ -1316,7 +1305,7 @@
 for ac_var in	exec_prefix prefix bindir sbindir libexecdir datarootdir \
 		datadir sysconfdir sharedstatedir localstatedir includedir \
 		oldincludedir docdir infodir htmldir dvidir pdfdir psdir \
-		libdir localedir mandir runstatedir
+		libdir localedir mandir
 do
   eval ac_val=\$$ac_var
   # Remove trailing slashes.
@@ -1469,7 +1458,6 @@
   --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
   --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
   --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
-  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
   --libdir=DIR            object code libraries [EPREFIX/lib]
   --includedir=DIR        C header files [PREFIX/include]
   --oldincludedir=DIR     C header files for non-gcc [/usr/include]
@@ -23318,9 +23306,9 @@
             ;;
             netbsd)  # Don't use this on OpenBSD, it's busted.
 
-$as_echo "#define SDL_AUDIO_DRIVER_BSD 1" >>confdefs.h
-
-                SOURCES="$SOURCES $srcdir/src/audio/bsd/*.c"
+$as_echo "#define SDL_AUDIO_DRIVER_NETBSD 1" >>confdefs.h
+
+                SOURCES="$SOURCES $srcdir/src/audio/netbsd/*.c"
                 have_audio=yes
             ;;
             aix)
diff -r 0bd1fbe480e0 -r 25cd7fe50180 configure.in
--- a/configure.in	Wed May 24 13:28:13 2017 -0400
+++ b/configure.in	Wed May 24 19:56:59 2017 -0400
@@ -3074,8 +3074,8 @@
                 have_audio=yes
             ;;
             netbsd)  # Don't use this on OpenBSD, it's busted.
-                AC_DEFINE(SDL_AUDIO_DRIVER_BSD, 1, [ ])
-                SOURCES="$SOURCES $srcdir/src/audio/bsd/*.c"
+                AC_DEFINE(SDL_AUDIO_DRIVER_NETBSD, 1, [ ])
+                SOURCES="$SOURCES $srcdir/src/audio/netbsd/*.c"
                 have_audio=yes
             ;;
             aix)
diff -r 0bd1fbe480e0 -r 25cd7fe50180 include/SDL_config.h.cmake
--- a/include/SDL_config.h.cmake	Wed May 24 13:28:13 2017 -0400
+++ b/include/SDL_config.h.cmake	Wed May 24 19:56:59 2017 -0400
@@ -210,7 +210,7 @@
 #cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO @SDL_AUDIO_DRIVER_PULSEAUDIO@
 #cmakedefine SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC @SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC@
 #cmakedefine SDL_AUDIO_DRIVER_HAIKU @SDL_AUDIO_DRIVER_HAIKU@
-#cmakedefine SDL_AUDIO_DRIVER_BSD @SDL_AUDIO_DRIVER_BSD@
+#cmakedefine SDL_AUDIO_DRIVER_NETBSD @SDL_AUDIO_DRIVER_NETBSD@
 #cmakedefine SDL_AUDIO_DRIVER_COREAUDIO @SDL_AUDIO_DRIVER_COREAUDIO@
 #cmakedefine SDL_AUDIO_DRIVER_DISK @SDL_AUDIO_DRIVER_DISK@
 #cmakedefine SDL_AUDIO_DRIVER_DUMMY @SDL_AUDIO_DRIVER_DUMMY@
diff -r 0bd1fbe480e0 -r 25cd7fe50180 include/SDL_config.h.in
--- a/include/SDL_config.h.in	Wed May 24 13:28:13 2017 -0400
+++ b/include/SDL_config.h.in	Wed May 24 19:56:59 2017 -0400
@@ -209,7 +209,7 @@
 #undef SDL_AUDIO_DRIVER_PULSEAUDIO
 #undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC
 #undef SDL_AUDIO_DRIVER_HAIKU
-#undef SDL_AUDIO_DRIVER_BSD
+#undef SDL_AUDIO_DRIVER_NETBSD
 #undef SDL_AUDIO_DRIVER_COREAUDIO
 #undef SDL_AUDIO_DRIVER_DISK
 #undef SDL_AUDIO_DRIVER_DUMMY
diff -r 0bd1fbe480e0 -r 25cd7fe50180 src/audio/SDL_audio.c
--- a/src/audio/SDL_audio.c	Wed May 24 13:28:13 2017 -0400
+++ b/src/audio/SDL_audio.c	Wed May 24 19:56:59 2017 -0400
@@ -44,8 +44,8 @@
 #if SDL_AUDIO_DRIVER_SNDIO
     &SNDIO_bootstrap,
 #endif
-#if SDL_AUDIO_DRIVER_BSD
-    &BSD_AUDIO_bootstrap,
+#if SDL_AUDIO_DRIVER_NETBSD
+    &NETBSDAUDIO_bootstrap,
 #endif
 #if SDL_AUDIO_DRIVER_OSS
     &DSP_bootstrap,
diff -r 0bd1fbe480e0 -r 25cd7fe50180 src/audio/SDL_audiodev.c
--- a/src/audio/SDL_audiodev.c	Wed May 24 13:28:13 2017 -0400
+++ b/src/audio/SDL_audiodev.c	Wed May 24 19:56:59 2017 -0400
@@ -22,7 +22,7 @@
 
 /* Get the name of the audio device we use for output */
 
-#if SDL_AUDIO_DRIVER_BSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
+#if SDL_AUDIO_DRIVER_NETBSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
 
 #include <fcntl.h>
 #include <sys/types.h>
diff -r 0bd1fbe480e0 -r 25cd7fe50180 src/audio/SDL_sysaudio.h
--- a/src/audio/SDL_sysaudio.h	Wed May 24 13:28:13 2017 -0400
+++ b/src/audio/SDL_sysaudio.h	Wed May 24 19:56:59 2017 -0400
@@ -183,7 +183,7 @@
 extern AudioBootStrap PULSEAUDIO_bootstrap;
 extern AudioBootStrap ALSA_bootstrap;
 extern AudioBootStrap SNDIO_bootstrap;
-extern AudioBootStrap BSD_AUDIO_bootstrap;
+extern AudioBootStrap NETBSDAUDIO_bootstrap;
 extern AudioBootStrap DSP_bootstrap;
 extern AudioBootStrap QSAAUDIO_bootstrap;
 extern AudioBootStrap SUNAUDIO_bootstrap;
diff -r 0bd1fbe480e0 -r 25cd7fe50180 src/audio/bsd/SDL_bsdaudio.c
--- a/src/audio/bsd/SDL_bsdaudio.c	Wed May 24 13:28:13 2017 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,418 +0,0 @@
-/*
-  Simple DirectMedia Layer
-  Copyright (C) 1997-2017 Sam Lantinga <slouken at libsdl.org>
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#if SDL_AUDIO_DRIVER_BSD
-
-/*
- * Driver for native OpenBSD/NetBSD audio(4).
- * vedge at vedge.com.ar.
- */
-
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/audioio.h>
-
-#include "SDL_timer.h"
-#include "SDL_audio.h"
-#include "../SDL_audio_c.h"
-#include "../SDL_audiodev_c.h"
-#include "SDL_bsdaudio.h"
-
-/* Use timer for synchronization */
-/* #define USE_TIMER_SYNC */
-
-/* #define DEBUG_AUDIO */
-/* #define DEBUG_AUDIO_STREAM */
-
-
-static void
-BSDAUDIO_DetectDevices(void)
-{
-    SDL_EnumUnixAudioDevices(0, NULL);
-}
-
-
-static void
-BSDAUDIO_Status(_THIS)
-{
-#ifdef DEBUG_AUDIO
-    /* *INDENT-OFF* */
-    audio_info_t info;
-    const audio_prinfo *prinfo;
-
-    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
-        fprintf(stderr, "AUDIO_GETINFO failed.\n");
-        return;
-    }
-
-    prinfo = this->iscapture ? &info.play : &info.record;
-
-    fprintf(stderr, "\n"
-            "[%s info]\n"
-            "buffer size	:   %d bytes\n"
-            "sample rate	:   %i Hz\n"
-            "channels	:   %i\n"
-            "precision	:   %i-bit\n"
-            "encoding	:   0x%x\n"
-            "seek		:   %i\n"
-            "sample count	:   %i\n"
-            "EOF count	:   %i\n"
-            "paused		:   %s\n"
-            "error occured	:   %s\n"
-            "waiting		:   %s\n"
-            "active		:   %s\n"
-            "",
-            this->iscapture ? "record" : "play",
-            prinfo->buffer_size,
-            prinfo->sample_rate,
-            prinfo->channels,
-            prinfo->precision,
-            prinfo->encoding,
-            prinfo->seek,
-            prinfo->samples,
-            prinfo->eof,
-            prinfo->pause ? "yes" : "no",
-            prinfo->error ? "yes" : "no",
-            prinfo->waiting ? "yes" : "no",
-            prinfo->active ? "yes" : "no");
-
-    fprintf(stderr, "\n"
-            "[audio info]\n"
-            "monitor_gain	:   %i\n"
-            "hw block size	:   %d bytes\n"
-            "hi watermark	:   %i\n"
-            "lo watermark	:   %i\n"
-            "audio mode	:   %s\n"
-            "",
-            info.monitor_gain,
-            info.blocksize,
-            info.hiwat, info.lowat,
-            (info.mode == AUMODE_PLAY) ? "PLAY"
-            : (info.mode = AUMODE_RECORD) ? "RECORD"
-            : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
-    /* *INDENT-ON* */
-#endif /* DEBUG_AUDIO */
-}
-
-
-/* This function waits until it is possible to write a full sound buffer */
-static void
-BSDAUDIO_WaitDevice(_THIS)
-{
-#ifndef USE_BLOCKING_WRITES     /* Not necessary when using blocking writes */
-    /* See if we need to use timed audio synchronization */
-    if (this->hidden->frame_ticks) {
-        /* Use timer for general audio synchronization */
-        Sint32 ticks;
-
-        ticks = ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
-        if (ticks > 0) {
-            SDL_Delay(ticks);
-        }
-    } else {
-        /* Use select() for audio synchronization */
-        fd_set fdset;
-        struct timeval timeout;
-
-        FD_ZERO(&fdset);
-        FD_SET(this->hidden->audio_fd, &fdset);
-        timeout.tv_sec = 10;
-        timeout.tv_usec = 0;
-#ifdef DEBUG_AUDIO
-        fprintf(stderr, "Waiting for audio to get ready\n");
-#endif
-        if (select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, &timeout)
-            <= 0) {
-            const char *message =
-                "Audio timeout - buggy audio driver? (disabled)";
-            /* In general we should never print to the screen,
-               but in this case we have no other way of letting
-               the user know what happened.
-             */
-            fprintf(stderr, "SDL: %s\n", message);
-            SDL_OpenedAudioDeviceDisconnected(this);
-            /* Don't try to close - may hang */
-            this->hidden->audio_fd = -1;
-#ifdef DEBUG_AUDIO
-            fprintf(stderr, "Done disabling audio\n");
-#endif
-        }
-#ifdef DEBUG_AUDIO
-        fprintf(stderr, "Ready!\n");
-#endif
-    }
-#endif /* !USE_BLOCKING_WRITES */
-}
-
-static void
-BSDAUDIO_PlayDevice(_THIS)
-{
-    int written, p = 0;
-
-    /* Write the audio data, checking for EAGAIN on broken audio drivers */
-    do {
-        written = write(this->hidden->audio_fd,
-                        &this->hidden->mixbuf[p], this->hidden->mixlen - p);
-
-        if (written > 0)
-            p += written;
-        if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
-            /* Non recoverable error has occurred. It should be reported!!! */
-            perror("audio");
-            break;
-        }
-
-#ifdef DEBUG_AUDIO
-        fprintf(stderr, "Wrote %d bytes of audio data\n", written);
-#endif
-
-        if (p < this->hidden->mixlen
-            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
-            SDL_Delay(1);       /* Let a little CPU time go by */
-        }
-    } while (p < this->hidden->mixlen);
-
-    /* If timer synchronization is enabled, set the next write frame */
-    if (this->hidden->frame_ticks) {
-        this->hidden->next_frame += this->hidden->frame_ticks;
-    }
-
-    /* If we couldn't write, assume fatal error for now */
-    if (written < 0) {
-        SDL_OpenedAudioDeviceDisconnected(this);
-    }
-}
-
-static Uint8 *
-BSDAUDIO_GetDeviceBuf(_THIS)
-{
-    return (this->hidden->mixbuf);
-}
-
-
-static int
-BSDAUDIO_CaptureFromDevice(_THIS, void *_buffer, int buflen)
-{
-    Uint8 *buffer = (Uint8 *) _buffer;
-    int br, p = 0;
-
-    /* Write the audio data, checking for EAGAIN on broken audio drivers */
-    do {
-        br = read(this->hidden->audio_fd, buffer + p, buflen - p);
-        if (br > 0)
-            p += br;
-        if (br == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
-            /* Non recoverable error has occurred. It should be reported!!! */
-            perror("audio");
-            return p ? p : -1;
-        }
-
-#ifdef DEBUG_AUDIO
-        fprintf(stderr, "Captured %d bytes of audio data\n", br);
-#endif
-
-        if (p < buflen
-            || ((br < 0) && ((errno == 0) || (errno == EAGAIN)))) {
-            SDL_Delay(1);       /* Let a little CPU time go by */
-        }
-    } while (p < buflen);
-}
-
-static void
-BSDAUDIO_FlushCapture(_THIS)
-{
-    audio_info_t info;
-    size_t remain;
-    Uint8 buf[512];
-
-    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
-        return;  /* oh well. */
-    }
-
-    remain = (size_t) (info.record.samples * (SDL_AUDIO_BITSIZE(this->spec.format) / 8));
-    while (remain > 0) {
-        const size_t len = SDL_min(sizeof (buf), remain);
-        const int br = read(this->hidden->audio_fd, buf, len);
-        if (br <= 0) {
-            return;  /* oh well. */
-        }
-        remain -= br;
-    }
-}
-
-static void
-BSDAUDIO_CloseDevice(_THIS)
-{
-    if (this->hidden->audio_fd >= 0) {
-        close(this->hidden->audio_fd);
-    }
-    SDL_free(this->hidden->mixbuf);
-    SDL_free(this->hidden);
-}
-
-static int
-BSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
-{
-    const int flags = iscapture ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT;
-    SDL_AudioFormat format = 0;
-    audio_info_t info;
-    audio_prinfo *prinfo = iscapture ? &info.play : &info.record;
-
-    /* We don't care what the devname is...we'll try to open anything. */
-    /*  ...but default to first name in the list... */
-    if (devname == NULL) {
-        devname = SDL_GetAudioDeviceName(0, iscapture);
-        if (devname == NULL) {
-            return SDL_SetError("No such audio device");
-        }
-    }
-
-    /* Initialize all variables that we clean on shutdown */
-    this->hidden = (struct SDL_PrivateAudioData *)
-        SDL_malloc((sizeof *this->hidden));
-    if (this->hidden == NULL) {
-        return SDL_OutOfMemory();
-    }
-    SDL_zerop(this->hidden);
-
-    /* Open the audio device */
-    this->hidden->audio_fd = open(devname, flags, 0);
-    if (this->hidden->audio_fd < 0) {
-        return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
-    }
-
-    AUDIO_INITINFO(&info);
-
-    /* Calculate the final parameters for this audio specification */
-    SDL_CalculateAudioSpec(&this->spec);
-
-    /* Set to play mode */
-    info.mode = iscapture ? AUMODE_RECORD : AUMODE_PLAY;
-    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
-        return SDL_SetError("Couldn't put device into play mode");
-    }
-
-    AUDIO_INITINFO(&info);
-    for (format = SDL_FirstAudioFormat(this->spec.format);
-         format; format = SDL_NextAudioFormat()) {
-        switch (format) {
-        case AUDIO_U8:
-            prinfo->encoding = AUDIO_ENCODING_ULINEAR;
-            prinfo->precision = 8;
-            break;
-        case AUDIO_S8:
-            prinfo->encoding = AUDIO_ENCODING_SLINEAR;
-            prinfo->precision = 8;
-            break;
-        case AUDIO_S16LSB:
-            prinfo->encoding = AUDIO_ENCODING_SLINEAR_LE;
-            prinfo->precision = 16;
-            break;
-        case AUDIO_S16MSB:
-            prinfo->encoding = AUDIO_ENCODING_SLINEAR_BE;
-            prinfo->precision = 16;
-            break;
-        case AUDIO_U16LSB:
-            prinfo->encoding = AUDIO_ENCODING_ULINEAR_LE;
-            prinfo->precision = 16;
-            break;
-        case AUDIO_U16MSB:
-            prinfo->encoding = AUDIO_ENCODING_ULINEAR_BE;
-            prinfo->precision = 16;
-            break;
-        default:
-            continue;
-        }
-
-        if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
-            break;
-        }
-    }
-
-    if (!format) {
-        return SDL_SetError("No supported encoding for 0x%x", this->spec.format);
-    }
-
-    this->spec.format = format;
-
-    AUDIO_INITINFO(&info);
-    prinfo->channels = this->spec.channels;
-    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
-        this->spec.channels = 1;
-    }
-    AUDIO_INITINFO(&info);
-    prinfo->sample_rate = this->spec.freq;
-    info.blocksize = this->spec.size;
-    info.hiwat = 5;
-    info.lowat = 3;
-    (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
-    (void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
-    this->spec.freq = prinfo->sample_rate;
-
-    if (!iscapture) {
-        /* Allocate mixing buffer */
-        this->hidden->mixlen = this->spec.size;
-        this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
-        if (this->hidden->mixbuf == NULL) {
-            return SDL_OutOfMemory();
-        }
-        SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
-    }
-
-    BSDAUDIO_Status(this);
-
-    /* We're ready to rock and roll. :-) */
-    return 0;
-}
-
-static int
-BSDAUDIO_Init(SDL_AudioDriverImpl * impl)
-{
-    /* Set the function pointers */
-    impl->DetectDevices = BSDAUDIO_DetectDevices;
-    impl->OpenDevice = BSDAUDIO_OpenDevice;
-    impl->PlayDevice = BSDAUDIO_PlayDevice;
-    impl->WaitDevice = BSDAUDIO_WaitDevice;
-    impl->GetDeviceBuf = BSDAUDIO_GetDeviceBuf;
-    impl->CloseDevice = BSDAUDIO_CloseDevice;
-    impl->CaptureFromDevice = BSDAUDIO_CaptureFromDevice;
-    impl->FlushCapture = BSDAUDIO_FlushCapture;
-
-    impl->HasCaptureSupport = SDL_TRUE;
-    impl->AllowsArbitraryDeviceNames = 1;
-
-    return 1;   /* this audio target is available. */
-}
-
-
-AudioBootStrap BSD_AUDIO_bootstrap = {
-    "bsd", "BSD audio", BSDAUDIO_Init, 0
-};
-
-#endif /* SDL_AUDIO_DRIVER_BSD */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff -r 0bd1fbe480e0 -r 25cd7fe50180 src/audio/bsd/SDL_bsdaudio.h
--- a/src/audio/bsd/SDL_bsdaudio.h	Wed May 24 13:28:13 2017 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-/*
-  Simple DirectMedia Layer
-  Copyright (C) 1997-2017 Sam Lantinga <slouken at libsdl.org>
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-*/
-#include "../../SDL_internal.h"
-
-#ifndef _SDL_bsdaudio_h
-#define _SDL_bsdaudio_h
-
-#include "../SDL_sysaudio.h"
-
-#define _THIS   SDL_AudioDevice *this
-
-struct SDL_PrivateAudioData
-{
-    /* The file descriptor for the audio device */
-    int audio_fd;
-
-    /* The parent process id, to detect when application quits */
-    pid_t parent;
-
-    /* Raw mixing buffer */
-    Uint8 *mixbuf;
-    int mixlen;
-
-    /* Support for audio timing using a timer, in addition to select() */
-    float frame_ticks;
-    float next_frame;
-};
-
-#define FUDGE_TICKS 10      /* The scheduler overhead ticks per frame */
-
-#endif /* _SDL_bsdaudio_h */
-
-/* vi: set ts=4 sw=4 expandtab: */
diff -r 0bd1fbe480e0 -r 25cd7fe50180 src/audio/netbsd/SDL_netbsdaudio.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audio/netbsd/SDL_netbsdaudio.c	Wed May 24 19:56:59 2017 -0400
@@ -0,0 +1,418 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2017 Sam Lantinga <slouken at libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#if SDL_AUDIO_DRIVER_NETBSD
+
+/*
+ * Driver for native NetBSD audio(4).
+ * vedge at vedge.com.ar.
+ */
+
+#include <errno.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/time.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/audioio.h>
+
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "../SDL_audio_c.h"
+#include "../SDL_audiodev_c.h"
+#include "SDL_bsdaudio.h"
+
+/* Use timer for synchronization */
+/* #define USE_TIMER_SYNC */
+
+/* #define DEBUG_AUDIO */
+/* #define DEBUG_AUDIO_STREAM */
+
+
+static void
+NETBSDAUDIO_DetectDevices(void)
+{
+    SDL_EnumUnixAudioDevices(0, NULL);
+}
+
+
+static void
+NETBSDAUDIO_Status(_THIS)
+{
+#ifdef DEBUG_AUDIO
+    /* *INDENT-OFF* */
+    audio_info_t info;
+    const audio_prinfo *prinfo;
+
+    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
+        fprintf(stderr, "AUDIO_GETINFO failed.\n");
+        return;
+    }
+
+    prinfo = this->iscapture ? &info.play : &info.record;
+
+    fprintf(stderr, "\n"
+            "[%s info]\n"
+            "buffer size	:   %d bytes\n"
+            "sample rate	:   %i Hz\n"
+            "channels	:   %i\n"
+            "precision	:   %i-bit\n"
+            "encoding	:   0x%x\n"
+            "seek		:   %i\n"
+            "sample count	:   %i\n"
+            "EOF count	:   %i\n"
+            "paused		:   %s\n"
+            "error occured	:   %s\n"
+            "waiting		:   %s\n"
+            "active		:   %s\n"
+            "",
+            this->iscapture ? "record" : "play",
+            prinfo->buffer_size,
+            prinfo->sample_rate,
+            prinfo->channels,
+            prinfo->precision,
+            prinfo->encoding,
+            prinfo->seek,
+            prinfo->samples,
+            prinfo->eof,
+            prinfo->pause ? "yes" : "no",
+            prinfo->error ? "yes" : "no",
+            prinfo->waiting ? "yes" : "no",
+            prinfo->active ? "yes" : "no");
+
+    fprintf(stderr, "\n"
+            "[audio info]\n"
+            "monitor_gain	:   %i\n"
+            "hw block size	:   %d bytes\n"
+            "hi watermark	:   %i\n"
+            "lo watermark	:   %i\n"
+            "audio mode	:   %s\n"
+            "",
+            info.monitor_gain,
+            info.blocksize,
+            info.hiwat, info.lowat,
+            (info.mode == AUMODE_PLAY) ? "PLAY"
+            : (info.mode = AUMODE_RECORD) ? "RECORD"
+            : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
+    /* *INDENT-ON* */
+#endif /* DEBUG_AUDIO */
+}
+
+
+/* This function waits until it is possible to write a full sound buffer */
+static void
+NETBSDAUDIO_WaitDevice(_THIS)
+{
+#ifndef USE_BLOCKING_WRITES     /* Not necessary when using blocking writes */
+    /* See if we need to use timed audio synchronization */
+    if (this->hidden->frame_ticks) {
+        /* Use timer for general audio synchronization */
+        Sint32 ticks;
+
+        ticks = ((Sint32) (this->hidden->next_frame - SDL_GetTicks())) - FUDGE_TICKS;
+        if (ticks > 0) {
+            SDL_Delay(ticks);
+        }
+    } else {
+        /* Use select() for audio synchronization */
+        fd_set fdset;
+        struct timeval timeout;
+
+        FD_ZERO(&fdset);
+        FD_SET(this->hidden->audio_fd, &fdset);
+        timeout.tv_sec = 10;
+        timeout.tv_usec = 0;
+#ifdef DEBUG_AUDIO
+        fprintf(stderr, "Waiting for audio to get ready\n");
+#endif
+        if (select(this->hidden->audio_fd + 1, NULL, &fdset, NULL, &timeout)
+            <= 0) {
+            const char *message =
+                "Audio timeout - buggy audio driver? (disabled)";
+            /* In general we should never print to the screen,
+               but in this case we have no other way of letting
+               the user know what happened.
+             */
+            fprintf(stderr, "SDL: %s\n", message);
+            SDL_OpenedAudioDeviceDisconnected(this);
+            /* Don't try to close - may hang */
+            this->hidden->audio_fd = -1;
+#ifdef DEBUG_AUDIO
+            fprintf(stderr, "Done disabling audio\n");
+#endif
+        }
+#ifdef DEBUG_AUDIO
+        fprintf(stderr, "Ready!\n");
+#endif
+    }
+#endif /* !USE_BLOCKING_WRITES */
+}
+
+static void
+NETBSDAUDIO_PlayDevice(_THIS)
+{
+    int written, p = 0;
+
+    /* Write the audio data, checking for EAGAIN on broken audio drivers */
+    do {
+        written = write(this->hidden->audio_fd,
+                        &this->hidden->mixbuf[p], this->hidden->mixlen - p);
+
+        if (written > 0)
+            p += written;
+        if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
+            /* Non recoverable error has occurred. It should be reported!!! */
+            perror("audio");
+            break;
+        }
+
+#ifdef DEBUG_AUDIO
+        fprintf(stderr, "Wrote %d bytes of audio data\n", written);
+#endif
+
+        if (p < this->hidden->mixlen
+            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
+            SDL_Delay(1);       /* Let a little CPU time go by */
+        }
+    } while (p < this->hidden->mixlen);
+
+    /* If timer synchronization is enabled, set the next write frame */
+    if (this->hidden->frame_ticks) {
+        this->hidden->next_frame += this->hidden->frame_ticks;
+    }
+
+    /* If we couldn't write, assume fatal error for now */
+    if (written < 0) {
+        SDL_OpenedAudioDeviceDisconnected(this);
+    }
+}
+
+static Uint8 *
+NETBSDAUDIO_GetDeviceBuf(_THIS)
+{
+    return (this->hidden->mixbuf);
+}
+
+
+static int
+NETBSDAUDIO_CaptureFromDevice(_THIS, void *_buffer, int buflen)
+{
+    Uint8 *buffer = (Uint8 *) _buffer;
+    int br, p = 0;
+
+    /* Write the audio data, checking for EAGAIN on broken audio drivers */
+    do {
+        br = read(this->hidden->audio_fd, buffer + p, buflen - p);
+        if (br > 0)
+            p += br;
+        if (br == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
+            /* Non recoverable error has occurred. It should be reported!!! */
+            perror("audio");
+            return p ? p : -1;
+        }
+
+#ifdef DEBUG_AUDIO
+        fprintf(stderr, "Captured %d bytes of audio data\n", br);
+#endif
+
+        if (p < buflen
+            || ((br < 0) && ((errno == 0) || (errno == EAGAIN)))) {
+            SDL_Delay(1);       /* Let a little CPU time go by */
+        }
+    } while (p < buflen);
+}
+
+static void
+NETBSDAUDIO_FlushCapture(_THIS)
+{
+    audio_info_t info;
+    size_t remain;
+    Uint8 buf[512];
+
+    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
+        return;  /* oh well. */
+    }
+
+    remain = (size_t) (info.record.samples * (SDL_AUDIO_BITSIZE(this->spec.format) / 8));
+    while (remain > 0) {
+        const size_t len = SDL_min(sizeof (buf), remain);
+        const int br = read(this->hidden->audio_fd, buf, len);
+        if (br <= 0) {
+            return;  /* oh well. */
+        }
+        remain -= br;
+    }
+}
+
+static void
+NETBSDAUDIO_CloseDevice(_THIS)
+{
+    if (this->hidden->audio_fd >= 0) {
+        close(this->hidden->audio_fd);
+    }
+    SDL_free(this->hidden->mixbuf);
+    SDL_free(this->hidden);
+}
+
+static int
+NETBSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture)
+{
+    const int flags = iscapture ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT;
+    SDL_AudioFormat format = 0;
+    audio_info_t info;
+    audio_prinfo *prinfo = iscapture ? &info.play : &info.record;
+
+    /* We don't care what the devname is...we'll try to open anything. */
+    /*  ...but default to first name in the list... */
+    if (devname == NULL) {
+        devname = SDL_GetAudioDeviceName(0, iscapture);
+        if (devname == NULL) {
+            return SDL_SetError("No such audio device");
+        }
+    }
+
+    /* Initialize all variables that we clean on shutdown */
+    this->hidden = (struct SDL_PrivateAudioData *)
+        SDL_malloc((sizeof *this->hidden));
+    if (this->hidden == NULL) {
+        return SDL_OutOfMemory();
+    }
+    SDL_zerop(this->hidden);
+
+    /* Open the audio device */
+    this->hidden->audio_fd = open(devname, flags, 0);
+    if (this->hidden->audio_fd < 0) {
+        return SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
+    }
+
+    AUDIO_INITINFO(&info);
+
+    /* Calculate the final parameters for this audio specification */
+    SDL_CalculateAudioSpec(&this->spec);
+
+    /* Set to play mode */
+    info.mode = iscapture ? AUMODE_RECORD : AUMODE_PLAY;
+    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
+        return SDL_SetError("Couldn't put device into play mode");
+    }
+
+    AUDIO_INITINFO(&info);
+    for (format = SDL_FirstAudioFormat(this->spec.format);
+         format; format = SDL_NextAudioFormat()) {
+        switch (format) {
+        case AUDIO_U8:
+            prinfo->encoding = AUDIO_ENCODING_ULINEAR;
+            prinfo->precision = 8;
+            break;
+        case AUDIO_S8:
+            prinfo->encoding = AUDIO_ENCODING_SLINEAR;
+            prinfo->precision = 8;
+            break;
+        case AUDIO_S16LSB:
+            prinfo->encoding = AUDIO_ENCODING_SLINEAR_LE;
+            prinfo->precision = 16;
+            break;
+        case AUDIO_S16MSB:
+            prinfo->encoding = AUDIO_ENCODING_SLINEAR_BE;
+            prinfo->precision = 16;
+            break;
+        case AUDIO_U16LSB:
+            prinfo->encoding = AUDIO_ENCODING_ULINEAR_LE;
+            prinfo->precision = 16;
+            break;
+        case AUDIO_U16MSB:
+            prinfo->encoding = AUDIO_ENCODING_ULINEAR_BE;
+            prinfo->precision = 16;
+            break;
+        default:
+            continue;
+        }
+
+        if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
+            break;
+        }
+    }
+
+    if (!format) {
+        return SDL_SetError("No supported encoding for 0x%x", this->spec.format);
+    }
+
+    this->spec.format = format;
+
+    AUDIO_INITINFO(&info);
+    prinfo->channels = this->spec.channels;
+    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
+        this->spec.channels = 1;
+    }
+    AUDIO_INITINFO(&info);
+    prinfo->sample_rate = this->spec.freq;
+    info.blocksize = this->spec.size;
+    info.hiwat = 5;
+    info.lowat = 3;
+    (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
+    (void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
+    this->spec.freq = prinfo->sample_rate;
+
+    if (!iscapture) {
+        /* Allocate mixing buffer */
+        this->hidden->mixlen = this->spec.size;
+        this->hidden->mixbuf = (Uint8 *) SDL_malloc(this->hidden->mixlen);
+        if (this->hidden->mixbuf == NULL) {
+            return SDL_OutOfMemory();
+        }
+        SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
+    }
+
+    NETBSDAUDIO_Status(this);
+
+    /* We're ready to rock and roll. :-) */
+    return 0;
+}
+
+static int
+NETBSDAUDIO_Init(SDL_AudioDriverImpl * impl)
+{
+    /* Set the function pointers */
+    impl->DetectDevices = NETBSDAUDIO_DetectDevices;
+    impl->OpenDevice = NETBSDAUDIO_OpenDevice;
+    impl->PlayDevice = NETBSDAUDIO_PlayDevice;
+    impl->WaitDevice = NETBSDAUDIO_WaitDevice;
+    impl->GetDeviceBuf = NETBSDAUDIO_GetDeviceBuf;
+    impl->CloseDevice = NETBSDAUDIO_CloseDevice;
+    impl->CaptureFromDevice = NETBSDAUDIO_CaptureFromDevice;
+    impl->FlushCapture = NETBSDAUDIO_FlushCapture;
+
+    impl->HasCaptureSupport = SDL_TRUE;
+    impl->AllowsArbitraryDeviceNames = 1;
+
+    return 1;   /* this audio target is available. */
+}
+
+
+AudioBootStrap NETBSDAUDIO_bootstrap = {
+    "netbsd", "NetBSD audio", NETBSDAUDIO_Init, 0
+};
+
+#endif /* SDL_AUDIO_DRIVER_NETBSD */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff -r 0bd1fbe480e0 -r 25cd7fe50180 src/audio/netbsd/SDL_netbsdaudio.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/audio/netbsd/SDL_netbsdaudio.h	Wed May 24 19:56:59 2017 -0400
@@ -0,0 +1,51 @@
+/*
+  Simple DirectMedia Layer
+  Copyright (C) 1997-2017 Sam Lantinga <slouken at libsdl.org>
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+*/
+#include "../../SDL_internal.h"
+
+#ifndef _SDL_bsdaudio_h
+#define _SDL_bsdaudio_h
+
+#include "../SDL_sysaudio.h"
+
+#define _THIS   SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData
+{
+    /* The file descriptor for the audio device */
+    int audio_fd;
+
+    /* The parent process id, to detect when application quits */
+    pid_t parent;
+
+    /* Raw mixing buffer */
+    Uint8 *mixbuf;
+    int mixlen;
+
+    /* Support for audio timing using a timer, in addition to select() */
+    float frame_ticks;
+    float next_frame;
+};
+
+#define FUDGE_TICKS 10      /* The scheduler overhead ticks per frame */
+
+#endif /* _SDL_bsdaudio_h */
+
+/* vi: set ts=4 sw=4 expandtab: */


More information about the commits mailing list