Created
June 5, 2017 19:59
-
-
Save rjbultitude/279fc4758ee6059a2159d9f63c0af758 to your computer and use it in GitHub Desktop.
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
p5.SoundFile.prototype.setVolume = function (vol, rampTime, tFromNow, volFrom, volTo) { | |
if (typeof vol === 'number') { | |
var rampTime = rampTime || 0; | |
var tFromNow = tFromNow || 0; | |
var now = p5sound.audiocontext.currentTime; | |
var currentVol = this.output.gain.value; | |
this.output.gain.cancelScheduledValues(now + tFromNow); | |
// Attack | |
if (typeof volFrom === 'number' && volFrom >= 0) { | |
this.output.gain.linearRampToValueAtTime(volFrom, now + tFromNow); | |
} else { | |
this.output.gain.linearRampToValueAtTime(currentVol, now + tFromNow); | |
} | |
// Decay | |
if (typeof volTo === 'number' && volTo >= 0) { | |
this.output.gain.linearRampToValueAtTime(volTo, now + tFromNow + rampTime); | |
} else { | |
this.output.gain.linearRampToValueAtTime(vol, now + tFromNow + rampTime); | |
} | |
} else if (vol) { | |
vol.connect(this.output.gain); | |
} else { | |
// return the Gain Node | |
return this.output.gain; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment