Sample player and FFT
Hi there!
This is not probably the best place to ask this type of questions, but i don't know were to ask them!
I'm using AudioLet to generate sound for a while and i'm loving it. But now i need to play a sample and get the FFT info. I've been looking to the API documentation and there is a FFT class. I don't know why i can't put it to work. Is there any example where i can see how this is done? or can anyone provide one?
thanks a lot J
fft = audioLib.FFT(device.sampleRate, 4096);
//and when you mix your sample: fft.pushSample(currentSample);
// now to visualize var height = canvas.height(); var width = canvas.width();
var y = height;
context.clear();
var length, count;
length = fft.spectrum.length / 8;
context.beginPath();
context.moveTo(0, height);
for (var count = 0; count < length; count++) {
context.lineTo(count / length * width, -fft.spectrum[count] * ((Math.log(count) * 2) + 8) * height + height);
}
context.moveTo(width,0);
context.closePath();
context.fill();
context.stroke();
// the magic number 8 is for my particular implementation - but the log is important since the FFT seems to attenuate at higher frequencies by a logarithmic factor. If you don't do the log you end up with high spikes in the lower frequencies and very small bumps in the higher frequencies, despite the fact that the fundemental is high frequency.
-- Hope that helps
thanks a lot Scott :)