[SOLVED] Bug in Audio Source->setPosition

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

[SOLVED] Bug in Audio Source->setPosition

Post 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.
Last edited by molul on Sun Mar 20, 2016 10:52 am, edited 1 time in total.
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

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

Post 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.
User avatar
molul
Party member
Posts: 264
Joined: Sun Feb 05, 2012 6:51 pm
Location: Valencia, Spain
Contact:

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

Post by molul »

Solved. I just had to add love.audio.setPosition(0, 1, 0) at the beginning of love.load() :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests