Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added exponentialRampToValueAtTime feature #428

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/gain.js
Expand Up @@ -130,17 +130,21 @@ define(function (require) {
* @for p5.Gain
* @param {Number} volume amplitude between 0 and 1.0
* @param {Number} [rampTime] create a fade that lasts rampTime
* @param {Number} [timeFromNow] schedule this event to happen
* seconds from now
* @param {string} [isExp=false] to Allow Exponentialchange in value of amplitude
*/
p5.Gain.prototype.amp = function(vol, rampTime, tFromNow) {
p5.Gain.prototype.amp = function(vol, rampTime, tFromNow, isExp = false) {
var rampTime = rampTime || 0;
var tFromNow = tFromNow || 0;
var now = p5sound.audiocontext.currentTime;
var currentVol = this.output.gain.value;
this.output.gain.cancelScheduledValues(now);
this.output.gain.linearRampToValueAtTime(currentVol, now + tFromNow);
this.output.gain.linearRampToValueAtTime(vol, now + tFromNow + rampTime);
if(isExp){
this.output.gain.exponentialRampToValueAtTime(currentVol, now + tFromNow);
this.output.gain.exponentialRampToValueAtTime(vol, now + tFromNow + rampTime);
}else{
this.output.gain.linearRampToValueAtTime(currentVol, now + tFromNow);
this.output.gain.linearRampToValueAtTime(vol, now + tFromNow + rampTime);
}
};

p5.Gain.prototype.dispose = function() {
Expand Down