[CM] scheme, snd, cm_patterns.scm

Bill Schottstaedt bil at ccrma.Stanford.EDU
Thu Jul 9 13:33:51 PDT 2015


On the definstrument, I think I'd write it:

(definstrument (examp1 start-time duration frequency amplitude)
  (let* ((beg (seconds->samples start-time))
	 (end (+ beg (seconds->samples duration)))
	 (sine-wave (make-oscil :frequency frequency)))
     (do ((i beg (+ i 1)))
         ((= i end))
       (let ((x (* amplitude (oscil sine-wave))))
	 (outa i x)
	 (outb i x)))))

In the original you're calling the same oscil twice, so you get
a sinewave in each channel at twice the desired frequency.
Also, once the srate is set in with-sound, you don't need to
repeat it.

(with-sound (:output "MyTest.wav" :srate 48000 :channels 2
             :header-type  mus-riff :statistics #t)
  (let ((i 0.0))
    (for-each
     (lambda (b)
       (examp1 i 0.25 b 0.5)
       (set! i (+ i 1.0)))
     bbb)))

The do loop in your example evaluates its body once and quits.



More information about the Cmdist mailing list