WinPhone8 - Music Volume

Monkey Forums/Monkey Bug Reports/WinPhone8 - Music Volume

dragon(Posted 2014) [#1]
I think here is something wrong with MusicVolume in WinPhone8

Volume 1.0 is loud
Volume 0.5 is not 50% - is is something like 5%

So i think the volume is not linear or so...
This is different to other targets...


SLotman(Posted 2014) [#2]
Take a look here: http://www.monkeycoder.co.nz/Community/posts.php?topic=7960


dragon(Posted 2014) [#3]
i used v78a
and have this problems
at the moment i changed music volume with mp3gain


marksibly(Posted 2014) [#4]
I have no idea what's happening here - it works OK on Windows RT/desktop/what-the-hell-are-we-meant-to-call-it 8. I've asked on MSDN but the chances of getting a useful response there are pretty minimal.

I attempted to kludge around the issue in v78a, but listening to it now, it's better but still sucks. About all I/we can do is play around with the kludge - the appropriate bit of code is lines 1485-1487 in mojo.winrt.cpp:

#if WINDOWS_PHONE_8
	volume=sqrtf( volume );
#endif


The goal is to map values in the range 0..1 to 0..1 in a way that 'boosts the curve' (I guess). Playing around with it now, I think this is an improvement:

#if WINDOWS_PHONE_8
	volume=pow( volume,.2 );
#endif


To my (admittedly pretty heavily abused!) ears, .3 and .1 are both 'too much' in either direction.

Any advice/ideas most welcome...


SLotman(Posted 2014) [#5]
Mark,

As I posted in the thread where I raised the bug, I'm using this:
mediaEngine->SetVolume( volume*0.80f + 0.20f );


Don't know why, but it's the best "proportion" I could find. I read somewhere that this value isn't exactly volume, but attenuation.
Ah, just found some info:

Volume is expressed as an attenuation level, where 0.0 indicates silence and 1.0 indicates full volume (no attenuation). For each channel, the attenuation level is the product of:

The master volume level of the audio session.

The volume level of the channel.

For example, if the master volume is 0.8 and the channel volume is 0.5, the attenuaton for that channel is 0.8 ? 0.5 = 0.4. Volume levels can exceed 1.0 (positive gain), but the audio engine clips any audio samples that exceed zero decibels. To change the volume level of individual channels, use the AudioStreamVolume interface.

Use the following formula to convert the volume level to the decibel (dB) scale:

Attenuation (dB) = 20 * log10(Level)

For example, a volume level of 0.50 represents 6.02 dB of attenuation.



Maybe that's the answer? Can't test it today unfortunately...


marksibly(Posted 2014) [#6]
Well, I got a response on MSDN:


Hello,

The volume control is a logarithmic function of the decimal value. You should be able to easily convert from the logarithmic function to a linear function.

Here is a quick search that will hopefully help to get you started:

http://www.bing.com/search?q=convert+from+logarithmic+to+linear+&qs=n&form=QBRE&pq=convert+from+logarithmic+to+linear+&sc=0-0&sp=-1&sk=&cvid=bbb89d1385b846bc9109b6759d706763

Thanks,
James



Umm...OK.

Any ideas?


SLotman(Posted 2014) [#7]
What about this:
mediaEngine->SetVolume(0.50 * pow (10, volume / 2.0f) );


From what I could find, Gain should be:
Gain = ref. value * 10 ^(volume / 20)

I "guessed" the ref. value at 0.5 - and reduced the 20 to 2.0 (since we're working in the 0...1 range) - tried here in my phone, doesn't sound too bad...


marksibly(Posted 2014) [#8]
> mediaEngine->SetVolume( volume*0.80f + 0.20f );

IMO, volume at 0.5 is too quiet.

> mediaEngine->SetVolume(0.50 * pow (10, volume / 2.0f) );

IMO, volume at 0.5 is too loud!

My favorite is still pow( volume,.2 ), basically purely on the fact that volume at 0.5 sounds 'about right' to me.

I've also tried log( volume+1 )/log( 2 ) which should convert linear->log range, but again volume at 0.5 is way too quiet.


SLotman(Posted 2014) [#9]
Are you trying those purely in the emulator, or in a real device...? The emulator seems completely different from what I hear on my Lumia device!


marksibly(Posted 2014) [#10]
I'm testing on an HTC 8S. Haven't tried the emulator...

For a test app, I modified audiotest so you can tap to increase/decrease music volume.

Perhaps a better test would be to be able to tap-to-toggle between a looping sound and looping music?


SLotman(Posted 2014) [#11]
On my game is exactly what I'm doing - while the options screen is visible, there's music being played in background.
Also, volume for sounds works ok here - just the music volume that is really weird...


Erik(Posted 2014) [#12]
I would need a fix for this as well, we don't use volume control, just on/off, so the important thing is that volume 1.0 sounds the same.


smilertoo(Posted 2014) [#13]
It's probably not helped by wp8 being buggy as far as volume control is concerned; my phone no longer changes volume unless you change the music file you're playing.


marksibly(Posted 2014) [#14]
Volumes 0 and 1 should work OK - it's just the values in between we're having problems with!

Are you having some sort of problem with volume 1?


Erik(Posted 2014) [#15]
No, sorry, I forgot that I had it at 0.5 as default.


LinderBoss(Posted 2014) [#16]
I'm testing with V78e and WP8 but it fails to compile.
gxtkAudio::SetMusicVolume() has a little syntax error here (extra parentheses):

#if WINDOWS_PHONE_8
// volume=pow( volume,.2 );
volume=0.50 * pow (10, volume / 2.0f) ); <<<< here
#endif


dragon(Posted 2014) [#17]
// volume=pow( volume,.2 );
volume=0.50 * pow (10, volume / 2.0f) ); <<<< here

both do not look right for me

what about this?
LOG10(volume * 9 + 1)

this give me following values:
0 =0
0,1 =0,278753601
0,2 =0,4471580313
0,3 =0,5682017241
0,4 =0,6627578317
0,5 =0,7403626895
0,6 =0,806179974
0,7 =0,8633228601
0,8 =0,9138138524
0,9 =0,9590413923
1 =1




note:
You can calculate logarithms to any base (n) for any number (x) by dividing the natural logarithm of x by the natural logarithm of n, as follows:
Log n(x) = Log(x) / Log(n)

so you can fine tune the "curve"


For example "LOG100" is more strong

LOG100(volume * 99 + 1)
0 =0
0,1 =0,518713249
0,2 =0,6590316675
0,3 =0,7435691877
0,4 =0,8042630168
0,5 =0,8516456891
0,6 =0,8905184693
0,7 =0,9234776625
0,8 =0,9520871841
0,9 =0,9773623955
1 =1



marksibly(Posted 2014) [#18]
I had another look at this and Pow( volume,.1 ) seems to work very well.

To verify, I disabled the volume kludge in mojo.winrt.cpp and used the small test app below to compare music volume with sound volume. The app will need happy.wav in the app data dir...

Touch center of device to cycle between sound/music volume, left side of device to reduce master volume and right side of device to increase master volume.

To my ears, the app gives good results - ie: sound and music volumes sound about the same. Internally, it uses Pow( volume,.1) to achieve this. Note that this gives a pretty extreme 'curve', eg: you need to set music volume to .9ish to achieve the same result as setting sound volume to .5!

Can someone else actually try this and verify it's a 'good enough' fix? And please only try on an actual phone (I have an HTC 8S) - no idea/don't care what an emulator does.

> LOG10(volume * 9 + 1)

Feel free to try with the test app, but I think Pow( volume,.1 ) will be hard to beat.




marksibly(Posted 2014) [#19]
Anyone?


dopeyrulz(Posted 2014) [#20]
Having a look now on my Lumia 920...


dopeyrulz(Posted 2014) [#21]
On my phone the .1 does sound slightly better in respect of overall volume especially the lower end.


Erik(Posted 2014) [#22]
I tweaked this a lot before release, I just looked at the code and I ended up using volume=pow( volume,.2f );

I just tested with volume=pow( volume,.1f ); and it does indeed sound better.


marksibly(Posted 2014) [#23]
Thanks - will stick with this solution for now.


Xaron(Posted 2014) [#24]
Thanks Mark but please fix the compiler error. ;)

#if WINDOWS_PHONE_8
//	volume=pow( volume,.2 );
volume=0.50 * pow (10, volume / 2.0f) );	<<<< here
#endif