changeset 3820:1f156fd874fa SDL-ryan-multiple-audio-device

Moved more audio drivers to 1.3 API (all 5 MiNT backends, BSD, IRIX...), and some other tweaks in already-converted drivers.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 07 Oct 2006 05:36:36 +0000
parents b225d9820ee3
children 18393b045759
files src/audio/bsd/SDL_bsdaudio.c src/audio/bsd/SDL_bsdaudio.h src/audio/dmedia/SDL_irixaudio.c src/audio/dmedia/SDL_irixaudio.h src/audio/dsp/SDL_dspaudio.c src/audio/macrom/SDL_romaudio.c src/audio/mint/SDL_mintaudio_dma8.c src/audio/mint/SDL_mintaudio_gsxb.c src/audio/mint/SDL_mintaudio_mcsn.c src/audio/mint/SDL_mintaudio_stfa.c src/audio/mint/SDL_mintaudio_xbios.c
diffstat 11 files changed, 844 insertions(+), 989 deletions(-) [+]
line wrap: on
line diff
--- a/src/audio/bsd/SDL_bsdaudio.c	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/bsd/SDL_bsdaudio.c	Sat Oct 07 05:36:36 2006 +0000
@@ -61,195 +61,102 @@
 /* #define DEBUG_AUDIO_STREAM */
 
 #ifdef USE_BLOCKING_WRITES
-#define OPEN_FLAGS	O_WRONLY
+#define OPEN_FLAGS_OUTPUT O_WRONLY
+#define OPEN_FLAGS_INPUT O_RDONLY
 #else
-#define OPEN_FLAGS	(O_WRONLY|O_NONBLOCK)
-#endif
-
-/* Audio driver functions */
-static void OBSD_WaitAudio(_THIS);
-static int OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec);
-static void OBSD_PlayAudio(_THIS);
-static Uint8 *OBSD_GetAudioBuf(_THIS);
-static void OBSD_CloseAudio(_THIS);
-
-#ifdef DEBUG_AUDIO
-static void OBSD_Status(_THIS);
+#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
+#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
 #endif
 
