Forums > MaxMSP

Sawtooth Wave Via expr

December 1, 2006 | 10:50 am

Hi, can someone tell me if this is a sawtooth wave (or atleast getting there) i know there is not enough harmonics
Thanks!

max v2;
#N vpatcher 15 55 615 455;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#N vpatcher 40 124 952 713;
#P window setfont "Sans Serif" 9.;
#P window linecount 3;
#P newex 95 209 377 9109513 expr (sin (3.14159 *2*1*$f1) + 0.5 *sin (3.14159 *2*2*$f1) + 0.33 *sin (3.14159 *2*3*$f1)) + 0.25 *sin (3.14159 *2*4*$f1) + 0.2 *sin (3.14159 *2*5*$f1) + 0.16 *sin (3.14159 *2*6*$f1) + 0.14 *sin (3.14159 *2*7*$f1);
#P number 17 151 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 0;
#P newex 95 163 38 9109513 / 511.;
#P newex 74 109 43 9109513 Uzi 512;
#N counter 0 511;
#X flags 0 0;
#P newobj 74 134 72 9109513 counter 0 511;
#P button 74 85 15 0;
#P inlet 74 55 15 0;
#P newex 74 311 49 9109513 pack 0 0.;
#P outlet 74 388 15 0;
#P window setfont "Sans Serif" 10.;
#P comment 218 182 100 9109514 Sawtooth;
#P connect 5 0 8 0;
#P connect 3 0 4 0;
#P connect 4 0 6 0;
#P connect 6 0 5 0;
#P connect 5 0 2 0;
#P connect 2 0 1 0;
#P fasten 5 0 7 0 79 157 100 157;
#P connect 7 0 9 0;
#P fasten 9 0 2 1 118 250;
#P pop;
#P newobj 210 107 59 9109513 p Sawtooth;
#P newex 210 134 79 9109513 peek~ sawtooth;
#P inlet 210 87 15 0;
#P connect 0 0 2 0;
#P connect 2 0 1 0;
#P pop;


December 1, 2006 | 11:19 am

Quote: Rocky wrote on Fri, 01 December 2006 11:50
—————————————————-
> Hi, can someone tell me if this is a sawtooth wave (or atleast getting there) i know there is not enough harmonics
> Thanks!

It looks like a sawtooth. I changed your patch so that it actually generates the waveform. Doubleclick the buffer~ to see it.

#P button 24 34 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 24 96 103 196617 buffer~ sawtooth 24;
#N vpatcher 40 124 516 387;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 70 175 35 196617 * 0.5;
#P newex 53 91 27 196617 t i i;
#P newex 53 71 27 196617 – 1;
#P window linecount 3;
#P newex 70 131 377 196617 expr (sin (3.14159 *2*1*$f1) + 0.5 *sin (3.14159 *2*2*$f1) + 0.33 *sin (3.14159 *2*3*$f1)) + 0.25 *sin (3.14159 *2*4*$f1) + 0.2 *sin (3.14159 *2*5*$f1) + 0.16 *sin (3.14159 *2*6*$f1) + 0.14 *sin (3.14159 *2*7*$f1);
#P window linecount 0;
#P newex 70 111 38 196617 / 511.;
#P newex 13 50 51 196617 uzi 1024;
#P inlet 13 29 15 0;
#P newex 53 197 49 196617 pack 0 0.;
#P outlet 53 217 15 0;
#P window setfont "Sans Serif" 10.;
#P comment 194 108 100 196618 Sawtooth;
#P connect 3 0 4 0;
#P connect 4 2 7 0;
#P connect 7 0 8 0;
#P connect 8 0 2 0;
#P connect 2 0 1 0;
#P connect 8 1 5 0;
#P connect 5 0 6 0;
#P connect 6 0 9 0;
#P connect 9 0 2 1;
#P pop;
#P newobj 24 52 59 196617 p Sawtooth;
#P newex 24 71 79 196617 peek~ sawtooth;
#P connect 3 0 1 0;
#P connect 1 0 0 0;
#P window clipboard copycount 4;


December 1, 2006 | 11:37 am

really appreciate the help, can you explain what the trigger does and why the buffer is set to 24 and also the -1.
Thanks


December 1, 2006 | 12:25 pm

On 01 Dec 2006, at 11:50, Freddy wrote:

