SetRange

This function sets the audible range of a sound source.

Syntax

Parameters

Remarks

Only sounds in mono format can be played with 3D spatialization. Stereo sounds will not be affected.

Example

range = 1.5
--Create a window
window = Window:Create()
context = Context:Create(window)

--Load a sound
local sound = Sound:Load("Sound/Music/menutheme.wav")

--Create a source
source = Source:Create()
source:SetSound(sound)
sound:Release()
source:SetLoopMode(true)
source:Play()
source:SetPosition(Vec3(0,0,1))

--Create a listener
local listener = Listener:Create()
listener:SetPosition(0,0,0)

while true do
--Press up/down keys to adjust the source range
if (window:KeyDown(Key.Up))then range = range + Time:GetSpeed()*0.1 end
if (window:KeyDown(Key.Down))then range =range - Time:GetSpeed()*0.1 end
if (range < 0)then range=0 end
source:SetRange(range)

if window:Closed() or window:KeyHit(Key.Escape) then return false end

Time:Update()
context:SetColor(0,0,0)
context:Clear()

context:SetColor(1,1,1)
context:SetBlendMode(Blend.Alpha)
context:DrawText("Range: "..range,2,2)

context:Sync()

end