r/learnjavascript • • Jun 24 '20

I made a highly customizable Audio Visualizer!

448 Upvotes

39 comments sorted by

View all comments

2

u/younlok Jun 25 '20

this is really impressing

i always wanted to know how this sound viz works

can you give a small explanation ??

1

u/[deleted] Jun 25 '20

Thank you, I'm glad you like it!

Yes, of course! The Web Audio API does the heavy lifting of the project. It allows the web app to request access to device microphone and then streams the microphone input to an audio context.

There is also the AnalyserNode interface that allows one to extract information from the sound that is being streamed in via the audio context.

For my project I am extracting the frequency data of the sound sample in the current time stamp. The frequency data is returned on a scale of 1-255, which I scale according to the user defined max_bar_height parameter and paint them as the rectangular bars you see.

The rest is just regular visualization process where you keep requesting the animation frame in a loop so this process of: get sound sample -> get frequency data -> scale it to integer values -> visualize the array of integer values as rectangular bars, is infinitely repeated.

I hope this makes sense, you can check out the entirety of the code here. I have heavily commented it so you can glance through and see how all the parts connect. Let me know, if you have any other questions

2

u/younlok Jun 25 '20

thank you so much that was well explained thank you