Curve type as SynthDef argument


#1

Hi, is there a possibility to change the curve type of an Env inside a SynthDef? Or a solution to get a similar result?

I tried the following, which didn’t work:

SynthDef(\envSound,{ |curveType|
	var sig = SinOsc.ar(300),
	env = Env.linen(1,0,0.01,0.2,curveType),
	envSig = EnvGen.ar(env,doneAction:2);
	Out.ar(0, (sig*envSig)!2);
}).add;

Thanks!


#2

It does work, but without affecting the current segment:

(
x = { |curveType = 0, gate = 1|
	var env, envSig;
	env = Env.linen(0.003, 0, 0.003, 0.2, curveType);
	envSig = EnvGen.ar(env, Impulse.ar(100) * gate);
	Out.ar(0, envSig!2);
}.scope;
)

x.set(\curveType, 5)

x.set(\curveType, -10)

x.release

#3

Alright, however when i try to change the curvature with a symbol such as:

x.set(\curveType, \sine)

it doesn’t seem to work?


#4

The server doesn’t understand symbols. If you want this kind of flexibility consider DemandEnvGen.

If you"re curious you could even do it with Env/EnvGen by using a little trick:
An Env is encoded into an array which you can regard with ‘asArray’.
Check:

Env.linen(0.003, 0, 0.003, 0.2, 7).asArray

-> [ 0, 3, -99, -99, 0.2, 0.003, 5, 7, 0.2, 0, 5, 7, 0, 0.003, 5, 7 ]

You see where the curvature and the curve type (= shape, see e.g. DemandEnvGen help for this convention) are stored.

Rewriting the above example

(
// default shape 5 (exponential curve value)
x = { |curvature = 0, shape = 5, gate = 1|
	var env, envSig;
	env = [
		0, 3, -99, -99, 0.2, 0.003, shape, curvature,
		0.2, 0, 1, 0, 0, 0.003, shape, curvature
	];
	envSig = EnvGen.ar(env, Impulse.ar(100) * gate);
	Out.ar(0, envSig!2);
}.scope;
)

// curvature value
x.set(\curvature, 10)

// sine shape
x.set(\shape, 3)

Attack and release times could also be made to args etc. But this is kind of a hack, DemandEnvGen is more comfortable.


#5
Env.shapeNumber(\sine)
-> 3

Env.shapeNumber(\exp)
-> 2

etc.

hjh


#6

It’s correct that this way you get the numerical encoding of the curve type (shape), but as the example is written, the argument (misleadingly named curveType) only takes over the curvature (‘curve factor’, basically of exponential type). That’s why I recommended DemandEnvGen or passing an array to EnvGen.


#7

That’s true – and, I didn’t say anything to contradict that.

The question was, if you’re using an array in EnvGen, or DemandEnvGen, how do you get from the shape symbol to the number that the server requires? So I answered that question :wink: that’s all.

hjh