Sound lags in calculations

#1

I tried to add sound to the game, but got a problem.
If a function that requires a lot of processor resources is working during music playback, then the sound lags. I have no idea how to solve this. Is it possible to add asynchrony here? Or limit the function? This happens not only with sound, the whole game freezes. But with sound, this is most noticeable.

A simple example below.
Function calc() calculates the sum of primes. Found it on the Internet. The main thing is the demanding function.Simple project.zip (8.9 MB)

0 Likes

#2

This is because built in audio is not played on its own thread currently. You can use either of these depending on your feature needs. extension-openal would be faster to use but defold-fmod has way more features posible.

6 Likes

#3

Thank you so much. Music plays perfectly.

0 Likes

#4

Would either of these extensions offer smoother playback on HTML5, or is that platform always problematic when it comes to audio?

0 Likes

#5

All JavaScript code is single threaded by nature. I guess the webaudio subsystem too.

0 Likes

#6

May be worth experimenting with. I remember webaudio supposed to be on its own thread, but maybe spectre/meltdown impacted that too.

0 Likes