與此頁面相關聯的功能,波形音訊,是舊版功能。 WASAPI 和 Audio Graphs已取代它。 WASAPI 和 音訊圖形 已針對 Windows 10 和 Windows 11 優化。 Microsoft強烈建議新程式代碼盡可能使用 WASAPI 和 Audio Graphs,而不是 波波音頻。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]
針對不超過兩個通道且具有 8 位或 16 位樣本的 PCM 音訊數據,請使用 的 SEMANTICATEX 結構來指定數據格式。
下列範例示範如何為 11.025 kHz 8 位單聲道和 44.1 kHz 16 位立體聲設置 WAVEFORMATEX 結構。 在設定 WAVEFORMATEX之後,此範例會呼叫 IsFormatSupported 函式,以確認 PCM 波形輸出裝置支援該格式。 IsFormatSupported 的原始程式碼會顯示在 判斷非標準格式支援範例中。
UINT wReturn;
WAVEFORMATEX pcmWaveFormat;
// Set up WAVEFORMATEX for 11 kHz 8-bit mono.
pcmWaveFormat.wFormatTag = WAVE_FORMAT_PCM;
pcmWaveFormat.nChannels = 1;
pcmWaveFormat.nSamplesPerSec = 11025L;
pcmWaveFormat.nAvgBytesPerSec = 11025L;
pcmWaveFormat.nBlockAlign = 1;
pcmWaveFormat.wBitsPerSample = 8;
pcmWaveFormat.cbSize = 0;
// 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 WAVEFORMATEX for 44.1 kHz 16-bit stereo.
pcmWaveFormat.wFormatTag = WAVE_FORMAT_PCM;
pcmWaveFormat.nChannels = 2;
pcmWaveFormat.nSamplesPerSec = 44100L;
pcmWaveFormat.nAvgBytesPerSec = 176400L;
pcmWaveFormat.nBlockAlign = 4;
pcmWaveFormat.wBitsPerSample = 16;
pcmWaveFormat.cbSize = 0;
// 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);