Shepard-Risset Flanger in Web Audio
Before they formally became the supergroup Swedish House Mafia, the trio collaborated with Laidback Luke in 2009 to produce Leave The World Behind. For the uninitiated:
The track at 128 beats per minute in E♭ minor with stripped-back production yet impeccable sound design, the defining feature of the group's first era. Infamously, its kickdrum has been sampled in countless tracks by other producers serving as EDM's staple next to only the Pryda snare. But beyond the percussion there is this white-noise riser percolating in the background, driving the tension throughout. The FX stem during the drop looks like:
The broadband noise drowns out the pitched movement, so it helps to fold the spectrum onto a musical grid. Instead of plotting raw frequency, we sum the energy into one bin per semitone, then subtract a local noise floor (the median level across the surrounding octave) from every bin.
What falls out from this analysis is that the perceived pitch of the riser increases a semitone a bar, with its lowest point around B♭2. Clearly, though, I'm burying the lede. This is a near-textbook example of a Shepard-Risset glissando: an auditory illusion perceived as a constant increase in pitch. The illusion comes from stacking several voices a fixed interval apart and bending them upward together. Each voice fades in at the bottom of the range and out at the top, with the combined signal remaining at a constant amplitude. This leaves no audible "seam" for the ear to catch. What's interesting in this instance, though, is that the Swedes didn't reach for traditional tonal oscillators. Instead, they used white noise fed through a flanger.
Flanging and Pitch
A flanger is built around a very short delay line (i.e. measured in milliseconds) which is then combined with the dry signal that fed it, with optional feedback:
The summation creates a comb filter with evenly spaced peaks and notches set by the length of the delay; where a wavelength fits neatly into the delay time the two reinforce, where it lands out of phase they cancel.
By modulating the delay time with an LFO you can vary this interference over time, creating the classic flanged sound.
Point such a filter at white noise and you get tone; white noise carries energy at every frequency, so the comb's teeth always have something to grab. The ear hears that harmonic series as a single tone at the fundamental 1/D.
Web Audio
The Web Audio API models sound as a graph. Every processing block (e.g. an oscillator, a filter, or a gain stage) is an AudioNode attached to an AudioContext, and you build your signal chain by calling connect on those nodes down to the context's destination. The graph runs on a dedicated audio thread, so once it is patched the main thread only has to nudge the odd parameter.
;
// A 440 Hz saw wave, shaped by a low-pass filter, into a gain stage.
;
;
;
filter;
gain;
ctx.destination;
// Browsers generally require user input for audio.
"click",;
Interestingly the API doesn't come with a built-in noise generator, so we have to build our own. The recommended method is to create an AudioWorklet which runs off-thread, much like a web worker.
"white-noise", WhiteNoiseProcessor;
We can implement the Shepard-Risset flanger in such a processor like so:
"shepard-risset-flanger", ShepardRissetFlangerProcessor;
Putting it all together: