]> git.tdb.fi Git - ext/openal.git/blob - core/hrtf.h
Tweak some types to work around an MSVC compile error
[ext/openal.git] / core / hrtf.h
1 #ifndef CORE_HRTF_H
2 #define CORE_HRTF_H
3
4 #include <array>
5 #include <cstddef>
6 #include <memory>
7 #include <string>
8
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"
18
19
20 struct HrtfStore {
21     RefCount mRef;
22
23     uint mSampleRate : 24;
24     uint mIrSize : 8;
25
26     struct Field {
27         float distance;
28         ubyte evCount;
29     };
30     /* NOTE: Fields are stored *backwards*. field[0] is the farthest field, and
31      * field[fdCount-1] is the nearest.
32      */
33     al::span<const Field> mFields;
34
35     struct Elevation {
36         ushort azCount;
37         ushort irOffset;
38     };
39     Elevation *mElev;
40     const HrirArray *mCoeffs;
41     const ubyte2 *mDelays;
42
43     void getCoeffs(float elevation, float azimuth, float distance, float spread, HrirArray &coeffs,
44         const al::span<uint,2> delays);
45
46     void add_ref();
47     void dec_ref();
48
49     DEF_PLACE_NEWDEL()
50 };
51 using HrtfStorePtr = al::intrusive_ptr<HrtfStore>;
52
53
54 struct EvRadians { float value; };
55 struct AzRadians { float value; };
56 struct AngularPoint {
57     EvRadians Elev;
58     AzRadians Azim;
59 };
60
61
62 struct DirectHrtfState {
63     std::array<float,BufferLineSize> mTemp;
64
65     /* HRTF filter state for dry buffer content */
66     uint mIrSize{0};
67     al::FlexArray<HrtfChannelState> mChannels;
68
69     DirectHrtfState(size_t numchans) : mChannels{numchans} { }
70     /**
71      * Produces HRTF filter coefficients for decoding B-Format, given a set of
72      * virtual speaker positions, a matching decoding matrix, and per-order
73      * high-frequency gains for the decoder. The calculated impulse responses
74      * are ordered and scaled according to the matrix input.
75      */
76     void build(const HrtfStore *Hrtf, const uint irSize, const bool perHrirMin,
77         const al::span<const AngularPoint> AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels],
78         const float XOverFreq, const al::span<const float,MaxAmbiOrder+1> AmbiOrderHFGain);
79
80     static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
81
82     DEF_FAM_NEWDEL(DirectHrtfState, mChannels)
83 };
84
85
86 al::vector<std::string> EnumerateHrtf(al::optional<std::string> pathopt);
87 HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate);
88
89 #endif /* CORE_HRTF_H */