NIH-plug

repository·master·Indexed 25 days ago

https://github.com/robbert-vdh/nih-plug

An API-agnostic audio plugin framework written in Rust, designed to provide a simple, stateful API for audio plugin development. It includes support for GUI adapters such as egui, iced, and VIZIA, as well as a bundling tool via cargo-nih-plug or nih_plug_xtask. The repository also contains several example plugins, including Buffr Glitch, Crisp, Crossover, Diopser, Loudness War Winner, Puberty Simulator, and Safety Limiter.

Tokens
25K
Snippets
41
Records
164
Agent score
83%

What's inside nih-plug

  1. Overview of Safety Limiter functionality

    master

    Safety Limiter is a utility designed to prevent ear damage by providing a non-subtle audio alert rather than traditional peak limiting.

    Behavior:

    • When an input peak exceeds 0 dBFS or a user-specified threshold, the plugin switches the output to play SOS in Morse code.
    • The plugin also triggers this behavior if the input contains NaN or infinite values.
    • The Morse code signal gradually fades out as the input returns to safe levels.

    Unlike a brickwall limiter, this plugin does not alter the sound of your signal; it serves as an audible warning to prevent accidental exposure to high volumes during development or sound design.

  2. Overview of NIH-plug

    master
    NIH-plug is an API-agnostic audio plugin framework written in Rust. It provides a stateful yet simple plugin API designed to minimize unnecessary ceremony and 'magic' while allowing for easy experimentation with different approaches. The project includes both the framework and a collection of example plugins.
  3. Use Diopser for phase rotation

    master

    Diopser is a plugin that rotates the phase of a signal around a specific frequency without affecting its spectral content. This allows for emphasizing transients in ways that regular equalizers or dynamics processors cannot, particularly for low-pitched or wide-band sounds.

    Usage Tips:

    • Frequency Selection: Alt+click on the spectrum analyzer to enter a frequency value in Hertz or musical notes.
    • Musical Snapping: Hold down Alt/Option while dragging the filter frequency to snap to whole notes.
    • Safe Mode: Enabled by default to limit frequency range and filter stages. Disable it for more extreme settings, but be aware that low frequencies may introduce loud resonances. It is recommended to use a peak limiter after Diopser when safe mode is disabled.
    • DSP Optimization: Reduce the automation precision to lower the DSP load when changing filter frequency and resonance, though this may introduce aliasing or zipper noise.
    • Resetting Filters: Change the number of filter stages to immediately reset the filters and stop ringing.
  4. Define plugin parameters using the declarative system

    master

    NIH-plug provides a declarative parameter system using the #[derive(Params)] attribute.

    To define parameters:

    1. Add fields to your parameter struct using types like FloatParam, IntParam, BoolParam, or EnumParam<T>.
    2. Assign stable IDs to each parameter using the #[id = "foobar"] attribute.
    3. For discrete options, use a simple enum that derives the Enum trait with EnumParam<T>.
    4. Group parameters using the #[nested(group = "...")] attribute.

    To store non-parameter state that should be serialized (e.g., for presets), add fields to your Params object that implement Serde and annotate them with #[persist = "key"].

  5. Configure Crossover multi-out chains in Bitwig Studio

    master

    Crossover splits signals into two to five bands sent to auxiliary outputs. To access these bands in Bitwig Studio:

    1. Click the 'Show plug-in multi-out chain selector' button.
    2. Click 'Add missing chains' to enable the auxiliary outputs.

    Note: The main output will not output any audio; all signal is routed to the auxiliary chains.

    To avoid repeating this setup, right-click the device and save the configuration as a default preset. Alternatively, you can download a pre-configured Bitwig preset here and set it as the default for Crossover.

  6. Integrate nih_plug_xtask into your project

    master

    Since Cargo does not yet support running binaries directly from dependencies, you can use nih_plug_xtask as a library by creating a local xtask binary in your project. This allows you to use NIH-plug's bundling and utility commands without forking the repository.

    Follow these steps to set it up:

    1. Create an xtask binary: Run cargo new --bin xtask in your project root.
    2. Add to Workspace: Add the xtask directory to your main Cargo.toml workspace members.
    3. Add Dependency: Add nih_plug_xtask to your xtask/Cargo.toml dependencies.
    4. Implement Main: Call nih_plug_xtask::main() from your new xtask/src/main.rs.
    5. Configure Cargo Alias: Create a .cargo/config file to enable running the commands via cargo xtask.
  7. Install cargo-nih-plug

    master

    Since cargo-nih-plug is not yet published to crates.io, you must install it directly from the GitHub repository using cargo install.

    Note: If you are working within an NIH-plug project, it is recommended to use the built-in xtask integration instead of this standalone subcommand to ensure compatibility with your project version.

    cargo install --git https://github.com/robbert-vdh/nih-plug.git cargo-nih-plug