Forums > MaxMSP

math/expr for ease in and ease out

January 22, 2006 | 10:52 pm

Hi Maxlist,

I’m trying to create some patches which (using line) numerically ease in, ease out, and ease in and out (like a window). It doesn’t really matter what kind/range of numbers. I’ve tried a few things with Table and Buffer, but was hoping to figure out a way to do it all within an expr. I also wanted to avoid using a signal in MSP. I’ve gotten it to work fairly well using sin/cos, but was curious if there was a better way to do it. I haven’t been able to figure out a good way to do both an ease in and ease out (i.e. easing out from 1 and going to 100 and easing in to 100).

Here’s what I’ve accomplished so far (seeing this will make more sense):

max v2;
#N vpatcher 75 54 810 447;
#P user dial 316 198 40 40 100 1 0 0 159 270 1 1. 170 170 170 221 221 221 120 120 120 225 225 225 0 0 0 0 0 0;
#P user dial 21 203 40 40 100 1 0 0 159 270 1 1. 170 170 170 221 221 221 120 120 120 225 225 225 0 0 0 0 0 0;
#P window setfont "Sans Serif" 9.;
#P flonum 316 176 287 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 316 71 62 196617 mousefilter;
#P newex 316 92 40 196617 t b i i;
#P newex 316 155 217 196617 expr ((cos($f1/63.6666))* ($f3-$f2)) + $f2;
#P newex 522 135 39 196617 bucket;
#P number 316 52 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 316 134 40 196617 line;
#P message 316 115 68 196617 0 , 100 3000;
#P comment 316 37 100 196617 ease in;
#P flonum 21 177 287 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 21 72 62 196617 mousefilter;
#P newex 21 93 40 196617 t b i i;
#P newex 21 157 209 196617 expr ((sin($f1/63.666))* ($f2-$f3)) + $f3;
#P newex 219 134 39 196617 bucket;
#P number 21 53 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 21 135 40 196617 line;
#P message 21 116 68 196617 0 , 100 3000;
#P comment 21 38 100 196617 ease out;
#P connect 3 0 7 0;
#P connect 7 0 6 0;
#P connect 6 0 1 0;
#P connect 1 0 2 0;
#P connect 2 0 5 0;
#P connect 5 0 8 0;
#P connect 8 0 18 0;
#P fasten 6 1 5 1 41 113 125 113;
#P fasten 6 2 4 0 56 113 224 113;
#P connect 4 0 5 2;
#P connect 12 0 16 0;
#P connect 16 0 15 0;
#P connect 15 0 10 0;
#P connect 10 0 11 0;
#P connect 11 0 14 0;
#P connect 14 0 17 0;
#P connect 17 0 19 0;
#P fasten 15 1 14 1 336 112 424 112;
#P fasten 15 2 13 0 351 112 527 112;
#P connect 13 0 14 2;
#P pop;

I would greatly appreciate any suggestions.

Thanks!

http://www.bartwoodstrup.com


January 23, 2006 | 12:18 am

Hi Bart
try this

max v2;
#N vpatcher 10 59 870 614;
#P window setfont "Sans Serif" 9.;
#P window linecount 2;
#P comment 337 130 100 196617 Exponential base , must be above 1.;
#P window setfont Arial 12.;
#P flonum 295 128 35 12 0 0 0 2001 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 3;
#P comment 42 44 100 131137548 this version spares the bucket ….;
#P user dial 180 206 40 40 100 1 0 0 159 270 1 1. 170 170 170 221 221
221 120 120 120 225 225 225 0 0 0 0 0 0;
#P window setfont "Sans Serif" 9.;
#P flonum 180 184 287 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 180 79 62 196617 mousefilter;
#P newex 180 100 20 196617 t b;
#P newex 180 163 129 196617 scale 0. 100. 0. 100. 1.06;
#P number 180 60 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 180 142 40 196617 line;
#P message 180 123 68 196617 0 , 100 3000;
#P comment 180 45 100 196617 ease in;
#P connect 3 0 6 0;
#P connect 6 0 5 0;
#P connect 5 0 1 0;
#P connect 1 0 2 0;
#P connect 2 0 4 0;
#P connect 4 0 7 0;
#P connect 7 0 8 0;
#P connect 10 0 4 5;
#P pop;

