I am relatively new to the whole programming neighborhood and was playing around with the Arduino Duemilanove and the LOL shield. I had this great idea to turn it into a visual equalizer and lo and behold there were people already doing it here.
The Arduino works fine and I am able to get code running on it. Simple code, but still code.
I followed all the instructions on how to get it working and am pretty close. However, whenever I try to compile the .ino file for uploading to the board, it gives me 2 errors:
error #1:
C:\Users\Jacob\Documents\Arduino\libraries\FFT\fix_fft.cpp:130:13: error:
expected unqualified-id before 'char'
int fix_fft(char fr[], char fi[], int m, int inverse)
^
error #2:
C:\Users\Jacob\Documents\Arduino\libraries\FFT\fix_fft.cpp:130:13: error:
expected ')' before 'char'
Error compiling.
Here is the source code (with large quantities of immaterial code removed):
#define fix_fft
#define __PROG_TYPES_COMPAT__
#include <avr/pgmspace.h>
#include "fix_fft.h"
/* fix_fft.c - Fixed-point in-place Fast Fourier Transform */
#define N_WAVE 256 /* full length of Sinewave[] */
#define LOG2_N_WAVE 8 /* log2(N_WAVE) */
const prog_int8_t Sinewave[N_WAVE-N_WAVE/4] PROGMEM = {
0, 3, 6, 9, 12, 15, 18, 21,
…
};
inline char FIX_MPY(char a, char b)
{
…
}
/*
fix_fft() - perform forward/inverse fast Fourier transform.
fr[n],fi[n] are real and imaginary arrays, both INPUT AND
RESULT (in-place FFT), with 0 <= n < 2**m; set inverse to
0 for forward transform (FFT), or 1 for iFFT.
*/
int fix_fft(char fr[], char fi[], int m, int inverse)
{
int mr, nn, i, j, l, k, istep, n, scale, shift;
char qr, qi, tr, ti, wr, wi;
n = 1 << m;
/* max FFT size = N_WAVE */
if (n > N_WAVE)
return -1;
mr = 0;
nn = n - 1;
scale = 0;
/* decimation in time - re-order data */
for (m=1; m<=nn; ++m) {
l = n;
do {
l >>= 1;
} while (mr+l > nn);
mr = (mr & (l-1)) + l;
if (mr <= m)
continue;
tr = fr[m];
fr[m] = fr[mr];
fr[mr] = tr;
ti = fi[m];
fi[m] = fi[mr];
fi[mr] = ti;
}
l = 1;
k = LOG2_N_WAVE-1;
while (l < n) {
if (inverse) {
/* variable scaling, depending upon data */
shift = 0;
for (i=0; i<n; ++i) {
j = fr[i];
if (j < 0)
j = -j;
m = fi[i];
if (m < 0)
m = -m;
if (j > 16383 || m > 16383) {
shift = 1;
break;
}
}
if (shift)
++scale;
} else {
/*
fixed scaling, for proper normalization --
there will be log2(n) passes, so this results
in an overall factor of 1/n, distributed to
maximize arithmetic accuracy.
*/
shift = 1;
}
/*
it may not be obvious, but the shift will be
performed on each data point exactly once,
during this pass.
*/
istep = l << 1;
for (m=0; m<l; ++m) {
j = m << k;
/* 0 <= j < N_WAVE/2 */
wr = pgm_read_word_near(Sinewave + j+N_WAVE/4);
/*Serial.println("asdfasdf");
Serial.println(wr);
Serial.println(j+N_WAVE/4);
Serial.println(Sinewave[256]);
Serial.println("");*/
wi = -pgm_read_word_near(Sinewave + j);
if (inverse)
wi = -wi;
if (shift) {
wr >>= 1;
wi >>= 1;
}
for (i=m; i<n; i+=istep) {
j = i + l;
tr = FIX_MPY(wr,fr[j]) - FIX_MPY(wi,fi[j]);
ti = FIX_MPY(wr,fi[j]) + FIX_MPY(wi,fr[j]);
qr = fr[i];
qi = fi[i];
if (shift) {
qr >>= 1;
qi >>= 1;
}
fr[j] = qr - tr;
fi[j] = qi - ti;
fr[i] = qr + tr;
fi[i] = qi + ti;
}
}
--k;
l = istep;
}
return scale;
}
…
There are other files in the audio conversion too.
What do you think this line does? Why do you think it is needed in your code at all?
#define fix_fft
When the preprocessor sees the line:
int fix_fft(char fr[], char fi[], int m, int inverse)
it is forced to translate that to:
int (char fr[], char fi[], int m, int inverse)
and now you can see why the compiler complains.
My preferred fix would be to remove the #define fix_fft
line altogether. If you need it for some reason, you could either rename the macro that's defined (#define fix_fft_c
to indicate that it's the fix_fft.c
file) or rename the function that's defined (don't forget to edit the header that declares the function too — you do have a header to declare the function, don't you?), or (to be truly perverse), use #define fix_fft fix_fft
. See the C standard, ISO/IEC 9899:2011 — §6.10.3.4 Rescanning and further replacement:
If the name of the macro being replaced is found during this scan of the replacement list (not including the rest of the source file’s preprocessing tokens), it is not replaced. Furthermore, if any nested replacements encounter the name of the macro being replaced, it is not replaced. These nonreplaced macro name preprocessing tokens are no longer available for further replacement even if they are later (re)examined in contexts in which that macro name preprocessing token would otherwise have been replaced.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments