Crate wasapi

source ·
Expand description

Wasapi bindings for Rust

The aim of this crate is to provide easy and safe access to the Wasapi API for audio playback and capture.

The presented API is all safe Rust, but structs and functions closely follow the original Windows API.

For details on how to use Wasapi, please see the Windows documentation.

Bindings are generated automatically using the windows crate.

Supported functionality

These things have been implemented so far:

  • Audio playback and capture
  • Shared and exclusive modes
  • Event-driven buffering
  • Loopback capture
  • Notifications for volume change, device disconnect etc

Included examples

ExampleDescription
playsinePlays a sine wave in shared mode on the default output device.
playsine_eventsSimilar to playsine but also listens to notifications.
playnoise_exclusivePlays white noise in exclusive mode on the default output device. Shows how to handle HRESULT errors.
loopbackShows how to simultaneously capture and render sound, with separate threads for capture and render.
recordRecords audio from the default device, and saves the raw samples to a file.
devicesLists all available audio devices and displays the default devices.

Structs

Enums

Functions

  • Calculate a period in units of 100ns that corresponds to the given number of buffer frames at the given sample rate. See the IAudioClient documentation.
  • Close the COM library on the current thread.
  • Get the default playback or capture device for the console role
  • Get the default playback or capture device for a specific role
  • Initializes COM for use by the calling thread for the multi-threaded apartment (MTA).
  • Initializes COM for use by the calling thread for a single-threaded apartment (STA).
  • Return a vector with suggested channel masks for the given number of channels. Used to find a format that a device accepts in exclusive mode. The values are sorted according to how likely they are to be accepted, with the most likely first.
  • Make a simple channel mask by adding the correct number of bits. Above the 18 channel positions that are defined it returns a zero.