简体   繁体   English

Core Audio (WASAPI) 缓冲区事件计时

[英]Core Audio (WASAPI) buffer event timing

I'm using the Windows core audio functions, mostly WASAPI, to render an exclusive stream, following the example in Exclusive-Mode Streams.我正在使用 Windows 核心音频功能(主要是 WASAPI)来渲染专有 stream,遵循 Exclusive-Mode Streams 中的示例。

This creates two alternating buffers played and filled alternately.这会创建两个交替播放和填充的缓冲区。 There is an event tied to buffer completion that wakes the thread so it can refill the buffer just completed.有一个与缓冲区完成相关的事件会唤醒线程,以便它可以重新填充刚刚完成的缓冲区。 GETPOSITION shows that the thread is waked when the current buffer is at frame 147 of a 160 frame buffer. GETPOSITION 显示当当前缓冲区位于 160 帧缓冲区的第 147 帧时线程被唤醒。 This leaves me with 13/160 of a buffer time to get a new buffer, fill it, and release it.这让我有 13/160 的缓冲时间来获取新的缓冲区、填充它并释放它。 I have a lot of calculation to do, this isn't enough time.我有很多计算要做,时间不够。 I suppose I could keep control of the processor instead of sleeping when a buffer is filled, but that doesn't seem like the right solution.我想我可以控制处理器而不是在缓冲区被填满时休眠,但这似乎不是正确的解决方案。

Further, even though my process is "PRO AUDIO" and has a priority of 25, sometimes the buffer completion event is delayed still farther, so the system starts replaying an unfilled buffer.此外,即使我的进程是“PRO AUDIO”并且优先级为 25,有时缓冲区完成事件会延迟更远,因此系统开始重播未填充的缓冲区。 I haven't found any discussion of how this timing is supposed to work, or how it can be controlled.我还没有找到任何关于这个时间应该如何工作或如何控制的讨论。 I expected the buffer completion event to arrive within a small number of frames into the next buffer.我预计缓冲区完成事件会在少量帧内到达下一个缓冲区。 Is anyone familiar with this stuff?有人熟悉这个东西吗? Either with a solution or a clue about where to look for one?有解决方案还是有关于在哪里寻找的线索?

You should have two threads. 您应该有两个线程。 In the main thread, you do all your audio processing and calculations, and deliver the results to the secondary thread. 在主线程中,进行所有音频处理和计算,然后将结果传递到辅助线程。 The secondary thread's job is solely to wait for WASAPI events and write the products of the main thread out to the sound card. 辅助线程的工作仅是等待WASAPI事件并将主线程的乘积写出到声卡。 The thread which writes audio out should be doing no audio processing. 写出音频的线程应该不进行音频处理。

It appears you have the share mode set to shared not exclusive, in exclusive mode you get two buffers of the same size when one buffer is finished the event is signalled and the second buffer of the same size is returned看来您将共享模式设置为共享非独占,在独占模式下,当一个缓冲区完成时,您将获得两个大小相同的缓冲区,发出事件信号并返回相同大小的第二个缓冲区

However if you have the share mode set to shared you are only given one buffer the help page IAudioClient::GetDevicePeriod method explains this.但是,如果您将共享模式设置为共享,则只会为您提供一个缓冲区,帮助页面 IAudioClient::GetDevicePeriod 方法对此进行了说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM