Class AlsaIn
An IWaveIn that records audio through ALSA on Linux.
public sealed class AlsaIn : IWaveIn, IDisposable, IWaveLatency
- Inheritance
-
AlsaIn
- Implements
- Inherited Members
Remarks
A dedicated background thread performs blocking snd_pcm_readi
calls, recovers from overruns, and raises DataAvailable
for each captured period. The thread is always joined before the
device handle is closed.
Constructors
AlsaIn()
Creates an AlsaIn on the default PCM device.
public AlsaIn()
AlsaIn(string)
Creates an AlsaIn on a specific PCM device.
public AlsaIn(string device)
Parameters
devicestringAn ALSA PCM name, e.g.
"default"or"hw:0".
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
The ring buffer is configured at StartRecording() time as
PeriodFrames × Periods, so the steady-state delay between a sample hitting the
hardware and being delivered to DataAvailable subscribers is the full
buffer's worth of frames.
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
Uses snd_pcm_delay, which on a capture stream returns the number of frames
already captured and waiting to be read — exactly the age of the oldest unread sample.
Falls back to AverageLatency when not running or the call fails.
WaveFormat
Recording WaveFormat
public WaveFormat WaveFormat { get; set; }
Property Value
Methods
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
StartRecording()
Start Recording
public void StartRecording()
StopRecording()
Stop Recording
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