From f3eeedc91a04ca0651e0fe78a2119e7e3e38e391 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 25 Sep 2024 17:36:31 +0200 Subject: WIP Audio API + facade --- src/crepe/CMakeLists.txt | 7 +++++-- src/crepe/Sound.cpp | 9 +++++++++ src/crepe/Sound.h | 30 ++++++++++++++++++++++++++++++ src/crepe/api/AudioSource.cpp | 25 +++++++++++++++++++++++++ src/crepe/api/AudioSource.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/crepe/api/CMakeLists.txt | 4 ++++ src/crepe/api/Component.h | 11 +++++++++++ src/crepe/api/Resource.h | 17 +++++++++++++++++ src/crepe/main.cpp | 3 --- src/crepe/util/CMakeLists.txt | 0 src/crepe/util/debug.cpp | 0 src/crepe/util/debug.h | 0 12 files changed, 143 insertions(+), 5 deletions(-) create mode 100644 src/crepe/Sound.cpp create mode 100644 src/crepe/Sound.h create mode 100644 src/crepe/api/AudioSource.cpp create mode 100644 src/crepe/api/AudioSource.h create mode 100644 src/crepe/api/CMakeLists.txt create mode 100644 src/crepe/api/Component.h create mode 100644 src/crepe/api/Resource.h delete mode 100644 src/crepe/main.cpp create mode 100644 src/crepe/util/CMakeLists.txt create mode 100644 src/crepe/util/debug.cpp create mode 100644 src/crepe/util/debug.h (limited to 'src/crepe') diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 392b7d7..aa64262 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -1,3 +1,6 @@ -target_sources(main PUBLIC - main.cpp +target_sources(crepe PUBLIC + Sound.cpp ) + +add_subdirectory(api) + diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp new file mode 100644 index 0000000..f45a697 --- /dev/null +++ b/src/crepe/Sound.cpp @@ -0,0 +1,9 @@ +#include "Sound.h" + +using namespace crepe; + +Sound::Sound(std::unique_ptr res) { + _res = std::move(res); +} + + diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h new file mode 100644 index 0000000..ac4b7f4 --- /dev/null +++ b/src/crepe/Sound.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +#include + +#include "api/Resource.h" + +namespace crepe { + +class Sound { +public: + Sound(std::unique_ptr res); + virtual ~Sound() = default; + +public: + void pause(); + void play(); + void rewind(); + void set_volume(float volume); + void set_looping(bool looping); + +private: + std::unique_ptr _res; + SoLoud::handle _handle; + bool _paused; +}; + +} + diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp new file mode 100644 index 0000000..cbde79f --- /dev/null +++ b/src/crepe/api/AudioSource.cpp @@ -0,0 +1,25 @@ +#include "AudioSource.h" + +#include "../Sound.h" +#include + +using namespace crepe::api; + +AudioSource::AudioSource(std::unique_ptr audio_clip) { + this->_sound = std::make_unique(std::move(audio_clip)); +} + +void AudioSource::play() { + return this->play(false); +} + +void AudioSource::play(bool looping) { + this->_sound->set_looping(looping); + this->_sound->play(); +} + +void AudioSource::stop() { + this->_sound->pause(); + this->_sound->rewind(); +} + diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h new file mode 100644 index 0000000..6a038be --- /dev/null +++ b/src/crepe/api/AudioSource.h @@ -0,0 +1,42 @@ +#pragma once + +#include + +#include "Component.h" +#include "Resource.h" + +namespace crepe { +class Sound; +} + +namespace crepe::api { + +//! Audio source component +class AudioSource : Component { +public: + AudioSource(std::unique_ptr audio_clip); + virtual ~AudioSource() = default; + +public: + //! Start or resume this audio source + void play(); + void play(bool looping); + //! Stop this audio source + void stop(); + +public: + //! Sample file location + std::unique_ptr audio_clip; + //! TODO: ????? + bool play_on_awake; + //! Repeat the current audio clip during playback + bool loop; + //! Normalized volume (0.0 - 1.0) + float volume; + +private: + std::unique_ptr _sound; +}; + +} + diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt new file mode 100644 index 0000000..94617a4 --- /dev/null +++ b/src/crepe/api/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(crepe PUBLIC + AudioSource.cpp +) + diff --git a/src/crepe/api/Component.h b/src/crepe/api/Component.h new file mode 100644 index 0000000..2abb461 --- /dev/null +++ b/src/crepe/api/Component.h @@ -0,0 +1,11 @@ +#pragma once + +namespace crepe::api { + +class Component { +public: + bool active; +}; + +} + diff --git a/src/crepe/api/Resource.h b/src/crepe/api/Resource.h new file mode 100644 index 0000000..620a10e --- /dev/null +++ b/src/crepe/api/Resource.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace crepe::api { + +class Resource { +public: + Resource(const std::string & source); + virtual ~Resource(); + +private: + std::string _source; +}; + +} + diff --git a/src/crepe/main.cpp b/src/crepe/main.cpp deleted file mode 100644 index 8e9a184..0000000 --- a/src/crepe/main.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int main() { printf("Hello World!\n"); } diff --git a/src/crepe/util/CMakeLists.txt b/src/crepe/util/CMakeLists.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/crepe/util/debug.cpp b/src/crepe/util/debug.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/crepe/util/debug.h b/src/crepe/util/debug.h new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 3cb7227c3c9678141ff74915331b706265c380cb Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sat, 28 Sep 2024 17:07:56 +0200 Subject: more WIP audio facade --- src/CMakeLists.txt | 15 +++++++++--- src/crepe/CMakeLists.txt | 6 +++++ src/crepe/Sound.cpp | 19 ++++++++++++++-- src/crepe/Sound.h | 54 ++++++++++++++++++++++++++++++++++++++------ src/crepe/SoundSystem.cpp | 25 ++++++++++++++++++++ src/crepe/SoundSystem.h | 27 ++++++++++++++++++++++ src/crepe/api/CMakeLists.txt | 9 +++++++- src/crepe/api/Resource.cpp | 12 ++++++++++ src/crepe/api/Resource.h | 11 ++++++--- src/dummy_audio.cpp | 37 ++++++++++++++++++++++++++++++ test/CMakeLists.txt | 2 +- 11 files changed, 200 insertions(+), 17 deletions(-) create mode 100644 src/crepe/SoundSystem.cpp create mode 100644 src/crepe/SoundSystem.h create mode 100644 src/crepe/api/Resource.cpp create mode 100644 src/dummy_audio.cpp (limited to 'src/crepe') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cc71435..232d330 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,13 +15,22 @@ project(crepe C CXX) add_library(crepe SHARED) target_include_directories(crepe - SYSTEM INTERFACE . + PUBLIC SYSTEM INTERFACE . ) -# NOTE: all libraries *must* be linked as PRIVATE +# TODO: libraries should be linked as PRIVATE target_link_libraries(crepe - PRIVATE soloud + PUBLIC soloud ) add_subdirectory(crepe) +install( + TARGETS crepe + FILE_SET HEADERS DESTINATION include/crepe +) + + +add_executable(dummy_audio dummy_audio.cpp) +target_link_libraries(dummy_audio PUBLIC crepe) + diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index aa64262..13d9be5 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -1,5 +1,11 @@ target_sources(crepe PUBLIC Sound.cpp + SoundSystem.cpp +) + +target_sources(crepe PUBLIC FILE_SET HEADERS FILES + Sound.h + SoundSystem.h ) add_subdirectory(api) diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index f45a697..d48393c 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -1,9 +1,24 @@ #include "Sound.h" +#include "SoundSystem.h" using namespace crepe; -Sound::Sound(std::unique_ptr res) { - _res = std::move(res); +Sound::Sound(std::unique_ptr res, SoundSystem & system) : system(system) { + this->res = std::move(res); } +void Sound::play() { + if (this->system.engine.getPause(this->handle)) { + // resume if paused + this->system.engine.setPause(this->handle, false); + } else { + // or start new sound + this->handle = this->system.engine.play(this->sample); + } +} + +void Sound::pause() { + if (this->system.engine.getPause(this->handle)) return; + this->system.engine.setPause(this->handle, true); +} diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index ac4b7f4..71fe390 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include @@ -8,22 +9,61 @@ namespace crepe { -class Sound { -public: - Sound(std::unique_ptr res); - virtual ~Sound() = default; +class SoundSystem; +class Sound { public: + /** + * \brief Pause this sample + * + * Pauses this sound if it is playing, or does nothing if it is already + * paused. The playhead position is saved, such that calling \c play() after + * this function makes the sound resume. + */ void pause(); + /** + * \brief Play this sample + * + * Resume playback if this sound is paused, or start from the beginning of + * the sample. + * + * \note This class only saves a reference to the most recent 'voice' of this + * sound. Calling \c play() while the sound is already playing causes + * multiple instances of the sample to play simultaniously. The sample + * started last is the one that is controlled afterwards. + */ void play(); + /** + * \brief Reset playhead position + * + * Resets the playhead position so that calling \c play() after this function + * makes it play from the start of the sample. If the sound is not paused + * before calling this function, this function will stop playback. + */ void rewind(); + /** + * \brief Set playback volume / gain + * + * \param volume Volume (0 = muted, 1 = full volume) + */ void set_volume(float volume); + /** + * \brief Set looping behavior for this sample + * + * \param looping Looping behavior (false = one-shot, true = loop) + */ void set_looping(bool looping); private: - std::unique_ptr _res; - SoLoud::handle _handle; - bool _paused; + Sound(std::unique_ptr res, SoundSystem & system); + SoundSystem & system; + friend class SoundSystem; + +private: + std::unique_ptr res; + SoLoud::Wav sample; + SoLoud::handle handle; + bool paused; }; } diff --git a/src/crepe/SoundSystem.cpp b/src/crepe/SoundSystem.cpp new file mode 100644 index 0000000..30b0157 --- /dev/null +++ b/src/crepe/SoundSystem.cpp @@ -0,0 +1,25 @@ +#include "SoundSystem.h" +#include + +using namespace crepe; + +SoundSystem SoundSystem::instance { }; + +std::unique_ptr SoundSystem::sound(const std::string & src) { + auto res = std::make_unique(src); + return SoundSystem::sound(std::move(res)); +} + +std::unique_ptr SoundSystem::sound(std::unique_ptr res) { + Sound * out = new Sound(std::move(res), SoundSystem::instance); + return std::unique_ptr(out); +} + +SoundSystem::SoundSystem() { + engine.init(); +} + +SoundSystem::~SoundSystem() { + engine.deinit(); +} + diff --git a/src/crepe/SoundSystem.h b/src/crepe/SoundSystem.h new file mode 100644 index 0000000..23bb00a --- /dev/null +++ b/src/crepe/SoundSystem.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include + +#include "Sound.h" + +namespace crepe { + +class SoundSystem { +public: + static std::unique_ptr sound(const std::string & res); + static std::unique_ptr sound(std::unique_ptr res); + +private: + SoundSystem(); + virtual ~SoundSystem(); + static SoundSystem instance; + +private: + SoLoud::Soloud engine; + friend class Sound; +}; + +} + diff --git a/src/crepe/api/CMakeLists.txt b/src/crepe/api/CMakeLists.txt index 94617a4..feb03ef 100644 --- a/src/crepe/api/CMakeLists.txt +++ b/src/crepe/api/CMakeLists.txt @@ -1,4 +1,11 @@ target_sources(crepe PUBLIC - AudioSource.cpp + # AudioSource.cpp + Resource.cpp +) + +target_sources(crepe PUBLIC FILE_SET HEADERS FILES + AudioSource.h + Component.h + Resource.h ) diff --git a/src/crepe/api/Resource.cpp b/src/crepe/api/Resource.cpp new file mode 100644 index 0000000..a38900b --- /dev/null +++ b/src/crepe/api/Resource.cpp @@ -0,0 +1,12 @@ +#include "Resource.h" + +using namespace crepe::api; + +Resource::Resource(const std::string & src) : src(src) { + this->file = std::ifstream(src, std::ios::in | std::ios::binary); +} + +const std::istream & Resource::read() { + return this->file; +} + diff --git a/src/crepe/api/Resource.h b/src/crepe/api/Resource.h index 620a10e..2260b1a 100644 --- a/src/crepe/api/Resource.h +++ b/src/crepe/api/Resource.h @@ -1,16 +1,21 @@ #pragma once #include +#include +#include namespace crepe::api { class Resource { public: - Resource(const std::string & source); - virtual ~Resource(); + Resource(const std::string & src); + +public: + const std::istream & read(); private: - std::string _source; + std::string src; + std::ifstream file; }; } diff --git a/src/dummy_audio.cpp b/src/dummy_audio.cpp new file mode 100644 index 0000000..5e0000e --- /dev/null +++ b/src/dummy_audio.cpp @@ -0,0 +1,37 @@ +#include "crepe/SoundSystem.h" + +#include +#include + +using namespace crepe; +using namespace std; +using namespace std::chrono_literals; + +int main() { + 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"); + + bgm->play(); + + // play each sample sequentially + this_thread::sleep_for(500ms); + sfx1->play(); + this_thread::sleep_for(500ms); + sfx2->play(); + bgm->pause(); + this_thread::sleep_for(500ms); + sfx3->play(); + bgm->play(); + this_thread::sleep_for(500ms); + + // play all samples simultaniously + sfx1->play(); + sfx2->play(); + sfx3->play(); + this_thread::sleep_for(1000ms); + + return 0; +} + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d103b9a..f015570 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,7 +13,7 @@ add_subdirectory(../src crepe) add_executable(test dummy.cpp - audio.cpp + # audio.cpp ) target_link_libraries(test -- cgit v1.2.3 From feea4cbb648d67e46b413880ddbf203c88c2a2b1 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 29 Sep 2024 16:15:49 +0200 Subject: implement debug logging functions and fix sound system segfault --- src/crepe/CMakeLists.txt | 1 + src/crepe/Sound.cpp | 17 ++++++++++----- src/crepe/Sound.h | 3 +-- src/crepe/SoundSystem.cpp | 11 ++++++++-- src/crepe/SoundSystem.h | 8 ++++++- src/crepe/util/CMakeLists.txt | 9 ++++++++ src/crepe/util/color.h | 42 +++++++++++++++++++++++++++++++++++ src/crepe/util/debug.cpp | 0 src/crepe/util/debug.h | 0 src/crepe/util/log.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++ src/crepe/util/log.h | 33 ++++++++++++++++++++++++++++ src/dummy_audio.cpp | 3 +++ 12 files changed, 167 insertions(+), 11 deletions(-) create mode 100644 src/crepe/util/color.h delete mode 100644 src/crepe/util/debug.cpp delete mode 100644 src/crepe/util/debug.h create mode 100644 src/crepe/util/log.cpp create mode 100644 src/crepe/util/log.h (limited to 'src/crepe') diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 13d9be5..9f7c91c 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -9,4 +9,5 @@ target_sources(crepe PUBLIC FILE_SET HEADERS FILES ) add_subdirectory(api) +add_subdirectory(util) diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index d48393c..94f97af 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -1,24 +1,29 @@ +#include "util/log.h" + #include "Sound.h" #include "SoundSystem.h" using namespace crepe; -Sound::Sound(std::unique_ptr res, SoundSystem & system) : system(system) { +Sound::Sound(std::unique_ptr res) { + dbg_trace(); this->res = std::move(res); } void Sound::play() { - if (this->system.engine.getPause(this->handle)) { + SoundSystem & system = SoundSystem::instance(); + if (system.engine.getPause(this->handle)) { // resume if paused - this->system.engine.setPause(this->handle, false); + system.engine.setPause(this->handle, false); } else { // or start new sound - this->handle = this->system.engine.play(this->sample); + this->handle = system.engine.play(this->sample); } } void Sound::pause() { - if (this->system.engine.getPause(this->handle)) return; - this->system.engine.setPause(this->handle, true); + SoundSystem & system = SoundSystem::instance(); + if (system.engine.getPause(this->handle)) return; + system.engine.setPause(this->handle, true); } diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index 71fe390..333465b 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -55,9 +55,8 @@ public: void set_looping(bool looping); private: - Sound(std::unique_ptr res, SoundSystem & system); - SoundSystem & system; friend class SoundSystem; + Sound(std::unique_ptr res); private: std::unique_ptr res; diff --git a/src/crepe/SoundSystem.cpp b/src/crepe/SoundSystem.cpp index 30b0157..29bd196 100644 --- a/src/crepe/SoundSystem.cpp +++ b/src/crepe/SoundSystem.cpp @@ -1,9 +1,14 @@ +#include "util/log.h" + #include "SoundSystem.h" #include using namespace crepe; -SoundSystem SoundSystem::instance { }; +SoundSystem & SoundSystem::instance() { + static SoundSystem instance; + return instance; +} std::unique_ptr SoundSystem::sound(const std::string & src) { auto res = std::make_unique(src); @@ -11,15 +16,17 @@ std::unique_ptr SoundSystem::sound(const std::string & src) { } std::unique_ptr SoundSystem::sound(std::unique_ptr res) { - Sound * out = new Sound(std::move(res), SoundSystem::instance); + Sound * out = new Sound(std::move(res)); return std::unique_ptr(out); } SoundSystem::SoundSystem() { + dbg_trace(); engine.init(); } SoundSystem::~SoundSystem() { + dbg_trace(); engine.deinit(); } diff --git a/src/crepe/SoundSystem.h b/src/crepe/SoundSystem.h index 23bb00a..515cb29 100644 --- a/src/crepe/SoundSystem.h +++ b/src/crepe/SoundSystem.h @@ -16,7 +16,13 @@ public: private: SoundSystem(); virtual ~SoundSystem(); - static SoundSystem instance; + + // singleton + static SoundSystem & instance(); + SoundSystem(const SoundSystem &) = delete; + SoundSystem(SoundSystem &&) = delete; + SoundSystem &operator=(const SoundSystem &) = delete; + SoundSystem &operator=(SoundSystem &&) = delete; private: SoLoud::Soloud engine; diff --git a/src/crepe/util/CMakeLists.txt b/src/crepe/util/CMakeLists.txt index e69de29..100f028 100644 --- a/src/crepe/util/CMakeLists.txt +++ b/src/crepe/util/CMakeLists.txt @@ -0,0 +1,9 @@ +target_sources(crepe PUBLIC + log.cpp +) + +target_sources(crepe PUBLIC FILE_SET HEADERS FILES + color.h + log.h +) + diff --git a/src/crepe/util/color.h b/src/crepe/util/color.h new file mode 100644 index 0000000..1af6c8f --- /dev/null +++ b/src/crepe/util/color.h @@ -0,0 +1,42 @@ +#pragma once + +namespace crepe::util::color { + +constexpr const char * RESET = "\e[0m"; + +constexpr const char * FG_BLACK = "\e[30m"; +constexpr const char * FG_RED = "\e[31m"; +constexpr const char * FG_GREEN = "\e[32m"; +constexpr const char * FG_YELLOW = "\e[33m"; +constexpr const char * FG_BLUE = "\e[34m"; +constexpr const char * FG_MAGENTA = "\e[35m"; +constexpr const char * FG_CYAN = "\e[36m"; +constexpr const char * FG_WHITE = "\e[37m"; +constexpr const char * BG_BLACK = "\e[40m"; +constexpr const char * BG_RED = "\e[41m"; +constexpr const char * BG_GREEN = "\e[42m"; +constexpr const char * BG_YELLOW = "\e[43m"; +constexpr const char * BG_BLUE = "\e[44m"; +constexpr const char * BG_MAGENTA = "\e[45m"; +constexpr const char * BG_CYAN = "\e[46m"; +constexpr const char * BG_WHITE = "\e[47m"; + +constexpr const char * FG_BLACK_BRIGHT = "\e[90m"; +constexpr const char * FG_RED_BRIGHT = "\e[91m"; +constexpr const char * FG_GREEN_BRIGHT = "\e[92m"; +constexpr const char * FG_YELLOW_BRIGHT = "\e[93m"; +constexpr const char * FG_BLUE_BRIGHT = "\e[94m"; +constexpr const char * FG_MAGENTA_BRIGHT = "\e[95m"; +constexpr const char * FG_CYAN_BRIGHT = "\e[96m"; +constexpr const char * FG_WHITE_BRIGHT = "\e[97m"; +constexpr const char * BG_BLACK_BRIGHT = "\e[100m"; +constexpr const char * BG_RED_BRIGHT = "\e[101m"; +constexpr const char * BG_GREEN_BRIGHT = "\e[102m"; +constexpr const char * BG_YELLOW_BRIGHT = "\e[103m"; +constexpr const char * BG_BLUE_BRIGHT = "\e[104m"; +constexpr const char * BG_MAGENTA_BRIGHT = "\e[105m"; +constexpr const char * BG_CYAN_BRIGHT = "\e[106m"; +constexpr const char * BG_WHITE_BRIGHT = "\e[107m"; + +} + diff --git a/src/crepe/util/debug.cpp b/src/crepe/util/debug.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/crepe/util/debug.h b/src/crepe/util/debug.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/crepe/util/log.cpp b/src/crepe/util/log.cpp new file mode 100644 index 0000000..796df49 --- /dev/null +++ b/src/crepe/util/log.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +#include "log.h" + +using namespace crepe::util; + +static const char * const LOG_PREFIX[] = { + [log_level::debug] = "[DBG] ", + [log_level::info] = "[INFO] ", + [log_level::warning] = "[WARN] ", + [log_level::error] = "[ERR] ", +}; + +static void va_logf(enum log_level level, va_list args, const std::string fmt) { + va_list args_copy; + va_copy(args_copy, args); + + // prepend log level and ensure newline + std::string format_fixed = LOG_PREFIX[level] + fmt; + if (!format_fixed.ends_with("\n")) format_fixed += "\n"; + + size_t sz = vsnprintf(NULL, 0, format_fixed.c_str(), args_copy) + 1; + char * msg = (char *) malloc(sz); + va_end(args_copy); + + vsnprintf(msg, sz, format_fixed.c_str(), args); + + // TODO: also log to file or smth + printf("%s", msg); + fflush(stdout); + + free(msg); +} + +void crepe::util::logf(const char * fmt, ...) { + va_list args; + va_start(args, fmt); + va_logf(crepe::util::log_level::debug, args, fmt); + va_end(args); +} + +void crepe::util::logf(log_level level, const char * fmt, ...) { + va_list args; + va_start(args, fmt); + va_logf(level, args, fmt); + va_end(args); +} + diff --git a/src/crepe/util/log.h b/src/crepe/util/log.h new file mode 100644 index 0000000..5295cb9 --- /dev/null +++ b/src/crepe/util/log.h @@ -0,0 +1,33 @@ +#pragma once + +// allow user to disable debug macros +#ifndef CREPE_DISABLE_MACROS + +#include "color.h" + +// utility macros +#define _crepe_logf_here(fmt, ...) \ + crepe::util::logf(util::log_level::debug, "%s%s (%s:%d)" fmt "\n", \ + crepe::util::color::FG_WHITE, \ + __PRETTY_FUNCTION__, \ + __FILE_NAME__, \ + __LINE__, \ + crepe::util::color::RESET, \ + __VA_ARGS__) + +#define dbg_logf(fmt, ...) _crepe_logf_here(": " fmt, __VA_ARGS__) +#define dbg_log(str) _crepe_logf_here(": %s", str) +#define dbg_trace() _crepe_logf_here("%s", "") + +#endif + +namespace crepe::util { + +enum log_level { debug, info, warning, error, }; + +void logf(const char * fmt, ...); +void logf(enum log_level level, const char * fmt, ...); + +} + + diff --git a/src/dummy_audio.cpp b/src/dummy_audio.cpp index 5e0000e..fb1e3ab 100644 --- a/src/dummy_audio.cpp +++ b/src/dummy_audio.cpp @@ -1,4 +1,5 @@ #include "crepe/SoundSystem.h" +#include "crepe/util/log.h" #include #include @@ -8,6 +9,8 @@ using namespace std; using namespace std::chrono_literals; 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"); -- cgit v1.2.3 From e4a3ef6e324acc8edf9f0797caa244967907a676 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 29 Sep 2024 16:37:12 +0200 Subject: implement audio poc using facade classes --- src/crepe/Sound.cpp | 1 + src/crepe/api/Resource.cpp | 11 +++++++++-- src/crepe/api/Resource.h | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 94f97af..181366a 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -8,6 +8,7 @@ using namespace crepe; Sound::Sound(std::unique_ptr res) { dbg_trace(); this->res = std::move(res); + this->sample.load(this->res->canonical()); } void Sound::play() { diff --git a/src/crepe/api/Resource.cpp b/src/crepe/api/Resource.cpp index a38900b..6bb081d 100644 --- a/src/crepe/api/Resource.cpp +++ b/src/crepe/api/Resource.cpp @@ -1,12 +1,19 @@ +#include + #include "Resource.h" using namespace crepe::api; -Resource::Resource(const std::string & src) : src(src) { - this->file = std::ifstream(src, std::ios::in | std::ios::binary); +Resource::Resource(const std::string & src) { + this->src = std::filesystem::canonical(src); + this->file = std::ifstream(this->src, std::ios::in | std::ios::binary); } const std::istream & Resource::read() { return this->file; } +const char * Resource::canonical() { + return this->src.c_str(); +} + diff --git a/src/crepe/api/Resource.h b/src/crepe/api/Resource.h index 2260b1a..2b62ff9 100644 --- a/src/crepe/api/Resource.h +++ b/src/crepe/api/Resource.h @@ -11,7 +11,10 @@ public: Resource(const std::string & src); public: + //! Get an input stream to the contents of this resource const std::istream & read(); + //! Get the canonical path to this resource + const char * canonical(); private: std::string src; -- cgit v1.2.3 From 90174919ba8c019d4b88915557be0adc3769b3e6 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Sun, 29 Sep 2024 17:22:58 +0200 Subject: WIP cleanup (broken, but more like the class diagram) --- src/crepe/Sound.cpp | 10 +++++++++- src/crepe/Sound.h | 10 +++++----- src/crepe/SoundSystem.cpp | 11 ----------- src/crepe/SoundSystem.h | 6 ------ src/dummy_audio.cpp | 29 +++++++++++++++-------------- 5 files changed, 29 insertions(+), 37 deletions(-) (limited to 'src/crepe') 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 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(src)); +} + +void Sound::load(std::unique_ptr 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 res); +private: + void load(std::unique_ptr res); + private: std::unique_ptr 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 using namespace crepe; @@ -10,16 +9,6 @@ SoundSystem & SoundSystem::instance() { return instance; } -std::unique_ptr SoundSystem::sound(const std::string & src) { - auto res = std::make_unique(src); - return SoundSystem::sound(std::move(res)); -} - -std::unique_ptr SoundSystem::sound(std::unique_ptr res) { - Sound * out = new Sound(std::move(res)); - return std::unique_ptr(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 -#include - #include "Sound.h" namespace crepe { class SoundSystem { -public: - static std::unique_ptr sound(const std::string & res); - static std::unique_ptr sound(std::unique_ptr 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 #include @@ -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; -- cgit v1.2.3 From de288a859a631acf6aac10fad825cafaa3744dc9 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 15:21:31 +0200 Subject: fix audio segfault --- src/crepe/Sound.cpp | 2 +- src/crepe/Sound.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 09ffd5f..136a71d 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -16,7 +16,7 @@ Sound::Sound(const char * src) { } void Sound::load(std::unique_ptr res) { - this->sample.load(this->res->canonical()); + this->sample.load(res->canonical()); } void Sound::play() { diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index 163c5b4..9da17b9 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -60,7 +60,6 @@ private: void load(std::unique_ptr res); private: - std::unique_ptr res; SoLoud::Wav sample; SoLoud::handle handle; }; -- cgit v1.2.3 From 311e98572c26750e4a4695079fa80ca5648d109e Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 17:21:37 +0200 Subject: implement remaining Sound functions --- src/crepe/Sound.cpp | 29 ++++++++++++++++++++++++++--- src/crepe/Sound.h | 15 +++++++++++++++ src/crepe/SoundSystem.cpp | 2 +- src/crepe/SoundSystem.h | 2 +- 4 files changed, 43 insertions(+), 5 deletions(-) (limited to 'src/crepe') 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 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 @@ -45,12 +45,24 @@ public: * \param volume Volume (0 = muted, 1 = full volume) */ 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; -- cgit v1.2.3 From fe9bf1344ceae0fac9144e4a28fdcdbcb2267850 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 17:23:33 +0200 Subject: rename SoundSystem to SoundContext (1/2) --- src/crepe/SoundContext.cpp | 21 +++++++++++++++++++++ src/crepe/SoundContext.h | 27 +++++++++++++++++++++++++++ src/crepe/SoundSystem.cpp | 21 --------------------- src/crepe/SoundSystem.h | 27 --------------------------- 4 files changed, 48 insertions(+), 48 deletions(-) create mode 100644 src/crepe/SoundContext.cpp create mode 100644 src/crepe/SoundContext.h delete mode 100644 src/crepe/SoundSystem.cpp delete mode 100644 src/crepe/SoundSystem.h (limited to 'src/crepe') diff --git a/src/crepe/SoundContext.cpp b/src/crepe/SoundContext.cpp new file mode 100644 index 0000000..b57e51a --- /dev/null +++ b/src/crepe/SoundContext.cpp @@ -0,0 +1,21 @@ +#include "util/log.h" + +#include "SoundSystem.h" + +using namespace crepe; + +SoundSystem & SoundSystem::get_instance() { + static SoundSystem instance; + return instance; +} + +SoundSystem::SoundSystem() { + dbg_trace(); + engine.init(); +} + +SoundSystem::~SoundSystem() { + dbg_trace(); + engine.deinit(); +} + diff --git a/src/crepe/SoundContext.h b/src/crepe/SoundContext.h new file mode 100644 index 0000000..34dd6c5 --- /dev/null +++ b/src/crepe/SoundContext.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include "Sound.h" + +namespace crepe { + +class SoundSystem { +private: + SoundSystem(); + virtual ~SoundSystem(); + + // singleton + static SoundSystem & get_instance(); + SoundSystem(const SoundSystem &) = delete; + SoundSystem(SoundSystem &&) = delete; + SoundSystem &operator=(const SoundSystem &) = delete; + SoundSystem &operator=(SoundSystem &&) = delete; + +private: + SoLoud::Soloud engine; + friend class Sound; +}; + +} + diff --git a/src/crepe/SoundSystem.cpp b/src/crepe/SoundSystem.cpp deleted file mode 100644 index b57e51a..0000000 --- a/src/crepe/SoundSystem.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "util/log.h" - -#include "SoundSystem.h" - -using namespace crepe; - -SoundSystem & SoundSystem::get_instance() { - static SoundSystem instance; - return instance; -} - -SoundSystem::SoundSystem() { - dbg_trace(); - engine.init(); -} - -SoundSystem::~SoundSystem() { - dbg_trace(); - engine.deinit(); -} - diff --git a/src/crepe/SoundSystem.h b/src/crepe/SoundSystem.h deleted file mode 100644 index 34dd6c5..0000000 --- a/src/crepe/SoundSystem.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -#include "Sound.h" - -namespace crepe { - -class SoundSystem { -private: - SoundSystem(); - virtual ~SoundSystem(); - - // singleton - static SoundSystem & get_instance(); - SoundSystem(const SoundSystem &) = delete; - SoundSystem(SoundSystem &&) = delete; - SoundSystem &operator=(const SoundSystem &) = delete; - SoundSystem &operator=(SoundSystem &&) = delete; - -private: - SoLoud::Soloud engine; - friend class Sound; -}; - -} - -- cgit v1.2.3 From 8e67adc6828181b1df7c95da76f32962444fc7fd Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 17:25:06 +0200 Subject: rename SoundSystem to SoundContext (2/2) --- src/crepe/CMakeLists.txt | 4 ++-- src/crepe/Sound.cpp | 36 ++++++++++++++++++------------------ src/crepe/SoundContext.cpp | 10 +++++----- src/crepe/SoundContext.h | 16 ++++++++-------- 4 files changed, 33 insertions(+), 33 deletions(-) (limited to 'src/crepe') diff --git a/src/crepe/CMakeLists.txt b/src/crepe/CMakeLists.txt index 9f7c91c..3a60840 100644 --- a/src/crepe/CMakeLists.txt +++ b/src/crepe/CMakeLists.txt @@ -1,11 +1,11 @@ target_sources(crepe PUBLIC Sound.cpp - SoundSystem.cpp + SoundContext.cpp ) target_sources(crepe PUBLIC FILE_SET HEADERS FILES Sound.h - SoundSystem.h + SoundContext.h ) add_subdirectory(api) diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 20f1787..1758282 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -1,7 +1,7 @@ #include "util/log.h" #include "Sound.h" -#include "SoundSystem.h" +#include "SoundContext.h" using namespace crepe; @@ -20,42 +20,42 @@ void Sound::load(std::unique_ptr res) { } void Sound::play() { - SoundSystem & system = SoundSystem::get_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->volume); - system.engine.setLooping(this->handle, this->looping); + this->handle = ctx.engine.play(this->sample, this->volume); + ctx.engine.setLooping(this->handle, this->looping); } } void Sound::pause() { - SoundSystem & system = SoundSystem::get_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() { - SoundSystem & system = SoundSystem::get_instance(); - if (!system.engine.isValidVoiceHandle(this->handle)) return; - system.engine.seek(this->handle, 0); + 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; - SoundSystem & system = SoundSystem::get_instance(); - if (!system.engine.isValidVoiceHandle(this->handle)) return; - system.engine.setVolume(this->handle, this->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; - SoundSystem & system = SoundSystem::get_instance(); - if (!system.engine.isValidVoiceHandle(this->handle)) return; - system.engine.setLooping(this->handle, this->looping); + SoundContext & ctx = SoundContext::get_instance(); + if (!ctx.engine.isValidVoiceHandle(this->handle)) return; + ctx.engine.setLooping(this->handle, this->looping); } diff --git a/src/crepe/SoundContext.cpp b/src/crepe/SoundContext.cpp index b57e51a..cfb7d82 100644 --- a/src/crepe/SoundContext.cpp +++ b/src/crepe/SoundContext.cpp @@ -1,20 +1,20 @@ #include "util/log.h" -#include "SoundSystem.h" +#include "SoundContext.h" using namespace crepe; -SoundSystem & SoundSystem::get_instance() { - static SoundSystem instance; +SoundContext & SoundContext::get_instance() { + static SoundContext instance; return instance; } -SoundSystem::SoundSystem() { +SoundContext::SoundContext() { dbg_trace(); engine.init(); } -SoundSystem::~SoundSystem() { +SoundContext::~SoundContext() { dbg_trace(); engine.deinit(); } diff --git a/src/crepe/SoundContext.h b/src/crepe/SoundContext.h index 34dd6c5..d361d83 100644 --- a/src/crepe/SoundContext.h +++ b/src/crepe/SoundContext.h @@ -6,17 +6,17 @@ namespace crepe { -class SoundSystem { +class SoundContext { private: - SoundSystem(); - virtual ~SoundSystem(); + SoundContext(); + virtual ~SoundContext(); // singleton - static SoundSystem & get_instance(); - SoundSystem(const SoundSystem &) = delete; - SoundSystem(SoundSystem &&) = delete; - SoundSystem &operator=(const SoundSystem &) = delete; - SoundSystem &operator=(SoundSystem &&) = delete; + static SoundContext & get_instance(); + SoundContext(const SoundContext &) = delete; + SoundContext(SoundContext &&) = delete; + SoundContext &operator=(const SoundContext &) = delete; + SoundContext &operator=(SoundContext &&) = delete; private: SoLoud::Soloud engine; -- cgit v1.2.3 From 65eda52aa51017f6f7aad158c4f8b6e91054cf0d Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Tue, 1 Oct 2024 17:27:14 +0200 Subject: `make format` --- mwe/audio/soloud/main.cpp | 3 +-- mwe/dynlink/exec/main.c | 1 - src/crepe/Sound.cpp | 1 - src/crepe/Sound.h | 3 +-- src/crepe/SoundContext.cpp | 1 - src/crepe/SoundContext.h | 7 +++---- src/crepe/api/AudioSource.cpp | 5 +---- src/crepe/api/AudioSource.h | 3 +-- src/crepe/api/Component.h | 3 +-- src/crepe/api/Resource.cpp | 9 ++------- src/crepe/api/Resource.h | 5 ++--- src/crepe/util/color.h | 3 +-- src/crepe/util/log.cpp | 1 - src/crepe/util/log.h | 20 ++++++++++---------- src/dummy_audio.cpp | 3 +-- test/audio.cpp | 3 +-- 16 files changed, 25 insertions(+), 46 deletions(-) (limited to 'src/crepe') diff --git a/mwe/audio/soloud/main.cpp b/mwe/audio/soloud/main.cpp index 25ba003..50df0b7 100644 --- a/mwe/audio/soloud/main.cpp +++ b/mwe/audio/soloud/main.cpp @@ -38,8 +38,7 @@ int main() { this_thread::sleep_for(500ms); // play all samples simultaniously - for (unsigned i = 0; i < 3; i++) - soloud.play(sfx[i]); + for (unsigned i = 0; i < 3; i++) soloud.play(sfx[i]); this_thread::sleep_for(1000ms); // stop all audio and exit diff --git a/mwe/dynlink/exec/main.c b/mwe/dynlink/exec/main.c index ea55feb..ff884f2 100644 --- a/mwe/dynlink/exec/main.c +++ b/mwe/dynlink/exec/main.c @@ -5,4 +5,3 @@ int main() { return 0; } - diff --git a/src/crepe/Sound.cpp b/src/crepe/Sound.cpp index 1758282..e1150ac 100644 --- a/src/crepe/Sound.cpp +++ b/src/crepe/Sound.cpp @@ -58,4 +58,3 @@ void Sound::set_looping(bool looping) { if (!ctx.engine.isValidVoiceHandle(this->handle)) return; ctx.engine.setLooping(this->handle, this->looping); } - diff --git a/src/crepe/Sound.h b/src/crepe/Sound.h index 4c51188..ac93991 100644 --- a/src/crepe/Sound.h +++ b/src/crepe/Sound.h @@ -79,5 +79,4 @@ private: bool looping = false; }; -} - +} // namespace crepe diff --git a/src/crepe/SoundContext.cpp b/src/crepe/SoundContext.cpp index cfb7d82..72047d2 100644 --- a/src/crepe/SoundContext.cpp +++ b/src/crepe/SoundContext.cpp @@ -18,4 +18,3 @@ SoundContext::~SoundContext() { dbg_trace(); engine.deinit(); } - diff --git a/src/crepe/SoundContext.h b/src/crepe/SoundContext.h index d361d83..090966d 100644 --- a/src/crepe/SoundContext.h +++ b/src/crepe/SoundContext.h @@ -15,13 +15,12 @@ private: static SoundContext & get_instance(); SoundContext(const SoundContext &) = delete; SoundContext(SoundContext &&) = delete; - SoundContext &operator=(const SoundContext &) = delete; - SoundContext &operator=(SoundContext &&) = delete; + SoundContext & operator=(const SoundContext &) = delete; + SoundContext & operator=(SoundContext &&) = delete; private: SoLoud::Soloud engine; friend class Sound; }; -} - +} // namespace crepe diff --git a/src/crepe/api/AudioSource.cpp b/src/crepe/api/AudioSource.cpp index cbde79f..4d1b093 100644 --- a/src/crepe/api/AudioSource.cpp +++ b/src/crepe/api/AudioSource.cpp @@ -9,9 +9,7 @@ AudioSource::AudioSource(std::unique_ptr audio_clip) { this->_sound = std::make_unique(std::move(audio_clip)); } -void AudioSource::play() { - return this->play(false); -} +void AudioSource::play() { return this->play(false); } void AudioSource::play(bool looping) { this->_sound->set_looping(looping); @@ -22,4 +20,3 @@ void AudioSource::stop() { this->_sound->pause(); this->_sound->rewind(); } - diff --git a/src/crepe/api/AudioSource.h b/src/crepe/api/AudioSource.h index 6a038be..4300c48 100644 --- a/src/crepe/api/AudioSource.h +++ b/src/crepe/api/AudioSource.h @@ -38,5 +38,4 @@ private: std::unique_ptr _sound; }; -} - +} // namespace crepe::api diff --git a/src/crepe/api/Component.h b/src/crepe/api/Component.h index 2abb461..d5e0499 100644 --- a/src/crepe/api/Component.h +++ b/src/crepe/api/Component.h @@ -7,5 +7,4 @@ public: bool active; }; -} - +} // namespace crepe::api diff --git a/src/crepe/api/Resource.cpp b/src/crepe/api/Resource.cpp index 6bb081d..1a647ce 100644 --- a/src/crepe/api/Resource.cpp +++ b/src/crepe/api/Resource.cpp @@ -9,11 +9,6 @@ Resource::Resource(const std::string & src) { this->file = std::ifstream(this->src, std::ios::in | std::ios::binary); } -const std::istream & Resource::read() { - return this->file; -} - -const char * Resource::canonical() { - return this->src.c_str(); -} +const std::istream & Resource::read() { return this->file; } +const char * Resource::canonical() { return this->src.c_str(); } diff --git a/src/crepe/api/Resource.h b/src/crepe/api/Resource.h index 2b62ff9..f2b2a0e 100644 --- a/src/crepe/api/Resource.h +++ b/src/crepe/api/Resource.h @@ -1,8 +1,8 @@ #pragma once -#include #include #include +#include namespace crepe::api { @@ -21,5 +21,4 @@ private: std::ifstream file; }; -} - +} // namespace crepe::api diff --git a/src/crepe/util/color.h b/src/crepe/util/color.h index 1af6c8f..066c9d3 100644 --- a/src/crepe/util/color.h +++ b/src/crepe/util/color.h @@ -38,5 +38,4 @@ constexpr const char * BG_MAGENTA_BRIGHT = "\e[105m"; constexpr const char * BG_CYAN_BRIGHT = "\e[106m"; constexpr const char * BG_WHITE_BRIGHT = "\e[107m"; -} - +} // namespace crepe::util::color diff --git a/src/crepe/util/log.cpp b/src/crepe/util/log.cpp index 796df49..6829ec3 100644 --- a/src/crepe/util/log.cpp +++ b/src/crepe/util/log.cpp @@ -48,4 +48,3 @@ void crepe::util::logf(log_level level, const char * fmt, ...) { va_logf(level, args, fmt); va_end(args); } - diff --git a/src/crepe/util/log.h b/src/crepe/util/log.h index 5295cb9..4cab338 100644 --- a/src/crepe/util/log.h +++ b/src/crepe/util/log.h @@ -8,12 +8,9 @@ // utility macros #define _crepe_logf_here(fmt, ...) \ crepe::util::logf(util::log_level::debug, "%s%s (%s:%d)" fmt "\n", \ - crepe::util::color::FG_WHITE, \ - __PRETTY_FUNCTION__, \ - __FILE_NAME__, \ - __LINE__, \ - crepe::util::color::RESET, \ - __VA_ARGS__) + crepe::util::color::FG_WHITE, __PRETTY_FUNCTION__, \ + __FILE_NAME__, __LINE__, crepe::util::color::RESET, \ + __VA_ARGS__) #define dbg_logf(fmt, ...) _crepe_logf_here(": " fmt, __VA_ARGS__) #define dbg_log(str) _crepe_logf_here(": %s", str) @@ -23,11 +20,14 @@ namespace crepe::util { -enum log_level { debug, info, warning, error, }; +enum log_level { + debug, + info, + warning, + error, +}; void logf(const char * fmt, ...); void logf(enum log_level level, const char * fmt, ...); -} - - +} // namespace crepe::util diff --git a/src/dummy_audio.cpp b/src/dummy_audio.cpp index 1249076..049bb49 100644 --- a/src/dummy_audio.cpp +++ b/src/dummy_audio.cpp @@ -1,5 +1,5 @@ -#include "crepe/util/log.h" #include "crepe/Sound.h" +#include "crepe/util/log.h" #include #include @@ -38,4 +38,3 @@ int main() { return 0; } - diff --git a/test/audio.cpp b/test/audio.cpp index a415919..47c5e84 100644 --- a/test/audio.cpp +++ b/test/audio.cpp @@ -1,8 +1,8 @@ #include #include -#include #include +#include #include #include @@ -26,4 +26,3 @@ TEST(audio, play) { ASSERT_TRUE(true); } - -- cgit v1.2.3