Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: smartastreacle on Mon 09/08/2021 16:21:35

Title: Audioclips cancelling each other out [Solved]
Post by: smartastreacle on Mon 09/08/2021 16:21:35
Hi, and audioclip and audiochannel question! (boom (sound effect))  :)

I have a cannon firing and someone digging. Both are animated and start on fade in of the room.
I have the sounds in the function room_RepExec() part of the room code. The digging has 7 frames, every frame 0 I have a digging sound, a shovel. The cannon has 16 frames and fires every frame 14. The animations run at different speeds.

Code (ags) Select
function room_AfterFadeIn()
{
  object[0].SetView(11);     // This is the digger
    object[0].Animate(0, 4, eRepeat, eNoBlock);
  object[1].SetView(12);    // This is the cannon
    object[1].Animate(0, 8, eRepeat, eNoBlock);
}

function room_RepExec()
{     
  if (object[0].Frame == 0){
     ashovel.Play();   
  }
  if (object[1].Frame == 14){
     aveggun2.Play();
  }


Basically the issue is quite simple and I know it probably has an easy solution but I just haven't found it - the digging sound blocks out the cannon boom. My understanding is that both sounds are probably playing on the same audio channel, so, my question is - can I assign a sound to a particular audiochannel like:

Audiochannel 1 assign dig
Audiochannel 2 assign cannon?

or from something I have seen:

AudioChannel *dig;
AudioChannel *cannon;


// and later

  if (object[0].Frame == 0){
    dig = ashovel.Play();   
  }
  if (object[1].Frame == 14){
    cannon = aveggun2.Play();
}


I tried this and it didn't work. Do I have the theory right? Any help more than gratefully received.  :)
Title: Re: Audioclips cancelling each other out
Post by: smartastreacle on Mon 09/08/2021 16:22:58
Sorry I posted this before I had finished writing it, I hope there's enough there for you.  8-0

I edited.
Title: Re: Audioclips cancelling each other out
Post by: newwaveburritos on Mon 09/08/2021 16:46:52
This doesn't answer your question but you can also assign a sound to a frame in a view in the editor to save you some work.  Open up the view and click on the frame you want and there's a place in the properties panel in the bottom right to assign a sound to it.
Title: Re: Audioclips cancelling each other out
Post by: smartastreacle on Mon 09/08/2021 16:52:30
Oh you are right! I'd forgotten about that. I'll give it a go and move things around.

Thank you.

Question about the channels still open though.  (nod)

Update. Syncs up fine but cancelling still the issue. Cannon sound is 6 seconds so never hear the digging.
Title: Re: Audioclips cancelling each other out
Post by: smartastreacle on Mon 09/08/2021 19:08:56
OK, I didn't know about the sound types. I stuck dig in ambient and cannon in sound (was maxchannels = 0 changed to 3 in the tree) and shortened the cannon clip. Now it all works a treat and hopefully still have room for another cannon and some mechanical sounds. If I have more time I will explain more clearly (I have to go out) but I hope I am using sound types right now.
I saw the tip from Crimson Wizard:

'Also, increase number of channels for music [or ambient or sound]. In your project tree select "Audio"->"Types"->"Music" and change MaxChannels property.'


'New audio system is explained in the manual which comes with AGS Editor.
Specifically:
- "Other features"->"Music and sound";
- "Scripting" -> "AudioChannel functions and properties";
- "Scripting" -> "AudioClip functions and properties";'
Title: Re: Audioclips cancelling each other out
Post by: Cassiebsg on Mon 09/08/2021 21:17:56
From the manual:
Quote
AGS currently has an 8-channel audio system, which means that up to 8 sounds can be playing at the same time. With the default Audio Types settings, one channel is reserved for speech, one for music and one for ambient sounds; thus leaving 5 available for sound effects.

So your Music should be set to 1 and ambient 1 (unless you want more ambient sounds playings, like maybe the sounds or a creek running, wind blowing and birds chirping...). This means that you should leave the sound at 0, so it'll use all other available channels. If you limit it to 3, then you might end up with unused channels. Music=1 , Sound=3, Ambient=1, Speech=1... that's 6 channels, and 2 that will never be used.

Also note, that if you are using MIDI, then you can only play one at a time no matter how many channels you have.
Title: Re: Audioclips cancelling each other out
Post by: Crimson Wizard on Mon 09/08/2021 21:22:19
One thing: it's 8 channels total but 1 channel is always reserved for voice speech, so 7 are free to use between audio types.
Title: Re: Audioclips cancelling each other out
Post by: smartastreacle on Tue 10/08/2021 06:40:23
Cassiebsg: Done. A little knowledge goes a long way.  (laugh)

Crimson Wizard: Noted. I might actually use some speech now.  :)

So, this is solved. To clarify, for those struggling at the noob end like me, the problem was I did not know about sound types so the dig sound and the explosion sound were competing on the same channel.
Type in the aveggun property box was Ambient Sound, type in the dig property box was Ambient Sound, in Explore Project/Audio/Types Ambient Sound was given a MaxChannels of 1. With gun and dig now defined as Sound and Sound given MaxChannels of 0 the rest of the available channels could handle the two sfx with no problem. Oh, and I could now allocate the sound to the correct frame in the view. I knew it would be easy. (I think that's right, if it's wrong I'll crawl back in my hole).