diff options
Diffstat (limited to 'src/crepe/Sound.cpp')
-rw-r--r-- | src/crepe/Sound.cpp | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 09ffd5f..64fa281 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -1,38 +1,60 @@ #include "util/log.h" #include "Sound.h" -#include "SoundSystem.h" +#include "SoundContext.h" using namespace crepe; -Sound::Sound(std::unique_ptr<api::Resource> res) { +Sound::Sound(std::unique_ptr<Asset> res) { dbg_trace(); this->load(std::move(res)); } Sound::Sound(const char * src) { dbg_trace(); - this->load(std::make_unique<api::Resource>(src)); + this->load(std::make_unique<Asset>(src)); } -void Sound::load(std::unique_ptr<api::Resource> res) { - this->sample.load(this->res->canonical()); +void Sound::load(std::unique_ptr<Asset> res) { + this->sample.load(res->canonical()); } void Sound::play() { - SoundSystem & system = SoundSystem::instance(); - if (system.engine.getPause(this->handle)) { + SoundContext & ctx = SoundContext::get_instance(); + if (ctx.engine.getPause(this->handle)) { // resume if paused - system.engine.setPause(this->handle, false); + ctx.engine.setPause(this->handle, false); } else { // or start new sound - this->handle = system.engine.play(this->sample); + this->handle = ctx.engine.play(this->sample, this->volume); + ctx.engine.setLooping(this->handle, this->looping); } } void Sound::pause() { - SoundSystem & system = SoundSystem::instance(); - if (system.engine.getPause(this->handle)) return; - system.engine.setPause(this->handle, true); + SoundContext & ctx = SoundContext::get_instance(); + if (ctx.engine.getPause(this->handle)) return; + ctx.engine.setPause(this->handle, true); } +void Sound::rewind() { + SoundContext & ctx = SoundContext::get_instance(); + if (!ctx.engine.isValidVoiceHandle(this->handle)) return; + ctx.engine.seek(this->handle, 0); +} + +void Sound::set_volume(float volume) { + this->volume = volume; + + SoundContext & ctx = SoundContext::get_instance(); + if (!ctx.engine.isValidVoiceHandle(this->handle)) return; + ctx.engine.setVolume(this->handle, this->volume); +} + +void Sound::set_looping(bool looping) { + this->looping = looping; + + SoundContext & ctx = SoundContext::get_instance(); + if (!ctx.engine.isValidVoiceHandle(this->handle)) return; + ctx.engine.setLooping(this->handle, this->looping); +} |