diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/sound/qmixer.cpp | 25 | ||||
-rw-r--r-- | engines/titanic/sound/qmixer.h | 67 | ||||
-rw-r--r-- | engines/titanic/sound/sound_manager.cpp | 37 | ||||
-rw-r--r-- | engines/titanic/sound/sound_manager.h | 18 | ||||
-rw-r--r-- | engines/titanic/sound/wave_file.cpp | 22 | ||||
-rw-r--r-- | engines/titanic/sound/wave_file.h | 37 | ||||
-rw-r--r-- | engines/titanic/support/movie.cpp | 4 |
7 files changed, 167 insertions, 43 deletions
diff --git a/engines/titanic/sound/qmixer.cpp b/engines/titanic/sound/qmixer.cpp index 7df6a70fd2..d0117b240e 100644 --- a/engines/titanic/sound/qmixer.cpp +++ b/engines/titanic/sound/qmixer.cpp @@ -24,4 +24,29 @@ namespace Titanic { +QMixer::QMixer(Audio::Mixer *mixer) : _mixer(mixer) { +} + +bool QMixer::qsWaveMixInitEx(const QMIXCONFIG &config) { + // Not current implemented in ScummVM + return true; +} + +void QMixer::qsWaveMixActivate(bool fActivate) { + // Not current implemented in ScummVM +} + +int QMixer::qsWaveMixOpenChannel(int iChannel, WaveMixOpenChannel mode) { + // Not current implemented in ScummVM + return 0; +} + +void QMixer::qsWaveMixCloseSession() { + _mixer->stopAll(); +} + +void QMixer::qsWaveMixFreeWave(Audio::SoundHandle &handle) { + _mixer->stopHandle(handle); +} + } // End of namespace Titanic z diff --git a/engines/titanic/sound/qmixer.h b/engines/titanic/sound/qmixer.h index 990abf5b52..8dda647d05 100644 --- a/engines/titanic/sound/qmixer.h +++ b/engines/titanic/sound/qmixer.h @@ -27,6 +27,35 @@ namespace Titanic { +enum WaveMixOpenChannel { + QMIX_OPENSINGLE = 0, // Open the single channel specified by iChannel + QMIX_OPENALL = 1, // Opens all the channels, iChannel ignored + QMIX_OPENCOUNT = 2, // Open iChannel Channels (eg. if iChannel = 4 will create channels 0-3) + QMIX_OPENAVAILABLE = 3 // Open the first unopened channel, and return channel number +}; + +/** + * Mixer configuration structure for qsWaveMixInitEx + */ +struct QMIXCONFIG { + uint32 dwSize; + uint32 dwFlags; + uint32 dwSamplingRate; // Sampling rate in Hz + void *lpIDirectSound; + const void *lpGuid; + int iChannels; // Number of channels + int iOutput; // if 0, uses best output device + int iLatency; // (in ms) if 0, uses default for output device + int iMath; // style of math + uint hwnd; + + QMIXCONFIG() : dwSize(40), dwFlags(0), dwSamplingRate(0), lpIDirectSound(nullptr), + lpGuid(nullptr), iChannels(0), iOutput(0), iLatency(0), iMath(0), hwnd(0) {} + QMIXCONFIG(uint32 rate, int channels, int latency) : dwSize(40), dwFlags(0), + dwSamplingRate(rate), iChannels(channels), iLatency(latency), + lpIDirectSound(nullptr), lpGuid(nullptr), iOutput(0), iMath(0), hwnd(0) {} +}; + /** * Vector positioning in metres */ @@ -41,19 +70,43 @@ struct QSVECTOR { * QSound Labs, Inc. Which itself is apparently based on Microsoft's * WaveMix API. * - * It does not currently have any actual code from - * the library, and instead remaps calls to ScummVM's existing mixer - * where possible. This means that advanced features of the QMixer - * library, like being able to set up both the player and sounds at - * different positions are currently ignored, and all sounds play - * at full volume. + * It does not currently have any actual code from the library, + * and instead remaps calls to ScummVM's existing mixer where possible. + * This means that advanced features of the QMixer library, like being + * able to set up both the player and sounds at different positions are + * currently ignored, and all sounds play at full volume. */ class QMixer { private: Audio::Mixer *_mixer; public: - QMixer(Audio::Mixer *mixer) : _mixer(mixer) {} + QMixer(Audio::Mixer *mixer); virtual ~QMixer() {} + + /** + * Initializes the mixer + */ + bool qsWaveMixInitEx(const QMIXCONFIG &config); + + /** + * Activates the mixer + */ + void qsWaveMixActivate(bool fActivate); + + /** + * Opens channels in the mixer for access + */ + int qsWaveMixOpenChannel(int iChannel, WaveMixOpenChannel mode); + + /** + * Closes down the mixer + */ + void qsWaveMixCloseSession(); + + /** + * Stops a sound from playing + */ + void qsWaveMixFreeWave(Audio::SoundHandle &handle); }; } // End of namespace Titanic diff --git a/engines/titanic/sound/sound_manager.cpp b/engines/titanic/sound/sound_manager.cpp index bd50a8ea9b..0d133c37e6 100644 --- a/engines/titanic/sound/sound_manager.cpp +++ b/engines/titanic/sound/sound_manager.cpp @@ -24,6 +24,10 @@ namespace Titanic { +const uint SAMPLING_RATE = 22050; +const uint LATENCY = 100; +const uint CHANNELS_COUNT = 16; + CSoundManager::CSoundManager() : _musicPercent(75.0), _speechPercent(75.0), _masterPercent(75.0), _parrotPercent(75.0), _field14(1) { } @@ -33,11 +37,27 @@ CSoundManager::CSoundManager() : _musicPercent(75.0), _speechPercent(75.0), QSoundManager::QSoundManager(Audio::Mixer *mixer) : CSoundManager(), QMixer(mixer), _field18(0), _field1C(0) { Common::fill(&_field4A0[0], &_field4A0[16], 0); + + qsWaveMixInitEx(QMIXCONFIG(SAMPLING_RATE, CHANNELS_COUNT, LATENCY)); + qsWaveMixActivate(true); + qsWaveMixOpenChannel(0, QMIX_OPENALL); +} + +QSoundManager::~QSoundManager() { + // Close down the mixer + qsWaveMixCloseSession(); } CWaveFile *QSoundManager::loadSound(const CString &name) { - warning("TODO"); - return nullptr; + CWaveFile *waveFile = new CWaveFile(); + + // Try to load the specified sound + if (!waveFile->loadSound(name)) { + delete waveFile; + return nullptr; + } + + return waveFile; } CWaveFile *QSoundManager::loadSpeech(CDialogueFile *dialogueFile, int speechId) { @@ -98,13 +118,8 @@ int QSoundManager::proc16() const { return 0; } -void QSoundManager::WaveMixPump() { - warning("TODO"); -} - -bool QSoundManager::movieStarted() const { - // TODO - return 0; +uint QSoundManager::getLatency() const { + return LATENCY; } void QSoundManager::proc19(int v) { @@ -127,4 +142,8 @@ void QSoundManager::proc30() { warning("TODO"); } +void QSoundManager::soundFreed(Audio::SoundHandle &handle) { + qsWaveMixFreeWave(handle); +} + } // End of namespace Titanic z diff --git a/engines/titanic/sound/sound_manager.h b/engines/titanic/sound/sound_manager.h index af97db35ed..f703e4f022 100644 --- a/engines/titanic/sound/sound_manager.h +++ b/engines/titanic/sound/sound_manager.h @@ -81,12 +81,11 @@ public: virtual bool isActive(const CWaveFile *waveFile) const { return false; } virtual int proc16() const { return 0; } - virtual void WaveMixPump() {} /** - * Called when a movie with audio is started + * Returns the movie latency */ - virtual bool movieStarted() const { return false; } + virtual uint getLatency() const { return 0; } virtual void setMusicPercent(double percent) { _musicPercent = percent; } virtual void setSpeechPercent(double percent) { _speechPercent = percent; } @@ -138,7 +137,7 @@ public: int _field4A0[16]; public: QSoundManager(Audio::Mixer *mixer); - virtual ~QSoundManager() {} + virtual ~QSoundManager(); /** * Loads a sound @@ -176,13 +175,11 @@ public: virtual bool isActive(const CWaveFile *soundRes) const; virtual int proc16() const; - virtual void WaveMixPump(); - /** - * Called when a movie with audio is started + * Returns the movie latency */ - virtual bool movieStarted() const; + virtual uint getLatency() const; virtual void proc19(int v); virtual void proc20(int v); @@ -190,6 +187,11 @@ public: virtual void proc29(); virtual void proc30(); + + /** + * Called when a wave file is freed + */ + void soundFreed(Audio::SoundHandle &handle); }; } // End of namespace Titanic diff --git a/engines/titanic/sound/wave_file.cpp b/engines/titanic/sound/wave_file.cpp index 7749a7bdfc..56e12e3e61 100644 --- a/engines/titanic/sound/wave_file.cpp +++ b/engines/titanic/sound/wave_file.cpp @@ -20,13 +20,35 @@ * */ +#include "audio/decoders/wave.h" #include "titanic/sound/wave_file.h" +#include "titanic/sound/sound_manager.h" +#include "titanic/support/simple_file.h" namespace Titanic { +CWaveFile::~CWaveFile() { + if (_stream) { + _owner->soundFreed(_soundHandle); + delete _stream; + } +} + int CWaveFile::fn1() { // TODO return 0; } +bool CWaveFile::loadSound(const CString &name) { + assert(!_stream); + + StdCWadFile file; + if (!file.open(name)) + return false; + + Common::SeekableReadStream *stream = file.readStream(); + _stream = Audio::makeWAVStream(stream->readStream(stream->size()), DisposeAfterUse::YES); +} + + } // End of namespace Titanic z diff --git a/engines/titanic/sound/wave_file.h b/engines/titanic/sound/wave_file.h index 0d8d8634ac..ff85df5bd0 100644 --- a/engines/titanic/sound/wave_file.h +++ b/engines/titanic/sound/wave_file.h @@ -23,32 +23,35 @@ #ifndef TITANIC_WAVE_FILE_H #define TITANIC_WAVE_FILE_H -#include "titanic/support/simple_file.h" +#include "audio/audiostream.h" +#include "audio/mixer.h" +#include "titanic/support/string.h" namespace Titanic { -class CSoundManager; +class QSoundManager; class CWaveFile { public: - int _field0; - int _field4; - int _field8; - uint _handle; - CSoundManager *_owner; - int _field14; - int _field18; - int _field1C; - int _field20; - int _field24; - int _field28; - int _field2C; + QSoundManager *_owner; + Audio::AudioStream *_stream; + Audio::SoundHandle _soundHandle; public: - CWaveFile() : _field0(2), _field4(0), _field8(0), _handle(0), - _owner(nullptr), _field14(1), _field18(0), _field1C(0), - _field20(0), _field24(0), _field28(0), _field2C(-1) {} + CWaveFile() : _owner(nullptr), _stream(nullptr) {} + CWaveFile(QSoundManager *owner) : _owner(owner), _stream(nullptr) {} + ~CWaveFile(); int fn1(); + + /** + * Tries to load the specified wave file sound + */ + bool loadSound(const CString &name); + + /** + * Returns true if the wave file has data loaded + */ + bool isLoaded() const { return _stream != nullptr; } }; } // End of namespace Titanic diff --git a/engines/titanic/support/movie.cpp b/engines/titanic/support/movie.cpp index 8810cf0a6c..5453d8ca9c 100644 --- a/engines/titanic/support/movie.cpp +++ b/engines/titanic/support/movie.cpp @@ -199,8 +199,8 @@ int OSMovie::getFrame() const { } void OSMovie::movieStarted() { - if (_aviSurface._hasAudio) - _aviSurface._soundManager->movieStarted(); + //if (_aviSurface._hasAudio) + // _aviSurface._soundManager->movieStarted(); // Register the movie in the playing list addToPlayingMovies(); |