diff options
author | Borja Lorente | 2016-08-01 17:19:29 +0200 |
---|---|---|
committer | Borja Lorente | 2016-08-14 19:00:36 +0200 |
commit | dd2908fe42d54037436e7b3a05bc275d11822a93 (patch) | |
tree | c17e824fbfcd99e651062a1882f2e162e9d2abe1 | |
parent | 842bff03e0fd949bcac1b3fd4c281d3fc5547ca5 (diff) | |
download | scummvm-rg350-dd2908fe42d54037436e7b3a05bc275d11822a93.tar.gz scummvm-rg350-dd2908fe42d54037436e7b3a05bc275d11822a93.tar.bz2 scummvm-rg350-dd2908fe42d54037436e7b3a05bc275d11822a93.zip |
MACVENTURE: Add basic audio playback
-rw-r--r-- | engines/macventure/macventure.cpp | 2 | ||||
-rw-r--r-- | engines/macventure/sound.cpp | 70 | ||||
-rw-r--r-- | engines/macventure/sound.h | 8 |
3 files changed, 44 insertions, 36 deletions
diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 5d9d6f9938..21d98b1601 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -117,7 +117,7 @@ Common::Error MacVentureEngine::run() { _world = new World(this, _resourceManager); _scriptEngine = new ScriptEngine(this, _world); - _soundManager = new SoundManager(this); + _soundManager = new SoundManager(this, _mixer); _paused = false; _halted = false; diff --git a/engines/macventure/sound.cpp b/engines/macventure/sound.cpp index f7fb0b5a17..7eca8b4e8a 100644 --- a/engines/macventure/sound.cpp +++ b/engines/macventure/sound.cpp @@ -22,12 +22,45 @@ #include "macventure/sound.h" +#include "audio/mixer.h" +#include "audio/audiostream.h" +#include "audio/decoders/raw.h" + namespace MacVenture { +// SoundManager +SoundManager::SoundManager(MacVentureEngine *engine, Audio::Mixer *mixer) { + _container = nullptr; + Common::String filename = engine->getFilePath(kSoundPathID); + _container = new Container(filename); + _mixer = mixer; + debug(1, "Created sound manager with file %s", filename.c_str()); +} + +SoundManager::~SoundManager(){ + if (_container) + delete _container; + + Common::HashMap<ObjID, SoundAsset*>::iterator it; + for (it = _assets.begin(); it != _assets.end(); it++) { + delete it->_value; + } +} + +uint32 SoundManager::playSound(ObjID sound) { + ensureLoaded(sound); + _assets[sound]->play(_mixer, &_handle); + return _assets[sound]->getPlayLength(); +} + +void SoundManager::ensureLoaded(ObjID sound) { + if (!_assets.contains(sound)) + _assets[sound] = new SoundAsset(_container, sound); +} + SoundAsset::SoundAsset(Container *container, ObjID id) : _container(container), _id(id) { - //TODO Decode the sound if (_container->getItemByteSize(_id) == 0) warning("Trying to load an empty sound asset."); @@ -67,9 +100,9 @@ SoundAsset::SoundAsset(Container *container, ObjID id) : SoundAsset::~SoundAsset() {} -void SoundAsset::play() { - //TODO: Play song - warning("SoundAsset::play() not yet implemented"); +void SoundAsset::play(Audio::Mixer *mixer, Audio::SoundHandle *soundHandle) { + Audio::AudioStream *sound = Audio::makeRawStream(&_data.front(), _length, _frequency, Audio::FLAG_UNSIGNED); + mixer->playStream(Audio::Mixer::kPlainSoundType, soundHandle, sound); } uint32 SoundAsset::getPlayLength() { @@ -221,33 +254,4 @@ void SoundAsset::decode7e(Common::SeekableReadStream *stream) { } } -// SoundManager -SoundManager::SoundManager(MacVentureEngine *engine) { - _container = nullptr; - Common::String filename = engine->getFilePath(kSoundPathID); - _container = new Container(filename); - debug(1, "Created sound manager with file %s", filename.c_str()); -} - -SoundManager::~SoundManager(){ - if (_container) - delete _container; - - Common::HashMap<ObjID, SoundAsset*>::iterator it; - for (it = _assets.begin(); it != _assets.end(); it++) { - delete it->_value; - } -} - -uint32 SoundManager::playSound(ObjID sound) { - ensureLoaded(sound); - _assets[sound]->play(); - return _assets[sound]->getPlayLength(); -} - -void SoundManager::ensureLoaded(ObjID sound) { - if (!_assets.contains(sound)) - _assets[sound] = new SoundAsset(_container, sound); -} - } //End of namespace MacVenture diff --git a/engines/macventure/sound.h b/engines/macventure/sound.h index 58fc650b00..d1b1bb8a37 100644 --- a/engines/macventure/sound.h +++ b/engines/macventure/sound.h @@ -29,6 +29,8 @@ #include "common/file.h" #include "common/hashmap.h" +#include "audio/mixer.h" + namespace MacVenture { enum SoundType { @@ -47,7 +49,7 @@ public: SoundAsset(Container *container, ObjID id); ~SoundAsset(); - void play(); + void play(Audio::Mixer *mixer, Audio::SoundHandle *soundHandle); uint32 getPlayLength(); private: @@ -72,7 +74,7 @@ private: class SoundManager { public: - SoundManager(MacVentureEngine *engine); + SoundManager(MacVentureEngine *engine, Audio::Mixer *mixer); ~SoundManager(); uint32 playSound(ObjID sound); @@ -84,6 +86,8 @@ private: Container *_container; Common::HashMap<ObjID, SoundAsset*> _assets; + Audio::SoundHandle _handle; + Audio::Mixer *_mixer; }; } // End of namespace MacVenture |