Search code examples
frequencyweb-audio-apitone.js

Tone.js - Note frequency


I'm writing a musical application using Tone.js library. I have a simple pad with notes which are played by the user.

I need to convert the "alphabetic" notation of a note (like A4,C3,D#4 ecc...) into frequencies.

I followed the documentation here: https://tonejs.github.io/docs/r13/Frequency .

Based on the documentation i should be able to convert my note into frequencies simply with:

Tone.Frequency("C3") 

I've been trying to use this line of code, but without any success.

If i try to run it in my browser console (obviously after importing the Tone.js library, which it's correctly included since my whole program works https://codepen.io/mattiasu96/pen/pxPXpB ), the command gives me: https://i.sstatic.net/fB1RQ.jpg which doesn't seem a frequency at all.

What's the problem? Am i missing something? I can't figure out why i can't "extract" the frequency using the given command in the documentation.


Solution

  • Tone.Frequency() is a constructor which creates an object which represents a frequency and provides various methods to convert that frequency. To get the actual frequency in Hertz you can use the toFrequency() method.

    Tone.Frequency('C3').toFrequency()