UPDATE
It's a bug. I made this sound panning example and it works fine in 0.8, but in 0.10.1 it moves the sound all to the left or all to the right:
Code: Select all
function love.load()
snd = love.audio.newSource("test.mp3", "stream")
snd:setLooping(false)
snd:setVolume(1)
snd:play()
pos = 0
end
function love.keypressed( key, scancode, isrepeat )
if (key == "escape") then os.exit(0) end
if (key == "left") then pos = pos - 0.1 end
if (key == "right") then pos = pos + 0.1 end
end
function love.update( dt )
snd:setPosition(pos,0,0)
end
function love.draw()
love.graphics.print("SOUND POSITION: " .. pos, 300, 300)
end
----
Original post:
I'm trying to implement a stereo sound system in my game, so any sfx balances left or right depending on its position relative to the viewport.
The point is that, if an object (an enemy, for instance) is visible in the viewport and it's currently at the right of the viewport, if the object plays any sound, it will be heard on the right speaker. And as the character (and therefore the camera) gets closer to the object, the sound "moves" to the center, thus playing on both left and right speakers. I'm normalizing the sfx position from -1 to 1.
Now, my problem: whenever I update the position, if it's any bigger than 0 (like 0.001), it plays only on the right speaker, and all to the left if it's any lower than 0. Is it supposed to work like that? I thought "setPosition" was meant to balance the sound between left and right speakers.