Event overlapping when using Pbind

Hi!

I would like to use a Pbind to control a sequence of events. I am aware of the asynchronicity between the server and client, but would it be possible for these events not to overlap?
I do not need extremely fast succession of events in general. The problem I have happens even with very slow dur values.
I posted an example of SynthDef with an envelope and a buffer whose values are constantly 1. In the example you can hear clicks because of the overlapping. Would it be possible for the succession of events happen smoothly? so that the output value is constantly at 1

thank you!!

(
var samplesize=2.pow(11);
v=Env.new(levels: [1,1,1,1,1], times: [0.25,0.25,0.25,0.25], curve:[10,10,10,10]).asSignal(samplesize);
n=Buffer.alloc(s,samplesize,1,bufnum:10);
n.loadCollection(v );
)

(
SynthDef(\test,{
	|
	t_trig=1,
	freq
	|
	var env=Env.new(levels: [ 1, 1, 1, 1,1 ], times: [0.25,0.25,0.25,0.25], curve:[-5, 0, 5,1]);
	var envGen=EnvGen.ar(env, gate: t_trig, levelScale: 1.0, levelBias: 0.0, timeScale: 1/freq, doneAction: 0);
	var play= BufRd.ar(1,10,Phasor.ar(Impulse.ar(1/freq),freq*(2048/Server.default.sampleRate),0,2040,0),1,4);
	var release= Line.ar(0,1,1/freq,doneAction: 2);
	var output=	Out.ar(0,	[play,envGen]);
}).add;
)

(
Pdef(\one,
	Pbind(
		\instrument, \test,
		\freq,Pseq([Pseq([100,200,100],100),Pseq([10,20,5],10)],inf),
		\t_trig,Pseq([1],inf),
		\dur, 1/Pkey(\freq)
	)
).play;
)


1 Like

I don’t think I fully understand what you’re trying to do with the buffer and the envelope you’re loading into it. Can you use Pmono or PmonoArtic? It would be helpful to know what these events are.

If you want a Synth that outputs a constant value of 1, you can do this, but I don’t think this is going to help you reach your goal:

(
	SynthDef(\one, {
		var sig = DC.ar(1.0);
		Out.ar(\out.kr(0), sig);
	}).add;
)

Note that this could, and probably should, just as well be all Control Rate ugens. If your goal is to test the effects of DC output on a set of speakers, this is perfect, but I’m not sure it’s helpful for anything else.

Hi mjsyts!

Thank you for your answer.
Well in this example I just want to illustrate the problem with the overlapment of the events. The clicks that are audible are because of this, if the events did not overlap no sound would be audible since the output would be at a constant value of 1. If you change the wavetable that is loaded in the buffer you would just hear an oscilator playing but with the overlaps of events, so the sound is not as if the oscilator would play normaly.

Would there be a way to fix this?

thank you!

That makes sense. If I’m following you correctly, there are a few ways to do this.

  1. Use PmonoArtic and use \legato, 1, whenever you want the Pbind to change a parameter without releasing the envelope, so it doesn’t spawn new synths. It just sets the parameters of the one that’s already there, so there’s no gap in the sound. Like this (note that I offset the channels by 12 so it wouldn’t play DC offset through my speakers):
(
    SynthDef(\one, {
        var sig = DC.ar(1.0);
        var env = Env.asr(0.001, 1.0, 0.001).kr(2); //this basically just frees the synth. it isn't affecting amplitude
        Poll.kr(Impulse.kr(0), sig, "Synth added"); //tells us when a new Synth is created
        Out.ar(\out.kr(12), sig);
    }).add;
)


(
    PmonoArtic(
        \one,
        \dur, 0.25,
        \out, 12,
        \legato, Pseq([1.0, 1.0, 1.0, 0.5, 0.5, 0.5], inf), //isn't making new synths while legato is 1
        \out, 12,
    ).play;

    s.scope(1, 12);
)
  1. You can use Ndef and crossfade to get smooth transitions. This is from the Ndef help file:
