Created
October 22, 2017 22:12
-
-
Save beefchimi/c312996ea41ad29348c8f9b97387b291 to your computer and use it in GitHub Desktop.
Tremolo method
This file contains hidden or 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
const defaultOptions = { | |
speed: 10, | |
duration: 1, | |
volume: { | |
min: 0.1, | |
max: 1, | |
}, | |
}; | |
tremolo(options = {}) { | |
const config = Object.assign(options, defaultOptions); | |
const interval = config.duration / config.speed; | |
for (let i = 0; i <= config.speed; i++) { | |
const newVolume = (i % 2) ? config.volume.min : config.volume.max; | |
this.gainNode.gain.exponentialRampToValueAtTime( | |
newVolume, | |
this.context.currentTime + (interval * i) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment