2014-11-30 18:20:35 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/WaveShaper"], function(Tone){
|
2014-06-16 23:37:25 +00:00
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
2014-06-16 23:37:25 +00:00
|
|
|
|
2014-06-14 23:11:37 +00:00
|
|
|
/**
|
2014-07-04 17:47:56 +00:00
|
|
|
* @class Constant audio-rate signal.
|
|
|
|
* Tone.Signal is a core component which allows for sample-accurate
|
|
|
|
* synchronization of many components. Tone.Signal can be scheduled
|
|
|
|
* with all of the functions available to AudioParams
|
2014-06-17 16:15:10 +00:00
|
|
|
*
|
2014-06-14 23:11:37 +00:00
|
|
|
* @constructor
|
2014-12-01 04:26:42 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
2015-02-04 05:36:18 +00:00
|
|
|
* @param {number|AudioParam} [value=0] initial value or the AudioParam to control
|
|
|
|
* note that the signal has no output
|
|
|
|
* if an AudioParam is passed in.
|
|
|
|
* @param {Tone.Signal.Unit} [units=Number] unit the units the signal is in
|
2014-06-14 23:11:37 +00:00
|
|
|
*/
|
2015-02-04 05:36:18 +00:00
|
|
|
Tone.Signal = function(value, units){
|
2014-06-21 19:54:11 +00:00
|
|
|
|
2014-06-16 23:37:25 +00:00
|
|
|
/**
|
|
|
|
* scales the constant output to the desired output
|
|
|
|
* @type {GainNode}
|
2014-07-30 17:56:32 +00:00
|
|
|
* @private
|
2014-06-16 23:37:25 +00:00
|
|
|
*/
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar = this.context.createGain();
|
2014-10-03 19:50:21 +00:00
|
|
|
|
2014-06-16 23:37:25 +00:00
|
|
|
/**
|
|
|
|
* the ratio of the this value to the control signal value
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-06-14 23:11:37 +00:00
|
|
|
this._syncRatio = 1;
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-10-03 19:50:21 +00:00
|
|
|
/**
|
2015-02-04 05:36:18 +00:00
|
|
|
* the units the signal is in
|
|
|
|
* @type {Tone.Signal.Type}
|
|
|
|
*/
|
|
|
|
this.units = this.defaultArg(units, Tone.Signal.Units.Number);
|
|
|
|
|
|
|
|
var destination;
|
|
|
|
if (value instanceof AudioParam){
|
|
|
|
destination = value;
|
|
|
|
destination.value = 0;
|
|
|
|
} else {
|
|
|
|
destination = this.context.createGain();
|
|
|
|
this.value = this.defaultArg(value, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {GainNode|AudioParam}
|
2014-10-03 19:50:21 +00:00
|
|
|
*/
|
2015-02-04 05:36:18 +00:00
|
|
|
this.input = this.output = destination;
|
2014-10-03 19:50:21 +00:00
|
|
|
|
2014-06-16 23:37:25 +00:00
|
|
|
//connect the constant 1 output to the node output
|
2014-12-01 02:32:09 +00:00
|
|
|
Tone.Signal._constant.chain(this._scalar, this.output);
|
2014-06-14 23:11:37 +00:00
|
|
|
};
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-12-01 04:26:42 +00:00
|
|
|
Tone.extend(Tone.Signal, Tone.SignalBase);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2015-02-04 05:36:18 +00:00
|
|
|
/**
|
|
|
|
* The value of the signal.
|
|
|
|
* @memberOf Tone.Signal#
|
|
|
|
* @type {Tone.Time|Tone.Frequency|number}
|
|
|
|
* @name value
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Tone.Signal.prototype, "value", {
|
|
|
|
get : function(){
|
|
|
|
return this._toUnits(this._scalar.gain.value);
|
|
|
|
},
|
|
|
|
set : function(value){
|
|
|
|
var convertedVal = this._fromUnits(value);
|
|
|
|
convertedVal *= this._syncRatio;
|
|
|
|
this._scalar.gain.value = convertedVal;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @param {Tone.Time|Tone.Volume|Tone.Frequency|number|undefined} val the value to convert
|
|
|
|
* @return {number} the number which the value should be set to
|
|
|
|
*/
|
|
|
|
Tone.Signal.prototype._fromUnits = function(val){
|
|
|
|
switch(this.units){
|
|
|
|
case Tone.Signal.Units.Time:
|
|
|
|
return this.toSeconds(val);
|
|
|
|
case Tone.Signal.Units.Frequency:
|
|
|
|
return this.toFrequency(val);
|
|
|
|
case Tone.Signal.Units.Decibels:
|
|
|
|
return this.dbToGain(val);
|
2015-02-04 15:29:25 +00:00
|
|
|
case Tone.Signal.Units.Normal:
|
|
|
|
return Math.min(Math.max(val, 0), 1);
|
|
|
|
case Tone.Signal.Units.Audio:
|
|
|
|
return Math.min(Math.max(val, -1), 1);
|
2015-02-04 05:36:18 +00:00
|
|
|
default:
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* convert to the desired units
|
|
|
|
* @private
|
|
|
|
* @param {number} val the value to convert
|
|
|
|
* @return {number}
|
|
|
|
*/
|
|
|
|
Tone.Signal.prototype._toUnits = function(val){
|
|
|
|
switch(this.units){
|
|
|
|
case Tone.Signal.Units.Decibels:
|
|
|
|
return this.gainToDb(val);
|
|
|
|
default:
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-14 23:11:37 +00:00
|
|
|
/**
|
|
|
|
* Schedules a parameter value change at the given time.
|
|
|
|
*
|
2014-06-16 23:37:25 +00:00
|
|
|
* @param {number} value
|
|
|
|
* @param {Tone.Time} time
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-14 23:11:37 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.setValueAtTime = function(value, time){
|
2015-02-04 05:36:18 +00:00
|
|
|
value = this._fromUnits(value);
|
2014-06-14 23:11:37 +00:00
|
|
|
value *= this._syncRatio;
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar.gain.setValueAtTime(value, this.toSeconds(time));
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-14 23:11:37 +00:00
|
|
|
};
|
|
|
|
|
2014-06-18 05:36:22 +00:00
|
|
|
/**
|
|
|
|
* creates a schedule point with the current value at the current time
|
2014-06-18 20:56:50 +00:00
|
|
|
*
|
|
|
|
* @param {number=} now (optionally) pass the now value in
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-18 05:36:22 +00:00
|
|
|
*/
|
2014-06-18 20:56:50 +00:00
|
|
|
Tone.Signal.prototype.setCurrentValueNow = function(now){
|
|
|
|
now = this.defaultArg(now, this.now());
|
2015-02-04 05:36:18 +00:00
|
|
|
var currentVal = this.value;
|
2014-06-18 05:36:22 +00:00
|
|
|
this.cancelScheduledValues(now);
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar.gain.setValueAtTime(currentVal, now);
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-18 05:36:22 +00:00
|
|
|
};
|
|
|
|
|
2014-06-14 23:11:37 +00:00
|
|
|
/**
|
|
|
|
* Schedules a linear continuous change in parameter value from the
|
|
|
|
* previous scheduled parameter value to the given value.
|
|
|
|
*
|
|
|
|
* @param {number} value
|
2014-06-15 21:38:59 +00:00
|
|
|
* @param {Tone.Time} endTime
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-14 23:11:37 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.linearRampToValueAtTime = function(value, endTime){
|
2015-02-04 05:36:18 +00:00
|
|
|
value = this._fromUnits(value);
|
2014-06-14 23:11:37 +00:00
|
|
|
value *= this._syncRatio;
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar.gain.linearRampToValueAtTime(value, this.toSeconds(endTime));
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-14 23:11:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedules an exponential continuous change in parameter value from
|
|
|
|
* the previous scheduled parameter value to the given value.
|
|
|
|
*
|
|
|
|
* @param {number} value
|
2014-06-15 21:38:59 +00:00
|
|
|
* @param {Tone.Time} endTime
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-14 23:11:37 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.exponentialRampToValueAtTime = function(value, endTime){
|
2015-02-04 05:36:18 +00:00
|
|
|
value = this._fromUnits(value);
|
2014-06-14 23:11:37 +00:00
|
|
|
value *= this._syncRatio;
|
2014-12-06 21:47:48 +00:00
|
|
|
//can't go below a certain value
|
|
|
|
value = Math.max(0.00001, value);
|
|
|
|
this._scalar.gain.exponentialRampToValueAtTime(value, this.toSeconds(endTime));
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-14 23:11:37 +00:00
|
|
|
};
|
|
|
|
|
2014-06-18 05:36:22 +00:00
|
|
|
/**
|
|
|
|
* Schedules an exponential continuous change in parameter value from
|
|
|
|
* the current time and current value to the given value.
|
|
|
|
*
|
|
|
|
* @param {number} value
|
2015-02-04 05:36:18 +00:00
|
|
|
* @param {Tone.Time} rampTime the time that it takes the
|
|
|
|
* value to ramp from it's current value
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-18 05:36:22 +00:00
|
|
|
*/
|
2015-02-04 05:36:18 +00:00
|
|
|
Tone.Signal.prototype.exponentialRampToValueNow = function(value, rampTime ){
|
2014-06-18 20:56:50 +00:00
|
|
|
var now = this.now();
|
|
|
|
this.setCurrentValueNow(now);
|
2015-02-04 05:36:18 +00:00
|
|
|
this.exponentialRampToValueAtTime(value, now + this.toSeconds(rampTime ));
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-18 05:36:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Schedules an linear continuous change in parameter value from
|
|
|
|
* the current time and current value to the given value at the given time.
|
|
|
|
*
|
|
|
|
* @param {number} value
|
2015-02-04 05:36:18 +00:00
|
|
|
* @param {Tone.Time} rampTime the time that it takes the
|
|
|
|
* value to ramp from it's current value
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-18 05:36:22 +00:00
|
|
|
*/
|
2015-02-04 05:36:18 +00:00
|
|
|
Tone.Signal.prototype.linearRampToValueNow = function(value, rampTime){
|
|
|
|
value = this._fromUnits(value);
|
2014-06-18 20:56:50 +00:00
|
|
|
var now = this.now();
|
|
|
|
this.setCurrentValueNow(now);
|
2014-06-18 05:36:22 +00:00
|
|
|
value *= this._syncRatio;
|
2015-02-04 05:36:18 +00:00
|
|
|
this._scalar.gain.linearRampToValueAtTime(value, now + this.toSeconds(rampTime));
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-18 05:36:22 +00:00
|
|
|
};
|
|
|
|
|
2014-06-14 23:11:37 +00:00
|
|
|
/**
|
|
|
|
* Start exponentially approaching the target value at the given time with
|
|
|
|
* a rate having the given time constant.
|
|
|
|
*
|
|
|
|
* @param {number} value
|
2014-06-15 21:38:59 +00:00
|
|
|
* @param {Tone.Time} startTime
|
2014-06-14 23:11:37 +00:00
|
|
|
* @param {number} timeConstant
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-14 23:11:37 +00:00
|
|
|
*/
|
|
|
|
Tone.Signal.prototype.setTargetAtTime = function(value, startTime, timeConstant){
|
2015-02-04 05:36:18 +00:00
|
|
|
value = this._fromUnits(value);
|
2014-06-14 23:11:37 +00:00
|
|
|
value *= this._syncRatio;
|
2014-09-03 21:31:51 +00:00
|
|
|
this._scalar.gain.setTargetAtTime(value, this.toSeconds(startTime), timeConstant);
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-14 23:11:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets an array of arbitrary parameter values starting at the given time
|
|
|
|
* for the given duration.
|
|
|
|
*
|
|
|
|
* @param {Array<number>} values
|
2014-06-15 21:38:59 +00:00
|
|
|
* @param {Tone.Time} startTime
|
|
|
|
* @param {Tone.Time} duration
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-14 23:11:37 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.setValueCurveAtTime = function(values, startTime, duration){
|
2014-06-14 23:11:37 +00:00
|
|
|
for (var i = 0; i < values.length; i++){
|
2015-02-04 05:36:18 +00:00
|
|
|
values[i] = this._fromUnits(values[i]);
|
2014-06-14 23:11:37 +00:00
|
|
|
values[i] *= this._syncRatio;
|
|
|
|
}
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar.gain.setValueCurveAtTime(values, this.toSeconds(startTime), this.toSeconds(duration));
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-14 23:11:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cancels all scheduled parameter changes with times greater than or
|
|
|
|
* equal to startTime.
|
|
|
|
*
|
2014-06-15 21:38:59 +00:00
|
|
|
* @param {Tone.Time} startTime
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-14 23:11:37 +00:00
|
|
|
*/
|
2014-04-05 22:05:42 +00:00
|
|
|
Tone.Signal.prototype.cancelScheduledValues = function(startTime){
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar.gain.cancelScheduledValues(this.toSeconds(startTime));
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-14 23:11:37 +00:00
|
|
|
};
|
|
|
|
|
2015-02-04 05:36:18 +00:00
|
|
|
/**
|
|
|
|
* Ramps to the given value over the duration of the rampTime.
|
|
|
|
* Automatically selects the best ramp type (exponential or linear)
|
|
|
|
* depending on the `units` of the signal
|
|
|
|
*
|
|
|
|
* @param {number} value
|
|
|
|
* @param {Tone.Time} rampTime the time that it takes the
|
|
|
|
* value to ramp from it's current value
|
|
|
|
* @returns {Tone.Signal} `this`
|
|
|
|
*/
|
|
|
|
Tone.Signal.prototype.rampTo = function(value, rampTime){
|
2015-02-10 21:33:55 +00:00
|
|
|
rampTime = this.defaultArg(rampTime, 0);
|
2015-02-04 05:36:18 +00:00
|
|
|
if (this.units === Tone.Signal.Units.Frequency){
|
|
|
|
this.exponentialRampToValueNow(value, rampTime);
|
|
|
|
} else {
|
|
|
|
this.linearRampToValueNow(value, rampTime);
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2014-06-14 23:11:37 +00:00
|
|
|
/**
|
2014-06-16 23:37:25 +00:00
|
|
|
* Sync this to another signal and it will always maintain the
|
|
|
|
* ratio between the two signals until it is unsynced
|
2014-06-20 05:23:47 +00:00
|
|
|
*
|
|
|
|
* Signals can only be synced to one other signal. while syncing,
|
|
|
|
* if a signal's value is changed, the new ratio between the signals
|
|
|
|
* is maintained as the syncing signal is changed.
|
2014-06-14 23:11:37 +00:00
|
|
|
*
|
|
|
|
* @param {Tone.Signal} signal to sync to
|
2014-06-20 05:23:47 +00:00
|
|
|
* @param {number=} ratio optionally pass in the ratio between
|
|
|
|
* the two signals, otherwise it will be computed
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-14 23:11:37 +00:00
|
|
|
*/
|
2014-06-20 05:23:47 +00:00
|
|
|
Tone.Signal.prototype.sync = function(signal, ratio){
|
|
|
|
if (ratio){
|
|
|
|
this._syncRatio = ratio;
|
2014-06-14 23:11:37 +00:00
|
|
|
} else {
|
2014-06-20 05:23:47 +00:00
|
|
|
//get the sync ratio
|
2015-02-04 05:36:18 +00:00
|
|
|
if (signal.value !== 0){
|
|
|
|
this._syncRatio = this.value / signal.value;
|
2014-06-20 05:23:47 +00:00
|
|
|
} else {
|
|
|
|
this._syncRatio = 0;
|
|
|
|
}
|
2014-06-14 23:11:37 +00:00
|
|
|
}
|
2014-06-16 23:37:25 +00:00
|
|
|
//make a new scalar which is not connected to the constant signal
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar.disconnect();
|
|
|
|
this._scalar = this.context.createGain();
|
2014-11-30 22:37:29 +00:00
|
|
|
this.connectSeries(signal, this._scalar, this.output);
|
2014-06-16 23:37:25 +00:00
|
|
|
//set it ot the sync ratio
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar.gain.value = this._syncRatio;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-14 23:11:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* unbind the signal control
|
|
|
|
*
|
|
|
|
* will leave the signal value as it was without the influence of the control signal
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-14 23:11:37 +00:00
|
|
|
*/
|
|
|
|
Tone.Signal.prototype.unsync = function(){
|
|
|
|
//make a new scalar so that it's disconnected from the control signal
|
|
|
|
//get the current gain
|
2015-02-04 05:36:18 +00:00
|
|
|
var currentGain = this.value;
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar.disconnect();
|
|
|
|
this._scalar = this.context.createGain();
|
|
|
|
this._scalar.gain.value = currentGain / this._syncRatio;
|
2014-06-14 23:11:37 +00:00
|
|
|
this._syncRatio = 1;
|
2014-06-16 23:37:25 +00:00
|
|
|
//reconnect things up
|
2014-12-01 04:26:42 +00:00
|
|
|
Tone.Signal._constant.chain(this._scalar, this.output);
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-14 23:11:37 +00:00
|
|
|
};
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-06-19 02:35:31 +00:00
|
|
|
/**
|
2015-02-02 01:02:30 +00:00
|
|
|
* dispose and disconnect
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Signal} `this`
|
2014-06-19 02:35:31 +00:00
|
|
|
*/
|
2015-02-02 03:05:24 +00:00
|
|
|
Tone.Signal.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
2014-08-23 18:22:18 +00:00
|
|
|
this._scalar.disconnect();
|
|
|
|
this._scalar = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-19 02:35:31 +00:00
|
|
|
};
|
|
|
|
|
2015-02-02 01:02:30 +00:00
|
|
|
/**
|
2015-02-04 05:36:18 +00:00
|
|
|
* The units the Signal is in
|
|
|
|
* @enum {string}
|
2015-02-02 01:02:30 +00:00
|
|
|
*/
|
2015-02-04 05:36:18 +00:00
|
|
|
Tone.Signal.Units = {
|
2015-02-10 16:37:36 +00:00
|
|
|
/** The default type. */
|
2015-02-04 05:36:18 +00:00
|
|
|
Number : "number",
|
2015-02-10 16:37:36 +00:00
|
|
|
/** Tone.Time will be converted into seconds. */
|
2015-02-04 05:36:18 +00:00
|
|
|
Time : "time",
|
2015-02-10 16:37:36 +00:00
|
|
|
/** Tone.Frequency will be converted into hertz. */
|
2015-02-04 05:36:18 +00:00
|
|
|
Frequency : "frequency",
|
2015-02-10 16:37:36 +00:00
|
|
|
/** A Gain value. */
|
2015-02-04 05:36:18 +00:00
|
|
|
Gain : "gain",
|
2015-02-10 16:37:36 +00:00
|
|
|
/** Within normal range [0,1]. */
|
2015-02-04 15:29:25 +00:00
|
|
|
Normal : "normal",
|
2015-02-10 16:37:36 +00:00
|
|
|
/** Within normal range [-1,1]. */
|
2015-02-04 15:29:25 +00:00
|
|
|
Audio : "audio",
|
2015-02-10 16:37:36 +00:00
|
|
|
/** In decibels. */
|
|
|
|
Decibels : "db",
|
|
|
|
/** In half-step increments, i.e. 12 is an octave above the root. */
|
|
|
|
Interval : "interval"
|
2015-02-04 05:36:18 +00:00
|
|
|
};
|
2014-10-03 19:50:21 +00:00
|
|
|
|
2014-07-30 17:56:32 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// STATIC
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
2014-11-30 18:20:35 +00:00
|
|
|
* the constant signal generator
|
2014-07-30 17:56:32 +00:00
|
|
|
* @static
|
|
|
|
* @private
|
2014-11-30 18:20:35 +00:00
|
|
|
* @const
|
|
|
|
* @type {OscillatorNode}
|
2014-07-30 17:56:32 +00:00
|
|
|
*/
|
2014-11-30 18:20:35 +00:00
|
|
|
Tone.Signal._generator = null;
|
2014-07-30 17:56:32 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-30 18:20:35 +00:00
|
|
|
* the signal generator waveshaper. makes the incoming signal
|
|
|
|
* only output 1 for all inputs.
|
2014-07-30 17:56:32 +00:00
|
|
|
* @static
|
|
|
|
* @private
|
2014-11-30 18:20:35 +00:00
|
|
|
* @const
|
|
|
|
* @type {Tone.WaveShaper}
|
2014-07-30 17:56:32 +00:00
|
|
|
*/
|
2014-11-30 18:20:35 +00:00
|
|
|
Tone.Signal._constant = null;
|
2014-07-30 17:56:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* initializer function
|
|
|
|
*/
|
|
|
|
Tone._initAudioContext(function(audioContext){
|
2014-11-30 18:20:35 +00:00
|
|
|
Tone.Signal._generator = audioContext.createOscillator();
|
|
|
|
Tone.Signal._constant = new Tone.WaveShaper([1,1]);
|
|
|
|
Tone.Signal._generator.connect(Tone.Signal._constant);
|
|
|
|
Tone.Signal._generator.start(0);
|
|
|
|
Tone.Signal._generator.noGC();
|
2014-07-30 17:56:32 +00:00
|
|
|
});
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
return Tone.Signal;
|
2014-06-14 23:11:37 +00:00
|
|
|
});
|