ECHO GARDEN / STUDY / LEVEL 5 OF 7
A note from
a position.
Echo Garden has no sound files. Every note is made on the spot with the Web Audio API, and everything about it comes from the note itself: height chooses the pitch, the player's colour chooses the timbre, and depth (how far it is pulled out of the panel) chooses the echo. This page plays notes with the scene's own recipe and the game's noteAtHeight and midiToHz.
Click the panel to play
each band is one noteTop: one period of the wave the oscillator makes. Bottom: the volume of the note and its echoes over time; this is what the gain nodes do.
The note
click to hear it- height y
- 1.60 m
- MIDI note
- 67 (G4)
- frequency
- 392 Hz
- echo depth
- 1.00
Pitch from height
echoGardenRules.jsThe six MIDI notes are C, D, E, G, A and the next C. MIDI note 69 is 440 Hz, and each step up multiplies the frequency by the twelfth root of 2.
Making the sound
echoGarden.jsFor each voice: an oscillator (the wave) into a gain (the volume) into a panner (level 6). The gain jumps from almost nothing to its peak in 18 ms and fades out exponentially. Far notes add two quieter voices later.
What you should be able to explain
- A pentatonic scale. C, D, E, G and A leave out the two notes that clash most. Any two of them sound fine together, so two players who know no music still make a pleasant melody.
- MIDI to hertz.
440 × 2^((n − 69) / 12). Twelve steps double the frequency (one octave): C4 is 262 Hz and C5 is 523 Hz. - Timbre. A sine wave has only the main frequency. A triangle wave adds weak odd harmonics (3×, 5×, …), so it sounds brighter. The two players can tell their notes apart by ear.
- The envelope. Switching a tone on and off abruptly makes a click. A quick rise and a smooth exponential fall sounds like a struck bell. The gain starts from 0.0001, not 0, because an exponential curve can never reach zero.
- A simple echo. Real distance adds reflections. The scene imitates them: the further back a note is, the longer the delay (0.17 to 0.37 s) and the louder the two copies.
Exercises: ① Click the same band with A and then B: describe the difference. ② Push the note fully into the panel and pull it all the way out: what happens to the echo? ③ Why would a sudden on/off make a click? (Hint: look at what the wave does at the moment it stops.)