hrtf.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /* The maximum number of virtual speakers used to generate HRTF coefficients
  9. * for decoding B-Format.
  10. */
  11. #define HRTF_AMBI_MAX_CHANNELS 18
  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. #define HRIR_BITS (7)
  16. #define HRIR_LENGTH (1<<HRIR_BITS)
  17. #define HRIR_MASK (HRIR_LENGTH-1)
  18. struct HrtfEntry;
  19. struct Hrtf {
  20. RefCount ref;
  21. ALuint sampleRate;
  22. ALsizei irSize;
  23. ALfloat distance;
  24. ALubyte evCount;
  25. const ALubyte *azCount;
  26. const ALushort *evOffset;
  27. const ALfloat (*coeffs)[2];
  28. const ALubyte (*delays)[2];
  29. };
  30. typedef struct HrtfState {
  31. alignas(16) ALfloat History[HRTF_HISTORY_LENGTH];
  32. alignas(16) ALfloat Values[HRIR_LENGTH][2];
  33. } HrtfState;
  34. typedef struct HrtfParams {
  35. alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
  36. ALsizei Delay[2];
  37. ALfloat Gain;
  38. } HrtfParams;
  39. typedef struct DirectHrtfState {
  40. /* HRTF filter state for dry buffer content */
  41. ALsizei Offset;
  42. ALsizei IrSize;
  43. struct {
  44. alignas(16) ALfloat Values[HRIR_LENGTH][2];
  45. alignas(16) ALfloat Coeffs[HRIR_LENGTH][2];
  46. } Chan[];
  47. } DirectHrtfState;
  48. struct AngularPoint {
  49. ALfloat Elev;
  50. ALfloat Azim;
  51. };
  52. void FreeHrtfs(void);
  53. vector_EnumeratedHrtf EnumerateHrtf(const_al_string devname);
  54. void FreeHrtfList(vector_EnumeratedHrtf *list);
  55. struct Hrtf *GetLoadedHrtf(struct HrtfEntry *entry);
  56. void Hrtf_IncRef(struct Hrtf *hrtf);
  57. void Hrtf_DecRef(struct Hrtf *hrtf);
  58. void GetHrtfCoeffs(const struct Hrtf *Hrtf, ALfloat elevation, ALfloat azimuth, ALfloat spread, ALfloat (*coeffs)[2], ALsizei *delays);
  59. /**
  60. * Produces HRTF filter coefficients for decoding B-Format, given a set of
  61. * virtual speaker positions and HF/LF matrices for decoding to them. The
  62. * returned coefficients are ordered and scaled according to the matrices.
  63. */
  64. 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);
  65. #endif /* ALC_HRTF_H */