I’ve seen many posts asking how to repair audio which has been clipped during recording. The general answer is: for mild cases use “Effect–>Clip Fix…”, but for severe cases IT CANT BE DONE. Well, since I’m an AmeriCAN rather than an AmeriCANT, I don’t accept that.
For simple speech, THERE IS A WAY to repair even severely clipped audio which produces an acceptable result. The problem is that the process is very time consuming. That’s where you brilliant Audacity experts come in: if you can teach us how to automate this process you will help a lot of folks.
By using View–>“Show Clipping” you all clipped regions are highlighted in red. What I have found is that if I go in and delete all those highlighted data points individually (TIME CONSUMING!) the result is acceptable sounding. So can someone tell me how do that quickly? Yes, in the worst cases this will produce a glitch, but it’s better than hearing the speaker try to interpret a clip.
It seems to me this should be easy for a coder since the program obviously knows where all those highlighted data points are. It would be best if this could be done in only selected regions since not all clips produces distorted sound.
I’ve found that if the data is filtered using Effect–>Equalization as in screen shot 1:
the result is that all the awful sounding glitches show up as distinct spikes. As shown in screen shot 2:
If I then go through and delete just those spikes the result is a pretty acceptable. It is REALLY time consuming to do it manually. So once again, my question is how could I delete all those quickly? (By the way, when you zoom in on those spikes, it looks as shown in screen shot 3, where the 2 tracks show a “before” and “after” applying the equalization of screen shot 1.)
So in each case my main question is: How can I use audacity to quickly delete all data points that exceed a defined threshold? If I could somehow export the data to Excel (64-bit) and reimport it to Audacity I would immediately know how to solve the problem, but no one seems to have solved that issue either.
So you essentially want the data that writes the red bars in the display that tells us where the clipping is.
Yes, in the case of moderate voice clipping that would probably work OK, however the two most experienced clipping events are plugging a powerful line-level stereo signal into the Mic-In of a laptop, and wanting to fix a camcorder rock concert recording.
The Mic-In problem produces very serious clipping and distortion 6dB down from Audacity overload. No red bars and no outward indication of damage. The rock concert recording is almost always 100% distortion and clipping garbage – and it’s all continuous music.
Straight, simple vocal clipping is a very distant third, but it does occur. This would be a good tool to have.
If it’s your recording, it would be far better to turn the input down to a more reasonable level (or ensure you plug into the correct input or record with an appropriate device. I assume image 2 is after deamplifying, and it looks very flat-topped. How exactly are you making these recordings?
It would be much better to go with a plug-in or some kind of filter processing on the whole track. I don’t think it’s ideal to EQ, delete, then apply the inverse EQ to get back to something like the original EQ.
Can you compile Audacity? There a couple of patches that have never been properly tested that apply Effect > Repair to sections detected by Analyze > Find Clipping. I don’t know if either patch still builds but I’ve been meaning to see if they do. Repair would be better than delete, but at present Repair only works on extremely small selections of up to 128 samples at a time. It may depend how clipped the recordings were in the first place.
I’ve attached a small mp3 portion of the audio to this post for steve and others who’ve requested it.
In response to Gale: yes, you are surely right that the BEST way is to record the audio without clipping in the first place. But as I mentioned, I’ve found many posts online from folks in a similar situation to mine: The recording cannot be made again because the event is over and if we want to share it with others we are stuck with this recording. Based on my manual deleting, I KNOW that a much better product can be made by deleting the largest spikes – but as I said, that process must be automated to be practical. I also agree that using EQ to magnify the portions to delete (the spikes seen in screenshot 3) is not ‘ideal’. But I want to emphasize that for simple speech it’s not necessary to have ‘ideal’ sound – but it is necessary to remove glitches that hurt your ears, and that’s all I’m after as the person who wants to ‘repair’ this audio.
In response to Koz: I guess you could say that I request 2 things in my post: (1) Being able to “select” all the data points which are highlighted when one chooses View–>Show Clipping. Once selected, you could then press “delete” and they’d be gone. (2) To be able to set a horizontal threshold above/below which data points would be selected – thus the spikes of screen shot 3 (which is where all the unpleasant glitches occur) could then be removed by pressing “delete”. I can do both (1) & (2) manually, but it just takes forever.
The “test.mp3” file I uploaded had already been altered with Audacity (I’ve been trying a LOT of things so I got confused). To this post, I’ve now attached the same portion of audio from the raw, original recording:
You’ll note that it’s pretty severely clipped.
Also, here are my answers to Gale’s other questions: I did not make this recording, but rather am in the position of “fixing” it. However, the same thing has happened when I have been responsible for doing recordings, and in that case Audacity was used to make the recording and the input was set too high, giving a similar result. I have never compiled Audacity but I suppose I could if really necessary – my coding experience is mostly with Excel VBA, but I’ve used other languages.
The problem is that it has been recorded with bad electronics that have allowed clipped audio to “overflow” between positive and negative numbers.
If you look at the highlighted section, the sample values have overflowed from positive values to negative.
What format is the original recording?
One of the problems that I am seeing is that the distortion has been further mashed by MP3 encoding.
Could you send a short clip in WAV or FLAC format?
In response to Steve, I’ve attached a “repaired” version of the testRaw.mp3 file:
I admit that it’s far from ideal, but at least the loudest screeching sounds are gone. After deleting the small sections, the discontinuities result in clicks – so I applied the repair tool to those – but even without the repair tool, the clicks are still much better than the screeching (especially with headphones!). Here is the procedure I followed to repair it:
Select All, Effect → Amplify → -4, Effect → Equalization → use profile shown in screen shot 1 above, Effect → Amplify → 7.2,
Select 0.796 - 0.855, delete
2.395 - 2.445
3.282 -3.361
5.325 - 5.451
5.522 - 5.579
10.022 - 10.126
11.438 - 11.522
I then took a little more off of the 10s spike, 10.015-10.022, amplified the result using Effect → amplify 6, and then went in to repair 0.002 second segments at each discontinuity, and finally amplified once more using Effect → amplify 0.6
I could imagine the process being automated by finding each spike that exceeds a threshold, defining a delete width, and then applying repair to the result.
As requested, I’ve also uploaded a .WAV version of the file:
I have a “working” version, but it can’t help with this because the inverted audio has been damaged further (MP3 encoding will have caused some damage). The “corners” where the audio is inverted are now slightly rounded so the plug-in is unable to recognise the inverted sections.
That appears to be another copy of the “fixed” version.
Using the MP3 sample, I applied this code in the Nyquist Prompt effect:
(setq threhold 0.95)
(setq frequency 16000)
(let* ((control (rms
(sum (- threhold)
(s-max (snd-abs s) threhold))
20))
(gain (/ (peak control ny:all)))
(control (mult frequency
(sum 1
(mult control (- gain))))))
(lp
(lp
(lp
(lp
(lp
(lp
(lp
(lp s
control)
control)
control)
control)
control)
control)
control)
control))
I figured out how to apply your solution: Effect–>Nyquist Prompt and then paste in your code. Although the result is far from perfect, it is an improvement. I also viewed using the individual Track Drop Down → spectrogram, but did not find it all that helpful (since this recording is SUCH a mess), and improving your solution manually with the repair tool just doesn’t seem worth the time. If anyone comes up with something better, I’ll be interested, but I’m going with Steve’s solution for now.
So, for those out there wanting to repair severely clipped audio by selectively removing the portions which cause distortion SCREECH: yes, it CAN be done – at least partially.
@Steve, your improved ClipFix that deals with inverted polarity would be interesting to see sometime.
Neither of the automated “Fix Clipping” effects I mentioned (based on using Repair on regions detected by Find Clipping) will now compile “as is” on Windows.
One of these effects was supplied with a DLL, so I could run that as an Audacity module, but it had no more effect on Tim’s track than doing manual Repair of sections. That’s not just because of the inverted polarity in that track, but because the effect would need to still detect the clipped parts after de-amplification so as to give some headroom to repair into. However it apparently can’t do that.
The other attempt at the same kind of effect claims it can do the detection after deamplification, but isn’t compilable at present.
There is an experimental version available on my website: http://audionyq.com/?p=226
Note that this is “experimental”. It may contain bugs and may crash Audacity. On anything more than a few seconds of audio it is likely to be extremely slow.
I did not have much success with it on a very contrived spoken clip where I had amplified to +2 dB, inverted a few samples in two separate regions, then de-amplified to -6 dB. ESP Clip Fix audibly (and visually) had a little more effect than standard Clip Fix.
Effect > Repair over the two inverted regions seemed to smooth them more completely than using ESP Clip Fix on them.
No it won’t work on that.
In real cases where inversion occurs, it is always the peaks that become inverted.
It also won’t work on MP3s because the “corners” are smoothed by MP3 encoding.
OK it worked fine when I inverted some peaked samples as you suggested.
It seems it won’t work on stereo tracks. It returns the value 100000, debug output as below, even if the track or the selection inside it is only a few thousand samples.