-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
pygame.mixer.Sound.get_volume
returned value is not correct
#3090
Comments
pygame.mixer.Sound.get_volume
returned value is not correct
I suspect this is actually intended behavior. |
The docs could probably do with an update to make it clear that this 129-step volume behavior is the actual behavior |
Very misleading. |
We could instead keep track of a float volume internally and return that Suppose I wanted to set the volume based on the current volume and to get the current volume I'd use |
Can we be sure SDL isn't changing the volume internally anywhere for whatever reason? |
yes Line 1251 in b0d45d1
|
That's really not what I meant, unless I am missunderstanding, what if the user calls set volume and sets it to 0.5 but then sdl for whatever reason changes its internal value to 0.2, because, uhh driver issues, then we'd be returning 0.5 instead of 0.2. |
Andrew explained this here already #3090 (comment)
|
(not very related, but my complaint is very pointless, you can go on to fix it how you please) |
The docs should still probably be updated about the 129 intervals, just so users know. |
First of all, it's weird that's it 129 values (0-128), rather than 128 values (0-127). Given than 128 values is half of 256 values, it could be represented in 7 bits. Secondly I don't see this as a bug at all, and I think it's worse to lie to the user about what the volume is. |
If it is desirable to still be able to know the 'real' volume, then in the new implementation it should have its own separate method, which is much less prone to misunderstanding compared to the current implementation. |
A separate method for something like that sounds overkill to me. SDL3 will change the volume to a float meaning this proposed fix will become the real volume soon enough. |
It's not exactly a terrible idea, we could then introduce |
I agree with @Starbuck5 that we shouldn't lie to the user about what the actual volume is. Changing the existing behavior is likely not going to happen because it would break backcompat. I'm personally in favor of a docs update to clarify what actually happens when the user requests a specific volume |
I agree with @Matiiss that storing a float may be better, for various reasons. This new behavior is, in my opinion, not 'lying' to the user. It is more of a lie to not meet user expectations than it is to not match technical reality. The current behavior is unpythonic and prone to various errors, especially since the methods seem very basic at a glance. Anyone who deals with these methods must know and remember that Possible bugs include...
It might not completely break backwards compatibility because this behavior is not documented in pygame. It may be considered an implementation detail or subject to change because one should not totally rely on undocumented special behavior. Though these changes will have effects. |
SDL3_mixer has no plans that I can see to change this thing to a float. I said that on the PR as well but also posting here because we're having 2 separate discussions on the same topic.
No, they'll need to remember get_volume is not smoothly continuous, and only if they're using it to implement a lerp or a transformation across multiple volumes. Has anyone else ever raised an issue about this before?
Almost all pygame methods I know of return the actual stored values rather than faking it, even when that behavior has foibles, like Rects. One exception that comes to mind is mouse.get_cursor, where we store the state ourselves since the state getter was removed in SDL2. |
So if SDL is moving towards float volume for their API, maybe we should lobby SDL_mixer to do the same in the SDL3 transition period. Haven’t done the research on that myself yet. |
Yes, only a part of the mixers users would experience issues for this, but a nonzero number. Even if the issue is rare, that is not a reason really to keep the current behavior. The main thing is that I'm not that convinced on why we shouldn't change the implementation for its cons. I think one of the problems with the current implementation is that it is halfway between reality/internals (integer volumes) and the intuitive abstraction (float volumes). Pygame should go all the way on the float interface to avoid the problems of the implementation mismatch. |
As I understand from my research, the reason why volume is an integer 0-128 is because it is used on mainly integer-sample audio formats, to multiply or whatever. In SDL, the new float volume actually uses all of the precision for float audio formats, and rounds for integer formats (idk about SDL_mixer implementation, looks a lot different and it stores the volume). |
This issue is on MacOS Ventura, Windows 11 and Linux Manjaro, so probably everywhere.
If you run this code, the value retuned from
get_volume
is not0.1
or even0.0999
but0.09375
.The text was updated successfully, but these errors were encountered: