Ramp to slope abstraction

hey, i have made an attempt to translate the ramp2slope abstraction from the gen~ book to SC:

(
var rampToSlope = { |phase|
	//var delta = HPZ1.ar(phase) * 2;
	var delta = Slope.ar(phase) * SampleDur.ir;
	delta.wrap(-0.5, 0.5) * SampleRate.ir;
};

var rampDiv = { |phase, scale|
	var slope = rampToSlope.(phase);
	Phasor.ar(DC.ar(0), slope / scale * SampleDur.ir);
};

{
	var plotScale = 400;
	var bpm = 120 * plotScale;
	var clockRate = bpm / 60;
	var beatsPerMeasure = 4;
	var measurePhaseRate = clockRate / beatsPerMeasure;
	var measureScale = 2;

	//var barPhase = (Phasor.ar(DC.ar(0), measurePhaseRate * SampleDur.ir) - SampleDur.ir).wrap(0, 1);
	var barPhase = LFSaw.ar(measurePhaseRate, 1).linlin(-1, 1, 0, 1);
	var divPhase = rampDiv.(barPhase, measureScale);
	[barPhase, divPhase];
}.plot(0.021);
)

grafik

Not sure if i should use Slope or HPZ1 here, they seem to have the same result when beeing scaled.

The slope of my attempt is a bit unstable even when the main Phasor is not modulated, would you think this is the same with the gen~ approach or something binded to Slope / HPZ1 ?

when the target slope for example is 8.0, i get:

UGen(BinaryOpUGen): 7.99084
UGen(BinaryOpUGen): 7.99609
UGen(BinaryOpUGen): 8.01187
UGen(BinaryOpUGen): 8.01187
UGen(BinaryOpUGen): 8.01187
UGen(BinaryOpUGen): 8.00135
UGen(BinaryOpUGen): 7.99084
UGen(BinaryOpUGen): 8.01187
UGen(BinaryOpUGen): 7.96981
UGen(BinaryOpUGen): 7.96981
UGen(BinaryOpUGen): 7.99084
UGen(BinaryOpUGen): 8.03289
UGen(BinaryOpUGen): 7.99084
UGen(BinaryOpUGen): 8.03289
UGen(BinaryOpUGen): 7.99084
UGen(BinaryOpUGen): 7.99609
UGen(BinaryOpUGen): 7.99609
UGen(BinaryOpUGen): 8.01187

Maybe you could scale the rate, get the slope and divide by the scaling factor to be more precise.

The rampDiv abstraction would probably be more precise with a feedback accumulator i guess.


@Sam_Pluta i think its the same here, using Delay1 gives me the same poll values compared to Slope:

var rampToHz = { |phase|
	var history = Delay1.ar(phase);
	var delta = (phase - history);
	delta.wrap(-0.5, 0.5) * SampleRate.ir;
};

still wondering if it would be possible to increase the accurancy by multiplying the phasor rate by a factor first and then dividing after getting the slope.

And also if the sub phasor would be more accurate when using an accumulator instead of a different phasor. The go.ramp.div.gendsp patch seems quite complex.

Slope seems to perform better then HPZ1 or phase - Delay1.ar(phase) for very low rates and LFSaw as a phase input works better for these cases then Phasor.

var rampToSlope = { |phase|
	var delta = Slope.ar(phase) * SampleDur.ir;
	delta.wrap(-0.5, 0.5);
};