SnowsongWolf
Member
Hello,
I'll start by saying that I am not an audio engineer. I know my way around a mixing board but talk of codecs, effects, and i2s in general confuses me greatly.
That said, I am building a costume that has Teensy 3.5-controlled lights that I wish to sync to music. I've already worked out timing more or less (https://www.youtube.com/watch?v=cxKQS1fh3w8), but I want to hide ultrasonic trigger sounds (20K tone) in the beginning of the song to sync my animations up. Looking over the Arduino Whistle example, it looks like the way to do this is with an FFT process. However I'm having a hard time wrapping my head around the code to achieve this.
I don't have the audio shield, I prefer to wire my microphone (ICS43432 MEMS I2S microphone on a breakout board) directly to the Teensy (space is a concern on this project). Looking over the FFT1024 example, am I correct in assuming I can simply comment out the audio shield control code and more or less use it as is? Is there a better way to get a tone trigger? Normally I would be willing to simply play the audio myself and sync the lights to the start of playback but I intend to do this on stage where I won't have direct access to the sound system and will need to hand over an audio file for playback.
I'll start by saying that I am not an audio engineer. I know my way around a mixing board but talk of codecs, effects, and i2s in general confuses me greatly.
That said, I am building a costume that has Teensy 3.5-controlled lights that I wish to sync to music. I've already worked out timing more or less (https://www.youtube.com/watch?v=cxKQS1fh3w8), but I want to hide ultrasonic trigger sounds (20K tone) in the beginning of the song to sync my animations up. Looking over the Arduino Whistle example, it looks like the way to do this is with an FFT process. However I'm having a hard time wrapping my head around the code to achieve this.
I don't have the audio shield, I prefer to wire my microphone (ICS43432 MEMS I2S microphone on a breakout board) directly to the Teensy (space is a concern on this project). Looking over the FFT1024 example, am I correct in assuming I can simply comment out the audio shield control code and more or less use it as is? Is there a better way to get a tone trigger? Normally I would be willing to simply play the audio myself and sync the lights to the start of playback but I intend to do this on stage where I won't have direct access to the sound system and will need to hand over an audio file for playback.
Code:
// 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>
#include <SD.h>
#include <SerialFlash.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.
// ------------------------------------------------------------------
// Disabled because I'm not using the audio shield - Snow
// audioShield.enable();
// audioShield.inputSelect(myInput);
// audioShield.volume(0.5);
// 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(" - "); // don't print "0.00"
}
}
Serial.println();
}
}