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

This class writes WAV data to a .wav file on disk. More...

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

Public Member Functions

 WaveFileWriter (Stream outStream, WaveFormat format)
 WaveFileWriter that actually writes to a stream.
 
 WaveFileWriter (string filename, WaveFormat format)
 Creates a new WaveFileWriter.
 
override int Read (byte[] buffer, int offset, int count)
 Throws an InvalidOperationException with the message "Cannot read from a WaveFileWriter".
 
override long Seek (long offset, SeekOrigin origin)
 Throws an InvalidOperationException with the message "Cannot seek within a WaveFileWriter".
 
override void SetLength (long value)
 Throws an InvalidOperationException with the message "Cannot set length of a WaveFileWriter".
 
void WriteData (byte[] data, int offset, int count)
 Writes the specified number of samples from the given array, starting at the specified offset.
 
override void Write (byte[] data, int offset, int count)
 Writes the specified bytes to the WAV file.
 
void WriteSample (float sample)
 Writes the specified audio sample to the wave file.
 
void WriteSamples (float[] samples, int offset, int count)
 Writes audio samples to the output stream based on the specified format and data.
 
void WriteData (short[] samples, int offset, int count)
 Writes 16 bit samples to the Wave file.
 
void WriteSamples (short[] samples, int offset, int count)
 Writes 16 bit samples to the Wave file.
 
override void Flush ()
 Updates the header and flushes the underlying stream.
 

Static Public Member Functions

static void CreateWaveFile16 (string filename, ISampleProvider sourceProvider)
 Creates a 16-bit wave file from the provided sourceProvider and saves it with the specified filename .
 
static void CreateWaveFile (string filename, IWaveProvider sourceProvider)
 Creates a wave file with the specified filename using the provided wave provider.
 
static void WriteWavFileToStream (Stream outStream, IWaveProvider sourceProvider)
 Writes the audio data from the specified sourceProvider to the outStream in WAV format.
 

Protected Member Functions

override void Dispose (bool disposing)
 Releases the unmanaged resources used by the ClassName and optionally releases the managed resources.
 
virtual void UpdateHeader (BinaryWriter writer)
 Updates the header of the audio file by flushing the writer and updating the RIFF, FACT, and data chunks.
 

Properties

string Filename [get]
 The wave file name or null if not applicable.
 
override long Length [get]
 Number of bytes of audio in the data chunk.
 
TimeSpan TotalTime [get]
 Total time (calculated from Length and average bytes per second)
 
WaveFormat WaveFormat [get]
 WaveFormat of this wave file.
 
override bool CanRead [get]
 Returns false: Cannot read from a WaveFileWriter.
 
override bool CanWrite [get]
 Returns true: Can write to a WaveFileWriter.
 
override bool CanSeek [get]
 Returns false: Cannot seek within a WaveFileWriter.
 
override long Position [get, set]
 Gets the Position in the WaveFile (i.e. number of bytes written so far)
 

Private Member Functions

void WriteDataChunkHeader ()
 Writes the data chunk header to the output stream.
 
void CreateFactChunk ()
 Creates a fact chunk in the output stream if it does not already exist.
 
bool HasFactChunk ()
 Checks if the wave format has a fact chunk.
 
void UpdateDataChunk (BinaryWriter writer)
 Updates the data chunk size in the binary writer at the specified position.
 
void UpdateRiffChunk (BinaryWriter writer)
 Updates the RIFF chunk in the output stream with the correct size.
 
void UpdateFactChunk (BinaryWriter writer)
 Updates the 'fact' chunk in the WAV file with the sample count information.
 
 ~WaveFileWriter ()
 Finaliser - should only be called if the user forgot to close this WaveFileWriter.
 

Private Attributes

Stream outStream
 
readonly BinaryWriter writer
 
long dataSizePos
 
long factSampleCountPos
 
long dataChunkSize
 
readonly WaveFormat format
 
readonly string filename
 
readonly byte[] value24 = new byte[3]
 

Detailed Description

This class writes WAV data to a .wav file on disk.

Constructor & Destructor Documentation

◆ WaveFileWriter() [1/2]

NAudio.Wave.WaveFileWriter.WaveFileWriter ( Stream outStream,
WaveFormat format )
inline