Martin~

Dr. Martin Parker
martin.parker@ed.ac.uk
Lecturer – Sound Design
Room G.02 extension 50 2333
Tel: +44(0)131 650 2333
http://sd.caad.ed.ac.uk/

http://ddm.caad.ed.ac.uk/

Postal address
Sound Design
Department of Music
University of Edinburgh
Alison House
Nicolson Square
Edinburgh
EH8 9DF, UK


January 23, 2006 | 1:26 am

On Jan 22, 2006, at 5:51 PM, vodstrup wrote:

> Hi Maxlist,
>
> I’m trying to create some patches which (using line) numerically
> ease in, ease out, and ease in and out (like a window). It doesn’t
> really matter what kind/range of numbers. I’ve tried a few things
> with Table and Buffer, but was hoping to figure out a way to do it
> all within an expr.

If you’re trying do windowing entirely with an expr, what you want to
do is assume the input is in the range 0 to 1. You can create a
number that moves repeatedly from 0 to 1 with the line object. Just
run that through an expr, and you’re all set.

Below is an example of how to use just a line and expr object to
create hann (aka hanning), hamming, and triangle windows without MSP
objects. As you can see, it is quite easy.

Formulas for many window types are available here:

http://en.wikipedia.org/wiki/Window_function

- John

max v2;
#N vpatcher 10 59 714 443;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 245 50 48 196617 loadbang;
#P comment 517 328 47 196617 Triangle;
#P user multiSlider 445 229 196 92 0. 1. 1 3193 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P flonum 495 203 57 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 495 174 118 196617 expr abs($f1 – 0.5) * 2;
#P comment 307 327 50 196617 Hamming;
#P user multiSlider 245 229 196 92 0. 1. 1 3193 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P flonum 245 203 57 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 45 203 57 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 45 174 197 196617 expr 0.5 * (1 – cos(2 * 3.14159 * $f1));
#P user multiSlider 45 229 196 92 0. 1. 1 3193 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P newex 245 174 246 196617 expr 0.53836 – 0.46164 * cos(2 * 3.14159
* $f1);
#P message 245 76 56 196617 0 , 1 2000;
#P flonum 245 143 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 245 115 40 196617 line 0.;
#P comment 106 327 76 196617 Hann (Hanning);
#P fasten 2 0 6 0 250 166 50 166;
#P connect 6 0 7 0;
#P connect 7 0 5 0;
#P connect 15 0 3 0;
#P connect 1 1 3 0;
#P connect 3 0 1 0;
#P connect 1 0 2 0;
#P connect 2 0 4 0;
#P connect 4 0 8 0;
#P connect 8 0 9 0;
#P fasten 12 0 13 0 500 223 450 223;
#P fasten 2 0 11 0 250 166 500 166;
#P connect 11 0 12 0;
#P pop;


January 23, 2006 | 1:24 pm

On around Jan 22, 2006, at 23:51, vodstrup said something like:
> I’m trying to create some patches which (using line) numerically ease
> in, ease out, and ease in and out (like a window). It doesn’t really
> matter what kind/range of numbers.

You might want to look at lp.scampf and friends from the Litter Power
Package. Using the symmetry and curve options you can get mappings like
the one below. The lcd at right is generated by the scampf object with
the values shown. You can easily set up arbitrary input and output
ranges with arguments or the four middle inlets.

You won’t get a mathematically exact Hamming window (at least, that’s
not what lp.scampf was designed for), but you can get a wide and wild
variety of ease in/ease out functions.

Lp.scampf is in the Litter Starter Pack (free, see URI below), as is
its integer-producing partner, lp.scampi. Their signal-processing pal,
lp.scamp~, is in Litter Pro.

Here are some more mappings generated with different mapping types
(linear, exponential, power) and curve factors:

(exp 30)
(pow -2)
(lin 14)

