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.

How far to trust it. This is a character simulation: the filters, levels and event timings were tuned by ear to sound like radio. It does not model a particular receiver or radio propagation, and we have not compared it with recordings of real radios or run a listening test. Every measurement below uses a synthetic signal.

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.

API diagram: input, options and process() produce channels, info.events and info.levelsDb
Figure 1. The whole API: input and options in, channels and an event list out.

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.

AM signal flow: fold to mono, band wall, mid rasp, AGC, flutter, skywave fade, mistune, clean/wet blend, with the noise bed summed in at the end
Figure 2. The AM chain. The amber boxes are the fade machinery; the dashed group is the noise bed.
AM spectrograms: clean programme, through the AM radio with a steep wall near 4 kHz and a thin heterodyne line near 10 kHz, and only the added interference
Figure 3. Before, after, and only what the radio added. Above the 4 kHz wall there is no programme, only the bed: hiss, the 10 kHz heterodyne line and the vertical stripes of static and crackle.

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.

FM signal flow: high-pass, 15 kHz ceiling, tone, soft clip, compressor, de-esser, treble trim, programme pulse, picket fence, antenna fizz, antenna knock and stereo blend, with the noise bed joining at the blend
Figure 4. The FM chain. The noise bed joins at the stereo blend, so it collapses with the programme.
FM spectrograms: clean programme, through the FM radio with a ceiling at 15 kHz and a pilot line at 19 kHz, and only the added interference
Figure 5. FM before, after, and only what was added. The green bar around 3 to 5 s is an antenna-fizz train; the bright lines at the bottom are the 15 kHz ceiling whistle and the 19 kHz pilot.

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.

Eight small spectrograms, one per AM feature: hum, buzz, hiss, heterodyne, crackle, sferics, selective fading and flutter
Figure 6. The AM ingredients. Hum is a harmonic stack at the bottom, buzz a hash that ticks at twice the mains rate, the heterodyne a thin drifting line, static a set of vertical stripes.
Eight small spectrograms, one per FM feature: hiss, picket fence, crackle, power tool, ceiling whistle, pilot, programme pulse and stereo side channel
Figure 7. The FM ingredients. The last panel is the stereo difference signal, which vanishes in the dips. The power tool is drawn at eventRate: 60, because at the default rate the first one starts 45 to 180 seconds in.
Close-up waveforms: AM crackle burst, lightning static, electrical tone, power-line buzz, FM power-tool sparks and FM crackle
Figure 8. Close-up waveforms of single artefacts (time spans differ per panel).
Mains hum spectra for a 50 Hz seed and a 60 Hz seed: peaks at the mains frequency and its harmonics, with gaps at multiples of four
Figure 9. Mains hum is a square wave at 1x and 2x the mains frequency (3x on some seeds) through a low-pass, so every harmonic appears except multiples of four.

The programme path

Frequency response of the AM and FM programme paths at three input levels
Figure 10. Frequency response of the programme path with interference off, measured with white noise at three levels.

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.

AM long-term average spectrum: clean input, AM output and the added interference, with the mains hum peaks and the heterodyne line marked
Figure 11. AM long-term average spectrum: the wall, the hum peaks at 60 Hz and its harmonics, the heterodyne line near 10 kHz.
FM long-term average spectrum: clean input, FM output and the added interference, with the 15 kHz ceiling and the 19 kHz pilot marked
Figure 12. FM long-term average spectrum: the ceiling and the 19 kHz pilot line above it.

Fades, nulls and the stereo image

AM carrier gain curves for four seeds over 40 seconds, the input and output levels for one seed, and an event timeline
Figure 13. Skywave fades for four seeds over 40 s. In our 12-seed, 40 s runs the carrier sagged between 2.5 and 5.6 dB at its deepest: what makes a fade sound like one is the selective part (mistuning, rasp, fizz), not the level change.
FM multipath over 30 seconds: programme gain dips, stereo separation collapsing toward mono in the same places, side-to-mid energy of the output against the input, and an event timeline
Figure 14. FM multipath over 30 s. The programme dipped by as much as 18 dB, the separation fell as low as 0.07 (almost mono), and the output's side-to-mid energy ratio fell as low as −21 dB, against a median of −6 dB in the clean input.

Levels, seeds and dials

Diagram of level handling: programme normalised to the input RMS; noise components scaled by amount and by a clamped input level
Figure 15. Levels follow the programme: the programme is normalised to the input level and the noise is scaled by the input level, so quiet clips do not drown and loud ones do not lose their noise.
Bar charts of the average level of each AM and FM ingredient relative to the programme
Figure 16. Average level of each ingredient against the programme (RMS over 14 s; bursty ingredients are far louder while they last). Mains hum is the loudest single ingredient when a seed rolls it, so switch hum off or lower amount if it is too much.
Diagram: seed and component name are hashed into a 32-bit value that seeds a mulberry32 stream per component
Figure 17. Why switching a feature off never disturbs the others: one named random stream per component.
Table of what seeds 1 to 12 roll for AM: mains frequency, hum, buzz, selective-fade chance, wander, deepest fade, lightning-static and crackle counts
Figure 18. What seeds 1 to 12 roll for AM. Seeds 3 and 6 have no hum; seeds 8 and 12 have no buzz.
The amount dial scales the noise bed by 20 log10 of its value; event counts grow with eventRate; AM spectrograms at three amounts
Figure 19. The two main dials. The added noise level follows 20 log10(amount) to within 0.01 dB for both modes; event counts grow with 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.

WhatResult
Code size38 KB as shipped (with licence and comments), 12.3 KB gzipped, AM and FM together
Speed, 20 s stereo clip, one coreAM 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 pilotpresent at 19.000 kHz at 48 kHz sampling; skipped at 32 kHz, where it would be above Nyquist
Amountnoise level follows 20 log10(amount) to within 0.01 dB (0.25 to 4)
Determinismsame input, mode and seed give identical samples; Node 24 and Chromium gave the same regression hashes
Processing speed of AM and FM from 16 to 48 kHz, in multiples of real time
Figure 20. Speed as multiples of real time at five sample rates.

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.