all repos — mgba @ 1c422d405726f4c93ef11df4bd99fe398fa8d097

mGBA Game Boy Advance Emulator

SDL: Use SDL2 audio APIs when compiled against SDL2
Jeffrey Pfau jeffrey@endrift.com
Mon, 23 Mar 2015 21:23:10 -0700
commit

1c422d405726f4c93ef11df4bd99fe398fa8d097

parent

9bb306f8319796d1e96079f93525c214e7687bf1

2 files changed, 27 insertions(+), 0 deletions(-)

jump to
M src/platform/sdl/sdl-audio.csrc/platform/sdl/sdl-audio.c

@@ -31,7 +31,13 @@ context->desiredSpec.userdata = context;

#if RESAMPLE_LIBRARY == RESAMPLE_NN context->drift = 0.f; #endif + +#if SDL_VERSION_ATLEAST(2, 0, 0) + context->deviceId = SDL_OpenAudioDevice(0, 0, &context->desiredSpec, &context->obtainedSpec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE); + if (context->deviceId == 0) { +#else if (SDL_OpenAudio(&context->desiredSpec, &context->obtainedSpec) < 0) { +#endif GBALog(0, GBA_LOG_ERROR, "Could not open SDL sound system"); return false; }

@@ -43,25 +49,43 @@ if (context->samples > threadContext->audioBuffers) {

threadContext->audioBuffers = context->samples * 2; } +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_PauseAudioDevice(context->deviceId, 0); +#else SDL_PauseAudio(0); +#endif return true; } void GBASDLDeinitAudio(struct GBASDLAudio* context) { UNUSED(context); +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_PauseAudioDevice(context->deviceId, 1); + SDL_CloseAudioDevice(context->deviceId); +#else SDL_PauseAudio(1); SDL_CloseAudio(); +#endif SDL_QuitSubSystem(SDL_INIT_AUDIO); } void GBASDLPauseAudio(struct GBASDLAudio* context) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_PauseAudioDevice(context->deviceId, 1); +#else UNUSED(context); SDL_PauseAudio(1); +#endif + } void GBASDLResumeAudio(struct GBASDLAudio* context) { +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_PauseAudioDevice(context->deviceId, 0); +#else UNUSED(context); SDL_PauseAudio(0); +#endif } static void _GBASDLAudioCallback(void* context, Uint8* data, int len) {
M src/platform/sdl/sdl-audio.hsrc/platform/sdl/sdl-audio.h

@@ -25,6 +25,9 @@ #endif

#if RESAMPLE_LIBRARY == RESAMPLE_NN float drift; #endif +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_AudioDeviceID deviceId; +#endif struct GBAThread* thread; };