Hello!
I know the result of running synthdef code is static.
But like a following code, I want to control the number of SinOsc with Pbind.
And I have some misc questions as commented below.
(// for sound
SynthDef(\varPolyTest, {
arg n = 30, freq = 300, envdur = 1.0; // setting default value of n occurs "Index not an Integer" error, why?
n = 30; // assigning value of n instead of above line is working, but this way is surely fix the value of n.
var ratio, mixSig, env;
ratio = Array.rand(n, 2.2, 5);
env = EnvGen.kr(Env.sine(envdur), doneAction:2);
mixSig = Mix.fill(n, {|i|
sig = SinOsc.ar(freq * ratio[i], mul:1/n * 0.5);
});
Out.ar(0, mixSig * env!2);
}).add;
)
(// for control
Pbind(
\instrument, \varPolyTest,
\n, Pwhite(5, 20, 1), // arg 'n' doesn't change.
\freq, Pwhite(300, 700, 1),
\envdur, Pwhite(5, 10, 1),
).play
)
I found alternative way of using a Function not a SynthDef.
But It is not possible controlled by Pbind or Pseq isn’t it?
(
~vp = {arg n = 10, freq = 200;
var ratio = Array.rand(n, 2.2, 5);
~sig = Array.newClear(n);
n.do{|i|
~sig[i] = {SinOsc.ar(freq * ratio[i], mul: 1/n * 0.5)}
};
~sig.sum;
};
)
~synthTest = {~vp.value(1 + 10.rand.postln, 200)}.play;
Please share your ideas.
Thanks.