Forums > MaxMSP

pong~ style waveshaping

February 7, 2007 | 9:25 am

Hi,

I need to implement a patch made in max/msp in another platform. My patch uses pong~ extensively, and I need to implement the waveshaping characteristics of pong~ in the other platform but I am a bit lost.

Pong inverts the signal that exceeds the high and low thresholds. I did manage do make a waveshaper that does exactly that. But if the inverted signal passes the other threshold, the signal is inverted again in pong~, and this loop goes forever. So it is like pong is always feeding itself back, folding back the wave back and forth until it fits the given range.

I am a bit of lost on programming same kind of waveshaping function. Hope there is an easy way to make it.

Any suggestions?

Thanks!


February 7, 2007 | 4:48 pm

Can you post your waveshaper to aid the discussion?

Thanks

On Feb 7, 2007, at 2:25 AM, Batuhan wrote:

>
> Pong inverts the signal that exceeds the high and low thresholds. I
> did manage do make a waveshaper that does exactly that. But if the
> inverted signal passes the other threshold, the signal is inverted
> again in pong~, and this loop goes forever. So it is like pong is
> always feeding itself back, folding back the wave back and forth
> until it fits the given range.

—-
Steven M. Miller

Home < http://pubweb.csf.edu/~smill>
SFIFEM <
http://sfifem.csf.edu>
Atrium Sound Space <
http://atrium.csf.edu>
OVOS <
http://pubweb.csf.edu/~smill/ovos.html>


February 7, 2007 | 6:29 pm

Yes, of course.

If signal exceeds low or hi thresholds, it is treated to the transfer function:

(2*threshold) – signal

This effectively wraps the signal.

But say, if the "wrapped" signal exceeds the high threshold, it needs to be wrapped, and if this "wrapped" signal exceeds the lower thereshold, it needs to be wrapped again, and if this signal exceeds the higher threshold, it needs to be wrapped again, and if this signal exceeds the lower threshold, it needs to be wrapped again… And this goes on and on. But how many times? This example has one pong object for comparison. My foldback patcher effectively folds 4 times then fails to to more. I can connect more in series but it will eventually fail at some point and it looks lame.

So there should be another way I guess? You can switch presets, the last one fails in my implementation.

Thanks
Batuhan


February 7, 2007 | 6:46 pm

Sounds like you need some modulo arithmetic to get you sorted out.

The "%~" object should do the trick.

Andrew B.


February 8, 2007 | 7:32 pm

Thanks Andrew, for the response.

%~ surely rings a bell but does not help me with my problem. One can derive a function with %~
thresh. – (sig % thresh.) –> for the high threshold and,
thresh. + (thresh. % sig) –> for the low threshold.

I think this is more expensive than multiplication but my problem lies at the fact that I will eventually have to compare the folded signal with the opposite threshold again, to see if it exceeds. But I could not find a way to see how many times I am going to need this comparison in advance, I just get my head around for the math of it.

Thanks for the help.


February 9, 2007 | 6:51 am

This is a control-rate version of pong~ that I wrote. Not signal rate,
but the math may be useful. It works with lists, too…

Peter McCulloch

PM.Pong

