Feature Focus: Audio effects

21
Official Construct Post
Ashley's avatar
Ashley
  • 16 Feb, 2023
  • 1,968 words
  • ~8-13 mins
  • 2,532 visits
  • 4 favourites

Feature Focus is a series of blog posts and videos where we occasionally highlight some of the best features of Construct. This time around we're talking about audio features and the various cool audio effects built in to Construct!

Playback options

The basic playback of audio uses the Play action. Sounds can be played at a specific volume, which is important to specify at playback time, as setting the volume shortly after playing could cause momentary playback at the wrong volume. Sounds can also be set to looping and a stereo pan set from -100 (left) through 0 (center) to 100 (right).

The Fade volume action provides a convenient way to adjust the volume over time, including fading out and then automatically stopping playback, or fading in and then continuing playback. The playback rate can also be adjusted, which also shifts the pitch, allowing for fun effects like slowing down the audio playback for slow-motion effects, or adjusting the pitch of a looping engine sound. There are also the standard pause/resume, seek, stop and mute playback controls that you'd expect, as well as a master volume setting and Silent mode to provide an easy mute setting.

Audio effects

Thanks to the power of the Web Audio API, Construct has also long supported a wide selection of audio effects. Try the Audio effects example for an interactive demo of some of them! (Remember to turn your sound up.)

The Audio Effects example, with a simple sound board that lets you try out several effects.The Audio Effects example, with a simple sound board that lets you try out several effects.

Here is a quick run-down of the audio effects Construct supports.

Compressor effect

The compressor effect allows for dynamic range compression (not to be confused with data compression used in lossy audio codecs). This is a standard audio processing effect that allows for control over volume levels, such as reducing the volume of sounds above a certain level. The compressor threshold, knee, ratio, and attack and release times can all be specified and adjusted over time.

Convolution effect

Convolution is a very powerful type of effect that allows using one sound to modify another. It can produce a range of effects such as reverb or a "telephone quality" sound.

Convolution works by providing a sound file that contains what's called an impulse response. An impulse is basically single moment of high volume, which sounds like a loud click, and the response is the sound that follows that in a space, such as the reverb. This can be synthesized, or recorded in a real place.

Then the impulse response sound is used to transform playback of another sound. What's cool about this is you can record the response of real-world places and then import that to your game as a convolution effect. For example if you record an impulse response in a large warehouse, you can then add that as a convolution effect in your game and get the same reverb effect as the large warehouse had. So you can record real-world environments and get your game to sound like they're taking place there! This could be a fun recording side-project for anyone out there who has the right gear and wants to experiment with convolution effects.

A saxophonist enjoying the reverb under a railway arch - probably also a good place to try capturing an impulse response!A saxophonist enjoying the reverb under a railway arch - probably also a good place to try capturing an impulse response!

Delay effect

A delay effect essentially repeats the sound after a short delay at a lower volume. It's an easy way to create a basic kind of echo effect.

Distortion effect

The distortion effect deliberately distorts the sound, similar to how a distorted guitar changes the clean guitar sound. It's based on a wave-shaping effect and has parameters for the threshold, headroom, drive and make-up gain.

Filter effect

In Construct the filter effect is based on a biquad filter that can implement various frequency-altering effects, such as a low-pass filter that "filters out" high frequency sounds for a kind of muffled effect. Several types of filters are supported including (in addition to low-pass) high-pass, band-pass, low/high-shelf, notch, and more. The filter frequency, detune, Q and gain can all be adjusted.

Flanger effect

The "flanger" is a classic audio effect that mixes the sound with a delayed version that is varied over time. The parameters can also be adjusted for a chorus style effect, another well-known classic audio effect.

Phaser effect

Another classic and personal favorite of mine, the phaser effect is based on an all-pass filter that varies over time, creating a sweeping sci-fi style sound.

Ring modulation effect

Another sci-fi classic - famously used to create the Dalek sounds in Dr. Who - the ring modulation effect produces a highly distorted alien or robotic sounding effect.

Tremolo effect

The tremolo effect rapidly adjusts the volume up and down at a given frequency. It's pretty straightforward but has creative uses for stuttering or vibrato style effects.

Analyser effect

Adding an analyser effect doesn't actually change the sound, but it allows retrieving the frequency information of the sound in real-time, such as to draw a live spectrum. See the Audio Analyser example for a demo.

A spectrum shown in the 'Audio analyser' example.A spectrum shown in the 'Audio analyser' example.

Utility effects

Construct also provides a set of effects for utility purposes. These can be inserted in to effect chains to help control groups of sounds. These include a gain (volume) effect, mute and stereo pan.

Tags

To provide a convenient way to modify playback of existing sounds, such as to change the volume or playback rate in response to gameplay, Construct uses a tagging system. For example a sound could be played with the tag "engine", and later the sound altered by referring back to the same tag.

Better yet, our latest beta releases have introduced support for multiple tags. This lets you specify additional tags separated by spaces, such as "player hit" and "monster hit". Then the tag "player" will refer to only the first sound, but the tag "hit" will refer to both those sounds. This allows for conveniently managing entire sets of sounds, such as adjusting the volume of all environmental sounds, while still allowing other tags for individual control of sounds.

