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

125 lines
3.3 KiB

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