Prefix Stretch

Drop an audio file anywhere

Waiting for audio

—

0%
18%

What is this?

Inspired by Marc Evanstein / music․py’s video about the average spectral signature of various songs, I wondered whether you could use prefix sums to quickly compute the average magnitude spectrum over any part of a song - from a precise moment to the whole song, or anything in between. Of course, this is exactly what prefix sums were made for, so it had to be tried!

I asked Codex 5.6 to create this single-page HTML instrument. As a result of using machines, I make no claims about this code and, to the extent legally possible, release it into the public domain under CC0 1.0 Universal. It's a single html file, so just download it or right-click view source. Do with it what you want!

Anyway, some more technical thoughts: with this kind of spectral resynthesis, you have to decide what to do about phase. A phase vocoder measures how phase changes over time in each bin and applies those changes to a rotating output phasor. This lets it reproduce frequencies that fall between FFT-bin centres, although conventional phase vocoders tend to smear transients. Algorithms like PaulStretch - as far as I understand - do something simpler: they randomise spectral phase, leading to an even breathier sound.

In this quick prototype, I compute the phase change for each bin from one frame to the next, normalize it to a unit vector, weight it by the geometric mean magnitude of the two frames, and compute prefix sums for both the weighted vector and its weight. This gives us an averaged phase rotation per bin for phase-vocoder-style resynthesis, as well as a coherence value: a measure of how consistent that phase advance is. I use that coherence to automatically add phase diffusion to bins with lots of phase variation. This means you don’t need blanket phase randomisation quite as much - although it remains available through the “extra phase randomisation” slider above.

Anyway, this was fun to try and can be an enjoyable instrument to play interactively. Try different source audio, and enjoy the original video.

Cheers - @mmalex.bsky.social