Using the PCMWAVEFORMAT Structure

For PCM audio data, use the PCMWAVEFORMAT structure to specify the data format. The following example shows how to set up a PCMWAVEFORMAT structure for 11.025 kilohertz (kHz) 8-bit mono and for 44.1 kHz 16-bit stereo. After setting up PCMWAVEFORMAT, the example calls the IsFormatSupported function to verify that the PCM waveform output device supports the format. The source code for IsFormatSupported is shown in an example in Determining Nonstandard Format Support.

UINT wReturn;

PCMWAVEFORMAT pcmWaveFormat;

// Set up PCMWAVEFORMAT for 11 kHz 8-bit mono.

pcmWaveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;

pcmWaveFormat.wf.nChannels = 1;

pcmWaveFormat.wf.nSamplesPerSec = 11025L;

pcmWaveFormat.wf.nAvgBytesPerSec = 11025L;

pcmWaveFormat.wf.nBlockAlign = 1;

pcmWaveFormat.wBitsPerSample = 8;

// See if format is supported by any device in system.

wReturn = IsFormatSupported(&pcmWaveFormat, WAVE_MAPPER);

// Report results.

if (wReturn == 0)

MessageBox(hMainWnd, "11 kHz 8-bit mono is supported.",

"", MB_ICONINFORMATION);

else if (wReturn == WAVERR_BADFORMAT)

MessageBox(hMainWnd, "11 kHz 8-bit mono NOT supported.",

"", MB_ICONINFORMATION);

else

MessageBox(hMainWnd, "Error opening waveform device.",

"Error", MB_ICONEXCLAMATION);

// Set up PCMWAVEFORMAT for 44.1 kHz 16-bit stereo.

pcmWaveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;

pcmWaveFormat.wf.nChannels = 2;

pcmWaveFormat.wf.nSamplesPerSec = 44100L;

pcmWaveFormat.wf.nAvgBytesPerSec = 176400L;

pcmWaveFormat.wf.nBlockAlign = 4;

pcmWaveFormat.wBitsPerSample = 32;

// See if format is supported by any device in the system.

wReturn = IsFormatSupported(&pcmWaveFormat, WAVE_MAPPER);

/ Report results.

if (wReturn == 0)

MessageBox(hMainWnd, "44.1 kHz 16-bit stereo is supported.",

"", MB_ICONINFORMATION);

else if (wReturn == WAVERR_BADFORMAT)

MessageBox(hMainWnd, "44.1 kHz 16-bit stereo NOT supported.",

"", MB_ICONINFORMATION);

else

MessageBox(hMainWnd, "Error opening waveform device.",

"Error", MB_ICONEXCLAMATION);

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database