mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-01-01 07:30:45 +00:00
Refactor : Better segregation and modularization of the audio backend functions
This commit is contained in:
parent
7fd1b350c2
commit
33a13abbc2
@ -1377,7 +1377,7 @@ static bool MB_DSInit()
|
||||
unsigned long dwDSLockedBufferSize = 0; // Size of the locked DirectSound buffer
|
||||
int16_t* pDSLockedBuffer;
|
||||
|
||||
if(!soundcore_isAvailable)
|
||||
if(!audio_isAvailable)
|
||||
return false;
|
||||
|
||||
int hr = DSGetSoundBuffer(&MockingboardVoice, DSBCAPS_CTRLVOLUME, g_dwDSBufferSize, SAMPLE_RATE, 2);
|
||||
@ -1763,7 +1763,7 @@ static void ResetState()
|
||||
|
||||
void MB_Reset()
|
||||
{
|
||||
if(!soundcore_isAvailable)
|
||||
if(!audio_isAvailable)
|
||||
return;
|
||||
|
||||
for(int i=0; i<NUM_AY8910; i++)
|
||||
|
0
src/audio/soundcore-backend.h
Normal file
0
src/audio/soundcore-backend.h
Normal file
@ -70,6 +70,8 @@ typedef struct ALVoices {
|
||||
|
||||
static ALVoices *voices = NULL;
|
||||
|
||||
static audio_backend_s openal_audio_backend = { 0 };
|
||||
|
||||
static long OpenALCreateSoundBuffer(AudioParams_s *params, ALSoundBufferStruct **soundbuf_struct, void *extra_data);
|
||||
static long OpenALDestroySoundBuffer(ALSoundBufferStruct **soundbuf_struct);
|
||||
|
||||
@ -151,7 +153,7 @@ static void PlaylistDequeue(ALVoice *voice, ALPlayBuf *node)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
long SoundSystemCreate(const char *sound_device, SoundSystemStruct **sound_struct)
|
||||
static long openal_systemInit(const char *sound_device, SoundSystemStruct **sound_struct)
|
||||
{
|
||||
assert(*sound_struct == NULL);
|
||||
assert(voices == NULL);
|
||||
@ -197,9 +199,8 @@ long SoundSystemCreate(const char *sound_device, SoundSystemStruct **sound_struc
|
||||
return -1;
|
||||
}
|
||||
|
||||
long SoundSystemDestroy(SoundSystemStruct **sound_struct)
|
||||
static long openal_systemShutdown(SoundSystemStruct **sound_struct)
|
||||
{
|
||||
// ugly assumption : this sets the extern g_lpDS ...
|
||||
assert(*sound_struct != NULL);
|
||||
|
||||
ALCcontext *ctx = (ALCcontext*) (*sound_struct)->implementation_specific;
|
||||
@ -212,7 +213,7 @@ long SoundSystemDestroy(SoundSystemStruct **sound_struct)
|
||||
return 0;
|
||||
}
|
||||
|
||||
long SoundSystemEnumerate(char ***device_list, const int limit)
|
||||
static long openal_systemEnumerate(char ***device_list, const int limit)
|
||||
{
|
||||
assert(*device_list == NULL);
|
||||
*device_list = malloc(sizeof(char*)*2);
|
||||
@ -223,7 +224,7 @@ long SoundSystemEnumerate(char ***device_list, const int limit)
|
||||
}
|
||||
|
||||
// pause all audio
|
||||
long SoundSystemPause()
|
||||
static long openal_systemPause(void)
|
||||
{
|
||||
ALVoices *vnode = NULL;
|
||||
ALVoices *tmp = NULL;
|
||||
@ -241,7 +242,7 @@ long SoundSystemPause()
|
||||
return 0;
|
||||
}
|
||||
|
||||
long SoundSystemUnpause()
|
||||
static long openal_systemResume(void)
|
||||
{
|
||||
ALVoices *vnode = NULL;
|
||||
ALVoices *tmp = NULL;
|
||||
@ -820,3 +821,16 @@ static long OpenALDestroySoundBuffer(ALSoundBufferStruct **soundbuf_struct)
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((constructor(CTOR_PRIORITY_EARLY)))
|
||||
static void _init_openal(void) {
|
||||
LOG("Initializing OpenAL sound system");
|
||||
|
||||
openal_audio_backend.init = &openal_systemInit;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,9 @@ static VOICE* g_pSpeakerVoice = NULL;
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
bool soundcore_isAvailable = false;
|
||||
bool audio_isAvailable = false;
|
||||
|
||||
audio_backend_s *audio_backend = NULL;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -239,14 +241,14 @@ static void _destroy_enumerated_sound_devices(void) {
|
||||
|
||||
bool DSInit()
|
||||
{
|
||||
if(soundcore_isAvailable)
|
||||
if(audio_isAvailable)
|
||||
{
|
||||
g_uDSInitRefCount++;
|
||||
return true; // Already initialised successfully
|
||||
}
|
||||
|
||||
_destroy_enumerated_sound_devices();
|
||||
num_sound_devices = SoundSystemEnumerate(&sound_devices, MAX_SOUND_DEVICES);
|
||||
num_sound_devices = audio_backend->enumerateDevices(&sound_devices, MAX_SOUND_DEVICES);
|
||||
int hr = (num_sound_devices <= 0);
|
||||
if(hr)
|
||||
{
|
||||
@ -261,9 +263,9 @@ bool DSInit()
|
||||
{
|
||||
if (g_lpDS)
|
||||
{
|
||||
SoundSystemDestroy((SoundSystemStruct**)&g_lpDS);
|
||||
audio_backend->shutdown((SoundSystemStruct**)&g_lpDS);
|
||||
}
|
||||
hr = (int)SoundSystemCreate(sound_devices[x], (SoundSystemStruct**)&g_lpDS);
|
||||
hr = (int)audio_backend->init(sound_devices[x], (SoundSystemStruct**)&g_lpDS);
|
||||
if(hr == 0)
|
||||
{
|
||||
bCreatedOK = true;
|
||||
@ -278,7 +280,7 @@ bool DSInit()
|
||||
return false;
|
||||
}
|
||||
|
||||
soundcore_isAvailable = true;
|
||||
audio_isAvailable = true;
|
||||
|
||||
g_uDSInitRefCount = 1;
|
||||
|
||||
@ -291,7 +293,7 @@ void DSUninit()
|
||||
{
|
||||
_destroy_enumerated_sound_devices();
|
||||
|
||||
if(!soundcore_isAvailable)
|
||||
if(!audio_isAvailable)
|
||||
return;
|
||||
|
||||
assert(g_uDSInitRefCount);
|
||||
@ -308,8 +310,8 @@ void DSUninit()
|
||||
|
||||
assert(g_uNumVoices == 0);
|
||||
|
||||
SoundSystemDestroy((SoundSystemStruct**)&g_lpDS);
|
||||
soundcore_isAvailable = false;
|
||||
audio_backend->shutdown((SoundSystemStruct**)&g_lpDS);
|
||||
audio_isAvailable = false;
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
|
@ -66,6 +66,7 @@ typedef struct IDirectSound {
|
||||
int (*CreateSoundBuffer)(AudioParams_s *pcDSBufferDesc, LPDIRECTSOUNDBUFFER * ppDSBuffer, void *pUnkOuter);
|
||||
int (*DestroySoundBuffer)(LPDIRECTSOUNDBUFFER * ppDSBuffer);
|
||||
} IDirectSound, *LPDIRECTSOUND;
|
||||
typedef struct IDirectSound SoundSystemStruct;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -101,13 +102,22 @@ void SoundCore_SetErrorMax(const int nErrorMax);
|
||||
bool DSInit();
|
||||
void DSUninit();
|
||||
|
||||
extern bool soundcore_isAvailable;
|
||||
extern bool audio_isAvailable;
|
||||
|
||||
typedef struct IDirectSound SoundSystemStruct;
|
||||
long SoundSystemCreate(const char *sound_device, SoundSystemStruct **sound_struct);
|
||||
long SoundSystemDestroy(SoundSystemStruct **sound_struct);
|
||||
long SoundSystemPause();
|
||||
long SoundSystemUnpause();
|
||||
long SoundSystemEnumerate(char ***sound_devices, const int maxcount);
|
||||
typedef struct audio_backend_s {
|
||||
|
||||
// mandatory audio backend functions
|
||||
long (*init)(const char *sound_device, SoundSystemStruct **sound_struct);
|
||||
long (*shutdown)(SoundSystemStruct **sound_struct);
|
||||
long (*pause)(void);
|
||||
long (*resume)(void);
|
||||
long (*enumerateDevices)(char ***sound_devices, const int maxcount);
|
||||
|
||||
} audio_backend_s;
|
||||
|
||||
/*
|
||||
* The registered audio backend (renderer).
|
||||
*/
|
||||
extern audio_backend_s *audio_backend;
|
||||
|
||||
#endif /* whole file */
|
||||
|
@ -1549,7 +1549,7 @@ static void *interface_thread(void *current_key)
|
||||
{
|
||||
pthread_mutex_lock(&interface_mutex);
|
||||
#ifdef AUDIO_ENABLED
|
||||
SoundSystemPause();
|
||||
audio_backend->pause();
|
||||
#endif
|
||||
in_interface = true;
|
||||
|
||||
@ -1593,7 +1593,7 @@ static void *interface_thread(void *current_key)
|
||||
}
|
||||
|
||||
#ifdef AUDIO_ENABLED
|
||||
SoundSystemUnpause();
|
||||
audio_backend->resume();
|
||||
#endif
|
||||
pthread_mutex_unlock(&interface_mutex);
|
||||
in_interface = false;
|
||||
|
Loading…
Reference in New Issue
Block a user