🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.3 KiB

  1. #ifndef CORE_HRTF_H
  2. #define CORE_HRTF_H
  3. #include <array>
  4. #include <cstddef>
  5. #include <memory>
  6. #include <string>
  7. #include "almalloc.h"
  8. #include "aloptional.h"
  9. #include "alspan.h"
  10. #include "atomic.h"
  11. #include "ambidefs.h"
  12. #include "bufferline.h"
  13. #include "mixer/hrtfdefs.h"
  14. #include "intrusive_ptr.h"
  15. #include "vector.h"
  16. struct HrtfStore {
  17. RefCount mRef;
  18. uint sampleRate;
  19. uint irSize;
  20. struct Field {
  21. float distance;
  22. ubyte evCount;
  23. };
  24. /* NOTE: Fields are stored *backwards*. field[0] is the farthest field, and
  25. * field[fdCount-1] is the nearest.
  26. */
  27. uint fdCount;
  28. const Field *field;
  29. struct Elevation {
  30. ushort azCount;
  31. ushort irOffset;
  32. };
  33. Elevation *elev;
  34. const HrirArray *coeffs;
  35. const ubyte2 *delays;
  36. void add_ref();
  37. void release();
  38. DEF_PLACE_NEWDEL()
  39. };
  40. using HrtfStorePtr = al::intrusive_ptr<HrtfStore>;
  41. struct EvRadians { float value; };
  42. struct AzRadians { float value; };
  43. struct AngularPoint {
  44. EvRadians Elev;
  45. AzRadians Azim;
  46. };
  47. struct DirectHrtfState {
  48. std::array<float,BufferLineSize> mTemp;
  49. /* HRTF filter state for dry buffer content */
  50. uint mIrSize{0};
  51. al::FlexArray<HrtfChannelState> mChannels;
  52. DirectHrtfState(size_t numchans) : mChannels{numchans} { }
  53. /**
  54. * Produces HRTF filter coefficients for decoding B-Format, given a set of
  55. * virtual speaker positions, a matching decoding matrix, and per-order
  56. * high-frequency gains for the decoder. The calculated impulse responses
  57. * are ordered and scaled according to the matrix input.
  58. */
  59. void build(const HrtfStore *Hrtf, const uint irSize,
  60. const al::span<const AngularPoint> AmbiPoints, const float (*AmbiMatrix)[MaxAmbiChannels],
  61. const float XOverFreq, const al::span<const float,MaxAmbiOrder+1> AmbiOrderHFGain);
  62. static std::unique_ptr<DirectHrtfState> Create(size_t num_chans);
  63. DEF_FAM_NEWDEL(DirectHrtfState, mChannels)
  64. };
  65. al::vector<std::string> EnumerateHrtf(al::optional<std::string> pathopt);
  66. HrtfStorePtr GetLoadedHrtf(const std::string &name, const uint devrate);
  67. void GetHrtfCoeffs(const HrtfStore *Hrtf, float elevation, float azimuth, float distance,
  68. float spread, HrirArray &coeffs, const al::span<uint,2> delays);
  69. #endif /* CORE_HRTF_H */