#ALSA #audio #sound

alsa

Thin but safe wrappers for ALSA (Linux sound API)

22 releases

✓ Uses Rust 2018 edition

0.4.1 Jan 10, 2020
0.4.0 Oct 28, 2019
0.3.0 Jul 18, 2019
0.2.1 Sep 17, 2018
0.0.5 Jun 21, 2015

#12 in Audio

Download history 853/week @ 2019-10-07 644/week @ 2019-10-14 716/week @ 2019-10-21 610/week @ 2019-10-28 701/week @ 2019-11-04 878/week @ 2019-11-11 697/week @ 2019-11-18 883/week @ 2019-11-25 820/week @ 2019-12-02 1002/week @ 2019-12-09 840/week @ 2019-12-16 768/week @ 2019-12-23 1204/week @ 2019-12-30 1626/week @ 2020-01-06 1308/week @ 2020-01-13

3,609 downloads per month
Used in 14 crates (9 directly)

Apache-2.0/MIT

405KB
11K SLoC

ALSA bindings for Rust

Thin but safe wrappers for ALSA, the most common API for accessing audio devices on Linux.

crates.io API documentation license

The ALSA API is rather big, so everything is not covered yet, but expect the following to work:

  • Audio Playback (example in pcm module docs)

  • Audio Recording

  • Mixer controls

  • HCtl API (jack detection example in hctl module docs)

  • Raw midi

  • Midi sequencer (most of it)

  • Ctl API

  • Device name hints (example in device_name module docs)

  • Enumerations of all of the above

  • Poll and/or wait for all of the above

The following is not yet implemented (mostly because nobody asked for them) :

  • Separate timer API (snd_timer_*)

  • Config API (snd_config_*)

  • Plug-in API

Quickstart guide / API design:

  • 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 can be consulted for additional information.

  • Structs are RAII and closed/freed on drop, e g, when a PCM struct is dropped, snd_pcm_close is called.

  • To read and write buffers, call the io_* methods. It will return a separate struct from which you can read or write, and which can also be used for mmap (if supported by the driver).

  • Error handling - most alsa-lib functions can return errors, so the return value from these is a Result.

  • Enumeration of cards, devices etc is done through structs implementing Iterator.

  • Many structs implement poll::Descriptors, to combine with poll or mio. Or just use wait if you don't need non-blocking functionality.

Dependencies

~1MB
~21K SLoC