Parameterizing Env for buffer initialization

Dear Supercollider community,

I’m struggling with creating an Env from a SynthDef's args. I can’t imagine this wouldn’t be possible in terms of code reuse. I would preferably like to encapsulate the wavetable, buffer, and Shaper from my previous post inside the SynthDef function. However, when I use simple arithmetic with the args I pass to the Synthdef I keep getting the following error:

ERROR: Primitive '_ArrayEnvAt' failed.
Wrong type.

Here is the code in which I try to do this:

(\parameterized_buffer, {
  var env, sig, envBuffer;
  env = Env(
    levels: [0 - envAmp, 0.0, envAmp],
    times: [1, 1],
    curve: [envCurve, 0 - envCurve],

  envBuffer = Buffer.loadCollection(s, env);

  sig =;, sig);

Thank you in advance!

loadCollection is a language-side operation and can’t be used in a SynthDef.

You’ll have to prepare the buffers from the language side before calling Synth().