Author Topic: Problem with playing sound effects in my Unity game  (Read 224 times)

srylain

  • Posts: 18
So I've been using Bass.NET inside of my Unity game, and I'm playing upwards of 11 tracks at once plus sound effects every so often.

The problem, is that pretty rarely the playing of a sound effect will cause the other channels to stutter and get de-synchronized from the gameplay (all that channels are still synced together though). All I'm doing in Bass.NET is assigning a track to a channel (each sound effect has its own channel as well), and then playing them.

Hopefully this isn't a known problem and there is a fix, so what would I potentially do to fix this issue?

radio42

  • Posts: 4574
Re: Problem with playing sound effects in my Unity game
« Reply #1 on: 16 Sep '17 - 17:10 »
Stuttering is typically an indication, that your sound device output buffer is too small, resp. that the samples cannot be delivered fast enough to it.
E.g. when you are playing/streaming from 11 files in parallel, you IO subs-system might simply not fast enough to deliver the sample data.

You might try to load them into memory to see, if that makes a difference or use the BASS_ASYNCFILE flag with your BASS_StreamCreateFile call.

srylain

  • Posts: 18
Re: Problem with playing sound effects in my Unity game
« Reply #2 on: 22 Sep '17 - 03:26 »
Instead of using Bass_StreamCreateFile for the sound effects, I went ahead and tried using Bass_SampleLoad and I haven't had the problem since (again it only happened rarely and mostly inside the Unity Editor). I believe the difference is that Bass_SampleLoad loads it all into memory instead of streaming the file?

Although using Bass_SampleLoad, on Linux I'm getting reports that these sound effects will only play once while on Windows they are able to be played over and over again. I have the "max" value set to 1 when using Bass_SampleLoad, is there a reason why it would work differently on Linux?

Ian @ un4seen

  • Administrator
  • Posts: 20401
Re: Problem with playing sound effects in my Unity game
« Reply #3 on: 22 Sep '17 - 13:16 »
It should be possible to play a sample multiple times on Linux too, but only once at a time if the BASS_SampleLoad "max" parameter is set to 1 (that applies on Windows too). Is the problem happening every time on Linux or only sometimes? Are any calls failing when the problem occurs, eg. the BASS_ChannelPlay call? If so, what is the error code from the call(s)? Also confirm whether you are calling BASS_SampleGetChannel for each playback or only once?

srylain

  • Posts: 18
Re: Problem with playing sound effects in my Unity game
« Reply #4 on: 23 Sep '17 - 04:09 »
I actually have the "max" parameter set to 4 (thought it was 1 earlier). I'm only using Bass_SampleGetChannel once (when the sound is loaded), should I be using it each time I play it?

I'll need to add some logging to a Linux build so I can see if there's any errors.