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

Represents a Wave file format. More...

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

Public Member Functions

 WaveFormat ()
 Creates a new PCM 44.1Khz stereo 16 bit format.
 
 WaveFormat (int sampleRate, int channels)
 Creates a new 16 bit wave format with the specified sample rate and channel count.
 
int ConvertLatencyToByteSize (int milliseconds)
 Converts the given latency in milliseconds to the corresponding byte size based on the average bytes per second.
 
 WaveFormat (int rate, int bits, int channels)
 Creates a new PCM format with the specified sample rate, bit depth and channels.
 
 WaveFormat (BinaryReader br)
 Reads a new WaveFormat object from a stream.
 
override string ToString ()
 Returns a string representation of the WaveFormat object.
 
override bool Equals (object obj)
 Determines whether the current WaveFormat object is equal to another object.
 
override int GetHashCode ()
 Computes the hash code for the WaveFormat instance.
 
virtual void Serialize (BinaryWriter writer)
 Serializes the wave format data and writes it to the specified BinaryWriter.
 

Static Public Member Functions

static WaveFormat CreateCustomFormat (WaveFormatEncoding tag, int sampleRate, int channels, int averageBytesPerSecond, int blockAlign, int bitsPerSample)
 Creates a custom WaveFormat with the specified parameters.
 
static WaveFormat CreateALawFormat (int sampleRate, int channels)
 Creates a new WaveFormat with A-Law encoding.
 
static WaveFormat CreateMuLawFormat (int sampleRate, int channels)
 Creates a new WaveFormat with MuLaw encoding.
 
static WaveFormat CreateIeeeFloatWaveFormat (int sampleRate, int channels)
 Creates a new IEEE float wave format with the specified sample rate and number of channels.
 
static WaveFormat MarshalFromPtr (IntPtr pointer)
 Marshals a WaveFormat structure from the specified pointer.
 
static IntPtr MarshalToPtr (WaveFormat format)
 Marshals the WaveFormat structure to a pointer.
 
static WaveFormat FromFormatChunk (BinaryReader br, int formatChunkLength)
 Reads the wave format and extra data from the specified binary reader and returns the WaveFormatExtraData.
 

Protected Attributes

WaveFormatEncoding waveFormatTag
 format type
 
short channels
 number of channels
 
int sampleRate
 sample rate
 
int averageBytesPerSecond
 for buffer estimation
 
short blockAlign
 block size of data
 
short bitsPerSample
 number of bits per sample of mono data
 
short extraSize
 number of following bytes
 

Properties

WaveFormatEncoding Encoding [get]
 Returns the encoding type used.
 
int Channels [get]
 Returns the number of channels (1=mono,2=stereo etc)
 
int SampleRate [get]
 Returns the sample rate (samples per second)
 
int AverageBytesPerSecond [get]
 Returns the average number of bytes used per second.
 
virtual int BlockAlign [get]
 Returns the block alignment.
 
int BitsPerSample [get]
 Returns the number of bits per sample (usually 16 or 32, sometimes 24 or 8) Can be 0 for some codecs.
 
int ExtraSize [get]
 Returns the number of extra bytes used by this waveformat. Often 0, except for compressed formats which store extra data after the WAVEFORMATEX header.
 

Private Member Functions

void ReadWaveFormat (BinaryReader br, int formatChunkLength)
 Reads the wave format information from the provided BinaryReader.
 

Detailed Description

Represents a Wave file format.

Constructor & Destructor Documentation

◆ WaveFormat() [1/4]

NAudio.Wave.WaveFormat.WaveFormat ( )
inline

Creates a new PCM 44.1Khz stereo 16 bit format.

Here is the caller graph for this function:

◆ WaveFormat() [2/4]

NAudio.Wave.WaveFormat.WaveFormat ( int sampleRate,
int channels )
inline

Creates a new 16 bit wave format with the specified sample rate and channel count.

Parameters
sampleRateSample Rate
channelsNumber of channels

◆ WaveFormat() [3/4]

NAudio.Wave.WaveFormat.WaveFormat ( int rate,
int bits,
int channels )
inline

Creates a new PCM format with the specified sample rate, bit depth and channels.

◆ WaveFormat() [4/4]

NAudio.Wave.WaveFormat.WaveFormat ( BinaryReader br)
inline

Reads a new WaveFormat object from a stream.

Parameters
brA binary reader that wraps the stream
Here is the call graph for this function:

Member Function Documentation

◆ ConvertLatencyToByteSize()

int NAudio.Wave.WaveFormat.ConvertLatencyToByteSize ( int milliseconds)
inline

