| 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"cxx . . $ `<file>/dwsys/NUMFourier.h`/ |
| 20 | |
| 21 | #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/ |
| 22 | #include "NUMFourierTable_def.h"cxx . . $ `<file>/dwsys/NUMFourierTable_def.h`/ |
| 23 | #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/ |
| 24 | #include "NUMFourierTable_def.h"cxx . . $ `<file>/dwsys/NUMFourierTable_def.h`/ |
| 25 | #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/ |
| 26 | #include "NUMFourierTable_def.h"cxx . . $ `<file>/dwsys/NUMFourierTable_def.h`/ |
| 27 | #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/ |
| 28 | #include "NUMFourierTable_def.h"cxx . . $ `<file>/dwsys/NUMFourierTable_def.h`/ |
| 29 | #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/ |
| 30 | #include "NUMFourierTable_def.h"cxx . . $ `<file>/dwsys/NUMFourierTable_def.h`/ |
| 31 | #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/ |
| 32 | #include "NUMFourierTable_def.h"cxx . . $ `<file>/dwsys/NUMFourierTable_def.h`/ |
| 33 | #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/ |
| 34 | #include "NUMFourierTable_def.h"cxx . . $ `<file>/dwsys/NUMFourierTable_def.h`/ |
| 35 | #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/ |
| 36 | #include "NUMFourierTable_def.h"cxx . . $ `<file>/dwsys/NUMFourierTable_def.h`/ |
| 37 | #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/ |
| 38 | #include "NUMFourierTable_def.h"cxx . . $ `<file>/dwsys/NUMFourierTable_def.h`/ |
| 39 | |
| 40 | #define FFT_DATA_TYPEcxx . . $ `dwsys/NUMFourier.cpp:40:9`! double |
| 41 | #include "NUMfft_core.h"cxx . . $ `<file>/dwsys/NUMfft_core.h`/ |
| 42 | |
| 43 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (NUMFourierTable, Daata, 0); |
| 44 | |
| 45 | autoNUMFourierTable NUMFourierTable_createcxx . . $ NUMFourierTable_create(10012c71e147318e). (integercxx . . $ integer# n) { |
| 46 | try { |
| 47 | autoNUMFourierTable me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (NUMFourierTable); |
| 48 | mycxx . . $ `melder/melder.h:44:9`! n = n; |
| 49 | mycxx . . $ `melder/melder.h:44:9`! trigcacheSize = 3 * n; |
| 50 | mycxx . . $ `melder/melder.h:44:9`! trigcache =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! trigcacheSize); |
| 51 | mycxx . . $ `melder/melder.h:44:9`! splitcacheSize = 32; |
| 52 | mycxx . . $ `melder/melder.h:44:9`! splitcache =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_INTVECcxx . . $ zero_INTVEC(dab5d3ef28d6a25). (mycxx . . $ `melder/melder.h:44:9`! splitcacheSize); |
| 53 | NUMrffticxx . . $ NUMrffti(ff3f085724bd613d). (n, mycxx . . $ `melder/melder.h:44:9`! trigcache.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), |
| 54 | mycxx . . $ `melder/melder.h:44:9`! splitcache.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).()); |
| 55 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 56 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 57 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot create NUMFourierTable."); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void NUMforwardRealFastFourierTransformcxx . . $ NUMforwardRealFastFourierTransform(33ae648fa537298c). (VECcxx . . $ VEC# data) { |
| 62 | autoNUMFourierTable table = NUMFourierTable_createcxx . . $ NUMFourierTable_create(10012c71e147318e). (data.sizecxx . . $ vector#size.); |
| 63 | NUMfft_forwardcxx . . $ NUMfft_forward(aea41fd94d07eee). (table.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), data); |
| 64 | if (data.sizecxx . . $ vector#size. > 1) { |
| 65 | /* |
| 66 | To be compatible with old behaviour. |
| 67 | */ |
| 68 | double tmp = data [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).data.sizecxx . . $ vector#size.]; |
| 69 | for (integercxx . . $ integer# i = data.sizecxx . . $ vector#size.; i > 2; i --) |
| 70 | data [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = data [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i - 1]; |
| 71 | data [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = tmp; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void NUMreverseRealFastFourierTransformcxx . . $ NUMreverseRealFastFourierTransform(33ae648fa537298c). (VECcxx . . $ VEC# data) { |
| 76 | if (data.sizecxx . . $ vector#size. > 1) { |
| 77 | /* |
| 78 | To be compatible with old behaviour. |
| 79 | */ |
| 80 | double tmp = data [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2]; |
| 81 | for (integercxx . . $ integer# i = 2; i < data.sizecxx . . $ vector#size.; i ++) |
| 82 | data [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = data [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i + 1]; |
| 83 | data [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).data.sizecxx . . $ vector#size.] = tmp; |
| 84 | } |
| 85 | autoNUMFourierTable table = NUMFourierTable_createcxx . . $ NUMFourierTable_create(10012c71e147318e). (data.sizecxx . . $ vector#size.); |
| 86 | NUMfft_backwardcxx . . $ NUMfft_backward(aea41fd94d07eee). (table.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), data); |
| 87 | } |
| 88 | |
| 89 | void NUMfft_forwardcxx . . $ NUMfft_forward(aea41fd94d07eee). (NUMFourierTable me, VECcxx . . $ VEC# data) { |
| 90 | if (mycxx . . $ `melder/melder.h:44:9`! n == 1) |
| 91 | return; |
| 92 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! n == data.size); |
| 93 | drftf1cxx . . $ drftf1(96c7958cb644dae). (mycxx . . $ `melder/melder.h:44:9`! n, data.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ vector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), |
| 94 | mycxx . . $ `melder/melder.h:44:9`! trigcache.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), |
| 95 | mycxx . . $ `melder/melder.h:44:9`! trigcache.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + mycxx . . $ `melder/melder.h:44:9`! n, |
| 96 | mycxx . . $ `melder/melder.h:44:9`! splitcache.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() |
| 97 | ); |
| 98 | } |
| 99 | |
| 100 | void NUMfft_backwardcxx . . $ NUMfft_backward(aea41fd94d07eee). (NUMFourierTable me, VECcxx . . $ VEC# data) { |
| 101 | if (mycxx . . $ `melder/melder.h:44:9`! n == 1) |
| 102 | return; |
| 103 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! n == data.size); |
| 104 | drftb1cxx . . $ drftb1(96c7958cb644dae). (mycxx . . $ `melder/melder.h:44:9`! n, data.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ vector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), |
| 105 | mycxx . . $ `melder/melder.h:44:9`! trigcache.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).(), |
| 106 | mycxx . . $ `melder/melder.h:44:9`! trigcache.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() + mycxx . . $ `melder/melder.h:44:9`! n, |
| 107 | mycxx . . $ `melder/melder.h:44:9`! splitcache.asArgumentToFunctionThatExpectsZeroBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsZeroBasedArray(5a2a78a048fb49a8).() |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | void NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (VECcxx . . $ VEC# data, integercxx . . $ integer# isign) { |
| 112 | if (isign == 1) |
| 113 | NUMforwardRealFastFourierTransformcxx . . $ NUMforwardRealFastFourierTransform(33ae648fa537298c). (data); |
| 114 | else |
| 115 | NUMreverseRealFastFourierTransformcxx . . $ NUMreverseRealFastFourierTransform(33ae648fa537298c). (data); |
| 116 | } |
| 117 | |
| 118 | /* End of file NUMFourier.cpp */ |