AudioEffectEQ in Godot – Complete Guide

Audio quality is one of the critical aspects that can make or break a gaming experience. It’s not just about the music or sound effects, but how they are managed and modified to fit various environments, situations, and platforms. That’s where AudioEffectEQ enters the scene. This tool in the Godot Engine provides immense power over the sonic landscape of a game, allowing developers to fine-tune audio frequencies with precision and create experiences that resonate, quite literally, with their audience. Dive into this tutorial to learn about the AudioEffectEQ class in Godot 4, and discover how to control the auditory heartbeat of your games.

What is AudioEffectEQ?

AudioEffectEQ is a base class for creating custom equalizers in Godot 4 that lets you modulate and control different frequencies within an audio stream. It comes with inherited specific classes like AudioEffectEQ6, AudioEffectEQ10, and AudioEffectEQ21, which offer different numbers of frequency bands for detailed adjustments.

What is it for?

Equalizers are vital for balancing your game’s audio across various sounds and music tracks, adjusting them to fit different environments, or crafting the right atmospheric effect. Whether you’re creating a game to be played on bulky desktop speakers, delicate mobile devices, or immersive headphones, an EQ can help you ensure your game’s audio plays out just as you’ve envisioned.

Why Should I Learn It?

Learning how to use AudioEffectEQ is essential for mastering the sound design of your games. The ability to enhance audio quality and tailor sound to any situation or device can not only improve the gaming experience but also prevent common audio issues that could distract or detract from gameplay. Understanding equalization is a fundamental skill for game developers, and it can set you apart in the industry. With this ability, you can:
– Address auditory deficiencies in your game
– Fully master and characterize your game’s mix
– Optimize audio performance for both speakers and headphones.

By the end of this tutorial, you’ll have a solid understanding of AudioEffectEQ in Godot 4 and practical knowledge to apply it to your projects. Let’s make your game sound as good as it looks!

CTA Small Image
FREE COURSES AT ZENVA
LEARN GAME DEVELOPMENT, PYTHON AND MORE
ACCESS FOR FREE
AVAILABLE FOR A LIMITED TIME ONLY

Creating Your First Equalizer

To start shaping your game’s audio, you first need to create an instance of an AudioEffectEQ class. You can choose from the subclasses based on the number of bands you need. Let’s begin with AudioEffectEQ6, which provides six bands to work with.

var eq = AudioEffectEQ6.new()

With your EQ instance created, the next step is to assign it to an Audio Bus. Audio Buses handle the processing of sound and can have multiple effects chained together.

var bus_idx = AudioServer.get_bus_index("Master")
AudioServer.add_bus_effect(bus_idx, eq, -1)

Adjusting Frequency Bands

Now, let’s manipulate the different bands to customize your audio. AudioEffectEQ6 features six bands, each of which corresponds to a range of frequencies. Here, we set the gain for each band, which can be a value between -60 and 24 decibels.

eq.set_band_gain_db(0, -5)  // Reduce low frequencies
eq.set_band_gain_db(1, 3)   // Slightly boost lower-mid frequencies
eq.set_band_gain_db(2, -2)  // Cut mid frequencies
eq.set_band_gain_db(3, 4)   // Boost upper-mid frequencies
eq.set_band_gain_db(4, -3)  // Reduce presence
eq.set_band_gain_db(5, 6)   // Increase brilliance

Modifying Band Frequency and Q

Changing band frequencies allows you to specify which frequencies the band will center on. Meanwhile, the Q factor controls the width of the frequency range affected by each band. A higher Q results in a narrower band.

eq.set_band_frequency_hz(0, 100)  // Set the low band to 100Hz
eq.set_band_frequency_hz(2, 1000) // Set mid band to 1kHz

eq.set_band_q(0, 1.1)  // Narrow the Q for the low band
eq.set_band_q(2, 0.7)  // Widen the Q for the mid band

Applying EQ to Specific Sounds

