Forums > MaxMSP

ElapseGraph

January 21, 2006 | 1:27 am

Hi List,
Recently, a friend of mine asked me about how to graph the envelope of
an audio input over time. This week’s example comprises my answer, a
patch that gives a visual read-out of the signal envelope over a
specified time interval.

This patch is especially useful for those of you who are interested in
using envelope-following to modulate some other parameter, and would
just like to know what kind of data you’re working with. I chose to use
an aesthetic based around the familiar function UI-object.

Besides demonstrating a way to roll your own heart-monitor, it also
shows some techniques for doing simple procedural animation using OpenGL
sketch messages and matrix data.

I hope you all enjoy, and have a great weekend.

Happy Patching!
Andrew B.
Cycling ’74

max v2;
#N vpatcher 377 44 1457 424;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 582 42 32 196617 sel 1;
#P newex 248 296 106 196617 bgcolor 200 220 190;
#P comment 728 32 188 196617 waveform display for envelope tracking;
#P comment 769 79 147 196617 andrewb@cycling74.com;
#P comment 342 193 98 196617 animate recordpoint;
#P message 400 231 22 196617 -1.;
#P newex 400 211 32 196617 sel 0;
#P toggle 441 191 15 0;
#P newex 441 211 29 196617 gate;
#P comment 78 186 74 196617 env. smoothing;
#P comment 153 51 58 196617 length (ms);
#P comment 974 266 75 196617 draw segments;
#P comment 789 250 81 196617 draw startpoint;
#P comment 828 285 71 196617 draw endpoint;
#P comment 865 233 71 196617 draw blue line;
#P newex 459 169 33 196617 -~ 1.;
#P newex 459 149 35 196617 *~ 2.;
#P flonum 146 90 76 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 146 34 60 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 146 69 49 196617 !/ 1000.;
#P message 615 214 319 196617 glcolor 0.15 0.2 0.05 , quad -1. 0.5 0.
1. 0.5 0. 1. -0.5 0. -1. -0.5 0.;
#P message 605 232 259 196617 glcolor 0. 0.4 8. 1. , moveto $1 0.5 0.
, lineto $1 -0.5 0.;
#P newex 177 237 27 196617 – 2;
#P newex 675 162 27 196617 – 1;
#P window setfont Helvetica 24.;
#P number 303 28 86 24 0 0 0 21 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 9.;
#P message 515 45 65 196617 dim $1 , bang;
#P newex 146 279 34 196617 +~ 1.;
#P message 566 284 261 196617 glcolor 0.5 0.7 0.2 , lineto 1. -0.5 0.
, framecircle 0.005;
#P newex 566 265 38 196617 sel 29;
#P number 42 185 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 42 205 48 196617 ramp $1;
#P flonum 60 99 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 20 131 50 196617 *~ 1.;
#P newex 459 191 55 196617 snapshot~;
#P newex 515 148 152 196617 jit.op @op pass – pass @val 0.5;
#P message 605 249 182 196617 moveto -1. -0.5 0. , framecircle 0.005;
#P newex 146 257 41 196617 *~ 28.;
#P message 605 266 369 196617 glcolor 0.5 0.7 0.2 1. , lineto $1 $2
$3 , glcolor 0.8 0.6 0.6 1. , framecircle 0.005;
#P newex 515 204 41 196617 jit.iter;
#P newex 515 169 71 196617 t l b b b reset;
#P newex 515 319 81 196617 jit.gl.sketch foo;
#P newex 248 277 185 196617 jit.window foo @fsaa 1 @size 640 480;
#P newex 248 258 263 196617 jit.gl.render foo @ortho 1 @erase_color 0.3
0.45 0.5 1.;
#P newex 248 102 58 196617 t b b erase;
#P newex 515 84 176 196617 jit.expr @expr "snorm[0]" "0." "0.";
#P newex 515 63 115 196617 jit.matrix 3 float32 30;
#P toggle 248 22 51 0;
#P newex 248 81 51 196617 qmetro 5;
#P newex 146 109 64 196617 phasor~ 0.2;
#P newex 515 128 83 196617 jit.matrix scope;
#P newex 20 243 101 196617 rampsmooth~ 50 50;
#P newex 20 303 136 196617 jit.poke~ scope 1 1;
#P user ezadc~ 20 54 64 87 0;
#P newex 20 99 31 196617 abs~;
#P comment 935 214 100 196617 draw backdrop;
#P comment 390 42 58 196617 # of points;
#P comment 67 116 60 196617 scale signal;
#P window setfont "Sans Serif" 24.;
#P comment 769 46 147 196632 ElapseGraph;
#P connect 5 0 4 0;
#P connect 4 0 25 0;
#P connect 25 0 7 0;
#P fasten 27 0 7 0 47 231 25 231;
#P connect 7 0 6 0;
#P connect 28 0 27 0;
#P connect 26 0 25 1;
#P connect 39 0 38 0;
#P connect 38 0 40 0;
#P connect 40 0 9 0;
#P connect 9 0 21 0;
#P connect 21 0 31 0;
#P connect 31 0 6 1;
#P fasten 33 0 35 0 308 128 182 128;
#P connect 35 0 21 1;
#P connect 11 0 10 0;
#P connect 10 0 14 0;
#P connect 14 0 15 0;
#P fasten 14 2 15 0 301 252 253 252;
#P fasten 50 0 51 0 446 209 405 209;
#P connect 51 0 52 0;
#P connect 50 0 49 0;
#P fasten 9 0 41 0 151 128 464 128;
#P connect 41 0 42 0;
#P fasten 14 1 24 0 277 188 464 188;
#P connect 42 0 24 0;
#P connect 24 0 49 1;
#P fasten 33 0 32 0 308 68 502 68 502 41 520 41;
#P fasten 57 0 12 0 587 61 520 61;
#P connect 32 0 12 0;
#P connect 12 0 13 0;
#P fasten 14 1 8 0 277 123 520 123;
#P connect 13 0 8 0;
#P connect 8 0 23 0;
#P connect 23 0 18 0;
#P connect 18 0 19 0;
#P connect 18 4 17 0;
#P connect 37 0 17 0;
#P connect 36 0 17 0;
#P connect 30 0 17 0;
#P connect 22 0 17 0;
#P connect 20 0 17 0;
#P connect 19 1 29 0;
#P connect 29 0 30 0;
#P fasten 11 0 57 0 253 79 493 79 493 34 587 34;
#P fasten 34 0 29 1 680 189 599 189;
#P fasten 52 0 36 0 405 251 504 251 504 229 610 229;
#P fasten 49 0 36 0 446 229 610 229;
#P connect 18 2 36 0;
#P connect 18 1 22 0;
#P connect 19 0 20 0;
#P connect 18 3 37 0;
#P fasten 33 0 34 0 308 114 680 114;
#P pop;


