Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample player and FFT #53

Open
joaodafonseca opened this issue Oct 25, 2013 · 2 comments
Open

Sample player and FFT #53

joaodafonseca opened this issue Oct 25, 2013 · 2 comments

Comments

@joaodafonseca
Copy link

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

@soshimozi
Copy link

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

@joaodafonseca
Copy link
Author

thanks a lot Scott :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants