A radio is a bundle of small, specific failures, and each one has a sound people recognise. AM has a steep top-end wall, a rasp in the mids, a hum from the mains and a carrier that fades in and out as the ionosphere moves. FM is wide and clean until multipath hits it: then the programme dips in fast picket-fence nulls, hiss splashes in and the stereo image collapses toward mono. We built an AM/FM effect for our radio-style apps, tuned it by ear, and rewrote it as plain sample-by-sample DSP so it runs anywhere JavaScript does and gives the same result every time. We are releasing it: radiogrit.js, MIT licensed, on GitHub. Try it live with your own audio.
An update to an older note
In September we wrote “Faking AM & FM in Web Audio” and said the recipes would stay in-house. We changed our minds: this is that effect, rewritten without Web Audio and published in full.
Is there already one?
We looked on npm and GitHub in October 2026 for a small, dependency-free JavaScript library that simulates AM and FM reception (as opposed to generic lo-fi, vinyl-crackle or telephone filters) and did not find one. “We did not find one” describes our search, not a guarantee.
Using it
<script src="radiogrit.js"></script>
<script>
// channels: an array of Float32Array, e.g. from AudioBuffer.getChannelData()
const out = radiogrit.process(channels, sampleRate, { mode: "fm", seed: 3 });
// out.channels: one Float32Array per channel (FM stereo, AM dual mono)
// out.info.events: every fade, null and burst, with start and end times
</script>
The seed picks the radio's personality: mains frequency (50 or 60 Hz), whether hum or buzz is present, and when every event happens. amount scales the noise bed, eventRate scales how often things happen, and every feature has its own switch. Switching one off never changes what the others do, because each component draws from its own random stream. It works on Float32Array or Int16Array, mono or stereo, at 8 to 192 kHz, in a page, a Worker or Node.
What an AM radio does
The programme goes through three low-passes that make a steep wall near 4 kHz, a mid-range bump and a soft clip for rasp, and an AGC compressor. A slow flutter and a skywave fade envelope ride on the carrier. In a selective fade the tuning drifts down, a distorted copy of the programme blends in and a fizz blooms, which is the sound of a real fade turning ugly. Alongside, a separately synthesised noise bed adds mains hum, power-line buzz, hiss, a heterodyne whistle at 9 or 10 kHz plus a slow whine, crackle, lightning static and the fizz.
What an FM radio does
FM keeps the programme to 15 kHz: a 35 Hz high-pass, six cascaded low-passes, a little tone shaping, a soft clip, a compressor and a split-band de-esser. A 1 Hz pulse wobbles the level. Then the multipath: picket-fence dips, antenna fizz, antenna knocks, and a mid/side stereo blend whose separation collapses toward mono in the same places. The bed (hiss, the splash that comes with the dips, power-tool sparks, crackle and rasp, a thin whistle near 15 kHz and the 19 kHz pilot) goes through the same blend.
The ingredients, one at a time
Each panel is a run with only that feature on, minus a run with everything off, so you can see what each part contributes.
eventRate: 60, because at the default rate the first one starts 45 to 180 seconds in.The programme path
With white noise at −28 dBFS the AM path passes the 1 kHz level down to about 4.5 kHz and is 20 dB below it by about 5.7 kHz. The FM path runs to a ceiling near 16 kHz. Both depend on level, because both have compressors and soft clips: louder input fills in above the FM ceiling with clipper harmonics (the 20 dB crossing moves from 17.3 kHz at −28 dBFS to 21.5 kHz at −16 dBFS). The FM path also lifts the 5 to 15 kHz region by roughly 10 dB over the 1 kHz level on this noise; we have not isolated which stage causes that.
Fades, nulls and the stereo image
Levels, seeds and dials
hum off or lower amount if it is too much.eventRate, a little less than proportionally at the top.The numbers
Measured in Node 24 on one Windows PC with a synthetic, seeded programme (a formant voice plus a wide-stereo pad); npm run measure regenerates every number and figure.
| What | Result |
|---|---|
| Code size | 38 KB as shipped (with licence and comments), 12.3 KB gzipped, AM and FM together |
| Speed, 20 s stereo clip, one core | AM 47.9x and FM 30.6x real time at 48 kHz; AM 113.6x and FM 92.8x at 16 kHz |
| AM programme path | −3 dB re 1 kHz at about 4.5 kHz, −20 dB at about 5.7 kHz |
| FM pilot | present at 19.000 kHz at 48 kHz sampling; skipped at 32 kHz, where it would be above Nyquist |
| Amount | noise level follows 20 log10(amount) to within 0.01 dB (0.25 to 4) |
| Determinism | same input, mode and seed give identical samples; Node 24 and Chromium gave the same regression hashes |
How we tested it — and what we have not
The test page in the download runs 59 checks in your own browser, offline (the same ones run in Node): output shape and length, finite samples and no clipping, determinism, input never modified, Int16 input, event schedules and eventRate, amount scaling the bed linearly, silence staying silent with every feature off, the AM wall and the FM ceiling on white noise, dual-mono AM, hum, heterodyne and independent random streams, FM stereo behaviour, the picket-fence dips, the pilot and ceiling whistle (and their absence at low sample rates), sample rates from 16 to 96 kHz, the async API and its cancellation, error cases, and fixed regression hashes. All passed in Node 24 and Chromium.
The honest limits: it is a character simulation, not a model of a specific receiver, and we have not compared it with real radio recordings or run a listening test. It is not sample-identical to our earlier Web Audio version, and we did not measure how far it differs. It processes a whole clip in memory (no streaming), short clips may get few events unless you raise eventRate, hum can be loud on seeds that roll it, and it has only been run in Node and Chromium, so other engines may differ in the last float bits. “AM” and “FM” are generic terms here; this is not affiliated with any broadcaster or radio maker.
Download
The source is on GitHub: github.com/dialersapps/radiogrit (issues and pull requests welcome). The downloads below are plain files with nothing to build, no tracking and no outside requests:
- radiogrit-1.0.0.zip — everything in one file (library, ES module, demo, tests, figure tools, figures, README, licence)
- radiogrit.js — the library (plain script tag,
require()and Workers) - radiogrit.mjs — the same code as an ES module
- demo.html — process your own audio as AM or FM (everything stays in your browser)
- test.html — the in-browser test suite
- README.md — API, options, limits
- LICENSE — MIT, copyright Dialer's Apps 2026
The code was written by Dialer's Apps. The filter shapes, levels and event timings follow what we tuned by ear for our earlier Web Audio effect; this is a fresh implementation as plain sample-by-sample DSP and it contains no code copied from another project.