From a7bae0148d57d25f631ffc10ae2dc6c455ee99ed Mon Sep 17 00:00:00 2001 From: Diogo Miranda Date: Sun, 29 Sep 2024 22:26:52 +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> --- engine/CMakeLists.txt | 3 ++ engine/include/cubos/engine/audio/audio.hpp | 27 ++++++++++++ engine/include/cubos/engine/audio/bridge.hpp | 30 +++++++++++++ engine/src/audio/audio.cpp | 44 ++++++++++++++++++++ engine/src/audio/bridge.cpp | 26 ++++++++++++ 5 files changed, 130 insertions(+) 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/engine/CMakeLists.txt b/engine/CMakeLists.txt index c17dca0871..14bb380277 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 0000000000..82a9aca1fc --- /dev/null +++ b/engine/include/cubos/engine/audio/audio.hpp @@ -0,0 +1,27 @@ +/// @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; + std::shared_ptr mData; // Raw data of the audio + size_t mLength; // Audio length in seconds TODO: add getter in audio + + explicit Audio(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 0000000000..576afe8cdd --- /dev/null +++ b/engine/include/cubos/engine/audio/bridge.hpp @@ -0,0 +1,30 @@ +/// @file +/// @brief Class @ref cubos::engine::AudioBridge. +/// @ingroup audio-plugin + +#pragma once + +#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: + /// @brief Constructs a bridge. + AudioBridge() + : FileBridge(core::reflection::reflect