Forums > MaxMSP

sin-to-saw function (max 4.6)

December 17, 2008 | 9:03 pm

Hello,

I’m trying to create an envelope that interpolates smoothly between a sin wave (domain between 0 – π) to a reversed sawtooth shape (same domain). However my math skills are not quite up to snuff here… I’ve gotten the sin shape, but turning it into a sawtooth is proving a little difficult. Help?

Thanks!

Here’s what I have…

max v2;
#N vpatcher 10 59 750 547;
#P window setfont "Sans Serif" 9.;
#P number 298 100 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P message 10 133 33 196617 set 0;
#P message 10 112 33 196617 clear;
#P newex 196 208 51 196617 pack 0 0.;
#P message 409 85 73 196617 setrange 0. 1.;
#P newex 196 183 32 196617 * 20;
#N counter;
#X flags 0 0;
#P newobj 196 163 66 196617 counter;
#P toggle 196 122 15 0;
#P newex 196 141 52 196617 metro 20;
#P newex 213 64 93 196617 prepend setdomain;
#P newex 244 183 64 196617 speedlim 20;
#P user function 333 135 533 235 1 1 0 0;
#X frgb 82 82 82;
#X brgb 204 204 204;
#X rgb2 85 85 85;
#X rgb3 255 255 255;
#X rgb4 0 0 0;
#X rgb5 0 0 0;
#X add 0. 0.020942 0;
#X add 20. 0.041876 0;
#X add 40. 0.062791 0;
#X add 60. 0.083678 0;
#X add 80. 0.104528 0;
#X add 100. 0.125333 0;
#X add 120. 0.146083 0;
#X add 140. 0.166769 0;
#X add 160. 0.187381 0;
#X add 180. 0.207912 0;
#X add 200. 0.228351 0;
#X add 220. 0.24869 0;
#X add 240. 0.26892 0;
#X add 260. 0.289032 0;
#X add 280. 0.309017 0;
#X add 300. 0.328867 0;
#X add 320. 0.348572 0;
#X add 340. 0.368125 0;
#X add 360. 0.387516 0;
#X add 380. 0.406737 0;
#X add 400. 0.425779 0;
#X add 420. 0.444635 0;
#X add 440. 0.463296 0;
#X add 460. 0.481754 0;
#X add 480. 0.5 0;
#X add 500. 0.518027 0;
#X add 520. 0.535827 0;
#X add 540. 0.553392 0;
#X add 560. 0.570714 0;
#X add 580. 0.587785 0;
#X add 600. 0.604599 0;
#X add 620. 0.621148 0;
#X add 640. 0.637424 0;
#X add 660. 0.653421 0;
#X add 680. 0.669131 0;
#X add 700. 0.684547 0;
#X add 720. 0.699663 0;
#X add 740. 0.714473 0;
#X add 760. 0.728969 0;
#X add 780. 0.743145 0;
#X add 800. 0.756995 0;
#X add 820. 0.770513 0;
#X add 840. 0.783693 0;
#X add 860. 0.79653 0;
#X add 880. 0.809017 0;
#X add 900. 0.821149 0;
#X add 920. 0.832921 0;
#X add 940. 0.844328 0;
#X add 960. 0.855364 0;
#X add 980. 0.866025 0;
#X add 1000. 0.876307 0;
#X add 1020. 0.886204 0;
#X add 1040. 0.895712 0;
#X add 1060. 0.904827 0;
#X add 1080. 0.913545 0;
#X add 1100. 0.921863 0;
#X add 1120. 0.929777 0;
#X add 1140. 0.937282 0;
#X add 1160. 0.944376 0;
#X add 1180. 0.951057 0;
#X add 1200. 0.957319 0;
#X add 1220. 0.963163 0;
#X add 1240. 0.968583 0;
#X add 1260. 0.973579 0;
#X add 1280. 0.978148 0;
#X add 1300. 0.982287 0;
#X add 1320. 0.985996 0;
#X add 1340. 0.989272 0;
#X add 1360. 0.992115 0;
#X add 1380. 0.994522 0;
#X add 1400. 0.996493 0;
#X add 1420. 0.998027 0;
#X add 1440. 0.999123 0;
#X add 1460. 0.999781 0;
#X add 1480. 1. 0;
#X add 1500. 0.999781 0;
#X add 1520. 0.999123 0;
#X add 1540. 0.998027 0;
#X add 1560. 0.996493 0;
#X add 1580. 0.994522 0;
#X add 1600. 0.992115 0;
#X add 1620. 0.989272 0;
#X add 1640. 0.985996 0;
#X add 1660. 0.982287 0;
#X add 1680. 0.978148 0;
#X add 1700. 0.973579 0;
#X add 1720. 0.968583 0;
#X add 1740. 0.963163 0;
#X add 1760. 0.957319 0;
#X add 1780. 0.951056 0;
#X add 1800. 0.944376 0;
#X add 1820. 0.937282 0;
#X add 1840. 0.929776 0;
#X add 1860. 0.921863 0;
#X add 1880. 0.913545 0;
#X add 1900. 0.904827 0;
#X add 1920. 0.895712 0;
#X add 1940. 0.886203 0;
#X add 1960. 0.876307 0;
#X add 1980. 0.866025 0;
#X add 2000. 0.855364 0;
#X add 2020. 0.844328 0;
#X add 2040. 0.832921 0;
#X add 2060. 0.821149 0;
#X add 2080. 0.809017 0;
#X add 2100. 0.79653 0;
#X add 2120. 0.783693 0;
#X add 2140. 0.770513 0;
#X add 2160. 0.756995 0;
#X add 2180. 0.743145 0;
#X add 2200. 0.728968 0;
#X add 2220. 0.714473 0;
#X add 2240. 0.699663 0;
#X add 2260. 0.684547 0;
#X add 2280. 0.66913 0;
#X add 2300. 0.65342 0;
#X add 2320. 0.637424 0;
#X add 2340. 0.621148 0;
#X add 2360. 0.604599 0;
#X add 2380. 0.587785 0;
#X add 2400. 0.570713 0;
#X add 2420. 0.553391 0;
#X add 2440. 0.535827 0;
#X add 2460. 0.518027 0;
#X add 2480. 0.5 0;
#X add 2500. 0.481753 0;
#X add 2520. 0.463296 0;
#X add 2540. 0.444635 0;
#X add 2560. 0.425779 0;
#X add 2580. 0.406736 0;
#X add 2600. 0.387515 0;
#X add 2620. 0.368124 0;
#X add 2640. 0.348572 0;
#X add 2660. 0.328866 0;
#X add 2680. 0.309017 0;
#X add 2700. 0.289031 0;
#X add 2720. 0.26892 0;
#X add 2740. 0.24869 0;
#X add 2760. 0.22835 0;
#X add 2780. 0.207911 0;
#X add 2800. 0.187381 0;
#X add 2820. 0.166768 0;
#X add 2840. 0.146083 0;
#X add 2860. 0.125333 0;
#X add 2880. 0.104528 0;
#X add 2900. 0.083677 0;
#X add 2920. 0.06279 0;
#X add 2940. 0.041875 0;
#X add 2960. 0.020942 0;
#X domain 3000.;
#X range 0. 1.;
#X done;
#P outlet 67 211 15 0;
#P inlet 11 10 15 0;
#P inlet 122 25 15 0;
#P newex 122 66 62 196617 prepend set;
#P button 11 31 15 0;
#P newex 212 30 52 196617 t b 3000.;
#P newex 212 10 48 196617 loadbang;
#P flonum 122 48 52 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 11 56 56 196617 first-bang;
#P newex 107 148 33 196617 t b b;
#P message 87 86 50 196617 3000.;
#P button 87 67 15 0;
#P message 11 86 55 196617 3.141593;
#P message 67 86 17 196617 0.;
#P flonum 67 185 68 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 67 154 21 196617 sin;
#P newex 67 126 50 196617 line 0. 0.;
#P connect 8 0 26 0;
#P connect 8 0 27 0;
#P connect 15 0 12 0;
#P connect 12 0 8 0;
#P connect 8 0 4 0;
#P connect 7 0 8 1;
#P connect 7 1 3 0;
#P connect 4 0 0 0;
#P connect 3 0 0 0;
#P connect 0 0 1 0;
#P connect 1 0 2 0;
#P connect 2 0 16 0;
#P connect 4 0 5 0;
#P connect 13 0 6 0;
#P connect 11 0 6 0;
#P connect 5 0 6 0;
#P connect 6 0 0 1;
#P connect 0 1 7 0;
#P connect 14 0 9 0;
#P connect 11 1 9 0;
#P connect 9 0 13 0;
#P connect 8 0 21 0;
#P connect 7 0 21 0;
#P connect 21 0 20 0;
#P connect 27 0 22 0;
#P connect 20 0 22 0;
#P connect 22 0 23 0;
#P connect 23 0 25 0;
#P connect 10 0 11 0;
#P connect 9 0 19 0;
#P connect 18 0 25 1;
#P connect 28 0 20 1;
#P connect 2 0 18 0;
#P connect 28 0 18 1;
#P hidden connect 26 0 17 0;
#P hidden connect 25 0 17 0;
#P connect 24 0 17 0;
#P connect 19 0 17 0;
#P connect 10 0 24 0;
#P pop;


