annotate _peck_fft_guts.h @ 8:f2d3b39267ee

fix Makefile
author Peter Meerwald <p.meerwald@bct-electronic.com>
date Mon, 19 Sep 2011 19:49:56 +0200
parents fee54f1878f7
children 655dc5c14169
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
1 /*
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
2 Copyright (c) 2003-2010, Mark Borgerding
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
3
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
4 All rights reserved.
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
5
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
7
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
8 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
9 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
10 * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission.
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
11
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
12 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
13 */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
14
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
15 /* peck_fft.h
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
16 defines peck_fft_scalar as either short or a float type
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
17 and defines
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
18 typedef struct { peck_fft_scalar r; peck_fft_scalar i; }peck_fft_cpx; */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
19 #include "peck_fft.h"
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
20 #include <limits.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
21
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
22 #define MAXFACTORS 32
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
23 /* e.g. an fft of length 128 has 4 factors
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
24 as far as kissfft is concerned
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
25 4*4*4*2
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
26 */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
27
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
28 struct peck_fft_state{
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
29 int nfft;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
30 int inverse;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
31 int factors[2*MAXFACTORS];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
32 peck_fft_cpx twiddles[1];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
33 };
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
34
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
35 /*
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
36 * Explanation of macros dealing with complex math:
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
37 * C_MUL(m,a,b) : m = a*b
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
38 * C_SUB( res, a,b) : res = a - b
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
39 * C_SUBFROM( res , a) : res -= a
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
40 * C_ADDTO( res , a) : res += a
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
41 */
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
42
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
43 #define S_MUL(a, b) ((a) * (b))
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
44 #define C_MUL(m, a, b) \
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
45 do { \
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
46 (m).r = (a).r*(b).r - (a).i*(b).i; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
47 (m).i = (a).r*(b).i + (a).i*(b).r; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
48 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
49 #define C_MULBYSCALAR(c, s ) \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
50 do { \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
51 (c).r *= (s); \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
52 (c).i *= (s); \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
53 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
54 #define C_ADD(res, a, b) \
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
55 do { \
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
56 (res).r = (a).r + (b).r; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
57 (res).i = (a).i + (b).i; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
58 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
59 #define C_SUB(res, a, b) \
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
60 do { \
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
61 (res).r = (a).r - (b).r; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
62 (res).i = (a).i - (b).i; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
63 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
64 #define C_ADDTO(res, a) \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
65 do { \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
66 (res).r += (a).r; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
67 (res).i += (a).i; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
68 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
69 #define C_SUBFROM(res, a) \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
70 do { \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
71 (res).r -= (a).r; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
72 (res).i -= (a).i; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
73 } while(0)
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
74
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
75 #if USE_SIMD == SIMD_SSE2
4
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
76 #define PECK_FFT_COS(phase) _mm_set1_ps(cosf(phase))
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
77 #define PECK_FFT_SIN(phase) _mm_set1_ps(sinf(phase))
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
78 #define HALF_OF(x) ((x)*_mm_set1_ps(0.5f))
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
79 #elif USE_SIMD == SIMD_NEON4
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
80 #define PECK_FFT_COS(phase) vdupq_n_f32(cosf(phase))
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
81 #define PECK_FFT_SIN(phase) vdupq_n_f32(sinf(phase))
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
82 #define HALF_OF(x) ((x)*vdupq_n_f32(0.5f))
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
83 #elif USE_SIMD == SIMD_NEON2
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
84 #define PECK_FFT_COS(phase) vdup_n_f32(cosf(phase))
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
85 #define PECK_FFT_SIN(phase) vdup_n_f32(sinf(phase))
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
86 #define HALF_OF(x) ((x)*vdup_n_f32(0.5f))
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
87 #else
4
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
88 #define PECK_FFT_COS(phase) (peck_fft_scalar) cosf(phase)
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
89 #define PECK_FFT_SIN(phase) (peck_fft_scalar) sinf(phase)
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
90 #define HALF_OF(x) ((x)*0.5f)
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
91 #endif
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
92
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
93 #define kf_cexp(x,phase) \
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
94 do { \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
95 (x)->r = PECK_FFT_COS(phase); \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
96 (x)->i = PECK_FFT_SIN(phase); \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
97 } while(0)
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
98
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
99 #ifdef PECK_FFT_USE_ALLOCA
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
100 // define this to allow use of alloca instead of malloc for temporary buffers
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
101 // Temporary buffers are used in two case:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
102 // 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
103 // 2. "in-place" FFTs. Notice the quotes, since kissfft does not really do an in-place transform.
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
104 #include <alloca.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
105 #define PECK_FFT_TMP_ALLOC(nbytes) alloca(nbytes)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
106 #define PECK_FFT_TMP_FREE(ptr)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
107 #else
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
108 #define PECK_FFT_TMP_ALLOC(nbytes) PECK_FFT_MALLOC(nbytes)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
109 #define PECK_FFT_TMP_FREE(ptr) PECK_FFT_FREE(ptr)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
110 #endif

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.