问题
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