[Scummvm-git-logs] scummvm master -> 8b174bfed608b0f9a66264e6b06d8e7003663da4

NMIError noreply at scummvm.org
Sat Jul 2 20:13:51 UTC 2022


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:
861b8c3555 CHEWY: Fix sound settings
8b174bfed6 CHEWY: Fix sound volume and panning


Commit: 861b8c355549124cc1600def3a5665f099b29cb0
    https://github.com/scummvm/scummvm/commit/861b8c355549124cc1600def3a5665f099b29cb0
Author: Coen Rampen (crampen at gmail.com)
Date: 2022-07-02T22:13:41+02:00

Commit Message:
CHEWY: Fix sound settings

This fixes the in-game options screen and synchronizes the sound settings there
with the ScummVM options screen settings.

Changed paths:
    engines/chewy/chewy.cpp
    engines/chewy/chewy.h
    engines/chewy/dialogs/options.cpp
    engines/chewy/sound.cpp
    engines/chewy/sound.h


diff --git a/engines/chewy/chewy.cpp b/engines/chewy/chewy.cpp
index 1181eaa2242..89bc197e8ad 100644
--- a/engines/chewy/chewy.cpp
+++ b/engines/chewy/chewy.cpp
@@ -92,6 +92,12 @@ Common::Error ChewyEngine::run() {
 
 #define SCUMMVM_TAG MKTAG('S', 'C', 'V', 'M')
 
+void ChewyEngine::syncSoundSettings() {
+	_sound->syncSoundSettings();
+
+	Engine::syncSoundSettings();
+}
+
 Common::Error ChewyEngine::loadGameStream(Common::SeekableReadStream *stream) {
 	exit_room(-1);
 
diff --git a/engines/chewy/chewy.h b/engines/chewy/chewy.h
index 1a94a2a6b95..6c0741512f6 100644
--- a/engines/chewy/chewy.h
+++ b/engines/chewy/chewy.h
@@ -93,6 +93,8 @@ public:
 		_canSave = canLoadSave;
 	}
 
+	void syncSoundSettings() override;
+
 	/**
 	 * Load savegame data
 	 */
diff --git a/engines/chewy/dialogs/options.cpp b/engines/chewy/dialogs/options.cpp
index 5f73b116e52..e895f2ff884 100644
--- a/engines/chewy/dialogs/options.cpp
+++ b/engines/chewy/dialogs/options.cpp
@@ -26,6 +26,8 @@
 #include "chewy/mcga_graphics.h"
 #include "chewy/sound.h"
 
+#include "common/config-manager.h"
+
 namespace Chewy {
 namespace Dialogs {
 
@@ -37,7 +39,7 @@ namespace Dialogs {
 #define MUND_END 11
 #define SCHNULL_OFF 23
 #define TDISP_START 12
-#define TDISP_END 19
+#define TDISP_END 13
 #define TDISP_EIN 20
 #define TDISP_AUS 21
 #define MUSIC_OFF 24
@@ -60,9 +62,6 @@ void Options::execute(TafInfo *ti) {
 	int16 mund_ani = MUND_START;
 	int16 mund_delay = 3;
 	int16 mund_count = mund_delay;
-	int16 tdisp_ani = TDISP_START;
-	int16 tdisp_delay = 3;
-	int16 tdisp_count = tdisp_delay;
 	_G(FrameSpeed) = 0;
 	int16 delay_count = _G(gameState).DelaySpeed;
 	//warning("stop_clock = (clock() / CLK_TCK) + 1;");
@@ -85,7 +84,7 @@ void Options::execute(TafInfo *ti) {
 		Common::String fps = Common::String::format("%d", _G(gameState).FramesPerSecond << 1);
 		_G(out)->printxy(36 + bar_off, 65, 255, 300, 0, fps.c_str());
 
-		if (g_engine->_sound->soundEnabled()) {
+		if (g_engine->_sound->speechEnabled()) {
 			_G(out)->spriteSet(ti->image[mund_ani],
 				18 + ti->correction[mund_ani << 1],
 				8 + ti->correction[(mund_ani << 1) + 1], 0);
@@ -101,15 +100,15 @@ void Options::execute(TafInfo *ti) {
 				8 + ti->correction[(SCHNULL_BAND << 1) + 1], 0);
 		}
 
-		const int soundVolume = g_engine->_sound->getSoundVolume() * Audio::Mixer::kMaxChannelVolume / 120;
+		const int soundVolume = MAX(1, g_engine->_sound->getSoundVolume() * 32 / Audio::Mixer::kMaxMixerVolume);
 		_G(out)->pop_box(32 - 2, 104 - 12, 42 + 4, 136 + 2, 192, 183, 182);
 		_G(out)->printxy(32 + 3, 104 - 10, 15, 300, 0, "S");
-		_G(out)->boxFill(33, 136 - (soundVolume >> 1), 42, 136, 15);
+		_G(out)->boxFill(33, 136 - soundVolume, 42, 136, 15);
 
-		const int musicVolume = g_engine->_sound->getSoundVolume() * Audio::Mixer::kMaxChannelVolume / 120;
+		const int musicVolume = MAX(1, g_engine->_sound->getMusicVolume() * 32 / Audio::Mixer::kMaxMixerVolume);
 		_G(out)->pop_box(52 - 2, 104 - 12, 62 + 4, 136 + 2, 192, 183, 182);
 		_G(out)->printxy(52 + 3, 104 - 10, 31, 300, 0, "M");
-		_G(out)->boxFill(53, 136 - (musicVolume >> 1), 62, 136, 31);
+		_G(out)->boxFill(53, 136 - musicVolume, 62, 136, 31);
 
 		if (g_engine->_sound->musicEnabled()) {
 			_G(out)->spriteSet(ti->image[MUSIC_ON1],
@@ -123,17 +122,21 @@ void Options::execute(TafInfo *ti) {
 				18 + ti->correction[MUSIC_OFF << 1],
 				8 + ti->correction[(MUSIC_OFF << 1) + 1], 0);
 
-		if (g_engine->_sound->subtitlesEnabled()) {
-			_G(out)->spriteSet(ti->image[tdisp_ani],
-				18 + ti->correction[tdisp_ani << 1],
-				8 + ti->correction[(tdisp_ani << 1) + 1], 0);
+		if (g_engine->_sound->soundEnabled()) {
+			_G(out)->spriteSet(ti->image[TDISP_START],
+				ti->correction[TDISP_START << 1],
+				ti->correction[(TDISP_START << 1) + 1], 0);
 			_G(out)->spriteSet(ti->image[TDISP_EIN],
 				18 + ti->correction[TDISP_EIN << 1],
 				8 + ti->correction[(TDISP_EIN << 1) + 1], 0);
-		} else
+		} else {
+			_G(out)->spriteSet(ti->image[TDISP_END],
+				ti->correction[TDISP_END << 1],
+				ti->correction[(TDISP_END << 1) + 1], 0);
 			_G(out)->spriteSet(ti->image[TDISP_AUS],
 				18 + ti->correction[TDISP_AUS << 1],
 				8 + ti->correction[(TDISP_AUS << 1) + 1], 0);
+		}
 
 		_G(out)->spriteSet(ti->image[EXIT],
 			18 + ti->correction[EXIT << 1],
@@ -141,19 +144,32 @@ void Options::execute(TafInfo *ti) {
 
 		key = _G(in)->getSwitchCode();
 		if ((_G(minfo).button == 1) || (key == Common::KEYCODE_RETURN)) {
-			WAIT_TASTE_LOS
+			// TODO This line breaks screen updates. Not sure what it does
+			// otherwise; options screen seems to work without it.
+			//WAIT_TASTE_LOS
 
 			int16 rect = _G(in)->findHotspot(_G(optionHotspots));
 			switch (rect) {
-			case 0:
+			case 0: // Hamster wheel arrow left (speed down)
 				if (_G(gameState).FramesPerSecond > 6)
 					--_G(gameState).FramesPerSecond;
 				break;
-			case 1:
+			case 1: // Hamster wheel arrow right (speed up)
 				if (_G(gameState).FramesPerSecond < 10)
 					++_G(gameState).FramesPerSecond;
 				break;
-			case 2:
+			case 2: // Mouth (speech/subtitles)
+				if (!g_engine->_sound->speechEnabled()) {
+					g_engine->_sound->toggleSubtitles(false);
+					g_engine->_sound->toggleSpeech(true);
+				} else {
+					g_engine->_sound->toggleSubtitles(true);
+					g_engine->_sound->toggleSpeech(false);
+				}
+				g_engine->syncSoundSettings();
+				break;
+			case 3:
+			case 4: // Speaker (sound)
 				if (g_engine->_sound->soundEnabled()) {
 					g_engine->_sound->toggleSound(false);
 					_G(det)->disable_room_sound();
@@ -161,18 +177,9 @@ void Options::execute(TafInfo *ti) {
 					g_engine->_sound->toggleSound(true);
 					_G(det)->enable_room_sound();
 				}
+				g_engine->syncSoundSettings();
 				break;
-			case 3:
-			case 4:
-				if (g_engine->_sound->subtitlesEnabled()) {
-					g_engine->_sound->toggleSubtitles(false);
-					g_engine->_sound->toggleSpeech(true);
-				} else {
-					g_engine->_sound->toggleSubtitles(true);
-					g_engine->_sound->toggleSpeech(false);
-				}
-				break;
-			case 5:
+			case 5: // Guitarist (music)
 				if (g_engine->_sound->musicEnabled()) {
 					g_engine->_sound->toggleMusic(false);
 					g_engine->_sound->stopMusic();
@@ -180,15 +187,18 @@ void Options::execute(TafInfo *ti) {
 					g_engine->_sound->toggleMusic(true);
 					g_engine->_sound->playRoomMusic(_G(gameState)._personRoomNr[P_CHEWY]);
 				}
+				g_engine->syncSoundSettings();
 				break;
-			case 6:
+			case 6: // Door (exit)
 				key = Common::KEYCODE_ESCAPE;
 				break;
-			case 7:
-				g_engine->_sound->setSoundVolume(((136 - g_events->_mousePos.y) << 1) * Audio::Mixer::kMaxChannelVolume / 120);
+			case 7: // S volume gauge
+				g_engine->_sound->setSoundVolume(MIN(32, 136 - g_events->_mousePos.y) * Audio::Mixer::kMaxMixerVolume / 32);
+				g_engine->syncSoundSettings();
 				break;
-			case 8:
-				g_engine->_sound->setMusicVolume(((136 - g_events->_mousePos.y) << 1) * Audio::Mixer::kMaxChannelVolume / 120);
+			case 8: // M volume gauge
+				g_engine->_sound->setMusicVolume(MIN(32, 136 - g_events->_mousePos.y) * Audio::Mixer::kMaxMixerVolume / 32);
+				g_engine->syncSoundSettings();
 				break;
 
 			default:
@@ -237,15 +247,6 @@ void Options::execute(TafInfo *ti) {
 					mund_ani = MUND_START;
 				mund_count = mund_delay;
 			}
-			if (tdisp_count > 0)
-				--tdisp_count;
-			else {
-				if (tdisp_ani < TDISP_END)
-					++tdisp_ani;
-				else
-					tdisp_ani = TDISP_START;
-				tdisp_count = tdisp_delay;
-			}
 			delay_count = _G(gameState).DelaySpeed;
 		} else
 			--delay_count;
diff --git a/engines/chewy/sound.cpp b/engines/chewy/sound.cpp
index c2c3da0262b..f2cd37cca8d 100644
--- a/engines/chewy/sound.cpp
+++ b/engines/chewy/sound.cpp
@@ -95,25 +95,26 @@ bool Sound::isSoundActive(uint channel) const {
 }
 
 void Sound::setSoundVolume(uint volume) {
-	_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, volume);
-	_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, volume);
+	_userSoundVolume = volume;
+	if (soundEnabled())
+		ConfMan.setInt("sfx_volume", volume);
 }
 
 int Sound::getSoundVolume() const {
-	return _mixer->getVolumeForSoundType(Audio::Mixer::kSFXSoundType);
+	return _userSoundVolume;
 }
 
 void Sound::pushVolume() {
-	_soundVolume = _mixer->getVolumeForSoundType(Audio::Mixer::kSFXSoundType);
+	/* _soundVolume = _mixer->getVolumeForSoundType(Audio::Mixer::kSFXSoundType);
 	_speechVolume = _mixer->getVolumeForSoundType(Audio::Mixer::kSpeechSoundType);
-	_musicVolume = _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType);
+	_musicVolume = _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType);*/
 }
 
 void Sound::popVolume() {
-	assert(_soundVolume >= 0 && _speechVolume >= 0 && _musicVolume >= 0);
+	/* assert(_soundVolume >= 0 && _speechVolume >= 0 && _musicVolume >= 0);
 	_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, _soundVolume);
 	_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, _speechVolume);
-	_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, _musicVolume);
+	_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, _musicVolume);*/
 }
 
 void Sound::setSoundChannelVolume(uint channel, uint volume) {
@@ -162,11 +163,13 @@ bool Sound::isMusicActive() const {
 }
 
 void Sound::setMusicVolume(uint volume) {
-	_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
+	_userMusicVolume = volume;
+	if (musicEnabled())
+		ConfMan.setInt("music_volume", volume);
 }
 
 int Sound::getMusicVolume() const {
-	return _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType);
+	return _userMusicVolume;
 }
 
 void Sound::playSpeech(int num, bool waitForFinish) {
@@ -227,19 +230,19 @@ void Sound::waitForSpeechToFinish() {
 }
 
 bool Sound::soundEnabled() const {
-	return !ConfMan.getBool("sfx_mute");
+	return ConfMan.getInt("sfx_volume") > 0;
 }
 
 void Sound::toggleSound(bool enable) {
-	return ConfMan.setBool("sfx_mute", !enable);
+	ConfMan.setInt("sfx_volume", enable ? _userSoundVolume : 0);
 }
 
 bool Sound::musicEnabled() const {
-	return !ConfMan.getBool("music_mute");
+	return ConfMan.getInt("music_volume") > 0;
 }
 
 void Sound::toggleMusic(bool enable) {
-	return ConfMan.setBool("music_mute", !enable);
+	ConfMan.setInt("music_volume", enable ? _userSoundVolume : 0);
 }
 
 bool Sound::speechEnabled() const {
@@ -247,7 +250,7 @@ bool Sound::speechEnabled() const {
 }
 
 void Sound::toggleSpeech(bool enable) {
-	return ConfMan.setBool("speech_mute", !enable);
+	ConfMan.setBool("speech_mute", !enable);
 }
 
 bool Sound::subtitlesEnabled() const {
@@ -255,7 +258,31 @@ bool Sound::subtitlesEnabled() const {
 }
 
 void Sound::toggleSubtitles(bool enable) {
-	return ConfMan.setBool("subtitles", enable);
+	ConfMan.setBool("subtitles", enable);
+}
+
+void Sound::syncSoundSettings() {
+	int confSoundVolume = ConfMan.getInt("sfx_volume");
+	int confMusicVolume = ConfMan.getInt("music_volume");
+
+	if (confSoundVolume == 0) {
+		// Sound is muted.
+		if (_userSoundVolume == 0)
+			// Set a default value.
+			_userSoundVolume = 192;
+		// Otherwise leave _soundVolume at the last value set by the user.
+	} else {
+		_userSoundVolume = confSoundVolume;
+	}
+	if (confMusicVolume == 0) {
+		// Music is muted.
+		if (_userMusicVolume == 0)
+			// Set a default value.
+			_userMusicVolume = 192;
+		// Otherwise leave _musicVolume at the last value set by the user.
+	} else {
+		_userMusicVolume = confMusicVolume;
+	}
 }
 
 struct RoomMusic {
diff --git a/engines/chewy/sound.h b/engines/chewy/sound.h
index e20be085fbb..b2862e35b84 100644
--- a/engines/chewy/sound.h
+++ b/engines/chewy/sound.h
@@ -92,13 +92,16 @@ public:
 	bool subtitlesEnabled() const;
 	void toggleSubtitles(bool enable);
 
+	void syncSoundSettings();
+
 private:
 	Audio::Mixer *_mixer;
 	Audio::SoundHandle _soundHandle[MAX_SOUND_EFFECTS];
 	Audio::SoundHandle _musicHandle;
 	Audio::SoundHandle _speechHandle;
 	int16 _curMusic = -1;
-	int _soundVolume = -1, _speechVolume = -1, _musicVolume = -1;
+	// Volume settings in the in-game options screen.
+	int _userSoundVolume = -1, _userMusicVolume = -1;
 
 	SoundResource *_speechRes;
 	SoundResource *_soundRes;


Commit: 8b174bfed608b0f9a66264e6b06d8e7003663da4
    https://github.com/scummvm/scummvm/commit/8b174bfed608b0f9a66264e6b06d8e7003663da4
Author: Coen Rampen (crampen at gmail.com)
Date: 2022-07-02T22:13:41+02:00

Commit Message:
CHEWY: Fix sound volume and panning

This commit fixes the initial panning for speech and scripted SFX. These were
set on the sound handle of the previous speech or SFX sample, which would not
affect the new sample.

Changed paths:
    engines/chewy/atds.cpp
    engines/chewy/detail.cpp
    engines/chewy/sound.cpp
    engines/chewy/sound.h
    engines/chewy/sprite.cpp
    engines/chewy/video/cfo_decoder.cpp


diff --git a/engines/chewy/atds.cpp b/engines/chewy/atds.cpp
index 1b7667a6cca..2bce9f8b457 100644
--- a/engines/chewy/atds.cpp
+++ b/engines/chewy/atds.cpp
@@ -665,8 +665,7 @@ void Atdsys::print_aad(int16 scrX, int16 scrY) {
 					_atdsv._vocNr = _aadv._strHeader->_vocNr - ATDS_VOC_OFFSET;
 					const int16 vocx = _G(moveState)[personId].Xypos[0] -
 								 _G(gameState).scrollx + _G(spieler_mi)[personId].HotX;
-					g_engine->_sound->setSoundChannelBalance(0, getStereoPos(vocx));
-					g_engine->_sound->playSpeech(_atdsv._vocNr, false);
+					g_engine->_sound->playSpeech(_atdsv._vocNr, false, getStereoPos(vocx));
 				}
 
 				if (_atdsv._vocNr >= 0 && !g_engine->_sound->isSpeechActive())
@@ -991,7 +990,7 @@ int16 Atdsys::calc_inv_no_use(int16 curInv, int16 testNr) {
 }
 
 int8 Atdsys::getStereoPos(int16 x) {
-	return floor(x / 2.5) * 2 - 127;
+	return floor(x / 2.5);
 }
 
 void Atdsys::saveAtdsStream(Common::WriteStream *stream) {
diff --git a/engines/chewy/detail.cpp b/engines/chewy/detail.cpp
index bb3fa31d71b..75b24a071c2 100644
--- a/engines/chewy/detail.cpp
+++ b/engines/chewy/detail.cpp
@@ -404,9 +404,7 @@ void Detail::plot_ani_details(int16 scrx, int16 scry, int16 start, int16 end, in
 					if ((adiptr->sfx.sound_start[k] == adiptr->ani_count) &&
 					        (!adiptr->delay_count)) {
 						const uint channel = adiptr->sfx.kanal[k] & 7;
-						sound->setSoundChannelBalance(channel, adiptr->sfx.stereo[k]);
-						sound->setSoundChannelVolume(channel, adiptr->sfx.volume[k]);
-						sound->playSound(soundEffect, channel,	adiptr->sfx.repeats[k]);
+						sound->playSound(soundEffect, channel, adiptr->sfx.repeats[k], adiptr->sfx.volume[k], adiptr->sfx.stereo[k]);
 					}
 				}
 			}
@@ -545,9 +543,7 @@ SprInfo Detail::plot_detail_sprite(int16 scrx, int16 scry, int16 det_nr, int16 s
 		        (_rdi.sample[soundEffect])) {
 			if (adiptr->sfx.sound_start[k] == spr_nr) {
 				const uint channel = adiptr->sfx.kanal[k] & 7;
-				sound->setSoundChannelBalance(channel, adiptr->sfx.stereo[k]);
-				sound->setSoundChannelVolume(channel, adiptr->sfx.volume[k]);
-				sound->playSound(soundEffect, channel, adiptr->sfx.repeats[k]);
+				sound->playSound(soundEffect, channel, adiptr->sfx.repeats[k], adiptr->sfx.volume[k], adiptr->sfx.stereo[k]);
 			}
 		}
 	}
@@ -594,9 +590,7 @@ void Detail::play_detail_sound(int16 nr) {
 		if ((sdb->sound_enable[k]) && (sdb->sound_index[k] != -1) &&
 		        (_rdi.sample[sdb->sound_index[k]])) {
 			const uint channel = sdb->kanal[k] & 7;
-			sound->setSoundChannelBalance(channel, sdb->stereo[k]);
-			sound->setSoundChannelVolume(channel, sdb->volume[k]);
-			sound->playSound(sdb->sound_index[k], channel, sdb->repeats[k]);
+			sound->playSound(sdb->sound_index[k], channel, sdb->repeats[k], sdb->volume[k], sdb->stereo[k]);
 		}
 	}
 }
diff --git a/engines/chewy/sound.cpp b/engines/chewy/sound.cpp
index f2cd37cca8d..937cb98e260 100644
--- a/engines/chewy/sound.cpp
+++ b/engines/chewy/sound.cpp
@@ -46,18 +46,18 @@ Sound::~Sound() {
 	delete _speechRes;
 }
 
-void Sound::playSound(int num, uint channel, bool loop) {
+void Sound::playSound(int num, uint channel, bool loop, uint16 volume, uint16 balance) {
 	SoundChunk *sound = _soundRes->getSound(num);
 	uint8 *data = (uint8 *)MALLOC(sound->size);
 	memcpy(data, sound->data, sound->size);
 
-	playSound(data, sound->size, channel, loop);
+	playSound(data, sound->size, channel, loop, volume, balance);
 
 	delete[] sound->data;
 	delete sound;
 }
 
-void Sound::playSound(uint8 *data, uint32 size, uint channel, bool loop, DisposeAfterUse::Flag dispose) {
+void Sound::playSound(uint8 *data, uint32 size, uint channel, bool loop, uint16 volume, uint16 balance, DisposeAfterUse::Flag dispose) {
 	stopSound(channel);
 
 	Audio::AudioStream *stream = Audio::makeLoopingAudioStream(
@@ -66,7 +66,11 @@ void Sound::playSound(uint8 *data, uint32 size, uint channel, bool loop, Dispose
 			dispose),
 		loop ? 0 : 1);
 
-	_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle[channel], stream);
+	assert(volume >= 0 && volume < 64);
+	assert(balance >= 0 && balance < 128);
+
+	_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle[channel], stream, -1,
+		volume * Audio::Mixer::kMaxChannelVolume / 63, MIN(127, (balance - 63) * 2));
 }
 
 void Sound::pauseSound(uint channel) {
@@ -172,7 +176,7 @@ int Sound::getMusicVolume() const {
 	return _userMusicVolume;
 }
 
-void Sound::playSpeech(int num, bool waitForFinish) {
+void Sound::playSpeech(int num, bool waitForFinish, uint16 balance) {
 	if (isSpeechActive())
 		stopSpeech();
 
@@ -190,8 +194,10 @@ void Sound::playSpeech(int num, bool waitForFinish) {
 		new Common::MemorySeekableReadWriteStream(data, size, DisposeAfterUse::YES),
 		DisposeAfterUse::YES);
 
-	_mixer->playStream(Audio::Mixer::kSpeechSoundType,
-		&_speechHandle, stream);
+	assert(balance >= 0 && balance < 128);
+
+	_mixer->playStream(Audio::Mixer::kSpeechSoundType, &_speechHandle, stream,
+		-1 , 255, MIN(127, (balance - 63) * 2));
 
 	if (waitForFinish) {
 		// Wait for speech to finish
@@ -229,6 +235,12 @@ void Sound::waitForSpeechToFinish() {
 	}
 }
 
+void Sound::setSpeechBalance(uint16 balance) {
+	if (isSpeechActive()) {
+		_mixer->setChannelBalance(_speechHandle, balance);
+	}
+}
+
 bool Sound::soundEnabled() const {
 	return ConfMan.getInt("sfx_volume") > 0;
 }
diff --git a/engines/chewy/sound.h b/engines/chewy/sound.h
index b2862e35b84..eb3d3021065 100644
--- a/engines/chewy/sound.h
+++ b/engines/chewy/sound.h
@@ -43,8 +43,8 @@ public:
 	Sound(Audio::Mixer *mixer);
 	virtual ~Sound();
 
-	void playSound(int num, uint channel = 0, bool loop = false);
-	void playSound(uint8 *data, uint32 size, uint channel = 0, bool loop = false, DisposeAfterUse::Flag dispose = DisposeAfterUse::YES);
+	void playSound(int num, uint channel = 0, bool loop = false, uint16 volume = 63, uint16 balance = 63);
+	void playSound(uint8 *data, uint32 size, uint channel = 0, bool loop = false, uint16 volume = 63, uint16 balance = 63, DisposeAfterUse::Flag dispose = DisposeAfterUse::YES);
 	void pauseSound(uint channel);
 	void resumeSound(uint channel);
 	void stopSound(uint channel = 0);
@@ -67,11 +67,12 @@ public:
 	int getMusicVolume() const;
 	void playRoomMusic(int16 roomNum);
 
-	void playSpeech(int num, bool waitForFinish);
+	void playSpeech(int num, bool waitForFinish, uint16 balance = 63);
 	void pauseSpeech();
 	void resumeSpeech();
 	void stopSpeech();
 	bool isSpeechActive() const;
+	void setSpeechBalance(uint16 balance = 63);
 
 	void stopAll();
 
diff --git a/engines/chewy/sprite.cpp b/engines/chewy/sprite.cpp
index 1ff46c0105d..7753b457228 100644
--- a/engines/chewy/sprite.cpp
+++ b/engines/chewy/sprite.cpp
@@ -507,9 +507,12 @@ bool startAtsWait(int16 txtNr, int16 txtMode, int16 col, int16 mode) {
 			if (g_engine->_sound->speechEnabled())  {
 				const int16 vocx = _G(moveState)[P_CHEWY].Xypos[0] - _G(gameState).scrollx + _G(spieler_mi)[P_CHEWY].HotX;
 
-				g_engine->_sound->setSoundChannelBalance(0, _G(atds)->getStereoPos(vocx));
 				if (vocNr >= 0) {
-					g_engine->_sound->playSpeech(vocNr, false);
+					g_engine->_sound->playSpeech(vocNr, false, _G(atds)->getStereoPos(vocx));
+				} else {
+					// Not sure if the game alters speech balance while speech
+					// plays, but the old code behaved this way.
+					g_engine->_sound->setSpeechBalance(_G(atds)->getStereoPos(vocx));
 				}
 
 				setupScreen(DO_SETUP);
diff --git a/engines/chewy/video/cfo_decoder.cpp b/engines/chewy/video/cfo_decoder.cpp
index e556651fe7a..dc9c4de53a6 100644
--- a/engines/chewy/video/cfo_decoder.cpp
+++ b/engines/chewy/video/cfo_decoder.cpp
@@ -258,12 +258,12 @@ void CfoDecoder::CfoVideoTrack::handleCustomFrame() {
 		case kChunkPlayVoc:
 			number = _fileStream->readUint16LE();
 			channel = _fileStream->readUint16LE();
-			volume = _fileStream->readUint16LE() * Audio::Mixer::kMaxChannelVolume / 63;
+			volume = _fileStream->readUint16LE();// * Audio::Mixer::kMaxChannelVolume / 63;
 			repeat = _fileStream->readUint16LE();
 			assert(number < MAX_SOUND_EFFECTS);
 
-			_sound->setSoundVolume(volume);
-			_sound->playSound(_soundEffects[number], _soundEffectSize[number], channel, repeat, DisposeAfterUse::NO);
+			//_sound->setSoundVolume(volume);
+			_sound->playSound(_soundEffects[number], _soundEffectSize[number], channel, repeat, volume, 63, DisposeAfterUse::NO);
 			break;
 		case kChunkSetSoundVolume:
 			volume = _fileStream->readUint16LE() * Audio::Mixer::kMaxChannelVolume / 63;




More information about the Scummvm-git-logs mailing list