Question

I'm currently trying to learn how to use live microphone input by analyzing the code here: https://github.com/cwilso/pitchdetect

It's a pitch detector, so that means there must be some function constantly looping to check the current state of the input. I've located this as the updatePitch() function since it is constantly logging information about the pitch if I check the console. It is defined on line 283: https://github.com/cwilso/PitchDetect/blob/master/js/pitchdetect.js

I can't seem to find how this function is looping or being constantly called. It's called once in gotStream() but checking that function with console.log it is only run once.

Any help is appreciated, thanks.

Was it helpful?

Solution

The function you're looking for in the code is updatePitch() function and it constantly loop by this last line of code:

window.requestAnimationFrame( updatePitch );

the number of callback for requestAnimationFrame() is 60 times per second. For more information you can check this out.

Hope this helps !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top