triangle wave problems

Apr 28, 2006 at 7:39pm

triangle wave problems

i’m trying to create a triangle waveform from a phasor~ – like cycle~ (i have a ramp buffer that cycle~ refers to). I won’t get into why I’m using cycle~ instead of phasor~…BUT, I’m getting a strange discontinuity that I can’t figure out. This patch demonstrates the problem (XP). Why does does the cycle~-based version behave differently????

Peter.

#P window setfont “Sans Serif” 9.;
#P window linecount 1;
#P comment 99 461 100 9109513 WHY????;
#P newex 119 63 27 9109513 0.5;
#P user ezdac~ 312 290 356 323 0;
#P newex 433 75 45 9109513 loadbang;
#N vpatcher 15 55 615 455;
#P window setfont “Sans Serif” 9.;
#P number 169 221 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 169 272 74 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 167 248 54 9109513 peek~ phsr;
#P inlet 66 73 15 0;
#P newex 89 138 32 9109513 / 512.;
#P button 50 93 15 0;
#P newex 67 93 40 9109513 Uzi 512;
#P newex 67 116 27 9109513 – 1;
#P newex 67 186 54 9109513 peek~ phsr;
#P newex 67 164 47 9109513 pack 0 0.;
#P newex 34 211 86 9109513 buffer~ phsr 11.61;
#P window linecount 6;
#P comment 129 92 100 9109513 i’ve been experiencing problems with phasor~ , so I replaced it with a cycle~ phsr. this creates the lookup table for cycle~…;
#P connect 6 0 5 0;
#P connect 8 0 5 0;
#P connect 5 2 4 0;
#P connect 4 0 2 0;
#P connect 2 0 3 0;
#P connect 4 0 7 0;
#P connect 7 0 2 1;
#P connect 11 0 9 0;
#P connect 9 0 10 0;
#P pop;
#P newobj 433 97 48 9109513 p phsrbuf;
#P flonum 385 106 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 507 77 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P user scope~ 452 291 582 421 32 3 128 -2. 2. 0 0. 0 0. 102 255 51 135 135 135 0;
#P user scope~ 595 120 695 170 32 3 128 -1. 1. 0 0. 0 0. 102 255 51 135 135 135 0;
#P newex 410 317 33 9109513 pass~;
#P newex 410 288 28 9109513 *~ 2.;
#P newex 522 157 27 9109513 -~;
#P newex 522 213 39 9109513 *~ -1.;
#P newex 522 184 27 9109513 /~;
#P newex 558 154 27 9109513 !-~ 1;
#P newex 466 216 27 9109513 /~;
#P newex 522 239 39 9109513 +~ 0.5;
#P newex 466 241 38 9109513 -~ 0.5;
#P newex 410 263 122 9109513 selector~ 2;
#P newex 410 241 30 9109513 +~ 1;
#P newex 410 220 27 9109513 >~;
#P newex 387 125 57 9109513 phasor~ 0.5;
#P outlet 410 356 15 0;
#P newex 132 21 45 9109513 loadbang;
#N vpatcher 15 55 615 455;
#P window setfont “Sans Serif” 9.;
#P number 169 221 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 169 272 74 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 167 248 54 9109513 peek~ phsr;
#P inlet 66 73 15 0;
#P newex 89 138 32 9109513 / 512.;
#P button 50 93 15 0;
#P newex 67 93 40 9109513 Uzi 512;
#P newex 67 116 27 9109513 – 1;
#P newex 67 186 54 9109513 peek~ phsr;
#P newex 67 164 47 9109513 pack 0 0.;
#P newex 34 211 86 9109513 buffer~ phsr 11.61;
#P window linecount 6;
#P comment 129 92 100 9109513 i’ve been experiencing problems with phasor~ , so I replaced it with a cycle~ phsr. this creates the lookup table for cycle~…;
#P connect 8 0 5 0;
#P connect 6 0 5 0;
#P connect 5 2 4 0;
#P connect 4 0 2 0;
#P connect 2 0 3 0;
#P connect 4 0 7 0;
#P connect 7 0 2 1;
#P connect 11 0 9 0;
#P connect 9 0 10 0;
#P pop;
#P newobj 132 43 48 9109513 p phsrbuf;
#P flonum 24 53 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 191 52 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P user scope~ 93 278 223 408 32 3 128 -2. 2. 0 0. 0 0. 102 255 51 135 135 135 0;
#P user scope~ 228 114 328 164 32 3 128 -1. 1. 0 0. 0 0. 102 255 51 135 135 135 0;
#P newex 49 307 33 9109513 pass~;
#P newex 49 278 28 9109513 *~ 2.;
#P newex 161 147 27 9109513 -~;
#P newex 161 203 39 9109513 *~ -1.;
#P newex 161 174 27 9109513 /~;
#P newex 197 144 27 9109513 !-~ 1;
#P newex 105 206 27 9109513 /~;
#P newex 161 229 39 9109513 +~ 0.5;
#P newex 105 231 38 9109513 -~ 0.5;
#P newex 49 253 122 9109513 selector~ 2;
#P newex 49 231 30 9109513 +~ 1;
#P newex 49 210 27 9109513 >~;
#P newex 26 115 73 9109513 cycle~ 0.5 phsr;
#P outlet 49 346 15 0;
#P comment 230 54 100 9109513 duty cycle;
#P window linecount 3;
#P comment 100 410 100 9109513 this one gets a discontinuity on the dn->up transition;
#P connect 19 0 3 0;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 14 0;
#P connect 14 0 15 0;
#P connect 15 0 2 0;
#P connect 18 0 4 1;
#P connect 14 0 17 0;
#P connect 3 0 9 0;
#P connect 9 0 7 0;
#P connect 7 0 6 1;
#P connect 21 0 43 0;
#P connect 18 0 9 1;
#P connect 21 0 20 0;
#P connect 3 0 13 0;
#P connect 13 0 11 0;
#P connect 11 0 12 0;
#P connect 12 0 8 0;
#P connect 8 0 6 2;
#P connect 18 0 13 1;
#P connect 10 0 11 1;
#P connect 43 0 18 0;
#P connect 18 0 10 0;
#P connect 3 0 16 0;
#P connect 19 0 39 0;
#P connect 39 0 23 0;
#P connect 23 0 24 0;
#P connect 24 0 25 0;
#P connect 25 0 26 0;
#P connect 26 0 34 0;
#P connect 34 0 35 0;
#P connect 35 0 22 0;
#P connect 38 0 24 1;
#P connect 41 0 40 0;
#P connect 34 0 37 0;
#P connect 23 0 29 0;
#P connect 29 0 27 0;
#P connect 27 0 26 1;
#P connect 38 0 29 1;
#P connect 18 0 38 0;
#P connect 23 0 33 0;
#P connect 33 0 31 0;
#P connect 31 0 32 0;
#P connect 32 0 28 0;
#P connect 28 0 26 2;
#P connect 38 0 33 1;
#P connect 30 0 31 1;
#P connect 38 0 30 0;
#P connect 23 0 36 0;
#P window clipboard copycount 45;

