🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.5 KiB

  1. #ifndef POLYPHASE_RESAMPLER_H
  2. #define POLYPHASE_RESAMPLER_H
  3. #include <vector>
  4. using uint = unsigned int;
  5. /* This is a polyphase sinc-filtered resampler. It is built for very high
  6. * quality results, rather than real-time performance.
  7. *
  8. * Upsample Downsample
  9. *
  10. * p/q = 3/2 p/q = 3/5
  11. *
  12. * M-+-+-+-> M-+-+-+->
  13. * -------------------+ ---------------------+
  14. * p s * f f f f|f| | p s * f f f f f |
  15. * | 0 * 0 0 0|0|0 | | 0 * 0 0 0 0|0| |
  16. * v 0 * 0 0|0|0 0 | v 0 * 0 0 0|0|0 |
  17. * s * f|f|f f f | s * f f|f|f f |
  18. * 0 * |0|0 0 0 0 | 0 * 0|0|0 0 0 |
  19. * --------+=+--------+ 0 * |0|0 0 0 0 |
  20. * d . d .|d|. d . d ----------+=+--------+
  21. * d . . . .|d|. . . .
  22. * q->
  23. * q-+-+-+->
  24. *
  25. * P_f(i,j) = q i mod p + pj
  26. * P_s(i,j) = floor(q i / p) - j
  27. * d[i=0..N-1] = sum_{j=0}^{floor((M - 1) / p)} {
  28. * { f[P_f(i,j)] s[P_s(i,j)], P_f(i,j) < M
  29. * { 0, P_f(i,j) >= M. }
  30. */
  31. struct PPhaseResampler {
  32. void init(const uint srcRate, const uint dstRate);
  33. void process(const uint inN, const double *in, const uint outN, double *out);
  34. private:
  35. uint mP, mQ, mM, mL;
  36. std::vector<double> mF;
  37. };
  38. #endif /* POLYPHASE_RESAMPLER_H */