Audio plugin host https://kx.studio/carla
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.

62 lines
1.9KB

  1. /*
  2. ZynAddSubFX - a software synthesizer
  3. FFTwrapper.h - A wrapper for Fast Fourier Transforms
  4. Copyright (C) 2002-2005 Nasca Octavian Paul
  5. Author: Nasca Octavian Paul
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10. */
  11. #ifndef FFT_WRAPPER_H
  12. #define FFT_WRAPPER_H
  13. #include <fftw3.h>
  14. #include <complex>
  15. #include "../globals.h"
  16. /**A wrapper for the FFTW library (Fast Fourier Transforms)*/
  17. class FFTwrapper
  18. {
  19. public:
  20. /**Constructor
  21. * @param fftsize The size of samples to be fed to fftw*/
  22. FFTwrapper(int fftsize_);
  23. /**Destructor*/
  24. ~FFTwrapper();
  25. /**Convert Samples to Frequencies using Fourier Transform
  26. * @param smps Pointer to Samples to be converted; has length fftsize_
  27. * @param freqs Structure FFTFREQS which stores the frequencies*/
  28. void smps2freqs(const float *smps, fft_t *freqs);
  29. void freqs2smps(const fft_t *freqs, float *smps);
  30. private:
  31. int fftsize;
  32. fftw_real *time;
  33. fftw_complex *fft;
  34. fftw_plan planfftw, planfftw_inv;
  35. };
  36. /*
  37. * The "std::polar" template has no clear definition for the range of
  38. * the input parameters, and some C++ standard library implementations
  39. * don't accept negative amplitude among others. Define our own
  40. * FFTpolar template, which works like we expect it to.
  41. */
  42. template<class _Tp>
  43. std::complex<_Tp>
  44. FFTpolar(const _Tp& __rho, const _Tp& __theta = _Tp(0))
  45. {
  46. _Tp __x = __rho * cos(__theta);
  47. if (std::isnan(__x))
  48. __x = 0;
  49. _Tp __y = __rho * sin(__theta);
  50. if (std::isnan(__y))
  51. __y = 0;
  52. return std::complex<_Tp>(__x, __y);
  53. }
  54. void FFT_cleanup();
  55. #endif