Table of Contents

Class WasapiCapture

Namespace
NAudio.CoreAudioApi
Assembly
NAudio.Wasapi.dll
[Obsolete("Use WasapiRecorderBuilder to create a WasapiRecorder instead. WasapiRecorder provides zero-copy buffers, MMCSS thread priority, IAsyncEnumerable capture, and process-specific loopback.")]
public class WasapiCapture : IWaveIn, IDisposable, IWaveLatency
Inheritance
WasapiCapture
Implements
Derived
Inherited Members

Constructors

WasapiCapture()

Initialises a new instance of the WASAPI capture class

public WasapiCapture()

WasapiCapture(MMDevice)

Initialises a new instance of the WASAPI capture class

public WasapiCapture(MMDevice captureDevice)

Parameters

captureDevice MMDevice

Capture device to use

WasapiCapture(MMDevice, bool)

Initializes a new instance of the WasapiCapture class.

public WasapiCapture(MMDevice captureDevice, bool useEventSync)

Parameters

captureDevice MMDevice

The capture device.

useEventSync bool

true if sync is done with event. false use sleep.

WasapiCapture(MMDevice, bool, int)

Initializes a new instance of the WasapiCapture class.

public WasapiCapture(MMDevice captureDevice, bool useEventSync, int audioBufferMillisecondsLength)

Parameters

captureDevice MMDevice

The capture device.

useEventSync bool

true if sync is done with event. false use sleep.

audioBufferMillisecondsLength int

Length of the audio buffer in milliseconds. A lower value means lower latency but increased CPU usage.

Properties

AverageLatency

The steady-state latency from a sample being queued for output to it being emitted by the audio hardware, assuming uninterrupted playback. This is a property of the buffer configuration and the driver, not of the current playback state.

public TimeSpan AverageLatency { get; }

Property Value

TimeSpan

Remarks

The requested capture buffer length. Read at StartRecording() time, so reflects what the engine actually negotiated for the period.

CaptureState

Current Capturing State

public CaptureState CaptureState { get; }

Property Value

CaptureState

CurrentLatency

The time that has elapsed since the sample currently emerging from the hardware was queued for output. In steady state this is approximately equal to AverageLatency; it differs during start-up, after an underrun, or when the host is filling buffers irregularly. Implementations that cannot meaningfully distinguish from the average are permitted to return AverageLatency.

public TimeSpan CurrentLatency { get; }

Property Value

TimeSpan

Remarks

Derived from IAudioClient::GetCurrentPadding, which on a capture stream reports the number of frames available to read — i.e. the age of the oldest captured sample still in the endpoint buffer. Returns AverageLatency when not recording or if the audio client has not yet been initialised.

ShareMode

Share Mode - set before calling StartRecording

public AudioClientShareMode ShareMode { get; set; }

Property Value

AudioClientShareMode

WaveFormat

Capturing wave format

public virtual WaveFormat WaveFormat { get; set; }

Property Value

WaveFormat

Methods

Dispose()

Dispose

public void Dispose()

GetAudioClientStreamFlags()

To allow overrides to specify different flags (e.g. loopback)

protected virtual AudioClientStreamFlags GetAudioClientStreamFlags()

Returns

AudioClientStreamFlags

GetDefaultCaptureDevice()

Gets the default audio capture device

public static MMDevice GetDefaultCaptureDevice()

Returns

MMDevice

The default audio capture device

StartRecording()

Start Capturing

public void StartRecording()

StopRecording()

Stop Capturing (requests a stop, wait for RecordingStopped event to know it has finished)

public void StopRecording()

Events

DataAvailable

Indicates recorded data is available

public event EventHandler<WaveInEventArgs> DataAvailable

Event Type

EventHandler<WaveInEventArgs>

RecordingStopped

Indicates that all recorded data has now been received.

public event EventHandler<StoppedEventArgs> RecordingStopped

Event Type

EventHandler<StoppedEventArgs>