Audio filters
Updated
Audio filters change how a source sounds. Muffle music behind a closed door, thin a voice into a walkie-talkie, give a cave its echo, a cathedral its reverberation, a synth a shimmering chorus or a guitar amp its grit. Each filter is a component you add to an audio entity. The source is heard through every enabled filter on its entity, one after the other, in the order the components are listed.
Before you start
Section titled “Before you start”- Read Audio sources to know the audio entities and how to reach their components from a script.
- Every audio entity accepts filters: Audio, Positional Audio, Audio Ambisonic, Audio Tone and Positional Audio Tone.
- A few terms used below:
- Frequency is the pitch of a part of the sound, in hertz (Hz). Bass is low (around 50 to 250 Hz), voices sit in the middle, cymbals are high (several thousand Hz).
- Cutoff is the frequency where a low-pass or high-pass filter starts cutting.
- Dry is the untouched sound; wet is the effect. The
wetprop mixes the two.
The filters
Section titled “The filters”| Component | Class | Type | What it does |
|---|---|---|---|
| Low pass | Audio |
comp- |
Cuts the highs above the cutoff: muffles, as through a wall or under water. |
| High pass | Audio |
comp- |
Cuts the lows below the cutoff: thins, as through a phone speaker. |
| Echo | Audio |
comp- |
Repeats the sound, each repeat quieter and duller. |
| Reverb | Audio |
comp- |
Puts the sound in a room, with a tail that dies away. |
| Chorus | Audio |
comp- |
Thickens and widens the sound with two wavering copies. |
| Distortion | Audio |
comp- |
Overdrives the sound, from a warm edge to a hard crunch. |
How the chain works
Section titled “How the chain works”- Order. The source feeds the first enabled filter, which feeds the next, and the last feeds the listener. A low pass before a reverb muffles the sound going into the room; after it, it muffles the room too.
- After the source. Filters come after the source’s volume, distance falloff, fade and zone mute. So a fade or a zone mute feeds the effect, and when the source stops, an echo or reverb tail dies away by itself instead of being cut.
- Free when unused. A source without filters goes straight to the listener, and a disabled filter costs nothing.
- Rewiring. The chain is rebuilt only when a filter is added, removed, enabled or disabled. Changing a prop never rewires anything.
Turn a filter on or off with filter.setEnabled(on), and change its sound with filter.setProps({ … }). Add one at runtime with entity.addComponent(new AudioReverbFilterComponent({ … })); each filter’s constructor takes its props.
Which changes glide
Section titled “Which changes glide”Most props glide to a new value over a few milliseconds, so a slider or a script can change them every frame without clicks. A few rebuild part of the effect and apply at once:
| Filter | Glides smoothly | Applies at once |
|---|---|---|
| Low pass, High pass | frequency, q |
rolloff |
| Echo | delayTime (with a slower glide that bends pitch like tape), feedback, highCut, wet |
none |
| Chorus | frequency, delayTime, depth, wet |
none |
| Reverb | wet |
decay, preDelay |
| Distortion | none | amount, wet |
Change the props in the right-hand column on an event, not every frame. The reverb in particular regenerates its room when decay or preDelay change.
Mixing with wet
Section titled “Mixing with wet”Echo, Reverb, Chorus and Distortion mix their effect with the dry sound by wet, from 0 (dry only) to 1 (effect only). Each mix keeps the overall level steady across the range, so moving wet changes the character of the sound, not its loudness. The low-pass and high-pass filters have no wet: they replace the signal.
Low pass and high pass
Section titled “Low pass and high pass”Both are smooth filters, flat up to the cutoff, then falling more steeply with a higher rolloff.
| Prop | Type | Default | Description |
|---|---|---|---|
frequency |
number | 5000 for low pass, 200 for high pass |
Cutoff in Hz, from 10 to 22000. |
q |
number | 0.707 |
Resonance, from 0.1 to 20. The default is flat; higher values add a peak at the cutoff, for a more synthetic, “wah” sound. |
rolloff |
12, 24 or 48 |
24 |
How steeply it cuts past the cutoff, in dB per octave. |
Typical low-pass cutoffs: 20000 leaves the sound open, 2000 sounds like the next room, 800 sounds behind a closed door, 300 sounds under water.
A delay that feeds back into itself through a high cut, so each repeat is quieter and duller than the one before.
| Prop | Type | Default | Description |
|---|---|---|---|
delayTime |
number | 0.25 |
Seconds between repeats, from 0.01 to 5. |
feedback |
number | 0.5 |
How much of each repeat feeds the next, from 0 to 0.95. Higher lasts longer; repeats always die away. |
highCut |
number | 6000 |
Frequency in Hz above which each repeat loses brightness, from 200 to 22000. |
wet |
number | 0.5 |
Effect mix, from 0 to 1. |
Reverb
Section titled “Reverb”A generated stereo room: the sound’s reflections fade out over decay, growing darker as they die, after preDelay of silence. A longer decay makes a bigger room, not a louder sound; wet alone sets the balance.
| Prop | Type | Default | Description |
|---|---|---|---|
decay |
number | 1.5 |
Seconds the tail takes to die away, from 0.1 to 10. About 0.5 is a small room, 2 a hall, 5 or more a cathedral or a cave. |
preDelay |
number | 0.01 |
Seconds of silence before the tail, from 0 to 0.5. A longer pre-delay suggests a larger space. |
wet |
number | 0.5 |
Effect mix, from 0 to 1. |
The same decay and preDelay always give the same room.
Chorus
Section titled “Chorus”Two copies of the sound, one per side, each delayed by a few milliseconds that waver slowly. The copies detune against each other into a wide, shimmering stereo image. A mono source is spread to both sides.
An Audio Chorus Filter on an ambient pad: a UI Switch fades its wet mix in and out with a tween, and two sliders set how fast and how far the copies waver.
With your sound on (headphones help), flip Chorus on and off and listen to the pad widen and shimmer. Raise Speed and Depth for a stronger wobble. Drag outside the panel to orbit the camera, scroll to zoom.
| Prop | Type | Default | Description |
|---|---|---|---|
frequency |
number | 0.8 |
How fast the copies waver, in Hz, from 0 to 20. |
delayTime |
number | 7 |
The copies’ average delay, in milliseconds, from 1 to 50. |
depth |
number | 0.35 |
How far the delay swings around delayTime, as a share of it, from 0 to 1. |
wet |
number | 0.5 |
Effect mix, from 0 to 1. |
Distortion
Section titled “Distortion”A saturation curve that adds harmonics as it drives the sound harder. It keeps moderate material at the same level whatever the amount: more drive means more grit, not more volume.
An Audio Distortion Filter on the music switches on below 60 health and grows harder with each hit, in four steps; healing switches it off again.
With your sound on, press Take a hit a few times: past the third hit the beat starts to crunch, harder at each hit. Press Heal to clean it. The beat is a short loop generated for this example. Drag outside the panel to orbit the camera.
| Prop | Type | Default | Description |
|---|---|---|---|
amount |
number | 0.4 |
How hard the sound is driven, from 0 to 1: clean, a warm edge, then a hard crunch. |
wet |
number | 1 |
Effect mix, from 0 to 1. |
Examples
Section titled “Examples”1. Music behind a door
Section titled “1. Music behind a door”Muffle the music while a door is closed and open it up when the door opens.
#pragma lifecycle(startup)
let lowPass;
function startup() { lowPass = findEntity('Party Music').getComponent(AudioLowPassFilterComponent);
on('door/open', () => lowPass.setProps({ frequency: 20000 })); on('door/close', () => lowPass.setProps({ frequency: 600 }));}Party music muffled behind a closed door opens up when the door opens: a Low Pass filter on a Positional Audio, its cutoff changed by a Behavior script on door signals.
With your sound on, press Open door and Close door and listen to the music change. Drag to orbit the camera, scroll to zoom.
How it works:
- The filter is authored on the entity at 600 Hz, so the party sounds muffled from the start.
setProps({ frequency })glides the cutoff to its new value, so the change is smooth even while the music plays.20000Hz is above almost everything people hear, so the filter is effectively open, without switching it off and risking a click.
2. A walkie-talkie voice
Section titled “2. A walkie-talkie voice”Add a band of filters at runtime to make any voice line sound like a radio.
#pragma lifecycle(startup)
let voice;
function startup() { const commander = findEntity('Commander'); voice = commander.getComponent(AudioComponent);
// Order matters: thin first, then cut the highs, then a little grit. commander.addComponent(new AudioHighPassFilterComponent({ frequency: 400, rolloff: 24 })); commander.addComponent(new AudioLowPassFilterComponent({ frequency: 3000, rolloff: 24 })); commander.addComponent(new AudioDistortionFilterComponent({ amount: 0.3, wet: 0.5 }));
on('radio/call', () => { voice.stop(); voice.play(); });}A Behavior script adds a High Pass, a Low Pass and a Distortion filter to an Audio entity at startup, so whatever it plays sounds like a small radio speaker.
With your sound on, press Play the call: the loop comes out thin and crackly, with its bass and air filtered away. The beat is a short loop generated for this example. Drag to orbit the camera, scroll to zoom.
How it works:
- A high pass at 400 Hz removes the body of the voice and a low pass at 3000 Hz removes its air. Together they keep only the narrow middle band a small speaker plays.
- A light distortion, half mixed in, adds the crackle of a cheap speaker.
- Components added with
addComponentjoin the chain in the order they are added, after any filters already on the entity.
3. Entering a cave
Section titled “3. Entering a cave”Fade in a reverb when the listener enters a cave zone, and out when they leave.
#pragma lifecycle(startup)
let reverb;let mix = 0;let fade;
function setWet(target) { if (fade) fade.stop(); fade = Tween.value(mix, target, (value) => { mix = value; reverb.setProps({ wet: value }); }, { duration: 1.5 });}
function startup() { reverb = findEntity('Footsteps').getComponent(AudioReverbFilterComponent);
on('cave', (event) => { if (event.eventType === EventType.AudioZone.Enter) setWet(0.6); if (event.eventType === EventType.AudioZone.Exit) setWet(0); });}A sound inside an Audio Zone gains a long Reverb as the listener walks in: the zone's enter and exit events tween the filter's wet mix up and down.
With your sound on, hold W for about a second to walk the camera into the cave: the drum beat inside sounds, and the cave's reverb swells in. Hold S to walk out. Sounds inside a zone are silent from outside it. The beat is a short loop generated for this example.
How it works:
- The reverb stays enabled at
wet: 0, which sounds dry. Tweeningwetbrings the effect in without the click that enabling a filter could cause. wetglides smoothly, so updating it every frame during the tween is safe.decayis set once in the scene, since changing it regenerates the room.mixremembers the current value so a new fade starts from wherever the last one is.
4. An echo you tune with sliders
Section titled “4. An echo you tune with sliders”Drive an echo from two UI sliders.
#pragma lifecycle(startup)
let echo;let timeSlider;let repeatSlider;
function startup() { echo = findEntity('Synth').getComponent(AudioEchoFilterComponent); timeSlider = findEntity('Echo Time'); repeatSlider = findEntity('Echo Repeats');
on('echo/ui', (event) => { if (event.eventType !== EventType.UISlider.Change) return; if (event.entityId === timeSlider.entityId) echo.setProps({ delayTime: event.data.value }); if (event.entityId === repeatSlider.entityId) echo.setProps({ feedback: event.data.value }); });}Two UI Sliders drive the delay time and feedback of an Audio Echo Filter on a looping beat; one listener tells the sliders apart by entity id.
With your sound on, click once to start the audio, then drag the sliders: longer times space the repeats out, more feedback makes them last. The beat is a short loop generated for this example. Drag outside the panel to orbit the camera.
How it works:
- Both sliders share one signal;
event.entityIdcompared with each slider’sentityIdtells which one moved. UISlider::changearrives at each step of a drag with{ value }. Echo props glide, so following every step is smooth.- Changing
delayTimewhile repeats are still ringing bends their pitch, like a tape echo. That is expected, and can be a fun effect.
Snippets
Section titled “Snippets”1. Underwater
Section titled “1. Underwater”Muffle and darken everything the player hears while the camera is under water.
#pragma lifecycle(startup)
// Scene: a Water Volume with a Signal Emitter on 'water'. Every audio entity that should// be affected has an Audio Low Pass Filter (frequency: 20000) and an Audio Reverb Filter// (decay: 2.5, wet: 0). Their names are listed below.const AFFECTED = ['Waves', 'Gulls', 'Boat Engine'];const filters = [];
function setUnderwater(under) { for (const { lowPass, reverb } of filters) { lowPass.setProps({ frequency: under ? 350 : 20000 }); reverb.setProps({ wet: under ? 0.5 : 0 }); }}
function startup() { for (const name of AFFECTED) { const entity = findEntity(name); filters.push({ lowPass: entity.getComponent(AudioLowPassFilterComponent), reverb: entity.getComponent(AudioReverbFilterComponent), }); }
on('water', (event) => { if (event.eventType === EventType.WaterVolume.Submerge) setUnderwater(true); if (event.eventType === EventType.WaterVolume.Emerge) setUnderwater(false); });}How it works:
WaterVolume::submergeis sent when the camera goes fully under the water line, andWaterVolume::emergewhen part of it comes back out.- A cutoff of 350 Hz leaves only a dull rumble, and a reverb adds the enclosed feeling of water. Both props glide, so the transition is smooth.
- The filters are looked up once and kept in an array; the events only change their props.
2. Overdrive with damage
Section titled “2. Overdrive with damage”Grow a distortion on the music as the player gets hurt, then clear it on recovery.
#pragma lifecycle(startup)
// Scene: an Audio entity "Music" with an Audio Distortion Filter (amount: 0, wet: 1),// starting disabled. Game code emits 'player/health' with a number from 0 to 100.let grit;
function startup() { grit = findEntity('Music').getComponent(AudioDistortionFilterComponent);
on('player/health', (health) => { if (health > 60) { grit.setEnabled(false); return; } grit.setEnabled(true); // Rounded to steps, because distortion changes apply at once. const amount = Math.round(((60 - health) / 60) * 4) / 4; grit.setProps({ amount }); });}How it works:
- Healthy players hear clean music: the filter is disabled, so it is not in the chain at all.
- Below 60 health the filter is enabled and its
amountgrows as health falls. - Distortion changes rebuild its curve and apply at once, so the script rounds the amount to four steps instead of changing it on every hit point.
Common mistakes
Section titled “Common mistakes”- Toggling a strong effect with
setEnabledduring playback. It can click. Keep the filter enabled and movewet(or a low pass’sfrequency) instead. - Changing reverb
decayorpreDelayevery frame. They regenerate the room each time. Set them on events; animatewet. - Forgetting the order. Filters run in component order. A distortion after a reverb distorts the whole room; before it, only the dry sound.
- Expecting
weton a pass filter. Low pass and high pass have nowet. Open a low pass with a highfrequencyinstead. - Looking for the filter on the wrong entity. A filter affects only the source on its own entity. Each sound that should change needs its own filter.
- Very high
feedbackwith shortdelayTime. The repeats pile up into a loud ring. Keepfeedbackmoderate for short delays.