AudioFilter

Hiển Thị Bản Đã Lỗi Thời

*Nội dung này sẽ sớm có sẵn bằng ngôn ngữ bạn chọn.

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.

Mẫu mã

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)

Tóm Tắt

Thuộc Tính

  • Đọc Song Song

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

  • Không Sao Chép
    Đọc Song Song
  • The curve type of the band represented by the filter.

  • Đọc Song Song

    The central frequency that the filter acts around.

  • Đọc Song Song

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

  • Đọc Song Song

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

Phương Pháp

Thuộc Tính

Bypass

Đọc Song Song

If true, audio streams are passed-through unaffected by this effect.

Editor

Không Sao Chép
Đọc Song Song
Bảo Mật Kịch Bản Roblox
Đọc Song Song

The type of frequency response curve that will be used to filter the audio signal. Each type of curve affects the frequency content of the audio in different ways.

Frequency

Đọc Song Song

The central frequency in hertz of the curve represented by the filter. Generally, adjusting this value up or down corresponds to a horizontal shift in the overall frequency curve. Ranges from 20 to 22000.

Gain

Đọc Song Song

The gain value in decibels used to determine the volume level of the curve represented by the filter. Only applies when the FilterType is Peak, LowShelf, or HighShelf. Ranges from -30 to 30.

Đọc Song Song

The quality value used to determine the slope or resonance of the curve represented by the filter. Only applies when the FilterType is Peak, Lowpass[x]dB, Highpass[x]dB, Bandpass, or Notch. Ranges from 0.1 to 10.

For FilterType values of Lowpass12dB and Highpass12dB, a Q value of sqrt(2) / 2, or 0.707, corresponds to a flat filter at a 12dB/octave slope.

Phương Pháp

GetConnectedWires

Instances

Returns an array of Wires that are connected to the specified pin. AudioFilter has one "Input" pin and one "Output" pin.

Tham Số

pin: string

Lợi Nhuận

Instances

GetGainAt

Returns the gain value, in decibels, of the frequency response curve represented by the filter at the given frequency, in hertz. This can be used to sample the exact shape of the filter in key places or as a whole.

Tham Số

frequency: number

The frequency, in hertz, to sample.


Lợi Nhuận

The gain value, in decibels, at the given frequency.

Sự Kiện

WiringChanged

Tham Số

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