Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Velocity curve #1

Open
floretan opened this issue Aug 10, 2016 · 0 comments
Open

Velocity curve #1

floretan opened this issue Aug 10, 2016 · 0 comments

Comments

@floretan
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant