all repos — mgba @ c8cc2eba2e24129f74205d06a5038d18d03cfaa9

mGBA Game Boy Advance Emulator

Switch: Fix audio when video rate desyncs (fixes #1532)
Vicki Pfau vi@endrift.com
Mon, 30 Sep 2019 18:18:56 -0700
commit

c8cc2eba2e24129f74205d06a5038d18d03cfaa9

parent

6bbf5755c63f49d974b31951c5609b42c7ae0492

1 files changed, 9 insertions(+), 2 deletions(-)

jump to
M src/platform/switch/main.csrc/platform/switch/main.c

@@ -20,7 +20,7 @@ #include <GLES3/gl3.h>

#include <GLES3/gl31.h> #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 @@ unsigned mode;

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 @@ }

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 @@ for (i = 0; i < N_BUFFERS; ++i) {

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; }