~ubuntu-branches/ubuntu/trusty/libsoxr/trusty

« back to all changes in this revision

Viewing changes to src/pffft.h

  • Committer: Package Import Robot
  • Author(s): Benjamin Drung
  • Date: 2013-01-19 13:59:15 UTC
  • Revision ID: package-import@ubuntu.com-20130119135915-ig85015j5zwtf0rp
Tags: upstream-0.1.0
ImportĀ upstreamĀ versionĀ 0.1.0

Show diffs side-by-side

added added

removed removed

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