WaveFileWriter that actually writes to a stream.

Parameters
outStreamStream to be written to
formatWave format to use
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaveFileWriter() [2/2]

NAudio.Wave.WaveFileWriter.WaveFileWriter ( string filename,
WaveFormat format )
inline

Creates a new WaveFileWriter.

Parameters
filenameThe filename to write to
formatThe Wave Format of the output data

◆ ~WaveFileWriter()

NAudio.Wave.WaveFileWriter.~WaveFileWriter ( )
inlineprivate

Finaliser - should only be called if the user forgot to close this WaveFileWriter.

Here is the call graph for this function:

Member Function Documentation

◆ CreateFactChunk()

void NAudio.Wave.WaveFileWriter.CreateFactChunk ( )
inlineprivate

Creates a fact chunk in the output stream if it does not already exist.

This method checks if a fact chunk already exists in the output stream. If not, it writes the fact chunk header and initializes the sample count to 0.

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

◆ CreateWaveFile()

static void NAudio.Wave.WaveFileWriter.CreateWaveFile ( string filename,
IWaveProvider sourceProvider )
inlinestatic

Creates a wave file with the specified filename using the provided wave provider.

Parameters
filenameThe name of the wave file to be created.
sourceProviderThe wave provider used as the source for the wave file.
Exceptions
ExceptionThrown when the WAV file becomes too large.

This method creates a wave file with the specified filename using the provided wave provider. It reads data from the source provider in chunks and writes it to the wave file until the end of the source provider is reached. If the WAV file becomes too large, an exception is thrown.

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

◆ CreateWaveFile16()

static void NAudio.Wave.WaveFileWriter.CreateWaveFile16 ( string filename,
ISampleProvider sourceProvider )
inlinestatic

Creates a 16-bit wave file from the provided sourceProvider and saves it with the specified filename .

Parameters
filenameThe name of the wave file to be created.
sourceProviderThe sample provider used to generate the wave file.

This method creates a 16-bit wave file using the provided sourceProvider by converting the samples to 16-bit PCM format. The resulting wave file is saved with the specified filename .

Here is the call graph for this function:

◆ Dispose()

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

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

Parameters
disposingTrue to release both managed and unmanaged resources; false to release only unmanaged resources.
Exceptions
IOExceptionAn I/O error occurs.

This method releases the unmanaged resources used by the ClassName and optionally releases the managed resources. If disposing is true, this method also releases all managed resources that this object holds. This method is called by the public Dispose method and the Finalize method.

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

◆ Flush()

override void NAudio.Wave.WaveFileWriter.Flush ( )
inline

Updates the header and flushes the underlying stream.

This method updates the header information and flushes the underlying stream to persist the changes.

Here is the call graph for this function:

◆ HasFactChunk()

bool NAudio.Wave.WaveFileWriter.HasFactChunk ( )
inlineprivate

Checks if the wave format has a fact chunk.

Returns
True if the wave format has a fact chunk; otherwise, false.
Here is the caller graph for this function:

◆ Read()

override int NAudio.Wave.WaveFileWriter.Read ( byte[] buffer,
int offset,
int count )
inline

Throws an InvalidOperationException with the message "Cannot read from a WaveFileWriter".

Parameters
bufferThe buffer to read the data into.
offsetThe zero-based byte offset in buffer at which to begin storing the data read from the current stream.
countThe maximum number of bytes to read.
Exceptions
InvalidOperationExceptionThrown when an attempt is made to read from a WaveFileWriter.

◆ Seek()

override long NAudio.Wave.WaveFileWriter.Seek ( long offset,
SeekOrigin origin )
inline

Throws an InvalidOperationException with the message "Cannot seek within a WaveFileWriter".

Parameters
offsetThe new position within the stream.
originSpecifies the beginning, the end, or the current position as a reference point for offset, using a value of type SeekOrigin.
Exceptions
InvalidOperationExceptionThrown when seeking within a WaveFileWriter is not allowed.

◆ SetLength()

override void NAudio.Wave.WaveFileWriter.SetLength ( long value)
inline

Throws an InvalidOperationException with the message "Cannot set length of a WaveFileWriter".