#25701
Apr 28, 2006 at 7:54pm

just checking, but is there a reason that the triangle~ and tri~ objects
don’t work for you?

#75979
Apr 28, 2006 at 8:36pm

i’ll be damned! I didn’t know triangle~ existed. Thanks for that. tri~ doesn’t “work” for me because it’s anti-aliased. I’m still curious why the above doesn’t work right, though.

#75980
Apr 28, 2006 at 8:50pm

On 28-Apr-2006, at 21:39, pnyboer wrote:
> BUT, I’m getting a strange discontinuity that I can’t figure out.

Going back to The Book:

>> The cycle~ object is an interpolating oscillator that reads
>> repeatedly through one cycle of a
>> waveform, using a wavetable of 512 samples. Its default waveform
>> is one cycle of a cosine
>> wave. It can use other waveforms by accessing samples from a
>> buffer~ object. The 513th
>> sample in the wavetable source (the buffer~) is used for
>> interpolation beyond the 512th
>> sample.

That last sentence is, I think, what’s killing you. Try defining that
513th sample at loadbang time.

– P.

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +—> Litter Power & Litter Bundle for Jitter
Heavy-Duty Mathematics for Everyday Use
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de

#75981
May 4, 2006 at 6:33pm

hmmm…ok, that 513th doesn’t really do it either. here’s a patch that demonstrates the problem I’m having. Theoretically, the cycle~ phasr should be the same as phasor~. Practically, it’s not:

