Limit convolution processing to the output ambisonic order
[openal-soft.git] / utils / makemhr / makemhr.h
blob89607cc03ef521edc16219d20ea752daf526f4f6
1 #ifndef MAKEMHR_H
2 #define MAKEMHR_H
4 #include <vector>
5 #include <complex>
7 #include "polyphase_resampler.h"
10 // The maximum path length used when processing filenames.
11 #define MAX_PATH_LEN (256)
13 // The limit to the number of 'distances' listed in the data set definition.
14 // Must be less than 256
15 #define MAX_FD_COUNT (16)
17 // The limits to the number of 'elevations' listed in the data set definition.
18 // Must be less than 256.
19 #define MIN_EV_COUNT (5)
20 #define MAX_EV_COUNT (181)
22 // The limits for each of the 'azimuths' listed in the data set definition.
23 // Must be less than 256.
24 #define MIN_AZ_COUNT (1)
25 #define MAX_AZ_COUNT (255)
27 // The limits for the 'distance' from source to listener for each field in
28 // the definition file.
29 #define MIN_DISTANCE (0.05)
30 #define MAX_DISTANCE (2.50)
32 // The limits for the sample 'rate' metric in the data set definition and for
33 // resampling.
34 #define MIN_RATE (32000)
35 #define MAX_RATE (96000)
37 // The limits for the HRIR 'points' metric in the data set definition.
38 #define MIN_POINTS (16)
39 #define MAX_POINTS (8192)
42 using uint = unsigned int;
44 /* Complex double type. */
45 using complex_d = std::complex<double>;
48 enum ChannelModeT : bool {
49 CM_AllowStereo = false,
50 CM_ForceMono = true
53 // Sample and channel type enum values.
54 enum SampleTypeT {
55 ST_S16 = 0,
56 ST_S24 = 1
59 // Certain iterations rely on these integer enum values.
60 enum ChannelTypeT {
61 CT_NONE = -1,
62 CT_MONO = 0,
63 CT_STEREO = 1
66 // Structured HRIR storage for stereo azimuth pairs, elevations, and fields.
67 struct HrirAzT {
68 double mAzimuth{0.0};
69 uint mIndex{0u};
70 double mDelays[2]{0.0, 0.0};
71 double *mIrs[2]{nullptr, nullptr};
74 struct HrirEvT {
75 double mElevation{0.0};
76 uint mIrCount{0u};
77 uint mAzCount{0u};
78 HrirAzT *mAzs{nullptr};
81 struct HrirFdT {
82 double mDistance{0.0};
83 uint mIrCount{0u};
84 uint mEvCount{0u};
85 uint mEvStart{0u};
86 HrirEvT *mEvs{nullptr};
89 // The HRIR metrics and data set used when loading, processing, and storing
90 // the resulting HRTF.
91 struct HrirDataT {
92 uint mIrRate{0u};
93 SampleTypeT mSampleType{ST_S24};
94 ChannelTypeT mChannelType{CT_NONE};
95 uint mIrPoints{0u};
96 uint mFftSize{0u};
97 uint mIrSize{0u};
98 double mRadius{0.0};
99 uint mIrCount{0u};
100 uint mFdCount{0u};
102 std::vector<double> mHrirsBase;
103 std::vector<HrirEvT> mEvsBase;
104 std::vector<HrirAzT> mAzsBase;
106 std::vector<HrirFdT> mFds;
110 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);
111 void MagnitudeResponse(const uint n, const complex_d *in, double *out);
112 void FftForward(const uint n, complex_d *inout);
113 void FftInverse(const uint n, complex_d *inout);
116 // Performs linear interpolation.
117 inline double Lerp(const double a, const double b, const double f)
118 { return a + f * (b - a); }
120 #endif /* MAKEMHR_H */