Fix audio buffer reading in SDL audio

This commit is contained in:
Jeffrey Pfau 2014-01-23 20:55:32 -08:00
parent 709269ee5c
commit 0e379fed41
1 changed files with 7 additions and 10 deletions

View File

@ -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 @@ static void _pulldownResample(struct GBASDLAudio* context, struct StereoSample*
// 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 @@ static void _pulldownResample(struct GBASDLAudio* context, struct StereoSample*
}
}
}
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;
}
}
}