Version
menu

Wwise SDK 2025.1.4
Simulating Rapid Gunfire

If you are working on a project that includes a firearm with a rapid rate of fire, such as a machine gun, it can be difficult to accurately synchronize the bullet sounds with the firing action. Because Wwise events are processed asynchronously on the audio thread, there might be a slight delay between the break action and the termination of a gunshot sound if you implement the sound through a Sample Accurate transition on a looping container.

To achieve a sample-accurate trigger rate with rapid gunshots, we recommend that you use MIDI to trigger each bullet sound. PostMIDIOnEvent makes it possible to respect the exact offset (in samples) within a given audio frame, which allows for high accuracy.

A MIDI-based solution requires the following:

  • Use one of the following options to manage audio rendering:
  • The Integration Demo contains a sample MIDI implementation that uses a metronome sound. You can apply the same principles to rapid gunfire. The relevant file is available at \SDK\samples\IntegrationDemo\DemoPages\DemoMIDIMetronome.cpp and the corresponding documentation is available at Integration Demo Sample (see the MIDI API section).
  • The relevant APIs are PostMIDIOnEvent() and StopMIDIOnEvent().

Limitations

There is a limitation when using MIDI-triggered events in conjunction with Wwise Spatial Audio. MIDI events are triggered internally by the sound engine and might occur between frame boundaries. However, the acoustics simulation is updated before the audio frame begins. If such an event occurs, it might not be possible for the acoustics engine to perform an update in time, which can cause the first frame of audio to be rendered without acoustic path information, resulting in audible glitches. This behavior happens when the first sound played on a Game Object is a sound triggered by MIDI, and the acoustics engine has not yet calculated the sound propagation paths for that Game Object.

As a workaround, play a separate sound on the same Game Object to force the acoustics engine to calculate the sound propagation paths. The Enable Diffraction and Transmission option must be selected for the separate sound. For a sustained event like rapid gunfire, the separate sound (for example, a loop of silence) must be played for the duration of the rapid gunfire event to ensure the paths are calculated when a MIDI event occurs.


Was this page helpful?

Need Support?

Questions? Problems? Need more info? Contact us, and we can help!

Visit our Support page

Tell us about your project. We're here to help.

Register your project and we'll help you get started with no strings attached!

Get started with Wwise