You may not want all game sounds to be affected equally. You can apply EQ to only specific audio streams by sending them through a different Audio Bus where your EQ is applied.

Create a new Audio Bus and add your EQ effect to it:

AudioServer.add_bus(AudioServer.get_bus_count())
AudioServer.set_bus_name(AudioServer.get_bus_count() - 1, "CustomEQBus")
var custom_bus_idx = AudioServer.get_bus_index("CustomEQBus")
AudioServer.add_bus_effect(custom_bus_idx, eq, -1)

Now direct a specific sound to use the new Audio Bus:

var stream_player = AudioStreamPlayer.new()
stream_player.bus = "CustomEQBus"
add_child(stream_player)
stream_player.stream = preload("res://path_to_your_audio_file.ogg")
stream_player.play()

By following these examples, you’ve learned how to create an equalizer, tweak frequency bands, adjust the Q factor for precision, and apply equalization effects to specific audio streams. With this knowledge, you’re well on your way to mastering audio manipulation in Godot 4 to immerse players in your game world even deeper. Stay tuned for the next part of our tutorial, where we’ll delve into some advanced techniques to elevate your audio effects!

Advanced EQ Techniques

When you start refining your game’s audio with advanced EQ techniques, you’re not just adjusting sounds—you’re sculpting an acoustic environment that can profoundly affect the player experience. Let’s explore some of these techniques.

Automating EQ Adjustments
In dynamic game environments, you might want to change EQ settings over time or based on in-game events. Godot’s animation system can be harnessed to automate EQ parameters.

var anim = AnimationPlayer.new()
add_child(anim)

var track_name = anim.add_track(Animation.TYPE_VALUE)
anim.track_set_path(track_name, "Master/EQ6:band_gain_db")

var animation = Animation.new()
animation.set_length(4.0)
animation.track_insert_key(track_name, 0.0, eq.get_band_gain_db(0))
animation.track_insert_key(track_name, 2.0, 5)  // Peak the gain at 2 seconds
animation.track_insert_key(track_name, 4.0, eq.get_band_gain_db(0))
anim.add_animation("EQ_Gain_Animation", animation)

anim.play("EQ_Gain_Animation")

Using Bypass for A/B Testing
When tweaking the sound, it can be useful to quickly compare the EQ’ed sound with the original. The bypass property allows you to toggle the EQ effect in real-time.

eq.bypass = true  // Disable the EQ
# ...listen to the audio...
eq.bypass = false  // Re-enable the EQ

Creating Custom Equalizer Profiles
To streamline the process of applying EQ settings for different sounds, create multiple “profile” presets of your AudioEffectEQ, which you can quickly apply when needed.

var eq_preset_for_dialogue = AudioEffectEQ10.new()
# Apply specific settings for dialogue
eq_preset_for_dialogue.set_band_gain_db(0, 3)
# ...other settings...

var eq_preset_for_ambient = AudioEffectEQ10.new()
# Apply specific settings for ambient sounds
eq_preset_for_ambient.set_band_gain_db(3, -2)
# ...other settings...

Creating an EQ Fade Out
When transitioning between scenes or for dramatic effect, you might want to fade out your music or sounds. The EQ can be used creatively to achieve a “fading out” impression by reducing high frequencies over time.

var fade_out_time = 5.0  # Time in seconds for fade out
var timer = Timer.new()
add_child(timer)

timer.wait_time = fade_out_time
timer.one_shot = true

timer.connect("timeout", self, "_on_Timer_timeout")
timer.start()

func _on_Timer_timeout():
    eq.set_band_gain_db(4, -24)
    eq.set_band_gain_db(5, -24)

Using EQ to Mimic Environments
The classic use of EQ is to simulate how sound would be heard in different environments, such as underwater, inside a cave, or in an open field.

# Underwater filter: Muffled high frequencies
eq.set_band_gain_db(4, -15)
eq.set_band_gain_db(5, -30)

# Cave reverb: Boosted low frequencies and reduced highs
eq.set_band_gain_db(0, 6)
eq.set_band_gain_db(5, -20)

