In the spirit of the new forum area...Here's some code

Started by Transmogrifox, March 03, 2006, 03:18:05 AM

Previous topic - Next topic

Peter Snowberg

It does add up and PICs are quick so a little more math isn't much of a problem.

Meta-code for average of 4 numbers:
load value1
add value2
add value3
add value4
shift right
shift right
save result


If you're playing in 11/17 or some other timing, the code gets a little more tricky.  :icon_wink:
Eschew paradigm obfuscation

Dave_B

That's what I was doing when my programmer went belly up.  Two shifts to the right.  The only difference is that I was using the 16-bit timer and ignoring all but the first and fourth switch closures (as I mentioned earlier). 
Help build our Wiki!

Transmogrifox

Quote from: Peter Snowberg on March 06, 2006, 01:06:30 PM
It does add up and PICs are quick so a little more math isn't much of a problem.

Meta-code for average of 4 numbers:
load value1
add value2
add value3
add value4
shift right
shift right
save result


If you're playing in 11/17 or some other timing, the code gets a little more tricky.  :icon_wink:

Since we don't have any 16-bit registers we may want to do something like this:

load value1
load value2
shift right value1 
shift right value2

add 2 results, store in A

load value3
load value4
shift right value3 
shift right value4

add results, store in B

load valueA
load valueB
shift right valueA
shift right valueB

add results, store in result register


...or we could keep track of an extra register per byte for carries
...or we could keep track of the non-zero 2-1 bits that shift off the end and add 1 to the final result if there is a pair generated...or just add 1 to the result if there is a non-zero 2-1 bit at any point in the operation.

I think the being off by 1 will be inconsequential.  We would perceive a phase lag rather than a tempo change if the musicians kept perfect tempo in the song, but usually we (speaking for myself mostly) don't keep to that degree of precision where our technology would be at fault for getting us out of sync.  We would need better than 8-bit processing if we were that good.
trans·mog·ri·fy
tr.v. trans·mog·ri·fied, trans·mog·ri·fy·ing, trans·mog·ri·fies To change into a different shape or form, especially one that is fantastic or bizarre.