Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: bx83 on Fri 29/09/2017 07:18:12

Title: How to alter AGS sound/music volume WHILE speech is playing
Post by: bx83 on Fri 29/09/2017 07:18:12
Hi,

I'm having a problem with my music while speech is being played. This isn't just the suond volume during a dialog; it's during actua speech.
I thought there must be any easy way to fix this (10% volume during speech, 100% rest of time), but can't find the option is Game options or anywhere else.
Can sound volume be altered during a dialog and/or during speech play?

Thank you :)
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: Khris on Fri 29/09/2017 09:03:39
Sounds like you're looking for Game.SetAudioTypeSpeechVolumeDrop(AudioType, int volumeReduction)
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: Monsieur OUXX on Fri 29/09/2017 10:25:24
also if you really want to fool around randomly with sound in a really simultaneous way with the speech, you might be facing the same issue as many people who want to do various things (not only sound) while speech is on: speech is sort-of blocking. So if Khris' solution is not enough for you, you might want to look into Background Speech.
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: bx83 on Fri 29/09/2017 13:45:48
Background speech?... Is this like a speech style, like Thinking?
Could you give me a function name?
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: bx83 on Fri 29/09/2017 13:59:37
Hi Kris, the function Game.SetAudioTypeSpeechVolumeDrop(AudioType, int volumeReduction):
a) set to 80, just as loud
b) while speech occurs, the audio is completely blanked out.
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: Crimson Wizard on Fri 29/09/2017 14:21:18
Quote from: bx83 on Fri 29/09/2017 13:59:37
Hi Kris, the function Game.SetAudioTypeSpeechVolumeDrop(AudioType, int volumeReduction):
a) set to 80, just as loud
b) while speech occurs, the audio is completely blanked out.

This function defines a volume drop that will be applied automatically when speech begins and reversed when speech ends. Commonly you only set it once at game start (but you also may adjust it for particular rooms/music played if that makes sense).
Alternatively, you may configure it in AudioType properties in the project tree.
The value is percent of volume drop, 0 meaning no drop, 100 - makes it completely silent.

Quote from: bx83 on Fri 29/09/2017 13:45:48
Background speech?... Is this like a speech style, like Thinking?
Could you give me a function name?
Background speech is not supported by AGS itself, you need module or plugin for that.
E: I think something like this: http://www.adventuregamestudio.co.uk/forums/index.php?topic=23806.0
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: Snarky on Fri 29/09/2017 15:11:19
Quote from: bx83 on Fri 29/09/2017 13:59:37
Hi Kris, the function Game.SetAudioTypeSpeechVolumeDrop(AudioType, int volumeReduction):
a) set to 80, just as loud
b) while speech occurs, the audio is completely blanked out.

Quote from: Crimson Wizard on Fri 29/09/2017 14:21:18
The value is percent of volume drop, 0 meaning no drop, 100 - makes it completely silent.

Unless this has changed recently, the value is the percentage point volume drop: it merely subtracts the audio-drop number from the volume of the clip. So if the volume is 80 or less in the first place, an 80-point volume drop will make it totally silent. This is likely to be the cause of the issue with audio being blanked out during speech.
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: Crimson Wizard on Fri 29/09/2017 15:23:48
Quote from: Snarky on Fri 29/09/2017 15:11:19
Unless this has changed recently, the value is the percentage point volume drop: it merely subtracts the audio-drop number from the volume of the clip. So if the volume is 80 or less in the first place, an 80-point volume drop will make it totally silent. This is likely to be the cause of the issue with audio being blanked out during speech.

Hmm, yes, it is subtracted, not multiplied by.
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: bx83 on Sat 30/09/2017 15:59:41
Aha, the points worked! Reduced it to 5 - works now :)

I'm still having a problem with the below code for two rooms.
Room 2 is BEACH
Room 7 is CAVE
a1_beachTheme_5_0 is a theme for the room BEACH, type Music. Music MaxChannel is 1.
aOcean_crash is a theme for BEACH, type Sound. It continues in BEACH or CAVE, but it set off in BEACH. Sound MaxChannels is 5.

in CAVE,
a1_beachTheme_5_0_CAVE is a lower volume, muffled one than the original. It's kept in sync with beachThemePos; this way, when music play's, it slips seemlessly from one to the other.
aWater_dripping is a sound effect, type Sound.

I use 3 AudioChannel* variables, called chan1, chan2 and chan3. Chan1 is a continuous Music channel that crossfades between rooms, using the standard game option.
Chan2 is for sound effects, and chan3 is an extra one.

I know this isn't the best solution, but usually it's just music and nothing else, and I cannot get my head around rising/falling channels, Tween, etc.

