Moved miniaudio to ma namespace. Added Engine destructor. Added Engine Listener Position.

This commit is contained in:
2025-09-04 23:11:31 +03:00
parent 29bcf9fbae
commit ee83818de2
3 changed files with 23 additions and 4 deletions

View File

@@ -6,16 +6,18 @@
#include <string> #include <string>
namespace ChargeAudio { namespace ChargeAudio {
using namespace Corrade; namespace _ma {
namespace {
#include "miniaudio/miniaudio.h" #include "miniaudio/miniaudio.h"
} }
using namespace Corrade;
using namespace _ma;
class Sound { class Sound {
public: public:
~Sound(); ~Sound();
void Play(); void Play();
void Pause(); void Pause();
void Reset(); void Reset();
void SetPosition(Magnum::Vector3 position); void SetPosition(Magnum::Vector3 position);
Magnum::Vector3 GetPosition(); Magnum::Vector3 GetPosition();
void SetVolume(float value); void SetVolume(float value);
@@ -31,7 +33,11 @@ private:
class Engine { class Engine {
public: public:
Engine(); Engine();
~Engine();
Containers::Pointer<Sound> CreateSound(std::string filepath); Containers::Pointer<Sound> CreateSound(std::string filepath);
void SetPosition(Magnum::Vector3 position);
Magnum::Vector3 GetPosition();
void SetVolume(float value); void SetVolume(float value);
float GetVolume(); float GetVolume();

View File

@@ -1,6 +1,7 @@
#include "ChargeAudio.hpp" #include "ChargeAudio.hpp"
#include <Corrade/Containers/Pointer.h> #include <Corrade/Containers/Pointer.h>
#include <Corrade/Utility/Debug.h> #include <Corrade/Utility/Debug.h>
#include <Magnum/Math/Vector3.h>
#include <cstddef> #include <cstddef>
#include <stdexcept> #include <stdexcept>
@@ -17,6 +18,8 @@ Engine::Engine() {
} }
} }
Engine::~Engine() { ma_engine_uninit(&maEngine); }
Containers::Pointer<Sound> Engine::CreateSound(std::string filepath) { Containers::Pointer<Sound> Engine::CreateSound(std::string filepath) {
auto sound = Containers::Pointer<Sound>(new Sound()); auto sound = Containers::Pointer<Sound>(new Sound());
sound->baseEngine = this; sound->baseEngine = this;
@@ -34,5 +37,16 @@ Containers::Pointer<Sound> Engine::CreateSound(std::string filepath) {
} }
// Controls // Controls
void Engine::SetPosition(Magnum::Vector3 position) {
ma_engine_listener_set_position(&maEngine, 0, position.x(), position.y(),
position.z());
}
Magnum::Vector3 Engine::GetPosition() {
ma_vec3f pos = ma_engine_listener_get_position(&maEngine, 0);
return Magnum::Vector3(pos.x, pos.y, pos.z);
;
}
void Engine::SetVolume(float value) { ma_engine_set_volume(&maEngine, value); } void Engine::SetVolume(float value) { ma_engine_set_volume(&maEngine, value); }
float Engine::GetVolume() { return ma_engine_get_volume(&maEngine); } float Engine::GetVolume() { return ma_engine_get_volume(&maEngine); }

View File

@@ -16,8 +16,7 @@ void Sound::SetPosition(Magnum::Vector3 position) {
} }
Magnum::Vector3 Sound::GetPosition() { Magnum::Vector3 Sound::GetPosition() {
ma_vec3f pos = ma_sound_get_position(&maSound); ma_vec3f pos = ma_sound_get_position(&maSound);
Magnum::Vector3 position(pos.x, pos.y, pos.z); return Magnum::Vector3(pos.x, pos.y, pos.z);
return position;
} }
void Sound::SetVolume(float value) { ma_sound_set_volume(&maSound, value); } void Sound::SetVolume(float value) { ma_sound_set_volume(&maSound, value); }
float Sound::GetVolume() { return ma_sound_get_volume(&maSound); } float Sound::GetVolume() { return ma_sound_get_volume(&maSound); }