[Scummvm-git-logs] scummvm master -> c03787f8bb4608f4210f244c3f5c0ea9a8d922af

AndywinXp noreply at scummvm.org
Sun Mar 6 20:58:43 UTC 2022


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
c03787f8bb SCUMM: DiMUSE: Fix possible buffer underruns


Commit: c03787f8bb4608f4210f244c3f5c0ea9a8d922af
    https://github.com/scummvm/scummvm/commit/c03787f8bb4608f4210f244c3f5c0ea9a8d922af
Author: Andrea Boscarino (andywinxp at gmail.com)
Date: 2022-03-06T21:58:40+01:00

Commit Message:
SCUMM: DiMUSE: Fix possible buffer underruns

Big thanks to athrxx for reporting this issue; the previous calculation for obtaining an optimal number for _maxQueuedStreams did not account for the differences between the sample rate targeted by the audio backend and the one targeted by DiMUSE (which is 22050Hz). 

This new formula has been tested for optimal latency and absence of underruns for all supported games and all known combinations of sample rates and output buffer sizes:
[22050, 44100, 48000, 96000], [1024, 2048, 4096, 8192].

Changed paths:
    engines/scumm/imuse_digi/dimuse_engine.cpp


diff --git a/engines/scumm/imuse_digi/dimuse_engine.cpp b/engines/scumm/imuse_digi/dimuse_engine.cpp
index c9244b5f92e..2ba54a7971a 100644
--- a/engines/scumm/imuse_digi/dimuse_engine.cpp
+++ b/engines/scumm/imuse_digi/dimuse_engine.cpp
@@ -103,13 +103,18 @@ IMuseDigital::IMuseDigital(ScummEngine_v7 *scumm, Audio::Mixer *mixer)
 	_filesHandler->allocSoundBuffer(DIMUSE_BUFFER_SMUSH, 198000, 0, 0);
 
 	if (_mixer->getOutputBufSize() != 0) {
-		_maxQueuedStreams = (_mixer->getOutputBufSize() / _waveOutPreferredFeedSize) + 1;
-		// This mixer's optimal output sample rate for this audio engine is 44100
-		// if it's higher than that, compensate the number of queued streams in order
-		// to try to achieve a better latency compromise
-		if (_mixer->getOutputRate() > DIMUSE_SAMPLERATE * 2) {
-			_maxQueuedStreams -= 2;
+		// Let's find the optimal value for the maximum number of streams which can stay in the queue at once;
+		// (A number which is too low can lead to buffer underrun, while the higher the number is, the higher is the audio latency)
+		_maxQueuedStreams = (int)ceil((_mixer->getOutputBufSize() / _waveOutPreferredFeedSize) / ((float)_mixer->getOutputRate() / DIMUSE_SAMPLERATE));
+
+		// This mixer's optimal output sample rate for this audio engine is one which is a multiple of 22050Hz;
+		// if we're dealing with one which is a multiple of 48000Hz, compensate the number of queued streams...
+		if (_mixer->getOutputRate() % DIMUSE_SAMPLERATE) {
+			_maxQueuedStreams++;
 		}
+
+		// The lower optimal bound is always 5, except if we're operating in low latency mode
+		_maxQueuedStreams = MAX(_mixer->getOutputBufSize() <= 1024 ? 4 : 5, _maxQueuedStreams);
 	} else {
 		debug(5, "IMuseDigital::IMuseDigital(): WARNING: output audio buffer size not specified for this platform, defaulting _maxQueuedStreams to 4");
 		_maxQueuedStreams = 4;




More information about the Scummvm-git-logs mailing list