Audio Gain [SOLVED]

Discussion in 'Programming' started by Ted Gress, Jan 10, 2019.

  1. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    400
    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.
     
  2. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,276
    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.
     
  3. Sam04

    Sam04 Member

    Joined:
    Nov 26, 2018
    Posts:
    24
    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.

    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:
    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.
     
  4. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,276
    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.
     
  5. Sam04

    Sam04 Member

    Joined:
    Nov 26, 2018
    Posts:
    24
    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.
     
  6. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    400
    I think @Sam04 is right. Anybody else have an opnion on this?
     
  7. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    400
  8. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    3,527
    If you explain how it would help other people in future who might have a similar issue, search and find this post.
     
  9. Ted Gress

    Ted Gress Member

    Joined:
    Sep 1, 2016
    Posts:
    400
    I would but embarrassingly enough I can't remember what the bug was and how I fixed it.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice