Page 1 of 1

[SOLVED] Bug in Audio Source->setPosition

Posted: Fri Mar 18, 2016 8:29 am
by molul
UPDATE 2: it's fixed just by adding love.audio.setPosition(0, 1, 0) at the beginning of love.load().


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
I've raised a ticket on the issue tracker for this issue: https://bitbucket.org/rude/love/issues/ ... etposition



----


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.

Re: [UPDATED] Bug in Audio Source->setPosition

Posted: Fri Mar 18, 2016 2:39 pm
by zorg
Just a guess, but maybe the default attenuation distances and such changed between two minor versions, and now they need to be explicitly set? (0.8->0.9->0.10)

Re: [UPDATED] Bug in Audio Source->setPosition

Posted: Fri Mar 18, 2016 2:47 pm
by molul
Well, I tried different values for love.audio.setPosition, love.audio.setOrientation, and love.audio.setDistanceModel, but the effect was either nothing (full pan for values different than zero) or no pan. Not sure if there's any other variable I should have tried. Anyway, if that was the case, it would be nice to have it on the wiki.

Re: [SOLVED] Bug in Audio Source->setPosition

Posted: Sun Mar 20, 2016 10:53 am
by molul
Solved. I just had to add love.audio.setPosition(0, 1, 0) at the beginning of love.load() :)