This commit is contained in:
Yotam Mann 2014-06-17 12:15:10 -04:00
parent 76fb8e7aa5
commit 92d3c7a238
2 changed files with 23 additions and 13 deletions

View file

@ -30,14 +30,19 @@ define(["Tone/core/Tone"], function(Tone){
generator.start(0);
/**
* Signal
* constant audio-rate signal
*
* audio rate value with ramping syncing
* useful for controlling AudioParams
* can sync to another Tone.Signal
* Tone.Signal is a core component which allows for synchronization of many components.
* A single signal can drive multiple parameters by applying Scaling.
*
* For example: to synchronize two Tone.Oscillators in octaves of each other,
* Signal --> OscillatorA.frequency
* ^--> Tone.Multiply(2) --> OscillatorB.frequency
*
*
* Tone.Signal can be scheduled with all of the functions available to AudioParams
*
*
* @constructor
* @param {number=} value (optional) initial value
*/

View file

@ -14,16 +14,21 @@ function(Tone){
Tone.Oscillator = function(freq, type){
Tone.Source.call(this);
//components
/**
* the main oscillator
* @type {OscillatorNode}
*/
this.oscillator = this.context.createOscillator();
this.control = new Tone.Signal(this.defaultArg(this.toFrequency(freq), 440));
/**
* the frequency control signal
* @type {Tone.Signal}
*/
this.frequency = new Tone.Signal(this.defaultArg(this.toFrequency(freq), 440));
//connections
this.oscillator.connect(this.output);
//parameters
//setup
this.oscillator.type = this.defaultArg(type, "sine");
this.isSynced = false;
};
Tone.extend(Tone.Oscillator, Tone.Source);
@ -43,7 +48,7 @@ function(Tone){
this.oscillator.detune.value = detune;
//connect the control signal to the oscillator frequency
this.oscillator.connect(this.output);
this.control.connect(this.oscillator.frequency);
this.frequency.connect(this.oscillator.frequency);
this.oscillator.frequency.value = 0;
//start the oscillator
this.oscillator.start(this.toSeconds(time));
@ -59,7 +64,7 @@ function(Tone){
* Transport start/pause/stop will also start/pause/stop the oscillator
*/
Tone.Oscillator.prototype.sync = function(){
Tone.Transport.sync(this, this.control);
Tone.Transport.sync(this, this.frequency);
};
/**
@ -67,7 +72,7 @@ function(Tone){
*/
Tone.Oscillator.prototype.unsync = function(){
Tone.Transport.unsync(this);
this.control.unsync();
this.frequency.unsync();
};
/**
@ -85,7 +90,7 @@ function(Tone){
* @param {Tone.Time=} rampTime when the oscillator will arrive at the frequency
*/
Tone.Oscillator.prototype.setFrequency = function(val, rampTime){
this.control.exponentialRampToValueAtTime(this.toFrequency(val), this.toSeconds(rampTime));
this.frequency.exponentialRampToValueAtTime(this.toFrequency(val), this.toSeconds(rampTime));
};
/**