diff --git a/examples/envelope.html b/examples/envelope.html index cddf7867..3c576f8b 100644 --- a/examples/envelope.html +++ b/examples/envelope.html @@ -1,6 +1,6 @@ - Ping Pong Delay + Envelope @@ -44,16 +44,16 @@
diff --git a/examples/lfo.html b/examples/lfo.html index d6cb150a..f7e9c35b 100644 --- a/examples/lfo.html +++ b/examples/lfo.html @@ -11,8 +11,8 @@ + + + + + + + + + + + + + + + + + +
+
+ + + \ No newline at end of file diff --git a/examples/pingPongDelay.html b/examples/pingPongDelay.html index 851a06c8..6b0cd00d 100644 --- a/examples/pingPongDelay.html +++ b/examples/pingPongDelay.html @@ -11,6 +11,7 @@ + diff --git a/src/components/Envelope.js b/src/components/Envelope.js index 1b668382..b00794ce 100644 --- a/src/components/Envelope.js +++ b/src/components/Envelope.js @@ -9,15 +9,20 @@ AudioUnit.Envelope = function(attack, decay, sustain, release, audioParam, minOu //extend Unit AudioUnit.call(this); + //pass audio through this.input.connect(this.output); + + //set the parameters this.param = this.defaultArg(audioParam, this.input.gain); this.attack = this.defaultArg(attack, .01); this.decay = this.defaultArg(decay, .1); this.release = this.defaultArg(release, 1); - this.sustain = this.defaultArg(sustain, .5); + // this.sustain = this.defaultArg(this.gainToPowScale(sustain), .1); + this.setSustain(this.defaultArg(sustain, .1)); this.min = this.defaultArg(minOutput, 0); this.max = this.defaultArg(maxOutput, 1); - //set the initial + + //set the initial value this.param.value = this.min; } @@ -37,7 +42,7 @@ AudioUnit.Envelope.prototype.triggerAttack = function(time){ this.param.linearRampToValueAtTime(sustainVal, time + this.decay + this.attack); } -//triggers the release portiion of the envelope +//triggers the release of the envelope AudioUnit.Envelope.prototype.triggerRelease = function(time){ var startVal = this.param.value; if (time){ @@ -54,32 +59,32 @@ AudioUnit.Envelope.prototype.triggerRelease = function(time){ /////////////////////////////////////////////////////////////////////////////// //@param {number} attack (seconds) -AudioUnit.Envelope.setAttack = function(attack){ +AudioUnit.Envelope.prototype.setAttack = function(attack){ this.attack = attack; } //@param {number} decay (seconds) -AudioUnit.Envelope.setDecay = function(decay){ +AudioUnit.Envelope.prototype.setDecay = function(decay){ this.decay = decay; } //@param {number} release (seconds) -AudioUnit.Envelope.setRelease = function(release){ +AudioUnit.Envelope.prototype.setRelease = function(release){ this.release = release; } -//@param {number} sustain (gain) -AudioUnit.Envelope.setSustain = function(sustain){ - this.sustain = sustain; +//@param {number} sustain as a percentage (0-1); +AudioUnit.Envelope.prototype.setSustain = function(sustain){ + this.sustain = this.gainToPowScale(sustain); } //@param {number} min -AudioUnit.Envelope.setMin = function(min){ +AudioUnit.Envelope.prototype.setMin = function(min){ this.min = min; } //@param {number} max -AudioUnit.Envelope.setMax = function(max){ +AudioUnit.Envelope.prototype.setMax = function(max){ this.max = max; } diff --git a/src/components/LFO.js b/src/components/LFO.js index d0d3c13e..08db46e0 100644 --- a/src/components/LFO.js +++ b/src/components/LFO.js @@ -4,7 +4,7 @@ // /////////////////////////////////////////////////////////////////////////////// -AudioUnit.LFO = function(param, rate, outputMin, outputMax){ +AudioUnit.LFO = function(rate, outputMin, outputMax, param){ //extends Unit AudioUnit.call(this); //pass audio through diff --git a/src/components/Player.js b/src/components/Player.js index 23d28836..c2c4f5c7 100644 --- a/src/components/Player.js +++ b/src/components/Player.js @@ -18,7 +18,7 @@ AudioUnit.extend(AudioUnit.Player, AudioUnit); //makes an xhr for the buffer at the url //invokes the callback at the end -//@param {function(AudioUnit.Player)=} callback +//@param {function(AudioUnit.Player)} callback AudioUnit.Player.prototype.load = function(callback){ var request = new XMLHttpRequest(); request.open('GET', this.url, true); @@ -26,13 +26,14 @@ AudioUnit.Player.prototype.load = function(callback){ // decode asynchronously var self = this; request.onload = function() { - self.context.decodeAudioData(request.response, function(b) { - self.buffer = b; + self.context.decodeAudioData(request.response, function(buff) { + self.buffer = buff; if (callback){ callback(self); } }); } + //send the request request.send(); } diff --git a/src/components/StereoMeter.js b/src/components/StereoMeter.js deleted file mode 100644 index a4ead5ac..00000000 --- a/src/components/StereoMeter.js +++ /dev/null @@ -1,11 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// -// -// PING PONG DELAY -// -/////////////////////////////////////////////////////////////////////////////// - -//@param {number=} delayTime -AudioUnit.StereoMeter = function(){ - AudioUnit.StereoSplit.call(this); - -} \ No newline at end of file diff --git a/src/core/AudioUnit.js b/src/core/AudioUnit.js index 877514fa..f08671af 100644 --- a/src/core/AudioUnit.js +++ b/src/core/AudioUnit.js @@ -47,16 +47,16 @@ /////////////////////////////////////////////////////////////////////////// var AudioUnit = function(){ - this.context = audioContext; this.input = audioContext.createGain(); this.output = audioContext.createGain(); } /////////////////////////////////////////////////////////////////////////// - // STATIC VARS + // CLASS VARS /////////////////////////////////////////////////////////////////////////// - AudioUnit.prototype.fadeTime = .001; //1ms + AudioUnit.prototype.context = audioContext; + AudioUnit.prototype.fadeTime = .005; //5ms AudioUnit.prototype.bufferSize = 1024; //default buffer size /////////////////////////////////////////////////////////////////////////// @@ -221,15 +221,14 @@ // STATIC METHODS /////////////////////////////////////////////////////////////////////////// - //A extends B //based on closure library 'inherit' function - AudioUnit.extend = function(childCtor, parentCtor){ + AudioUnit.extend = function(child, parent){ /** @constructor */ - function tempCtor() {}; - tempCtor.prototype = parentCtor.prototype; - childCtor.prototype = new tempCtor(); - /** @override */ - childCtor.prototype.constructor = childCtor; + function tempConstructor() {}; + tempConstructor.prototype = parent.prototype; + child.prototype = new tempConstructor(); + /** @override */ + child.prototype.constructor = child; } /////////////////////////////////////////////////////////////////////////// @@ -243,7 +242,7 @@ //put a hard limiter on the output so we don't blow any eardrums this.limiter = this.context.createDynamicsCompressor(); this.limiter.threshold.value = 0; - this.limiter.ratio.value = 100; + this.limiter.ratio.value = 20; this.chain(this.input, this.limiter, this.output, this.context.destination); } AudioUnit.extend(Master, AudioUnit); diff --git a/src/effects/Effect.js b/src/effects/Effect.js index 869a22f5..050d9576 100644 --- a/src/effects/Effect.js +++ b/src/effects/Effect.js @@ -14,17 +14,13 @@ AudioUnit.Effect = function(){ this.dry = this.context.createGain(); this.effectSend = this.context.createGain(); this.effectReturn = this.context.createGain(); - this.feedback = this.context.createGain(); - this.feedback.gain.value = 0; //connections this.input.connect(this.dry); this.dry.connect(this.output); this.input.connect(this.effectSend); this.effectReturn.connect(this.output); - //feedback loop - this.chain(this.effectReturn, this.feedback, this.effectSend); - + //some initial values this.setDry(.5); } @@ -50,10 +46,6 @@ AudioUnit.Effect.prototype.bypass = function(){ this.setDry(1); } -AudioUnit.Effect.prototype.setFeedback = function(fback){ - this.rampToValue(this.feedback.gain, fback); -} - AudioUnit.Effect.prototype.connectEffect = function(effect){ this.chain(this.effectSend, effect, this.effectReturn); } \ No newline at end of file diff --git a/src/effects/FeedbackDelay.js b/src/effects/FeedbackDelay.js index 57d9b7c8..db95e637 100644 --- a/src/effects/FeedbackDelay.js +++ b/src/effects/FeedbackDelay.js @@ -6,7 +6,7 @@ //@param {number} delayTime AudioUnit.FeedbackDelay = function(delayTime){ - AudioUnit.Effect.call(this); + AudioUnit.FeedbackEffect.call(this); this.delay = this.context.createDelay(4); this.delay.delayTime.value = this.defaultArg(delayTime, .25); @@ -15,7 +15,7 @@ AudioUnit.FeedbackDelay = function(delayTime){ this.connectEffect(this.delay); } -AudioUnit.extend(AudioUnit.FeedbackDelay, AudioUnit.Effect); +AudioUnit.extend(AudioUnit.FeedbackDelay, AudioUnit.FeedbackEffect); AudioUnit.FeedbackDelay.prototype.setDelayTime = function(delayTime){ this.rampToValue(this.delay.delayTime, delayTime); diff --git a/src/effects/FeedbackEffect.js b/src/effects/FeedbackEffect.js new file mode 100644 index 00000000..38021269 --- /dev/null +++ b/src/effects/FeedbackEffect.js @@ -0,0 +1,26 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// FEEDBACK EFFECTS +// +// an effect with feedback +/////////////////////////////////////////////////////////////////////////////// + + +AudioUnit.FeedbackEffect = function(){ + //extends Unit + AudioUnit.Effect.call(this); + + this.feedback = this.context.createGain(); + //feedback loop + this.chain(this.effectReturn, this.feedback, this.effectSend); + + //some initial values + this.setDry(.5); +} + +AudioUnit.extend(AudioUnit.FeedbackEffect, AudioUnit.Effect); + + +AudioUnit.Effect.prototype.setFeedback = function(fback){ + this.rampToValue(this.feedback.gain, fback); +}