Xeno-rat
Loading...
Searching...
No Matches
NAudio.Wave.WaveFileReader Class Reference

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

Inheritance diagram for NAudio.Wave.WaveFileReader:
Collaboration diagram for NAudio.Wave.WaveFileReader:

Public Member Functions

 WaveFileReader (String waveFile)
 Supports opening a WAV file.
 
 WaveFileReader (Stream inputStream)
 Creates a Wave File Reader based on an input stream.
 
byte[] GetChunkData (RiffChunk chunk)
 Retrieves the data of a specific RIFF chunk from the wave stream.
 
override int Read (byte[] array, int offset, int count)
 Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
 
float[] ReadNextSampleFrame ()
 Reads the next sample frame from the audio data and returns it as an array of floats.
 
bool TryReadFloat (out float sampleValue)
 Tries to read the next sample frame and returns a float value if successful.
 
- Public Member Functions inherited from NAudio.Wave.WaveStream
override void Flush ()
 Flushes the buffer of the current stream and causes any buffered data to be written to the underlying device.
 
override long Seek (long offset, SeekOrigin origin)
 Sets the position within the current stream.
 
override void SetLength (long length)
 Throws a NotSupportedException with the message "Can't set length of a WaveFormatString".
 
override void Write (byte[] buffer, int offset, int count)
 Throws a NotSupportedException with the message "Can't write to a WaveFormatString".
 
void Skip (int seconds)
 Skips the playback to a new position in the audio file based on the specified number of seconds.
 
virtual bool HasData (int count)
 Checks if there is data available at the current position.
 

Protected Member Functions

override void Dispose (bool disposing)
 Releases the unmanaged resources used by the WaveFileReader and optionally releases the managed resources.
 

Properties

List< RiffChunkExtraChunks [get]
 Gets a list of the additional chunks found in this file.
 
override WaveFormat WaveFormat [get]
 WaveStream.WaveFormat
 
override long Length [get]
 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) WaveStream.WaveFormat
 
long SampleCount [get]
 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.
 
override long Position [get, set]
 Position in the WAV data chunk. Stream.Position
 
- Properties inherited from NAudio.Wave.WaveStream
WaveFormat WaveFormat [get]
 Retrieves the WaveFormat for this stream.
 
override bool CanRead [get]
 We can read from this stream.
 
override bool CanSeek [get]
 We can seek within this stream.
 
override bool CanWrite [get]
 We can't write to this stream.
 
virtual int BlockAlign [get]
 The block alignment for this wavestream. Do not modify the Position to anything that is not a whole multiple of this value.
 
virtual TimeSpan CurrentTime [get, set]
 The current position in the stream in Time format.
 
virtual TimeSpan TotalTime [get]
 Total length in real-time of the stream (may be an estimate for compressed files)
 
- Properties inherited from NAudio.Wave.IWaveProvider

Private Member Functions

 WaveFileReader (Stream inputStream, bool ownInput)
 

Private Attributes

readonly WaveFormat waveFormat
 
readonly bool ownInput
 
readonly long dataPosition
 
readonly long dataChunkLength
 
readonly object lockObject = new object()
 
Stream waveStream
 

Detailed Description

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

Constructor & Destructor Documentation

◆ WaveFileReader() [1/3]

NAudio.Wave.WaveFileReader.WaveFileReader ( String waveFile)
inline

Supports opening a WAV file.

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

◆ WaveFileReader() [2/3]

NAudio.Wave.WaveFileReader.WaveFileReader ( Stream inputStream)
inline

Creates a Wave File Reader based on an input stream.

Parameters
inputStreamThe input stream containing a WAV file including header

◆ WaveFileReader() [3/3]

NAudio.Wave.WaveFileReader.WaveFileReader ( Stream inputStream,
bool ownInput )
inlineprivate
Here is the call graph for this function:

Member Function Documentation

◆ Dispose()

override void NAudio.Wave.WaveFileReader.Dispose ( bool disposing)
inlineprotected

Releases the unmanaged resources used by the WaveFileReader and optionally releases the managed resources.

Parameters
disposingtrue to release both managed and unmanaged resources; false to release only unmanaged resources.

