Wolfram Archive
Wolfram Programming Lab is a legacy product.
All the same functionality and features, including access to Programming Lab Explorations, are available with Wolfram|One.
Start programming now. »

# Synthesize Sounds

Make sounds the way early electronic music synthesizers did.

Run the code and press the Play button to play a 440-hertz tone. Try frequencies other than 440:

A sine waveform gives a pure tone.

This makes a sine wave sound with a frequency of 440 hertz that plays for 1 second. Click the Play button to hear the sound:

Play[Sin[2 Pi 440 t], {t, 0, 1}]

Use EmitSound to play the sound immediately:

EmitSound[Play[Sin[2 Pi 440 t], {t, 0, 1}]]

Play[Sin[2 Pi 440 t], {t, 0, 1}]

Play the tone with vibrato. Try strengths of vibrato other than 2:

Adding another sine function inside the first one makes the frequency of the tone waver, giving a vibrato effect.

This gives vibrato with a frequency of 8 hertz:

Play[Sin[2 Pi 440 t + 2 Sin[2 Pi 8 t]], {t, 0, 1}]

The factor of 2 in the vibrato governs its strength. Make the vibrato much stronger:

Play[Sin[2 Pi 440 t + 10 Sin[2 Pi 8 t]], {t, 0, 1}]

Play[Sin[2 Pi 440 t + 2 Sin[2 Pi 8 t]], {t, 0, 1}]

Increase the frequency of the vibrato. Try other values, like 60 or 2,000:

As you increase the frequency of the vibrato, it eventually stops sounding like vibrato and creates a new, completely different sound:

Play[Sin[2 Pi 440 t + 2 Sin[2 Pi 16 t]], {t, 0, 1}]
Play[Sin[2 Pi 440 t + 2 Sin[2 Pi 32 t]], {t, 0, 1}]
Play[Sin[2 Pi 440 t + 2 Sin[2 Pi 128 t]], {t, 0, 1}]
Play[Sin[2 Pi 440 t + 2 Sin[2 Pi 512 t]], {t, 0, 1}]

This is how John Chowning discovered FM synthesis, a technique that was used in the first Yamaha music synthesizers.

Play[Sin[2 Pi 440 t + 2 Sin[2 Pi 900 t]], {t, 0, 1}]

Make a synthesizer. Drag the sliders to make new sounds:

This plays a sound with a carrier frequency of 440 hertz, a modulation frequency of 900 hertz and a modulation index of 2:

Play[Sin[2 Pi 440 t + 2 Sin[2 Pi 900 t]], {t, 0, 1}]

Different modulation frequencies give different sounds.

Explore the effects of various modulation frequencies interactively with Manipulate.

Wrap the EmitSound expression with Manipulate, replace the fixed modulation frequency 900 with the variable mf and specify that mf ranges from 1 to 2000 with an initial value of 900. Now you can drag the slider to change the modulation frequency. ContinuousActionFalse specifies that the sound should only be played when you stop dragging the slider:

Manipulate[ EmitSound[Play[Sin[2 Pi 440 t + 2 Sin[2 Pi mf t]], {t, 0, 1}]]; "Drag and release the slider!", {{mf, 900, "modulation frequency"}, 1, 2000}, ContinuousAction -> False ]

Add controls for the carrier frequency and modulation index:

Manipulate[ EmitSound[Play[Sin[2 Pi cf t + b Sin[2 Pi mf t]], {t, 0, 1}]]; "Drag and release a slider!", {{cf, 440, "carrier frequency"}, 80, 900}, {{mf, 900, "modulation frequency"}, 1, 2000}, {{b, 2, "modulation index"}, 0, 10}, ContinuousAction -> False ]

Manipulate[ EmitSound[Play[Sin[2 Pi cf t + b Sin[2 Pi mf t]], {t, 0, 1}]]; "Drag and release a slider!", {{cf, 440, "carrier frequency"}, 80, 900}, {{mf, 900, "modulation frequency"}, 1, 2000}, {{b, 2, "modulation index"}, 0, 10}, ContinuousAction -> False ]