[Scummvm-git-logs] scummvm master -> 78bd7e965ab24041b27a9c5465af19b39be8a732

dreammaster noreply at scummvm.org
Tue Apr 28 07:02:20 UTC 2026


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

Summary:
78bd7e965a MADS: PHANTOM: Shifting the ASound class into Nebular namespace


Commit: 78bd7e965ab24041b27a9c5465af19b39be8a732
    https://github.com/scummvm/scummvm/commit/78bd7e965ab24041b27a9c5465af19b39be8a732
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2026-04-28T17:01:28+10:00

Commit Message:
MADS: PHANTOM: Shifting the ASound class into Nebular namespace

Sounds in Return of the Phantom aren't sounding entirely like
the original; likely the ASound driver being re-used from Nebular
has some differences. This is already something I feared, since
the AdlibChannel structure in my disassembly of one driver had
extra state fields that Rex's didn't have.

For now, I've done a clearer separation of the ASound implementation
from the SoundManager class, and Phantom still derives from
the Rex Nebular::ASound class. But this makes it easier to
completely reimplement a new version of ASound for Phantom.
And hopefully the other remaining games can share it.

Changed paths:
  A engines/mads/core/sound_manager.cpp
  A engines/mads/core/sound_manager.h
  A engines/mads/nebular/core/asound.cpp
  A engines/mads/nebular/core/asound.h
  R engines/mads/core/sound.cpp
  R engines/mads/core/sound.h
    engines/mads/madsv2/engine.cpp
    engines/mads/madsv2/engine.h
    engines/mads/madsv2/phantom/sound_phantom.h
    engines/mads/module.mk
    engines/mads/nebular/nebular.cpp
    engines/mads/nebular/nebular.h
    engines/mads/nebular/sound_nebular.h