Best,
Peter

————– http://www.bek.no/~pcastine/Litter/ ————–
Peter Castine | ^
| Litter Power & Litter Bundle for Jitter
pcastine@gmx.net |
pcastine@bek.no | iCE: Sequencing, Recording, and Interface Building
4-15@kagi.com | for Max/MSP
| Extremely cool
| http://www.dspaudio.com
| http://www.dspaudio.com/software/software.html


January 23, 2006 | 1:47 pm

If you want the ramp to the new value to start and end smoothly here
are two possibilities using tanh and cosine respectively:

Best,
Trond

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 357 197 49 196617 $1 2000;
#P user multiSlider 357 272 169 86 0. 100. 1 3193 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P button 357 132 15 0;
#P newex 357 170 64 196617 random 100;
#N vpatcher 95 230 695 630;
#P outlet 76 359 15 0;
#P window setfont "Sans Serif" 9.;
#P message 356 236 50 196617 3.141593;
#P newex 356 204 62 196617 prepend set;
#P message 356 148 30 196617 bang;
#P newex 356 178 26 196617 tl.pi;
#P inlet 76 49 15 0;
#P window linecount 1;
#P newex 163 144 39 196617 t b f;
#P message 163 117 20 196617 $1;
#P newex 76 244 23 196617 cos;
#P newex 76 306 155 196617 scale 1. -1. 0. 1.;
#P window linecount 3;
#P message 76 117 61 196617 0. , 3.141593 $2;
#P window linecount 1;
#P newex 163 233 27 196617 f;
#P newex 76 214 53 196617 line 0. 20;
#P connect 7 0 2 0;
#P connect 2 0 0 0;
#P connect 0 0 4 0;
#P connect 4 0 3 0;
#P connect 3 0 12 0;
#P connect 7 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 1 0;
#P connect 1 0 3 3;
#P fasten 3 0 1 1 81 339 274 339 274 213 185 213;
#P connect 6 1 3 4;
#P connect 9 0 8 0;
#P connect 8 0 10 0;
#P connect 10 0 11 0;
#P pop;
#P newobj 357 225 60 196617 p sin_ramp;
#P message 169 197 49 196617 $1 2000;
#P user multiSlider 169 272 169 86 0. 100. 1 3193 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P button 169 132 15 0;
#P newex 169 170 64 196617 random 100;
#N vpatcher 95 230 695 630;
#P outlet 76 359 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 0;
#P message 356 236 50 196617 0.986614;
#P newex 356 204 62 196617 prepend set;
#P message 356 148 23 196617 2.5;
#P newex 356 178 29 196617 tanh;
#P inlet 76 49 15 0;
#P window linecount 1;
#P newex 163 144 39 196617 t b f;
#P message 163 117 20 196617 $1;
#P newex 76 244 29 196617 tanh;
#P newex 76 306 158 196617 scale -0.986614 0.986614 0. 1.;
#P message 76 117 67 196617 -2.5 , 2.5 $2;
#P newex 163 233 27 196617 f;
#P newex 76 214 53 196617 line 0. 20;
#P connect 7 0 2 0;
#P connect 2 0 0 0;
#P connect 0 0 4 0;
#P connect 4 0 3 0;
#P connect 3 0 12 0;
#P connect 7 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 1 0;
#P connect 1 0 3 3;
#P fasten 3 0 1 1 81 339 274 339 274 213 185 213;
#P connect 6 1 3 4;
#P connect 9 0 8 0;
#P connect 8 0 10 0;
#P connect 10 0 11 0;
#P pop;
#P newobj 169 225 66 196617 p tanh_ramp;
#P connect 7 0 6 0;
#P connect 5 0 8 0;
#P connect 6 0 9 0;
#P connect 9 0 5 0;
#P connect 4 0 0 0;
#P connect 1 0 4 0;
#P connect 0 0 3 0;
#P connect 2 0 1 0;
#P window clipboard copycount 10;


January 23, 2006 | 9:44 pm

These are all very interesting and helpful – thank you!

Bart


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