GMS 2 audio_group_set_gain VS volume in sound editor[SOLVED]

MCHLV

Member
Hello,

I have a question on how the volume in the sound editor work and how to adjust sounds from one another :

Is there a way to combine the audio_group_set_gain function with the volume settings from the audio editor ?
So that I can have one audio group with multiple sounds in it. Fine tune the volumes of all those sounds relatively from each other. And then use audio_group_set_gain in my game to allow the player to set the overall volume level.

When I try to use audio_group_set_gain (I used it once only in my singleton controler object upon creation), all sounds are played as if they were set with full volume in the editor (but it is not the case)
I tested it in an empty project: 1 room, 1 object, 1 default audio group, 1 sound.
- sound's volume setting is set to 0.01
- object has audio_group_set_gain(audiogroup_default,1, 0) in creation
- object has audio_play_sound(sound0,0,false) in mouse click
If I comment / delete audio_group_set_gain, then the sound is barely audible
If I keep it, then settings are ignoresd


So I understood that audio_set_gain overide my individual sounds settings. Is that the case ?
But then, is there an easy and proper way to adapt the sounds volumes for those that are too loud ?


Thank you !!!
M.
 

MCHLV

Member
No one ? Maybe most of us like programing more than audio... At least it is my case, I am just starting including audio after 10 months on my game...

Sorry if I am not clear. What I am trying to do:
- Adjust (=reduce) the volume for some of my sounds for which the volume in the ogg file is way too loud (too lood compared to the other sounds). I have 2 sounds out of ~30 that are too loud and I want to reduce their volume in GMS2 x0.5 vs the file base volume. For that I have been using GMS2 audio editor.
- Allow player to decide in game the volume level for the music and the volume level for all other sounds (but keeping the relative volume I have set above, so those 2 sounds keep their volume x0.5 compared to the native file's volume )

I know I could:
- Use external software but I am sure there is a way in GMS2, and do not feel like learnig a new soft
- Use a switch in my custom audio_play_ext() script to adapt the sounds volumes based on their asset idx
- Use 2 emitters, but I do not want to use any stereo or advanced features

Thanks..
M.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
So I understood that audio_set_gain overide my individual sounds settings. Is that the case ?
Yes. The manual is actually wrong in that repsect as it suggests that the gain set in the sound editor is actually the capped gain when the project is run, which is not the case. It's simply the initial volume for the sound.

Sorry if I am not clear. What I am trying to do:
- Adjust (=reduce) the volume for some of my sounds for which the volume in the ogg file is way too loud (too lood compared to the other sounds). I have 2 sounds out of ~30 that are too loud and I want to reduce their volume in GMS2 x0.5 vs the file base volume. For that I have been using GMS2 audio editor.
- Allow player to decide in game the volume level for the music and the volume level for all other sounds (but keeping the relative volume I have set above, so those 2 sounds keep their volume x0.5 compared to the native file's volume )
The best way I can think of that you could do this is to store the initial value for all sounds in a global array as being the maximum volume for that sound, and then when the global volume is set, get all the max volumes from the array, and then set the sound volume based on global volume percentage between 0 and the max volume in the array. For example, say you have a bullet sound and it's max volume is 0.7, and the global volume is set to 0.7 too. So you'd have:

bullet_vol = max_vol * global.vol = 0.7 * 0.7 = 0.49

This means that when the user changes the global gain, you simply have to go through the array and set the new gain values using the above formula for all the sounds.

Hope that helps!
 

MCHLV

Member
Thank you very much for your answer @Nocturne . I appreciate you taking the time to think this through.

It is a nice solution as it fits in my project with almost no change. I went for it and it works fine
Thanks again

For those who might be interested here are the two scripts (in GMS2.2) one run at game start to store the settings as I defined them in the editor and the other one I run everytime the player change the volume setting.
All the 'show_debug' + '_debug_string' lines are just for... debug

M.

GML:
///@function audio_set_base_gains()
///@description save gain settings for all audio assets. Intended to be used once on game start to save the gains as defined in the IDE in the audio editor

var _debug_string = "The starting gains were saved for ";
for (i=0; audio_exists(i); i++)
{
    sound_base_gains_array[i] = audio_sound_get_gain(i);
    _debug_string += "\n" + audio_get_name(i) + ": " + string(audio_sound_get_gain(i));   
}
_debug_string += "\n" + string_format(i, 0, 0) + " sounds saved.";   
show_debug_message(_debug_string);
return sound_base_gains_array;

//-------------------------------------------------------------------------------

///@function audio_update_gains(gain, base_gains_array)
///@description update the gain settings for all audio assets. It takes into account the base settings as a relative value and apply an overall gain setting. Itendeded to be used when changing the gain setting
///@param gain
///@param sound_base_gains_array

var _gain = argument[0];
var _sound_base_gains_array = argument[1];
var _debug_string = "The gains were update for ";
var _len  = array_length_1d(_sound_base_gains_array); 
for (var i = _len - 1; i>=0 ; i--)
{
    if audio_exists(i)
    {
        audio_sound_gain(i,_sound_base_gains_array[i] *_gain, 0);
        _debug_string += "\n" + audio_get_name(i) + ": " + string(audio_sound_get_gain(i));   
    }
}

show_debug_message(_debug_string);
 
Top