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.

38 lines
783B

  1. #pragma once
  2. namespace rack {
  3. /** Perform a direct convolution
  4. x[-len + 1] to x[0] must be defined
  5. */
  6. inline float convolve(const float *x, const float *kernel, int len) {
  7. float y = 0.0;
  8. for (int i = 0; i < len; i++) {
  9. y += x[-i] * kernel[i];
  10. }
  11. return y;
  12. }
  13. inline void blackmanHarrisWindow(float *x, int n) {
  14. const float a0 = 0.35875;
  15. const float a1 = 0.48829;
  16. const float a2 = 0.14128;
  17. const float a3 = 0.01168;
  18. for (int i = 0; i < n; i++) {
  19. x[i] *= a0
  20. - a1 * cosf(2 * M_PI * i / (n - 1))
  21. + a2 * cosf(4 * M_PI * i / (n - 1))
  22. - a3 * cosf(6 * M_PI * i / (n - 1));
  23. }
  24. }
  25. inline void boxcarFIR(float *x, int n, float cutoff) {
  26. for (int i = 0; i < n; i++) {
  27. float t = (float)i / (n - 1) * 2.0 - 1.0;
  28. x[i] = sincf(t * n * cutoff);
  29. }
  30. }
  31. } // namespace rack