PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

AmbientReverb

SoundService

ReverbType

The ambient sound environment preset used by SoundService.

The Enum/ReverbType this property simulates a range of different environment’s impact on sound. Each different option corresponds with a preset available in the FMOD sound engine. For example, when AmbientReverb is set to Hangar, the sound will reverberate differently to simulate being in a large enclosed space.

Changing the AmbientReverb effects the following properties used by Roblox’s sound engine.

  • Reverberation decay time
  • Initial reflection delay time
  • Late reverberation delay time relative to initial reflection
  • Reference high frequency
  • High-frequency to mid-frequency decay time ratio
  • Value that controls the echo density in the late reverberation decay
  • Value that controls the modal density in the late reverberation decay
  • Reference low frequency
  • Relative room effect level at low frequencies
  • Relative room effect level at high frequencies
  • Early reflections level relative to room effect
  • Room effect level at mid frequencies

Those interested in finding more out about ambient reverb presets should see the FMOD documentation on the topic. For most developers however, the Enum/ReverbType names are descriptive enough to be able to use this setting without advanced knowledge.


Code Samples


Dynamic Reverb System

The code in this sample, when ran from a LocalScript, will change the SoundService/AmbientReverb property of SoundService when the player is inside a BasePart tagged using CollectionService.

To add or remove tags and reverb types, change the entries in the ‘reverbTags’ table.

local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local SoundService = game:GetService("SoundService")

local localPlayer = Players.LocalPlayer

-- define tags
local reverbTags = {
	["reverb_Cave"] = Enum.ReverbType.Cave
}

-- collect parts and group them by tag
local parts = {}
for reverbTag, reverbType in pairs(reverbTags) do
	for _, part in pairs(CollectionService:GetTagged(reverbTag)) do
		parts[part] = reverbType
	end
end

-- function to check if a position is within a part's extents
local function positionInPart(part, position)
	local extents = part.Size / 2
	local offset = part.CFrame:pointToObjectSpace(position)
	return offset.x < extents.x
		and offset.y < extents.y
		and offset.z < extents.z
end

local reverbType = SoundService.AmbientReverb

while true do 
	wait()
	if not localPlayer then
		return
	end

	local character = localPlayer.Character

	-- default to no reverb
	local newReverbType = Enum.ReverbType.NoReverb

	if character and character.PrimaryPart then
		local position = character.PrimaryPart.Position

		-- go through all the indexed parts
		for part, type in pairs(parts) do
			-- see if the character is within them
			if positionInPart(part, position) then
				-- if so, pick that reverb type
				newReverbType = type
				break
			end
		end
	end

	-- set the reverb type if it has changed
	if newReverbType ~= reverbType then
		SoundService.AmbientReverb = newReverbType
		reverbType = newReverbType
	end
end