Class WaveInWindow
Records audio using the winmm waveIn API with CALLBACK_WINDOW, delivering the
DataAvailable event on the UI thread's message pump. Useful for apps that
want recording callbacks to arrive on the UI thread without any manual marshaling. For
background-thread capture use WaveIn in the NAudio.WinMM package instead.
public class WaveInWindow : IWaveIn, IDisposable, IWaveLatency
- Inheritance
-
WaveInWindow
- Implements
- Inherited Members
Constructors
WaveInWindow()
Creates a WaveInWindow that owns a hidden callback window. Must be constructed on a thread with a running Windows Forms message loop.
public WaveInWindow()
WaveInWindow(nint)
Creates a WaveInWindow that subclasses an existing window so its HWND receives waveIn callbacks. The handle must belong to a window whose message loop is running on the thread that constructs this instance.
public WaveInWindow(nint windowHandle)
Parameters
windowHandlenint
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
Remarks
Mirrors WaveIn: in steady state every queued buffer plus half of the one currently being filled by the driver sits between the microphone and the application.
BufferMilliseconds
Milliseconds per buffer. Recommended value is 100ms.
public int BufferMilliseconds { get; set; }
Property Value
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
Remarks
Mirrors CurrentLatency: returns the elapsed time since the most recent buffer was delivered, which is a sawtooth reading ~0 at delivery and rising to ~BufferMilliseconds just before the next one arrives.
DeviceCount
Returns the number of waveIn devices available on the system.
public static int DeviceCount { get; }
Property Value
DeviceNumber
The device number to use.
public int DeviceNumber { get; set; }
Property Value
NumberOfBuffers
Number of buffers to use (usually 2 or 3).
public int NumberOfBuffers { get; set; }
Property Value
WaveFormat
Format being recorded.
public WaveFormat WaveFormat { get; set; }
Property Value
Methods
Dispose()
Closes this device.
public void Dispose()
Dispose(bool)
Dispose pattern.
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
GetCapabilities(int)
Retrieves the capabilities of a waveIn device.
public static WaveInCapabilities GetCapabilities(int devNumber)
Parameters
devNumberint
Returns
GetMixerLine()
Microphone mixer line for this device.
public MixerLine GetMixerLine()
Returns
GetPosition()
Current byte position as reported by waveInGetPosition.
public long GetPosition()
Returns
StartRecording()
Start recording.
public void StartRecording()
StopRecording()
Stop recording. The driver will return any pending buffers via the window callback and RecordingStopped will be raised on the UI thread once drained.
public void StopRecording()
Events
DataAvailable
Indicates recorded data is available.
public event EventHandler<WaveInEventArgs> DataAvailable
Event Type
RecordingStopped
Indicates that all recorded data has now been received.
public event EventHandler<StoppedEventArgs> RecordingStopped