Class WaveFileReader
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, IDisposable, IAsyncDisposable, IWaveProvider
- Inheritance
-
WaveFileReader
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
WaveFileReader(Stream)
Creates a Wave File Reader based on an input stream
public WaveFileReader(Stream inputStream)
Parameters
inputStream
StreamThe 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
ExtraChunks
Gets a list of the additional chunks found in this file
public List<RiffChunk> ExtraChunks { get; }
Property Value
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
Position
Position in the WAV data chunk. Position
public override long Position { get; set; }
Property Value
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
WaveFormat
public override WaveFormat WaveFormat { get; }
Property Value
Methods
Dispose(bool)
Cleans up the resources associated with this WaveFileReader
protected override void Dispose(bool disposing)
Parameters
disposing
bool
GetChunkData(RiffChunk)
Gets the data for the specified chunk
public byte[] GetChunkData(RiffChunk chunk)
Parameters
chunk
RiffChunk
Returns
- byte[]
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
Returns
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
TryReadFloat(out float)
Attempts to read a sample into a float. n.b. only applicable for uncompressed formats Will normalise the value read into the range -1.0f to 1.0f if it comes from a PCM encoding
[Obsolete("Use ReadNextSampleFrame instead (this version does not support stereo properly)")]
public bool TryReadFloat(out float sampleValue)
Parameters
sampleValue
float
Returns
- bool
False if the end of the WAV data chunk was reached