Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of SDL-ryan-multiple-audio-device
authorRyan C. Gordon <icculus@icculus.org>
Wed, 04 Oct 2006 19:54:23 +0000
branchSDL-ryan-multiple-audio-device
changeset 3796b19680c84cdf
parent 3795 589bc3d060cd
child 3797 9dc81c6acaf5
Bunch of 1.3 audio cleanups to remove FIXMEs, get driver specific crap out of
the core and into the drivers where it belongs, and push generic
responsibilities out of the drivers and into the core where they belong.
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/dart/SDL_dart.c
src/audio/dummy/SDL_dummyaudio.c
src/audio/macosx/SDL_coreaudio.c
src/audio/macosx/SDL_coreaudio.h
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
     1.1 --- a/src/audio/SDL_audio.c	Wed Oct 04 06:00:10 2006 +0000
     1.2 +++ b/src/audio/SDL_audio.c	Wed Oct 04 19:54:23 2006 +0000
     1.3 @@ -34,11 +34,51 @@
     1.4  #include <os2.h>
     1.5  #endif
     1.6  
     1.7 +#define _THIS	SDL_AudioDevice *this
     1.8 +
     1.9  static SDL_AudioDriver current_audio;
    1.10  
    1.11  /* !!! FIXME: don't use a static array, but it's Good Enough For Now... */
    1.12  static SDL_AudioDevice *open_devices[16];
    1.13  
    1.14 +/* !!! FIXME: These are wordy and unlocalized... */
    1.15 +#define DEFAULT_OUTPUT_DEVNAME "System audio output device"
    1.16 +#define DEFAULT_INPUT_DEVNAME "System audio capture device"
    1.17 +
    1.18 +
    1.19 +/*
    1.20 + * Not all of these will be compiled and linked in, but it's convenient
    1.21 + *  to have a complete list here and saves yet-another block of #ifdefs...
    1.22 + *  Please see bootstrap[], below, for the actual #ifdef mess.
    1.23 + */
    1.24 +extern AudioBootStrap BSD_AUDIO_bootstrap;
    1.25 +extern AudioBootStrap DSP_bootstrap;
    1.26 +extern AudioBootStrap DMA_bootstrap;
    1.27 +extern AudioBootStrap ALSA_bootstrap;
    1.28 +extern AudioBootStrap QNXNTOAUDIO_bootstrap;
    1.29 +extern AudioBootStrap SUNAUDIO_bootstrap;
    1.30 +extern AudioBootStrap DMEDIA_bootstrap;
    1.31 +extern AudioBootStrap ARTS_bootstrap;
    1.32 +extern AudioBootStrap ESD_bootstrap;
    1.33 +extern AudioBootStrap NAS_bootstrap;
    1.34 +extern AudioBootStrap DSOUND_bootstrap;
    1.35 +extern AudioBootStrap WAVEOUT_bootstrap;
    1.36 +extern AudioBootStrap Paud_bootstrap;
    1.37 +extern AudioBootStrap BAUDIO_bootstrap;
    1.38 +extern AudioBootStrap COREAUDIO_bootstrap;
    1.39 +extern AudioBootStrap SNDMGR_bootstrap;
    1.40 +extern AudioBootStrap AHI_bootstrap;
    1.41 +extern AudioBootStrap MINTAUDIO_GSXB_bootstrap;
    1.42 +extern AudioBootStrap MINTAUDIO_MCSN_bootstrap;
    1.43 +extern AudioBootStrap MINTAUDIO_STFA_bootstrap;
    1.44 +extern AudioBootStrap MINTAUDIO_XBIOS_bootstrap;
    1.45 +extern AudioBootStrap MINTAUDIO_DMA8_bootstrap;
    1.46 +extern AudioBootStrap DISKAUD_bootstrap;
    1.47 +extern AudioBootStrap DUMMYAUD_bootstrap;
    1.48 +extern AudioBootStrap DCAUD_bootstrap;
    1.49 +extern AudioBootStrap MMEAUDIO_bootstrap;
    1.50 +extern AudioBootStrap DART_bootstrap;
    1.51 +
    1.52  
    1.53  /* Available audio drivers */
    1.54  static AudioBootStrap *bootstrap[] = {
    1.55 @@ -133,13 +173,71 @@
    1.56  
    1.57  
    1.58  /* stubs for audio drivers that don't need a specific entry point... */
    1.59 -/* !!! FIXME: fill in more of these. */
    1.60 +static int SDL_AudioDetectDevices_Default(int iscapture) { return -1; }
    1.61 +static void SDL_AudioThreadInit_Default(_THIS) { /* no-op. */ }
    1.62 +static void SDL_AudioWaitDevice_Default(_THIS) { /* no-op. */ }
    1.63 +static void SDL_AudioPlayDevice_Default(_THIS) { /* no-op. */ }
    1.64 +static Uint8 *SDL_AudioGetDeviceBuf_Default(_THIS) { return NULL; }
    1.65 +static void SDL_AudioWaitDone_Default(_THIS) { /* no-op. */ }
    1.66 +static void SDL_AudioCloseDevice_Default(_THIS) { /* no-op. */ }
    1.67 +static void SDL_AudioDeinitialize_Default(void) { /* no-op. */ }
    1.68  
    1.69 -static void SDL_DeinitializeAudio_Default(void)
    1.70 +static int
    1.71 +SDL_AudioOpenDevice_Default(_THIS, const char *devname, int iscapture)
    1.72 +{
    1.73 +    return 0;
    1.74 +}
    1.75 +
    1.76 +static const char *SDL_AudioGetDeviceName_Default(int index, int iscapture)
    1.77  {
    1.78 -    /* no-op. */
    1.79 +    SDL_SetError("No such device");
    1.80 +    return NULL;
    1.81 +}
    1.82 +
    1.83 +static void
    1.84 +SDL_AudioLockDevice_Default(SDL_AudioDevice * device)
    1.85 +{
    1.86 +    if (device->thread && (SDL_ThreadID() == device->threadid)) {
    1.87 +        return;
    1.88 +    }
    1.89 +    SDL_mutexP(device->mixer_lock);
    1.90  }
    1.91  
    1.92 +static void
    1.93 +SDL_AudioUnlockDevice_Default(SDL_AudioDevice * device)
    1.94 +{
    1.95 +    if (device->thread && (SDL_ThreadID() == device->threadid)) {
    1.96 +        return;
    1.97 +    }
    1.98 +    SDL_mutexV(device->mixer_lock);
    1.99 +}
   1.100 +
   1.101 +
   1.102 +static void finalize_audio_entry_points(void)
   1.103 +{
   1.104 +    /*
   1.105 +     * Fill in stub functions for unused driver entry points. This lets us
   1.106 +     *  blindly call them without having to check for validity first.
   1.107 +     */
   1.108 +
   1.109 +    #define FILL_STUB(x) \
   1.110 +        if (current_audio.impl.x == NULL) { \
   1.111 +            current_audio.impl.x = SDL_Audio##x##_Default; \
   1.112 +        }
   1.113 +    FILL_STUB(DetectDevices);
   1.114 +    FILL_STUB(GetDeviceName);
   1.115 +    FILL_STUB(OpenDevice);
   1.116 +    FILL_STUB(ThreadInit);
   1.117 +    FILL_STUB(WaitDevice);
   1.118 +    FILL_STUB(PlayDevice);
   1.119 +    FILL_STUB(GetDeviceBuf);
   1.120 +    FILL_STUB(WaitDone);
   1.121 +    FILL_STUB(CloseDevice);
   1.122 +    FILL_STUB(LockDevice);
   1.123 +    FILL_STUB(UnlockDevice);
   1.124 +    FILL_STUB(Deinitialize);
   1.125 +    #undef FILL_STUB
   1.126 +}
   1.127  
   1.128  
   1.129  /* The general mixing thread function */
   1.130 @@ -172,10 +270,8 @@
   1.131  #endif
   1.132  
   1.133      /* Perform any thread setup */
   1.134 -    if (current_audio.impl.ThreadInit != NULL) {
   1.135 -        current_audio.impl.ThreadInit(device);
   1.136 -    }
   1.137      device->threadid = SDL_ThreadID();
   1.138 +    current_audio.impl.ThreadInit(device);
   1.139  
   1.140      /* Set up the mixing function */
   1.141      fill = device->spec.callback;
   1.142 @@ -206,29 +302,6 @@
   1.143      D(bug("Entering audio loop...\n"));
   1.144  #endif
   1.145  
   1.146 -/* !!! FIXME: push this out of core. */
   1.147 -#ifdef __OS2__
   1.148 -    /* Increase the priority of this thread to make sure that
   1.149 -       the audio will be continuous all the time! */
   1.150 -#ifdef USE_DOSSETPRIORITY
   1.151 -    if (SDL_getenv("SDL_USE_TIMECRITICAL_AUDIO")) {
   1.152 -#ifdef DEBUG_BUILD
   1.153 -        printf
   1.154 -            ("[SDL_RunAudio] : Setting priority to TimeCritical+0! (TID%d)\n",
   1.155 -             SDL_ThreadID());
   1.156 -#endif
   1.157 -        DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
   1.158 -    } else {
   1.159 -#ifdef DEBUG_BUILD
   1.160 -        printf
   1.161 -            ("[SDL_RunAudio] : Setting priority to ForegroundServer+0! (TID%d)\n",
   1.162 -             SDL_ThreadID());
   1.163 -#endif
   1.164 -        DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0);
   1.165 -    }
   1.166 -#endif
   1.167 -#endif
   1.168 -
   1.169      /* Loop, filling the audio buffers */
   1.170      while (device->enabled) {
   1.171  
   1.172 @@ -281,42 +354,20 @@
   1.173      }
   1.174  
   1.175      /* Wait for the audio to drain.. */
   1.176 -    if (current_audio.impl.WaitDone) {
   1.177 -        current_audio.impl.WaitDone(device);
   1.178 -    }
   1.179 +    current_audio.impl.WaitDone(device);
   1.180 +
   1.181 +/* !!! FIXME: get this out of core. */
   1.182  #if SDL_AUDIO_DRIVER_AHI
   1.183      D(bug("WaitDevice...Done\n"));
   1.184 -
   1.185 -    audio->CloseDevice(audio);
   1.186 -
   1.187 +    current_audio.impl.CloseDevice(device);
   1.188 +    device->opened = 0;
   1.189      D(bug("CloseDevice..Done, subtask exiting...\n"));
   1.190      audio_configured = 0;
   1.191  #endif
   1.192 -#ifdef __OS2__
   1.193 -#ifdef DEBUG_BUILD
   1.194 -    printf("[SDL_RunAudio] : Task exiting. (TID%d)\n", SDL_ThreadID());
   1.195 -#endif
   1.196 -#endif
   1.197 +
   1.198      return (0);
   1.199  }
   1.200  
   1.201 -static void
   1.202 -SDL_LockDevice_Default(SDL_AudioDevice * audio)
   1.203 -{
   1.204 -    if (audio->thread && (SDL_ThreadID() == audio->threadid)) {
   1.205 -        return;
   1.206 -    }
   1.207 -    SDL_mutexP(audio->mixer_lock);
   1.208 -}
   1.209 -
   1.210 -static void
   1.211 -SDL_UnlockDevice_Default(SDL_AudioDevice * audio)
   1.212 -{
   1.213 -    if (audio->thread && (SDL_ThreadID() == audio->threadid)) {
   1.214 -        return;
   1.215 -    }
   1.216 -    SDL_mutexV(audio->mixer_lock);
   1.217 -}
   1.218  
   1.219  static SDL_AudioFormat
   1.220  SDL_ParseAudioFormat(const char *string)
   1.221 @@ -448,14 +499,7 @@
   1.222          }
   1.223      }
   1.224  
   1.225 -    if (!current_audio.impl.LockDevice && !current_audio.impl.UnlockDevice) {
   1.226 -        current_audio.impl.LockDevice = SDL_LockDevice_Default;
   1.227 -        current_audio.impl.UnlockDevice = SDL_UnlockDevice_Default;
   1.228 -    }
   1.229 -
   1.230 -    if (!current_audio.impl.Deinitialize) {
   1.231 -        current_audio.impl.Deinitialize = SDL_DeinitializeAudio_Default;
   1.232 -    }
   1.233 +    finalize_audio_entry_points();
   1.234  
   1.235      return (0);
   1.236  }
   1.237 @@ -473,9 +517,21 @@
   1.238  int
   1.239  SDL_GetNumAudioDevices(int iscapture)
   1.240  {
   1.241 -    if (!SDL_WasInit(SDL_INIT_AUDIO) || !current_audio.impl.DetectDevices) {
   1.242 +    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
   1.243          return -1;
   1.244      }
   1.245 +    if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
   1.246 +        return 0;
   1.247 +    }
   1.248 +
   1.249 +    if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
   1.250 +        return 1;
   1.251 +    }
   1.252 +
   1.253 +    if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
   1.254 +        return 1;
   1.255 +    }
   1.256 +
   1.257      return current_audio.impl.DetectDevices(iscapture);
   1.258  }
   1.259  
   1.260 @@ -488,11 +544,24 @@
   1.261          return NULL;
   1.262      }
   1.263  
   1.264 -    if ((index < 0) && (!current_audio.impl.GetDeviceName)) {
   1.265 +    if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
   1.266 +        SDL_SetError("No capture support");
   1.267 +        return NULL;
   1.268 +    }
   1.269 +
   1.270 +    if (index < 0) {
   1.271          SDL_SetError("No such device");
   1.272          return NULL;
   1.273      }
   1.274  
   1.275 +    if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
   1.276 +        return DEFAULT_INPUT_DEVNAME;
   1.277 +    }
   1.278 +
   1.279 +    if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
   1.280 +        return DEFAULT_OUTPUT_DEVNAME;
   1.281 +    }
   1.282 +
   1.283      return current_audio.impl.GetDeviceName(index, iscapture);
   1.284  }
   1.285  
   1.286 @@ -513,12 +582,10 @@
   1.287      if (device->convert.needed) {
   1.288          SDL_FreeAudioMem(device->convert.buf);
   1.289      }
   1.290 -#if !SDL_AUDIO_DRIVER_AHI   /* !!! FIXME: get rid of this #if. */
   1.291      if (device->opened) {
   1.292          current_audio.impl.CloseDevice(device);
   1.293          device->opened = 0;
   1.294      }
   1.295 -#endif
   1.296      SDL_FreeAudioMem(device);
   1.297  }
   1.298  
   1.299 @@ -596,21 +663,21 @@
   1.300                      const SDL_AudioSpec *_desired, SDL_AudioSpec *obtained,
   1.301                      int min_id)
   1.302  {
   1.303 -    int i = 0;
   1.304      SDL_AudioDeviceID id = 0;
   1.305      SDL_AudioSpec desired;
   1.306      SDL_AudioDevice *device;
   1.307 -
   1.308 -    if (iscapture) {
   1.309 -        SDL_SetError("Audio capture support not implemented yet!");
   1.310 -        return 0;  /* !!! FIXME */
   1.311 -    }
   1.312 +    int i = 0;
   1.313  
   1.314      if (!SDL_WasInit(SDL_INIT_AUDIO)) {
   1.315          SDL_SetError("Audio subsystem is not initialized");
   1.316          return 0;
   1.317      }
   1.318  
   1.319 +    if ((iscapture) && (!current_audio.impl.HasCaptureSupport)) {
   1.320 +        SDL_SetError("No capture support");
   1.321 +        return 0;
   1.322 +    }
   1.323 +
   1.324      if (!prepare_audiospec(_desired, &desired)) {
   1.325          return 0;
   1.326      }
   1.327 @@ -620,6 +687,46 @@
   1.328          devname = SDL_getenv("SDL_AUDIO_DEVICE_NAME");
   1.329      }
   1.330  
   1.331 +    /*
   1.332 +     * Catch device names at the high level for the simple case...
   1.333 +     * This lets us have a basic "device enumeration" for systems that
   1.334 +     *  don't have multiple devices, but makes sure the device name is
   1.335 +     *  always NULL when it hits the low level.
   1.336 +     *
   1.337 +     * Also make sure that the simple case prevents multiple simultaneous
   1.338 +     *  opens of the default system device.
   1.339 +     */
   1.340 +
   1.341 +    if ((iscapture) && (current_audio.impl.OnlyHasDefaultInputDevice)) {
   1.342 +        if ((devname) && (SDL_strcmp(devname, DEFAULT_INPUT_DEVNAME) != 0)) {
   1.343 +            SDL_SetError("No such device");
   1.344 +            return 0;
   1.345 +        }
   1.346 +        devname = NULL;
   1.347 +
   1.348 +        for (i = 0; i < SDL_arraysize(open_devices); i++) {
   1.349 +            if ((open_devices[i]) && (open_devices[i]->iscapture)) {
   1.350 +                SDL_SetError("Audio device already open");
   1.351 +                return;
   1.352 +            }
   1.353 +        }
   1.354 +    }
   1.355 +
   1.356 +    if ((!iscapture) && (current_audio.impl.OnlyHasDefaultOutputDevice)) {
   1.357 +        if ((devname) && (SDL_strcmp(devname, DEFAULT_OUTPUT_DEVNAME) != 0)) {
   1.358 +            SDL_SetError("No such device");
   1.359 +            return 0;
   1.360 +        }
   1.361 +        devname = NULL;
   1.362 +
   1.363 +        for (i = 0; i < SDL_arraysize(open_devices); i++) {
   1.364 +            if ((open_devices[i]) && (!open_devices[i]->iscapture)) {
   1.365 +                SDL_SetError("Audio device already open");
   1.366 +                return;
   1.367 +            }
   1.368 +        }
   1.369 +    }
   1.370 +
   1.371      device = (SDL_AudioDevice *) SDL_AllocAudioMem(sizeof (SDL_AudioDevice));
   1.372      if (device == NULL) {
   1.373          SDL_OutOfMemory();
   1.374 @@ -627,21 +734,19 @@
   1.375      }
   1.376      SDL_memset(device, '\0', sizeof (SDL_AudioDevice));
   1.377      SDL_memcpy(&device->spec, &desired, sizeof (SDL_AudioSpec));
   1.378 -    device->driver = &current_audio;  /* !!! FIXME: unused... */
   1.379      device->enabled = 1;
   1.380      device->paused = 1;
   1.381 +    device->iscapture = iscapture;
   1.382  
   1.383 -/* !!! FIXME: Get this out of the core. */
   1.384 -#if defined(__MINT__) && SDL_THREADS_DISABLED
   1.385 -    /* Uses interrupt driven audio, without thread */
   1.386 -#else
   1.387      /* Create a semaphore for locking the sound buffers */
   1.388 -    device->mixer_lock = SDL_CreateMutex();
   1.389 -    if (device->mixer_lock == NULL) {
   1.390 -        SDL_SetError("Couldn't create mixer lock");
   1.391 -        return 0;
   1.392 +    if (!current_audio.impl.SkipMixerLock) {
   1.393 +        device->mixer_lock = SDL_CreateMutex();
   1.394 +        if (device->mixer_lock == NULL) {
   1.395 +            close_audio_device(device);
   1.396 +            SDL_SetError("Couldn't create mixer lock");
   1.397 +            return 0;
   1.398 +        }
   1.399      }
   1.400 -#endif /* __MINT__ */
   1.401  
   1.402  /* !!! FIXME: Get this #if out of the core. */
   1.403  /* AmigaOS opens audio inside the main loop */
   1.404 @@ -650,7 +755,7 @@
   1.405          close_audio_device(device);
   1.406          return 0;
   1.407      }
   1.408 -    device->opened = 2;  /* !!! FIXME */
   1.409 +    device->opened = 1;
   1.410  #else
   1.411  #   error needs to be fixed for new internal API. Email Ryan for details.
   1.412  
   1.413 @@ -729,10 +834,10 @@
   1.414          return 0;
   1.415      }
   1.416  
   1.417 +/* !!! FIXME: get this out of core. */
   1.418  #if !SDL_AUDIO_DRIVER_AHI
   1.419      /* Start the audio thread if necessary */
   1.420 -    switch (device->opened) {  /* !!! FIXME: what is this?! */
   1.421 -    case 1:
   1.422 +    if (!current_audio.impl.ProvidesOwnCallbackThread) {
   1.423          /* Start the audio thread */
   1.424  /* !!! FIXME: this is nasty. */
   1.425  #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC)
   1.426 @@ -746,12 +851,8 @@
   1.427              SDL_SetError("Couldn't create audio thread");
   1.428              return 0;
   1.429          }
   1.430 -        break;
   1.431 +    }
   1.432  
   1.433 -    default:
   1.434 -        /* The audio is now playing */
   1.435 -        break;
   1.436 -    }
   1.437  #else
   1.438      SDL_mutexV(audio->mixer_lock);
   1.439      D(bug("SDL_OpenAudio USCITA...\n"));
   1.440 @@ -838,12 +939,10 @@
   1.441  void
   1.442  SDL_LockAudioDevice(SDL_AudioDeviceID devid)
   1.443  {
   1.444 -    if (current_audio.impl.LockDevice != NULL) {
   1.445 -        SDL_AudioDevice *device = get_audio_device(devid);
   1.446 -        /* Obtain a lock on the mixing buffers */
   1.447 -        if (device) {
   1.448 -            current_audio.impl.LockDevice(device);
   1.449 -        }
   1.450 +    /* Obtain a lock on the mixing buffers */
   1.451 +    SDL_AudioDevice *device = get_audio_device(devid);
   1.452 +    if (device) {
   1.453 +        current_audio.impl.LockDevice(device);
   1.454      }
   1.455  }
   1.456  
   1.457 @@ -856,12 +955,10 @@
   1.458  void
   1.459  SDL_UnlockAudioDevice(SDL_AudioDeviceID devid)
   1.460  {
   1.461 -    if (current_audio.impl.UnlockDevice != NULL) {
   1.462 -        SDL_AudioDevice *device = get_audio_device(devid);
   1.463 -        /* Obtain a lock on the mixing buffers */
   1.464 -        if (device) {
   1.465 -            current_audio.impl.UnlockDevice(device);
   1.466 -        }
   1.467 +    /* Obtain a lock on the mixing buffers */
   1.468 +    SDL_AudioDevice *device = get_audio_device(devid);
   1.469 +    if (device) {
   1.470 +        current_audio.impl.UnlockDevice(device);
   1.471      }
   1.472  }
   1.473  
     2.1 --- a/src/audio/SDL_sysaudio.h	Wed Oct 04 06:00:10 2006 +0000
     2.2 +++ b/src/audio/SDL_sysaudio.h	Wed Oct 04 19:54:23 2006 +0000
     2.3 @@ -45,6 +45,13 @@
     2.4      void (*LockDevice) (_THIS);
     2.5      void (*UnlockDevice) (_THIS);
     2.6      void (*Deinitialize) (void);
     2.7 +
     2.8 +    /* Some flags to push duplicate code into the core and reduce #ifdefs. */
     2.9 +    int ProvidesOwnCallbackThread:1;
    2.10 +    int SkipMixerLock:1;
    2.11 +    int HasCaptureSupport:1;
    2.12 +    int OnlyHasDefaultOutputDevice:1;
    2.13 +    int OnlyHasDefaultInputDevice:1;
    2.14  } SDL_AudioDriverImpl;
    2.15  
    2.16  
    2.17 @@ -66,10 +73,6 @@
    2.18  struct SDL_AudioDevice
    2.19  {
    2.20      /* * * */
    2.21 -    /* Lowlevel audio implementation */
    2.22 -    const SDL_AudioDriver *driver;
    2.23 -
    2.24 -    /* * * */
    2.25      /* Data common to all devices */
    2.26  
    2.27      /* The current audio specification (shared with audio thread) */
    2.28 @@ -79,6 +82,7 @@
    2.29      SDL_AudioCVT convert;
    2.30  
    2.31      /* Current state flags */
    2.32 +    int iscapture;
    2.33      int enabled;
    2.34      int paused;
    2.35      int opened;
    2.36 @@ -96,10 +100,6 @@
    2.37      /* * * */
    2.38      /* Data private to this driver */
    2.39      struct SDL_PrivateAudioData *hidden;
    2.40 -
    2.41 -    /* * * */
    2.42 -    /* The function used to dispose of this structure */
    2.43 -    void (*free) (_THIS);
    2.44  };
    2.45  #undef _THIS
    2.46  
    2.47 @@ -111,77 +111,5 @@
    2.48      int (*init) (SDL_AudioDriverImpl *impl);
    2.49  } AudioBootStrap;
    2.50  
    2.51 -#if SDL_AUDIO_DRIVER_BSD
    2.52 -extern AudioBootStrap BSD_AUDIO_bootstrap;
    2.53 -#endif
    2.54 -#if SDL_AUDIO_DRIVER_OSS
    2.55 -extern AudioBootStrap DSP_bootstrap;
    2.56 -extern AudioBootStrap DMA_bootstrap;
    2.57 -#endif
    2.58 -#if SDL_AUDIO_DRIVER_ALSA
    2.59 -extern AudioBootStrap ALSA_bootstrap;
    2.60 -#endif
    2.61 -#if SDL_AUDIO_DRIVER_QNXNTO
    2.62 -extern AudioBootStrap QNXNTOAUDIO_bootstrap;
    2.63 -#endif
    2.64 -#if SDL_AUDIO_DRIVER_SUNAUDIO
    2.65 -extern AudioBootStrap SUNAUDIO_bootstrap;
    2.66 -#endif
    2.67 -#if SDL_AUDIO_DRIVER_DMEDIA
    2.68 -extern AudioBootStrap DMEDIA_bootstrap;
    2.69 -#endif
    2.70 -#if SDL_AUDIO_DRIVER_ARTS
    2.71 -extern AudioBootStrap ARTS_bootstrap;
    2.72 -#endif
    2.73 -#if SDL_AUDIO_DRIVER_ESD
    2.74 -extern AudioBootStrap ESD_bootstrap;
    2.75 -#endif
    2.76 -#if SDL_AUDIO_DRIVER_NAS
    2.77 -extern AudioBootStrap NAS_bootstrap;
    2.78 -#endif
    2.79 -#if SDL_AUDIO_DRIVER_DSOUND
    2.80 -extern AudioBootStrap DSOUND_bootstrap;
    2.81 -#endif
    2.82 -#if SDL_AUDIO_DRIVER_WAVEOUT
    2.83 -extern AudioBootStrap WAVEOUT_bootstrap;
    2.84 -#endif
    2.85 -#if SDL_AUDIO_DRIVER_PAUD
    2.86 -extern AudioBootStrap Paud_bootstrap;
    2.87 -#endif
    2.88 -#if SDL_AUDIO_DRIVER_BAUDIO
    2.89 -extern AudioBootStrap BAUDIO_bootstrap;
    2.90 -#endif
    2.91 -#if SDL_AUDIO_DRIVER_COREAUDIO
    2.92 -extern AudioBootStrap COREAUDIO_bootstrap;
    2.93 -#endif
    2.94 -#if SDL_AUDIO_DRIVER_SNDMGR
    2.95 -extern AudioBootStrap SNDMGR_bootstrap;
    2.96 -#endif
    2.97 -#if SDL_AUDIO_DRIVER_AHI
    2.98 -extern AudioBootStrap AHI_bootstrap;
    2.99 -#endif
   2.100 -#if SDL_AUDIO_DRIVER_MINT
   2.101 -extern AudioBootStrap MINTAUDIO_GSXB_bootstrap;
   2.102 -extern AudioBootStrap MINTAUDIO_MCSN_bootstrap;
   2.103 -extern AudioBootStrap MINTAUDIO_STFA_bootstrap;
   2.104 -extern AudioBootStrap MINTAUDIO_XBIOS_bootstrap;
   2.105 -extern AudioBootStrap MINTAUDIO_DMA8_bootstrap;
   2.106 -#endif
   2.107 -#if SDL_AUDIO_DRIVER_DISK
   2.108 -extern AudioBootStrap DISKAUD_bootstrap;
   2.109 -#endif
   2.110 -#if SDL_AUDIO_DRIVER_DUMMY
   2.111 -extern AudioBootStrap DUMMYAUD_bootstrap;
   2.112 -#endif
   2.113 -#if SDL_AUDIO_DRIVER_DC
   2.114 -extern AudioBootStrap DCAUD_bootstrap;
   2.115 -#endif
   2.116 -#if SDL_AUDIO_DRIVER_MMEAUDIO
   2.117 -extern AudioBootStrap MMEAUDIO_bootstrap;
   2.118 -#endif
   2.119 -#if SDL_AUDIO_DRIVER_DART
   2.120 -extern AudioBootStrap DART_bootstrap;
   2.121 -#endif
   2.122 -
   2.123  #endif /* _SDL_sysaudio_h */
   2.124  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/audio/dart/SDL_dart.c	Wed Oct 04 06:00:10 2006 +0000
     3.2 +++ b/src/audio/dart/SDL_dart.c	Wed Oct 04 19:54:23 2006 +0000
     3.3 @@ -285,7 +285,25 @@
     3.4  void
     3.5  DART_ThreadInit(_THIS)
     3.6  {
     3.7 -    return;
     3.8 +    /* Increase the priority of this thread to make sure that
     3.9 +       the audio will be continuous all the time! */
    3.10 +#ifdef USE_DOSSETPRIORITY
    3.11 +    if (SDL_getenv("SDL_USE_TIMECRITICAL_AUDIO")) {
    3.12 +#ifdef DEBUG_BUILD
    3.13 +        printf
    3.14 +            ("[SDL_RunAudio] : Setting priority to TimeCritical+0! (TID%d)\n",
    3.15 +             SDL_ThreadID());
    3.16 +#endif
    3.17 +        DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, 0);
    3.18 +    } else {
    3.19 +#ifdef DEBUG_BUILD
    3.20 +        printf
    3.21 +            ("[SDL_RunAudio] : Setting priority to ForegroundServer+0! (TID%d)\n",
    3.22 +             SDL_ThreadID());
    3.23 +#endif
    3.24 +        DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 0, 0);
    3.25 +    }
    3.26 +#endif
    3.27  }
    3.28  
    3.29  /* This function waits until it is possible to write a full sound buffer */
     4.1 --- a/src/audio/dummy/SDL_dummyaudio.c	Wed Oct 04 06:00:10 2006 +0000
     4.2 +++ b/src/audio/dummy/SDL_dummyaudio.c	Wed Oct 04 19:54:23 2006 +0000
     4.3 @@ -65,6 +65,7 @@
     4.4      impl->PlayDevice = DUMMYAUD_PlayDevice;
     4.5      impl->GetDeviceBuf = DUMMYAUD_GetDeviceBuf;
     4.6      impl->CloseDevice = DUMMYAUD_CloseDevice;
     4.7 +    impl->OnlyHasDefaultOutputDevice = 1;
     4.8  
     4.9      return 1;
    4.10  }
     5.1 --- a/src/audio/macosx/SDL_coreaudio.c	Wed Oct 04 06:00:10 2006 +0000
     5.2 +++ b/src/audio/macosx/SDL_coreaudio.c	Wed Oct 04 19:54:23 2006 +0000
     5.3 @@ -233,7 +233,7 @@
     5.4      impl->GetDeviceBuf = COREAUDIO_GetDeviceBuf;
     5.5      impl->CloseDevice = COREAUDIO_CloseDevice;
     5.6      impl->Deinitialize = COREAUDIO_Deinitialize;
     5.7 -
     5.8 +    impl->ProvidesOwnCallbackThread = 1;
     5.9      return 1;
    5.10  }
    5.11  
    5.12 @@ -382,7 +382,7 @@
    5.13          AURenderCallbackStruct callback;
    5.14          const AudioUnitElement output_bus = 0;
    5.15          const AudioUnitElement input_bus = 1;
    5.16 -        const int iscapture = this->hidden->isCapture;
    5.17 +        const int iscapture = this->iscapture;
    5.18          const AudioUnitElement bus = ((iscapture) ? input_bus : output_bus);
    5.19          const AudioUnitScope scope = ((iscapture) ? kAudioUnitScope_Output :
    5.20                                                      kAudioUnitScope_Input);
    5.21 @@ -571,8 +571,6 @@
    5.22      }
    5.23      SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    5.24  
    5.25 -    this->hidden->isCapture = iscapture;
    5.26 -
    5.27      /* Setup a AudioStreamBasicDescription with the requested format */
    5.28      memset(&strdesc, '\0', sizeof(AudioStreamBasicDescription));
    5.29      strdesc.mFormatID = kAudioFormatLinearPCM;
     6.1 --- a/src/audio/macosx/SDL_coreaudio.h	Wed Oct 04 06:00:10 2006 +0000
     6.2 +++ b/src/audio/macosx/SDL_coreaudio.h	Wed Oct 04 19:54:23 2006 +0000
     6.3 @@ -36,7 +36,6 @@
     6.4      UInt32 bufferOffset;
     6.5      UInt32 bufferSize;
     6.6      AudioDeviceID deviceID;
     6.7 -    int isCapture;
     6.8  };
     6.9  
    6.10  #endif /* _SDL_coreaudio_h */
     7.1 --- a/src/audio/macrom/SDL_romaudio.c	Wed Oct 04 06:00:10 2006 +0000
     7.2 +++ b/src/audio/macrom/SDL_romaudio.c	Wed Oct 04 19:54:23 2006 +0000
     7.3 @@ -70,14 +70,16 @@
     7.4  SNDMGR_Init(SDL_AudioDriverImpl *impl)
     7.5  {
     7.6      /* Set the function pointers */
     7.7 +    impl->DetectDevices = SNDMGR_DetectDevices;
     7.8 +    impl->GetDeviceName = SNDMGR_GetDeviceName;
     7.9      impl->OpenDevice = SNDMGR_OpenDevice;
    7.10      impl->CloseDevice = SNDMGR_CloseDevice;
    7.11 +    impl->ProvidesOwnCallbackThread = 1;
    7.12 +    impl->OnlyHasDefaultOutputDevice = 1;
    7.13 +
    7.14 +#ifndef __MACOSX__               /* Mac OS X uses threaded audio, so normal thread code is okay */
    7.15      impl->LockDevice = SNDMGR_LockDevice;
    7.16      impl->UnlockDevice = SNDMGR_UnlockDevice;
    7.17 -
    7.18 -#ifdef __MACOSX__               /* Mac OS X uses threaded audio, so normal thread code is okay */
    7.19 -    impl->LockDevice = NULL;
    7.20 -    impl->UnlockDevice = NULL;
    7.21  #endif
    7.22  
    7.23      return 1;
    7.24 @@ -90,7 +92,6 @@
    7.25  
    7.26  #pragma options align=power
    7.27  
    7.28 -static volatile int audio_is_opened = 0;
    7.29  static volatile SInt32 audio_is_locked = 0;
    7.30  static volatile SInt32 need_to_mix = 0;
    7.31  
    7.32 @@ -99,6 +100,7 @@
    7.33  static CmpSoundHeader header;
    7.34  static volatile Uint32 fill_me = 0;
    7.35  
    7.36 +
    7.37  static void
    7.38  mix_buffer(SDL_AudioDevice * audio, UInt8 * buffer)
    7.39  {
    7.40 @@ -206,18 +208,6 @@
    7.41      int i;
    7.42      long initOptions;
    7.43  
    7.44 -    if (audio_is_opened) {
    7.45 -        SDL_SetError("SoundManager driver doesn't support multiple opens");
    7.46 -        return 0;
    7.47 -    }
    7.48 -
    7.49 -    if (iscapture) {
    7.50 -        SDL_SetError("SoundManager driver doesn't support recording");
    7.51 -        return 0;
    7.52 -    }
    7.53 -
    7.54 -    /* !!! FIXME: ignore devname? */
    7.55 -
    7.56      /* Initialize all variables that we clean on shutdown */
    7.57      this->hidden = (struct SDL_PrivateAudioData *)
    7.58                          SDL_malloc((sizeof *this->hidden));
    7.59 @@ -320,14 +310,12 @@
    7.60          SndDoCommand(channel, &cmd, 0);
    7.61      }
    7.62  
    7.63 -    audio_is_opened = 1;
    7.64      return 1;
    7.65  }
    7.66  
    7.67  static void
    7.68  SNDMGR_CloseDevice(_THIS)
    7.69  {
    7.70 -
    7.71      int i;
    7.72  
    7.73      running = 0;
    7.74 @@ -345,7 +333,6 @@
    7.75      }
    7.76      SDL_free(this->hidden);
    7.77      this->hidden = NULL;
    7.78 -    audio_is_opened = 0;
    7.79  }
    7.80  
    7.81  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/audio/mint/SDL_mintaudio_dma8.c	Wed Oct 04 06:00:10 2006 +0000
     8.2 +++ b/src/audio/mint/SDL_mintaudio_dma8.c	Wed Oct 04 19:54:23 2006 +0000
     8.3 @@ -150,6 +150,11 @@
     8.4      this->UnlockAudio = Mint_UnlockAudio;
     8.5      this->free = Audio_DeleteDevice;
     8.6  
     8.7 +    /* Uses interrupt driven audio, without thread */
     8.8 +    #if SDL_THREADS_DISABLED
     8.9 +    this->SkipMixerLock = 1;
    8.10 +    #endif
    8.11 +
    8.12      return this;
    8.13  }
    8.14  
     9.1 --- a/src/audio/mint/SDL_mintaudio_gsxb.c	Wed Oct 04 06:00:10 2006 +0000
     9.2 +++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Wed Oct 04 19:54:23 2006 +0000
     9.3 @@ -156,6 +156,11 @@
     9.4      this->UnlockAudio = Mint_UnlockAudio;
     9.5      this->free = Audio_DeleteDevice;
     9.6  
     9.7 +    /* Uses interrupt driven audio, without thread */
     9.8 +    #if SDL_THREADS_DISABLED
     9.9 +    this->SkipMixerLock = 1;
    9.10 +    #endif
    9.11 +
    9.12      return this;
    9.13  }
    9.14  
    10.1 --- a/src/audio/mint/SDL_mintaudio_mcsn.c	Wed Oct 04 06:00:10 2006 +0000
    10.2 +++ b/src/audio/mint/SDL_mintaudio_mcsn.c	Wed Oct 04 19:54:23 2006 +0000
    10.3 @@ -171,6 +171,11 @@
    10.4      this->UnlockAudio = Mint_UnlockAudio;
    10.5      this->free = Audio_DeleteDevice;
    10.6  
    10.7 +    /* Uses interrupt driven audio, without thread */
    10.8 +    #if SDL_THREADS_DISABLED
    10.9 +    this->SkipMixerLock = 1;
   10.10 +    #endif
   10.11 +
   10.12      return this;
   10.13  }
   10.14  
    11.1 --- a/src/audio/mint/SDL_mintaudio_stfa.c	Wed Oct 04 06:00:10 2006 +0000
    11.2 +++ b/src/audio/mint/SDL_mintaudio_stfa.c	Wed Oct 04 19:54:23 2006 +0000
    11.3 @@ -150,6 +150,11 @@
    11.4      this->UnlockAudio = Mint_UnlockAudio;
    11.5      this->free = Audio_DeleteDevice;
    11.6  
    11.7 +    /* Uses interrupt driven audio, without thread */
    11.8 +    #if SDL_THREADS_DISABLED
    11.9 +    this->SkipMixerLock = 1;
   11.10 +    #endif
   11.11 +
   11.12      return this;
   11.13  }
   11.14  
    12.1 --- a/src/audio/mint/SDL_mintaudio_xbios.c	Wed Oct 04 06:00:10 2006 +0000
    12.2 +++ b/src/audio/mint/SDL_mintaudio_xbios.c	Wed Oct 04 19:54:23 2006 +0000
    12.3 @@ -155,6 +155,11 @@
    12.4      this->UnlockAudio = Mint_UnlockAudio;
    12.5      this->free = Audio_DeleteDevice;
    12.6  
    12.7 +    /* Uses interrupt driven audio, without thread */
    12.8 +    #if SDL_THREADS_DISABLED
    12.9 +    this->SkipMixerLock = 1;
   12.10 +    #endif
   12.11 +
   12.12      return this;
   12.13  }
   12.14