Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Ali on Tue 19/06/2018 15:46:24

Title: Problem setting audiochannel volume.
Post by: Ali on Tue 19/06/2018 15:46:24
I'm playing music by calling a function called playMusicContinuous, which is supposed to check the level of the volume slider (MusicVol). Except it doesn't work. When I lower the slider to 0, the music cuts out, but when I enter the next room, it plays at normal volume.

In the GlobalScript I have:
Code (ags) Select
function playMusicContinuous (AudioClip* clip){
  channelMusic = clip.PlayFrom(musicPos[cN.Room], eAudioPriorityNormal, eRepeat);
  channelMusic.Volume = MusicVol.Value;
}



In the room script I have:

Code (ags) Select
// script for Room: Player enters screen (after fadein)
playMusicContinuous (aMusic1ogg);


The volume is not set correctly. This doesn't work either:

Code (ags) Select
// script for Room: Player enters screen (after fadein)
playMusicContinuous (aMusic1ogg);
Wait(1);
channelMusic.Volume = MusicVol.Value;


But this DOES work after playing for a few seconds:

Code (ags) Select
// script for Room: Player enters screen (after fadein)
playMusicContinuous (aMusic1ogg);
Wait(150);
channelMusic.Volume = MusicVol.Value;


Does that make sense to anyone?
Title: Re: Problem setting audiochannel volume.
Post by: Snarky on Tue 19/06/2018 15:52:44
The obvious questions are what MusicVol.Value is, where its value is set, and if you've checked that it has the value you assume when you use it to set the channelMusic volume.
Title: Re: Problem setting audiochannel volume.
Post by: Ali on Tue 19/06/2018 16:03:01
Yes, MusicVol.Value is 0 throughout.

If I do this:

Code (ags) Select
playMusicContinuous (aMusic1ogg);
channelMusic.Volume = MusicVol.Value;
Display (String.Format ("MusicVol: %d", MusicVol.Value));
channelMusic.Volume = MusicVol.Value;


It mutes the music only after displaying "MusicVol: 0". Just like before, setting the volume only works when there's some kind of delay.

EDIT: I have given up on making sense of this, and am using Game.SetAudioTypeVolume(eAudioTypeMusic, MusicVol.Value, eVolExistingAndFuture) instead. It would be very helpful in the help document if SetMusicVolume redirected to this function instead of AudioChannel.Volume.
Title: Re: Problem setting audiochannel volume.
Post by: Snarky on Wed 20/06/2018 18:55:51
Yeah, sorry, I have no clue either.
Title: Re: Problem setting audiochannel volume.
Post by: morganw on Wed 20/06/2018 19:57:03
Are you accidentally cross-fading with yourself, and 150 ticks is enough to clear the cross-fade duration?
Title: Re: Problem setting audiochannel volume.
Post by: Ali on Wed 20/06/2018 23:00:25
That is probably exactly what I'm doing. Crossfade is on. Good thinking!

But it's not very intuitive. It's far from obvious that you can't set a channel's volume if it's currently fading.
Title: Re: Problem setting audiochannel volume.
Post by: Crimson Wizard on Wed 20/06/2018 23:12:28
Quote from: Ali on Wed 20/06/2018 23:00:25
But it's not very intuitive. It's far from obvious that you can't set a channel's volume if it's currently fading.

This was mentioned as an issue in another thread not long ago. Crossfade overrides volume, iirc forcing it to go from 0 to max.