Disclaimer: I'm a LOVE (and Lua) noob, so.. get your grain of salt ready..
The way I handle this in other game libraries is, as anjo mentioned, create multiple sources from the same file.
You can use a basic queue system to ensure the "freshest" (as in "most likely to have finished playing") source will be played next.
Something like this:
Code: Select all
SoundQueue = {}
function SoundQueue:new(src, type, length)
local this = {}
local sources = {}
local index = 1
for i = 1, length, 1 do
table.insert(sources, love.audio.newSource(src, type))
end
function this:play()
if (#sources == 0) then
return
end
if (index > #sources) then
index = 1
end
love.audio.stop(sources[index])
love.audio.play(sources[index])
index = index + 1
end
return this
end
function love.load()
queue = SoundQueue:new('fire.wav', 'static', 10)
end
(function()
local timer = 0
function love.update(dt)
timer = timer + dt
-- play the sound every 100 milliseconds
while (timer >= .1) do
timer = timer - .1
queue:play()
end
end
end)()
I'm using 10 sources in this example. I suggest you try to limit yourself to 16, if possible. I have seen some environments where OpenAL reports that 32, 64, etc .. simultaneous channels are available, but I have never seen one report less than 16 channels.
-- Matt