Hey,
Sorry to drag back the subject but its becoming a bit of a bottleneck in my program!
I'm using the filter found on MusicDSP (http://www.musicdsp.org/showone.php?id=185) and it sounds absolutely brilliant but i'm doing my filter calculations within an interrupt.
My sample rate is at 36kHz, leaving about 27.8uS/interrupt trigger. Obviously i'm not wanting to use up all of that time in the interrupt or i'll never get anything else done!
I've tested my code, it uses DDS to output a waveform with a 9bit phase accumulator and with the filter calculations disabled (using an if(filteroff = 1) to turn on/off the calculations) the code takes 4.5uS. This is fine as the interrupt will exit leaving about 23uS of processing time before another interrupt is fired. This is long enough to turn a couple of LED's on or off/read a few inputs.
Of that 4.5uS, 1.6uS of that seems to be writing to the PWM outputs. i'm using pseudo 16bit PWM by combining two 8 bit PWM's and doing some bitshifts/and'ing to send the correct values to each output. Could this time be shortened with direct manipulation (quite like on arduino, using OCRxA/B)?
Once the filter is activated (filteroff = 0), the interrupt time hikes up to 14.3uS which is immense! As you can probably tell, that only leaves me ~8uS of processor time between interrupts with ain't too much!
After doing a simple test on the maple, I found that int math is 7.1x faster than float math and 9.6x faster than double math. Precision is not a massive problem here as i'm only using "relative" cut off frequencies instead of actual values (for example 200Hz).
The filter code within the interrupt is:
FilterVariable1 = OneMinusRC*FilterVariable1 - Cutoff*FilterVariable2 + Cutoff*SampleVal;
FilterVariable2 = OneMinusRC*FilterVariable2 + Cutoff*FilterVariable1;
PWMWriteVar = FilterVariable2;
OneMinusRC is calculated within the main loop to save on interrupt time, along with the cutoff.
The calculations for these are:
Cutoff = 6.3*FilterValue/SampleRate;
Resonance = pow(0.5, ((256/ResV)+32)/16);
OneMinusRC = (1-Resonance*Cutoff);
Where filter value is my cutoff frequency and sample rate is 36k. ResV is the value used for resonance.
As you can see, i've already reduced the accuracy by using the small angle approximation (tan(O) = O at small angles), and even pi has been reduced in accuracy from 6.282 to 6.3.
How will I go about converting this to int math? If I could manage this, it would drastically reduce the interrupt time and allow me to add many more effects!
Cheers,
Harris