WP8 - SetChannelVolume has no effect on audio.

Monkey Forums/Monkey Bug Reports/WP8 - SetChannelVolume has no effect on audio.

SLotman(Posted 2014) [#1]
I have a small function in my libs to change the sound volume globally in my games:

Function setAudioVol(vol:Float)
   Config.audioVol = vol
	For Local f:Int=0 To MAX_CHANNELS
		SetChannelVolume f, vol
	Next
End Function


It is working pretty well on most targets - but on WP8 it does nothing!
Tested both on emulator as in a Nokia 620 - it gets more noticeable on Nokia at the max volume.

I set the volume in the 0...1 interval - and no change is made to it, unless its zero (then no sound is played, but that could be my library, that skips the sound playing altogether when volume=0)

Setting music volume works (kind of - see notes below), which makes me wonder what could be going on.

PS1: I just found out something else: if music played is set to loop, and app looses focus (I kept holding the back key until the game is 'minimized') and regain it - calling "ResumeMusic" on OnResume resumes the music... but it won't loop, and when reaching the end, the music stops. (Only on WP8, other targets works) - music volume also appears to reset.

PS2: Music also has a strange volume: I can't hear anything if music volume gets below 0.5... other targets works appropriately.

I would love to release my 'When Pigs Fly' game on WP8 - but that is stopping me from doing so :(


marksibly(Posted 2014) [#2]
Fixes/kludges coming!

The music volume <.5 issue is weird - On my HTC-8S, I can still *just* hear music at volume <.5, but music volume is definitely on some weird scale.

I've come up with a half-assed kludge for this that makes music volume behave more like sound volume, but its still not quite the same. Still, should be good enough...


SLotman(Posted 2014) [#3]
Thanks Mark! Can't wait to test those :)

PS: Would it be possible to add a #TARGET_NAME on Monkey? I'm getting a cel with Firefox OS to test things, and being able to differentiate regular html5 from the "FirefoxOS target" I'm building would be great! (And could also be used to differentiate between Windows 8 and Windows Phone 8 in the "winrt" target!)


SLotman(Posted 2014) [#4]
I think I fixed the SetChannelVolume thing! There was nothing implemented on it!

This works for me:
int gxtkAudio::SetVolume( int channel,float volume ){
	this->masterVoice->SetVolume(volume*0.25f); // don't know why this, but on real phone it works better...
	return 0;
}

(Probably not a proper fix, since I'm not considering the channel... but at least it works for my purposes)

Maybe this is a proper fix? (Edit: doesn't work on real device...)
int gxtkAudio::SetVolume( int channel,float volume ){
	gxtkChannel *chan=&channels[channel];
	if (chan)
		if (chan->voice) { chan->voice->SetVolume(volume); }

	return 0;
}


Now only left is the music volume thing and why when the game is resumed, music won't keep looping...


SLotman(Posted 2014) [#5]
I take back what I said about the "proper fix" - it seemed to work in the emulator, but it doesn't in the real thing. So I am back to the first one, which ignores the channel, but it works (but I assume it sets the volume globally not for a single sound?).

I also made a quick "hack" in the music volume:
int gxtkAudio::SetMusicVolume( float volume ){
	mediaEngine->SetVolume( volume*0.80f + 0.20f );
	return 0;
}

With this when setting music volume to zero I can still hear something very faint... but only when I get the phone speakers really close to my ears - and even then, its hard to hear - so for now, I'll use that ^_^


SLotman(Posted 2014) [#6]
Got the music "not looping" fixed:

int gxtkAudio::ResumeMusic(){

	if( musicState!=2 ) return 0;
	
	mediaEngine->SetLoop( musicLoop ); // fixes non looping after losing focus
	mediaEngine->Play();
	
	musicState=1;
	
	return 0;
}



SLotman(Posted 2014) [#7]
Also, I'd like to suggest something: a #WINRT_PUBLISHER_ID setting (or something like it) in Monkey, so we don't have to alter the target, or the WMAppManifest.xaml each time a new project is created.


marksibly(Posted 2014) [#8]
Hi,

Just uploaded v78a with fixes for these issues.

You shouldn't have to pause/resume music inside OnSuspend/OnResume - and you don't on Windows 8, only Windows *phone* 8 (could they have named all these platforms any more confusingly?!?). Windows phone 8 pauses OK, just doesn't resume, so I've hopefully fixed that now.

The wacky music volume issue is again unique to Windows phone 8 - on Windows 8 it seems to work OK 'as is'. I've kludged Windows phone 8 by using Sqrt( volume ) internally, which seems to work pretty well.