32 releases

0.9.1 Aug 21, 2024
0.9.0 Feb 21, 2024
0.8.1 Oct 13, 2023
0.7.1 Jul 30, 2023
0.0.5 Jun 21, 2015

#9 in Audio

Download history 45996/week @ 2024-08-05 53574/week @ 2024-08-12 60640/week @ 2024-08-19 62257/week @ 2024-08-26 58464/week @ 2024-09-02 51527/week @ 2024-09-09 55143/week @ 2024-09-16 61879/week @ 2024-09-23 64005/week @ 2024-09-30 57002/week @ 2024-10-07 62203/week @ 2024-10-14 63724/week @ 2024-10-21 66609/week @ 2024-10-28 75312/week @ 2024-11-04 65762/week @ 2024-11-11 72610/week @ 2024-11-18

284,686 downloads per month
Used in 633 crates (25 directly)

Apache-2.0/MIT

430KB
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 your favorite async framework. Or just use wait if you don't need non-blocking functionality.

Notes:

  • To run the tests successfully, there must be a "default" sound card configured. This is usually not a problem when running on normal hardware, but some CI systems, docker images etc, might not have that configured by default.

Dependencies

~435KB
~12K SLoC