🛠️🐜 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.

120 lines
3.1 KiB

  1. #ifndef MAKEMHR_H
  2. #define MAKEMHR_H
  3. #include <vector>
  4. #include <complex>
  5. #include "polyphase_resampler.h"
  6. // The maximum path length used when processing filenames.
  7. #define MAX_PATH_LEN (256)
  8. // The limit to the number of 'distances' listed in the data set definition.
  9. // Must be less than 256
  10. #define MAX_FD_COUNT (16)
  11. // The limits to the number of 'elevations' listed in the data set definition.
  12. // Must be less than 256.
  13. #define MIN_EV_COUNT (5)
  14. #define MAX_EV_COUNT (181)
  15. // The limits for each of the 'azimuths' listed in the data set definition.
  16. // Must be less than 256.
  17. #define MIN_AZ_COUNT (1)
  18. #define MAX_AZ_COUNT (255)
  19. // The limits for the 'distance' from source to listener for each field in
  20. // the definition file.
  21. #define MIN_DISTANCE (0.05)
  22. #define MAX_DISTANCE (2.50)
  23. // The limits for the sample 'rate' metric in the data set definition and for
  24. // resampling.
  25. #define MIN_RATE (32000)
  26. #define MAX_RATE (96000)
  27. // The limits for the HRIR 'points' metric in the data set definition.
  28. #define MIN_POINTS (16)
  29. #define MAX_POINTS (8192)
  30. using uint = unsigned int;
  31. /* Complex double type. */
  32. using complex_d = std::complex<double>;
  33. enum ChannelModeT : bool {
  34. CM_AllowStereo = false,
  35. CM_ForceMono = true
  36. };
  37. // Sample and channel type enum values.
  38. enum SampleTypeT {
  39. ST_S16 = 0,
  40. ST_S24 = 1
  41. };
  42. // Certain iterations rely on these integer enum values.
  43. enum ChannelTypeT {
  44. CT_NONE = -1,
  45. CT_MONO = 0,
  46. CT_STEREO = 1
  47. };
  48. // Structured HRIR storage for stereo azimuth pairs, elevations, and fields.
  49. struct HrirAzT {
  50. double mAzimuth{0.0};
  51. uint mIndex{0u};
  52. double mDelays[2]{0.0, 0.0};
  53. double *mIrs[2]{nullptr, nullptr};
  54. };
  55. struct HrirEvT {
  56. double mElevation{0.0};
  57. uint mIrCount{0u};
  58. uint mAzCount{0u};
  59. HrirAzT *mAzs{nullptr};
  60. };
  61. struct HrirFdT {
  62. double mDistance{0.0};
  63. uint mIrCount{0u};
  64. uint mEvCount{0u};
  65. uint mEvStart{0u};
  66. HrirEvT *mEvs{nullptr};
  67. };
  68. // The HRIR metrics and data set used when loading, processing, and storing
  69. // the resulting HRTF.
  70. struct HrirDataT {
  71. uint mIrRate{0u};
  72. SampleTypeT mSampleType{ST_S24};
  73. ChannelTypeT mChannelType{CT_NONE};
  74. uint mIrPoints{0u};
  75. uint mFftSize{0u};
  76. uint mIrSize{0u};
  77. double mRadius{0.0};
  78. uint mIrCount{0u};
  79. uint mFdCount{0u};
  80. std::vector<double> mHrirsBase;
  81. std::vector<HrirEvT> mEvsBase;
  82. std::vector<HrirAzT> mAzsBase;
  83. std::vector<HrirFdT> mFds;
  84. };
  85. int PrepareHrirData(const uint fdCount, const double (&distances)[MAX_FD_COUNT], const uint (&evCounts)[MAX_FD_COUNT], const uint azCounts[MAX_FD_COUNT * MAX_EV_COUNT], HrirDataT *hData);
  86. void MagnitudeResponse(const uint n, const complex_d *in, double *out);
  87. void FftForward(const uint n, complex_d *inout);
  88. void FftInverse(const uint n, complex_d *inout);
  89. // Performs linear interpolation.
  90. inline double Lerp(const double a, const double b, const double f)
  91. { return a + f * (b - a); }
  92. #endif /* MAKEMHR_H */