Class AiffFileWriter
This class writes audio data to a .aif file on disk
public class AiffFileWriter : Stream, IAsyncDisposable, IDisposable
- Inheritance
-
AiffFileWriter
- Implements
- Inherited Members
Constructors
AiffFileWriter(Stream, WaveFormat)
AiffFileWriter that actually writes to a stream
public AiffFileWriter(Stream outStream, WaveFormat format)
Parameters
outStreamStreamStream to be written to
formatWaveFormatWave format to use
Remarks
The supplied stream is not owned by the writer: disposing the writer finalizes the AIFF header and flushes the stream, but leaves it open for the caller to dispose. Use the filename constructor if you want the writer to own and close the underlying file.
AiffFileWriter(string, WaveFormat)
Creates a new AiffFileWriter
public AiffFileWriter(string filename, WaveFormat format)
Parameters
filenamestringThe filename to write to
formatWaveFormatThe Wave Format of the output data
Properties
CanRead
Returns false: Cannot read from a AiffFileWriter
public override bool CanRead { get; }
Property Value
CanSeek
Returns false: Cannot seek within a AiffFileWriter
public override bool CanSeek { get; }
Property Value
CanWrite
Returns true: Can write to a AiffFileWriter
public override bool CanWrite { get; }
Property Value
Filename
The aiff 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 AiffFile (i.e. number of bytes written so far)
public override long Position { get; set; }
Property Value
WaveFormat
WaveFormat of this aiff file
public WaveFormat WaveFormat { get; }
Property Value
Methods
CreateAiffFile(string, WaveStream)
Creates an Aiff 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 Aiff File will grow indefinitely.
public static void CreateAiffFile(string filename, WaveStream sourceProvider)
Parameters
filenamestringThe filename to use
sourceProviderWaveStreamThe source WaveProvider
Dispose(bool)
Actually performs the close,making sure the header contains the correct data
protected override void Dispose(bool disposing)
Parameters
disposingboolTrue if called from
Dispose
~AiffFileWriter()
Finaliser - should only be called if the user forgot to close this AiffFileWriter
protected ~AiffFileWriter()
Flush()
Ensures data is written to disk
public override void Flush()
Read(byte[], int, int)
Read is not supported for a AiffFileWriter
public override int Read(byte[] buffer, int offset, int count)
Parameters
Returns
Seek(long, SeekOrigin)
Seek is not supported for a AiffFileWriter
public override long Seek(long offset, SeekOrigin origin)
Parameters
offsetlongoriginSeekOrigin
Returns
SetLength(long)
SetLength is not supported for AiffFileWriter
public override void SetLength(long value)
Parameters
valuelong
UpdateHeader(BinaryWriter)
Updates the header with file size information
protected virtual void UpdateHeader(BinaryWriter writer)
Parameters
writerBinaryWriter
Write(byte[], int, int)
Appends bytes to the AiffFile (assumes they are already in the correct format)
public override void Write(byte[] data, int offset, int count)
Parameters
databyte[]the buffer containing the wave data
offsetintthe offset from which to start writing
countintthe number of bytes to write
Write(ReadOnlySpan<byte>)
Appends bytes to the AiffFile (assumes they are already in the correct format)
public override void Write(ReadOnlySpan<byte> buffer)
Parameters
bufferReadOnlySpan<byte>the buffer containing the wave data
WriteSample(float)
Writes a single sample to the AIFF file.
public void WriteSample(float sample)
Parameters
samplefloatThe sample value, between -1.0f and 1.0f.
WriteSamples(short[], int, int)
Writes 16 bit samples to the Aiff file
public void WriteSamples(short[] samples, int offset, int count)
Parameters
samplesshort[]The buffer containing the 16 bit samples
offsetintThe offset from which to start writing
countintThe number of 16 bit samples to write
WriteSamples(ReadOnlySpan<short>)
Writes 16 bit samples to the Aiff file
public void WriteSamples(ReadOnlySpan<short> samples)
Parameters
samplesReadOnlySpan<short>The buffer containing the 16 bit samples
WriteSamples(float[], int, int)
Writes 32 bit floating point samples to the Aiff file They will be converted to the appropriate bit depth depending on the WaveFormat of the AIF file
public void WriteSamples(float[] samples, int offset, int count)