Jump to content

Source SetRange Issue


Recommended Posts

At first thought this was an issue with mono vs stereo sounds, but tracked down the issue to Source:SetRange(). Whenever the range of a mono sound is set to 1.0 or below, it will play at full volume no matter how far away the source is from the listener.

 

Using a slightly modified version of the Source:SetRange lua example, the sound will play when the range is greater than 2 (which is the distance from source to listener) and when the range is equal or less than 1.0:

function App:Start()

self.window = Window:Create("Source SetRange Issue",0,0,400,300)

self.context = Context:Create(self.window)

 

local sound = Sound:Load("Sound/doors/fdn_door_automatic_servo_driven_close_short_05.wav")

self.source = Source:Create()

self.source:SetSound(sound)

sound:Release()

self.source:SetLoopMode(true)

self.source:Play()

self.source:SetPosition(Vec3(0,0,2))

 

local listener = Listener:Create()

listener:SetPosition(0,0,0)

 

range = 0.1

toggle = 0.005

 

return true

end

 

function App:Loop()

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

 

range = range + toggle

if range>=3 then toggle = -0.005 end

if range<=0 then toggle = 0.005 end

self.source:SetRange(range)

 

Time:Update()

self.context:SetColor(0,0,0)

self.context:Clear()

self.context:SetColor(1,1,1)

self.context:SetBlendMode(Blend.Alpha)

self.context:DrawText(string.format("Range: %.2f",range),0,2)

self.context:Sync(true)

 

return true

end

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Also noticed that creating a listener makes no difference in the behavior of this script. Is a listener being created automatically when the context is created?

 

Edit -- doesnt appear to be the case. Commenting out the context still allows sounds to be played. hmmm...

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

As it may be related to the problem above, SetPosition has to be used after the source is initially played or the source is not actually positioned. Just flipping the order of 'self.source:Play()' and 'self.source:SetPosition(Vec3(0,0,3))' in the above script will cause the sound to be heard at full volume no matter what the range is set to.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

  • 10 months later...
  • 1 month later...
Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...