December 17, 2008 | 9:18 pm

Have a look at the [kink~] help file. It does something similar to what you’re looking for. Otherwise you could use [uzi 256] and [expr] for the sine wave and [scale] for the sawtooth to generate a list and then pattr to morph between the two. The [multislider] object is good to display the waves and you can [peek~] them into a [buffer~].

I hope this helps.

lh


December 17, 2008 | 9:28 pm

See also 2dwave~. There was a nice patch posted some time ago that
interpolates between various wave shapes with 2dwave~ – try searching the
list archives for it, or if you can’t find it, I’ll try to dig it out
tomorrow,
Cheers
Roger

On 17/12/2008 21:18, "Luke"

wrote:

>
> Have a look at the [kink~] help file. It does something similar to what you’re
> looking for. Otherwise you could use [uzi 256] and [expr] for the sine wave
> and [scale] for the sawtooth to generate a list and then pattr to morph
> between the two. The [multislider] object is good to display the waves and you
> can [peek~] them into a [buffer~].
>
> I hope this helps.
>
> lh


December 17, 2008 | 9:54 pm

Thanks for the replies. I’ve tried looking for the 2dwave~ patch, I think I found it but it appears that 2dwave~ is a jitter object (which I don’t have). I’ll check to make sure. Right now I’m looking into using [uzi] and [expr] and the CNMAT object [list-interpolate]. I think this might work…

Thanks again,

John


December 17, 2008 | 10:05 pm

2dwave~ is a straightforward MSP object, as shown by the ‘~’ (Jitter objects
all start ‘jit.’), so you should have it,
Cheers
Roger

On 17/12/2008 21:54, "John Tamm-Buckle" wrote:

>
> Thanks for the replies. I’ve tried looking for the 2dwave~ patch, I think I
> found it but it appears that 2dwave~ is a jitter object (which I don’t have).
> I’ll check to make sure. Right now I’m looking into using [uzi] and [expr]
> and the CNMAT object [list-interpolate]. I think this might work…
>
> Thanks again,
>
> John



Eli
December 17, 2008 | 11:01 pm

I made this patch a long long time ago, it’s not really what you’re looking for, but it’s fun to play around with!

Eli


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