;;; -*- syntax: common-lisp; package: clm; base: 10; mode: lisp -*-
;;;
;;; plot a sine
;;; s-rate is the number of points (samples) to plot per cycle
;;; to use with EnvEd
(defun simp-sine-plot (amplitude frequency duration &optional (phase 0)(s-rate 10.0))
(loop for i from 0 by (/ 1 (* frequency s-rate)) to duration do
(format t "~4,4f ~4,4f " i (* amplitude (sin (+ (* 2 pi frequency i) phase))))))
;;; playing a sine from "pure" Lisp
(defun simp (start-time duration frequency amplitude)
(let* ((beg (floor (* start-time sampling-rate)))
(end (+ beg (floor (* duration sampling-rate)))))
(loop for i from beg to end and j from 0 by 1 do
(outa i (* amplitude (sin (* j two-pi (/ frequency sampling-rate))))))))
;;; playing a sine with a CLM oscillator
(definstrument simp-clm (start-time duration frequency amplitude)
(multiple-value-bind (beg end) (get-beg-end start-time duration)
(let ((s (make-oscil :frequency frequency)))
(run
(loop for i from beg to end do
(outa i (* amplitude (oscil s))))))))
;;; playing a sine with a CLM oscillator and envelope
(definstrument simp-clm-env (start-time duration frequency amplitude
&optional (amp-env '(0 0 50 1 100 0)))
(multiple-value-bind (beg end) (get-beg-end start-time duration)
(let ((s (make-oscil :frequency frequency))
(amp (make-env :envelope amp-env :scaler amplitude)))
(run
(loop for i from beg to end do
(outa i (* (env amp) (oscil s))))))))