I have an I2S microphone as input and an analog output to a amplifier with connected speaker and a Teensy 3.2. With the speaker I generate a sine wave frequency and record it with the microphone.
I tested this in a test environment (without other features of my project) and it works well.
This ist the code of this test environment:
If I include the functionality in my project, the "notefreq1.available()" always return false.
Here is the Audio Configuration:
I also have a analog microphone. If I use this microphone my project code works well.
Does anyone have an idea or a hint what I could do?
I tested this in a test environment (without other features of my project) and it works well.
This ist the code of this test environment:
Code:
#include "TeensyThreads.h"
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=177,216
//AudioInputAnalog 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, 0.3);
envelope1.noteOn();
AudioInterrupts();
}
void setup() {
Serial.begin(9600);
AudioMemory(30);
dac1.analogReference(EXTERNAL);
notefreq1.begin(.15);
delay(100);
}
float note, prob;
elapsedMillis fps;
void loop() {
if (fps > 2000) {
fps = 0;
play_tone(10);
}
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);
}
delay(5);
}
If I include the functionality in my project, the "notefreq1.available()" always return false.
Here is the Audio Configuration:
Code:
AudioInputI2S i2s1; //xy=145,489
//AudioInputAnalog i2s1; //xy=145,489
AudioSynthWaveformSineHires sine_hires4; //xy=156,316
AudioSynthWaveformSineHires sine_hires3; //xy=157,240
AudioSynthWaveformSineHires sine_hires2; //xy=159,169
AudioSynthWaveformSineHires sine_hires1; //xy=160,99
AudioEffectEnvelope envelope4; //xy=373,319
AudioEffectEnvelope envelope1; //xy=382,100
AudioEffectEnvelope envelope2; //xy=383,173
AudioEffectEnvelope envelope3; //xy=384,243
AudioMixer4 mixer1; //xy=649,203
AudioOutputAnalog dac1; //xy=888,200
AudioAnalyzeNoteFrequency notefreq1; //xy=369,598
AudioAnalyzeRMS rms1; //xy=361,529
AudioConnection patchCord1(i2s1, 0, notefreq1, 0);
AudioConnection patchCord2(i2s1, 0, rms1, 0);
AudioConnection patchCord3(sine_hires4, 0, envelope4, 0);
AudioConnection patchCord4(sine_hires3, 0, envelope3, 0);
AudioConnection patchCord5(sine_hires2, 0, envelope2, 0);
AudioConnection patchCord6(sine_hires1, 0, envelope1, 0);
AudioConnection patchCord7(envelope4, 0, mixer1, 3);
AudioConnection patchCord8(envelope1, 0, mixer1, 0);
AudioConnection patchCord9(envelope2, 0, mixer1, 1);
AudioConnection patchCord10(envelope3, 0, mixer1, 2);
AudioConnection patchCord11(mixer1, dac1);
I also have a analog microphone. If I use this microphone my project code works well.
Does anyone have an idea or a hint what I could do?
Last edited by a moderator: