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.

FFTwrapper.h 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 modify
  7. it under the terms of version 2 of the GNU General Public License
  8. as published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License (version 2 or later) for more details.
  13. You should have received a copy of the GNU General Public License (version 2)
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. #ifndef FFT_WRAPPER_H
  18. #define FFT_WRAPPER_H
  19. #include <fftw3.h>
  20. #include <complex>
  21. #include "../globals.h"
  22. /**A wrapper for the FFTW library (Fast Fourier Transforms)*/
  23. class FFTwrapper
  24. {
  25. public:
  26. /**Constructor
  27. * @param fftsize The size of samples to be fed to fftw*/
  28. FFTwrapper(int fftsize_);
  29. /**Destructor*/
  30. ~FFTwrapper();
  31. /**Convert Samples to Frequencies using Fourier Transform
  32. * @param smps Pointer to Samples to be converted; has length fftsize_
  33. * @param freqs Structure FFTFREQS which stores the frequencies*/
  34. void smps2freqs(const float *smps, fft_t *freqs);
  35. void freqs2smps(const fft_t *freqs, float *smps);
  36. private:
  37. int fftsize;
  38. fftw_real *time;
  39. fftw_complex *fft;
  40. fftw_plan planfftw, planfftw_inv;
  41. };
  42. /*
  43. * The "std::polar" template has no clear definition for the range of
  44. * the input parameters, and some C++ standard library implementations
  45. * don't accept negative amplitude among others. Define our own
  46. * FFTpolar template, which works like we expect it to.
  47. */
  48. template<class _Tp>
  49. std::complex<_Tp>
  50. FFTpolar(const _Tp& __rho, const _Tp& __theta = _Tp(0))
  51. {
  52. _Tp __x = __rho * cos(__theta);
  53. if (isnan(__x))
  54. __x = 0;
  55. _Tp __y = __rho * sin(__theta);
  56. if (isnan(__y))
  57. __y = 0;
  58. return std::complex<_Tp>(__x, __y);
  59. }
  60. void FFT_cleanup();
  61. #endif