0
0

I’m currently working with background music in a game where I have several different streams that I want to be played in random order upon completion of the previous track (possibly with a specified interval in between). I’m wondering about the best way to do this. I also want the possibility of changing the music based on situation (e.g. big encounter).

I currently listen to the channel End-callback and set a timer for playing the next sound upon receiving the signal. When the timer hits 0, I use System::playSound() on the randomly chosen stream. This, however, gives me horrible lag spikes which I assume is due to buffering. Using a normal sound instead works, but this is of course not feasible for lengthy tracks. In a test case where I used my logic to repetitively play one stream (8s, 96 kHz) I measured a call time of about 200 ms from FMOD_System_PlaySound().

I’ve looked at e.g. Sound::setSubSoundSentence and Channel::setPosition, but I’m not sure if this is the right way to go and I haven’t found any thread mentioning this particular problem on this forum. It feels like I’m missing something very trivial here, as I imagine more people have wanted to do the same thing.

  • You must to post comments
0
0

Streams should only buffer inside playSound if they were created with FMOD_OPENONLY flag or if they have already been played. When a stream is loaded it will prebuffer (unless OPENONLY flag is specified). When a stream finishes it does not automatically rebuffer ready to start again, but you can cause it to rebuffer by calling Channel::setPosition() back to the start of the stream.

  • You must to post comments
0
0

[quote="peter":rf60wgbl]Streams should only buffer inside playSound if they were created with FMOD_OPENONLY flag or if they have already been played. When a stream is loaded it will prebuffer (unless OPENONLY flag is specified). When a stream finishes it does not automatically rebuffer ready to start again, but you can cause it to rebuffer by calling Channel::setPosition() back to the start of the stream.[/quote:rf60wgbl]

Thank you for your response. I ended up rewriting the loading of sounds so streams are created with the FMOD_NONBLOCKING flag instead, which solved the problem for us. The delay in sound is not critical in our project as long as it doesn’t affect game performance. I’m a bit curious what the best way to do this would be anyway though.

The odd thing about this way of flushing is that it has to be performed on a running channel and it should be performed about the time when playback is ending. If I tried to implement this I would probably add a syncpoint just before the track finishes (since the channel is already disposed when receiving the END-callback) and call Channel::setPosition() from there, but this would mean the channel won’t close down automatically which is what I’d want at this point.

Is this a method you’d suggest or am I making things too complicated?

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.