From ead1e742d1279b7f9de262fb7ec2881991027868 Mon Sep 17 00:00:00 2001 From: cat Date: Thu, 4 Sep 2025 22:30:24 +0300 Subject: [PATCH] For now using unique_ptr and implementation of Sound() --- src/ChargeAudio.hpp | 3 ++- src/Engine.cpp | 8 ++++---- src/Sound.cpp | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/ChargeAudio.hpp b/src/ChargeAudio.hpp index 90f6455..4f9b33a 100644 --- a/src/ChargeAudio.hpp +++ b/src/ChargeAudio.hpp @@ -2,6 +2,7 @@ #define CHARGE_AUDIO_BASE_H #include #include +#include #include namespace ChargeAudio { @@ -29,7 +30,7 @@ private: class Engine { public: Engine(); - Sound CreateSound(std::string filepath); + std::unique_ptr CreateSound(std::string filepath); void SetVolume(float value); float GetVolume(); diff --git a/src/Engine.cpp b/src/Engine.cpp index 1fd5991..10b266e 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -16,12 +16,12 @@ Engine::Engine() { } } -Sound Engine::CreateSound(std::string filepath) { - Sound sound; - sound.baseEngine = this; +std::unique_ptr Engine::CreateSound(std::string filepath) { + auto sound = std::unique_ptr(new Sound()); + sound->baseEngine = this; maResponse = ma_sound_init_from_file(&maEngine, filepath.c_str(), 0, NULL, - NULL, &sound.maSound); + NULL, &sound->maSound); if (maResponse != MA_SUCCESS) { Utility::Error{} << "Failed to create the sound from the file: " << filepath.c_str() << " (" << maResponse << ")"; diff --git a/src/Sound.cpp b/src/Sound.cpp index 8340ab6..2d47b5b 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -3,6 +3,7 @@ #include using namespace ChargeAudio; +Sound::Sound() {} Sound::~Sound() { ma_sound_uninit(&maSound); } // Controls