mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
moving constants to Context
This commit is contained in:
parent
a74e84fa26
commit
19a41080ba
3 changed files with 5 additions and 61 deletions
|
@ -61,25 +61,12 @@ define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/Expr", "Tone/compon
|
|||
this.side.connect(this._right, 0, 1);
|
||||
this._left.connect(this._merge, 0, 0);
|
||||
this._right.connect(this._merge, 0, 1);
|
||||
sqrtTwo.connect(this._left, 0, 2);
|
||||
sqrtTwo.connect(this._right, 0, 2);
|
||||
this.context._sqrtTwo.connect(this._left, 0, 2);
|
||||
this.context._sqrtTwo.connect(this._right, 0, 2);
|
||||
};
|
||||
|
||||
Tone.extend(Tone.MidSideMerge);
|
||||
|
||||
/**
|
||||
* A constant signal equal to 1 / sqrt(2).
|
||||
* @type {Number}
|
||||
* @signal
|
||||
* @private
|
||||
* @static
|
||||
*/
|
||||
var sqrtTwo = null;
|
||||
|
||||
Tone._initAudioContext(function(){
|
||||
sqrtTwo = new Tone.Signal(1 / Math.sqrt(2));
|
||||
});
|
||||
|
||||
/**
|
||||
* clean up
|
||||
* @returns {Tone.MidSideMerge} this
|
||||
|
|
|
@ -43,25 +43,12 @@ define(["Tone/core/Tone", "Tone/signal/Expr", "Tone/signal/Signal", "Tone/compon
|
|||
this._split.connect(this.mid, 1, 1);
|
||||
this._split.connect(this.side, 0, 0);
|
||||
this._split.connect(this.side, 1, 1);
|
||||
sqrtTwo.connect(this.mid, 0, 2);
|
||||
sqrtTwo.connect(this.side, 0, 2);
|
||||
this.context._sqrtTwo.connect(this.mid, 0, 2);
|
||||
this.context._sqrtTwo.connect(this.side, 0, 2);
|
||||
};
|
||||
|
||||
Tone.extend(Tone.MidSideSplit);
|
||||
|
||||
/**
|
||||
* a constant signal equal to 1 / sqrt(2)
|
||||
* @type {Number}
|
||||
* @signal
|
||||
* @private
|
||||
* @static
|
||||
*/
|
||||
var sqrtTwo = null;
|
||||
|
||||
Tone._initAudioContext(function(){
|
||||
sqrtTwo = new Tone.Signal(1 / Math.sqrt(2));
|
||||
});
|
||||
|
||||
/**
|
||||
* clean up
|
||||
* @returns {Tone.MidSideSplit} this
|
||||
|
|
|
@ -41,7 +41,7 @@ define(["Tone/core/Tone", "Tone/signal/WaveShaper", "Tone/type/Type", "Tone/core
|
|||
this.input = this._param = this._gain.gain;
|
||||
|
||||
//connect the const output to the node output
|
||||
Tone.Signal._constant.chain(this._gain);
|
||||
this.context._ones.chain(this._gain);
|
||||
};
|
||||
|
||||
Tone.extend(Tone.Signal, Tone.Param);
|
||||
|
@ -84,35 +84,5 @@ define(["Tone/core/Tone", "Tone/signal/WaveShaper", "Tone/type/Type", "Tone/core
|
|||
return this;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// STATIC
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Generates a constant output of 1.
|
||||
* @static
|
||||
* @private
|
||||
* @const
|
||||
* @type {AudioBufferSourceNode}
|
||||
*/
|
||||
Tone.Signal._constant = null;
|
||||
|
||||
/**
|
||||
* initializer function
|
||||
*/
|
||||
Tone._initAudioContext(function(audioContext){
|
||||
var buffer = audioContext.createBuffer(1, 128, audioContext.sampleRate);
|
||||
var arr = buffer.getChannelData(0);
|
||||
for (var i = 0; i < arr.length; i++){
|
||||
arr[i] = 1;
|
||||
}
|
||||
Tone.Signal._constant = audioContext.createBufferSource();
|
||||
Tone.Signal._constant.channelCount = 1;
|
||||
Tone.Signal._constant.channelCountMode = "explicit";
|
||||
Tone.Signal._constant.buffer = buffer;
|
||||
Tone.Signal._constant.loop = true;
|
||||
Tone.Signal._constant.start(0);
|
||||
});
|
||||
|
||||
return Tone.Signal;
|
||||
});
|
Loading…
Reference in a new issue