Every sound in Skyhop comes from one small
function, beep(): an oscillator, a pitch slide and a
volume fade. Shape one yourself, then hear what the waveform type
actually changes.
Move the sliders, then press Play or hit Space. The graph and the code follow as you go.
Starting pitch in Hz. Higher is higher.
Length in seconds. Fade and slide both end here.
Waveform shape, which sets the tone colour.
Starting volume. Keep it low, oscillators are loud.
Hz to shift by the end. Negative sweeps down, 0 stays flat.
Gem, checkpoint and win are several beeps in a row. Clicking one plays it and loads its first beep into the sliders.
OscillatorNode.type sets the shape of the wave the
oscillator outputs, which changes the tone you hear. Press Play on
any card to listen.
sine is the default value. An oscillator can also take a
custom shape through setPeriodicWave(), which sets the
type to custom.
Why square and sawtooth sound buzzier than sine and triangle. Every shape is a sine at the main pitch plus quieter sines at whole-number multiples of it, called overtones. Add them one at a time and watch each shape build up.