SDL: Use SDL2 audio APIs when compiled against SDL2
Jeffrey Pfau jeffrey@endrift.com
Mon, 23 Mar 2015 21:23:10 -0700
2 files changed,
27 insertions(+),
0 deletions(-)
M
src/platform/sdl/sdl-audio.c
→
src/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.h
→
src/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; };