]> git.tdb.fi Git - ext/openal.git/blob - common/polyphase_resampler.h
Tweak some types to work around an MSVC compile error
[ext/openal.git] / common / polyphase_resampler.h
1 #ifndef POLYPHASE_RESAMPLER_H
2 #define POLYPHASE_RESAMPLER_H
3
4 #include <vector>
5
6
7 using uint = unsigned int;
8
9 /* This is a polyphase sinc-filtered resampler. It is built for very high
10  * quality results, rather than real-time performance.
11  *
12  *              Upsample                      Downsample
13  *
14  *              p/q = 3/2                     p/q = 3/5
15  *
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-+-+-+->
28  *
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. }
34  */
35
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);
39
40     explicit operator bool() const noexcept { return !mF.empty(); }
41
42 private:
43     uint mP, mQ, mM, mL;
44     std::vector<double> mF;
45 };
46
47 #endif /* POLYPHASE_RESAMPLER_H */