3D Audio

Construct also supports positioned sounds. This means rather than merely playing a sound, it is played at a specific position in the layout. Then the sound is processed, adjusting the volume, pan and filtering, to make it sound like it is coming from that position relative to the view or player.

This is in fact powered by a true 3D audio engine! It works well in 2D, using X and Y co-ordinates and assuming the camera is looking down on the layout. However thanks to a recent Construct update you can now also specify the Z co-ordinate of sounds, and specify a 3D orientation of the listener. This works nicely with Construct's other 3D features, allowing sound playback to adapt to a 3D Camera view.

The 'Foggy Outbreak' example demonstrates using a 3D camera, a situation where it would also be important to have 3D Audio for the right kind of atmospheric playback.The 'Foggy Outbreak' example demonstrates using a 3D camera, a situation where it would also be important to have 3D Audio for the right kind of atmospheric playback.

Sample-accurate scheduling

A game running at 60 FPS will advance in 16ms steps. This produces a good visual result, but is sometimes not accurate enough for scheduling precise playback of sounds. It can be especially noticable if you want to repeat a sound very quickly at a short interval.

Fortunately Construct provides sample-accurate scheduling, so you can specify an exact time for a playback to start, down to the audio sample. The Audio scheduling example demonstrates how this can be used to improve the timing accuracy of playback.

Recording

Despite the name, Construct's Video Recorder object can make audio recordings with no video track. This can also be connected up to a microphone source from the User Media object to record audio clips which can then be downloaded or shared. See the Voice Recorder example for a demo of this!

Memory management

By default Construct automatically manages memory for sounds, and for many games that works fine. However if you have an enormous amount of audio in your game, you may need to manage when sounds are loaded and unloaded from memory. First untick Preload sounds in Project Properties to turn off Construct automatically loading sounds on startup. Then the Preload actions allow ensuring audio is loaded and decoded ready for prompt playback, and the Unload actions allow freeing memory.

Scripting possibilities

When using JavaScript coding in Construct, you can take advantage of the full scope of the Web Audio API - a mature, powerful and high-performance audio processing API provided by all modern browsers. You can find a simple example of playback from code in the Audio Scripting example. With further coding you can do advanced things like set up a custom audio routing graph with advanced effects, custom low-latency multithreaded audio processing code with AudioWorklet, and synthesizing audio from code - an example of which you can find in the Sound Synthesis example.

Codec support

While browsers can play a range of audio formats, for Construct we've selected WebM Opus as a single format to support on all platforms. WebM is a container format derived from Matroska designed specifically for the web which has achieved widespread support across many other tools and platforms. Opus is a totally open, royalty-free lossy audio codec with very good quality while having high levels of data compression. Construct's Import Audio dialog lets you import a range of formats including WAV, FLAC, MP3, AAC and Ogg Vorbis, automatically converting them to WebM Opus for you.

Over the years browser support for WebM Opus has increased to the point where it's nearly supported by all browsers. The only place it's not supported? Safari on iOS. It's even supported in Safari on macOS, but mysteriously it's still not supported on iPhones or iPads, and Apple won't say anything about why this is or whether they even intend to fix it. This kind of apparent glitch or oversight remaining long-term, with Apple saying nothing useful about it, is sadly entirely typical of how Apple operate. However we've long had a backup WebAssembly decoder for WebM Opus, so Construct can just resort to that if it's not supported and audio playback continues working fine. Still, it would be nice to get rid of that and rely on built-in browser support. So if anyone from Apple is reading this, what's going on? Doesn't Apple care about interoperability and consistency across the web?

Conclusion

Construct's audio support is powerful and flexible, with all the usual playback features, a range of intriguing audio effects that can add a lot of atmosphere to your games, a full 3D audio engine for positioned sounds, sample-accurate scheduling for games with strict timing demands, recording, memory management for large projects, and all with an advanced modern audio codec which provides very good quality even with low data rates, helping reduce the download size of your project. If you're a coder then you can also jump in to the full Web Audio API, and do pretty much anything you can dream of - it's been widely supported for years and is incredibly powerful, and is what underpins all of Construct's audio support. And it all comes with the very browser you're reading this blog in! It's yet another example of the incredible power of the web platform, and how we've taken full advantage of that to bring you a wide set of creative features in Construct.

Past feature focus blogs

Construct is absolutely stuffed with impressive features that are easy to use but allow great scope for creativity. You can learn more about some of them in our past Feature Focus blogs below.

Subscribe

Get emailed when there are new posts!

  • 3 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • Wow, I never knew about all of these! Also, on a side note, will we get Animated Tiled Backgrounds and 9 Patches anytime soon?

  • The Convolution effect is very powerful, I used it in a dungeon game to make the sound effects more coherent by adding an echo to everything.

  • great article! I have an educational game that requires the use of many audio files, can I make more than 100 audios that can be inserted and played individually? another question is about this ios issue, if i export as an ios app will the audios work on ipad? thanks!!