I'm impressed - the soft clipping sounds better than my original plug-in

It does weird things on stereo files though.
For processing stereo files you could add this to the end:
Code: Select all
(if (arrayp s)
(vector (limit (aref s 0))(limit (aref s 1)))
(limit s))
but you would also need to rename the variable "s" within the function so as to differentiate it from "s".
For example:
Code: Select all
;nyquist plug-in
;version 1
;type process
;name "soft-knee brickwall limiter"
(defun limit (s-in)
(mult s-in (diff 1.0 (mult 0.5 (s-abs s-in)))))
(if (arrayp s)
(vector (limit (aref s 0))(limit (aref s 1)))
(limit s))
A shorter, but somewhat more cryptic way of writing this would be:
Code: Select all
(defun limit (s-in)
(mult s-in (diff 1.0 (mult 0.5 (s-abs s-in)))))
(multichan-expand #'limit s)
(note the single quote after the #)
If this effect is used for "maximising" a recording, you will want to amplify the output to compensate for the reduction in peak gain.
Fortunately, this algorithm produces easily predictable attenuation (where the multiplier of (s-abs s) is greater than 0.5).
Here is a slight modification that allows the limiter threshold to be set in the range of 0 to -6 dB ( -6dB is the same as your code) and can also perform the necessary amplification to compensate for the peak attenuation.
Code: Select all
;nyquist plug-in
;version 1
;type process
;name "soft-clip brickwall limiter"
;info "Usually best to Normalize the audio before using this effect."
;control thresh "Threshold" real "dB" -3 -6 0
;control mu "Apply Make-Up Gain?" choice "Yes,No" 0
; limit max and min values of thresh
(setq thresh (min (max thresh -6) 0))
; convertthresh to linear scale
(setq thresh (dB-to-linear thresh))
(Let
((make-up (if (= mu 0)(/ thresh)1)) ; set make up gain to inverse of thresh, or 1
(thresh (- 1.0 thresh))) ; set thresh
(defun limit (s-in)
(mult s-in make-up (diff 1.0 (mult thresh (s-abs s-in)))))
(multichan-expand #'limit s))