Tuun is an interactive sound and music generation system. It's based on the idea of using programming languages to specify sounds and music.
Tuun serves several purposes, roughly in this order:
- As a vehicle to help me (@djspoons) learn about sound and music and Rust.
- As a system for interactively exploring how sounds and music are created.
- As a system for performing and recording music.
Tuun can be built as both a native app and for the web using WebAssembly.
Visit the Tuun Documentation for more information about Tuun waveforms and expressions. It includes many interactive examples and an online playground.
If you're looking for more examples, some of my writing also makes use of Tuun.
- Install Rust
- Install sdl2 and sdl2_ttf
On my Mac this means:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
brew install sdl2 sdl2_ttf
export LIBRARY_PATH="$LIBRARY_PATH:$(brew --prefix)/lib"
For help running the native Tuun application:
cargo run --bin tuun -- --help
Tuun reads specifications both from files and in the user interface. Files supplied with the --context_file (or -C) flag should be bindings of the form var = expr separated by commas. Files supplied with the --program_file (or -P) flag should be expressions (one per line) that evaluate to waveforms. Specifications supplied the --program (or -p) should also be expressions that evaluate to waveforms. All of these flags can be supplied multiple times.
cargo run --bin tuun -- -C context.tuun -p '$440 * Qw'
Or for a slightly more complex example:
cargo run --bin tuun -- -C context.tuun -p 'let h = harmonica(Q, 440) in <[h, h, h, h]>' -p 'pulse((X + 1) * 0.5, Y * 440) * 0.1'
Try playing the second program, holding the option key, and moving your mouse to the left and right.
Once Tuun has started, use the following keys to navigate and edit.
In "select" mode (when a solid triangle appears at the left-hand side):
- enter - switch to "edit" mode for the current program
- cmd + enter - evaluate current program and play the resulting waveform at the beginning of the next measure and every measure afterward
- shift + cmd + enter - evaluate current program and play the resulting waveform at the beginning of the next measure and every other measure afterward
- escape - stop playback of future iterations of the current waveform
- cmd + escape - immediate stop playback of the current waveform
- (hold) option - switch to "slider" mode
- R - reload all context files
- L - load all program files (and overwrite the current programs)
- S - save all programs to a file
- D - evaluate the current program and dump the waveform to stdout
- number - select the program with the given number
- down - select the next program
- up - select the previous program
In "edit" mode (when the current program is rendered in white):
- enter - evaluate the current program and play the resulting waveform at the beginning of the next measure
- cmd + enter - evaluate current program and play the resulting waveform at the beginning of the next measure and every measure afterward
- shift + cmd + enter - evaluate current program and play the resulting waveform at the beginning of the next measure and every other measure afterward
- escape - switch to "select" mode
In "slider" mode (slider marks at top and left turn green):
- move mouse (or track-pad) left and right - adjust "X" slider
- move mouse (or track-pad) up and down - adjust "Y" slider
- (release) option - return to "select" mode
Tuun can run in web browsers via WebAssembly! This allows you to experiment with the synthesizer without installing native dependencies.
# Install wasm-pack (only needed once)
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
# Build the WASM package
./build-wasm.sh
# Serve locally
cd web && python3 -m http.server 8080Then open http://localhost:8080 in your browser.
The web version provides:
- Real-time audio synthesis using the Web Audio API
- Interactive expression editor
- Adjustable sample rate and duration
- Expression parser and optimizer
Note: The web version focuses on the core synthesis engine. The native version provides additional features like the interactive UI with sliders, file I/O, and real-time waveform visualization.
The web version requires:
- Chrome 66+ or Edge 79+
- Firefox 60+
- Safari 11.1+
All browsers must support:
- WebAssembly
- Web Audio API
- ES6 modules