
Originally Posted by
jpk
it seems to me that something in the i2s part of the audio library is broken, here is my code:
....
I use the Adafruit SPH0645 mems mic as input connected to a teensy 4 without the MCLK pin wired.
Good news. I found my box of microphones and I had this exact Adafruit SPH0645. So I wired it up to a Teensy 4.0 and ran you program. It seems to work, at least as well as this microphone works anyway. Here's a quick video of the test I did.
For this test, I modified your program slightly. It prints only the first 20 bins (as much as my camera could record without taking a lot of time to set up a better recording) and I edited it to print 3 digits since the mic's levels are so low. Here's the exact code I ran in that test for the video.
Code:
#include <Audio.h>
AudioInputI2S input;
// AudioInputI2SQuad input;
AudioAnalyzeFFT1024 fft;
AudioConnection connection(input, 0, fft, 0);
void setup() {
AudioMemory(50);
}
// copied from the fft example:
void loop() {
float n;
int i;
if (fft.available()) {
// each time new FFT data is available
// print it all to the Arduino Serial Monitor
Serial.print("FFT: ");
for (i = 0; i < 20; i++) {
n = fft.read(i);
if (n >= 0.001) {
Serial.print(n, 3);
Serial.print(" ");
} else {
Serial.print(" -- "); // don't print "0.00"
}
}
Serial.println();
}
}

(click for full size)
EDIT: Here is a better program which uses a high-pass filter to remove the SPH0645's strong DC output and then applies some digital gain before passing the signal into the FFT. It gives much better results.
Code:
#include <Audio.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=180,111
AudioFilterStateVariable filter1; //xy=325,101
AudioAmplifier amp1; //xy=470,93
AudioAnalyzeFFT1024 fft1024_1; //xy=616,102
AudioConnection patchCord1(i2s1, 0, filter1, 0);
AudioConnection patchCord2(filter1, 2, amp1, 0);
AudioConnection patchCord3(amp1, fft1024_1);
// GUItool: end automatically generated code
void setup() {
AudioMemory(50);
filter1.frequency(30); // filter out DC & extremely low frequencies
amp1.gain(8.5); // amplify sign to useful range
}
void loop() {
if (fft1024_1.available()) {
// each time new FFT data is available
// print 20 bins to the Arduino Serial Monitor
Serial.print("FFT: ");
for (int i = 0; i < 20; i++) {
float n = fft1024_1.read(i);
if (n >= 0.001) {
Serial.print(n, 3);
Serial.print(" ");
} else {
Serial.print(" -- "); // don't print "0.000"
}
}
Serial.println();
}
}
I'm going to add this as an example in the Audio library, and probably in the future more examples for each specific MEMS microphone. Hopefully that will help in the future when these sorts of issues come up.
Edit Again: I've added this to the library's examples.
https://github.com/PaulStoffregen/Au...6f55f29d92e1a6