This build started with optimizing DSP operations on 8-bit Atmel MCU. floating point is too slow, so i designed 16-bit fixed point arithmetic with optimized assembly language inline multiply. Exponential rise-fall dynamics are hard to calculate directly, but are the impulse response of first order ODEs, which can be converted to a single add and shift operation. Thus envelope generation reduces to a few shifts, adds, and two fixed point multiplies.

The amplitude envelope chosen is the product of two exponentials, a relatively fast rise and slow fall of the form: a(t) = A*exp(-t/τfall)*(1-exp(-t/τrise)) To generate this envelope at 8 KHz with no floating point, some rearrangement of the math and a few simplifications were done. First we note that the differential equation with solution equal to the desired exponential exp(-t/k) is dy/dt = -k*x. Then we quantize the differential equation to a difference equation using an Euler approximation with time step equal to the sample time ∆t, and where n denotes the current sample and n+1 the updated value. [x(n+1) - x(n)]/∆t = -k*x(n)

rearranging gives x(n+1) = x(n) - ∆t*k*x(n)

Next, we allow k to be only a negative power of two, say 2^-p ,

(corresponding a time constant greater than the sample time), and scale k so that ∆t equals one, then we can rewrite the difference equation to x(n+1) = x(n) - (x(n)>>p)

## Discussions

## Become a Hackaday.io Member

Create an account to leave a comment. Already have an account? Log In.