🛠️🐜 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. /* This is a polyphase sinc-filtered resampler. It is built for very high
  5. * quality results, rather than real-time performance.
  6. *
  7. * Upsample Downsample
  8. *
  9. * p/q = 3/2 p/q = 3/5
  10. *
  11. * M-+-+-+-> M-+-+-+->
  12. * -------------------+ ---------------------+
  13. * p s * f f f f|f| | p s * f f f f f |
  14. * | 0 * 0 0 0|0|0 | | 0 * 0 0 0 0|0| |
  15. * v 0 * 0 0|0|0 0 | v 0 * 0 0 0|0|0 |
  16. * s * f|f|f f f | s * f f|f|f f |
  17. * 0 * |0|0 0 0 0 | 0 * 0|0|0 0 0 |
  18. * --------+=+--------+ 0 * |0|0 0 0 0 |
  19. * d . d .|d|. d . d ----------+=+--------+
  20. * d . . . .|d|. . . .
  21. * q->
  22. * q-+-+-+->
  23. *
  24. * P_f(i,j) = q i mod p + pj
  25. * P_s(i,j) = floor(q i / p) - j
  26. * d[i=0..N-1] = sum_{j=0}^{floor((M - 1) / p)} {
  27. * { f[P_f(i,j)] s[P_s(i,j)], P_f(i,j) < M
  28. * { 0, P_f(i,j) >= M. }
  29. */
  30. struct PPhaseResampler {
  31. using uint = unsigned int;
  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 */