50 template<auto GetSpeakerAngleFunction>
96 static constexpr float StepMin = 0.224686f;
97 static constexpr float StepMax = 0.447623f;
170 template<auto GetSpeakerAngleFunction>
176 uint16 mLUTResolution = 0;
177 uint16 mLUTResolutionMask = 0;
178 float mInvLUTResolution = 0.0f;
179 uint8 mNumTargetChannels = 0;
192 template<CVec3 Vec3Type>
201 LUT.GetSpeakerGains({
203 static_cast<float>(
GetZ(
dir)) },
225 template<auto GetSpeakerVectorFunction, auto GetSpeakerAngleFunction>
250 template<auto GetSpeakerAngleFunction>
254 using Array = std::pmr::vector<T>;
255 using ChannelAngleArray = Array<ChannelAngle>;
275#if JPL_VALIDATE_VBAP_LUT
280 void ComputePairMatrices();
284 template<
class ThisType,
class CallbackType>
299 uint32 mNumInternalChannels;
300 uint32 mNumTargetChannels;
330 return static_cast<int>(
332 * mLUTResolution + 0.5f
333 ) & mLUTResolutionMask;
348 return static_cast<int>(
Math::FMA(
static_cast<float>(mLUTResolution),
diamond, 0.5f)) & mLUTResolutionMask;
364 return static_cast<int>(
uniformAngleT * mLUTResolution + 0.5f) & mLUTResolutionMask;
369 const float angle = std::atan2(
x,
z);
397 mLUTResolutionMask = mLUTResolution - 1;
398 mInvLUTResolution = 1.0f / mLUTResolution;
441 static_cast<uint32>(mNumTargetChannels) << 1,
442 (
static_cast<uint32>(mNumTargetChannels) << 1) + mNumTargetChannels
463 auto isPow2 = [](
uint32 n) {
return n && ((n & (n - 1)) == 0); };
474 const float p =
static_cast<float>(
j) *
invM_Corr;
480 float theta = std::atan2(
v.X,
v.Y);
485 const float t = (
theta * JPL_INV_TWO_PI) *
static_cast<float>(
N_uniform);
494 auto isPow2 = [](
uint32_t n) {
return n && ((n & (n - 1)) == 0); };
504 const float p =
static_cast<float>(
j) *
invM_Corr;
509 float theta = std::atan2(
v.X,
v.Y);
523 if (d > 0.5f) d -= 1.0f;
524 if (d < -0.5f) d += 1.0f;
526 if (
u < 0.0f)
u += 1.0f;
527 if (
u >= 1.0f)
u -= 1.0f;
533 template<auto GetSpeakerAngleFunction>
538 mNumTargetChannels =
channelMap.GetNumChannels();
546 static constexpr bool skipLFE =
false;
548 JPL_ASSERT(mChannelAngels.size() == mNumInternalChannels);
552 ComputePairMatrices();
556 mChannelConversionWeights.
Resize(mNumTargetChannels, mNumInternalChannels);
557 ComputeChannelConversionRectangularWeights(mChannelMapInternal, mChannelMapTarget, mChannelConversionWeights);
560 mLUT.Resize(LUTType::LUTStats::Resolution, mNumTargetChannels);
563 template<auto GetSpeakerAngleFunction>
583 template<auto GetSpeakerAngleFunction>
587 for (
const ChannelPair&
pair : mChannelPairs)
596 if (RequiresChannelConversion())
616 template<auto GetSpeakerAngleFunction>
622 const float step = 1.0f / mLUT.GetLUTResolution();
642 template<auto GetSpeakerAngleFunction>
662 mChannelPairs.emplace_back(
671 template<auto GetSpeakerAngleFunction>
672 template<
class ThisType,
class CallbackType>
673 inline void LUTBuilder2D<GetSpeakerAngleFunction>::ForEachChannelAnglePair(
ThisType&
self,
678 return idx + (
self.mChannelAngels[
idx].ChannelId ==
self.mLFEIndex);
686 const ChannelAngle&
cha1 =
self.mChannelAngels[
ch1];
687 const ChannelAngle&
cha2 =
self.mChannelAngels[
ch2];
695 const ChannelAngle&
cha1 =
self.mChannelAngels[
ch1];
696 const ChannelAngle&
cha2 =
self.mChannelAngels[
ch2];
701 template<auto GetSpeakerAngleFunction>
718 template<auto GetSpeakerAngleFunction>
719 inline void LUTBuilder2D<GetSpeakerAngleFunction>::ApplyChannelConversion(
const std::pair<uint32, uint32>&
inChannelIds,
733#if JPL_VALIDATE_VBAP_LUT
734 template<auto GetSpeakerAngleFunction>
735 void LUTBuilder2D<GetSpeakerAngleFunction>::ValidateLUT()
const
744 if (!LUTCodec::IsValidCode(
i))
747 const auto&
speakers = mLUT->Speakers[
i];
755 if (!LUTCodec::IsValidCode(
i))
758 const auto&
gains = mLUT->Gains[
i];
#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
Utility helper to access 2D array kind of weights.
Definition ChannelConversion.h:100
JPL_INLINE void Resize(uint32 numOutputs, uint32 numInputs)
Definition ChannelConversion.h:113
Definition ChannelMap.h:150
constexpr uint32 GetNumChannels() const noexcept
Definition ChannelMap.h:162
static constexpr ChannelMap FromChannelMask(uint32 channelMask)
Definition ChannelMap.h:198
constexpr uint32 GetChannelIndex(EChannel channel) const
Definition ChannelMap.h:163
Look-up table containing channel gains for each direction.
Definition VBAPLUT2D.h:56
JPL_INLINE int AngleNormalizedToLUTPosition(float angleNormalised) const
Definition VBAPLUT2D.h:326
JPL_INLINE bool IsInitialized() const noexcept
Definition VBAPLUT2D.h:107
static void BuildDiamondToAngleNormLUT(Array< float > &outCorrectionLUT, uint32 M_corr=1024)
Definition VBAPLUT2D.h:492
std::pmr::vector< T > Array
Definition VBAPLUT2D.h:102
JPL_INLINE size_t GetLUTSize() const noexcept
Size of the LUT = LUT Resolution * Number of Channels.
Definition VBAPLUT2D.h:126
JPL_INLINE int CartesianToLUTPosition(float x, float y) const
Get LUT position from direction vector.
Definition VBAPLUT2D.h:344
static void BuildDiamondToUniformIndexLUT(Array< uint32 > &outCorrectionLUT, uint32 N_uniform, uint32 M_corr=1024)
Definition VBAPLUT2D.h:460
JPL_INLINE size_t GetLUTResolution() const noexcept
Resolution of the LUT.
Definition VBAPLUT2D.h:129
JPL_INLINE float & operator[](int i)
Definition VBAPLUT2D.h:122
JPL_INLINE const float & operator[](int i) const
Definition VBAPLUT2D.h:123
JPL_INLINE int AngleToLUTPosition(float angleInRadians) const
Definition VBAPLUT2D.h:336
JPL_INLINE float LUTPositionToAngle(int pos) const
Definition VBAPLUT2D.h:402
JPL_INLINE void GetSpeakerGains(int lutPosition, std::span< float > outGains) const
Get preprocessed speaker gains at specific LUT posotion.
Definition VBAPLUT2D.h:411
JPL_INLINE float GetLUTValue(uint32 positionInLUT) const
Definition VBAPLUT2D.h:120
Forward declarations.
Definition VBAPLUT2D.h:252
bool BuildForAllDirections()
Build the entire LUT for all directions.
Definition VBAPLUT2D.h:617
LUTBuilder2D(ChannelMap channelMap, LUTType &LUT)
Definition VBAPLUT2D.h:534
bool ComputeCellFor(const Vec2 &direction, int lutOffset)
Comput LUT gains for given direction and LUT offset.
Definition VBAPLUT2D.h:584
JPL_INLINE bool RequiresChannelConversion() const noexcept
Definition VBAPLUT2D.h:264
float FindShortestAperture() const
Find shortest aperture between two speakers of the target map.
Definition VBAPLUT2D.h:564
Definition VBAPLUT2D.h:227
static JPL_INLINE QueryType Query(const LUT2D &LUT)
Make LUTQuery object to query 'LUT' for speaker gains.
Definition VBAPLUT2D.h:242
std::remove_cvref_t< decltype(GetSpeakerVectorFunction(EChannel{}))> Vec3Type
Definition VBAPLUT2D.h:229
LUTBuilder2D< GetSpeakerAngleFunction > BuilderType
Definition VBAPLUT2D.h:231
static JPL_INLINE BuilderType MakeBuilder(ChannelMap channelMap, LUT2D &lut)
Make LUTBuilder object to build LUT for given 'channelMap' and 'LUTType'.
Definition VBAPLUT2D.h:236
LUTQuery2D QueryType
Definition VBAPLUT2D.h:232
Interface to query LUT gains for a direction.
Definition VBAPLUT2D.h:185
JPL_INLINE void GainsFor(const Vec3Type &direction, std::span< float > outGains) const
Definition VBAPLUT2D.h:193
JPL_INLINE void GainsFor(const simd &dirX, const simd &dirY, const simd &dirZ, std::span< simd > outGains) const
Definition VBAPLUT2D.h:210
JPL_INLINE LUTQuery2D(const LUT2D &lut) noexcept
Definition VBAPLUT2D.h:187
const LUT2D & LUT
Definition VBAPLUT2D.h:219
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 bool IsNormalizedL2(const ContainerType &data, float tolerance=JPL_FLOAT_EPS)
Definition Algorithm.h:115
JPL_INLINE constexpr T FMA(T a, T b, T c) noexcept
Inlined fuse multiply-add. Compiler in some circumstances is more eager to optimize this than std::fm...
Definition Math.h:186
JPL_INLINE simd InvSqrtFast(const simd &vec) noexcept
Definition SIMD.h:1783
JPL_INLINE std::pair< T, T > SinCos(T value) noexcept
Definition Math.h:164
Forward declaration.
Definition DummySpeakers.h:31
constexpr Vec2 FromDiamond(float p) noexcept
Decode scalar [0, 1] to a 2D unit vector.
Definition DirectionEncoding.h:212
JPL_INLINE auto GetX(const Vec3Type &v) noexcept
Definition Vec3Traits.h:35
JPL_INLINE void SetY(Vec3Type &v, Vec3FloatType< Vec3Type > value) noexcept
Definition Vec3Traits.h:40
JPL_INLINE auto GetZ(const Vec3Type &v) noexcept
Definition Vec3Traits.h:37
std::uint32_t uint32
Definition Core.h:311
std::pmr::memory_resource * GetDefaultMemoryResource() noexcept
Definition Memory.h:42
std::uint16_t uint16
Definition Core.h:310
EChannel
Definition ChannelMap.h:39
@ LFE
Definition ChannelMap.h:43
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
constexpr float ToDiamond(Vec2 dir) noexcept
"Diamond Encoding" of a 2D unit vector as per:
Definition DirectionEncoding.h:197
Minimal 2x2 matrix interface.
Definition MinimalMat.h:35
static JPL_INLINE constexpr Mat2 FromColumns(const Vec2 &l1, const Vec2 &l2) noexcept
Definition MinimalMat.h:42
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 VBAPLUT2D.h:92
static constexpr float StepVariance
Definition VBAPLUT2D.h:95
static constexpr float StepMinMaxGap
Definition VBAPLUT2D.h:98
static constexpr float StepMax
Definition VBAPLUT2D.h:97
static constexpr float StepMin
Definition VBAPLUT2D.h:96
static constexpr float StepWidth
Definition VBAPLUT2D.h:94
static constexpr uint16 Resolution
Definition VBAPLUT2D.h:93
Definition VBAPLUT3D.h:112
Definition MinimalVec2.h:29
static constexpr std::size_t size() noexcept
Get number of element of the vector.
Definition SIMD.h:231
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