aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2019-10-15 22:18:05 +0200
committerBastien Bouclet2019-10-20 17:06:33 +0200
commitc71fa02bf5c6a154d4d3a029664769e870d3394f (patch)
tree16165b5e9954e13e8edc87331cc069ba3ada04b8
parent650da9eb5bfa8960a6eea1baa0158465311b0960 (diff)
downloadscummvm-rg350-c71fa02bf5c6a154d4d3a029664769e870d3394f.tar.gz
scummvm-rg350-c71fa02bf5c6a154d4d3a029664769e870d3394f.tar.bz2
scummvm-rg350-c71fa02bf5c6a154d4d3a029664769e870d3394f.zip
3DS: Change the audio thread to wait for the audio buffers to complete
Fixes the regular pop sounds caused by buffer underruns / clobbering of the previous implementation.
-rw-r--r--backends/platform/3ds/osystem-audio.cpp34
1 files changed, 15 insertions, 19 deletions
diff --git a/backends/platform/3ds/osystem-audio.cpp b/backends/platform/3ds/osystem-audio.cpp
index 58262372cc..043aaf1fe2 100644
--- a/backends/platform/3ds/osystem-audio.cpp
+++ b/backends/platform/3ds/osystem-audio.cpp
@@ -31,18 +31,16 @@ static void audioThreadFunc(void *arg) {
Audio::MixerImpl *mixer = (Audio::MixerImpl *)arg;
OSystem_3DS *osys = (OSystem_3DS *)g_system;
- int i;
const int channel = 0;
int bufferIndex = 0;
- const int bufferCount = 3;
- const int bufferSize = 80000; // Can't be too small, based on delayMillis duration
+ const int bufferCount = 2;
const int sampleRate = mixer->getOutputRate();
- int sampleLen = 0;
- uint32 lastTime = osys->getMillis(true);
- uint32 time = lastTime;
+ const int bufferSamples = 1024;
+ const int bufferSize = bufferSamples * 4;
+
ndspWaveBuf buffers[bufferCount];
- for (i = 0; i < bufferCount; ++i) {
+ for (int i = 0; i < bufferCount; ++i) {
memset(&buffers[i], 0, sizeof(ndspWaveBuf));
buffers[i].data_vaddr = linearAlloc(bufferSize);
buffers[i].looping = false;
@@ -55,27 +53,25 @@ static void audioThreadFunc(void *arg) {
ndspChnSetFormat(channel, NDSP_FORMAT_STEREO_PCM16);
while (!osys->exiting) {
- osys->delayMillis(100); // Note: Increasing the delay requires a bigger buffer
-
- time = osys->getMillis(true);
- sampleLen = (time - lastTime) * 22 * 4; // sampleRate / 1000 * channelCount * sizeof(int16);
- lastTime = time;
+ svcSleepThread(5000 * 1000); // Wake up the thread every 5 ms
- if (!osys->sleeping && sampleLen > 0) {
- bufferIndex++;
- bufferIndex %= bufferCount;
- ndspWaveBuf *buf = &buffers[bufferIndex];
+ if (osys->sleeping) continue;
- buf->nsamples = mixer->mixCallback(buf->data_adpcm, sampleLen);
+ ndspWaveBuf *buf = &buffers[bufferIndex];
+ if (buf->status == NDSP_WBUF_FREE || buf->status == NDSP_WBUF_DONE) {
+ buf->nsamples = mixer->mixCallback(buf->data_adpcm, bufferSize);
if (buf->nsamples > 0) {
DSP_FlushDataCache(buf->data_vaddr, bufferSize);
ndspChnWaveBufAdd(channel, buf);
}
+
+ bufferIndex++;
+ bufferIndex %= bufferCount;
}
}
- for (i = 0; i < bufferCount; ++i)
- linearFree(buffers[i].data_pcm8);
+ for (int i = 0; i < bufferCount; ++i)
+ linearFree(buffers[i].data_pcm16);
}
void OSystem_3DS::initAudio() {