Skip to main content

Playing Sound with tone

The tone function plays sound from the Desmos Graphing Calculator. Changing frequencies over time can even produce simple music.

tone(Frequency, Gain)​

tone(a)\mathrm{tone}(a) plays a sound at frequency a [Hz]a\,[\mathrm{Hz}]. Supported frequencies range from 20 Hz20\,\mathrm{Hz} to 20000 Hz20000\,\mathrm{Hz}.

1
tone(440)\mathrm{tone}(440)

A speaker button appears above the expression. Desmos starts muted, so press the button to hear the 440 Hz440\,\mathrm{Hz} sine wave.

The audio button above a tone expression

The second argument controls gain.

1
tone(440,1.5)\mathrm{tone}(440,1.5)

Maximum gain depends on frequency and is calculated as min⁡(10,660/frequency)\min(10,660/\text{frequency}).

A simple melody​

This graph varies the frequency over time to play a melody. Press the speaker button inside the expression list.

Loading graph…
Open in Desmos ↗

Beats​

Combining two nearby frequencies creates a periodic change in loudness called a beat. Adjust the frequencies in this graph to see and hear the effect.

Loading graph…
Open in Desmos ↗

For frequencies f1f_1 and f2f_2, the beat frequency is

∣f1−f2∣ [Hz].|f_1-f_2|\,[\mathrm{Hz}].