| 1 | /* fft/hc_init.c |
| 2 | * |
| 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough |
| 4 | * |
| 5 | * This program 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 program 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 program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_fft_halfcomplex_wavetable) * |
| 21 | FUNCTIONcxx . . $ `./templates_on.h:233:9`!(gsl_fft_halfcomplex_wavetable,alloc) (size_t n) |
| 22 | { |
| 23 | int status; |
| 24 | size_t i; |
| 25 | size_t n_factors; |
| 26 | size_t t, product, product_1, q; |
| 27 | double d_theta; |
| 28 | |
| 29 | TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_fft_halfcomplex_wavetable) * wavetable ; |
| 30 | |
| 31 | if (n == 0) |
| 32 | { |
| 33 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("length n must be positive integer", GSL_EDOM, 0); |
| 34 | } |
| 35 | |
| 36 | wavetable = (TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_fft_halfcomplex_wavetable) *) |
| 37 | malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_fft_halfcomplex_wavetable))); |
| 38 | |
| 39 | if (wavetable == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 40 | { |
| 41 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate struct", GSL_ENOMEM, 0); |
| 42 | } |
| 43 | |
| 44 | wavetable->trigcxx . . $ $anonymous_type_fb32f42d9d274735_0#trig. = (TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_complex) *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (n * sizeof (TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_complex))); |
| 45 | |
| 46 | if (wavetable->trigcxx . . $ $anonymous_type_fb32f42d9d274735_0#trig. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 47 | { |
| 48 | /* error in constructor, prevent memory leak */ |
| 49 | |
| 50 | freecxx . . $ free(5d22bdacc48458e8).(wavetable) ; |
| 51 | |
| 52 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate trigonometric lookup table", |
| 53 | GSL_ENOMEM, 0); |
| 54 | } |
| 55 | |
| 56 | wavetable->ncxx . . $ $anonymous_type_fb32f42d9d274735_0#n. = n ; |
| 57 | |
| 58 | status = fft_halfcomplex_factorizecxx . . $ fft_halfcomplex_factorize(59465bcb0bde3658). (n, &n_factors, wavetable->factorcxx . . $ $anonymous_type_fb32f42d9d274735_0#factor.); |
| 59 | |
| 60 | if (status) |
| 61 | { |
| 62 | /* error in constructor, prevent memory leak */ |
| 63 | |
| 64 | freecxx . . $ free(5d22bdacc48458e8).(wavetable->trigcxx . . $ $anonymous_type_fb32f42d9d274735_0#trig.) ; |
| 65 | freecxx . . $ free(5d22bdacc48458e8).(wavetable) ; |
| 66 | |
| 67 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("factorization failed", GSL_EFACTOR, 0); |
| 68 | } |
| 69 | |
| 70 | wavetable->nfcxx . . $ $anonymous_type_fb32f42d9d274735_0#nf. = n_factors; |
| 71 | |
| 72 | d_theta = 2.0 * M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! / ((double) n); |
| 73 | |
| 74 | t = 0; |
| 75 | product = 1; |
| 76 | for (i = 0; i < n_factors; i++) |
| 77 | { |
| 78 | size_t j; |
| 79 | const size_t factor = wavetable->factorcxx . . $ $anonymous_type_fb32f42d9d274735_0#factor.[i]; |
| 80 | wavetable->twiddlecxx . . $ $anonymous_type_fb32f42d9d274735_0#twiddle.[i] = wavetable->trigcxx . . $ $anonymous_type_fb32f42d9d274735_0#trig. + t; |
| 81 | product_1 = product; /* product_1 = p_(i-1) */ |
| 82 | product *= factor; |
| 83 | q = n / product; |
| 84 | |
| 85 | for (j = 1; j < factor; j++) |
| 86 | { |
| 87 | size_t k; |
| 88 | size_t m = 0; |
| 89 | for (k = 1; k < (q + 1) / 2; k++) |
| 90 | { |
| 91 | double theta; |
| 92 | m = m + j * product_1; |
| 93 | m = m % n; |
| 94 | theta = d_theta * m; /* d_theta*j*k*product_1 */ |
| 95 | GSL_REALcxx . . $ `external/gsl/gsl_complex.h:88:9`!(wavetable->trig[t]) = cos (theta); |
| 96 | GSL_IMAGcxx . . $ `external/gsl/gsl_complex.h:89:9`!(wavetable->trig[t]) = sin (theta); |
| 97 | |
| 98 | t++; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | if (t > (n / 2)) |
| 104 | { |
| 105 | /* error in constructor, prevent memory leak */ |
| 106 | |
| 107 | freecxx . . $ free(5d22bdacc48458e8).(wavetable->trigcxx . . $ $anonymous_type_fb32f42d9d274735_0#trig.) ; |
| 108 | freecxx . . $ free(5d22bdacc48458e8).(wavetable) ; |
| 109 | |
| 110 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("overflowed trigonometric lookup table", GSL_ESANITY, 0); |
| 111 | } |
| 112 | |
| 113 | return wavetable; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | void |
| 118 | FUNCTIONcxx . . $ `./templates_on.h:233:9`!(gsl_fft_halfcomplex_wavetable,free) (TYPEcxx . . $ `./templates_on.h:234:9`!(gsl_fft_halfcomplex_wavetable) * wavetable) |
| 119 | { |
| 120 | |
| 121 | /* release trigonometric lookup tables */ |
| 122 | |
| 123 | freecxx . . $ free(5d22bdacc48458e8). (wavetable->trigcxx . . $ $anonymous_type_fb32f42d9d274735_0#trig.); |
| 124 | wavetable->trigcxx . . $ $anonymous_type_fb32f42d9d274735_0#trig. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 125 | |
| 126 | freecxx . . $ free(5d22bdacc48458e8). (wavetable); |
| 127 | } |
| 128 |