Ndef(\a).play; // play to hardware output.
Ndef(\a).fadeTime = 2; // fadeTime specifies crossfade
// set the source
Ndef(\a, { SinOsc.ar([350, 351.3], 0, 0.2) });
Ndef(\a, { Pulse.ar([350, 351.3] / 4, 0.4, 0.2) });
Ndef(\a, Pbind(\dur, 0.03, \freq, Pbrown(0, 1, 0.1, inf).linexp(0, 1, 200, 350)));

Ndef(\a, { Ringz.ar(Ndef.ar(\b), [350, 351.3] * 2, 0.4) });
Ndef(\b, { Impulse.ar([5, 7]/2, [0, 0.5], 0.15) });

Ndef.clear(3); // clear all after 3 seconds
  1. You could use Synth.set in a routine and then set the parameters you want to change instead of freeing the Synth and making a new one with the new parameters.

  2. You could send all the Synths you don’t want to overlap to a group and then use doneAction 13, which will free everything in that group so you’ll only ever have one Synth in the group.

I think PmonoArtic is probably going to be what you’re after.

Hey!

thnx so much for all this info!!
I believe PmonoArtic is the best solution yet!

Legato 1, works best, the only problem I get now is that the Env does not get retriggered in each event. It only triggers once at the start. With legato 0.9 or even 0.9999 works almost as I would like to but still has every now and then some gaps that cause clipping. Is there a way to retriger the envelope when in Legato 1?
I have posted below an example. If the envelope can get retrigered with Legato 1, most of my problems will have been solved especially when the Synthdef I am working on starts to become a bit more complex.

thank you!

(
SynthDef(\test,{|lvls=#[ 1, 1, 1, 1,1 ],dur|
	var trigg=Impulse.kr(1/dur);
	var envM=Env.new(levels: lvls, times: [0.25,0.25,0.25,0.25], curve:[-5, 0, 5,1]);
	var envGenM=EnvGen.ar(envM, gate: trigg, levelScale: 1.0, levelBias: 0.0, timeScale: dur, doneAction: 0);
	var output=	Out.ar(0,	(envGenM!2));
}).add;
)

(
Pdef(\onee,
PmonoArtic(
	\test,
	\args, #[lvls],
	\lvls,Pseq([[[ 1, 0.5, 0.5, 0.5,0.5 ]]],inf),
	\t_trig,Pseq([1],inf),
	\freq,Pseq([Pseq([10,20,10,20],inf)],inf)*10, 
	\dur, 1/Pkey(\freq),
	\legato, 1
)).play
)


1 Like

You could add an additional trigger rate variable which will always be set to 1 during each event like this

(
SynthDef(\test, {
	var dur = \dur.kr(1.0);
	var sig = SinOscFB.ar(
		\freq.kr(100.0),
		feedback: Env([0, 1, 0], [dur/2, dur/2],).kr(
			doneAction: Done.freeSelf,
			gate: \myTrig.tr(1.0),
		)
	) * \amp.kr(0.2);
	OffsetOut.ar(\out.kr(0), sig.dup);
}).add;
)

(
Pdef(\foo, PmonoArtic(\test,
	\dur, 1.0,
	\legato, 1.0,
	\myTrig, 1.0,
)).play
)

I am glad I did not have my system blasted at full volume or was wearing head phones when I tested your example:) Please don’t write synthdefs that output a constant of 1 to the main bus, total speaker killers with the DC offset, not good for headphones or ears either. You can try and scope the signal with s.freqscope and s.scope to see what I am talking about.

It is not clear to me what you are trying to obtain, from your description it sounds very straight forward. Wether you use a normal pbind or a pmonoArtic it is easy to control wether notes overlap or not.

Thank you, this seems to work now with the trigger!!
Don’t understand why it did not work with the trigger I had in my example though…

I would like to ask one more thing. I want to pass the output through a bus that is controlled by an other PmonoArtic