>
> Hi, can someone tell me if this is a sawtooth wave (or atleast
> getting there) i know there is not enough harmonics
> Thanks!

i would use something like this to sum an "arbitrary" number of
partials into a single sawtooth-waveform.
volker.

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 132 36 66 196617 loadmess 12;
#P message 37 418 66 196617 normalize 1.;
#P newex 122 398 48 196617 loadbang;
#P newex 423 511 80 196617 buffer~ saw 24;
#P message 122 419 45 196617 set saw;
#P user waveform~ 37 446 363 137 3 9;
#W mode select;
#W mouseoutput none;
#W clipdraw 1;
#W unit samples;
#W grid 22.675737;
#W ticks 0;
#W labels 1;
#W vlabels 0;
#W vticks 0;
#W bpm 120. 4.;
#W frgb 33 0 0;
#W brgb 60 178 173;
#W rgb2 0 95 255;
#W rgb3 0 0 0;
#W rgb4 0 0 0;
#W rgb5 146 179 217;
#W rgb6 100 100 100;
#W rgb7 100 100 100;
#P newex 482 57 72 196617 loadmess 512;
#P comment 467 259 31 196617 N;
#P number 482 84 42 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 482 195 27 196617 – 1;
#P number 482 236 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 320 141 27 196617 – 1;
#P newex 246 182 27 196617 t b i;
#P newex 193 377 111 196617 peek~ saw;
#P newex 320 169 40 196617 t i b i;
#P window setfont "Sans Serif" 12.;
#P number 132 77 40 12 1 0 69 3 0 0 0 127 255 75 222 222 222 0 0 0;
#P window setfont "Sans Serif" 9.;
#P newex 212 275 41 196617 t b b;
#P message 212 309 31 196617 set 0;
#P newex 243 340 48 196617 accum 0.;
#P button 282 89 21 0;
#P newex 222 219 51 196617 uzi 5;
#P newex 282 119 49 196617 Uzi 512;
#P comment 363 259 31 196617 n;
#P newex 262 275 230 196617 expr (1./$i1) * sin(2*3.141593*$i1*$i2/$f3);
#P comment 272 259 19 196617 k;
#P comment 308 92 25 196617 go!;
#P comment 34 80 100 196617 number of partials;
#P window linecount 3;
#P comment 528 77 62 196617 N: number of samples in wavetable;
#P window linecount 2;
#P comment 295 337 172 196617 sum all values that influence one
sample in the final waveform;
#P connect 28 0 13 0;
#P connect 26 0 24 0;
#P connect 10 0 15 1;
#P fasten 14 0 15 0 325 243 198 243;
#P lcolor 7;
#P connect 18 0 5 2;
#P connect 19 0 18 0;
#P fasten 20 0 7 1 487 109 326 109;
#P connect 20 0 19 0;
#P connect 22 0 20 0;
#P fasten 14 2 5 1 355 230 377 230;
#P connect 17 0 14 0;
#P connect 7 2 17 0;
#P connect 9 0 7 0;
#P fasten 16 0 9 0 251 204 235 204 235 84 287 84;
#P connect 16 1 8 1;
#P connect 5 0 10 1;
#P connect 8 2 5 0;
#P connect 13 0 16 0;
#P connect 12 1 10 0;
#P connect 11 0 10 0;
#P fasten 14 1 8 0 340 211 227 211;
#P connect 12 0 11 0;
#P connect 8 1 12 0;
#P fasten 24 0 23 0 127 440 42 440;
#P connect 27 0 23 0;
#P fasten 7 1 27 0 306 150 42 150;
#P window clipboard copycount 29;


December 1, 2006 | 2:48 pm

Quote: Rocky wrote on Fri, 01 December 2006 12:37
—————————————————-
> really appreciate the help, can you explain what the trigger does and why the buffer is set to 24 and also the -1.
> Thanks
—————————————————-

np :)

The trigger makes sure the second argument of pack is set before the first argument. This is because the first argument triggers the pack to send its output.

The 24 is because the buffer needs to know how much samples it is supposed to hold. 24 is in milliseconds, with a samplerate of 44100 Hz this amounts to (a bit more than) 1024 samples.

-1 after uzi is because uzi’s third outlet starts outputting at 1 while the sample index in peek~ starts at 0.

This can all be found in the tutorials and help files. I would advise you to do the max and msp tutorials. There’s a lot info you might find useful.

Cheers,
Mattijs


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