mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-27 02:34:03 +02:00
Miscellaneous work on the OpenAL backend.
This commit is contained in:
@@ -4121,6 +4121,11 @@ typedef mal_ALCvoid mal_ALvoid;
|
||||
#define MAL_ALC_CAPTURE_DEVICE_SPECIFIER 0x310
|
||||
#define MAL_ALC_CAPTURE_SAMPLES 0x312
|
||||
|
||||
#define MAL_AL_SOURCE_STATE 0x1010
|
||||
#define MAL_AL_INITIAL 0x1011
|
||||
#define MAL_AL_PLAYING 0x1012
|
||||
#define MAL_AL_PAUSED 0x1013
|
||||
#define MAL_AL_STOPPED 0x1014
|
||||
#define MAL_AL_FORMAT_MONO8 0x1100
|
||||
#define MAL_AL_FORMAT_MONO16 0x1101
|
||||
#define MAL_AL_FORMAT_STEREO8 0x1102
|
||||
@@ -4220,7 +4225,7 @@ mal_result mal_context_init__openal(mal_context* pContext)
|
||||
"libopenal.so";
|
||||
#endif
|
||||
#ifdef MAL_APPLE
|
||||
// I don't own a Mac so a contribution here would be much appreciated!
|
||||
// I don't own a Mac so a contribution here would be much appreciated! Just don't know what the library is called...
|
||||
#endif
|
||||
|
||||
pContext->openal.hOpenAL = mal_dlopen(libName);
|
||||
@@ -4395,6 +4400,11 @@ static mal_result mal_device_init__openal(mal_context* pContext, mal_device_type
|
||||
pDevice->periods = MAL_MAX_PERIODS_OPENAL;
|
||||
}
|
||||
|
||||
// OpenAL has bad latency in my testing :(
|
||||
if (pDevice->flags & MAL_DEVICE_FLAG_USING_DEFAULT_BUFFER_SIZE) {
|
||||
pDevice->bufferSizeInFrames *= 4;
|
||||
}
|
||||
|
||||
mal_ALCsizei bufferSizeInSamplesAL = pConfig->bufferSizeInFrames;
|
||||
mal_ALCuint frequencyAL = pConfig->sampleRate;
|
||||
|
||||
@@ -4622,6 +4632,15 @@ static mal_result mal_device__main_loop__openal(mal_device* pDevice)
|
||||
|
||||
framesAvailable -= framesToRead;
|
||||
}
|
||||
|
||||
|
||||
// There's a chance the source has stopped playing due to there not being any buffer's queue. Make sure it's restarted.
|
||||
mal_ALenum state;
|
||||
((MAL_LPALGETSOURCEI)pDevice->pContext->openal.alGetSourcei)(pDevice->openal.sourceAL, MAL_AL_SOURCE_STATE, &state);
|
||||
|
||||
if (state != MAL_AL_PLAYING) {
|
||||
((MAL_LPALSOURCEPLAY)pDevice->pContext->openal.alSourcePlay)(pDevice->openal.sourceAL);
|
||||
}
|
||||
} else {
|
||||
while (framesAvailable > 0) {
|
||||
mal_uint32 framesToSend = (framesAvailable > pDevice->openal.subBufferSizeInFrames) ? pDevice->openal.subBufferSizeInFrames : framesAvailable;
|
||||
@@ -5224,6 +5243,11 @@ void mal_device_uninit(mal_device* pDevice)
|
||||
mal_device_uninit__sles(pDevice);
|
||||
}
|
||||
#endif
|
||||
#ifdef MAL_ENABLE_OPENAL
|
||||
if (pDevice->pContext->backend == mal_backend_openal) {
|
||||
mal_device_uninit__openal(pDevice);
|
||||
}
|
||||
#endif
|
||||
#ifdef MAL_ENABLE_NULL
|
||||
if (pDevice->pContext->backend == mal_backend_null) {
|
||||
mal_device_uninit__null(pDevice);
|
||||
|
||||
Reference in New Issue
Block a user