I’m currently working on a shooter game with weapons (such as miniguns) that have a certain rate of fire.
The problem is that the FPS is not very stable at the moment, so playing an event per bullet happens to sound very unsteady. The boss wants the bullet sounds to remain constant no matter the frame rate, just like Crysis 2. We’re not using looped events.
I’d be very grateful if anyone could shed some light on how can I achieve this. A constant sounding weapon in a hostile FPS world 😛
One of our ideas was to use a different thread that keeps playing a sound at a certain rate and the game logic enables/disables it. This wasn’t totally succesful though, since the termination of the event depends on the logic and thus is FPS dependent. But with some tweaking may be the way to go.
We’ve also noticed that a highly prioritized thread that looks like this:
[code:3blj13vi]static int ThreadLoop( void* pParam )
int test = 5;
while( –test > 0 )
Sleep( myInteval );
which should play a number of sounds each "myInterval" happens to sound unsteady from time to time (actually, ours is constantly running and put to sleep while no sound is required). Is is possible that out inconsistencies in frame rate affect (A LOT) FMOD internals, thus producing undesired latency?
Any insights will be much appreciated. Thanks in advance.
- janko asked 7 years ago
First of all, you should not be calling FMOD functions from multiple threads unless you are protecting against race conditions.
A looping event would behave the same as your thread, as long as you can start and stop it at the right time then there should be no issues. In fact it should be more consistent than your thread because the accuracy of ‘Sleep’ varies per platform. Depending on how you loop the event it may be dependent on relatively consitent calls to EventSystem::update.
[quote:347y3v98]Is is possible that out inconsistencies in frame rate affect (A LOT) FMOD internals, thus producing undesired latency? [/quote:347y3v98]
Latency is determined by the number and size of the mix buffers. If you have a buffer size 1024 and 4 buffers (default on PC) then that equates to roughly (4096/48000) = 0.085s or 85ms of latency. You can tweak these values to reduce latency (decreasing latency increases CPU usage).
- Guest answered 7 years ago
Thanks for the response. That was fast
[quote="peter":2aq0lew4]Latency is determined by the number and size of the mix buffers. If you have a buffer size 1024 and 4 buffers (default on PC) then that equates to roughly (4096/48000) = 0.085s or 85ms of latency. You can tweak these values to reduce latency (decreasing latency increases CPU usage).[/quote:2aq0lew4]
Great tip. By reducing the DSP Buffer size we’ve noticed a lot less latency.
[quote="bLAZER":2aq0lew4]Do you really need to play the sound for every bullet? Why not start a looped sound and the stop it when the user stops firing?[/quote:2aq0lew4]
[quote="peter":2aq0lew4]A looping event would behave the same as your thread, as long as you can start and stop it at the right time then there should be no issues. In fact it should be more consistent than your thread because the accuracy of ‘Sleep’ varies per platform. Depending on how you loop the event it may be dependent on relatively consitent calls to EventSystem::update.[/quote:2aq0lew4]
I’m not really a fan of using more threads than necessary ( extra burden, extra headaches 😛 ). But our sound designer was reluctant to use looping sounds for weapons, since they don’t behave well when shooting single bullets with guns that use looping sounds.
BUT, today we’ve tried a different loop-based approach. We play an event with a sustain point that uses a sound definition with multiple waveforms and ‘Start Mode’ set to ‘Wait For Previous’. For as long as I don’t trigger a key-off, different sounds are played at the rate determined by the sound designer. And this behaves fine for single shots, as well. Or it should…
My problem now is that the key-off command sometimes arrives too late and more sounds than expected are played. This is quite evident when shooting a weapon with a high fire rate just once.
Is there any common practice to achieve this ‘one bullet – one sound’ playback behaviour using looped events? Should I start the sound with a little delay and keep track of elapsed time differences so I can stop the loop on time?
Also I’d like to know if it’s a good idea to have the EventSystem::update function called from a different thread at a given rate (protecting everyting from race conditions) in unstable FPS scenarios like mine.
Thanks again for all the advice.
[quote="martinrobinson":1gaa5p0e]I was going to respond earlier but assumed you were using low-level FMOD rather than the EventSystem![/quote:1gaa5p0e]
My bad. I should have mentioned it beforehand.
[quote="martinrobinson":1gaa5p0e]If you need variations-per-bullet could you use spawning in the sound def to achieve a similar effect to your solution?[/quote:1gaa5p0e]
Yes, that’s what we’re using now.
For instance, one of our events has a sound definition with some waveforms that are picked randomly. This definition has a spawn time of [66,66] ms (the weapon fire rate) and ‘Start Mode = Immediate’. The event has a velocity parameter (set to 100) and a sustain point just at the end of the sound definition.
This sounds great when in the middle of a shooting burst. The sound loop is quite constant. But when the game’s logic decides that the event needs to stop (either if the player is no longer shooting or if the the weapon has a limited number of bullets per round) and we key off the parameter, sometimes the sound definition is triggered again and an aditional sound can be heard. It sounds weird if the weapon is supposed to fire 3 bullets per round, but sometimes 4 are heard.
I suppose it’s a synchronization problem, since the logic’s update is in charge of stopping the event, but I was wondering if there was something that one could do on the Designer part. How is this problem usually solved? I’ve searched the forums for realistic weapon sound desing, but just found this:
This doesn’t work for us because we also want to be able to shoot just a single bullet (play the loop just once) and the cycle example always follows the intro/loop/end steps.
We’ve also tried using 66 ms long waveforms, a spawn time of [1,1] and ‘Start Mode = Wait for previous’, with no better results.
[quote="icuurd12b42":1gaa5p0e]Make sure you are using wav format and make sure you dont use the streamed method. And reduce the sound quality, even make your sound(s) mono[/quote:1gaa5p0e]
I finally convinced the sound designer to use mono instead of stereo for the shoot sounds. Thanks 😉
Thanks a lot for the kind responses. Looking forward to hear some ideas on how to create great sounding weapons (that sound great no matter the fps)
Please login first to submit.