Name Description Size
card.rs Sound card enumeration 1549
chmap.rs 4994
ctl_int.rs 20097
device_name.rs Enumerate devices in the alsa library configuration # Example Print all devices found in various categories. ``` use std::ffi::CString; use alsa::device_name::HintIter; for t in &["pcm", "ctl", "rawmidi", "timer", "seq", "hwdep"] { println!("{} devices:", t); let i = HintIter::new(None, &*CString::new(*t).unwrap()).unwrap(); for a in i { println!(" {:?}", a) } } ``` 2851
direct
direct.rs Functions that bypass alsa-lib and talk directly to the kernel. 92
error.rs 3230
hctl.rs HCtl API - for mixer control and jack detection # Example Print all jacks and their status ``` for a in ::alsa::card::Iter::new().map(|x| x.unwrap()) { use std::ffi::CString; use alsa::hctl::HCtl; let h = HCtl::open(&CString::new(format!("hw:{}", a.get_index())).unwrap(), false).unwrap(); h.load().unwrap(); for b in h.elem_iter() { use alsa::ctl::ElemIface; let id = b.get_id().unwrap(); if id.get_interface() != ElemIface::Card { continue; } let name = id.get_name().unwrap(); if !name.ends_with(" Jack") { continue; } if name.ends_with(" Phantom Jack") { println!("{} is always present", &name[..name.len()-13]) } else { println!("{} is {}", &name[..name.len()-5], if b.read().unwrap().get_boolean(0).unwrap() { "plugged in" } else { "unplugged" }) } } } ``` 6358
io.rs self.buffer_string(|b| f.write_str(try!(str::from_utf8(b).map_err(|_| fmt::Error)))) 1380
lib.rs Thin but safe wrappers for [ALSA](https://alsa-project.org). [GitHub repo](https://github.com/diwic/alsa-rs) [Crates.io](https://crates.io/crates/alsa) This ALSA API wrapper/binding is WIP - the ALSA API is huge, and new functions and structs might be added as requested. Most functions map 1-to-1 to alsa-lib functions, e g, `ctl::CardInfo::get_id()` is a wrapper around `snd_ctl_card_info_get_id` and the [alsa-lib documentation](https://www.alsa-project.org/alsa-doc/alsa-lib/) can be consulted for additional information. Enjoy! 3749
mixer.rs Mixer API - Simple Mixer API for mixer control 24768
pcm.rs Audio playback and capture # Example Playback a sine wave through the "default" device. ``` use alsa::{Direction, ValueOr}; use alsa::pcm::{PCM, HwParams, Format, Access, State}; // Open default playback device let pcm = PCM::new("default", Direction::Playback, false).unwrap(); // Set hardware parameters: 44100 Hz / Mono / 16 bit let hwp = HwParams::any(&pcm).unwrap(); hwp.set_channels(1).unwrap(); hwp.set_rate(44100, ValueOr::Nearest).unwrap(); hwp.set_format(Format::s16()).unwrap(); hwp.set_access(Access::RWInterleaved).unwrap(); pcm.hw_params(&hwp).unwrap(); let io = pcm.io_i16().unwrap(); // Make sure we don't start the stream too early let hwp = pcm.hw_params_current().unwrap(); let swp = pcm.sw_params_current().unwrap(); swp.set_start_threshold(hwp.get_buffer_size().unwrap()).unwrap(); pcm.sw_params(&swp).unwrap(); // Make a sine wave let mut buf = [0i16; 1024]; for (i, a) in buf.iter_mut().enumerate() { *a = ((i as f32 * 2.0 * ::std::f32::consts::PI / 128.0).sin() * 8192.0) as i16 } // Play it back for 2 seconds. for _ in 0..2*44100/1024 { assert_eq!(io.writei(&buf[..]).unwrap(), 1024); } // In case the buffer was larger than 2 seconds, start the stream manually. if pcm.state() != State::Running { pcm.start().unwrap() }; // Wait for the stream to finish playback. pcm.drain().unwrap(); ``` 49039
poll.rs Tiny poll ffi A tiny wrapper around libc's poll system call. 2293
rawmidi.rs MIDI devices I/O and enumeration 8090
seq.rs MIDI sequencer I/O and enumeration 62840