Cracking, Popping Sounds when Repeatedly and Consecutively Playing an Audio Cue

I have a sound that fires off when you press a button. It’s a sound attached to the firing of a projectile. You shoot. It makes a sound. If I repeatedly click the button super fast it starts to make a cracking or popping sound. I want the audio file to fire off every time a user clicks the button. How do I do this and avoid the popping sound? I tried fading in and out as the cue starts and stops with each subsequent click, but that doesn’t work. It’s an android/daydream build.

Not sure it’s the case here, but it could be. Sound is waves going to the speakers, and a property of waves is that they can cancel each other out, or combine into a big wave. More waves - more complicated patterns. If you want look up fourier transforms. You can hit a roof, where the speaker can’t follow it’s speed or amplitude, and this will materialize in distortion, clipping and similar. If you play a single, well-mixed sample, it’ll be a wave that sounds good. Once you play several sounds together, they start interacting. They are combined before the speaker. We then need to start mixing, to make sure we don’t hit those limits. Some techniques are lowering gain on samples, or to have some samples lower all other sounds when they play, or dynamic comression using f.ex the envelope follower.

Thanks. I really appreciate your response. My blueprint code stops the sound and then plays the sound when I hit the fire button again though. For further clarification: I noticed the same thing happens when I play the file in Windows Media Play and press the play button and then stop it very quickly. It’s the same distorted sound.

Stopping it abruptly mid-sound? You go from nice wave to nothing in an instant, that is a ‘square’ wave and a noticeable click in speaker. Universal audio issue. You need to let the sound play out, OR include a fadeout to your stop so the wave ends smoothly(i suggest experiment between 2-200ms).

edit: o wait just saw you mentioned fading in/out in first post, my bad. We need more info then.

Hi Jasonh2013,

Would you mind posting a video of this, so I can get an idea of your BP setup and how it’s sounding for you?

Thank you for replying. I am trying to be accurate and give you all the details so forgive me if this post is a little long:

Here is my video:

I played around more.

The problem completely disappears when I use Play Sound at 2D. I was using the Play function attached to the audio function. It appears Play Sound at 2D handles the file differently than the simple Play Function.

I used the Play function as per UE4’s tutorial on the topic. In that video I was informed that you could manipulate the sound file with greater ease and do cool things like fade in and fade out if you used the Play function attached to an audio component. That’s why I used a Play function attached to an audio component.

In my video above I play my own custom sound, and also the default firing sound from the starter content. I play each audio file first using Play Sound at 2D, and then using the Play function which references an audio component containing each sound. It is the Play function attached to the audio component which is causing the problem. Maybe that’s not the right phrase. It’s just handling the file differently.

Some observations:

  1. The sound in the video sounds nothing like what I hear from my headphones when I play the game on my viewport on my PC. So you’re going to hear distortions that you wouldn’t normally hear using either Play Sound at 2D or Play for both files. I suppose this is due to the way my Screen Capture software compresses the audio I assume. However, the important thing is you will hear a difference between using the two functions.

  2. There is something which I think is also having an impact with regard to the way the default audio sounds versus the way my custom audio sounds. Based on the thumbnail image in the content browser it appears the starter content firing sound has no sound in the last 2/3rds of the file. I believe this might help in minimizing the distortion I am experiencing. In my custom sound about 2/3rds of the file is not blank.

  3. It’s hard to notice, I don’t think it’s my imagination, but playing the default firing sound from the starter content produces a similar but much more subtle distortion (almost barely noticeable) as my custom sound file when you play it using the play function versus playing it using Play at 2D. So I don’t think it’s just that the sound files are different, or that one is optimized for firing and one is not. It sounds like there is a difference in the way Play at 2D function is handling the file and the way Play function is handling the file

Side note: I was told in the Discord chat room that sound attenuation might be causing this problem. I disabled sound attenuation on all audio components, and this did not resolve the problem.

How is Play at 2D working to manipulate the file to eliminate the distortion?

So using Play at 2D instead of the Play Function with audio component eliminates the problem.

But in the hopes of getting my firing sound to work with the Play function I experimented with fade in and fade out as you suggested.

I added dead air to the end of my custom firing sound to make it more closely resemble the default firing sound from the starter content.

I then added dead air to the beginning of the firing sound.

I then experimenting with various files and fade ins and fade outs. With fade ins and fade outs and some buffer (no sound added) I was able to minimize the distortion in various ways, but I haven’t been able to completely eliminate it. Maybe my custom firing sound is just terrible and I need a new sound?

I think I mislabeled the title of this thread. I think the term “audio cue” might be a little misleading to future readers. I meant sound cue in a general sense. I changed my first post title, and I think it might be a good idea to change the thread title to what I have as the first post title so no one else in the future is confused by this. I think an admin might have to do this.

Your sound does sound a bit blown(and metallic).
If the source sample is clipping, it’s not a good starting point for further usage/modifications of it. If you upload it somewhere, I can analyze it for you.

That said, it could be the audio output buffer too. Not sure how to change it, or how that is applied in editor previews, or what platform you’re targeting, but again it’s an universal digital audio issue. In any sound editor, if the output buffer is too low, we get crackling. We can normally increase the buffer, but the tradeoff is latency. No idea what state the buffer is in(with new audio engine), or how to change it, but it would sound similar if that was your problem. Don’t think it’s that though, if you’re all defaults and targeting PC platform.

So I expect the issue has to do with your Stopping–in the engine there is some interpolation to try to smooth out stopping sounds–but with your spamming, it’s hard to say how many sounds are active, etc.

The reason I suspect this is that with your 2D sound, you are not stopping anything.

It could be useful to take a video with the following debug commands active:
stat SoundWaves
stat SoundCues

The other thing worth noting is that you don’t need to call Stop every time, we actually have an asset called SoundConcurrency which allows you to define Groups of Concurrent Sounds and limit the number of Active sounds per group with several Rules for how to resolve too many sounds.

The other thing worth mentioning is that you may actually want to allow more than one sound at a time–you will want to find a balance based on your fire rate and what the player should reasonably be able to hear.

And lastly, you will want to design sounds that have a great deal of dynamic range so that overlapping sounds don’t overload the audio output on mixdown.

(And in cases of high-repetition/fully-automatic fire, you may actually want a looping fire sound that fires at your game rate–machine gun style)

I ran into this same issue and can confirm that the following cleared up my problems:

  • Reduce number of active sounds waves by using better Sound Concurrency settings
  • Re-implement all rapid fire, single shot sounds as looping sounds (this will help w/ the above, as well)

I would like to just state somewhere public that this comment led to me finding the stat SoundWaves, which allowed me to find sounds that should have had attenutation on that didn’t. This solved a problem for us. Thank you!