diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-09-29 17:22:58 +0200 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-09-29 17:22:58 +0200 |
commit | 90174919ba8c019d4b88915557be0adc3769b3e6 (patch) | |
tree | a89feb8c2137f4eefb22d5b09031e6826bbbfc72 /src | |
parent | e4a3ef6e324acc8edf9f0797caa244967907a676 (diff) |
WIP cleanup (broken, but more like the class diagram)
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/Sound.cpp | 10 | ||||
-rw-r--r-- | src/crepe/Sound.h | 10 | ||||
-rw-r--r-- | src/crepe/SoundSystem.cpp | 11 | ||||
-rw-r--r-- | src/crepe/SoundSystem.h | 6 | ||||
-rw-r--r-- | src/dummy_audio.cpp | 29 |
5 files changed, 29 insertions, 37 deletions
diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 181366a..09ffd5f 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -7,7 +7,15 @@ using namespace crepe; Sound::Sound(std::unique_ptr<api::Resource> res) { dbg_trace(); - this->res = std::move(res); + this->load(std::move(res)); +} + +Sound::Sound(const char * src) { + dbg_trace(); + this->load(std::make_unique<api::Resource>(src)); +} + +void Sound::load(std::unique_ptr<api::Resource> res) { this->sample.load(this->res->canonical()); } diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index 333465b..163c5b4 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -9,8 +9,6 @@ namespace crepe { -class SoundSystem; - class Sound { public: /** @@ -54,15 +52,17 @@ public: */ void set_looping(bool looping); -private: - friend class SoundSystem; +public: + Sound(const char * src); Sound(std::unique_ptr<api::Resource> res); private: + void load(std::unique_ptr<api::Resource> res); + +private: std::unique_ptr<api::Resource> res; SoLoud::Wav sample; SoLoud::handle handle; - bool paused; }; } diff --git a/src/crepe/SoundSystem.cpp b/src/crepe/SoundSystem.cpp index 29bd196..00f874c 100644 --- a/src/crepe/SoundSystem.cpp +++ b/src/crepe/SoundSystem.cpp @@ -1,7 +1,6 @@ #include "util/log.h" #include "SoundSystem.h" -#include <memory> using namespace crepe; @@ -10,16 +9,6 @@ SoundSystem & SoundSystem::instance() { return instance; } -std::unique_ptr<Sound> SoundSystem::sound(const std::string & src) { - auto res = std::make_unique<api::Resource>(src); - return SoundSystem::sound(std::move(res)); -} - -std::unique_ptr<Sound> SoundSystem::sound(std::unique_ptr<api::Resource> res) { - Sound * out = new Sound(std::move(res)); - return std::unique_ptr<Sound>(out); -} - SoundSystem::SoundSystem() { dbg_trace(); engine.init(); diff --git a/src/crepe/SoundSystem.h b/src/crepe/SoundSystem.h index 515cb29..da3927a 100644 --- a/src/crepe/SoundSystem.h +++ b/src/crepe/SoundSystem.h @@ -2,17 +2,11 @@ #include <soloud.h> -#include <memory> - #include "Sound.h" namespace crepe { class SoundSystem { -public: - static std::unique_ptr<Sound> sound(const std::string & res); - static std::unique_ptr<Sound> sound(std::unique_ptr<api::Resource> res); - private: SoundSystem(); virtual ~SoundSystem(); diff --git a/src/dummy_audio.cpp b/src/dummy_audio.cpp index fb1e3ab..1249076 100644 --- a/src/dummy_audio.cpp +++ b/src/dummy_audio.cpp @@ -1,5 +1,5 @@ -#include "crepe/SoundSystem.h" #include "crepe/util/log.h" +#include "crepe/Sound.h" #include <chrono> #include <thread> @@ -7,32 +7,33 @@ using namespace crepe; using namespace std; using namespace std::chrono_literals; +using std::make_unique; int main() { dbg_trace(); - auto bgm = SoundSystem::sound("../mwe/audio/bgm.ogg"); - auto sfx1 = SoundSystem::sound("../mwe/audio/sfx1.wav"); - auto sfx2 = SoundSystem::sound("../mwe/audio/sfx2.wav"); - auto sfx3 = SoundSystem::sound("../mwe/audio/sfx3.wav"); + auto bgm = Sound("../mwe/audio/bgm.ogg"); + auto sfx1 = Sound("../mwe/audio/sfx1.wav"); + auto sfx2 = Sound("../mwe/audio/sfx2.wav"); + auto sfx3 = Sound("../mwe/audio/sfx3.wav"); - bgm->play(); + bgm.play(); // play each sample sequentially this_thread::sleep_for(500ms); - sfx1->play(); + sfx1.play(); this_thread::sleep_for(500ms); - sfx2->play(); - bgm->pause(); + sfx2.play(); + bgm.pause(); this_thread::sleep_for(500ms); - sfx3->play(); - bgm->play(); + sfx3.play(); + bgm.play(); this_thread::sleep_for(500ms); // play all samples simultaniously - sfx1->play(); - sfx2->play(); - sfx3->play(); + sfx1.play(); + sfx2.play(); + sfx3.play(); this_thread::sleep_for(1000ms); return 0; |