The story so far:
We have this code that will apply a 5 ms fade-in to the start of the selection, and a 5 ms fade-out to the end.
(setq fade-length 0.005)
(setq dur (get-duration 1))
(abs-env
(control-srate-abs *sound-srate*
(let* ((fl fade-length)
(env (pwlv 0 fl 1 (- dur fl) 1 dur 0)))
(mult s env))))
It applies a simple linear fade because that creates the least amount of distortion for very short fades (for longer fades, “curved” fades will provide less harmonic distortion than linear fades, but we are only dealing with very short fades).
Reference: http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference
To turn this code into a plugin we need to add the “plugin header”.
At the time of writing, the release version of Audacity is 2.0.6, so we shall write this as a “version 3” plugin (the most recent version supported by Audacity 2.0.6).
So here is the plugin code:
;nyquist plug-in
;version 3
;type process
;name "Fade Clip Edges"
;action "Applying Fades..."
;author "Steve Daulton"
;copyright "Released under terms of the GNU General Public License version 2"
;; fade-edges.ny by Steve Daulton Feb 2015
;; Released under terms of the GNU General Public License version 2:
;; http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
;;
;; For information about writing and modifying Nyquist plug-ins:
;; http://wiki.audacityteam.org/wiki/Nyquist_Plug-ins_Reference
(setq fade-length 0.005)
(setq dur (get-duration 1))
(abs-env
(control-srate-abs *sound-srate*
(let* ((fl fade-length)
(env (pwlv 0 fl 1 (- dur fl) 1 dur 0)))
(mult s env))))
And here as a downloadable file:
fade-edges.ny (726 Bytes)
So far there is no error checking in this code.
We should probably add a warning if the selected audio is too short for applying the fades.
Question for Steve Bender: How are we doing so far?