By mastering these advanced EQ techniques, you can create a more immersive and responsive soundscape for your games. Different scenarios, from combat to stealth, from dialogues to environmental ambiance, can all benefit from thoughtful equalization. Remember, sound is half the experience in gaming—good EQ settings can transform a decent game into an unforgettable one. With Godot’s flexible audio system and your newfound knowledge, you’re now equipped to take full control of your game’s audio narrative. Happy sound designing!Utilize Side-Chain Compression With EQ
Side-chain compression, widely used in music production, can be creatively applied in games to make certain sounds stand out by reducing the volume of competing frequencies when a certain audio signal plays. For example, when a character speaks, you can subtly lower the game music’s volume to ensure clear dialogue.

# Setup a bus for the music with an EQ and a compressor
var music_bus_idx = AudioServer.add_bus(AudioServer.get_bus_count())
AudioServer.set_bus_name(music_bus_idx, "MusicBus")
var eq_for_music = AudioEffectEQ6.new()
var compressor = AudioEffectCompressor.new()
AudioServer.add_bus_effect(music_bus_idx, eq_for_music, 0)
AudioServer.add_bus_effect(music_bus_idx, compressor, 1)

# Setup a bus for the dialogue
var dialogue_bus_idx = AudioServer.add_bus(AudioServer.get_bus_count())
AudioServer.set_bus_name(dialogue_bus_idx, "DialogueBus")

# Side-chain the dialogue to the compressor on the music bus
compressor.set_sidechain("DialogueBus")

# Setup an AudioStreamPlayer for the music
var music_player = AudioStreamPlayer.new()
music_player.bus = "MusicBus"
add_child(music_player)
music_player.stream = preload("res://path_to_your_music_file.ogg")

# Setup an AudioStreamPlayer for the dialogue
var dialogue_player = AudioStreamPlayer.new()
dialogue_player.bus = "DialogueBus"
add_child(dialogue_player)
dialogue_player.stream = preload("res://path_to_your_dialogue_file.ogg")

# Play both streams
music_player.play()
dialogue_player.play()

Dynamic EQ According to Player Actions
EQ settings can change in response to player actions to emphasize the impact of those actions. For example, you might want to create a temporary audio effect when the player takes damage.

# Define a function to apply an EQ effect dynamically
func apply_damage_sound_effect():
    var player_damage_eq = AudioEffectEQ6.new()
    player_damage_eq.set_band_gain_db(1, -12)  # Dip mid frequencies for a 'hollow' effect
    player_damage_eq.bypass = false  # Ensure EQ is active

    # Assume 'PlayerBus' has already been created and set up
    var player_bus_idx = AudioServer.get_bus_index("PlayerBus")
    AudioServer.add_bus_effect(player_bus_idx, player_damage_eq, 0)

    # Use a timer for the temporary effect
    var timer = Timer.new()
    timer.wait_time = 1.0  # Duration of the effect
    timer.one_shot = true
    timer.connect("timeout", self, "_on_Timer_timeout", [player_damage_eq, player_bus_idx])
    add_child(timer)
    timer.start()

func _on_Timer_timeout(effect, bus_idx):
    AudioServer.remove_bus_effect(bus_idx, effect)

Simulate Location-Based Sounds
With EQ, you can modify the audio to create the illusion that certain sounds are coming from specific directions or distances. This can be useful to simulate off-screen events or to indicate directionality in a stereo soundscape.

# Create an EQ that simulates a sound coming from the left side
var left_side_eq = AudioEffectEQ10.new()
left_side_eq.set_band_gain_db(0, 3)  # Increase low frequencies slightly
left_side_eq.set_band_gain_db(9, -6)  # Decrease high frequencies for 'distance' effect