January 21, 2006 | 8:56 am

Hi Andrew,

I had to modify something in your patch to get it work here (latest
maxmspjitter for windows) : the green background quad was drawn in front (Z
= 0.) and masking everything else, so I had to set it to a lower Z position
(-0.01 is ok).

(Below modified patch)

That gives me the opportunity to say you: Thanks very much Andrew for all
your patches, please continue sharing as you do, it’s very helpful!

Maybe it would be a good idea to post your patches also somewhere on the web
; I mean it would be easier to access them : searching in the huge max mail
archive for all messages posted by andrewb@cycling74.com is not so fun (I
did it recently to check if I didn’t missed some of your patches, and I
realised that I missed a lot of them!).
Doing it would also allow you to add your patches to http://www.maxobjects.com
(there is a "patch" category, almost empty for the moment…)

Best

Mathieu Chamagne
http://www.maxobjects.com

max v2;
#N vpatcher 16 51 1083 411;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 51 23 31 9109513 open;
#N sfplay~ 1 120960 0 ;
#P newobj 51 53 60 9109513 sfplay~;
#P message 101 23 35 9109513 loop 1;
#P toggle 84 23 15 0;
#P newex 580 27 32 9109513 sel 1;
#P newex 246 281 106 9109513 bgcolor 200 220 190;
#P comment 726 17 188 9109513 waveform display for envelope tracking;
#P comment 767 64 147 9109513 andrewb@cycling74.com;
#P comment 340 178 98 9109513 animate recordpoint;
#P message 398 216 22 9109513 -1.;
#P newex 398 196 32 9109513 sel 0;
#P toggle 439 176 15 0;
#P newex 439 196 29 9109513 gate;
#P comment 76 171 74 9109513 env. smoothing;
#P comment 151 36 58 9109513 length (ms);
#P comment 972 251 75 9109513 draw segments;
#P comment 787 235 81 9109513 draw startpoint;
#P comment 826 270 71 9109513 draw endpoint;
#P comment 863 218 71 9109513 draw blue line;
#P newex 457 154 33 9109513 -~ 1.;
#P newex 457 134 35 9109513 *~ 2.;
#P flonum 144 75 76 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 144 19 60 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 144 54 49 9109513 !/ 1000.;
#P message 613 199 335 9109513 glcolor 0.15 0.2 0.05 , quad -1. 0.5 -0.01
1. 0.5 -0.01 1. -0.5 -0.01 -1. -0.5 -0.01;
#P message 603 217 233 9109513 glcolor 0. 0.4 8. 1. , moveto $1 0.5 0. ,
lineto $1 -0.5 0.;
#P newex 175 222 27 9109513 – 2;
#P newex 673 147 27 9109513 – 1;
#P window setfont "Sans Serif" 24.;
#P number 301 13 86 24 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 9.;
#P message 513 30 65 9109513 dim $1 , bang;
#P newex 144 264 34 9109513 +~ 1.;
#P message 564 269 261 9109513 glcolor 0.5 0.7 0.2 , lineto 1. -0.5 0. ,
framecircle 0.005;
#P newex 564 250 38 9109513 sel 29;
#P number 40 170 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 40 190 48 9109513 ramp $1;
#P flonum 58 84 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 18 116 50 9109513 *~ 1.;
#P newex 457 176 55 9109513 snapshot~;
#P newex 513 133 152 9109513 jit.op @op pass – pass @val 0.5;
#P message 603 234 182 9109513 moveto -1. -0.5 0. , framecircle 0.005;
#P newex 144 242 41 9109513 *~ 28.;
#P message 603 251 369 9109513 glcolor 0.5 0.7 0.2 1. , lineto $1 $2 $3
, glcolor 0.8 0.6 0.6 1. , framecircle 0.005;
#P newex 513 189 41 9109513 jit.iter;
#P newex 513 154 71 9109513 t l b b b reset;
#P newex 513 304 81 9109513 jit.gl.sketch foo;
#P newex 246 262 167 9109513 jit.window foo @fsaa 0 @size 640 480;
#P newex 246 243 263 9109513 jit.gl.render foo @ortho 1 @erase_color 0.3
0.45 0.5 1.;
#P newex 246 87 58 9109513 t b b erase;
#P newex 513 69 176 9109513 jit.expr @expr "snorm[0]" "0." "0.";
#P newex 513 48 115 9109513 jit.matrix 3 float32 30;
#P toggle 246 7 51 0;
#P newex 246 66 51 9109513 qmetro 5;
#P newex 144 94 64 9109513 phasor~ 0.2;
#P newex 513 113 83 9109513 jit.matrix scope;
#P newex 18 228 101 9109513 rampsmooth~ 50 50;
#P newex 18 288 136 9109513 jit.poke~ scope 1 1;
#P user ezadc~ 0 36 44 69 0;
#P newex 18 84 31 9109513 abs~;
#P comment 950 200 100 9109513 draw backdrop;
#P comment 388 27 58 9109513 # of points;
#P comment 65 101 60 9109513 scale signal;
#P window setfont "Sans Serif" 24.;
#P comment 767 31 147 9109528 ElapseGraph;
#P connect 60 0 4 0;
#P connect 5 0 4 0;
#P connect 4 0 25 0;
#P connect 25 0 7 0;
#P fasten 27 0 7 0 45 216 23 216;
#P connect 7 0 6 0;
#P connect 28 0 27 0;
#P connect 58 0 60 0;
#P connect 59 0 60 0;
#P connect 61 0 60 0;
#P connect 26 0 25 1;
#P connect 39 0 38 0;
#P connect 38 0 40 0;
#P connect 40 0 9 0;
#P connect 9 0 21 0;
#P connect 21 0 31 0;
#P connect 31 0 6 1;
#P fasten 33 0 35 0 306 113 180 113;
#P connect 35 0 21 1;
#P connect 11 0 10 0;
#P connect 10 0 14 0;
#P connect 14 0 15 0;
#P fasten 14 2 15 0 299 237 251 237;
#P fasten 50 0 51 0 444 194 403 194;
#P connect 51 0 52 0;
#P connect 50 0 49 0;
#P fasten 9 0 41 0 149 113 462 113;
#P connect 41 0 42 0;
#P fasten 14 1 24 0 275 173 462 173;
#P connect 42 0 24 0;
#P connect 24 0 49 1;
#P fasten 33 0 32 0 306 53 500 53 500 26 518 26;
#P fasten 57 0 12 0 585 46 518 46;
#P connect 32 0 12 0;
#P connect 12 0 13 0;
#P connect 13 0 8 0;
#P fasten 14 1 8 0 275 108 518 108;
#P connect 8 0 23 0;
#P connect 23 0 18 0;
#P connect 18 0 19 0;
#P connect 18 4 17 0;
#P connect 37 0 17 0;
#P connect 36 0 17 0;
#P connect 30 0 17 0;
#P connect 22 0 17 0;
#P connect 20 0 17 0;
#P connect 19 1 29 0;
#P connect 29 0 30 0;
#P fasten 11 0 57 0 251 64 491 64 491 19 585 19;
#P fasten 34 0 29 1 678 174 597 174;
#P fasten 52 0 36 0 403 236 502 236 502 214 608 214;
#P fasten 49 0 36 0 444 214 608 214;
#P connect 18 2 36 0;
#P connect 18 1 22 0;
#P connect 19 0 20 0;
#P connect 18 3 37 0;
#P fasten 33 0 34 0 306 99 678 99;
#P pop;


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