# Confusion in Pbind timing

hey I built an example out of a problem i cannot solve
I am trying to use a synth to play a portion of a signal that plays infinitely

dispatch synth is used to segment the never stopping signal (synth blo)
while the synth bli play a sequence over a defined amount of beats

///bpm
t = TempoClock.new(151.703592/60).permanent_(true);

//to pass the infinite signal
~bu = Bus.audio(s,2);

~grp = Group.new;

(
SynthDef(\dispatch2,{|in, out, dur|Out.ar(out, In.ar(in,2)* EnvGen.kr(Env([0,1,1,0],[0,dur,0,0]),doneAction:2))}).add;

SynthDef(\bli, {|out,dur|Out.ar(out,LFPulse.ar(mul: EnvGen.kr(Env([0,0.1,0.1,0],[0,0.1,0,0]),doneAction: 2))!2)}).add;
)

(
Ppar([
Pbind(\instrument,\blo,\out, ~bu, \dur ,99999),

Pseq([ Pbind(\instrument,\bli,\out, 0, \dur ,Pseq([1/1],12)),
Pbind(\instrument,\dispatch2, \dur , Pseq([4/1 ],1) ,\in,~bu,\out,0, \group ,~grp)

],inf)
],1).play(t)
)


dispatch makes blo signal overlaps over the following bli

I can hear the envelope of dispatch is not considering the bpm and keeps playing with the default tempo

please how do you make this work ?

thanks a lot !!

one solution is to divide dur argument from dispatch to get the actual value for 151 bpm

dur/2.3730486223424.

it works, would there be an easier way maybe to get the same result?

thanks

Yes, this is a bit of a gotcha… \dur for events is a measurement of BEATS, not seconds. It just so happens that when tempo == 1, one beat is one second, which makes it very easy to assume they are the same.

One other subtlety here too: \dur is the number of beats between events. \sustain is the duration in beats of a single event. Usually, you want to scale envelopes by \sustain and not \dur, because this reflects how long your event is actually supposed to play - doing it by \dur means your envelope will stop when the next event plays, even if you intended your Events to overlap. I’ll refer to \sustain and not \dur because it’s a little more correct…

You can solve this by calculating the sustain in seconds (\sustainTime) and passing that to your synth:

SynthDef(\dispatch2, {
|in, out, sustainTime|
Out.ar(
out,
In.ar(in,2)
* EnvGen.kr(Env([0,1,1,0],[0,1,0,0]), timeScale: sustainTime, doneAction:2)
)

Pbind(
\instrument, \dispatch2,
\dur, Pseq([4/1], 1),
\sustainTime: { ~sustain.value / (~tempo ?? thisThread.tempo) },
\in, ~bu,
\out, 0,
\group, ~grp
)


The tempo key in Event unfortunately behaves a little badly… it’s nil by default, and the Event playback stuff pulls the tempo from thisThread.tempo in the nil case, so you have to do the same for your key.

2 Likes

allright I suggest to keep putting dur as argument in the envelope and for the timescale 60/bpm, this solution works thanks a lot Scott