Load wavs into memory then play sounds asynchronously using Win32 API

亡梦爱人 提交于 2021-02-05 08:57:26

问题


I'm writing a simple game, using C++ and the Win32 API. I'd like to load a few sound effects into memory during the initialisation phase (before the game starts). Then I want to be able to trigger those sounds asynchronously during the game.

I've researched a few posts that recommend mmlib, (PlaySound), this works but the examples seem to load from file each time, something like this:

PlaySound("rocket_launch.wav", NULL, SND_FILENAME | SND_ASYNC);

I'd like to load my sounds into memory at the start, then play them whenever. Hopefully I won't need to use a resource file.

How can I do this?


回答1:


The PlaySound docs say to pass in SND_MEMORY to indicate that the first parameter points to a memory buffer.

So first, load the file into memory, and then pass in the pointer to the buffer, and swap out the SND_FILENAME flag for the SND_MEMORY flag.



来源:https://stackoverflow.com/questions/32320825/load-wavs-into-memory-then-play-sounds-asynchronously-using-win32-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!