Please proceed with caution if your SC version is below 3.12.
The Pbind
example below gave me extremely loud levels while I used a 3.11 version.
I updated thanks to this thread.
Hi, I’ve started to create my first SynthDefs
, this one seems to work OK when I play it via .play
(sorry for the verbose code, hope this helps me when I try to understand it at some point in the future):
(
SynthDef.new(\xylophone,
{
arg
freq = 440,
amp = 0.1,
duration = 2,
scale = 5,
velocity = 1,
harmonics = #[1, 4, 7, 9, 13];
var
env_volume,
env_harmonics,
signal,
out;
//make higher notes decay shorter
duration = duration*440/freq;
env_volume = XLine.kr(
start: 1,
end: 0.01,
dur: duration,
add: -0.01,
doneAction: Done.freeSelf
);
env_harmonics = XLine.kr(
start: 1,
end: 0.01,
//higher harmonics have shorter decay & lower velocities make envelopes shorter
dur: (duration/((1-scale) + (harmonics*scale)))*velocity,
add: -0.01
);
signal = amp*FSinOsc.ar(
freq: freq*harmonics,
iphase: 0,
mul: velocity*1/harmonics*env_harmonics;
);
signal = Mix.ar(
array: signal
);
signal = signal*env_volume*amp;
signal = Pan2.ar(signal,0);
out = Out.ar(
bus: 0,
channelsArray: signal
);
}
).play;
)
I can now access the synth and change its argument values like this:
x=Synth(\xylophone, [\freq, 200, \amp, 0.5, \velocity, 0.1]);
But when I play it via a Pbind, \velocity
values are not respected, while \amp
values are:
(
Pbind(
\instrument, \xylophone,
\amp, 0.3,
\velocity, 0.1,
\dur, Pseq([0.125,0.125,0.125,0.125,0.25,0.25],10),
\freq,Prand([400,300,400,500,600],inf)
).play;
)
Please, where is my mistake? According to how I understood this page, corresponding names are key to making this work. Why does it work when accessing the Synth via x=Synth(\…
, but not in the Pbind
case? Thanks in advance!