Simplify void_t
[openal-soft.git] / core / hrtf.h
blob0c8d2a49540fc2dba1c2e8c70d82e25fbf5c918e
1 #ifndef CORE_HRTF_H
2 #define CORE_HRTF_H
4 #include <array>
5 #include <cstddef>
6 #include <memory>
7 #include <string>
9 #include "almalloc.h"
10 #include "aloptional.h"
11 #include "alspan.h"
12 #include "atomic.h"
13 #include "ambidefs.h"
14 #include "bufferline.h"
15 #include "mixer/hrtfdefs.h"
16 #include "intrusive_ptr.h"
17 #include "vector.h"
20 struct HrtfStore {
21 RefCount mRef;
23 uint sampleRate;
24 uint irSize;
26 struct Field {
27 float distance;
28 ubyte evCount;
30 /* NOTE: Fields are stored *backwards*. field[0] is the farthest field, and
31 * field[fdCount-1] is the nearest.
33 uint fdCount;
34 const Field *field;
36 struct Elevation {
37 ushort azCount;
38 ushort irOffset;
40 Elevation *elev;
41 const HrirArray *coeffs;
42 const ubyte2 *delays;
44 void add_ref();
45 void dec_ref();
47 DEF_PLACE_NEWDEL()
49 using HrtfStorePtr = al::intrusive_ptr<HrtfStore>;
52 struct EvRadians { float value; };
53 struct AzRadians { float value; };
54 struct AngularPoint {
55 EvRadians Elev;
56 AzRadians Azim;
60 struct DirectHrtfState {
61 std::array<float,BufferLineSize> mTemp;
63 /* HRTF filter state for dry buffer content */
64 uint mIrSize{0};
65 al::FlexArray<HrtfChannelState> mChannels;
67 DirectHrtfState(size_t numchans) : mChannels{numchans} { }
68 /**
69 * Produces HRTF filter coefficients for decoding B-Format, given a set of
70 * virtual speaker positions, a matching decoding matrix, and per-order
71 * high-frequency gains for the decoder. The calculated impulse responses
72 * are ordered and scaled according to the matrix input.
74 void build(const HrtfStore *Hrtf, const uint irSize, const bool perHrirMin,
75 const al::span<const AngularPoint> AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels],
76 const float XOverFreq, const al::span<const float,MaxAmbiOrder+1> AmbiOrderHFGain);
78 static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
80 DEF_FAM_NEWDEL(DirectHrtfState, mChannels)
84 al::vector<std::string> EnumerateHrtf(al::optional<std::string> pathopt);
85 HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate);
87 void GetHrtfCoeffs(const HrtfStore *Hrtf, float elevation, float azimuth, float distance,
88 float spread, HrirArray &coeffs, const al::span<uint,2> delays);
90 #endif /* CORE_HRTF_H */