Audio ducking help

Sound designer/Composer here taking my first swing at some dnd tutorials starting with "Space Rocks". What I am trying to achieve is a temporary drop in volume in the background music whenever any SFX are triggered for the entire duration of whichever sound effect is occurring. In a DAW, we'd call this ducking in which the drop in volume is directly relative to the level of the sfx. I'm curious what the most efficient way to go about this in GMS2 would be.

Thanks in advance for any and all help!
 

poliver

Member
i doubt you can create this in dnd

but in gml i would create a 'Listener' object that listens
  1. whether a background music is playing, and if it is
  2. whether any other sounds are playing ("for" loop through an array of all possible sound indexes., and if any sound is
SIMPLE WAY: (instant drop in volume)
-------------------------------------------------------------
If those checks are true, set the volume of background music using audio_sound_gain(sound_name, new_gain_value(0-1), time_in_ms_to_apply_gain);
If those checks are false, set the volume of background music to default value

LONGER WAY: (smoother fade of volume drop, for this you'd have declared two extra variables at the start, "duck" and "min_gain_value")
-------------------------------------------------------------
If those checks are true, trigger 'duck' flag variable to TRUE
  • check if gain of background music is equal to min_gain_value
  • if it is do nothing
  • if it's not decrease it by a certain amount each step
If those checks are false, restore 'duck' variable to FALSE
  • check if gain of background music is equal to original value
  • if it is do nothing
  • if it's not increase it by a certain amount each step


///////////////////////////////////////////////////////////////////
Some tips:
  • Use linear interpolation(lerp) or anything similar to achieve a smooth fade-in out effect
  • Gain in gamemaker is measured from 0 to 1, 0 = silence. 1 = full volume. Use logarithmic functions to achieve required volume in float value.
    0.5 is not half the volume
    ~ -6dB is half the volume
 
Last edited:
Thanks for your timely reply!

I was able to execute the ducking within the dnd interface using a mix of drag and drop and your suggestions. I had to tinker with the release time on the audio_sound_gain code execution but I got it to a place that I am happy with.

Screen Shot 2019-11-15 at 4.13.10 PM.png

Thanks again for your help!
 
R

robproctor83

Guest
If I could make any suggestion, it would be to forgo using drag and drop events and instead learn GML. You will likely end up spending just as much time trying to figure out how to use the limited d&d system as you would just learning how to code. GML is very easy to learn, especially for beginners.
 
If I could make any suggestion, it would be to forgo using drag and drop events and instead learn GML. You will likely end up spending just as much time trying to figure out how to use the limited d&d system as you would just learning how to code. GML is very easy to learn, especially for beginners.
While I don't entirely disagree with your statement (and you're probably right), I am a visual learner and the D&D system facilitates that handicap. I plan to slowly transition into using GML solely after getting my feet wet as this is only my 2nd week doing anything coding or game related in my life. Plus, I'm not sure if you noticed but I did use GML code where D&D fell short. Total newb here... :) I appreciate the feedback though.
 
R

robproctor83

Guest
All good, if it works for you then that's all that matters. I do know that with gm2 they made the drag and drop stuff a lot better, haven't messed with it since v1, so maybe it's a lot more robust now.

I'd still recommend learning some gml as you go along, the online docs are really good and have good visual examples of things. Learning basics like variables, scripts, conditions and loops are all essential parts to making a game. Best of luck, post back if u run into more issues.
 
Top