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 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. namespace zyncarla {
  17. /**A wrapper for the FFTW library (Fast Fourier Transforms)*/
  18. class FFTwrapper
  19. {
  20. public:
  21. /**Constructor
  22. * @param fftsize The size of samples to be fed to fftw*/
  23. FFTwrapper(int fftsize_);
  24. /**Destructor*/
  25. ~FFTwrapper();
  26. /**Convert Samples to Frequencies using Fourier Transform
  27. * @param smps Pointer to Samples to be converted; has length fftsize_
  28. * @param freqs Structure FFTFREQS which stores the frequencies*/
  29. void smps2freqs(const float *smps, fft_t *freqs);
  30. void freqs2smps(const fft_t *freqs, float *smps);
  31. private:
  32. int fftsize;
  33. fftw_real *time;
  34. fftw_complex *fft;
  35. fftw_plan planfftw, planfftw_inv;
  36. };
  37. /*
  38. * The "std::polar" template has no clear definition for the range of
  39. * the input parameters, and some C++ standard library implementations
  40. * don't accept negative amplitude among others. Define our own
  41. * FFTpolar template, which works like we expect it to.
  42. */
  43. template<class _Tp>
  44. std::complex<_Tp>
  45. FFTpolar(const _Tp& __rho, const _Tp& __theta = _Tp(0))
  46. {
  47. _Tp __x = __rho * cos(__theta);
  48. if (std::isnan(__x))
  49. __x = 0;
  50. _Tp __y = __rho * sin(__theta);
  51. if (std::isnan(__y))
  52. __y = 0;
  53. return std::complex<_Tp>(__x, __y);
  54. }
  55. void FFT_cleanup();
  56. }
  57. #endif