Waveform expressions?

njosnari's icon

Hello, I am trying to create functions for generating waveforms outside of the signal domain using the expr object.
Sine was simple enough to achieve with:
expr sin (2 * 3.14159 * $f1 * 0.05)

I would like to make a square/pulse, triangle, and saw wave with the same method, but am having a difficult time doing so.

Can anyone help me?

Wetterberg's icon

Paging dr. Roman! Paging dr. Roman!

In the meantime, I think I can improve your code there.

Max Patch
Copy patch and select New From Clipboard in Max.

Here's something to get you started:

njosnari's icon

That is fantastic! Thank you very much!!!

Wetterberg's icon

any time - this was fun! :)

Roman Thilenius's icon

(damn, where is the post i just sent?)

@njosnari:
what is your aim? what are the input and output ranges you need?

@wetterberg:expr 5%12 should work, it is just not officially supported.
otherwise use ($f1-int($f1/$f2)*$f2).

njosnari's icon

I'm doing some modulation, and I'm trying to keep it out of the signal domain to conserve some cpu. The input and output ranges aren't so important, mostly they're being kept between 0 and 1 and then scaled to 0 - 4095 before leaving the patch via a DA convertor.