add (copy of 2.0-ongoing) rubberband to 3.0
[ardour.git] / libs / rubberband / src / FFT.h
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
2
3 /*
4     Rubber Band
5     An audio time-stretching and pitch-shifting library.
6     Copyright 2007-2008 Chris Cannam.
7     
8     This program is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License as
10     published by the Free Software Foundation; either version 2 of the
11     License, or (at your option) any later version.  See the file
12     COPYING included with this distribution for more information.
13 */
14
15 #ifndef _RUBBERBAND_FFT_H_
16 #define _RUBBERBAND_FFT_H_
17
18 #include "sysutils.h"
19
20 namespace RubberBand {
21
22 class FFTImpl;
23
24 /**
25  * Provide the basic FFT computations we need, using one of a set of
26  * candidate FFT implementations (depending on compile flags).
27  *
28  * Implements real->complex FFTs of power-of-two sizes only.  Note
29  * that only the first half of the output signal is returned (the
30  * complex conjugates half is omitted), so the "complex" arrays need
31  * room for size/2+1 elements.
32  *
33  * Not thread safe: use a separate instance per thread.
34  */
35
36 class FFT
37 {
38 public:
39     enum Exception { InvalidSize };
40
41     FFT(int size, int debugLevel = 0); // may throw InvalidSize
42     ~FFT();
43
44     void forward(const double *R__ realIn, double *R__ realOut, double *R__ imagOut);
45     void forwardPolar(const double *R__ realIn, double *R__ magOut, double *R__ phaseOut);
46     void forwardMagnitude(const double *R__ realIn, double *R__ magOut);
47
48     void forward(const float *R__ realIn, float *R__ realOut, float *R__ imagOut);
49     void forwardPolar(const float *R__ realIn, float *R__ magOut, float *R__ phaseOut);
50     void forwardMagnitude(const float *R__ realIn, float *R__ magOut);
51
52     void inverse(const double *R__ realIn, const double *R__ imagIn, double *R__ realOut);
53     void inversePolar(const double *R__ magIn, const double *R__ phaseIn, double *R__ realOut);
54     void inverseCepstral(const double *R__ magIn, double *R__ cepOut);
55
56     void inverse(const float *R__ realIn, const float *R__ imagIn, float *R__ realOut);
57     void inversePolar(const float *R__ magIn, const float *R__ phaseIn, float *R__ realOut);
58     void inverseCepstral(const float *R__ magIn, float *R__ cepOut);
59
60     // Calling one or both of these is optional -- if neither is
61     // called, the first call to a forward or inverse method will call
62     // init().  You only need call these if you don't want to risk
63     // expensive allocations etc happening in forward or inverse.
64     void initFloat();
65     void initDouble();
66
67     float *getFloatTimeBuffer();
68     double *getDoubleTimeBuffer();
69
70     static void tune();
71
72 protected:
73     FFTImpl *d;
74     static int m_method;
75 };
76
77 }
78
79 #endif
80