Forums > MaxMSP

Dumb question – Sawtooth to triangle

April 29, 2009 | 1:16 pm

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.



Eli
April 29, 2009 | 3:30 pm

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. –

April 29, 2009 | 6:29 pm

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.


April 29, 2009 | 7:30 pm

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. –

April 29, 2009 | 7:47 pm

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. –

April 30, 2009 | 11:51 am

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


April 30, 2009 | 2:20 pm

[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!)


April 30, 2009 | 4:26 pm

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.


April 30, 2009 | 6:33 pm

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. Smile


May 1, 2009 | 3:17 am
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.


Viewing 10 posts - 1 through 10 (of 10 total)