AudioGraph 2 Documentation
Author: intykat
Date: 2024
This module provides a powerful and flexible way to declaratively manage the audio API in Roblox. It enables dynamic creation, modification, and control of audio connections, including support for branching and sidechaining. It was used to create the audio system in On Tap [17+], which won the 2024 innovation award for best use of audio/vc.
If you are unfamiliar with graphing or how it relates to the audio api, please see Audio Graphing: Managing the new audio apis with a graph. This resource has been updated to use the new version of AudioGraph.
Get the module for AudioGraph V2 here.
If you were using AudioGraph V1
The new version of AudioGraph is almost completely backwards compatible, there are some minor api changes. Most importantly, shortened names like “Compressor” must now be lengthened to the actual instance name “AudioCompressor”. Connecting premade modifiers and consumers is now easier than ever with the new:ConnectInstances
method, allowing you to insert any audio instance or array of instances and they will be connected.
Module Structure
Types
-
AudioProducerInstance
: An object that produces audio, such as anAudioPlayer
,AudioDeviceInput
, orAudioListener
. -
AudioModifierInstance
: An object that modifies audio, including various effects likeAudioCompressor
,AudioFilter
,AudioFader
, etc. -
AudioConsumerInstance
: An object that consumes audio, such as anAudioEmitter
,AudioAnalyzer
, orAudioDeviceOutput
. -
ModifierName
: A string representing a valid audio modifier type (e.g., “AudioCompressor”, “AudioFader”). -
ConsumerName
: A string representing a valid audio consumer type (e.g., “AudioEmitter”, “AudioAnalyzer”). -
AudioGraph
: The core class for managing audio connections and effects.
Core Functions
-
Audio.NewGraph(Producer)
: Creates a new audio graph with the specified producer instance. -
AudioGraph:ConnectInstances(Instances)
: Connects one or more audio modifiers or consumers to the graph. -
AudioGraph:Create(Modifiers, Properties)
: Creates and connects one or more audio modifiers to the graph with specified properties. -
AudioGraph:SetVolume(Volume)
: Sets the overall volume of the audio graph. -
AudioGraph:RemoveModifier(Modifier)
: Removes an audio modifier from the graph. -
AudioGraph:RemoveConsumer(Consumer)
: Removes an audio consumer from the graph. -
AudioGraph:GetAudioInstance(Name)
: Retrieves an audio modifier or consumer from the graph by name. -
AudioGraph:Branch(Modifier, DestroyAllOnCleanup)
: Creates a new branch in the audio graph starting from the specified modifier. -
AudioGraph:Cleanup(DestroyAll)
: Cleans up the audio graph, optionally destroying all associated instances. -
AudioGraph:Duck(AudioInstance, CompressorProperties)
: Applies sidechain compression (ducking) to the audio graph using the specified audio instance as the sidechain source. -
AudioGraph:ReleaseDuck()
: Releases the ducking effect from the audio graph. -
Audio.GetFirstGraph(Producer)
: Retrieves the first audio graph associated with the specified producer instance. -
Audio.IsModifier(AudioInstance)
: Checks if an instance is an audio modifier. -
Audio.IsConsumer(AudioInstance)
: Checks if an instance is an audio consumer.
Usage Examples
Locally playing a player’s voice through a part with spooky effects
--localscript, starterplayerscripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Audio = require(ReplicatedStorage:WaitForChild("Audio"))
local MicGraph = Audio.NewGraph(Instance.new("AudioDeviceInput"))
MicGraph.ProducerInstance.Player = game.Players.LocalPlayer
local Emitter = Instance.new("AudioEmitter", game.Workspace:WaitForChild("EmitterPart"))
MicGraph:ConnectConsumer(Emitter)
MicGraph:Create{
["AudioReverb"] = {
Name = "REVERBERANCE",
},
["AudioPitchShifter"] = {
Name = "Distortion",
Pitch = -1
},
}
Ducking a song with local player’s voice that is playing out of a part
--localscript, starterplayerscripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Audio = require(ReplicatedStorage:WaitForChild("Audio"))
local MicInput = Audio.NewGraph(Instance.new("AudioDeviceInput"))
MicInput.ProducerInstance.Player = game.Players.LocalPlayer
local Emitter = Instance.new("AudioEmitter", game.Workspace:WaitForChild("EmitterPart"))
MicInput:ConnectConsumer(Emitter)
local BackgroundPlayer = Instance.new("AudioPlayer")
BackgroundPlayer.AssetId = "rbxassetid://9046862383"
BackgroundPlayer.Looping = true
BackgroundPlayer:Play()
local BackgroundGraph = Audio.NewGraph(BackgroundPlayer)
BackgroundGraph:ConnectConsumer(Emitter)
BackgroundGraph:Duck(MicInput.ProducerInstance)
Important Notes
- The module automatically manages wire connections between audio instances.
- When removing modifiers or consumers, the module updates connections to maintain the audio flow.
- Branching allows you to create parallel audio processing paths.
- Ducking provides a way to dynamically control the volume of the graph based on another audio source.
- The
Cleanup
function helps manage the lifecycle of the audio graph and its associated instances.
For more advanced use cases and detailed explanations, refer to the in-code comments and experiment with the module’s functionality.
Don’t be afraid to reach out or comment below if you’re confused about anything!