gyng / synthrs

Toy audio synthesizer library in Rust with basic MIDI support.

Home Page:https://gyng.github.io/synthrs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

synthrs

Documentation

Toy synthesiser library in Rust.

For programmatic playback, please check out the cpal integration.

Features

  • 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

Integrations

Examples (loud)

You have to right-click > download the bigger ones to your computer because GitHub does not like to stream audio

Try

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/.

Examples

Check out Cargo.toml for the full example list.

  • simple generates simple tones in out/
  • telecoms generates phone tones in out/
  • filters generates examples of audio filtering in out/
  • midi synthesises a few MIDI files in out/

This generates WAV or PCM files which can be opened in Audacity. Example MIDI files are public domain as far as I can tell.

cpal

Example usage with cpal

midi-to-wav

midi-to-wav, a simple cli to convert MIDI files to WAV

wasm

Audacity PCM import settings

File > Import > Raw Data...

  • Signed 16-bit PCM
  • Little-endian
  • 1 Channel (Mono)
  • Sample rate: 44_100Hz (or whatever your samples generated have)

License

synthrs is licensed under the MIT License. See LICENSE for details.

About

Toy audio synthesizer library in Rust with basic MIDI support.

https://gyng.github.io/synthrs/

License:MIT License


Languages

Language:Rust 100.0%