But, the better way to do what I think you’re trying to do (evil grin) is to pass the Envelope as an argument to the Synth:
(
SynthDef(\tick, {
var sig, env;
env = \env.kr(Env.perc().asArray); // Make a synth parameter out of an Env array....
env = EnvGen.kr(env, gate: \gate.kr(1)); // Make sure to EnvGen it.
sig = WhiteNoise.ar;
Out.ar(
\out.kr(0),
sig * env * [1, 1]
);
}).add;
Pdef(\ticks, Pbind(
\instrument, \tick,
\legato, 1,
\dur, Prand([1/4, 1/3, 1, 1.5], inf),
\env, Prand([
`(Env.perc(curve: -9)), // default
`(Env.perc(0.9, 0.01, 1, curve: 9)) // long atttack
], inf)
)).play
)
The two gotchas here:
When you specify an Env().asArray as the default value of a synth arg, that’s the maximum size of the envelope you can pass - if you pass an envelope that has more values than that, you’ll definitely break something. Usually, you can stick with Env.perc or Env.adsr and just make sure you pass variations of that envelope, which should be the same size - or, allocate a really large envelope with Env.newClear(8).
If you want to pass envelopes to a synth inside a pattern, as I did in my example, you have to wrap them in an extra pair of square braces: [Env.perc()] . If you don’t do this, the Event / pattern systems can get confused and not send them correctly.
In this case, wasn’t the buffer supposed to have a duration of 1.001 seconds since the default argument values are Env.perc(attackTime: 0.01, releaseTime: 1.0, level: 1.0, curve: -4.0) ?
After running ~b.duration I am getting 0.023219954648526…
after checking the doc I’ve seen that the .discretize(n: 1024) undocumented method accepts the size, so it is setting the buffer to this value of samples
That’s expected and correct behavior. Discretizing an envelope preserves the time ratios of the segments, and scales them onto the given number of samples.