AudioFilter 오디오 스트림의 주파수 콘텐츠를 조정합니다.그것은 하나의 입력 핀과 하나의 출력 핀을 제공하며, Wires 연결할 수 있습니다.AudioFilter 는 자신의 FilterType , Gain 및 Q 속성을 사용하여 특정 삭감 Frequency 주위에서 수행할 작업을 결정합니다.
코드 샘플
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.
-- 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
FilterType
오디오 신호를 필터링하는 데 사용될 주파수 응답 곡선의 유형.각 곡선 유형은 오디오의 주파수 콘텐츠를 다양한 방식으로 영향을 줍니다.
Frequency
필터에 의해 나타나는 곡선의 중앙 주파수(헤르츠).일반적으로 이 값을 위쪽이나 아래쪽으로 조정하면 전체 주파수 곡선의 가로 이동에 해당합니다.20에서 22000까지의 범위.
필터에 의해 나타나는 곡선의 경사 또는 공진 값을 결정하는 데 사용되는 품질 값.오직 FilterType 가 Peak , Lowpass[x]dB , Highpass[x]dB , Bandpass 또는 Notch 일 때만 적용됩니다.0.1에서 10까지의 범위.
For FilterType 값의 Lowpass12dB 및 Highpass12dB , a Q 값의 sqrt(2) / 2 또는 0.707 는 12dB/오케이브 경사에서 평면 필터에 해당합니다.
메서드
GetConnectedWires
지정된 핀하다연결된 배열 Wires 을 반환합니다. AudioFilter 는 "입력" 핀과 "출력" 핀하다하나씩 있습니다.
매개 변수
반환
GetGainAt
필터에서 지정된 주파수에서 표시되는 주파수 응답 곡선의 이득 값, 데시벨로, 반환합니다. Returns the gain value, in decibels, of the frequency response curve represented by the filter at the given frequency, in hertz.이를 사용하여 필터의 정확한 모양을 주요 장소나 전체로 샘플링할 수 있습니다.
매개 변수
샘플링할 주파수, 헤르츠.
반환
주어진 주파수에서 얻는 값, 데시벨, 어떤 값.
이벤트
WiringChanged
연결되거나 연결 해제된 Wire 후 발생하는 이벤트로, Wire 는 현재 또는 이전에 AudioFilter 및 다른 연결 가능한 인스턴스에 고정되었거나 고정되었습니다.
매개 변수
인스턴스가 연결되었거나 연결 해제되었는지 여부.
타겟 AudioFilter 에 있는 핀은 다음과 같습니다.The pin on the that the Wire targets.
Wire 와 다른 인스턴스 사이의 AudioFilter.