[openal] Looking for tips on streaming music.
support at blindaudiogames.com
Fri Aug 8 14:14:40 EDT 2014
I'm looking for tips on handling streaming of music data.
I'm using libsndfile to parse a 3.5 minute, 4 megabyte embedded ogg
Right now I decode the entire thing at once and store it in a newly
created OpenAL buffer.
Then I set it to looping and play it.
The decoding takes about 1.2 seconds.
I'd like to use alSourceQueueBuffers so I can decode just the first 5
seconds or so and get it playing, then take my time in subsequent game
loops to load the rest of the file.
My first thought was that it would be nice to stop worrying about
queueing and further decoding overhead once the entire file had been
loaded into buffers.
Then I'd just let the normal looping property on a source take care of
looping it, assuming that works with queued buffers.
And I'd be able to release the original file handle.
But I've just done some testing and found these results:
About 5 seconds of this file would be 95KB of ogg vorbis data.
The decoded buffer is about 36 megs.
So 5 seconds is about 871KB of raw data.
Due to the 36 megs of uncompressed data I now wonder if it would be
better to keep the file handle open and repeatedly decode the data into
buffers, including handling looping myself by starting decoding at the
beginning of the file once I've reached the end.
Does anyone have experience with this?
I'd appreciate some advice or thoughts on pros and cons of the 2 ideas.
Also, is there an optimal buffer size?
How many buffers should I have queued per source?
Off hand it seems like 2 buffers, one that is currently playing and one
that is pre-loaded.
And once I have queued buffers working does it make sense for me to use
them on all my sound files? Or just certain ones based on size of file
and whether it needs to be uncompressed?
If just certain ones, what rules should I use to choose whether to load
the whole file or use queued buffers?
I could of course experiment with different rules, but I'm hoping more
experienced people will be able to tell me what works best for them.
I'm using the OpenALSoft implementation of OpenAL, just in case there
are extensions or implementation details that would be relevant here.
More information about the openal