|
- #include <Audio.h>
- #include <Wire.h>
- #include <SPI.h>
- #include <SD.h>
-
- const int myInput = AUDIO_INPUT_LINEIN;
- //const int myInput = AUDIO_INPUT_MIC;
-
- // Create the Audio components. These should be created in the
- // order data flows, inputs/sources -> processing -> outputs
- //
- AudioInputI2S audioInput; // audio shield: mic or line-in
- AudioSynthWaveformSine sinewave;
- AudioAnalyzeFFT1024 myFFT;
- AudioOutputI2S audioOutput; // audio shield: headphones & line-out
-
- // Connect either the live input or synthesized sine wave
- AudioConnection patchCord1(audioInput, 0, myFFT, 0);
- //AudioConnection patchCord1(sinewave, 0, myFFT, 0);
-
- AudioControlSGTL5000 audioShield;
-
- void setup() {
- // Audio connections require memory to work. For more
- // detailed information, see the MemoryAndCpuUsage example
- AudioMemory(12);
-
- // Enable the audio shield and set the output volume.
- audioShield.enable();
- audioShield.inputSelect(myInput);
- audioShield.volume(0.6);
-
- // Configure the window algorithm to use
- myFFT.windowFunction(AudioWindowHanning1024);
- //myFFT.windowFunction(NULL);
-
- // Create a synthetic sine wave, for testing
- // To use this, edit the connections above
- sinewave.amplitude(0.8);
- sinewave.frequency(1034.007);
- }
-
- 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<40; i++) {
- n = myFFT.read(i);
- if (n >= 0.01) {
- Serial.print(n);
- Serial.print(" ");
- } else {
- Serial.print(" - ");
- }
- }
- Serial.println();
- }
- }
-
|