Fade in & Fade Out Audio

Started by Arjunaz78, Fri 28/10/2011 08:17:20

Previous topic - Next topic

Arjunaz78

How to make a sound or music fade in/fade out when playing in games?
I just refer to manual but got confuse to making it happen..
Then I just try to create the custom global variable like the manual and put the code like the manual show it,but it still not work correctly..besides I don't know to place or use the right code insteads...

Code: ags
longWindedSound = aExplosion.Play();


later on, elsewhere in the script, you can change the volume by doing:

Code: ags
if (longWindedSound != null)
{
  longWindedSound.Volume = 20;
}


The problem is..how to make the sound volume fade in or fade out until the tones reach 0 or 100%
volume?

also,i try put the code like below..but it's seems conflict with custom GUIs that i create it in the custom room intros,the GUIs become freeze & unclickable for just 2-3 seconds..and the sound just stop without fade in..

Code: ags

if (longWindedSound != null)
{
  longWindedSound.Volume = 20;
wait(40)
  longWindedSound.Volume = 10;
wait(20)
  longWindedSound.Volume = 0;
}
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Adrian

#1
In a quick search I found some threads dealing with this issue regarding fade in and out for objects, guis etc. but not sound in particular. So try this:

Code: ags

// Fade out:

int trans = longWindedSound.Volume;
while (trans > 0) {
  trans--;
  longWindedSound.Volume = trans;
  Wait(1);
}


// Fade in:

int trans = longWindedSound.Volume;
while (trans < 100) {
  trans++;
  longWindedSound.Volume = trans;
  Wait(1);
}


You can make the fade longer or shorter by changing the value of the wait command.

This would still block your gui, though.
If you want to fade in/out sound not blocking other functions, have a look at the Tween Module

Arjunaz78

Thanks mate..i will try it first..and i'll respond it ASAP..

THX.
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Snarky

Oh yeah, I forgot that the Tween module does volume as well. That's your best bet, every time.

Adrian

Quote from: Snarky on Fri 28/10/2011 15:44:15
Oh yeah, I forgot that the Tween module does volume as well. That's your best bet, every time.

Yes, tweening makes me happy!  ;D

Grim

I think I tried tweening volume before and it didn't work for me... If it works, that's the best news of the day! ( must  test it asap ... ;) )

I love Tween module 8)

Arjunaz78

Yes..unfortunately it doesn't work when i'm try too..however the Tween Module as a great one module..but not when setup for tweening volume,it seems the module have requiring additional code..but i'm weak on C++ programming..so i don't know which code need to be added..
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Khris

The module shouldn't need any additional code, and it isn't C++, it's AGS script.

What did you try, what code did you use, what didn't work? ::)

Adrian

Quote from: Tween Module manualPlease note that currently most of the functions for tweening music and sound effects are written with the old-style audio scripting system, which is the default up to AGS version 3.2.

If you're using AGS 3.2 or later and would like to use these functions, you have to set the "Enforce new-style audio scripting system" to False. Either way, the Tween module is compatible with AGS 3.2 or later versions.

Better audio support will (hopefully) come in a future version.

Arjunaz78

Before i use this Module,i've already set the "Enforce new-style audio scripting system" to False. (i'm using the latest AGS engine v.3.2.1)

Well I set the normal music channel on my normal room script like below (audio part is a red one):

Code: ags
// room script file

function room_AfterFadeIn()
{
 gIconbar.Visible = false;
     gStatusline.Visible = false;
     
    AudioChannel *channel = [color=red]aHappy2.Play[color](eAudioPriorityNormal, eRepeat);
    channel.Volume = 80;
    
        int trans = object[2].Transparency;
 while (trans <100) {
   trans++;
   object[2].Transparency = trans;
   Wait(1);
   object[3].Transparency = trans;
   Wait(1);
}
   mouse.UseModeGraphic(eModePointer);
    gViewIntro.Visible = true;
     gSkipIntro.Visible = true;
}

function on_key_press (int keycode)
{
   if (keycode == eKeyTab)
    ClaimEvent();
    }



Notice that the 'gViewIntro' & 'gSkipIntro' is the custom normal GUIs & when their visible the custom GUIs button with 'Intro' & 'Start' text appear..

Then the 'SIButton' (refer to GlobalScript below) actually is 'Start' GUIs button under 'gSkipIntro' normal GUIs..


Code: ags
function SIButton_OnClick(GUIControl *control, MouseButton button)
 {
 if (button == eMouseRight) {
 return;
 }

aNEW1.Play();

  TweenChannelVolume(3.0, 1, 80, 0, eEaseInTween, eNoBlockTween);
 
 gStartGame.Visible = true;
 
  gSkipIntro.Visible = false;
   gViewIntro.Visible = false;
   
}


The 2nd room is actually the custom GUIs room that include the menu for option to 'start game' & 'load game' etc..then i try change the custom GUIs room scripts on GlobalScript.asc like above..what i want is the audio fade in when i click on the 'Start' GUIs button and then continue fade in when reach the 2nd room (or should i say custom 'GUIs room').

However i didn't change anything on my 2nd room (custom GUIs room) because it's on GlobalScript,besides i've already change & set the 'TweenChannelVolume' script function inside the other GUIs before ('SIButton' GUIs) and i think better not to make a 'doubling' or 'repeating the same function inside the GlobalScript.

In other words,it's finally not change anything & the music channel still continue playing without fade in..
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Adrian

I tried to fade in the audio channel by tweening in one room, which worked well. When I made the player change to a second room the tweening just stopped, which I assume to be wanted behaviour for tweening when changing rooms. So I don't know if there is a way to change that.

When you mention that your audio channel isn't fading at all, maybe you put in the wrong channel number inside the tween command?

Arjunaz78

Did you mean audio number or channel number?or ID number?
which one?
..In the making of Silent Hill: The Hospital..

https://www.facebook.com/ArjunazGamesStudio

Adrian

#12
Quote from: Arjunaz78 on Tue 01/11/2011 09:02:27
Did you mean audio number or channel number?or ID number?
which one?

I mean the audio channel number:

TweenChannelVolume(3.0, 1, 80, 0, eEaseInTween, eNoBlockTween);

Also, if you want to fade music in, you have to flip the values for short fromVolume and short toVolume in the tween command:

TweenChannelVolume(3.0, 1, 0, 80, eEaseInTween, eNoBlockTween);


selmiak

I'm using AGS 321, set the enforce new style audio scripting to false, but how do I set up the channels to be shorts that the tween module can fiddle with? at the moment my audiochannels have names not numbers. Do the channel numbers start with 0 or 1?

selmiak


Khris

Couldn't you use new-style scripting and AudioChannel.ID?

selmiak

how do I find out the audio channel ID? I defined them as global variables with names, not numbers.
I allowed 3 channels for music, so are they numbered in the order I start playing music in them? And do they start with channel ID 0 or 1?

Khris

An AudioChannel pointer has a .ID property; you shouldn't need anything else, just that:

Code: ags
AudioChannel* music1;

...

  TweenChannelVolume(3.0, music1.ID, ...);


On the other hand I don't know how the TweenModule is using that number; afaik there's no global audiochannel[] array, is there?

What I would is find out whether the TweenModule was changed to incorporate the 3.2 audio system changes and use the appropriate system and tween module manual.

selmiak

ah, okay, I see.
This addresses the correct channel. But sadly something is not quite working with the TweenChannelVolume part of the tween module so this is only halfway working

SMF spam blocked by CleanTalk