scide: GenericCodeEditor - accept drag/drop of text/plain
[supercollider.git] / include / common / SC_fftlib.h
blob4460dbc3d9a827628c2ad69434d6d5f4ccdc5c2b
1 /*
2 SC_fftlib.h
3 An interface to abstract over different FFT libraries, for SuperCollider 3.
4 Copyright (c) 2008 Dan Stowell. All rights reserved.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef _SC_fftlib_
23 #define _SC_fftlib_
25 #include <string.h>
27 // These specify the min & max FFT sizes expected (used when creating windows, also allocating some other arrays).
28 #define SC_FFT_MINSIZE 8
29 #define SC_FFT_LOG2_MINSIZE 3
30 #define SC_FFT_MAXSIZE 8192
31 #define SC_FFT_LOG2_MAXSIZE 13
34 // Note that things like *fftWindow actually allow for other sizes, to be created on user request.
35 #define SC_FFT_ABSOLUTE_MAXSIZE 2147483648
36 #define SC_FFT_LOG2_ABSOLUTE_MAXSIZE 31
37 #define SC_FFT_LOG2_ABSOLUTE_MAXSIZE_PLUS1 32
39 struct scfft;
41 class SCFFT_Allocator
43 public:
44 virtual void* alloc(size_t size) = 0;
45 virtual void free(void* ptr) = 0;
48 enum SCFFT_Direction
50 kForward = 1,
51 kBackward = 0
54 // These values are referred to from SC lang as well as in the following code - do not rearrange!
55 enum SCFFT_WindowFunction
57 kRectWindow = -1,
58 kSineWindow = 0,
59 kHannWindow = 1
62 ////////////////////////////////////////////////////////////////////////////////////////////////////
63 // Functions
65 // To initialise a specific FFT, ensure your input and output buffers exist. Internal data structures
66 // will be allocated using the alloc object,
67 // Both "fullsize" and "winsize" should be powers of two (this is not checked internally).
68 scfft * scfft_create(size_t fullsize, size_t winsize, SCFFT_WindowFunction wintype,
69 float *indata, float *outdata, SCFFT_Direction forward, SCFFT_Allocator & alloc);
71 // These two will take data from indata, use trbuf to process it, and put their results in outdata.
72 void scfft_dofft(scfft *f);
73 void scfft_doifft(scfft *f);
75 // destroy any resources held internally.
76 void scfft_destroy(scfft *f, SCFFT_Allocator & alloc);
78 #endif