The following example shows that the envelope buffer’s contents are definitely respected – even changing mid-grain.
I guess the problem is that you’ve hard-coded a bufnum for z into the synth, but then you change the bufnum by doing Buffer.sendCollection, and you never informed the synth of the new bufnum.
s.boot;
(
fork {
var cond = CondVar.new;
b = Buffer.alloc(s, 0.025 * s.sampleRate, 1);
c = Buffer.alloc(s, 2 * s.sampleRate, 1, completionMessage: { |buf| buf.fillMsg(0, buf.numFrames, 1) });
z = Buffer.alloc(s, 512, 1);
SynthDef(\test, {
var frames = BufFrames.kr(c);
var trig = Impulse.ar(1 / 0.005);
var dur = 0.005;
var sig = GrainBuf.ar(
1, trig, dur,
c, 1,
Phasor.ar(0, 1, 0, frames) / frames,
4,
envbufnum: z
);
RecordBuf.ar(sig, b, run: 1, loop: 0, doneAction: 2);
}).add;
s.sync;
z.setn(0, Env([0, 1, 0], [0.1, 0.9], -4).discretize(z.numFrames));
s.bind { a = Synth(\test) };
0.0125.wait;
s.bind { z.setn(0, Env([0, 1, 0], [0.9, 0.1], -4).discretize(z.numFrames)) };
a.onFree { cond.signalAll };
cond.wait;
fork {
b.getToFloatArray(0, -1, -1, 5, { |data|
defer { data.plot };
cond.signalAll;
});
};
cond.wait;
b.free;
c.free;
z.free;
};
)
Indeed that seems to be assumed. But… the grain’s duration is fully specified by dur
. What would be the point of having a dur
argument if the envelope could override it?
Also note the behavior of discretize: the Env object’s duration is lost at this point. You only have an array of some size, but there is no concrete relationship between the array size and the Env duration. You could discretize to a different size and this would not encode anything about the Env duration.
hjh