JPL Spatial
Sound spatialization and propagation library
Loading...
Searching...
No Matches
DummySpeakers.h
Go to the documentation of this file.
1//
2// ██╗██████╗ ██╗ ██╗██████╗ ███████╗
3// ██║██╔══██╗ ██║ ██║██╔══██╗██╔════╝ ** JPLSpatial **
4// ██║██████╔╝ ██║ ██║██████╔╝███████╗
5// ██ ██║██╔═══╝ ██║ ██║██╔══██╗╚════██║ https://github.com/Jaytheway/JPLSpatial
6// ╚█████╔╝██║ ███████╗██║██████╔╝███████║
7// ╚════╝ ╚═╝ ╚══════╝╚═╝╚═════╝ ╚══════╝
8//
9// Copyright 2024 Jaroslav Pevno, JPLSpatial is offered under the terms of the ISC license:
10//
11// Permission to use, copy, modify, and/or distribute this software for any purpose with or
12// without fee is hereby granted, provided that the above copyright notice and this permission
13// notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
14// WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
16// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17// WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
18// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20#pragma once
21
22#include "JPLSpatial/Core.h"
25
26#include <type_traits>
27#include <vector>
28#include <algorithm>
29
30namespace JPL::VBAP
31{
32 //==========================================================================
34 template<auto GetChannelVectorFunction>
36 {
37 public:
38 using Vec3Type = std::remove_cvref_t<decltype(GetChannelVectorFunction(EChannel{}))>;
39
40 JPL_INLINE constexpr DummySpeakers(ChannelMap channelMap, std::pmr::vector<Vec3Type>& speakerVectors) noexcept
41 : mMap(channelMap)
42 , mVectors(speakerVectors)
43 , mDummyIndices(GetDefaultMemoryResource())
44 {
45 }
46
48 {
49 mVectors.push_back(speakerVector);
50 mDummyIndices.push_back(static_cast<uint32>(mVectors.size() - 1));
51 }
52
58
59 [[nodiscard]] JPL_INLINE constexpr bool Contains(uint32 index) const
60 {
61 return std::find(mDummyIndices.begin(), mDummyIndices.end(), index) != mDummyIndices.end();
62 }
63
64 [[nodiscard]] JPL_INLINE constexpr bool HasDummyAt(const Vec3Type& direction, float tolerance) const noexcept
65 {
66 for (uint32 idx : mDummyIndices)
67 {
69 return true;
70 }
71
72 return false;
73 }
74
75 [[nodiscard]] JPL_INLINE constexpr uint32 GetNumDummies() const noexcept { return static_cast<uint32>(mDummyIndices.size()); }
76 [[nodiscard]] JPL_INLINE constexpr ChannelMap GetChannelMap() const noexcept { return mMap; }
77
78 private:
79 ChannelMap mMap;
80 std::pmr::vector<Vec3Type>& mVectors;
81 std::pmr::vector<uint32> mDummyIndices;
82 };
83} // namespace JPL::VBAP
Definition ChannelMap.h:150
constexpr bool Has(EChannel channel) const noexcept
Definition ChannelMap.h:157
Utility class to encapsulate dummy speaker handling while building a LUT.
Definition DummySpeakers.h:36
std::remove_cvref_t< decltype(GetChannelVectorFunction(EChannel{}))> Vec3Type
Definition DummySpeakers.h:38
JPL_INLINE constexpr void AddIfChannelNotPresent(EChannel channel)
Definition DummySpeakers.h:53
JPL_INLINE constexpr DummySpeakers(ChannelMap channelMap, std::pmr::vector< Vec3Type > &speakerVectors) noexcept
Definition DummySpeakers.h:40
JPL_INLINE constexpr ChannelMap GetChannelMap() const noexcept
Definition DummySpeakers.h:76
JPL_INLINE constexpr bool Contains(uint32 index) const
Definition DummySpeakers.h:59
JPL_INLINE constexpr uint32 GetNumDummies() const noexcept
Definition DummySpeakers.h:75
JPL_INLINE constexpr bool HasDummyAt(const Vec3Type &direction, float tolerance) const noexcept
Definition DummySpeakers.h:64
JPL_INLINE constexpr void AddDummy(const Vec3Type &speakerVector)
Definition DummySpeakers.h:47
JPL_INLINE constexpr bool IsNearlyEqual(T a, T b, T tolerance=JPL_FLOAT_EPS_V< T >) noexcept
Definition Math.h:152
Forward declaration.
Definition DummySpeakers.h:31
std::uint32_t uint32
Definition Core.h:311
std::pmr::memory_resource * GetDefaultMemoryResource() noexcept
Definition Memory.h:42
EChannel
Definition ChannelMap.h:39
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813