Question

I created audiocontext and connected my microphone to analyser:

context = new AudioContext();
microphone = context.createMediaStreamSource(stream);
analyser = context.createAnalyser();
analyser.fftSize = 2048;
microphone.connect(analyser);

Then I got some arrays with frequencies:

fFrequencyData = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(fFrequencyData);

I want to play some musical notes before microphone and then show what note is it. How I can get frequency of musical note? For example, A1 = 440.00 Hz, F#3 = 1480.00 Hz.

Thank you!

Was it helpful?

Solution

As per Brad's comment - you probably don't want to use Realtime Analyser for this. You can also check out https://github.com/cwilso/PitchDetect - for the precise question you asked, the "noteFromPitch" method, around line 194 of https://github.com/cwilso/PitchDetect/blob/master/js/pitchdetect.js, will do this.

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