aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2019-10-03 10:24:01 -0400
committerClyne Sullivan <clyne@bitgloo.com>2019-10-03 10:24:01 -0400
commiteed19ec73698c8180a51c33fa56c7cfe7c0e60f0 (patch)
treed231c15d73a16decf0c76b399bb2e212507ad195
parent16a29df61f6cbc546123c91a0b72d1bfb68d6de2 (diff)
positional audio working
-rw-r--r--Assets/boing.wavbin605018 -> 302628 bytes
-rw-r--r--Assets/jump.wavbin303194 -> 151716 bytes
-rw-r--r--src/audio.cpp18
-rw-r--r--src/engine.cpp1
4 files changed, 17 insertions, 2 deletions
diff --git a/Assets/boing.wav b/Assets/boing.wav
index a142197..088963d 100644
--- a/Assets/boing.wav
+++ b/Assets/boing.wav
Binary files differ
diff --git a/Assets/jump.wav b/Assets/jump.wav
index 1cd1681..b9849ab 100644
--- a/Assets/jump.wav
+++ b/Assets/jump.wav
Binary files differ
diff --git a/src/audio.cpp b/src/audio.cpp
index 8bb1413..2f14c97 100644
--- a/src/audio.cpp
+++ b/src/audio.cpp
@@ -19,6 +19,7 @@
*/
#include "audio.hpp"
+#include "components/Player.hpp"
#include <AL/alut.h>
#include <iostream>
@@ -55,12 +56,25 @@ void AudioSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
if (alutInitWithoutContext(nullptr, nullptr) != AL_TRUE)
return; // TODO Third uh oh
+
+ ALfloat listenerOri[] = { 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f };
+ alListener3f(AL_POSITION, 0, 0, 0.0f);
+ alListener3f(AL_VELOCITY, 0, 0, 0);
+ alListenerfv(AL_ORIENTATION, listenerOri);
}
-void AudioSystem::update([[maybe_unused]] entityx::EntityManager& entities,
+void AudioSystem::update(entityx::EntityManager& entities,
[[maybe_unused]] entityx::EventManager& events,
[[maybe_unused]] entityx::TimeDelta dt)
-{}
+{
+ entities.each<Player, Position>(
+ []([[maybe_unused]] entityx::Entity e,
+ [[maybe_unused]] Player& p,
+ Position &pos)
+ {
+ alListener3f(AL_POSITION, pos.x, pos.y, 0.0f);
+ });
+}
void AudioSystem::receive(const entityx::ComponentAddedEvent<Audio>& cae)
{
diff --git a/src/engine.cpp b/src/engine.cpp
index c6bec27..dc0c481 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -120,6 +120,7 @@ void Engine::logicLoop(void)
});
}
+ systems.update<AudioSystem>(dt);
std::this_thread::yield();
}
}