Forums > MaxMSP

+~ code?

July 3, 2010 | 9:37 pm

Hi,

I want to write a +~ object that won’t distort – i.e., if the result of adding the signals > 1, it outputs 1.

Is the code for max objects available? It would sure be easier to tweak the existing +~ than to code from scratch.

Unless anyone has any other ideas, or there’s an object that does this that I’ve missed?

Thx

Mike


July 3, 2010 | 9:48 pm

I’m not sure I understand what you mean by distort. It will currently return results of > 1 with linearity. If you mean won’t let audio distort your sound card by clipping the output to 1, then you’ll be distorting the audio before it reaches your sound card, and in much the same way.

If you want a +~ that will stop not allow output of that excedes 1 or -1 then just put a [tanh~ ] after a standard [+~ ] object. This will soft-clip and sound less like digital clipping.

You can just put a [clip~ -1 1 ] after your [+~ ] to get the behaviour you desire……however if you use this with audio it *will* distort if your addition exceeds +/-1.

If you go to the download section you can get the Max5 SDK, which will walk you through writing externals, and I imagine it has code examples for standard objects.


July 3, 2010 | 10:34 pm

1) There seems to be a fundamental misunderstanding of how MSP works. MSP works with 32-bit floating point samples, giving you a range FARFARFARFARFARFARFARFAR greater than [-1 .. 1] to work with intermediate calculations. You can +~, *~, -~ and anything else to your heart’s content. As long as you scale it back to [-1 .. 1] before going to the DACs, you’re fine.

What you want to do will *add* distortion to a signal.

2) The SDK for coding objects in C is available on this very web site. But I’d get point #1 sorted out before starting coding in C.


July 4, 2010 | 6:31 am

if you want your signal to never reach zero the louder you get above zero, try to search the forum for atan distortion.

It sounds more ‘analog’

p


July 4, 2010 | 3:13 pm

peter: that was not what he meant, but adding 2 signals with 25 bits integer would
still give him a higher precision than remaining in 32 bits float. of course noone
needs to use only integer overflow bits for summing, because all audio software
uses float somwehere anywhere (last but not least when dithering down to 16 bits)

-110


July 5, 2010 | 9:54 am

Hi everyone, thanks for your comments, there’s some really useful information there, much appreciated! All the best, M


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