62#define JPL_VALIDATE_VBAP_LUT 0
66#define JPL_SCOPE_TIME(outFloat)
67#define JPL_SCOPE_TIME(outFloat)
78 struct VBAPBaseTraits;
80 template<
class PannerType,
class Traits>
113 std::pair<EChannel, float>{
FrontLeft, -0.785398f },
114 std::pair<EChannel, float>{
FrontRight, 0.785398f },
116 std::pair<EChannel, float>{
LFE, 0.0f },
117 std::pair<EChannel, float>{
BackLeft, -2.35619f },
118 std::pair<EChannel, float>{
BackRight, 2.35619f },
121 std::pair<EChannel, float>{
BackCenter, 3.14159f },
122 std::pair<EChannel, float>{
SideLeft, -1.5708f },
123 std::pair<EChannel, float>{
SideRight, 1.5708f },
125 std::pair<EChannel, float>{
TopCenter, 3.14159f },
130 std::pair<EChannel, float>{
TopSideLeft, -1.5708f },
133 std::pair<EChannel, float>{
TopBackLeft, -2.35619f },
137 std::pair<EChannel, float>{
WideLeft, -1.0472f },
138 std::pair<EChannel, float>{
WideRight, 1.0472f }
142 [
channel](
const std::pair<EChannel, float>& p)
144 return p.first == channel;
153 std::pair<EChannel, Vec3Type>{
FrontLeft, { -0.7071f, 0.0f, -0.7071f } },
154 std::pair<EChannel, Vec3Type>{
FrontRight, { 0.7071f, 0.0f, -0.7071f } },
155 std::pair<EChannel, Vec3Type>{
FrontCenter, { 0.0f, 0.0f, -1.0f } },
156 std::pair<EChannel, Vec3Type>{
LFE, { 0.0f, 0.0f, -1.0f } },
157 std::pair<EChannel, Vec3Type>{
BackLeft, { -0.7071f, 0.0f, 0.7071f } },
158 std::pair<EChannel, Vec3Type>{
BackRight, { 0.7071f, 0.0f, 0.7071f } },
159 std::pair<EChannel, Vec3Type>{
FrontLeftCenter, { -0.3162f, 0.0f, -0.9487f } },
160 std::pair<EChannel, Vec3Type>{
FrontRightCenter, { 0.3162f, 0.0f, -0.9487f } },
161 std::pair<EChannel, Vec3Type>{
BackCenter, { 0.0f, 0.0f, 1.0f } },
162 std::pair<EChannel, Vec3Type>{
SideLeft, { -1.0f, 0.0f, 0.0f } },
163 std::pair<EChannel, Vec3Type>{
SideRight, { 1.0f, 0.0f, 0.0f } },
165 std::pair<EChannel, Vec3Type>{
TopCenter, { 0.0f, 1.0f, 0.0f } },
166 std::pair<EChannel, Vec3Type>{
TopFrontLeft, { -0.5774f, 0.5774f, -0.5774f } },
167 std::pair<EChannel, Vec3Type>{
TopFrontCenter, { 0.0f, 0.7071f, -0.7071f } },
168 std::pair<EChannel, Vec3Type>{
TopFrontRight, { 0.5774f, 0.5774f, -0.5774f } },
170 std::pair<EChannel, Vec3Type>{
TopSideLeft, { -0.7071f, 0.7071f, 0.0f } },
171 std::pair<EChannel, Vec3Type>{
TopSideRight, { 0.7071f, 0.7071f, 0.0f } },
173 std::pair<EChannel, Vec3Type>{
TopBackLeft, { -0.5774f, 0.5774f, 0.5774f } },
174 std::pair<EChannel, Vec3Type>{
TopBackCenter, { 0.0f, 0.7071f, 0.7071f } },
175 std::pair<EChannel, Vec3Type>{
TopBackRight, { 0.5774f, 0.5774f, 0.5774f } },
177 std::pair<EChannel, Vec3Type>{
WideLeft, { -0.866f, 0.0f, -0.5f } },
178 std::pair<EChannel, Vec3Type>{
WideRight, { 0.866f, 0.0f, -0.5f } },
183 [
channel](
const std::pair<EChannel, Vec3Type>& p)
185 return p.first == channel;
197 return "Failed to initialize SourceLayout, provided invalid channel map.";
201 return "Failed to initialize SourceLayout for VBAPPanner, provided channel map has top channels that don't participate in panning.";
225 template<
class PannerType,
class Traits>
231 template<
class T>
using Array = std::pmr::vector<T>;
308 static_assert(std::same_as<typename LUTInterface::Vec3Type, Vec3Type>);
360 template<
class OnChannelGeneratedCallback = std::
identity>
366 template<
class OnChannelGeneratedCallback = std::
identity>
368 const PanUpdateDataWithOrientation&
updateData,
382 template<
class OnChannelGeneratedCallback = std::
identity>
390 template<
bool bAccumulatePow>
391 inline void ProcessVirtualSourcesImpl(std::span<const VirtualSource>
virtualSources,
394 template<
bool bAccumulatePow>
404 ChannelMap mChannelMap;
409 float mShortestEdgeAperture = std::numeric_limits<float>::max();
422#define JPL_SLERP_SPREAD 1
424 template<
class PannerType,
class Traits>
430 template<
class PannerType,
class Traits>
437 template<
class PannerType,
class Traits>
444 template<
class PannerType,
class Traits>
460 mShortestEdgeAperture =
lutBuilder.FindShortestAperture();
467#if JPL_VALIDATE_VBAP_LUT
474 template<
class PannerType,
class Traits>
475 template<
class OnChannelGeneratedCallback>
481 JPL_ASSERT(
sourceLayout.GetTargetChannelMap() == mChannelMap,
"VBAP Panner can only work with VBAP source layout created for that panner.");
492 template<
class PannerType,
class Traits>
493 template<
class OnChannelGeneratedCallback>
499 JPL_ASSERT(
sourceLayout.GetTargetChannelMap() == mChannelMap,
"VBAP Panner can only work with VBAP source layout created for that panner.");
508 template<
class PannerType,
class Traits>
509 template<
class OnChannelGeneratedCallback>
519 "outChannelMixMap size must be equal to [num source channels] * [num target channels]");
551 namespace stdr = std::ranges;
552 namespace stdv = std::views;
563 static constexpr auto vsBufferCapacity =
static_cast<uint32>(SourceLayoutType::GetMaxNumVirtualSources());
639 if constexpr (!std::same_as<std::remove_cvref_t<OnChannelGeneratedCallback>, std::identity>)
720 template<
class PannerType,
class Traits>
734 template<
class PannerType,
class Traits>
735 template<
bool bAccumulatePow>
741 using QueryType =
typename LUTInterface::QueryType;
743 if constexpr (
requires{
typename QueryType::VBAPCell; })
749 typename QueryType::VBAPCell
cell;
751 LUTInterface::Query(*mLUT).GainsFor(
vs.Direction,
cell);
796 template<
class PannerType,
class Traits>
797 template<
bool bAccumulatePow>
805 using QueryType =
typename LUTInterface::QueryType;
807 if constexpr (
requires{
typename QueryType::VBAPCell; })
868 template<
class PannerType,
class Traits>
884 template<
class PannerType,
class Traits>
893 template<
class PannerType,
class Traits>
911 template<
class PannerType,
class Traits>
917 JPL_INFO_TAG(
"VBAP Panner",
"Requested source channel map with LFE, LFE is going to be skipped in the resulting channel mix map "
918 "(e.g. 5.1 source channel set going to have 5 channels, not 6).");
#define JPL_ASSERT(inExpression,...)
Main assert macro, usage: JPL_ASSERT(condition, message) or JPL_ASSERT(condition)
Definition ErrorReporting.h:76
#define JPL_ENSURE(inExpression,...)
Define ENSURE.
Definition ErrorReporting.h:90
#define JPL_ERROR_TAG(tag, message)
Definition ErrorReporting.h:124
#define JPL_INFO_TAG(tag, message)
Definition ErrorReporting.h:108
#define JPL_SCOPE_TIME(outFloat)
Definition PannerBase.h:66
Definition ChannelMap.h:150
constexpr bool IsValid() const noexcept
Definition ChannelMap.h:160
Definition PannerBase.h:227
JPL_INLINE bool InitializeSourceLayout(ChannelMap channelMap, SourceLayoutType &outLayout) const
Create/initialize SourceLayout for given source channelMap
Definition PannerBase.h:425
typename PanType::LUTInterface LUTInterface
Definition PannerBase.h:302
JPL_INLINE void ProcessVirtualSources(std::span< const VirtualSource > virtualSources, std::span< float > outGains) const
Definition PannerBase.h:721
typename Traits::Vec3Type Vec3Type
Aliases to avoid typing wordy templates.
Definition PannerBase.h:230
std::pmr::vector< T > Array
Definition PannerBase.h:231
JPL_INLINE void GetSpeakerGains(const Vec3Type &direction, std::span< float > outGains) const
Definition PannerBase.h:431
typename PanType::LUTType LUTType
Definition PannerBase.h:301
JPL_INLINE void ProcessVBAPData(const SourceLayoutType &sourceLayout, const PanUpdateData &updateData, std::span< float > outChannelMixMap, OnChannelGeneratedCallback &&onVSsGeneratedCb={}) const
Definition PannerBase.h:476
JPL_INLINE bool IsLUTInitialized() const noexcept
Definition PannerBase.h:317
typename PanType::SourceLayout SourceLayoutType
Definition PannerBase.h:303
JPL_INLINE const LUTType * GetLUT() const noexcept
Get the look-up table. Can be nullptr, if hasn't been initialized yet.
Definition PannerBase.h:320
bool InitializeLUT(ChannelMap channelMap)
Definition PannerBase.h:445
PannerType PanType
Definition PannerBase.h:300
JPL_INLINE uint32 GetNumChannels() const noexcept
Definition PannerBase.h:341
typename Traits::ChannelGains & ChannelGainsRef
Definition PannerBase.h:232
static JPL_INLINE void NormalizeWeights(std::span< VirtualSource > virtualSources)
Normalize weights of the virtual sources to ensure consistent energy.
Definition PannerBase.h:869
JPL_INLINE float GetShortestSpeakerAperture() const noexcept
Definition PannerBase.h:348
JPL_INLINE ChannelMap GetChannelMap() const noexcept
Get the channel map the panner is initialized to.
Definition PannerBase.h:344
JPL_INLINE bool IsInitialized() const noexcept
Definition PannerBase.h:336
JPL_INLINE constexpr void NormalizeL2(ContainerType &&data)
Apply unit vector scaling, so that the magnitude of the vector = 1.
Definition Algorithm.h:98
JPL_INLINE constexpr T InvSqrt(T x) noexcept
Definition Math.h:283
JPL_INLINE constexpr auto Abs(const T &value) noexcept
Standard abs is not constexpr in C++20.
Definition Math.h:87
Vec3 Slerp(const Vec3 &v0, const Vec3 &v1, float t) noexcept
Input vectors must be normalized.
Definition Vec3Math.h:142
Definition AcousticMaterial.h:36
JPL_INLINE constexpr auto GetNumSIMDOps(std::unsigned_integral auto count) noexcept
Get number of SIMD operations that can fit into the count
Definition SIMDMath.h:51
std::uint32_t uint32
Definition Core.h:311
JPL_INLINE std::optional< const char * > IsValidSourceChannelMap(ChannelMap channelMap)
Definition PannerBase.h:193
std::pmr::memory_resource * GetDefaultMemoryResource() noexcept
Definition Memory.h:42
Vec3BufferView< simd > Vec3SIMDBufferView
View into a Vec3-like SoA buffer, holding separate arrays of Vec3 components X, Y,...
Definition Vec3Buffer.h:56
EChannel
Definition ChannelMap.h:39
@ TopBackLeft
Definition ChannelMap.h:67
@ TopFrontRight
Definition ChannelMap.h:61
@ BackCenter
Definition ChannelMap.h:53
@ TopSideRight
Definition ChannelMap.h:65
@ TopFrontCenter
Definition ChannelMap.h:60
@ TopSideLeft
Definition ChannelMap.h:64
@ FrontLeftCenter
Definition ChannelMap.h:48
@ TopBackCenter
Definition ChannelMap.h:68
@ SideRight
Definition ChannelMap.h:46
@ SideLeft
Definition ChannelMap.h:45
@ FrontCenter
Definition ChannelMap.h:42
@ WideRight
Definition ChannelMap.h:56
@ BackRight
Definition ChannelMap.h:52
@ TopBackRight
Definition ChannelMap.h:69
@ BackLeft
Definition ChannelMap.h:51
@ FrontRightCenter
Definition ChannelMap.h:49
@ TopCenter
Definition ChannelMap.h:58
@ LFE
Definition ChannelMap.h:43
@ FrontLeft
Definition ChannelMap.h:40
@ WideLeft
Definition ChannelMap.h:55
@ TopFrontLeft
Definition ChannelMap.h:59
@ FrontRight
Definition ChannelMap.h:41
std::uint8_t uint8
Definition Core.h:309
JPL_INLINE simd min(const simd &a, const simd &b) noexcept
Element-wise min.
Definition SIMD.h:1813
JPL_INLINE float GetSpreadFromSourceSize(float sourceSize, float distance)
Definition PannerBase.h:69
Orthonormal basis (column-major)
Definition MinimalBasis.h:35
Minimum data required to do our orientation math.
Definition Position.h:32
Minimal quaternion (w + xi + yj + zk)
Definition MinimalQuat.h:38
Forward declaration.
Definition PannerBase.h:91
static constexpr auto MAX_CHANNELS
Definition PannerBase.h:99
static constexpr auto MAX_CHANNEL_MIX_MAP_SIZE
Definition PannerBase.h:103
Vec3 Vec3Type
Definition PannerBase.h:92
static constexpr auto MAX_SOURCE_CHANNELS
Definition PannerBase.h:101
static Vec3Type GetChannelVector(EChannel channel)
Definition PannerBase.h:148
static float GetChannelAngle(EChannel channel)
Definition PannerBase.h:108
std::array< float, MAX_CHANNELS > ChannelGains
Definition PannerBase.h:105
static void GetSortedChannelAngles(ChannelMap channelMap, ArrayType< ChannelAngle, Args... > &sortedChannelAngles, std::function< float(EChannel)> getChannelAngle, bool skipLFE=true)
Get channel angles from ChannelMap, normalize to [0, Pi] and sort in assending order.
Definition VBAPEx.h:255
Definition PannerBase.h:265
Quat< Vec3Type > Rotation
Channel group rotation offset as per the channel this group is associated to.
Definition PannerBase.h:267
uint32 Channel
Index or Id of the channel this group is associated to.
Definition PannerBase.h:270
Definition PannerBase.h:247
PanSourceOrientation Orientation
Definition PannerBase.h:249
PanUpdateData Pan
Definition PannerBase.h:248
Parameters to update VBAP data for a source.
Definition PannerBase.h:238
Vec3Type SourceDirection
Definition PannerBase.h:239
float Spread
Definition PannerBase.h:241
float Focus
Definition PannerBase.h:240
Definition PannerBase.h:281
float mDefaultVSWeight
Definition PannerBase.h:296
Array< ChannelGroup > ChannelGroups
Groups of virtual sources associated with source channels.
Definition PannerBase.h:283
JPL_INLINE float GetDefaultVSWeight() const noexcept
Definition PannerBase.h:289
ChannelMap mTargetChannelMap
Definition PannerBase.h:295
JPL_INLINE ChannelMap GetTargetChannelMap() const noexcept
Definition PannerBase.h:286
JPL_INLINE void SetTargetChannelMap(ChannelMap targetChannelMap) noexcept
Definition PannerBase.h:290
bool InitializeBase(ChannelMap channelMap, ChannelMap targetMap, uint32 numVirtualSourcesPerChannel)
Definition PannerBase.h:912
JPL_INLINE bool IsInitialized() const noexcept
Definition PannerBase.h:285
Definition PannerBase.h:256
float Weight
Definition PannerBase.h:258
Vec3Type Direction
Definition PannerBase.h:257
Definition Vec3Buffer.h:89
Definition Vec3Buffer.h:66
Minimal 4-wide 32-bit float vector implementation for SIMD.
Definition SIMD.h:60
static constexpr std::size_t size() noexcept
Get number of element of the vector.
Definition SIMD.h:97