(
SynthDef(\test,{
	|
	out=0,dur
	|
	var envelope=Env.new(levels: [1,1,0], times: [0.5,0.5], curve:-5);
	var envGen=EnvGen.ar(envelope, gate: \myTrig.tr(1.0), levelScale: 1.0, levelBias: 0.0, timeScale: dur, doneAction: 0).clip(-1,1.0);
	var sig= SinOsc.ar(1000)*0.2;
	var output=OffsetOut.ar(out,sig*envGen);
}).add;


SynthDef(\busout,{
	|
in,out
	|
	var output,inSig = In.ar(in,2);
	output=	OffsetOut.ar(out,inSig);
}).add;
)


(
~a = Bus.audio(s, 2);
)



the problem I have now it that when the legato on the source sound Stynth is 1 no sound is audible, and when i put anything less than 1, sound is audible

(// with legato less than 1 there is sound 
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test,
		\myTrig,Pseq([1],inf), 
		\out, Pseq([~a],inf),
		\dur, 0.01,
		\legato, 0.999, 
		//\legato, 1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)


(// with legato 1 no sound
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test,
		\myTrig,Pseq([1],inf), 
		\out, Pseq([~a],inf),
		\dur, 0.01,
		\legato, 1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)

if a put legato 1 and the output directly to 0, there is sound

(// with legato 1 and output not through bus sound is audible
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test,
		\myTrig,Pseq([1],inf), 
		\out, Pseq([0],inf),
		\dur, 0.01,
		\legato, 1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)

Is there a way the bus routing would work with legato set at 1?

and one more thing, why when I play the synths very fast while having legato 1 the envelopes stop working and when legato is less than 1, they work fine?

(
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test,
		\myTrig,Pseq([1],inf), 
		\out, Pseq([0],inf),
		\dur, 0.001,   //for times less that 0.01  and legato 1 no sound is audible, 
		\legato, 1, 
		
	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)

(
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test,
		\myTrig,Pseq([1],inf), 
		\out, Pseq([0],inf),
		\dur, 0.01,   //for times less that 0.01  and legato 1 no sound is audible, 
		\legato, 1, 
		
	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)

(
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test,
		\myTrig,Pseq([1],inf), 
		\out, Pseq([0],inf),
		//\dur, 0.001,
		\dur, 0.001,   //for times less that 0.01  and legato less than 1 sound is audible,  
		\legato, 0.9999
	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)

thank you for all the help!

Hi Thor_Madsen!

Well I am fully aware about the DC offset and how it looks at the scope. Sorry for the example above, just wanted to illustrate my problem. Here I just have narrowed down my issues so I dont post too much information that is not relevant. I need those signals for some stuff I want to do later in the definition.

I also understand that my problem is very straight forward and dont understand why I am having this issue, but as you can see from the example I posted at the beggining, despite the signal beeing at constantly at 1 the clicks you here are because the synths overlap and I do not understand why.

with PmonoArtic the problem seems to correct itself with leggato 0.9999 but not completely, since with legato less than 1 there is some spacing between events.
Basicaly if there is a way to make the first example I posted with the events that overlap not to overlap I would be really happy! I understand that what I try to achieve might not be evident because the defs I post are extremely narrowed down to illustrate the problems.

thank you again

Pmono and PmonoAritc are special cases of patterns where gate values are only sent when needed unlike a normal Pbind which will send gate 0 and gate 1 for each note. This means that if the legato is equal to 1, no gate information is sent, since the Pmono is reusing the node, like if you had a synth with doneAction = 0 and used \type, \set messages. If you need something to trigger on every note or event produced by Pmono or PmonoArtic regardless of the legato value, use an arg NOT named ‘gate’, could be ‘gate2’ or anything you like.

Is it important to use a pattern to control the \busout synth? If it is an fx type synth, you instantiate it once and make sure it is downstream from you first Pmono by using groups. You could still use a pattern with \type, \set to control the \busout synth if needed.

So Pmono and PmonoArtic are much more complex than a normal Pbind. To illustrate:

(
Pdef(\test,
	Pbind(
		\midinote, Pseq([50, 55, 60], inf),
		\c, Pfunc{|ev| ev.postln}
)).play
)
(
Pdef(\test,
	Pmono(
		\default,
		\midinote, Pseq([50, 55, 60], inf),
		\c, Pfunc{|ev| ev.postln}
)).play
)
Pdef(\test).clear;

In cases where you don’t specifically need the functionality of a Pmono or PmonoArtic (usually the portamento effect of setting legato to 1), I would just use a normal Pbind. As I wrote earlier, you can have total control over note duration in either case and avoid overlapping notes if needed.

Thank you for all this info, its been really helpfull!

I think that Pmono or PmonoArtic are really helpfull in my case because of the legato. It is really helpfull because I want the synth to be able to operate without releasing itself, but sometimes because I use a few envelopes on the signal, the envelopes very often get desync (they do not start at the same time) they have slight imperfections in timing, so with legato less than 1 somehow this gets resolved because the synth is created new each time.

So I guess now I have 2 questions which would be really helpfull if answered.

  1. On the example I posted above, by having “\myTrig” (similar to what you suggested to name ‘gate2’) even with legato 1, indeed the triger is sent to the synth, so the envelopes get trigered on each event, so that is sorted. What I cannot understand is why when the “dur” of each event is less than 0.01 and closer to 0.001 why while having legato 1, the envelopes are not triggered, and when I place a legato value less than 1 with “dur” 0.001 the envelopes are triggered normally. So why do the envelopes work normally for both legato 1 and legato <1 but when the duration becomes smaller than 0.01 the envelopes stop working for legato=1 and continue to work when legato<1?

  2. Ideally for me yes I need to control the \busout synth with patterns. From the above example I posted, I think the problem is not on the \busout synth, since the \busout synth works fine even with legato 1 or less. The sound disappears when legato=1 for the source synth \test and the strange thing is that if I put the out of the \test synth 0 I hear the sound normally. Any thoughts on why this happens?

thank you in advance!!

Can you post your code in a minimal example showing the problems, synthdefs included?

Hey! sorry for the late reply, I was just trying to narrow things down in a meaningful way but tbh the narrowed down versions are more or less what I have previously posted but with some variations for clarity. For some reasons although all the insights in Pbind and PmonoArtic were very helpfull to understand things, I still do not know how to resolve the issues I am having. I am posting a bit more refined examples now that illustrate the 3 issues I am having.

Basically the whole discussion started because of Pbind events overlaping and then went to PmonoArtic, which was usefull because of the legato.

here is a wavetable and a synthdef to play it

(
var samplesize=2.pow(11);
v=Env.new(levels: [1,0], times: [0.25], curve:[-10]).asSignal(samplesize);
n=Buffer.alloc(s,samplesize,1,bufnum:4);
n.loadCollection(v );
)

(
SynthDef(\test1,{
	|
	dur
	|
	var trig= Impulse.ar(1/dur);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur).poll  * (2048/Server.default.sampleRate)),trig,0,1).clip(-1,1);
	var output=OffsetOut.ar(0,playbuf!2);

}).add;
)

  1. If you see the .poll numbers they should be in a sequence of 50,100,200.
    With legato 1 something strange happens which I believe messes up with the stuff I do later.
    It behaves similar as if there is a Prand instead of Pseq
