I worked with a new UGen class and I found little issue with that approach:
StomperOsc : UGen {
*ar {
arg freq = 440, amp = 0.5, form = 0, distort = 0, noise = 0, gate = 1;
var sig, snoise; // UGen
var rq, freqd; // variables
var env; //Envelop with gate
// rq: 0.0001: presque pur, 1 bruit complet
rq=noise.linlin(0,1,0.0001,1,\minmax);
freqd=freq*(1+LFNoise1.kr(500,distort));
sig = SinOsc.ar(freqd).pow(form.linexp(0,1,1,20,nil));
// amplitude compensation: 1/rq trop peu dans noise = 1, 1/rq.sqrt trop peu dans noise = 0
snoise=Resonz.ar(PinkNoise.ar(1),freqd,rq,2/rq.pow(1,5).sqrt);
sig=XFade2.ar(sig,snoise,noise.linlin(0,1,-1,1));
sig = sig * amp * EnvGen.kr(Env.asr(),gate);
^sig;
}
}
And now I can use this new UGen as basis for my Synth/SynthDef:
// -exemple 2: Noise+Distort
// ** define the SynthDef **
(
SynthDef(\s2, {
arg out = 0, // specific
freq= 440, amp= 0.5, form = 0, gate = 1;
var sig = StomperOsc.ar(
freq: freq, form: form, gate: 1, // I force gate = 1 to bypass the default gate and use only the specific one
amp: EnvGen.kr(Env.asr(20,1,10), gate, doneAction: Done.freeSelf) * amp,
noise: LFNoise0.kr(LFNoise0.kr(10).range(0.25,2)).range(0,0.8),
distort: LFNoise0.kr(LFNoise0.kr(10).range(0.25,2)).range(0,0.8),
);
Out.ar(out, sig);
}).add;
)
// ** play **
( r = Routine(
{ ~s2=Synth.new(\s2,args: [\out,1]);})
.play(SystemClock);
)
~s2.set(\freq,320);
~s2.release;