[CM] FM how-to question

Bill Schottstaedt bil@ccrma.Stanford.EDU
10 Jun 2003 06:12:31 -0700


> So, I have the following formula:
> cos(2*pi*f*t + f(t)),

There are several ways to do this; for example:

(let* ((pi 3.141592653589793)
       (reader (make-sample-reader 0)) ; modulating signal 
       (osc (make-oscil 440.0 ; or whatever the carrier frequency is
	               (/ pi 2.0)))) 
             ;; cos rather than sin -- probably not important
  (map-channel 
    (lambda (y) 
      (* .5 (oscil osc 0.0 (reader))))))

This overwrites the modulating signal with the FM result. If you'd
rather write to a new temp file,

(load "ws.scm")
(with-sound ()
  (let* ((reader (make-readin "modulating-signal-filename"))
         (len (mus-sound-frames "modulating-signal-filename"))
         (freq (hz->radians 440.0))) ; carrier
    (do ((i 0 (1+ i)))
        ((= i len))
      (outa i (* .5 (cos (+ (* i freq) (readin reader)))) *output*)))))

Or open a blank new file,

(let ((new-snd (open-sound "test.snd"))
      (len (frames modsig))) 
      ;; Snd-style sound index of modulating signal
  (pad-channel 0 frames) ; get some empty space to write to
  ... the rest can follow the first example
  )