OpenShot Library | OpenShotAudio  0.2.2
juce_FFT.h
1 
2 /** @weakgroup juce_dsp-frequency
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  By using JUCE, you agree to the terms of both the JUCE 5 End-User License
15  Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
16  27th April 2017).
17 
18  End User License Agreement: www.juce.com/juce-5-licence
19  Privacy Policy: www.juce.com/juce-5-privacy-policy
20 
21  Or: You may also use this code under the terms of the GPL v3 (see
22  www.gnu.org/licenses).
23 
24  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
25  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
26  DISCLAIMED.
27 
28  ==============================================================================
29 */
30 
31 namespace juce
32 {
33 namespace dsp
34 {
35 
36 /**
37  Performs a fast fourier transform.
38 
39  This is only a simple low-footprint implementation and isn't tuned for speed - it may
40  be useful for simple applications where one of the more complex FFT libraries would be
41  overkill. (But in the future it may end up becoming optimised of course...)
42 
43  The FFT class itself contains lookup tables, so there's some overhead in creating
44  one, you should create and cache an FFT object for each size/direction of transform
45  that you need, and re-use them to perform the actual operation.
46 
47  @tags{DSP}
48 */
50 {
51 public:
52  //==============================================================================
53  /** Initialises an object for performing forward and inverse FFT with the given size.
54  The number of points the FFT will operate on will be 2 ^ order.
55  */
56  FFT (int order);
57 
58  /** Destructor. */
59  ~FFT();
60 
61  //==============================================================================
62  /** Performs an out-of-place FFT, either forward or inverse.
63  The arrays must contain at least getSize() elements.
64  */
65  void perform (const Complex<float>* input, Complex<float>* output, bool inverse) const noexcept;
66 
67  /** Performs an in-place forward transform on a block of real data.
68 
69  As the coefficients of the negative frequencies (frequencies higher than
70  N/2 or pi) are the complex conjugate of their positive counterparts,
71  it may not be necessary to calculate them for your particular application.
72  You can use dontCalculateNegativeFrequencies to let the FFT
73  engine know that you do not plan on using them. Note that this is only a
74  hint: some FFT engines (currently only the Fallback engine), will still
75  calculate the negative frequencies even if dontCalculateNegativeFrequencies
76  is true.
77 
78  The size of the array passed in must be 2 * getSize(), and the first half
79  should contain your raw input sample data. On return, if
80  dontCalculateNegativeFrequencies is false, the array will contain size
81  complex real + imaginary parts data interleaved. If
82  dontCalculateNegativeFrequencies is true, the array will contain at least
83  (size / 2) + 1 complex numbers. Both outputs can be passed to
84  performRealOnlyInverseTransform() in order to convert it back to reals.
85  */
86  void performRealOnlyForwardTransform (float* inputOutputData,
87  bool dontCalculateNegativeFrequencies = false) const noexcept;
88 
89  /** Performs a reverse operation to data created in performRealOnlyForwardTransform().
90 
91  Although performRealOnlyInverseTransform will only use the first ((size / 2) + 1)
92  complex numbers, the size of the array passed in must still be 2 * getSize(), as some
93  FFT engines require the extra space for the calculation. On return, the first half of the
94  array will contain the reconstituted samples.
95  */
96  void performRealOnlyInverseTransform (float* inputOutputData) const noexcept;
97 
98  /** Takes an array and simply transforms it to the magnitude frequency response
99  spectrum. This may be handy for things like frequency displays or analysis.
100  The size of the array passed in must be 2 * getSize().
101  */
102  void performFrequencyOnlyForwardTransform (float* inputOutputData) const noexcept;
103 
104  /** Returns the number of data points that this FFT was created to work with. */
105  int getSize() const noexcept { return size; }
106 
107  //==============================================================================
108  #ifndef DOXYGEN
109  /* internal */
110  struct Instance;
111  template <typename> struct EngineImpl;
112  #endif
113 
114 private:
115  //==============================================================================
116  struct Engine;
117 
118  std::unique_ptr<Instance> engine;
119  int size;
120 
121  //==============================================================================
122  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FFT)
123 };
124 
125 } // namespace dsp
126 } // namespace juce
127 
128 /** @}*/
Performs a fast fourier transform.
Definition: juce_FFT.h:50
int getSize() const noexcept
Returns the number of data points that this FFT was created to work with.
Definition: juce_FFT.h:105
#define JUCE_API
This macro is added to all JUCE public class declarations.