//see poll numbers should be 50,100,200,50,100,200,50,100,200 but they are not
(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
		\legato,1, 
	)
).play.reset;
)

//poll numbers are in right sequence but gaps between events are big

(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
		\legato,0.8, 
	)
).play.reset;
)

//poll numbers are in right sequence but events overlap

(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
		\legato,0.99999, 
	)
).play.reset;
)
  1. If I use Pbind, it works well but there is the event overlap (something similar with the PmonoArtic with legato 0.9)
//works ok but events overlap
(
SynthDef(\test2,{
	|
	dur
	|
	var trig= Impulse.ar(1/dur);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur).poll  * (2048/Server.default.sampleRate)),trig,0,1,0).clip(-1,1);
	var release= Line.kr(0,1,dur,doneAction: 2);
	var output=OffsetOut.ar(0,	playbuf!2);

}).add;
)

(
Pdef(\t,
	Pbind(
		\instrument,\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
	)
).play.reset;
)
  1. The 3rd problem I have is that of routing. Ineed to control parameters with patterns on the bussynth

Here are the synthdefs

(
SynthDef(\test2,{
	|
	out=0,dur
	|
	var trig= Impulse.ar(1/dur);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur).poll  * (2048/Server.default.sampleRate)),trig,0,1,0).clip(-1,1);
	var output=OffsetOut.ar(out,playbuf);
}).add;


