Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: cat on Sun 09/09/2012 20:52:03

Title: Problem setting AudioChannel.Volume
Post by: cat on Sun 09/09/2012 20:52:03
Hi!

I have a function to ensure that the correct audio with correct level is playing when I enter any room. Now the problem is: when I lower the volume with the slider it works fine, even changing to a room with the same track but different attenuation works (3rd if-clause). BUT as soon as I change to a room with a different track, the volume is loud again (2nd if-clause).
Code (AGS) Select
function EnsureMusic(AudioClip* music, int attenuation)
{
   _currentAttenuation = attenuation;
   if (music == null)
   {
      CurrentMusic.Stop();
      CurrentMusic = null;     
   }
   else if (CurrentMusic == null || CurrentMusic.PlayingClip != music)
   {
      if (CurrentMusic != null)
         CurrentMusic.Stop();
      CurrentMusic = music.Play(eAudioPriorityNormal, eRepeat);
      CurrentMusic.Volume = ValidVolume(_musicVolume - attenuation);
   }
   else if (CurrentMusic != null)
   {
      CurrentMusic.Volume = ValidVolume(_musicVolume - attenuation);
   }
}


_musicVolume is only set when I change the slider. Why does setting the volume not work?
Title: Re: Problem setting AudioChannel.Volume
Post by: Calin Leafshade on Sun 09/09/2012 20:57:51
This is a bug with relation to the fading.

If a fade is set it will override your volume.

So line 13 causes the clip to play and then line 14 sets the volume
but then the volume is set to 0 again by the engine and the music is faded up to full volume.

So just disable the fading and handle it manually.
Title: Re: Problem setting AudioChannel.Volume
Post by: cat on Sun 09/09/2012 21:05:42
Ok, without fading it works correctly. Thanks!