Added Listeners instead of single engine listener
This commit is contained in:
@@ -19,8 +19,9 @@ pkg_check_modules(AVCODEC REQUIRED libavcodec)
|
||||
pkg_check_modules(AVUTIL REQUIRED libavutil)
|
||||
pkg_check_modules(SWRESAMPLE REQUIRED libswresample)
|
||||
|
||||
add_library(ChargeAudio SHARED "src/ChargeAudio.hpp" "src/Engine.cpp"
|
||||
"src/Sound.cpp" "lib/miniaudio/miniaudio.c")
|
||||
add_library(
|
||||
ChargeAudio SHARED "src/ChargeAudio.hpp" "src/Engine.cpp" "src/Sound.cpp"
|
||||
"src/Listener.cpp" "lib/miniaudio/miniaudio.c")
|
||||
|
||||
target_link_libraries(
|
||||
ChargeAudio
|
||||
|
@@ -30,20 +30,35 @@ private:
|
||||
friend class Engine;
|
||||
};
|
||||
|
||||
class Listener {
|
||||
public:
|
||||
void SetPosition(Magnum::Vector3 position);
|
||||
Magnum::Vector3 GetPosition();
|
||||
|
||||
private:
|
||||
Listener();
|
||||
class Engine *baseEngine;
|
||||
ma_uint64 listenerID;
|
||||
friend class Engine;
|
||||
};
|
||||
|
||||
class Engine {
|
||||
public:
|
||||
Engine();
|
||||
~Engine();
|
||||
Containers::Pointer<Sound> CreateSound(std::string filepath);
|
||||
|
||||
void SetPosition(Magnum::Vector3 position);
|
||||
Magnum::Vector3 GetPosition();
|
||||
// Creating tools
|
||||
Containers::Pointer<Sound> CreateSound(std::string filepath);
|
||||
Containers::Pointer<Listener> CreateListener();
|
||||
|
||||
void SetVolume(float value);
|
||||
float GetVolume();
|
||||
|
||||
private:
|
||||
ma_engine maEngine;
|
||||
ma_result maResponse;
|
||||
ma_uint64 listenerCounter = 0;
|
||||
friend class Listener;
|
||||
};
|
||||
|
||||
} // namespace ChargeAudio
|
||||
|
@@ -32,21 +32,17 @@ Containers::Pointer<Sound> Engine::CreateSound(std::string filepath) {
|
||||
throw new std::runtime_error(
|
||||
"Failed to create the sound from file. Check STDERR for more info.");
|
||||
}
|
||||
|
||||
return sound;
|
||||
}
|
||||
|
||||
Containers::Pointer<Listener> Engine::CreateListener() {
|
||||
auto listener = Containers::Pointer<Listener>(new Listener());
|
||||
listener->baseEngine = this;
|
||||
listener->listenerID = listenerCounter++;
|
||||
|
||||
return listener;
|
||||
}
|
||||
|
||||
// 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); }
|
||||
float Engine::GetVolume() { return ma_engine_get_volume(&maEngine); }
|
||||
|
19
src/Listener.cpp
Normal file
19
src/Listener.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "ChargeAudio.hpp"
|
||||
#include <Magnum/Math/Vector3.h>
|
||||
|
||||
using namespace ChargeAudio;
|
||||
|
||||
Listener::Listener() {}
|
||||
|
||||
// Controls
|
||||
void Listener::SetPosition(Magnum::Vector3 position) {
|
||||
ma_engine_listener_set_position(&baseEngine->maEngine, listenerID,
|
||||
position.x(), position.y(), position.z());
|
||||
}
|
||||
|
||||
Magnum::Vector3 Listener::GetPosition() {
|
||||
ma_vec3f pos =
|
||||
ma_engine_listener_get_position(&baseEngine->maEngine, listenerID);
|
||||
return Magnum::Vector3(pos.x, pos.y, pos.z);
|
||||
;
|
||||
}
|
Reference in New Issue
Block a user