View Single Post
Howth Castle and Environs
Aaron's Guide to Repairing Clipped Audio with Audacity

This was requested at another board, so I might as well poast it here too.
EDIT October 14, 2012: I have concluded that Adobe Audition CS6's declipper can produce much better results. Specific instructions on how the declipper differs from Audacity's filter can be found here and in the following posts, although it is used similarly. These posts assume you are already familiar with the information in this post.
The first thing you're going to want to do is make sure the album is actually clipped. The best way to do this is by looking at the waveform. If it looks like this:



Then it's probably clipped. You can zoom in further to see what the peaks look like. A clipped signal will somewhat resemble this:



Where you can see lots of signals hitting the peak right next to one another. (Audacity has a feature called "Show Clipping," but this will only work if the signal goes all the way up to 0 dB, and it's not always reliable).

Clip Fix will affect audio compressed with other compression filters, but it will not do so as much. If the audio used a distortion filter, you'll get quite a bit of recovery, though not as much as you would from actually clipped audio. If the audio used a peak limiter, you probably won't get any audible difference. Unfortunately the only way I'm aware of to tell for sure whether distortion or peak limiting was used is running clip fix and seeing how much dynamic range was recovered.

So you've determined you have clipped audio. You're going to want to make sure you have a good-quality version of the album before you start repairing it, because there is no point in repairing bad audio. Ideally you should be repairing from FLAC or some other lossless audio format, because applying lossy compression to audio already sourced from a lossy source results in egregious losses of quality that even non-audiophiles will be able to notice. Unfortunately, occasionally people upload tracks that are converted from lossy formats as FLAC, so you'll want to go to the spectrum analysis, which you can do by clicking the arrow on the top next to the "1.0" in the track view and selecting "Spectrum". Zoom out to 22k. If you have frequencies going all the way up:



Then it's probably legit. (Occasionally, albums are mixed from lossy sources. In these cases, there is no way to get a legitimate lossless rip, unless you happen to have the original master tapes and can make your own mix; in which case, it would be pointless to Clip Fix the audio anyway. Also, with piano music and other instruments that don't have lots of high frequencies you won't see audio extending to 22 kHz, but piano music is rarely clipped anyway). The best way to ensure you have a legit rip is to make your own FLAC rip with Exact Audio Copy. If you don't have the CD, there are plenty of places where you can find rips, but teaching you how to pirate music is beyond the scope of this guide.

Ideally, the best way to repair clipped audio is to do an entire album at once. This way you can be sure you are reducing the volume of all tracks by the same net amount, meaning that you will not get inconsistent levels from track to track. I would recommend loading the entire album into foobar2000, selecting "Convert", outputting as FLAC, destination "Generate multi-track files." This will embed a cuesheet into the file that will preserve the track listing, and it will also enable you to work on the entire album at once.

First I am going to run you through how to fix a case of ordinary digital clipping, and then I will run you through a couple of special cases.

The filter we're going to be using is called "Clip Fix." You can access this under the "Effect" menu. Clip Fix advises you to reduce the volume of the track by 10 dB. In my experience, this often isn't enough. If an album is as badly clipped as My Beautiful Dark Twisted Fantasy (the record I'm using for my example), you will easily recover much more than 10 dB of dynamic range. We're not going to be keeping all of this, because Clip Fix often overcompensates, but you need the room to work with in the mean time. I would recommend amplifying by -20 dB. If you've over-compensated, you can always re-amplify later. So the first thing you'll want to do is select the entire album, select "Effect - Amplify" and type in "-20." (You can use a different number, but if you do, you'll want to remember it and replace future references to "-20" in this tutorial with the number you use).

After you've got the track volume reduced, you're going to want to make sure the audio maintains a consistent level across the album. Sometimes record companies clip different tracks, or even different sections of the same track, at different levels. I have no idea why they do this, but I can name numerous albums by different artists (Dream Theater - Falling into Infinity, several albums by Moonsorrow, etc.), where different tracks, or different sections of the same tracks, are clipped at different ranges. You will want to zoom in at the peak of the waveform and see if they are clipped at different ranges. Here is Falling into Infinity by Dream Theater:



As you can see, the second song is clipped at a different level than the rest of the album. So for Falling into Infinity, you will want to start by clip fixing the first song, then clip fixing the second song, then clip fixing the rest of the album approximately twenty minutes at a time. The reason you need to do this is because Clip Fix only addresses audio near the peak of the selection. Since the clipped audio in the second track will mostly not be near the peak of the selection, you will need to address the audio in the second track separately.

(Note: Clip Fix will not work with more than about twenty-five minutes of audio for some reason; add more, and it will process the audio, but it will not alter it. Hence the necessity of doing the audio in segments. It is best to make your selections begin and end in segments that do not approach peak level, to ensure you repair as much audio as possible).

The settings you're going to want to use with Clip Fix will usually be the default. (In cases where faded out audio is clipped, you may wish to adjust the settings; I will address doing faded out audio later). 95% threshold is good. Too much lower than that and you start having the filter alter audio that's not really clipped. That's bad. I would say 90% is the absolute minimum you will want for audio clipped at a constant level. In some cases you actually may need to go higher (98% or 99%) to preserve audio fidelity. I have not actually worked out why this is, or how to identify recordings where this will be necessary, but when I did a 95% clip fix of Petrychor's Dryad I noticed a distinctly audible loss of higher-frequency registers that did not occur when I clip fixed it at 99%. This is the only time I have ever observed this happening, however. (On the other hand, occasionally 99% clip repair also recovers more dynamic range than 95%; the track "Scars of Time" from Chrono Cross, which is not something you would expect to be as badly clipped as it is, is one such example).

Once you've done the entire album, you will have something that looks like this:



Unfortunately, Clip Fix isn't a perfect filter; it will have overcompensated in many cases and created audio that will create undesirable "pops" in the speaker. If we've recovered more than about 5 dB of audio (you can tell how much you recovered by going to "Amplify" and seeing how much it suggests adding to the piece; subtract from 20, or whatever number you reduced the volume by, to see how much you recovered), we'll probably have this problem. The best way to deal with this is (strangely, given how much I usually hate dynamic range compression) by applying moderate volume compression to the repaired segments of the audio.

There are a number of different compression algorithms one can use, but I find most of them to be flawed in some way or another. There is a custom "soft knee" filter that does not work instantaneously and produces some distortion; there are several compressor filters that usually create audible "pumping" in the mix due to their lack of instantaneous attack and release. The best compression algorithm I have found in Audacity is the default plugin called the "hard limiter," though it is actually a hard knee filter.

Remember how we reduced the volume by -20? We're going to start at .5 above -20 and keep periodically applying the hard knee filter. Go to "Effects - Hard Limiter", input "-19.5" as the dB limit, and input something close to 1 as the "Residue Level." I select .840896 because it is the quad root of 0.5, meaning you will cut the amplitude in half approximately every 2 dB, but it is not necessary to use something so pedantic. As long as it is fairly close to 1, the effects will be desirable.

(EDIT: Since I originally wrote this guide, I have decided that starting at .5 dB below the original peak is overkill. I'd start at 2.5 dB instead, meaning that if I were rewriting this guide today you would see -17.5 in this screenshot)



Now keep increasing the limit by .5 and repeating the filter until you hit the peak of the audio. You can tell what the peak is because it will be specified in the "Amplify" filter. If the value of your last pass through the "Hard Limiter" filter is greater than the value given to you in "Amplify," you're done.

Now the last step is to amplify the audio. I would recommend leaving 0.1 range, like so:



(If I had done the whole album we would be amplifying by much less than 14.2 dB; "Runaway" is one of the quieter tracks on MBDTF).

Naturally, since we sourced this from FLAC, we'll want to export this as FLAC. If you save as sixteen-bit FLAC, you will actually probably still be throwing away a small amount of audio data, since the volume has been reduced and the amount of data we have is beyond the scope of the sixteen-bit sample rate, but 24-bit FLAC is usually about twice the size of 16-bit FLAC and it is unlikely that the human ear can tell the difference with a clip fix from a 16-bit source, so I would recommend simply exporting as 16-bit FLAC.

That said, certain methods of exporting 16-bit audio result in the introduction of a fair bit of noise into the files. It is probably not audible to most people, but it will make the files larger. Before you export, I would recommend going to "Preferences", selecting "Quality" and setting "Dithering" to "Rectangle". This will eliminate the problem.

And we're done. The result should look something like this:



And it should be much more pleasing to the ear than the crap record companies usually excrete these days. Note that we will not have fixed all instances of clipping in the album; Clip Fix is not that good. But we still will have solved enough of them to make a difference.

Two additional last things are worth noting. The first is cases where engineers clipped the audio before fading it out. This is a massive pain in the arse and unfortunately, the way the plugin exists right now, the only way to deal with it is to clip fix a few tenths of a second of audio at a time. This example from Moonsorrow's Kivenkantaja is one such case of clipped fadeout:



And here's a zoomed-in view of one peak where you can tell the peaks are clipped:



Unfortunately, you will simply have to bear the tedium of applying the filter several dozen times. Luckily, since you're only clip fixing a few tenths of a second of audio at a time, you won't have to wait long for the filter to execute. You'll also want to make sure you're not selecting near the peaks of the audio, as Clip Fix will not affect audio near the edges of a selection. Make your selection between peaks. Also, with faded out audio it is fine to use a somewhat lower threshold of clipping, although you're not going to want to reduce it too much. Sometimes, if your sensitivity is too low, Audacity won't even recover a lot of clipping. I would recommend using 90% as the threshold for faded out clipping. (Just remember to increase it back to 95% when you go get around to fixing the next track).

The only other thing worth noting is cases where there is "soft" or analogue clipping. The remasters of Van der Graaf Generator are like this. You will see waveforms approximately like this:



Ideally you're going to want to go back to non-clipped sources (like the original VdGG CD issues) because this is a massive pain in the arse to deal with, but otherwise the only real way to deal with it is by clipping the audio at a constant level. You can do this by using the "Hard Limiter" as an actual hard limiter, with a residue level of 0. You can tell what decibel level you want by selecting "Waveform - dB" in the audio view dropdown menu and zooming in. Ideally you'll want the smallest possible value that results in clipping at a constant level. Pawn Hearts complicates things further by clipping each track in a different manner (some are clipped at a constant level and some are clipped in a more analogue-like manner), so this is one of the rare cases where you will want to handle each track separately. Just make sure you amplify each track by the same amount, or albums that are continuous will have undesirable jumps in volume at track divisions.

You can create your own lossy encodes of the music after you've exported it if you want to put it on an iPod or something, but I'd recommend saving the FLAC (burning it off to disc if you're running low on disk space) so you don't have to repeat the process, because it is an incredibly time-consuming one.

Let me know if you need clarification on any of this and I will try to do so as best as I can.
__________________


ff · tmv · reds · lj · last.fm · soundcloud · pm for facebook (which I never check)

I never knew a man could tell so many lies
He had a different story for every set of eyes
How can he remember who he’s talking to?
’Cause I know it ain’t me, and I hope it isn’t you
I’m armed to the teeth
Like a fucking animal
I ruin everything
I get my bony hands on

And here we go now over the bridge of sighs
We will get a cross like Christ, crucified
It’s like a birth but it is in reverse
Never gets better, always gets worse
Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose vis-à-vis an introduction, so let me simply add that it’s my very good honor to meet you and you may call me V.
Vaulting, veering, vomiting up the values that victimized me, feeling vast,
feeling virginal... was this how he felt? This verve, this vitality... this vision...

La voie... la vérité... la vie.
(SPOILER)
The Dead Flag Blues
The car is on fire, and there’s no driver at the wheel, and the sewers are all muddied with a thousand lonely suicides, and a dark wind blows. The government is corrupt, and we’re on so many drugs with the radio on and the curtains drawn. We are trapped in the belly of this horrible machine, and the machine is bleeding to death. The sun has fallen down, and the billboards are all leering, and the flags are all dead at the top of their poles.

It went like this: The buildings tumbled in on themselves; mothers clutching babies picked through the rubble and pulled out their hair. The skyline was beautiful on fire, all twisted metal stretching upwards, everything washed in a thin orange haze. I said, “Kiss me, you are beautiful; these are truly the last days.” You grabbed my hand, and we fell into it like a daydream or a fever.

We woke up one morning and fell a little further down; for sure it’s the valley of death. I open up my wallet, and it’s full of blood.
Gravity’s Rainbow
The Smashing Pumpkins
we can watch the world devoured in its hate.
The late prophet Bill Hicks
I’m so sick of arming the world and then sending troops over to destroy the fucking arms, you know what I mean? We keep arming these little countries then we go and blow the shit out of ’em. We’re like the bullies of the world, you know. We’re like Jack Palance in the movie Shane, throwing the pistol at the sheep herder’s feet: “Pick it up.” “I don’t wanna pick it up, mister; you’ll shoot me.” “Pick up the gun.” “Mister, I don’t want no trouble, huh. I just came downtown here to get some hard rock candy for my kids, some gingham for my wife. I don’t even know what gingham is, but she goes through about ten rolls a week of that stuff. I ain’t looking for no trouble, mister.” “Pick up the gun.” Boom, boom. “You all saw him. He had a gun.”

moar I’ll show you politics in America. Here it is, right here. “I think the puppet on the right shares my beliefs.” “I think the puppet on the left is more to my liking.” “Hey, wait a minute, there’s one guy holding out both puppets!” “Shut up! Go back to bed, America! Your government is in control. Here's Love Connection. Watch this and get fat and stupid. By the way, keep drinking beer, you fucking morons.”

All governments are liars and murderers. Go back to bed, America! Your government has figured out how it all transpired. Go back to bed, America! Your government is in control again. Here, here’s American Gladiators. Watch this, shut up! Go back to bed, America! Here is American Gladiators; here is 56 channels of it! Watch these pituitary retards bang their fucking skulls together and congratulate you on living in the land of freedom! Here you go, America: You are free to do what we tell you! You are free to do what we tell you!

The Supreme Court says pornography is anything without artistic merit that causes sexual thoughts, that’s their definition, essentially. No artistic merit, causes sexual thoughts. Hmm… Sounds like… every commercial on television, doesn’t it? You know, when I see those two twins on that Doublemint commercial? I’m not thinking of gum. I am thinking of chewing, so maybe that’s the connection they’re trying to make.

I have this feeling man, ’cause you know, it’s just a handful of people who run everything, you know… that’s true, it’s provable. It’s not… I’m not a fucking conspiracy nut; it’s provable. A handful, a very small elite, run and own these corporations, which include the mainstream media. I have this feeling that whoever is elected president, like Clinton was, no matter what you promise on the campaign trail – blah, blah, blah – when you win, you go into this smoke-filled room with the twelve industrialist capitalist scumfucks who got you in there. And you’re in this smoky room, and this little film screen comes down, and a big guy with a cigar goes, “Roll the film.” And it’s a shot of the Kennedy assassination from an angle you’ve never seen before that looks suspiciously like it’s from the grassy knoll. And then the screen goes up and the lights come up, and they go to the new president, “Any questions?” “Er, just what my agenda is.” “First we bomb Baghdad.” “You got it…”

They don’t want the voice of reason spoken, folks, ’cause otherwise, we’d be free. Otherwise, we wouldn’t believe their fucking horseshit lies, nor the fucking propaganda machine of the mainstream media and buy their horseshit products that we don’t fucking need and become a third world consumer fucking plantation, which is what we’re becoming. Fuck them! They are liars and murderers. All governments are liars and murderers, and I am now Jesus, and this is MY compound.

The world is like a ride at an amusement park. It goes up and down and round and round. It has thrills and chills and it’s very brightly coloured and it’s very loud and it’s fun for awhile. Some people have been on the ride for a long time and they begin to question, is this real, or is this just a ride? And other people have remembered, and they come back to us, they say, “hey – don't worry, don’t be afraid, ever, because this is just a ride…” And we… kill those people. Haha. “Shut him up. We have a lot invested in this ride. Shut him up. Look at my furrows of worry. Look at my big bank account and my family. This just has to be real.” It’s just a ride. But we always kill those good guys who try and tell us that, you ever notice that? And let the demons run amok. Jesus murdered; Martin Luther King mudered; Malcolm X murdered; Gandhi murdered; John Lennon murdered; Reagan… wounded. But it doesn’t matter because it’s just a ride. And we can change it anytime we want. It’s only a choice. No effort, no work, no job, no savings and money. A choice, right now, between fear and love. The eyes of fear want you to put bigger locks on your doors, buy guns, close yourself off. The eyes of love, instead, see all of us as one. Here’s what we can do to change the world, right now, to a better ride. Take all that money that we spend on weapons and defences each year and instead spend it feeding and clothing and educating the poor of the world, which it would many times over, not one human being excluded, and we could explore space, together, both inner and outer, forever, in peace. Thank you; you’ve been great.

ACF awards an' shit Best Member Rep · Best Signature · Most Respected · Best Poster · Best Debater · Most Intelligent · Most Political Knowledge · Second Most Literary Knowledge · Third Best Male Member (Tie) · Third Most Likely to Get Modded (Tie) · Third Most Likely to Become the Next Admin
quote