سؤال

I've just began working with OpenAL.

I've successfully loaded in WAV files into it, and played them successfully. It was easy enough.

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.

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.

From what I understand, OpenAL should have built in functions for this. But I cannot find them.

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.

هل كانت مفيدة؟

المحلول

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 implements this in its SoundStream class (C++), you can look at it as a reference if you like.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top