From 1c422d405726f4c93ef11df4bd99fe398fa8d097 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 23 Mar 2015 21:23:10 -0700 Subject: [PATCH] SDL: Use SDL2 audio APIs when compiled against SDL2 --- src/platform/sdl/sdl-audio.c | 24 ++++++++++++++++++++++++ src/platform/sdl/sdl-audio.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/platform/sdl/sdl-audio.c b/src/platform/sdl/sdl-audio.c index ccdd41d2d..7b4017d41 100644 --- a/src/platform/sdl/sdl-audio.c +++ b/src/platform/sdl/sdl-audio.c @@ -31,7 +31,13 @@ bool GBASDLInitAudio(struct GBASDLAudio* context, struct GBAThread* threadContex #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 @@ bool GBASDLInitAudio(struct GBASDLAudio* context, struct GBAThread* threadContex 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) { diff --git a/src/platform/sdl/sdl-audio.h b/src/platform/sdl/sdl-audio.h index 316b07d95..6730333eb 100644 --- a/src/platform/sdl/sdl-audio.h +++ b/src/platform/sdl/sdl-audio.h @@ -25,6 +25,9 @@ struct GBASDLAudio { #if RESAMPLE_LIBRARY == RESAMPLE_NN float drift; #endif +#if SDL_VERSION_ATLEAST(2, 0, 0) + SDL_AudioDeviceID deviceId; +#endif struct GBAThread* thread; };