;;; -*- syntax: common-lisp; package: clm; base: 10; mode:lisp -*-
(define *srate* 44100)

;; bipolar sawtooth implementation
(definstrument (sawtooth start-time duration amplitude freq)
  (let* ((oscillator (make-sawtooth-wave freq))
	 (start-sample (floor (* start-time *srate*)))
	 (end-sample (+ start-sample (floor (* duration *srate*)))))
    (do ((index start-sample (+ index 1)))
         ((> index end-sample))
       (outa index (* amplitude (sawtooth-wave oscillator))))))

;;(with-sound (:srate 44100 :statistics #t) (sawtooth 0 4 .3 330))

(definstrument (triangle start-time duration amplitude freq)
  (let* ((oscillator (make-triangle-wave freq))
	 (start-sample (floor (* start-time *srate*)))
	 (end-sample (+ start-sample (floor (* duration *srate*)))))
    (do ((index start-sample (+ index 1)))
         ((> index end-sample))
       (outa index (* amplitude (triangle-wave oscillator))))))

;;(with-sound (:srate 44100 :statistics #t) (triangle 0 4 .3 330))

(definstrument (square start-time duration amplitude freq)
  (let* ((oscillator (make-square-wave freq))
	 (start-sample (floor (* start-time *srate*)))
	 (end-sample (+ start-sample (floor (* duration *srate*)))))
    (do ((index start-sample (+ index 1)))
         ((> index end-sample))
       (outa index (* amplitude (square-wave oscillator))))))

;;(with-sound (:srate 44100 :statistics #t) (square 0 4 .3 330))


(definstrument (pulse start-time duration amplitude freq)
  (let* ((oscillator (make-pulse-train freq))
	 (start-sample (floor (* start-time *srate*)))
	 (end-sample (+ start-sample (floor (* duration *srate*)))))
    (do ((index start-sample (+ index 1)))
         ((> index end-sample))
       (outa index (* amplitude (pulse-train oscillator))))))

;;(with-sound (:srate 44100 :statistics #t) (pulse 0 4 .7 33))


		 

