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

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

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

Public Member Functions

 AiffFileWriter (Stream outStream, WaveFormat format)
 AiffFileWriter that actually writes to a stream.
 
 AiffFileWriter (string filename, WaveFormat format)
 Creates a new AiffFileWriter.
 
override int Read (byte[] buffer, int offset, int count)
 Throws an InvalidOperationException with a message indicating that reading from an AiffFileWriter is not allowed.
 
override long Seek (long offset, SeekOrigin origin)
 Throws an InvalidOperationException with a message indicating that seeking within an AiffFileWriter is not allowed.
 
override void SetLength (long value)
 Throws an InvalidOperationException with the message "Cannot set length of an AiffFileWriter".
 
override void Write (byte[] data, int offset, int count)
 Writes the specified byte array to the output stream after swapping the bytes based on the format's BitsPerSample property.
 
void WriteSample (float sample)
 Writes a sample to the audio writer based on the wave format.
 
void WriteSamples (float[] samples, int offset, int count)
 Writes audio samples to the underlying stream based on the specified wave format.
 
void WriteSamples (short[] samples, int offset, int count)
 Writes 16 bit samples to the Aiff file.
 
override void Flush ()
 Flushes the buffer of the writer.
 

Static Public Member Functions

static void CreateAiffFile (string filename, WaveStream sourceProvider)
 Creates an AIFF audio file from the provided WaveStream.
 

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 binary writer.
 

Properties

string Filename [get]
 The aiff file name or null if not applicable.
 
override long Length [get]
 Number of bytes of audio in the data chunk.
 
WaveFormat WaveFormat [get]
 WaveFormat of this aiff file.
 
override bool CanRead [get]
 Returns false: Cannot read from a AiffFileWriter.
 
override bool CanWrite [get]
 Returns true: Can write to a AiffFileWriter.
 
override bool CanSeek [get]
 Returns false: Cannot seek within a AiffFileWriter.
 
override long Position [get, set]
 Gets the Position in the AiffFile (i.e. number of bytes written so far)
 

Private Member Functions

void WriteSsndChunkHeader ()
 Writes the SSND chunk header to the output stream.
 
byte[] SwapEndian (short n)
 Swaps the endianness of the input integer and returns the result as a byte array.
 
byte[] SwapEndian (int n)
 
void CreateCommChunk ()
 Creates a 'COMM' chunk in the WAV file.
 
void UpdateCommChunk (BinaryWriter writer)
 Updates the communication chunk in the binary writer.
 
void UpdateSsndChunk (BinaryWriter writer)
 Updates the SSND chunk in the WAV file by writing the data chunk size in little-endian format.
 
 ~AiffFileWriter ()
 Finaliser - should only be called if the user forgot to close this AiffFileWriter.
 

Private Attributes

Stream outStream
 
BinaryWriter writer
 
long dataSizePos
 
long commSampleCountPos
 
int dataChunkSize = 8
 
WaveFormat format
 
string filename
 
byte[] value24 = new byte[3]
 

Detailed Description

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

Constructor & Destructor Documentation

◆ AiffFileWriter() [1/2]

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

AiffFileWriter 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:

◆ AiffFileWriter() [2/2]

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

Creates a new AiffFileWriter.

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

◆ ~AiffFileWriter()

NAudio.Wave.AiffFileWriter.~AiffFileWriter ( )
inlineprivate

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

Here is the call graph for this function:

Member Function Documentation

◆ CreateAiffFile()

static void NAudio.Wave.AiffFileWriter.CreateAiffFile ( string filename,
WaveStream sourceProvider )
inlinestatic

Creates an AIFF audio file from the provided WaveStream.

Parameters
filenameThe name of the AIFF file to be created.
sourceProviderThe WaveStream providing the audio data.

This method reads audio data from the sourceProvider and writes it to an AIFF file specified by filename . The method uses a buffer to read and write the audio data in chunks, and it ensures that the entire audio data is written to the AIFF file.

Here is the call graph for this function:

◆ CreateCommChunk()

void NAudio.Wave.AiffFileWriter.CreateCommChunk ( )
inlineprivate

Creates a 'COMM' chunk in the WAV file.

This method writes the 'COMM' chunk to the WAV file. The 'COMM' chunk contains information about the audio format, such as the number of channels, bits per sample, and sample rate. It also includes a placeholder for the total number of samples, which is updated later when the actual audio data is written to the file.

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

◆ Dispose()

override void NAudio.Wave.AiffFileWriter.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 disposes of the unmanaged resources used by the ClassName. If disposing is true, it also disposes of the managed resources. The method first checks if outStream is not null, then attempts to update the header using the UpdateHeader method. If an IOException occurs during the update, the method ensures that the outStream is disposed in a finally block to prevent resource leaks.

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

◆ Flush()

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

Flushes the buffer of the writer.

This method flushes the buffer of the writer, writing any buffered data to the underlying stream.

Here is the caller graph for this function:

◆ Read()

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

Throws an InvalidOperationException with a message indicating that reading from an AiffFileWriter is not allowed.

Parameters
bufferThe buffer to read 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 to indicate that reading from an AiffFileWriter is not allowed.

◆ Seek()

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

Throws an InvalidOperationException with a message indicating that seeking within an AiffFileWriter is not allowed.

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 an AiffFileWriter is attempted.

◆ SetLength()

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

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

