Main Page       Index


xenvelope.lsp


 xenvelope.lsp
 Version 1.00  14 November 04
 Author  Steven Jones

 Contact jones57@swbell.net include the word "nyquist" in subject line  

 The contents of this file are released under the terms of the GNU General
 Public License. See the file LICENSE.txt

 Exponential envelopes.


function

xad

 (xad [a [d]])
 Two stage attack/decay envelope with exponential shape.
 a      - FLONUM. Attack time in seconds, default 0
 d      - FLONUM. Decay time, default 1 sec
 return - SOUND.


function

xasd

 (xasd  [a [s [d]]])
 A three stage attack-sustain-decay envelope with exponential contour.

 a      - flonum. Attack time, default 0 sec.
 s      - flonum. Sustain time, default 1 sec.
 d      - flonum. Decay time, default 0 sec.
 return - sound


function

xadsr

 (xadsr  [a [d [s [r [sl [dur][[[[[)
 A four stage ADSR style envelope with exponential contour.

 a      - flonum. Attack time, default 0 sec
 d      - flonum. Decay time, default 0 sec.
 s      - flonum. Sustain time, default 1 sec.
 r      - flonum. Release time, default 0 sec.
 sl     - flonum. Sustain level 0 <= sl <= 1, default 0.75
 dur    - flonum. Explicit duration. If not specified the total duration is 
          the implicit sum a+d+s+r. If dur is specified and is greater the 
          implicit duration, the sustain stage is lengthened as needed. If 
          the explicit duration is less then the implicit duration, a two 
          stage envelope is used with the a:r ratio maintained and 
          a+r = dur.
 return - sound


View the Sourcecode :



;; xenvelope.lsp
;; Version 1.00  14 November 04
;; Author  Steven Jones
;;
;; Contact jones57@swbell.net include the word "nyquist" in subject line  
;;
;; The contents of this file are released under the terms of the GNU General
;; Public License. See the file LICENSE.txt
;;
;; Exponential envelopes.
;;

(provide 'xenvelope)
(current-file "xenvelope")


;; @doc function xad
;; (xad [a [d]])
;; Two stage attack/decay envelope with exponential shape.
;; a      - FLONUM. Attack time in seconds, default 0
;; d      - FLONUM. Decay time, default 1 sec
;; return - SOUND.
;;

(defun xad (&rest args)
  (let ((a (or (car args) 0))
	(d (or (car (cdr args)) 1)))
    (xasd a 0 d)))


;; @doc function xasd 
;; (xasd  [a [s [d]]])
;; A three stage attack-sustain-decay envelope with exponential contour.
;;
;; a      - flonum. Attack time, default 0 sec.
;; s      - flonum. Sustain time, default 1 sec.
;; d      - flonum. Decay time, default 0 sec.
;; return - sound
;;

(defun xasd (&rest args)
  (let ((a (or (car args) 0))
	(s (or (second args) 1))
	(d (or (third args) 0)))
    (sum -1 (pwer a 2 s 2 d))))


;; @doc function xadsr
;; (xadsr  [a [d [s [r [sl [dur][[[[[)
;; A four stage ADSR style envelope with exponential contour.
;;
;; a      - flonum. Attack time, default 0 sec
;; d      - flonum. Decay time, default 0 sec.
;; s      - flonum. Sustain time, default 1 sec.
;; r      - flonum. Release time, default 0 sec.
;; sl     - flonum. Sustain level 0 <= sl <= 1, default 0.75
;; dur    - flonum. Explicit duration. If not specified the total duration is 
;;          the implicit sum a+d+s+r. If dur is specified and is greater the 
;;          implicit duration, the sustain stage is lengthened as needed. If 
;;          the explicit duration is less then the implicit duration, a two 
;;          stage envelope is used with the a:r ratio maintained and 
;;          a+r = dur.
;; return - sound
;;

(defun xadsr (&rest args)
  (let* ((a (or (car args) 0))
	 (d (or (second args) 0))
	 (s (or (third args) 1))
	 (r (or (fourth args) 0))
	 (sl (clamp (+ 1 (or (fifth args) 0.75)) 1 2))
	 (idur (+ a d s r))
	 (xdur (or (sixth args) idur)))
    (cond ((= xdur idur)(sum -1 (pwer a 2 d sl s sl r)))
	  ((> xdur idur)(sum -1 (pwer a 2 d sl (+ s (- xdur idur)) sl r)))
	  (t (let  (ar rr)
	       (cond ((> a r)
		      (setq ar (/ r (float (max a 0.00001)))
			    rr (- 1 ar)))
		     ((= a r)
		      (setq ar 0.5
			    rr 0.5))
		     (t
		      (setq rr (/ a (float (max r 0.00001)))
			    ar (- 1 rr))))
	       (xasd (* xdur rr) 0 (* xdur ar)))))))


Main Page       Index