Don't inline the utf8 converters
[openal-soft.git] / alc / hrtf.h
blobd133133a12b782d021537202dcc0662fffdfe8b9
1 #ifndef ALC_HRTF_H
2 #define ALC_HRTF_H
4 #include <array>
5 #include <cstddef>
6 #include <memory>
7 #include <string>
9 #include "AL/al.h"
11 #include "almalloc.h"
12 #include "alspan.h"
13 #include "ambidefs.h"
14 #include "atomic.h"
15 #include "vector.h"
17 struct HrtfHandle;
20 #define HRTF_HISTORY_BITS (6)
21 #define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
22 #define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
24 #define HRIR_BITS (7)
25 #define HRIR_LENGTH (1<<HRIR_BITS)
26 #define HRIR_MASK (HRIR_LENGTH-1)
29 struct HrtfEntry {
30 RefCount mRef;
32 ALuint sampleRate;
33 ALuint irSize;
35 struct Field {
36 ALfloat distance;
37 ALubyte evCount;
39 /* NOTE: Fields are stored *backwards*. field[0] is the farthest field, and
40 * field[fdCount-1] is the nearest.
42 ALuint fdCount;
43 const Field *field;
45 struct Elevation {
46 ALushort azCount;
47 ALushort irOffset;
49 Elevation *elev;
50 const ALfloat (*coeffs)[2];
51 const ALubyte (*delays)[2];
53 void IncRef();
54 void DecRef();
56 DEF_PLACE_NEWDEL()
59 struct EnumeratedHrtf {
60 std::string name;
62 HrtfHandle *hrtf;
66 using float2 = std::array<float,2>;
67 using HrirArray = std::array<float2,HRIR_LENGTH>;
69 struct HrtfState {
70 alignas(16) std::array<ALfloat,HRTF_HISTORY_LENGTH> History;
71 alignas(16) HrirArray Values;
74 struct HrtfFilter {
75 alignas(16) HrirArray Coeffs;
76 ALsizei Delay[2];
77 ALfloat Gain;
80 struct DirectHrtfState {
81 /* HRTF filter state for dry buffer content */
82 ALuint IrSize{0};
83 alignas(16) HrirArray Values{};
84 al::FlexArray<HrirArray,16> Coeffs;
86 DirectHrtfState(size_t numchans) : Coeffs{numchans} { }
88 static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
90 DEF_FAM_NEWDEL(DirectHrtfState, Coeffs)
93 struct AngularPoint {
94 ALfloat Elev;
95 ALfloat Azim;
99 al::vector<EnumeratedHrtf> EnumerateHrtf(const char *devname);
100 HrtfEntry *GetLoadedHrtf(HrtfHandle *handle);
102 void GetHrtfCoeffs(const HrtfEntry *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat distance,
103 ALfloat spread, HrirArray &coeffs, ALsizei (&delays)[2]);
106 * Produces HRTF filter coefficients for decoding B-Format, given a set of
107 * virtual speaker positions, a matching decoding matrix, and per-order high-
108 * frequency gains for the decoder. The calculated impulse responses are
109 * ordered and scaled according to the matrix input.
111 void BuildBFormatHrtf(const HrtfEntry *Hrtf, DirectHrtfState *state,
112 const al::span<const AngularPoint> AmbiPoints, const ALfloat (*AmbiMatrix)[MAX_AMBI_CHANNELS],
113 const ALfloat *AmbiOrderHFGain);
115 #endif /* ALC_HRTF_H */