AudioFilter

Show Deprecated

AudioFilter adjusts the frequency content of audio streams. It provides one Input pin and one Output pin which can be connected to/from by Wires. AudioFilter uses its FilterType, Gain, and Q properties to determine what to do around a particular cutoff Frequency.

Code Samples

An AudioFilter can be used to change the frequency content of audio streams. In this example, an AudioFilter is used to make the AudioEmitter output more muffled when there's a wall between it and the AudioListener.

Emitter Filtering

-- This assumes the workspace contains a Part with an AudioEmitter and an AudioPlayer, and the camera has an AudioListener
local RunService = game:GetService("RunService")
local part: BasePart = workspace.Part
local camera: Camera = workspace.CurrentCamera
local audioPlayer: AudioPlayer = part.AudioPlayer
local audioEmitter: AudioEmitter = part.AudioEmitter
local audioListener: AudioListener = camera.AudioListener
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = { audioEmitter.Parent }
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
-- Create a new AudioFilter
local filter: AudioFilter = Instance.new("AudioFilter")
filter.FilterType = Enum.AudioFilterType.Lowpass12dB
filter.Frequency = 22000
filter.Q = math.sqrt(2) / 2 -- This Q value produces a flat lowpass for the 12dB slope type
filter.Parent = part
-- Put the AudioFilter between the player and the emitter
local function wireTo(source: Instance, target: Instance): Wire
local wire = Instance.new("Wire")
wire.SourceInstance = source
wire.TargetInstance = target
wire.Parent = target
end
wireTo(audioPlayer, filter)
wireTo(filter, audioEmitter)
-- Update the filter based on the positions of the emitter and listener
RunService.Heartbeat:Connect(function()
local emitterPos: Vector3 = part.Position
local listenerPos: Vector3 = camera.CFrame.Position
local raycastResult = workspace:Raycast(emitterPos, (listenerPos - emitterPos), raycastParams)
filter.Frequency = if raycastResult then 500 else 22000
end)

Summary

Properties

  • Read Parallel

    Whether audio streams are passed-through unaffected by this effect.

  • Not Replicated
    Roblox Script Security
    Read Parallel
  • The curve type of the band represented by the filter.

  • Read Parallel

    The central frequency that the filter acts around.

  • Read Parallel

    For peaking and shelving filters, controls volume increase or reduction.

  • Read Parallel

    For peaking, lowpass, highpass, bandpass, and notch filters, controls the selectiveness or resonance.

Methods

Events

Properties

Bypass

Read Parallel

Editor

Not Replicated
Roblox Script Security
Read Parallel
Read Parallel

Frequency

Read Parallel

Gain

Read Parallel
Read Parallel

Methods

GetConnectedWires

Instances

Parameters

pin: string

Returns

Instances

GetGainAt

Parameters

frequency: number

Returns

GetInputPins


Returns

GetOutputPins


Returns

Events

WiringChanged

Parameters

connected: boolean
pin: string
wire: Wire
instance: Instance