[Scummvm-git-logs] scummvm branch-2-3 -> ae6b03402ef805450a94f97339f1af2422f49fa8

dreammaster dreammaster at scummvm.org
Sat Aug 28 19:24:11 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:
6d0fce154a AGS: Delay starting sound playback until a channel is set
ae6b03402e AGS: Fix volume slider affecting overall volume


Commit: 6d0fce154a2c32b444843d6c4219727982b85636
    https://github.com/scummvm/scummvm/commit/6d0fce154a2c32b444843d6c4219727982b85636
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-08-28T12:22:55-07:00

Commit Message:
AGS: Delay starting sound playback until a channel is set

In AGS, setting the channel for music, sfx, or voice
frequently happens after the call to play has already been done.
This poses a problem for ScummVM, since I need the sound type
directly for the playStream call. And it's not feasible to
refactor everywhere that plays a clip to set the channel first.
With this change, any play call sets a flag, and defers calling
playStream until the channel is set. Hopefully there aren't
any places that call play without setting the channel before/after.

Changed paths:
    engines/ags/engine/ac/global_audio.cpp
    engines/ags/engine/media/audio/audio.cpp
    engines/ags/engine/media/audio/sound_clip.cpp
    engines/ags/engine/media/audio/sound_clip.h


diff --git a/engines/ags/engine/ac/global_audio.cpp b/engines/ags/engine/ac/global_audio.cpp
index 38d9330e8a..df21e65f2f 100644
--- a/engines/ags/engine/ac/global_audio.cpp
+++ b/engines/ags/engine/ac/global_audio.cpp
@@ -543,8 +543,6 @@ static bool play_voice_clip_on_channel(const String &voice_name) {
 		return false;
 	}
 
-	set_clip_to_channel(SCHAN_SPEECH, speechmp3);
-
 	if (!speechmp3->play()) {
 		// Could not play, so clean up manually.
 		speechmp3->destroy();
@@ -552,6 +550,7 @@ static bool play_voice_clip_on_channel(const String &voice_name) {
 		speechmp3 = nullptr;
 	}
 
+	set_clip_to_channel(SCHAN_SPEECH, speechmp3);
 	return true;
 }
 
