mohayonao / web-audio-engine

Pure JS implementation of the Web Audio API
243 stars 32 forks source link

Implement AnalyserNode #31

Closed skratchdot closed 8 years ago

skratchdot commented 8 years ago

I spent time today working on implementing the AnalyserNode. I still have some more work to do before submitting a pull request, but I wanted to get this issue logged so you can provide feedback / guidance, and so I can share some information about the work I did.

I have a test page that I'll update with both the existing code, and the code I worked on so you can see the difference: http://plnkr.co/edit/7Unkd1Ynj9iY2OPy6ObW?p=preview

skratchdot commented 8 years ago

Before submitting a pull request I need to:

skratchdot commented 8 years ago

One other thing to notice, I am using Math.log10() in my toDecibel(gainValue) utility function. I'm not sure if you are okay with the browser support on that, or if I should look into making sure babel polyfills it?

mohayonao commented 8 years ago

Looks good 👍

One request for before pull request

ES2015 polyfill is not needed.

skratchdot commented 8 years ago

Thanks! What you suggested makes sense. I actually pulled that code from here: https://www.nayuki.io/page/free-small-fft-in-multiple-languages (so it's not published on NPM yet). I did some profiling a while back, and found that I liked this fft library. I'll do some more testing with the widely used ones on NPM- and pick one of those. Keep up the good work (and thanks for the quick feedback)!

mohayonao commented 8 years ago

I know. I couldn't find a simple and pretty FFT library in npm..

skratchdot commented 8 years ago

Well, I found a FFT that performs well (and has a nice API). I'm also including a library for the Blackman window function (no need to write test cases for that when a library already exists). I'm including it like:

const blackman = require("scijs-window-functions/blackman");

so it shouldn't include all the unused window functions in that library.

Here are the 2 libs I added as dependencies:

"fourier-transform": "^1.0.2"
"scijs-window-functions": "^2.0.2"

I'll have a pull request fairly soon. Just need to write a few more tests.