emmanuel63
Well-known member
Hello,
I want to mesure as fast as possible the frequency of a sine.
The audio library already provides objects for pitch tracking, but they have some latency due to buffering.
Since my signal is almost a pure sine, I would like to use a "zero crossing" method to estimate frequency.
I use a teensy 3.6 with audio shield.
I have already created very basic custom audio objects, but I can't figure out how to start for this one. For the moment, I was just able to create an object that indicates when the audio signal is either positive or negative.
If someone could give me some directions an ideas, that would help me a lot.
Emmanuel
I want to mesure as fast as possible the frequency of a sine.
The audio library already provides objects for pitch tracking, but they have some latency due to buffering.
Since my signal is almost a pure sine, I would like to use a "zero crossing" method to estimate frequency.
I use a teensy 3.6 with audio shield.
I have already created very basic custom audio objects, but I can't figure out how to start for this one. For the moment, I was just able to create an object that indicates when the audio signal is either positive or negative.
If someone could give me some directions an ideas, that would help me a lot.
Emmanuel
Code:
#include "zero_pitch.h"
void zero_pitch::update(void) {
int16_t *p, *end;
audio_block_t *block;
block = receiveReadOnly(0); //block reçoit l'adresse du paquet audio canal 0
if (block == NULL) return;
p = block->data;
end = p + AUDIO_BLOCK_SAMPLES;
while (p < end) {
int16_t s = *p;
if (s < 0 && alternance == 1) {
alternance = 0;
}
if (s > 0 && alternance == 0) {
alternance = 1;
}
p++;
}
transmit(block);
release(block);
}
bool zero_pitch::getAlternance() {
return alternance;
}