c@120
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
c@120
|
2 /*
|
c@120
|
3 Constant-Q library
|
c@120
|
4 Copyright (c) 2013-2014 Queen Mary, University of London
|
c@120
|
5
|
c@120
|
6 Permission is hereby granted, free of charge, to any person
|
c@120
|
7 obtaining a copy of this software and associated documentation
|
c@120
|
8 files (the "Software"), to deal in the Software without
|
c@120
|
9 restriction, including without limitation the rights to use, copy,
|
c@120
|
10 modify, merge, publish, distribute, sublicense, and/or sell copies
|
c@120
|
11 of the Software, and to permit persons to whom the Software is
|
c@120
|
12 furnished to do so, subject to the following conditions:
|
c@120
|
13
|
c@120
|
14 The above copyright notice and this permission notice shall be
|
c@120
|
15 included in all copies or substantial portions of the Software.
|
c@120
|
16
|
c@120
|
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
c@120
|
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
c@120
|
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
c@120
|
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
c@120
|
21 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
c@120
|
22 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
c@120
|
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
c@120
|
24
|
c@120
|
25 Except as contained in this notice, the names of the Centre for
|
c@120
|
26 Digital Music; Queen Mary, University of London; and Chris Cannam
|
c@120
|
27 shall not be used in advertising or otherwise to promote the sale,
|
c@120
|
28 use or other dealings in this Software without prior written
|
c@120
|
29 authorization.
|
c@120
|
30 */
|
c@120
|
31
|
c@120
|
32 #ifndef FFT_H
|
c@120
|
33 #define FFT_H
|
c@120
|
34
|
c@120
|
35 class FFT
|
c@120
|
36 {
|
c@120
|
37 public:
|
c@120
|
38 /**
|
c@120
|
39 * Construct an FFT object to carry out complex-to-complex
|
c@120
|
40 * transforms of size nsamples. nsamples does not have to be a
|
c@120
|
41 * power of two.
|
c@120
|
42 */
|
c@120
|
43 FFT(int nsamples);
|
c@120
|
44 ~FFT();
|
c@120
|
45
|
c@120
|
46 /**
|
c@120
|
47 * Carry out a forward or inverse transform (depending on the
|
c@120
|
48 * value of inverse) of size nsamples, where nsamples is the value
|
c@120
|
49 * provided to the constructor above.
|
c@120
|
50 *
|
c@120
|
51 * realIn and (where present) imagIn should contain nsamples each,
|
c@120
|
52 * and realOut and imagOut should point to enough space to receive
|
c@120
|
53 * nsamples each.
|
c@120
|
54 *
|
c@120
|
55 * imagIn may be NULL if the signal is real, but the other
|
c@120
|
56 * pointers must be valid.
|
c@120
|
57 *
|
c@120
|
58 * The inverse transform is scaled by 1/nsamples.
|
c@120
|
59 */
|
c@120
|
60 void process(bool inverse,
|
c@120
|
61 const double *realIn, const double *imagIn,
|
c@120
|
62 double *realOut, double *imagOut);
|
c@120
|
63
|
c@120
|
64 private:
|
c@120
|
65 class D;
|
c@120
|
66 D *m_d;
|
c@120
|
67 };
|
c@120
|
68
|
c@120
|
69 class FFTReal
|
c@120
|
70 {
|
c@120
|
71 public:
|
c@120
|
72 /**
|
c@120
|
73 * Construct an FFT object to carry out real-to-complex transforms
|
c@120
|
74 * of size nsamples. nsamples does not have to be a power of two,
|
c@120
|
75 * but it does have to be even. (Use the complex-complex FFT above
|
c@120
|
76 * if you need an odd FFT size. This constructor will throw
|
c@120
|
77 * std::invalid_argument if nsamples is odd.)
|
c@120
|
78 */
|
c@120
|
79 FFTReal(int nsamples);
|
c@120
|
80 ~FFTReal();
|
c@120
|
81
|
c@120
|
82 /**
|
c@120
|
83 * Carry out a forward real-to-complex transform of size nsamples,
|
c@120
|
84 * where nsamples is the value provided to the constructor above.
|
c@120
|
85 *
|
c@120
|
86 * realIn, realOut, and imagOut must point to (enough space for)
|
c@120
|
87 * nsamples values. For consistency with the FFT class above, and
|
c@120
|
88 * compatibility with existing code, the conjugate half of the
|
c@120
|
89 * output is returned even though it is redundant.
|
c@120
|
90 */
|
c@120
|
91 void forward(const double *realIn,
|
c@120
|
92 double *realOut, double *imagOut);
|
c@120
|
93
|
c@120
|
94 /**
|
c@120
|
95 * Carry out a forward real-to-complex transform of size nsamples,
|
c@120
|
96 * where nsamples is the value provided to the constructor
|
c@120
|
97 * above. Return only the magnitudes of the complex output values.
|
c@120
|
98 *
|
c@120
|
99 * realIn and magOut must point to (enough space for) nsamples
|
c@120
|
100 * values. For consistency with the FFT class above, and
|
c@120
|
101 * compatibility with existing code, the conjugate half of the
|
c@120
|
102 * output is returned even though it is redundant.
|
c@120
|
103 */
|
c@120
|
104 void forwardMagnitude(const double *realIn, double *magOut);
|
c@120
|
105
|
c@120
|
106 /**
|
c@120
|
107 * Carry out an inverse real transform (i.e. complex-to-real) of
|
c@120
|
108 * size nsamples, where nsamples is the value provided to the
|
c@120
|
109 * constructor above.
|
c@120
|
110 *
|
c@120
|
111 * realIn and imagIn should point to at least nsamples/2+1 values;
|
c@120
|
112 * if more are provided, only the first nsamples/2+1 values of
|
c@120
|
113 * each will be used (the conjugate half will always be deduced
|
c@120
|
114 * from the first nsamples/2+1 rather than being read from the
|
c@120
|
115 * input data). realOut should point to enough space to receive
|
c@120
|
116 * nsamples values.
|
c@120
|
117 *
|
c@120
|
118 * The inverse transform is scaled by 1/nsamples.
|
c@120
|
119 */
|
c@120
|
120 void inverse(const double *realIn, const double *imagIn,
|
c@120
|
121 double *realOut);
|
c@120
|
122
|
c@120
|
123 private:
|
c@120
|
124 class D;
|
c@120
|
125 D *m_d;
|
c@120
|
126 };
|
c@120
|
127
|
c@120
|
128 #endif
|