SynthDef(\busout,{
	|
in,out
	|
	var output,inSig = In.ar(in,2);
	output=	OffsetOut.ar(out,inSig);
}).add;
)


(
~a = Bus.audio(s, 2);
)

here are the problems:

(// with legato 1 there is no sound

Pdef(\ttt,Ppar([
	PmonoArtic(
		\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([~a],inf),
		\dur, 1/Pkey(\freq),
		\legato,1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)

(// if i change the ruting directly  to 0 and not use the bus there is normal sound

Pdef(\ttt,Ppar([
	PmonoArtic(
		\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([0],inf),
		\dur, 1/Pkey(\freq),
		\legato,1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)



(// with legato less than 1 there is sound  through the bus
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([~a],inf),
		\dur, 1/Pkey(\freq),
		\legato,0.8, 
		//\legato, 1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)


(// with legato 9 events overlap
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([~a],inf),
		\dur, 1/Pkey(\freq),
		\legato,0.9, 
		//\legato, 1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)

3b) here is the routing problem when using Pbind. You can listen to sound being not continuous

(
SynthDef(\test3,{
	|
	out=0,dur
	|
	var trig= Impulse.ar(1/dur);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur).poll  * (2048/Server.default.sampleRate)),trig,0,1,0).clip(-1,1);
	var release= Line.kr(0,1,dur,doneAction: 2);
	var output=OffsetOut.ar(out,playbuf);
}).add;


SynthDef(\busout2,{
	|
in,out,dur
	|
	var output,inSig = In.ar(in,2);
	var release= Line.kr(0,1,dur,doneAction: 2);
	output=	OffsetOut.ar(out,inSig);
	
}).add;
)
(
Pdef(\ttt,Ppar([
	Pbind(
		\instrument,\test3,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([~a],inf),
		\dur, 1/Pkey(\freq)
	),
	Pbind(
		\instrument,\busout2,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1
	)]
)
).play.reset;
)

I hope these examples will illustrate the issues I am having. Any help would be extremely important.
Thank you again and sorry for the late reply, I just had to put things down.

Hey! sorry for the late reply, I was just trying to narrow things down in a meaningful way but tbh the narrowed down versions are more or less what I have previously posted but with some variations for clarity. For some reasons although all the insights in Pbind and PmonoArtic were very helpfull to understand things, I still do not know how to resolve the issues I am having. I am posting a bit more refined examples now that illustrate the 3 issues I am having.

Basically the whole discussion started because of Pbind events overlaping and then went to PmonoArtic, which was usefull because of the legato.

here is a wavetable and a synthdef to play it

(
var samplesize=2.pow(11);
v=Env.new(levels: [1,0], times: [0.25], curve:[-10]).asSignal(samplesize);
n=Buffer.alloc(s,samplesize,1,bufnum:4);
n.loadCollection(v );
)

(
SynthDef(\test1,{
	|
	dur
	|
	var trig= Impulse.ar(1/dur);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur).poll  * (2048/Server.default.sampleRate)),trig,0,1).clip(-1,1);
	var output=OffsetOut.ar(0,playbuf!2);

}).add;
)
  1. If you see the .poll numbers they should be in a sequence of 50,100,200.
    With legato 1 something strange happens which I believe messes up with the stuff I do later.
    It behaves similar as if there is a Prand instead of Pseq
//see poll numbers should be 50,100,200,50,100,200,50,100,200 but they are not
(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
		\legato,1, 
	)
).play.reset;
)

//poll numbers are in right sequence but gaps between events are big

(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
		\legato,0.8, 
	)
).play.reset;
)

