This class writes WAV data to a .wav file on disk.
More...
|
| 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.
|
|
|
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.
|
|
|
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)
|
|
|
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.
|
|
This class writes WAV data to a .wav file on disk.
◆ WaveFileWriter() [1/2]
NAudio.Wave.WaveFileWriter.WaveFileWriter |
( |
Stream | outStream, |
|
|
WaveFormat | format ) |
|
inline |
WaveFileWriter that actually writes to a stream.
- Parameters
-
outStream | Stream to be written to |
format | Wave format to use |
◆ WaveFileWriter() [2/2]
NAudio.Wave.WaveFileWriter.WaveFileWriter |
( |
string | filename, |
|
|
WaveFormat | format ) |
|
inline |
Creates a new WaveFileWriter.
- Parameters
-
filename | The filename to write to |
format | The 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.
◆ 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.
◆ 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
-
filename | The name of the wave file to be created. |
sourceProvider | The wave provider used as the source for the wave file. |
- Exceptions
-
Exception | Thrown 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.
◆ 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
-
filename | The name of the wave file to be created. |
sourceProvider | The 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 .
◆ 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
-
disposing | True to release both managed and unmanaged resources; false to release only unmanaged resources. |
- Exceptions
-
IOException | An 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.
◆ 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.
◆ 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.
◆ 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
-
buffer | The buffer to read the data into. |
offset | The zero-based byte offset in buffer at which to begin storing the data read from the current stream. |
count | The maximum number of bytes to read. |
- Exceptions
-
InvalidOperationException | Thrown 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
-
offset | The new position within the stream. |
origin | Specifies the beginning, the end, or the current position as a reference point for offset, using a value of type SeekOrigin. |
- Exceptions
-
InvalidOperationException | Thrown 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
-
InvalidOperationException | Thrown 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
-
writer | The 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.
◆ UpdateFactChunk()
void NAudio.Wave.WaveFileWriter.UpdateFactChunk |
( |
BinaryWriter | writer | ) |
|
|
inlineprivate |
Updates the 'fact' chunk in the WAV file with the sample count information.
- Parameters
-
writer | The 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.
◆ 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
-
writer | The 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.
◆ UpdateRiffChunk()
void NAudio.Wave.WaveFileWriter.UpdateRiffChunk |
( |
BinaryWriter | writer | ) |
|
|
inlineprivate |
Updates the RIFF chunk in the output stream with the correct size.
- Parameters
-
writer | The 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.
◆ Write()
override void NAudio.Wave.WaveFileWriter.Write |
( |
byte[] | data, |
|
|
int | offset, |
|
|
int | count ) |
|
inline |
Writes the specified bytes to the WAV file.
- Parameters
-
data | The array of bytes to be written. |
offset | The zero-based byte offset in data at which to begin copying bytes to the WAV file. |
count | The number of bytes to be written. |
- Exceptions
-
ArgumentException | Thrown 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.
◆ 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
-
samples | The array containing the samples to be written. |
offset | The zero-based index in the array at which to start writing samples. |
count | The number of samples to write. |
- Exceptions
-
ObsoleteException | This method is obsolete. Use WriteSamples instead. |
◆ WriteData() [2/2]
void NAudio.Wave.WaveFileWriter.WriteData |
( |
short[] | samples, |
|
|
int | offset, |
|
|
int | count ) |
|
inline |
Writes 16 bit samples to the Wave file.
- Parameters
-
samples | The buffer containing the 16 bit samples |
offset | The offset from which to start writing |
count | The number of 16 bit samples to write |
◆ 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.
◆ WriteSample()
void NAudio.Wave.WaveFileWriter.WriteSample |
( |
float | sample | ) |
|
|
inline |
Writes the specified audio sample to the wave file.
- Parameters
-
sample | The audio sample to be written. |
- Exceptions
-
InvalidOperationException | Thrown 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.
◆ 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
-
samples | The array of audio samples to be written. |
offset | The offset in the samples array from which to start writing. |
count | The number of samples to write. |
- Exceptions
-
InvalidOperationException | Thrown 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.
◆ WriteSamples() [2/2]
void NAudio.Wave.WaveFileWriter.WriteSamples |
( |
short[] | samples, |
|
|
int | offset, |
|
|
int | count ) |
|
inline |
Writes 16 bit samples to the Wave file.
- Parameters
-
samples | The buffer containing the 16 bit samples |
offset | The offset from which to start writing |
count | The 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
-
outStream | The output stream to write the WAV data to. |
sourceProvider | The audio source provider containing the audio data to be written. |
- Exceptions
-
ArgumentNullException | Thrown 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 .
◆ 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 |
◆ 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 of this wave file.
The documentation for this class was generated from the following file:
- /Users/sumansaurabh/Documents/my-startup/xeno-rat/Plugins/LiveMicrophone/lib/NAudio.Core/Wave/WaveOutputs/WaveFileWriter.cs