-
Notifications
You must be signed in to change notification settings - Fork 0
/
chowdsp_fft.h
123 lines (100 loc) · 3.89 KB
/
chowdsp_fft.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
Copyright (c) 2024 Jatin Chowdhury ( [email protected] )
Copyright (c) 2013 Julien Pommier ( [email protected] )
Based on original fortran 77 code from FFTPACKv4 from NETLIB,
authored by Dr Paul Swarztrauber of NCAR, in 1985.
As confirmed by the NCAR fftpack software curators, the following
FFTPACKv5 license applies to FFTPACKv4 sources. My changes are
released under the same terms.
FFTPACK license:
http://www.cisl.ucar.edu/css/software/fftpack5/ftpk.html
Copyright (c) 2004 the University Corporation for Atmospheric
Research ("UCAR"). All rights reserved. Developed by NCAR's
Computational and Information Systems Laboratory, UCAR,
www.cisl.ucar.edu.
Redistribution and use of the Software in source and binary forms,
with or without modification, is permitted provided that the
following conditions are met:
- Neither the names of NCAR's Computational and Information Systems
Laboratory, the University Corporation for Atmospheric Research,
nor the names of its sponsors or contributors may be used to
endorse or promote products derived from this Software without
specific prior written permission.
- Redistributions of source code must retain the above copyright
notices, this list of conditions, and the disclaimer below.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the disclaimer below in the
documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
SOFTWARE.
*/
#pragma once
#ifdef __cplusplus
#include <cstddef>
extern "C"
{
namespace chowdsp::fft
{
#else
#include <stddef.h>
#include <stdbool.h>
#endif
/* direction of the transform */
typedef enum
{
FFT_FORWARD,
FFT_BACKWARD
} fft_direction_t;
/* type of transform */
typedef enum
{
FFT_REAL,
FFT_COMPLEX
} fft_transform_t;
/*
prepare for performing transforms of size N -- the returned
FFT_Setup structure is read-only so it can safely be shared by
multiple concurrent threads.
*/
void* fft_new_setup (int N, fft_transform_t transform, bool use_avx_if_available
#ifdef __cplusplus
= true
#endif
);
void fft_destroy_setup (void*);
/*
Perform a Fourier transform , The z-domain data is stored as
interleaved complex numbers.
Transforms are not scaled: PFFFT_BACKWARD(PFFFT_FORWARD(x)) = N*x.
Typically you will want to scale the backward transform by 1/N.
The 'work' pointer should point to an area of N (2*N for complex
fft) floats, properly aligned. If 'work' is NULL, then stack will
be used instead (this is probably the best strategy for small
FFTs, say for N < 16384).
input and output may alias.
*/
void fft_transform (void* setup, const float* input, float* output, float* work, fft_direction_t direction);
/**
* Same as the above method, but without necessarily maintaining the correct data order
* in the frequency domain. This may be useful if your frequency-domain operations
* are order-independent, for example, convolution.
*/
void fft_transform_unordered (void* setup, const float* input, float* output, float* work, fft_direction_t direction);
/**
* Convolve two (unordered) frequency-domain signals, with some scale factor.
*/
void fft_convolve_unordered (void* setup, const float* a, const float* b, float* ab, float scaling);
void* aligned_malloc (size_t nb_bytes);
void aligned_free (void*);
#ifdef __cplusplus
}
} // namespace chowdsp::fft
#endif