Fading in music?

Started by auriond, Wed 15/11/2006 06:35:53

Previous topic - Next topic

auriond

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

Scorpiorus

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... ?

auriond

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!

Scorpiorus

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:

  • unfortunately there is no GetMusicMasterVolume() command in AGS, so I used VOLUME instead. VOLUME can be a global variable to hold the current music volume; you change it along with using SetMusicMasterVolume:

    VOLUME = 80;
    SetMusicMasterVolume(VOLUME);

    ...instead of just "SetMusicMasterVolume(80);" to make sure they match

  • it will start to fade-in but not from 0 in volume; that's how the music volume system works in AGS. You can probably try to fix this by setting the Music volume adjustment option to "quietest" in the Room pane.

    QuoteThen 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.

    Yeah, I guess something like doing StopMusic() before/after PlayVideo() should do the trick.

    QuoteI 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!

    No problem, you may probably need to experiment with the actual length of the silent track (AGS music player may not always work correctly with very short tracks, so you can make it a bit longer and use SeekMP3PosMillis() to get to the very end of the track), and let us know how it turns out :)

SMF spam blocked by CleanTalk