Skip to content

RustAudio/rust-jack

Repository files navigation

JACK (for Rust)

Rust bindings for JACK Audio Connection Kit.

Crates.io Docs.rs Test License ❤️ Sponsor

Overview

JACK is a low-latency audio server that allows multiple applications to share audio and MIDI devices and route signals between each other. This crate provides safe Rust bindings to create JACK clients that can process audio and MIDI in real-time.

Documentation

Quick Example

use std::io;

fn main() {
    // Create a JACK client
    let (client, _status) =
        jack::Client::new("rust_jack_simple", jack::ClientOptions::default()).unwrap();

    // Register input and output ports
    let in_port = client
        .register_port("input", jack::AudioIn::default())
        .unwrap();
    let mut out_port = client
        .register_port("output", jack::AudioOut::default())
        .unwrap();

    // Create a processing callback that copies input to output
    let process = jack::contrib::ClosureProcessHandler::new(
        move |_: &jack::Client, ps: &jack::ProcessScope| -> jack::Control {
            out_port.as_mut_slice(ps).clone_from_slice(in_port.as_slice(ps));
            jack::Control::Continue
        },
    );

    // Activate the client
    let _active_client = client.activate_async((), process).unwrap();

    // Wait for user to quit
    println!("Press enter to quit...");
    let mut input = String::new();
    io::stdin().read_line(&mut input).ok();
}

See the examples directory for more.

Installation

Add to your Cargo.toml:

[dependencies]
jack = "0.13"

JACK Server Setup

A JACK server must be running for clients to connect. Install one of:

By default, clients request the server to start on demand. Use ClientOptions::default() or the NO_START_SERVER flag to disable this.

Testing

Tests require a dummy JACK server and must run single-threaded:

./dummy_jack_server.sh &
cargo nextest run

If cargo nextest is unavailable: RUST_TEST_THREADS=1 cargo test

Troubleshooting

  • Use cargo nextest instead of cargo test for better handling of timing-sensitive tests
  • Try libjack2 or pipewire-jack if tests fail with your current JACK implementation

License

MIT - see LICENSE for details.

About

Rust bindings for JACK. A realtime sound server for audio and midi IO

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 27

Languages