Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: auriond on Wed 15/11/2006 06:35:53

Title: Fading in music?
Post by: auriond on Wed 15/11/2006 06:35:53
I'm sure this must have been discussed somewhere, but for the life of me I can't find it!

Is there any way that I can do a script that fades in music when it is first played? I'm using .ogg files that loop over several rooms, but because I want them to loop seamlessly, upon entering the room for the first time the music tends to start rather abruptly. Crossfading doesn't work for me because in between rooms I sometimes have video cutscenes.

The closest solution I have found is:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=14668.0

but that's only for implementing in one room. Is there any way I can do this globally, i.e. fade in music when it is first played throughout the game?

Hope I was able to express that clearly enough... I tend to lack vocaulary when I need it most  ;D
Title: Re: Fading in music?
Post by: Scorpiorus on Wed 15/11/2006 15:03:48
So, basically you are looking for a way to fade-in a digital music track, right?

Can you elaborate on why does the crossfade music feature not work for you when a video cutscene is there?


To fade-in a track you can try adding a short silent music file and use it to crossfade:

music111.ogg --> just 2-3 seconds (or so) of silence

Then playing the next track making it fade-in:

StopMusic(); // just in case
PlayMusicQueued(111); // fade-out it (actually silence)
PlayMusicQueued(music_to_fadein); // fade-in

Crossfading must be turned on, of course.

Quotebut that's only for implementing in one room. Is there any way I can do this globally, i.e. fade in music when it is first played throughout the game?

I believe it can be done so, but I'm not quite sure what you mean with "fade in music when it is first played throughout the game". Does it play only once, or does it repeat after a period of time but you want a fade-in just for the first time it starts to play, or... ?
Title: Re: Fading in music?
Post by: auriond on Wed 15/11/2006 22:38:13
Quotedoes it repeat after a period of time but you want a fade-in just for the first time it starts to play

Yes, that's exactly what I meant, thank you for rephrasing it. I have a faint idea of how to do it for one room, but I would rather have something I can put in the global script once and then use the music normally.

Crossfading doesn't work with the video because, for example, my title screen (room #1) uses music #1. Then the opening video comes in, with some silence at the end of the video. Then when it finishes, somehow the music for the title screen will come on again before crossfading to room#2's music. Could be how I set up the music to start/stop though. I'll fiddle around with it a bit more.

I didn't think of using the silent track idea - I'll try that now and see how that works :) That might just be the quick workaround I'm looking for. Thanks Scorpiorus!
Title: Re: Fading in music?
Post by: Scorpiorus on Thu 16/11/2006 09:24:08
Quote from: auriondI have a faint idea of how to do it for one room, but I would rather have something I can put in the global script once and then use the music normally.

Well, first of all, you may probably need a global script to do that music fade-in effect, in case you will prefer this scripting method over the silent track one:

main global script:

int FadeInMusic_volume = -1;

function FadeInMusic( )
{
   FadeInMusic_volume = 0;
}


function repeatedly_execute_always( )
{

   if (FadeInMusic_volume >= 0)
   {
      FadeInMusic_volume++;
      SetMusicMasterVolume( FadeInMusic_volume );

      if (FadeInMusic_volume >= VOLUME)
      {
         SetMusicMasterVolume( VOLUME );
         FadeInMusic_volume = -1;
      }

   }

}

script header:

import function FadeInMusic();

Then, you are to invoke the FadeInMusic() function from within wherever you need, including the global and/or room scripts. One possible way is to put it just after the PlayVideo function to fade-in right after video cutscene.

This scripting approch is not perfect too: