8 #include "polyphase_resampler.h"
11 // The maximum path length used when processing filenames.
12 #define MAX_PATH_LEN (256)
14 // The limit to the number of 'distances' listed in the data set definition.
15 // Must be less than 256
16 #define MAX_FD_COUNT (16)
18 // The limits to the number of 'elevations' listed in the data set definition.
19 // Must be less than 256.
20 #define MIN_EV_COUNT (5)
21 #define MAX_EV_COUNT (181)
23 // The limits for each of the 'azimuths' listed in the data set definition.
24 // Must be less than 256.
25 #define MIN_AZ_COUNT (1)
26 #define MAX_AZ_COUNT (255)
28 // The limits for the 'distance' from source to listener for each field in
29 // the definition file.
30 #define MIN_DISTANCE (0.05)
31 #define MAX_DISTANCE (2.50)
33 // The limits for the sample 'rate' metric in the data set definition and for
35 #define MIN_RATE (32000)
36 #define MAX_RATE (96000)
38 // The limits for the HRIR 'points' metric in the data set definition.
39 #define MIN_POINTS (16)
40 #define MAX_POINTS (8192)
43 using uint
= unsigned int;
45 /* Complex double type. */
46 using complex_d
= std::complex<double>;
49 enum ChannelModeT
: bool {
50 CM_AllowStereo
= false,
54 // Sample and channel type enum values.
60 // Certain iterations rely on these integer enum values.
67 // Structured HRIR storage for stereo azimuth pairs, elevations, and fields.
71 double mDelays
[2]{0.0, 0.0};
72 double *mIrs
[2]{nullptr, nullptr};
76 double mElevation
{0.0};
78 HrirAzT
*mAzs
{nullptr};
82 double mDistance
{0.0};
85 HrirEvT
*mEvs
{nullptr};
88 // The HRIR metrics and data set used when loading, processing, and storing
89 // the resulting HRTF.
92 SampleTypeT mSampleType
{ST_S24
};
93 ChannelTypeT mChannelType
{CT_NONE
};
100 std::vector
<double> mHrirsBase
;
101 std::vector
<HrirEvT
> mEvsBase
;
102 std::vector
<HrirAzT
> mAzsBase
;
104 std::vector
<HrirFdT
> mFds
;
106 /* GCC warns when it tries to inline this. */
111 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
);
112 void MagnitudeResponse(const uint n
, const complex_d
*in
, double *out
);
114 // Performs a forward FFT.
115 inline void FftForward(const uint n
, complex_d
*inout
)
116 { forward_fft(al::as_span(inout
, n
)); }
118 // Performs an inverse FFT.
119 inline void FftInverse(const uint n
, complex_d
*inout
)
121 inverse_fft(al::as_span(inout
, n
));
123 for(uint i
{0};i
< n
;i
++)
127 // Performs linear interpolation.
128 inline double Lerp(const double a
, const double b
, const double f
)
129 { return a
+ f
* (b
- a
); }
131 #endif /* MAKEMHR_H */