aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/SoundContext.h
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-11 13:21:19 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-11 13:21:19 +0100
commit357ebfc3eac1d39b02875e1bd78ae6f58b10f824 (patch)
tree7d79435fa764c0fedcc912ddaf876ff03ef8be5e /src/crepe/facade/SoundContext.h
parent6eef90e9ffb1d8fc25161e912bc5d8aa8e4024da (diff)
parentc45b60941b82dec2097d958b396a117b1634eada (diff)
Merge remote-tracking branch 'origin/master' into max/AI
Diffstat (limited to 'src/crepe/facade/SoundContext.h')
-rw-r--r--src/crepe/facade/SoundContext.h62
1 files changed, 56 insertions, 6 deletions
diff --git a/src/crepe/facade/SoundContext.h b/src/crepe/facade/SoundContext.h
index d703c16..d986c59 100644
--- a/src/crepe/facade/SoundContext.h
+++ b/src/crepe/facade/SoundContext.h
@@ -2,30 +2,80 @@
#include <soloud/soloud.h>
+#include "../api/Config.h"
+
#include "Sound.h"
+#include "SoundHandle.h"
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 {
-private:
- // singleton
+public:
SoundContext();
virtual ~SoundContext();
+
SoundContext(const SoundContext &) = delete;
SoundContext(SoundContext &&) = delete;
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 SoundHandle play(Sound & resource);
+ /**
+ * \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(const SoundHandle & 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(const SoundHandle & 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(const SoundHandle & handle, bool loop);
+
private:
- static SoundContext & get_instance();
+ //! Abstracted class
SoLoud::Soloud engine;
- friend class Sound;
+
+ //! Config reference
+ Config & config = Config::get_instance();
+
+ //! Sound handle registry
+ std::unordered_map<SoundHandle, SoLoud::handle> registry;
+ //! Unique handle counter
+ SoundHandle next_handle = 0;
};
} // namespace crepe