;nyquist plug-in ;version 1 ;type process ;name "Delete With Crossfade" ;action "Crossfading..." ;info "Delete with Crossfade written by Malcolm Sharpe and Bruce Sharpe\nCopyright (c) 2005 Singular Software ;control fade-length "Crossfade length" real "s" 0.10 0 10 ;; Copyright (c) 2005, Singular Software ;; All rights reserved. ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are ;; met: ;; ;; * Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; * Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; * Neither the name of Singular Software nor the names of its ;; contributors may be used to endorse or promote products derived ;; from this software without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ;; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ;; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ;; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. (setq +max-seconds+ 600) (setq +max-samples+ (* +max-seconds+ 44100)) (defun snd-range (snd) (snd-extent snd +max-samples+)) (defun process-channel (channel) (let* ((range (snd-range channel)) (length (cadr range))) ; Check if selection is long enough (when (> (* 2 fade-length) length) (progn ; need progn because Nyquist does not allow multiple expressions in body of when (format t "Selection of length ~a not long enough for cross fade of ~a~%" length fade-length) (return-from process-channel channel))) ; Extract beginning and end of selection (let* ((fade-length-ratio (/ fade-length length)) (beg-sound (extract 0 fade-length-ratio channel)) (end-sound (extract (- 1 fade-length-ratio) 1 channel))) ; Crossfade the beginning and end, discarding the middle ; We use pwl instead of ramp because ramp has an extra sample at the end which can cause glitches (let* ((end-ramp (control-srate-abs (snd-srate channel) (pwl fade-length-ratio 1))) (beg-ramp (diff (const 1) end-ramp))) (sum (mult beg-sound beg-ramp) (mult end-sound end-ramp)))))) ; Stereo files require special processing because not all sound functions support stereo (if (arrayp s) (progn (let ((out-array (make-array 2))) (dotimes (i 2) (setf (aref out-array i) (process-channel (aref s i)))) out-array)) (process-channel s))