Skip to content

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.

@Jaduplex
Copy link
Contributor

Jaduplex commented Sep 9, 2024

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

@Jaduplex
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

@Jaduplex
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)

@Geokureli
Copy link
Member

I'm taking all non-breaking changes off 6.0.0, but I promise i'll get to this on the next release

@Geokureli Geokureli modified the milestones: 6.0.0, Post 6.0.0 stuff Jan 30, 2025
@Geokureli
Copy link
Member

Geokureli commented Apr 21, 2025

untested, for now, but this should account for group volume, sound tray volume, fade volume and individual sound volume. Also, before i didn't like that it transformed the public volume to something different than what it was explicitly set to

@Geokureli
Copy link
Member

Geokureli commented Apr 21, 2025

I'll be honest, I still don't get this logarithmic sound curve. I messed with a few apps and yeah, it seems like spotify and mac use logarithmic, but youtube doesn't. In my tests, I fucking hate the log ones and completely disagree with that article's assessments (assuming this follows that). For example

This means that we are much more sensitive to small variations in amplitude for silent sounds than for loud sounds

Using your log curve vs the old linear curve made no difference in whether I could distinguish a difference in volume, every increment sounded distinct, but lower volumes sounded far, far less distinct using the log curve, where linear, to me, seemed like each increment was as distinct as the others.

The perceived maximum volume level is reached around the middle of the slider, making the upper half useless

IMO the left side of the slider is useless in logarithmic, my spotify has never gone below 50% and in the example given in the article I can't hear the sound until I'm at 50% despite my system volume being at max. The linear slider in the example does seem to have little effect on the right half, but this is not my expereince with the flixel sound tray. Where .8 seems "loud" .9 seems "too loud" and 1.0 seems "way too fucking loud" in my opinion. This makes me wonder if openfl uses some underlying non-linear curve, already. I only tested this on html5, btw I assume all target behave the same, but that has been a bad assumption, in the past

Maybe this is just a personal preference, So I made it easy to customize the global sound curve, but I'm keeping the default as it was

Lastly:

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"

This isn't how any of the examples work and I don't understand why setting the sound to 0.5 should sound differently to incrementing the sound to the halfway mark

@Geokureli
Copy link
Member

I'm down to revisit this, later. I still feel like there's something I'm not grasping. but hopefully this lets everyone do what they want, for now

@Geokureli Geokureli merged commit b99e311 into HaxeFlixel:dev Apr 21, 2025
11 checks passed
@Geokureli Geokureli changed the title logarithmic volume control for global soundtray / volume Customizable volume curve Apr 21, 2025
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