Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Flyman on Tue 17/01/2012 20:46:19

Title: Fade in out sound
Post by: Flyman on Tue 17/01/2012 20:46:19
After my object "Ufo" esc room I qant realize a fede out the sound of the flying ufo

I've set a initial:
PlaySound(125);
after my object move and animated at:
object[0].Move(420, 60, -2, eBlock, eAnywhere);
I've prove with "Fade out":
int vol = 100;
  while (vol >= 0) {
    SetSoundVolume(vol);
    vol--;
    Wait(1);
  }
but don't work...
what's wrong...how can set a fade in and a fade out for a sound?? HELP!
Title: Re: Fade in out sound
Post by: Moogle on Tue 17/01/2012 21:57:48
Try to make a Bool for Fadeout = (true/false);

function room_RepExec(){
if(Fadeout == true){
if(vol >= 1){
if(vol >= 0){
vol -= 1;
SetSoundVolume(vol);
   

}
else if(vol <= 0){//If it somehow goes below 0 then it should do nothing
vol == vol;
SetSoundVolume(vol);
}

}

}


if(Fadeout == false){
if(vol <= 1){
if(vol <= 0){
vol += 1;
SetSoundVolume(vol);
   

}
else if(vol >= 100){//If it somehow goes below 0 then it should do nothing
vol == vol;
SetSoundVolume(vol);
}

}

}
Title: Re: Fade in out sound
Post by: Khris on Tue 17/01/2012 22:48:39
Are you kidding us? What the hell is that supposed to be?

Please don't post completely broken code.
Title: Re: Fade in out sound
Post by: Moogle on Tue 17/01/2012 22:56:59
If you talking about me, I was just trying to help. :=

Or if your talking to him then, I don't...
Title: Re: Fade in out sound
Post by: Khris on Tue 17/01/2012 23:12:43
I was talking to you. And that's my point, helping is fine, but what you posted doesn't help at all.

Flyman:
The move command you are using is blocking so the sound won't fade out until after the object has stopped moving.
If I remember correctly you're moving the object 360 pixels across, at a speed of -2. This takes 720 frames or 18 seconds.
So you will only hear the sound fade out if it's longer than 18 seconds.

You might also want to use SetDigitalMasterVolume(), not SetSoundVolume (which accepts values from 0 to 255, not 100 btw.)
Title: Re: Fade in out sound
Post by: Moogle on Tue 17/01/2012 23:27:41
Im sorry Khris. I thought it would have worked. :-\
Title: Re: Fade in out sound
Post by: monkey0506 on Wed 18/01/2012 00:42:27
No. Seriously. You thought that this would work?

function room_RepExec()
{
  if (Fadeout == true)
  {
    if (vol >= 1)
    {
      if (vol >= 0) // this will NEVER be 0
      {
        vol -= 1;
        SetSoundVolume(vol);
      }
      else if (vol <= 0) // this will NEVER be called
      {
        vol == vol; // comparison...does NOTHING
        SetSoundVolume(vol);
      }
    }
  }
  if (Fadeout == false)
  {
    if (vol <= 1)
    {
      if (vol <= 0)
      {
        vol += 1;
        SetSoundVolume(vol); // this may be using a negative value for vol!!
      }
      else if (vol >= 100) // THIS WILL NEVER HAPPEN
      {
        vol == vol; // WHAT DO YOU THINK THIS IS DOING?!?
        SetSoundVolume(vol);
      }
    }
  }
}


Explain. Stripping out the code that will never be called...

function room_RepExec()
{
  if ((Fadeout) && (vol >= 1)) vol--;
  else if ((!Fadeout) && (vol <= 0)) vol++;
  SetSoundVolume(vol);
}


So basically if you're fading out, the volume is constantly decreasing, down to a minimum of 0. Fair enough.

But what is the purpose of the else clause there? It's ensuring that if you're not fading out and if vol is not at least set to 1...then it slowly increments it to 1. So that your code would make it impossible to set the volume to 0 when you're not fading out. What's the deal man?

From there, how about the fact that you very well could be passing a negative value into SetSoundVolume? Not cool bro. Oh, and as mentioned, SetSoundVolume only applies to SOUNDs in the old audio system. Sound volume, music volume, the master volume, they're all very different.

Add in the fact that your code is ridiculously complex for what it's doing, specifically does not work properly when not fading out, and still doesn't even address the true underlying problem that it was a blocking function call that was preventing the original code from executing...Khris was reasonably justified in his description of your code as "completely broken" and your post as "[not] help[ing] at all".

Definitely a nice gesture that you tried to help out, but you need to understand what your code is doing first.
Title: Re: Fade in out sound
Post by: Dualnames on Wed 18/01/2012 03:23:49
Right, I'm sure having nice intentions works, but sometimes, you have to make sure that whatever you're posting here, works in some way.

I want to ask if Flyman is using the new audio system. Or tell us the AGS version he's using. So we can provide a solution to fit his needs.

I do have a certain understanding that this post may be a bit obsolete, if you think about it.
Title: Re: Fade in out sound
Post by: Flyman on Fri 20/01/2012 09:51:03
Hi, I will thanks all!!
I'm used ags version for  sound