MM: Move Sound class into Shared namespace

This commit is contained in:
Paul Gilbert 2023-02-26 16:37:37 -08:00
parent 0a4d59b5b7
commit f9543cba7a
12 changed files with 228 additions and 174 deletions

@ -23,8 +23,11 @@
namespace MM {
MMEngine *g_engine;
MMEngine::MMEngine(OSystem *syst, const MM::MightAndMagicGameDescription *gameDesc) :
Engine(syst), _gameDescription(gameDesc), _randomSource("MightAndMagic") {
Engine(syst), _gameDescription(gameDesc), _randomSource("MightAndMagic") {
g_engine = this;
}
bool MMEngine::hasFeature(EngineFeature f) const {
@ -50,4 +53,8 @@ Common::Platform MMEngine::getPlatform() const {
return _gameDescription->desc.platform;
}
bool MMEngine::getIsCD() const {
return getFeatures() & ADGF_CD;
}
} // namespace MM

@ -67,6 +67,11 @@ public:
*/
uint32 getGameID() const;
/**
* Returns true if the game is the CD version
*/
bool getIsCD() const;
/**
* Get a random number
*/
@ -75,6 +80,8 @@ public:
}
};
extern MMEngine *g_engine;
} // namespace MM
#endif // MM_MM_H

@ -10,6 +10,9 @@ MODULE_OBJS := \
shared/utils/xeen_font.o \
shared/xeen/cc_archive.o \
shared/xeen/file.o \
shared/xeen/sound.o \
shared/xeen/sound_driver.o \
shared/xeen/sound_driver_adlib.o \
shared/xeen/sprites.o \
shared/xeen/xsurface.o
@ -255,9 +258,6 @@ MODULE_OBJS += \
xeen/saves.o \
xeen/screen.o \
xeen/scripts.o \
xeen/sound.o \
xeen/sound_driver.o \
xeen/sound_driver_adlib.o \
xeen/spells.o \
xeen/sprites.o \
xeen/subtitles.o \

@ -23,24 +23,25 @@
#include "audio/decoders/voc.h"
#include "backends/audiocd/audiocd.h"
#include "common/config-manager.h"
#include "mm/xeen/sound.h"
#include "mm/xeen/sound_driver_adlib.h"
#include "mm/xeen/xeen.h"
#include "mm/shared/xeen/sound.h"
#include "mm/shared/xeen/sound_driver_adlib.h"
#include "mm/mm.h"
namespace MM {
namespace Shared {
namespace Xeen {
Sound::Sound(Audio::Mixer *mixer) : _mixer(mixer), _fxOn(true), _musicOn(true), _subtitles(false),
_songData(nullptr), _effectsData(nullptr), _musicSide(0), _musicPercent(100),
_musicVolume(0), _sfxVolume(0) {
_SoundDriver = new SoundDriverAdlib();
if (g_vm->getIsCD())
if (g_engine->getIsCD())
g_system->getAudioCDManager()->open();
}
Sound::~Sound() {
stopAllAudio();
if (g_vm->getIsCD())
if (g_engine->getIsCD())
g_system->getAudioCDManager()->close();
delete _SoundDriver;
@ -111,7 +112,7 @@ void Sound::setFxOn(bool isOn) {
ConfMan.setBool("mute", false);
ConfMan.flushToDisk();
g_vm->syncSoundSettings();
g_engine->syncSoundSettings();
}
void Sound::loadEffectsData() {
@ -215,7 +216,7 @@ void Sound::setMusicOn(bool isOn) {
ConfMan.setBool("mute", false);
ConfMan.flushToDisk();
g_vm->syncSoundSettings();
g_engine->syncSoundSettings();
}
bool Sound::isMusicPlaying() const {
@ -250,5 +251,6 @@ void Sound::updateVolume() {
songCommand(SET_VOLUME, _musicPercent * _musicVolume / 100, _sfxVolume);
}
} // End of namespace Xeen
} // End of namespace MM
} // namespace Xeen
} // namespace Shared
} // namespace MM

@ -0,0 +1,168 @@
/* 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 MM_SHARED_XEEN_SOUND_H
#define MM_SHARED_XEEN_SOUND_H
#include "audio/mixer.h"
#include "audio/audiostream.h"
#include "mm/shared/xeen/file.h"
#include "mm/shared/xeen/sound_driver.h"
namespace MM {
namespace Shared {
namespace Xeen {
class Sound {
private:
SoundDriver *_SoundDriver;
const byte *_effectsData;
Common::Array<uint16> _effectsOffsets;
const byte *_songData;
Audio::Mixer *_mixer;
Audio::SoundHandle _soundHandle;
byte _musicPercent;
int _musicVolume, _sfxVolume;
private:
/**
* Loads effects data that was embedded in the music driver
*/
void loadEffectsData();
/**
* Updates any playing music
*/
void update();
/**
* Updates the music and sound effects playing volume
*/
void updateVolume();
public:
bool _fxOn;
bool _musicOn;
Common::String _currentMusic;
int _musicSide;
bool _subtitles;
public:
Sound(Audio::Mixer *mixer);
virtual ~Sound();
/**
* Starts an effect playing
*/
void playFX(uint effectId);
/**
* Stops any currently playing FX
*/
void stopFX();
/**
* Executes special music command
*/
int songCommand(uint commandId, byte musicVolume = 0, byte sfxVolume = 0);
/**
* Stops any currently playing music
*/
void stopSong() {
songCommand(STOP_SONG);
}
/**
* Sets the in-game music volume percent. This is separate from the ScummVM volume
*/
void setMusicPercent(byte percent);
/**
* Plays a song
*/
void playSong(Common::SeekableReadStream &stream);
/**
* Plays a song
*/
void playSong(const Common::String &name, int param = 0);
/**
* Returns true if music is playing
*/
bool isMusicPlaying() const;
/**
* Sets whether music is on
*/
void setMusicOn(bool isOn);
/**
* Sets whether sound effects is on
*/
void setFxOn(bool isOn);
/**
* Called to reload sound settings
*/
void updateSoundSettings();
/**
* Stops all playing music, FX, and sound samples
*/
void stopAllAudio();
/**
* Play a given sound
*/
void playSound(Common::SeekableReadStream &s, int unused = 0);
/**
* Play a given sound
*/
void playSound(const Common::String &name, int unused = 0);
/**
* Play a given sound
*/
void playSound(const Common::String &name, int ccNum, int unused);
/**
* Stop playing a sound loaded from a .m file
* @remarks In the original, passing 1 to playSound stopped the sound
*/
void stopSound();
/**
* Returns true if a sound file is currently playing
* @remarks In the original, passing 0 to playSound returned play status
*/
bool isSoundPlaying() const;
/**
* Play a given voice file
*/
void playVoice(const Common::String &name, int ccMode = -1);
};
} // namespace Xeen
} // namespace Shared
} // namespace MM
#endif

