AudioChannelSplitter

Afficher les obsolètes
Non navigable

AudioChannelSplitter splits an audio stream into component channels so that each can be processed independently. It provides one Input pin, one combined Output pin, as well as the following secondary output pins, all of which can be connected to/from by Wires: Left, Right, Center, SurroundLeft, SurroundRight, Sub, BackLeft, BackRight, TopLeft, TopRight, TopBackLeft, and TopBackRight.

Diagram showing position of all potential channels.

Échantillons de code

Splitting & Mixing Channels

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
-- Send what the listener hears to a splitter and send a mix to the final output
wireUp(listener, splitter)
wireUp(mixer, output)
-- Set up both the splitter and mixer to use a quadrophonic layout
splitter.Layout = Enum.AudioChannelLayout.Quad
mixer.Layout = Enum.AudioChannelLayout.Quad
-- Give each of the four channels its own pitch shifter
local frontLeft = Instance.new("AudioPitchShifter")
frontLeft.Name = "Front Left"
frontLeft.Pitch = 1.25
frontLeft.Parent = Workspace
local backLeft = Instance.new("AudioPitchShifter")
backLeft.Name = "Back Left"
backLeft.Pitch = 0.5
backLeft.Parent = Workspace
local frontRight = Instance.new("AudioPitchShifter")
frontRight.Name = "Front Right"
frontRight.Pitch = 1.5
frontRight.Parent = Workspace
local backRight = Instance.new("AudioPitchShifter")
backRight.Name = "Back Right"
backRight.Pitch = 0.75
backRight.Parent = Workspace
wireUp(splitter, frontLeft, "Left")
wireUp(splitter, backLeft, "BackLeft")
wireUp(splitter, frontRight, "Right")
wireUp(splitter, backRight, "BackRight")
wireUp(frontLeft, mixer, nil, "Left")
wireUp(backLeft, mixer, nil, "BackLeft")
wireUp(frontRight, mixer, nil, "Right")
wireUp(backRight, mixer, nil, "BackRight")
-- Configure a part to emit audio
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)
-- Start playing the audio
assetPlayer:Play()
-- Adjust the part's color as the audio plays
while true do
local peak = math.sqrt(analyzer.PeakLevel)
part.Color = Color3.new(peak, peak, peak)
task.wait()
end

Résumé

Propriétés

Méthodes

Évènements

Propriétés

Lecture parallèle

Controls the input channel layout to be split from. When changed, all audio streams prior to this channel splitter's input may need to be up-mixed (widened to at least as many channels as the input requires).

The Output pin produces a copy of the stream wired to Input but, depending on the value of AudioChannelSplitter.Layout:

  • For Mono, the Center pin produces an audio stream.
  • For Stereo, the Left and Right pins produce audio streams.
  • For Quad, the Left, Right, BackLeft, and BackRight pins produce audio streams.
  • Surround_5 is the same as Quad, plus Center produces an audio stream.
  • Surround_5_1 is the same as Surround_5, plus Sub produces an audio stream.
  • Surround_7_1 is the same as Surround_5_1, plus SurroundLeft and SurroundRight produce audio streams.
  • For Surround_7_1_4, all secondary output pins produce audio streams.

Méthodes

GetConnectedWires

Instances

Returns an array of Wires that are connected to the specified pin.

Paramètres

pin: string

Retours

Instances

GetInputPins

Returns a table containing one string, "Input", indicating the input pin available for Wire.TargetName.


Retours

GetOutputPins

Returns a table of strings indicating which output pins are available for Wire.SourceName:

  • "Output"
  • "Left"
  • "Right"
  • "Center"
  • "SurroundLeft"
  • "SurroundRight"
  • "BackLeft"
  • "BackRight"
  • "Sub"
  • "TopLeft"
  • "TopRight"
  • "TopBackLeft"
  • "TopBackRight"

Retours

Évènements

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 AudioChannelSplitter and to some other wirable instance.

Paramètres

connected: bool

Whether the instance got connected or disconnected.

pin: string

The pin on the AudioChannelSplitter that the Wire targets.

wire: Wire

The Wire between the AudioChannelSplitter and the other instance.

instance: Instance

The other instance that is or was connected through the Wire.