diff --git a/engines/mads/core/sound_manager.cpp b/engines/mads/core/sound_manager.cpp
new file mode 100644
index 00000000000..a613a484303
--- /dev/null
+++ b/engines/mads/core/sound_manager.cpp
@@ -0,0 +1,124 @@
+/* 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/fmopl.h"
+#include "common/memstream.h"
+#include "mads/core/sound_manager.h"
+
+namespace Audio {
+class Mixer;
+}
+
+namespace MADS {
+
+SoundManager::SoundManager(Audio::Mixer *mixer, bool &soundFlag) : _mixer(mixer), _soundFlag(soundFlag) {
+	_opl = OPL::Config::create();
+	_opl->init();
+}
+
+SoundManager::~SoundManager() {
+	if (_driver) {
+		_driver->stop();
+		delete _driver;
+	}
+
+	delete _opl;
+}
+
+void SoundManager::init(int sectionNumber) {
+	assert(sectionNumber > 0 && sectionNumber < 10);
+
+	if (_driver != nullptr)
+		delete _driver;
+
+	// Load the correct driver for the section
+	loadDriver(sectionNumber);
+
+	// Set volume for newly loaded driver
+	_driver->setVolume(_masterVolume);
+}
+
+void SoundManager::closeDriver() {
+	if (_driver) {
+		command(0);
+		setEnabled(false);
+		stop();
+
+		removeDriver();
+	}
+}
+
+void SoundManager::removeDriver() {
+	delete _driver;
+	_driver = nullptr;
+}
+
+void SoundManager::setEnabled(bool flag) {
+	_pollSoundEnabled = flag;
+	_soundPollFlag = false;
+}
+
+void SoundManager::pauseNewCommands() {
+	_newSoundsPaused = true;
+}
+
+void SoundManager::startQueuedCommands() {
+	_newSoundsPaused = false;
+
+	while (!_queuedCommands.empty()) {
+		int commandId = _queuedCommands.pop();
+		command(commandId);
+	}
+}
+
+void SoundManager::setVolume(int volume) {
+	_masterVolume = volume;
+
+	if (_driver)
+		_driver->setVolume(volume);
+}
+
+int SoundManager::command(int commandId, int param) {
+	if (_newSoundsPaused) {
+		if (_queuedCommands.size() < 8)
+			_queuedCommands.push(commandId);
+		return _queuedCommands.size() - 1;
+	} else if (_driver) {
+		// Note: I don't know any way to identify music commands versus sfx
+		// commands, so if sfx is mute, then so is music
+		if (_soundFlag)
+			_driver->command(commandId, param);
+	}
+
+	return 0;
+}
+
+void SoundManager::stop() {
+	if (_driver)
+		_driver->stop();
+}
+
+void SoundManager::noise() {
+	if (_driver)
+		_driver->noise();
+}
+
+} // namespace MADS
diff --git a/engines/mads/core/sound_manager.h b/engines/mads/core/sound_manager.h
new file mode 100644
index 00000000000..9a767222591
--- /dev/null
+++ b/engines/mads/core/sound_manager.h
@@ -0,0 +1,169 @@
+/* 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 MADS_CORE_SOUND_MANAGER_H
+#define MADS_CORE_SOUND_MANAGER_H
+
+#include "common/array.h"
+#include "common/file.h"
+#include "common/mutex.h"
+#include "common/queue.h"
+
+namespace Audio {
+class Mixer;
+}
+
+namespace OPL {
+class OPL;
+}
+
+namespace MADS {
+
+class SoundDriver {
+protected:
+	Audio::Mixer *_mixer;
+	OPL::OPL *_opl;
+
+public:
+	SoundDriver(Audio::Mixer *mixer, OPL::OPL *opl) : _mixer(mixer), _opl(opl) {}
+	virtual ~SoundDriver() {
+	}
+
+	/**
+	 * Execute a player command. Most commands represent sounds to play, but some
+	 * low number commands also provide control operations.
+	 * @param commandId		Player ommand to execute.
+	 * @param param			Optional parameter used by a few commands
+	 */
+	virtual int command(int commandId, int param) = 0;
+
+	/**
+	 * Stop all currently playing sounds
+	 */
+	virtual int stop() = 0;
+
+	/**
+	 * Main poll method to allow sounds to progress
+	 */
+	virtual int poll() {
+		return 0;
+	}
+
+	/**
+	 * General noise/note output
+	 */
+	virtual void noise() = 0;
+
+	/**
+	 * Set the volume
+	 */
+	virtual void setVolume(int volume) = 0;
+};
+
+class SoundManager {
+protected:
+	Audio::Mixer *_mixer;
+	bool &_soundFlag;
+	OPL::OPL *_opl = nullptr;
+	SoundDriver *_driver = nullptr;
+	bool _pollSoundEnabled = false;
+	bool _soundPollFlag = false;
+	bool _newSoundsPaused = false;
+	Common::Queue<int> _queuedCommands;
+	int _masterVolume = 255;
+
+protected:
+	/**
+	 * Load the particular section sound handler
+	 * @param sectionNum	Section number
+	 */
+	virtual void loadDriver(int sectionNum) = 0;
+
+public:
+	SoundManager(Audio::Mixer *mixer, bool &soundFlag);
+	virtual ~SoundManager();
+
+	virtual void validate() = 0;
+
+	bool _preferRoland;
+
+	/**
+	 * Initializes the sound driver for a given game section
+	 */
+	void init(int sectionNumber);
+
+	/**
+	 * Stop any currently active sound and remove the driver
+	 */
+	void closeDriver();
+
+	/**
+	 * Remove the driver
+	 */
+	void removeDriver();
+
+	/**
+	 * Sets the enabled status of the sound
+	 * @flag		True if sound should be enabled
+	 */
+	void setEnabled(bool flag);
+
+	/**
+	 * Temporarily pause the playback of any new sound commands
+	 */
+	void pauseNewCommands();
+
+	/**
+	 * Stop queueing sound commands, and execute any previously queued ones
+	 */
+	void startQueuedCommands();
+
+	/**
+	 * Set the master volume
+	 */
+	void setVolume(int volume);
+
+	//@{
+	/**
+	 * Executes a command on the sound driver
+	 * @param commandid		Command Id to execute
+	 * @param param			Optional paramater specific to a few commands
+	 */
+	int command(int commandId, int param = 0);
+
+	/**
+	 * Stops any currently playing sound
+	 */
+	void stop();
+
+	/**
+	 * Noise
+	 * Some sort of random noise generation?
+	 */
+	void noise();
+
+	//@}
+};
+
+
+} // namespace MADS
+
+#endif
diff --git a/engines/mads/madsv2/engine.cpp b/engines/mads/madsv2/engine.cpp
index 0f85f0cd9d8..1d28b7e067b 100644
--- a/engines/mads/madsv2/engine.cpp
+++ b/engines/mads/madsv2/engine.cpp
@@ -52,7 +52,7 @@
 #include "mads/madsv2/core/timer.h"
 #include "mads/madsv2/core/vocab.h"
 #include "mads/madsv2/phantom/main.h"
