Refactor : remove enumerate devices and other API simplifications

This commit is contained in:
Aaron Culliney 2015-06-19 22:03:48 -07:00
parent f353a11ec5
commit 3ed43fa43c
3 changed files with 14 additions and 61 deletions

View File

@ -9,10 +9,7 @@
*
*/
// HACK NOTE: DO NOT REFACTOR (yet) ...
// OK this is more hackish than it needs to be because it's attempting to mimic a DirectSound backend ...Oh God, Why?...
// Here I must confess that because of general ignorance of the mockingboard and other soundcard code at this time,
// there is a need to track any changes/fixes implemented in AppleWin...
// soundcore OpenAL backend -- streaming audio
#include "common.h"
@ -151,7 +148,7 @@ static void PlaylistDequeue(ALVoice *voice, ALPlayBuf *node)
// ----------------------------------------------------------------------------
static long openal_systemSetup(const char *sound_device, AudioContext_s **audio_context)
static long openal_systemSetup(INOUT AudioContext_s **audio_context)
{
assert(*audio_context == NULL);
assert(voices == NULL);
@ -197,7 +194,7 @@ static long openal_systemSetup(const char *sound_device, AudioContext_s **audio_
return -1;
}
static long openal_systemShutdown(AudioContext_s **audio_context)
static long openal_systemShutdown(INOUT AudioContext_s **audio_context)
{
assert(*audio_context != NULL);
@ -211,16 +208,6 @@ static long openal_systemShutdown(AudioContext_s **audio_context)
return 0;
}
static long openal_systemEnumerate(char ***device_list, const int limit)
{
assert(*device_list == NULL);
*device_list = malloc(sizeof(char*)*2);
(*device_list)[0] = strdup("unused-by-OpenAL");
unsigned int num_devices = 1;
(*device_list)[num_devices] = NULL; // sentinel
return num_devices;
}
// pause all audio
static long openal_systemPause(void)
{
@ -821,11 +808,12 @@ __attribute__((constructor(CTOR_PRIORITY_EARLY)))
static void _init_openal(void) {
LOG("Initializing OpenAL sound system");
assert(audio_backend == NULL && "there can only be one!");
openal_audio_backend.setup = &openal_systemSetup;
openal_audio_backend.shutdown = &openal_systemShutdown;
openal_audio_backend.pause = &openal_systemPause;
openal_audio_backend.resume = &openal_systemResume;
openal_audio_backend.enumerateDevices = &openal_systemEnumerate;
audio_backend = &openal_audio_backend;
}

View File

@ -58,49 +58,15 @@ bool audio_init(void) {
return true;
}
char **sound_devices = NULL;
long num_sound_devices = audio_backend->enumerateDevices(&sound_devices, MAX_SOUND_DEVICES);
long err = (num_sound_devices <= 0);
if (audioContext) {
audio_backend->shutdown(&audioContext);
}
do {
if (err) {
LOG("enumerate sound devices failed to find any devices : %ld", err);
break;
}
LOG("Number of sound devices = %ld", num_sound_devices);
bool createdAudioContext = false;
for (int i=0; i<num_sound_devices; i++) {
if (audioContext) {
audio_backend->shutdown(&audioContext);
}
err = audio_backend->setup(sound_devices[i], (AudioContext_s**)&audioContext);
if (!err) {
createdAudioContext = true;
break;
}
LOG("warning : failed to create sound device:%d err:%ld", i, err);
}
if (!createdAudioContext) {
LOG("Failed to create an audio context!");
err = true;
break;
}
LOG("Created an audio context!");
long err = audio_backend->setup((AudioContext_s**)&audioContext);
if (err) {
LOG("Failed to create an audio context!");
} else {
audio_isAvailable = true;
} while (0);
if (num_sound_devices > 0) {
char **p = sound_devices;
while (*p) {
FREE(*p);
++p;
}
FREE(sound_devices);
sound_devices = NULL;
}
return err;

View File

@ -48,7 +48,7 @@ typedef struct AudioBuffer_s {
long (*Lock)(struct AudioBuffer_s *_this, unsigned long dwWriteCursor, unsigned long dwWriteBytes, INOUT int16_t **lplpvAudioPtr1, INOUT unsigned long *lpdwAudioBytes1, void **lplpvAudioPtr2, unsigned long *lpdwAudioBytes2, unsigned long dwFlags);
// This method releases a locked sound buffer.
long (*Unlock)(struct AudioBuffer_s *_this, int16_t *lpvAudioPtr1, unsigned long dwAudioBytes1, void *lpvAudioPtr2, unsigned long dwAudioBytes2);
long (*Unlock)(struct AudioBuffer_s *_this, void *lpvAudioPtr1, unsigned long dwAudioBytes1, void *lpvAudioPtr2, unsigned long dwAudioBytes2);
long (*GetStatus)(struct AudioBuffer_s *_this, unsigned long *lpdwStatus);
@ -114,9 +114,8 @@ typedef struct AudioContext_s {
typedef struct AudioBackend_s {
// basic backend functionality controlled by soundcore
PRIVATE long (*setup)(const char *sound_device, INOUT AudioContext_s **audio_context);
PRIVATE long (*setup)(INOUT AudioContext_s **audio_context);
PRIVATE long (*shutdown)(INOUT AudioContext_s **audio_context);
PRIVATE long (*enumerateDevices)(INOUT char ***sound_devices, const int maxcount);
PRIVATE long (*pause)(void);
PRIVATE long (*resume)(void);