Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to make an entity fire one or more machine-guns.

For each gun I store the time between shots (1.0 / firing rate) and the time since the last shot.

Also I've loaded ~10 different gun-shot sound-effects.

Now, for each gun I do the following:

function update(deltatime):
    timeSinceLastShot += deltatime

    if timeSinceLastShot >= timeBetweenShots + verySmallRandomValue():
        timeSinceLastShot -= timeBetweenShots

        if gunIsFiring:

But now I often get a crackling noise (which I assume is when two or more guns are firing at the same time and confuse the sound-device).

My question is whether

A) This a common problem and there is a well-known solution, maybe to do with the channels or something, or

B) I am using a completely wrong approach to the task. I had a look at some sound-assets for other games and they used complete burst with multiple shots. I suppose I could try that, but I would like to have organic little hickups in the gun-fire (that's what the random value is for) to make the game more gritty and dirty.

I am using Panda3D, but I had the exact same problem in PyGame and SDL.


Thanks a lot for the answers so far! One more problem with faking it though: Now how do I stop the sound? Let's say I have an effect with 5 bangs...

*bang* *bang* *bang* *bang* *bang* 

And I magically manage to loop it so that there's no gap or overlap if the player fires more than 5 shots. Now, what do I do if the player stops firing halfway through the third bang? How do I know how long to keep playing the sample so that the third bang is completed and I can start playing the rumbling echo of the last shot?

Of course I can look up the shot/pause timing of that sound-sample and code accordingly, but it feels extremely hacky.

share|improve this question
1 mentions this: "The default is set to reduce the chance of scratchy sounds on some computers. You can change the default buffer by calling pygame.mixer.pre_init before pygame.mixer.init or pygame.init is called. For example: pygame.mixer.pre_init(44100,-16,2, 1024) The default size was changed from 1024 to 3072 in pygame 1.8." It might help to fiddle with the buffer size. – Eric Nov 5 '12 at 12:21
ok, gonna look up "buffer size" then, thanks. – HumanCatfood Nov 5 '12 at 12:27

A) Yes, fake it

Don't synchronize each bullet with a single shot sound. Rather play one sound having multiple shots in it as long as you are shooting. As long as your damage and impact effects code is setup properly nobody is gonna see any difference.

share|improve this answer
So it's "B) Yes, fake it". :-) – Eric Nov 5 '12 at 12:23
Right @Eric, kind of both :) – Maik Semder Nov 5 '12 at 12:31
Hi Maik, dankeschön so far. I'm not exactly happy with that approach, but I'll try it. How scalable would that be though? What I mean is: atm I have two overlapping machine-guns. Let's say the problem is solved by using two sound-effects, containing ten bangs each, rather than 20 short ones containing one bang each. Now what if I want to add ten more machine-guns (it's not a very nice game.. )? I'd run into the same problem again, wouldn't I? Sorry for OCDing, I don't mean to criticise the answer, I genuinely want to solve this. – HumanCatfood Nov 8 '12 at 17:52
@Jan why two sounds? Just loop one sound. No matter how many machine guns, each machine gun gets its own looping sound played. I don't see a problem there. – Maik Semder Nov 8 '12 at 18:12
@Maik, two, because two guns are firing at the same time (in the simplified case). If there are more guns than the limit of simultaneous sounds, it's the same issue again as if there's a sound-effect for each shot. – HumanCatfood Nov 8 '12 at 18:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.