Table of Contents

Class AiffFileWriter

Namespace
NAudio.Wave
Assembly
NAudio.Core.dll

This class writes audio data to a .aif file on disk

public class AiffFileWriter : Stream, IDisposable, IAsyncDisposable
Inheritance
AiffFileWriter
Implements
Inherited Members

Constructors

AiffFileWriter(Stream, WaveFormat)

AiffFileWriter that actually writes to a stream

public AiffFileWriter(Stream outStream, WaveFormat format)

Parameters

outStream Stream

Stream to be written to

format WaveFormat

Wave format to use

AiffFileWriter(string, WaveFormat)

Creates a new AiffFileWriter

public AiffFileWriter(string filename, WaveFormat format)

Parameters

filename string

The filename to write to

format WaveFormat

The Wave Format of the output data

Properties

CanRead

Returns false: Cannot read from a AiffFileWriter

public override bool CanRead { get; }

Property Value

bool

CanSeek

Returns false: Cannot seek within a AiffFileWriter

public override bool CanSeek { get; }

Property Value

bool

CanWrite

Returns true: Can write to a AiffFileWriter

public override bool CanWrite { get; }

Property Value

bool

Filename

The aiff file name or null if not applicable

public string Filename { get; }

Property Value

string

Length

Number of bytes of audio in the data chunk

public override long Length { get; }

Property Value

long

Position

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

public override long Position { get; set; }

Property Value

long

WaveFormat

WaveFormat of this aiff file

public WaveFormat WaveFormat { get; }

Property Value

WaveFormat

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

filename string

The filename to use

sourceProvider WaveStream

The source WaveProvider

Dispose(bool)

Actually performs the close,making sure the header contains the correct data

protected override void Dispose(bool disposing)

Parameters

disposing bool

True 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

buffer byte[]
offset int
count int

Returns

int

Seek(long, SeekOrigin)

Seek is not supported for a AiffFileWriter

public override long Seek(long offset, SeekOrigin origin)

Parameters

offset long
origin SeekOrigin

Returns

long

SetLength(long)

SetLength is not supported for AiffFileWriter

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 AiffFile (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 int

the offset from which to start writing

count int

the number of bytes to write

WriteSample(float)

Writes a single sample to the Aiff file

public void WriteSample(float sample)

Parameters

sample float

the sample to write (assumed floating point with 1.0f as max value)

WriteSamples(short[], int, int)

Writes 16 bit samples to the Aiff file

public void WriteSamples(short[] samples, int offset, int count)

Parameters

samples short[]

The buffer containing the 16 bit samples

offset int

The offset from which to start writing

count int

The number of 16 bit samples to write

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)

Parameters

samples float[]

The buffer containing the floating point samples

offset int

The offset from which to start writing

count int

The number of floating point samples to write