-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fix shifting of sample waveform during zoom #7222
Conversation
The original code was doing division in `int`, which causes lost of accuracy and results in the waveform randomly shifting when zooming in and out. This should fix it by casting variables to `float` before dividing, as well as keeping the values in `float` type. The pull request also changes some type declaration to explicit to increase readability
Why were the type declaration changes removed? I see @Veratil mentioned going back to |
I did mean the part mentioned only, but that's fine if we want to specify. |
Sorry for the previous weird changes, I misunderstood some of the conversations in the review. Should I change all primitive type declarations to explicit this time @sakertooth ? |
For clarity as to what the types are, I would say yes. It's important here because we do a lot of arithmetic, so we need to be careful to avoid truncation when dividing, thinking variables are in a certain type when they aren't, etc. The use of |
@sakertooth I think it's still better to make all primitive declarations explicit, even though it doesn't seem necessary. It can help detect more bugs, and make future code changes easier in general, in this case the arrival of sample caching. I'll go ahead and make all primitive type declarations explicit. For the variables created from the |
Sorry for causing the back and forth churn. :) |
Yes, this is what I mentioned 🤣 I was in agreement in making the primitive declarations explicit for the same reasons. |
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.
After the discussion in Discord, keeping them auto
is fine, but if you want to specify the type here, that's fine too (as long as there are no implicit conversions, which I believe you mentioned there weren't any).
The original code was doing division in
int
, which causes loss of accuracy and results in the waveform randomly shifting when zooming in and out.This should fix it by casting variables to
float
before dividing, as well as keeping the values infloat
type.