| @@ -1,3 +1,16 @@ | |||
| // FFT Test | |||
| // | |||
| // Compute a 1024 point Fast Fourier Transform (spectrum analysis) | |||
| // on audio connected to the Left Line-In pin. By changing code, | |||
| // a synthetic sine wave can be input instead. | |||
| // | |||
| // The first 40 (of 512) frequency analysis bins are printed to | |||
| // the Arduino Serial Monitor. Viewing the raw data can help you | |||
| // understand how the FFT works and what results to expect when | |||
| // using the data to control LEDs, motors, or other fun things! | |||
| // | |||
| // This example code is in the public domain. | |||
| #include <Audio.h> | |||
| #include <Wire.h> | |||
| #include <SPI.h> | |||
| @@ -28,7 +41,7 @@ void setup() { | |||
| // Enable the audio shield and set the output volume. | |||
| audioShield.enable(); | |||
| audioShield.inputSelect(myInput); | |||
| audioShield.volume(0.6); | |||
| audioShield.volume(0.5); | |||
| // Configure the window algorithm to use | |||
| myFFT.windowFunction(AudioWindowHanning1024); | |||
| @@ -54,7 +67,7 @@ void loop() { | |||
| Serial.print(n); | |||
| Serial.print(" "); | |||
| } else { | |||
| Serial.print(" - "); | |||
| Serial.print(" - "); // don't print "0.00" | |||
| } | |||
| } | |||
| Serial.println(); | |||
| @@ -1,42 +0,0 @@ | |||
| /* Mono peak meter example using Analog objects. Assumes Teensy 3.1 | |||
| At a minimum DC decouple audio signals to/from Teensy pins with capacitors in the signal paths both in and out, 10uF is often used. | |||
| Possibly worthwhile to set up virtual ground at 3v3/2 for both, or if changing DAC REF to 1.2V then 1.2V/2 for output side. | |||
| This example code is in the public domain | |||
| */ | |||
| #include <Audio.h> | |||
| #include <Wire.h> | |||
| #include <SPI.h> | |||
| #include <SD.h> | |||
| AudioInputAnalog audioInput(A0); // A0 is pin 14, feel free to change. | |||
| AudioAnalyzePeak peak; | |||
| AudioOutputAnalog audioOutput; // DAC pin. | |||
| AudioConnection c1(audioInput,peak); | |||
| AudioConnection c2(audioInput,audioOutput); | |||
| void setup() { | |||
| AudioMemory(4); | |||
| Serial.begin(9600); | |||
| } | |||
| // for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can. | |||
| elapsedMillis fps; | |||
| void loop() { | |||
| if (fps > 24) { | |||
| if (peak.available()) { | |||
| fps = 0; | |||
| uint8_t monoPeak = peak.read() * 30.0; | |||
| Serial.print("|"); | |||
| for (uint8_t cnt=0;cnt<monoPeak;cnt++) { | |||
| Serial.print(">"); | |||
| } | |||
| Serial.println(); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,45 @@ | |||
| /* Mono Peak Meter | |||
| Scrolling peak audio level meter in the Arduino Serial Monitor | |||
| Audio input needs to connect to pin 16 (A2). The signal range is 0 to 1.2V. | |||
| See the documentation in the Audio System Design Tool for the recommended | |||
| circuit to connect an analog signal. | |||
| This example code is in the public domain | |||
| */ | |||
| #include <Audio.h> | |||
| #include <Wire.h> | |||
| #include <SPI.h> | |||
| #include <SD.h> | |||
| // GUItool: begin automatically generated code | |||
| AudioInputAnalog adc1; //xy=164,95 | |||
| AudioAnalyzePeak peak1; //xy=317,123 | |||
| AudioConnection patchCord1(adc1, peak1); | |||
| // GUItool: end automatically generated code | |||
| void setup() { | |||
| AudioMemory(4); | |||
| Serial.begin(9600); | |||
| } | |||
| // for best effect make your terminal/monitor a minimum of 31 chars wide and as high as you can. | |||
| elapsedMillis fps; | |||
| void loop() { | |||
| if (fps > 24) { | |||
| if (peak1.available()) { | |||
| fps = 0; | |||
| int monoPeak = peak1.read() * 30.0; | |||
| Serial.print("|"); | |||
| for (int cnt=0; cnt<monoPeak; cnt++) { | |||
| Serial.print(">"); | |||
| } | |||
| Serial.println(); | |||
| } | |||
| } | |||
| } | |||