AK47

This is probably one of the longest and most difficult exercises I am presenting in this work. It's long because I am going to be thorough and explain some vital pieces of new theory. It is not easy because it contains a lot of stages to build and because there are complex relationships to consider in physical reality and within our DSP model. For brevity we will skip some of these and make a few assumptions which I will endeavor to point out along the way. Filling in these gaps you should be able to produce top class firearm effects that sound dead realistic.

Firing

Those of you who've tried to record firearms probably know what a difficult task this is. The kind of microphone that can handle the dynamic range of a gunshot costs a fortune, and using anything else either gives you an overdriven thud, or a weak and distant sounding shot dominated by ambient reflections. Once again artistic licence trumps absolute realism. Listen to the gunshots in a spaghetti western, they go on forever with almost comical ricochet sounds, even when they hit somebody. We will develop a sound theory behind the real physics of firearms but then add a little spice to get the extra oomph we need later on. There will be plenty of time to talk about various little details of guns in more depth soon, but let's just look at the essential core points now. When you pull the trigger a firing pin impacts with the base of a tiny brass shell. In the bottom is a primary charge, held in a thin brass bubble. This explosive, sometimes silver fulminate or mercury fulminate, which is quite unstable, detonates on impact. But it's only a tiny charge, no bigger than a toy cap gun. It sets off the secondary charge of cordite (nitro-cellulose and nitro-toluene) in the main body of the shell. Because it's a high explosive the detonation happens almost instantly unlike an old fashioned cannon or firework using black powder which "deflagrates" (burns normally). The actual time that an explosion is happening in the shell is very quick. Detonation happens at between 5000m/s and 8000m/s so a 10mm shell has used all its fuel in about 2 microseconds. During this time a large amount of energy is released. To get a feel for the numbers consider that a rifle round travelling at 800m/s contains the same kinetic energy as a 1000lb motorcycle travelling at 80km/h. The important reason for this is its velocity due to the fast time in which the charge detonation happens, and consequently the high velocity of the round. Since there is a large amount of energy released in a short period of time the energy density is extremely high. The sound of a shell exploding then is like a single extremely loud click, for which we have a name, an impulse.

The idealised impulse

We talked about ideal impulses before. An ideal impulse is a theoretical thing, because it is infinitely short and infinitely loud. If it were possible to record or synthesise such a thing it would destroy any loudspeaker or sound system. The loudspeaker coil and cone would have to travel at the same speed as a bullet or the same speed as the detonation shock wave from a high explosive, and it would rip the loudspeaker apart and embed itself in the head of someone sitting in the front row. How's that for surround sound matey? Fortunately this can't happen. The mechanics of the loudspeaker and the inductive impedance of the coil mean it simply won't respond to an ideal impulse. Long before the coil has even started to move the event is over, so in fact we hear virtually nothing. So, does that mean a gunshot is impossible to record or synthesise on a digital system. Well, applying the strictest theory yes it does. At a typical sample rate a single sample takes 1/44000th of a second, during which time the theoretical impulse of a high velocity rifle round has come and gone. Why we hear anything at all, and why it's possible to record gunshots will be explained soon but stick with this mental picture if an impossibly short sound for a moment.

Sweep impulse

In theory an ideal impulse contains every frequency. This is counterintuitive, because it's duration is less than a single wavecycle of any periodic frequency, but the math shows us that this is true. We can use this equivalence to perform a cunning hack and cheat our way to emulating a real high intensity impulse. A "chirp" or sweep impulse is a very short sound that behaves and sounds a lot like a real impulse. Instead of cramming all those frequencies into an infinitely short time we can spread them out into real human listenable time. If we take a sinewave and move its frequency quickly from zero to 20,000Hz, right across the human hearing range, it starts to sound like a really loud click. Because we've spread out the energy into a longer time a digital system and loudspeakers can now actually handle it. The magic number is about 20ms. There isn't a name for this special time used widely in the literature, but I call it the Garbor time, after a famous mathematician on whose theories granular synthesis is founded. Anything that happens in a time of about 20ms is perceived by the human ear/brain as a single event. If you like it is the quantum unit of human hearing. To create our gunshot we are going to start by producing a sweep impulse. On its own it sounds absolutely nothing like an explosion. The next patch and audio example show how we do this and demonstrates the sound with slow and then faster sweeps.

A better sweep impulse

