diff --git a/src/Sound/Jukebox.cpp b/src/Sound/Jukebox.cpp index 094ed28e..cb7b5c12 100644 --- a/src/Sound/Jukebox.cpp +++ b/src/Sound/Jukebox.cpp @@ -165,7 +165,8 @@ namespace Dynamo::Sound { } // Apply the filters - ListenerProperties &listener = find_closest_listener(material); + ListenerProperties &listener = + _listeners.find_closest(material.position); for (const auto &filter : material.filters) { transformed = filter->apply(transformed, 0, @@ -189,22 +190,6 @@ namespace Dynamo::Sound { chunk.frame += length; } - ListenerProperties & - Jukebox::find_closest_listener(const DynamicMaterial &material) { - u32 closest_index = 0; - for (u32 i = 0; i < _listeners.size(); i++) { - Vec3 best = _listeners[i].position; - Vec3 curr = _listeners[closest_index].position; - - f32 a = (best - material.position).length_squared(); - f32 b = (curr - material.position).length_squared(); - if (b < a) { - closest_index = i; - } - } - return _listeners[closest_index]; - } - const std::vector Jukebox::get_devices() { std::vector devices; PaError err; diff --git a/src/Sound/Jukebox.hpp b/src/Sound/Jukebox.hpp index 1525388d..dc785a6a 100644 --- a/src/Sound/Jukebox.hpp +++ b/src/Sound/Jukebox.hpp @@ -160,15 +160,6 @@ namespace Dynamo::Sound { */ void process_chunk(Chunk &chunk); - /** - * @brief Find the closest listener to a sound - * - * @param material - * @return ListenerProperties& - */ - ListenerProperties & - find_closest_listener(const DynamicMaterial &material); - public: /** * @brief Construct a new Jukebox object diff --git a/src/Sound/Listener.hpp b/src/Sound/Listener.hpp index eca4adec..10dafbde 100644 --- a/src/Sound/Listener.hpp +++ b/src/Sound/Listener.hpp @@ -1,8 +1,8 @@ #pragma once -#include "../Types.hpp" #include "../Math/Quaternion.hpp" #include "../Math/Vec3.hpp" +#include "../Types.hpp" #include "../Utils/IdTracker.hpp" #include "../Utils/SparseSet.hpp" @@ -125,5 +125,26 @@ namespace Dynamo::Sound { inline ListenerProperties &operator[](u32 index) { return _properties.at(index); } + + /** + * @brief Find the closest listener to a given position. + * + * @param position + * @return ListenerProperties& + */ + ListenerProperties &find_closest(Vec3 position) { + u32 closest_index = 0; + for (u32 i = 0; i < _properties.size(); i++) { + Vec3 best = _properties.at(i).position; + Vec3 curr = _properties.at(closest_index).position; + + f32 a = (best - position).length_squared(); + f32 b = (curr - position).length_squared(); + if (b < a) { + closest_index = i; + } + } + return _properties.at(closest_index); + } }; } // namespace Dynamo::Sound \ No newline at end of file