Thank you Paul, I've got the microphone running with these pin connections.
I'm using the following code, to detect frequencies of tones. Frequencies approximately up to 15 kHz are detected right. If I set the output frequency to more than 15 kHz (e.g. 18 kHz), the detected value is ca. 5 kHz.
The microphone should detect up to 20 kHz. Do you mean, this is a software or a hardware problem?
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=177,216
AudioSynthWaveformSineHires sine_hires1; //xy=183,212
AudioEffectEnvelope envelope1; //xy=405,206
AudioMixer4 mixer1; //xy=637,227
AudioOutputAnalog dac1; //xy=889,228
AudioAnalyzeNoteFrequency notefreq1; //xy=418,374
AudioAnalyzeRMS rms1;
AudioConnection patchCord1(i2s1, 0, notefreq1, 0);
AudioConnection patchCord5(i2s1, 0, rms1, 0);
AudioConnection patchCord2(sine_hires1, 0, envelope1, 0);
AudioConnection patchCord3(envelope1, 0, mixer1, 0);
AudioConnection patchCord4(mixer1, dac1);
// GUItool: end automatically generated code
void play_tone(float tone_frequency) {
AudioNoInterrupts();
sine_hires1.amplitude(1.0);
sine_hires1.frequency(tone_frequency);
// define envelope
envelope1.attack(75);
envelope1.hold(250);
envelope1.decay(10);
envelope1.sustain(0);
envelope1.release(50);
mixer1.gain(0, 1.0);
envelope1.noteOn();
AudioInterrupts();
}
void setup() {
Serial.begin(9600);
AudioMemory(30);
dac1.analogReference(EXTERNAL);
notefreq1.begin(.15);
delay(1000);
}
float note, prob;
elapsedMillis fps;
void loop() {
if (fps > 2000) {
fps = 0;
play_tone(15000);
}
if (notefreq1.available()) {
note = notefreq1.read();
prob = notefreq1.probability();
Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
}
if (rms1.available()) {
float volume_level = rms1.read() * 100.0;
//Serial.printf("Volume level: %3.2f", volume_level);
//Serial.print("Volume level: ");
//Serial.println(volume_level);
}
}