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;
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.
Declared in mmreg.h and mmsystem.h. Include mmreg.h or mmsystem.h.
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.