多通道声音与winmm,许多WaveOutOpen?

发布于 2024-12-08 15:34:31 字数 334 浏览 0 评论 0原文

我正在尝试在 Windows XP 上以多通道(并行)方式播放声音。 我在某处读到过,用 WinMM 播放并行声音可能是不可能的, 但我观察到的是:

当我调用 WaveOutOpen() 一次,然后多次调用 WaveOutWrite() 时 那么声音就不是并行的——它们是排队的。

但是当我调用 WaveOutOpen 说九次(然后存储九个句柄) 然后用九种不同的声音调用九次 WaveOutWrite() 并行播放(多通道) - 即它们是混合的。

它似乎有效,但我不确定是否可以,因为我没有发现它明确说明 在任何教程或文档中。

以这种“许多 WaveOutOpen”方式播放声音可以吗?

I am trying to play a sound on Windows XP in multi-channel (parallel) manner.
I had read somewhere that playing parallel sounds with WinMM is maybe not possible,
but here is what I observe:

When I call WaveOutOpen() once, and then call many WaveOutWrite() many times
then sounds are not parallel - they are queued.

But when I call WaveOutOpen say nine times (and then store nine handles to it)
and then call nine times WaveOutWrite() with nine different sounds they are
played in parallel (multi-channel) - that is they are mixed.

It seems to work but I am not sure if it is okay because I don't find it stated clearly
in any tutorial or documentation.

It is okay to play sound in such 'many WaveOutOpen' way??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请别遗忘我 2024-12-15 15:34:31

当我调用 WaveOutOpen() 一次,然后调用多次 WaveOutWrite() 时
那么声音不是并行的 - 它们是排队的。

这正是应该发生的事情。 WaveOutWrite 将下一个缓冲区排队。它允许您以小块的形式发送您想要播放的音频。

但是当我打电话给 WaveOutOpen 说九次(然后存储九次
句柄),然后调用九次 WaveOutWrite(),其中 9
它们并行播放不同的声音(多通道) - 即
它们是混合的。

再次强调,这是正确且符合预期的。这是同时播放许多声音的最简单方法。然而,如果您想要精确混合样本,您应该自己将音频样本混合到一个样本流中,并通过单个 WaveOut 设备进行播放。

When I call WaveOutOpen() once, and then call many WaveOutWrite() many
times then sounds are not parallel - they are queued.

That's exactly what is supposed to happen. WaveOutWrite queues the next buffer. It allows you to send the audio you want to play in small chunks.

But when I call WaveOutOpen say nine times (and then store nine
handles to it) and then call nine times WaveOutWrite() with nine
different sounds they are played in parallel (multi-channel) - that is
they are mixed.

Again, this is correct and expected. This is the simplest way to play back many simultaneous sounds. If you want sample accurate mixing however, you should mix the audio samples yourself into one stream of samples and play that through a single WaveOut device.

美胚控场 2024-12-15 15:34:31

我对 waveOut* API 同时播放和混合声音的能力感到更正。

这是好奇的测试代码: http://www.alax.info /trac/public/browser/trunk/Utilities/WaveOutMultiPlay 使用参数 abc 启动的应用程序分别以 1、5 和 15 kHz 的频率在不同线程上播放声音,并且它们搅拌均匀。

同时 DirectShow 音频渲染器建立在同一 API 之上的 (WaveOut) Filter 无法播放除单个流之外的任何内容,没有明显的原因。

仅供参考,waveOutOpen API 很久以前就已退役,目前是较新 API 的包装器。 waveOutOpen 假设音频输出设备被打开以供独占使用,因此不能保证同时打开的多个设备会产生混合音频输出。要实现这种行为,您最好使用更新的音频 API:DirectSound、DirectSound 或 WASAPI 之上的 DirectShow。

I stand corrected with ability of waveOut* API to play sounds simultaneously and mixed.

Here is test code for the curious: http://www.alax.info/trac/public/browser/trunk/Utilities/WaveOutMultiPlay An application started with arguments abc plays on different threads sounds at 1, 5 and 15 kHz respectively and they mix well.

At the same time DirectShow Audio Renderer (WaveOut) Filter built on top of the same API is unable to play anything more that a single stream, for no visible reason.

FYI waveOutOpen API is retired since long ago and currently is wrapper on top of newer APIs. waveOutOpen assumes that audio output device is opened for exclusive use so there is no guarantee that multiply opened devices simultanesouly would produce mixed audio output. To achieve such behavior you would be better off with a newer audio API: DirectSound, DirectShow on top of DirectSound or WASAPI.

旧街凉风 2024-12-15 15:34:31

如果您的产品面向消费者,我建议使用 DirectSound。

从 DirectX8 开始,API 已经变得非常简单,大多数消费类机器都会安装它。

I suggest going with DirectSound if your product is for consumers.

From DirectX8 onwards the API is at the point where it is actually quite painless and most consumer machines will have it installed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文