[Scummvm-git-logs] scummvm branch-2-6 -> e208659aa877a034920cf9131a27db2aeb6c5d03

bluegr noreply at scummvm.org
Tue Jun 21 15:12:13 UTC 2022


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

Summary:
2df1ab382c CHEWY: Fix pops at start of SFX and speech
6aaabb3e03 CHEWY: Fix intro music
dbc0c84668 CHEWY: Use the ScummVM volume - bug #13595
6494eb1375 CHEWY: Slight cleanup of the barrier code
7a236b23e5 CHEWY: Fix music and sound volume in options
0695ea5adf CHEWY: Renames for dialog closeup functionality
2204bddd25 CHEWY: Use a direct variable for text delay
0f2a74fad6 CHEWY: More renaming for the dialog closeup code
86a4d419b2 CHEWY: Cleanup loadDialogCloseup()
44d2dd9267 CHEWY: Clear pending events when starting a dialog closeup - bug #13593
796166b501 AUDIO: Enable subclassing of VocStream
e208659aa8 AUDIO: Fix VOC infinite loop


Commit: 2df1ab382c8f402c4dee6fecb640f1ee9771666c
    https://github.com/scummvm/scummvm/commit/2df1ab382c8f402c4dee6fecb640f1ee9771666c
Author: Coen Rampen (crampen at gmail.com)
Date: 2022-06-21T18:11:44+03:00

Commit Message:
CHEWY: Fix pops at start of SFX and speech

SFX and speech data are actually VOC format without the header. This was not
correctly processed and non-audio data was played as audio, causing popping.
This commit adds a VocStream subclass to handle this variant of the VOC format.

Changed paths:
  A engines/chewy/audio/chewy_voc.cpp
  A engines/chewy/audio/chewy_voc.h
  A engines/chewy/audio/module_tmf.cpp
  A engines/chewy/audio/module_tmf.h
  A engines/chewy/audio/tmf_stream.cpp
  A engines/chewy/audio/tmf_stream.h
  R engines/chewy/music/module_tmf.cpp
  R engines/chewy/music/module_tmf.h
  R engines/chewy/music/tmf_stream.cpp
  R engines/chewy/music/tmf_stream.h
    engines/chewy/module.mk
    engines/chewy/resource.cpp
    engines/chewy/sound.cpp


diff --git a/engines/chewy/audio/chewy_voc.cpp b/engines/chewy/audio/chewy_voc.cpp
new file mode 100644
index 00000000000..80aadbc9fd1
--- /dev/null
+++ b/engines/chewy/audio/chewy_voc.cpp
@@ -0,0 +1,63 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "chewy/audio/chewy_voc.h"
+
+#include "common/stream.h"
+
+namespace Chewy {
+
+ChewyVocStream::ChewyVocStream(Common::SeekableReadStream* stream, DisposeAfterUse::Flag disposeAfterUse) :
+		VocStream(stream, true, disposeAfterUse) {
+	removeHeaders();
+}
+
+void ChewyVocStream::removeHeaders() {
+	// Check the sample blocks for non-standard headers.
+	for (BlockList::iterator i = _blocks.begin(), end = _blocks.end(); i != end; ++i) {
+		if (i->code == 1 && i->sampleBlock.samples > 80) {
+			// Found a sample block. Check for the headers.
+			int headerSize = 0;
+			if (_stream->readUint32BE() == FOURCC_RIFF) {
+				// Found a RIFF header. 
+				headerSize = 44;
+			} else {
+				_stream->seek(i->sampleBlock.offset + 76);
+				if (_stream->readUint32BE() == FOURCC_SCRS) {
+					// Found an SCRS (?) header.
+					headerSize = 80;
+				}
+			}
+
+			if (headerSize > 0) {
+				// Move the offset past the header and adjust the length.
+				i->sampleBlock.offset += headerSize;
+				i->sampleBlock.samples -= headerSize;
+				_length = _length.addFrames(-headerSize);
+			}
+		}
+	}
+
+	// Reset the stream.
+	rewind();
+}
+
+} // End of namespace Chewy
diff --git a/engines/chewy/audio/chewy_voc.h b/engines/chewy/audio/chewy_voc.h
new file mode 100644
index 00000000000..b925e157997
--- /dev/null
+++ b/engines/chewy/audio/chewy_voc.h
@@ -0,0 +1,49 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef CHEWY_AUDIO_CHEWY_VOC_H
+#define CHEWY_AUDIO_CHEWY_VOC_H
+
+#include "audio/decoders/voc.h"
+
+#include "common/endian.h"
+
+namespace Chewy {
+
+// This stream differs from the standard VOC stream on 2 points:
+// - VOC data header is not present, so not processed.
+// - Some VOC blocks contain non-standard headers. These are removed because
+//   otherwise they will be interpreted as audio data and cause static.
+class ChewyVocStream : public Audio::VocStream {
+protected:
+	static const uint32 FOURCC_SCRS = MKTAG('S', 'C', 'R', 'S');
+	static const uint32 FOURCC_RIFF = MKTAG('R', 'I', 'F', 'F');
+
+public:
+	ChewyVocStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse);
+
+protected:
+	void removeHeaders();
+};
+
+} // End of namespace Audio
+
+#endif
diff --git a/engines/chewy/music/module_tmf.cpp b/engines/chewy/audio/module_tmf.cpp
similarity index 99%
rename from engines/chewy/music/module_tmf.cpp
rename to engines/chewy/audio/module_tmf.cpp
index 97547260bc1..36efeb1fa21 100644
--- a/engines/chewy/music/module_tmf.cpp
+++ b/engines/chewy/audio/module_tmf.cpp
@@ -19,7 +19,7 @@
  *
  */
 
-#include "chewy/music/module_tmf.h"
+#include "chewy/audio/module_tmf.h"
 
 #include "common/array.h"
 #include "common/stream.h"
diff --git a/engines/chewy/music/module_tmf.h b/engines/chewy/audio/module_tmf.h
similarity index 100%
rename from engines/chewy/music/module_tmf.h
rename to engines/chewy/audio/module_tmf.h
diff --git a/engines/chewy/music/tmf_stream.cpp b/engines/chewy/audio/tmf_stream.cpp
similarity index 94%
rename from engines/chewy/music/tmf_stream.cpp
rename to engines/chewy/audio/tmf_stream.cpp
index fcbfed95a4d..d47a2811445 100644
--- a/engines/chewy/music/tmf_stream.cpp
+++ b/engines/chewy/audio/tmf_stream.cpp
@@ -19,9 +19,9 @@
  *
  */
 
-#include "chewy/music/tmf_stream.h"
+#include "chewy/audio/tmf_stream.h"
 
-#include "chewy/music/module_tmf.h"
+#include "chewy/audio/module_tmf.h"
 
 Chewy::TMFStream::TMFStream(Common::SeekableReadStream *stream, int offs) : ProtrackerStream(44100, true) {
 	_module = new Module_TMF();
diff --git a/engines/chewy/music/tmf_stream.h b/engines/chewy/audio/tmf_stream.h
similarity index 100%
rename from engines/chewy/music/tmf_stream.h
rename to engines/chewy/audio/tmf_stream.h
diff --git a/engines/chewy/module.mk b/engines/chewy/module.mk
index d8b77a1d456..b981a9a9e00 100644
--- a/engines/chewy/module.mk
+++ b/engines/chewy/module.mk
@@ -29,14 +29,15 @@ MODULE_OBJS = \
 	text.o \
 	timer.o \
 	types.o \
+	audio/chewy_voc.o \
+	audio/module_tmf.o \
+	audio/tmf_stream.o \
 	dialogs/cinema.o \
 	dialogs/credits.o \
 	dialogs/files.o \
 	dialogs/inventory.o \
 	dialogs/main_menu.o \
 	dialogs/options.o \
-	music/module_tmf.o \
-	music/tmf_stream.o \
 	video/cfo_decoder.o \
 	video/video_player.o \
 	rooms/room00.o \
diff --git a/engines/chewy/resource.cpp b/engines/chewy/resource.cpp
index 337d6daef81..7998b18da09 100644
--- a/engines/chewy/resource.cpp
+++ b/engines/chewy/resource.cpp
@@ -287,42 +287,11 @@ SoundChunk *SoundResource::getSound(uint num) {
 
 	Chunk *chunk = &_chunkList[num];
 	SoundChunk *sound = new SoundChunk();
+	sound->size = chunk->size;
+	sound->data = new uint8[sound->size];
 
 	_stream.seek(chunk->pos, SEEK_SET);
-
-	uint8 blocksRemaining;
-	uint32 totalLength = 0;
-	uint32 blockSize;
-
-	do {
-		blocksRemaining = _stream.readByte();
-
-		uint8 b1 = _stream.readByte();
-		uint8 b2 = _stream.readByte();
-		uint8 b3 = _stream.readByte();
-		blockSize = b1 + (b2 << 8) + (b3 << 16);
-
-		totalLength += blockSize;
-		_stream.skip(blockSize);
-	} while (blocksRemaining > 1);
-
-	sound->size = totalLength;
-	sound->data = new uint8[totalLength];
-	uint8 *ptr = sound->data;
-
-	_stream.seek(chunk->pos, SEEK_SET);
-
-	do {
-		blocksRemaining = _stream.readByte();
-
-		uint8 b1 = _stream.readByte();
-		uint8 b2 = _stream.readByte();
-		uint8 b3 = _stream.readByte();
-		blockSize = b1 + (b2 << 8) + (b3 << 16);
-
-		_stream.read(ptr, blockSize);
-		ptr += blockSize;
-	} while (blocksRemaining > 1);
+	_stream.read(sound->data, sound->size);
 
 	return sound;
 }
diff --git a/engines/chewy/sound.cpp b/engines/chewy/sound.cpp
index e8741bf0e68..cce6a6c67f3 100644
--- a/engines/chewy/sound.cpp
+++ b/engines/chewy/sound.cpp
@@ -24,12 +24,14 @@
 #include "audio/decoders/raw.h"
 #include "audio/mods/protracker.h"
 #include "common/config-manager.h"
+#include "common/memstream.h"
 #include "common/system.h"
 #include "chewy/resource.h"
 #include "chewy/sound.h"
 #include "chewy/types.h"
 #include "chewy/globals.h"
-#include "chewy/music/tmf_stream.h"
+#include "chewy/audio/chewy_voc.h"
+#include "chewy/audio/tmf_stream.h"
 
 namespace Chewy {
 
@@ -75,10 +77,10 @@ void Sound::playSound(int num, uint channel, bool loop) {
 
 void Sound::playSound(uint8 *data, uint32 size, uint channel, bool loop, DisposeAfterUse::Flag dispose) {
 	Audio::AudioStream *stream = Audio::makeLoopingAudioStream(
-	                                 Audio::makeRawStream(data,
-	                                         size, 22050, Audio::FLAG_UNSIGNED,
-	                                         dispose),
-	                                 loop ? 0 : 1);
+		new ChewyVocStream(
+			new Common::MemorySeekableReadWriteStream(data, size, dispose),
+			dispose),
+		loop ? 0 : 1);
 
 	_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle[channel], stream);
 }
@@ -175,9 +177,9 @@ void Sound::playSpeech(int num, bool waitForFinish) {
 	delete sound;
 
 	// Play it
-	Audio::AudioStream *stream = Audio::makeLoopingAudioStream(
-	    Audio::makeRawStream(data, size, 22050, Audio::FLAG_UNSIGNED,
-		DisposeAfterUse::YES), 1);
+	Audio::AudioStream *stream = new ChewyVocStream(
+		new Common::MemorySeekableReadWriteStream(data, size, DisposeAfterUse::YES),
+		DisposeAfterUse::YES);
 
 	_mixer->playStream(Audio::Mixer::kSpeechSoundType,
 		&_speechHandle, stream);


Commit: 6aaabb3e033e2740fbdc7ab2be60681dc7ffe264
    https://github.com/scummvm/scummvm/commit/6aaabb3e033e2740fbdc7ab2be60681dc7ffe264
Author: Coen Rampen (crampen at gmail.com)
Date: 2022-06-21T18:11:45+03:00

Commit Message:
CHEWY: Fix intro music

playIntroSequence would not set the playVideo stopMusic parameter to false,
so the music would be immediately stopped. Also, the CfoVideoTrack destructor
would stop all mixer channels, including the music. This would cause the music
to stop at the end of each video. This is replaced by a call to stopAllSounds,
and stopMusic is only called when the music is in the video data.
This commit also fixes an issue where playing a sound on a channel where a
sound was already active would not stop the old sound, but replace the sound
handle with a new one. The old sound could then no longer be accessed by the
sound class.

Changed paths:
    engines/chewy/r_event.cpp
    engines/chewy/sound.cpp
    engines/chewy/video/cfo_decoder.cpp


diff --git a/engines/chewy/r_event.cpp b/engines/chewy/r_event.cpp
index ae9bc0f1ee5..79cff1160da 100644
--- a/engines/chewy/r_event.cpp
+++ b/engines/chewy/r_event.cpp
@@ -676,7 +676,7 @@ static void playIntroSequence() {
 		if (introDialog[i] != -1)
 			start_aad(introDialog[i], -1);
 
-		ret = g_engine->_video->playVideo(introVideo[i]) ? 0 : -1;
+		ret = g_engine->_video->playVideo(introVideo[i], false) ? 0 : -1;
 		_G(atds)->stopAad();
 		SHOULD_QUIT_RETURN;
 	}
diff --git a/engines/chewy/sound.cpp b/engines/chewy/sound.cpp
index cce6a6c67f3..e8bf3d29cf0 100644
--- a/engines/chewy/sound.cpp
+++ b/engines/chewy/sound.cpp
@@ -76,6 +76,8 @@ void Sound::playSound(int num, uint channel, bool loop) {
 }
 
 void Sound::playSound(uint8 *data, uint32 size, uint channel, bool loop, DisposeAfterUse::Flag dispose) {
+	stopSound(channel);
+
 	Audio::AudioStream *stream = Audio::makeLoopingAudioStream(
 		new ChewyVocStream(
 			new Common::MemorySeekableReadWriteStream(data, size, dispose),
@@ -101,7 +103,7 @@ void Sound::stopSound(uint channel) {
 }
 
 void Sound::stopAllSounds() {
-	for (int i = 4; i < 8; i++)
+	for (int i = 0; i < 14; i++)
 		stopSound(i);
 }
 
diff --git a/engines/chewy/video/cfo_decoder.cpp b/engines/chewy/video/cfo_decoder.cpp
index 1524c3bdc40..e556651fe7a 100644
--- a/engines/chewy/video/cfo_decoder.cpp
+++ b/engines/chewy/video/cfo_decoder.cpp
@@ -86,14 +86,19 @@ CfoDecoder::CfoVideoTrack::CfoVideoTrack(Common::SeekableReadStream *stream, uin
 }
 
 CfoDecoder::CfoVideoTrack::~CfoVideoTrack() {
-	_sound->stopAll();
+	// Stop all sound effects.
+	_sound->stopAllSounds();
 
 	for (int i = 0; i < MAX_SOUND_EFFECTS; i++) {
 		delete[] _soundEffects[i];
 	}
 
-	delete[] _musicData;
-	_musicData = nullptr;
+	// Only stop music if it is included in the video data.
+	if (_musicData) {
+		_sound->stopMusic();
+		delete[] _musicData;
+		_musicData = nullptr;
+	}
 }
 
 void CfoDecoder::CfoVideoTrack::readHeader() {


Commit: dbc0c84668fc9ff46494a6a5d3ee8d3efd61ea8f
    https://github.com/scummvm/scummvm/commit/dbc0c84668fc9ff46494a6a5d3ee8d3efd61ea8f
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-06-21T18:11:45+03:00

Commit Message:
CHEWY: Use the ScummVM volume - bug #13595

This avoids having the volume reset on game startup. Also, volume is
no longer stored in saved games

Changed paths:
    engines/chewy/dialogs/main_menu.cpp
    engines/chewy/dialogs/options.cpp
    engines/chewy/globals.h
    engines/chewy/inits.cpp
    engines/chewy/r_event.cpp
    engines/chewy/sound.cpp
    engines/chewy/sound.h
    engines/chewy/types.cpp
    engines/chewy/types.h
    engines/chewy/video/video_player.cpp


diff --git a/engines/chewy/dialogs/main_menu.cpp b/engines/chewy/dialogs/main_menu.cpp
index f5afa53af6c..3c3b7b6da45 100644
--- a/engines/chewy/dialogs/main_menu.cpp
+++ b/engines/chewy/dialogs/main_menu.cpp
@@ -173,15 +173,11 @@ void MainMenu::startGame() {
 	animate();
 	exit_room(-1);
 
-	uint8 soundVol = _G(gameState).SoundVol;
-	uint8 musicVol = _G(gameState).MusicVol;
 	uint8 framesPerSecond = _G(gameState).FramesPerSecond;
 	int sndLoopMode = _G(gameState).soundLoopMode;
 
 	var_init();
 
-	_G(gameState).SoundVol = soundVol;
-	_G(gameState).MusicVol = musicVol;
 	_G(gameState).FramesPerSecond = framesPerSecond;
 	_G(gameState).soundLoopMode = sndLoopMode;
 
diff --git a/engines/chewy/dialogs/options.cpp b/engines/chewy/dialogs/options.cpp
index e93f490d87d..3032118089a 100644
--- a/engines/chewy/dialogs/options.cpp
+++ b/engines/chewy/dialogs/options.cpp
@@ -65,17 +65,17 @@ void Options::execute(TafInfo *ti) {
 	int16 tdisp_count = tdisp_delay;
 	_G(FrameSpeed) = 0;
 	int16 delay_count = _G(gameState).DelaySpeed;
-	warning("stop_clock = (clock() / CLK_TCK) + 1;");
+	//warning("stop_clock = (clock() / CLK_TCK) + 1;");
 	while (key != Common::KEYCODE_ESCAPE) {
 		_G(out)->map_spr2screen(_G(ablage)[_G(room_blk).AkAblage], 0, 0);
 		++_G(FrameSpeed);
-		warning("akt_clock = clock() / CLK_TCK;");
+		//warning("akt_clock = clock() / CLK_TCK;");
 		if (akt_clock >= stop_clock) {
 			//TmpFrame = _G(FrameSpeed);
 			_G(gameState).DelaySpeed = (_G(FrameSpeed) >> 1) / _G(gameState).FramesPerSecond;
 
 			_G(FrameSpeed) = 0;
-			warning("stop_clock = (clock() / CLK_TCK) + 1;");
+			//warning("stop_clock = (clock() / CLK_TCK) + 1;");
 		}
 
 		_G(out)->spriteSet(ti->image[surimy_ani], 18 + ti->correction[surimy_ani << 1],
@@ -100,13 +100,16 @@ void Options::execute(TafInfo *ti) {
 				18 + ti->correction[SCHNULL_BAND << 1],
 				8 + ti->correction[(SCHNULL_BAND << 1) + 1], 0);
 		}
+
+		const int soundVolume = g_engine->_sound->getSoundVolume() * Audio::Mixer::kMaxChannelVolume / 2 * 120;
 		_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 - (_G(gameState).SoundVol >> 1), 42, 136, 15);
+		_G(out)->boxFill(33, 136 - (soundVolume >> 1), 42, 136, 15);
 
+		const int musicVolume = g_engine->_sound->getSoundVolume() * Audio::Mixer::kMaxChannelVolume / 2 * 120;
 		_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 - (_G(gameState).MusicVol >> 1), 62, 136, 31);
+		_G(out)->boxFill(53, 136 - (musicVolume >> 1), 62, 136, 31);
 		if (g_engine->_sound->musicEnabled()) {
 			_G(out)->spriteSet(ti->image[MUSIC_ON1],
 				18 + ti->correction[MUSIC_ON1 << 1],
@@ -181,12 +184,10 @@ void Options::execute(TafInfo *ti) {
 				key = Common::KEYCODE_ESCAPE;
 				break;
 			case 7:
-				_G(gameState).SoundVol = (136 - g_events->_mousePos.y) << 1;
-				g_engine->_sound->setSoundVolume(_G(gameState).SoundVol * Audio::Mixer::kMaxChannelVolume / 120);
+				g_engine->_sound->setSoundVolume(((136 - g_events->_mousePos.y) << 1) * Audio::Mixer::kMaxChannelVolume / 120);
 				break;
 			case 8:
-				_G(gameState).MusicVol = (136 - g_events->_mousePos.y) << 1;
-				g_engine->_sound->setMusicVolume(_G(gameState).MusicVol * Audio::Mixer::kMaxChannelVolume / 120);
+				g_engine->_sound->setMusicVolume(((136 - g_events->_mousePos.y) << 1) * Audio::Mixer::kMaxChannelVolume / 120);
 				break;
 
 			default:
diff --git a/engines/chewy/globals.h b/engines/chewy/globals.h
index ad5bdc5822a..02d23cb408d 100644
--- a/engines/chewy/globals.h
+++ b/engines/chewy/globals.h
@@ -389,7 +389,6 @@ void init_load();
 void var_init();
 
 void new_game();
-void sound_init();
 void show_intro();
 void register_cutscene(int cutsceneNum);
 void getCutscenes(Common::Array<int> &cutscenes);
diff --git a/engines/chewy/inits.cpp b/engines/chewy/inits.cpp
index ee85087db71..a628f935bfd 100644
--- a/engines/chewy/inits.cpp
+++ b/engines/chewy/inits.cpp
@@ -79,7 +79,6 @@ void standard_init() {
 	_G(out)->cls();
 	_G(uhr)->setNewTimer(0, 5, SEC_10_MODE);
 
-	sound_init();
 	init_load();
 }
 
@@ -249,13 +248,6 @@ void tidy() {
 	_G(mem) = nullptr;
 }
 
-void sound_init() {
-	_G(gameState).MusicVol = 63;
-	_G(gameState).SoundVol = 63;
-	g_engine->_sound->setMusicVolume(_G(gameState).MusicVol * Audio::Mixer::kMaxChannelVolume / 120);
-	g_engine->_sound->setSoundVolume(_G(gameState).SoundVol * Audio::Mixer::kMaxChannelVolume / 120);
-}
-
 void show_intro() {
 	if (!ConfMan.getBool("shown_intro")) {
 		ConfMan.setBool("shown_intro", true);
diff --git a/engines/chewy/r_event.cpp b/engines/chewy/r_event.cpp
index 79cff1160da..2058cac70a2 100644
--- a/engines/chewy/r_event.cpp
+++ b/engines/chewy/r_event.cpp
@@ -789,8 +789,6 @@ void flic_cut(int16 nr) {
 	SHOULD_QUIT_RETURN;
 
 	g_events->delay(50);
-	g_engine->_sound->setSoundVolume(_G(gameState).SoundVol * Audio::Mixer::kMaxChannelVolume / 120);
-	g_engine->_sound->setMusicVolume(_G(gameState).MusicVol * Audio::Mixer::kMaxChannelVolume / 120);
 
 	if (nr != FCUT_135) {
 		g_engine->_sound->playRoomMusic(_G(gameState)._personRoomNr[0]);
diff --git a/engines/chewy/sound.cpp b/engines/chewy/sound.cpp
index e8bf3d29cf0..c2c3da0262b 100644
--- a/engines/chewy/sound.cpp
+++ b/engines/chewy/sound.cpp
@@ -35,24 +35,6 @@
 
 namespace Chewy {
 
-const uint8 Sound::TMF_MOD_SONG_NAME[] = {
-	'S', 'C', 'U', 'M', 'M',
-	'V', 'M', ' ', 'M', 'O',
-	'D', 'U', 'L', 'E', '\0',
-	'\0', '\0', '\0', '\0', '\0'};
-const uint8 Sound::TMF_MOD_INSTRUMENT_NAME[] = {
-	'S', 'C', 'U', 'M', 'M',
-	'V', 'M', ' ', 'I', 'N',
-	'S', 'T', 'R', 'U', 'M',
-	'E', 'N', 'T', '\0', '\0',
-	'\0', '\0'};
-// TODO Verify period values used by the game; this is an educated guess.
-const uint16 Sound::TMF_MOD_PERIODS[] = {
-	856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453,
-	428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226,
-	214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113
-};
-
 Sound::Sound(Audio::Mixer *mixer) {
 	_mixer = mixer;
 	_speechRes = new SoundResource("speech.tvp");
@@ -114,6 +96,24 @@ bool Sound::isSoundActive(uint channel) const {
 
 void Sound::setSoundVolume(uint volume) {
 	_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, volume);
+	_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, volume);
+}
+
+int Sound::getSoundVolume() const {
+	return _mixer->getVolumeForSoundType(Audio::Mixer::kSFXSoundType);
+}
+
+void Sound::pushVolume() {
+	_soundVolume = _mixer->getVolumeForSoundType(Audio::Mixer::kSFXSoundType);
+	_speechVolume = _mixer->getVolumeForSoundType(Audio::Mixer::kSpeechSoundType);
+	_musicVolume = _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType);
+}
+
+void Sound::popVolume() {
+	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);
 }
 
 void Sound::setSoundChannelVolume(uint channel, uint volume) {
@@ -165,6 +165,10 @@ void Sound::setMusicVolume(uint volume) {
 	_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, volume);
 }
 
+int Sound::getMusicVolume() const {
+	return _mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType);
+}
+
 void Sound::playSpeech(int num, bool waitForFinish) {
 	if (isSpeechActive())
 		stopSpeech();
@@ -210,10 +214,6 @@ bool Sound::isSpeechActive() const {
 	return _mixer->isSoundHandleActive(_speechHandle);
 }
 
-void Sound::setSpeechVolume(uint volume) {
-	_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, volume);
-}
-
 void Sound::stopAll() {
 	_mixer->stopAll();
 }
diff --git a/engines/chewy/sound.h b/engines/chewy/sound.h
index 09c0d5e5b05..e20be085fbb 100644
--- a/engines/chewy/sound.h
+++ b/engines/chewy/sound.h
@@ -51,8 +51,11 @@ public:
 	void stopAllSounds();
 	bool isSoundActive(uint channel) const;
 	void setSoundVolume(uint volume);
+	int getSoundVolume() const;
 	void setSoundChannelVolume(uint channel, uint volume);
 	void setSoundChannelBalance(uint channel, int8 balance);
+	void pushVolume();
+	void popVolume();
 
 	void playMusic(int16 num, bool loop = false);
 	void playMusic(uint8 *data, uint32 size);
@@ -61,6 +64,7 @@ public:
 	void stopMusic();
 	bool isMusicActive() const;
 	void setMusicVolume(uint volume);
+	int getMusicVolume() const;
 	void playRoomMusic(int16 roomNum);
 
 	void playSpeech(int num, bool waitForFinish);
@@ -68,7 +72,6 @@ public:
 	void resumeSpeech();
 	void stopSpeech();
 	bool isSpeechActive() const;
-	void setSpeechVolume(uint volume);
 
 	void stopAll();
 
@@ -95,6 +98,7 @@ private:
 	Audio::SoundHandle _musicHandle;
 	Audio::SoundHandle _speechHandle;
 	int16 _curMusic = -1;
+	int _soundVolume = -1, _speechVolume = -1, _musicVolume = -1;
 
 	SoundResource *_speechRes;
 	SoundResource *_soundRes;
diff --git a/engines/chewy/types.cpp b/engines/chewy/types.cpp
index a45948dbe84..7ad2072907f 100644
--- a/engines/chewy/types.cpp
+++ b/engines/chewy/types.cpp
@@ -150,9 +150,9 @@ bool GameState::synchronize(Common::Serializer &s) {
 	s.syncAsSint16LE(SVal4);
 	s.syncAsSint16LE(soundLoopMode);
 	s.syncAsByte(dummy);	// sound switch
-	s.syncAsByte(SoundVol);
+	s.syncAsByte(dummy);	// sound volume
 	s.syncAsByte(dummy);	// music switch
-	s.syncAsByte(MusicVol);
+	s.syncAsByte(dummy);	// music volume
 	s.syncAsByte(dummy);	// speech switch
 	s.syncAsByte(FramesPerSecond);
 	s.syncAsByte(dummy);	// subtitles switch
diff --git a/engines/chewy/types.h b/engines/chewy/types.h
index 0d1316cd89c..d01a9018891 100644
--- a/engines/chewy/types.h
+++ b/engines/chewy/types.h
@@ -517,8 +517,6 @@ struct GameState : public GameFlags {
 	int16 SVal3 = 0;
 	int16 SVal4 = 0;
 	int16 soundLoopMode = 0;
-	uint8 SoundVol = 0;
-	uint8 MusicVol = 0;
 	uint8 FramesPerSecond = 0;
 };
 
diff --git a/engines/chewy/video/video_player.cpp b/engines/chewy/video/video_player.cpp
index d41a838f574..3043ac09c6f 100644
--- a/engines/chewy/video/video_player.cpp
+++ b/engines/chewy/video/video_player.cpp
@@ -36,6 +36,7 @@ bool VideoPlayer::playVideo(uint num, bool stopMusic) {
 	CfoDecoder *cfoDecoder = new CfoDecoder(g_engine->_sound);
 	VideoResource *videoResource = new VideoResource("cut.tap");
 	Common::SeekableReadStream *videoStream = videoResource->getVideoStream(num);
+	g_engine->_sound->pushVolume();
 	_playCount = 0;
 
 	if (stopMusic) {
@@ -101,6 +102,7 @@ bool VideoPlayer::playVideo(uint num, bool stopMusic) {
 
 	g_system->getPaletteManager()->setPalette(curPalette, 0, 256);
 	_G(cur)->show_cur();
+	g_engine->_sound->popVolume();
 
 	delete videoResource;
 	delete cfoDecoder;


Commit: 6494eb1375f87c456a180bf514436e2f9c290c67
    https://github.com/scummvm/scummvm/commit/6494eb1375f87c456a180bf514436e2f9c290c67
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-06-21T18:11:45+03:00

Commit Message:
CHEWY: Slight cleanup of the barrier code

Changed paths:
    engines/chewy/barriers.cpp


diff --git a/engines/chewy/barriers.cpp b/engines/chewy/barriers.cpp
index 3c46b269067..b0de07ac758 100644
--- a/engines/chewy/barriers.cpp
+++ b/engines/chewy/barriers.cpp
@@ -42,53 +42,51 @@ int16 Barriers::getBarrierId(int16 g_idx, const byte *buffer) {
 		switch (_G(gameState)._personRoomNr[P_CHEWY]) {
 		case 8:
 			if (_G(gameState).R8GTuer)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 9:
 			if (!_G(gameState).R9Gitter)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 16:
 			if (!_G(gameState).R16F5Exit)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 17:
 			if (_G(gameState).R17Location != 1)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 21:
 			if (!_G(gameState).R21Laser2Weg)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 31:
 			if (!_G(gameState).R31KlappeZu)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 41:
 			if (!_G(gameState).R41LolaOk)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 52:
 			if (!_G(gameState).R52LichtAn)
-				idx_nr = 2;
+				return 2;
 			else
-				idx_nr = 4;
+				return 4;
 			break;
 
 		case 71:
-			idx_nr = _G(gameState).R71LeopardVined ? 1 : 0;
-			break;
+			return _G(gameState).R71LeopardVined ? 1 : 0;
 
 		case 76:
-			idx_nr = _G(gameState).flags29_4 ? 4 : 0;
-			break;
+			return _G(gameState).flags29_4 ? 4 : 0;
 
 		case 84:
 			if (!_G(gameState).R88UsedMonkey)
@@ -97,17 +95,17 @@ int16 Barriers::getBarrierId(int16 g_idx, const byte *buffer) {
 
 		case 86:
 			if (!_G(gameState).flags32_2)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 94:
 			if (!_G(gameState).flags35_10)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 97:
 			if (_G(gameState).flags35_80)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		default:
@@ -119,31 +117,30 @@ int16 Barriers::getBarrierId(int16 g_idx, const byte *buffer) {
 		switch (_G(gameState)._personRoomNr[P_CHEWY]) {
 		case 17:
 			if (_G(gameState).R17Location != 2)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 21:
-			if (!_G(gameState).R21Laser1Weg) {
-				idx_nr = 0;
-			} else
-				idx_nr = 3;
-			break;
+			if (!_G(gameState).R21Laser1Weg)
+				return 0;
+			else
+				return 3;
 
 		case 37:
 			if (!_G(gameState).R37Kloppe)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		case 52:
 			if (!_G(gameState).R52TuerAuf)
-				idx_nr = 2;
+				return 2;
 			else
-				idx_nr = 4;
+				return 4;
 			break;
 
 		case 97:
 			if (_G(gameState).flags36_20)
-				idx_nr = 0;
+				return 0;
 			break;
 
 		default:
@@ -152,10 +149,8 @@ int16 Barriers::getBarrierId(int16 g_idx, const byte *buffer) {
 		break;
 
 	case 42:
-		if (_G(gameState)._personRoomNr[P_CHEWY] == 97) {
-			if (!_G(gameState).flags37_1)
-				idx_nr = 0;
-		}
+		if (_G(gameState)._personRoomNr[P_CHEWY] == 97 && !_G(gameState).flags37_1)
+			return 0;
 		break;
 
 	default:


Commit: 7a236b23e58a3735091bc2997205bd870b249ecf
    https://github.com/scummvm/scummvm/commit/7a236b23e58a3735091bc2997205bd870b249ecf
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-06-21T18:11:46+03:00

Commit Message:
CHEWY: Fix music and sound volume in options

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


diff --git a/engines/chewy/dialogs/options.cpp b/engines/chewy/dialogs/options.cpp
index 3032118089a..d95075807b7 100644
--- a/engines/chewy/dialogs/options.cpp
+++ b/engines/chewy/dialogs/options.cpp
@@ -101,15 +101,16 @@ void Options::execute(TafInfo *ti) {
 				8 + ti->correction[(SCHNULL_BAND << 1) + 1], 0);
 		}
 
-		const int soundVolume = g_engine->_sound->getSoundVolume() * Audio::Mixer::kMaxChannelVolume / 2 * 120;
+		const int soundVolume = g_engine->_sound->getSoundVolume() * Audio::Mixer::kMaxChannelVolume / 120;
 		_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);
 
-		const int musicVolume = g_engine->_sound->getSoundVolume() * Audio::Mixer::kMaxChannelVolume / 2 * 120;
+		const int musicVolume = g_engine->_sound->getSoundVolume() * Audio::Mixer::kMaxChannelVolume / 120;
 		_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);
+
 		if (g_engine->_sound->musicEnabled()) {
 			_G(out)->spriteSet(ti->image[MUSIC_ON1],
 				18 + ti->correction[MUSIC_ON1 << 1],


Commit: 0695ea5adf9776859e601fa826fc33f8e9e6ee20
    https://github.com/scummvm/scummvm/commit/0695ea5adf9776859e601fa826fc33f8e9e6ee20
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-06-21T18:11:46+03:00

Commit Message:
CHEWY: Renames for dialog closeup functionality

Changed paths:
    engines/chewy/atds.cpp
    engines/chewy/atds.h
    engines/chewy/globals.h
    engines/chewy/main.cpp
    engines/chewy/menus.cpp
    engines/chewy/rooms/room08.cpp
    engines/chewy/rooms/room11.cpp
    engines/chewy/rooms/room14.cpp
    engines/chewy/rooms/room35.cpp
    engines/chewy/rooms/room37.cpp
    engines/chewy/rooms/room41.cpp
    engines/chewy/rooms/room42.cpp
    engines/chewy/rooms/room55.cpp
    engines/chewy/rooms/room56.cpp
    engines/chewy/rooms/room63.cpp
    engines/chewy/rooms/room65.cpp
    engines/chewy/rooms/room67.cpp
    engines/chewy/rooms/room68.cpp
    engines/chewy/rooms/room76.cpp
    engines/chewy/rooms/room84.cpp
    engines/chewy/rooms/room93.cpp
    engines/chewy/sprite.cpp
    engines/chewy/t_event.cpp
    engines/chewy/text.cpp
    engines/chewy/types.h


diff --git a/engines/chewy/atds.cpp b/engines/chewy/atds.cpp
index 17e15137ca0..65dfe3ea71d 100644
--- a/engines/chewy/atds.cpp
+++ b/engines/chewy/atds.cpp
@@ -65,7 +65,7 @@ bool AadTxtHeader::load(const void *src) {
 	return true;
 }
 
-bool AdsTxtHeader::load(const void *src) {
+bool DialogCloseupTxtHeader::load(const void *src) {
 	Common::MemoryReadStream rs((const byte *)src, 8);
 
 	_diaNr = rs.readSint16LE();
@@ -80,10 +80,10 @@ Atdsys::Atdsys() {
 	_aadv._dialog = false;
 	_aadv._strNr = -1;
 	_aadv._silentCount = false;
-	_adsv._dialog = -1;
-	_adsv._autoDia = false;
-	_adsv._strNr = -1;
-	_adsv._silentCount = false;
+	_dialogCloseup._dialog = -1;
+	_dialogCloseup._autoDia = false;
+	_dialogCloseup._strNr = -1;
+	_dialogCloseup._silentCount = false;
 	_tmpDelay = 1;
 	_atdsv._delay = &_tmpDelay;
 	_atdsv._silent = false;
@@ -98,9 +98,9 @@ Atdsys::Atdsys() {
 	_dialogResource = new DialogResource(ADS_TXT_STEUER);
 	_text = new Text();
 
-	_adsnb._blkNr = 0;
-	_adsnb._endNr = 0;
-	_adsStackPtr = 0;
+	_dialogCloseupNextBlock._blkNr = 0;
+	_dialogCloseupNextBlock._endNr = 0;
+	_dialogCloseupStackPtr = 0;
 
 	init();
 	initItemUseWith();
@@ -129,7 +129,7 @@ void Atdsys::init() {
 	set_handle(ATDS_TXT, ATS_DATA, ATS_TAP_OFF, ATS_TAP_MAX);
 	set_handle(ATDS_TXT, INV_ATS_DATA, INV_TAP_OFF, INV_TAP_MAX);
 	set_handle(ATDS_TXT, AAD_DATA, AAD_TAP_OFF, AAD_TAP_MAX);
-	set_handle(ATDS_TXT, ADS_DATA, ADS_TAP_OFF, ADS_TAP_MAX);
+	set_handle(ATDS_TXT, DIALOG_CLOSEUP_DATA, ADS_TAP_OFF, ADS_TAP_MAX);
 	set_handle(ATDS_TXT, INV_USE_DATA, USE_TAP_OFF, USE_TAP_MAX);
 	_G(gameState).AadSilent = 10;
 	_G(gameState).DelaySpeed = 5;
@@ -693,7 +693,7 @@ void Atdsys::print_aad(int16 scrX, int16 scrY) {
 					if (_atdsv.aad_str != 0)
 						_atdsv.aad_str(_atdsv._diaNr, _aadv._strNr, personId, AAD_STR_END);
 					_aadv._dialog = false;
-					_adsv._autoDia = false;
+					_dialogCloseup._autoDia = false;
 					_aadv._strNr = -1;
 					splitString._next = false;
 				} else {
@@ -784,59 +784,59 @@ void Atdsys::aad_search_dia(int16 diaNr, char **ptr) {
 	}
 }
 
-bool  Atdsys::ads_start(int16 diaNr) {
+bool  Atdsys::startDialogCloseup(int16 diaNr) {
 	bool ret = false;
 
-	load_atds(diaNr, ADS_DATA);
-	bool ende = false;
+	load_atds(diaNr, DIALOG_CLOSEUP_DATA);
+	bool end = false;
 
 	if (_atdsMem[ADS_HANDLE][0] == (char)BLOCKENDE &&
 		    _atdsMem[ADS_HANDLE][1] == (char)BLOCKENDE &&
 		    _atdsMem[ADS_HANDLE][2] == (char)BLOCKENDE)
-		ende = true;
+		end = true;
 
-	if (!ende) {
-		_adsv._ptr = _atdsMem[ADS_HANDLE];
-		_adsv._txtHeader.load(_adsv._ptr);
+	if (!end) {
+		_dialogCloseup._ptr = _atdsMem[ADS_HANDLE];
+		_dialogCloseup._txtHeader.load(_dialogCloseup._ptr);
 
-		if (_adsv._txtHeader._diaNr == diaNr) {
+		if (_dialogCloseup._txtHeader._diaNr == diaNr) {
 			ret = true;
-			_adsv._ptr += AdsTxtHeader::SIZE();
-			_adsv._person.load(_adsv._ptr, _adsv._txtHeader._perNr);
-			_adsv._ptr += _adsv._txtHeader._perNr * AadInfo::SIZE();
-			_adsv._dialog = diaNr;
-			_adsv._strNr = 0;
-			_adsStack[0] = 0;
-			_adsStackPtr = 1;
+			_dialogCloseup._ptr += DialogCloseupTxtHeader::SIZE();
+			_dialogCloseup._person.load(_dialogCloseup._ptr, _dialogCloseup._txtHeader._perNr);
+			_dialogCloseup._ptr += _dialogCloseup._txtHeader._perNr * AadInfo::SIZE();
+			_dialogCloseup._dialog = diaNr;
+			_dialogCloseup._strNr = 0;
+			_dialogCloseupStack[0] = 0;
+			_dialogCloseupStackPtr = 1;
 		}
 	}
 	return ret;
 }
 
-void Atdsys::stop_ads() {
-	_adsv._dialog = -1;
-	_adsv._autoDia = false;
+void Atdsys::stopDialogCloseup() {
+	_dialogCloseup._dialog = -1;
+	_dialogCloseup._autoDia = false;
 }
 
-int16 Atdsys::ads_get_status() {
-	return _adsv._dialog;
+int16 Atdsys::getDialogCloseupStatus() {
+	return _dialogCloseup._dialog;
 }
 
-char **Atdsys::ads_item_ptr(uint16 dialogNum, int16 blockNr, int16 *retNr) {
+char **Atdsys::dialogCloseupItemPtr(uint16 dialogNum, int16 blockNr, int16 *retNr) {
 	*retNr = 0;
-	memset(_ePtr, 0, sizeof(char *) * ADS_MAX_BL_EIN);
-	if (_adsv._dialog != -1) {
-		_adsv._blkPtr = _adsv._ptr;
-		ads_search_block(blockNr, &_adsv._blkPtr);
-		if (_adsv._blkPtr) {
-			for (int16 i = 0; i < ADS_MAX_BL_EIN; i++) {
-				char *tmp_adr = _adsv._blkPtr;
-				ads_search_item(i, &tmp_adr);
-				if (tmp_adr) {
-					char nr = tmp_adr[-1];
-					tmp_adr += sizeof(AadStrHeader);
+	memset(_ePtr, 0, sizeof(char *) * DIALOG_CLOSEUP_MAX);
+	if (_dialogCloseup._dialog != -1) {
+		_dialogCloseup._blockPtr = _dialogCloseup._ptr;
+		dialogCloseupSearchBlock(blockNr, &_dialogCloseup._blockPtr);
+		if (_dialogCloseup._blockPtr) {
+			for (int16 i = 0; i < DIALOG_CLOSEUP_MAX; i++) {
+				char *itemPtr = _dialogCloseup._blockPtr;
+				dialogCloseupSearchItem(i, &itemPtr);
+				if (itemPtr) {
+					char nr = itemPtr[-1];
+					itemPtr += sizeof(AadStrHeader);
 					if (_dialogResource->isItemShown(dialogNum, blockNr, (int16)nr)) {
-						_ePtr[*retNr] = tmp_adr;
+						_ePtr[*retNr] = itemPtr;
 						_eNr[*retNr] = (int16)nr;
 						++(*retNr);
 					}
@@ -848,120 +848,120 @@ char **Atdsys::ads_item_ptr(uint16 dialogNum, int16 blockNr, int16 *retNr) {
 	return _ePtr;
 }
 
-AdsNextBlk *Atdsys::ads_item_choice(uint16 dialogNum, int16 blockNr, int16 itemNr) {
-	_adsnb._blkNr = blockNr;
+DialogCloseupNextBlock *Atdsys::dialogCloseupItemChoice(uint16 dialogNum, int16 blockNr, int16 itemNr) {
+	_dialogCloseupNextBlock._blkNr = blockNr;
 	if (!_aadv._dialog) {
-		if (!_adsv._autoDia) {
-			ads_search_item(_eNr[itemNr], &_adsv._blkPtr);
-			if (_adsv._blkPtr) {
-				if (start_ads_auto_dia(_adsv._blkPtr))
-					_adsv._autoDia = true;
+		if (!_dialogCloseup._autoDia) {
+			dialogCloseupSearchItem(_eNr[itemNr], &_dialogCloseup._blockPtr);
+			if (_dialogCloseup._blockPtr) {
+				if (startAutoDialogCloseup(_dialogCloseup._blockPtr))
+					_dialogCloseup._autoDia = true;
 				if (_dialogResource->hasExitBit(dialogNum, blockNr, _eNr[itemNr])) {
-					stop_ads();
-					_adsnb._endNr = _eNr[itemNr];
-					_adsnb._blkNr = -1;
+					stopDialogCloseup();
+					_dialogCloseupNextBlock._endNr = _eNr[itemNr];
+					_dialogCloseupNextBlock._blkNr = -1;
 				}
 			}
 		}
 	}
 
-	return &_adsnb;
+	return &_dialogCloseupNextBlock;
 }
 
-AdsNextBlk *Atdsys::calc_next_block(uint16 dialogNum, int16 blockNr, int16 itemNr) {
+DialogCloseupNextBlock *Atdsys::calcNextDialogCloseupBlock(uint16 dialogNum, int16 blockNr, int16 itemNr) {
 	if (!_dialogResource->hasShowBit(dialogNum, blockNr, _eNr[itemNr]))
 		_dialogResource->setItemShown(dialogNum, blockNr, _eNr[itemNr], false);
-	_adsnb._endNr = _eNr[itemNr];
+	_dialogCloseupNextBlock._endNr = _eNr[itemNr];
 
 	if (_dialogResource->hasRestartBit(dialogNum, blockNr, _eNr[itemNr])) {
-		_adsnb._blkNr = 0;
+		_dialogCloseupNextBlock._blkNr = 0;
 
-		_adsStackPtr = 0;
+		_dialogCloseupStackPtr = 0;
 	} else {
 		const uint8 nextBlock = _dialogResource->getNextBlock(dialogNum, blockNr, _eNr[itemNr]);
 		if (nextBlock) {
-			_adsnb._blkNr = nextBlock;
+			_dialogCloseupNextBlock._blkNr = nextBlock;
 
-			int16 anzahl = 0;
-			while (!anzahl && _adsnb._blkNr != -1) {
+			int16 option = 0;
+			while (!option && _dialogCloseupNextBlock._blkNr != -1) {
 
-				anzahl = 0;
-				ads_item_ptr(dialogNum, _adsnb._blkNr, &anzahl);
-				if (!anzahl) {
-					_adsnb._blkNr = return_block(dialogNum);
+				option = 0;
+				dialogCloseupItemPtr(dialogNum, _dialogCloseupNextBlock._blkNr, &option);
+				if (!option) {
+					_dialogCloseupNextBlock._blkNr = getDialogCloseupBlock(dialogNum);
 				}
 			}
 		} else {
-			_adsnb._blkNr = return_block(dialogNum);
+			_dialogCloseupNextBlock._blkNr = getDialogCloseupBlock(dialogNum);
 		}
 	}
-	_adsStack[_adsStackPtr] = _adsnb._blkNr;
-	++_adsStackPtr;
+	_dialogCloseupStack[_dialogCloseupStackPtr] = _dialogCloseupNextBlock._blkNr;
+	++_dialogCloseupStackPtr;
 
-	return &_adsnb;
+	return &_dialogCloseupNextBlock;
 }
 
-int16 Atdsys::return_block(uint16 dialogNum) {
-	_adsStackPtr -= 1;
+int16 Atdsys::getDialogCloseupBlock(uint16 dialogNum) {
+	_dialogCloseupStackPtr -= 1;
 	int16 ret = -1;
-	bool ende = false;
-	while (_adsStackPtr >= 0 && !ende) {
-		short blk_nr = _adsStack[_adsStackPtr];
-		int16 anz;
-		ads_item_ptr(dialogNum, blk_nr, &anz);
-		if (anz) {
+	bool end = false;
+	while (_dialogCloseupStackPtr >= 0 && !end) {
+		short blk_nr = _dialogCloseupStack[_dialogCloseupStackPtr];
+		int16 option;
+		dialogCloseupItemPtr(dialogNum, blk_nr, &option);
+		if (option) {
 			ret = blk_nr;
-			ende = true;
+			end = true;
 		} else {
-			--_adsStackPtr;
+			--_dialogCloseupStackPtr;
 		}
 	}
 
-	++_adsStackPtr;
+	++_dialogCloseupStackPtr;
 	return ret;
 }
 
-void Atdsys::ads_search_block(int16 blockNr, char **ptr) {
+void Atdsys::dialogCloseupSearchBlock(int16 blockNr, char **ptr) {
 	char *start_ptr = *ptr;
-	bool ende = false;
-	while (!ende) {
+	bool end = false;
+	while (!end) {
 		if (*start_ptr == (char)blockNr) {
-			ende = true;
+			end = true;
 			*ptr = start_ptr;
 		} else {
 			start_ptr += 2 + sizeof(AadStrHeader);
 			while (*start_ptr++ != ATDS_END_BLOCK) {}
 			if (start_ptr[0] == ATDS_END &&
 			        start_ptr[1] == ATDS_END) {
-				ende = true;
+				end = true;
 				*ptr = nullptr;
 			}
 		}
 	}
 }
 
-void Atdsys::ads_search_item(int16 itemNr, char **blkAdr) {
+void Atdsys::dialogCloseupSearchItem(int16 itemNr, char **blkAdr) {
 	char *start_ptr = *blkAdr + 1;
-	bool ende = false;
-	while (!ende) {
+	bool end = false;
+	while (!end) {
 		if (*start_ptr == itemNr) {
-			ende = true;
+			end = true;
 			*blkAdr = start_ptr + 1;
 		} else {
 			start_ptr += 1 + sizeof(AadStrHeader);
 			while (*start_ptr++ != ATDS_END_ENTRY) {}
 			if (*start_ptr == ATDS_END_BLOCK) {
-				ende = true;
+				end = true;
 				*blkAdr = nullptr;
 			}
 		}
 	}
 }
 
-int16 Atdsys::start_ads_auto_dia(char *itemAdr) {
+int16 Atdsys::startAutoDialogCloseup(char *itemAdr) {
 	_aadv._dialog = false;
 	if (itemAdr) {
-		_aadv._person = _adsv._person;
+		_aadv._person = _dialogCloseup._person;
 		_aadv._ptr = itemAdr;
 		_aadv._dialog = true;
 		_aadv._strNr = 0;
@@ -970,7 +970,7 @@ int16 Atdsys::start_ads_auto_dia(char *itemAdr) {
 		int16 txt_len;
 		aad_get_zeilen(_aadv._ptr, &txt_len);
 		_aadv._delayCount = get_delay(txt_len);
-		_atdsv._diaNr = _adsv._txtHeader._diaNr + 10000;
+		_atdsv._diaNr = _dialogCloseup._txtHeader._diaNr + 10000;
 
 		if (_atdsv.aad_str != nullptr)
 			_atdsv.aad_str(_atdsv._diaNr, 0, _aadv._strHeader->_akPerson, AAD_STR_START);
@@ -983,11 +983,11 @@ int16 Atdsys::start_ads_auto_dia(char *itemAdr) {
 	return _aadv._dialog;
 }
 
-void Atdsys::hide_item(int16 diaNr, int16 blockNr, int16 itemNr) {
+void Atdsys::hideDialogCloseupItem(int16 diaNr, int16 blockNr, int16 itemNr) {
 	_dialogResource->setItemShown(diaNr, blockNr, itemNr, false);
 }
 
-void Atdsys::show_item(int16 diaNr, int16 blockNr, int16 itemNr) {
+void Atdsys::showDialogCloseupItem(int16 diaNr, int16 blockNr, int16 itemNr) {
 	_dialogResource->setItemShown(diaNr, blockNr, itemNr, true);
 }
 
diff --git a/engines/chewy/atds.h b/engines/chewy/atds.h
index 0a260215ea0..b949771c68b 100644
--- a/engines/chewy/atds.h
+++ b/engines/chewy/atds.h
@@ -37,7 +37,7 @@ namespace Chewy {
 #define AAD_STR_END 1
 #define AAD_DATA 0
 #define ATS_DATA 1
-#define ADS_DATA 2
+#define DIALOG_CLOSEUP_DATA 2
 #define INV_USE_DATA 4
 #define INV_ATS_DATA 6
 
@@ -74,9 +74,8 @@ namespace Chewy {
 
 #define CONTROL_BYTE 0xff
 
-#define MAX_ADS_DIALOG 500
-#define ADS_MAX_BL_EIN 6
-#define ADS_STACK_SIZE 50
+#define DIALOG_CLOSEUP_MAX 6
+#define DIALOG_CLOSEUP_STACK_SIZE 50
 
 #define ADS_EXIT_BIT 1
 #define ADS_SHOW_BIT 2
@@ -150,7 +149,8 @@ struct AadVar {
 	int16 _silentCount;
 };
 
-struct AdsTxtHeader {
+// ADS (dialog closeup) header
+struct DialogCloseupTxtHeader {
 	int16 _diaNr;
 	int16 _perNr;
 	int16 _aMov;
@@ -160,19 +160,19 @@ struct AdsTxtHeader {
 	static constexpr int SIZE() { return 8; }
 };
 
-struct AdsVar {
+struct DialogCloseupVariables {
 	int16 _dialog;
 	int16 _autoDia;
-	AdsTxtHeader _txtHeader;
+	DialogCloseupTxtHeader _txtHeader;
 	AadInfoArray _person;
 	char *_ptr;
-	char *_blkPtr;
+	char *_blockPtr;
 	int16 _strNr;
 	int16 _delayCount;
 	int16 _silentCount;
 };
 
-struct AdsNextBlk {
+struct DialogCloseupNextBlock {
 	int16 _blkNr;
 	int16 _endNr;
 };
@@ -251,18 +251,20 @@ public:
 	void set_string_end_func(void (*strFunc)(int16 diaNr, int16 strNr, int16 personNr, int16 mode));
 	void aad_search_dia(int16 diaNr, char **ptr);
 	int16 aad_get_zeilen(char *str, int16 *txtLen);
-	bool ads_start(int16 diaNr);
-	void stop_ads();
-	char **ads_item_ptr(uint16 dialogNum, int16 blockNr, int16 *retNr);
-	AdsNextBlk *ads_item_choice(uint16 dialogNum, int16 blockNr, int16 itemNr);
-	AdsNextBlk *calc_next_block(uint16 dialogNum, int16 blockNr, int16 itemNr);
-	int16 ads_get_status();
-	void hide_item(int16 diaNr, int16 blockNr, int16 itemNr);
-	void show_item(int16 diaNr, int16 blockNr, int16 itemNr);
-	int16 return_block(uint16 dialogNum);
-	void ads_search_block(int16 blockNr, char **ptr);
-	void ads_search_item(int16 itemNr, char **blkAdr);
-	int16 start_ads_auto_dia(char *itemAdr);
+
+	bool startDialogCloseup(int16 diaNr);
+	void stopDialogCloseup();
+	char **dialogCloseupItemPtr(uint16 dialogNum, int16 blockNr, int16 *retNr);
+	DialogCloseupNextBlock *dialogCloseupItemChoice(uint16 dialogNum, int16 blockNr, int16 itemNr);
+	DialogCloseupNextBlock *calcNextDialogCloseupBlock(uint16 dialogNum, int16 blockNr, int16 itemNr);
+	int16 getDialogCloseupStatus();
+	void hideDialogCloseupItem(int16 diaNr, int16 blockNr, int16 itemNr);
+	void showDialogCloseupItem(int16 diaNr, int16 blockNr, int16 itemNr);
+	int16 getDialogCloseupBlock(uint16 dialogNum);
+	void dialogCloseupSearchBlock(int16 blockNr, char **ptr);
+	void dialogCloseupSearchItem(int16 itemNr, char **blkAdr);
+	int16 startAutoDialogCloseup(char *itemAdr);
+
 	int16 calc_inv_no_use(int16 curInv, int16 testNr);
 	int8 getStereoPos(int16 x);
 	void enableEvents(bool nr) {
@@ -289,13 +291,13 @@ private:
 	uint8 *_ats_sheader = nullptr;
 	AadVar _aadv;
 	AtsVar _atsv;
-	AdsVar _adsv;
+	DialogCloseupVariables _dialogCloseup;
 	AtdsVar _atdsv;
-	char *_ePtr[ADS_MAX_BL_EIN] = { nullptr };
-	int16 _eNr[ADS_MAX_BL_EIN] = { 0 };
-	AdsNextBlk _adsnb;
-	uint8 _adsStack[ADS_STACK_SIZE] = { 0 };
-	int16 _adsStackPtr;
+	char *_ePtr[DIALOG_CLOSEUP_MAX] = { nullptr };
+	int16 _eNr[DIALOG_CLOSEUP_MAX] = { 0 };
+	DialogCloseupNextBlock _dialogCloseupNextBlock;
+	uint8 _dialogCloseupStack[DIALOG_CLOSEUP_STACK_SIZE] = { 0 };
+	int16 _dialogCloseupStackPtr;
 
 	SplitStringInit _ssi[AAD_MAX_PERSON] = {
 		{ 0, 100, 0 },
diff --git a/engines/chewy/globals.h b/engines/chewy/globals.h
index 02d23cb408d..98a703125c8 100644
--- a/engines/chewy/globals.h
+++ b/engines/chewy/globals.h
@@ -130,7 +130,7 @@ public:
 	byte *_workpage = nullptr;
 	byte *_workptr = nullptr;
 	byte *_spblende = nullptr;
-	char **_ads_item_ptr = nullptr;
+	char **_dialogCloseupItemPtr = nullptr;
 
 	int16 _ads_dia_nr = 0;
 	int16 _ads_item_nr = 0;
@@ -439,7 +439,7 @@ uint16 exit_flip_flop(int16 ani_nr, int16 eib_nr1, int16 eib_nr2,
                         int16 ats_nr1, int16 ats_nr2, int16 sib_nr,
                         int16 spr_nr1, int16 spr_nr2, int16 flag);
 
-int16 loadAdsDia(int16 diaNr);
+int16 loadDialogCloseup(int16 diaNr);
 
 void setSsiPos();
 
@@ -481,7 +481,7 @@ void startAadWait(int16 diaNr);
 
 void start_aad(int16 diaNr);
 void aadWait(int16 strNr);
-void startAdsWait(int16 diaNr);
+void startDialogCloseupWait(int16 diaNr);
 void start_aad(int16 diaNr, int16 ssiNr);
 void wait_auto_obj(int16 nr);
 
diff --git a/engines/chewy/main.cpp b/engines/chewy/main.cpp
index efe3945aeed..f5926167cd5 100644
--- a/engines/chewy/main.cpp
+++ b/engines/chewy/main.cpp
@@ -486,7 +486,7 @@ void setupScreen(SetupScreenMode mode) {
 			                 , _G(scr_width));
 		}
 
-		if (_G(flags).AdsDialog)
+		if (_G(flags).DialogCloseup)
 			adsMenu();
 		if (_G(mouseLeftClick)) {
 			if (_G(menu_item) == CUR_WALK) {
@@ -1864,7 +1864,7 @@ bool is_chewy_busy() {
 	bool ret = true;
 	if (!_G(atds)->atsShown()) {
 		if (_G(atds)->aadGetStatus() == -1) {
-			if (_G(atds)->ads_get_status() == -1) {
+			if (_G(atds)->getDialogCloseupStatus() == -1) {
 				if (!_G(mov)->auto_go_status()) {
 					if (!_G(moveState)[P_CHEWY].Count) {
 						if (!_G(flags).ExitMov) {
diff --git a/engines/chewy/menus.cpp b/engines/chewy/menus.cpp
index 23cfab1ea82..74e011769b7 100644
--- a/engines/chewy/menus.cpp
+++ b/engines/chewy/menus.cpp
@@ -252,7 +252,7 @@ void adsMenu() {
 	int16 curYStart;
 	int16 col;
 
-	if (_G(flags).AdsDialog) {
+	if (_G(flags).DialogCloseup) {
 		_G(flags).ShowAtsInvTxt = false;
 		_G(flags).MainInput = false;
 		if (_G(ads_item_nr) > 4)
@@ -280,7 +280,7 @@ void adsMenu() {
 					col = 255;
 				else
 					col = 14;
-				_G(out)->printxy(4, curYStart - i * 10, col, 300, 0, _G(ads_item_ptr)[i]);
+				_G(out)->printxy(4, curYStart - i * 10, col, 300, 0, _G(dialogCloseupItemPtr)[i]);
 			}
 		}
 
@@ -291,16 +291,16 @@ void adsMenu() {
 				_G(cur_display) = false;
 				_G(ads_push) = true;
 				g_events->_mousePos.y = 159;
-				AdsNextBlk *an_blk = _G(atds)->ads_item_choice(_G(ads_dia_nr), _G(ads_blk_nr), curY);
+				DialogCloseupNextBlock *an_blk = _G(atds)->dialogCloseupItemChoice(_G(ads_dia_nr), _G(ads_blk_nr), curY);
 				if (an_blk->_blkNr == -1) {
 					selectDialogOption(_G(ads_dia_nr), _G(ads_blk_nr), an_blk->_endNr);
 					ads_ende(_G(ads_dia_nr), _G(ads_blk_nr), an_blk->_endNr);
 					stop_ads_dialog();
 				} else {
-					an_blk = _G(atds)->calc_next_block(_G(ads_dia_nr), _G(ads_blk_nr), curY);
+					an_blk = _G(atds)->calcNextDialogCloseupBlock(_G(ads_dia_nr), _G(ads_blk_nr), curY);
 					selectDialogOption(_G(ads_dia_nr), _G(ads_blk_nr), an_blk->_endNr);
 					_G(ads_blk_nr) = an_blk->_blkNr;
-					_G(ads_item_ptr) = _G(atds)->ads_item_ptr(_G(ads_dia_nr), _G(ads_blk_nr), &_G(ads_item_nr));
+					_G(dialogCloseupItemPtr) = _G(atds)->dialogCloseupItemPtr(_G(ads_dia_nr), _G(ads_blk_nr), &_G(ads_item_nr));
 				}
 				_G(det)->stop_detail(_G(talk_start_ani));
 				_G(det)->showStaticSpr(_G(talk_hide_static));
@@ -322,9 +322,9 @@ void stop_ads_dialog() {
 	_G(cur_display) = true;
 	_G(flags).ShowAtsInvTxt = true;
 	_G(flags).MainInput = true;
-	_G(flags).AdsDialog = false;
+	_G(flags).DialogCloseup = false;
 	_G(mouseLeftClick) = false;
-	_G(atds)->stop_ads();
+	_G(atds)->stopDialogCloseup();
 	if (_G(minfo).button)
 		_G(flags).mainMouseFlag = 1;
 }
diff --git a/engines/chewy/rooms/room08.cpp b/engines/chewy/rooms/room08.cpp
index c1a26032368..819d8ba26a3 100644
--- a/engines/chewy/rooms/room08.cpp
+++ b/engines/chewy/rooms/room08.cpp
@@ -174,12 +174,12 @@ void Room8::talk_nimoy() {
 		int16 diaNr = _G(gameState).R8GipsWurf ? 2 : 1;
 
 		if (!_G(gameState).R8GTuer)
-			loadAdsDia(diaNr);
+			loadDialogCloseup(diaNr);
 		else
 			startAadWait(61);
 	} else {
 		startAadWait(603);
-		loadAdsDia(6);
+		loadDialogCloseup(6);
 	}
 
 	_G(flags).NoScroll = false;
diff --git a/engines/chewy/rooms/room11.cpp b/engines/chewy/rooms/room11.cpp
index 1720f9e0302..8006039df40 100644
--- a/engines/chewy/rooms/room11.cpp
+++ b/engines/chewy/rooms/room11.cpp
@@ -107,7 +107,7 @@ void Room11::talk_debug() {
 	if (_G(gameState).R12ChewyBork) {
 		_G(flags).AutoAniPlay = true;
 		autoMove(8, P_CHEWY);
-		startAdsWait(5);
+		startDialogCloseupWait(5);
 		_G(menu_item) = CUR_WALK;
 		cursorChoice(CUR_WALK);
 
@@ -156,7 +156,7 @@ int16 Room11::scanner() {
 			cursorChoice(_G(menu_item));
 			startAadWait(12);
 			showCur();
-			loadAdsDia(3);
+			loadDialogCloseup(3);
 		} else if (!_G(gameState).inv_cur) {
 			if (!_G(gameState).R11TerminalOk) {
 				actionFl = true;
@@ -167,7 +167,7 @@ int16 Room11::scanner() {
 				startAadWait(12);
 				_G(menu_item) = CUR_TALK;
 				cursorChoice(_G(menu_item));
-				loadAdsDia(3);
+				loadDialogCloseup(3);
 			}
 		}
 	}
diff --git a/engines/chewy/rooms/room14.cpp b/engines/chewy/rooms/room14.cpp
index f6c7b5d9a18..d1fa687895d 100644
--- a/engines/chewy/rooms/room14.cpp
+++ b/engines/chewy/rooms/room14.cpp
@@ -117,7 +117,7 @@ void Room14::talk_eremit()  {
 		_G(flags).AutoAniPlay = true;
 
 		if (_G(gameState).R14Translator) {
-			loadAdsDia(0);
+			loadDialogCloseup(0);
 			_G(obj)->show_sib(46);
 		} else {
 			hideCur();
diff --git a/engines/chewy/rooms/room35.cpp b/engines/chewy/rooms/room35.cpp
index 2fa3be379c9..fd08525a74d 100644
--- a/engines/chewy/rooms/room35.cpp
+++ b/engines/chewy/rooms/room35.cpp
@@ -131,7 +131,7 @@ void Room35::talk_cat() {
 		_G(gameState)._personHide[P_CHEWY] = true;
 		switchRoom(36);
 		showCur();
-		startAdsWait(dia_nr);
+		startDialogCloseupWait(dia_nr);
 		_G(gameState)._personHide[P_CHEWY] = false;
 		switchRoom(35);
 
diff --git a/engines/chewy/rooms/room37.cpp b/engines/chewy/rooms/room37.cpp
index 22258932087..f1aaa611987 100644
--- a/engines/chewy/rooms/room37.cpp
+++ b/engines/chewy/rooms/room37.cpp
@@ -314,7 +314,7 @@ void Room37::hahn_dia() {
 	_G(gameState).scrollx = 0;
 	_G(gameState).scrolly = 0;
 	switchRoom(38);
-	startAdsWait(9);
+	startDialogCloseupWait(9);
 	_G(gameState)._personHide[P_CHEWY] = false;
 	_G(flags).LoadGame = true;
 	_G(gameState).scrollx = tmp_scrollx;
diff --git a/engines/chewy/rooms/room41.cpp b/engines/chewy/rooms/room41.cpp
index 51572217370..5c3362175a1 100644
--- a/engines/chewy/rooms/room41.cpp
+++ b/engines/chewy/rooms/room41.cpp
@@ -99,7 +99,7 @@ void Room41::talk_hoggy1() {
 
 	} else if (!_G(gameState).R41Einbruch) {
 		showCur();
-		startAdsWait(11);
+		startDialogCloseupWait(11);
 
 	} else if (_G(gameState).R41Einbruch) {
 		if (!_G(gameState).R41BruchInfo) {
@@ -202,7 +202,7 @@ int16 Room41::use_lola() {
 
 		_G(atds)->delControlBit(267, ATS_ACTIVE_BIT);
 		_G(atds)->set_ats_str(267, 1, ATS_DATA);
-		_G(atds)->hide_item(11, 0, 3);
+		_G(atds)->hideDialogCloseupItem(11, 0, 3);
 		showCur();
 	}
 
@@ -244,7 +244,7 @@ void Room41::sub_dia() {
 
 	if (_G(gameState).R41LolaOk) {
 		startAadWait(163);
-		_G(atds)->hide_item(11, 0, 2);
+		_G(atds)->hideDialogCloseupItem(11, 0, 2);
 		stop_ads_dialog();
 		autoMove(5, P_CHEWY);
 		new_invent_2_cur(PAPIER_INV);
diff --git a/engines/chewy/rooms/room42.cpp b/engines/chewy/rooms/room42.cpp
index aa77e84f8db..1676a94ac63 100644
--- a/engines/chewy/rooms/room42.cpp
+++ b/engines/chewy/rooms/room42.cpp
@@ -172,7 +172,7 @@ void Room42::talkToStationEmployee() {
 		dia_nr = 14;
 	}
 
-	startAdsWait(dia_nr);
+	startDialogCloseupWait(dia_nr);
 }
 
 void Room42::dialogWithStationEmployee(int16 str_end_nr) {
diff --git a/engines/chewy/rooms/room55.cpp b/engines/chewy/rooms/room55.cpp
index c5ffe74aa16..657961e51b6 100644
--- a/engines/chewy/rooms/room55.cpp
+++ b/engines/chewy/rooms/room55.cpp
@@ -280,7 +280,7 @@ void Room55::get_job() {
 	switchRoom(61);
 
 	showCur();
-	startAdsWait(15);
+	startDialogCloseupWait(15);
 	_G(gameState)._personHide[P_CHEWY] = false;
 	_G(flags).LoadGame = true;
 	_G(gameState).scrollx = oldScrollx;
diff --git a/engines/chewy/rooms/room56.cpp b/engines/chewy/rooms/room56.cpp
index 207074f3174..82b76e06c07 100644
--- a/engines/chewy/rooms/room56.cpp
+++ b/engines/chewy/rooms/room56.cpp
@@ -239,7 +239,7 @@ int16 Room56::use_taxi() {
 void Room56::talk_man() {
 	autoMove(3, P_CHEWY);
 	if (!_G(gameState).R56AbfahrtOk) {
-		startAdsWait(16);
+		startDialogCloseupWait(16);
 	} else if (!_G(gameState).R62Flucht) {
 		hideCur();
 		startAadWait(343);
diff --git a/engines/chewy/rooms/room63.cpp b/engines/chewy/rooms/room63.cpp
index c5a9e5773e0..89a7df04b29 100644
--- a/engines/chewy/rooms/room63.cpp
+++ b/engines/chewy/rooms/room63.cpp
@@ -255,7 +255,7 @@ void Room63::talk_girl() {
 	_G(det)->stop_detail(12);
 	startSetAILWait(13, 1, ANI_FRONT);
 	_G(det)->set_static_ani(14, -1);
-	startAdsWait(17);
+	startDialogCloseupWait(17);
 	_G(det)->del_static_ani(14);
 	_G(det)->startDetail(12, 255, ANI_FRONT);
 }
diff --git a/engines/chewy/rooms/room65.cpp b/engines/chewy/rooms/room65.cpp
index a60e758c8ca..df2c68dcf34 100644
--- a/engines/chewy/rooms/room65.cpp
+++ b/engines/chewy/rooms/room65.cpp
@@ -51,7 +51,7 @@ void Room65::entry() {
 		startAadWait(_G(gameState).PersonDia[P_HOWARD]);
 		showCur();
 	} else {
-		startAdsWait(_G(gameState).PersonDia[P_HOWARD] - 10000);
+		startDialogCloseupWait(_G(gameState).PersonDia[P_HOWARD] - 10000);
 	}
 	_G(flags).LoadGame = true;
 	show_person();
diff --git a/engines/chewy/rooms/room67.cpp b/engines/chewy/rooms/room67.cpp
index 35033bec369..800f71da52a 100644
--- a/engines/chewy/rooms/room67.cpp
+++ b/engines/chewy/rooms/room67.cpp
@@ -146,7 +146,7 @@ int16 Room67::talk_papagei() {
 			showCur();
 
 			_G(atds)->set_split_win(2, 270 - _G(gameState).scrollx, 10);
-			startAdsWait(19);
+			startDialogCloseupWait(19);
 			_G(room)->set_timer_status(1, TIMER_START);
 		} else if (_G(menu_item) == CUR_NICHELLE) {
 			startAadWait(380);
@@ -156,7 +156,7 @@ int16 Room67::talk_papagei() {
 			showCur();
 
 			_G(atds)->set_split_win(2, 270 - _G(gameState).scrollx, 10);
-			startAdsWait(18);
+			startDialogCloseupWait(18);
 			_G(room)->set_timer_status(1, TIMER_START);
 		} else if (_G(menu_item) == CUR_USE) {
 			hideCur();
diff --git a/engines/chewy/rooms/room68.cpp b/engines/chewy/rooms/room68.cpp
index c51a79fc255..c14af72c5b5 100644
--- a/engines/chewy/rooms/room68.cpp
+++ b/engines/chewy/rooms/room68.cpp
@@ -230,7 +230,7 @@ void Room68::talk_keeper() {
 	int16 x = _G(moveState)[P_CHEWY].Xypos[0] - _G(gameState).scrollx + _G(spieler_mi)[P_CHEWY].HotX;
 	int16 y = _G(moveState)[P_CHEWY].Xypos[1] - _G(gameState).scrolly;
 	_G(atds)->set_split_win(3, x, y);
-	startAdsWait(20);
+	startDialogCloseupWait(20);
 	_G(cur_hide_flag) = false;
 	hideCur();
 	_G(det)->del_static_ani(16);
@@ -416,7 +416,7 @@ void Room68::talk_papagei() {
 	showCur();
 
 	_G(atds)->set_split_win(2, 60, 80);
-	startAdsWait(18);
+	startDialogCloseupWait(18);
 }
 
 } // namespace Rooms
diff --git a/engines/chewy/rooms/room76.cpp b/engines/chewy/rooms/room76.cpp
index 6a57c1e8abd..f1c4b0db10f 100644
--- a/engines/chewy/rooms/room76.cpp
+++ b/engines/chewy/rooms/room76.cpp
@@ -206,7 +206,7 @@ int Room76::proc7() {
 
 		startAadWait(427);
 		showCur();
-		startAdsWait(21);
+		startDialogCloseupWait(21);
 		hideCur();
 		startAadWait(428);
 		showCur();
diff --git a/engines/chewy/rooms/room84.cpp b/engines/chewy/rooms/room84.cpp
index a8808baecf3..c96d76af14c 100644
--- a/engines/chewy/rooms/room84.cpp
+++ b/engines/chewy/rooms/room84.cpp
@@ -176,7 +176,7 @@ void Room84::talk1() {
 	_G(flags).NoScroll = true;
 	setPersonSpr(P_LEFT, P_CHEWY);
 	auto_scroll(150, 0);
-	startAdsWait(22);
+	startDialogCloseupWait(22);
 	_G(flags).NoScroll = false;
 }
 
diff --git a/engines/chewy/rooms/room93.cpp b/engines/chewy/rooms/room93.cpp
index 8535126aadb..ea58bad20ce 100644
--- a/engines/chewy/rooms/room93.cpp
+++ b/engines/chewy/rooms/room93.cpp
@@ -40,7 +40,7 @@ void Room93::entry() {
 	_G(det)->del_static_ani(0);
 	startSetAILWait(3, 1, ANI_FRONT);
 	_G(det)->set_static_ani(1, -1);
-	startAdsWait(27);
+	startDialogCloseupWait(27);
 
 	if (!_G(gameState).flags37_40) {
 		_G(det)->del_static_ani(1);
diff --git a/engines/chewy/sprite.cpp b/engines/chewy/sprite.cpp
index b6c36148a08..d119d99dfac 100644
--- a/engines/chewy/sprite.cpp
+++ b/engines/chewy/sprite.cpp
@@ -571,12 +571,12 @@ void start_aad(int16 diaNr, int16 ssiNr) {
 	_G(atds)->start_aad(diaNr);
 }
 
-void startAdsWait(int16 diaNr) {
-	if (!_G(flags).AdsDialog) {
+void startDialogCloseupWait(int16 diaNr) {
+	if (!_G(flags).DialogCloseup) {
 		_G(menu_item) = CUR_TALK;
 		cursorChoice(_G(menu_item));
-		loadAdsDia(diaNr);
-		while (_G(flags).AdsDialog && !SHOULD_QUIT) {
+		loadDialogCloseup(diaNr);
+		while (_G(flags).DialogCloseup && !SHOULD_QUIT) {
 			setupScreen(DO_SETUP);
 		}
 	}
diff --git a/engines/chewy/t_event.cpp b/engines/chewy/t_event.cpp
index 38c9525a253..be9082c5de5 100644
--- a/engines/chewy/t_event.cpp
+++ b/engines/chewy/t_event.cpp
@@ -29,16 +29,16 @@
 
 namespace Chewy {
 
-int16 loadAdsDia(int16 diaNr) {
+int16 loadDialogCloseup(int16 diaNr) {
 	int16 ret = false;
 
-	if (_G(flags).AdsDialog == false) {
-		bool tmp = _G(atds)->ads_start(diaNr);
+	if (_G(flags).DialogCloseup == false) {
+		bool tmp = _G(atds)->startDialogCloseup(diaNr);
 		if (tmp == true) {
 			ret = true;
 			_G(ads_blk_nr) = 0;
-			_G(ads_item_ptr) = _G(atds)->ads_item_ptr(diaNr, _G(ads_blk_nr), &_G(ads_item_nr));
-			_G(flags).AdsDialog = true;
+			_G(dialogCloseupItemPtr) = _G(atds)->dialogCloseupItemPtr(diaNr, _G(ads_blk_nr), &_G(ads_item_nr));
+			_G(flags).DialogCloseup = true;
 			_G(ads_push) = true;
 			_G(ads_tmp_dsp) = _G(gameState).DispFlag;
 			_G(gameState).DispFlag = false;
@@ -1185,7 +1185,7 @@ void selectDialogOption(int16 diaNr, int16 blkNr, int16 strEndNr) {
 
 		case 17:
 			if (blkNr == 0 && strEndNr == 2)
-				_G(atds)->show_item(17, 0, 1);
+				_G(atds)->showDialogCloseupItem(17, 0, 1);
 
 			break;
 
@@ -2767,7 +2767,7 @@ void calc_person_dia(int16 p_nr) {
 					_G(stopAutoMove)[P_NICHELLE] = _G(gameState).PersonDiaRoom[P_NICHELLE];
 					showCur();
 				} else {
-					startAdsWait(_G(gameState).PersonDia[P_NICHELLE] - 10000);
+					startDialogCloseupWait(_G(gameState).PersonDia[P_NICHELLE] - 10000);
 				}
 			}
 		}
diff --git a/engines/chewy/text.cpp b/engines/chewy/text.cpp
index 3fd81352c3b..0a920246453 100644
--- a/engines/chewy/text.cpp
+++ b/engines/chewy/text.cpp
@@ -95,7 +95,7 @@ TextEntry *Text::getText(uint chunk, uint entry, int type, int subEntry) {
 		chunk += kADSTextMax;
 		isText = true;
 		break;
-	case ADS_DATA:
+	case DIALOG_CLOSEUP_DATA:
 		// No change - chunk starts from 0
 		break;
 	case INV_USE_DATA:
diff --git a/engines/chewy/types.h b/engines/chewy/types.h
index d01a9018891..9cf28399a90 100644
--- a/engines/chewy/types.h
+++ b/engines/chewy/types.h
@@ -565,7 +565,7 @@ struct Flags {
 	uint16 AtsAction : 1;
 	uint16 AdsAction : 1;
 	uint16 AtsText : 1;
-	uint16 AdsDialog : 1;
+	uint16 DialogCloseup : 1;
 	uint16 ShowAtsInvTxt : 1;
 	uint16 MainInput : 1;
 	uint16 InventMenu : 1;


Commit: 2204bddd259b0c1dc68b283035f746782f56689c
    https://github.com/scummvm/scummvm/commit/2204bddd259b0c1dc68b283035f746782f56689c
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-06-21T18:11:46+03:00

Commit Message:
CHEWY: Use a direct variable for text delay

Changed paths:
    engines/chewy/atds.cpp
    engines/chewy/atds.h


diff --git a/engines/chewy/atds.cpp b/engines/chewy/atds.cpp
index 65dfe3ea71d..cc61f75efbd 100644
--- a/engines/chewy/atds.cpp
+++ b/engines/chewy/atds.cpp
@@ -84,8 +84,7 @@ Atdsys::Atdsys() {
 	_dialogCloseup._autoDia = false;
 	_dialogCloseup._strNr = -1;
 	_dialogCloseup._silentCount = false;
-	_tmpDelay = 1;
-	_atdsv._delay = &_tmpDelay;
+	_atdsv._delay = 1;
 	_atdsv._silent = false;
 	_atdsv._diaNr = -1;
 	_atdsv.aad_str = nullptr;
@@ -162,7 +161,7 @@ void Atdsys::initItemUseWith() {
 }
 
 void Atdsys::set_delay(int16 *delay, int16 silent) {
-	_atdsv._delay = delay;
+	_atdsv._delay = *delay;
 	_atdsv._silent = silent;
 }
 
@@ -180,7 +179,7 @@ int16 Atdsys::get_delay(int16 txt_len) {
 	if (txt_len > maxLen)
 		txt_len = maxLen;
 
-	int16 ret = *_atdsv._delay * (txt_len + z_len);
+	int16 ret = _atdsv._delay * (txt_len + z_len);
 	return ret;
 }
 
diff --git a/engines/chewy/atds.h b/engines/chewy/atds.h
index b949771c68b..1230fdc4354 100644
--- a/engines/chewy/atds.h
+++ b/engines/chewy/atds.h
@@ -90,7 +90,7 @@ struct AdsDiaHeaders {
 
 struct AtdsVar {
 	int16 _silent = 0;
-	int16 *_delay = nullptr;
+	int16 _delay = 1;
 	int16 _diaNr = 0;
 
 	bool _eventsEnabled = false;
@@ -315,7 +315,6 @@ private:
 	char *_splitPtr[MAX_STR_SPLIT] = { nullptr };
 	int16 _splitX[MAX_STR_SPLIT] = { 0 };
 	int16 _invBlockNr;
-	int16 _tmpDelay;
 	int16 _mousePush = 0;
 	int _printDelayCount1 = 0;
 	DialogResource *_dialogResource;


Commit: 0f2a74fad634c3584db6a2c413a4fa53917a6424
    https://github.com/scummvm/scummvm/commit/0f2a74fad634c3584db6a2c413a4fa53917a6424
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-06-21T18:11:47+03:00

Commit Message:
CHEWY: More renaming for the dialog closeup code

Changed paths:
    engines/chewy/globals.h
    engines/chewy/main.cpp
    engines/chewy/menus.cpp
    engines/chewy/rooms/room41.cpp
    engines/chewy/t_event.cpp


diff --git a/engines/chewy/globals.h b/engines/chewy/globals.h
index 98a703125c8..b59250aec34 100644
--- a/engines/chewy/globals.h
+++ b/engines/chewy/globals.h
@@ -415,9 +415,9 @@ void remove_inventory(int16 nr);
 void getDisplayCoord(int16 *x, int16 *y, int16 nr);
 void calcTxtXy(int16 *x, int16 *y, char *txtAdr, int16 txtNr);
 void calcTxtXy(int16 *x, int16 *y, Common::StringArray &desc);
-void adsMenu();
+void handleDialogCloseupMenu();
 
-void stop_ads_dialog();
+void stopDialogCloseupDialog();
 
 void play_scene_ani(int16 nr, int16 mode);
 
@@ -447,7 +447,7 @@ int16 atsAction(int16 txtNr, int16 txtMode, int16 MODE);
 
 void selectDialogOption(int16 diaNr, int16 blkNr, int16 strEndNr);
 
-void ads_ende(int16 diaNr, int16 blkNr, int16 strEndNr);
+void endDialogCloseup(int16 diaNr, int16 blkNr, int16 strEndNr);
 
 void atdsStringStart(int16 diaNr, int16 strNr, int16 personNr,
                        int16 mode);
diff --git a/engines/chewy/main.cpp b/engines/chewy/main.cpp
index f5926167cd5..eec36498e90 100644
--- a/engines/chewy/main.cpp
+++ b/engines/chewy/main.cpp
@@ -487,7 +487,7 @@ void setupScreen(SetupScreenMode mode) {
 		}
 
 		if (_G(flags).DialogCloseup)
-			adsMenu();
+			handleDialogCloseupMenu();
 		if (_G(mouseLeftClick)) {
 			if (_G(menu_item) == CUR_WALK) {
 				if (_G(cur_ausgang_flag)) {
diff --git a/engines/chewy/menus.cpp b/engines/chewy/menus.cpp
index 74e011769b7..7c32d53c9ac 100644
--- a/engines/chewy/menus.cpp
+++ b/engines/chewy/menus.cpp
@@ -248,7 +248,7 @@ void autoMenu(int16 *x, int16 *y, int16 lineNr, int16 height, char *text, int16
 
 #define ADS_WIN 0,153,20,3,60,1
 
-void adsMenu() {
+void handleDialogCloseupMenu() {
 	int16 curYStart;
 	int16 col;
 
@@ -294,8 +294,8 @@ void adsMenu() {
 				DialogCloseupNextBlock *an_blk = _G(atds)->dialogCloseupItemChoice(_G(ads_dia_nr), _G(ads_blk_nr), curY);
 				if (an_blk->_blkNr == -1) {
 					selectDialogOption(_G(ads_dia_nr), _G(ads_blk_nr), an_blk->_endNr);
-					ads_ende(_G(ads_dia_nr), _G(ads_blk_nr), an_blk->_endNr);
-					stop_ads_dialog();
+					endDialogCloseup(_G(ads_dia_nr), _G(ads_blk_nr), an_blk->_endNr);
+					stopDialogCloseupDialog();
 				} else {
 					an_blk = _G(atds)->calcNextDialogCloseupBlock(_G(ads_dia_nr), _G(ads_blk_nr), curY);
 					selectDialogOption(_G(ads_dia_nr), _G(ads_blk_nr), an_blk->_endNr);
@@ -316,7 +316,7 @@ void adsMenu() {
 	}
 }
 
-void stop_ads_dialog() {
+void stopDialogCloseupDialog() {
 	aadWait(-1);
 	_G(gameState).DispFlag = _G(ads_tmp_dsp);
 	_G(cur_display) = true;
diff --git a/engines/chewy/rooms/room41.cpp b/engines/chewy/rooms/room41.cpp
index 5c3362175a1..bc742d4687f 100644
--- a/engines/chewy/rooms/room41.cpp
+++ b/engines/chewy/rooms/room41.cpp
@@ -245,7 +245,7 @@ void Room41::sub_dia() {
 	if (_G(gameState).R41LolaOk) {
 		startAadWait(163);
 		_G(atds)->hideDialogCloseupItem(11, 0, 2);
-		stop_ads_dialog();
+		stopDialogCloseupDialog();
 		autoMove(5, P_CHEWY);
 		new_invent_2_cur(PAPIER_INV);
 
diff --git a/engines/chewy/t_event.cpp b/engines/chewy/t_event.cpp
index be9082c5de5..c2e104d2056 100644
--- a/engines/chewy/t_event.cpp
+++ b/engines/chewy/t_event.cpp
@@ -1160,7 +1160,7 @@ void selectDialogOption(int16 diaNr, int16 blkNr, int16 strEndNr) {
 				Room41::sub_dia();
 			} else if (blkNr == 0 && strEndNr == 3) {
 				_G(gameState).R41RepairInfo = true;
-				stop_ads_dialog();
+				stopDialogCloseupDialog();
 			}
 			break;
 
@@ -1173,7 +1173,7 @@ void selectDialogOption(int16 diaNr, int16 blkNr, int16 strEndNr) {
 		case 15:
 			if (blkNr == 1 && strEndNr == 0) {
 				_G(gameState).R55Job = true;
-				stop_ads_dialog();
+				stopDialogCloseupDialog();
 			}
 			break;
 
@@ -1212,7 +1212,7 @@ void selectDialogOption(int16 diaNr, int16 blkNr, int16 strEndNr) {
 	}
 }
 
-void ads_ende(int16 diaNr, int16 blkNr, int16 strEndNr) {
+void endDialogCloseup(int16 diaNr, int16 blkNr, int16 strEndNr) {
 	switch (diaNr) {
 	case 0:
 		_G(flags).AutoAniPlay = false;


Commit: 86a4d419b210de5b8aa36425bbcaa61076a8070c
    https://github.com/scummvm/scummvm/commit/86a4d419b210de5b8aa36425bbcaa61076a8070c
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-06-21T18:11:47+03:00

Commit Message:
CHEWY: Cleanup loadDialogCloseup()

Changed paths:
    engines/chewy/t_event.cpp


diff --git a/engines/chewy/t_event.cpp b/engines/chewy/t_event.cpp
index c2e104d2056..4b4d592d19e 100644
--- a/engines/chewy/t_event.cpp
+++ b/engines/chewy/t_event.cpp
@@ -30,12 +30,8 @@
 namespace Chewy {
 
 int16 loadDialogCloseup(int16 diaNr) {
-	int16 ret = false;
-
 	if (_G(flags).DialogCloseup == false) {
-		bool tmp = _G(atds)->startDialogCloseup(diaNr);
-		if (tmp == true) {
-			ret = true;
+		if (_G(atds)->startDialogCloseup(diaNr)) {
 			_G(ads_blk_nr) = 0;
 			_G(dialogCloseupItemPtr) = _G(atds)->dialogCloseupItemPtr(diaNr, _G(ads_blk_nr), &_G(ads_item_nr));
 			_G(flags).DialogCloseup = true;
@@ -47,9 +43,10 @@ int16 loadDialogCloseup(int16 diaNr) {
 			_G(ads_dia_nr) = diaNr;
 			_G(talk_start_ani) = -1;
 			_G(talk_hide_static) = -1;
+			return true;
 		}
 	}
-	return ret;
+	return false;
 }
 
 void setSsiPos() {


Commit: 44d2dd9267941562cc150ae8659fe863f8aac2ea
    https://github.com/scummvm/scummvm/commit/44d2dd9267941562cc150ae8659fe863f8aac2ea
Author: Filippos Karapetis (bluegr at gmail.com)
Date: 2022-06-21T18:11:47+03:00

Commit Message:
CHEWY: Clear pending events when starting a dialog closeup - bug #13593

Changed paths:
    engines/chewy/sprite.cpp


diff --git a/engines/chewy/sprite.cpp b/engines/chewy/sprite.cpp
index d119d99dfac..93c80bea60c 100644
--- a/engines/chewy/sprite.cpp
+++ b/engines/chewy/sprite.cpp
@@ -575,7 +575,12 @@ void startDialogCloseupWait(int16 diaNr) {
 	if (!_G(flags).DialogCloseup) {
 		_G(menu_item) = CUR_TALK;
 		cursorChoice(_G(menu_item));
+		_G(minfo).button = 0;
+		g_events->_kbInfo._keyCode = '\0';
+		g_events->_kbInfo._scanCode = Common::KEYCODE_INVALID;
+
 		loadDialogCloseup(diaNr);
+
 		while (_G(flags).DialogCloseup && !SHOULD_QUIT) {
 			setupScreen(DO_SETUP);
 		}


Commit: 796166b501fcc7cda4611c14a716af0335ec67f3
    https://github.com/scummvm/scummvm/commit/796166b501fcc7cda4611c14a716af0335ec67f3
Author: Coen Rampen (crampen at gmail.com)
Date: 2022-06-21T18:11:48+03:00

Commit Message:
AUDIO: Enable subclassing of VocStream

Changed paths:
    audio/decoders/voc.cpp
    audio/decoders/voc.h


diff --git a/audio/decoders/voc.cpp b/audio/decoders/voc.cpp
index b55b86e1267..30bb2ed0412 100644
--- a/audio/decoders/voc.cpp
+++ b/audio/decoders/voc.cpp
@@ -19,6 +19,8 @@
  *
  */
 
+#include "audio/decoders/voc.h"
+
 #include "common/debug.h"
 #include "common/endian.h"
 #include "common/util.h"
@@ -32,8 +34,6 @@
 
 namespace Audio {
 
-namespace {
-
 bool checkVOCHeader(Common::ReadStream &stream) {
 	VocFileHeader fileHeader;
 
@@ -73,83 +73,6 @@ bool checkVOCHeader(Common::ReadStream &stream) {
 	return true;
 }
 
-class VocStream : public SeekableAudioStream {
-public:
-	VocStream(Common::SeekableReadStream *stream, bool isUnsigned, DisposeAfterUse::Flag disposeAfterUse);
-	~VocStream();
-
-	int readBuffer(int16 *buffer, const int numSamples) override;
-
-	bool isStereo() const override { return false; }
-
-	int getRate() const override { return _rate; }
-
-	bool endOfData() const override { return (_curBlock == _blocks.end()) && (_blockLeft == 0); }
-
-	bool seek(const Timestamp &where) override;
-
-	Timestamp getLength() const override { return _length; }
-private:
-	void preProcess();
-
-	Common::SeekableReadStream *const _stream;
-	const DisposeAfterUse::Flag _disposeAfterUse;
-
-	const bool _isUnsigned;
-
-	int _rate;
-	Timestamp _length;
-
-	struct Block {
-		uint8 code;
-		uint32 length;
-
-		union {
-			struct {
-				uint32 offset;
-				int rate;
-				int samples;
-			} sampleBlock;
-
-			struct {
-				int count;
-			} loopBlock;
-		};
-	};
-
-	typedef Common::List<Block> BlockList;
-	BlockList _blocks;
-
-	BlockList::const_iterator _curBlock;
-	uint32 _blockLeft;
-
-	/**
-	 * Advance one block in the stream in case
-	 * the current one is empty.
-	 */
-	void updateBlockIfNeeded();
-
-	// Do some internal buffering for systems with really slow slow disk i/o
-	enum {
-		/**
-		 * How many samples we can buffer at once.
-		 *
-		 * TODO: Check whether this size suffices
-		 * for systems with slow disk I/O.
-		 */
-		kSampleBufferLength = 2048
-	};
-	byte _buffer[kSampleBufferLength];
-
-	/**
-	 * Fill the temporary sample buffer used in readBuffer.
-	 *
-	 * @param maxSamples Maximum samples to read.
-	 * @return actual count of samples read.
-	 */
-	int fillBuffer(int maxSamples);
-};
-
 VocStream::VocStream(Common::SeekableReadStream *stream, bool isUnsigned, DisposeAfterUse::Flag disposeAfterUse)
 	: _stream(stream), _disposeAfterUse(disposeAfterUse), _isUnsigned(isUnsigned), _rate(0),
 	  _length(), _blocks(), _curBlock(_blocks.end()), _blockLeft(0), _buffer() {
@@ -533,8 +456,6 @@ void VocStream::preProcess() {
 	rewind();
 }
 
-} // End of anonymous namespace
-
 int getSampleRateFromVOCRate(int vocSR) {
 	if (vocSR == 0xa5 || vocSR == 0xa6) {
 		return 11025;
diff --git a/audio/decoders/voc.h b/audio/decoders/voc.h
index 2e33c2628ba..a92972db965 100644
--- a/audio/decoders/voc.h
+++ b/audio/decoders/voc.h
@@ -23,6 +23,7 @@
  * @file
  * Sound decoder used in engines:
  *  - agos
+ *  - chewy (subclass)
  *  - kyra
  *  - saga
  *  - scumm
@@ -32,6 +33,9 @@
 #ifndef AUDIO_VOC_H
 #define AUDIO_VOC_H
 
+#include "audio/audiostream.h"
+
+#include "common/list.h"
 #include "common/scummsys.h"
 #include "common/types.h"
 
@@ -64,6 +68,84 @@ struct VocBlockHeader {
 
 #include "common/pack-end.h"	// END STRUCT PACKING
 
+class VocStream : public SeekableAudioStream {
+public:
+	VocStream(Common::SeekableReadStream *stream, bool isUnsigned, DisposeAfterUse::Flag disposeAfterUse);
+	virtual ~VocStream();
+
+	int readBuffer(int16 *buffer, const int numSamples) override;
+
+	bool isStereo() const override { return false; }
+
+	int getRate() const override { return _rate; }
+
+	bool endOfData() const override { return (_curBlock == _blocks.end()) && (_blockLeft == 0); }
+
+	bool seek(const Timestamp &where) override;
+
+	Timestamp getLength() const override { return _length; }
+
+protected:
+	void preProcess();
+
+	Common::SeekableReadStream *const _stream;
+	const DisposeAfterUse::Flag _disposeAfterUse;
+
+	const bool _isUnsigned;
+
+	int _rate;
+	Timestamp _length;
+
+	struct Block {
+		uint8 code;
+		uint32 length;
+
+		union {
+			struct {
+				uint32 offset;
+				int rate;
+				int samples;
+			} sampleBlock;
+
+			struct {
+				int count;
+			} loopBlock;
+		};
+	};
+
+	typedef Common::List<Block> BlockList;
+	BlockList _blocks;
+
+	BlockList::const_iterator _curBlock;
+	uint32 _blockLeft;
+
+	/**
+	 * Advance one block in the stream in case
+	 * the current one is empty.
+	 */
+	void updateBlockIfNeeded();
+
+	// Do some internal buffering for systems with really slow slow disk i/o
+	enum {
+		/**
+		 * How many samples we can buffer at once.
+		 *
+		 * TODO: Check whether this size suffices
+		 * for systems with slow disk I/O.
+		 */
+		kSampleBufferLength = 2048
+	};
+	byte _buffer[kSampleBufferLength];
+
+	/**
+	 * Fill the temporary sample buffer used in readBuffer.
+	 *
+	 * @param maxSamples Maximum samples to read.
+	 * @return actual count of samples read.
+	 */
+	int fillBuffer(int maxSamples);
+};
+
 /**
  * Take a sample rate parameter as it occurs in a VOC sound header, and
  * return the corresponding sample frequency.


Commit: e208659aa877a034920cf9131a27db2aeb6c5d03
    https://github.com/scummvm/scummvm/commit/e208659aa877a034920cf9131a27db2aeb6c5d03
Author: Coen Rampen (crampen at gmail.com)
Date: 2022-06-21T18:11:48+03:00

Commit Message:
AUDIO: Fix VOC infinite loop

This fixes a possible infinite loop in VocStream. It depends on the stream size
matching the size specified in the VOC block headers, but if the size in the
headers is incorrect and larger than the stream size, it will keep trying to
read the stream. This is fixed by adding an end-of-stream check to the error
check.

Changed paths:
    audio/decoders/voc.cpp


diff --git a/audio/decoders/voc.cpp b/audio/decoders/voc.cpp
index 30bb2ed0412..0fb80634080 100644
--- a/audio/decoders/voc.cpp
+++ b/audio/decoders/voc.cpp
@@ -168,9 +168,9 @@ int VocStream::fillBuffer(int maxSamples) {
 		maxSamples -= samplesRead;
 		_blockLeft -= samplesRead;
 
-		// In case of an error we will stop
+		// In case of an error or end of stream we will stop
 		// stream playback.
-		if (_stream->err()) {
+		if (_stream->err() || _stream->eos()) {
 			_blockLeft = 0;
 			_curBlock = _blocks.end();
 			break;




More information about the Scummvm-git-logs mailing list