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
Example | Description |
---|---|
playsine | Plays a sine wave in shared mode on the default output device. |
playsine_events | Similar to playsine but also listens to notifications. |
playnoise_exclusive | Plays white noise in exclusive mode on the default output device. Shows how to handle HRESULT errors. |
loopback | Shows how to simultaneously capture and render sound, with separate threads for capture and render. |
record | Records audio from the default device, and saves the raw samples to a file. |
devices | Lists all available audio devices and displays the default devices. |
record_application | Records audio from a single application, and saves the raw samples to a file. |
Structs§
- Struct wrapping an IAudioCaptureClient.
- Struct wrapping an IAudioClient.
- Struct wrapping an IAudioClock.
- Struct wrapping an IAudioRenderClient.
- Struct wrapping an IAudioSessionControl.
- Struct representing the _AUDCLNT_BUFFERFLAGS enum values.
- Struct wrapping an IMMDevice.
- Struct wrapping an IMMDeviceCollection.
- Iterator for DeviceCollection
- A structure holding the callbacks for notifications
- A globally unique identifier (GUID) used to identify COM and WinRT interfaces.
- Struct wrapping a [HANDLE] to an Event Object.
- Error returned by the Wasapi crate.
- Struct wrapping a WAVEFORMATEXTENSIBLE format descriptor.
Enums§
- Possible states for an [IMMDevice], an enum representing the DEVICE_STATE_XXX constants
- Audio direction, playback or capture.
- Reason for session disconnect, an enum representing the
DisconnectReasonXxx
values of the AudioSessionDisconnectReason enum - Wrapper for ERole. Console is the role used by most applications
- Sample type, float or integer
- Possible states for an AudioSessionControl, an enum representing the AudioSessionStateXxx constants
- Sharemode for device
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.