-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 1330-add-active-component-for-all-kinds-of-d…
…isabling-purposes
- Loading branch information
Showing
7 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// @file | ||
/// @brief Class @ref cubos::engine::Audio. | ||
/// @ingroup audio-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/core/al/miniaudio_context.hpp> | ||
#include <cubos/core/memory/stream.hpp> | ||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
#include <cubos/engine/assets/asset.hpp> | ||
|
||
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<cubos::core::al::AudioContext>& context, core::memory::Stream& stream); | ||
Audio(Audio&& other) noexcept; | ||
~Audio(); | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/// @file | ||
/// @brief Class @ref cubos::engine::AudioBridge. | ||
/// @ingroup audio-plugin | ||
|
||
#pragma once | ||
|
||
#include <utility> | ||
|
||
#include <cubos/engine/assets/bridges/file.hpp> | ||
#include <cubos/engine/audio/audio.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Bridge which loads and saves @ref Audio assets. | ||
/// | ||
/// Uses the default supported file formats from miniaudio.h, which are WAV, FLAC, and MP3. | ||
/// | ||
/// @ingroup audio-plugin | ||
class AudioBridge : public FileBridge | ||
{ | ||
|
||
std::shared_ptr<cubos::core::al::AudioContext> mContext; | ||
|
||
public: | ||
/// @brief Constructs a bridge. | ||
AudioBridge(std::shared_ptr<cubos::core::al::AudioContext> context) | ||
: FileBridge(core::reflection::reflect<Audio>()) | ||
, mContext(std::move(context)) | ||
{ | ||
} | ||
|
||
protected: | ||
bool loadFromFile(Assets& assets, const AnyAsset& handle, core::memory::Stream& stream) override; | ||
bool saveToFile(const Assets& assets, const AnyAsset& handle, core::memory::Stream& stream) override; | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <cubos/core/reflection/external/cstring.hpp> | ||
#include <cubos/core/reflection/type.hpp> | ||
#include <cubos/core/tel/logging.hpp> | ||
|
||
#include <cubos/engine/audio/audio.hpp> | ||
|
||
CUBOS_REFLECT_IMPL(cubos::engine::Audio) | ||
{ | ||
return core::reflection::Type::create("cubos::engine::Audio"); | ||
} | ||
|
||
cubos::engine::Audio::Audio(const std::shared_ptr<cubos::core::al::AudioContext>& context, core::memory::Stream& stream) | ||
{ | ||
stream.seek(0, cubos::core::memory::SeekOrigin::End); | ||
size_t streamSize = stream.tell(); | ||
void* contents = operator new(sizeof(char) * streamSize); | ||
stream.seek(0, cubos::core::memory::SeekOrigin::Begin); | ||
if (!stream.readExact((char*)contents, streamSize)) | ||
{ | ||
CUBOS_ERROR("Couldn't load audio: stream read failed"); | ||
buffer = nullptr; | ||
operator delete(contents); | ||
return; | ||
} | ||
|
||
buffer = context->createBuffer(contents, (size_t)streamSize); | ||
if (buffer == nullptr) | ||
{ | ||
CUBOS_ERROR("Couldn't create audio buffer"); | ||
} | ||
operator delete(contents); | ||
} | ||
|
||
cubos::engine::Audio::~Audio() = default; | ||
|
||
cubos::engine::Audio::Audio(Audio&& other) noexcept | ||
: buffer(std::move(other.buffer)) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <cubos/core/tel/logging.hpp> | ||
|
||
#include <cubos/engine/assets/assets.hpp> | ||
#include <cubos/engine/audio/audio.hpp> | ||
#include <cubos/engine/audio/bridge.hpp> | ||
|
||
using namespace cubos::engine; | ||
|
||
bool AudioBridge::loadFromFile(Assets& assets, const AnyAsset& handle, core::memory::Stream& stream) | ||
{ | ||
Audio audio{mContext, stream}; | ||
if (audio.buffer == nullptr) | ||
{ | ||
return false; | ||
} | ||
assets.store(handle, std::move(audio)); | ||
return true; | ||
} | ||
bool AudioBridge::saveToFile(const Assets& assets, const AnyAsset& handle, core::memory::Stream& stream) | ||
{ | ||
(void)assets; | ||
(void)handle; | ||
(void)stream; | ||
CUBOS_ERROR("Saving audios is currently unsupported"); | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters