Table of Contents

Class AudioFileReader

Namespace
NAudio.Wave
Assembly
NAudio.dll

AudioFileReader simplifies opening an audio file in NAudio Simply pass in the filename, and it will attempt to open the file and set up a conversion path that turns into PCM IEEE float. ACM codecs will be used for conversion. It provides a volume property and implements both WaveStream and ISampleProvider, making it possibly the only stage in your audio pipeline necessary for simple playback scenarios

public class AudioFileReader : WaveStream, IAsyncDisposable, IDisposable, IWaveProvider, ISampleProvider
Inheritance
AudioFileReader
Implements
Inherited Members

Constructors

AudioFileReader(Stream)

Initializes a new instance of AudioFileReader from a stream. The audio format is detected from the stream contents, so no file name is required. WAV and AIFF streams are handled by the cross-platform readers; on the Windows build any other format is passed to Media Foundation.

public AudioFileReader(Stream inputStream)

Parameters

inputStream Stream

The stream to read from. It must be readable and seekable, and the caller retains ownership of it — disposing the AudioFileReader does not dispose the underlying stream.

Exceptions

ArgumentNullException

inputStream is null.

ArgumentException

inputStream is unreadable or unseekable.

NotSupportedException

The stream is in a format the cross-platform build cannot read. Use the Windows build for Media Foundation, or SoundFileReader from the NAudio.SoundFile package.

AudioFileReader(string)

Initializes a new instance of AudioFileReader

public AudioFileReader(string fileName)

Parameters

fileName string

The file to open

Exceptions

NotSupportedException

The file is in a format the cross-platform build cannot read. Use the Windows build for Media Foundation, or SoundFileReader from the NAudio.SoundFile package.

Properties

FileName

File Name (null when this reader was created from a stream)

public string FileName { get; }

Property Value

string

Length

Length of this stream (in bytes)

public override long Length { get; }

Property Value

long

Position

Position of this stream (in bytes)

public override long Position { get; set; }

Property Value

long

Volume

Gets or Sets the Volume of this AudioFileReader. 1.0f is full volume

public float Volume { get; set; }

Property Value

float

WaveFormat

WaveFormat of this stream

public override WaveFormat WaveFormat { get; }

Property Value

WaveFormat

Methods

Dispose(bool)

Disposes this AudioFileReader

protected override void Dispose(bool disposing)

Parameters

disposing bool

True if called from Dispose

Read(byte[], int, int)

Reads from this wave stream

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

Parameters

buffer byte[]
offset int
count int

Returns

int

Read(Span<byte>)

Reads from this wave stream

public override int Read(Span<byte> buffer)

Parameters

buffer Span<byte>

Returns

int

Read(Span<float>)

Reads audio samples from this file reader

public int Read(Span<float> buffer)

Parameters

buffer Span<float>

Returns

int