Table of Contents

Class WaveFormat

Namespace
NAudio.Wave
Assembly
NAudio.Core.dll

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 BinaryReader

A 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

sampleRate int

Sample Rate

channels int

Number of channels

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

rate int
bits int
channels int

Fields

averageBytesPerSecond

for buffer estimation

protected int averageBytesPerSecond

Field Value

int

bitsPerSample

number of bits per sample of mono data

protected short bitsPerSample

Field Value

short

blockAlign

block size of data

protected short blockAlign

Field Value

short

channels

number of channels

protected short channels

Field Value

short

extraSize

number of following bytes

protected short extraSize

Field Value

short

sampleRate

sample rate

protected int sampleRate

Field Value

int

waveFormatTag

format type

protected WaveFormatEncoding waveFormatTag

Field Value

WaveFormatEncoding

Properties

AverageBytesPerSecond

Returns the average number of bytes used per second

public int AverageBytesPerSecond { get; }

Property Value

int

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

int

BlockAlign

Returns the block alignment

public virtual int BlockAlign { get; }

Property Value

int

Channels

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

public int Channels { get; }

Property Value

int

Encoding

Returns the encoding type used

public WaveFormatEncoding Encoding { get; }

Property Value

WaveFormatEncoding

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

int

SampleRate

Returns the sample rate (samples per second)

public int SampleRate { get; }

Property Value

int

Methods

ConvertLatencyToByteSize(int)

Gets the size of a wave buffer equivalent to the latency in milliseconds.

public int ConvertLatencyToByteSize(int milliseconds)

Parameters

milliseconds int

The milliseconds.

Returns

int

CreateALawFormat(int, int)

Creates an A-law wave format

public static WaveFormat CreateALawFormat(int sampleRate, int channels)

Parameters

sampleRate int

Sample Rate

channels int

Number of Channels

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 WaveFormatEncoding

The encoding

sampleRate int

Sample Rate

channels int

Number of channels

averageBytesPerSecond int

Average Bytes Per Second

blockAlign int

Block Align

bitsPerSample int

Bits Per Sample

Returns

WaveFormat

CreateIeeeFloatWaveFormat(int, int)

Creates a new 32 bit IEEE floating point wave format

public static WaveFormat CreateIeeeFloatWaveFormat(int sampleRate, int channels)

Parameters

sampleRate int

sample rate

channels int

number of channels

Returns

WaveFormat

CreateMuLawFormat(int, int)

Creates a Mu-law wave format

public static WaveFormat CreateMuLawFormat(int sampleRate, int channels)

Parameters

sampleRate int

Sample Rate

channels int

Number of Channels

Returns

WaveFormat

Wave Format

Equals(object)

Compares with another WaveFormat object

public override bool Equals(object obj)

Parameters

obj object

Object 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 BinaryReader

Binary reader

formatChunkLength int

Format 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 nint

WaveFormat structure

Returns

WaveFormat

MarshalToPtr(WaveFormat)

Helper function to marshal WaveFormat to an IntPtr

public static nint MarshalToPtr(WaveFormat format)

Parameters

format WaveFormat

WaveFormat

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 BinaryWriter

the output stream

ToString()

Reports this WaveFormat as a string

public override string ToString()

Returns

string

String describing the wave format