[CM] Working with channels in Snd

Richard Liston liston@cc.gatech.edu
Tue, 16 Mar 2004 18:05:24 -0500


On 03/16/04, Bill Schottstaedt said:
> 
> This is most easily handled via "outb" -- the "outa"
> call in your instrument sends its data to channel 0.
> Then, make sure your output has 2 channels:
> 
> (with-sound (:channels 2) ...)
> 

Great! So that I don't have to separately define instruments
for each channel, I defined scm-simp-fn to take outa or outb
as an arg:

(definstrument
  (scm-simp-fn start-time duration frequency amplitude outfn)
  (let* ((beg (inexact->exact (floor (* start-time (mus-srate)))))
         (dur (inexact->exact (floor (* duration (mus-srate)))))
         (s (make-oscil :frequency frequency)))
    (run
      (lambda ()
        (do ((i 0 (1+ i)))
            ((= i dur))
          (outfn (+ i beg) (* amplitude (oscil s)) *output*))))))

Then I create the sound using with-sound:

(with-sound (:channels 2) 
  (scm-simp-fn 0 3 440 .5 outa)
  (scm-simp-fn 0 3 440 .5 outb))

Now I've got the two channels that I'm looking for. Then I
define these two functions to shape the envelopes:

(define* (rampdown #:optional (chan 0))
  (env-sound (list 0 1 1 0) 0 #t #t #t chan))

(define* (rampup #:optional (chan 0))
  (env-sound (list 0 0 1 1) 0 #t #t #t chan))

Then (rampdown 0) and (rampup 1) create the stereo effect.

Fun stuff...
Richard