Free Electron
hrtf.h
1 #ifndef ALC_HRTF_H
2 #define ALC_HRTF_H
3 
4 #include "AL/al.h"
5 #include "AL/alc.h"
6 
7 #include "alMain.h"
8 #include "alstring.h"
9 #include "atomic.h"
10 
11 
12 #define HRTF_HISTORY_BITS (6)
13 #define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
14 #define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
15 
16 #define HRIR_BITS (7)
17 #define HRIR_LENGTH (1<<HRIR_BITS)
18 #define HRIR_MASK (HRIR_LENGTH-1)
19 
20 
21 struct HrtfEntry;
22 
23 struct Hrtf {
24  RefCount ref;
25 
26  ALuint sampleRate;
27  ALsizei irSize;
28 
29  ALfloat distance;
30  ALubyte evCount;
31 
32  const ALubyte *azCount;
33  const ALushort *evOffset;
34  const ALfloat (*coeffs)[2];
35  const ALubyte (*delays)[2];
36 };
37 
38 
39 typedef struct HrtfState {
40  alignas(16) ALfloat History[HRTF_HISTORY_LENGTH];
41  alignas(16) ALfloat Values[HRIR_LENGTH][2];
42 } HrtfState;
43 
44 typedef struct HrtfParams {
45  alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
46  ALsizei Delay[2];
47  ALfloat Gain;
48 } HrtfParams;
49 
50 typedef struct DirectHrtfState {
51  /* HRTF filter state for dry buffer content */
52  ALsizei Offset;
53  ALsizei IrSize;
54  struct {
55  alignas(16) ALfloat Values[HRIR_LENGTH][2];
56  alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
57  } Chan[];
58 } DirectHrtfState;
59 
60 struct AngularPoint {
61  ALfloat Elev;
62  ALfloat Azim;
63 };
64 
65 
66 void FreeHrtfs(void);
67 
68 vector_EnumeratedHrtf EnumerateHrtf(const_al_string devname);
69 void FreeHrtfList(vector_EnumeratedHrtf *list);
70 struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry);
71 void Hrtf_IncRef(struct Hrtf *hrtf);
72 void Hrtf_DecRef(struct Hrtf *hrtf);
73 
74 void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*coeffs)[2], ALsizei *delays);
75 
76 /**
77  * Produces HRTF filter coefficients for decoding B-Format, given a set of
78  * virtual speaker positions, a matching decoding matrix, and per-order high-
79  * frequency gains for the decoder. The calculated impulse responses are
80  * ordered and scaled according to the matrix input.
81  */
82 void BuildBFormatHrtf(const struct Hrtf *Hrtf, DirectHrtfState *state, ALsizei NumChannels, const struct AngularPoint *AmbiPoints, const ALfloat (*restrict AmbiMatrix)[MAX_AMBI_COEFFS], ALsizei AmbiCount, const ALfloat *restrict AmbiOrderHFGain);
83 
84 #endif /* ALC_HRTF_H */