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.

93 lines
3.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. /**
  18. A very minimal FFT class.
  19. This is only a simple low-footprint implementation and isn't tuned for speed - it may
  20. be useful for simple applications where one of the more complex FFT libraries would be
  21. overkill. (But in the future it may end up becoming optimised of course...)
  22. The FFT class itself contains lookup tables, so there's some overhead in creating
  23. one, you should create and cache an FFT object for each size/direction of transform
  24. that you need, and re-use them to perform the actual operation.
  25. */
  26. class JUCE_API FFT
  27. {
  28. public:
  29. /** Initialises an object for performing either a forward or inverse FFT with the given size.
  30. The the number of points the FFT will operate on will be 2 ^ order.
  31. */
  32. FFT (int order, bool isInverse);
  33. /** Destructor. */
  34. ~FFT();
  35. /** A complex number, for the purposes of the FFT class. */
  36. struct Complex
  37. {
  38. float r; /**< Real part. */
  39. float i; /**< Imaginary part. */
  40. };
  41. /** Performs an out-of-place FFT, either forward or inverse depending on the mode
  42. that was passed to this object's constructor.
  43. The arrays must contain at least getSize() elements.
  44. */
  45. void perform (const Complex* input, Complex* output) const noexcept;
  46. /** Performs an in-place forward transform on a block of real data.
  47. The size of the array passed in must be 2 * getSize(), and the first half
  48. should contain your raw input sample data. On return, the array will contain
  49. complex frequency + phase data, and can be passed to performRealOnlyInverseTransform()
  50. in order to convert it back to reals.
  51. */
  52. void performRealOnlyForwardTransform (float* inputOutputData) const noexcept;
  53. /** Performs a reverse operation to data created in performRealOnlyForwardTransform().
  54. The size of the array passed in must be 2 * getSize(), containing complex
  55. frequency and phase data. On return, the first half of the array will contain
  56. the reconstituted samples.
  57. */
  58. void performRealOnlyInverseTransform (float* inputOutputData) const noexcept;
  59. /** Takes an array and simply transforms it to the frequency spectrum.
  60. This may be handy for things like frequency displays or analysis.
  61. */
  62. void performFrequencyOnlyForwardTransform (float* inputOutputData) const noexcept;
  63. /** Returns the number of data points that this FFT was created to work with. */
  64. int getSize() const noexcept { return size; }
  65. private:
  66. struct FFTConfig;
  67. ScopedPointer<FFTConfig> config;
  68. const int size;
  69. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FFT)
  70. };