Class WaveFormat
Represents a Wave file format
public class WaveFormat
- Inheritance
-
WaveFormat
- Derived
- Inherited Members
- Extension Methods
Constructors
WaveFormat()
Creates a new PCM 44.1Khz stereo 16 bit format
public WaveFormat()
WaveFormat(BinaryReader)
Reads a new WaveFormat object from a stream
public WaveFormat(BinaryReader br)
Parameters
br
BinaryReaderA binary reader that wraps the stream
WaveFormat(int, int)
Creates a new 16 bit wave format with the specified sample rate and channel count
public WaveFormat(int sampleRate, int channels)
Parameters
WaveFormat(int, int, int)
Creates a new PCM format with the specified sample rate, bit depth and channels
public WaveFormat(int rate, int bits, int channels)
Parameters
Fields
averageBytesPerSecond
for buffer estimation
protected int averageBytesPerSecond
Field Value
bitsPerSample
number of bits per sample of mono data
protected short bitsPerSample
Field Value
blockAlign
block size of data
protected short blockAlign
Field Value
channels
number of channels
protected short channels
Field Value
extraSize
number of following bytes
protected short extraSize
Field Value
sampleRate
sample rate
protected int sampleRate
Field Value
waveFormatTag
format type
protected WaveFormatEncoding waveFormatTag
Field Value
Properties
AverageBytesPerSecond
Returns the average number of bytes used per second
public int AverageBytesPerSecond { get; }
Property Value
BitsPerSample
Returns the number of bits per sample (usually 16 or 32, sometimes 24 or 8) Can be 0 for some codecs
public int BitsPerSample { get; }
Property Value
BlockAlign
Returns the block alignment
public virtual int BlockAlign { get; }
Property Value
Channels
Returns the number of channels (1=mono,2=stereo etc)
public int Channels { get; }
Property Value
Encoding
Returns the encoding type used
public WaveFormatEncoding Encoding { get; }
Property Value
ExtraSize
Returns the number of extra bytes used by this waveformat. Often 0, except for compressed formats which store extra data after the WAVEFORMATEX header
public int ExtraSize { get; }
Property Value
SampleRate
Returns the sample rate (samples per second)
public int SampleRate { get; }
Property Value
Methods
ConvertLatencyToByteSize(int)
Gets the size of a wave buffer equivalent to the latency in milliseconds.
public int ConvertLatencyToByteSize(int milliseconds)
Parameters
milliseconds
intThe milliseconds.
Returns
CreateALawFormat(int, int)
Creates an A-law wave format
public static WaveFormat CreateALawFormat(int sampleRate, int channels)
Parameters
Returns
- WaveFormat
Wave Format
CreateCustomFormat(WaveFormatEncoding, int, int, int, int, int)
Creates a WaveFormat with custom members
public static WaveFormat CreateCustomFormat(WaveFormatEncoding tag, int sampleRate, int channels, int averageBytesPerSecond, int blockAlign, int bitsPerSample)
Parameters
tag
WaveFormatEncodingThe encoding
sampleRate
intSample Rate
channels
intNumber of channels
averageBytesPerSecond
intAverage Bytes Per Second
blockAlign
intBlock Align
bitsPerSample
intBits Per Sample
Returns
CreateIeeeFloatWaveFormat(int, int)
Creates a new 32 bit IEEE floating point wave format
public static WaveFormat CreateIeeeFloatWaveFormat(int sampleRate, int channels)
Parameters
Returns
CreateMuLawFormat(int, int)
Creates a Mu-law wave format
public static WaveFormat CreateMuLawFormat(int sampleRate, int channels)
Parameters
Returns
- WaveFormat
Wave Format
Equals(object)
Compares with another WaveFormat object
public override bool Equals(object obj)
Parameters
obj
objectObject to compare to
Returns
- bool
True if the objects are the same
FromFormatChunk(BinaryReader, int)
Reads in a WaveFormat (with extra data) from a fmt chunk (chunk identifier and length should already have been read)
public static WaveFormat FromFormatChunk(BinaryReader br, int formatChunkLength)
Parameters
br
BinaryReaderBinary reader
formatChunkLength
intFormat chunk length
Returns
- WaveFormat
A WaveFormatExtraData
GetHashCode()
Provides a Hashcode for this WaveFormat
public override int GetHashCode()
Returns
- int
A hashcode
MarshalFromPtr(nint)
Helper function to retrieve a WaveFormat structure from a pointer
public static WaveFormat MarshalFromPtr(nint pointer)
Parameters
pointer
nintWaveFormat structure
Returns
MarshalToPtr(WaveFormat)
Helper function to marshal WaveFormat to an IntPtr
public static nint MarshalToPtr(WaveFormat format)
Parameters
format
WaveFormatWaveFormat
Returns
- nint
IntPtr to WaveFormat structure (needs to be freed by callee)
Serialize(BinaryWriter)
Writes this WaveFormat object to a stream
public virtual void Serialize(BinaryWriter writer)
Parameters
writer
BinaryWriterthe output stream
ToString()
Reports this WaveFormat as a string
public override string ToString()
Returns
- string
String describing the wave format