var w = new Waveform(512,{doubleBuffer:true,bits:16});
var a2 = new Uint16Array(512);
var a = new Int16Array(a2.buffer);
w.on("buffer", function(buf) {
a2.set(buf);
E.FFT(a2);
var m=0,n=-1,b;
for (var i=150;i<250;i++){b=Math.abs(a[i]);if(b>n){n=b;m=i;}}
console.log(m.toFixed(0)+"Hz @ "+n);
});
w.startInput(D2,512,{repeat:true});
It's sampling at 512Hz, which seems to be good enough for what you want.
Ideally the input voltage range would be higher and you could go back to 8 bits though - I had to use 16 because my microphone isn't very good.
Also, there appears to be some bug in the FFT where it's returning signed values when it shouldn't be - I'll look into that, but for now the attached code seems to work ok.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Something like this seems to work:
It's sampling at 512Hz, which seems to be good enough for what you want.
Ideally the input voltage range would be higher and you could go back to 8 bits though - I had to use 16 because my microphone isn't very good.
Also, there appears to be some bug in the FFT where it's returning signed values when it shouldn't be - I'll look into that, but for now the attached code seems to work ok.