Fade in out sound

Started by Flyman, Tue 17/01/2012 20:46:19

Previous topic - Next topic

Flyman

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!

Moogle

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);
}

}

}

Khris

Are you kidding us? What the hell is that supposed to be?

Please don't post completely broken code.

Moogle

If you talking about me, I was just trying to help. :=

Or if your talking to him then, I don't...

Khris

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

Moogle

Im sorry Khris. I thought it would have worked. :-\

monkey0506

#6
No. Seriously. You thought that this would work?

Code: ags
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...

Code: ags
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.

Dualnames

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.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Flyman

Hi, I will thanks all!!
I'm used ags version for  sound

SMF spam blocked by CleanTalk