Table of Contents

Class BufferedWaveProvider

Namespace
NAudio.Wave
Assembly
NAudio.Core.dll

Provides a buffered store of samples. Read method will return queued samples or fill buffer with zeroes. Backed by a circular buffer.

public class BufferedWaveProvider : IWaveProvider
Inheritance
BufferedWaveProvider
Implements
Inherited Members
Extension Methods

Constructors

BufferedWaveProvider(WaveFormat, TimeSpan?)

Creates a new buffered WaveProvider

public BufferedWaveProvider(WaveFormat waveFormat, TimeSpan? bufferDuration = null)

Parameters

waveFormat WaveFormat

WaveFormat

bufferDuration TimeSpan?

Buffer duration (defaults to 5 seconds)

Properties

BufferDuration

Buffer duration

public TimeSpan BufferDuration { get; }

Property Value

TimeSpan

BufferLength

Buffer length in bytes

public int BufferLength { get; }

Property Value

int

BufferedBytes

The number of buffered bytes

public int BufferedBytes { get; }

Property Value

int

BufferedDuration

Buffered Duration

public TimeSpan BufferedDuration { get; }

Property Value

TimeSpan

DiscardOnBufferOverflow

If true, when the buffer is full, start throwing away data. If false, AddSamples will throw an exception when buffer is full.

public bool DiscardOnBufferOverflow { get; set; }

Property Value

bool

ReadFully

If true, always read the amount of data requested, padding with zeroes if necessary. By default is set to true.

public bool ReadFully { get; set; }

Property Value

bool

WaveFormat

Gets the WaveFormat

public WaveFormat WaveFormat { get; }

Property Value

WaveFormat

Methods

AddSamples(byte[], int, int)

Adds samples. Takes a copy of buffer, so that buffer can be reused if necessary.

public void AddSamples(byte[] buffer, int offset, int count)

Parameters

buffer byte[]
offset int
count int

AddSamples(ReadOnlySpan<byte>)

Adds samples from a span. Takes a copy of the data.

public void AddSamples(ReadOnlySpan<byte> data)

Parameters

data ReadOnlySpan<byte>

ClearBuffer()

Discards all audio from the buffer

public void ClearBuffer()

Read(Span<byte>)

Reads from this audio source. Will always return the full span if ReadFully is set, zero-filling if not enough data available.

public int Read(Span<byte> buffer)

Parameters

buffer Span<byte>

Returns

int