Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playback delay #91

Closed
bitbrain opened this issue Nov 3, 2021 · 3 comments
Closed

Playback delay #91

bitbrain opened this issue Nov 3, 2021 · 3 comments

Comments

@bitbrain
Copy link
Contributor

bitbrain commented Nov 3, 2021

There seems to be a slight delay when playing sounds for me. I did some googling and a possible problem might be the buffer size configured (see Unity forum)

  • what is the current default buffer size configured when using this plugin?

Within fmod.h I found this signature:

FMOD_RESULT F_API FMOD_System_SetDSPBufferSize  (FMOD_SYSTEM *system, unsigned int bufferlength, int numbuffers);
FMOD_RESULT F_API FMOD_System_GetDSPBufferSize  (FMOD_SYSTEM *system, unsigned int *bufferlength, int *numbuffers);

I might raise a PR to support those two methods, so we can call them from within Godot.

@bitbrain
Copy link
Contributor Author

bitbrain commented Nov 9, 2021

I was unable to build the PRs I raised due to the current Github actions setup. In the meantime, I have been granted contributor access to create branches on this repository until #95 is closed.

@CedNaru
Copy link
Member

CedNaru commented Nov 9, 2021

From the FMOD documentation:

The mixer engine block size. Use this to adjust mixer update granularity.
See below for more information on buffer length vs latency.

Units: Samples Default: 1024

numbuffers
The mixer engine number of buffers used. Use this to adjust mixer latency. See below for more information on number of buffers vs latency.

Default: 4

To get the bufferlength in milliseconds, divide it by the output rate and multiply the result by 1000. For a bufferlength of 1024 and an output rate of 48khz (see System::SetSoftwareFormat), milliseconds = 1024 / 48000 * 1000 = 21.33ms. This means the mixer updates every 21.33ms.

To get the total buffer size multiply the bufferlength by the numbuffers value. By default this would be 41024 = 4096 samples, or 421.33ms = 85.33ms. This would generally be the total latency of the software mixer, but in reality due to one of the buffers being written to constantly, and the cursor position of the buffer that is audible, the latency is typically more like the (number of buffers - 1.5) multiplied by the buffer length.

So the "default" latency should be (4 -1.5) x 21.33 = 53.325 ms.
It seems short enough to not be noticeable. Are you sure it's the source ?

@bitbrain
Copy link
Contributor Author

bitbrain commented Nov 9, 2021

Yes, after setting the DSP buffer size manually by using the method provided by my PR it fixed the delay. Those 50ms are most likely theoretical and depend on the system and drivers, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants