Calculate window rate with unknown trigger frequency

hey, in the following code i calculate the windowRate by tFreq / overlap:

(
{
	var tFreq = \tFreq.kr(100);
	var trig = Impulse.ar(tFreq);

	var windowRate = tFreq / \overlap.kr(1);
	var windowPhase = Sweep.ar(trig, windowRate);

	IEnvGen.ar(Env([0, 1, 0], [0.5, 0.5], \sin), windowPhase);

}.plot(0.01);
)

would it be possible to receive triggers via In.ar and “calculate” the window rate with an unknown trigger frequency:

(
{
	var trig = In.ar(\in.kr(0), 1);

	var windowRate = ???;
	var windowPhase = Sweep.ar(trig, windowRate);

	IEnvGen.ar(Env([0, 1, 0], [0.5, 0.5], \sin), windowPhase);

}.plot(0.01);
)

i guess not, but maybe there is a workaround. if you have one let me know :slight_smile:

If the triggers are relatively steady, then you can measure the time between triggers. Frequency is then 1/time. You may need some sort of smoothing function on the times, to absorb minor timing jitter.

If the trigger timing fluctuates wildly, then an estimate of the rate wouldn’t be useful. But if the triggers are generated by another synth in SC, using Impulse, then the measurements should be precise.

hjh

hey, thanks.
i would modulate the trigger frequency of Impulse by an LFO and mask the triggers with binary sequences before sending them to the source synth, so im not sure.
Its not a big deal to just place everything in the source SynthDef but i thought it would be possible to separate these two things from each other, especially the demand trigger masking, which is a whole thing on its own.

i have made one attempt with OffsetOut and InFeedback to route the triggers from the source synth to the trigger masking synth and back to the source synth, which is working.
But beside the binary masking sequence for example [1, 0, 0, 1, 0, 0, 1, 0] im also calculating the corresponding legato values [3, 3, 2] to scale the windowRate / Envelope, which has to be done in the source Synthdef.
Im not really happy with that solution atm. The routing would be more straight forward if it could be trigger synth → filter triggers by masking function → source synth or just keep everything in the same SynthDef i guess, which has the downside that the trigger mask cannot be a function.

I’m sure there are techniques to infer the greatest common divisor of the measured times (even within some degree of error tolerance) – e.g. if you’re measuring 0.2 sec and 0.3 sec (in arbitrary order and arbitrary repeats) then the rhythmic base would evidently be 0.1 sec.

However, doing this in the server isn’t a high priority problem for me, so you’d have to do your own research on that.

If you are simultaneously modulating trigger rate and omitting arbitrary pulses, then it sounds like an exceptionally difficult problem, requiring a level of pattern matching analysis that is well beyond my level. (One thought: Can you, by ear, identify the underlying pulses if many are omitted and the rate is modulating? If not, how do you expect the machine to do it?) I think you would need one of these to be steady – either a constant trigger rate, or a steady stream of pulses.

hjh

thanks for evaluating the problem.
I think there is no easy solution and the whole thing is already complicated enough, so i will keep everything in the source SynthDef.