diff --git a/include/Nazara/Audio/Sound.hpp b/include/Nazara/Audio/Sound.hpp index 770c5e043..a1c45c8d3 100644 --- a/include/Nazara/Audio/Sound.hpp +++ b/include/Nazara/Audio/Sound.hpp @@ -17,6 +17,8 @@ namespace Nz class NAZARA_AUDIO_API Sound final : public SoundEmitter { public: + using Params = SoundBufferParams; + using SoundEmitter::SoundEmitter; Sound(); Sound(AudioDevice& audioDevice, std::shared_ptr soundBuffer); @@ -36,9 +38,9 @@ namespace Nz bool IsLooping() const override; bool IsPlayable() const; - bool LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params = SoundBufferParams()); - bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams()); - bool LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams()); + static std::shared_ptr LoadFromFile(const std::filesystem::path& filePath, const Params& params = {}); + static std::shared_ptr LoadFromMemory(const void* data, std::size_t size, const Params& params = {}); + static std::shared_ptr LoadFromStream(Stream& stream, const Params& params = {}); void Pause() override; void Play() override; diff --git a/src/Nazara/Audio/Sound.cpp b/src/Nazara/Audio/Sound.cpp index 9759174d1..b1f60de9c 100644 --- a/src/Nazara/Audio/Sound.cpp +++ b/src/Nazara/Audio/Sound.cpp @@ -141,17 +141,18 @@ namespace Nz * * \remark Produces a NazaraError if loading failed */ - bool Sound::LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params) + std::shared_ptr Sound::LoadFromFile(const std::filesystem::path& filePath, const Params& params) { std::shared_ptr buffer = SoundBuffer::LoadFromFile(filePath, params); if (!buffer) { NazaraErrorFmt("failed to load buffer from file ({0})", filePath); - return false; + return {}; } - SetBuffer(std::move(buffer)); - return true; + std::shared_ptr sound = std::make_shared(); + sound->SetBuffer(std::move(buffer)); + return sound; } /*! @@ -164,17 +165,18 @@ namespace Nz * * \remark Produces a NazaraError if loading failed */ - bool Sound::LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params) + std::shared_ptr Sound::LoadFromMemory(const void* data, std::size_t size, const Params& params) { std::shared_ptr buffer = SoundBuffer::LoadFromMemory(data, size, params); if (!buffer) { NazaraErrorFmt("failed to load buffer from memory ({0})", PointerToString(data)); - return false; + return {}; } - SetBuffer(std::move(buffer)); - return true; + std::shared_ptr sound = std::make_shared(); + sound->SetBuffer(std::move(buffer)); + return sound; } /*! @@ -186,17 +188,18 @@ namespace Nz * * \remark Produces a NazaraError if loading failed */ - bool Sound::LoadFromStream(Stream& stream, const SoundBufferParams& params) + std::shared_ptr Sound::LoadFromStream(Stream& stream, const Params& params) { std::shared_ptr buffer = SoundBuffer::LoadFromStream(stream, params); if (!buffer) { NazaraError("failed to load buffer from stream"); - return false; + return {}; } - SetBuffer(std::move(buffer)); - return true; + std::shared_ptr sound = std::make_shared(); + sound->SetBuffer(std::move(buffer)); + return sound; } /*!