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
(the tarbull in the top left has all the examples)
Try multiplying by a float, what you’re getting is integer overflow e.g.
----------begin_max5_patcher---------- 441.3ocwUFsaBCBEF95ZhuCMb4hZJTZ0t61ywxhAsLESKsofN2L6cevAYSmZ raSc8BOgy4.7yG+stoam.zjp0bEJ79vGCCB1XxD.4rYB7IBPkr0SKXJnQTIW oXy3ndaKp4q0Pg9jLZV5PRV5m0jKKExBtFlIwmUjC8WMYQ+jcasZo12K1m94 JoVIdiCIICh74c8pesl6TOBE9juVMSOctPNabCep1UFiGYlaXLdnMfibAStu lkcmjrRX8POzHXEHnx6c6XilPuVyHI+Eyo6PDcmYq8OsGRzKFjDR843TpkLD J1FFk.ChtVX5jVIJNy9LjRGzdLEei7RjgDmWhBln3z+euzOfRjKFkdtnhcF6 DIMCbPwPXT100NYDj4LcbTfOBJvm.EjeIJ5EhlvjyNCRhiA+RB7AojnCQRMq w.DMuYLWxlT.6QT64kagPEB4AeYGjisv2nnpZYyT+YYKYB2QQ4bkVHYZQkbm ln62zbQdNWtmXyEJ6A.HdzouVasrnsQVl+RIDeSkEoMxJ9lKqVcIR9SWha8Z r55U7F01U1oHyqlKpZriS64FKjtwtUF0vWI7SgZx.qp4mOvOh.dc -----------end_max5_patcher-----------
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~?
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.
----------begin_max5_patcher---------- 684.3oc2XtsiaBCDF9ZxSAx8tU6Fgs4X6U8Enu.UUUDvaVuBrQwj1r6pMO60 XCIjzzHGNX01bAnYrM7yGCyLwusvArhuiH.tez8qtNNusvwQ4pwgSqsCnLcW VQpPMM.i7S9pmA2qGplrqV4lyHU7BxdWb2PrskTVAoVsLzQm7s0cdgsdejyp EzWIJenkdstqRqydhxV+8MjrZsFQwAxg6NE4oLjGc+V6ZzW85WpH5E.Dz0rz BvgIPy05c0yOfffdBfkVpVC3yanxEzLv6KVzb39+kPCDOEnAF++EZBUnwCOE nAOsnojHDoqI+FaJ37JWu4kKHcHSfhH9J5.iuFWt72QdVjHv4kHPEJfnwQDX hcHx7BCXXPOXfQKCFFLhrCL3UD17xCT+fCbzPCNBsRtUwiUEour+FHBZnDos ziehwIVu2ErJks9x7I3J7ocDQ5O5the3KMWsCOsRnKeqndKkDJkim1C3Sx60 .fK407zraAhWK4htxiumlVGNdQHflvPg61OuIM0OWXbu7DCt7ZhU93HqfVs2 0aoKb4EQCdh6WMPcJDMpNOrSOY2sW1nT2ukybeY9JfnaCIIbTzIxJz4glnFI XhsRu7ISQXicJ2HmCsbaoUwSa+Ivw0PefU3CiSEjKmGFNsXIRWXYbeMgLCJp kBJnry2DAk7Z7eJoD7sax5t8cE6cOJwbhnlxRqobVuIkbxbdhlmSX8q0VRyq 3TVsnqqjjlRPXnpCMTzQq+PK.lJ1lMLvHwBMWriTRwFnnyj8bKInIZJvtRBa fjNS2yslPlHIrUkTjARxtPJz.EEYUEYR9pPqpnDSBjP+cJoaHQYWd7vX0I4e hpyZrIGLIHCFLnZPHHTukAGsFqZilC0F4OSpMYFTKBNSrsYiLmd0h0r0G0Ws MVmnVow6K9Uy2R8C -----------end_max5_patcher-----------
@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.