Firelight Technologies FMOD Studio API
System::setDSPBufferSize
Sets the FMOD internal mixing buffer size. This function is used if you need to control mixer latency or granularity. Smaller buffersizes lead to smaller latency, but can lead to stuttering/skipping/unstable sound on slower machines or soundcards with bad drivers.
C++ Syntax
FMOD_RESULT System::setDSPBufferSize(
unsigned int bufferlength,
int numbuffers
);
C Syntax
FMOD_RESULT FMOD_System_SetDSPBufferSize(
FMOD_SYSTEM *system,
unsigned int bufferlength,
int numbuffers
);
C# Syntax
RESULT System.setDSPBufferSize(
uint bufferlength,
int numbuffers
);
JavaScript Syntax
System.setDSPBufferSize(
bufferlength,
numbuffers
);
Parameters
- bufferlength
- The mixer engine block size in samples. Use this to adjust mixer update granularity. Default = 1024. (milliseconds = 1024 at 48khz = 1024 / 48000 * 1000 = 21.33ms). This means the mixer updates every 21.33ms.
- numbuffers
- The mixer engine number of buffers used. Use this to adjust mixer latency. Default = 4. To get the total buffersize multiply the bufferlength by the numbuffers value. By default this would be 4*1024.
Return Values
If the function succeeds then the return value is FMOD_OK.
If the function fails then the return value will be one of the values defined in the FMOD_RESULT enumeration.
Remarks
The FMOD software mixer mixes to a ringbuffer. The size of this ringbuffer is determined here. It mixes a block of sound data every 'bufferlength' number of samples, and there are 'numbuffers' number of these blocks that make up the entire ringbuffer. Adjusting these values can lead to extremely low latency performance (smaller values), or greater stability in sound output (larger values).
Warning! The 'buffersize' is generally best left alone. Making the granularity smaller will just increase CPU usage (cache misses and DSP network overhead). Making it larger affects how often you hear commands update such as volume/pitch/pan changes. Anything above 20ms will be noticable and sound parameter changes will be obvious instead of smooth.
FMOD chooses the most optimal size by default for best stability, depending on the output type, and if the drivers are emulated or not (for example DirectSound is emulated using waveOut on NT). It is not recommended changing this value unless you really need to. You may get worse performance than the default settings chosen by FMOD.
To convert from milliseconds to 'samples', simply multiply the value in milliseconds by the sample rate of the output (ie 48000 if that is what it is set to), then divide by 1000.
The values in milliseconds and average latency expected from the settings can be calculated using the following code.
FMOD_RESULT result;
unsigned int blocksize;
int numblocks;
float ms;
result = system->getDSPBufferSize(&blocksize, &numblocks);
result = system->getSoftwareFormat(&frequency, 0, 0);
ms = (float)blocksize * 1000.0f / (float)frequency;
printf("Mixer blocksize = %.02f ms\n", ms);
printf("Mixer Total buffersize = %.02f ms\n", ms * numblocks);
printf("Mixer Average Latency = %.02f ms\n", ms * ((float)numblocks - 1.5f));
Platform Notes
- Some output modes (such as FMOD_OUTPUTTYPE_ASIO) will change the buffer size to match their own internal optimal buffer size. Use System::getDSPBufferSize after calling System::init to see if this is the case.
- Xbox 360 defaults to 256 sample buffersize and 4 for numblocks. This gives a 5.333ms granularity with roughly a 10-15ms latency.
- PS3 ignores this function. Check FMOD_PS3_EXTRADRIVERDATA to control output latency.
- This function cannot be called after FMOD is already activated with System::init.
- It must be called before System::init, or after System::close.
See Also
Version 1.10.03 Built on Feb 1, 2018