Converts the given latency in milliseconds to the corresponding byte size based on the average bytes per second.

Parameters
millisecondsThe latency in milliseconds to be converted.
Returns
The byte size calculated based on the average bytes per second and the given latency.

This method calculates the byte size by multiplying the average bytes per second by the given latency in milliseconds and then rounding it to the nearest block align if necessary. If the calculated byte size is not already aligned to the block size, it is adjusted to the next block-aligned value.

Here is the caller graph for this function:

◆ CreateALawFormat()

static WaveFormat NAudio.Wave.WaveFormat.CreateALawFormat ( int sampleRate,
int channels )
inlinestatic

Creates a new WaveFormat with A-Law encoding.

Parameters
sampleRateThe sample rate of the audio.
channelsThe number of channels in the audio.
Returns
A new WaveFormat with A-Law encoding, sample rate, channels, and other parameters set accordingly.
Here is the call graph for this function:

◆ CreateCustomFormat()

static WaveFormat NAudio.Wave.WaveFormat.CreateCustomFormat ( WaveFormatEncoding tag,
int sampleRate,
int channels,
int averageBytesPerSecond,
int blockAlign,
int bitsPerSample )
inlinestatic

Creates a custom WaveFormat with the specified parameters.

Parameters
tagThe encoding format of the WaveFormat.
sampleRateThe sample rate of the WaveFormat.
channelsThe number of channels in the WaveFormat.
averageBytesPerSecondThe average bytes per second for the WaveFormat.
blockAlignThe block alignment for the WaveFormat.
bitsPerSampleThe number of bits per sample in the WaveFormat.
Returns
A custom WaveFormat with the specified parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateIeeeFloatWaveFormat()

static WaveFormat NAudio.Wave.WaveFormat.CreateIeeeFloatWaveFormat ( int sampleRate,
int channels )
inlinestatic

Creates a new IEEE float wave format with the specified sample rate and number of channels.

Parameters
sampleRateThe sample rate of the wave format.
channelsThe number of channels in the wave format.
Returns
A new WaveFormat object representing the IEEE float wave format with the specified parameters.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CreateMuLawFormat()

static WaveFormat NAudio.Wave.WaveFormat.CreateMuLawFormat ( int sampleRate,
int channels )
inlinestatic

Creates a new WaveFormat with MuLaw encoding.

Parameters
sampleRateThe sample rate of the audio.
channelsThe number of channels in the audio.
Returns
A new WaveFormat with MuLaw encoding, based on the specified sampleRate and channels .
Here is the call graph for this function:

◆ Equals()

override bool NAudio.Wave.WaveFormat.Equals ( object obj)
inline

Determines whether the current WaveFormat object is equal to another object.

Parameters
objThe object to compare with the current WaveFormat object.
Returns
true if the specified object is equal to the current object; otherwise, false.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ FromFormatChunk()

static WaveFormat NAudio.Wave.WaveFormat.FromFormatChunk ( BinaryReader br,
int formatChunkLength )
inlinestatic

Reads the wave format and extra data from the specified binary reader and returns the WaveFormatExtraData.

Parameters
brThe BinaryReader used to read the wave format and extra data.
formatChunkLengthThe length of the format chunk.
Returns
The WaveFormatExtraData containing the wave format and extra data.

This method reads the wave format from the specified BinaryReader using the formatChunkLength to determine the length of the format chunk. It then reads the extra data from the same BinaryReader. The WaveFormatExtraData object containing the wave format and extra data is returned.

Here is the caller graph for this function:

◆ GetHashCode()

override int NAudio.Wave.WaveFormat.GetHashCode ( )
inline

Computes the hash code for the WaveFormat instance.

Returns
The computed hash code.

◆ MarshalFromPtr()

static WaveFormat NAudio.Wave.WaveFormat.MarshalFromPtr ( IntPtr pointer)
inlinestatic

Marshals a WaveFormat structure from the specified pointer.

Parameters
pointerA pointer to the WaveFormat structure.
Returns
The WaveFormat structure marshaled from the specified pointer .

This method marshals a WaveFormat structure from the specified pointer . It first marshals the WaveFormat structure using Marshal.PtrToStructure method. Then, based on the wave format encoding, it may further marshal the structure to a more specific type, such as WaveFormatExtensible, AdpcmWaveFormat, Gsm610WaveFormat, or WaveFormatExtraData. If the wave format encoding is PCM, the extra size is set to 0 to avoid reading corrupt data. If the wave format encoding is Extensible, Adpcm, or Gsm610, the structure is further marshaled to the specific type. If the wave format encoding is not recognized and the extra size is greater than 0, the structure is marshaled to WaveFormatExtraData. The marshaled WaveFormat structure is then returned.

