(
SynthDef(“kick2”, {
var sub = SinOsc.ar(ExpRand(58, 62.0));
sub = sub * Env.perc(0.1, 3).ar;
var snd = Pan2.ar(sub).distort;
Out.ar(0, snd);
}).add;
)
and I can’t seem to get my around to why.
By rewriting the line with Env.perc as
(
SynthDef(“kick2”, {
var sub = SinOsc.ar(ExpRand(58, 62.0));
var subenv = sub * Env.perc(0.1, 3).ar;
var snd = Pan2.ar(snd).distort;
Out.ar(0, snd);
}).add;
)
The error disappears. However it seems that assigning a variable holding
audio signals to itself is valid, as the following works fine:
(
SynthDef(“kick2”, {
var test = SinOsc.ar();
test = test * 0.1;
}).add;
)
What is my misconception here? Thanks for all pointers!
best, Peter
Unlike C++, you cannot declare a variable this way. They must be declared at the beginning. After introducing other expressions, the language does not allow you to declare new variables. In this case var snd should come before sub =.
Strange, my neither Bruno Ruviaro nor Eli Fieldsteel mention this
explicitely in their excellent introductory textbooks.
So one could summarize:
In an environment there might be any number of lines starting with var
declarations, but they all have to be at the beginning of the code before
other lines/expressions.
Strange the interpreter doesn’t allow this, but I am sure there is a
good reason for it.