Envelope in a buffer ? How to?

Hello everyone,
I’m trying to figure out how to write an Envelope in a buffer to read it with PlayBuf or similar.

I saw that is possible to discretize an Env

(
e = Env([0, 1, 0.5, 0], [0.1, 0.4, 0.8]);
e.discretize(512).plot;
)

how to write it in a buffer?
Any advice ?

Thank you very much like always

You can use loadCollection to load your envelope into a buffer:

~b = Buffer.loadCollection(s, Env.perc().discretize, action: {
	{ ~b.plot }.defer
})

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:

  1. 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).
  2. 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.
2 Likes

Thank you very much for the reply @scztt
In a way I’m looking for something that can be done like you suggested :wink: