Table of Contents

Class WaveFileReader

Namespace
NAudio.Wave
Assembly
NAudio.Core.dll

This class supports the reading of WAV files, providing a repositionable WaveStream that returns the raw data contained in the WAV file

public class WaveFileReader : WaveStream, IAsyncDisposable, IDisposable, IWaveProvider
Inheritance
WaveFileReader
Implements
Inherited Members
Extension Methods

Constructors

WaveFileReader(Stream)

Creates a Wave File Reader based on an input stream

public WaveFileReader(Stream inputStream)

Parameters

inputStream Stream

The input stream containing a WAV file including header

WaveFileReader(string)

Supports opening a WAV file

public WaveFileReader(string waveFile)

Parameters

waveFile string

Remarks

The WAV file format is a real mess, but we will only support the basic WAV file format which actually covers the vast majority of WAV files out there. For more WAV file format information visit www.wotsit.org. If you have a WAV file that can't be read by this class, email it to the NAudio project and we will probably fix this reader to support it

Properties

Chunks

The non-essential RIFF chunks found in this file (everything except fmt and data). Use the returned WaveChunks to enumerate chunk metadata, fetch raw bytes via GetData(RiffChunk), or run an IWaveChunkInterpreter<T> — the built-in interpreters for cue lists, BWF, and LIST/INFO metadata are exposed as extension methods in WaveChunksExtensions.

public WaveChunks Chunks { get; }

Property Value

WaveChunks

Length

This is the length of audio data contained in this WAV file, in bytes (i.e. the byte length of the data chunk, not the length of the WAV file itself) WaveFormat

public override long Length { get; }

Property Value

long

Position

Position in the WAV data chunk. Position

public override long Position { get; set; }

Property Value

long

SampleCount

Number of Sample Frames (if possible to calculate) This currently does not take into account number of channels Multiply number of channels if you want the total number of samples

public long SampleCount { get; }

Property Value

long

WaveFormat

public override WaveFormat WaveFormat { get; }

Property Value

WaveFormat

Methods

Dispose(bool)

Cleans up the resources associated with this WaveFileReader

protected override void Dispose(bool disposing)

Parameters

disposing bool

Read(byte[], int, int)

Reads bytes from the Wave File. Read(byte[], int, int)

public override int Read(byte[] array, int offset, int count)

Parameters

array byte[]
offset int
count int

Returns

int

Read(Span<byte>)

Reads bytes from the Wave File into the provided span. Read(Span<byte>)

public override int Read(Span<byte> buffer)

Parameters

buffer Span<byte>

Returns

int

ReadNextSampleFrame()

Attempts to read the next sample or group of samples as floating point normalised into the range -1.0f to 1.0f

public float[] ReadNextSampleFrame()

Returns

float[]

An array of samples, 1 for mono, 2 for stereo etc. Null indicates end of file reached