[SOLVED] The audio channel of sounds linked to animation

Started by .M.M., Sat 25/09/2021 11:31:28

Previous topic - Next topic

.M.M.

Hi there,

I'm wondering, is there a way to set an audio channel for sounds linked to an animation frame? Or is there a default audio channel for this purpose? I'd like to adjust the panning and volume of the sounds, but I'm not sure whether there's a way without some work around.

Crimson Wizard

#1
Not at the moment, iirc they are playing on the channels as designated by their audio type. It's not defined explicitly, but may be calculated summing up all reserved "Max Channels" values from audio types in order. Speech channel is always fixed at ID 0. Total number of channels in the latest version is 8.

For example, if you have audio types:
- Music: max channels = 1;
- Sound: max channels = 0; (not limited therefore not reserved)
- Ambience: max channels = 1;
- Footsteps: max channels = 1;

This gives channel IDs:
0 - speech;
1 - music;
2 - ambience;
3 - footsteps.
- remaining 4 channels are used freely for sounds.

Then you may access respective channel as System.AudioChannels[3].

That works if you have 1 reserved channel for these frame sounds, but if you have 2 or more, then situation is more complicated, as you'd have to check all of them to find out which are playing.

All that said, in general, I have doubts about the whole approach. Because there's no event or other signal when the frame plays a sound, you cannot really know which of them is playing right now.
So long as only 1 animation (1 character basically) may play sounds at a time - you know at least which character is playing it. But if multiple characters have animations with sounds - there's also a problem how to guess whose sound is playing there. To which I see no direct solution.

eri0o

@M.M., can you talk a bit about the intention here? What are you trying to achieve? :)

.M.M.

Quote from: Crimson Wizard on Sat 25/09/2021 16:10:01
For example, if you have audio types:
- Music: max channels = 1;
- Sound: max channels = 0; (not limited therefore not reserved)
- Ambience: max channels = 1;
- Footsteps: max channels = 1;

This gives channel IDs:
0 - speech;
1 - music;
2 - ambience;
3 - footsteps.
- remaining 4 channels are used freely for sounds.

Hmm, footsteps are a separate audio type by default? I don't have this type defined, maybe it's because it was introduced in later version of AGS than where my project had started?
This actually leads my to an idea, maybe it's because I don't understand the audio system correctly: if I were to create a new audio type for the sounds linked to frame and set its MaxChannels property to 1, would it then be easier to take track of it?

Quote from: eri0o on Sat 25/09/2021 18:12:30
@M.M., can you talk a bit about the intention here? What are you trying to achieve? :)
Sure.  :) It's an idea for improving the atmosphere and immersion in my game. It's an RPG with turn-based battle system, similar to Shadowrun or Fallout (in the basic system, definitely not in quality  :-D ). The sounds linked to animations are mostly shots, punching etc. - because of the turn-based nature of it, the animations are blocking which should make it easier, and I already have a code to change the sounds inside animations on the go (to have variety of shot sounds without the need of duplicate loops).
So, what I've wanted to try is to change mostly the L/R panning of the sounds based on their relative position to player and see if it helps with the atmosphere.

eri0o

You can create any audio type.

@CrimsonWizard it's the same usecase of the mod AlanDrake has in his draconian AGS, not sure what to do with that information, but thought about mentioning.

Crimson Wizard

#5
Quote from: .M.M. on Sun 26/09/2021 09:42:25
Hmm, footsteps are a separate audio type by default? I don't have this type defined, maybe it's because it was introduced in later version of AGS than where my project had started?
This actually leads my to an idea, maybe it's because I don't understand the audio system correctly: if I were to create a new audio type for the sounds linked to frame and set its MaxChannels property to 1, would it then be easier to take track of it?

"Footsteps" type is an example. Like eri0o mentioned you are free to create new types (and delete existing ones, iirc).
Yes, having a dedicated type with MaxChannels set is what I refered to in my reply. However I must again point out that this will only help you to know which channel they are playing on, but it won't help to know which character the currently played sound is related to if you have multiple characters.

I have a suspicion that this task may have to be implemented in script instead: that is, instead of linking sounds to animation frames, track current character animations in "rep-exec" or "rep-exec-always" and run sounds depending on their current Character.View, Loop and Frame. Then, because you are the one who starts a sound playback, you will also know which character (or Object) it is related to and be able to adjust it's parameters according to that character's position.

Unless someone has a good idea of how to handle this with the linked frame sounds instead...

Quote from: eri0o on Sun 26/09/2021 12:41:24
@CrimsonWizard it's the same usecase of the mod AlanDrake has in his draconian AGS.

It looks like, but from the quick glance his branch has this effect hardcoded, which was probably useful for his own game.

I think in overall, the biggest problem here is that frame sounds system does not provide much setup, and also AGS does not let user to "intercept" and reconfigure frame sounds "on the fly" when they are about to play.

EDIT: There's only one parameter I know that affect frame sounds: Character's property "AdjustVolumeWithScaling" (Character.ScaleVolume in script) that makes sound volume go up or down depending on character's scaling (probably used to emulate walking away/up close). In theory there could be similar parameters for panning or directional volume.

Alan v.Drake

Yes, I enforced the panned sound to all view-generated sounds, because for me there is no case where that is not preferable. We could add an option for enabling/disabling it manually and merge this feature in ags4.
The only con is that the sound origin, for objects, takes the corner which is not the center. At least until we can change the origin. It's only an issue if one has a very wide sprite animation.

Another possible way to handle it was to implement function binding  to individual frames, and maybe pass the type and id of the object/character so it can be dealt properly via script.

- Alan

.M.M.

Hi, sorry for digging up this thread, but I didn't have much time to spend with AGS lately. Now I've finally implemented a solution for the panning and volume based on your suggestions - a big thanks to all of you!  :)

Maybe it'll help someone in the future, or you'll find a better solution based on this one. :)

First, I listen to a sound on the designated audio channel - all sounds have a special type assigned with its own channel (MaxChannels set to 1, as described above by Crimson Wizard). Variables sound_direction_x/y are specified together with the animation, best way probably is to put it into a custom animate function.
I needed this because you can't change the panning and volume when there's no audio playing on the channel: making this possible would be great!
Code: ags

function repeatedly_execute_always() {  
 
 if (System.AudioChannels[3].IsPlaying && sound_direction_x != -1)
 {
  SetSoundDirection(3, sound_direction_x, sound_direction_y);
 }
}


And this is the actual setting. 
Code: ags

void SetSoundDirection(int channel_id, int vector_x, int vector_y)
{
 sound_direction_x = -1;
 sound_direction_y = -1;
 if (vector_x == 0 && vector_y == 0) return;
 sound_distance = MathsFunc.Distance(0, 0, vector_x, vector_y*2); //simple custom function, *2 is because of the perspective of my game
 sound_distance = sound_distance/8; //kept separate, change the number to play around with the effect's intensity
 if (sound_distance > 90) sound_distance = 90; // the sound is always at least at 10% of volume
 vector_x = vector_x/4; // change the number to play around with the effect's intensity
 if (MathsFunc.Absolute(vector_x) > 100)
 {
  if (vector_x < 0) vector_x = -100;
  else vector_x = 100;
 }
 System.AudioChannels[channel_id].Panning = vector_x;
 System.AudioChannels[channel_id].Volume = 100-sound_distance;
}

It may look a bit clumsy, but it works fine. :)

SMF spam blocked by CleanTalk