GameMaker has built-in audio effects such as reverb, delay and frequency filters that let you enhance the audio experience for your players.
In this tutorial we’re going to use the reverb, delay, low-pass filter and bitcrusher effects.
For a cave level, I want every sound in my game to have a reverb. We can do this easily by applying the reverb effect to the “main audio bus”.
All the audio in your game goes through an “audio bus”. We will later create our own buses, however there is already a default bus called the "main audio bus".
If you apply an effect to this bus, every sound in your game gets that effect, as they all go through this bus.
var _reverb = audio_effect_create(AudioEffectType.Reverb1); _reverb.mix = 0.8; audio_bus_main.effects = _reverb;
- This creates the reverb effect. It’s called Reverb1 to allow for more reverb types to be added in the future.
- It sets the mix of the reverb effect to 0.8, meaning 80% of the sound will be the reverberated version, and 20% will be the original. You have to set this after creating an effect, as by default the mix is set to 0, which results in no change in the sound.
- Finally it applies the effect to the first effect slot in the main audio bus. An audio bus allows up to 8 slots.
- You can’t do array_push() on the effects array as it’s a fixed 8-slot array.
With this, everything in your game gets reverb!
Delay With Custom Bus
I want to apply delay to an “attack” sound, to make it more impactful. For this I need to use a custom audio bus.
The bus will have a delay effect, so my emitter audio goes through the bus, with the delay effect applied.
In code, this means we need to create an emitter and a bus, and connect them.
Then we apply a delay effect to the bus, and play our sound through the connected emitter:
// Delay route delay_emitter = audio_emitter_create(); delay_bus = audio_bus_create(); audio_emitter_bus(delay_emitter, delay_bus); // Delay effect var _delay_effect = audio_effect_create(AudioEffectType.Delay); _delay_effect.feedback = 0.55; _delay_effect.time = 0.1; _delay_effect.mix = 0.7; delay_bus.effects = _delay_effect;
Then play the sound whenever you need to:
audio_play_sound_on(delay_emitter, snd_punch, 0, 1);
This will give your attack sound an impactful delay effect:
Destroy the audio emitter with audio_emitter_free() when you no longer need it, for example, in the Clean Up event. You don’t need to free any audio buses as they’re automatically garbage collected.
“What are they talking about? Shh, it's a secret.”
For people talking on the other side of a wall, a low-pass filter helps sell the effect. You can do it just like the delay:
// Low-pass route lp_emitter = audio_emitter_create(); lp_bus = audio_bus_create(); audio_emitter_bus(lp_emitter, lp_bus); // Low-pass effect var _lp_effect = audio_effect_create(AudioEffectType.LPF2); _lp_effect.cutoff = 500; lp_bus.effects = _lp_effect; // Play audio audio_play_sound_on(lp_emitter, snd_voice, 1, 1);
This is the result:
By now, you know how to use audio effects. Still, I wanted to show you the Bitcrusher effect, which is pretty cool.
It reduces the sample rate and resolution of a sound, making it stand out and feel less “ambient”. Applying heavy “bitcrushing” makes a sound more retro.
// Bitcrusher route bc_emitter = audio_emitter_create(); bc_bus = audio_bus_create(); audio_emitter_bus(bc_emitter, bc_bus); // Bitcrusher effect var _bc_effect = audio_effect_create(AudioEffectType.Bitcrusher); _bc_effect.factor = 20; bc_bus.effects = _bc_effect; // Play audio audio_play_sound_on(bc_emitter, snd_item, 0, 1);
Here is a sound without a bitcrusher, with a light bitcrusher (factor of 10) and with a heavy one (factor of 50):
There is also a “high-pass filter” effect, which lets higher frequencies through, as opposed to the “low-pass filter” effect which we used to only let the lower frequencies be audible.
Another effect is “gain”, which is a simple volume-changing effect.
If you’re going to use emitters for your audio effects, remember you can also position your emitters freely in 3D space for positional audio.
Read all about audio effects in the manual.