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 and polled 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. |
playsine_poll | Similar to playsine but uses polling instead of event driven timing mode. |
playnoise_exclusive | Plays white noise in exclusive mode on the default output device. Shows how to handle HRESULT errors. |
playnoise_exclusive_poll | Similar to playnoise_exclusive but uses polling instead of event driven timing mode. |
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§
- Audio
Capture Client - Struct wrapping an IAudioCaptureClient.
- Audio
Client - Struct wrapping an IAudioClient.
- Audio
Clock - Struct wrapping an IAudioClock.
- Audio
Render Client - Struct wrapping an IAudioRenderClient.
- Audio
Session Control - Struct wrapping an IAudioSessionControl.
- Buffer
Flags - Struct representing the _AUDCLNT_BUFFERFLAGS enum values.
- Device
- Struct wrapping an IMMDevice.
- Device
Collection - Struct wrapping an IMMDeviceCollection.
- Device
Collection Iter - Iterator for DeviceCollection
- Event
Callbacks - A structure holding the callbacks for notifications
- Event
Registration - Struct for keeping track of the registered notifications.
- GUID
- A globally unique identifier (GUID) used to identify COM and WinRT interfaces.
- Handle
- Struct wrapping a [HANDLE] to an Event Object.
- Wave
Format - Struct wrapping a WAVEFORMATEXTENSIBLE format descriptor.
Enums§
- Device
State - Possible states for an [IMMDevice], an enum representing the DEVICE_STATE_XXX constants
- Direction
- Audio direction, playback or capture.
- Disconnect
Reason - Reason for session disconnect, an enum representing the
DisconnectReasonXxx
values of the AudioSessionDisconnectReason enum - Role
- Wrapper for ERole. Console is the role used by most applications
- Sample
Type - Sample type, float or integer
- Session
State - Possible states for an AudioSessionControl, an enum representing the AudioSessionStateXxx constants
- Share
Mode - Sharemode for device
- Stream
Mode - Helper enum for initializing an AudioClient. There are four main modes that can be specified, corresponding to the four possible combinations of sharing mode and timing. The enum variants only expose the parameters that can be set in each mode.
- Timing
Mode - Timing mode for device
- Wasapi
Error
Functions§
- calculate_
period_ 100ns - 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.
- deinitialize
- Close the COM library on the current thread.
- get_
default_ device - Get the default playback or capture device for the console role
- get_
default_ device_ for_ role - Get the default playback or capture device for a specific role
- initialize_
mta - Initializes COM for use by the calling thread for the multi-threaded apartment (MTA).
- initialize_
sta - Initializes COM for use by the calling thread for a single-threaded apartment (STA).
- make_
channelmasks - 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_
simple_ channelmask - Make a simple channel mask by adding the correct number of bits. Above the 18 channel positions that are defined it returns a zero.