Skip to content

C++, Rust or the browser: the languages of five of my audio projects

When I start on an audio processor, the first thing I try to settle is where it will run: in a DAW (a program for making music, such as Logic or Reaper), in a program of its own, or in a browser tab. In my projects, the answer to that has picked the language more than the algorithm has.

Monster is a plugin that changes the stereo field of a track, for podcasts and music. It is C++ on JUCE, a framework for audio plugins, and my brother Anton designed its interface. JUCE builds one C++ code base into each of the plugin formats that DAWs load, such as VST3 and AU.

My compressor plugin went through two languages. It started from a C++ compressor that Chip Audette shared on his OpenAudio blog. I translated it into Python, added look-ahead and a filter on the sidechain, and plotted test signals to check the attack and release times against what they should be. The plugin itself is C++.

RS VST Host is a VST3 host in Rust: a program that loads plugins, as a DAW does, and keeps running when one crashes. It talks to the plugins through the C++ interfaces of VST3, and every call through them is unsafe in Rust: the compiler can't prove those raw pointers valid. 109 of its 1,414 tests also run under Miri and 564 under AddressSanitizer, two tools that find bad memory access at run time. I wrote about it in A VST3 host in Rust that keeps running when a plugin crashes.

In a browser, real-time audio code can run in an AudioWorklet, on the audio thread of the page, in blocks of 128 frames by default. My sidechain compressor runs in one. It lowers the music when a second signal, such as speech, comes in. Its interface is React, and it falls back to a ScriptProcessorNode, the older API for audio code, in browsers with no AudioWorklet.

The synth puts Rust in the browser. Its DSP is Rust with no dependencies. It compiles to a WebAssembly module of 14 KB, which exports a few plain functions and needs no glue code. The AudioWorklet gets the bytes of the module, compiles them, and calls render once for each block:

apps/synth/dsp/src/lib.rs
/// Renders up to 128 frames and returns how many it wrote.
#[no_mangle]
pub extern "C" fn render(frames: u32) -> u32 {
    let (synth, tables) = state();
    synth.render(frames, tables)
}

The same Rust also builds as native code, and cargo test runs its tests that way. A DAW plugin from it would still need a wrapper for a plugin format, and the synth doesn't have one.

You can play it here, with the mouse, a finger or the computer keyboard:

Synth

I also build plugins and audio tools for clients: services.