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

Controlling how velocity impacts note volume #92

Open
iplanwebsites opened this issue Sep 29, 2024 · 5 comments
Open

Controlling how velocity impacts note volume #92

iplanwebsites opened this issue Sep 29, 2024 · 5 comments

Comments

@iplanwebsites
Copy link

Thanks for yet another fantastic library.
I really like the variety samples used for the different velocities, it's especially great on the SFZ piano.
I was wondering how we could control the note velocity -> volume function.
Currently, the volume delta is very big and low velocity notes are often almost silent.
A basic, easy to implement , approach could be to set min and max volume thresholds. Normalizing input velocity might also have a similar effect in practice, but it wouldn't benefit from those multiple velocity samples.

@github-staff github-staff deleted a comment Sep 29, 2024
@danigb
Copy link
Owner

danigb commented Sep 30, 2024

Hey, thanks for the kind words.

I'm not sure if this is what are you looking for, but there's this volumeToGain option that accepts a function that receives a volume level and return a gain value. See https://github.com/danigb/smplr?tab=readme-ov-file#shared-configuration-options

By default it uses MIDI recommendation on how to convert 127 level value to gain

@iplanwebsites
Copy link
Author

Thank you! I see how volumeToGain is replacing the default midiVelToGain function. I'll have a closer look.

@iplanwebsites
Copy link
Author

Ok, it's not in the docs, but there's the function velocityToGain can also be passed as an option to the sampler and the piano. That's the one that matters to adjust volume based on velocity.

 // ugly example of a custom curve that sounds decent on my midi device.
 function velocityToGain(vel) {
  const classicCurve = (vel * vel) / 16129; // 16129 = 127 * 127  ///official one.
  const RATIO_VEL = 0.9;
  const MIN = 0.3;
  const MAX = 1.0;
  const computer = (vel / 127) * RATIO_VEL + 1 - RATIO_VEL;
  return Math.max(MIN, Math.min(computer, MAX));
  }

@danigb
Copy link
Owner

danigb commented Oct 6, 2024

What you mean is not in the docs? Is this issue fixed?

@iplanwebsites
Copy link
Author

iplanwebsites commented Oct 6, 2024 via email

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

2 participants