Revert to spinlocking for audio sync

This commit is contained in:
wheremyfoodat 2024-02-24 00:24:41 +02:00
parent 426162f709
commit 56f716c1f1
3 changed files with 105 additions and 91 deletions

View file

@ -92,6 +92,14 @@ void MiniAudioDevice::init(Samples& samples, bool safe) {
auto self = reinterpret_cast<MiniAudioDevice*>(device->pUserData);
s16* output = reinterpret_cast<ma_int16*>(out);
// Wait until there's enough samples to pop
while (self->samples->size() < frameCount * channelCount) {
// If audio output is disabled from the emulator thread, make sure that this callback will return and not hang
if (!self->running) {
return;
}
}
self->samples->pop(output, frameCount * channelCount);
};

View file

@ -128,6 +128,11 @@ void TeakraDSP::setAudioEnabled(bool enable) {
// Push our samples at the end of an audio frame
if (audioFrameIndex >= audioFrame.size()) {
audioFrameIndex -= audioFrame.size();
// Wait until we've actually got room to do so
while (sampleBuffer.size() + 2 > sampleBuffer.Capacity()) {
}
sampleBuffer.push(audioFrame.data(), audioFrame.size());
}
});