• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows Adjusting Volume For Multiple Sounds

S

Sabrina Stoakes

Guest
Howdy!

So I've been working on a little shoot em up and ran into what I assume is a small issue.

I have set up the explosion sound for when an enemy is destroyed with JUST audio_play_sound. Problem? when you destroy multiple enemies either at once, or close enough together, it creates a very yucky loud (sometimes even clipping) sound effect.

Now, I would ASSUME that this could be fixed by checking to see if the sound effect is playing and then adjusting the sound that way, which I tried doing, but didn't work. I did something like this within the death event for the enemies:

Code:
if audio_is_playing(explode_sound)
{
control.sfxgain -= 0.1
} else {control.sfxgain = //whatever it was I had it set to prior}
I'm using a variable within the control object to set the volume of the specific sound.

Any help would be FANTASTIC, and I hope you have a great day <3
 

JeffJ

Member
When you say it doesn't work, what do you mean? Does the code within the statement not trigger?
Does explode_sound refer to an instance of the sound or an actual sound asset?

If you read the docs on the function
https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sounds/audio_is_playing.html

It states that it can check for both. When you use audio_play_sound, it stores an index which can also be checked. Are you checking an index or an asset? If you're checking an index that has already stopped, that would likely be the culprit.

Also, try checking the return value of audio_is_playing with something like:
debug = audio_is_playing(explode_sound)
show_debug_message(debug)

Then keep an eye on your log to see what it says.
 

obscene

Member
Well, hard to know exactly why this wouldn't work only seeing part of the code.

Typically if you want to change the gain of a sound, you need to have the ID of the playing instance of the sound...

snd=audio_play_sound(etc...)
audio_sound_gain(snd,etc...)

Simply setting the gain of the snd asset will not do anything.
 
S

Sabrina Stoakes

Guest
When you say it doesn't work, what do you mean? Does the code within the statement not trigger?
Does explode_sound refer to an instance of the sound or an actual sound asset?

If you read the docs on the function
https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sounds/audio_is_playing.html

It states that it can check for both. When you use audio_play_sound, it stores an index which can also be checked. Are you checking an index or an asset? If you're checking an index that has already stopped, that would likely be the culprit.

Also, try checking the return value of audio_is_playing with something like:
debug = audio_is_playing(explode_sound)
show_debug_message(debug)

Then keep an eye on your log to see what it says.

I would say that it does adjust the volume, but it doesn't work very well when 3+ sounds are playing, only works well for 2 sounds. I had the idea to simply check to see if the sound is playing or not and just straight up not play it if it is, which works, but I'm not sure how much I like it.

Also explode_sound is the name of the asset!
 
S

Sabrina Stoakes

Guest
Well, hard to know exactly why this wouldn't work only seeing part of the code.

Typically if you want to change the gain of a sound, you need to have the ID of the playing instance of the sound...

snd=audio_play_sound(etc...)
audio_sound_gain(snd,etc...)

Simply setting the gain of the snd asset will not do anything.
The code I provided is placed in the step event of the enemy and is triggered if their hp is <= 0. The instance is destroyed within the same trigger btw.
 

obscene

Member
My point is: You only showed code where you reduced the value of a variable. What are you doing with that variable somewhere else? Where are you changing the gain of a sound?
 
S

Sabrina Stoakes

Guest
My point is: You only showed code where you reduced the value of a variable. What are you doing with that variable somewhere else? Where are you changing the gain of a sound?
ohhhhhh, yeah in the control object's step event I have audio_sound_gain(explode_sound,sfxgain,0)
 

obscene

Member
Is explode_sound the name of the sound effect asset, or is that the ID of the currently playing instance of that sound (see my post example)
 
S

Sabrina Stoakes

Guest
When you say it doesn't work, what do you mean? Does the code within the statement not trigger?
Does explode_sound refer to an instance of the sound or an actual sound asset?

If you read the docs on the function
https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sounds/audio_is_playing.html

It states that it can check for both. When you use audio_play_sound, it stores an index which can also be checked. Are you checking an index or an asset? If you're checking an index that has already stopped, that would likely be the culprit.

Also, try checking the return value of audio_is_playing with something like:
debug = audio_is_playing(explode_sound)
show_debug_message(debug)

Then keep an eye on your log to see what it says.
Just wanted to follow up and say that I watched the value of sfxgain and it gets set into the negatives because of the code that reduces the volume. It never returns the volume back to what it originally was despite the else statement afterwards. Not sure how this would make the sound still clip though, seems like it would make it silent.
 

JeffJ

Member
I can't say for certain what effect going into negatives would have in this context, but to avoid it, you could just clamp it:
sfxgain = clamp(sfxgain,0,1)

As for the problem: since you are referencing the asset directly, you are essentially changing the gain for the same sound played multiple times. If you want the gain to be unique, you should store each sound as its own index and reference that when changing the gain.
 
S

Sabrina Stoakes

Guest
I can't say for certain what effect going into negatives would have in this context, but to avoid it, you could just clamp it:
sfxgain = clamp(sfxgain,0,1)

As for the problem: since you are referencing the asset directly, you are essentially changing the gain for the same sound played multiple times. If you want the gain to be unique, you should store each sound as its own index and reference that when changing the gain.
BLESS.

I did find another way that actually sounded really good.

I put this in the death event for the enemies
Code:
if audio_is_playing(explode_sound)
{
audio_stop_sound(explode_sound)
}
if not audio_is_playing(explode_sound)
{
audio_play_sound(explode_sound,1,false)
}
a little excessive, but it kept the sounds from getting too loud by canceling the sound if it's playing and immediately replacing it. Would be an easy fix for some people who may read this in the future.
 
Top