Browse Source

Update more examples

dds
PaulStoffregen 10 years ago
parent
commit
c1f34a4b18
5 changed files with 60 additions and 44 deletions
  1. +15
    -2
      examples/Analysis/FFT/FFT.ino
  2. +0
    -42
      examples/Analysis/MonoPeakMeterAnalog/MonoPeakMeterAnalog.ino
  3. +45
    -0
      examples/Analysis/PeakMeterMono/PeakMeterMono.ino
  4. +0
    -0
      examples/Analysis/PeakMeterStereo/PeakMeterStereo.ino
  5. +0
    -0
      examples/Analysis/SpectrumAnalyzerBasic/SpectrumAnalyzerBasic.ino

+ 15
- 2
examples/Analysis/FFT/FFT.ino View File

// 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 <Audio.h>
#include <Wire.h> #include <Wire.h>
#include <SPI.h> #include <SPI.h>
// Enable the audio shield and set the output volume. // Enable the audio shield and set the output volume.
audioShield.enable(); audioShield.enable();
audioShield.inputSelect(myInput); audioShield.inputSelect(myInput);
audioShield.volume(0.6);
audioShield.volume(0.5);


// Configure the window algorithm to use // Configure the window algorithm to use
myFFT.windowFunction(AudioWindowHanning1024); myFFT.windowFunction(AudioWindowHanning1024);
Serial.print(n); Serial.print(n);
Serial.print(" "); Serial.print(" ");
} else { } else {
Serial.print(" - ");
Serial.print(" - "); // don't print "0.00"
} }
} }
Serial.println(); Serial.println();

+ 0
- 42
examples/Analysis/MonoPeakMeterAnalog/MonoPeakMeterAnalog.ino View File

/* 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();
}
}
}

+ 45
- 0
examples/Analysis/PeakMeterMono/PeakMeterMono.ino View File

/* 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();
}
}
}

examples/Analysis/StereoPeakMeter/StereoPeakMeter.ino → examples/Analysis/PeakMeterStereo/PeakMeterStereo.ino View File


examples/Analysis/SpectrumAnalyzer/SpectrumAnalyzer.ino → examples/Analysis/SpectrumAnalyzerBasic/SpectrumAnalyzerBasic.ino View File


Loading…
Cancel
Save