This article mainly introduces the use of WINDOWSAPI implementation of the PCM audio method, very practical a function, the need for friends can refer to the next
This paper introduces the method of using WINDOWSAPI to realize the playback of PCM audio, which is similar to the principle of using WINDOWSAPI to get audio recording, so it is no longer detailed to describe the parameters of the specific function and structure, the same part is omitted, and the main functional part of the code is introduced. As shown below:
1. Waveoutgetnumdevs
2. Waveoutgetdevcaps
3. Waveoutopen
callback function:
?
1 |
void CALLBACK PlayCallback(HWAVEOUT hwaveout, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2); |
4. Waveoutprepareheader
5. Waveoutwrite: Start playing immediately after execution, the current buffer playback completion will call the callback function
Here's what to note:
In order to be able to achieve a continuous playback effect, in the 4th need to prepare two or two more playback data.
Interested friends can compare the previous article manually debug the example described in this article.
Ways to play PCM audio using WINDOWSAPI