Adding AudioInputAnalog breaks the project
Hello!
I'm a beginner with Teensy, so I've spent the night setting up a simple mic and analog input that I want to do FFT. I've tried all samples I can find that uses AudioInputAnalog, but it just won't compile if I select Teensy 4.0 as a board. If I select any other Teensy board it will, but then it won't upload to the Teensy (which, of course, is understandable).
Is it me or something else?
Here's what I'm trying to do:
Hello!
I'm a beginner with Teensy, so I've spent the night setting up a simple mic and analog input that I want to do FFT. I've tried all samples I can find that uses AudioInputAnalog, but it just won't compile if I select Teensy 4.0 as a board. If I select any other Teensy board it will, but then it won't upload to the Teensy (which, of course, is understandable).
Is it me or something else?
Here's what I'm trying to do:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioInputAnalog adc1; //xy=122,68
AudioAmplifier amp1; //xy=279,126
AudioAnalyzeFFT1024 fft1024; //xy=433,180
AudioConnection patchCord1(adc1, amp1);
AudioConnection patchCord2(amp1, fft1024);
// GUItool: end automatically generated code
//AudioInputAnalog adc1(A0);
float level[16];
void setup() {
AudioMemory(12);
}
void loop() {
if (fft1024.available()) {
// read the 512 FFT frequencies into 16 levels
// music is heard in octaves, but the FFT data
// is linear, so for the higher octaves, read
// many FFT bins together.
level[0] = fft1024.read(0);
level[1] = fft1024.read(1);
level[2] = fft1024.read(2, 3);
level[3] = fft1024.read(4, 6);
level[4] = fft1024.read(7, 10);
level[5] = fft1024.read(11, 15);
level[6] = fft1024.read(16, 22);
level[7] = fft1024.read(23, 32);
level[8] = fft1024.read(33, 46);
level[9] = fft1024.read(47, 66);
level[10] = fft1024.read(67, 93);
level[11] = fft1024.read(94, 131);
level[12] = fft1024.read(132, 184);
level[13] = fft1024.read(185, 257);
level[14] = fft1024.read(258, 359);
level[15] = fft1024.read(360, 511);
// See this conversation to change this to more or less than 16 log-scaled bands?
// https://forum.pjrc.com/threads/32677-Is-there-a-logarithmic-function-for-FFT-bin-selection-for-any-given-of-bands
for (int i = 0; i < 16; i++) {
Serial.print(level[i]);
//Serial.print(shown[i]);
Serial.print(" ");
}
Serial.print(" cpu:");
Serial.println(AudioProcessorUsageMax());
}
}
Last edited: