HulaLoop
Simple cross-platform audio loopback and recording.
FFTRealPair.h
1 /*
2  * Free FFT and convolution (C++)
3  *
4  * Copyright (c) 2017 Project Nayuki. (MIT License)
5  * https://www.nayuki.io/page/free-small-fft-in-multiple-languages
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of
8  * this software and associated documentation files (the "Software"), to deal in
9  * the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11  * the Software, and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  * - The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  * - The Software is provided "as is", without warranty of any kind, express or
16  * implied, including but not limited to the warranties of merchantability,
17  * fitness for a particular purpose and noninfringement. In no event shall the
18  * authors or copyright holders be liable for any claim, damages or other
19  * liability, whether in an action of contract, tort or otherwise, arising from,
20  * out of or in connection with the Software or the use or other dealings in the
21  * Software.
22  */
23 
24 #pragma once
25 
26 #include <vector>
27 
28 
29 namespace Fft
30 {
31 
32  /*
33  * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
34  * The vector can have any length. This is a wrapper function.
35  */
36  void transform(std::vector<double> &real, std::vector<double> &imag);
37 
38 
39  /*
40  * Computes the inverse discrete Fourier transform (IDFT) of the given complex vector, storing the result back into the vector.
41  * The vector can have any length. This is a wrapper function. This transform does not perform scaling, so the inverse is not a true inverse.
42  */
43  void inverseTransform(std::vector<double> &real, std::vector<double> &imag);
44 
45 
46  /*
47  * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
48  * The vector's length must be a power of 2. Uses the Cooley-Tukey decimation-in-time radix-2 algorithm.
49  */
50  void transformRadix2(std::vector<double> &real, std::vector<double> &imag);
51 
52 
53  /*
54  * Computes the discrete Fourier transform (DFT) of the given complex vector, storing the result back into the vector.
55  * The vector can have any length. This requires the convolution function, which in turn requires the radix-2 FFT function.
56  * Uses Bluestein's chirp z-transform algorithm.
57  */
58  void transformBluestein(std::vector<double> &real, std::vector<double> &imag);
59 
60 
61  /*
62  * Computes the circular convolution of the given real vectors. Each vector's length must be the same.
63  */
64  void convolve(const std::vector<double> &x, const std::vector<double> &y, std::vector<double> &out);
65 
66 
67  /*
68  * Computes the circular convolution of the given complex vectors. Each vector's length must be the same.
69  */
70  void convolve(
71  const std::vector<double> &xreal, const std::vector<double> &ximag,
72  const std::vector<double> &yreal, const std::vector<double> &yimag,
73  std::vector<double> &outreal, std::vector<double> &outimag);
74 
75 }
Definition: FFTRealPair.h:29