2014-04-04 17:07:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// SIGNAL
|
|
|
|
//
|
|
|
|
// audio-rate value
|
|
|
|
// useful for controlling AudioParams
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-04-06 20:51:30 +00:00
|
|
|
define(["Tone/core/Tone"], function(Tone){
|
2014-04-05 22:05:42 +00:00
|
|
|
|
|
|
|
//@param {number=} value
|
|
|
|
Tone.Signal = function(value){
|
|
|
|
Tone.call(this);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
//components
|
|
|
|
this.signal = this.context.createWaveShaper();
|
|
|
|
this.scalar = this.context.createGain();
|
|
|
|
//generator to drive values
|
|
|
|
this.generator = this.context.createOscillator();
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
//connections
|
|
|
|
this.chain(this.generator, this.signal, this.scalar, this.output);
|
2014-04-06 00:47:59 +00:00
|
|
|
//pass values through
|
|
|
|
this.input.connect(this.output);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
//setup
|
|
|
|
this.generator.start(0);
|
|
|
|
this._signalCurve();
|
|
|
|
this.setValue(this.defaultArg(value, 0));
|
2014-04-06 00:47:59 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.extend(Tone.Signal);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
//generates a constant output of 1
|
|
|
|
Tone.Signal.prototype._signalCurve = function(){
|
|
|
|
var len = 8;
|
|
|
|
var curve = new Float32Array(len);
|
|
|
|
for (var i = 0; i < len; i++){
|
|
|
|
//all inputs produce the output value
|
|
|
|
curve[i] = 1;
|
|
|
|
}
|
|
|
|
//console.log(curve);
|
|
|
|
this.signal.curve = curve;
|
2014-04-04 17:07:16 +00:00
|
|
|
}
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.getValue = function(val){
|
|
|
|
return this.scalar.gain.value;
|
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.setValue = function(val){
|
|
|
|
this.scalar.gain.value = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
//all of the automation curves are available
|
|
|
|
Tone.Signal.prototype.setValueAtTime = function(value, time){
|
|
|
|
this.scalar.gain.setValueAtTime(value, time);
|
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.linearRampToValueAtTime = function(value, endTime){
|
|
|
|
this.scalar.gain.linearRampToValueAtTime(value, endTime);
|
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.exponentialRampToValueAtTime = function(value, endTime){
|
|
|
|
this.scalar.gain.exponentialRampToValueAtTime(value, endTime);
|
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.setTargetAtTime = function(target, startTime, timeConstant){
|
|
|
|
this.scalar.gain.setTargetAtTime(target, startTime, timeConstant);
|
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.setValueCurveAtTime = function(values, startTime, duration){
|
|
|
|
this.scalar.gain.setValueCurveAtTime(values, startTime, duration);
|
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.cancelScheduledValues = function(startTime){
|
|
|
|
this.scalar.gain.cancelScheduledValues(startTime);
|
|
|
|
}
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
return Tone.Signal;
|
|
|
|
})
|