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

aquadran noreply at scummvm.org
Thu Dec 9 21:03:44 UTC 2021


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

Summary:
f37489dd80 AUDIO/BACKENDS: Store output audio buffer size in Mixer
c9e5ff7e9e SCUMM: DiMUSE: Fix bug #13080


Commit: f37489dd80b454c3da47fe96b92ab124f32da0dc
    https://github.com/scummvm/scummvm/commit/f37489dd80b454c3da47fe96b92ab124f32da0dc
Author: Andrea Boscarino (andywinxp at gmail.com)
Date: 2021-12-09T22:03:40+01:00

Commit Message:
AUDIO/BACKENDS: Store output audio buffer size in Mixer

Changed paths:
    audio/mixer.cpp
    audio/mixer.h
    audio/mixer_intern.h
    backends/mixer/null/null-mixer.cpp
    backends/mixer/sdl/sdl-mixer.cpp
    backends/platform/android/android.cpp
    backends/platform/android3d/android.cpp
    backends/platform/ios7/ios7_osys_sound.cpp
    backends/platform/iphone/osys_sound.cpp


diff --git a/audio/mixer.cpp b/audio/mixer.cpp
index e3d0a309df..1a3b32120a 100644
--- a/audio/mixer.cpp
+++ b/audio/mixer.cpp
@@ -177,10 +177,11 @@ private:
 #pragma mark --- Mixer ---
 #pragma mark -
 
