Make Sound FilesystemAppComponent-compliant

This commit is contained in:
SweetId 2024-03-11 19:37:35 -04:00
parent 4199582a52
commit e306a66956
2 changed files with 20 additions and 15 deletions

View File

@ -17,6 +17,8 @@ namespace Nz
class NAZARA_AUDIO_API Sound final : public SoundEmitter class NAZARA_AUDIO_API Sound final : public SoundEmitter
{ {
public: public:
using Params = SoundBufferParams;
using SoundEmitter::SoundEmitter; using SoundEmitter::SoundEmitter;
Sound(); Sound();
Sound(AudioDevice& audioDevice, std::shared_ptr<SoundBuffer> soundBuffer); Sound(AudioDevice& audioDevice, std::shared_ptr<SoundBuffer> soundBuffer);
@ -36,9 +38,9 @@ namespace Nz
bool IsLooping() const override; bool IsLooping() const override;
bool IsPlayable() const; bool IsPlayable() const;
bool LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params = SoundBufferParams()); static std::shared_ptr<Sound> LoadFromFile(const std::filesystem::path& filePath, const Params& params = {});
bool LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params = SoundBufferParams()); static std::shared_ptr<Sound> LoadFromMemory(const void* data, std::size_t size, const Params& params = {});
bool LoadFromStream(Stream& stream, const SoundBufferParams& params = SoundBufferParams()); static std::shared_ptr<Sound> LoadFromStream(Stream& stream, const Params& params = {});
void Pause() override; void Pause() override;
void Play() override; void Play() override;

View File

@ -141,17 +141,18 @@ namespace Nz
* *
* \remark Produces a NazaraError if loading failed * \remark Produces a NazaraError if loading failed
*/ */
bool Sound::LoadFromFile(const std::filesystem::path& filePath, const SoundBufferParams& params) std::shared_ptr<Sound> Sound::LoadFromFile(const std::filesystem::path& filePath, const Params& params)
{ {
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromFile(filePath, params); std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromFile(filePath, params);
if (!buffer) if (!buffer)
{ {
NazaraErrorFmt("failed to load buffer from file ({0})", filePath); NazaraErrorFmt("failed to load buffer from file ({0})", filePath);
return false; return {};
} }
SetBuffer(std::move(buffer)); std::shared_ptr<Sound> sound = std::make_shared<Sound>();
return true; sound->SetBuffer(std::move(buffer));
return sound;
} }
/*! /*!
@ -164,17 +165,18 @@ namespace Nz
* *
* \remark Produces a NazaraError if loading failed * \remark Produces a NazaraError if loading failed
*/ */
bool Sound::LoadFromMemory(const void* data, std::size_t size, const SoundBufferParams& params) std::shared_ptr<Sound> Sound::LoadFromMemory(const void* data, std::size_t size, const Params& params)
{ {
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromMemory(data, size, params); std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromMemory(data, size, params);
if (!buffer) if (!buffer)
{ {
NazaraErrorFmt("failed to load buffer from memory ({0})", PointerToString(data)); NazaraErrorFmt("failed to load buffer from memory ({0})", PointerToString(data));
return false; return {};
} }
SetBuffer(std::move(buffer)); std::shared_ptr<Sound> sound = std::make_shared<Sound>();
return true; sound->SetBuffer(std::move(buffer));
return sound;
} }
/*! /*!
@ -186,17 +188,18 @@ namespace Nz
* *
* \remark Produces a NazaraError if loading failed * \remark Produces a NazaraError if loading failed
*/ */
bool Sound::LoadFromStream(Stream& stream, const SoundBufferParams& params) std::shared_ptr<Sound> Sound::LoadFromStream(Stream& stream, const Params& params)
{ {
std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromStream(stream, params); std::shared_ptr<SoundBuffer> buffer = SoundBuffer::LoadFromStream(stream, params);
if (!buffer) if (!buffer)
{ {
NazaraError("failed to load buffer from stream"); NazaraError("failed to load buffer from stream");
return false; return {};
} }
SetBuffer(std::move(buffer)); std::shared_ptr<Sound> sound = std::make_shared<Sound>();
return true; sound->SetBuffer(std::move(buffer));
return sound;
} }
/*! /*!