Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Added audio device enumeration for 1.3.
  • Loading branch information
icculus committed Oct 3, 2006
1 parent aa918f9 commit 429efc03252f4bfd30f3685a5911e76db5886f27
Showing with 84 additions and 7 deletions.
  1. +3 −0 include/SDL_audio.h
  2. +28 −0 src/audio/SDL_audio.c
  3. +2 −0 src/audio/SDL_sysaudio.h
  4. +51 −7 src/audio/macosx/SDL_coreaudio.c
@@ -235,6 +235,9 @@ extern DECLSPEC int SDLCALL SDL_GetNumAudioDevices(int iscapture);
* Get the human-readable name of a specific audio device.
* Must be a value between 0 and (number of audio devices-1).
* Only valid after a successfully initializing the audio subsystem.
* The values returned by this function reflect the latest call to
* SDL_GetNumAudioDevices(); recall that function to redetect available
* hardware.
*/
extern DECLSPEC const char *SDLCALL SDL_GetAudioDevice(int index,
int iscapture);
@@ -455,6 +455,34 @@ SDL_GetCurrentAudioDriver()
return current_audio.name;
}


int
SDL_GetNumAudioDevices(int iscapture)
{
if (!SDL_WasInit(SDL_INIT_AUDIO) || !current_audio.impl.DetectDevices) {
return -1;
}
return current_audio.impl.DetectDevices(iscapture);
}


const char *
SDL_GetAudioDevice(int index, int iscapture)
{
if (!SDL_WasInit(SDL_INIT_AUDIO)) {
SDL_SetError("Audio subsystem is not initialized");
return NULL;
}

if ((index < 0) && (!current_audio.impl.GetAudioDevice)) {
SDL_SetError("No such device");
return NULL;
}

return current_audio.impl.GetAudioDevice(index, iscapture);
}


static void
close_audio_device(SDL_AudioDevice *device)
{
@@ -34,6 +34,8 @@ typedef struct SDL_AudioDevice SDL_AudioDevice;
/* !!! FIXME: rename these from "Audio" to "Device" ... */
typedef struct SDL_AudioDriverImpl
{
int (*DetectDevices)(int iscapture);
const char *(*GetAudioDevice)(int index, int iscapture);
int (*OpenAudio) (_THIS, const char *devname, int iscapture);
void (*ThreadInit) (_THIS); /* Called by audio thread at start */
void (*WaitAudio) (_THIS);
@@ -29,7 +29,7 @@
#include "../SDL_sysaudio.h"
#include "SDL_coreaudio.h"

#define DEBUG_COREAUDIO 1
#define DEBUG_COREAUDIO 0

typedef struct COREAUDIO_DeviceList
{
@@ -169,6 +169,22 @@ build_device_list(int iscapture, COREAUDIO_DeviceList **devices, int *devCount)
}
}

static inline void
build_device_lists(void)
{
build_device_list(0, &outputDevices, &outputDeviceCount);
build_device_list(1, &inputDevices, &inputDeviceCount);
}


static inline void
free_device_lists(void)
{
free_device_list(&outputDevices, &outputDeviceCount);
free_device_list(&inputDevices, &inputDeviceCount);
}


static int
find_device_id(const char *devname, int iscapture, AudioDeviceID *id)
{
@@ -188,6 +204,8 @@ find_device_id(const char *devname, int iscapture, AudioDeviceID *id)

/* Audio driver functions */

static int COREAUDIO_DetectDevices(int iscapture);
static const char *COREAUDIO_GetAudioDevice(int index, int iscapture);
static int COREAUDIO_OpenAudio(_THIS, const char *devname, int iscapture);
static void COREAUDIO_WaitAudio(_THIS);
static void COREAUDIO_PlayAudio(_THIS);
@@ -206,11 +224,9 @@ COREAUDIO_Available(void)
static int
COREAUDIO_Init(SDL_AudioDriverImpl *impl)
{
/* !!! FIXME: should these _really_ be static? */
build_device_list(0, &outputDevices, &outputDeviceCount);
build_device_list(1, &inputDevices, &inputDeviceCount);

/* Set the function pointers */
impl->DetectDevices = COREAUDIO_DetectDevices;
impl->GetAudioDevice = COREAUDIO_GetAudioDevice;
impl->OpenAudio = COREAUDIO_OpenAudio;
impl->WaitAudio = COREAUDIO_WaitAudio;
impl->PlayAudio = COREAUDIO_PlayAudio;
@@ -227,11 +243,39 @@ AudioBootStrap COREAUDIO_bootstrap = {
};


static int
COREAUDIO_DetectDevices(int iscapture)
{
if (iscapture) {
build_device_list(1, &inputDevices, &inputDeviceCount);
return inputDeviceCount;
} else {
build_device_list(0, &outputDevices, &outputDeviceCount);
return outputDeviceCount;
}

return 0; /* shouldn't ever hit this. */
}


static const char *
COREAUDIO_GetAudioDevice(int index, int iscapture)
{
if ((iscapture) && (index < inputDeviceCount)) {
return inputDevices[index].name;
} else if ((!iscapture) && (index < outputDeviceCount)) {
return outputDevices[index].name;
}

SDL_SetError("No such device");
return NULL;
}


static void
COREAUDIO_Deinitialize(void)
{
free_device_list(&outputDevices, &outputDeviceCount);
free_device_list(&inputDevices, &inputDeviceCount);
free_device_lists();
}


0 comments on commit 429efc0

Please sign in to comment.