Table of Contents

Class AlsaOut

Namespace
NAudio.Wave.Alsa
Assembly
NAudio.Alsa.dll

An IWavePlayer that plays audio through ALSA on Linux.

public sealed class AlsaOut : IWavePlayer, IDisposable, IWaveLatency
Inheritance
AlsaOut
Implements
Inherited Members
Extension Methods

Remarks

Audio is taken through a SampleChannel (giving software volume and mono→stereo handling) and converted to the first device- supported format among IEEE float, 16-bit and 24-bit PCM. A dedicated background thread performs blocking snd_pcm_writei calls and recovers from xruns; it is always joined before the device handle is closed.

Constructors

AlsaOut()

Creates an AlsaOut on the default PCM device.

public AlsaOut()

AlsaOut(string)

Creates an AlsaOut on a specific PCM device.

public AlsaOut(string device)

Parameters

device string

An 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

TimeSpan

Remarks

The ALSA ring buffer is sized as PeriodFrames × Periods at configuration time, so the steady-state delay between writing a sample and the card consuming it 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

TimeSpan

Remarks

Uses snd_pcm_delay, which reports exactly the number of frames currently in flight between the application and the audio hardware. Falls back to AverageLatency when not playing or if the call fails.

OutputWaveFormat

The WaveFormat this device is using for playback

public WaveFormat OutputWaveFormat { get; }

Property Value

WaveFormat

PlaybackState

Current playback state

public PlaybackState PlaybackState { get; }

Property Value

PlaybackState

Volume

The volume 1.0f is full scale Note that not all implementations necessarily support volume changes

public float Volume { get; set; }

Property Value

float

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Init(IWaveProvider)

Initialise playback

public void Init(IWaveProvider waveProvider)

Parameters

waveProvider IWaveProvider

The wave provider to be played

Pause()

Pause Playback

public void Pause()

Play()

Begin playback

public void Play()

Stop()

Stop playback

public void Stop()

Events

PlaybackStopped

Indicates that playback has gone into a stopped state due to reaching the end of the input stream or an error has been encountered during playback

public event EventHandler<StoppedEventArgs> PlaybackStopped

Event Type

EventHandler<StoppedEventArgs>