Threading and Audio Nodes

Hi,

I’m experiencing some trouble in HeroDex where even even a slight drop in framerate can cause audio effects.

The situation is that I have a short (1 or 2 seconds) loop of audio that’s played while cards are moving. The volume of that audio is adjusted each frame based on how many/how fast cards are moving. When all cards stop it is then stopped. When they start or when the sound stops its started again.

That starting/etc is all done from the render thread - which works most of the time. However if there is a stutter in frame rate for any reason then it starts to cause audio glitches, in particular if it happens at the point the end of the loop is reached then you get a break or a stutter before it starts again - which then draws attention to the fact that there was a slow down in the first place.

I was wondering if I can work around this by using a separate thread to manage the audio somehow and what the limitations are on that sort of thing. A search on the forums seemed to say that all audio stuff has to be done from the render thread…

Thanks,
Z

I haven’t looked at that for a long while but isn’t there a buffer you can set that would mitigate that? Like a time in seconds you can buffer?

Can you produce a simple test case illustrating the issue?

The audio is already played from a separate thread… I believe it also handles the looping. In my case, I’m streaming my audo so I have to self-loop on the update thread which is why my loops stop when rendering stops. Your volume setting will be on the render thread and maybe that is causing some issues with timing?

Either way, I don’t see these issues in my game so I’m trying to figure out what’s different.

1 Like

I’m a fool. I couldn’t use setLooping for my music since the playlists contain multiple tracks and are streamed…so then by the time it came to do this I’d forgotten about setLooping and just used the manual resume I already implemented for the music.

It’s too late now but tomorrow I’ll do some tests using the jme3 looping rather than my own and see how much difference it makes!

1 Like

Cue Homer Simpson “D’oh!” :slight_smile:

@pspeed rocks my world :smiley:

It’s early days yet but initial reports are that not only could I strip out a bunch of code but this solved the glitching :slight_smile: