2009-03-30 05:43 AM
Saturating arithmetic
2011-05-17 04:07 AM
To my way of thinking you want gradual compression such that you will never get to the point of clipping. I would focus my thinking around 0V +/- signal. Because you are only using two channels the following may work well:
Arithmetically scale your a+b and a-b signal to +/- pi/2. Then take the sine. You now have a number in –1..+1. Scale appropriately and output to your DAC. I have a fast sin(x) where x is an unsigned 32-bit integer representing 0 to 2pi. Value returned is a signed 32-bit integer = sin(x)*2^24 good to 12 bits. My function is all integer following the infinite series through -x^7/7! It never returns a result >1.0. I only use 0x6C bytes of ROM, a few stack words and no dedicated RAM. With this scheme low amplitude values are hardly attenuated. High amplitude values are reduced by as much as 50%. And the reduction is gradual. I would begin by using a floating point library sine function. That will take many more clocks that my fast integer sine. If it sounds okay than write a fast integer sine. Or... you could simply use (a+b)/2 and (a-b)/2 using an analog amplifier if needed to boost the signal.