hrtf.h 2.2 KB

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