Audio fade in/out?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Duster
Prole
Posts: 32
Joined: Fri Dec 19, 2014 8:34 pm
Location: Ontario, Canada

Audio fade in/out?

Post 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.
_dementia_
Prole
Posts: 5
Joined: Sat Jan 17, 2015 3:19 am

Re: Audio fade in/out?

Post 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.
User avatar
Duster
Prole
Posts: 32
Joined: Fri Dec 19, 2014 8:34 pm
Location: Ontario, Canada

Re: Audio fade in/out?

Post by Duster »

I've decided to work around it by just using love.audio instead of TESound for atmospheric effects, which works perfectly.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 8 guests