Ultimate Guide to Sound Frequency Generation
Frequency is the heartbeat of sound. Every tone you hear is air pressure oscillating back and forth, and frequency counts how many complete oscillations happen in one second — measured in hertz (Hz). A 440 Hz tone completes 440 cycles every second, which is why it feels "higher" than a 220 Hz tone: its pressure waves arrive twice as often. The full range of human hearing runs from roughly 20 Hz, a deep sub-bass rumble you feel more than hear, up to about 20,000 Hz, a piercing airiness most adults lose part of with age. That entire audible window is what a sound frequency generator covers.
The period is the flip side of frequency and the simplest calculation in acoustics: period = 1 ÷ frequency. At 440 Hz each cycle lasts about 2.27 milliseconds; at 20 Hz a single cycle stretches to 50 milliseconds. This reciprocal relationship is why low frequencies feel slow and heavy — the speaker cone physically moves back and forth far less often — and why high frequencies feel tense and fast. Any time you need to reason about speaker movement, buffer sizes, or beat lengths, converting frequency to period is the first step.
Musical pitch maps to frequency exponentially, and that mapping is the reason music sounds the way it does. Doubling a frequency raises a note by exactly one octave: 440 Hz (A4) to 880 Hz (A5). Halving drops it an octave: 440 to 220. Within an octave, the twelve notes are spaced by equal ratios, about 6% each, so each doubling of frequency is divided into twelve equal steps. The standard tuning reference for most Western music is A4 = 440 Hz, with C4 (middle C) at 261.63 Hz. Some musicians prefer A4 = 432 Hz, a subtly lower, warmer reference that sits just under 32 cents flat of 440.
A pure tone of a single frequency is called a sine wave, and it is the cleanest sound the Web Audio API can produce — no extra harmonics, just the fundamental. Real instruments are never this pure; they layer harmonics, multiples of the fundamental, whose mix defines each instrument's timbre. Understanding that a sine is the building block and that every other waveform adds harmonics is the key to knowing which tone you actually want: a pure sine for tuning and calibration, a richer waveform when you want something that sounds like an instrument.
Waveform shape is what changes timbre. A square wave adds only odd harmonics — at 1/3, 1/5, 1/7 of the fundamental's amplitude — which gives it a hollow, buzzy, almost vintage-computer sound. A sawtooth contains every harmonic, odd and even, which makes it bright and reedy, the classic synthesizer lead. A triangle wave keeps only the odd harmonics but rolls them off much faster — 1/9, 1/25 — producing a warm, flute-like tone. The same 440 Hz frequency sounds completely different through each of these shapes, because the shape, not the pitch, defines the character.
Browsers enforce a strict rule that shapes every tone generator: audio cannot start until a user gesture. Clicking a button, pressing a key, or tapping a screen counts; a page loading does not. This is why the AudioContext is created inside the Start click handler rather than on page load — the browser grants audio access only within that gesture, so the generator stays instantly usable while respecting the autoplay policy. It is also why a generator that works in one context may refuse in another: if you never interact with the page, there is no gesture, and there is no sound.
Sudden changes in volume are audible as clicks and pops, so a good generator ramps. Instead of jumping the gain from zero to full volume in one sample, the Web Audio API changes it exponentially over a short interval — around 30 milliseconds on start and slightly longer on stop. The ear perceives this as a smooth attack and release rather than an ugly transient. Forcing the volume to jump instantly is the difference between a professional-sounding tool and one that thumps on every press, and it is also the difference between a tool that respects your speakers and one that startles you.
Hearing safety is part of the design, not an afterthought. Volume defaults to a conservative 25%, well below anything uncomfortable, and the tool warns when you push past 80%. The guidance is simple: start quiet, raise slowly, and never test your tolerance with sustained high volume through headphones. Frequencies near the top of the range are especially fatiguing, and prolonged exposure at high level is how hearing damage accumulates. A tone generator is a measuring instrument, not a maximum-volume demonstration — treat the levels with the same respect you would any professional audio gear.
Put it together and a frequency generator becomes a utility with surprising breadth. Tune an instrument by matching a note to the 440 Hz reference and adjusting until the beats disappear. Test a speaker or headphone by sweeping frequencies and listening for resonances and dead spots. Calibrate an audio path against a known sine. Explore sound therapy with gentle low tones. Because the tool couples frequency, waveform, and volume with a live waveform preview and a harmonic spectrum hint, you can hear the tone and see its structure simultaneously — and reason precisely about what you are listening to.