annotate _peck_fft_guts.h @ 13:3e85a9101f02 default tip

readme
author Peter Meerwald <p.meerwald@bct-electronic.com>
date Thu, 09 Feb 2012 09:44:39 +0100
parents 655dc5c14169
children
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
12
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 6
diff changeset
16 * defines peck_fft_scalar as either short or a float type and defines
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 6
diff changeset
17 * typedef struct { peck_fft_scalar r; peck_fft_scalar i; } peck_fft_cpx;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 6
diff changeset
18 */
0
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
12
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 6
diff changeset
24 * as far as kissfft is concerned: 4*4*4*2
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
25 */
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
26
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
27 struct peck_fft_state{
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
28 int nfft;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
29 int inverse;
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
30 int factors[2*MAXFACTORS];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
31 peck_fft_cpx twiddles[1];
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
32 };
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
33
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
34 /*
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
35 * Explanation of macros dealing with complex math:
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
36 * 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
37 * 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
38 * C_SUBFROM( res , a) : res -= a
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
39 * C_ADDTO( res , a) : res += a
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
40 */
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
41
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
42 #define S_MUL(a, b) ((a) * (b))
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
43 #define C_MUL(m, a, b) \
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
44 do { \
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
45 (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
46 (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
47 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
48 #define C_MULBYSCALAR(c, s ) \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
49 do { \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
50 (c).r *= (s); \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
51 (c).i *= (s); \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
52 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
53 #define C_ADD(res, a, b) \
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
54 do { \
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
55 (res).r = (a).r + (b).r; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
56 (res).i = (a).i + (b).i; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
57 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
58 #define C_SUB(res, a, b) \
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
59 do { \
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
60 (res).r = (a).r - (b).r; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
61 (res).i = (a).i - (b).i; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
62 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
63 #define C_ADDTO(res, a) \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
64 do { \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
65 (res).r += (a).r; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
66 (res).i += (a).i; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
67 } while(0)
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
68 #define C_SUBFROM(res, a) \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
69 do { \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
70 (res).r -= (a).r; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
71 (res).i -= (a).i; \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
72 } while(0)
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
73
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
74 #if USE_SIMD == SIMD_SSE2
4
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
75 #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
76 #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
77 #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
78 #elif USE_SIMD == SIMD_NEON4
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
79 #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
80 #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
81 #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
82 #elif USE_SIMD == SIMD_NEON2
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
83 #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
84 #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
85 #define HALF_OF(x) ((x)*vdup_n_f32(0.5f))
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
86 #else
4
2d6c49fcafcb neon2 and neon4 support
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 0
diff changeset
87 #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
88 #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
89 #define HALF_OF(x) ((x)*0.5f)
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
90 #endif
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
91
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
92 #define kf_cexp(x,phase) \
6
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
93 do { \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
94 (x)->r = PECK_FFT_COS(phase); \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
95 (x)->i = PECK_FFT_SIN(phase); \
fee54f1878f7 kill FIXED_POINT stuff, simplify
Peter Meerwald <p.meerwald@bct-electronic.com>
parents: 4
diff changeset
96 } while(0)
0
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
97
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
98 #ifdef PECK_FFT_USE_ALLOCA
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
99 // define this to allow use of alloca instead of malloc for temporary buffers
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
100 // Temporary buffers are used in two case:
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
101 // 1. FFT sizes that have "bad" factors. i.e. not 2,3 and 5
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
102 // 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
103 #include <alloca.h>
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
104 #define PECK_FFT_TMP_ALLOC(nbytes) alloca(nbytes)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
105 #define PECK_FFT_TMP_FREE(ptr)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
106 #else
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
107 #define PECK_FFT_TMP_ALLOC(nbytes) PECK_FFT_MALLOC(nbytes)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
108 #define PECK_FFT_TMP_FREE(ptr) PECK_FFT_FREE(ptr)
Peter Meerwald <p.meerwald@bct-electronic.com>
parents:
diff changeset
109 #endif

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