This class writes audio data to a .aif file on disk.
More...
|
| 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.
|
|
|
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.
|
|
|
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)
|
|
|
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.
|
|
This class writes audio data to a .aif file on disk.
◆ AiffFileWriter() [1/2]
NAudio.Wave.AiffFileWriter.AiffFileWriter |
( |
Stream | outStream, |
|
|
WaveFormat | format ) |
|
inline |
AiffFileWriter that actually writes to a stream.
- Parameters
-
outStream | Stream to be written to |
format | Wave format to use |
◆ AiffFileWriter() [2/2]
NAudio.Wave.AiffFileWriter.AiffFileWriter |
( |
string | filename, |
|
|
WaveFormat | format ) |
|
inline |
Creates a new AiffFileWriter.
- Parameters
-
filename | The filename to write to |
format | The 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.
◆ CreateAiffFile()
static void NAudio.Wave.AiffFileWriter.CreateAiffFile |
( |
string | filename, |
|
|
WaveStream | sourceProvider ) |
|
inlinestatic |
Creates an AIFF audio file from the provided WaveStream.
- Parameters
-
filename | The name of the AIFF file to be created. |
sourceProvider | The 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.
◆ 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.
◆ 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
-
disposing | True to release both managed and unmanaged resources; false to release only unmanaged resources. |
- Exceptions
-
IOException | An 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.
◆ 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.
◆ 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
-
buffer | The buffer to read 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 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
-
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 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
-
InvalidOperationException | Thrown 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
-
n | The 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.
◆ UpdateCommChunk()
void NAudio.Wave.AiffFileWriter.UpdateCommChunk |
( |
BinaryWriter | writer | ) |
|
|
inlineprivate |
Updates the communication chunk in the binary writer.
- Parameters
-
writer | The 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).
◆ UpdateHeader()
virtual void NAudio.Wave.AiffFileWriter.UpdateHeader |
( |
BinaryWriter | writer | ) |
|
|
inlineprotectedvirtual |
Updates the header of the binary writer.
- Parameters
-
writer | The 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.
◆ 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
-
writer | The 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.
◆ 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
-
data | The byte array to be written to the output stream. |
offset | The zero-based byte offset in data at which to begin copying bytes to the output stream. |
count | The 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
-
sample | The sample to be written. |
- Exceptions
-
InvalidOperationException | Thrown 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.
◆ 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
-
samples | The array of audio samples to be written. |
offset | The offset in the samples array at which to begin writing. |
count | The number of samples to write. |
- Exceptions
-
InvalidOperationException | Thrown 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.
◆ WriteSamples() [2/2]
void NAudio.Wave.AiffFileWriter.WriteSamples |
( |
short[] | samples, |
|
|
int | offset, |
|
|
int | count ) |
|
inline |
Writes 16 bit samples to the Aiff 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 |
◆ 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.
◆ 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
◆ outStream
Stream NAudio.Wave.AiffFileWriter.outStream |
|
private |
◆ value24
byte [] NAudio.Wave.AiffFileWriter.value24 = new byte[3] |
|
private |
◆ writer
BinaryWriter NAudio.Wave.AiffFileWriter.writer |
|
private |
◆ 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 of this aiff 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/AiffFileWriter.cs