If you have a square wave of which you know the amplitude and period, can't you just create the triangle wave from that using simple geometry?

Triangle wave - HandWiki[^]

If the rise start point of the TW is synced with the rise of the SW, then all you are doing is drawing the diagonal from BL to TR, then TL to BR which is trivial and should be fast and space efficient.

If the sync is "stepped" as per the diagram in the link, then that's just an offset start point you need to cater for - again simple geometry.

15,797,923 members

Square wave: +1 +1 +1 +1 +1 -1 -1 -1 -1 -1 +1 +1 +1 +1 +1 -1 -1 -1 -1 -1 ....

Running sum: +1 +2 +3 +4 +5 +4 +3 +2 +1 +0 +1 +2 +3 +4 +5 +4 +3 +2 +1 +0 ....

Shift and scale to your taste...

If we assume that it is easier to generate a triangle signal from a symmetrical square wave signal, you would have to sample the signal with a fairly exact timing. You need a lot of information about the signal to be sampled. Latencies and other effects occur as a result of the sampling and the calculation.

I then use that delta to increment my phase between 0 and TWO_PI by delta each time, generating a sort of sawtooth that I apply f=sin(phase) to to get my wav. The *only* reason I can't generate that as a triangle given what I know how to do is because the phase is a saw rather than cycling up and down and up and down. But the sin *does* cycle up and down, so I was hoping I could use that. My square wave is just f = phase>PI; So I don't know. I want to get a triangle by deriving one of those.