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.

102 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. /**
  24. A very minimal FFT class.
  25. This is only a simple low-footprint implementation and isn't tuned for speed - it may
  26. be useful for simple applications where one of the more complex FFT libraries would be
  27. overkill. (But in the future it may end up becoming optimised of course...)
  28. The FFT class itself contains lookup tables, so there's some overhead in creating
  29. one, you should create and cache an FFT object for each size/direction of transform
  30. that you need, and re-use them to perform the actual operation.
  31. */
  32. class JUCE_API FFT
  33. {
  34. public:
  35. /** Initialises an object for performing either a forward or inverse FFT with the given size.
  36. The the number of points the FFT will operate on will be 2 ^ order.
  37. */
  38. FFT (int order, bool isInverse);
  39. /** Destructor. */
  40. ~FFT();
  41. /** A complex number, for the purposes of the FFT class. */
  42. struct Complex
  43. {
  44. float r; /**< Real part. */
  45. float i; /**< Imaginary part. */
  46. };
  47. /** Performs an out-of-place FFT, either forward or inverse depending on the mode
  48. that was passed to this object's constructor.
  49. The arrays must contain at least getSize() elements.
  50. */
  51. void perform (const Complex* input, Complex* output) const noexcept;
  52. /** Performs an in-place forward transform on a block of real data.
  53. The size of the array passed in must be 2 * getSize(), and the first half
  54. should contain your raw input sample data. On return, the array will contain
  55. complex frequency + phase data, and can be passed to performRealOnlyInverseTransform()
  56. in order to convert it back to reals.
  57. */
  58. void performRealOnlyForwardTransform (float* inputOutputData) const noexcept;
  59. /** Performs a reverse operation to data created in performRealOnlyForwardTransform().
  60. The size of the array passed in must be 2 * getSize(), containing complex
  61. frequency and phase data. On return, the first half of the array will contain
  62. the reconstituted samples.
  63. */
  64. void performRealOnlyInverseTransform (float* inputOutputData) const noexcept;
  65. /** Takes an array and simply transforms it to the frequency spectrum.
  66. This may be handy for things like frequency displays or analysis.
  67. */
  68. void performFrequencyOnlyForwardTransform (float* inputOutputData) const noexcept;
  69. /** Returns the number of data points that this FFT was created to work with. */
  70. int getSize() const noexcept { return size; }
  71. private:
  72. JUCE_PUBLIC_IN_DLL_BUILD (struct FFTConfig)
  73. ScopedPointer<FFTConfig> config;
  74. const int size;
  75. void performRealOnlyForwardTransform (Complex*, float*) const noexcept;
  76. void performRealOnlyInverseTransform (Complex*, float*) const noexcept;
  77. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FFT)
  78. };