Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added audio device enumeration for 1.3.
  • Loading branch information
icculus committed Oct 3, 2006
1 parent aa918f9 commit 429efc0
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
3 changes: 3 additions & 0 deletions include/SDL_audio.h
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/audio/SDL_audio.c
Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/audio/SDL_sysaudio.h
Expand Up @@ -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);
Expand Down
58 changes: 51 additions & 7 deletions src/audio/macosx/SDL_coreaudio.c
Expand Up @@ -29,7 +29,7 @@
#include "../SDL_sysaudio.h"
#include "SDL_coreaudio.h"

#define DEBUG_COREAUDIO 1
#define DEBUG_COREAUDIO 0

typedef struct COREAUDIO_DeviceList
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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();
}


Expand Down

0 comments on commit 429efc0

Please sign in to comment.