Previous Next

WAVEFORMATEX

The WAVEFORMATEX structure specifies the data format of a wave audio stream.

typedef struct
{
  WORD  wFormatTag;
  WORD  nChannels;
  DWORD  nSamplesPerSec;
  DWORD  nAvgBytesPerSec;
  WORD  nBlockAlign;
  WORD  wBitsPerSample;
  WORD  cbSize;
} WAVEFORMATEX; *PWAVEFORMATEX;

Members

wFormatTag
Specifies the waveform audio format type. See the following Comments section.
nChannels
Specifies the number of channels of audio data. For monophonic audio, set this member to 1. For stereo, set this member to 2.
nSamplesPerSec
Specifies the sample frequency at which each channel should be played or recorded. If wFormatTag = WAVE_FORMAT_PCM, then common values for nSamplesPerSec are 8.0 kHz, 11.025 kHz, 22.05 kHz, and 44.1 kHz. For example, to specify a sample frequency of 11.025 kHz, set nSamplesPerSec to 11025. For non-PCM formats, this member should be computed according to the manufacturer's specification of the format tag.
nAvgBytesPerSec
Specifies the required average data transfer rate in bytes per second. This value is useful for estimating buffer size.
nBlockAlign
Specifies the block alignment in bytes. The block alignment is the size of the minimum atomic unit of data for the wFormatTag format type. If wFormatTag = WAVE_FORMAT_PCM, set nBlockAlign to (nChannels*wBitsPerSample)/8, which is the size of a single audio frame. For non-PCM formats, this member should be computed according to the manufacturer's specification for the format tag.

Playback and record software should process a multiple of nBlockAlign bytes of data at a time. Data written to and read from a device should always start at the beginning of a block.

wBitsPerSample
Specifies the number of bits per sample for the format type specified by wFormatTag. If wFormatTag = WAVE_FORMAT_PCM, then wBitsPerSample should be set to either 8 or 16. For non-PCM formats, this member should be set according to the manufacturer's specification for the format tag. Some compression schemes cannot define a value for wBitsPerSample. In this case, set wBitsPerSample to zero.
cbSize
Specifies the size, in bytes, of extra format information appended to the end of the WAVEFORMATEX structure. This information can be used by non-PCM formats to store extra attributes for the wFormatTag. If no extra information is required by the wFormatTag, this member must be set to zero. For WAVE_FORMAT_PCM formats, this member is ignored.

Headers

Declared in mmreg.h and mmsystem.h. Include mmreg.h or mmsystem.h.

Comments

As a self-contained format descriptor, the WAVEFORMATEX structure is obsolete and has been replaced by the WAVEFORMATEXTENSIBLE structure. WAVEFORMATEXTENSIBLE contains an embedded WAVEFORMATEX structure as a member, but it also contains additional data for describing multichannel formats and sample sizes greater than 16 bits. WAVEFORMATEX cannot unambiguously specify data formats with more than two channels or with sample sizes greater than 16 bits.

For the benefit of older drivers, the WDM audio subsystem provides limited support for the WAVEFORMATEX structure. New drivers should be written to use WAVEFORMATEXTENSIBLE instead. The WDM audio subsystem in all versions of Windows except for Windows 98 "Gold" supports WAVEFORMATEXTENSIBLE. For information about the limited support available for WAVEFORMATEX, see Data Formats for Audio Wave Streams.

The wFormatTag member is set to one of the wave formats that are defined in mmreg.h. Some of the more common nonproprietary formats are listed in the following table.

wFormatTag Value Meaning
WAVE_FORMAT_PCM PCM (pulse-code modulated) data in integer format.
WAVE_FORMAT_IEEE_FLOAT PCM data in IEEE floating-point format.
WAVE_FORMAT_DRM DRM-encoded format (for digital-audio content protected by Microsoft Digital Rights Management).
WAVE_FORMAT_EXTENSIBLE Extended WAVEFORMATEX structure (see WAVEFORMATEXTENSIBLE).
WAVE_FORMAT_ALAW A-law-encoded format.
WAVE_FORMAT_MULAW Mu-law-encoded format.
WAVE_FORMAT_ADPCM ADPCM (adaptive differential pulse-code modulated) data.
WAVE_FORMAT_MPEG MPEG-1 data format (stream conforms to ISO 11172-3 Audio specification).
WAVE_FORMAT_DOLBY_AC3_SPDIF AC3 (aka Dolby Digital) over S/PDIF.

See mmreg.h for the complete list of WAVE_FORMAT_XXX formats.

WAVEFORMATEX is nearly identical to the PCMWAVEFORMAT structure, which is an obsolete structure used to specify PCM formats. The only difference is that WAVEFORMATEX contains a cbSize member and PCMWAVEFORMAT does not. By convention, cbSize should be ignored when wFormatTag = WAVE_FORMAT_PCM. This convention allows driver software to treat the WAVEFORMATEX and PCMWAVEFORMAT structures identically in the case of a PCM format. For more information about PCMWAVEFORMAT, see the Platform SDK documentation.

When wFormatTag = WAVE_FORMAT_PCM, initialize cbSize to zero. For all other values of wFormatTag, cbSize specifies how many bytes of additional format data are appended to the WAVEFORMATEX structure.

When wFormatTag = WAVE_FORMAT_EXTENSIBLE, set cbSize to sizeof(WAVEFORMATEXTENSIBLE)-sizeof(WAVEFORMATEX) plus the size of any format-specific data that is appended to the WAVEFORMATEXTENSIBLE structure.

See Also

WAVEFORMATEXTENSIBLE