## Dumb question – Sawtooth to triangle

Apr 29, 2009 at 1:16pm

# Dumb question – Sawtooth to triangle

Maths scares me! How can i convert a sawtooth wave into a triangle. I can do sawtooth to sine but cant suss out traingle. Driving me mad.

Also any ideas on some good reading on this sort of mathmatics.

Thx.

#43584
Apr 29, 2009 at 3:30pm

If math scares you then think of it visually or analytically! To make a sawtooth wave look the same as a triangle wave, you would take the latter half of the sawtooth wave and flip it down, so that the wave ramps up and then ramps down, instead of the long ramp and then the jump down to “0″ that a sawtooth wave does.

Here’s a patch that explains it in simple terms, albeit the process is slow and impractical:

– Pasted Max Patch, click to expand. –
#156372
Apr 29, 2009 at 6:29pm

Love the patch, Thx. I was trying to achieve it with just math which was hurting my head. The split object made perfect sense as soon as I saw it.

Any chance I could get some guidance on making a square wave from phasor or saw. Obviously its a case of detecting mid point of a wave, Im pretty new to all this so implementing is hard without experience.

Its more involved then I thought? Thx for help.

#156373
Apr 29, 2009 at 7:30pm

Another option would be to just take the absolute value of a saw wave from -1 to 1 with [abs~] to get a triangle wave that goes from 0 to 1. Using the split this way is actually a pretty awful idea if you’re doing anything with MSP, because you’re essentially downsampling from 44.1khz to below 1khz when you snapshot the values like that… and I’m not sure there’s a single MSP object that will provide that split function (though all I did to check was try to make a [split~]…)

– Pasted Max Patch, click to expand. –
#156374
Apr 29, 2009 at 7:47pm

I missed your question about square waves the first time around. You’re right about detecting the midpoint of a wave, and in this case, [greaterthan~] is your friend. When you give it a signal, it outputs 1 for true and 0 for false. Given an oscillating signal as an input and the average of said signal as the argument, it’ll output a nice periodic square wave.

– Pasted Max Patch, click to expand. –
#156375
Apr 30, 2009 at 11:51am

But you know there are also antialiased tri~ and rect~ objects, works without math…
And if you want to go seemless from saw to triangle have a look at triangle~…

You can sync them with a phasor~…

Stefan

#156376
Apr 30, 2009 at 2:20pm

[quote title=Bryan Dodson wrote on Wed, 29 April 2009 21:30]and I’m not sure there’s a single MSP object that will provide that split function (though all I did to check was try to make a [split~]…)

[> 0.5]

(if you use > or >= will not matter when the 0.5 will
be the 0. later!)

#156377
Apr 30, 2009 at 4:26pm

Right, but what I was saying is that no single object would split the signal. [>] will only give you a 0 or 1, and must be combined with a routing object as part of a sidechain in order to split the signal.

#156378
Apr 30, 2009 at 6:33pm

right right, as you can see i thought about non
signal, probably the coffee level was not high enough.

i also use my custom split~, btw.

#156379
May 1, 2009 at 3:17am
 MadBeat wrote on Wed, 29 April 2009 08:16 Maths scares me! How can i convert a sawtooth wave into a triangle. I can do sawtooth to sine but cant suss out traingle. Driving me mad.

A non-math way to work with this is to use [table] with its line tool to draw the shapes, then put into buffer~ with peek~. You could also use multislider with (say) 512 sliders and draw whatever wave you want, then use [pattr] to interpolate between them, which might give you some interesting new waves to play with. And of course you can just draw into waveform~ with the pencil, though there’s no direct way to interpolate.

jit.buffer~ also might give you some ideas, since you can use cool stuff like jit.xfade between two, or run it through other “video” effects, which could create some interesting new shapes you might not otherwise think of.

but math is also fun.

#156380

You must be logged in to reply to this topic.