mathr / blog / #

Low-latency Disco

disco/designer screenshot

Back in 2019 I experimented a bit with Haar wavelets for audio analysis and resynthesis. The main idea was splitting audio into octaves, calculating energy per octave, then doing the same for each octave over a longer time period, calculating energy per octave of rhythm frequencies for each octave of audible frequencies. I intended to use these rhythm fingerprints for discriminating (hence the name for the project, "Disco") between speech and music, but didn't get very far at the time (more recently I had success distinguishing between genres of music, using the rhythm fingerprints as input to an artifical neural network).

I made a small graphical interface for drawing rhythm fingerprints, called "disco/designer", with a web version, and played a gig or two using it as an instrument, but the main problem was that it was very high latency - it took so long between drawing a shape and the sound to change that it neither easy nor fun to play.

Meanwhile, in 2021 I made Deep Disco, which ported something similar to the rhythm fingerprint noise resynthesis to classic Amiga A500: with a 7 MHz CPU there're not many cycles spare, so the code has to be tight and optimized (I traded speed vs space by using many lookup tables). This version didn't use Haar wavelets, instead it used a variant of the Voss-Clarke-Gardner-McCartney pink noise generation algorithm. The pink noise algorithm runs in realtime, overlaying many noise streams at different octaves, picking the octave to change by counting the number of trailing zeros of the audio sample index.

Today I ported parts of the Deep Disco implementation back to disco/designer, allowing much lower-latency response in the sound from drawing in the graphical user interface, which makes playing with it much more fun. The texture of the sound is different (due to the different synthesis method), but some aspects of the 2019 version were bad apart from the latency (weird volume fades and jumps), and the 2022 version is responsive and usable as an instrument. I kept both web versions online at different URLs so you can compare yourself, see the Disco homepage for links and source code.