MCPcopy Create free account
hub / github.com/CalcProgrammer1/KeyboardVisualizer / cfft

Function cfft

KeyboardVisualizerCommon/chuck_fft.c:212–258  ·  view source on GitHub ↗

----------------------------------------------------------------------------- name: cfft() desc: complex value fft these routines from CARL software, spect.c check out the CARL CMusic distribution for more software cfft replaces float array x containing NC complex values (2*NC float values alternating real, imagininary, etc.) by its Fourier transform if forward is true, or by its inverse Fourier

Source from the content-addressed store, hash-verified

210//
211//-----------------------------------------------------------------------------
212void cfft(float * x, long NC, unsigned int forward)
213{
214 float wr, wi, wpr, wpi, theta, scale;
215 long mmax, ND, m, i, j, delta;
216 ND = NC << 1;
217 bit_reverse(x, ND);
218
219 for (mmax = 2; mmax < ND; mmax = delta)
220 {
221 delta = mmax << 1;
222 theta = TWOPI / (forward ? mmax : -mmax);
223 wpr = (float)(-2.*pow(sin(0.5*theta), 2.));
224 wpi = (float)sin(theta);
225 wr = 1.;
226 wi = 0.;
227
228 for (m = 0; m < mmax; m += 2)
229 {
230 register float rtemp, itemp;
231 for (i = m; i < ND; i += delta)
232 {
233 j = i + mmax;
234 rtemp = wr*x[j] - wi*x[j + 1];
235 itemp = wr*x[j + 1] + wi*x[j];
236 if (j >= 511 || i >= 511)
237 {
238 j = 0;
239 }
240 x[j] = x[i] - rtemp;
241 x[j + 1] = x[i + 1] - itemp;
242 x[i] += rtemp;
243 x[i + 1] += itemp;
244 }
245
246 wr = (rtemp = wr)*wpr - wi*wpi + wr;
247 wi = wi*wpr + rtemp*wpi + wi;
248 }
249 }
250
251 // scale output
252 scale = (float)(forward ? 1. / ND : 2.);
253 {
254 register float *xi = x, *xe = x + ND;
255 while (xi < xe)
256 *xi++ *= scale;
257 }
258}
259
260
261

Callers 1

rfftFunction · 0.85

Calls 1

bit_reverseFunction · 0.85

Tested by

no test coverage detected