# Env.circle Glitch?

Hi there -
I’ve run into a small snag with the envelope generating - I was hoping someone could help me. Maybe I’m missing something, but…

This works fine…

{ SinOsc.ar(EnvGen.kr(Env.circle([0, 1, 0], [0.01, 0.5, 0.2])) * 440 + 200) * 0.2 }.play;


This doesn’t work…(does not loop)

~x = Env.circle([0, 1, 0], [0.01, 0.5, 0.2]);
{ SinOsc.ar(EnvGen.kr(~x) * 440 + 200) * 0.2 }.play;


I’m curious to know what causes that discrepancy, as perhaps my understanding of envelopes is flawed. Thank you.

Depends what you are trying to achieve but I have been advised to make a Synth instead of manipulating Enveloppes this way.

Something about the clock when playing not synching with the tempo

	SynthDef(\gate,{|in, out=0, vlAtk=0, vlDec=1,vlSub=0, vlRel=0, atkT=0, decT=1, subsT=0, relT=0, atkC=0, decC=0, relC=0, bus1, bus2, dur,relSu=0,vlSub2=0|
var env =   In.ar(in, 1) *    EnvGen.kr(Env(
[vlAtk,vlDec                  ,vlSub ,vlSub2,vlRel,0],
[dur * atkT ,dur * decT   , dur * subsT,dur* relT],
[atkC,decC ,0     ,relC]),

timeScale:  t.beatDur,	doneAction:2);
Out.ar(out, env);

Pbind(\instrument, \gate ,\in,0  ,\vlDec,1,
\dur,Pseq([1/1],inf) , \out,0,
\vlSub,Pfunc({0.7.exprand(0.4,1)}),\vlSub2,Pkey(\vlSub),\atkT,Pfunc({0.14.exprand(0.01)}),
\decT,Pfunc({0.6.exprand(0.8,0.3)}),
\subsT,Pfunc({0.2.exprand(0.1)}),
\relT,Pfunc({0.22.exprand(0.1,1)}),
\atckC,0,
\decC,Pfunc({(-4).exprand(-0.1)}),
\relC,Pfunc({-8.exprand(-2,1)}),\vlAtk ,Pfunc({1.00.exprand(0.01)}),\vlRel,Pfunc({0.1.exprand(0.01)})).play



Hi @Devon66 - thanks for the advice, but I’m not sure this really directly relates to the problem. I really have no idea why the syntax would impact that Envelope in this way.

It’s hidden from view, but Env.circle creates UGens.

If you save the synth in a variable, you can trace it. (If you don’t save it in a variable, then you can’t do anything with it except stop it by cmd-dot – so IMO it’s a good habit to get into, always to write a = { ... }.play [or a different variable name], and never to write just { ... }.play.)

a = { SinOsc.ar(EnvGen.kr(Env.circle([0, 1, 0], [0.01, 0.5, 0.2])) * 440 + 200) * 0.2 }.play;

a.trace;

unit 0 Impulse
in  0 0
out 0
unit 1 Latch
in  1 0
out 1
unit 2 BinaryOpUGen
in  1 0.2
out 0.2
unit 3 EnvGen
in  1 1 0 1 0 0 4 3 0 0 0.2 1 0 1 0.01 1 0 0 0.5 1 0 0 inf 1 0
out 0.0872093
... etc

a.free;

~x = Env.circle([0, 1, 0], [0.01, 0.5, 0.2]);
a = { SinOsc.ar(EnvGen.kr(~x) * 440 + 200) * 0.2 }.play;

a.trace;

unit 0 EnvGen
in  1 1 0 1 0 0 2 -99 -99 1 0.01 1 0 0 0.5 1 0
out 0
... etc


UGens must be created within the synthesis function, not outside… so Env.circle is not safe to use outside of the function. (It would be worth filing a documentation bug for this – it isn’t mentioned in the help but should be.)

hjh

1 Like