(load "blit.lisp")
(defun envelope-or-number (in)
(if (numberp in)
(list 0 in 1 in)
in
))
(definstrument good-saw (start-time duration frequency &optional (amp 1.0)
&key (amp-env '(0 1.0 1.0 1.0))
(freq-env '(0 1 1.0 1)) ;frequency envelope as a factor of original frequency
(leak (- 1 (/ 35 *srate*))) ; -0.5 dB at 20 Hz 0.99841
(limit .9) ;attenuation at Nyquist, affects sharpness of waveform, eliminates Gibb's phenomena (!! Must be less than 1.0)
(glide 4) ;exponent of portamento (quartic functions approximate logarithmic behavior)
(phase 0) ;between 0 and 1
)
(multiple-value-bind (beg end) (times->samples start-time duration)
(let* (
(theblit (make-blit-init :frequency frequency :phase phase :nyquist limit))
(integrator (make-one-pole :a0 1
:b1 (- leak)))
(amp (make-env :envelope amp-env
:scaler amp
:duration duration))
(freq (make-env :envelope (envelope-exp freq-env glide)
:scaler frequency
:duration duration))
f
)
(run
(loop for i from beg below end do
(setf f (env freq))
(if (blit-wrapped theblit)
(set-blit-frequency theblit f)
)
(outa i (* (env amp) 1.6 ;;correction factor
(one-pole integrator (blit theblit))
)
))))
)
)
;(with-sound () (good-saw 0 5 100 0.3 :freq-env '(0 1 1 16)))
;;(with-sound () (good-saw 0 5 100 0.3 :freq-env '(0 1 1 .125) :cutoff '(0 1000 1 100) :resonance 0.8))