Merge pull request #204 from jhasse/android-byte-order
[openal-soft.git] / Alc / hrtf.h
blobab68929b4aa31e82bee21e666458b3faca14864e
1 #ifndef ALC_HRTF_H
2 #define ALC_HRTF_H
4 #include "AL/al.h"
5 #include "AL/alc.h"
7 #include "alMain.h"
8 #include "alstring.h"
9 #include "atomic.h"
12 #define HRTF_HISTORY_BITS (6)
13 #define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
14 #define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
16 #define HRIR_BITS (7)
17 #define HRIR_LENGTH (1<<HRIR_BITS)
18 #define HRIR_MASK (HRIR_LENGTH-1)
21 struct HrtfEntry;
23 struct Hrtf {
24 RefCount ref;
26 ALuint sampleRate;
27 ALsizei irSize;
29 ALfloat distance;
30 ALubyte evCount;
32 const ALubyte *azCount;
33 const ALushort *evOffset;
34 const ALfloat (*coeffs)[2];
35 const ALubyte (*delays)[2];
39 typedef struct HrtfState {
40 alignas(16) ALfloat History[HRTF_HISTORY_LENGTH];
41 alignas(16) ALfloat Values[HRIR_LENGTH][2];
42 } HrtfState;
44 typedef struct HrtfParams {
45 alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
46 ALsizei Delay[2];
47 ALfloat Gain;
48 } HrtfParams;
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;
60 struct AngularPoint {
61 ALfloat Elev;
62 ALfloat Azim;
66 void FreeHrtfs(void);
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);
74 void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*coeffs)[2], ALsizei *delays);
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.
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);
84 #endif /* ALC_HRTF_H */