public class WasapiCapture : ISoundIn
Captures audio data from a audio device (through Wasapi Apis). To capture audio from an output device, use the WasapiLoopbackCapture class. Minimum supported OS: Windows Vista (see IsSupportedOnCurrentPlatform property).
ReftimesPerMillisecond
Reference time units per millisecond.
public const Int32 ReftimesPerMillisecond
Constant Value
ReftimesPerSecond
Reference time units per second.
public const Int32 ReftimesPerSecond
Constant Value
DataAvailable
Occurs when new data got captured and is available.
public DataAvailable
Stopped
Occurs when WasapiCapture stopped capturing audio.
public Stopped
WasapiCapture()
Initializes a new instance of the WasapiCapture class. CaptureThreadPriority = AboveNormal. DefaultFormat = null. Latency = 100ms. EventSync = true. SharedMode = Shared.
public void WasapiCapture()
WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode)
Initializes a new instance of the WasapiCapture class. CaptureThreadPriority = AboveNormal. DefaultFormat = null. Latency = 100ms.
public void WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode)
Parameters
eventSync
BooleanTrue, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.
shareMode
AudioClientShareModeSpecifies how to open the audio device. Note that if exclusive mode is used, the device can only be used once on the whole system. Don't use exclusive mode in combination with eventSync.
WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency)
Initializes a new instance of the WasapiCapture class. CaptureThreadPriority = AboveNormal. DefaultFormat = null.
public void WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency)
Parameters
eventSync
BooleanTrue, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.
shareMode
AudioClientShareModeSpecifies how to open the audio device. Note that if exclusive mode is used, the device can only be used once on the whole system. Don't use exclusive mode in combination with eventSync.
latency
Int32Latency of the capture specified in milliseconds.
WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency, WaveFormat defaultFormat)
Initializes a new instance of the WasapiCapture class. CaptureThreadPriority = AboveNormal.
public void WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency, WaveFormat defaultFormat)
Parameters
eventSync
BooleanTrue, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.
shareMode
AudioClientShareModeSpecifies how to open the audio device. Note that if exclusive mode is used, the device can only be used once on the whole system. Don't use exclusive mode in combination with eventSync.
latency
Int32Latency of the capture specified in milliseconds.
defaultFormat
WaveFormatThe default WaveFormat to use for the capture. If this parameter is set to null, the best available format will be chosen automatically.
WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency, WaveFormat defaultFormat, ThreadPriority captureThreadPriority)
Initializes a new instance of the WasapiCapture class. SynchronizationContext = null.
public void WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency, WaveFormat defaultFormat, ThreadPriority captureThreadPriority)
Parameters
eventSync
BooleanTrue, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.
shareMode
AudioClientShareModeSpecifies how to open the audio device. Note that if exclusive mode is used, the device can only be used once on the whole system. Don't use exclusive mode in combination with eventSync.
latency
Int32Latency of the capture specified in milliseconds.
captureThreadPriority
ThreadPriorityThreadPriority of the capturethread which runs in background and provides the audiocapture itself.
defaultFormat
WaveFormatThe default WaveFormat to use for the capture. If this parameter is set to null, the best available format will be chosen automatically.
WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency, WaveFormat defaultFormat, ThreadPriority captureThreadPriority, SynchronizationContext synchronizationContext)
Initializes a new instance of the WasapiCapture class.
public void WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency, WaveFormat defaultFormat, ThreadPriority captureThreadPriority, SynchronizationContext synchronizationContext)
Parameters
eventSync
BooleanTrue, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.
shareMode
AudioClientShareModeSpecifies how to open the audio device. Note that if exclusive mode is used, the device can only be used once on the whole system. Don't use exclusive mode in combination with eventSync.
latency
Int32Latency of the capture specified in milliseconds.
captureThreadPriority
ThreadPriorityThreadPriority of the capturethread which runs in background and provides the audiocapture itself.
defaultFormat
WaveFormatThe default WaveFormat to use for the capture. If this parameter is set to null, the best available format will be chosen automatically.
synchronizationContext
SynchronizationContextThe SynchronizationContext to use to fire events on.
Exceptions
PlatformNotSupportedException
The current platform does not support Wasapi. For more details see: IsSupportedOnCurrentPlatform.
ArgumentException
The eventSync parameter is set to true while the shareMode is set to Exclusive.
Dispose()
Stops the capture and frees all resources.
public void Dispose()
Dispose(Boolean disposing)
Releases unmanaged and - optionally - managed resources.
protected virtual void Dispose(Boolean disposing)
Parameters
disposing
Booleantrue to release both managed and unmanaged resources; false to release only unmanaged resources.
Finalize()
Finalizes an instance of the WasapiCapture class.
protected void Finalize()
GetDefaultDevice()
Returns the default device.
protected virtual MMDevice GetDefaultDevice()
Returns
The default device.
GetStreamFlags()
Returns the stream flags to use for the audioclient initialization.
protected virtual AudioClientStreamFlags GetStreamFlags()
Returns
The stream flags to use for the audioclient initialization.
Initialize()
Initializes WasapiCapture and prepares all resources for recording. Note that properties like Device, etc. won't affect WasapiCapture after calling Initialize.
public void Initialize()
Start()
Start recording.
public void Start()
Stop()
Stop recording.
public void Stop()
DebuggingId
Random ID based on internal audioclients memory address for debugging purposes.
public Int64 DebuggingId { get; }
Device
Gets or sets the capture device to use. Set this property before calling Initialize.
public MMDevice Device { get; set; }
IsSupportedOnCurrentPlatform
Gets a value indicating whether the WasapiCapture class is supported on the current platform. If , it is supported; otherwise false.
public Boolean IsSupportedOnCurrentPlatform { get; }
RecordingState
Gets the RecordingState.
public RecordingState RecordingState { get; }
WaveFormat
Gets the OutputFormat.
public WaveFormat WaveFormat { get; }