-- $LastChangedDate: 2008-12-26 21:33:34 -0500 (Fri, 26 Dec 2008) $
-- Play sounds.
-- See module.txt for documentation and pitfalls.
--
-- Note: This Lua code isn't as inefficient as it seems.
-- Although Lua calls C++ Sound::Play() every tick,
-- it will be a NOP if the same args are passed while it hasn't finished playing.
-- So this Lua code can be kept simple/brief by relying on the "anti-redundancy" of C++.

-----------
-- Sound --
-----------

Sound = { }

-- Monitor events that need sound.
function Sound:Tick()
	-- Update engine sound.
	local engineVolume = PlayerActor.aircraft:GetThrottle()  -- throttle equals volume {0.0,..,1.0}
	if ( engineVolume < 0.05 or PlayerActor:IfDestroyed() ) then
		PlayerActor.aircraft:StopEngineSound()
	else
		PlayerActor.aircraft:PlayEngineSound( engineVolume )
	end
	
	-- Update stall warning sound.
	if ( PlayerActor.aircraft:GetPhysics():IfStall() ) then
		sim.Sound:Play( "stall.wav.gz", sim.Sound.PLAY_LOOP, 0.6 )
	else
		sim.Sound:Stop( "stall.wav.gz" )
	end
end
