• Stars
    star
    150
  • Rank 247,323 (Top 5 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A safe, fast, and modular framework to create LV2 plugins, written in Rust

Rust-LV2

Build Status Current Crates.io Version

A safe, fast, and ergonomic framework to create LV2 plugins for audio processing, written in Rust.

This library is a work in progress.

It provides the following features, through the LV2 Core specification:

  • Lightweight, realtime non-blocking and allocation-free audio processing.
  • Generates all the boilerplate to make a LV2 plugin binary, usable by any LV2 host.
  • Any number of ports / Any channel mapping, which can be different for input and output.
    This obviously includes Mono, Stereo, Surround, etc., any configuration your CPU can handle.
  • Can be extended to support any additional features, extensions and port types.
    They can be official, unofficial or completely custom.

Through the LV2 official additional specifications, this library also provides many additional features, including:

  • MIDI processing
  • Serialization of custom data structures, and plugin-plugin or plugin-GUI communication and property manipulation
  • State management
  • Asynchronous work processing
  • Custom Graphical User Interfaces, both in a toolkit-agnostic and in a platform-agnostic way (Not yet implemented)
  • Presets handling (Not yet implemented)
  • ... and more! (Not yet implemented either)

Note that this library will only provide Rust bindings for the official LV2 specifications, however it is compatible with any other arbitrary or custom specification, and other, external crates are able and welcome to provide Rust bindings to any other specification that will integrate with this library.

Example

This example contains the code of a simple amplification plugin. Please note that this isn't the only thing required to create a plugin, see the documentation below for more details.

// Import everything we need.
use lv2::prelude::*;

// The input and output ports are defined by a struct which implements the `PortCollection` trait.
// In this case, there is an input control port for the gain of the amplification, an input audio
// port and an output audio port.
#[derive(PortCollection)]
struct Ports {
    gain: InputPort<Control>,
    input: InputPort<Audio>,
    output: OutputPort<Audio>,
}

// The plugin struct. In this case, we don't need any data and therefore, this struct is empty.
//
// LV2 uses URIs to identify types. This association is expressed via the `UriBound` trait,
// which tells the framework that the type `Amp` is identified by the given URI. The usual
// way to implement this trait is to use the `uri` attribute.
#[uri("urn:rust-lv2-book:eg-amp-rs")]
struct Amp;

// The implementation of the `Plugin` trait, which turns `Amp` into a plugin.
impl Plugin for Amp {
    // Tell the framework which ports this plugin has.
    type Ports = Ports;

    // We don't need any special host features; We can leave them out.
    type InitFeatures = ();
    type AudioFeatures = ();

    // Create a new instance of the plugin; Trivial in this case.
    fn new(_plugin_info: &PluginInfo, _features: &mut ()) -> Option<Self> {
        Some(Self)
    }

    // Process a chunk of audio. The audio ports are dereferenced to slices, which the plugin
    // iterates over.
    fn run(&mut self, ports: &mut Ports, _features: &mut ()) {
        let coef = if *(ports.gain) > -90.0 {
            10.0_f32.powf(*(ports.gain) * 0.05)
        } else {
            0.0
        };

        for (in_frame, out_frame) in Iterator::zip(ports.input.iter(), ports.output.iter_mut()) {
            *out_frame = in_frame * coef;
        }
    }
}

// Generate the plugin descriptor function which exports the plugin to the outside world.
lv2_descriptors!(Amp);

About this framework

Q&A

Does my host program support it?

Plugins created with rust-lv2 are compatible to all LV2 hosts that comply to the specifications. If your application uses lilv, it's a good sign that it will support your plugin. Some prime examples are Carla and Ardour.

Can I host plugins with rust-lv2?

Currently, hosting plugins is not supported. This project was initialy started to create plugins using safe Rust and therefore, it is very plugin-centric. There are plans for integrated plugin hosting or a spin-off project, but those won't start in the near future.

However, there is a lot of code that can be re-used for a hosting framework. If you want to create such a framework, you should take a look at lv2-sys, urid, and lv2-atom.

A bare hosting framework would require an RDF triple store which can load Turtle files, an internal store for plugin interfaces and their extensions, a centralized URID map store, and a graph based work scheduling system to execute run functions in order.

Documentation

There are multiple valuable sources of documentation:

Features

Internally, this framework is built of several sub-crates which are re-exported by the lv2 crate. All dependencies are optional and can be enabled via features. These are:

  • lv2-atom: General data IO.
  • lv2-core: Implementation of the core LV2 specification.
  • lv2-midi: MIDI message extension for lv2-midi. Support for the wmidi crate can be enabled with the wmidi feature.
  • lv2-state: Extension for LV2 plugins to store their state.
  • lv2-time: Specification to describe position in time and passage of time, in both real and musical terms.
  • lv2-units: Measuring unit definitions.
  • lv2-urid: LV2 integration of the URID concept.
  • lv2-worker: Work scheduling library that allows real-time capable LV2 plugins to execute non-real-time actions.
  • urid: Idiomatic URID support.

Sub-crates with an lv2- prefix implement a certain LV2 specification, which can be looked up in the reference. Enabling a crate only adds new content, it does not remove or break others.

There are also feature sets that account for common scenarios:

  • minimal_plugin: The bare minimum to create plugins. Includes lv2-core and urid.
  • plugin: Usual crates for standard plugins. Includes lv2-core, lv2-atom, lv2-midi, lv2-urid, and urid. This is the default.
  • full: All sub-crates.

Supported targets

Rust-LV2 uses pregenerated C API bindings for different targets in order to increase usability and building speed. Rust has a lot of supported targets, but our maintaining power is limited and therefore, only certain targets can be supported. We've ranked different targets in Tiers, just like rustc does, which gives you a general understanding of what to expect of a target. The tables below list the supported targets, the used binding in the lv2-sys crate, and, if applicable, the maintainer and the last verification of that target.

The bindings itself are generated with the LV2 systool and verified by building the example plugins of the book and testing them with a host of that target.

Tier 1

A Tier 1 target for rust-lv2 also has to be a Tier 1 target of rustc. You can check the platform support page to see which targets are included and what they provide. Additionally, there has to be a maintainer of rust-lv2 who has access to a machine that runs this target and who can generate and verify bindings on this machine. This means that if you have a problem running your code on a Tier 1 target, there will be a maintainer who can help you.

Target Binding Maintainer Last Verification
x86_64-unknown-linux-gnu linux/x86_64.rs @Janonard 10. of May 2020, using Carla v2.1, running on Arch Linux
x86-unknown-linux-gnu linux/x86.rs @Janonard 16th of May 2020, using Carla v2.1, running on Linux Mint 19.3 32-bit

Tier 2

A Tier 2 target is a target that is at least in Tier 2 of rustc and has a generated binding. However, it might not work (well) and there might not be a maintainer who has access to a machine that runs this target and who can generate and verify bindings on this machine. This means that if you have a problem running your code on a Tier 2 target, you're stepping into uncharted territory.

Target Binding
aarch64-unknown-linux-gnu aarch64.rs
arm-unknown-linux-gnueabi arm.rs
arm-unknown-linux-gnueabihf arm.rs
armv5te-unknown-linux-gnueabi arm.rs
armv7-unknown-linux-gnueabi arm.rs
armv7-unknown-linux-gnueabihf arm.rs
thumbv7neon-unknown-linux-gnueabihf arm.rs
x86_64-pc-windows-msvc windows.rs

License

Licensed under either of

at your option.

More Repositories

1

cpal

Cross-platform audio I/O library in pure Rust
Rust
2,614
star
2

rodio

Rust audio playback library
Rust
1,690
star
3

vst-rs

VST 2.4 API implementation in rust. Create plugins or hosts. Previously rust-vst on the RustDSP group.
Rust
973
star
4

dasp

The fundamentals for Digital Audio Signal Processing. Formerly `sample`.
Rust
720
star
5

rust-portaudio

PortAudio bindings and wrappers for Rust.
Rust
373
star
6

deepspeech-rs

Rust bindings for the deepspeech library
Rust
295
star
7

dsp-chain

A library for chaining together multiple audio dsp processors/generators, written in Rust!
Rust
287
star
8

lewton

Rust vorbis decoder
Rust
250
star
9

vst3-sys

Raw Bindings to the VST3 API
Rust
210
star
10

rust-jack

Decent jack bindings for rust
Rust
204
star
11

baseview

low-level window system interface for audio plugin UIs
Rust
184
star
12

synth

A polyphonic Synth type whose multiple oscillators generate sound via amplitude and frequency envelopes, implemented in Rust. DEPRECATED: This is a very old crate with very old design patterns and is no longer maintained. You might be interested in checking out `dasp` for composing your own synth instead.
Rust
172
star
13

coreaudio-rs

A friendly rust interface to Apple's Core Audio API.
Rust
169
star
14

audrey

A crate to simplify reading, writing and converting between a variety of audio formats.
Rust
114
star
15

ogg

Ogg container decoder and encoder written in pure Rust
Rust
97
star
16

rimd

Library for handling Midi and Standard Midi Files in Rust
Rust
77
star
17

wmidi

Rust midi encoding and decoding library.
Rust
63
star
18

pitch_calc

A library for musical pitch conversions! Provides functions and methods for converting between frequency (hz), midi-step, letter-octave and mels.
Rust
60
star
19

coreaudio-sys

Raw bindings to the OSX CoreAudio framework generated by bindgen (see coreaudio-rs for a more rust-esque wrapper).
Rust
59
star
20

sound_stream

A Rust audio IO stream in the style of an "Event Iterator" driven by PortAudio.
Rust
57
star
21

time_calc

A library for music/DSP time conversions! Provides functions and methods for converting between ticks, ms, samples, bars, beats and measures.
Rust
49
star
22

musical_keyboard

A small lib for converting keyboard input into musical notes.
Rust
26
star
23

mp3

Rust MP3 decoder project
Rust
23
star
24

sampler

A polyphonic sampler instrument that supports unique sample mappings across both frequency and velocity ranges. DEPRECATED: This is a very old crate with very old design patterns and is no longer maintained. You might be interested in checking out `dasp` for composing your own sampler instead.
Rust
23
star
25

areweaudioyet

Are We Audio Yet?
CSS
18
star
26

simplemad

A Rust interface for the MPEG audio (MP1, MP2, MP3) decoding library libmad
Shell
17
star
27

caf

Rust decoder for Apple's Core Audio Format (CAF)
Rust
14
star
28

envelope

An interpolatable Envelope type along with a generic 2D Point, useful for controlling parameters over time.
Rust
13
star
29

website

Website for all things audio in the Rust programming language
HTML
10
star
30

vst2-sys

Bindings for the VST 2.4 API.
Rust
9
star
31

instrument

Converts discrete note events to a continuous signal of amplitude and frequency frames over N number of voices.
Rust
8
star
32

rnnoise-c

Rust bindings to Xiph's rnnoise denoising library
Rust
7
star
33

rms

A simple type for calculating and storing the RMS given some buffer of interleaved audio samples.
Rust
7
star
34

volume

A simple dsp-chain node for multiplying the amplitude of the output buffer by some volume.
Rust
6
star
35

panning

A variety of utilities related to audio panning in Rust.
Rust
5
star
36

lyra

Feature extraction POC
Rust
4
star