scratch-audio/src/effects/FuzzEffect.js

45 lines
741 B
JavaScript
Raw Normal View History

2016-11-29 18:33:09 -05:00
/*
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;