The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

100 lines
4.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. /**
  20. Performs a fast fourier transform.
  21. This is only a simple low-footprint implementation and isn't tuned for speed - it may
  22. be useful for simple applications where one of the more complex FFT libraries would be
  23. overkill. (But in the future it may end up becoming optimised of course...)
  24. The FFT class itself contains lookup tables, so there's some overhead in creating
  25. one, you should create and cache an FFT object for each size/direction of transform
  26. that you need, and re-use them to perform the actual operation.
  27. */
  28. class JUCE_API FFT
  29. {
  30. public:
  31. //==============================================================================
  32. /** Initialises an object for performing forward and inverse FFT with the given size.
  33. The number of points the FFT will operate on will be 2 ^ order.
  34. */
  35. FFT (int order);
  36. /** Destructor. */
  37. ~FFT();
  38. //==============================================================================
  39. /** Performs an out-of-place FFT, either forward or inverse.
  40. The arrays must contain at least getSize() elements.
  41. */
  42. void perform (const Complex<float> *input, Complex<float> * output, bool inverse) const noexcept;
  43. /** Performs an in-place forward transform on a block of real data.
  44. The size of the array passed in must be 2 * getSize(), and the first half
  45. should contain your raw input sample data. On return, the array will contain
  46. size complex real + imaginary parts data interleaved, and can be passed to
  47. performRealOnlyInverseTransform() in order to convert it back to reals.
  48. */
  49. void performRealOnlyForwardTransform (float* inputOutputData) const noexcept;
  50. /** Performs a reverse operation to data created in performRealOnlyForwardTransform().
  51. The size of the array passed in must be 2 * getSize(), containing size complex
  52. real and imaginary parts interleaved numbers. On return, the first half of the
  53. array will contain the reconstituted samples.
  54. */
  55. void performRealOnlyInverseTransform (float* inputOutputData) const noexcept;
  56. /** Takes an array and simply transforms it to the magnitude frequency response
  57. spectrum. This may be handy for things like frequency displays or analysis.
  58. The size of the array passed in must be 2 * getSize().
  59. */
  60. void performFrequencyOnlyForwardTransform (float* inputOutputData) const noexcept;
  61. /** Returns the number of data points that this FFT was created to work with. */
  62. int getSize() const noexcept { return size; }
  63. //==============================================================================
  64. #ifndef DOXYGEN
  65. /* internal */
  66. struct Instance;
  67. template <typename> struct EngineImpl;
  68. #endif
  69. private:
  70. //==============================================================================
  71. struct Engine;
  72. ScopedPointer<Instance> engine;
  73. int size;
  74. //==============================================================================
  75. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FFT)
  76. };