From c8cc2eba2e24129f74205d06a5038d18d03cfaa9 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 30 Sep 2019 18:18:56 -0700 Subject: [PATCH] Switch: Fix audio when video rate desyncs (fixes #1532) --- src/platform/switch/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/platform/switch/main.c b/src/platform/switch/main.c index f87caf667..45560cab4 100644 --- a/src/platform/switch/main.c +++ b/src/platform/switch/main.c @@ -20,7 +20,7 @@ #include #define AUTO_INPUT 0x4E585031 -#define SAMPLES 0x400 +#define SAMPLES 0x200 #define BUFFER_SIZE 0x1000 #define N_BUFFERS 4 #define ANALOG_DEADZONE 0x4000 @@ -281,6 +281,8 @@ static void _setup(struct mGUIRunner* runner) { if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode < SM_MAX) { screenMode = mode; } + + runner->core->setAudioBufferSize(runner->core, SAMPLES); } static void _gameLoaded(struct mGUIRunner* runner) { @@ -539,6 +541,11 @@ static void _postAudioBuffer(struct mAVStream* stream, blip_t* left, blip_t* rig if (enqueuedBuffers >= N_BUFFERS - 1 && R_SUCCEEDED(audoutWaitPlayFinish(&releasedBuffers, &audoutNReleasedBuffers, 10000000))) { enqueuedBuffers -= audoutNReleasedBuffers; } + if (enqueuedBuffers >= N_BUFFERS) { + blip_clear(left); + blip_clear(right); + return; + } struct GBAStereoSample* samples = audioBuffer[audioBufferActive]; blip_read_samples(left, &samples[0].left, SAMPLES, true); @@ -754,7 +761,7 @@ int main(int argc, char* argv[]) { audoutBuffer[i].next = NULL; audoutBuffer[i].buffer = audioBuffer[i]; audoutBuffer[i].buffer_size = BUFFER_SIZE; - audoutBuffer[i].data_size = BUFFER_SIZE; + audoutBuffer[i].data_size = SAMPLES * 4; audoutBuffer[i].data_offset = 0; }