fork/rust-sdks
git clone https://git.julia.blue/fork/rust-sdks
2e4d385
main
1/* https://bitbucket.org/jpommier/pffft/raw/483453d8f7661058e74aa4e7cf5c27bcd7887e7a/pffft.h 2* with minor changes for libsoxr. */ 3 4#if !definedPFFT_MACROS_ONLY 5 6/* Copyright (c) 2013 Julien Pommier ( pommier@modartt.com ) 7 8Based on original fortran 77 code from FFTPACKv4 from NETLIB, 9authored by Dr Paul Swarztrauber of NCAR, in 1985. 10 11As confirmed by the NCAR fftpack software curators, the following 12FFTPACKv5 license applies to FFTPACKv4 sources. My changes are 13released under the same terms. 14 15FFTPACK license: 16 17http://www.cisl.ucar.edu/css/software/fftpack5/ftpk.html 18 19Copyright (c) 2004 the University Corporation for Atmospheric 20Research ("UCAR"). All rights reserved. Developed by NCAR's 21Computational and Information Systems Laboratory, UCAR, 22www.cisl.ucar.edu. 23 24Redistribution and use of the Software in source and binary forms, 25with or without modification, is permitted provided that the 26following conditions are met: 27 28- Neither the names of NCAR's Computational and Information Systems 29Laboratory, the University Corporation for Atmospheric Research, 30nor the names of its sponsors or contributors may be used to 31endorse or promote products derived from this Software without 32specific prior written permission. 33 34- Redistributions of source code must retain the above copyright 35notices, this list of conditions, and the disclaimer below. 36 37- Redistributions in binary form must reproduce the above copyright 38notice, this list of conditions, and the disclaimer below in the 39documentation and/or other materials provided with the 40distribution. 41 42THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 43EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF 44MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 45NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT 46HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL, 47EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN 48ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 49CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE 50SOFTWARE. 51*/ 52 53/* 54PFFFT : a Pretty Fast FFT. 55 56This is basically an adaptation of the single precision fftpack 57(v4) as found on netlib taking advantage of SIMD instruction found 58on cpus such as intel x86 (SSE1), powerpc (Altivec), and arm (NEON). 59 60For architectures where no SIMD instruction is available, the code 61falls back to a scalar version. 62 63Restrictions: 64 65- 1D transforms only, with 32-bit single precision. 66 67- supports only transforms for inputs of length N of the form 68N=(2^a)*(3^b)*(5^c), a >= 5, b >=0, c >= 0 (32, 48, 64, 96, 128, 69144, 160, etc are all acceptable lengths). Performance is best for 70128<=N<=8192. 71 72- all (float*) pointers in the functions below are expected to 73have an "simd-compatible" alignment, that is 16 bytes on x86 and 74powerpc CPUs. 75 76You can allocate such buffers with the functions 77pffft_aligned_malloc / pffft_aligned_free (or with stuff like 78posix_memalign..) 79 80*/ 81 82#ifndef PFFFT_H 83#define PFFFT_H 84 85#include <stddef.h> 86 87#ifdef __cplusplus 88extern "C" { 89#endif 90 91#if PFFFT_DOUBLE 92#define float double 93#endif 94 95/* opaque struct holding internal stuff (precomputed twiddle factors) 96this struct can be shared by many threads as it contains only 97read-only data. 98*/ 99typedef struct PFFFT_Setup PFFFT_Setup ; 100 101/* direction of the transform */ 102typedef enum {PFFFT_FORWARD ,PFFFT_BACKWARD }pffft_direction_t ; 103 104/* type of transform */ 105typedef enum {PFFFT_REAL ,PFFFT_COMPLEX }pffft_transform_t ; 106 107/* 108prepare for performing transforms of size N -- the returned 109PFFFT_Setup structure is read-only so it can safely be shared by 110multiple concurrent threads. 111*/ 112static 113PFFFT_Setup * pffft_new_setup (int N ,pffft_transform_t transform ); 114static 115void pffft_destroy_setup (PFFFT_Setup * ); 116/* 117Perform a Fourier transform , The z-domain data is stored in the 118most efficient order for transforming it back, or using it for 119convolution. If you need to have its content sorted in the 120"usual" way, that is as an array of interleaved complex numbers, 121either use pffft_transform_ordered , or call pffft_zreorder after 122the forward fft, and before the backward fft. 123 124Transforms are not scaled: PFFFT_BACKWARD(PFFFT_FORWARD(x)) = N*x. 125Typically you will want to scale the backward transform by 1/N. 126 127The 'work' pointer should point to an area of N (2*N for complex 128fft) floats, properly aligned. If 'work' is NULL, then stack will 129be used instead (this is probably the best strategy for small 130FFTs, say for N < 16384). 131 132input and output may alias. 133*/ 134static 135void pffft_transform (PFFFT_Setup * setup ,const float * input ,float * output ,float * work ,pffft_direction_t direction ); 136 137/* 138Similar to pffft_transform, but makes sure that the output is 139ordered as expected (interleaved complex numbers). This is 140similar to calling pffft_transform and then pffft_zreorder. 141 142input and output may alias. 143*/ 144static 145void pffft_transform_ordered (PFFFT_Setup * setup ,const float * input ,float * output ,float * work ,pffft_direction_t direction ); 146 147/* 148call pffft_zreorder(.., PFFFT_FORWARD) after pffft_transform(..., 149PFFFT_FORWARD) if you want to have the frequency components in 150the correct "canonical" order, as interleaved complex numbers. 151 152(for real transforms, both 0-frequency and half frequency 153components, which are real, are assembled in the first entry as 154F(0)+i*F(n/2+1). Note that the original fftpack did place 155F(n/2+1) at the end of the arrays). 156 157input and output should not alias. 158*/ 159static 160void pffft_zreorder (PFFFT_Setup * setup ,const float * input ,float * output ,pffft_direction_t direction ); 161 162/* 163Perform a multiplication of the frequency components of dft_a and 164dft_b and accumulate them into dft_ab. The arrays should have 165been obtained with pffft_transform(.., PFFFT_FORWARD) and should 166*not* have been reordered with pffft_zreorder (otherwise just 167perform the operation yourself as the dft coefs are stored as 168interleaved complex numbers). 169 170the operation performed is: dft_ab += (dft_a * fdt_b)*scaling 171 172The dft_a, dft_b and dft_ab pointers may alias. 173*/ 174void pffft_zconvolve_accumulate (PFFFT_Setup * setup ,const float * dft_a ,const float * dft_b ,float * dft_ab ,float scaling ); 175 176/* 177the float buffers must have the correct alignment (16-byte boundary 178on intel and powerpc). This function may be used to obtain such 179correctly aligned buffers. 180*/ 181#if 0 182void * pffft_aligned_malloc (size_t nb_bytes ); 183void pffft_aligned_free (void * ); 184 185/* return 4 or 1 wether support SSE/Altivec instructions was enable when building pffft.c */ 186int pffft_simd_size (); 187#endif 188 189#undef float 190 191#ifdef __cplusplus 192} 193#endif 194 195#endif 196 197#endif