Add some assumes for the limiter
[openal-soft.git] / common / alcomplex.c
blobd4045aebd2efc1aa6b3751f5579da08af4de0daa
2 #include "config.h"
4 #include "alcomplex.h"
5 #include "math_defs.h"
8 extern inline ALcomplex complex_add(ALcomplex a, ALcomplex b);
9 extern inline ALcomplex complex_sub(ALcomplex a, ALcomplex b);
10 extern inline ALcomplex complex_mult(ALcomplex a, ALcomplex b);
12 void complex_fft(ALcomplex *FFTBuffer, ALsizei FFTSize, ALdouble Sign)
14 ALsizei i, j, k, mask, step, step2;
15 ALcomplex temp, u, w;
16 ALdouble arg;
18 /* Bit-reversal permutation applied to a sequence of FFTSize items */
19 for(i = 1;i < FFTSize-1;i++)
21 for(mask = 0x1, j = 0;mask < FFTSize;mask <<= 1)
23 if((i&mask) != 0)
24 j++;
25 j <<= 1;
27 j >>= 1;
29 if(i < j)
31 temp = FFTBuffer[i];
32 FFTBuffer[i] = FFTBuffer[j];
33 FFTBuffer[j] = temp;
37 /* Iterative form of Danielson–Lanczos lemma */
38 for(i = 1, step = 2;i < FFTSize;i<<=1, step<<=1)
40 step2 = step >> 1;
41 arg = M_PI / step2;
43 w.Real = cos(arg);
44 w.Imag = sin(arg) * Sign;
46 u.Real = 1.0;
47 u.Imag = 0.0;
49 for(j = 0;j < step2;j++)
51 for(k = j;k < FFTSize;k+=step)
53 temp = complex_mult(FFTBuffer[k+step2], u);
54 FFTBuffer[k+step2] = complex_sub(FFTBuffer[k], temp);
55 FFTBuffer[k] = complex_add(FFTBuffer[k], temp);
58 u = complex_mult(u, w);
63 void complex_hilbert(ALcomplex *Buffer, ALsizei size)
65 const ALdouble inverse_size = 1.0/(ALdouble)size;
66 ALsizei todo, i;
68 for(i = 0;i < size;i++)
69 Buffer[i].Imag = 0.0;
71 complex_fft(Buffer, size, 1.0);
73 todo = size >> 1;
74 Buffer[0].Real *= inverse_size;
75 Buffer[0].Imag *= inverse_size;
76 for(i = 1;i < todo;i++)
78 Buffer[i].Real *= 2.0*inverse_size;
79 Buffer[i].Imag *= 2.0*inverse_size;
81 Buffer[i].Real *= inverse_size;
82 Buffer[i].Imag *= inverse_size;
83 i++;
85 for(;i < size;i++)
87 Buffer[i].Real = 0.0;
88 Buffer[i].Imag = 0.0;
91 complex_fft(Buffer, size, -1.0);