I have a loop with a few map functions in it, i was wondering if there is a clever way to reduce the time it takes to do these. (i hope this makes sense to someone)
map's have a divide and a multiply in them, and
I know neither of those are good for speed :-[ I had to use them here, i couldnt think of anything else that would keep a nice smooth output.
bitClear (PORTG ,1); //Pin 40 test output for loop frequency and how much time code section takes by observing duty cycle on scope
modmatrixDest[0] =
((((map(LFO0F0,0,127,0,modmatrixSource[0]))>>10)
+ ((map (EG0F0,0,127,0,modmatrixSource[2]))>>11)
+ ((map (EG1F0,0,127,0,modmatrixSource[3]))>>11)
+ ((modmatrixSource[4] * VELF0)>>9)
+ ((map(NOTEF0,0,127,0,modmatrixSource[6]))>>10)
+ filterfreq));
modmatrixDest[0] = constrain(modmatrixDest[0],0,1023);
modmatrixDest[1] =
((map (CCuse[10],0,127,0,modmatrixSource[0]))
+ (map (CCuse[8],0,127,0,modmatrixSource[2]))
+ (map (CCuse[9],0,127,0,modmatrixSource[3]))
+ ((modmatrixSource[4] * CCuse[11]))
);
bitSet (PORTG ,1); //PIN40 test output high
UpdateOscs();
modmatrixSource and modmatrixDest are long integers
modmatrixSource[] are continuously changing, they range from -4,194,304 to 4,194,304 (i can use different or positive numbers only if it will help to make it faster, but no less than 1,048,576)
modmatrixDest[] are used by an ISR (osc frequency) and a PWM output (filter control voltage),
The other controls (CCuse, and LFO0F0 etc) are values from MIDI inputs and analog potentiometer inputs. they are bytes. and range from 0 to 127
I would like to add another set of modulation controls now i have set it up with external flash ROM, which would modulate the position in a wavetable. but
Right now that bit of code is taking up half of my main loop, which is quite large, it contains MIDI input, analog input, MUX control, control scaling , 3 envelope generators and an LFO
the main loop frequency is at 650 hz, and it can not go below 500hz before you start noticing bad timing. (its a synthesizer btw)
any help would be greatly appreciated!