var clipSeconds = 3, currentSecond = 0;
var w = new Waveform(512,{doubleBuffer:true,bits:16});
var a = new Uint16Array(512 * clipSeconds);
w.on("buffer", function(buf) {
a.set(buf, currentSecond * 512);
currentSecond++;
if (currentSecond >= clipSeconds) {
w.stop();
E.FFT(a);
var m=0,n=-1;
for (var i=150;i<250;i++)if(a[i]>n)n=a[m=i];
console.log(m.toFixed(0)+"Hz @ "+n);
}
});
w.startInput(D2,512,{repeat:true});
My understanding is that all the sound as buffer will be stored in "a" from where once all the data is aggregated we could define the frequency.
When this code is deployed the flow hangs on "E.FFT(a);" and I cannot connect to the Puck anymore. Please advice.
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.
Hi @Gordon,
Based on the code below:
My understanding is that all the sound as buffer will be stored in "a" from where once all the data is aggregated we could define the frequency.
When this code is deployed the flow hangs on "E.FFT(a);" and I cannot connect to the Puck anymore. Please advice.
Thank you.