diff --git a/engines/ags/engine/media/audio/audio.cpp b/engines/ags/engine/media/audio/audio.cpp
index 137c2ce0ef..2a149523ab 100644
--- a/engines/ags/engine/media/audio/audio.cpp
+++ b/engines/ags/engine/media/audio/audio.cpp
@@ -70,13 +70,13 @@ SOUNDCLIP *AudioChannelsLock::SetChannel(int index, SOUNDCLIP *ch) {
 	if (wavClip) {
 		switch (index) {
 		case SCHAN_SPEECH:
-			wavClip->_soundType = Audio::Mixer::kSpeechSoundType;
+			wavClip->setType(Audio::Mixer::kSpeechSoundType);
 			break;
 		case SCHAN_MUSIC:
-			wavClip->_soundType = Audio::Mixer::kMusicSoundType;
+			wavClip->setType(Audio::Mixer::kMusicSoundType);
 			break;
 		default:
-			wavClip->_soundType = Audio::Mixer::kSFXSoundType;
+			wavClip->setType(Audio::Mixer::kSFXSoundType);
 			break;
 		}
 	}
diff --git a/engines/ags/engine/media/audio/sound_clip.cpp b/engines/ags/engine/media/audio/sound_clip.cpp
index ee6a0bad0f..9da1ae2782 100644
--- a/engines/ags/engine/media/audio/sound_clip.cpp
+++ b/engines/ags/engine/media/audio/sound_clip.cpp
@@ -61,25 +61,35 @@ void SoundClipWaveBase::poll() {
 }
 
 int SoundClipWaveBase::play() {
-	_mixer->playStream(_soundType, &_soundHandle, _stream,
-	                   -1, _vol, 0, DisposeAfterUse::NO);
+	if (_soundType != Audio::Mixer::kPlainSoundType) {
+		_mixer->playStream(_soundType, &_soundHandle, _stream,
+			-1, _vol, 0, DisposeAfterUse::NO);
+	} else {
+		_waitingToPlay = true;
+	}
+
 	return 1;
 }
 
-int SoundClipWaveBase::play_from(int position) {
-	if (position == 0) {
-		play();
-		return 1;
-	} else {
-		// TODO: Implement playing from arbitrary positions. This is
-		// used when restoring savegames to resume the music at the
-		// point the savegame was made. For now, since ScummVM doesn't
-		// have seek for audio streams, we'll restart from the beginning
+void SoundClipWaveBase::setType(Audio::Mixer::SoundType type) {
+	assert(type != Audio::Mixer::kPlainSoundType);
+	_soundType = type;
+
+	if (_waitingToPlay) {
+		_waitingToPlay = false;
+
 		play();
-		return 1;
 	}
 }
 
+int SoundClipWaveBase::play_from(int position) {
+	if (position != 0)
+		seek(position);
+
+	play();
+	return 1;
+}
+
 void SoundClipWaveBase::pause() {
 	_mixer->pauseHandle(_soundHandle, false);
 	_state = SoundClipPaused;
diff --git a/engines/ags/engine/media/audio/sound_clip.h b/engines/ags/engine/media/audio/sound_clip.h
index d0bd8af0ef..d9b4be043f 100644
--- a/engines/ags/engine/media/audio/sound_clip.h
+++ b/engines/ags/engine/media/audio/sound_clip.h
@@ -163,17 +163,22 @@ protected:
 };
 
 struct SoundClipWaveBase : public SOUNDCLIP {
+private:
+	Audio::Mixer::SoundType _soundType = Audio::Mixer::kPlainSoundType;
+public:
 	Audio::Mixer *_mixer;
 	Audio::AudioStream *_stream;
 	Audio::SoundHandle _soundHandle;
 	SoundClipState _state;
-	Audio::Mixer::SoundType _soundType = Audio::Mixer::kPlainSoundType;
+	bool _waitingToPlay = false;
 
 	SoundClipWaveBase(Audio::AudioStream *stream, int volume, bool repeat = false);
 	~SoundClipWaveBase() override {
 		destroy();
 	}
 
+	void setType(Audio::Mixer::SoundType type);
+
 	void destroy() override;
 	void poll() override;
 	int play() override;


Commit: ae6b03402ef805450a94f97339f1af2422f49fa8
    https://github.com/scummvm/scummvm/commit/ae6b03402ef805450a94f97339f1af2422f49fa8
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-08-28T12:23:08-07:00

Commit Message:
AGS: Fix volume slider affecting overall volume

Changed paths:
    engines/ags/engine/ac/system.cpp


diff --git a/engines/ags/engine/ac/system.cpp b/engines/ags/engine/ac/system.cpp
index 8c62d528ea..eb119265fe 100644
--- a/engines/ags/engine/ac/system.cpp
+++ b/engines/ags/engine/ac/system.cpp
@@ -20,6 +20,7 @@
  *
  */
 
+#include "common/config-manager.h"
 #include "ags/shared/ac/common.h"
 #include "ags/engine/ac/draw.h"
 #include "ags/engine/ac/dynobj/cc_audio_channel.h"
@@ -45,6 +46,7 @@
 #include "ags/engine/script/script_api.h"
 #include "ags/engine/script/script_runtime.h"
 #include "ags/engine/ac/dynobj/script_string.h"
+#include "ags/ags.h"
 #include "ags/globals.h"
 #include "ags/events.h"
 
@@ -180,10 +182,14 @@ void System_SetVolume(int newvol) {
 		quit("!System.Volume: invalid volume - must be from 0-100");
 
 	_GP(play).digital_master_volume = newvol;
-#if !AGS_PLATFORM_SCUMMVM
-	auto newvol_f = static_cast<float>(newvol) / 100.0;
-	audio_core_set_master_volume(newvol_f);
-#endif
+
+	Audio::Mixer *mixer = ::AGS::g_vm->_mixer;
+	double percent = (double)newvol / 100.0;
+	int musicVol = static_cast<int>((double)ConfMan.getInt("music_volume") * percent);
+	int sfxVol = static_cast<int>((double)ConfMan.getInt("sfx_volume") * percent);
+
+	mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, musicVol);
+	mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, sfxVol);
 }
 
 const char *System_GetRuntimeInfo() {




More information about the Scummvm-git-logs mailing list