-MixerImpl::MixerImpl(uint sampleRate)
-	: _mutex(), _sampleRate(sampleRate), _mixerReady(false), _handleSeed(0), _soundTypeSettings() {
+MixerImpl::MixerImpl(uint sampleRate, uint outBufSize)
+	: _mutex(), _sampleRate(sampleRate), _outBufSize(outBufSize), _mixerReady(false), _handleSeed(0), _soundTypeSettings() {
 
 	assert(sampleRate > 0);
+	assert(outBufSize >= 0);
 
 	for (int i = 0; i != NUM_CHANNELS; i++)
 		_channels[i] = nullptr;
@@ -201,6 +202,10 @@ uint MixerImpl::getOutputRate() const {
 	return _sampleRate;
 }
 
+uint MixerImpl::getOutputBufSize() const {
+	return _outBufSize;
+}
+
 void MixerImpl::insertChannel(SoundHandle *handle, Channel *chan) {
 	int index = -1;
 	for (int i = 0; i != NUM_CHANNELS; i++) {
diff --git a/audio/mixer.h b/audio/mixer.h
index 10ccd6181b..d504960124 100644
--- a/audio/mixer.h
+++ b/audio/mixer.h
@@ -305,6 +305,13 @@ public:
 	 * @return The output sample rate in Hz.
 	 */
 	virtual uint getOutputRate() const = 0;
+
+	/**
+	 * Return the output sample buffer size of the system.
+	 *
+	 * @return The number of samples processed at each audio callback.
+	 */
+	virtual uint getOutputBufSize() const = 0;
 };
 
 /** @} */
diff --git a/audio/mixer_intern.h b/audio/mixer_intern.h
index 9856d93ee7..4c5d121548 100644
--- a/audio/mixer_intern.h
+++ b/audio/mixer_intern.h
@@ -65,6 +65,7 @@ private:
 	Common::Mutex _mutex;
 
 	const uint _sampleRate;
+	const uint _outBufSize;
 	bool _mixerReady;
 	uint32 _handleSeed;
 
@@ -81,7 +82,7 @@ private:
 
 public:
 
-	MixerImpl(uint sampleRate);
+	MixerImpl(uint sampleRate, uint outBufSize = 0);
 	~MixerImpl();
 
 	virtual bool isReady() const { Common::StackLock lock(_mutex); return _mixerReady; }
@@ -129,6 +130,7 @@ public:
 	virtual int getVolumeForSoundType(SoundType type) const;
 
 	virtual uint getOutputRate() const;
+	virtual uint getOutputBufSize() const;
 
 protected:
 	void insertChannel(SoundHandle *handle, Channel *chan);
diff --git a/backends/mixer/null/null-mixer.cpp b/backends/mixer/null/null-mixer.cpp
index 821ff7d678..561ca1d242 100644
--- a/backends/mixer/null/null-mixer.cpp
+++ b/backends/mixer/null/null-mixer.cpp
@@ -37,7 +37,7 @@ NullMixerManager::~NullMixerManager() {
 }
 
 void NullMixerManager::init() {
-	_mixer = new Audio::MixerImpl(_outputRate);
+	_mixer = new Audio::MixerImpl(_outputRate, _samples);
 	assert(_mixer);
 	_mixer->setReady(true);
 }
diff --git a/backends/mixer/sdl/sdl-mixer.cpp b/backends/mixer/sdl/sdl-mixer.cpp
index c56edaa26e..e08947d759 100644
--- a/backends/mixer/sdl/sdl-mixer.cpp
+++ b/backends/mixer/sdl/sdl-mixer.cpp
@@ -74,7 +74,7 @@ void SdlMixerManager::init() {
 		warning("Could not open audio device: %s", SDL_GetError());
 
 		// The mixer is not marked as ready
-		_mixer = new Audio::MixerImpl(desired.freq);
+		_mixer = new Audio::MixerImpl(desired.freq, desired.samples);
 		return;
 	}
 
@@ -89,7 +89,7 @@ void SdlMixerManager::init() {
 			warning("Could not open audio device: %s", SDL_GetError());
 
 			// The mixer is not marked as ready
-			_mixer = new Audio::MixerImpl(desired.freq);
+			_mixer = new Audio::MixerImpl(desired.freq, desired.samples);
 			return;
 		}
 
@@ -111,7 +111,7 @@ void SdlMixerManager::init() {
 		error("SDL mixer output requires stereo output device");
 #endif
 
-	_mixer = new Audio::MixerImpl(_obtained.freq);
+	_mixer = new Audio::MixerImpl(_obtained.freq, desired.samples);
 	assert(_mixer);
 	_mixer->setReady(true);
 
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index 954527543f..249cc39052 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -464,7 +464,7 @@ void OSystem_Android::initBackend() {
 
 	gettimeofday(&_startTime, 0);
 
-	_mixer = new Audio::MixerImpl(_audio_sample_rate);
+	_mixer = new Audio::MixerImpl(_audio_sample_rate, _audio_buffer_size);
 	_mixer->setReady(true);
 
 	_timer_thread_exit = false;
diff --git a/backends/platform/android3d/android.cpp b/backends/platform/android3d/android.cpp
index d8a270b2f4..53ee9f8f18 100644
--- a/backends/platform/android3d/android.cpp
+++ b/backends/platform/android3d/android.cpp
@@ -368,7 +368,7 @@ void OSystem_Android::initBackend() {
 
 	gettimeofday(&_startTime, 0);
 
-	_mixer = new Audio::MixerImpl(_audio_sample_rate);
+	_mixer = new Audio::MixerImpl(_audio_sample_rate, _audio_buffer_size);
 	_mixer->setReady(true);
 
 	_timer_thread_exit = false;
diff --git a/backends/platform/ios7/ios7_osys_sound.cpp b/backends/platform/ios7/ios7_osys_sound.cpp
index fdbb1f2ecb..fa38c5ab7b 100644
--- a/backends/platform/ios7/ios7_osys_sound.cpp
+++ b/backends/platform/ios7/ios7_osys_sound.cpp
@@ -46,7 +46,7 @@ void OSystem_iOS7::mixCallback(void *sys, byte *samples, int len) {
 }
 
 void OSystem_iOS7::setupMixer() {
-	_mixer = new Audio::MixerImpl(AUDIO_SAMPLE_RATE);
+	_mixer = new Audio::MixerImpl(AUDIO_SAMPLE_RATE, WAVE_BUFFER_SIZE);
 
 	s_soundCallback = mixCallback;
 	s_soundParam = this;
diff --git a/backends/platform/iphone/osys_sound.cpp b/backends/platform/iphone/osys_sound.cpp
index 533487503e..8a9539987a 100644
--- a/backends/platform/iphone/osys_sound.cpp
+++ b/backends/platform/iphone/osys_sound.cpp
@@ -46,7 +46,7 @@ void OSystem_IPHONE::mixCallback(void *sys, byte *samples, int len) {
 }
 
 void OSystem_IPHONE::setupMixer() {
-	_mixer = new Audio::MixerImpl(AUDIO_SAMPLE_RATE);
+	_mixer = new Audio::MixerImpl(AUDIO_SAMPLE_RATE, WAVE_BUFFER_SIZE);
 
 	s_soundCallback = mixCallback;
 	s_soundParam = this;


Commit: c9e5ff7e9e3b952f9ebad11d5cdab15d38db8ab5
    https://github.com/scummvm/scummvm/commit/c9e5ff7e9e3b952f9ebad11d5cdab15d38db8ab5
Author: Andrea Boscarino (andywinxp at gmail.com)
Date: 2021-12-09T22:03:40+01:00

Commit Message:
SCUMM: DiMUSE: Fix bug #13080

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


diff --git a/engines/scumm/imuse_digi/dimuse_engine.cpp b/engines/scumm/imuse_digi/dimuse_engine.cpp
index 5492fbbbb1..ece52bc925 100644
--- a/engines/scumm/imuse_digi/dimuse_engine.cpp
+++ b/engines/scumm/imuse_digi/dimuse_engine.cpp
@@ -103,6 +103,19 @@ 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;
+		}
+	} else {
+		debug(5, "IMuseDigital::IMuseDigital(): WARNING: output audio buffer size not specified for this platform, defaulting _maxQueuedStreams to 4");
+		_maxQueuedStreams = 4;
+	}
+
 	_vm->getTimerManager()->installTimerProc(timer_handler, 1000000 / _callbackFps, this, "IMuseDigital");
 }
 
diff --git a/engines/scumm/imuse_digi/dimuse_engine.h b/engines/scumm/imuse_digi/dimuse_engine.h
index ccb7926d04..786ee56ad7 100644
--- a/engines/scumm/imuse_digi/dimuse_engine.h
+++ b/engines/scumm/imuse_digi/dimuse_engine.h
@@ -86,6 +86,8 @@ private:
 	int _outputFeedSize;
 	int _outputSampleRate;
 
+	int _maxQueuedStreams; // maximum number of streams which can be queued before they are played
+
 	int _currentSpeechVolume, _currentSpeechFrequency, _currentSpeechPan;
 	int _curMixerMusicVolume, _curMixerSpeechVolume, _curMixerSFXVolume;
 	bool _radioChatterSFX;
diff --git a/engines/scumm/imuse_digi/dimuse_tracks.cpp b/engines/scumm/imuse_digi/dimuse_tracks.cpp
index e0e7b5481b..01517b5bdb 100644
--- a/engines/scumm/imuse_digi/dimuse_tracks.cpp
+++ b/engines/scumm/imuse_digi/dimuse_tracks.cpp
@@ -155,7 +155,7 @@ void IMuseDigital::tracksCallback() {
 
 	// If we leave the number of queued streams unbounded, we fill the queue with streams faster than
 	// we can play them: this leads to a very noticeable audio latency and desync with the graphics.
-	if (_internalMixer->_stream->numQueuedStreams() < 3) {
+	if (_internalMixer->_stream->numQueuedStreams() < _maxQueuedStreams) {
 		if (!_isEarlyDiMUSE)
 			dispatchPredictFirstStream();
 




More information about the Scummvm-git-logs mailing list