将wavs加载到内存中,然后使用Win32 API异步播放声音 [英] Load wavs into memory then play sounds asynchronously using Win32 API

查看:40
本文介绍了将wavs加载到内存中,然后使用Win32 API异步播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C ++和Win32 API编写一个简单的游戏.我想在初始化阶段(游戏开始之前)将一些声音效果加载到内存中.然后,我希望能够在游戏过程中异步触发这些声音.

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.

我研究了一些推荐mmlib(PlaySound)的帖子,它可以工作,但是示例似乎每次都从文件加载,如下所示:

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.

我该怎么做?

推荐答案

PlaySound

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

因此,首先将文件加载到内存中,然后将指针传递到缓冲区,然后将 SND_FILENAME 标志换为 SND_MEMORY 标志.

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.

这篇关于将wavs加载到内存中,然后使用Win32 API异步播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