Exceptions
InvalidOperationExceptionThrown when an attempt is made to set the length of a WaveFileWriter.

◆ UpdateDataChunk()

void NAudio.Wave.WaveFileWriter.UpdateDataChunk ( BinaryWriter writer)
inlineprivate

Updates the data chunk size in the binary writer at the specified position.

Parameters
writerThe binary writer to be updated.

This method seeks to the specified position in the binary writer and writes the updated data chunk size as a 32-bit unsigned integer.

Here is the caller graph for this function:

◆ UpdateFactChunk()

void NAudio.Wave.WaveFileWriter.UpdateFactChunk ( BinaryWriter writer)
inlineprivate

Updates the 'fact' chunk in the WAV file with the sample count information.

Parameters
writerThe BinaryWriter used to write data to the WAV file.

This method checks if the 'fact' chunk exists in the WAV file. If it does, it calculates the sample count based on the data chunk size, bits per sample, and number of channels, and updates the 'fact' chunk with the calculated sample count information.

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

◆ UpdateHeader()

virtual void NAudio.Wave.WaveFileWriter.UpdateHeader ( BinaryWriter writer)
inlineprotectedvirtual

Updates the header of the audio file by flushing the writer and updating the RIFF, FACT, and data chunks.

Parameters
writerThe BinaryWriter used to write to the audio file.

This method flushes the writer to ensure that all buffered data is written to the file. It then updates the RIFF chunk, FACT chunk, and data chunk in the audio file.

Reimplemented in NAudio.Wave.CueWaveFileWriter.

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

◆ UpdateRiffChunk()

void NAudio.Wave.WaveFileWriter.UpdateRiffChunk ( BinaryWriter writer)
inlineprivate

Updates the RIFF chunk in the output stream with the correct size.

Parameters
writerThe BinaryWriter used to write data to the output stream.

This method updates the RIFF chunk in the output stream by seeking to the 4th position from the beginning and writing the correct size, which is calculated as the length of the output stream minus 8 bytes.

Here is the caller graph for this function:

◆ Write()

override void NAudio.Wave.WaveFileWriter.Write ( byte[] data,
int offset,
int count )
inline

Writes the specified bytes to the WAV file.

Parameters
dataThe array of bytes to be written.
offsetThe zero-based byte offset in data at which to begin copying bytes to the WAV file.
countThe number of bytes to be written.
Exceptions
ArgumentExceptionThrown when the WAV file size exceeds the maximum allowed value.

This method writes the specified bytes from the input array data to the WAV file. It also updates the data chunk size accordingly.

Here is the caller graph for this function:

◆ WriteData() [1/2]

void NAudio.Wave.WaveFileWriter.WriteData ( byte[] data,
int offset,
int count )
inline

Writes the specified number of samples from the given array, starting at the specified offset.

Parameters
samplesThe array containing the samples to be written.
offsetThe zero-based index in the array at which to start writing samples.
countThe number of samples to write.
Exceptions
ObsoleteExceptionThis method is obsolete. Use WriteSamples instead.
Here is the call graph for this function:

◆ WriteData() [2/2]

void NAudio.Wave.WaveFileWriter.WriteData ( short[] samples,
int offset,
int count )
inline

Writes 16 bit samples to the Wave file.

Parameters
samplesThe buffer containing the 16 bit samples
offsetThe offset from which to start writing
countThe number of 16 bit samples to write
Here is the call graph for this function:

◆ WriteDataChunkHeader()

void NAudio.Wave.WaveFileWriter.WriteDataChunkHeader ( )
inlineprivate

Writes the data chunk header to the output stream.

This method writes the "data" header to the output stream using UTF-8 encoding and then writes a placeholder for the data size. The position of the data size placeholder is stored in dataSizePos.

Here is the caller graph for this function:

◆ WriteSample()

void NAudio.Wave.WaveFileWriter.WriteSample ( float sample)
inline

Writes the specified audio sample to the wave file.

Parameters
sampleThe audio sample to be written.
Exceptions
InvalidOperationExceptionThrown when the audio data format is not supported (i.e., not 16, 24, or 32 bit PCM or IEEE float).

