-
Notifications
You must be signed in to change notification settings - Fork 270
feat: Allow logarithmic amplification (needs input on API) #715
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
Conversation
This is my first contribution on this crate. Just checking in with you about the general approach for this. Is it ok? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the choices you made however I think we can do better. Let me know what you think of the feedback.
Further more did you look at the resource Roderick linked in the issue? It features a slightly more involved calculation that leads to a nicer volume curve. We could use that instead or have both the current log and that nicer one.
Yeah I wanted to keep myself in the same page with you. I just skimmed through the article I will check it out. Thanks for review |
You can look at the code I linked to, which compresses that article into 10 lines of code. You can copy and/or modify those lines from me under public domain. |
@roderickvd Do I add this to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at source/mod.rs
. Do we want a amplify_decibel()
in there?
I would also add it to amplify. But you are right, there are many places we deal with volume atm, we will probably want it there too. |
This is why I liked @PetrGlad's suggestion here: #714 (comment) If we just add such public helper methods, then the user can plug it where-ever they want. |
So maybe we keep |
The main issue I'm having here is that I don't understand how I fit the mapping that @roderickvd suggested into the |
Maybe we need to sketch out & agree on the API first. To me, // Direct linear gain
sink.set_volume(1.5); // amplify by 150%
source.amplify(0.5); // attenuate to 50%
// Using decibels
sink.set_volume(db_to_gain(6.0)); // +6 dB
source.amplify(db_to_gain(-3.0)); // -3 dB
// Using normalized with logarithmic scaling
sink.set_volume(norm_to_log_gain(0.5)); // 50% perceived volume
source.amplify(norm_to_log_gain(0.75)); // 75% perceived volume |
The thing I like about the |
Terms
Funny, to me setting volume and amplifying are different :) Lets see what kind of terms we got:
The name of
Yes I get that. That makes sense from a programming standpoint. On the other hand human hearing is logarithmic so linear amplification is generally not the best from a UI perspective and thus should not be the default. Helper vs UI
That would make it clear that decibels is just another way of expressing that amplification factor. On the other hand its not super discoverable and using a factor would still be the default. this: some_source
.pausable()
.fade_in(Duration::from_secs(60))
.amplify(to_linear(10));
other_source
.pausable()
.fade_in(Duration::from_secs(60))
.amplify(1.1); is to me less clear then: some_source
.pausable()
.fade_in(Duration::from_secs(60))
.amplify_by_db(10);
some_source
.pausable()
.fade_in(Duration::from_secs(60))
.amplify_by_factor(1.1); Its a difficult UI to get right.... |
I like the use of perceived there, maybe |
I agree with @roderickvd btw and I think we should keep going back and forth till we all agree we have the best possible API. |
Maybe it's best to close this and revisit it at some point later wdyt? I plan to help with refactoring on this crate. Is there any particular section you want me to work on? Feel like |
I see no reason to close this, we need a little more input to figure out the best API though. I'll mark it as help wanted and hope someone else chimes in. |
on sink? yes though that would be a breaking change affecting a lot of users. Since we already want to redo sink entirely I rather keep such a change till then. You could start doing that, but that will be quite difficult. A good starting point on it would be figuring out how to do proper cross-fade (see the user stories issue for what a proper cross-fade is). Maybe @roderickvd or @PetrGlad know whats a good issue to work on while we wait for more input on this. |
You know, I'd actually like to get agreement on the API and have @daalfox continue work on it. It's useful, not too hard, and has already begun, so let's also complete it. We just need agreement.
I also do not see the point of breaking the current API, although:
Because w.r.t. to your @dvdsk stating:
I don't disagree with that definition, but that's currently not what it does. They are the same today, and I don't recognize a need for So back to the API... I'm for not breaking the current API if we don't need to, and we don't need to. So it comes down to the question: do we want helper functions (less discoverable, easy to plug as arguments to the existing functions) or do we want new functions? Let's take it from there and then we can decide on naming. |
I have one more question, do we panic outside of [0.0, 1.0] range for normalized? |
We could also return a Result<(), OutOfRangeError>. That might be better since it would trigger users to read the docs :). Which would note the required range and have an Errors section pointing that out. |
agreed
I prefer new functions |
We’re talking about the 0-100% “volume slider” right? For ease of use we could also simply clamp and document that. |
yeah lets do that 👍 We should highlight the clamping behavior in the documentations example. |
Feel free to rephrase the documentations as you like. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot picking this up again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me! Ended up being quite a nuanced feature. Thank you for getting this through!
Yeah that was something. Thank you everyone |
missed something (no worries its the tiniest thing). This deserves a change-log entry! :) |
Done |
Awesome thanks for hanging out with us 👍 As one last improvement may I request that you reword the changelog statement of "better volume control" to be more specific like "perceptually linear"? |
🥳 |
Adds volume control in decibels discussed in #714