Use kAudioObjectPropertyElementMaster on macOS for compatibility
[openal-soft.git] / common / polyphase_resampler.h
blob0795c80d897ee250b2196f1b74154bbc5e2e8fc6
1 #ifndef POLYPHASE_RESAMPLER_H
2 #define POLYPHASE_RESAMPLER_H
4 #include <vector>
6 #include "alspan.h"
9 using uint = unsigned int;
11 /* This is a polyphase sinc-filtered resampler. It is built for very high
12 * quality results, rather than real-time performance.
14 * Upsample Downsample
16 * p/q = 3/2 p/q = 3/5
18 * M-+-+-+-> M-+-+-+->
19 * -------------------+ ---------------------+
20 * p s * f f f f|f| | p s * f f f f f |
21 * | 0 * 0 0 0|0|0 | | 0 * 0 0 0 0|0| |
22 * v 0 * 0 0|0|0 0 | v 0 * 0 0 0|0|0 |
23 * s * f|f|f f f | s * f f|f|f f |
24 * 0 * |0|0 0 0 0 | 0 * 0|0|0 0 0 |
25 * --------+=+--------+ 0 * |0|0 0 0 0 |
26 * d . d .|d|. d . d ----------+=+--------+
27 * d . . . .|d|. . . .
28 * q->
29 * q-+-+-+->
31 * P_f(i,j) = q i mod p + pj
32 * P_s(i,j) = floor(q i / p) - j
33 * d[i=0..N-1] = sum_{j=0}^{floor((M - 1) / p)} {
34 * { f[P_f(i,j)] s[P_s(i,j)], P_f(i,j) < M
35 * { 0, P_f(i,j) >= M. }
38 struct PPhaseResampler {
39 void init(const uint srcRate, const uint dstRate);
40 void process(const al::span<const double> in, const al::span<double> out);
42 explicit operator bool() const noexcept { return !mF.empty(); }
44 private:
45 uint mP{}, mQ{}, mM{}, mL{};
46 std::vector<double> mF;
49 #endif /* POLYPHASE_RESAMPLER_H */