//poll numbers are in right sequence but events overlap

(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
		\legato,0.99999, 
	)
).play.reset;
)
  1. If I use Pbind, it works well but there is the event overlap (something similar with the PmonoArtic with legato 0.9)
//works ok but events overlap
(
SynthDef(\test2,{
	|
	dur
	|
	var trig= Impulse.ar(1/dur);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur).poll  * (2048/Server.default.sampleRate)),trig,0,1,0).clip(-1,1);
	var release= Line.kr(0,1,dur,doneAction: 2);
	var output=OffsetOut.ar(0,	playbuf!2);

}).add;
)

(
Pdef(\t,
	Pbind(
		\instrument,\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
	)
).play.reset;
)

  1. The 3rd problem I have is that of routing. Ineed to control parameters with patterns on the bussynth

Here are the synthdefs

(
SynthDef(\test2,{
	|
	out=0,dur
	|
	var trig= Impulse.ar(1/dur);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur).poll  * (2048/Server.default.sampleRate)),trig,0,1,0).clip(-1,1);
	var output=OffsetOut.ar(out,playbuf);
}).add;


SynthDef(\busout,{
	|
in,out
	|
	var output,inSig = In.ar(in,2);
	output=	OffsetOut.ar(out,inSig);
}).add;
)


(
~a = Bus.audio(s, 2);
)

here are the problems:

(// with legato 1 there is no sound

Pdef(\ttt,Ppar([
	PmonoArtic(
		\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([~a],inf),
		\dur, 1/Pkey(\freq),
		\legato,1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)

(// if i change the ruting directly  to 0 and not use the bus there is normal sound

Pdef(\ttt,Ppar([
	PmonoArtic(
		\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([0],inf),
		\dur, 1/Pkey(\freq),
		\legato,1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)



(// with legato less than 1 there is sound  through the bus
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([~a],inf),
		\dur, 1/Pkey(\freq),
		\legato,0.8, 
		//\legato, 1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)


(// with legato 9 events overlap
Pdef(\ttt,Ppar([
	PmonoArtic(
		\test2,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([~a],inf),
		\dur, 1/Pkey(\freq),
		\legato,0.9, 
		//\legato, 1, 

	),
	PmonoArtic(
		\busout,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1,
		\legato, 1
	)]
)
).play.reset;
)

3b) here is the routing problem when using Pbind. You can listen to sound being not continuous

(
SynthDef(\test3,{
	|
	out=0,dur
	|
	var trig= Impulse.ar(1/dur);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur).poll  * (2048/Server.default.sampleRate)),trig,0,1,0).clip(-1,1);
	var release= Line.kr(0,1,dur,doneAction: 2);
	var output=OffsetOut.ar(out,playbuf);
}).add;


SynthDef(\busout2,{
	|
in,out,dur
	|
	var output,inSig = In.ar(in,2);
	var release= Line.kr(0,1,dur,doneAction: 2);
	output=	OffsetOut.ar(out,inSig);
	
}).add;
)
(
Pdef(\ttt,Ppar([
	Pbind(
		\instrument,\test3,
		\freq,Pseq([5,10,20],inf)*10,
		\out,Pseq([~a],inf),
		\dur, 1/Pkey(\freq)
	),
	Pbind(
		\instrument,\busout2,
		\in,Pseq([~a],inf),
		\out, Pseq([0],inf),
		\dur,1
	)]
)
).play.reset;
)

I hope these examples will illustrate the issues I am having. Any help would be extremely important.
Thank you again and sorry for the late reply, I just had to put things down.

The first problems comes from naming the arg ‘dur’, since the name ‘dur’ is a ‘reserved name’ and has a special meaning for patterns. Try renaming the dur to ie. dur2 in the synthdef:

(
SynthDef(\test1,{
	|
	dur2
	|
	var trig= Impulse.ar(1/dur2);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur2).poll  * (2048/Server.default.sampleRate)),trig,0,1).clip(-1,1);
	var output=OffsetOut.ar(0,playbuf!2);

}).add;
)

// check the polling
(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
		\dur2, 1/Pkey(\freq),
		\legato,1, 
	)
).play.reset;
)

