Porting a PD Patch with Scientific Notation to Max? [IMG]

Mar 19, 2012 at 12:09pm

Porting a PD Patch with Scientific Notation to Max? [IMG]

Hi – I'm trying to port a PD patch by the venerable Andy Farnell and have run into a situation where a calculation using scientific notation is required and the resulting sound output is massively different – does anyone know if Max can handle numbers in the billions / billionths?

I'm guessing this is the cause as all the other object have decent enough equivalents (right?)

Attached are both the pd and max versions. The arguments $1 and $2 are 3 and 0.008 respectively and what the patch is meant to do is create a very sharp stuttering effect used in the modelling of electricity.

The PD version perfectly cuts the audio but the max version just sounds like bad distortion.

For anyone else interested in this – the pd src and audio is here

http://aspress.co.uk/sd/practical16.php

(the tarbull in the top left has all the examples)

Thanks

[attachment=188824,3565] [attachment=188824,3566]

Attachments:
  1. randgatemax.png
#62466
Mar 19, 2012 at 12:54pm

Try multiplying by a float, what you’re getting is integer overflow e.g.

– Pasted Max Patch, click to expand. –
#225639
Mar 19, 2012 at 3:32pm

Thanks for the reply – I’d never heard of integer overflow. It’s weird how in your patch there are a few numerical artifacts even when multiplying by a float between 0. and 1. (e.g. 0.521)

I also changed clip~ to use floats but strangely enough, neither change affected the sound output of the patch – its still just distortion and quite different to the pd version.

Hard to see where else the problem could be unless lop~ is significantly different to lores~?

#225640
Mar 19, 2012 at 4:01pm

UPDATE:

Turns out the equivalent of the PD object lop~ is onepole~, not lores~.

For anyone else interested – below is the patch that sounds almost the same as the PD version.

– Pasted Max Patch, click to expand. –

[attachment=188849,3567]

Attachments:
  1. randgatemaxv2.png
#225641
Mar 19, 2012 at 4:46pm

the artefacts you notice, are down to floating point representations.

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

#225642
Mar 22, 2012 at 10:17am

@big_post: Although the difference between ints and floats is significant the the Max world, in MSP everything is float. Always.

Artefacts being caused by floating point representation is, as you rightly point out, another gotcha. In the patch in question these might be slightly minimized by combining the two multiplications [*~ 0.0008] -> [*~ 1000000000] into a single object [*~ 800000]. (Double check those zeros). With 32 bit floats you have a 24 bit mantissa which limits accuracy to about 6 digits.

Alternately, on Max 6 with 64-bit floats you’ve got a 53-bit mantissa, ie accuracy to 13 decimal digits. That ought to get this patch through the night.

#225643
Mar 26, 2012 at 9:04am

@peter, you are of course right, and I need to stop skim reading (bad habit) ….

#225644

You must be logged in to reply to this topic.