I'm working on a music app. I have a very short audio sample (a drum hit), which I've connected to a timer such that the sound will play every 200 msec. When I run the scene, the tempo that is produced, while mostly consistent, is inconsistent enough that it's not musically useful. Is there anything I can do to get more even timing? I have the timer node set to physics mode. I also have V-sync enabled, if that makes a difference here.

Essentially, I have the same question as this one, but that was asked a while ago and I wondered if anything has changed since then.

a month later

I would try some approaches: 1. Make your drum loop last exactly 200 msec (you can do it with audacity) and play it together with your music 2. Call get_playback_position() of AudioStreamPlayer on every _process call instead of using a timer. It can still be offsync, but will not accumulate over time and most of time will probably be in sync.

Here's a little hint, though I'm not sure if it will actually be useful. Is your audio sample a wav, or a compressed ogg? A largely uncompressed wav file is what you are going to want to use for audio samples that need to be integrated into gameplay. It is less costly for Godot to load those files into memory and play them back without any delay. An audio sample stored in a compressed format like ogg has to be interpreted before it can be loaded into memory, which can create a slight delay in playback.

Also, a repeating timer is probably not what you're going to want to be using. Something like that can trip up due to the game performance. (or lack thereof) You're going to want to disconnect the timing from the standard game loop, and test against duration from a fixed point, most likely the retrieved time from when you started the action. Your specific beat can then be calculated based on a pre-determined float value.

The only way I know it would be possible to get a precise 200msec would be with a built in clock. delta would be a way to count 200msec, but it would be a little bit off sync, sometimes more, sometimes less. It however might be such a small difference that the human brain will not perseve it. Even if your using a built in clock, it will be a little bit off and different on all machines. However, the differences will be microscopic.

5 years later