AudioEqualizer
AudioEqualizer adjusts the frequency content of audio streams. It provides one Input pin and one Output pin which can be connected to/from by Wires. AudioEqualizer has 3 frequency bands whose gain values can be controlled, and the crossover points between bands can be moved.
Code Samples
local function wireUp(source: Instance, target: Instance) : Wire
local wire = Instance.new("Wire")
wire.Parent = target
wire.SourceInstance = source
wire.TargetInstance = target
return wire
end
local function getCFrameFrom(inst: Instance) : CFrame?
local parent = inst.Parent
if not parent then
return nil
elseif parent:IsA("Model") then
return parent.WorldPivot
elseif parent:IsA("BasePart") then
return parent.CFrame
elseif parent:IsA("Attachment") then
return parent.WorldCFrame
elseif parent:IsA("Camera") then
return parent.CFrame
else
return nil
end
end
local function rescale(value: number, oldRange: NumberRange, newRange: NumberRange) : number
local clamped = math.clamp(value, oldRange.Min, oldRange.Max)
local normalized = clamped - oldRange.Min / (oldRange.Max - oldRange.Min)
return normalized * (newRange.Max - newRange.Min) + newRange.Min
end
local assetPlayer = Instance.new("AudioPlayer")
assetPlayer.AssetId = "rbxassetid://142376088"
assetPlayer.Parent = workspace
local equalizer = Instance.new("AudioEqualizer")
equalizer.MidRange = NumberRange.new(400, 3000)
equalizer.Parent = workspace
local emitterPart = Instance.new("Part")
emitterPart.Anchored = true
emitterPart.Position = Vector3.new(0, 5, 0)
emitterPart.Parent = workspace
local emitter = Instance.new("AudioEmitter")
emitter.Parent = emitterPart
local listener = Instance.new("AudioListener")
listener.Parent = workspace.CurrentCamera
local output = Instance.new("AudioDeviceOutput")
output.Parent = workspace
wireUp(assetPlayer, equalizer)
wireUp(equalizer, emitter)
wireUp(listener, output)
assetPlayer.Looping = true
assetPlayer:Play()
while true do
local emitterFrame = getCFrameFrom(emitter)
local listenerFrame = getCFrameFrom(listener)
if emitterFrame and listenerFrame then
local towardEmitter = emitterFrame.Position - listenerFrame.Position
local look = towardEmitter.Unit:Dot(listenerFrame.LookVector) -- ranges from [-1, 1]
look = rescale(look, NumberRange.new(-1, 1), NumberRange.new(-20, 0))
local distance = math.max(towardEmitter.Magnitude, 1)
local rolloff = 1 / distance -- ranges from [0, 1]
rolloff = rescale(rolloff, NumberRange.new(0, 1), NumberRange.new(-10, 10))
equalizer.HighGain = look + rolloff
equalizer.LowGain = rolloff
end
task.wait()
end
Summary
Properties
Whether audio streams are passed-through unaffected by this effect.
Gain value to be applied to the frequency content of the highest band in the equalizer.
Gain value to be applied to the frequency content of the lowest band in the equalizer.
Gain value to be applied to the frequency content of the middle band in the equalizer.
The frequency range of the band influenced by MidGain.
Methods
Returns an array of Wires that are connected to the specified pin.
Events
Fires when another instance is connected to or disconnected from the AudioEqualizer via a Wire.
Properties
Editor
HighGain
Gain value, in decibels, to be applied to the frequency content of the highest band in the equalizer. Ranges from -80 to 10.
LowGain
Gain value, in decibels, to be applied to the frequency content of the lowest band in the equalizer. Ranges from -80 to 10.
MidGain
Gain value, in decibels, to be applied to the frequency content of the middle band in the equalizer. Ranges from -80 to 10.
MidRange
The frequency range in hertz of the band influenced by MidGain. The lower value of the range determines the crossover frequency between the low and mid bands. The higher value of the range determines the crossover frequency between the mid and high bands. Both crossover frequencies range from 200 to 20,000.
Methods
GetConnectedWires
Returns an array of Wires that are connected to the specified pin. AudioEqualizer has one "Input" pin and one "Output" pin.
Parameters
Returns
Events
WiringChanged
Event that fires after a Wire becomes connected or disconnected, and that Wire is now or was previously connected to a pin on the AudioEqualizer and to some other wirable instance.
Parameters
Whether the instance got connected or disconnected.
The pin on the AudioEqualizer that the Wire targets.
The Wire between the AudioEqualizer and the other instance.