Use a proper struct for specifying angular points
[openal-soft.git] / Alc / hrtf.h
blobcb6dfddc8b5512b80af92b2c391d63f23accc3df
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 /* The maximum number of virtual speakers used to generate HRTF coefficients
13 * for decoding B-Format.
15 #define HRTF_AMBI_MAX_CHANNELS 18
18 #define HRTF_HISTORY_BITS (6)
19 #define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS)
20 #define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1)
22 #define HRIR_BITS (7)
23 #define HRIR_LENGTH (1<<HRIR_BITS)
24 #define HRIR_MASK (HRIR_LENGTH-1)
27 struct HrtfEntry;
29 struct Hrtf {
30 RefCount ref;
32 ALuint sampleRate;
33 ALsizei irSize;
35 ALfloat distance;
36 ALubyte evCount;
38 const ALubyte *azCount;
39 const ALushort *evOffset;
40 const ALfloat (*coeffs)[2];
41 const ALubyte (*delays)[2];
45 typedef struct HrtfState {
46 alignas(16) ALfloat History[HRTF_HISTORY_LENGTH];
47 alignas(16) ALfloat Values[HRIR_LENGTH][2];
48 } HrtfState;
50 typedef struct HrtfParams {
51 alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
52 ALsizei Delay[2];
53 ALfloat Gain;
54 } HrtfParams;
56 typedef struct DirectHrtfState {
57 /* HRTF filter state for dry buffer content */
58 ALsizei Offset;
59 ALsizei IrSize;
60 struct {
61 alignas(16) ALfloat Values[HRIR_LENGTH][2];
62 alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
63 } Chan[];
64 } DirectHrtfState;
66 struct AngularPoint {
67 ALfloat Elev;
68 ALfloat Azim;
72 void FreeHrtfs(void);
74 vector_EnumeratedHrtf EnumerateHrtf(const_al_string devname);
75 void FreeHrtfList(vector_EnumeratedHrtf *list);
76 struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry);
77 void Hrtf_IncRef(struct Hrtf *hrtf);
78 void Hrtf_DecRef(struct Hrtf *hrtf);
80 void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*coeffs)[2], ALsizei *delays);
82 /**
83 * Produces HRTF filter coefficients for decoding B-Format, given a set of
84 * virtual speaker positions and HF/LF matrices for decoding to them. The
85 * returned coefficients are ordered and scaled according to the matrices.
87 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);
89 #endif /* ALC_HRTF_H */