-/* Audio driver bootstrap functions */
-
-static int
-Audio_Available(void)
-{
-    int fd;
-    int available;
+/* !!! FIXME: so much cut and paste with dsp/dma drivers... */
+static char **outputDevices = NULL;
+static int outputDeviceCount = 0;
+static char **inputDevices = NULL;
+static int inputDeviceCount = 0;
 
-    available = 0;
-    fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
-    if (fd >= 0) {
-        available = 1;
-        close(fd);
-    }
-    return (available);
+static inline void
+free_device_list(char ***devs, int *count)
+{
+    SDL_FreeUnixAudioDevices(devs, count);
 }
 
-static void
-Audio_DeleteDevice(SDL_AudioDevice * device)
+static inline void
+build_device_list(int iscapture, char ***devs, int *count)
 {
-    SDL_free(device->hidden);
-    SDL_free(device);
+    const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
+    free_device_list(devs, count);
+    SDL_EnumUnixAudioDevices(flags, 0, NULL, devs, count);
 }
 
-static SDL_AudioDevice *
-Audio_CreateDevice(int devindex)
+static inline void
+build_device_lists(void)
 {
-    SDL_AudioDevice *this;
+    build_device_list(0, &outputDevices, &outputDeviceCount);
+    build_device_list(1, &inputDevices, &inputDeviceCount);
+}
 
-    /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
-    if (this) {
-        SDL_memset(this, 0, (sizeof *this));
-        this->hidden = (struct SDL_PrivateAudioData *)
-            SDL_malloc((sizeof *this->hidden));
-    }
-    if ((this == NULL) || (this->hidden == NULL)) {
-        SDL_OutOfMemory();
-        if (this)
-            SDL_free(this);
-        return (0);
-    }
-    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
-    audio_fd = -1;
 
-    /* Set the function pointers */
-    this->OpenAudio = OBSD_OpenAudio;
-    this->WaitAudio = OBSD_WaitAudio;
-    this->PlayAudio = OBSD_PlayAudio;
-    this->GetAudioBuf = OBSD_GetAudioBuf;
-    this->CloseAudio = OBSD_CloseAudio;
-
-    this->free = Audio_DeleteDevice;
-
-    return this;
+static inline void
+free_device_lists(void)
+{
+    free_device_list(&outputDevices, &outputDeviceCount);
+    free_device_list(&inputDevices, &inputDeviceCount);
 }
 
-AudioBootStrap BSD_AUDIO_bootstrap = {
-    BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
-    Audio_Available, Audio_CreateDevice, 0
-};
-
-/* This function waits until it is possible to write a full sound buffer */
-static void
-OBSD_WaitAudio(_THIS)
-{
-#ifndef USE_BLOCKING_WRITES     /* Not necessary when using blocking writes */
-    /* See if we need to use timed audio synchronization */
-    if (frame_ticks) {
-        /* Use timer for general audio synchronization */
-        Sint32 ticks;
-
-        ticks = ((Sint32) (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(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(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);
-            this->enabled = 0;
-            /* Don't try to close - may hang */
-            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 int
+BSDAUDIO_Available(void)
+{
+    int available = 0;
+    build_device_lists();
+    available = ((outputDeviceCount > 0) || (inputDeviceCount > 0));
+    free_device_lists();
+    return available;
 }
 
+
 static void
-OBSD_PlayAudio(_THIS)
+BSDAUDIO_Deinitialize(void)
 {
-    int written, p = 0;
+    free_device_lists();
+}
+
 
-    /* Write the audio data, checking for EAGAIN on broken audio drivers */
-    do {
-        written = write(audio_fd, &mixbuf[p], 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;
-        }
-
-        if (p < written
-            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
-            SDL_Delay(1);       /* Let a little CPU time go by */
-        }
-    }
-    while (p < written);
-
-    /* If timer synchronization is enabled, set the next write frame */
-    if (frame_ticks) {
-        next_frame += frame_ticks;
+static int
+BSDAUDIO_DetectDevices(int iscapture)
+{
+    if (iscapture) {
+        build_device_list(1, &inputDevices, &inputDeviceCount);
+        return inputDeviceCount;
+    } else {
+        build_device_list(0, &outputDevices, &outputDeviceCount);
+        return outputDeviceCount;
     }
 
-    /* If we couldn't write, assume fatal error for now */
-    if (written < 0) {
-        this->enabled = 0;
-    }
-#ifdef DEBUG_AUDIO
-    fprintf(stderr, "Wrote %d bytes of audio data\n", written);
-#endif
+    return 0;  /* shouldn't ever hit this. */
 }
 
-static Uint8 *
-OBSD_GetAudioBuf(_THIS)
+static const char *
+BSDAUDIO_GetDeviceName(int index, int iscapture)
 {
-    return (mixbuf);
+    if ((iscapture) && (index < inputDeviceCount)) {
+        return inputDevices[index];
+    } else if ((!iscapture) && (index < outputDeviceCount)) {
+        return outputDevices[index];
+    }
+
+    SDL_SetError("No such device");
+    return NULL;
 }
 
+
 static void
-OBSD_CloseAudio(_THIS)
+BSDAUDIO_Status(_THIS)
 {
-    if (mixbuf != NULL) {
-        SDL_FreeAudioMem(mixbuf);
-        mixbuf = NULL;
-    }
-    if (audio_fd >= 0) {
-        close(audio_fd);
-        audio_fd = -1;
-    }
-}
-
 #ifdef DEBUG_AUDIO
-void
-OBSD_Status(_THIS)
-{
     audio_info_t info;
 
-    if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
+    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
         fprintf(stderr, "AUDIO_GETINFO failed.\n");
         return;
     }
@@ -296,42 +203,170 @@
             (info.mode == AUMODE_PLAY) ? "PLAY"
             : (info.mode = AUMODE_RECORD) ? "RECORD"
             : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
+#endif /* DEBUG_AUDIO */
 }
-#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);
+            this->enabled = 0;
+            /* 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;
+        }
+
+        if (p < written
+            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
+            SDL_Delay(1);       /* Let a little CPU time go by */
+        }
+    }
+    while (p < written);
+
+    /* 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) {
+        this->enabled = 0;
+    }
+#ifdef DEBUG_AUDIO
+    fprintf(stderr, "Wrote %d bytes of audio data\n", written);
+#endif
+}
+
+static Uint8 *
+BSDAUDIO_GetDeviceBuf(_THIS)
+{
+    return (this->hidden->mixbuf);
+}
+
+static void
+BSDAUDIO_CloseDevice(_THIS)
+{
+    if (this->hidden != NULL) {
+        if (this->hidden->mixbuf != NULL) {
+            SDL_FreeAudioMem(this->hidden->mixbuf);
+            this->hidden->mixbuf = NULL;
+        }
+        if (this->hidden->audio_fd >= 0) {
+            close(this->hidden->audio_fd);
+            this->hidden->audio_fd = -1;
+        }
+        SDL_free(this->hidden);
+        this->hidden = NULL;
+    }
+}
 
 static int
-OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec)
+BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
 {
-    char audiodev[64];
-    SDL_AudioFormat format;
+    const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
+    SDL_AudioFormat format = 0;
     audio_info_t info;
 
+    /* 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) {
+        if ( ((iscapture) && (inputDeviceCount == 0)) ||
+             ((!iscapture) && (outputDeviceCount == 0)) ) {
+            SDL_SetError("No such audio device");
+            return 0;
+        }
+        devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
+    }
+
+    /* Initialize all variables that we clean on shutdown */
+    this->hidden = (struct SDL_PrivateAudioData *)
+                        SDL_malloc((sizeof *this->hidden));
+    if (this->hidden == NULL) {
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+
+    /* Open the audio device */
+    this->hidden->audio_fd = open(devname, flags, 0);
+    if (this->hidden->audio_fd < 0) {
+        SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
+        return 0;
+    }
+
     AUDIO_INITINFO(&info);
 
     /* Calculate the final parameters for this audio specification */
-    SDL_CalculateAudioSpec(spec);
-
-#ifdef USE_TIMER_SYNC
-    frame_ticks = 0.0;
-#endif
-
-    /* Open the audio device */
-    audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
-    if (audio_fd < 0) {
-        SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
-        return (-1);
-    }
+    SDL_CalculateAudioSpec(&this->spec);
 
     /* Set to play mode */
     info.mode = AUMODE_PLAY;
-    if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
+    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
+        BSDAUDIO_CloseDevice(this);
         SDL_SetError("Couldn't put device into play mode");
-        return (-1);
+        return 0;
     }
 
-    mixbuf = NULL;
     AUDIO_INITINFO(&info);
-    for (format = SDL_FirstAudioFormat(spec->format);
+    for (format = SDL_FirstAudioFormat(this->spec.format);
          format; format = SDL_NextAudioFormat()) {
         switch (format) {
         case AUDIO_U8:
@@ -361,46 +396,70 @@
         default:
             continue;
         }
-        if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0)
+
+        if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
             break;
+        }
     }
 
     if (!format) {
-        SDL_SetError("No supported encoding for 0x%x", spec->format);
-        return (-1);
+        BSDAUDIO_CloseDevice(this);
+        SDL_SetError("No supported encoding for 0x%x", this->spec.format);
+        return 0;
     }
 
-    spec->format = format;
+    this->spec.format = format;
 
     AUDIO_INITINFO(&info);
-    info.play.channels = spec->channels;
-    if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1)
-        spec->channels = 1;
+    info.play.channels = this->spec.channels;
+    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
+        this->spec.channels = 1;
+    }
     AUDIO_INITINFO(&info);
-    info.play.sample_rate = spec->freq;
-    info.blocksize = spec->size;
+    info.play.sample_rate = this->spec.freq;
+    info.blocksize = this->spec.size;
     info.hiwat = 5;
     info.lowat = 3;
-    (void) ioctl(audio_fd, AUDIO_SETINFO, &info);
-    (void) ioctl(audio_fd, AUDIO_GETINFO, &info);
-    spec->freq = info.play.sample_rate;
+    (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
+    (void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
+    this->spec.freq = info.play.sample_rate;
     /* Allocate mixing buffer */
-    mixlen = spec->size;
-    mixbuf = (Uint8 *) SDL_AllocAudioMem(mixlen);
-    if (mixbuf == NULL) {
-        return (-1);
+    this->hidden->mixlen = this->spec.size;
+    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
+    if (this->hidden->mixbuf == NULL) {
+        BSDAUDIO_CloseDevice(this);
+        SDL_OutOfMemory();
+        return 0;
     }
-    SDL_memset(mixbuf, spec->silence, spec->size);
+    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
 
-    /* Get the parent process id (we're the parent of the audio thread) */
-    parent = getpid();
-
-#ifdef DEBUG_AUDIO
-    OBSD_Status(this);
-#endif
+    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 = DSP_DetectDevices;
+    impl->GetDeviceName = DSP_GetDeviceName;
+    impl->OpenDevice = DSP_OpenDevice;
+    impl->PlayDevice = DSP_PlayDevice;
+    impl->WaitDevice = DSP_WaitDevice;
+    impl->GetDeviceBuf = DSP_GetDeviceBuf;
+    impl->CloseDevice = DSP_CloseDevice;
+    impl->Deinitialize = DSP_Deinitialize;
+
+    build_device_lists();
+    return 1;
+}
+
+
+AudioBootStrap BSD_AUDIO_bootstrap = {
+    BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
+    BSDAUDIO_Available, BSDAUDIO_Init, 0
+};
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/bsd/SDL_bsdaudio.h	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/bsd/SDL_bsdaudio.h	Sat Oct 07 05:36:36 2006 +0000
@@ -21,8 +21,8 @@
 */
 #include "SDL_config.h"
 
-#ifndef _SDL_openbsdaudio_h
-#define _SDL_openbsdaudio_h
+#ifndef _SDL_bsdaudio_h
+#define _SDL_bsdaudio_h
 
 #include "../SDL_sysaudio.h"
 
@@ -47,13 +47,6 @@
 
 #define FUDGE_TICKS	10      /* The scheduler overhead ticks per frame */
 
-/* Old variable names */
-#define audio_fd		(this->hidden->audio_fd)
-#define parent			(this->hidden->parent)
-#define mixbuf			(this->hidden->mixbuf)
-#define mixlen			(this->hidden->mixlen)
-#define frame_ticks		(this->hidden->frame_ticks)
-#define next_frame		(this->hidden->next_frame)
+#endif /* _SDL_bsdaudio_h */
 
-#endif /* _SDL_openbsdaudio_h */
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/dmedia/SDL_irixaudio.c	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/dmedia/SDL_irixaudio.c	Sat Oct 07 05:36:36 2006 +0000
@@ -45,73 +45,18 @@
 #define alSetWidth(x,y) ALsetwidth(x,y)
 #endif
 
-/* Audio driver functions */
-static int AL_OpenAudio(_THIS, SDL_AudioSpec * spec);
-static void AL_WaitAudio(_THIS);
-static void AL_PlayAudio(_THIS);
-static Uint8 *AL_GetAudioBuf(_THIS);
-static void AL_CloseAudio(_THIS);
-
-/* Audio driver bootstrap functions */
-
 static int
-Audio_Available(void)
+IRIXAUDIO_Available(void)
 {
     return 1;
 }
 
-static void
-Audio_DeleteDevice(SDL_AudioDevice * device)
-{
-    SDL_free(device->hidden);
-    SDL_free(device);
-}
-
-static SDL_AudioDevice *
-Audio_CreateDevice(int devindex)
-{
-    SDL_AudioDevice *this;
-
-    /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
-    if (this) {
-        SDL_memset(this, 0, (sizeof *this));
-        this->hidden = (struct SDL_PrivateAudioData *)
-            SDL_malloc((sizeof *this->hidden));
-    }
-    if ((this == NULL) || (this->hidden == NULL)) {
-        SDL_OutOfMemory();
-        if (this) {
-            SDL_free(this);
-        }
-        return (0);
-    }
-    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
-
-    /* Set the function pointers */
-    this->OpenAudio = AL_OpenAudio;
-    this->WaitAudio = AL_WaitAudio;
-    this->PlayAudio = AL_PlayAudio;
-    this->GetAudioBuf = AL_GetAudioBuf;
-    this->CloseAudio = AL_CloseAudio;
-
-    this->free = Audio_DeleteDevice;
-
-    return this;
-}
-
-AudioBootStrap DMEDIA_bootstrap = {
-    "AL", "IRIX DMedia audio",
-    Audio_Available, Audio_CreateDevice, 0
-};
-
-
 void static
-AL_WaitAudio(_THIS)
+IRIXAUDIO_WaitDevice(_THIS)
 {
     Sint32 timeleft;
 
-    timeleft = this->spec.samples - alGetFillable(audio_port);
+    timeleft = this->spec.samples - alGetFillable(this->hidden->audio_port);
     if (timeleft > 0) {
         timeleft /= (this->spec.freq / 1000);
         SDL_Delay((Uint32) timeleft);
@@ -119,61 +64,78 @@
 }
 
 static void
-AL_PlayAudio(_THIS)
+IRIXAUDIO_PlayDevice(_THIS)
 {
     /* Write the audio data out */
-    if (alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0) {
+    ALport port = this->hidden->audio_port;
+    Uint8 *mixbuf = this->hidden->mixbuf;
+    if (alWriteFrames(port, mixbuf, this->spec.samples) < 0) {
         /* Assume fatal error, for now */
         this->enabled = 0;
     }
 }
 
 static Uint8 *
-AL_GetAudioBuf(_THIS)
+IRIXAUDIO_GetDeviceBuf(_THIS)
 {
-    return (mixbuf);
+    return (this->hidden->mixbuf);
 }
 
 static void
-AL_CloseAudio(_THIS)
+IRIXAUDIO_CloseDevice(_THIS)
 {
-    if (mixbuf != NULL) {
-        SDL_FreeAudioMem(mixbuf);
-        mixbuf = NULL;
-    }
-    if (audio_port != NULL) {
-        alClosePort(audio_port);
-        audio_port = NULL;
+    if (this->hidden != NULL) {
+        if (this->hidden->mixbuf != NULL) {
+            SDL_FreeAudioMem(this->hidden->mixbuf);
+            this->hidden->mixbuf = NULL;
+        }
+        if (this->hidden->audio_port != NULL) {
+            alClosePort(this->hidden->audio_port);
+            this->hidden->audio_port = NULL;
+        }
+        SDL_free(this->hidden);
+        this->hidden = NULL;
     }
 }
 
 static int
-AL_OpenAudio(_THIS, SDL_AudioSpec * spec)
+IRIXAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
 {
-    SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
+    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
     long width = 0;
     long fmt = 0;
     int valid = 0;
 
+    /* !!! FIXME: Handle multiple devices and capture? */
+
+    /* Initialize all variables that we clean on shutdown */
+    this->hidden = (struct SDL_PrivateAudioData *)
+                        SDL_malloc((sizeof *this->hidden));
+    if (this->hidden == NULL) {
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+
 #ifdef OLD_IRIX_AUDIO
     {
         long audio_param[2];
         audio_param[0] = AL_OUTPUT_RATE;
-        audio_param[1] = spec->freq;
+        audio_param[1] = this->spec.freq;
         valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0);
     }
 #else
     {
         ALpv audio_param;
         audio_param.param = AL_RATE;
-        audio_param.value.i = spec->freq;
+        audio_param.value.i = this->spec.freq;
         valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0);
     }
 #endif
 
     while ((!valid) && (test_format)) {
         valid = 1;
-        spec->format = test_format;
+        this->spec.format = test_format;
 
         switch (test_format) {
         case AUDIO_S8:
@@ -203,30 +165,31 @@
             ALconfig audio_config = alNewConfig();
             valid = 0;
             if (audio_config) {
-                if (alSetChannels(audio_config, spec->channels) < 0) {
-                    if (spec->channels > 2) {   /* can't handle > stereo? */
-                        spec->channels = 2;     /* try again below. */
+                if (alSetChannels(audio_config, this->spec.channels) < 0) {
+                    if (this->spec.channels > 2) { /* can't handle > stereo? */
+                        this->spec.channels = 2;   /* try again below. */
                     }
                 }
 
                 if ((alSetSampFmt(audio_config, fmt) >= 0) &&
                     ((!width) || (alSetWidth(audio_config, width) >= 0)) &&
-                    (alSetQueueSize(audio_config, spec->samples * 2) >= 0) &&
-                    (alSetChannels(audio_config, spec->channels) >= 0)) {
+                    (alSetQueueSize(audio_config,this->spec.samples*2) >= 0) &&
+                    (alSetChannels(audio_config, this->spec.channels) >= 0)) {
 
-                    audio_port = alOpenPort("SDL audio", "w", audio_config);
-                    if (audio_port == NULL) {
+                    this->hidden->audio_port = alOpenPort("SDL audio", "w",
+                                                          audio_config);
+                    if (this->hidden->audio_port == NULL) {
                         /* docs say AL_BAD_CHANNELS happens here, too. */
                         int err = oserror();
                         if (err == AL_BAD_CHANNELS) {
-                            spec->channels = 2;
-                            alSetChannels(audio_config, spec->channels);
-                            audio_port = alOpenPort("SDL audio", "w",
-                                                    audio_config);
+                            this->spec.channels = 2;
+                            alSetChannels(audio_config, this->spec.channels);
+                            this->hidden->audio_port = alOpenPort("SDL audio", "w",
+                                                                 audio_config);
                         }
                     }
 
-                    if (audio_port != NULL) {
+                    if (this->hidden->audio_port != NULL) {
                         valid = 1;
                     }
                 }
@@ -237,23 +200,44 @@
     }
 
     if (!valid) {
+        IRIXAUDIO_CloseDevice(this);
         SDL_SetError("Unsupported audio format");
-        return (-1);
+        return 0;
     }
 
     /* Update the fragment size as size in bytes */
-    SDL_CalculateAudioSpec(spec);
+    SDL_CalculateAudioSpec(&this->spec);
 
     /* Allocate mixing buffer */
-    mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size);
-    if (mixbuf == NULL) {
+    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size);
+    if (this->hidden->mixbuf == NULL) {
+        IRIXAUDIO_CloseDevice(this);
         SDL_OutOfMemory();
-        return (-1);
+        return 0;
     }
-    SDL_memset(mixbuf, spec->silence, spec->size);
+    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
 
     /* We're ready to rock and roll. :-) */
-    return (0);
+    return 1;
 }
 
+static int
+IRIXAUDIO_Init(SDL_AudioDriverImpl *impl)
+{
+    /* Set the function pointers */
+    impl->OpenDevice = DSP_OpenDevice;
+    impl->PlayDevice = DSP_PlayDevice;
+    impl->WaitDevice = DSP_WaitDevice;
+    impl->GetDeviceBuf = DSP_GetDeviceBuf;
+    impl->CloseDevice = DSP_CloseDevice;
+    impl->OnlyHasDefaultOutputDevice = 1;  /* !!! FIXME: not true, I think. */
+
+    return 1;
+}
+
+AudioBootStrap IRIXAUDIO_bootstrap = {
+    "AL", "IRIX DMedia audio",
+    IRIXAUDIO_Available, IRIXAUDIO_Init, 0
+};
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/dmedia/SDL_irixaudio.h	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/dmedia/SDL_irixaudio.h	Sat Oct 07 05:36:36 2006 +0000
@@ -33,15 +33,9 @@
 
 struct SDL_PrivateAudioData
 {
-    /* The handle for the audio device */
-    ALport audio_port;
-
-    Uint8 *mixbuf;              /* The app mixing buffer */
+    ALport audio_port;    /* The handle for the audio device */
+    Uint8 *mixbuf;        /* The app mixing buffer */
 };
 
-/* Old variable names */
-#define audio_port		(this->hidden->audio_port)
-#define mixbuf			(this->hidden->mixbuf)
-
 #endif /* _SDL_lowaudio_h */
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/dsp/SDL_dspaudio.c	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/dsp/SDL_dspaudio.c	Sat Oct 07 05:36:36 2006 +0000
@@ -58,8 +58,6 @@
 #define OPEN_FLAGS_OUTPUT    (O_WRONLY|O_NONBLOCK)
 #define OPEN_FLAGS_INPUT    (O_RDONLY|O_NONBLOCK)
 
-/* Audio driver bootstrap functions */
-
 static char **outputDevices = NULL;
 static int outputDeviceCount = 0;
 static char **inputDevices = NULL;
@@ -106,7 +104,8 @@
 }
 
 
-static void DSP_Deinitialize(void)
+static void
+DSP_Deinitialize(void)
 {
     free_device_lists();
 }
@@ -186,7 +185,6 @@
         return 0;
     }
     SDL_memset(this->hidden, 0, (sizeof *this->hidden));
-    this->hidden->audio_fd = -1;
 
     /* Open the audio device */
     this->hidden->audio_fd = open(devname, flags, 0);
--- a/src/audio/macrom/SDL_romaudio.c	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/macrom/SDL_romaudio.c	Sat Oct 07 05:36:36 2006 +0000
@@ -309,9 +309,11 @@
     impl->ProvidesOwnCallbackThread = 1;
     impl->OnlyHasDefaultOutputDevice = 1;
 
-#ifndef __MACOSX__               /* Mac OS X uses threaded audio, so normal thread code is okay */
+/* Mac OS X uses threaded audio, so normal thread code is okay */
+#ifndef __MACOSX__
     impl->LockDevice = SNDMGR_LockDevice;
     impl->UnlockDevice = SNDMGR_UnlockDevice;
+    impl->SkipMixerLock = 1;
 #endif
 
     return 1;
--- a/src/audio/mint/SDL_mintaudio_dma8.c	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_dma8.c	Sat Oct 07 05:36:36 2006 +0000
@@ -61,30 +61,10 @@
 
 static unsigned long cookie_snd, cookie_mch;
 
-/*--- Audio driver functions ---*/
-
-static void Mint_CloseAudio(_THIS);
-static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_LockAudio(_THIS);
-static void Mint_UnlockAudio(_THIS);
-
-/* To check/init hardware audio */
-static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
-
-/*--- Audio driver bootstrap functions ---*/
 
 static int
-Audio_Available(void)
+MINTDMA8_Available(void)
 {
-    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
-
-    /* Check if user asked a different audio driver */
-    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
-        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
-        return 0;
-    }
-
     /* Cookie _MCH present ? if not, assume ST machine */
     if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
         cookie_mch = MCH_ST;
@@ -116,55 +96,7 @@
 }
 
 static void
-Audio_DeleteDevice(SDL_AudioDevice * device)
-{
-    SDL_free(device->hidden);
-    SDL_free(device);
-}
-
-static SDL_AudioDevice *
-Audio_CreateDevice(int devindex)
-{
-    SDL_AudioDevice *this;
-
-    /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
-    if (this) {
-        SDL_memset(this, 0, (sizeof *this));
-        this->hidden = (struct SDL_PrivateAudioData *)
-            SDL_malloc((sizeof *this->hidden));
-    }
-    if ((this == NULL) || (this->hidden == NULL)) {
-        SDL_OutOfMemory();
-        if (this) {
-            SDL_free(this);
-        }
-        return (0);
-    }
-    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
-
-    /* Set the function pointers */
-    this->OpenAudio = Mint_OpenAudio;
-    this->CloseAudio = Mint_CloseAudio;
-    this->LockAudio = Mint_LockAudio;
-    this->UnlockAudio = Mint_UnlockAudio;
-    this->free = Audio_DeleteDevice;
-
-    /* Uses interrupt driven audio, without thread */
-    #if SDL_THREADS_DISABLED
-    this->SkipMixerLock = 1;
-    #endif
-
-    return this;
-}
-
-AudioBootStrap MINTAUDIO_DMA8_bootstrap = {
-    MINT_AUDIO_DRIVER_NAME, "MiNT DMA 8 bits audio driver",
-    Audio_Available, Audio_CreateDevice, 0
-};
-
-static void
-Mint_LockAudio(_THIS)
+MINTDMA8_LockDevice(_THIS)
 {
     void *oldpile;
 
@@ -175,7 +107,7 @@
 }
 
 static void
-Mint_UnlockAudio(_THIS)
+MINTDMA8_UnlockDevice(_THIS)
 {
     void *oldpile;
 
@@ -186,57 +118,59 @@
 }
 
 static void
-Mint_CloseAudio(_THIS)
+MINTDMA8_CloseDevice(_THIS)
 {
-    void *oldpile;
+    if (this->hidden != NULL) {
+        /* Stop replay */
+        void *oldpile = (void *) Super(0);
 
-    /* Stop replay */
-    oldpile = (void *) Super(0);
-    DMAAUDIO_IO.control = 0;
-    Super(oldpile);
+        DMAAUDIO_IO.control = 0;
+        Super(oldpile);
+
+        DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n"));
 
-    DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n"));
+        /* Disable interrupt */
+        Jdisint(MFP_DMASOUND);
 
-    /* Disable interrupt */
-    Jdisint(MFP_DMASOUND);
+        DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n"));
 
-    DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n"));
+        /* Wait if currently playing sound */
+        while (SDL_MintAudio_mutex != 0) {}
 
-    /* Wait if currently playing sound */
-    while (SDL_MintAudio_mutex != 0) {
-    }
-
-    DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n"));
+        DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n"));
 
-    /* Clear buffers */
-    if (SDL_MintAudio_audiobuf[0]) {
-        Mfree(SDL_MintAudio_audiobuf[0]);
-        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        /* Clear buffers */
+        if (SDL_MintAudio_audiobuf[0]) {
+            Mfree(SDL_MintAudio_audiobuf[0]);
+            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        }
+
+        DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n"));
+        SDL_free(this->buffer);
+        this->buffer = NULL;
     }
-
-    DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n"));
 }
 
 static int
-Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
+MINTDMA8_CheckAudio(_THIS)
 {
     int i, masterprediv, sfreq;
     unsigned long masterclock;
 
     DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",
-                 SDL_AUDIO_BITSIZE(spec->format)));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
-    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
-    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+                 SDL_AUDIO_BITSIZE(this->spec.format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
+    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
+    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
-    if (spec->channels > 2) {
-        spec->channels = 2;     /* no more than stereo! */
+    if (this->spec.channels > 2) {
+        this->spec.channels = 2;     /* no more than stereo! */
     }
 
     /* Check formats available */
-    spec->format = AUDIO_S8;
+    this->spec.format = AUDIO_S8;
 
     /* Calculate and select the closest frequency */
     sfreq = 0;
@@ -277,22 +211,22 @@
     }
 #endif
 
-    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
-    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
+    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
+    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
 
     DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
-                 SDL_AUDIO_BITSIZE(spec->format)));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
-    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
-    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+                 SDL_AUDIO_BITSIZE(this->spec.format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
+    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
+    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
     return 0;
 }
 
 static void
-Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
+MINTDMA8_InitAudio(_THIS)
 {
     void *oldpile;
     unsigned long buffer;
@@ -321,7 +255,7 @@
     DMAAUDIO_IO.end_low = buffer & 255;
 
     mode = 3 - MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor;
-    if (spec->channels == 1) {
+    if (this->spec.channels == 1) {
         mode |= 1 << 7;
     }
     DMAAUDIO_IO.sound_ctrl = mode;
@@ -344,29 +278,40 @@
 }
 
 static int
-Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
+MINTDMA8_OpenDevice(_THIS, const char *devname, int iscapture)
 {
     SDL_MintAudio_device = this;
 
     /* Check audio capabilities */
-    if (Mint_CheckAudio(this, spec) == -1) {
-        return -1;
+    if (MINTDMA8_CheckAudio(this) == -1) {
+        return 0;
     }
 
-    SDL_CalculateAudioSpec(spec);
+    /* Initialize all variables that we clean on shutdown */
+    this->hidden = (struct SDL_PrivateAudioData *)
+                        SDL_malloc((sizeof *this->hidden));
+    if (this->hidden == NULL) {
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+
+    SDL_CalculateAudioSpec(&this->spec);
 
     /* Allocate memory for audio buffers in DMA-able RAM */
-    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
+    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
 
-    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
+    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
     if (SDL_MintAudio_audiobuf[0] == NULL) {
-        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
-        return (-1);
+        SDL_free(this->hidden);
+        this->hidden = NULL;
+        SDL_OutOfMemory();
+        return 0;
     }
-    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
+    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
     SDL_MintAudio_numbuf = 0;
-    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
-    SDL_MintAudio_audiosize = spec->size;
+    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
+    SDL_MintAudio_audiosize = this->spec.size;
     SDL_MintAudio_mutex = 0;
 
     DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
@@ -377,9 +322,29 @@
     SDL_MintAudio_CheckFpu();
 
     /* Setup audio hardware */
-    Mint_InitAudio(this, spec);
+    MINTDMA8_InitAudio(this);
 
-    return (1);                 /* We don't use threaded audio */
+    return 1;  /* good to go. */
 }
 
+static int
+MINTDMA8_Init(SDL_AudioDriverImpl *impl)
+{
+    /* Set the function pointers */
+    impl->OpenDevice = MINTDMA8_OpenDevice;
+    impl->CloseDevice = MINTDMA8_CloseDevice;
+    impl->LockAudio = MINTDMA8_LockAudio;
+    impl->UnlockAudio = MINTDMA8_UnlockAudio;
+    impl->OnlyHasDefaultOutputDevice = 1;
+    impl->ProvidesOwnCallbackThread = 1;
+    impl->SkipMixerLock = 1;
+
+    return 1;
+}
+
+AudioBootStrap MINTAUDIO_DMA8_bootstrap = {
+    MINT_AUDIO_DRIVER_NAME, "MiNT DMA 8 bits audio driver",
+    MINTDMA8_Available, MINTDMA8_Init, 0
+};
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/mint/SDL_mintaudio_gsxb.c	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Sat Oct 07 05:36:36 2006 +0000
@@ -63,32 +63,14 @@
 
 /*--- Audio driver functions ---*/
 
-static void Mint_CloseAudio(_THIS);
-static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_LockAudio(_THIS);
-static void Mint_UnlockAudio(_THIS);
+/* GSXB callbacks */
+static void MINTGSXB_GsxbInterrupt(void);
+static void MINTGSXB_GsxbNullInterrupt(void);
 
-/* To check/init hardware audio */
-static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
-
-/* GSXB callbacks */
-static void Mint_GsxbInterrupt(void);
-static void Mint_GsxbNullInterrupt(void);
-
-/*--- Audio driver bootstrap functions ---*/
 
 static int
-Audio_Available(void)
+MINTGSXB_Available(void)
 {
-    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
-
-    /* Check if user asked a different audio driver */
-    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
-        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
-        return (0);
-    }
-
     /* Cookie _SND present ? if not, assume ST machine */
     if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
         cookie_snd = SND_PSG;
@@ -121,123 +103,80 @@
     return (1);
 }
 
-static void
-Audio_DeleteDevice(SDL_AudioDevice * device)
-{
-    SDL_free(device->hidden);
-    SDL_free(device);
-}
-
-static SDL_AudioDevice *
-Audio_CreateDevice(int devindex)
-{
-    SDL_AudioDevice *this;
-
-    /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
-    if (this) {
-        SDL_memset(this, 0, (sizeof *this));
-        this->hidden = (struct SDL_PrivateAudioData *)
-            SDL_malloc((sizeof *this->hidden));
-    }
-    if ((this == NULL) || (this->hidden == NULL)) {
-        SDL_OutOfMemory();
-        if (this) {
-            SDL_free(this);
-        }
-        return (0);
-    }
-    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
-
-    /* Set the function pointers */
-    this->OpenAudio = Mint_OpenAudio;
-    this->CloseAudio = Mint_CloseAudio;
-    this->LockAudio = Mint_LockAudio;
-    this->UnlockAudio = Mint_UnlockAudio;
-    this->free = Audio_DeleteDevice;
-
-    /* Uses interrupt driven audio, without thread */
-    #if SDL_THREADS_DISABLED
-    this->SkipMixerLock = 1;
-    #endif
-
-    return this;
-}
-
-AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
-    MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver",
-    Audio_Available, Audio_CreateDevice, 0
-};
 
 static void
-Mint_LockAudio(_THIS)
+MINTGSXB_LockDevice(_THIS)
 {
     /* Stop replay */
     Buffoper(0);
 }
 
 static void
-Mint_UnlockAudio(_THIS)
+MINTGSXB_UnlockDevice(_THIS)
 {
     /* Restart replay */
     Buffoper(SB_PLA_ENA | SB_PLA_RPT);
 }
 
 static void
-Mint_CloseAudio(_THIS)
+MINTGSXB_CloseDevice(_THIS)
 {
-    /* Stop replay */
-    Buffoper(0);
+    if (this->hidden != NULL) {
+        /* Stop replay */
+        Buffoper(0);
 
-    /* Uninstall interrupt */
-    if (NSetinterrupt(2, SI_NONE, Mint_GsxbNullInterrupt) < 0) {
-        DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n"));
-    }
+        /* Uninstall interrupt */
+        if (NSetinterrupt(2, SI_NONE, MINTGSXB_GsxbNullInterrupt) < 0) {
+            DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n"));
+        }
 
-    /* Wait if currently playing sound */
-    while (SDL_MintAudio_mutex != 0) {
-    }
+        /* Wait if currently playing sound */
+        while (SDL_MintAudio_mutex != 0) {}
 
-    /* Clear buffers */
-    if (SDL_MintAudio_audiobuf[0]) {
-        Mfree(SDL_MintAudio_audiobuf[0]);
-        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        /* Clear buffers */
+        if (SDL_MintAudio_audiobuf[0]) {
+            Mfree(SDL_MintAudio_audiobuf[0]);
+            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        }
+
+        /* Unlock sound system */
+        Unlocksnd();
+
+        SDL_free(this->hidden);
+        this->hidden = NULL;
     }
-
-    /* Unlock sound system */
-    Unlocksnd();
 }
 
 static int
-Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
+MINTGSXB_CheckAudio(_THIS)
 {
     long snd_format;
     int i, resolution, format_signed, format_bigendian;
-    SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
+    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
     int valid_datatype = 0;
 
-    resolution = SDL_AUDIO_BITSIZE(spec->format);
-    format_signed = SDL_AUDIO_ISSIGNED(spec->format);
-    format_bigendian = SDL_AUDIO_ISBIGENDIAN(spec->format);
+    resolution = SDL_AUDIO_BITSIZE(this->spec.format);
+    format_signed = SDL_AUDIO_ISSIGNED(this->spec.format);
+    format_bigendian = SDL_AUDIO_ISBIGENDIAN(this->spec.format);
 
     DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", resolution));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
     DEBUG_PRINT(("signed=%d, ", format_signed));
     DEBUG_PRINT(("big endian=%d, ", format_bigendian));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
-    if (spec->channels > 2) {
-        spec->channels = 2;     /* no more than stereo! */
+    if (this->spec.channels > 2) {
+        this->spec.channels = 2;     /* no more than stereo! */
     }
 
     while ((!valid_datatype) && (test_format)) {
         /* Check formats available */
         snd_format = Sndstatus(SND_QUERYFORMATS);
-        spec->format = test_format;
-        resolution = SDL_AUDIO_BITSIZE(spec->format);
-        format_signed = SDL_AUDIO_ISSIGNED(spec->format);
-        format_bigendian = SDL_AUDIO_ISBIGENDIAN(spec->format);
+        this->spec.format = test_format;
+        resolution = SDL_AUDIO_BITSIZE(this->spec.format);
+        format_signed = SDL_AUDIO_ISSIGNED(this->spec.format);
+        format_bigendian = SDL_AUDIO_ISBIGENDIAN(this->spec.format);
         switch (test_format) {
             case AUDIO_U8:
             case AUDIO_S8:
@@ -284,14 +223,14 @@
             /* Ok */
         } else if (snd_format & SND_FORMATUNSIGNED) {
             /* Give unsigned format */
-            spec->format = spec->format & (~SDL_AUDIO_MASK_SIGNED);
+            this->spec.format = this->spec.format & (~SDL_AUDIO_MASK_SIGNED);
         }
     } else {
         if (snd_format & SND_FORMATUNSIGNED) {
             /* Ok */
         } else if (snd_format & SND_FORMATSIGNED) {
             /* Give signed format */
-            spec->format |= SDL_AUDIO_MASK_SIGNED;
+            this->spec.format |= SDL_AUDIO_MASK_SIGNED;
         }
     }
 
@@ -300,14 +239,14 @@
             /* Ok */
         } else if (snd_format & SND_FORMATLITTLEENDIAN) {
             /* Give little endian format */
-            spec->format = spec->format & (~SDL_AUDIO_MASK_ENDIAN);
+            this->spec.format = this->spec.format & (~SDL_AUDIO_MASK_ENDIAN);
         }
     } else {
         if (snd_format & SND_FORMATLITTLEENDIAN) {
             /* Ok */
         } else if (snd_format & SND_FORMATBIGENDIAN) {
             /* Give big endian format */
-            spec->format |= SDL_AUDIO_MASK_ENDIAN;
+            this->spec.format |= SDL_AUDIO_MASK_ENDIAN;
         }
     }
 
@@ -329,22 +268,22 @@
     }
 #endif
 
-    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
-    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
+    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
+    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
 
     DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
-                 SDL_AUDIO_BITSIZE(spec->format)));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
-    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
-    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+                 SDL_AUDIO_BITSIZE(this->spec.format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
+    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
+    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
     return 0;
 }
 
 static void
-Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
+MINTGSXB_InitAudio(_THIS)
 {
     int channels_mode, prediv;
     void *buffer;
@@ -357,23 +296,23 @@
     Setmontracks(0);
 
     /* Select replay format */
-    switch (SDL_AUDIO_BITSIZE(spec->format)) {
+    switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
     case 8:
-        if (spec->channels == 2) {
+        if (this->spec.channels == 2) {
             channels_mode = STEREO8;
         } else {
             channels_mode = MONO8;
         }
         break;
     case 16:
-        if (spec->channels == 2) {
+        if (this->spec.channels == 2) {
             channels_mode = STEREO16;
         } else {
             channels_mode = MONO16;
         }
         break;
     case 32:
-        if (spec->channels == 2) {
+        if (this->spec.channels == 2) {
             channels_mode = STEREO32;
         } else {
             channels_mode = MONO32;
@@ -392,12 +331,12 @@
 
     /* Set buffer */
     buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
-    if (Setbuffer(0, buffer, buffer + spec->size) < 0) {
+    if (Setbuffer(0, buffer, buffer + this->spec.size) < 0) {
         DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
     }
 
     /* Install interrupt */
-    if (NSetinterrupt(2, SI_PLAY, Mint_GsxbInterrupt) < 0) {
+    if (NSetinterrupt(2, SI_PLAY, MINTGSXB_GsxbInterrupt) < 0) {
         DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed\n"));
     }
 
@@ -407,35 +346,46 @@
 }
 
 static int
-Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
+MINTGSXB_OpenDevice(_THIS, const char *devname, int iscapture)
 {
     /* Lock sound system */
     if (Locksnd() != 1) {
-        SDL_SetError("Mint_OpenAudio: Audio system already in use");
-        return (-1);
+        SDL_SetError("MINTGSXB_OpenDevice: Audio system already in use");
+        return 0;
     }
 
     SDL_MintAudio_device = this;
 
     /* Check audio capabilities */
-    if (Mint_CheckAudio(this, spec) == -1) {
-        return -1;
+    if (MINTGSXB_CheckAudio(this) == -1) {
+        return 0;
     }
 
-    SDL_CalculateAudioSpec(spec);
+    /* Initialize all variables that we clean on shutdown */
+    this->hidden = (struct SDL_PrivateAudioData *)
+                        SDL_malloc((sizeof *this->hidden));
+    if (this->hidden == NULL) {
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+
+    SDL_CalculateAudioSpec(&this->spec);
 
     /* Allocate memory for audio buffers in DMA-able RAM */
-    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
+    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
 
-    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
+    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
     if (SDL_MintAudio_audiobuf[0] == NULL) {
-        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
-        return (-1);
+        SDL_free(this->hidden);
+        this->hidden = NULL;
+        SDL_OutOfMemory();
+        return 0;
     }
-    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
+    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
     SDL_MintAudio_numbuf = 0;
-    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
-    SDL_MintAudio_audiosize = spec->size;
+    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
+    SDL_MintAudio_audiosize = this->spec.size;
     SDL_MintAudio_mutex = 0;
 
     DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
@@ -446,13 +396,13 @@
     SDL_MintAudio_CheckFpu();
 
     /* Setup audio hardware */
-    Mint_InitAudio(this, spec);
+    MINTGSXB_InitAudio(this);
 
-    return (1);                 /* We don't use threaded audio */
+    return 1;  /* good to go. */
 }
 
 static void
-Mint_GsxbInterrupt(void)
+MINTGSXB_GsxbInterrupt(void)
 {
     Uint8 *newbuf;
 
@@ -470,8 +420,28 @@
 }
 
 static void
-Mint_GsxbNullInterrupt(void)
+MINTGSXB_GsxbNullInterrupt(void)
 {
 }
 
+static int
+MINTGSXB_Init(SDL_AudioDriverImpl *impl)
+{
+    /* Set the function pointers */
+    impl->OpenDevice = MINTGSXB_OpenDevice;
+    impl->CloseDevice = MINTGSXB_CloseDevice;
+    impl->LockAudio = MINTGSXB_LockAudio;
+    impl->UnlockAudio = MINTGSXB_UnlockAudio;
+    impl->OnlyHasDefaultOutputDevice = 1;
+    impl->ProvidesOwnCallbackThread = 1;
+    impl->SkipMixerLock = 1;
+
+    return 1;
+}
+
+AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
+    MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver",
+    MINTGSXB_Available, MINTGSXB_Init, 0
+};
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/mint/SDL_mintaudio_mcsn.c	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_mcsn.c	Sat Oct 07 05:36:36 2006 +0000
@@ -61,27 +61,14 @@
 
 /*--- Static variables ---*/
 
-static unsigned long cookie_snd, cookie_mch;
-static cookie_mcsn_t *cookie_mcsn;
-
-/*--- Audio driver functions ---*/
-
-static void Mint_CloseAudio(_THIS);
-static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_LockAudio(_THIS);
-static void Mint_UnlockAudio(_THIS);
-
-/* To check/init hardware audio */
-static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
-
-/*--- Audio driver bootstrap functions ---*/
+static unsigned long cookie_snd = 0;
+static unsigned long cookie_mch = 0;
+static cookie_mcsn_t *cookie_mcsn = NULL;
 
 static int
-Audio_Available(void)
+MINTMCSN_Available(void)
 {
-    unsigned long dummy;
-    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
+    unsigned long dummy = 0;
 
     SDL_MintAudio_mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND);
 
@@ -90,12 +77,6 @@
         return (0);
     }
 
-    /* Check if user asked a different audio driver */
-    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
-        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
-        return (0);
-    }
-
     /* Cookie _MCH present ? if not, assume ST machine */
     if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
         cookie_mch = MCH_ST;
@@ -137,121 +118,77 @@
 }
 
 static void
-Audio_DeleteDevice(SDL_AudioDevice * device)
-{
-    SDL_free(device->hidden);
-    SDL_free(device);
-}
-
-static SDL_AudioDevice *
-Audio_CreateDevice(int devindex)
-{
-    SDL_AudioDevice *this;
-
-    /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
-    if (this) {
-        SDL_memset(this, 0, (sizeof *this));
-        this->hidden = (struct SDL_PrivateAudioData *)
-            SDL_malloc((sizeof *this->hidden));
-    }
-    if ((this == NULL) || (this->hidden == NULL)) {
-        SDL_OutOfMemory();
-        if (this) {
-            SDL_free(this);
-        }
-        return (0);
-    }
-    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
-
-    /* Set the function pointers */
-    this->OpenAudio = Mint_OpenAudio;
-    this->CloseAudio = Mint_CloseAudio;
-    this->LockAudio = Mint_LockAudio;
-    this->UnlockAudio = Mint_UnlockAudio;
-    this->free = Audio_DeleteDevice;
-
-    /* Uses interrupt driven audio, without thread */
-    #if SDL_THREADS_DISABLED
-    this->SkipMixerLock = 1;
-    #endif
-
-    return this;
-}
-
-AudioBootStrap MINTAUDIO_MCSN_bootstrap = {
-    MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver",
-    Audio_Available, Audio_CreateDevice, 0
-};
-
-static void
-Mint_LockAudio(_THIS)
+MINTMCSN_LockDevice(_THIS)
 {
     /* Stop replay */
     Buffoper(0);
 }
 
 static void
-Mint_UnlockAudio(_THIS)
+MINTMCSN_UnlockDevice(_THIS)
 {
     /* Restart replay */
     Buffoper(SB_PLA_ENA | SB_PLA_RPT);
 }
 
 static void
-Mint_CloseAudio(_THIS)
+MINTMCSN_CloseDevice(_THIS)
 {
-    /* Stop replay */
-    SDL_MintAudio_WaitThread();
-    Buffoper(0);
+    if (this->hidden != NULL) {
+        /* Stop replay */
+        SDL_MintAudio_WaitThread();
+        Buffoper(0);
 
-    if (!SDL_MintAudio_mint_present) {
-        /* Uninstall interrupt */
-        Jdisint(MFP_DMASOUND);
-    }
+        if (!SDL_MintAudio_mint_present) {
+            /* Uninstall interrupt */
+            Jdisint(MFP_DMASOUND);
+        }
 
-    /* Wait if currently playing sound */
-    while (SDL_MintAudio_mutex != 0) {
-    }
+        /* Wait if currently playing sound */
+        while (SDL_MintAudio_mutex != 0) {}
 
-    /* Clear buffers */
-    if (SDL_MintAudio_audiobuf[0]) {
-        Mfree(SDL_MintAudio_audiobuf[0]);
-        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        /* Clear buffers */
+        if (SDL_MintAudio_audiobuf[0]) {
+            Mfree(SDL_MintAudio_audiobuf[0]);
+            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        }
+
+        /* Unlock sound system */
+        Unlocksnd();
+
+        SDL_free(this->hidden);
+        this->hidden = NULL;
     }
-
-    /* Unlock sound system */
-    Unlocksnd();
 }
 
 static int
-Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
+MINTMCSN_CheckAudio(_THIS)
 {
     int i;
     unsigned long masterclock, masterprediv;
 
     DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",
-                 SDL_AUDIO_BITSIZE(spec->format)));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
-    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
-    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+                 SDL_AUDIO_BITSIZE(this->spec.format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
+    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
+    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
-    if (spec->channels > 2) {
-        spec->channels = 2;     /* no more than stereo! */
+    if (this->spec.channels > 2) {
+        this->spec.channels = 2;     /* no more than stereo! */
     }
 
     /* Check formats available */
     MINTAUDIO_freqcount = 0;
     switch (cookie_mcsn->play) {
     case MCSN_ST:
-        spec->channels = 1;
-        spec->format = AUDIO_S8;        /* FIXME: is it signed or unsigned ? */
+        this->spec.channels = 1;
+        this->spec.format = AUDIO_S8;  /* FIXME: is it signed or unsigned ? */
         SDL_MintAudio_AddFrequency(this, 12500, 0, 0, -1);
         break;
     case MCSN_TT:              /* Also STE, Mega STE */
-        spec->format = AUDIO_S8;
+        this->spec.format = AUDIO_S8;
         masterclock = MASTERCLOCK_STE;
         masterprediv = MASTERPREDIV_STE;
         if ((cookie_mch >> 16) == MCH_TT) {
@@ -285,10 +222,10 @@
                                            (1 << i) - 1, -1);
             }
         }
-        spec->format |= SDL_AUDIO_MASK_SIGNED;  /* Audio is always signed */
-        if ((SDL_AUDIO_BITSIZE(spec->format)) == 16) {
-            spec->format |= SDL_AUDIO_MASK_ENDIAN;      /* Audio is always big endian */
-            spec->channels = 2; /* 16 bits always stereo */
+        this->spec.format |= SDL_AUDIO_MASK_SIGNED;  /* Audio is always signed */
+        if ((SDL_AUDIO_BITSIZE(this->spec.format)) == 16) {
+            this->spec.format |= SDL_AUDIO_MASK_ENDIAN;      /* Audio is always big endian */
+            this->spec.channels = 2; /* 16 bits always stereo */
         }
         break;
     }
@@ -302,22 +239,22 @@
     }
 #endif
 
-    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
-    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
+    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
+    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
 
     DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
-                 SDL_AUDIO_BITSIZE(spec->format)));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
-    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
-    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+                 SDL_AUDIO_BITSIZE(this->spec.format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
+    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
+    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
     return 0;
 }
 
 static void
-Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
+MINTMCSN_InitAudio(_THIS)
 {
     int channels_mode, prediv, dmaclock;
     void *buffer;
@@ -334,9 +271,9 @@
 
     /* Select replay format */
     channels_mode = STEREO16;
-    switch (SDL_AUDIO_BITSIZE(spec->format)) {
+    switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
     case 8:
-        if (spec->channels == 2) {
+        if (this->spec.channels == 2) {
             channels_mode = STEREO8;
         } else {
             channels_mode = MONO8;
@@ -363,7 +300,7 @@
 
     /* Set buffer */
     buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
-    if (Setbuffer(0, buffer, buffer + spec->size) < 0) {
+    if (Setbuffer(0, buffer, buffer + this->spec.size) < 0) {
         DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
     }
 
@@ -386,35 +323,46 @@
 }
 
 static int
-Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
+MINTMCSN_OpenDevice(_THIS, const char *devname, int iscapture)
 {
     /* Lock sound system */
     if (Locksnd() != 1) {
-        SDL_SetError("Mint_OpenAudio: Audio system already in use");
-        return (-1);
+        SDL_SetError("MINTMCSN_OpenDevice: Audio system already in use");
+        return 0;
     }
 
     SDL_MintAudio_device = this;
 
     /* Check audio capabilities */
-    if (Mint_CheckAudio(this, spec) == -1) {
-        return -1;
+    if (MINTMCSN_CheckAudio(this) == -1) {
+        return 0;
     }
 
-    SDL_CalculateAudioSpec(spec);
+    /* Initialize all variables that we clean on shutdown */
+    this->hidden = (struct SDL_PrivateAudioData *)
+                        SDL_malloc((sizeof *this->hidden));
+    if (this->hidden == NULL) {
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+
+    SDL_CalculateAudioSpec(&this->spec);
 
     /* Allocate memory for audio buffers in DMA-able RAM */
-    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
+    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
 
-    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
+    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
     if (SDL_MintAudio_audiobuf[0] == NULL) {
-        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
-        return (-1);
+        SDL_free(this->hidden);
+        this->hidden = NULL;
+        SDL_OutOfMemory();
+        return 0;
     }
-    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
+    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
     SDL_MintAudio_numbuf = 0;
-    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
-    SDL_MintAudio_audiosize = spec->size;
+    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
+    SDL_MintAudio_audiosize = this->spec.size;
     SDL_MintAudio_mutex = 0;
 
     DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
@@ -425,9 +373,29 @@
     SDL_MintAudio_CheckFpu();
 
     /* Setup audio hardware */
-    Mint_InitAudio(this, spec);
+    MINTMCSN_InitAudio(this);
 
-    return (1);                 /* We don't use SDL threaded audio */
+    return 1;  /* good to go. */
 }
 
+static int
+MINTMCSN_Init(SDL_AudioDriverImpl *impl)
+{
+    /* Set the function pointers */
+    impl->OpenDevice = MINTMCSN_OpenDevice;
+    impl->CloseDevice = MINTMCSN_CloseDevice;
+    impl->LockAudio = MINTMCSN_LockAudio;
+    impl->UnlockAudio = MINTMCSN_UnlockAudio;
+    impl->OnlyHasDefaultOutputDevice = 1;
+    impl->ProvidesOwnCallbackThread = 1;
+    impl->SkipMixerLock = 1;
+
+    return 1;
+}
+
+AudioBootStrap MINTAUDIO_MCSN_bootstrap = {
+    MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver",
+    MINTMCSN_Available, MINTMCSN_Init, 0
+};
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/mint/SDL_mintaudio_stfa.c	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_stfa.c	Sat Oct 07 05:36:36 2006 +0000
@@ -59,8 +59,9 @@
 
 /*--- Static variables ---*/
 
-static unsigned long cookie_snd, cookie_mch;
-static cookie_stfa_t *cookie_stfa;
+static unsigned long cookie_snd = 0;
+static unsigned long cookie_mch = 0;
+static cookie_stfa_t *cookie_stfa = NULL;
 
 static const int freqs[16] = {
     4995, 6269, 7493, 8192,
@@ -69,30 +70,9 @@
     30720, 32336, 43885, 49152
 };
 
-/*--- Audio driver functions ---*/
-
-static void Mint_CloseAudio(_THIS);
-static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_LockAudio(_THIS);
-static void Mint_UnlockAudio(_THIS);
-
-/* To check/init hardware audio */
-static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
-
-/*--- Audio driver bootstrap functions ---*/
-
 static int
-Audio_Available(void)
+MINTSTFA_Available(void)
 {
-    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
-
-    /* Check if user asked a different audio driver */
-    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
-        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
-        return (0);
-    }
-
     /* Cookie _MCH present ? if not, assume ST machine */
     if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
         cookie_mch = MCH_ST;
@@ -116,115 +96,65 @@
 }
 
 static void
-Audio_DeleteDevice(SDL_AudioDevice * device)
-{
-    SDL_free(device->hidden);
-    SDL_free(device);
-}
-
-static SDL_AudioDevice *
-Audio_CreateDevice(int devindex)
+MINTSTFA_LockDevice(_THIS)
 {
-    SDL_AudioDevice *this;
-
-    /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
-    if (this) {
-        SDL_memset(this, 0, (sizeof *this));
-        this->hidden = (struct SDL_PrivateAudioData *)
-            SDL_malloc((sizeof *this->hidden));
-    }
-    if ((this == NULL) || (this->hidden == NULL)) {
-        SDL_OutOfMemory();
-        if (this) {
-            SDL_free(this);
-        }
-        return (0);
-    }
-    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
-
-    /* Set the function pointers */
-    this->OpenAudio = Mint_OpenAudio;
-    this->CloseAudio = Mint_CloseAudio;
-    this->LockAudio = Mint_LockAudio;
-    this->UnlockAudio = Mint_UnlockAudio;
-    this->free = Audio_DeleteDevice;
-
-    /* Uses interrupt driven audio, without thread */
-    #if SDL_THREADS_DISABLED
-    this->SkipMixerLock = 1;
-    #endif
-
-    return this;
-}
-
-AudioBootStrap MINTAUDIO_STFA_bootstrap = {
-    MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver",
-    Audio_Available, Audio_CreateDevice, 0
-};
-
-static void
-Mint_LockAudio(_THIS)
-{
-    void *oldpile;
-
     /* Stop replay */
-    oldpile = (void *) Super(0);
+    void *oldpile = (void *) Super(0);
     cookie_stfa->sound_enable = STFA_PLAY_DISABLE;
     Super(oldpile);
 }
 
 static void
-Mint_UnlockAudio(_THIS)
+MINTSTFA_UnlockDevice(_THIS)
 {
-    void *oldpile;
-
     /* Restart replay */
-    oldpile = (void *) Super(0);
+    void *oldpile = (void *) Super(0);
     cookie_stfa->sound_enable = STFA_PLAY_ENABLE | STFA_PLAY_REPEAT;
     Super(oldpile);
 }
 
 static void
-Mint_CloseAudio(_THIS)
+MINTSTFA_CloseDevice(_THIS)
 {
-    void *oldpile;
-
-    /* Stop replay */
-    oldpile = (void *) Super(0);
-    cookie_stfa->sound_enable = STFA_PLAY_DISABLE;
-    Super(oldpile);
+    if (this->hidden != NULL) {
+        /* Stop replay */
+        void *oldpile = (void *) Super(0);
+        cookie_stfa->sound_enable = STFA_PLAY_DISABLE;
+        Super(oldpile);
 
-    /* Wait if currently playing sound */
-    while (SDL_MintAudio_mutex != 0) {
-    }
+        /* Wait if currently playing sound */
+        while (SDL_MintAudio_mutex != 0) {}
 
-    /* Clear buffers */
-    if (SDL_MintAudio_audiobuf[0]) {
-        Mfree(SDL_MintAudio_audiobuf[0]);
-        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        /* Clear buffers */
+        if (SDL_MintAudio_audiobuf[0]) {
+            Mfree(SDL_MintAudio_audiobuf[0]);
+            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        }
+
+        SDL_free(this->hidden);
+        this->hidden = NULL;
     }
 }
 
 static int
-Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
+MINTSTFA_CheckAudio(_THIS)
 {
     int i;
 
     DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",
-                 SDL_AUDIO_BITSIZE(spec->format)));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
-    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
-    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+                 SDL_AUDIO_BITSIZE(this->spec.format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
+    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
+    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
-    if (SDL_AUDIO_BITSIZE(spec->format) > 16) {
-        spec->format = AUDIO_S16SYS;    /* clamp out int32/float32 ... */
+    if (SDL_AUDIO_BITSIZE(this->spec.format) > 16) {
+        this->spec.format = AUDIO_S16SYS;    /* clamp out int32/float32 ... */
     }
 
-    if (spec->channels > 2) {
-        spec->channels = 2;     /* no more than stereo! */
+    if (this->spec.channels > 2) {
+        this->spec.channels = 2;     /* no more than stereo! */
     }
 
     /* Check formats available */
@@ -242,29 +172,25 @@
     }
 #endif
 
-    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
-    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
+    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
+    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
 
     DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
-                 SDL_AUDIO_BITSIZE(spec->format)));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
-    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
-    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+                 SDL_AUDIO_BITSIZE(this->spec.format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
+    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
+    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
     return 0;
 }
 
 static void
-Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
+MINTSTFA_InitAudio(_THIS)
 {
-    void *buffer;
-    void *oldpile;
-
-    buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
-
-    oldpile = (void *) Super(0);
+    void *buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
+    void *oldpile = (void *) Super(0);
 
     /* Stop replay */
     cookie_stfa->sound_enable = STFA_PLAY_DISABLE;
@@ -272,22 +198,22 @@
     /* Select replay format */
     cookie_stfa->sound_control =
         MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor;
-    if (SDL_AUDIO_BITSIZE(spec->format) == 8) {
+    if (SDL_AUDIO_BITSIZE(this->spec.format) == 8) {
         cookie_stfa->sound_control |= STFA_FORMAT_8BIT;
     } else {
         cookie_stfa->sound_control |= STFA_FORMAT_16BIT;
     }
-    if (spec->channels == 2) {
+    if (this->spec.channels == 2) {
         cookie_stfa->sound_control |= STFA_FORMAT_STEREO;
     } else {
         cookie_stfa->sound_control |= STFA_FORMAT_MONO;
     }
-    if (SDL_AUDIO_ISSIGNED(spec->format) != 0) {
+    if (SDL_AUDIO_ISSIGNED(this->spec.format) != 0) {
         cookie_stfa->sound_control |= STFA_FORMAT_SIGNED;
     } else {
         cookie_stfa->sound_control |= STFA_FORMAT_UNSIGNED;
     }
-    if (SDL_AUDIO_ISBIGENDIAN(spec->format) != 0) {
+    if (SDL_AUDIO_ISBIGENDIAN(this->spec.format) != 0) {
         cookie_stfa->sound_control |= STFA_FORMAT_BIGENDIAN;
     } else {
         cookie_stfa->sound_control |= STFA_FORMAT_LITENDIAN;
@@ -295,7 +221,7 @@
 
     /* Set buffer */
     cookie_stfa->sound_start = (unsigned long) buffer;
-    cookie_stfa->sound_end = (unsigned long) (buffer + spec->size);
+    cookie_stfa->sound_end = (unsigned long) (buffer + this->spec.size);
 
     /* Set interrupt */
     cookie_stfa->stfa_it = SDL_MintAudio_StfaInterrupt;
@@ -309,29 +235,40 @@
 }
 
 static int
-Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
+MINTSTFA_OpenDevice(_THIS, const char *devname, int iscapture)
 {
     SDL_MintAudio_device = this;
 
     /* Check audio capabilities */
-    if (Mint_CheckAudio(this, spec) == -1) {
-        return -1;
+    if (MINTSTFA_CheckAudio(this) == -1) {
+        return 0;
     }
 
-    SDL_CalculateAudioSpec(spec);
+    /* Initialize all variables that we clean on shutdown */
+    this->hidden = (struct SDL_PrivateAudioData *)
+                        SDL_malloc((sizeof *this->hidden));
+    if (this->hidden == NULL) {
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+
+    SDL_CalculateAudioSpec(&this->spec);
 
     /* Allocate memory for audio buffers in DMA-able RAM */
-    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
+    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
 
-    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
+    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
     if (SDL_MintAudio_audiobuf[0] == NULL) {
-        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
-        return (-1);
+        SDL_OutOfMemory()
+        SDL_free(this->hidden);
+        this->hidden = NULL;
+        return 0;
     }
-    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
+    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
     SDL_MintAudio_numbuf = 0;
-    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
-    SDL_MintAudio_audiosize = spec->size;
+    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
+    SDL_MintAudio_audiosize = this->spec.size;
     SDL_MintAudio_mutex = 0;
 
     DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
@@ -342,9 +279,30 @@
     SDL_MintAudio_CheckFpu();
 
     /* Setup audio hardware */
-    Mint_InitAudio(this, spec);
+    MINTSTFA_InitAudio(this);
 
-    return (1);                 /* We don't use threaded audio */
+    return 1;  /* good to go. */
 }
 
+
+static int
+MINTSTFA_Init(SDL_AudioDriverImpl *impl)
+{
+    /* Set the function pointers */
+    impl->OpenDevice = MINTSTFA_OpenDevice;
+    impl->CloseDevice = MINTSTFA_CloseDevice;
+    impl->LockAudio = MINTSTFA_LockAudio;
+    impl->UnlockAudio = MINTSTFA_UnlockAudio;
+    impl->OnlyHasDefaultOutputDevice = 1;
+    impl->ProvidesOwnCallbackThread = 1;
+    impl->SkipMixerLock = 1;
+
+    return 1;
+}
+
+AudioBootStrap MINTAUDIO_STFA_bootstrap = {
+    MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver",
+    MINTSTFA_Available, MINTSTFA_Init, 0
+};
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/audio/mint/SDL_mintaudio_xbios.c	Fri Oct 06 20:36:23 2006 +0000
+++ b/src/audio/mint/SDL_mintaudio_xbios.c	Sat Oct 07 05:36:36 2006 +0000
@@ -60,29 +60,12 @@
 #define DEBUG_PRINT(what)
 #endif
 
-/*--- Static variables ---*/
-
-static unsigned long cookie_snd;
-
-/*--- Audio driver functions ---*/
-
-static void Mint_CloseAudio(_THIS);
-static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_LockAudio(_THIS);
-static void Mint_UnlockAudio(_THIS);
-
-/* To check/init hardware audio */
-static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
-static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
-
-/*--- Audio driver bootstrap functions ---*/
+static unsigned long cookie_snd = 0;
 
 static int
-Audio_Available(void)
+MINTXBIOS_Available(void)
 {
-    unsigned long dummy;
-    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
-
+    unsigned long dummy = 0;
     /*SDL_MintAudio_mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND); */
     SDL_MintAudio_mint_present = SDL_FALSE;
 
@@ -91,12 +74,6 @@
         return (0);
     }
 
-    /* Check if user asked a different audio driver */
-    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
-        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
-        return (0);
-    }
-
     /* Cookie _SND present ? if not, assume ST machine */
     if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
         cookie_snd = SND_PSG;
@@ -121,91 +98,47 @@
 }
 
 static void
-Audio_DeleteDevice(SDL_AudioDevice * device)
-{
-    SDL_free(device->hidden);
-    SDL_free(device);
-}
-
-static SDL_AudioDevice *
-Audio_CreateDevice(int devindex)
-{
-    SDL_AudioDevice *this;
-
-    /* Initialize all variables that we clean on shutdown */
-    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
-    if (this) {
-        SDL_memset(this, 0, (sizeof *this));
-        this->hidden = (struct SDL_PrivateAudioData *)
-            SDL_malloc((sizeof *this->hidden));
-    }
-    if ((this == NULL) || (this->hidden == NULL)) {
-        SDL_OutOfMemory();
-        if (this) {
-            SDL_free(this);
-        }
-        return (0);
-    }
-    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
-
-    /* Set the function pointers */
-    this->OpenAudio = Mint_OpenAudio;
-    this->CloseAudio = Mint_CloseAudio;
-    this->LockAudio = Mint_LockAudio;
-    this->UnlockAudio = Mint_UnlockAudio;
-    this->free = Audio_DeleteDevice;
-
-    /* Uses interrupt driven audio, without thread */
-    #if SDL_THREADS_DISABLED
-    this->SkipMixerLock = 1;
-    #endif
-
-    return this;
-}
-
-AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {
-    MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver",
-    Audio_Available, Audio_CreateDevice, 0
-};
-
-static void
-Mint_LockAudio(_THIS)
+MINTXBIOS_LockDevice(_THIS)
 {
     /* Stop replay */
     Buffoper(0);
 }
 
 static void
-Mint_UnlockAudio(_THIS)
+MINTXBIOS_UnlockDevice(_THIS)
 {
     /* Restart replay */
     Buffoper(SB_PLA_ENA | SB_PLA_RPT);
 }
 
 static void
-Mint_CloseAudio(_THIS)
+MINTXBIOS_CloseDevice(_THIS)
 {
-    /* Stop replay */
-    SDL_MintAudio_WaitThread();
-    Buffoper(0);
+    if (this->hidden != NULL) {
+        /* Stop replay */
+        SDL_MintAudio_WaitThread();
+        Buffoper(0);
 
-    if (!SDL_MintAudio_mint_present) {
-        /* Uninstall interrupt */
-        Jdisint(MFP_DMASOUND);
-    }
+        if (!SDL_MintAudio_mint_present) {
+            /* Uninstall interrupt */
+            Jdisint(MFP_DMASOUND);
+        }
 
-    /* Wait if currently playing sound */
-    while (SDL_MintAudio_mutex != 0) {
-    }
+        /* Wait if currently playing sound */
+        while (SDL_MintAudio_mutex != 0) {}
 
-    /* Clear buffers */
-    if (SDL_MintAudio_audiobuf[0]) {
-        Mfree(SDL_MintAudio_audiobuf[0]);
-        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        /* Clear buffers */
+        if (SDL_MintAudio_audiobuf[0]) {
+            Mfree(SDL_MintAudio_audiobuf[0]);
+            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
+        }
+
+        /* Unlock sound system */
+        Unlocksnd();
+
+        SDL_free(this->hidden);
+        this->hidden = NULL;
     }
-
-    /* Unlock sound system */
-    Unlocksnd();
 }
 
 /* Falcon XBIOS implementation of Devconnect() is buggy with external clock */
@@ -274,7 +207,7 @@
 }
 
 static void
-Mint_CheckExternalClock(_THIS)
+MINTXBIOS_CheckExternalClock(_THIS)
 {
 #define SIZE_BUF_CLOCK_MEASURE (44100/10)
 
@@ -360,33 +293,33 @@
 }
 
 static int
-Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
+MINTXBIOS_CheckAudio(_THIS)
 {
     int i;
     Uint32 extclock;
 
     DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",
-                 SDL_AUDIO_BITSIZE(spec->format)));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
-    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
-    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+                 SDL_AUDIO_BITSIZE(this->spec.format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
+    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
+    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
-    spec->format |= SDL_AUDIO_MASK_SIGNED;      /* Audio is always signed */
+    this->spec.format |= SDL_AUDIO_MASK_SIGNED;   /* Audio is always signed */
 
     /* clamp out int32/float32 */
-    if (SDL_AUDIO_BITSIZE(spec->format) >= 16) {
-        spec->format = AUDIO_S16MSB;    /* Audio is always big endian */
-        spec->channels = 2;     /* 16 bits always stereo */
-    } else if (spec->channels > 2) {
-        spec->channels = 2;     /* no more than stereo! */
+    if (SDL_AUDIO_BITSIZE(this->spec.format) >= 16) {
+        this->spec.format = AUDIO_S16MSB;    /* Audio is always big endian */
+        this->spec.channels = 2;     /* 16 bits always stereo */
+    } else if (this->spec.channels > 2) {
+        this->spec.channels = 2;     /* no more than stereo! */
     }
 
     MINTAUDIO_freqcount = 0;
 
     /* Add external clocks if present */
-    Mint_CheckExternalClock(this);
+    MINTXBIOS_CheckExternalClock(this);
 
     /* Standard clocks */
     for (i = 1; i < 12; i++) {
@@ -409,22 +342,22 @@
     }
 #endif
 
-    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
-    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
+    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
+    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
 
     DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
-                 SDL_AUDIO_BITSIZE(spec->format)));
-    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
-    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
-    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
-    DEBUG_PRINT(("channels=%d, ", spec->channels));
-    DEBUG_PRINT(("freq=%d\n", spec->freq));
+                 SDL_AUDIO_BITSIZE(this->spec.format)));
+    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
+    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
+    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
+    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
+    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
 
     return 0;
 }
 
 static void
-Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
+MINTXBIOS_InitAudio(_THIS)
 {
     int channels_mode, dmaclock, prediv;
     void *buffer;
@@ -441,9 +374,9 @@
 
     /* Select replay format */
     channels_mode = STEREO16;
-    switch (SDL_AUDIO_BITSIZE(spec->format)) {
+    switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
     case 8:
-        if (spec->channels == 2) {
+        if (this->spec.channels == 2) {
             channels_mode = STEREO8;
         } else {
             channels_mode = MONO8;
@@ -466,7 +399,7 @@
 
     /* Set buffer */
     buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
-    if (Setbuffer(0, buffer, buffer + spec->size) < 0) {
+    if (Setbuffer(0, buffer, buffer + this->spec.size) < 0) {
         DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
     }
 
@@ -490,35 +423,46 @@
 }
 
 static int
-Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
+MINTXBIOS_OpenDevice(_THIS, const char *devname, int iscapture)
 {
     /* Lock sound system */
     if (Locksnd() != 1) {
-        SDL_SetError("Mint_OpenAudio: Audio system already in use");
-        return (-1);
+        SDL_SetError("MINTXBIOS_OpenAudio: Audio system already in use");
+        return 0;
     }
 
     SDL_MintAudio_device = this;
 
     /* Check audio capabilities */
-    if (Mint_CheckAudio(this, spec) == -1) {
-        return -1;
+    if (MINTXBIOS_CheckAudio(this) == -1) {
+        return 0;
     }
 
-    SDL_CalculateAudioSpec(spec);
+    /* Initialize all variables that we clean on shutdown */
+    this->hidden = (struct SDL_PrivateAudioData *)
+                        SDL_malloc((sizeof *this->hidden));
+    if (this->hidden == NULL) {
+        SDL_OutOfMemory();
+        return 0;
+    }
+    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
+
+    SDL_CalculateAudioSpec(&this->spec);
 
     /* Allocate memory for audio buffers in DMA-able RAM */
-    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
+    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
 
-    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
+    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
     if (SDL_MintAudio_audiobuf[0] == NULL) {
-        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
-        return (-1);
+        SDL_free(this->hidden);
+        this->hidden = NULL;
+        SDL_OutOfMemory();
+        return 0;
     }
-    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
+    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
     SDL_MintAudio_numbuf = 0;
-    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
-    SDL_MintAudio_audiosize = spec->size;
+    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
+    SDL_MintAudio_audiosize = this->spec.size;
     SDL_MintAudio_mutex = 0;
 
     DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
@@ -529,9 +473,29 @@
     SDL_MintAudio_CheckFpu();
 
     /* Setup audio hardware */
-    Mint_InitAudio(this, spec);
+    MINTXBIOS_InitAudio(this);
 
-    return (1);                 /* We don't use SDL threaded audio */
+    return 1;  /* good to go. */
 }
 
+static int
+MINTXBIOS_Init(SDL_AudioDriverImpl *impl)
+{
+    /* Set the function pointers */
+    impl->OpenDevice = MINTXBIOS_OpenDevice;
+    impl->CloseDevice = MINTXBIOS_CloseDevice;
+    impl->LockAudio = MINTXBIOS_LockAudio;
+    impl->UnlockAudio = MINTXBIOS_UnlockAudio;
+    impl->OnlyHasDefaultOutputDevice = 1;
+    impl->ProvidesOwnCallbackThread = 1;
+    impl->SkipMixerLock = 1;
+
+    return 1;
+}
+
+AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {
+    MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver",
+    MINTXBIOS_Available, MINTXBIOS_Init, 0
+};
+
 /* vi: set ts=4 sw=4 expandtab: */