Wanted: a plugin to find synchronous zero crossings

I wasn’t a programmer either, but I needed modified versions of some plug-ins, so I used the documentation and had a go. I was fortunate to have help when I needed it (that was on a mailing list, as this forum had only just started). As with anything, the more you do, the more you learn :wink:

Try this version. I’ve also added some comments to the code that explain some of the less obvious parts:
(a “comment” is text that is ignored by Nyquist and is for the benefit of anyone reading the code. Comments begin with a semicolon “;”)

If you have any questions about this code, feel free to ask.

(defun find-zero (sig)
  (let ((prev0  (plusp (snd-fetch (aref sig 0)))) ; is left positive
        (prev1  (plusp (snd-fetch (aref sig 1)))) ; is right positive
        new0  ;new sample (left)
        new1  ;new sample (right)
        rslt
        zx0 ; zero crossing flag (left)
        zx1); zero crossing flag (right) 
    (do ((val0 (snd-fetch (aref sig 0)) (snd-fetch (aref sig 0)))
         (val1 (snd-fetch (aref sig 1)) (snd-fetch (aref sig 1)))
         (count 0.5 (1+ count)))  ; rslt flag will be placed between previous and current samples
        ((not val0) rslt)
      (setf new0 (plusp val0))  ; is left still positive
      (setf new1 (plusp val1))  ; is right still positive
      ;; Previous and current sign both positive, or both "not positive".
      ;; When both are the same sign, we have not crossed zero.
      (setf zx0 (or (and prev0 new0)
                    (and (not prev0) (not new0))))
      (setf zx1 (or (and prev1 new1)
                    (and (not prev1) (not new1))))
      (when (and (not zx0) (not zx1))  ; left and right have crossed zero
        (setf rslt count))
      ;; Update previous sample flags
      (setf prev0 new0)
      (setf prev1 new1))))


(setf z (find-zero *track*))
(if z
    (list (list (/ z *sound-srate*) "Z"))
    "Zero crossing not found")



I can only speak for myself:
When I’m doing a lot of detailed editing, I’m usually working with mono tracks, so this is a non-issue.
When working with stereo tracks, I’m usually only making a few edits, so it’s no great difficulty to simply zoom in close (Ctrl + Mouse wheel) and select an edit point manually.