Fields (2) Events (2) Methods (14) Properties (5)
Namespace: CSCore.SoundIn

Syntax

public class WasapiCapture : ISoundIn

Implements

Summary

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).

Uses

Fields

ReftimesPerMillisecond

Reference time units per millisecond.

public const Int32 ReftimesPerMillisecond

Constant Value

10000

ReftimesPerSecond

Reference time units per second.

public const Int32 ReftimesPerSecond

Constant Value

10000000

Events

DataAvailable

Occurs when new data got captured and is available.

public DataAvailable

Stopped

Occurs when WasapiCapture stopped capturing audio.

public Stopped

Methods

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

Boolean

True, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.

shareMode

AudioClientShareMode

Specifies 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

Boolean

True, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.

shareMode

AudioClientShareMode

Specifies 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

Int32

Latency 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

Boolean

True, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.

shareMode

AudioClientShareMode

Specifies 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

Int32

Latency of the capture specified in milliseconds.

defaultFormat

WaveFormat

The default WaveFormat to use for the capture. If this parameter is set to null, the best available format will be chosen automatically.

public void WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency, WaveFormat defaultFormat, ThreadPriority captureThreadPriority)

Parameters

eventSync

Boolean

True, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.

shareMode

AudioClientShareMode

Specifies 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

Int32

Latency of the capture specified in milliseconds.

captureThreadPriority

ThreadPriority

ThreadPriority of the capturethread which runs in background and provides the audiocapture itself.

defaultFormat

WaveFormat

The default WaveFormat to use for the capture. If this parameter is set to null, the best available format will be chosen automatically.

public void WasapiCapture(Boolean eventSync, AudioClientShareMode shareMode, Int32 latency, WaveFormat defaultFormat, ThreadPriority captureThreadPriority, SynchronizationContext synchronizationContext)

Parameters

eventSync

Boolean

True, to use eventsynchronization instead of a simple loop and sleep behavior. Don't use this in combination with exclusive mode.

shareMode

AudioClientShareMode

Specifies 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

Int32

Latency of the capture specified in milliseconds.

captureThreadPriority

ThreadPriority

ThreadPriority of the capturethread which runs in background and provides the audiocapture itself.

defaultFormat

WaveFormat

The default WaveFormat to use for the capture. If this parameter is set to null, the best available format will be chosen automatically.

synchronizationContext

SynchronizationContext

The 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

Boolean

true 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()

Properties

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; }