From dc99734f0eb380c4682f95f2908e162beac7af21 Mon Sep 17 00:00:00 2001 From: Diogo Miranda Date: Fri, 4 Oct 2024 00:47:48 +0100 Subject: [PATCH] feat(audio): Add Audio asset (#230) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: João Miguel Nogueira <101069446+Dageus@users.noreply.github.com> --- CHANGELOG.md | 5 ++- engine/CMakeLists.txt | 3 ++ engine/include/cubos/engine/audio/audio.hpp | 28 ++++++++++++++ engine/include/cubos/engine/audio/bridge.hpp | 35 ++++++++++++++++++ engine/src/audio/audio.cpp | 39 ++++++++++++++++++++ engine/src/audio/bridge.cpp | 26 +++++++++++++ 6 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 engine/include/cubos/engine/audio/audio.hpp create mode 100644 engine/include/cubos/engine/audio/bridge.hpp create mode 100644 engine/src/audio/audio.cpp create mode 100644 engine/src/audio/bridge.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 7395f2a2e..b741c9601 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,20 +18,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Deadzone for input axis (#844, **@kuukitenshi**). - Generic Camera component to hold projection matrix (#1331, **@mkuritsu**). - Initial application debugging through Tesseratos (#1303, **@RiscadoA**). -- Print stacktrace with *cpptrace* on calls to CUBOS_FAIL (#1172, **@RiscadoA**). +- Print stacktrace with _cpptrace_ on calls to CUBOS_FAIL (#1172, **@RiscadoA**). - Orthographic Camera component (#1182, **@mkuritsu**). - Importer plugin (#1299, **@Scarface1809**). - Handle body rotation on penetration solving (#1272, **&fallenatlas**). - Cascaded shadow maps (#1187, **@tomas7770**). - Global telemetry level (for tracing/logging) (#1265, **@roby2014**). - Spans for tracing and profiling (#1265, **@roby2014**). +- Audio asset (#230, **@Dageus**, **@diogomsmiranda**). ### Changed - Moved Glad and stb-image libs to another repositories, cubos-glad and cubos-stb, respectively (#1323, **@kuukitenshi**). - Moved most tools from Tesseratos to the engine (#1322, **@RiscadoA**). - Replaced OpenAL audio device with Miniaudio backend (#1005, **@Dageus**, **@diogomsmiranda**) + ### Fixed + - Spot light angle mismatch between light and shadows (#1310, **@tomas7770**). - Spot shadows cause light range cutoff (#1312, **@tomas7770**). - Precision error in split screen size calculations (**@mkuritsu**). diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index e29913c7e..13a420688 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -36,6 +36,9 @@ set(CUBOS_ENGINE_SOURCE "src/utils/free_camera/plugin.cpp" "src/utils/free_camera/controller.cpp" + "src/audio/audio.cpp" + "src/audio/bridge.cpp" + "src/assets/plugin.cpp" "src/assets/assets.cpp" "src/assets/bridge.cpp" diff --git a/engine/include/cubos/engine/audio/audio.hpp b/engine/include/cubos/engine/audio/audio.hpp new file mode 100644 index 000000000..939944fd7 --- /dev/null +++ b/engine/include/cubos/engine/audio/audio.hpp @@ -0,0 +1,28 @@ +/// @file +/// @brief Class @ref cubos::engine::Audio. +/// @ingroup audio-plugin +#pragma once + +#include +#include +#include + +#include + +namespace cubos::engine +{ + /// @brief Asset containing raw Audio data. + /// + /// @ingroup audio-plugin + struct CUBOS_ENGINE_API Audio + { + CUBOS_REFLECT; + + /// @brief Audio buffer. + cubos::core::al::Buffer buffer; + + explicit Audio(const std::shared_ptr& context, core::memory::Stream& stream); + Audio(Audio&& other) noexcept; + ~Audio(); + }; +} // namespace cubos::engine diff --git a/engine/include/cubos/engine/audio/bridge.hpp b/engine/include/cubos/engine/audio/bridge.hpp new file mode 100644 index 000000000..87091c182 --- /dev/null +++ b/engine/include/cubos/engine/audio/bridge.hpp @@ -0,0 +1,35 @@ +/// @file +/// @brief Class @ref cubos::engine::AudioBridge. +/// @ingroup audio-plugin + +#pragma once + +#include + +#include +#include + +namespace cubos::engine +{ + /// @brief Bridge which loads and saves @ref Sound assets. + /// + /// Uses the format specified in @ref Audio::loadFrom and @ref Audio::writeTo + /// + /// @ingroup audio-plugin + class AudioBridge : public FileBridge + { + public: + std::shared_ptr mContext; + + /// @brief Constructs a bridge. + AudioBridge(std::shared_ptr context) + : FileBridge(core::reflection::reflect