Here is the caller graph for this function:

◆ MarshalToPtr()

static IntPtr NAudio.Wave.WaveFormat.MarshalToPtr ( WaveFormat format)
inlinestatic

Marshals the WaveFormat structure to a pointer.

Parameters
formatThe WaveFormat structure to be marshaled.
Returns
A pointer to the marshaled WaveFormat structure.

This method allocates memory for the WaveFormat structure, marshals the structure to the allocated memory, and returns a pointer to the marshaled structure. The allocated memory must be released using Marshal.FreeHGlobal when it is no longer needed to prevent memory leaks.

Here is the caller graph for this function:

◆ ReadWaveFormat()

void NAudio.Wave.WaveFormat.ReadWaveFormat ( BinaryReader br,
int formatChunkLength )
inlineprivate

Reads the wave format information from the provided BinaryReader.

Parameters
brThe BinaryReader to read the wave format from.
formatChunkLengthThe length of the format chunk.
Exceptions
InvalidDataExceptionThrown when the formatChunkLength is less than 16, indicating an invalid WaveFormat structure.

This method reads the wave format information from the provided BinaryReader, including the wave format tag, number of channels, sample rate, average bytes per second, block align, and bits per sample. If the formatChunkLength is greater than 16, it also reads the extra size and checks for format chunk mismatch.

Here is the caller graph for this function:

◆ Serialize()

virtual void NAudio.Wave.WaveFormat.Serialize ( BinaryWriter writer)
inlinevirtual

Serializes the wave format data and writes it to the specified BinaryWriter.

Parameters
writerThe BinaryWriter to which the wave format data will be written.

This method serializes the wave format data including encoding, channels, sample rate, average bytes per second, block align, bits per sample, and extra size, and writes it to the specified BinaryWriter.

Reimplemented in NAudio.Wave.Gsm610WaveFormat, NAudio.Wave.TrueSpeechWaveFormat, and NAudio.Wave.WaveFormatExtraData.

Here is the caller graph for this function:

◆ ToString()

override string NAudio.Wave.WaveFormat.ToString ( )
inline

Returns a string representation of the WaveFormat object.

Returns
A string representing the wave format, including the number of bits per sample, the sample rate in Hertz, and the number of channels.

This method returns a string representation of the WaveFormat object based on the wave format tag. If the wave format tag is PCM or Extensible, it returns a string with the number of bits per sample, the sample rate in Hertz, and the number of channels. If the wave format tag is IEEEFloat, it returns a string with the number of bits per sample, the sample rate in Hertz, and the number of channels. If the wave format tag is neither PCM, Extensible, nor IEEEFloat, it returns the wave format tag as a string.

Member Data Documentation

◆ averageBytesPerSecond

int NAudio.Wave.WaveFormat.averageBytesPerSecond
protected

for buffer estimation

◆ bitsPerSample

short NAudio.Wave.WaveFormat.bitsPerSample
protected

number of bits per sample of mono data

◆ blockAlign

short NAudio.Wave.WaveFormat.blockAlign
protected

block size of data

◆ channels

short NAudio.Wave.WaveFormat.channels
protected

number of channels

◆ extraSize

short NAudio.Wave.WaveFormat.extraSize
protected

number of following bytes

◆ sampleRate

int NAudio.Wave.WaveFormat.sampleRate
protected

sample rate

◆ waveFormatTag

WaveFormatEncoding NAudio.Wave.WaveFormat.waveFormatTag
protected

format type

Property Documentation

◆ AverageBytesPerSecond

int NAudio.Wave.WaveFormat.AverageBytesPerSecond
get

Returns the average number of bytes used per second.

◆ BitsPerSample

int NAudio.Wave.WaveFormat.BitsPerSample
get

Returns the number of bits per sample (usually 16 or 32, sometimes 24 or 8) Can be 0 for some codecs.

◆ BlockAlign

virtual int NAudio.Wave.WaveFormat.BlockAlign
get

Returns the block alignment.

◆ Channels

int NAudio.Wave.WaveFormat.Channels
get

Returns the number of channels (1=mono,2=stereo etc)

◆ Encoding

WaveFormatEncoding NAudio.Wave.WaveFormat.Encoding
get

Returns the encoding type used.

◆ ExtraSize

int NAudio.Wave.WaveFormat.ExtraSize
get

Returns the number of extra bytes used by this waveformat. Often 0, except for compressed formats which store extra data after the WAVEFORMATEX header.

◆ SampleRate

int NAudio.Wave.WaveFormat.SampleRate
get

Returns the sample rate (samples per second)


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