# Apply the EQ to a sound destined to simulate coming from the left
var left_side_sound = AudioStreamPlayer2D.new()
left_side_sound.position = Vector2(100, 0)  # Position to the left
left_side_sound.bus = "LeftSideBus"         # Assume this bus has been set up and added
AudioServer.add_bus_effect(AudioServer.get_bus_index("LeftSideBus"), left_side_eq, -1)
add_child(left_side_sound)
left_side_sound.stream = preload("res://path_to_your_audio_file.ogg")
left_side_sound.play()

Enhance Environmental Effects With Filter Sweeps
Using EQ sweeps, you can enhance in-game environmental changes, such as transitioning from a dense forest to an open field, by sweeping the EQ frequencies over time to match the environmental characteristics.

func start_environment_transition():
    var environment_eq = AudioEffectEQ10.new()
    var environment_bus_idx = AudioServer.get_bus_index("EnvironmentBus") 

    AudioServer.add_bus_effect(environment_bus_idx, environment_eq, -1)

    var anim_player = AnimationPlayer.new()
    add_child(anim_player)
    var anim = Animation.new()
    anim.set_length(10)  # The length of the transition animation in seconds

    # Automate an EQ sweep across bands to simulate an environment transition
    for band_index in range(environment_eq.get_band_count()):
        var track_name = anim_player.add_track(Animation.TYPE_VALUE)
        var band_path = "EnvironmentBus/EQ10:band_gain_db:" + String(band_index)
        anim_player.track_set_path(track_name, band_path)
        anim.track_insert_key(track_name, 0.0, environment_eq.get_band_gain_db(band_index))
        anim.track_insert_key(track_name, 5.0, -5)  # Decrease by 5dB in the middle of transition
        anim.track_insert_key(track_name, 10.0, environment_eq.get_band_gain_db(band_index))

    anim_player.add_animation("Environment_Transition", anim)
    anim_player.play("Environment_Transition")

With these examples, you see how Godot’s AudioEffectEQ can be a powerful tool for dynamically crafting immersive audio experiences that respond to gameplay and environmental contexts. By understanding and utilizing these techniques, your game’s audio landscape can be just as dynamic and interactive as its visual counterpart. Sound now becomes not just a background element but an integral part of gameplay feedback and player immersion. Go forth and create vibrant auditory worlds that captivate and engage your players.

Continue Your Game Development Journey

With the knowledge gained from this tutorial, you’re now well-equipped to tackle the auditory aspects of your games in Godot. But why stop here? Your journey in game development is just beginning, and there’s an entire world of design and programming waiting for you to explore it.

One of the best ways to keep learning and refining your skills is through our Godot Game Development Mini-Degree. This series of courses is designed to take you further into the game development process with Godot, covering topics that range from 2D and 3D asset handling to complex gameplay mechanics.

Whether you’re looking to dive into the specifics of GDScript or to polish your skills in creating engaging player experiences, our Mini-Degree has got you covered. It’s perfect for beginners with no prior experience, as well as those looking to advance their existing skills. Plus, after completing it, you’ll have a myriad of practical projects to add to your portfolio.

For an even broader array of Godot tutorials and courses, check out our full collection of Godot courses at Zenva Academy. Take the next step in your game development career with us – at your own pace, on your own terms. The path to becoming a professional game developer is at your fingertips!

Conclusion

In the world of game development, the mastery of audio with tools like AudioEffectEQ can elevate your projects from good to unforgettable. Remember, great games are not just seen; they are also felt and heard. By applying the techniques covered in this tutorial, your game’s audio will not just mimic reality but will enhance the player’s emotional connection to your virtual worlds. So, integrate what you’ve learned, let your creativity flow, and make each audio experience as impactful as the gameplay itself.

We at Zenva believe in your potential to create amazing games and are committed to supporting every step of your learning journey. If you’re ready to expand upon these skills and delve deeper into game creation, our Godot Game Development Mini-Degree awaits. Join us and thousands of other students who have transformed their visions into playable realities. Let’s code, create, and connect through the power of game development!

FREE COURSES
Python Blog Image

FINAL DAYS: Unlock coding courses in Unity, Godot, Unreal, Python and more.