From 6e727db553141811d10ec9e0478c8343d6dda2cb Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Mon, 21 Jul 2014 00:29:38 -0700 Subject: [PATCH] Set buffer size to 512 samples in the SDL/GL port --- src/gba/gba-audio.c | 2 +- src/platform/sdl/gl-main.c | 5 ++++- src/platform/sdl/sdl-audio.c | 2 +- src/platform/sdl/sdl-audio.h | 5 +++++ src/platform/sdl/sw-main.c | 4 +++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gba/gba-audio.c b/src/gba/gba-audio.c index 6716abdc7..641b95550 100644 --- a/src/gba/gba-audio.c +++ b/src/gba/gba-audio.c @@ -6,7 +6,7 @@ #include "gba-thread.h" #include "gba-video.h" -const unsigned GBA_AUDIO_SAMPLES = 512; +const unsigned GBA_AUDIO_SAMPLES = 2048; const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t); #define SWEEP_CYCLES (GBA_ARM7TDMI_FREQUENCY / 128) diff --git a/src/platform/sdl/gl-main.c b/src/platform/sdl/gl-main.c index f1114f0f6..65e85c770 100644 --- a/src/platform/sdl/gl-main.c +++ b/src/platform/sdl/gl-main.c @@ -85,6 +85,7 @@ int main(int argc, char** argv) { struct GBAThread context = { .renderer = &renderer.d.d, + .audioBuffers = 512, .startCallback = _GBASDLStart, .cleanCallback = _GBASDLClean, .sync.videoFrameWait = 0, @@ -96,6 +97,9 @@ int main(int argc, char** argv) { GBAMapOptionsToContext(&opts, &context); + renderer.audio.samples = context.audioBuffers; + GBASDLInitAudio(&renderer.audio); + GBAThreadStart(&context); _GBASDLRunloop(&context, &renderer); @@ -115,7 +119,6 @@ static int _GBASDLInit(struct GLSoftwareRenderer* renderer) { } GBASDLInitEvents(&renderer->events); - GBASDLInitAudio(&renderer->audio); #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); diff --git a/src/platform/sdl/sdl-audio.c b/src/platform/sdl/sdl-audio.c index ac4d0c3d6..566ce4a2e 100644 --- a/src/platform/sdl/sdl-audio.c +++ b/src/platform/sdl/sdl-audio.c @@ -16,7 +16,7 @@ bool GBASDLInitAudio(struct GBASDLAudio* context) { context->desiredSpec.freq = 44100; context->desiredSpec.format = AUDIO_S16SYS; context->desiredSpec.channels = 2; - context->desiredSpec.samples = BUFFER_SIZE; + context->desiredSpec.samples = context->samples; context->desiredSpec.callback = _GBASDLAudioCallback; context->desiredSpec.userdata = context; context->audio = 0; diff --git a/src/platform/sdl/sdl-audio.h b/src/platform/sdl/sdl-audio.h index 436b9286a..f857d581e 100644 --- a/src/platform/sdl/sdl-audio.h +++ b/src/platform/sdl/sdl-audio.h @@ -6,10 +6,15 @@ #include struct GBASDLAudio { + // Input + size_t samples; + + // State SDL_AudioSpec desiredSpec; SDL_AudioSpec obtainedSpec; float drift; float ratio; + struct GBAAudio* audio; struct GBAThread* thread; }; diff --git a/src/platform/sdl/sw-main.c b/src/platform/sdl/sw-main.c index c69907c7c..99eed9e79 100644 --- a/src/platform/sdl/sw-main.c +++ b/src/platform/sdl/sw-main.c @@ -79,6 +79,9 @@ int main(int argc, char** argv) { GBAMapOptionsToContext(&opts, &context); + renderer.audio.samples = context.audioBuffers; + GBASDLInitAudio(&renderer.audio); + #if SDL_VERSION_ATLEAST(2, 0, 0) renderer.events.fullscreen = graphicsOpts.fullscreen; renderer.window = SDL_CreateWindow(PROJECT_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderer.viewportWidth, renderer.viewportHeight, SDL_WINDOW_OPENGL | (SDL_WINDOW_FULLSCREEN_DESKTOP * renderer.events.fullscreen)); @@ -145,7 +148,6 @@ static int _GBASDLInit(struct SoftwareRenderer* renderer) { } GBASDLInitEvents(&renderer->events); - GBASDLInitAudio(&renderer->audio); #if !SDL_VERSION_ATLEAST(2, 0, 0) #ifdef COLOR_16_BIT