max v2;
#N vpatcher 57 44 832 342;
#P origin 9 -62;
#P inlet 491 113 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 508 113 128 196617 loadmess $3;
#P newex 259 147 242 196617 PM.MinMax 0.;
#P inlet 259 113 15 0;
#P outlet 27 235 15 0;
#N vpatcher 20 74 601 258;
#P outlet 32 133 15 0;
#P inlet 32 49 15 0;
#P inlet 406 47 15 0;
#P inlet 219 47 15 0;
#P window setfont "Sans Serif" 9.;
#P hidden newex 428 47 113 196617 loadmess scalarmode 1;
#P newex 32 81 385 196617 vexpr
(((((($f1-$f2)/($f3-$f2))-int(($f1-$f2)/($f3-$f2))))*($f3-
$f2)+$f2)*(($f1-$f2)>=0))+(((((($f1-$f2)/($f3-$f2))-int(($f1-$f2)/($f3-
$f2))))*($f3-$f2)+$f3)*(($f1-$f2)<0));
#P hidden fasten 1 0 0 0 433 76 37 76;
#P connect 4 0 0 0;
#P connect 0 0 5 0;
#P connect 2 0 0 1;
#P connect 3 0 0 2;
#P pop;
#P newobj 52 191 475 196617 p Wrap;
#P newex 136 54 27 196617 % 2;
#P newex 136 31 65 196617 loadmess $1;
#P newex 113 86 27 196617 + 1;
#N vpatcher 20 74 620 474;
#P outlet 32 191 15 0;
#P inlet 32 49 15 0;
#P inlet 406 47 15 0;
#P inlet 219 47 15 0;
#P window setfont "Sans Serif" 9.;
#P hidden newex 466 46 113 196617 loadmess scalarmode 1;
#P newex 32 169 75 196617 vexpr $f1+$f2;
#P newex 97 118 383 196617 vexpr
[(((abs(int(($f2-$f1)/($f3-$f2)))<0.)+(abs(int(($f2-$f1)/($f3-
$f2)))%2)%2)==1)]*[(-1.*abs(($f1-$f2)-(int(($f1-$f2)/($f3-$f2)))*($f3-
$f2)))+$f3];
#P newex 32 81 385 196617 vexpr
[(((abs(int(($f2-$f1)/($f3-$f2)))<0.)+(abs(int(($f2-$f1)/($f3-
$f2)))%2)%2)==0)*(abs(($f1-$f2)-(int(($f1-$f2)/($f3-$f2)))*($f3-
$f2))+$f2)];
#P hidden fasten 3 0 0 0 471 76 37 76;
#P connect 6 0 0 0;
#P hidden fasten 3 0 2 0 471 163 37 163;
#P connect 0 0 2 0;
#P connect 2 0 7 0;
#P hidden fasten 3 0 1 0 471 113 102 113;
#P connect 6 0 1 0;
#P connect 1 0 2 1;
#P connect 4 0 0 1;
#P connect 4 0 1 1;
#P connect 5 0 0 2;
#P connect 5 0 1 2;
#P pop;
#P newobj 27 171 475 196617 p Fold;
#P newex 27 117 35 196617 gate 2;
#P inlet 113 31 15 0;
#P inlet 52 31 15 0;
#P newex 276 113 128 196617 loadmess $2;
#P fasten 5 0 3 0 118 109 32 109;
#P connect 3 0 4 0;
#P connect 8 0 9 0;
#P connect 4 0 9 0;
#P connect 1 0 3 1;
#P connect 3 1 8 0;
#P fasten 7 0 5 0 141 78 118 78;
#P connect 2 0 5 0;
#P connect 6 0 7 0;
#P connect 0 0 11 0;
#P connect 10 0 11 0;
#P connect 11 0 4 1;
#P connect 11 0 8 1;
#P connect 12 0 11 1;
#P connect 13 0 11 1;
#P connect 11 1 4 2;
#P connect 11 1 8 2;
#P pop;


February 9, 2007 | 9:43 am

On 9-Feb-2007, at 7:51, Peter McCulloch wrote:
> This is a control-rate version of pong~ that I wrote. Not signal
> rate, but the math may be useful.

Seems to be missing an abstraction named PM.MinMax?

Here’s a reminder that lp.scampf and lp.scampi offer pong~
functionality for ints and floats. Part of the free Litter Power
Starter pack. URI below.

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
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


February 9, 2007 | 11:11 am

Thanks for the input!

Andrew was right, I’ve successfully managed to derive two transfer functions with %~ operator. And it works fine.

I’ll be checking out your control rate example tonight, to see if it works more efficiently.

I’ll be posting my waveshaper later today. So thanks for all the help!


February 9, 2007 | 3:51 pm

>
> Seems to be missing an abstraction named PM.MinMax?
>

Whoops. Here is PM.MinMax

max v2;
#N vpatcher 20 74 463 292;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 193 97 185 196617 Useful when dealing with clip situations;
#P comment 211 79 154 196617 A float value allows float output;
#P comment 228 144 128 196617 peter.mculloch@gmail.com;
#P comment 192 61 215 196617 Sorts two numbers , so that outlet 1 <
outlet 2;
#P window setfont "Arial Black" 18.;
#P comment 192 25 167 791478290 PM.MinMax;
#P window setfont "Sans Serif" 9.;
#P comment 193 79 21 196617 $1;
#N comlet maximum;
#P outlet 104 140 15 0;
#N comlet minimum;
#P outlet 32 141 15 0;
#P comment 84 32 24 196617 V2;
#N comlet Max;
#P inlet 87 50 15 0;
#N comlet Min;
#P inlet 32 50 15 0;
#P newex 32 80 65 196617 bondo 2 5;
#P newex 104 118 68 196617 maximum $1;
#P newex 32 118 65 196617 minimum $1;
#P comment 30 32 24 196617 V1;
#P connect 4 0 3 0;
#P connect 3 0 1 0;
#P connect 1 0 7 0;
#P connect 5 0 3 1;
#P connect 3 1 1 1;
#P connect 3 0 2 0;
#P connect 2 0 8 0;
#P connect 3 1 2 1;
#P pop;


February 9, 2007 | 5:35 pm

Ok, this is my implementation of a foldback distortion. I think it works identical to pong~ foldback mode. It is more than 4 times inefficient and cpu hungry. :) The formulas I used are commented in patcher.

Implementing mathematical formulas with objects is killing me. In max I have expr, is there anything something like it in signal domain? I’ve looked for something like expr~ but had no luck.


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