[sdiy] MIDI velocity

rsdio at audiobanshee.com rsdio at audiobanshee.com
Sun Apr 10 01:45:27 CEST 2016


On Apr 7, 2016, at 5:05 AM, Neil Johnson <neil.johnson71 at gmail.com> wrote:
> About 7 years ago when I was writing the keyboard scanning code for a
> Siel Opera 6 I had a simple scheme for scanning and measuring play and
> release velocity (not many folks seem to know about release velocity
> although some synthesizers do recognise it).
The Matrix-12 from 1984 implements release velocity - it both generates it and responds to it.

> Using an Atmel ATMega8 scanning the entire keyboard every 1ms I run
> 4-state state machine for each key, where the states are UP,
> GOINGDOWN, DOWN, GOINGUP, and an 8-bit counter for each key.
> Debouncing is handled by the algorithm rather than a separate
> debouncing step.  With the right encoding of the states you can do
> most of the testing and state transitions using btiwise operations, 8
> keys at a time (on a 32-bit processor you could do 32 keys at a time).
I'm curious: Why have an 8-bit counter for each key? That requires multiple counter increments at each tick. You could just have a single tick counter and copy the initial value as each key starts GOINGDOWN, and then subtract that from the final tick counter upon reaching the DOWN state. This requires handling the overflow of the tick counter, but that's not too hard, provided there is no way for the time to exceed the maximum count or your algorithm has some way to cap it out.

I suppose it is a little easier to have multiple counters, though, because each one can saturate independently at 255 without complicated detection for the extremely unlikely case that someone presses a key so slowly that the tick counter could overflow twice!

> I'll try and dig out the code and sling it up on github sometime.
> It's all in C, no assembler required.
Yeah, it's generally better to start in C for nearly everything. I only bother with assembly if I need a really high rate interrupt for something like an LED output matrix. The simpler the code, the easier it is to manage in assembly. Not sure that I'd want to start out writing a velocity-sensing algorithm in assembly!

Brian Willoughby
Sound Consulting




More information about the Synth-diy mailing list