We’re building a WebGL project using Unity, but during some operations that perform some switching of interfaces, the music playing makes a noticeable lagging sound. I noticed that the documentation mentions something about this and gives some sample code.
CPU Overhead
By default FMOD mixes at 48000hz. If the browser is not running at that rate, it will introduce a resampler to convert the rate, which consumes CPU time and adds a DSP block worth of latency.
This can be solved by querying the hardware’s rate before System::init, and calling System::setSoftwareFormat to the same rate as the output. Here is an example (from the PlaySound example)var outval = {}; result = gSystem.getDriverInfo(0, null, null, outval, null, null); CHECK_RESULT(result); result = gSystem.setSoftwareFormat(outval.val, FMOD.SPEAKERMODE_DEFAULT, 0) CHECK_RESULT(result);
Audio Stability (Stuttering)
Some devices cannot handle the default buffer size of 4 blocks of 1024 samples (4096 samples) without stuttering, so to avoid this set the buffer size in your application to 2 blocks of 2048.
Here is an exampleresult = gSystem.setDSPBufferSize(2048, 2); CHECK_RESULT(result);
But how do I use this code? They look like JS code rather than C# code.
If I want to do these operations in C#, where should I perform them?
For example, according to the description I should execute this code before the System.init
method call, but I have not searched for a reference to the System.init
method in the entire C# project for Unity.