[CM] generators
James Hearon
j_hearon at hotmail.com
Mon Dec 11 15:26:49 PST 2017
Hi,
I've been using the generators in generators.scm for a while, and enjoy making sound with them, but for the life of me I cannot seem to understand how they work. I'm confused about the lambda part and the use of fm. What is fm doing? I'd be grateful if someone could explain that.
Such as in nxycos, It seems like (set! angle (+ angle fm frequency)) is critical, but is (+ angle fm frequency), simply the sum of those variables, such as (+ 3 1 2), > 6? Or does the fm part contribute to the radians value of angle in some other way in that bit of code. I've tried using display and formatted output to look at output values such as x, y, den, angle in radians in lambda, but nothing is really making sense to me yet. I've also experimented with input of different values and viewing the fft outputs to see the frequency in hz, ratio, n, and also angle or phase start in the waveform view of snd.
For ex. if I do something like:
...
(outa i (* .5 (nxycos gen 0.1))))))
such as adding a value for fm, then the frequency really takes off, so I'm not sure I'm understanding what fm does in the generator or how it's supposed to be used.
Thank you,
Jim
(defgenerator (nxycos :make-wrapper convert-frequency)
(frequency 0.0) (ratio 1.0) (n 1) (angle 0.0) fm)
(define nxycos
(let ((+documentation+ "(make-nxycos frequency (ratio 1.0) (n 1)) creates an nxycos generator. (nxycos gen (fm 0.0))
returns n cosines from frequency spaced by frequency * ratio."))
(lambda* (gen (fm 0.0))
(let-set! gen 'fm fm)
(with-let gen
(let* ((x angle)
(y (* x ratio))
(den (sin (* y 0.5))))
(set! angle (+ angle fm frequency))
(if (< (abs den) nearly-zero)
1.0
(/ (* (cos (+ x (* 0.5 (- n 1) y)))
(sin (* 0.5 n y)))
(* n den)))))))) ; n=normalization
#|
(with-sound (:clipped #f :statistics #t :play #t)
(let ((gen (make-nxycos 300 1/3 3)))
(do ((i 0 (+ i 1)))
((= i 20000))
(outa i (* .5 (nxycos gen))))))
|#
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/mailman/private/cmdist/attachments/20171211/154a15c2/attachment.html>
More information about the Cmdist
mailing list