-#include "mads/core/sound.h"
+#include "mads/core/sound_manager.h"
 
 namespace MADS {
 namespace MADSV2 {
diff --git a/engines/mads/madsv2/engine.h b/engines/mads/madsv2/engine.h
index b44311d5e4a..ba6c4017f62 100644
--- a/engines/mads/madsv2/engine.h
+++ b/engines/mads/madsv2/engine.h
@@ -29,7 +29,7 @@
 #include "common/random.h"
 #include "graphics/screen.h"
 #include "mads/mads.h"
-#include "mads/core/sound.h"
+#include "mads/core/sound_manager.h"
 #include "mads/madsv2/core/speech.h"
 
 namespace MADS {
diff --git a/engines/mads/madsv2/phantom/sound_phantom.h b/engines/mads/madsv2/phantom/sound_phantom.h
index fe1429eb69b..38bd91b9f31 100644
--- a/engines/mads/madsv2/phantom/sound_phantom.h
+++ b/engines/mads/madsv2/phantom/sound_phantom.h
@@ -22,12 +22,15 @@
 #ifndef MADS_PHANTOM_SOUND_H
 #define MADS_PHANTOM_SOUND_H
 
-#include "mads/core/sound.h"
+#include "mads/nebular/core/asound.h"
 
 namespace MADS {
 namespace MADSV2 {
 namespace Phantom {
 
+using Nebular::AdlibChannel;
+using Nebular::AdlibSample;
+
 class PhantomSoundManager : public SoundManager {
 protected:
 	void loadDriver(int sectionNum) override;
@@ -41,7 +44,7 @@ public:
 	void validate() override;
 };
 
-class PhantomASound : public ASound {
+class PhantomASound : public Nebular::ASound {
 protected:
 	// Per-driver scripting register file (256 byte-sized registers)
 	byte _scratchArr[256];
diff --git a/engines/mads/module.mk b/engines/mads/module.mk
index ee122aec664..2cf1ef87422 100644
--- a/engines/mads/module.mk
+++ b/engines/mads/module.mk
@@ -1,7 +1,7 @@
 MODULE := engines/mads
 
 MODULE_OBJS := \
-	core/sound.o \
+	core/sound_manager.o \
 	nebular/nebular.o \
 	nebular/debugger.o \
 	nebular/dialogs_nebular.o \
@@ -21,6 +21,7 @@ MODULE_OBJS := \
 	nebular/core/action.o \
 	nebular/core/animation.o \
 	nebular/core/assets.o \
+	nebular/core/asound.o \
 	nebular/core/audio.o \
 	nebular/core/camera.o \
 	nebular/core/compression.o \
diff --git a/engines/mads/core/sound.cpp b/engines/mads/nebular/core/asound.cpp
similarity index 90%
rename from engines/mads/core/sound.cpp
rename to engines/mads/nebular/core/asound.cpp
index 5f9387d1ed6..b99c19038b5 100644
--- a/engines/mads/core/sound.cpp
+++ b/engines/mads/nebular/core/asound.cpp
@@ -21,107 +21,10 @@
 
 #include "audio/fmopl.h"
 #include "common/memstream.h"
-#include "mads/core/sound.h"
-
-namespace Audio {
-class Mixer;
-}
+#include "mads/nebular/core/asound.h"
 
 namespace MADS {
-
-SoundManager::SoundManager(Audio::Mixer *mixer, bool &soundFlag) : _mixer(mixer), _soundFlag(soundFlag) {
-	_opl = OPL::Config::create();
-	_opl->init();
-}
-
-SoundManager::~SoundManager() {
-	if (_driver) {
-		_driver->stop();
-		delete _driver;
-	}
-
-	delete _opl;
-}
-
-void SoundManager::init(int sectionNumber) {
-	assert(sectionNumber > 0 && sectionNumber < 10);
-
-	if (_driver != nullptr)
-		delete _driver;
-
-	// Load the correct driver for the section
-	loadDriver(sectionNumber);
-
-	// Set volume for newly loaded driver
-	_driver->setVolume(_masterVolume);
-}
-
-void SoundManager::closeDriver() {
-	if (_driver) {
-		command(0);
-		setEnabled(false);
-		stop();
-
-		removeDriver();
-	}
-}
-
-void SoundManager::removeDriver() {
-	delete _driver;
-	_driver = nullptr;
-}
-
-void SoundManager::setEnabled(bool flag) {
-	_pollSoundEnabled = flag;
-	_soundPollFlag = false;
-}
-
-void SoundManager::pauseNewCommands() {
-	_newSoundsPaused = true;
-}
-
-void SoundManager::startQueuedCommands() {
-	_newSoundsPaused = false;
-
-	while (!_queuedCommands.empty()) {
-		int commandId = _queuedCommands.pop();
-		command(commandId);
-	}
-}
-
-void SoundManager::setVolume(int volume) {
-	_masterVolume = volume;
-
-	if (_driver)
-		_driver->setVolume(volume);
-}
-
-int SoundManager::command(int commandId, int param) {
-	if (_newSoundsPaused) {
-		if (_queuedCommands.size() < 8)
-			_queuedCommands.push(commandId);
-		return _queuedCommands.size() - 1;
-	} else if (_driver) {
-		// Note: I don't know any way to identify music commands versus sfx
-		// commands, so if sfx is mute, then so is music
-		if (_soundFlag)
-			_driver->command(commandId, param);
-	}
-
-	return 0;
-}
-
-void SoundManager::stop() {
-	if (_driver)
-		_driver->stop();
-}
-
-void SoundManager::noise() {
-	if (_driver)
-		_driver->noise();
-}
-
-/*-----------------------------------------------------------------------*/
+namespace Nebular {
 
 bool AdlibChannel::_channelsEnabled;
 
@@ -251,7 +154,8 @@ AdlibSample::AdlibSample(Common::SeekableReadStream &s) {
 
 /*-----------------------------------------------------------------------*/
 
-ASound::ASound(Audio::Mixer *mixer, OPL::OPL *opl, const Common::Path &filename, int dataOffset) {
+ASound::ASound(Audio::Mixer *mixer, OPL::OPL *opl, const Common::Path &filename, int dataOffset) :
+	SoundDriver(mixer, opl) {
 	// Open up the appropriate sound file
 	if (!_soundFile.open(filename))
 		error("Could not open file - %s", filename.toString().c_str());
@@ -866,4 +770,5 @@ int ASound::command8() {
 	return result;
 }
 
+} // namespace Nebular
 } // namespace MADS
diff --git a/engines/mads/core/sound.h b/engines/mads/nebular/core/asound.h
similarity index 76%
rename from engines/mads/core/sound.h
rename to engines/mads/nebular/core/asound.h
index 5f0d8896193..e3c5acf2f3e 100644
--- a/engines/mads/core/sound.h
+++ b/engines/mads/nebular/core/asound.h
@@ -19,112 +19,16 @@
  *
  */
 
-#ifndef MADS_SOUND_H
-#define MADS_SOUND_H
+#ifndef MADS_NEBULAR_CORE_ASOUND_H
+#define MADS_NEBULAR_CORE_ASOUND_H
 
-#include "common/array.h"
-#include "common/file.h"
-#include "common/mutex.h"
-#include "common/queue.h"
-
-namespace Audio {
-class Mixer;
-}
-
-namespace OPL {
-class OPL;
-}
+#include "mads/core/sound_manager.h"
 
 namespace MADS {
+namespace Nebular {
 
 class ASound;
 
-class SoundManager {
-protected:
-	Audio::Mixer *_mixer;
-	bool &_soundFlag;
-	OPL::OPL *_opl = nullptr;
-	ASound *_driver = nullptr;
-	bool _pollSoundEnabled = false;
-	bool _soundPollFlag = false;
-	bool _newSoundsPaused = false;
-	Common::Queue<int> _queuedCommands;
-	int _masterVolume = 255;
-
-protected:
-	/**
-	 * Load the particular section sound handler
-	 * @param sectionNum	Section number
-	 */
-	virtual void loadDriver(int sectionNum) = 0;
-
-public:
-	SoundManager(Audio::Mixer *mixer, bool &soundFlag);
-	virtual ~SoundManager();
-
-	virtual void validate() = 0;
-
-	bool _preferRoland;
-
-	/**
-	 * Initializes the sound driver for a given game section
-	 */
-	void init(int sectionNumber);
-
-	/**
-	 * Stop any currently active sound and remove the driver
-	 */
-	void closeDriver();
-
-	/**
-	 * Remove the driver
-	 */
-	void removeDriver();
-
-	/**
-	 * Sets the enabled status of the sound
-	 * @flag		True if sound should be enabled
-	 */
-	void setEnabled(bool flag);
-
-	/**
-	 * Temporarily pause the playback of any new sound commands
-	 */
-	void pauseNewCommands();
-
-	/**
-	 * Stop queueing sound commands, and execute any previously queued ones
-	 */
-	void startQueuedCommands();
-
-	/**
-	 * Set the master volume
-	 */
-	void setVolume(int volume);
-
-	//@{
-	/**
-	 * Executes a command on the sound driver
-	 * @param commandid		Command Id to execute
-	 * @param param			Optional paramater specific to a few commands
-	 */
-	int command(int commandId, int param = 0);
-
-	/**
-	 * Stops any currently playing sound
-	 */
-	void stop();
-
-	/**
-	 * Noise
-	 * Some sort of random noise generation?
-	 */
-	void noise();
-
-	//@}
-};
-
-
 /**
  * Represents the data for a channel on the Adlib
  */
@@ -236,7 +140,7 @@ struct CachedDataEntry {
 /**
  * Base class for the sound player resource files
  */
-class ASound {
+class ASound : public SoundDriver {
 private:
 	Common::List<CachedDataEntry> _dataCache;
 	uint16 _randomSeed;
@@ -383,8 +287,6 @@ protected:
 		return 0;
 	}
 public:
-	Audio::Mixer *_mixer;
-	OPL::OPL *_opl;
 	AdlibChannel _channels[ADLIB_CHANNEL_COUNT];
 	AdlibChannel *_activeChannelPtr;
 	AdlibChannelData _channelData[11];
@@ -429,35 +331,27 @@ public:
 	/**
 	 * Destructor
 	 */
-	virtual ~ASound();
+	~ASound() override;
 
 	/**
 	 * Validates the Adlib sound files
 	 */
 	static void validate();
 
-	/**
-	 * Execute a player command. Most commands represent sounds to play, but some
-	 * low number commands also provide control operations.
-	 * @param commandId		Player ommand to execute.
-	 * @param param			Optional parameter used by a few commands
-	 */
-	virtual int command(int commandId, int param) = 0;
-
 	/**
 	 * Stop all currently playing sounds
 	 */
-	int stop();
+	int stop() override;
 
 	/**
 	 * Main poll method to allow sounds to progress
 	 */
-	int poll();
+	int poll() override;
 
 	/**
 	 * General noise/note output
 	 */
-	void noise();
+	void noise() override;
 
 	/**
 	 * Return the current frame counter
@@ -474,9 +368,10 @@ public:
 	/**
 	 * Set the volume
 	 */
-	void setVolume(int volume);
+	void setVolume(int volume) override;
 };
 
+} // namespace Nebular
 } // namespace MADS
 
 #endif
diff --git a/engines/mads/nebular/nebular.cpp b/engines/mads/nebular/nebular.cpp
index 50ee1214252..24681fc502c 100644
--- a/engines/mads/nebular/nebular.cpp
+++ b/engines/mads/nebular/nebular.cpp
@@ -31,7 +31,6 @@
 #include "mads/nebular/core/screen.h"
 #include "mads/nebular/core/msurface.h"
 #include "mads/nebular/core/resources.h"
-#include "mads/core/sound.h"
 #include "mads/nebular/core/sprites.h"
 #include "mads/nebular/core/mps_installer.h"
 
diff --git a/engines/mads/nebular/nebular.h b/engines/mads/nebular/nebular.h
index fbead86bb9b..8a17289ec88 100644
--- a/engines/mads/nebular/nebular.h
+++ b/engines/mads/nebular/nebular.h
@@ -39,7 +39,7 @@
 #include "mads/nebular/core/screen.h"
 #include "mads/nebular/core/msurface.h"
 #include "mads/nebular/core/resources.h"
-#include "mads/core/sound.h"
+#include "mads/nebular/sound_nebular.h"
 
 namespace MADS {
 namespace Nebular {
diff --git a/engines/mads/nebular/sound_nebular.h b/engines/mads/nebular/sound_nebular.h
index fe5b232bc4e..3a25a4bee2f 100644
--- a/engines/mads/nebular/sound_nebular.h
+++ b/engines/mads/nebular/sound_nebular.h
@@ -22,7 +22,7 @@
 #ifndef MADS_SOUND_NEBULAR_H
 #define MADS_SOUND_NEBULAR_H
 
-#include "mads/core/sound.h"
+#include "mads/nebular/core/asound.h"
 
 namespace MADS {
 namespace Nebular {




More information about the Scummvm-git-logs mailing list