aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-30 17:27:16 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-30 17:27:16 +0100
commitb8194e02679dc88f5c0a240da83a4700ec5200cf (patch)
tree216e2e28793fce2d468b23fa9b5d2a17db32012b /src/crepe/facade
parent9eff2e24fa4cf0ffad2b47cc922a6558bc1a9fa1 (diff)
add doxygen comments + clean up
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/Sound.cpp34
-rw-r--r--src/crepe/facade/Sound.h9
-rw-r--r--src/crepe/facade/SoundContext.cpp7
-rw-r--r--src/crepe/facade/SoundContext.h48
4 files changed, 51 insertions, 47 deletions
diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp
index 33a0c47..ad50637 100644
--- a/src/crepe/facade/Sound.cpp
+++ b/src/crepe/facade/Sound.cpp
@@ -2,7 +2,6 @@
#include "../util/Log.h"
#include "Sound.h"
-#include "SoundContext.h"
using namespace crepe;
using namespace std;
@@ -12,36 +11,3 @@ Sound::Sound(const Asset & src) : Resource(src) {
dbg_trace();
}
Sound::~Sound() { dbg_trace(); }
-
-// void Sound::play(SoundContext & ctx) {
-// if (ctx.engine.getPause(this->handle)) {
-// // resume if paused
-// ctx.engine.setPause(this->handle, false);
-// } else {
-// // or start new sound
-// this->handle = ctx.engine.play(this->sample, this->volume);
-// ctx.engine.setLooping(this->handle, this->looping);
-// }
-// }
-//
-// void Sound::pause(SoundContext & ctx) {
-// if (ctx.engine.getPause(this->handle)) return;
-// ctx.engine.setPause(this->handle, true);
-// }
-//
-// void Sound::rewind(SoundContext & ctx) {
-// if (!ctx.engine.isValidVoiceHandle(this->handle)) return;
-// ctx.engine.seek(this->handle, 0);
-// }
-//
-// void Sound::set_volume(SoundContext & ctx, float volume) {
-// this->volume = volume;
-// if (!ctx.engine.isValidVoiceHandle(this->handle)) return;
-// ctx.engine.setVolume(this->handle, this->volume);
-// }
-//
-// void Sound::set_looping(SoundContext & ctx, bool looping) {
-// this->looping = looping;
-// if (!ctx.engine.isValidVoiceHandle(this->handle)) return;
-// ctx.engine.setLooping(this->handle, this->looping);
-// }
diff --git a/src/crepe/facade/Sound.h b/src/crepe/facade/Sound.h
index 35bccdb..a78a2a7 100644
--- a/src/crepe/facade/Sound.h
+++ b/src/crepe/facade/Sound.h
@@ -12,21 +12,24 @@ class SoundContext;
/**
* \brief Sound resource facade
*
- * This class is a wrapper around a \c SoLoud::Wav instance, which holds a
- * single sample. It is part of the sound facade.
+ * This class is a wrapper around a \c SoLoud::Wav instance, which holds a single sample. It is
+ * part of the sound facade.
*/
class Sound : public Resource {
public:
Sound(const Asset & src);
~Sound(); // dbg_trace
+ //! Voice handle wrapper
struct Handle {
+ //! Voice handle (soloud), used by SoundContext
SoLoud::handle handle;
};
private:
+ //! Deserialized resource (soloud)
SoLoud::Wav sample;
-
+ //! SoundContext uses \c sample
friend class SoundContext;
};
diff --git a/src/crepe/facade/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp
index 470b3cc..8bd7e74 100644
--- a/src/crepe/facade/SoundContext.cpp
+++ b/src/crepe/facade/SoundContext.cpp
@@ -17,17 +17,16 @@ SoundContext::~SoundContext() {
Sound::Handle SoundContext::play(Sound & resource) {
return {
- .handle = this->engine.play(resource.sample, this->default_volume),
+ .handle = this->engine.play(resource.sample, 1.0f),
};
}
void SoundContext::stop(Sound::Handle & handle) { this->engine.stop(handle.handle); }
-void SoundContext::set_volume(Sound & resource, Sound::Handle & handle, float volume) {
+void SoundContext::set_volume(Sound::Handle & handle, float volume) {
this->engine.setVolume(handle.handle, volume);
- this->default_volume = volume;
}
-void SoundContext::set_loop(Sound & resource, Sound::Handle & handle, bool loop) {
+void SoundContext::set_loop(Sound::Handle & handle, bool loop) {
this->engine.setLooping(handle.handle, loop);
}
diff --git a/src/crepe/facade/SoundContext.h b/src/crepe/facade/SoundContext.h
index c651cd5..3bc8be5 100644
--- a/src/crepe/facade/SoundContext.h
+++ b/src/crepe/facade/SoundContext.h
@@ -11,8 +11,8 @@ namespace crepe {
/**
* \brief Sound engine facade
*
- * This class is a wrapper around a \c SoLoud::Soloud instance, which provides
- * the methods for playing \c Sound instances. It is part of the sound facade.
+ * This class is a wrapper around a \c SoLoud::Soloud instance, which provides the methods for
+ * playing \c Sound instances. It is part of the sound facade.
*/
class SoundContext {
public:
@@ -24,15 +24,51 @@ public:
SoundContext & operator=(const SoundContext &) = delete;
SoundContext & operator=(SoundContext &&) = delete;
+ /**
+ * \brief Play a sample
+ *
+ * Plays a Sound from the beginning of the sample and returns a handle to control it later.
+ *
+ * \param resource Sound instance to play
+ *
+ * \returns Handle to control this voice
+ */
virtual Sound::Handle play(Sound & resource);
- virtual void stop(Sound::Handle &);
- virtual void set_volume(Sound &, Sound::Handle &, float);
- virtual void set_loop(Sound &, Sound::Handle &, bool);
+ /**
+ * \brief Stop a voice immediately if it is still playing
+ *
+ * \note This function does nothing if the handle is invalid or if the sound is already
+ * stopped / finished playing.
+ *
+ * \param handle Voice handle returned by SoundContext::play
+ */
+ virtual void stop(Sound::Handle & handle);
+ /**
+ * \brief Change the volume of a voice
+ *
+ * \note This function does nothing if the handle is invalid or if the sound is already
+ * stopped / finished playing.
+ *
+ * \param handle Voice handle returned by SoundContext::play
+ * \param volume New gain value (0=silent, 1=default)
+ */
+ virtual void set_volume(Sound::Handle & handle, float volume);
+ /**
+ * \brief Set the looping behavior of a voice
+ *
+ * \note This function does nothing if the handle is invalid or if the sound is already
+ * stopped / finished playing.
+ *
+ * \param handle Voice handle returned by SoundContext::play
+ * \param loop Looping behavior (false=oneshot, true=loop)
+ */
+ virtual void set_loop(Sound::Handle & handle, bool loop);
private:
+ //! Abstracted class
SoLoud::Soloud engine;
- float default_volume = 1.0f;
+ //! Config reference
Config & config = Config::get_instance();
};