This method releases the unmanaged resources used by the WaveFileReader and optionally releases the managed resources. If disposing is true, this method releases all resources held by any managed objects that this WaveFileReader references. This method also calls the Dispose method of the base class with the disposing parameter set to true. If disposing is false, this method indicates that the WaveFileReader was not disposed.

Exceptions
System.Diagnostics.Debug.AssertExceptionThrown when WaveFileReader was not disposed.

◆ GetChunkData()

byte[] NAudio.Wave.WaveFileReader.GetChunkData ( RiffChunk chunk)
inline

Retrieves the data of a specific RIFF chunk from the wave stream.

Parameters
chunkThe RIFF chunk for which the data needs to be retrieved.
Returns
The byte array containing the data of the specified chunk .

This method temporarily changes the position of the wave stream to read the data of the specified chunk . It then restores the original position of the wave stream after reading the data.

◆ Read()

override int NAudio.Wave.WaveFileReader.Read ( byte[] array,
int offset,
int count )
inline

Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.

Parameters
arrayAn array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
offsetThe zero-based byte offset in array at which to begin storing the data read from the current stream.
countThe maximum number of bytes to be read from the current stream.
Exceptions
ArgumentExceptionThrown when count is not a multiple of waveFormat.BlockAlign.
Returns
The total number of bytes read into the buffer. This might be less than the number of bytes requested if that many bytes are not currently available, or zero if the end of the stream is reached.

This method ensures that a complete block of bytes is read, as it throws an ArgumentException if count is not a multiple of waveFormat.BlockAlign. It then locks the current object and reads a sequence of bytes from the waveStream into the specified array, starting at the specified offset. If the position plus count exceeds the length of the data chunk, it adjusts the count to read only up to the end of the data chunk.

Implements NAudio.Wave.IWaveProvider.

Here is the caller graph for this function:

◆ ReadNextSampleFrame()

float[] NAudio.Wave.WaveFileReader.ReadNextSampleFrame ( )
inline

Reads the next sample frame from the audio data and returns it as an array of floats.

Exceptions
InvalidOperationExceptionThrown when the audio data encoding is not supported (only 16, 24, or 32 bit PCM or IEEE float audio data are supported).
InvalidDataExceptionThrown when an unexpected end of file is encountered while reading the audio data.
Returns
An array of floats representing the next sample frame from the audio data.

This method reads the next sample frame from the audio data based on the specified wave format. It handles different bit depths and encodings to convert the raw byte data into floats. If the end of the file is reached, it returns null.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TryReadFloat()

bool NAudio.Wave.WaveFileReader.TryReadFloat ( out float sampleValue)
inline

Tries to read the next sample frame and returns a float value if successful.

Parameters
sampleValueWhen this method returns, contains the float value read from the sample frame, if the read operation succeeded, or 0 if it failed.
Returns
true if a sample frame was successfully read and sampleValue contains a valid float value; otherwise, false.

This method is marked as obsolete and it is recommended to use ReadNextSampleFrame instead, as this version does not support stereo properly.

Here is the call graph for this function:

Member Data Documentation

◆ dataChunkLength

readonly long NAudio.Wave.WaveFileReader.dataChunkLength
private

◆ dataPosition

readonly long NAudio.Wave.WaveFileReader.dataPosition
private

◆ lockObject

readonly object NAudio.Wave.WaveFileReader.lockObject = new object()
private

◆ ownInput

readonly bool NAudio.Wave.WaveFileReader.ownInput
private

◆ waveFormat

readonly WaveFormat NAudio.Wave.WaveFileReader.waveFormat
private

◆ waveStream

Stream NAudio.Wave.WaveFileReader.waveStream
private

Property Documentation

◆ ExtraChunks

List<RiffChunk> NAudio.Wave.WaveFileReader.ExtraChunks
get

Gets a list of the additional chunks found in this file.

◆ Length

override long NAudio.Wave.WaveFileReader.Length
get

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) WaveStream.WaveFormat

◆ Position

override long NAudio.Wave.WaveFileReader.Position
getset

Position in the WAV data chunk. Stream.Position

◆ SampleCount

long NAudio.Wave.WaveFileReader.SampleCount
get

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.

◆ WaveFormat

override WaveFormat NAudio.Wave.WaveFileReader.WaveFormat
get

WaveStream.WaveFormat

Implements NAudio.Wave.IWaveProvider.


The documentation for this class was generated from the following file: