Debian Codegraph @

dwsys/NUMFourier.cpp

raw
1 /* NUMFourier.cpp
2 *
3 * Copyright (C) 1997-2011,2025 David Weenink, Paul Boersma 2016-2018,2020
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "NUMFourier.h"
20
21 #include "oo_DESTROY.h"
22 #include "NUMFourierTable_def.h"
23 #include "oo_COPY.h"
24 #include "NUMFourierTable_def.h"
25 #include "oo_EQUAL.h"
26 #include "NUMFourierTable_def.h"
27 #include "oo_CAN_WRITE_AS_ENCODING.h"
28 #include "NUMFourierTable_def.h"
29 #include "oo_WRITE_TEXT.h"
30 #include "NUMFourierTable_def.h"
31 #include "oo_WRITE_BINARY.h"
32 #include "NUMFourierTable_def.h"
33 #include "oo_READ_TEXT.h"
34 #include "NUMFourierTable_def.h"
35 #include "oo_READ_BINARY.h"
36 #include "NUMFourierTable_def.h"
37 #include "oo_DESCRIPTION.h"
38 #include "NUMFourierTable_def.h"
39
40 #define FFT_DATA_TYPE double
41 #include "NUMfft_core.h"
42
43 Thing_implement (NUMFourierTable, Daata, 0);
44
45 autoNUMFourierTable NUMFourierTable_create (integer n) {
46 try {
47 autoNUMFourierTable me = Thing_new (NUMFourierTable);
48 my n = n;
49 my trigcacheSize = 3 * n;
50 my trigcache = zero_VEC (my trigcacheSize);
51 my splitcacheSize = 32;
52 my splitcache = zero_INTVEC (my splitcacheSize);
53 NUMrffti (n, my trigcache.asArgumentToFunctionThatExpectsZeroBasedArray(),
54 my splitcache.asArgumentToFunctionThatExpectsZeroBasedArray());
55 return me;
56 } catch (MelderError) {
57 Melder_throw (U"Cannot create NUMFourierTable.");
58 }
59 }
60
61 void NUMforwardRealFastFourierTransform (VEC data) {
62 autoNUMFourierTable table = NUMFourierTable_create (data.size);
63 NUMfft_forward (table.get(), data);
64 if (data.size > 1) {
65 /*
66 To be compatible with old behaviour.
67 */
68 double tmp = data [data.size];
69 for (integer i = data.size; i > 2; i --)
70 data [i] = data [i - 1];
71 data [2] = tmp;
72 }
73 }
74
75 void NUMreverseRealFastFourierTransform (VEC data) {
76 if (data.size > 1) {
77 /*
78 To be compatible with old behaviour.
79 */
80 double tmp = data [2];
81 for (integer i = 2; i < data.size; i ++)
82 data [i] = data [i + 1];
83 data [data.size] = tmp;
84 }
85 autoNUMFourierTable table = NUMFourierTable_create (data.size);
86 NUMfft_backward (table.get(), data);
87 }
88
89 void NUMfft_forward (NUMFourierTable me, VEC data) {
90 if (my n == 1)
91 return;
92 Melder_assert (my n == data.size);
93 drftf1 (my n, data.asArgumentToFunctionThatExpectsZeroBasedArray(),
94 my trigcache.asArgumentToFunctionThatExpectsZeroBasedArray(),
95 my trigcache.asArgumentToFunctionThatExpectsZeroBasedArray() + my n,
96 my splitcache.asArgumentToFunctionThatExpectsZeroBasedArray()
97 );
98 }
99
100 void NUMfft_backward (NUMFourierTable me, VEC data) {
101 if (my n == 1)
102 return;
103 Melder_assert (my n == data.size);
104 drftb1 (my n, data.asArgumentToFunctionThatExpectsZeroBasedArray(),
105 my trigcache.asArgumentToFunctionThatExpectsZeroBasedArray(),
106 my trigcache.asArgumentToFunctionThatExpectsZeroBasedArray() + my n,
107 my splitcache.asArgumentToFunctionThatExpectsZeroBasedArray()
108 );
109 }
110
111 void NUMrealft (VEC data, integer isign) {
112 if (isign == 1)
113 NUMforwardRealFastFourierTransform (data);
114 else
115 NUMreverseRealFastFourierTransform (data);
116 }
117
118 /* End of file NUMFourier.cpp */