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

logarithmic volume control for global soundtray / volume #3248

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

ninjamuffin99
Copy link
Member

the global volume math is linear, however actual sound and dB stuff is NOT linear.
-10dB is NOT 10x quieter than -1dB for example

This PR changes specifically the GLOBAL volume control when using the soundtray. Changing via FlxG.sound.volume = 0.5 for example would scale it linearly as normal, however pressing the + and - keys will properly change the volume logarithmically to sound more "proper". Pressing - until it's about halfway will actually sound like the volume is set to half.

@CyndaquilDAC
Copy link
Contributor

THANK YOU. i KNEW something was up with the volume scale in the soundtray!!!

@Vortex2Oblivion
Copy link
Contributor

Could linearToLog and logToLinear maybe go in FlxMath instead of are they probably not going to get used

@CyndaquilDAC
Copy link
Contributor

Could linearToLog and logToLinear maybe go in FlxMath instead of are they probably not going to get used

I'm pretty sure this is just for DB purposes. If they were to go in FlxMath, they'd probably need more descriptive names.

@Vortex2Oblivion
Copy link
Contributor

I'm pretty sure this is just for DB purposes. If they were to go in FlxMath, they'd probably need more descriptive names.

Fair enough!

@Geokureli
Copy link
Member

Geokureli commented Sep 13, 2024

Do we have any examples of how other systems handle volume? I'm looking at wikipedia and I see that 10db is 10x the power 0db, and 20db is 100x, but do people expect that behavior with volume controls?

-10dB is NOT 10x quieter than -1dB for example

Can we talk specifically about a 1db sound played at certain volume levels? What currently happens and what happens with this change. the above sentence confuses me because you only talk about decibels, not volume levels, and -10db is 10x quieter than 0db so I'm not sure what point you're trying to make.

Also, I think this implementation is flawed, for a few reasons. Consider the following:

FlxG.sound.volume = 0;
FlxG.sound.changeVolume(0.5);
assert(FlxG.sound.volume == 0.5);// FAIL - volume is 0.0316227766016838

there's inconsistent behavior, now, between setting volume directly and changing the volume relatively.

If I'm smelling what you're stepping in, it sounds like, currently, a volume of 0.5 will play a 1db sound at 0.5db, which is not half the "power" and with this change, a volume of 0.5 will be half the power which is actually like -3db?

If I'm right, I still think we shouldn't change the value of volume to be non-linear, even under the hood, if anything we should have some getEffectiveVolume which is used when actually playing sounds, or maybe we set the openfl sound volume rather than the flixel sound volume

Perhaps here?

@Geokureli
Copy link
Member

Geokureli commented Sep 13, 2024

found this
image
Am I crazy or does windows behave the same way flixel does currently? not gonna lie it's hard for me to wrap my head around this stuff

@CyndaquilDAC
Copy link
Contributor

found this image Am I crazy or does windows behave the same way flixel does currently? not gonna lie it's hard for me to wrap my head around this stuff

if this is a breaking issue, maybe fully change how flxsound volume works as a breaking change in a major version update instead? the current linear scale is really annyoing (you have to change master volume SUPER low for it to be decently low) but inconsistencies like this arent great either.

@Geokureli
Copy link
Member

it might be a breaking change, but I figured we could could add a compile flag FLX_LOG_VOLUME and FLX_LINEAR_VOLUME, or even just have a global FlxG.sound.volumeTapering or something. im not worried about that, I'm just trying to suggest a different implementation

@ninjamuffin99
Copy link
Member Author

what are thoughts on a variable like scaledVolume, which if set, it will set to a properly logarithm calculated volume, while still maintaining the volume variable if someone wants to change the volume in the linear way.

So sound.scaledVolume = 0.5; will change volume and vice versa, so it can be changed without going through a math function directly, and you'd have easy access to both a scaled "auditory perceptive" volume, but also the actual linear volume value.

@Geokureli
Copy link
Member

Geokureli commented Sep 16, 2024

  1. I'm still not clear on the actual goal and problem, and 2. I still don't like where the conversion is being done.

on the first point:

Can we talk specifically about a 1db sound played at certain volume levels? What currently happens and what happens with this change. the above sentence confuses me because you only talk about decibels, not volume levels, and -10db is 10x quieter than 0db so I'm not sure what point you're trying to make.

either that or give me some kind of description of the experience you're currently having with sound and what you think should happen, like: "i think .5 volume is too loud, it seems more than half as loud as 1.0"

For the second point, I still say the conversion should not be done in FlxG.sound.volume, but rather here. this way we are applying the same curve for all FlxSound.volume, FlxG.sound.volume, FlxSoundGroup.volume and proximity sounds (though perhaps proximity sounds should have a different curve? I wonder how volume decreases in sounds based on distance)

Lastly, I tried out this branch, I honestly believe 0.5 is now far too quiet with this curve, most sounds I tried seem too quiet to hear at 0.3 volume or less. I graphed the curve of linearToLog and it looks like this:

Screenshot 2024-09-16 at 12 47 05 PM

The opposite of the curve that I see used elsewhere:

Screenshot 2024-09-16 at 1 04 52 PM

What makes intuitive sense to me, is that flixel volume curve should match our PCs' volume curves, so I'm going to record sounds with various speaker volumes and compare the db to playing a sound in flixel at various volume levels

@ninjamuffin99
Copy link
Member Author

ninjamuffin99 commented Nov 20, 2024

this post has good lil writeup about volume control, the interactive demo is particularly helpful

https://www.dr-lex.be/info-stuff/volumecontrols.html

also random testing of volume controls, i believe at the very least both:

  • macos volume control is logarithmic, volume change stepping between all the volume bars seems very consistent
  • spotify's volume control seems very consistent (tested on desktop app for mac)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants