Pitch Detection on an ADC input

Status
Not open for further replies.

tenkai

Well-known member
Has anyone gotten pitch detection to work on an ADC input pin?

I am trying to do this and all I get out of serial is garbage, and then it freezes.

Here is the code I am trying:

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

#define kSerialSpeed 115200

AudioInputAnalog              adc(A6);
AudioAnalyzeNoteFrequency     notefreq;

AudioConnection               patchCord1(adc, 0, notefreq, 0);

void setup() {
  AudioMemory(30);
  notefreq.begin(.15);
  Serial.begin(kSerialSpeed);
}

void loop() {

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

}

I have tried various values for the threshold with no luck. Also tried various clock speeds. I know of the bug at 72Mhz for the ADC input. Also have tried a second Teensy! Peak detection seems to work fine, but no go for noteFreq.
 
Last edited:
Not Paul's circuit, but I am biasing the ADC input to be within 0-3v3. I realize that the ADC input is by default 0-1.6v, but I changed the ADC input library to use external 3v3 as reference.

I verified that the teensy is recognizing the signal by mirroring the ADC input to the DAC and the waveforms are similar:

IMG_8251.jpg

Top is DAC output, Bottom is the wave that is being sent to the ADC (through an op amp circuit designed to convert bipolar 5v to 0-3v3)

Regardless, even if there is nothing connected, the above code never makes it past notefreq.begin(.15)

Can someone else try this for a sanity check for me?
 
As a data point, I can use FFT just fine and analyze signals that way, but noteFreq does not work for me.
 
My hardware is using Paul's bias circuit on A2, using A2 instead of A6 everything is working.

Note: 1092.84 | Probability: 0.96
Note: 1092.60 | Probability: 0.99
Note: 1092.79 | Probability: 0.99
Note: 1092.03 | Probability: 0.99
Note: 1092.40 | Probability: 0.99
Note: 1092.33 | Probability: 0.99
Note: 1092.44 | Probability: 0.99
Note: 1092.31 | Probability: 0.99
Note: 1092.52 | Probability: 0.99
Note: 1092.67 | Probability: 0.99
Note: 1092.39 | Probability: 0.99
Note: 1092.41 | Probability: 0.99
Note: 1092.57 | Probability: 0.99
Note: 1092.18 | Probability: 0.99
 
What frequency are you running at?

I think I must have something funky going on in my installation. I will have to re-install everything tomorrow and see where we are at.

Good news is that in all this, I wrote code to set the reference voltage for the ADC pin. I did a pull request, but I think I actually need to do a bit more testing first.
 
I can get this to work fine now with regular arduino and T1.29. I usually use Platform IO and I think there is something funky going on there!
 
Status
Not open for further replies.
Back
Top