keyboard icon indicating copy to clipboard operation
keyboard copied to clipboard

Velocity curve

Open floretan opened this issue 8 years ago • 0 comments

I recently finished a teensy-based keyboard similar to yours, and your code was quite helpful. Since you mentioned issues with the velocity curve, I thought I would share my findings which gave very natural results with a bit of tweaking.

The keyboard matrix I had was different, and I also used a shift register and different wiring, so the code is different, but here's the important part:

velocity = 127 - log(interval/shortestInterval) / log(2) * velocityAttenuation;

Where shortestInterval is the time interval between the two switches when hitting a key as fast as I could, and velocityAttenuation is by how much to reduce the velocity when the time interval is doubled. The division by log(2) is just to get a log base two since arduino doesn't provide that function natively.

In my case the shortest interval is set to 2000 microseconds, hitting the keys with that interval gives me a MIDI velocity close to 127. I set velocityAttenuation to 20, so if I hit the keys a bit less hard and get an interval of around 4000 microseconds, then the MIDI velocity is around 107 (127 - 20). 8000 microseconds gives a velocity of 87, 16000 gives 67, etc. You can see the full code here: https://github.com/floretan/p150

Thank you for giving me a great head start, I hope this can be helpful to you too!

floretan avatar Aug 10 '16 20:08 floretan