Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Frequency to musical note in Web Audio API

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!

like image 863
Roman A. Avatar asked Apr 10 '14 19:04

Roman A.


1 Answers

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.

like image 114
cwilso Avatar answered Oct 18 '22 11:10

cwilso