fork/rust-sdks

git clone https://git.julia.blue/fork/rust-sdks

Théo Monnomsoxr-sys (#438)2e4d385

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