-
Notifications
You must be signed in to change notification settings - Fork 425
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
Use decibel scaling for volume control #6490
base: master
Are you sure you want to change the base?
Changes from 1 commit
f0a489f
ef5a892
41ec0a8
38e105d
2b61198
998f687
370a49c
590d1d0
8ea57e8
844989f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,7 @@ public class VolumeScaler | |
public const double MIN = -60; | ||
public const double STEP = 0.5; | ||
|
||
private static readonly double ln_ten = Math.Log(10); | ||
private const double k = ln_ten / 20; | ||
private const double k = Math.Log(10) / 20; | ||
|
||
public readonly BindableNumber<double> Real; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call these There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this "real" one looks like it should not be externally mutable. should either be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I was hoping it would remain mutable so that we aren't deciding on a developers' behalf which they choose to use. Both may have valid use cases, depending on how you're audio engineeringing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, as long as it's not possible to break the instances of this into complete nonsense by setting both to random values and putting it in a completely invalid state |
||
public readonly BindableNumber<double> Scaled = new BindableNumber<double>(1) | ||
|
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.
constant declarations must use compile-time constants on the rhs of the assignment. this can't work with
const
, it must bestatic readonly
. are you even compiling this code?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.
My bad
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 kinda still want
k
to beconst
. I guess that's why I went with the numeric literal to begin with.const
will get embedded into the IL code wherever it's used, whereasstatic readonly
requires a memory lookup each time it's accessed.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.
please actually profile this and get back to me. i am 99% confident this will not be measurable. i prefer non-obfuscated code over pedantically marginal performance 'gains'.
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.
If you like, I can change the name of the variable from
ln_ten
to something that's more readable.But if the code is decently readable either way, why use the slower version, regardless of how pedantically marginal the difference may be?
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.
there is no solution with the const that i would consider more readable than just writing out what the number is
but i also have no time nor patience to continue this discussion
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.
Make is
static readonly
or close the PR.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.
Certainly. I apologize if I came across as confrontational. I'm just trying to have a discussion about your coding philosophies and the reasons behind them.
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.
It's pretty simple: storing one value to memory that is going to take up 8 bytes is not a concern and shouldn't lead to discussion. By using it we don't have to figure out what a random constant decimal number is and check whether it's correct.
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 think I see what you're saying. I figured if I just gave the variable a good enough name, describing what it's supposed to represent, then everything would be fine, but at the end of the day, there's still this big ugly numeric literal sitting in the middle of the code and it's a bit unsightly.