Skip to content

Instantly share code, notes, and snippets.

@beefchimi
Created October 22, 2017 22:12
Tremolo method
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