AudioFilter 调整音频流的频率内容。它提供一个 输入 端口和一个
代码示例
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)
概要
属性
是否允许音频流通过此效果而不受影响。
带有过滤器的曲线类型代表。
过滤器在周围的中心频率。
对于尖峰和货架过滤器,控制音量增加或减少。
对于峰值、低通、高通、带通和不奇特过滤器,控制选择或共振。
方法
返回连接到指定端置顶的Wires阵列。
将给定频率的过滤器的响应返回。
属性
Editor
Gain
使用 decibels 的获得值来确定曲线由过滤器表示的音量级别。 只适用于当 FilterType 处于 Peak 、 LowShelf 或 1> HighShelf1> 。 范围从 -30 到 30。
用于确定过滤器表示的曲线的斜倾或共振值的质量。 只适用于 FilterType 是 Peak、Lowpass[x]dB、2>Highpass[x]dB2>、5>Bandpass5> 或
对于 FilterType 值的 Lowpass12dB 和 Highpass12dB ,一个 1> Q