diff options
author | Sven Gothel <[email protected]> | 2019-04-07 23:39:04 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-04-07 23:39:04 +0200 |
commit | 73233ce69919fc19c53ce8663c5b8cc05227f07e (patch) | |
tree | f2b6ccc1a14d7c387f33398a44ea4511d7ecb212 /Alc/hrtf.h | |
parent | 8efa4c7ba5ee8eb399d31a9884e45f743d4625ad (diff) | |
parent | 99a55c445211fea77af6ab61cbc6a6ec4fbdc9b9 (diff) |
Merge branch 'v1.19' of git://repo.or.cz/openal-soft into v1.19v1.19
Diffstat (limited to 'Alc/hrtf.h')
-rw-r--r-- | Alc/hrtf.h | 84 |
1 files changed, 64 insertions, 20 deletions
@@ -4,37 +4,81 @@ #include "AL/al.h" #include "AL/alc.h" +#include "alMain.h" #include "alstring.h" +#include "atomic.h" -enum DevFmtChannels; -struct Hrtf; - -typedef struct HrtfEntry { - al_string name; - al_string filename; - - const struct Hrtf *hrtf; -} HrtfEntry; -TYPEDEF_VECTOR(HrtfEntry, vector_HrtfEntry) +#define HRTF_HISTORY_BITS (6) +#define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS) +#define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1) #define HRIR_BITS (7) #define HRIR_LENGTH (1<<HRIR_BITS) #define HRIR_MASK (HRIR_LENGTH-1) -#define HRTFDELAY_BITS (20) -#define HRTFDELAY_FRACONE (1<<HRTFDELAY_BITS) -#define HRTFDELAY_MASK (HRTFDELAY_FRACONE-1) + + +struct HrtfEntry; + +struct Hrtf { + RefCount ref; + + ALuint sampleRate; + ALsizei irSize; + + ALfloat distance; + ALubyte evCount; + + const ALubyte *azCount; + const ALushort *evOffset; + const ALfloat (*coeffs)[2]; + const ALubyte (*delays)[2]; +}; + + +typedef struct HrtfState { + alignas(16) ALfloat History[HRTF_HISTORY_LENGTH]; + alignas(16) ALfloat Values[HRIR_LENGTH][2]; +} HrtfState; + +typedef struct HrtfParams { + alignas(16) ALfloat Coeffs[HRIR_LENGTH][2]; + ALsizei Delay[2]; + ALfloat Gain; +} HrtfParams; + +typedef struct DirectHrtfState { + /* HRTF filter state for dry buffer content */ + ALsizei Offset; + ALsizei IrSize; + struct { + alignas(16) ALfloat Values[HRIR_LENGTH][2]; + alignas(16) ALfloat Coeffs[HRIR_LENGTH][2]; + } Chan[]; +} DirectHrtfState; + +struct AngularPoint { + ALfloat Elev; + ALfloat Azim; +}; + void FreeHrtfs(void); -vector_HrtfEntry EnumerateHrtf(const_al_string devname); -void FreeHrtfList(vector_HrtfEntry *list); +vector_EnumeratedHrtf EnumerateHrtf(const_al_string devname); +void FreeHrtfList(vector_EnumeratedHrtf *list); +struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry); +void Hrtf_IncRef(struct Hrtf *hrtf); +void Hrtf_DecRef(struct Hrtf *hrtf); -ALuint GetHrtfSampleRate(const struct Hrtf *Hrtf); -ALuint GetHrtfIrSize(const struct Hrtf *Hrtf); +void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*coeffs)[2], ALsizei *delays); -void GetLerpedHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat dirfact, ALfloat gain, ALfloat (*coeffs)[2], ALuint *delays); -ALuint GetMovingHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat dirfact, ALfloat gain, ALfloat delta, ALint counter, ALfloat (*coeffs)[2], ALuint *delays, ALfloat (*coeffStep)[2], ALint *delayStep); -void GetBFormatHrtfCoeffs(const struct Hrtf *Hrtf, const ALuint num_chans, ALfloat (**coeffs_list)[2], ALuint **delay_list); +/** + * Produces HRTF filter coefficients for decoding B-Format, given a set of + * virtual speaker positions, a matching decoding matrix, and per-order high- + * frequency gains for the decoder. The calculated impulse responses are + * ordered and scaled according to the matrix input. + */ +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); #endif /* ALC_HRTF_H */ |