I'm trying to use the audio library to do a FFT on the input signal. I'm following the example, except I modified it to read from the ADC instead of the audio shied and also to print all the bins instead of just 40, but it's not working. The AudioAnalyzeFFT256's available() function never returns TRUE. What am I doing wrong? Here's my code:
Thanks.
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// Create the Audio components. These should be created in the
// order data flows, inputs/sources -> processing -> outputs
//
AudioInputAnalog audioInput(A2);
AudioAnalyzeFFT256 myFFT;
// Connect either the live input or synthesized sine wave
AudioConnection patchCord1(audioInput, myFFT);
void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
AudioMemory(20);
// Configure the window algorithm to use
myFFT.windowFunction(AudioWindowHanning256);
}
void loop() {
float n;
int i;
if (myFFT.available()) {
// each time new FFT data is available
// print it all to the Arduino Serial Monitor
// Serial.print("FFT: ");
for (i=0; i<127; i++) {
n = myFFT.read(i);
//if (n >= 0.01) {
Serial.print(n);
Serial.print(" ");
//} else {
// Serial.print(" - "); // don't print "0.00"
//}
}
Serial.println();
}
}
Thanks.