Forked from ichabodcole/Web Audio API - Sound Fading
Created
October 27, 2015 15:26
-
-
Save rowild/f02438e6107fd853ebd7 to your computer and use it in GitHub Desktop.
Reference for fading in and out sounds with the Web Audio API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fadeTo: (value, fadeLength)-> | |
fadeLength = fadeLength || @defaultfadeLength | |
currentTime = @ctx.currentTime | |
#time the fade should complete | |
fadeTime = currentTime + fadeLength | |
#set the start time | |
@masterGain.gain.setValueAtTime(@userVolume, currentTime) | |
@masterGain.gain.linearRampToValueAtTime(value, fadeTime) | |
fadeOut: (fadeLength)-> | |
fadeLength = fadeLength || @defaultfadeLength | |
@fadeTo(0, fadeLength) | |
fadeIn: (fadeLength)-> | |
fadeLength = fadeLength || @defaultfadeLength | |
@fadeTo(@userVolume, fadeLength) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment