I am running a pretty basic audio input with FFT analysis setup. I have passthrough audio too. It works fine but now that I am adding in the fastLED library, the passthrough is totally distorted (just screeching sounds). Is there an overlapping output or something?
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <FastLED.h>
//fastLED stuff
#define NUM_LEDS 1130
#define DATA_PIN 7
#define CLOCK_PIN 14
#define BRIGHTNESS 200
#define FRAMES_PER_SECOND 60
CRGB leds[NUM_LEDS];
bool gReverseDirection = false;
//AUDIO SHIELD STUFF
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
AudioMixer4 mixer1;
// Connect either the live input or synthesized sine wave
//AudioConnection patchCord1(sinewave, 0, myFFT, 0);
AudioConnection patchCord1(audioInput, 0, audioOutput, 0); //one for left and one for right, allows stereo passthrough
AudioConnection patchCord2(audioInput, 1, audioOutput, 1); //
AudioConnection patchCord3(audioInput, 0, mixer1, 0); //need to mix L and R for the FFT analysis (non-stereo)
AudioConnection patchCord4(audioInput, 1, mixer1, 1);
AudioConnection patchCord5(mixer1, myFFT); //this feeds the mixed L and R into the FFT analyzer
AudioControlSGTL5000 audioShield;
void setup() {
//fastLED stuff
delay(3000); // sanity delay
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR, DATA_RATE_MHZ(4)>(leds, NUM_LEDS); //the BGR sets the order of the LEDs, it corrects the red-blue reverse
FastLED.setBrightness( BRIGHTNESS );
//AUDIO SHIELD STUFF
// 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.5);
// Configure the window algorithm to use - test others!
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();
}
leds[0].setHSV( 220, 187, (myFFT.read(1))*1000);
leds[1].setHSV( 0, 187, (myFFT.read(2))*1000);
leds[2].setHSV( 32, 187, (myFFT.read(3))*1000);
leds[3].setHSV( 64, 187, (myFFT.read(4))*1000);
leds[4].setHSV( 96, 187, (myFFT.read(5))*1000);
leds[5].setHSV( 128, 187, (myFFT.read(6))*1000);
leds[6].setHSV( 160, 187, (myFFT.read(0))*1000);
FastLED.show();
}