The polling looks swapped at places, but I think this has to do with the extremely short durations, the shortest being 1/200 = 5 ms, the longes being 1/50 = 50 ms. Polling by default happens 10 times per second = 100 ms and communication between language and server is bound by the blockSize (defaults to 64 samples = (64/s.sampleRate * 1000) ms). So between two adjacent polling values, a lot of stuff has happened which you can’t see from polling

A better way is to plot the signal or plot the dur2.

I will look at the other problems later, but it all might be clearer with this fix

If you slow the pattern down and use trace inside the pattern instead of poll in the synth it is easier to inspect:

(
SynthDef(\test1,{
	|
	dur2
	|
	var trig= Impulse.ar(1/dur2);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur2)  * (2048/Server.default.sampleRate)),trig,0,1).clip(-1,1);
	var output=OffsetOut.ar(0,playbuf!2);
	Silence.ar
}).add;
)

// check the polling
(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		// \dur, Pkey(\freq),
		\dur, 0.25,
		\dur2, Pkey(\freq).trace,
		\legato,1, 
	)
).play.reset;
)

Actually I am not sure if the renaming of the dur arg is needed, maybe it is just a polling issue…

hey! thnx for your reply!

Yes I do not think the dur was the problem as well. I understand what you said about the polling and makes sense, but still I find the signal not being “stable”

By playing the same duration the signal should sound as if it doesn’t change. You can hear what I am saying when legato is 0.8, the signal sounds stable. When legato is 1, it sounds as if there is a modulation in the signal and this is really audible.

if you see the waveform the first hit should last for 0.02 sec, the second one 0.01 sec and third 0.005sec
Indeed if you measure the182053 recording that has legato 0.8, the timing is right.

If you measure the above 181802 recording, the hits you get are 0.016 sec, then 0.008 sec and then 0.013 sec, which is really off. If you measure the rest hits on the 181802 rec, there are always inconsistencies which result in the the audible modulation when legato is 1.

The recordings were from the below definition


(
SynthDef(\test1,{
	|
	dur2
	|
	var trig= Impulse.ar(1/dur2);
	var playbuf= PlayBuf.ar(1,4,  ((1/dur2).poll  * (2048/Server.default.sampleRate)),trig,0,1).clip(-1,1);
	var output=OffsetOut.ar(0,playbuf!2);

}).add;
)


(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
		\dur2, 1/Pkey(\freq).trace,
		\legato,1, 
	)
).play.reset;
)


(
Pdef(\t,
	PmonoArtic(
		\test1,
		\freq,Pseq([5,10,20],inf)*10,
		\dur, 1/Pkey(\freq),
		\dur2, 1/Pkey(\freq),
		\legato,0.8, 
	)
).play.reset;
)

You put in buffer number 4, I don’t know what that buffer number refers to. We also might be nearing the depth of my SC knowledge but a couple of general observations:

There is a limit to how precise you can get communication between language and server which is primarily based on the blocksize. With the default blocksize of 64 and the default sampling rate of 44100 hz, the blocksize amounts to 64/44100 = 1.5 ms, so the clock jitter will be in the same neighborhood. Since you are dealing with extremely short durations times, this will cause problems. To really know you got it working like you want, I would first test the design with demand ugens running at audio rate with some preset sequences, ie. no communication between language and server after initiating the synth(s). Setting synth args has the same blocksize-limits as patterns. Alternatively you could set SC to blocksize to 1, but still there would have to be some delay before values are received by the synth, whereas demand ugens at audio rate will be sample accurate.

When legato is set to 1 the freq is lag’ed by some amount, I wonder if other keys are also lag’ed which could explain the difference in timing. In any case, the lag time is much longer than you longest dur time so the lag will never end, but multiple lags will be stacked (I think) in the same way as if you keep re-triggering and env before it has ended. I still am not really sure what you are aiming sound-wise but I have a feeling you should try to approach it from a different angle than using patterns with durations of 5, 10 and 20 ms.