Question from a noob about audio input

Status
Not open for further replies.

vagrant

Member
Hello all,
I just received the tutorial breadboard kit and began playing with it. The project that I'm trying to accomplish is:

A. "listen" for a certain frequency tone with the onboard microphone in a room with moderate ambient noise.
B. filter the audio input to exclude all of the noise pollution
B. output the captured frequency to the monitor and light a series of LED's (onboard would be fine) when the prescribed frequency is found.

That's it...

The problem is that I went through the tutorials and can't seem to get it together.

Thanks for any input or suggestions
 
Well, this is what I have come up with after scouring tutorials and examples from the web. There are a bunch of unused variables declared for future use, and this code is obviously a mess that I'll clean up once I know that I'm on the right track. I can't tell whether I'm actually getting input to the onboard Mic and get no output to the serial monitor.

My question is; would it be better to go the FFT or NoteFrequency route?

Code:
#include <SerialFlash.h>
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>

const int LedPin = 13; // LED Pin- for Teensy 3.2 with soundshield = Pin 13
const int ThresholdBin = 51; // FFT1024 bin for 2200 Hz at 44100 input
const int ListenFrequency = 2200; // Threshold frequency if FFT is not used
const int BeepCnt = 3; // Number of tones in signal pattern

/*NoteFrequency Code part 1 */
AudioInputI2S             i2s1;
AudioAnalyzeNoteFrequency notefreq;
AudioOutputAnalog         i2s2;
AudioMixer4               mixer;
//---------------------------------------------------------------------------------------
AudioConnection patchCord0(i2s1, 0, mixer, 0);
AudioConnection patchCord1(mixer, 0, notefreq, 0);
AudioConnection patchCord2(mixer, 0, i2s2, 0);
AudioControlSGTL5000     sgtl5000_1;
//---------------------------------------------------------------------------------------
/* End NoteFrequency Code Part 1 */

void setup() {
  pinMode (LedPin, OUTPUT); //Set LED to output mode
  digitalWrite (LedPin, LOW); // set onboard LED to OFF

/* Initialize the soundshield onboard microphone */
  Serial.begin(9600);
  AudioMemory(8);
  sgtl5000_1.enable();
  sgtl5000_1.volume(0.5);
  sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
  sgtl5000_1.micGain(36);
  delay(1000);
}

void loop() {
   // read back fundamental frequency
    if (notefreq.available()) {
        float note = notefreq.read();
        float prob = notefreq.probability();
        Serial.printf("Note: %3.2f | Probability: %.2f\n", note, prob);
    }

}

Thanks for any input
 
Status
Not open for further replies.
Back
Top