Exceptions
InvalidOperationExceptionThrown when attempting to set the length of an AiffFileWriter.

◆ SwapEndian() [1/2]

byte[] NAudio.Wave.AiffFileWriter.SwapEndian ( int n)
inlineprivate

◆ SwapEndian() [2/2]

byte[] NAudio.Wave.AiffFileWriter.SwapEndian ( short n)
inlineprivate

Swaps the endianness of the input integer and returns the result as a byte array.

Parameters
nThe integer value whose endianness needs to be swapped.
Returns
A byte array representing the input integer with swapped endianness.

This method swaps the endianness of the input integer by rearranging its bytes in reverse order to convert between little-endian and big-endian representations. The resulting byte array contains the bytes of the input integer in the opposite order.

Here is the caller graph for this function:

◆ UpdateCommChunk()

void NAudio.Wave.AiffFileWriter.UpdateCommChunk ( BinaryWriter writer)
inlineprivate

Updates the communication chunk in the binary writer.

Parameters
writerThe binary writer to update.

This method seeks to the position of the communication sample count in the writer and updates it with the calculated value. The calculated value is obtained by swapping the endianness of the result of the expression (dataChunkSize * 8 / format.BitsPerSample / format.Channels).

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

◆ UpdateHeader()

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

Updates the header of the binary writer.

Parameters
writerThe binary writer to update the header for.

This method flushes the current state, seeks to position 4 in the writer, and writes the updated length of the output stream in little-endian format. It then updates the communication chunk and sound chunk within the writer.

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

◆ UpdateSsndChunk()

void NAudio.Wave.AiffFileWriter.UpdateSsndChunk ( BinaryWriter writer)
inlineprivate

Updates the SSND chunk in the WAV file by writing the data chunk size in little-endian format.

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

This method seeks to the position of the data size in the WAV file and writes the data chunk size in little-endian format using the provided BinaryWriter.

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

◆ Write()

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

Writes the specified byte array to the output stream after swapping the bytes based on the format's BitsPerSample property.

Parameters
dataThe byte array to be written to the output stream.
offsetThe zero-based byte offset in data at which to begin copying bytes to the output stream.
countThe number of bytes to be written to the output stream.

This method swaps the bytes in the input byte array data based on the format's BitsPerSample property. It then writes the swapped byte array to the output stream starting from the specified offset and writes the specified number of bytes. The dataChunkSize field is updated by adding the count of bytes written to the output stream.

◆ WriteSample()

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

Writes a sample to the audio writer based on the wave format.

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

This method writes the input sample to the audio writer based on the wave format. If the wave format is 16 bits per sample, it writes the sample as a 16-bit integer and updates the data chunk size by 2. If the wave format is 24 bits per sample, it writes the sample as a 24-bit integer and updates the data chunk size by 3. If the wave format is 32 bits per sample and the encoding is extensible, it writes the sample as a 32-bit unsigned integer and updates the data chunk size by 4.

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

◆ WriteSamples() [1/2]

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

Writes audio samples to the underlying stream based on the specified wave format.

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

This method writes the audio samples to the underlying stream based on the specified wave format. It handles 16, 24, and 32 bit PCM data by writing the samples in little-endian format and updating the data chunk size accordingly.

Here is the call graph for this function:

◆ WriteSamples() [2/2]

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

Writes 16 bit samples to the Aiff 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:

◆ WriteSsndChunkHeader()

void NAudio.Wave.AiffFileWriter.WriteSsndChunkHeader ( )
inlineprivate

Writes the SSND chunk header to the output stream.

This method writes the "SSND" identifier to the output stream, followed by placeholder values for data size and zero offset. It then writes the block align value after swapping its endianness.

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

Member Data Documentation

◆ commSampleCountPos

long NAudio.Wave.AiffFileWriter.commSampleCountPos
private

◆ dataChunkSize

int NAudio.Wave.AiffFileWriter.dataChunkSize = 8
private

◆ dataSizePos

long NAudio.Wave.AiffFileWriter.dataSizePos
private

◆ filename

string NAudio.Wave.AiffFileWriter.filename
private

◆ format

WaveFormat NAudio.Wave.AiffFileWriter.format
private

◆ outStream

Stream NAudio.Wave.AiffFileWriter.outStream
private

◆ value24

byte [] NAudio.Wave.AiffFileWriter.value24 = new byte[3]
private

◆ writer

BinaryWriter NAudio.Wave.AiffFileWriter.writer
private

Property Documentation

◆ CanRead

override bool NAudio.Wave.AiffFileWriter.CanRead
get

Returns false: Cannot read from a AiffFileWriter.

◆ CanSeek

override bool NAudio.Wave.AiffFileWriter.CanSeek
get

Returns false: Cannot seek within a AiffFileWriter.

◆ CanWrite

override bool NAudio.Wave.AiffFileWriter.CanWrite
get

Returns true: Can write to a AiffFileWriter.

◆ Filename

string NAudio.Wave.AiffFileWriter.Filename
get

The aiff file name or null if not applicable.

◆ Length

override long NAudio.Wave.AiffFileWriter.Length
get

Number of bytes of audio in the data chunk.

◆ Position

override long NAudio.Wave.AiffFileWriter.Position
getset

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

◆ WaveFormat

WaveFormat NAudio.Wave.AiffFileWriter.WaveFormat
get

WaveFormat of this aiff file.


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