15 #include "bufferline.h"
16 #include "flexarray.h"
17 #include "intrusive_ptr.h"
18 #include "mixer/hrtfdefs.h"
21 struct alignas(16) HrtfStore
{
22 std::atomic
<uint
> mRef
;
24 uint mSampleRate
: 24;
31 /* NOTE: Fields are stored *backwards*. field[0] is the farthest field, and
32 * field[fdCount-1] is the nearest.
34 al::span
<const Field
> mFields
;
40 al::span
<Elevation
> mElev
;
41 al::span
<const HrirArray
> mCoeffs
;
42 al::span
<const ubyte2
> mDelays
;
44 void getCoeffs(float elevation
, float azimuth
, float distance
, float spread
,
45 const HrirSpan coeffs
, const al::span
<uint
,2> delays
) const;
50 void *operator new(size_t) = delete;
51 void *operator new[](size_t) = delete;
52 void operator delete[](void*) noexcept
= delete;
54 void operator delete(gsl::owner
<void*> block
, void*) noexcept
55 { ::operator delete[](block
, std::align_val_t
{alignof(HrtfStore
)}); }
56 void operator delete(gsl::owner
<void*> block
) noexcept
57 { ::operator delete[](block
, std::align_val_t
{alignof(HrtfStore
)}); }
59 using HrtfStorePtr
= al::intrusive_ptr
<HrtfStore
>;
62 struct EvRadians
{ float value
; };
63 struct AzRadians
{ float value
; };
70 struct DirectHrtfState
{
71 std::array
<float,BufferLineSize
> mTemp
{};
73 /* HRTF filter state for dry buffer content */
75 al::FlexArray
<HrtfChannelState
> mChannels
;
77 DirectHrtfState(size_t numchans
) : mChannels
{numchans
} { }
79 * Produces HRTF filter coefficients for decoding B-Format, given a set of
80 * virtual speaker positions, a matching decoding matrix, and per-order
81 * high-frequency gains for the decoder. The calculated impulse responses
82 * are ordered and scaled according to the matrix input.
84 void build(const HrtfStore
*Hrtf
, const uint irSize
, const bool perHrirMin
,
85 const al::span
<const AngularPoint
> AmbiPoints
,
86 const al::span
<const std::array
<float,MaxAmbiChannels
>> AmbiMatrix
,
87 const float XOverFreq
, const al::span
<const float,MaxAmbiOrder
+1> AmbiOrderHFGain
);
89 static std::unique_ptr
<DirectHrtfState
> Create(size_t num_chans
);
91 DEF_FAM_NEWDEL(DirectHrtfState
, mChannels
)
95 std::vector
<std::string
> EnumerateHrtf(std::optional
<std::string
> pathopt
);
96 HrtfStorePtr
GetLoadedHrtf(const std::string_view name
, const uint devrate
);
98 #endif /* CORE_HRTF_H */