Skip to main content

Module audio

Module audio 

Source
Expand description

USB Audio Class 1 (UAC1) and 2 (UAC2) functions.

The Linux kernel configuration option CONFIG_USB_CONFIGFS_F_UAC1 must be enabled for UAC1 and CONFIG_USB_CONFIGFS_F_UAC2 must be enabled for UAC2.

§UAC1 Example

use usb_gadget::{
    default_udc,
    function::audio::{Channel, Uac1},
    Class, Config, Gadget, Id, Strings,
};

// capture: stereo, 48000 Hz, 16 bit, playback: stereo, 48000 Hz, 16 bit
let (audio, func) = Uac1::new(Channel::new(0b11, 48000, 2), Channel::new(0b11, 48000, 2));

let udc = default_udc().expect("cannot get UDC");
let reg = Gadget::new(
    Class::INTERFACE_SPECIFIC,
    Id::LINUX_FOUNDATION_COMPOSITE,
    Strings::new("Clippy Manufacturer", "Rust UAC1", "RUST0123456"),
)
.with_config(Config::new("Audio Config 1").with_function(func))
.bind(&udc)
.expect("cannot bind to UDC");

println!(
    "UAC1 audio {} at {} to {} status {:?}",
    reg.name().to_string_lossy(),
    reg.path().display(),
    udc.name().to_string_lossy(),
    audio.status()
);

§UAC2 Example

use usb_gadget::{
    default_udc,
    function::audio::{Channel, Uac2},
    Class, Config, Gadget, Id, Strings,
};

// capture: 8 ch, 48000 Hz, 24 bit, playback: 2 ch, 48000 Hz, 16 bit
let (audio, func) =
    Uac2::new(Channel::new(0b1111_1111, 48000, 24 / 8), Channel::new(0b11, 48000, 16 / 8));

let udc = default_udc().expect("cannot get UDC");
let reg = Gadget::new(
    Class::INTERFACE_SPECIFIC,
    Id::LINUX_FOUNDATION_COMPOSITE,
    Strings::new("Clippy Manufacturer", "Rust UAC2", "RUST0123456"),
)
.with_config(Config::new("Audio Config 1").with_function(func))
.bind(&udc)
.expect("cannot bind to UDC");

println!(
    "UAC2 audio {} at {} to {} status {:?}",
    reg.name().to_string_lossy(),
    reg.path().display(),
    udc.name().to_string_lossy(),
    audio.status()
);

Structs§

Channel
Audio channel configuration.
Uac1
USB Audio Class 1 (UAC1) function.
Uac2
USB Audio Class 2 (UAC2) function.
Uac1Builder
Builder for USB audio class 1 (UAC1) function.
Uac1Config
Audio device configuration for UAC1.
Uac2Builder
Builder for USB audio class 2 (UAC2) function.
Uac2Config
Audio device configuration.