6 releases

0.1.4 Jan 15, 2022
0.0.3 Jan 13, 2021

#939 in Audio


Used in minidsp-daemon

Apache-2.0 and LGPL-3.0

665KB
17K SLoC

This crate provides a high level API for accessing and configuring a MiniDSP device. To get started, start by instantiating the right transport. If the device is locally connected via USB, use transport::hid::HidTransport. If using the WI-DG or connecting to an instance of this program running the server component, see transport::net::StreamTransport.

use anyhow::Result;
use futures::StreamExt;
use minidsp::{
    transport::{hid, Multiplexer},
    Builder, Channel, Gain, MiniDSP,
};

#[tokio::main]
async fn main() -> Result<()> {
    // Get a list of local devices
    let mut builder = Builder::new();
    builder.with_default_usb().unwrap();

    let mut devices: Vec<_> = builder
        // Probe each candidate device for its hardware id and serial number
        .probe()
        // Filter the list to keep the working devices
        .filter_map(|x| async move { x.ok() })
        .collect()
        .await;

    // Use the first device for further commands
    let dsp = devices
        .first()
        .expect("no devices found")
        .to_minidsp()
        .expect("unable to open device");

    let status = dsp.get_master_status().await?;
    println!("Master volume: {:.1}", status.volume.unwrap().0);

    // Activate a different configuration
    dsp.set_config(2).await?;

    // Set the input gain for both input channels
    for i in 0..2 {
        dsp.input(i)?.set_gain(Gain(-10.)).await?;
    }

    // Mute the last output channel
    dsp.output(3)?.set_mute(true).await?;

    Ok(())
}

Dependencies

~15–28MB
~402K SLoC