aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/Sound.cpp29
-rw-r--r--src/crepe/Sound.h15
-rw-r--r--src/crepe/SoundSystem.cpp2
-rw-r--r--src/crepe/SoundSystem.h2
4 files changed, 43 insertions, 5 deletions
diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp
index 136a71d..20f1787 100644
--- a/src/crepe/Sound.cpp
+++ b/src/crepe/Sound.cpp
@@ -20,19 +20,42 @@ void Sound::load(std::unique_ptr<api::Resource> res) {
}
void Sound::play() {
- SoundSystem & system = SoundSystem::instance();
+ SoundSystem & system = SoundSystem::get_instance();
if (system.engine.getPause(this->handle)) {
// resume if paused
system.engine.setPause(this->handle, false);
} else {
// or start new sound
- this->handle = system.engine.play(this->sample);
+ this->handle = system.engine.play(this->sample, this->volume);
+ system.engine.setLooping(this->handle, this->looping);
}
}
void Sound::pause() {
- SoundSystem & system = SoundSystem::instance();
+ SoundSystem & system = SoundSystem::get_instance();
if (system.engine.getPause(this->handle)) return;
system.engine.setPause(this->handle, true);
}
+void Sound::rewind() {
+ SoundSystem & system = SoundSystem::get_instance();
+ if (!system.engine.isValidVoiceHandle(this->handle)) return;
+ system.engine.seek(this->handle, 0);
+}
+
+void Sound::set_volume(float volume) {
+ this->volume = volume;
+
+ SoundSystem & system = SoundSystem::get_instance();
+ if (!system.engine.isValidVoiceHandle(this->handle)) return;
+ system.engine.setVolume(this->handle, this->volume);
+}
+
+void Sound::set_looping(bool looping) {
+ this->looping = looping;
+
+ SoundSystem & system = SoundSystem::get_instance();
+ if (!system.engine.isValidVoiceHandle(this->handle)) return;
+ system.engine.setLooping(this->handle, this->looping);
+}
+
diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h
index 9da17b9..4c51188 100644
--- a/src/crepe/Sound.h
+++ b/src/crepe/Sound.h
@@ -46,11 +46,23 @@ public:
*/
void set_volume(float volume);
/**
+ * \brief Get playback volume / gain
+ *
+ * \return Volume
+ */
+ float get_volume() const { return this->volume; }
+ /**
* \brief Set looping behavior for this sample
*
* \param looping Looping behavior (false = one-shot, true = loop)
*/
void set_looping(bool looping);
+ /**
+ * \brief Get looping behavior
+ *
+ * \return true if looping, false if one-shot
+ */
+ bool get_looping() const { return this->looping; }
public:
Sound(const char * src);
@@ -62,6 +74,9 @@ private:
private:
SoLoud::Wav sample;
SoLoud::handle handle;
+
+ float volume = 1.0f;
+ bool looping = false;
};
}
diff --git a/src/crepe/SoundSystem.cpp b/src/crepe/SoundSystem.cpp
index 00f874c..b57e51a 100644
--- a/src/crepe/SoundSystem.cpp
+++ b/src/crepe/SoundSystem.cpp
@@ -4,7 +4,7 @@
using namespace crepe;
-SoundSystem & SoundSystem::instance() {
+SoundSystem & SoundSystem::get_instance() {
static SoundSystem instance;
return instance;
}
diff --git a/src/crepe/SoundSystem.h b/src/crepe/SoundSystem.h
index da3927a..34dd6c5 100644
--- a/src/crepe/SoundSystem.h
+++ b/src/crepe/SoundSystem.h
@@ -12,7 +12,7 @@ private:
virtual ~SoundSystem();
// singleton
- static SoundSystem & instance();
+ static SoundSystem & get_instance();
SoundSystem(const SoundSystem &) = delete;
SoundSystem(SoundSystem &&) = delete;
SoundSystem &operator=(const SoundSystem &) = delete;