#P window setfont “Sans Serif” 9.;
#P window linecount 3;
#P comment 331 337 294 9109513 these problems couldn’t be distilled into something easy to understand , (or even hard to understand) , so I thought I’d try cycle~ instead of phasor~. cured the problems but introduced this one :(;
#P window linecount 4;
#P comment 129 337 199 9109513 the reason I can’t use phasor is because i’m experiencing bad problems if I use it instead of this cycle~ to generate some different waveforms.;
#P window linecount 1;
#P comment 162 46 199 9109513 generate a phasor~ liike buffer~;
#P comment 254 72 199 9109513 change your motivation!;
#P window setfont “Sans Serif” 12.;
#P comment 474 253 199 9109516 SO WHY THE CLICKS??;
#P window setfont “Sans Serif” 9.;
#P comment 454 87 199 9109513 according to this test , these are equivalent!!!!;
#P newex 255 114 27 9109513 + 1;
#P user ubumenu 255 89 100 9109513 0 1 1 0;
#X add clicks;
#X add noclicks;
#X prefix_set 0 0 0;
#X pattrmode 1;
#P newex 369 113 54 9109513 phasor~ 10;
#P newex 289 113 73 9109513 cycle~ 10. phsr;
#P user number~ 493 165 532 180 9 139 3 2 0. 0. 0 0. 250 0. 0 0 0 221 221 221 222 222 222 0 0 0;
#P user number~ 553 163 592 178 9 139 3 2 0. 0. 0 0. 250 0. 0 0 0 221 221 221 222 222 222 0 0 0;
#P user number~ 513 219 552 234 9 139 3 2 0. 0. 0 0. 250 0. 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 514 190 27 9109513 -~;
#P flonum 527 107 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 541 140 49 9109513 phasor~ 0;
#P newex 470 142 68 9109513 cycle~ 0. phsr;
#P window linecount 4;
#P comment 21 206 100 9109513 this vs. “512 0″ just changes the bandwidth of the clicks (less hi freqs).;
#P user ezdac~ 285 231 329 264 0;
#P window linecount 1;
#P newex 286 197 59 9109513 triangle~ 0.5;
#P newex 280 141 62 9109513 selector~ 2 1;
#P window setfont “Sans Serif” 10.;
#P newex 147 63 53 9109514 loadbang;
#P window setfont “Sans Serif” 9.;
#P message 123 206 34 9109513 512 0.5;
#P newex 207 200 32 9109513 / 512.;
#P button 146 45 15 0;
#P newex 170 83 40 9109513 Uzi 512;
#P newex 169 109 27 9109513 – 1;
#P newex 169 249 54 9109513 peek~ phsr;
#P newex 169 227 47 9109513 pack 0 0.;
#P newex 136 274 86 9109513 buffer~ phsr 11.61;
#P connect 15 0 13 1;
#P connect 15 0 14 1;
#P connect 14 0 16 1;
#P connect 14 0 18 0;
#P connect 13 0 19 0;
#P connect 13 0 16 0;
#P connect 21 0 9 2;
#P connect 20 0 9 1;
#P connect 23 0 9 0;
#P connect 22 0 23 0;
#P connect 9 0 10 0;
#P connect 10 0 11 0;
#P connect 10 0 11 1;
#P connect 16 0 17 0;
#P connect 3 0 1 0;
#P connect 3 0 6 0;
#P connect 1 0 2 0;
#P connect 8 0 4 0;
#P connect 6 0 1 1;
#P connect 5 0 4 0;
#P connect 7 0 2 0;
#P connect 4 2 3 0;
#P connect 4 1 7 0;
#P window clipboard copycount 30;

#75982
May 4, 2006 at 6:56pm

At 44.1kHz 11.61 milliseconds makes a buffer~ with 512 samples. You
want a buffer~ with 513 samples.

Ben

#75983
May 4, 2006 at 8:39pm

hmmm…right. but I still the clicks if I change the buffer size to 11.63265. Did changing this fix the problem for you, or is it just an observation of me being absent minded? :)

p.

#75984
May 4, 2006 at 11:30pm

hi,
this works for me.
cheers,
volker.

#P window setfont “Sans Serif” 9.;
#P flonum 397 71 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 255 114 27 196617 + 1;
#P user ubumenu 255 89 100 196617 0 1 1 0;
#X add clicks;
#X add noclicks;
#X prefix_set 0 0 0;
#X pattrmode 1;
#P newex 353 144 68 196617 phasor~ 10;
#P newex 319 121 87 196617 cycle~ 10. phsr;
#P user ezdac~ 269 256 313 289 0;
#P newex 286 197 73 196617 triangle~ 0.5;
#P newex 286 169 76 196617 selector~ 2 1;
#P window setfont “Sans Serif” 10.;
#P newex 135 112 53 196618 loadbang;
#P window setfont “Sans Serif” 9.;
#P newex 206 203 46 196617 / 512.;
#P newex 135 141 45 196617 Uzi 513;
#P newex 169 173 27 196617 – 1;
#P newex 169 249 54 196617 peek~ phsr;
#P newex 169 227 47 196617 pack 0 0.;
#P newex 136 274 82 196617 buffer~ phsr 12;
#P connect 14 0 10 0;
#P connect 14 0 11 0;
#P connect 3 0 1 0;
#P connect 3 0 5 0;
#P connect 11 0 7 2;
#P connect 10 0 7 1;
#P connect 8 0 9 0;
#P connect 8 0 9 1;
#P connect 7 0 8 0;
#P connect 13 0 7 0;
#P connect 12 0 13 0;
#P connect 5 0 1 1;
#P connect 4 2 3 0;
#P connect 6 0 4 0;
#P connect 1 0 2 0;
#P window clipboard copycount 15;

#75985
May 5, 2006 at 3:19pm

thanks! works here too.

#75986

You must be logged in to reply to this topic.