Debian Codegraph @

src/fft.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2015, Mike Walters <[email protected]>
3 *
4 * This file is part of inspectrum.
5 *
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 3 of the License, or
9 * (at your option) any later version.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "fft.h"
21 #include "string.h"
22
23 FFT::FFT(int size)
24 {
25 fftSize = size;
26
27 fftwIn = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize);
28 fftwOut = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * fftSize);
29 fftwPlan = fftwf_plan_dft_1d(fftSize, fftwIn, fftwOut, FFTW_FORWARD, FFTW_MEASURE);
30 }
31
32 FFT::~FFT()
33 {
34 if (fftwPlan) fftwf_destroy_plan(fftwPlan);
35 if (fftwIn) fftwf_free(fftwIn);
36 if (fftwOut) fftwf_free(fftwOut);
37 }
38
39 void FFT::process(void *dest, void *source)
40 {
41 memcpy(fftwIn, source, fftSize * sizeof(fftwf_complex));
42 fftwf_execute(fftwPlan);
43 memcpy(dest, fftwOut, fftSize * sizeof(fftwf_complex));
44 }