We’re making some kind of Dance Dance Revolution/Stepmania game where player has to hit buttons in time with the music.
I’ve been asked to play a (rewarding) sound each time a player hit a button. Here’s what I do to mimic that:
1) Take ‘playsound’ FMOD Ex sample.
2) Choose some rhythmic music as a background sound (played when ‘1’ pressed).
3) Choose some simple short sound as a beat sound (played when ‘2’ pressed).
4) Try to press ‘2’ (play the beat sound) in sync with the music.
My problem is that apparently there’s a noticeable delay between when I start the sound and when it is actually heard (say 200ms for example).
Am I doing something wrong?
- plus asked 8 years ago
Audiodev is right, there are a couple of other things which can affect latency too.
Make sure you only call createSound once and have the sound ready to play.
The maximum overall latency of the mixer is determined by:
[code:uzh28uen] FMOD_RESULT System::setDSPBufferSize(
unsigned int bufferlength,
The default on windows in bufferlength = 1024 and numbuffers = 4, will give a minimum latency of:
[code:uzh28uen]buffersize x (numbuffers – 2) = 1024 x 2 = 2048 samples = 42.6ms @ 48kHz[/code:uzh28uen]
and a maximum latency of:
[code:uzh28uen]buffersize x (numbuffers – 1) = 1024 x 3 = 3072 samples = 64ms @ 48kHz[/code:uzh28uen]
Reducing these values will reduce latency but will also increase CPU usage. Check the ‘dsp’ value of System::getCPUUsage to see how much CPU time is being used by the mixer.
- Guest answered 8 years ago
Streaming sounds do not have any more latency than an in memory sound, unless you’re talking about the time it takes to prime the buffer. This can be done in advanced (simply by opening the sound).
Be careful reducing dsp buffer size on PC. It is probably better nowadays (especially with vista/7) but on windows XP you will run into drivers that cannot handle small buffer sizes and audio will stutter.
You should make sure your beat sound is a resident sound, not a streaming sound. Streaming sounds will definitely have latency on every play (unless you pre-buffer them). Also, check for other sources of latency in your application (low update rate, buffered input handling, etc).
- audiodev answered 8 years ago
Please login first to submit.