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

mduggan noreply at scummvm.org
Sun Jul 28 23:16:01 UTC 2024


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

Summary:
f4d1345cc3 DGDS: Add RAW sound file support


Commit: f4d1345cc354a92fd12617607fdc7c7d85e0d1d0
    https://github.com/scummvm/scummvm/commit/f4d1345cc354a92fd12617607fdc7c7d85e0d1d0
Author: Matthew Duggan (mgithub at guarana.org)
Date: 2024-07-29T09:14:53+10:00

Commit Message:
DGDS: Add RAW sound file support

This is a really simple sound format, only seems to be used in the Willy
Beamish CD version intro.

Changed paths:
  A engines/dgds/sound_raw.cpp
  A engines/dgds/sound_raw.h
    engines/dgds/includes.h
    engines/dgds/module.mk
    engines/dgds/sound.cpp
    engines/dgds/ttm.cpp
    engines/dgds/ttm.h


diff --git a/engines/dgds/includes.h b/engines/dgds/includes.h
index ec969f6418f..b8606047912 100644
--- a/engines/dgds/includes.h
+++ b/engines/dgds/includes.h
@@ -31,23 +31,25 @@ namespace Dgds {
 #define ID_FNM MKTAG24('F', 'N', 'M')
 #define ID_FNT MKTAG24('F', 'N', 'T')
 #define ID_GAD MKTAG24('G', 'A', 'D')
-#define ID_INF MKTAG24('I', 'N', 'F')
 #define ID_GDS MKTAG24('G', 'D', 'S')
+#define ID_INF MKTAG24('I', 'N', 'F')
 #define ID_MTX MKTAG24('M', 'T', 'X')
+#define ID_OFF MKTAG24('O', 'F', 'F')
 #define ID_PAG MKTAG24('P', 'A', 'G')
+#define ID_RAW MKTAG24('R', 'A', 'W')
 #define ID_REQ MKTAG24('R', 'E', 'Q')
 #define ID_RES MKTAG24('R', 'E', 'S')
 #define ID_SCR MKTAG24('S', 'C', 'R')
 #define ID_SCN MKTAG24('S', 'C', 'N')
 #define ID_SDS MKTAG24('S', 'D', 'S')
+#define ID_SND MKTAG24('S', 'N', 'D')
 #define ID_SNG MKTAG24('S', 'N', 'G')
 #define ID_TAG MKTAG24('T', 'A', 'G')
 #define ID_TT3 MKTAG24('T', 'T', '3')
+#define ID_TTI MKTAG24('T', 'T', 'I')
 #define ID_VER MKTAG24('V', 'E', 'R')
 #define ID_VGA MKTAG24('V', 'G', 'A')
 #define ID_VQT MKTAG24('V', 'Q', 'T')
-#define ID_OFF MKTAG24('O', 'F', 'F')
-#define ID_TTI MKTAG24('T', 'T', 'I')
 
 /* Heart of China */
 #define ID_MA8 MKTAG24('M', 'A', '8')
@@ -60,10 +62,11 @@ namespace Dgds {
 #define EX_ADS MKTAG24('A', 'D', 'S')
 #define EX_AMG MKTAG24('A', 'M', 'G')
 #define EX_BMP MKTAG24('B', 'M', 'P')
+#define EX_FNT MKTAG24('F', 'N', 'T')
 #define EX_GDS MKTAG24('G', 'D', 'S')
 #define EX_INS MKTAG24('I', 'N', 'S')
 #define EX_PAL MKTAG24('P', 'A', 'L')
-#define EX_FNT MKTAG24('F', 'N', 'T')
+#define EX_RAW MKTAG24('R', 'A', 'W')
 #define EX_REQ MKTAG24('R', 'E', 'Q')
 #define EX_RST MKTAG24('R', 'S', 'T')
 #define EX_SCR MKTAG24('S', 'C', 'R')
@@ -73,7 +76,6 @@ namespace Dgds {
 #define EX_TTM MKTAG24('T', 'T', 'M')
 #define EX_VIN MKTAG24('V', 'I', 'N')
 
-
 /* Heart of China */
 #define EX_DAT MKTAG24('D', 'A', 'T')
 #define EX_DDS MKTAG24('D', 'D', 'S')
diff --git a/engines/dgds/module.mk b/engines/dgds/module.mk
index 707ac698040..a0f4b7bde9d 100644
--- a/engines/dgds/module.mk
+++ b/engines/dgds/module.mk
@@ -21,6 +21,7 @@ MODULE_OBJS := \
 	resource.o \
 	scripts.o \
 	shell_game.o \
+	sound_raw.o \
 	ttm.o \
 	scene.o \
 	sound.o
diff --git a/engines/dgds/sound.cpp b/engines/dgds/sound.cpp
index 0c9cac04919..9cf90baed39 100644
--- a/engines/dgds/sound.cpp
+++ b/engines/dgds/sound.cpp
@@ -229,7 +229,7 @@ bool Sound::playPCM(const byte *data, uint32 size) {
 		byte volume = 255;
 		Audio::AudioStream *input = Audio::makeRawStream(trackPtr[part], trackSiz[part],
 														 rate, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
-		_mixer->playStream(Audio::Mixer::kSFXSoundType, &ch->handle, input, -1, volume);
+		_mixer->playStream(Audio::Mixer::kSFXSoundType, &ch->handle, input, -1, volume, 0, DisposeAfterUse::YES);
 	}
 	return true;
 }
diff --git a/engines/dgds/sound_raw.cpp b/engines/dgds/sound_raw.cpp
new file mode 100644
index 00000000000..9ca58ca883a
--- /dev/null
+++ b/engines/dgds/sound_raw.cpp
@@ -0,0 +1,74 @@
+/* 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 "audio/mixer.h"
+#include "audio/audiostream.h"
+#include "audio/decoders/raw.h"
+
+#include "dgds/dgds.h"
+#include "dgds/sound_raw.h"
+#include "dgds/includes.h"
+
+namespace Dgds {
+
+SoundRaw::SoundRaw(ResourceManager *resourceMan, Decompressor *decompressor) : _decompressor(decompressor), _resourceMan(resourceMan) {
+}
+
+void SoundRaw::load(const Common::String &filename) {
+	Common::SeekableReadStream *fileStream = _resourceMan->getResource(filename);
+	if (!fileStream)
+		error("SoundRaw::load: Couldn't get raw resource '%s'", filename.c_str());
+
+	DgdsChunkReader chunk(fileStream);
+	while (chunk.readNextHeader(EX_RAW, filename)) {
+		chunk.readContent(_decompressor);
+		Common::SeekableReadStream *stream = chunk.getContent();
+		if (chunk.isSection(ID_RAW)) {
+			_data.resize(chunk.getSize());
+			stream->read(_data.data(), chunk.getSize());
+			break;
+		}
+	}
+}
+
+SoundRaw::~SoundRaw() {
+	stop();
+}
+
+
+void SoundRaw::play() {
+	Audio::Mixer *mixer = DgdsEngine::getInstance()->_mixer;
+	Audio::AudioStream *input = Audio::makeRawStream(_data.data(), _data.size(),
+													 11025, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
+	mixer->playStream(Audio::Mixer::kSFXSoundType, &_handle, input, -1, 255, 0, DisposeAfterUse::YES);
+}
+
+void SoundRaw::stop() {
+	Audio::Mixer *mixer = DgdsEngine::getInstance()->_mixer;
+	mixer->stopHandle(_handle);
+}
+
+bool SoundRaw::isPlaying() const {
+	Audio::Mixer *mixer = DgdsEngine::getInstance()->_mixer;
+	return mixer->isSoundHandleActive(_handle);
+}
+
+} // end namespace Dgds
diff --git a/engines/dgds/sound_raw.h b/engines/dgds/sound_raw.h
new file mode 100644
index 00000000000..f3748c38430
--- /dev/null
+++ b/engines/dgds/sound_raw.h
@@ -0,0 +1,58 @@
+/* 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 DGDS_SOUND_RAW_H
+#define DGDS_SOUND_RAW_H
+
+#include "audio/mixer.h"
+
+#include "common/str.h"
+#include "common/array.h"
+
+#include "dgds/resource.h"
+#include "dgds/decompress.h"
+
+namespace Dgds {
+
+/**
+ * A simple raw PCM file format which seems to only be used in
+ * Willy Beamish CD version intro.
+ */
+class SoundRaw {
+public:
+	SoundRaw(ResourceManager *resourceMan, Decompressor *decompressor);
+	~SoundRaw();
+
+	void load(const Common::String &filename);
+	void play();
+	void stop();
+	bool isPlaying() const;
+
+private:
+	Common::Array<byte> _data;
+	ResourceManager *_resourceMan;
+	Decompressor *_decompressor;
+	Audio::SoundHandle _handle;
+};
+
+} // end namespace Dgds
+
+#endif // DGDS_SOUND_RAW_H
diff --git a/engines/dgds/ttm.cpp b/engines/dgds/ttm.cpp
index 76b796b61c3..d0b5a11e3f9 100644
--- a/engines/dgds/ttm.cpp
+++ b/engines/dgds/ttm.cpp
@@ -33,6 +33,7 @@
 #include "dgds/image.h"
 #include "dgds/sound.h"
 #include "dgds/font.h"
+#include "dgds/sound_raw.h"
 
 
 namespace Dgds {
@@ -974,6 +975,22 @@ void TTMInterpreter::handleOperation(TTMEnviro &env, TTMSeq &seq, uint16 op, byt
 		_vm->_soundPlayer->playMusic(ivals[0]);
 		break;
 	}
+	case 0xc210: {  // LOAD RAW SFX filename:str
+		if (seq._executed) // this is a one-shot op
+			break;
+		SoundRaw *snd = new SoundRaw(_vm->getResourceManager(), _vm->getDecompressor());
+		snd->load(sval);
+		env._soundRaw.reset(snd);
+		break;
+	}
+	case 0xc220: {	// PLAY RAW SFX
+		if (seq._executed) // this is a one-shot op
+			break;
+		if (!env._soundRaw)
+			warning("TODO: Trying to play raw SFX but nothing loaded");
+		env._soundRaw->play();
+		break;
+	}
 	case 0xf010: { // LOAD SCR:	filename:str
 		if (seq._executed) // this is a one-shot op
 			break;
diff --git a/engines/dgds/ttm.h b/engines/dgds/ttm.h
index 3afe2bb2c93..f1103d1ae4a 100644
--- a/engines/dgds/ttm.h
+++ b/engines/dgds/ttm.h
@@ -27,6 +27,8 @@
 
 namespace Dgds {
 
+class SoundRaw;
+
 class GetPutRegion {
 public:
 	Common::Rect _area;
@@ -62,6 +64,7 @@ public:
 	Common::SharedPtr<Image> _scrollShape;
 	int16 _xScroll;
 	int16 _yScroll;
+	Common::SharedPtr<SoundRaw> _soundRaw;
 };
 
 enum TTMRunType {




More information about the Scummvm-git-logs mailing list