Class WaveFileWriter
This class writes WAV data to a .wav file on disk
public class WaveFileWriter : Stream, IDisposable, IAsyncDisposable
- Inheritance
-
WaveFileWriter
- Implements
- Derived
- Inherited Members
Constructors
WaveFileWriter(Stream, WaveFormat)
WaveFileWriter that actually writes to a stream
public WaveFileWriter(Stream outStream, WaveFormat format)
Parameters
outStream
StreamStream to be written to
format
WaveFormatWave format to use
WaveFileWriter(string, WaveFormat)
Creates a new WaveFileWriter
public WaveFileWriter(string filename, WaveFormat format)
Parameters
filename
stringThe filename to write to
format
WaveFormatThe Wave Format of the output data
Properties
CanRead
Returns false: Cannot read from a WaveFileWriter
public override bool CanRead { get; }
Property Value
CanSeek
Returns false: Cannot seek within a WaveFileWriter
public override bool CanSeek { get; }
Property Value
CanWrite
Returns true: Can write to a WaveFileWriter
public override bool CanWrite { get; }
Property Value
Filename
The wave file name or null if not applicable
public string Filename { get; }
Property Value
Length
Number of bytes of audio in the data chunk
public override long Length { get; }
Property Value
Position
Gets the Position in the WaveFile (i.e. number of bytes written so far)
public override long Position { get; set; }
Property Value
TotalTime
Total time (calculated from Length and average bytes per second)
public TimeSpan TotalTime { get; }
Property Value
WaveFormat
WaveFormat of this wave file
public WaveFormat WaveFormat { get; }
Property Value
Methods
CreateWaveFile(string, IWaveProvider)
Creates a Wave file by reading all the data from a WaveProvider BEWARE: the WaveProvider MUST return 0 from its Read method when it is finished, or the Wave File will grow indefinitely.
public static void CreateWaveFile(string filename, IWaveProvider sourceProvider)
Parameters
filename
stringThe filename to use
sourceProvider
IWaveProviderThe source WaveProvider
CreateWaveFile16(string, ISampleProvider)
Creates a 16 bit Wave File from an ISampleProvider BEWARE: the source provider must not return data indefinitely
public static void CreateWaveFile16(string filename, ISampleProvider sourceProvider)
Parameters
filename
stringThe filename to write to
sourceProvider
ISampleProviderThe source sample provider
Dispose(bool)
Actually performs the close,making sure the header contains the correct data
protected override void Dispose(bool disposing)
Parameters
disposing
boolTrue if called from
Dispose
~WaveFileWriter()
Finaliser - should only be called if the user forgot to close this WaveFileWriter
protected ~WaveFileWriter()
Flush()
Ensures data is written to disk Also updates header, so that WAV file will be valid up to the point currently written
public override void Flush()
Read(byte[], int, int)
Read is not supported for a WaveFileWriter
public override int Read(byte[] buffer, int offset, int count)
Parameters
Returns
Seek(long, SeekOrigin)
Seek is not supported for a WaveFileWriter
public override long Seek(long offset, SeekOrigin origin)
Parameters
offset
longorigin
SeekOrigin
Returns
SetLength(long)
SetLength is not supported for WaveFileWriter
public override void SetLength(long value)
Parameters
value
long
UpdateHeader(BinaryWriter)
Updates the header with file size information
protected virtual void UpdateHeader(BinaryWriter writer)
Parameters
writer
BinaryWriter
Write(byte[], int, int)
Appends bytes to the WaveFile (assumes they are already in the correct format)
public override void Write(byte[] data, int offset, int count)
Parameters
data
byte[]the buffer containing the wave data
offset
intthe offset from which to start writing
count
intthe number of bytes to write
WriteData(byte[], int, int)
Appends bytes to the WaveFile (assumes they are already in the correct format)
[Obsolete("Use Write instead")]
public void WriteData(byte[] data, int offset, int count)
Parameters
data
byte[]the buffer containing the wave data
offset
intthe offset from which to start writing
count
intthe number of bytes to write
WriteData(short[], int, int)
Writes 16 bit samples to the Wave file
[Obsolete("Use WriteSamples instead")]
public void WriteData(short[] samples, int offset, int count)
Parameters
samples
short[]The buffer containing the 16 bit samples
offset
intThe offset from which to start writing
count
intThe number of 16 bit samples to write
WriteSample(float)
Writes a single sample to the Wave file
public void WriteSample(float sample)
Parameters
sample
floatthe sample to write (assumed floating point with 1.0f as max value)
WriteSamples(short[], int, int)
Writes 16 bit samples to the Wave file
public void WriteSamples(short[] samples, int offset, int count)
Parameters
samples
short[]The buffer containing the 16 bit samples
offset
intThe offset from which to start writing
count
intThe number of 16 bit samples to write
WriteSamples(float[], int, int)
Writes 32 bit floating point samples to the Wave file They will be converted to the appropriate bit depth depending on the WaveFormat of the WAV file
public void WriteSamples(float[] samples, int offset, int count)
Parameters
samples
float[]The buffer containing the floating point samples
offset
intThe offset from which to start writing
count
intThe number of floating point samples to write
WriteWavFileToStream(Stream, IWaveProvider)
Writes to a stream by reading all the data from a WaveProvider BEWARE: the WaveProvider MUST return 0 from its Read method when it is finished, or the Wave File will grow indefinitely.
public static void WriteWavFileToStream(Stream outStream, IWaveProvider sourceProvider)
Parameters
outStream
StreamThe stream the method will output to
sourceProvider
IWaveProviderThe source WaveProvider