Refactor : clarify basic subsystem interface

This commit is contained in:
Aaron Culliney 2015-06-16 23:02:25 -07:00
parent 107db0dbde
commit 72389b941a
3 changed files with 45 additions and 24 deletions

View File

@ -134,3 +134,11 @@ void audio_shutdown(void) {
audio_isAvailable = false; audio_isAvailable = false;
} }
void audio_pause(void) {
audio_backend->pause();
}
void audio_resume(void) {
audio_backend->resume();
}

View File

@ -59,24 +59,8 @@ typedef struct AudioBuffer_s {
} AudioBuffer_s; } AudioBuffer_s;
typedef struct AudioParams_s {
uint16_t nChannels;
unsigned long nSamplesPerSec;
unsigned long nAvgBytesPerSec;
uint16_t nBlockAlign;
uint16_t wBitsPerSample;
unsigned long dwBufferBytes;
} AudioParams_s;
typedef struct AudioContext_s {
void *implementation_specific;
long (*CreateSoundBuffer)(const AudioParams_s *params, INOUT AudioBuffer_s **buffer, const struct AudioContext_s *sound_system);
long (*DestroySoundBuffer)(INOUT AudioBuffer_s **buffer);
} AudioContext_s;
long DSGetLock(AudioBuffer_s *bufferObj, unsigned long dwOffset, unsigned long dwBytes, INOUT int16_t **samplesBuf, INOUT unsigned long *samplesBufSz, INOUT int16_t **samplesBufAlt, INOUT unsigned long *samplesBufAltSz); long DSGetLock(AudioBuffer_s *bufferObj, unsigned long dwOffset, unsigned long dwBytes, INOUT int16_t **samplesBuf, INOUT unsigned long *samplesBufSz, INOUT int16_t **samplesBufAlt, INOUT unsigned long *samplesBufAltSz);
long DSGetSoundBuffer(INOUT AudioBuffer_s **pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels); long DSGetSoundBuffer(INOUT AudioBuffer_s **pVoice, unsigned long dwFlags, unsigned long dwBufferSize, unsigned long nSampleRate, int nChannels);
void DSReleaseSoundBuffer(INOUT AudioBuffer_s **pVoice); void DSReleaseSoundBuffer(INOUT AudioBuffer_s **pVoice);
@ -90,8 +74,39 @@ bool audio_init(void);
*/ */
void audio_shutdown(void); void audio_shutdown(void);
/*
* Pause the audio subsystem.
*/
void audio_pause(void);
/*
* Resume the audio subsystem.
*/
void audio_resume(void);
/*
* Is the audio subsystem available?
*/
extern bool audio_isAvailable; extern bool audio_isAvailable;
// ----------------------------------------------------------------------------
// Private audio backend APIs
typedef struct AudioParams_s {
uint16_t nChannels;
unsigned long nSamplesPerSec;
unsigned long nAvgBytesPerSec;
uint16_t nBlockAlign;
uint16_t wBitsPerSample;
unsigned long dwBufferBytes;
} AudioParams_s;
typedef struct AudioContext_s {
void *implementation_specific;
PRIVATE long (*CreateSoundBuffer)(const AudioParams_s *params, INOUT AudioBuffer_s **buffer, const struct AudioContext_s *sound_system);
PRIVATE long (*DestroySoundBuffer)(INOUT AudioBuffer_s **buffer);
} AudioContext_s;
typedef struct AudioBackend_s { typedef struct AudioBackend_s {
// basic backend functionality controlled by soundcore // basic backend functionality controlled by soundcore
@ -99,14 +114,12 @@ typedef struct AudioBackend_s {
PRIVATE long (*shutdown)(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 (*enumerateDevices)(INOUT char ***sound_devices, const int maxcount);
PUBLIC long (*pause)(void); PRIVATE long (*pause)(void);
PUBLIC long (*resume)(void); PRIVATE long (*resume)(void);
} AudioBackend_s; } AudioBackend_s;
/* // Audio backend registered at CTOR time
* The registered audio backend (renderer). PRIVATE extern AudioBackend_s *audio_backend;
*/
extern AudioBackend_s *audio_backend;
#endif /* whole file */ #endif /* whole file */

View File

@ -1549,7 +1549,7 @@ static void *interface_thread(void *current_key)
{ {
pthread_mutex_lock(&interface_mutex); pthread_mutex_lock(&interface_mutex);
#ifdef AUDIO_ENABLED #ifdef AUDIO_ENABLED
audio_backend->pause(); audio_pause();
#endif #endif
in_interface = true; in_interface = true;
@ -1593,7 +1593,7 @@ static void *interface_thread(void *current_key)
} }
#ifdef AUDIO_ENABLED #ifdef AUDIO_ENABLED
audio_backend->resume(); audio_resume();
#endif #endif
pthread_mutex_unlock(&interface_mutex); pthread_mutex_unlock(&interface_mutex);
in_interface = false; in_interface = false;