Going back to the question of why we can hear a gunshot let's stop thinking about the charge in the shell and start thinking about the rest of the system, the round, the barrel and the body of the rifle. As you will recall from earlier an impulse excites things around it. It sets everything vibrating with energy. No sooner has that 2 microsecond explosion finished than the shockwave spreads to every part of the gun. Most importantly, from a killing perspective, to the air in the cavity just behind the slug which expands along with gasses produced in the explosion rapidly. It also spreads to the metal barrel, to the stock and other parts of the weapon which clang loudly. As the shockwave excites everything into action a massive pulse of high frequencies is produced. It's complicated to explain exactly why, but remember that the shockwave is actually moving at many times the speed of sound. The first frequencies we hear are the fastest ones, the ones at the highest frequencies. Our perfect sweep impulse we just made contains all frequencies spread evenly and equally through its duration. That's actually useful for things like testing concert halls for reverb or a sonar ping, but it doesn't quite fit the bill for simulating a rifle crack. We want to tip the balance of frequencies so we get a lot more high ones. To do this we will use our old trick of modulation to get a whole bunch of extra sidebands. We will also use distortion, which serves two purposes, when the signal clips it adds more high frequencies because the wave becomes squared off, but it also limits the real amplitude, something we will be grateful for later when we try to mix the various parts of the rifle shot sound.

IMPORTANT NOTE: This is where I have to point out that the mpeg3 compression algorithm is rather limited. I know what a revolution it is and how most people think it's the best thing since sliced bread and peanut butter, but from an audio engineers perspective it sucks donkeys. What you hear in the following audio examples is an approximation of what the patches are producing. To make them listenable I have had to apply some compression. However the conversion process introduces artifacts and hammers the dynamic range. If you want to hear what's really happening in the subtleties of this exercise I highly recommend you download the Puredata files and listen to them on a good system.

47impulses

Puredata file .pd

Audio .mp3

Excitation

The sweep impulse we have made sounds nothing like a gunshot does it? But wait, hang in there chaps, reinforcements are about to arrive. Psychologically the sweep impulse is important, it tells us that something bad, something very loud and energetic is happening. But it doesn't tell us what. To find out "what" our brains listen carefully to the formant, the distribution of energy in frequencies that immediately follow the first 20ms attack. These resonances characterise the sound enormously. From a cognitive psychology viewpoint consider that for survival our brains are incredibly attuned to discriminating short high energy sounds. This initial recognition time, which happens lower down in the brain long before we have a word to describe the sound we heard happens in the next 40-60ms. In that time we can tell the difference between a crack of lightning, a twig snapping or a raindrop on a leaf. This particular acuity in judging the underlying physics of the first attack part of a sound means we have to be especially careful designing the next part of the sound which will tell us most about what is happening. The barrel itself is a semi open pipe, in that regard it's no different from a flute or pipe organ. The resonance is partly determined by the dimensions and material of the barrel, partly by the muzzle velocity of the gas, rifling spin, flash hiders and so on. Predominantly we hear a crack due to the shockwaves secondary effects which radiate from the barrel.

47impulses2

Puredata file .pd

It's important that the noise forming the tail part of the "crack" sound goes through exactly the same resonant formant as the impulse, this glues them together as far as our ear is concerned and makes them one sound. If there is a tiny delay, even of a few microseconds between the two the latter will be perceived as a reverb or after shock of the former making us think the first sound was very loud.

47shelldetonate

Audio .mp3

Puredata file .pd

Gaseous explosion

That handles the major part of the loud crack for our rifle, but it sounds very thin and sharp. A real gunshot has quite a lot of bass to it as well. The cause of this is the gas venting as the muzzle emits hot products from the explosion. When we hear a gunshot the loudest part by far is the explosion of gasses emerging from the end of barrel after the round leaves, but the detonation is far more penetrating and faster moving. In a shell the explosive undergoes a chemical reaction. There is a little residue left in the casing but most of its mass has been converted to gasses, a complex mixture depending on the exact explosive charge of some nitrogen, some hydrogen chloride, some carbon dioxide and monoxide, molecular hydrogen and water vapour. These are all at high temperature and so they occupy an even larger volume than normal. The volume of gas released by one gram of charge is about 160 litres. Due to the elastic compressibility of air this happens in a far slower timeframe than the detonation and continues to expand for a while after the round leaves the barrel. That means we get to hear a follow-up boom of strong bass frequencies as if a balloon were popped.

47gaseous

Puredata file .pd

Puredata file .pd

Reverberation

An important design point needs addressing here. Normally we avoid adding reverb sounds at all. The reason is that it's not our place as a sound designer, especially in games to be doing this, spacialisation and reverberation should be handled by the context and provided by the engine as a function of local geometry. We can easily make a great sounding reverb that perfectly fits a weapon fired outdoors, but when it's fired in a well furnished room it sounds completely incorrect if that reverb tail is part of the sound. Since we're already playing with firearms lets be naughty and break this golden rule, after all in just a little while we'll have an AK47 so who's going to argue with us then?

Audio .mp3

Chambering slide

