问题描述
我刚刚开始使用OpenAL.
I've just began working with OpenAL.
我已成功将WAV文件加载到其中,并成功播放了它们.很简单.
I've successfully loaded in WAV files into it, and played them successfully. It was easy enough.
现在,我需要能够将音乐流传输到OpenAL中,而不是将整个文件加载到其中.正如您可能知道的那样,虽然这对于声音效果等很有好处,但是对音乐进行处理可能非常危险.
Now, I need to be able to stream music into OpenAL rather than loading entire files into it. While this is good for sound effects and the like, it can be very dangerous to do with music, as you probably know.
问题是,我似乎无法在Google上找到与此相关的任何内容.虽然我找到了一些与流OGG文件有关的示例,但我还是希望构建一个支持所有音乐文件的系统.
The problem is, I cannot seem to find anything on Google related to this. While I have found some examples related to streaming OGG files, I'd much rather make a system that supports all music files.
据我了解,OpenAL应该为此内置了功能.但是我找不到它们.
From what I understand, OpenAL should have built in functions for this. But I cannot find them.
所以,我的问题是,如何在删除已播放的部分并导入尚未播放的部分的同时,将音频流传输到OpenAL的缓冲区中?
So, my question is, how do I stream audio into a buffer for OpenAL, while removing parts that have played and importing parts that haven't yet?
如果这是一个愚昧的问题,我深表歉意.
If this is an ignorant question I apologize.
推荐答案
使用alSourceQueueBuffers()
将源直接连续播放的缓冲区排队.在播放过程中,将alGetSourcei()
与AL_BUFFERS_PROCESSED
结合使用可获得已完全播放并准备重用的缓冲区数. alSourceUnqueueBuffers()
会为您从队列中弹出这些缓冲区,因此您可以用新数据填充它们并再次将它们排队.
Use alSourceQueueBuffers()
to queue up buffers to be played in direct succession by a source. During playback, use alGetSourcei()
in conjunction with AL_BUFFERS_PROCESSED
to obtain the number of buffers that have been fully played and are ready for reuse. alSourceUnqueueBuffers()
will pop these buffers off the queue for you, so you can fill them with new data and queue them up again.
基本上,您将在一个线程中循环:睡眠一小段时间,测试新的可用缓冲区,将其填充数据,排队并再次进入睡眠状态.
Basically you will be looping in a thread: sleeping for a short time, testing for new usable buffers, filling them with data, queuing them up and going to sleep again.
SFML在其 SoundStream类中实现了这一点(C ++),如果愿意,可以将其作为参考.
SFML implements this in its SoundStream class (C++), you can look at it as a reference if you like.
这篇关于如何将音频流传输到OpenAL源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!