@ -19,13 +19,15 @@
*
*/
#include "common/debug.h"
#include "common/md5.h"
#include "common/config-manager.h"
#include "mm/xeen/sound_driver.h"
#include "mm/xeen/xeen.h"
#include "mm/xeen/files.h"
#include "mm/shared/xeen/sound_driver.h"
#include "mm/shared/xeen/file.h"
#include "mm/mm.h"
namespace MM {
namespace Shared {
namespace Xeen {
SoundDriver::SoundDriver() : _frameCtr(0) {
@ -238,5 +240,6 @@ const CommandFn SoundDriver::FX_COMMANDS[16] = {
&SoundDriver::cmdChangeFrequency, &SoundDriver::fxEndSubroutine
};
} // End of namespace Xeen
} // End of namespace MM
} // namespace Xeen
} // namespace Shared
} // namespace MM

@ -19,8 +19,8 @@
*
*/
#ifndef XEEN_SOUND_DRIVER_H
#define XEEN_SOUND_DRIVER_H
#ifndef MM_SHARED_XEEN_SOUND_DRIVER_H
#define MM_SHARED_XEEN_SOUND_DRIVER_H
#include "audio/fmopl.h"
#include "audio/mixer.h"
@ -28,7 +28,7 @@
#include "common/mutex.h"
#include "common/queue.h"
#include "common/stack.h"
#include "mm/xeen/files.h"
#include "mm/shared/xeen/file.h"
#define CHANNEL_COUNT 9
@ -37,6 +37,7 @@ namespace OPL {
}
namespace MM {
namespace Shared {
namespace Xeen {
enum MusicCommand {
@ -199,7 +200,8 @@ public:
}
};
} // End of namespace Xeen
} // End of namespace MM
} // namespace Xeen
} // namespace Shared
} // namespace MM
#endif

@ -19,10 +19,12 @@
*
*/
#include "mm/xeen/sound_driver_adlib.h"
#include "mm/xeen/xeen.h"
#include "common/debug.h"
#include "mm/shared/xeen/sound_driver_adlib.h"
#include "mm/mm.h"
namespace MM {
namespace Shared {
namespace Xeen {
#define CALLBACKS_PER_SECOND 73
@ -424,5 +426,6 @@ byte SoundDriverAdlib::calculateLevel(byte level, bool isFx) {
return scaling | (0x3f - totalLevel);
}
} // End of namespace Xeen
} // End of namespace MM
} // namespace Xeen
} // namespace Shared
} // namespace MM

@ -19,16 +19,17 @@
*
*/
#ifndef XEEN_SOUND_DRIVER_ADLIB_H
#define XEEN_SOUND_DRIVER_ADLIB_H
#ifndef MM_SHARED_XEEN_SOUND_DRIVER_ADLIB_H
#define MM_SHARED_XEEN_SOUND_DRIVER_ADLIB_H
#include "mm/xeen/sound_driver.h"
#include "mm/shared/xeen/sound_driver.h"
namespace OPL {
class OPL;
}
namespace MM {
namespace Shared {
namespace Xeen {
class SoundDriverAdlib : public SoundDriver {
@ -162,7 +163,8 @@ public:
int songCommand(uint commandId, byte musicVolume = 0, byte sfxVolume = 0) override;
};
} // End of namespace Xeen
} // End of namespace MM
} // namespace Xeen
} // namespace Shared
} // namespace MM
#endif

@ -22,143 +22,12 @@
#ifndef XEEN_SOUND_H
#define XEEN_SOUND_H
#include "audio/mixer.h"
#include "audio/audiostream.h"
#include "mm/xeen/files.h"
#include "mm/xeen/sound_driver.h"
#include "mm/shared/xeen/sound.h"
namespace MM {
namespace Xeen {
class Sound {
private:
SoundDriver *_SoundDriver;
const byte *_effectsData;
Common::Array<uint16> _effectsOffsets;
const byte *_songData;
Audio::Mixer *_mixer;
Audio::SoundHandle _soundHandle;
byte _musicPercent;
int _musicVolume, _sfxVolume;
private:
/**
* Loads effects data that was embedded in the music driver
*/
void loadEffectsData();
/**
* Updates any playing music
*/
void update();
/**
* Updates the music and sound effects playing volume
*/
void updateVolume();
public:
bool _fxOn;
bool _musicOn;
Common::String _currentMusic;
int _musicSide;
bool _subtitles;
public:
Sound(Audio::Mixer *mixer);
virtual ~Sound();
/**
* Starts an effect playing
*/
void playFX(uint effectId);
/**
* Stops any currently playing FX
*/
void stopFX();
/**
* Executes special music command
*/
int songCommand(uint commandId, byte musicVolume = 0, byte sfxVolume = 0);
/**
* Stops any currently playing music
*/
void stopSong() {
songCommand(STOP_SONG);
}
/**
* Sets the in-game music volume percent. This is separate from the ScummVM volume
*/
void setMusicPercent(byte percent);
/**
* Plays a song
*/
void playSong(Common::SeekableReadStream &stream);
/**
* Plays a song
*/
void playSong(const Common::String &name, int param = 0);
/**
* Returns true if music is playing
*/
bool isMusicPlaying() const;
/**
* Sets whether music is on
*/
void setMusicOn(bool isOn);
/**
* Sets whether sound effects is on
*/
void setFxOn(bool isOn);
/**
* Called to reload sound settings
*/
void updateSoundSettings();
/**
* Stops all playing music, FX, and sound samples
*/
void stopAllAudio();
/**
* Play a given sound
*/
void playSound(Common::SeekableReadStream &s, int unused = 0);
/**
* Play a given sound
*/
void playSound(const Common::String &name, int unused = 0);
/**
* Play a given sound
*/
void playSound(const Common::String &name, int ccNum, int unused);
/**
* Stop playing a sound loaded from a .m file
* @remarks In the original, passing 1 to playSound stopped the sound
*/
void stopSound();
/**
* Returns true if a sound file is currently playing
* @remarks In the original, passing 0 to playSound returned play status
*/
bool isSoundPlaying() const;
/**
* Play a given voice file
*/
void playVoice(const Common::String &name, int ccMode = -1);
};
using Shared::Xeen::Sound;
} // End of namespace Xeen
} // End of namespace MM

@ -339,9 +339,5 @@ uint32 XeenEngine::getGameFeatures() const {
return _gameDescription->features;
}
bool XeenEngine::getIsCD() const {
return getFeatures() & ADGF_CD;
}
} // End of namespace Xeen
} // End of namespace MM

@ -198,11 +198,6 @@ public:
*/
uint32 getGameFeatures() const;
/**
* Returns true if the game is the CD version
*/
bool getIsCD() const;
/**
* Returns a random number
*/