Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: subspark on Thu 11/03/2010 09:56:54

Title: Problems with AGS' new AudioSystem :(
Post by: subspark on Thu 11/03/2010 09:56:54
Okay. I admit it! I don't have a clue how the new audio system works. But for what I want to do with it, the system seems counter-intuitive.

I have a list of footstep sounds that I want to change the volume of based on which room the player is in.
function repeatedly_execute_always ( )
{
  AudioClip *idle;
  AudioClip *regularA;
  AudioClip *regularB;

  if(player.Room==4)
  {
    idle=aFootstep_dirt_B_stop;
    regularA=aFootstep_dirt_B_walk;
    regularB=aFootstep_dirt_B_walk;
  }
etc, etc, etc.


However, how am i supposed to change the volume of a collection of specific sounds (footsteps) if you have to play the sound before you can set the channel's volume. DOH! I just don't get it.

Do I write something like this?
  AudioChannel *FS_IDLE_ROOM4 = aFootstep_dirt_B_stop & aFootstep_dirt_B_walk_1 & aFootstep_dirt_B_walk_2 & aFootstep_dirt_B_walk_3;
  FS_IDLE_ROOM4.Volume = 25;


I'm totally confused with the whole channel thing right now and the help file does nothing to make sense of it.
I would appreciate it if someone could explain it to me in english. ;)
Cheers guys and sorry for sounding completely fresh. It's just the audio I swear! :P

Sparky.
Title: Re: Problems with AGS' new AudioSystem :(
Post by: Khris on Thu 11/03/2010 10:52:35
How about this:

void on_event(EventType event, int data) {
 
  if (event == eEventEnterRoomBeforeFadein) {

    ViewFrame*v;
    AudioClip*a;

    if (player.Room == 4) a = aFootstep_hushed;
    else a = aFootstep;

    int i;
    while (i < 4) {
      v = Game.GetViewFrame(player.View, i, 4);
      v.LinkedAudio = a;
      v = Game.GetViewFrame(player.View, i, 7);
      v.LinkedAudio = a;
    }
  }
}
Title: Re: Problems with AGS' new AudioSystem :(
Post by: subspark on Thu 11/03/2010 23:40:56
Thanks for the hand Khris. But where is the volume bit? I somehow need to change the volume of the footstep sounds and don't know how. You can only change the volume of a channel and I still don't understand how those work either.

Thanks again in advance. :)

Sparky.
Title: Re: Problems with AGS' new AudioSystem :(
Post by: Khris on Thu 11/03/2010 23:57:29
I've used two different sounds, the idea being that you simply lower the volume outside AGS. That's a bit cheap but should work nonetheless.

Then I've assigned the hushed sound to frames 4 & 7 if the player entered room 4, the standard sounds otherwise.
Title: Re: Problems with AGS' new AudioSystem :(
Post by: subspark on Fri 12/03/2010 00:04:27
Isnt there a way to adjust the volume of my varied footstep effects dynamically in the script?
I'm not sure I want to have 2 copies of every footstep variation. Im sure theres a better way.
Thanks though. I really do appreciate the assist.

Sparky.  :)
Title: Re: Problems with AGS' new AudioSystem :(
Post by: monkey0506 on Fri 12/03/2010 00:46:38
I think you should be able to do something like this:

// room script

function repeatedly_execute_always() {
  int i = 0;
  while (i < System.AudioChannelCount) {
    AudioChannel *channel = System.AudioChannels[i];
    if ((channel.PlayingClip == aFootstep_dirt_B_stop) || (channel.PlayingClip == aFootstep_dirt_B_walk)) channel.Volume = 25;
    i++;
  }
}


That should be able to catch the footstep clip before it gets played I would think.
Title: Re: Problems with AGS' new AudioSystem :(
Post by: subspark on Fri 12/03/2010 02:32:02
I see. Wow that's complicated! Can't we seriously just change the volume of an AudioClip dynamically?

For the meantime, I suggest (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=40361.new#new) we have the ability to do this:
aMySound.Volume = 25;

Cheers,
Sparky.
Title: Re: Problems with AGS' new AudioSystem :(
Post by: monkey0506 on Fri 12/03/2010 03:27:53
Upon some further digging around I found the Game.SetAudioTypeVolume function. So basically you could change all of your footstep sounds to a new audio type, for example eAudioTypeFootstep, and then have something such as the following:

// GlobalScript.asc

function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    if (data == 4) Game.SetAudioTypeVolume(eAudioTypeFootstep, 25, eVolExistingAndFuture); // 25% volume for room 4
    else if (data == 10) Game.SetAudioTypeVolume(eAudioTypeFootstep, 42, eVolExistingAndFuture); // 42% volume for room 10
    else Game.SetAudioTypeVolume(eAudioTypeFootstep, 100, eVolExistingAndFuture); // 100% volume for all other rooms
  }
}
Title: Re: Problems with AGS' new AudioSystem :(
Post by: SpacePaw on Sat 13/03/2010 10:51:05
Quote from: monkey_05_06 on Fri 12/03/2010 03:27:53
// GlobalScript.asc

function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    if (data == 4) Game.SetAudioTypeVolume(eAudioTypeFootstep, 25, eVolExistingAndFuture); // 25% volume for room 4
    else if (data == 10) Game.SetAudioTypeVolume(eAudioTypeFootstep, 42, eVolExistingAndFuture); // 42% volume for room 10
    else Game.SetAudioTypeVolume(eAudioTypeFootstep, 100, eVolExistingAndFuture); // 100% volume for all other rooms
  }
}


I don't see any eAudioTypeFootstep in newest AGS :) only Music, Ambient and  Sound. So we can't affect only footsteps. I go with Subspark's suggestion for adding volume to AudioClip. Furthermore it would be even BETTER if this volume was dependant on current volume. So if you set volume to 50% in audio clip it would be 50% for SoundVolume 100% and 25% for SoundVolume 50%. If you get my drift :)
Title: Re: Problems with AGS' new AudioSystem :(
Post by: monkey0506 on Sat 13/03/2010 13:50:33
You can create new audio types. This is what I meant by changing the footstep sounds to "a new audio type". You can set it so every piece of non-speech audio in your game is declared as the same audio type, or you can create as many audio types as you want.

This isn't something that's hard-coded. You do have to have at least one audio type, but you can create more if you want.
Title: Re: Problems with AGS' new AudioSystem :(
Post by: subspark on Sat 13/03/2010 14:46:46
Wow, I certainly can see the power of this now. Thanks both you guys.
I'll target these Footsteps volume with an AudioType then.


Cheers,
Sparky.