I’m developing a game for Android which uses beat detection for the gameplay. After a lot of trials I decided that the best way to do the beat detection algorithm was by playing two streams of the same song (the streams are created from different files, in fact it is the same song file but with the name changed). First, I start a stream of the song with volume 0. This stream is the one I use for the beat detection, I’m doing this by calling FMOD_Channel_GetSpectrum. After a little while I played the first stream, let’s say 5 seconds, I play the second one with volume, this one is only for listening the song and create some gameplay with the data I have collected from the beat detection algorithm.
The problem I have right now is that when I start streaming the second file it’s stuttering from time to time. This obviously ruins all the game. So I searched on the documentation of fmod and I saw that it was useful to increase the stream buffer size with FMOD_System_SetStreamBufferSize in order to use less cpu and avoid the stuttering. This didn’t work, I doubled two times the buffer size but it didn’t do the trick. So I tried the other workaraound to avoid stuttering which is in the documentation: increase the decodebuffersize value which is in the FMOD_CREATESOUNDEXINFO struct. This worked to some extent, right now the values I’m using for decodebuffersize are really big… 352800 pcm samples… but anyway it’s still stuttering from time to time (less than before doing all this tweaks).
So I would like to ask if there are any other tweaks I can apply to avoid stuttering, or maybe if there is some way of playing only one stream delayed? I have applied a delay on the channel playing the song but then the values I get from getSpectrum function are also delayed. I’m saying this because my knowledge on dsp is non-existent.
- shruglins asked 5 years ago
Do you get stuttering when playing a single stream?
If you don’t have problems playing a single stream it might be useful to just process the beat data and then use it in the game afterwards, avoiding the use of two simultaneous streams altogether.
Hope this helps.
Thanks for answering,
With only one stream I have no stuttering problems.
Well, I have the two versions of the algorithm, the "online" version to do it while the sound is being streamed with getSpectrum and another "offline", but my offline version is just too slow… maybe I could improve it more (I’ve already done some iterations on improving it) but as I saw that the "online" version was much more quick.
The main reason why the offline is slower is because of the readData function to get the data from the stream. It is reaaaally slow to get just a little chunk of data (remember we are working on Android). I’m testing the algorithm with a motorola (800mhz cpu), I am sure that it would go quicker on a better phone but I want it to work with the motorola just to increase the number of phones the game could work. I know I could also do the job of reading the data from the sound with sound::lock but it is soooo slow to load a whole song (specially when the final user could be loading a 10 minutes song or whatever) as a sound.
I have the same algorithm in a pc and it’s working like a charm.
Any other ideas?
Well, I solved the problem. After searching on the forum for other posts on sound stuttering I found this one:
So, I tried to put the FMOD_INIT_STREAM_FROM_UPDATE flag on the system::init method and it worked. Now I have no stuttering but changing this has affected the performance of the game (about 10-12fps less than before)… well… let’s call it a day.
Please login first to submit.