diff --git a/src/effects/EchoEffect.js b/src/effects/EchoEffect.js new file mode 100644 index 0000000..304bfb8 --- /dev/null +++ b/src/effects/EchoEffect.js @@ -0,0 +1,52 @@ +/* + +An echo effect + +0 mutes the effect +Values up to 100 set the echo feedback amount, +increasing the time it takes the echo to fade away + +Clamped 0-100 + +*/ + +var Tone = require('tone'); + +function EchoEffect () { + Tone.Effect.call(this); + + this.value = 0; + + this.delay = new Tone.FeedbackDelay(0.25, 0.5); + + this.effectSend.chain(this.delay, this.effectReturn); +} + +Tone.extend(EchoEffect, Tone.Effect); + +EchoEffect.prototype.set = function (val) { + this.value = val; + + this.value = this.clamp(this.value, 0, 100); + + // mute the effect if value is 0 + if (this.value == 0) { + this.wet.value = 0; + } else { + this.wet.value = 1; + } + + var feedback = (this.value / 100) * 0.75; + this.delay.feedback.rampTo(feedback, 1/60); +}; + +EchoEffect.prototype.changeBy = function (val) { + this.set(this.value + val); +}; + +EchoEffect.prototype.clamp = function (input, min, max) { + return Math.min(Math.max(input, min), max); +}; + +module.exports = EchoEffect; + diff --git a/src/effects/FuzzEffect.js b/src/effects/FuzzEffect.js new file mode 100644 index 0000000..2fcb369 --- /dev/null +++ b/src/effects/FuzzEffect.js @@ -0,0 +1,44 @@ +/* + +A fuzz effect + +Distortion + +the value controls the wet/dry amount + +Clamped 0-100 + +*/ + +var Tone = require('tone'); + +function FuzzEffect () { + Tone.Effect.call(this); + + this.value = 0; + + this.distortion = new Tone.Distortion(1); + + this.effectSend.chain(this.distortion, this.effectReturn); +} + +Tone.extend(FuzzEffect, Tone.Effect); + +FuzzEffect.prototype.set = function (val) { + this.value = val; + + this.value = this.clamp(this.value, 0, 100); + + this.distortion.wet.value = this.value / 100; +}; + +FuzzEffect.prototype.changeBy = function (val) { + this.set(this.value + val); +}; + +FuzzEffect.prototype.clamp = function (input, min, max) { + return Math.min(Math.max(input, min), max); +}; + +module.exports = FuzzEffect; + diff --git a/src/effects/PanEffect.js b/src/effects/PanEffect.js new file mode 100644 index 0000000..daf8107 --- /dev/null +++ b/src/effects/PanEffect.js @@ -0,0 +1,42 @@ +/* + +A Pan effect + +-100 puts the audio on the left channel, 0 centers it, 100 makes puts it on the right. + +Clamped -100 to 100 + +*/ + +var Tone = require('tone'); + +function PanEffect () { + Tone.Effect.call(this); + + this.value = 0; + + this.panner = new Tone.Panner(); + + this.effectSend.chain(this.panner, this.effectReturn); +} + +Tone.extend(PanEffect, Tone.Effect); + +PanEffect.prototype.set = function (val) { + this.value = val; + + this.value = this.clamp(this.value, -100, 100); + + this.panner.pan.value = this.value / 100; +}; + +PanEffect.prototype.changeBy = function (val) { + this.set(this.value + val); +}; + +PanEffect.prototype.clamp = function (input, min, max) { + return Math.min(Math.max(input, min), max); +}; + +module.exports = PanEffect; + diff --git a/src/effects/PitchEffect.js b/src/effects/PitchEffect.js new file mode 100644 index 0000000..105ee11 --- /dev/null +++ b/src/effects/PitchEffect.js @@ -0,0 +1,39 @@ +/* + +A Pitch effect + +*/ + +var Tone = require('tone'); + +function PitchEffect () { + this.value = 0; + + this.tone = new Tone(); +} + +PitchEffect.prototype.set = function (val, players) { + this.value = val; + this.updatePlayers(players); +}; + +PitchEffect.prototype.changeBy = function (val, players) { + this.set(this.value + val, players); +}; + +PitchEffect.prototype.getRatio = function () { + return this.tone.intervalToFrequencyRatio(this.value / 10); +}; + +PitchEffect.prototype.updatePlayers = function (players) { + if (!players) return; + + var ratio = this.getRatio(); + for (var i=0; i