Separate ALCdevice from the implementation
[openal-soft.git] / core / hrtf.h
blob91c9244387bedc109ff4d0e295f9d823bbcd20b9
1 #ifndef CORE_HRTF_H
2 #define CORE_HRTF_H
4 #include <array>
5 #include <cstddef>
6 #include <memory>
7 #include <optional>
8 #include <string>
9 #include <string_view>
10 #include <vector>
12 #include "almalloc.h"
13 #include "alspan.h"
14 #include "ambidefs.h"
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;
25 uint mIrSize : 8;
27 struct Field {
28 float distance;
29 ubyte evCount;
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;
36 struct Elevation {
37 ushort azCount;
38 ushort irOffset;
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;
47 void add_ref();
48 void dec_ref();
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; };
64 struct AngularPoint {
65 EvRadians Elev;
66 AzRadians Azim;
70 struct DirectHrtfState {
71 std::array<float,BufferLineSize> mTemp{};
73 /* HRTF filter state for dry buffer content */
74 uint mIrSize{0};
75 al::FlexArray<HrtfChannelState> mChannels;
77 DirectHrtfState(size_t numchans) : mChannels{numchans} { }
78 /**
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 */