Say I have a an instrument like
(definst sinewave [freq 220] (sin-osc freq))
And I start it up using
(def sound (sinewave))
So it starts making a 220 Hz sound.
Now, some arbitrary amount of time later I want to change it to be at some
other arbitrary frequency; let's say 440 Hz. Normally I could just do
(ctl sound :freq 440)
and it would switch to 440 Hz.
However, I want to be fancy about it and make it slide up to that frequency
over the course of a second or so.
The intuitive thing for me to do at this point, given my current limited
knowledge of how this all works, is to pass a line ugen to the control
function. My reasoning goes like this: I can pass a line ugen to sin-osc
in a definst, and freq is just what gets passed to sin-osc, so I should be
able to use ctl to pass a line ugen to sin-osc by using the :freq
parameter, like so:
(ctl :freq (line:ar 220 440 1))
But when I try to do that, I get an exception:
Failed attempting to send an OSC message to SuperCollider server. Reason:
incorrect arglist type in OSC message /n_set. Expected a float representing
a control value found class overtone.sc.machinery.ugen.sc_ugen.SCUGen.
Message name: /n_set Type sig: [:node-id
:ALTERNATING-ctl-handle-THEN-ctl-val*] Arg list: (52 "freq" #<sc-ugen:
So that's no good, apparently because of something to do with how
SuperCollider works (control messages can only be to non-changing float
So what _is_ the idiomatic way to slide from one frequency to another in an
instrument that is already playing? Is there an "easy" way to do that, or
do you have to kind of kludge it with something like:
(definst sliding-sine [start-freq 0 end-freq 220 slide-duration 1]
(sin-osc (line:ar start-freq end-freq slide-duration)))
(def slider (atom (sliding-sine)))
(at (+ (now) 1000) (do (kill @slider) (reset! slider (sliding-sine 440 330
[apologies if g-mail destroys the formatting...]
This does mostly do what I want it to, except there's a faint 'pop' when it
kills the first sound and starts the second, which is fine for just fooling
around but I wouldn't want it in anything final.