Problems with AGS' new AudioSystem :(

Started by subspark, Thu 11/03/2010 09:56:54

Previous topic - Next topic

subspark

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

Khris

How about this:

Code: ags
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;
    }
  }
}

subspark

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.

Khris

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.

subspark

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

monkey0506

I think you should be able to do something like this:

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

subspark

I see. Wow that's complicated! Can't we seriously just change the volume of an AudioClip dynamically?

For the meantime, I suggest we have the ability to do this:
Code: ags
aMySound.Volume = 25;


Cheers,
Sparky.

monkey0506

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:

Code: ags
// 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
  }
}

SpacePaw

Quote from: monkey_05_06 on Fri 12/03/2010 03:27:53
Code: ags
// 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 :)

monkey0506

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.

subspark

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.

SMF spam blocked by CleanTalk