One sound we always need is the slide/cocking noise. A gun in a film always needs the slide cocking at least four times before use,

To obtain this part of the reload sound I've used our old friend the delay chain and some clicks. For how to produce plastic and metallic clicks for buttons and levers see the section on switches. The locking mechanism on an AK47 is nothing like this. Artistic licence is the excuse for the following sounds and I appologise if you are a purist. There are two parts to the sound. Firstly there is the sliding mechanism which is approximated by a filtered noise source rising in amplitude and then there are the clicks arranged into a ratchet cluster for the lock. Both these components are fed into a delay based resonance to emulate the body of the rifle. Strictly this should be coupled to the barrel and stock body resonance of the shots, however I didn't want to overcomplicate this already difficult example, so that part is omitted.

47reload1
47reloadslide
47reloadratchet

Puredata file .pd

The audio examples here Audio .mp3 break the sound up into its parts for demonstration. First you hear the individual clicks that make up the ratchet sound, then a succession of ratchet parts building up the sound, finally these are combined with the slide for the full effect.

Audio .mp3

Ejected shell casings

I think the first game I played which featured shell cases falling was the Half-Life, this is another little touch that really adds depth to play. Most weapons spit the casing up and to the side. That's so they don't all come landing on the shooter and so they don't hit the guy standing next to you in the face. For our sound it means there is a noticeable delay between firing and the casing landing somewhere. The gas recoil from the shot provides the energy to eject the casing and rechamber the next round. We could model this but for the mostpart it's masked by the shot. Now, technically this delay should be handled by the game code, it should be an object-world collision event and the sound code of course belongs in the shell case. It should also be a texture/world material parameterised event, meaning the casing makes a different noise on concrete than on wood or dry ground. That's why the sound code belongs in the casing itself, tightly bound to the physics code where edge collision, rolling, spinning etc all parameterise the sound. More about this in the part on realtime parameterisation, for now we are going to cheat and implement some random collision modes and we're going to build in the eject delay and a bit of random bounce physics right here into our sound where it doesn't belong.

Each shell tinkle is a burst of white noise into a bandpass filter formant tuned to a metallic tone. Notice the high resonance to make the filters ring. When the subpatch receives a bang it sets off a chain of random delay timings on the left which sequence the bouncing shell. Each bounce may make a slightly different sound, perhaps landing on its edge or side, or rolling. We don't want these sounds to be too different. Most of all we want the fundamental formant component, the major eigenvalue of the cavity to remain fixed so the shell doesn't seem to change in size or width, but by gently modifying one of the others on each bounce we get the effect of a casing landing in different ways. There are three bounces in all, each of which decays away in volume. The volume decay is achieved by the counter on the left beneath the random delay chain which outputs a gradually lower and lower amplitude control signal on each bounce.

47shelltinkle

Audio .mp3

Puredata file .pd

Clip in/out

Think of the clip sliding into the receptor rather like a trombone. As we push it in the resonant pitch centre increases, and the opposite when pulled out again. The source of noise to excite the system is friction of the clip against the sides of the receptacle. Bear in mind that a clip full of rounds is going to make a different sound than an empty clip. One important place to make this subtle change is in dropped sounds. Pedantry in game realism is not to be laughed at. I've played many shooters where finesse in details like this is valuable tactical information - "was the clip that guy just dropped empty or full?" A great player knows many of the weapon sounds, knowing what weapon your opponent has before you even see him is a distinct advantage if he's foolish enough to reload within hearing range. It's also no more difficult to work this detail in, since we're going to model the empty box section sound of the clip first and then choose damping values to reflect the fact that it's filled anyway we don't have to do much extra work.

Final assembly

Here's the components together. The final Puredata file contains some small tweaks and optimisations that I haven't fully explained above but I'm sure you can work these out and appreciate them. Below is the mix of parts. The audio example should be played really loud because I've mixed these with a slightly more realistic dynamic range, still nothing like reality where the discharge should be about 90dB louder than the shell case tinkles, but if we did that we would never hear them.

47-all

Finally here's a pretty wrapper to make it fun to play with.

47wrap

Audio .mp3

Puredata file .pd

Other guns

Your game or film scene will probably call for a range of weapons. There's no room to go through the construction of every type here. After that punishing exercise I hope you're not expecting me to cover each weapon in the arsenal and develop the same technique over. Most other weapons can be created by some modifications to what we've just covered. Use the '47 template as a base to start building other sounds. Remember the characteristics have little to do with what bullets go in the gun and a lot to do with the physical construction of the barrel, stock and magazine housing. Remember most of all the sound is dominated by where the weapon is fired, more than 70% of the sound is down to reverb. Remember that technically all shots should be done dry as a bone and the rest left to external reverberation process. The essential points again are: