OpenAL 中播放缓冲区之间的静音?

发布于 2024-10-28 11:03:27 字数 111 浏览 0 评论 0原文

我使用 alSourceQueueBuffers 将缓冲区流式传输到 AL 声源中。我有不同大小的缓冲区需要依次播放。到目前为止一切都很好,但是,在一些缓冲区之间我需要可变数量的静默,我如何以编程方式添加它?

I use alSourceQueueBuffers to stream buffers into a AL sound source. I have buffers of different size that need to be played one after another. So far so good, however, between some buffer I need a variable amount of silence, how can I add it programmatic?

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

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

发布评论

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

评论(1

永不分离 2024-11-04 11:03:27

也许最简单的方法是生成保持所需长度的静默的缓冲区,并对它们进行适当的排队。您只需要根据采样率和所需的静音长度创建一个充满零的数组,并将其传递到缓冲区中。

如果您希望事情变得更复杂,那么您就无法对所有缓冲区进行排队。您将立即需要播放的游戏放入队列,并设置一个计时器来确定何时完成(并且静默时间也已过去)。然后您可以对下一个缓冲区进行排队。或者,您可以轮询源以查看它是否已停止,当停止时,开始倒计时静音时间。您还可以使用流媒体功能...


编辑:
这对我有用。采样率需要与源上排队的其他缓冲区相同。您还可以拥有一个“最大公分母”长度缓冲区,然后将其多次排队。

int sampleRate=22050;
double sTime=2.5;     // How long to maintain silence.
int sampleCount= int(sTime*sampleRate);
int byteCount  = sampleCount*sizeof(short);
short* silence = (short*)malloc(byteCount);
memset(silence,0,byteCount);

alBufferData(silenceBuffer,AL_FORMAT_MONO16,silence,byteCount,sampleRate);
alSourceQueueBuffers(mySource,1,&silenceBuffer);

free(silence);

Perhaps the easiest way would be to generate buffers that hold silence of the length needed and queue them appropriately. You just need to make an array full of zeros based on the sample rate and the desired length of silence and pass it into the buffer.

If you want things to be more complicated, then you can't queue all of the buffers. You queue the one that needs to play right now and set a timer for when it will be done (and the amount of silent time has also passed). Then you can queue the next buffer. Or you can poll the source to see if it has stopped and when it does, start counting down the silent time. You could also use the streaming functionality...


Edit:
This worked for me. Sample rate needs to be the same as other buffers queued on your source. You could also have a 'greatest common denominator' length buffer and just queue it up multiple times.

int sampleRate=22050;
double sTime=2.5;     // How long to maintain silence.
int sampleCount= int(sTime*sampleRate);
int byteCount  = sampleCount*sizeof(short);
short* silence = (short*)malloc(byteCount);
memset(silence,0,byteCount);

alBufferData(silenceBuffer,AL_FORMAT_MONO16,silence,byteCount,sampleRate);
alSourceQueueBuffers(mySource,1,&silenceBuffer);

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