The problem is: chan2 initially plays the Water_dripping sound effect; but then, regardless that it's non-null, it stops after the 2nd or 3rd time. After this, it causes an error at the 5th time, saying it is null.

I'm guessing that chan2 is not 'static', and that I'm getting it to reach the MaxChannel limit and then crash with an erronious error. But then....?
Whatever I do, chan2 crashes erroniously, eventually.
What's causing it?

No idea what's going on.

Beach - room_load():

if (cJulius.PreviousRoom == 7) {
chan1 = a1_beachTheme_5_0.Play(eAudioPriorityNormal, eRepeat);
chan1.Seek(beachThemePos);
if (chan2.PlayingClip==aWater_dripping) {
chan2.Stop();
}
} else {
if (chan1 != null) {
if (chan1.PlayingClip!=a1_beachTheme_5_0) {
chan1 = a1_beachTheme_5_0.Play(eAudioPriorityNormal, eRepeat);
}
} else {
chan1 = a1_beachTheme_5_0.Play(eAudioPriorityNormal, eRepeat);
}
}

if (chan3!=null) {
if (chan3.PlayingClip != aOcean_crash_cave) {
chan3 = aOcean_crash.Play(eAudioPriorityHigh, eRepeat);
}
} else {
chan3 = aOcean_crash.Play(eAudioPriorityHigh, eRepeat);
}


Cave - room_load():

if (cJulius.PreviousRoom == 2) {
chan1 = a1_beachTheme_5_0_CAVE.Play(eAudioPriorityNormal, eRepeat);
chan1.Seek(beachThemePos);
} else {
if (chan1!=null) {
if (chan1.PlayingClip != a1_beachTheme_5_0_CAVE) {
chan1 = a1_beachTheme_5_0_CAVE.Play(eAudioPriorityNormal, eRepeat);
} else {
chan1 = a1_beachTheme_5_0_CAVE.Play(eAudioPriorityNormal, eRepeat);
}
}
}

if (chan2 != null) {
    if (chan2.PlayingClip!=aWater_dripping) {
      chan2 = aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
    }
  } else {
    chan2 = aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
  }
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: bx83 on Mon 02/10/2017 02:06:17
Crimson, Snarky, what do you suggest?
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: bx83 on Mon 02/10/2017 05:47:35
Okay, I've learnt more about the audiochannel system, and edited my code.

It all works -- except that the beach_theme is restarted every time I enter room 2 (Beach) from room 7 (Cave). You start in Beach.
Cave works fine; beach does not.

Beach:

function room_FirstLoad()
{
    SetGameOption(OPT_CROSSFADEMUSIC, 2);
}

function room_AfterFadeIn()
{
  if (cJulius.PreviousRoom == CAVE) {
    aWater_dripping.Stop();
  }

  if (chan1==null) {
    chan1=aOcean_crash.PlayFrom(oceanThemePos, eAudioPriorityHigh, eRepeat);
    chan1=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);    //run the first time I'm in Bach -- ie. after game loads
  } else {
    chan1=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);    //runs every time after that
  }
}

function room_RepExec()
{
  beachThemePos=chan1.PositionMs;
}



Cave:

function room_AfterFadeIn()
{
  if (cJulius.PreviousRoom == BEACH) {
    chan1=a1_beachTheme_5_0_CAVE.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
  }

  if (chan1.PlayingClip!=aWater_dripping) {
    chan1=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
  }
}

function room_RepExec()
{
  beachThemePos=chan1.PositionMs;
}
Title: Re: How to alter AGS sound/music volume WHILE speech is playing
Post by: bx83 on Tue 03/10/2017 02:36:59
Here's the final working code:

Beach:


function room_FirstLoad()
{
  SetGameOption(OPT_CROSSFADEMUSIC, 2);
  chan1=aOcean_crash.Play(eAudioPriorityNormal, eRepeat);
  chan2=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
}

function room_AfterFadeIn()
{
if (cJulius.PreviousRoom == CAVE) {
aWater_dripping.Stop();
if (chan2!=null) {
chan2=a1_beachTheme_5_0.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
}
}

}


Cave:


function room_AfterFadeIn()
{
if (cJulius.PreviousRoom == BEACH) {
chan2=a1_beachTheme_5_0_CAVE.PlayFrom(beachThemePos, eAudioPriorityNormal, eRepeat);
}

if (chan1.PlayingClip!=aWater_dripping) {
chan1=aWater_dripping.Play(eAudioPriorityNormal, eRepeat);
}

}

function room_RepExec()
{
beachThemePos=chan2.Position+1100;
}