This method writes the specified audio sample to the wave file based on the wave format's bits per sample and encoding. If the wave format is 16-bit, it writes the sample as a 16-bit integer and updates the data chunk size by 2 bytes. If the wave format is 24-bit, it converts the sample to a 24-bit integer and writes it as 3 bytes, updating the data chunk size accordingly. If the wave format is 32-bit with extensible encoding, it writes the sample as a 32-bit integer and updates the data chunk size by 4 bytes. If the wave format is IEEE float, it directly writes the sample as a float and updates the data chunk size by 4 bytes. If the wave format does not match any of the supported formats, an InvalidOperationException is thrown.

Here is the caller graph for this function:

◆ WriteSamples() [1/2]

void NAudio.Wave.WaveFileWriter.WriteSamples ( float[] samples,
int offset,
int count )
inline

Writes audio samples to the output stream based on the specified format and data.

Parameters
samplesThe array of audio samples to be written.
offsetThe offset in the samples array from which to start writing.
countThe number of samples to write.
Exceptions
InvalidOperationExceptionThrown when the audio data format is not supported (only 16, 24, or 32 bit PCM or IEEE float audio data are supported).

This method writes the audio samples to the output stream based on the specified format and data. It handles different bit depths and encodings, updating the data chunk size accordingly for each case.

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

◆ WriteSamples() [2/2]

void NAudio.Wave.WaveFileWriter.WriteSamples ( short[] samples,
int offset,
int count )
inline

Writes 16 bit samples to the Wave file.

Parameters
samplesThe buffer containing the 16 bit samples
offsetThe offset from which to start writing
countThe number of 16 bit samples to write

◆ WriteWavFileToStream()

static void NAudio.Wave.WaveFileWriter.WriteWavFileToStream ( Stream outStream,
IWaveProvider sourceProvider )
inlinestatic

Writes the audio data from the specified sourceProvider to the outStream in WAV format.

Parameters
outStreamThe output stream to write the WAV data to.
sourceProviderThe audio source provider containing the audio data to be written.
Exceptions
ArgumentNullExceptionThrown when either outStream or sourceProvider is null.

This method writes the audio data from the sourceProvider to the outStream in WAV format. It uses a buffer to read data from the sourceProvider and write it to the outStream . The process continues until no more data is available from the sourceProvider .

Here is the call graph for this function:

Member Data Documentation

◆ dataChunkSize

long NAudio.Wave.WaveFileWriter.dataChunkSize
private

◆ dataSizePos

long NAudio.Wave.WaveFileWriter.dataSizePos
private

◆ factSampleCountPos

long NAudio.Wave.WaveFileWriter.factSampleCountPos
private

◆ filename

readonly string NAudio.Wave.WaveFileWriter.filename
private

◆ format

readonly WaveFormat NAudio.Wave.WaveFileWriter.format
private

◆ outStream

Stream NAudio.Wave.WaveFileWriter.outStream
private

◆ value24

readonly byte [] NAudio.Wave.WaveFileWriter.value24 = new byte[3]
private

◆ writer

readonly BinaryWriter NAudio.Wave.WaveFileWriter.writer
private

Property Documentation

◆ CanRead

override bool NAudio.Wave.WaveFileWriter.CanRead
get

Returns false: Cannot read from a WaveFileWriter.

◆ CanSeek

override bool NAudio.Wave.WaveFileWriter.CanSeek
get

Returns false: Cannot seek within a WaveFileWriter.

◆ CanWrite

override bool NAudio.Wave.WaveFileWriter.CanWrite
get

Returns true: Can write to a WaveFileWriter.

◆ Filename

string NAudio.Wave.WaveFileWriter.Filename
get

The wave file name or null if not applicable.

◆ Length

override long NAudio.Wave.WaveFileWriter.Length
get

Number of bytes of audio in the data chunk.

◆ Position

override long NAudio.Wave.WaveFileWriter.Position
getset

Gets the Position in the WaveFile (i.e. number of bytes written so far)

◆ TotalTime

TimeSpan NAudio.Wave.WaveFileWriter.TotalTime
get

Total time (calculated from Length and average bytes per second)

◆ WaveFormat

WaveFormat NAudio.Wave.WaveFileWriter.WaveFormat
get

WaveFormat of this wave file.


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