If you only need to process very short sections at a time (say, under a couple of seconds), then your algorithm can be applied quite simply.
I’ve added a lot of comments to this code so that hopefully you can see what it is doing.
Note that the sample values must be exactly zero to be corrected.
; limit selection to 100,000 samples
(setq max-samples (min 100000 (truncate len)))
;;; Function to correct zero samples
(defun correct (sig)
;grab samples in an array
(setf s-array (snd-samples sig max-samples))
;; main loop
(do ((count 1 (1+ count)))
; loop through samples
((>= count (- max-samples 2))
; return sound from samples
(snd-from-array 0 *sound-srate* s-array))
; when sample value is zero
(when (= (aref s-array count) 0)
;; set new 'average' value
(setf (aref s-array count)
(/ (+ (aref s-array (1- count))
(aref s-array (1+ count)))
2.0))
; and skip the next 3 samples
(setq count (+ 3 count)))))
;; check selection length and if OK run the program
(if (<= len max-samples)
; run it
(multichan-expand #'correct s)
; print an error message
(format nil "Error.~%maximum selection length is ~a seconds."
(/ max-samples *sound-srate*)))
Again you can run this code in the Nyquist Prompt effect.
Don’t try to use this simple approach on selections more than a few seconds or you will probably crash Audacity.
This version is limited to 100,000 samples which should be safe.