[PD] tri function in [expr~]

Derek Holzer macumbista at googlemail.com
Sun Aug 13 18:33:18 CEST 2017


Dear list,

I am transcribing some code from C to Pd expressions, and I am wondering 
how I might best get the tri function working since it's not native to expr.

I have been using this expression as my triangle function:

(min($v1, 1- $v1) - 0.25) * 4

So for this example:

wave_x = .5-triangle((phasor-9/16)/(2/16))*.5;

I have tried the following, which doesn't function correctly compared 
with the original C:

[phasor~ 200]
|
[expr~ ($v1-9./16.)/(2./16.)]
|
[expr~ (0.5 - (min($v1, 1.- $v1) - 0.25) * 4.) * 0.5]
|
[s~ wave_x]

I am quite sure I have made some errors in the syntax somewhere, and I 
did trial-and-error many other combinations before arriving at this one. 
Would someone more math-literate than me care to help work this out?

SIDENOTE: when is it necessary to force expr~ to consider a number as a 
float by using a decimal?

(9/16) doesn't work but (9./16.) does.

((min($v1, 1- $v1) - 0.25) * 4) works regardless of whether the 1 and 
the 4 have a decimal point following them or not.

Thanks much!
Derek




-- 
derek holzer
noise.art.technology
http://macumbista.net



More information about the Pd-list mailing list