ScratchMarker

ScratchMarker plugin, for finding scratches on vinyl for subsequent repair (manual or using another plugin).
ScratchMarker.ny (1.17 KB)

Thanks Colin. It works for me.
Would you like some ideas for how to improve it?

Of course. Though I haven’t used it myself for a long time and don’t expect to in the foreseeable future. I wrote it years ago, and only recently thought it might be useful to someone else.

Cool :sunglasses:

The age of the plug-in answers my first point. It’s written as a “version 1” plug-in. We’re now up to “version 4”, which has additional features that we can benefit from.

Converting the plug-in to version 4 is dead easy. All you need to do is:

  1. change the ;version 1 header to ;version 4
  2. change occurrences of the variable S (the track audio) to track

Currently you are finding the peak level of the selection with:

(setq x (peak s1 NY:ALL))

where s1 is either the original track audio, or if stereo, is the mix of left and right channels.

An unfortunate feature of (peak NY:ALL) is that when evaluated, the sound is retained in memory, which is a potential crash problem for long selections (Nyquist is 32-bit, so has limited addressable memory space).

A new feature in version 4 plug-ins is that we can read the peak level of a selection directly from Audacity (because Audacity already knows).
Documentation: http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference#.2ASELECTION.2A
Example:

(print (linear-to-db (get '*SELECTION* 'PEAK-LEVEL)))

However, I thing we can do better than that.

I really like how simple the algorithm is in your plug-in, but it falls down when the music is highly dynamic. If there is one or more loud bits in the music, then the reference level for determining peaks anywhere in the selection is a proportion of the level of the highest peak. Thus we end up either marking a lot of inaudible clicks during loud parts, or failing to mark very audible peaks during quiet parts.

I’d suggest as an alternative, comparing the “click level” with a localized peak level, for example, look at what the peak level is within a proximity of say +/- 0.1 seconds of where the (possible) click occurs. Thus we are looking at the difference between the high-pass filtered signal, and a proportion of the local peak level for unfiltered audio.

A way to do this would be to use SND-AVG.
Schematically, we would subtract a proportion of the ‘rolling peak’ (calculated with snd-avg) from the filtered peaks, the look to see where the level is greater than zero.