Lớp công cụ
AudioChannelSplitter
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Thuộc Tính
Phương Pháp
GetConnectedWires(pin: string):{Wire} |
Sự Kiện
WiringChanged(connected: boolean,pin: string,wire: Wire,instance: Instance):RBXScriptSignal |
Mẫu mã
Phân Tách & Trộn Kênh
local Workspace = game:GetService("Workspace")
local function wireUp(source: Instance, target: Instance, sourceName: string?, targetName: string?)
local wire = Instance.new("Wire", source)
wire.SourceInstance = source
wire.TargetInstance = target
if sourceName then
wire.SourceName = sourceName
end
if targetName then
wire.TargetName = targetName
end
return wire
end
local listener = Instance.new("AudioListener")
listener.Parent = Workspace.CurrentCamera
local output = Instance.new("AudioDeviceOutput")
output.Parent = Workspace
local splitter = Instance.new("AudioChannelSplitter")
splitter.Parent = Workspace
local mixer = Instance.new("AudioChannelMixer")
mixer.Parent = Workspace
-- Gửi những gì mà người nghe nghe đến một bộ phân tách và gửi một bản phối đến đầu ra cuối
wireUp(listener, splitter)
wireUp(mixer, output)
-- Thiết lập cả bộ phân tách và bộ trộn để sử dụng bố cục quadrophonic
splitter.Layout = Enum.AudioChannelLayout.Quad
mixer.Layout = Enum.AudioChannelLayout.Quad
-- Đưa mỗi một trong bốn kênh đến một bộ thay đổi âm cao riêng
local frontLeft = Instance.new("AudioPitchShifter")
frontLeft.Name = "Trước Trái"
frontLeft.Pitch = 1.25
frontLeft.Parent = Workspace
local backLeft = Instance.new("AudioPitchShifter")
backLeft.Name = "Sau Trái"
backLeft.Pitch = 0.5
backLeft.Parent = Workspace
local frontRight = Instance.new("AudioPitchShifter")
frontRight.Name = "Trước Phải"
frontRight.Pitch = 1.5
frontRight.Parent = Workspace
local backRight = Instance.new("AudioPitchShifter")
backRight.Name = "Sau Phải"
backRight.Pitch = 0.75
backRight.Parent = Workspace
wireUp(splitter, frontLeft, "Trái")
wireUp(splitter, backLeft, "SauTrái")
wireUp(splitter, frontRight, "Phải")
wireUp(splitter, backRight, "SauPhải")
wireUp(frontLeft, mixer, nil, "Trái")
wireUp(backLeft, mixer, nil, "SauTrái")
wireUp(frontRight, mixer, nil, "Phải")
wireUp(backRight, mixer, nil, "SauPhải")
-- Cấu hình một phần để phát âm thanh
local part = Instance.new("Part")
part.Shape = Enum.PartType.Ball
part.Size = Vector3.new(4, 4, 4)
part.Material = Enum.Material.SmoothPlastic
part.CastShadow = false
part.Position = Vector3.new(0, 4, -12)
part.Anchored = true
part.Parent = Workspace
local analyzer = Instance.new("AudioAnalyzer")
analyzer.Parent = part
local emitter = Instance.new("AudioEmitter")
emitter.Parent = part
local assetPlayer = Instance.new("AudioPlayer")
assetPlayer.Looping = true
assetPlayer.Asset = "rbxassetid://97799489309320"
assetPlayer.Parent = emitter
wireUp(assetPlayer, emitter)
wireUp(assetPlayer, analyzer)
-- Bắt đầu phát âm thanh
assetPlayer:Play()
-- Điều chỉnh màu sắc của phần khi âm thanh phát
while true do
local peak = math.sqrt(analyzer.PeakLevel)
part.Color = Color3.new(peak, peak, peak)
task.wait()
endTài Liệu Tham Khảo API
Thuộc Tính
Phương Pháp
GetConnectedWires
Sự Kiện