2014-04-04 17:07:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// DRY/WET KNOB
|
|
|
|
//
|
|
|
|
// equal power fading
|
2014-04-04 18:36:01 +00:00
|
|
|
// control values:
|
2014-04-05 00:24:19 +00:00
|
|
|
// -1 = 100% dry
|
|
|
|
// 1 = 100% wet
|
2014-04-04 17:07:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
define(["core/Tone", "signal/Signal", "signal/Invert", "signal/Scale"], function(Tone){
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.DryWet = function(initialDry){
|
|
|
|
Tone.call(this);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
//components
|
|
|
|
this.dry = this.context.createGain();
|
|
|
|
this.wet = this.context.createGain();
|
|
|
|
this.output = this.context.createGain();
|
|
|
|
this.equalGain = this.context.createWaveShaper();
|
|
|
|
//control signal
|
|
|
|
this.control = new Tone.Signal();
|
|
|
|
this.invert = new Tone.Invert();
|
|
|
|
this.dryScale = new Tone.Scale(0, 1);
|
|
|
|
this.wetScale = new Tone.Scale(0, 1);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-04 18:36:01 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
//connections
|
|
|
|
this.dry.connect(this.output);
|
|
|
|
this.wet.connect(this.output);
|
|
|
|
//control signal connections
|
|
|
|
this.control.connect(this.equalGain);
|
|
|
|
//wet chain
|
|
|
|
this.chain(this.equalGain, this.wetScale, this.wet.gain);
|
|
|
|
//dry chain
|
|
|
|
this.chain(this.equalGain, this.invert, this.dryScale, this.dry.gain);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
//setup
|
|
|
|
this._equalPowerGainCurve();
|
|
|
|
this.dry.gain.value = 0;
|
|
|
|
this.wet.gain.value = 0;
|
|
|
|
this.setDry(0);
|
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.extend(Tone.DryWet);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.DryWet.prototype.setDry = function(val, rampTime){
|
|
|
|
rampTime = this.defaultArg(rampTime, 0);
|
|
|
|
this.control.linearRampToValueAtTime(val, rampTime);
|
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.DryWet.prototype.setWet = function(val, rampTime){
|
|
|
|
this.setDry(-val, rampTime);
|
2014-04-04 17:07:16 +00:00
|
|
|
}
|
2014-04-05 22:05:42 +00:00
|
|
|
|
|
|
|
//generates the values for the waveshaper
|
|
|
|
Tone.DryWet.prototype._equalPowerGainCurve = function(){
|
|
|
|
var len = this.bufferSize;
|
|
|
|
var curve = new Float32Array(len);
|
|
|
|
for (var i = 0; i < len; i++){
|
|
|
|
//values between -1 to 1
|
|
|
|
var baseline = (i / (len - 1)) * 2 - 1;
|
|
|
|
// scale it by amount
|
|
|
|
curve[i] = this.equalPowerGain(baseline);
|
|
|
|
// curve[i] = baseline;
|
|
|
|
}
|
|
|
|
this.equalGain.curve = curve;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Tone.DryWet;
|
|
|
|
});
|