clang-tidy cleanups (#800)
[openal-soft.git] / common / polyphase_resampler.h
blob557485bb2f61834399b479a6517e13902e635474
1 #ifndef POLYPHASE_RESAMPLER_H
2 #define POLYPHASE_RESAMPLER_H
4 #include <vector>
7 using uint = unsigned int;
9 /* This is a polyphase sinc-filtered resampler. It is built for very high
10 * quality results, rather than real-time performance.
12 * Upsample Downsample
14 * p/q = 3/2 p/q = 3/5
16 * M-+-+-+-> M-+-+-+->
17 * -------------------+ ---------------------+
18 * p s * f f f f|f| | p s * f f f f f |
19 * | 0 * 0 0 0|0|0 | | 0 * 0 0 0 0|0| |
20 * v 0 * 0 0|0|0 0 | v 0 * 0 0 0|0|0 |
21 * s * f|f|f f f | s * f f|f|f f |
22 * 0 * |0|0 0 0 0 | 0 * 0|0|0 0 0 |
23 * --------+=+--------+ 0 * |0|0 0 0 0 |
24 * d . d .|d|. d . d ----------+=+--------+
25 * d . . . .|d|. . . .
26 * q->
27 * q-+-+-+->
29 * P_f(i,j) = q i mod p + pj
30 * P_s(i,j) = floor(q i / p) - j
31 * d[i=0..N-1] = sum_{j=0}^{floor((M - 1) / p)} {
32 * { f[P_f(i,j)] s[P_s(i,j)], P_f(i,j) < M
33 * { 0, P_f(i,j) >= M. }
36 struct PPhaseResampler {
37 void init(const uint srcRate, const uint dstRate);
38 void process(const uint inN, const double *in, const uint outN, double *out);
40 explicit operator bool() const noexcept { return !mF.empty(); }
42 private:
43 uint mP, mQ, mM, mL;
44 std::vector<double> mF;
47 #endif /* POLYPHASE_RESAMPLER_H */