all repos — mgba @ 0e379fed418585dc77cb3ade5cbeb2a71402fb15

mGBA Game Boy Advance Emulator

Fix audio buffer reading in SDL audio
Jeffrey Pfau jeffrey@endrift.com
Thu, 23 Jan 2014 20:55:32 -0800
commit

0e379fed418585dc77cb3ade5cbeb2a71402fb15

parent

709269ee5c2791ee37a41cb02ced2606002eb31e

1 files changed, 7 insertions(+), 10 deletions(-)

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

@@ -3,6 +3,8 @@

#include "gba.h" #include "gba-thread.h" +#include <math.h> + #define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2) #define FPS_TARGET 60.f

@@ -48,9 +50,9 @@ int32_t right[BUFFER_SIZE];

// toRead is in GBA samples // TODO: Do this with fixed-point math - int toRead = samples / context->ratio; + unsigned toRead = ceilf(samples / context->ratio); while (samples > 0) { - int currentRead = BUFFER_SIZE >> 1; + unsigned currentRead = BUFFER_SIZE >> 2; if (currentRead > toRead) { currentRead = toRead; }

@@ -70,14 +72,9 @@ return;

} } } - if (read < BUFFER_SIZE >> 2) { - if (samples > 1) { - memset(output, 0, samples * sizeof(struct StereoSample)); - return; - } else { - // Account for lost sample due to floating point conversion - toRead = 1; - } + if (read < currentRead) { + memset(output, 0, samples * sizeof(struct StereoSample)); + return; } } }