Toy synthesiser library in Rust.
For programmatic playback, please check out the cpal integration.
- Not too difficult syntax for writing your own tones (see examples)
- Basic filters (low-pass, high-pass, band-pass, band-reject, all-pass, comb, delay line, attack/decay envelope)
- Basic waveforms (sine, square, triangle, sawtooth, tangent, bastardised Karplus-Strong, and more)
- MIDI synthesis
- Basic sample synthesis (WAV)
- PCM or WAV output
You have to right-click > download the bigger ones to your computer because GitHub does not like to stream audio
- busy signal
- bell
- mtnking-pure pure square wave
- mtnking-envelope butchered Karplus-Strong square wave with attack and decay
- gymnopedie piano sample
- rustle
- clarinet sample
To run examples (list below)
cargo run --example EXAMPLE_NAME
To use as a library, add this to Cargo.toml
[dependencies.synthrs]
git = "https://github.com/gyng/synthrs"
rev = "the commit you want"
To write a custom tone to a WAV file
extern crate synthrs;
use synthrs::synthesizer::{ make_samples, quantize_samples };
use synthrs::wave::sine_wave;
use synthrs::writer::write_wav_file;
fn main() {
// Using a predefined generator
write_wav_file("out/sine.wav", 44_100,
&quantize_samples::<i16>(
&make_samples(1.0, 44_100, sine_wave(440.0))
)
).expect("failed to write to file");
// `make_samples` takes in the duration, sample rate, and a generator closure.
// It returns an iterator which `quantize_samples` wraps around (setting the bit depth).
write_wav_file("out/sine_closure.wav", 44_100,
&quantize_samples::<i16>(
&make_samples(1.0, 44_100, |t| (t * 440.0 * 2.0 * 3.14159).sin())
)
).expect("failed to write to file");
}
More examples are in examples/
.
Check out Cargo.toml
for the full example list.
simple
generates simple tones inout/
telecoms
generates phone tones inout/
filters
generates examples of audio filtering inout/
midi
synthesises a few MIDI files inout/
This generates WAV or PCM files which can be opened in Audacity. Example MIDI files are public domain as far as I can tell.
midi-to-wav, a simple cli to convert MIDI files to WAV
File > Import > Raw Data...
- Signed 16-bit PCM
- Little-endian
- 1 Channel (Mono)
- Sample rate: 44_100Hz (or whatever your samples generated have)
synthrs is licensed under the MIT License. See LICENSE
for details.