Page 2 of 4

Re: Deleting Clipped Audio

Posted: Thu Nov 22, 2012 2:13 pm
by steve
Gale Andrews wrote:Did you ever finish that version of Clip Fix that compensated for inverted polarity?
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.
tlm wrote:As requested, I've also uploaded a .WAV version of the file:
That appears to be another copy of the "fixed" version.

Using the MP3 sample, I applied this code in the Nyquist Prompt effect:

Code: Select all

(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))

and this is the result:
testFixed2.flac
(596.42 KiB) Downloaded 123 times

Re: Deleting Clipped Audio

Posted: Thu Nov 22, 2012 2:23 pm
by steve
The sample can be cleaned up a bit more by manually using the Repair tool. The track Spectrum view can help to identify the clicks: http://manual.audacityteam.org/o/man/tr ... pectrogram
testFixed3.flac
(593.48 KiB) Downloaded 119 times

Solution?

Posted: Thu Nov 22, 2012 4:13 pm
by tlm
Steve,

Are you saying you were able to produce testFixed2.flac without doing it manually? If so, I think it's great.

Can you provide step-by-step instructions for how you did it? I'd love to apply the technique to the whole audio.

By the way, the original is not available to me -- just the mp3.

Thanks again!

Problem Solved!

Posted: Thu Nov 22, 2012 4:54 pm
by tlm
Steve,

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.

Thanks again, Steve!

Re: Deleting Clipped Audio

Posted: Thu Nov 22, 2012 6:11 pm
by steve
After "fixing" the track with the Nyquist script, it is possible that some parts may be over 0 dB, so use the Normalize effect and normalize to -1 dB.

Re: Problem Solved!

Posted: Fri Nov 23, 2012 6:24 am
by Gale Andrews
@Steve, your improved ClipFix that deals with inverted polarity would be interesting to see sometime.
tlm wrote: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.
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.


Gale

Re: Deleting Clipped Audio

Posted: Fri Nov 23, 2012 4:17 pm
by steve
Gale Andrews wrote:@Steve, your improved ClipFix that deals with inverted polarity would be interesting to see sometime.
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.

Re: Deleting Clipped Audio

Posted: Sat Nov 24, 2012 9:18 am
by Gale Andrews
steve wrote:
Gale Andrews wrote:@Steve, your improved ClipFix that deals with inverted polarity would be interesting to see sometime.
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.
Thanks for that.

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.


Gale

Re: Deleting Clipped Audio

Posted: Sat Nov 24, 2012 5:00 pm
by steve
Gale Andrews wrote: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.
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.
firsttrack004.png
firsttrack004.png (8.61 KiB) Viewed 2223 times

Re: Deleting Clipped Audio

Posted: Tue Nov 27, 2012 8:15 am
by Gale Andrews
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.

Code: Select all

error: bad argument type - #(#<Sound: #6680628> #<Sound: #6680568>)
Function: #<Subr-SND-LENGTH: #b052430>
Arguments:
  #(#<Sound: #6680628> #<Sound: #6680568>)
  100000000
Function: #<FSubr-SETQ: #b054500>
Arguments:
  SLENGTH
  (SND-LENGTH S LARGENUMBER)
1> #(#<Sound: #6680628> #<Sound: #6680568>)
1> 0
1> 0.5
1> error: unbound variable - SLENGTH
if continued: try evaluating symbol again
Function: #<FSubr-SETQ: #b054500>
Arguments:
  ARRAY
  (SND-FETCH-ARRAY S1 SLENGTH SLENGTH)
Function: #<Subr-SND-LENGTH: #b052430>
Arguments:
  #(#<Sound: #6680628> #<Sound: #6680568>)
  100000000
Function: #<FSubr-SETQ: #b054500>
Arguments:
  SLENGTH
  (SND-LENGTH S LARGENUMBER)
2> error: unbound variable - ARRAY
if continued: try evaluating symbol again
Function: #<FSubr-SETQ: #b054500>
Arguments:
  CURRENT
  (AREF ARRAY 0)
Function: #<FSubr-SETQ: #b054500>
Arguments:
  ARRAY
  (SND-FETCH-ARRAY S1 SLENGTH SLENGTH)
Function: #<Subr-SND-LENGTH: #b052430>
Arguments:
  #(#<Sound: #6680628> #<Sound: #6680568>)
  100000000
Function: #<FSubr-SETQ: #b054500>
Arguments:
  SLENGTH
  (SND-LENGTH S LARGENUMBER)
3> error: unbound variable - SLENGTH
if continued: try evaluating symbol again
Function: #<FSubr-DO: #b0536d0>
Arguments:
  ((COUNT 0 (+ COUNT 1)))
  ((>= COUNT SLENGTH) ARRAY)
  (SETQ NEXT (AREF ARRAY COUNT))
  (SETQ DIF (DIFF CURRENT NEXT))
  (IF (< DIF 0) (SETQ DIF (DIFF 0 DIF)))
  (IF (> DIF LIMIT) (SETF (AREF ARRAY COUNT) CURRENT))
  (IF (> DIF LIMIT) (SETQ NEXT CURRENT) (SETQ CURRENT NEXT))
Function: #<FSubr-SETQ: #b054500>
Arguments:
  CURRENT
  (AREF ARRAY 0)
Function: #<FSubr-SETQ: #b054500>
Arguments:
  ARRAY
  (SND-FETCH-ARRAY S1 SLENGTH SLENGTH)
Function: #<Subr-SND-LENGTH: #b052430>
Arguments:
  #(#<Sound: #6680628> #<Sound: #6680568>)
  100000000
Function: #<FSubr-SETQ: #b054500>
Arguments:
  SLENGTH
  (SND-LENGTH S LARGENUMBER)
4> error: bad argument type - #(#<Sound: #6680628> #<Sound: #6680568>)
Function: #<Subr-SND-SRATE: #b052d10>
Arguments:
  #(#<Sound: #6680628> #<Sound: #6680568>)
Function: #<FSubr-SETQ: #b054500>
Arguments:
  S
  (SND-FROM-ARRAY 0 (SND-SRATE S) ARRAY)
Function: #<FSubr-DO: #b0536d0>
Arguments:
  ((COUNT 0 (+ COUNT 1)))
  ((>= COUNT SLENGTH) ARRAY)
  (SETQ NEXT (AREF ARRAY COUNT))
  (SETQ DIF (DIFF CURRENT NEXT))
  (IF (< DIF 0) (SETQ DIF (DIFF 0 DIF)))
  (IF (> DIF LIMIT) (SETF (AREF ARRAY COUNT) CURRENT))
  (IF (> DIF LIMIT) (SETQ NEXT CURRENT) (SETQ CURRENT NEXT))
Function: #<FSubr-SETQ: #b054500>
Arguments:
  CURRENT
  (AREF ARRAY 0)
Function: #<FSubr-SETQ: #b054500>
Arguments:
  ARRAY
  (SND-FETCH-ARRAY S1 SLENGTH SLENGTH)
Function: #<Subr-SND-LENGTH: #b052430>
Arguments:
  #(#<Sound: #6680628> #<Sound: #6680568>)
  100000000
Function: #<FSubr-SETQ: #b054500>
Arguments:
  SLENGTH
  (SND-LENGTH S LARGENUMBER)
5> DECLIP
5> WORKHORSE
5> NIL
5> #(#<Sound: #6680328> #<Sound: #66806d8>)
5> 4> 3> 2> 1> 



Gale