Page 1 of 1

Audio fade in/out?

Posted: Thu Jan 15, 2015 7:55 pm
by Duster
I can't seem to find a way to do this properly without frequent audio glitches.
Currently what I'm doing is tweening a volume variable from 0-1 and assigning it to my audio every update. Unfortunately this sporadically causes some unwanted noise (http://vocaroo.com/i/s0ZvMDfwY1BO).
What are some other ways I can smoothly increment/decrement volume? Should I just do it manually?

EDIT: Turns out this is an issue with TESound, the audio library I'm using. Apparently something about its volume function doesn't agree with being called every update.

Re: Audio fade in/out?

Posted: Sat Jan 17, 2015 7:12 am
by _dementia_
Couldn't you put some kind of timer on it where the volume increasing function is only called when a timer reaches 0? You could probably do it with faster speeds like dt.

Completely untested but my idea:

Code: Select all

function increase_volume(dt,rate)
 audioSrc:setVolume(audiosrc:getVolume()+rate*dt 
end
function love.update(dt)
 local timer = 1
 if timer > 0 then
  timer = timer-1
  elseif timer < 0 then
   increase_volume(dt,rate)
   timer = 1
 end
end
I'm going to test it in a few.

Re: Audio fade in/out?

Posted: Mon Jan 19, 2015 8:16 am
by Duster
I've decided to work around it by just using love.audio instead of TESound for atmospheric effects, which works perfectly.