Sign in to follow this  
swifty666

FMOD playSound latency

Recommended Posts

Hi There,


I am currently working on a project that involves recording peoples reaction speeds to hearing audio tones, and also to record a person's spontaneous rhythm speed.

I using FMOD Ex v4.32.05 (according to the header file).

I have a quick simple shell setup that loads in some wav files and plays them when i press the 1-7 keys.

The time at which I press the key to the time I hear the sound is noticeably delayed. Perhaps by a quarter of a second. Is this a delay that is inevitable or could it be improved somehow by changing some FMOD setting? Such as to ensure the entire sound data is cached on the card ready for playing?

I have checked the wav files and there is no silent area at the beginning of them.

To Load my wav file I simply use:

m_pFMODSystem->createSound(filename, FMOD_HARDWARE, 0, ppSound);


and to play I simply use

m_pFMODSystem->playSound(FMOD_CHANNEL_FREE,pSound,false,0);


And I am not really doing much else.

I also have a decent enough sound card I would have thought, Creative SoundBlaster X-Fi.

Any suggestions?

Many Thanks

Share this post


Link to post
Share on other sites
Have you tried disabling hardware acceleration? It's not consistent across different platforms/hardware and in general is a pain to use. I recall it could cause delays, at least in FMOD - but I'm not sure as that was a while ago.

The FMOD docs recommend software mode. I even think I remember them saying they would remove hardware support if they were sure none of their clients relied on it. It's that complicated!

Share this post


Link to post
Share on other sites
Oh I didn't even consider trying software instead, I guess I was pretty naive to assume that because I have a sound card that cost a few quid, that it would be an actual improvement. (heh, I jest, I'm sure its an improvement for many things) [lol].

Thanks for the suggestion I'll give software mode a go when I get home and let you know.

For my purpose in this case I have no requirements for any sound effects or processing, I just need the lowest possible latency for getting audio to play on request.

Share this post


Link to post
Share on other sites
Is the delay actually when you're playing the sound or when you're creating it? Loading from disk will always tend to be pokey. Pre-loading short sounds into memory is important.

How long/big is the sound? Play sound will play the entire thing in one go. If the sound is lengthy (more than maybe 5 seconds) streaming the sound out (I forget the mechanism for this in fmod, it's been a while) will behave much better.

Share this post


Link to post
Share on other sites
The delay is from each time I call System::playSound(), after the sound has been loaded, which is a very short beep WAV file; maybe a second long at most.

I was hoping that I could load the sound onto the soundcard (or just in memory if software) which I assumed createSound() would handle, and playing it would then be a case of saying, play that sound, i.e. with playSound(), I imagine the latency to be very short if the sound data is already in memory.. I just have no idea if that's really how it works or how to ensure that's what's happening in FMOD. Not really done much sound work myself before, i'm really more of a graphics programmer.

Share this post


Link to post
Share on other sites
I'm not sure what to say. I loaded up one of my older projects that used fmod ex and played a ~1s wav. It was in C# and thus was using some added binding overhead, but took about 1.6s to play the entire wav, 1.7 if you include loading it. I'm not doing anything fancy... just load, play.

Share this post


Link to post
Share on other sites
Managed to find some info that helped. Apparently the latency is due to the buffer size and number of buffers. If you lower it, the latency is improved.

I'm using

m_pFMODSystem->setDSPBufferSize(512,2);

which has to be called before init. 512 is just enough to not have horrible distortions, and 2 is the minimum number of buffers, though the time between me pressing a key and hearing the sound is still noticeable, but it's not overly terrible. I'm still not convinced that there isn't a way to improve it though, I mean, I've never seen any problem in games that have a sound as a physics response for example, or a gunfire. You wouldn't expect to have a noticeable delay between clicking your mouse and hearing a gun shot, or seeing a ball hit a wall and hearing the bounce..

Share this post


Link to post
Share on other sites
Huh? setDSPBufferSize () shouldn't affect playback latency. It's for effects processing (echo, compressors, pitching etc..) and usually it's the other way around anyway, if you increase the buffer size you get more latency, not less. But still, if you're not using DSP effects you won't see any difference.

I assume you've asked on the FMOD forums already? At least two years ago, they were read by the developers and they gave their input very often.

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
And you're playing a wav? not something that needs decoding?


It doesn't matter. He gets latency after the playSound () call, not after loading it which is when FMOD will decompress it (unless it's streaming).

Share this post


Link to post
Share on other sites
I reckon on making a simple effort to time the latency, its about 80ms..

according to this topic
http://www.fmod.org/forum/viewtopic.php?t=13451

and the equation fmod gives, i should be getting a latency between 0ms and 10.6 ms when using a buffer size of 512 and 2 buffers.. :|

Share this post


Link to post
Share on other sites
Quote:
Original post by KulSeran
You could look into passing the FMOD_CREATESOUNDEXINFO into the sound creation function. Then modify the passed in FMOD_CREATESOUNDEXINFO::decodebuffersize.


It's only valid for streaming buffers.

80 ms is too much and not what I'm seeing on my end. The OP should really ask the FMOD guys, they might know.

Share this post


Link to post
Share on other sites
I have posted on the fmod forums now and still await replies from those guys, but in the meantime, I have some further info now that maybe will spark some ideas from someone..

I have found that the delay differs a lot from PC to PC, I have found that on my housemate's PC who has a "VIA High Definition" driver (OnBoard), and my mini laptop which has a "IDT High Definition Audio" (OnBoard) the delay is massivly better and very difficult to notice, vs my "Creative SB X-Fi" (SoundCard) which is still around 80ms or so.

I can only assume that the delay is caused by interfacing to the hardware, and that fmod is sending sound data as and when playing a sound, any ideas on how I can make sure the soundcard is primed with the data ready for play upon human input?

I suppose it's not really overly surprising that the simpler the sound device, the lower the latency, but there must be a way to control a fully hardware capable sound device properly to improve this, otherwise no one would want a sound card if it meant all their games played with noticeable sound delays and videos with lip-sync issues! [smile]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this