• 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!

Audio Gain [SOLVED]

I have a slider I created to change the audio gain for music in my game. It returns values between 0.05 and 85.
I also have a step event in an object that is supposed to change the music gain according to the slider's value.

Code:
///meter for music
music_volume = global.slider_percent/200;
show_debug_message("MUSIC VOLUME:" + string(music_volume));
audio_sound_gain(WinMusic, music_volume,0);
audio_sound_gain(PlayerDeath, music_volume, 0);
audio_sound_gain(RockIntro, music_volume, 0);
audio_sound_gain(Level1Music, music_volume, 0);
Problem is, no matter what audio_sound_gain is set to, it doesn't change the volume of the music.
 

obscene

Member
Audio works kind of like objects/instances...

When you play a sound, you make an instance of that sound. You store the ID of the instance of that sound and then you would use audio_sound_gain() to change it instead of trying to change the gain of the asset.

So you probably want to do something like global.current_music=audio_play_sound() each time you call a sound, then just change the gain of global.current_music.
 

Sam04

Member
I have a slider I created to change the audio gain for music in my game. It returns values between 0.05 and 85.
I also have a step event in an object that is supposed to change the music gain according to the slider's value.

Code:
///meter for music
music_volume = global.slider_percent/200;
show_debug_message("MUSIC VOLUME:" + string(music_volume));
audio_sound_gain(WinMusic, music_volume,0);
audio_sound_gain(PlayerDeath, music_volume, 0);
audio_sound_gain(RockIntro, music_volume, 0);
audio_sound_gain(Level1Music, music_volume, 0);
Problem is, no matter what audio_sound_gain is set to, it doesn't change the volume of the music.
If you are going to set the same volume on all sounds then you might as well use the "audio_master_gain()" function. You can find more about it here.

Audio works kind of like objects/instances...

When you play a sound, you make an instance of that sound. You store the ID of the instance of that sound and then you would use audio_sound_gain() to change it instead of trying to change the gain of the asset.

So you probably want to do something like global.current_music=audio_play_sound() each time you call a sound, then just change the gain of global.current_music.
I believe this is wrong. According to the user manual page on the "audio_sound_gain()" function it does apply to all instances of that index. It says:
This function will affect all instances of the sound that are playing currently in the room if the index is a sound resource, and the final volume will be the volume at which all further instances of the sound will be played. However if you have used the index returned from a function like audio_play_sound it will only affect that one instance of the sound.
But sometimes the user manual get it wrong and can't really confirm it as I haven't played that much with the gain functions.
 

obscene

Member
According to that, if referring to the sound asset, future instances of the sound would play at the defined gain but the one that is already playing would be unaffected.
 

Sam04

Member
According to that, if referring to the sound asset, future instances of the sound would play at the defined gain but the one that is already playing would be unaffected.
I believe not. The first sentence says: "This function will affect all instances of the sound that are playing currently in the room if the index is a sound resource...". So it shouldn't exclude the ones already playing. But then again, that's what the manual says, and I've seen the user manual being wrong before.
 

fawf

Member
Bumping this thread because I've just had this exact issue, and I believe I've found what the problem is.

The fadeout only works on sound instances and will not work if it references the asset.

e.g this will fade out

GML:
music_inst = audio_play_sound(music_asset,1,1);
audio_sound_gain(music_inst,0,1000);
and this will not

GML:
audio_play_sound(music_asset,1,1);
audio_sound_gain(music_asset,0,1000);
You can still use reference the asset id when using audio_sound_gain but only if you set time to 0.
 
Top