# Ramp to trig abstraction

hey, i have worked on some abstractions from the gen~ book. One is this ramp2trig abstraction. Would you think my approach lines up with the gen~ patch?

``````(
var rampToTrig = { |phase|
var difference = HPZ1.ar(phase);
var sum = LPZ1.ar(phase);
var trig = (difference / sum).abs > 0.5;
Trig1.ar(trig, SampleDur.ir);
};

{
var plotScale = 400;
var bpm = 120 * plotScale;
var clockRate = bpm / 60;
var beatsPerMeasure = 4;
var measurePhaseRate = clockRate / beatsPerMeasure;
var stepsPerMeasure = 8;

//var phase = (Phasor.ar(0, measurePhaseRate * SampleDur.ir) - SampleDur.ir).wrap(0, 1);
var phase = LFSaw.ar(measurePhaseRate, 1).linlin(-1, 1, 0, 1);
var trigA = rampToTrig.((phase * stepsPerMeasure).wrap(0, 1));
var trigB = Changed.ar((phase * stepsPerMeasure).ceil);
[phase, trigA, trigB];
}.plot(0.01);
)
``````

I have also compared it to a Changed / ceil approach, they look the same on the plot. But when being played the wrapping of the phase when using `rampToTrig` seems to drift away from the master Phasor and the `Changed / ceil` approach more precise. Does this make any sense? But probably I have spent too much time with this and cant hear it anymore…
Problem with the Changed / ceil approach is, you cant get triggers from a ramp when you dont multiply the phase by some ramp division. I thought of one universal ramp to trig function.

`Changed` with rhythm:

`Changed` with regular pulse:

`Changed` with bpm synced ratchets:

rampToTrig with rhythm:

ramptToTrig with regular pulse:

rampToTrig with bpm synced ratchets:

And one additional question: is there a way to start a `Phasor` exactly at the same phase like `LFSaw.ar(freq, 1).linlin(-1, 1, 0, 1)`, otherwise you dont get the initial trigger at the start, and dont want to add Impulse.ar(0);

Why not just do this:

``````var rampToTrig = { |phase|
var last = Delay1.ar(phase);
Trig1.ar(((phase-last)/(phase+last)).abs>0.5, SampleDur.ir)
};
``````

Seems like it is exactly the same code.

Sam

wonderful, i should think more with `Delay1` when working with these single sample stuff would you also know how to offset the phase of a Phasor to start at an equal phase compared to `LFSaw.ar(freq, 1).linlin(-1, 1, 0, 1)` and keep the phase relationship? I would like to be able to reset the main phasor and the rampToTrig function nicely gives an initial trigger when using the LFSaw approach, to trigger Demand Ugens.

when using `(Phasor.ar(reset, rate * SampleDur.ir) - SampleDur.ir).wrap(0, 1);` instead, the trigger is too late to trigger Demand Ugens.