Added audio device enumeration for 1.3. SDL-ryan-multiple-audio-device
authorRyan C. Gordon <icculus@icculus.org>
Tue, 03 Oct 2006 20:07:50 +0000
branchSDL-ryan-multiple-audio-device
changeset 37908f8209f8da6d
parent 3789 e2f68b579a01
child 3791 be33495e4d97
Added audio device enumeration for 1.3.
include/SDL_audio.h
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
src/audio/macosx/SDL_coreaudio.c
     1.1 --- a/include/SDL_audio.h	Tue Oct 03 20:05:33 2006 +0000
     1.2 +++ b/include/SDL_audio.h	Tue Oct 03 20:07:50 2006 +0000
     1.3 @@ -235,6 +235,9 @@
     1.4   * Get the human-readable name of a specific audio device.
     1.5   *  Must be a value between 0 and (number of audio devices-1).
     1.6   *  Only valid after a successfully initializing the audio subsystem.
     1.7 + *  The values returned by this function reflect the latest call to
     1.8 + *  SDL_GetNumAudioDevices(); recall that function to redetect available
     1.9 + *  hardware.
    1.10   */
    1.11  extern DECLSPEC const char *SDLCALL SDL_GetAudioDevice(int index,
    1.12                                                         int iscapture);
     2.1 --- a/src/audio/SDL_audio.c	Tue Oct 03 20:05:33 2006 +0000
     2.2 +++ b/src/audio/SDL_audio.c	Tue Oct 03 20:07:50 2006 +0000
     2.3 @@ -455,6 +455,34 @@
     2.4      return current_audio.name;
     2.5  }
     2.6  
     2.7 +
     2.8 +int
     2.9 +SDL_GetNumAudioDevices(int iscapture)
    2.10 +{
    2.11 +    if (!SDL_WasInit(SDL_INIT_AUDIO) || !current_audio.impl.DetectDevices) {
    2.12 +        return -1;
    2.13 +    }
    2.14 +    return current_audio.impl.DetectDevices(iscapture);
    2.15 +}
    2.16 +
    2.17 +
    2.18 +const char *
    2.19 +SDL_GetAudioDevice(int index, int iscapture)
    2.20 +{
    2.21 +    if (!SDL_WasInit(SDL_INIT_AUDIO)) {
    2.22 +        SDL_SetError("Audio subsystem is not initialized");
    2.23 +        return NULL;
    2.24 +    }
    2.25 +
    2.26 +    if ((index < 0) && (!current_audio.impl.GetAudioDevice)) {
    2.27 +        SDL_SetError("No such device");
    2.28 +        return NULL;
    2.29 +    }
    2.30 +
    2.31 +    return current_audio.impl.GetAudioDevice(index, iscapture);
    2.32 +}
    2.33 +
    2.34 +
    2.35  static void
    2.36  close_audio_device(SDL_AudioDevice *device)
    2.37  {
     3.1 --- a/src/audio/SDL_sysaudio.h	Tue Oct 03 20:05:33 2006 +0000
     3.2 +++ b/src/audio/SDL_sysaudio.h	Tue Oct 03 20:07:50 2006 +0000
     3.3 @@ -34,6 +34,8 @@
     3.4  /* !!! FIXME: rename these from "Audio" to "Device" ... */
     3.5  typedef struct SDL_AudioDriverImpl
     3.6  {
     3.7 +    int (*DetectDevices)(int iscapture);
     3.8 +    const char *(*GetAudioDevice)(int index, int iscapture);
     3.9      int (*OpenAudio) (_THIS, const char *devname, int iscapture);
    3.10      void (*ThreadInit) (_THIS); /* Called by audio thread at start */
    3.11      void (*WaitAudio) (_THIS);
     4.1 --- a/src/audio/macosx/SDL_coreaudio.c	Tue Oct 03 20:05:33 2006 +0000
     4.2 +++ b/src/audio/macosx/SDL_coreaudio.c	Tue Oct 03 20:07:50 2006 +0000
     4.3 @@ -29,7 +29,7 @@
     4.4  #include "../SDL_sysaudio.h"
     4.5  #include "SDL_coreaudio.h"
     4.6  
     4.7 -#define DEBUG_COREAUDIO 1
     4.8 +#define DEBUG_COREAUDIO 0
     4.9  
    4.10  typedef struct COREAUDIO_DeviceList
    4.11  {
    4.12 @@ -169,6 +169,22 @@
    4.13      }
    4.14  }
    4.15  
    4.16 +static inline void
    4.17 +build_device_lists(void)
    4.18 +{
    4.19 +    build_device_list(0, &outputDevices, &outputDeviceCount);
    4.20 +    build_device_list(1, &inputDevices, &inputDeviceCount);
    4.21 +}
    4.22 +
    4.23 +
    4.24 +static inline void
    4.25 +free_device_lists(void)
    4.26 +{
    4.27 +    free_device_list(&outputDevices, &outputDeviceCount);
    4.28 +    free_device_list(&inputDevices, &inputDeviceCount);
    4.29 +}
    4.30 +
    4.31 +
    4.32  static int
    4.33  find_device_id(const char *devname, int iscapture, AudioDeviceID *id)
    4.34  {
    4.35 @@ -188,6 +204,8 @@
    4.36  
    4.37  /* Audio driver functions */
    4.38  
    4.39 +static int COREAUDIO_DetectDevices(int iscapture);
    4.40 +static const char *COREAUDIO_GetAudioDevice(int index, int iscapture);
    4.41  static int COREAUDIO_OpenAudio(_THIS, const char *devname, int iscapture);
    4.42  static void COREAUDIO_WaitAudio(_THIS);
    4.43  static void COREAUDIO_PlayAudio(_THIS);
    4.44 @@ -206,11 +224,9 @@
    4.45  static int
    4.46  COREAUDIO_Init(SDL_AudioDriverImpl *impl)
    4.47  {
    4.48 -    /* !!! FIXME: should these _really_ be static? */
    4.49 -    build_device_list(0, &outputDevices, &outputDeviceCount);
    4.50 -    build_device_list(1, &inputDevices, &inputDeviceCount);
    4.51 -
    4.52      /* Set the function pointers */
    4.53 +    impl->DetectDevices = COREAUDIO_DetectDevices;
    4.54 +    impl->GetAudioDevice = COREAUDIO_GetAudioDevice;
    4.55      impl->OpenAudio = COREAUDIO_OpenAudio;
    4.56      impl->WaitAudio = COREAUDIO_WaitAudio;
    4.57      impl->PlayAudio = COREAUDIO_PlayAudio;
    4.58 @@ -227,11 +243,39 @@
    4.59  };
    4.60  
    4.61  
    4.62 +static int
    4.63 +COREAUDIO_DetectDevices(int iscapture)
    4.64 +{
    4.65 +    if (iscapture) {
    4.66 +        build_device_list(1, &inputDevices, &inputDeviceCount);
    4.67 +        return inputDeviceCount;
    4.68 +    } else {
    4.69 +        build_device_list(0, &outputDevices, &outputDeviceCount);
    4.70 +        return outputDeviceCount;
    4.71 +    }
    4.72 +
    4.73 +    return 0;  /* shouldn't ever hit this. */
    4.74 +}
    4.75 +
    4.76 +
    4.77 +static const char *
    4.78 +COREAUDIO_GetAudioDevice(int index, int iscapture)
    4.79 +{
    4.80 +    if ((iscapture) && (index < inputDeviceCount)) {
    4.81 +        return inputDevices[index].name;
    4.82 +    } else if ((!iscapture) && (index < outputDeviceCount)) {
    4.83 +        return outputDevices[index].name;
    4.84 +    }
    4.85 +
    4.86 +    SDL_SetError("No such device");
    4.87 +    return NULL;
    4.88 +}
    4.89 +
    4.90 +
    4.91  static void
    4.92  COREAUDIO_Deinitialize(void)
    4.93  {
    4.94 -    free_device_list(&outputDevices, &outputDeviceCount);
    4.95 -    free_device_list(&inputDevices, &inputDeviceCount);
    4.96 +    free_device_lists();
    4.97  }
    4.98  
    4.99