Hello World!
I am trying to design a device that will measure the acoustics of a room. The concept behind it involves playing test tones such as pink noise and a logarithmic frequency sweep while simultaneously measuring the FFT of the tone played through a speaker. I have the teensy 3.2 audio tutorial breadboard kit. I have tried to accomplish this task in a couple of different ways.
First I tried playing the test tones through files saved on the SD while running the FFT. I tried merging two example codes "FFT" with "do_more_while_playing" and I couldn't get them to work properly. Obviously I had to modify the codes because the two example codes referenced different control for the AudioControlSGTL5000. So I stuck with one and replaced the instances from the other code. I got it to compile however when I uploaded it neither the tone played nor did the serial monitor print the FFT.
Next I tried Pete's (el_supremo's) tonesweep fix and I was able to merge this code semi successfully with the FFT example code. I can now get the frequency sweep to play and the microphone to read from the FFT from the line in input. My problem is I can't get them to do it at the same time. Currently with the code attached in this post they do the operations sequentially. The changes i made to merge the two example codes are mentioned in comments throughout the code.
I'm sure I just need to put them in a loop of some kind but I can't figure out the best way to do this. Any suggestions? 
Code:
#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;
//commented this line to only have one output
//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);
/*
* ///////////////////////////////////////////////////////////////////////////////
* These next few lines are from Pete's tone sweep code
*/
// GUItool: begin automatically generated code
AudioSynthToneSweep tonesweep1; //xy=255,382
AudioOutputI2S i2s1; //xy=763,360
AudioConnection patchCord5(tonesweep1, 0, i2s1, 0);
AudioConnection patchCord6(tonesweep1, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=242,174
// GUItool: end automatically generated code
/*
* Pete's Tone sweep lines end here for now
* /////////////////////////////////////////////////////////////////////////////////
*
*/
//AudioControlSGTL5000 audioShield;
void setup() {
// Audio connections require memory to work. For more
// detailed information, see the MemoryAndCpuUsage example
//Changed this line to add the memory from Pete's tonesweep code so
//there is only one instance of this line
AudioMemory(16);
/*
* ///////////////////////////////////////////////////////////////////////////////
* These next few lines are from Pete's tone sweep code
*/
while(!Serial);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5); Serial.begin(115200);
//AudioMemory(4);
AudioProcessorUsageMaxReset();
AudioMemoryUsageMaxReset();
/*
* Pete's Tone sweep lines end here for now
* /////////////////////////////////////////////////////////////////////////////////
*
*/
//I had to comment these lines out to only have one instance
//also changed the line from audioShield.inputSelect(myInput)
//to sgtl5000_1.inputSelect(myInput)
// Enable the audio shield and set the output volume.
// audioShield.enable();
sgtl5000_1.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();
}
}