Renamed AudioUnit -> Tone

This commit is contained in:
Yotam Mann 2014-03-16 13:33:56 -04:00
parent 6119c75ea8
commit 9a190abac1
24 changed files with 201 additions and 196 deletions

View file

@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="../style/GUI.css">
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../src/core/AudioUnit.js"></script>
<script type="text/javascript" src="../src/core/Tone.js"></script>
<script type="text/javascript" src="../src/components/Envelope.js"></script>
<script type="text/javascript" src="../src/components/Noise.js"></script>
</head>
@ -44,8 +44,8 @@
</style>
<div id='Trigger'></div>
<script type="text/javascript">
var env = new AudioUnit.Envelope(.05, .01, .7, .4);
var noise = new AudioUnit.Noise();
var env = new Tone.Envelope(.05, .01, .7, .4);
var noise = new Tone.Noise();
noise.connect(env);
env.toMaster();

View file

@ -5,14 +5,14 @@
<link rel="stylesheet" type="text/css" href="../style/GUI.css">
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../src/core/AudioUnit.js"></script>
<script type="text/javascript" src="../src/core/Tone.js"></script>
<script type="text/javascript" src="../src/components/LFO.js"></script>
<script type="text/javascript" src="../src/components/Noise.js"></script>
</head>
<body>
<script type="text/javascript">
var noise = new AudioUnit.Noise("brown");
var lfo = new AudioUnit.LFO(1);
var noise = new Tone.Noise("brown");
var lfo = new Tone.LFO(1);
noise.connect(lfo);
lfo.toMaster();

View file

@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="../style/GUI.css">
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../src/core/AudioUnit.js"></script>
<script type="text/javascript" src="../src/core/Tone.js"></script>
<script type="text/javascript" src="../src/components/Meter.js"></script>
<script type="text/javascript" src="../src/components/Envelope.js"></script>
<script type="text/javascript" src="../src/components/Noise.js"></script>
@ -76,12 +76,12 @@
<div id='Trigger'></div>
<div id='MasterOut'></div>
<script type="text/javascript">
var meter = new AudioUnit.Meter(2);
var mic = new AudioUnit.Microphone();
var env = new AudioUnit.Envelope(.05, .01, 0, 0);
var feedbackDelay = new AudioUnit.FeedbackDelay(.25);
var fader = new AudioUnit.GUI.GainFader($("#MasterOut"), AudioUnit.Master.output, "mstr");
var meterGui = new AudioUnit.GUI.Meter($("#MasterOut"), meter, "master", 20);
var meter = new Tone.Meter(2);
var mic = new Tone.Microphone();
var env = new Tone.Envelope(.05, .01, 0, 0);
var feedbackDelay = new Tone.FeedbackDelay(.25);
var fader = new Tone.GUI.GainFader($("#MasterOut"), Tone.Master.output, "mstr");
var meterGui = new Tone.GUI.Meter($("#MasterOut"), meter, "master", 20);
mic.connect(feedbackDelay);
feedbackDelay.setWet(1);
@ -89,7 +89,7 @@
feedbackDelay.toMaster();
//the master output meter
AudioUnit.Master.connect(meter);
Tone.Master.connect(meter);
$("#Trigger").bind("mousedown touchstart", function(e){
mic.start();

View file

@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="../style/GUI.css">
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../src/core/AudioUnit.js"></script>
<script type="text/javascript" src="../src/core/Tone.js"></script>
<script type="text/javascript" src="../src/components/Meter.js"></script>
<script type="text/javascript" src="../src/components/Envelope.js"></script>
<script type="text/javascript" src="../src/components/Noise.js"></script>
@ -82,13 +82,13 @@
<div id='Trigger'></div>
<div id='MasterOut'></div>
<script type="text/javascript">
var meter = new AudioUnit.Meter(2);
var env = new AudioUnit.Envelope(.05, .01, 0, 0);
var noise = new AudioUnit.Noise();
var feedbackDelay = new AudioUnit.PingPongDelay(.25);
var fader = new AudioUnit.GUI.GainFader($("#MasterOut"), AudioUnit.Master.output, "mstr");
var meterGui = new AudioUnit.GUI.Meter($("#MasterOut"), meter, "master", 20);
var compGui = new AudioUnit.GUI.Compressor($("body"), AudioUnit.Master.limiter);
var meter = new Tone.Meter(2);
var env = new Tone.Envelope(.05, .01, 0, 0);
var noise = new Tone.Noise();
var feedbackDelay = new Tone.PingPongDelay(.25);
var fader = new Tone.GUI.GainFader($("#MasterOut"), Tone.Master.output, "mstr");
var meterGui = new Tone.GUI.Meter($("#MasterOut"), meter, "master", 20);
var compGui = new Tone.GUI.Compressor($("body"), Tone.Master.limiter);
noise.connect(env);
env.connect(feedbackDelay);
@ -96,7 +96,7 @@
feedbackDelay.toMaster();
//the master output meter
AudioUnit.Master.connect(meter);
Tone.Master.connect(meter);
$("#Trigger").bind("mousedown touchstart", function(e){
env.triggerAttack();

View file

@ -5,7 +5,7 @@
<link rel="stylesheet" type="text/css" href="../style/GUI.css">
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script type="text/javascript" src="../src/core/AudioUnit.js"></script>
<script type="text/javascript" src="../src/core/Tone.js"></script>
<script type="text/javascript" src="../src/components/Player.js"></script>
</head>
<body>
@ -43,7 +43,7 @@
</style>
<div id='Trigger'></div>
<script type="text/javascript">
var player = new AudioUnit.Player("../audio/casio/A1.mp3");
var player = new Tone.Player("../audio/casio/A1.mp3");
player.toMaster();

View file

@ -7,9 +7,9 @@
//@param {Element} container
//@param {number=} segments
AudioUnit.GUI.Bar = function(container, segments){
Tone.GUI.Bar = function(container, segments){
//extend GUI
AudioUnit.GUI.call(this);
Tone.GUI.call(this);
//vars
this.element = this.createElement();
@ -38,10 +38,10 @@ AudioUnit.GUI.Bar = function(container, segments){
this.appendChild(this.element, this.label);
}
AudioUnit.extend(AudioUnit.GUI.Bar, AudioUnit.GUI);
Tone.extend(Tone.GUI.Bar, Tone.GUI);
//@param {number} val (0-1)
AudioUnit.GUI.Bar.prototype.setLevel = function(val){
Tone.GUI.Bar.prototype.setLevel = function(val){
val *= this.segmentCount;
for (var i = 0; i < this.segmentCount; i++){
var seg = this.segments[i];

View file

@ -1,17 +1,17 @@
AudioUnit.GUI.Compressor = function(container, compressor, segments){
AudioUnit.GUI.call(this);
Tone.GUI.Compressor = function(container, compressor, segments){
Tone.GUI.call(this);
this.element = this.createElement();
//display the gain reduction
this.reduction = new AudioUnit.GUI.ParamFader(this.element, compressor.reduction, -20, 0, "reduct", "lin", segments);
this.reduction = new Tone.GUI.ParamFader(this.element, compressor.reduction, -20, 0, "reduct", "lin", segments);
this.reduction.slider.remove();
//fader for thresh
this.threshold = new AudioUnit.GUI.ParamFader(this.element, compressor.threshold, -60, 0, "thresh", "lin", segments);
this.threshold = new Tone.GUI.ParamFader(this.element, compressor.threshold, -60, 0, "thresh", "lin", segments);
//fader for ratio
this.ratio = new AudioUnit.GUI.ParamFader(this.element, compressor.ratio, 1, 20, "ratio", "log", segments);
this.ratio = new Tone.GUI.ParamFader(this.element, compressor.ratio, 1, 20, "ratio", "log", segments);
this.appendChild(container, this.element);
}
AudioUnit.extend(AudioUnit.GUI.Compressor, AudioUnit.GUI);
Tone.extend(Tone.GUI.Compressor, Tone.GUI);

View file

@ -4,9 +4,9 @@
//
///////////////////////////////////////////////////////////////////////////////
AudioUnit.GUI.Fader = function(container, minOutput, maxOutput, label, segments){
Tone.GUI.Fader = function(container, minOutput, maxOutput, label, segments){
//extend GUI
AudioUnit.GUI.call(this);
Tone.GUI.call(this);
//components
this.element = this.createElement();
@ -25,7 +25,7 @@ AudioUnit.GUI.Fader = function(container, minOutput, maxOutput, label, segments)
this.currentLevel = null;
this.scaling = "lin";
this.bars = new AudioUnit.GUI.Bar(this.track, segments);
this.bars = new Tone.GUI.Bar(this.track, segments);
//set it
this.setClass(this.element, "fader");
@ -44,14 +44,14 @@ AudioUnit.GUI.Fader = function(container, minOutput, maxOutput, label, segments)
this.setLabel(this.defaultArg(label, ""));
}
AudioUnit.extend(AudioUnit.GUI.Fader, AudioUnit.GUI);
Tone.extend(Tone.GUI.Fader, Tone.GUI);
//called when the value has changed
AudioUnit.GUI.Fader.prototype.onchange = function(){};
Tone.GUI.Fader.prototype.onchange = function(){};
//set the level of the
AudioUnit.GUI.Fader.prototype.setLevel = function(level){
Tone.GUI.Fader.prototype.setLevel = function(level){
if (level !== this.currentLevel){
this.currentLevel = level;
this._setText(level);
@ -64,13 +64,13 @@ AudioUnit.GUI.Fader.prototype.setLevel = function(level){
// SCALING VALUES
///////////////////////////////////////////////////////////////////////////////
AudioUnit.GUI.Fader.prototype._onchangeText = function(e){
Tone.GUI.Fader.prototype._onchangeText = function(e){
var val = parseFloat(this.textInput.value);
this.setLevel(val);
}
//called when the value has changed
AudioUnit.GUI.Fader.prototype._onchangeSlider = function(){
Tone.GUI.Fader.prototype._onchangeSlider = function(){
var scaledVal = this._scale(this.slider.value / 100)
var val = this.interpolate(scaledVal, this.min, this.max);
this.setLevel(val);
@ -78,7 +78,7 @@ AudioUnit.GUI.Fader.prototype._onchangeSlider = function(){
//@param {number} val
AudioUnit.GUI.Fader.prototype._setText = function(val){
Tone.GUI.Fader.prototype._setText = function(val){
if (val < 10){
this.textInput.value = val.toFixed(3);
} else if (val < 100){
@ -88,7 +88,7 @@ AudioUnit.GUI.Fader.prototype._setText = function(val){
}
}
AudioUnit.GUI.Fader.prototype._setSlider = function(val){
Tone.GUI.Fader.prototype._setSlider = function(val){
//scale it to the slider range
var normed = this.normalize(val, this.min, this.max);
var scaled = this._inverseScale(normed);
@ -98,7 +98,7 @@ AudioUnit.GUI.Fader.prototype._setSlider = function(val){
//input a value between 0-1
AudioUnit.GUI.Fader.prototype._inverseScale = function(x){
Tone.GUI.Fader.prototype._inverseScale = function(x){
switch(this.scaling){
case "lin" :
return parseFloat(x);
@ -110,7 +110,7 @@ AudioUnit.GUI.Fader.prototype._inverseScale = function(x){
}
//input a value between 0-1
AudioUnit.GUI.Fader.prototype._scale = function(x){
Tone.GUI.Fader.prototype._scale = function(x){
switch(this.scaling){
case "lin" :
return parseFloat(x);
@ -126,17 +126,17 @@ AudioUnit.GUI.Fader.prototype._scale = function(x){
///////////////////////////////////////////////////////////////////////////////
//called when the value has changed
AudioUnit.GUI.Fader.prototype._setupEvents = function(){
Tone.GUI.Fader.prototype._setupEvents = function(){
this.textInput.onchange = this._onchangeText.bind(this);
this.slider.onchange = this._onchangeSlider.bind(this);
this.slider.onmousedown = this._mousedown.bind(this);
this.slider.onmouseup = this._mouseup.bind(this);
};
AudioUnit.GUI.Fader.prototype._mousedown = function(e){
Tone.GUI.Fader.prototype._mousedown = function(e){
this.isDragging = true;
}
AudioUnit.GUI.Fader.prototype._mouseup = function(e){
Tone.GUI.Fader.prototype._mouseup = function(e){
this.isDragging = false;
}

View file

@ -2,26 +2,26 @@
//
// GAIN FADER
//
// attach it to an GainNode or an AudioUnit to control the output gain
// attach it to an GainNode or an Tone to control the output gain
///////////////////////////////////////////////////////////////////////////////
AudioUnit.GUI.GainFader = function(container, gain, label, segments){
Tone.GUI.GainFader = function(container, gain, label, segments){
if (!(gain instanceof GainNode) && gain.output instanceof GainNode){
gain = gain.output;
}
//extend Fader
AudioUnit.GUI.ParamFader.call(this, container, gain.gain, 0, 1, label, "log", segments);
Tone.GUI.ParamFader.call(this, container, gain.gain, 0, 1, label, "log", segments);
}
AudioUnit.extend(AudioUnit.GUI.GainFader, AudioUnit.GUI.ParamFader);
Tone.extend(Tone.GUI.GainFader, Tone.GUI.ParamFader);
//@override
AudioUnit.GUI.GainFader.prototype._setText = function(val){
Tone.GUI.GainFader.prototype._setText = function(val){
this.textInput.value = this.gainToDb(val).toFixed(1) + "db";
}
//@override
AudioUnit.GUI.GainFader.prototype._onchangeText = function(e){
Tone.GUI.GainFader.prototype._onchangeText = function(e){
var val = parseFloat(this.textInput.value);
this.setLevel(this.dbToGain(val));
}

View file

@ -1,10 +1,10 @@
//@param {Element} container
//@param {AudioUnit.Meter} meter
//@param {Tone.Meter} meter
//@param {string=} label
//@param {number=} segments
AudioUnit.GUI.Meter = function(container, meter, label, segments){
AudioUnit.GUI.call(this);
Tone.GUI.Meter = function(container, meter, label, segments){
Tone.GUI.call(this);
//components
this.meter = meter;
@ -14,7 +14,7 @@ AudioUnit.GUI.Meter = function(container, meter, label, segments){
//add the bars
for (var i = 0; i < this.meter.channels; i++){
var bar = new AudioUnit.GUI.Bar(this.element, segments);
var bar = new Tone.GUI.Bar(this.element, segments);
this.bars[i] = bar;
}
@ -28,9 +28,9 @@ AudioUnit.GUI.Meter = function(container, meter, label, segments){
this.appendChild(this.element, this.label);
}
AudioUnit.extend(AudioUnit.GUI.Meter, AudioUnit.GUI);
Tone.extend(Tone.GUI.Meter, Tone.GUI);
AudioUnit.GUI.Meter.prototype.update = function(){
Tone.GUI.Meter.prototype.update = function(){
for (var channel = 0, channelCount = this.meter.channels; channel < channelCount; channel++){
var volume = this.meter.getLevel(channel);
this.bars[channel].setLevel(this.gainToLogScale(volume));
@ -38,7 +38,7 @@ AudioUnit.GUI.Meter.prototype.update = function(){
}
}
AudioUnit.GUI.Meter.prototype.labelUpdate = function(){
Tone.GUI.Meter.prototype.labelUpdate = function(){
for (var channel = 0, channelCount = this.meter.channels; channel < channelCount; channel++){
var db = this.meter.getDb(channel);
if (db < -120){

View file

@ -5,9 +5,9 @@
// attach it to an AudioParam and let it control/follow it's value
///////////////////////////////////////////////////////////////////////////////
AudioUnit.GUI.ParamFader = function(container, audioParam, minOutput, maxOutput, label, scaling, segments){
Tone.GUI.ParamFader = function(container, audioParam, minOutput, maxOutput, label, scaling, segments){
//extend Fader
AudioUnit.GUI.Fader.call(this, container, minOutput, maxOutput, label, segments);
Tone.GUI.Fader.call(this, container, minOutput, maxOutput, label, segments);
//set the scaling
this.scaling = this.defaultArg(scaling, "log");
@ -16,15 +16,15 @@ AudioUnit.GUI.ParamFader = function(container, audioParam, minOutput, maxOutput,
this.onAnimationFrame(this.followValue, this);
}
AudioUnit.extend(AudioUnit.GUI.ParamFader, AudioUnit.GUI.Fader);
Tone.extend(Tone.GUI.ParamFader, Tone.GUI.Fader);
//called 60fps
AudioUnit.GUI.ParamFader.prototype.followValue = function(){
Tone.GUI.ParamFader.prototype.followValue = function(){
if (!this.isDragging){
this.setLevel(this.watch.value);
}
}
AudioUnit.GUI.ParamFader.prototype.onchange = function(val){
Tone.GUI.ParamFader.prototype.onchange = function(val){
this.watch.value = val;
}

View file

@ -17,25 +17,25 @@ window.requestAnimFrame = (function(){
(function(global){
AudioUnit.GUI = function(){
Tone.GUI = function(){
this.element = null;
this._fastUpdateID = null;
this._slowUpdateID = null;
}
//BORROW SOME METHODS FROM AUDIOUNIT
AudioUnit.extend(AudioUnit.GUI, AudioUnit);
Tone.extend(Tone.GUI, Tone);
///////////////////////////////////////////////////////////////////////////
// PRIVATE
///////////////////////////////////////////////////////////////////////////
//@private
//@type {Array<AudioUnit.GUI>}
//@type {Array<Tone.GUI>}
var _onFastUpdateCallbacks = [];
//@private
//@type {Array<AudioUnit.GUI>}
//@type {Array<Tone.GUI>}
var _onSlowUpdateCallbacks = [];
//@private
@ -73,7 +73,7 @@ window.requestAnimFrame = (function(){
//callback gets envoked at 60fps
//@param {function()} callback
//@param {Object} ctx (the "this" object)
AudioUnit.GUI.prototype.onAnimationFrame = function(callback, ctx){
Tone.GUI.prototype.onAnimationFrame = function(callback, ctx){
var id = getNextID();
var callbackObj = {
callback : callback,
@ -86,7 +86,7 @@ window.requestAnimFrame = (function(){
//callback gets envoked at 60fps
//@param {function()} callback
//@param {Object} ctx (the "this" object)
AudioUnit.GUI.prototype.onSlowUpdate = function(callback, ctx){
Tone.GUI.prototype.onSlowUpdate = function(callback, ctx){
var id = getNextID();
var callbackObj = {
callback : callback,
@ -96,7 +96,7 @@ window.requestAnimFrame = (function(){
_onSlowUpdateCallbacks.push(callbackObj);
}
AudioUnit.GUI.prototype.remove = function(){
Tone.GUI.prototype.remove = function(){
if (this.element !== null){
this.removeChildren();
this.element.remove();
@ -118,7 +118,7 @@ window.requestAnimFrame = (function(){
// UTILITIES
///////////////////////////////////////////////////////////////////////////
AudioUnit.GUI.prototype.removeChildren = function(){
Tone.GUI.prototype.removeChildren = function(){
if (this.element){
var child;
while (child = this.element.firstChild) {
@ -129,19 +129,19 @@ window.requestAnimFrame = (function(){
//@param {Element} container
//@param {Element} element
AudioUnit.GUI.prototype.appendChild = function(container, element){
Tone.GUI.prototype.appendChild = function(container, element){
this._getElement(container).appendChild(this._getElement(element));
}
//@param {string=} type
AudioUnit.GUI.prototype.createElement = function(type){
Tone.GUI.prototype.createElement = function(type){
type = this.defaultArg(type, "div");
return document.createElement(type);
}
//@param {Element} element
//@param {Element} unwraps jquery if necessary
AudioUnit.GUI.prototype._getElement = function(el){
Tone.GUI.prototype._getElement = function(el){
if (typeof jQuery !== 'undefined' && el instanceof jQuery){
return el[0];
} else if (el.element && meterGui.element instanceof HTMLElement){
@ -153,12 +153,12 @@ window.requestAnimFrame = (function(){
//@param {Element} element
//@param {string} className
AudioUnit.GUI.prototype.setClass = function(element, className){
Tone.GUI.prototype.setClass = function(element, className){
this._getElement(element).className = className;
}
//@param {string} str
AudioUnit.GUI.prototype.setLabel = function(str){
Tone.GUI.prototype.setLabel = function(str){
if (this.label && this.label instanceof HTMLElement){
this.label.textContent = str;
}
@ -166,5 +166,5 @@ window.requestAnimFrame = (function(){
//give it to the window
global.AudioUnit.GUI = AudioUnit.GUI;
global.Tone.GUI = Tone.GUI;
})(window);

View file

@ -5,9 +5,9 @@
// ADR envelope generator attaches to an AudioParam
///////////////////////////////////////////////////////////////////////////////
AudioUnit.Envelope = function(attack, decay, sustain, release, audioParam, minOutput, maxOutput){
Tone.Envelope = function(attack, decay, sustain, release, audioParam, minOutput, maxOutput){
//extend Unit
AudioUnit.call(this);
Tone.call(this);
//pass audio through
this.input.connect(this.output);
@ -26,10 +26,10 @@ AudioUnit.Envelope = function(attack, decay, sustain, release, audioParam, minOu
this.param.value = this.min;
}
AudioUnit.extend(AudioUnit.Envelope, AudioUnit);
Tone.extend(Tone.Envelope, Tone);
//attack->decay->sustain
AudioUnit.Envelope.prototype.triggerAttack = function(time){
Tone.Envelope.prototype.triggerAttack = function(time){
var startVal = this.min;
if (!time){
startVal = this.param.value;
@ -43,7 +43,7 @@ AudioUnit.Envelope.prototype.triggerAttack = function(time){
}
//triggers the release of the envelope
AudioUnit.Envelope.prototype.triggerRelease = function(time){
Tone.Envelope.prototype.triggerRelease = function(time){
var startVal = this.param.value;
if (time){
startVal = (this.max - this.min) * this.sustain + this.min;
@ -59,32 +59,32 @@ AudioUnit.Envelope.prototype.triggerRelease = function(time){
///////////////////////////////////////////////////////////////////////////////
//@param {number} attack (seconds)
AudioUnit.Envelope.prototype.setAttack = function(attack){
Tone.Envelope.prototype.setAttack = function(attack){
this.attack = attack;
}
//@param {number} decay (seconds)
AudioUnit.Envelope.prototype.setDecay = function(decay){
Tone.Envelope.prototype.setDecay = function(decay){
this.decay = decay;
}
//@param {number} release (seconds)
AudioUnit.Envelope.prototype.setRelease = function(release){
Tone.Envelope.prototype.setRelease = function(release){
this.release = release;
}
//@param {number} sustain as a percentage (0-1);
AudioUnit.Envelope.prototype.setSustain = function(sustain){
Tone.Envelope.prototype.setSustain = function(sustain){
this.sustain = this.gainToPowScale(sustain);
}
//@param {number} min
AudioUnit.Envelope.prototype.setMin = function(min){
Tone.Envelope.prototype.setMin = function(min){
this.min = min;
}
//@param {number} max
AudioUnit.Envelope.prototype.setMax = function(max){
Tone.Envelope.prototype.setMax = function(max){
this.max = max;
}

View file

@ -4,9 +4,9 @@
//
///////////////////////////////////////////////////////////////////////////////
AudioUnit.LFO = function(rate, outputMin, outputMax, param){
Tone.LFO = function(rate, outputMin, outputMax, param){
//extends Unit
AudioUnit.call(this);
Tone.call(this);
//pass audio through
this.input.connect(this.output);
@ -31,10 +31,10 @@ AudioUnit.LFO = function(rate, outputMin, outputMax, param){
this.setType("sine");
}
AudioUnit.extend(AudioUnit.LFO, AudioUnit);
Tone.extend(Tone.LFO, Tone);
//generates the values for the waveshaper
AudioUnit.LFO.prototype._createCurve = function(){
Tone.LFO.prototype._createCurve = function(){
var len = 16;
var curve = new Float32Array(len);
for (var i = 0; i < len; i++){
@ -46,32 +46,32 @@ AudioUnit.LFO.prototype._createCurve = function(){
}
//sets the gain value
AudioUnit.LFO.prototype._setScalar = function(){
Tone.LFO.prototype._setScalar = function(){
this.scalar.gain.value = this.max - this.min;
}
//set the params
AudioUnit.LFO.prototype.setRate = function(rate){
Tone.LFO.prototype.setRate = function(rate){
this.rate = rate;
this.rampToValue(this.oscillator.frequency, rate, .1);
}
//set the params
AudioUnit.LFO.prototype.setMin = function(min){
Tone.LFO.prototype.setMin = function(min){
this.min = min;
this._createCurve();
this._setScalar();
}
//set the params
AudioUnit.LFO.prototype.setMax = function(max){
Tone.LFO.prototype.setMax = function(max){
this.max = max;
this._setScalar();
}
//set the waveform of the LFO
//@param {string | number} type ('sine', 'square', 'sawtooth', 'triangle', 'custom');
AudioUnit.LFO.prototype.setType = function(type){
Tone.LFO.prototype.setType = function(type){
this.oscillator.type = type;
}

View file

@ -9,9 +9,9 @@
///////////////////////////////////////////////////////////////////////////////
//@param {number=} channels
AudioUnit.Meter = function(channels){
Tone.Meter = function(channels){
//extends Unit
AudioUnit.call(this);
Tone.call(this);
this.channels = this.defaultArg(channels, 1);
this.volume = new Array(this.channels);
@ -31,12 +31,12 @@ AudioUnit.Meter = function(channels){
this.toMaster(this.jsNode);
}
AudioUnit.extend(AudioUnit.Meter, AudioUnit);
Tone.extend(Tone.Meter, Tone);
//@param {number=} channel
//@returns {number}
AudioUnit.Meter.prototype.getLevel = function(channel){
Tone.Meter.prototype.getLevel = function(channel){
channel = this.defaultArg(channel, 0);
var vol = this.volume[channel];
if (vol < .00001){
@ -48,17 +48,17 @@ AudioUnit.Meter.prototype.getLevel = function(channel){
//@param {number=} channel
//@returns {number} the channel volume in decibels
AudioUnit.Meter.prototype.getDb = function(channel){
Tone.Meter.prototype.getDb = function(channel){
return this.gainToDb(this.getLevel(channel));
}
// @returns {boolean} if the audio has clipped in the last 500ms
AudioUnit.Meter.prototype.isClipped = function(){
Tone.Meter.prototype.isClipped = function(){
return Date.now() - this.clipTime < 500;
}
//get the max value
AudioUnit.Meter.prototype.onprocess = function(event){
Tone.Meter.prototype.onprocess = function(event){
var bufferSize = this.jsNode.bufferSize;
for (var channel = 0; channel < this.channels; channel++){
var input = event.inputBuffer.getChannelData(channel);

View file

@ -5,9 +5,9 @@
///////////////////////////////////////////////////////////////////////////////
//@param {number=} inputNum
AudioUnit.Microphone = function(inputNum){
Tone.Microphone = function(inputNum){
//extend the base class
AudioUnit.call(this);
Tone.call(this);
//components
this.mediaStream = null;
@ -24,23 +24,23 @@ AudioUnit.Microphone = function(inputNum){
});
}
AudioUnit.extend(AudioUnit.Microphone, AudioUnit);
Tone.extend(Tone.Microphone, Tone);
//stop the WebRTC connection
AudioUnit.Microphone.prototype.start = function(){
Tone.Microphone.prototype.start = function(){
// Only get the audio stream.
navigator.getUserMedia(this.constraints, this._onStream.bind(this), this._onStreamError.bind(this));
}
//stop the WebRTC connection
AudioUnit.Microphone.prototype.stop = function(){
Tone.Microphone.prototype.stop = function(){
if (this.stream){
this.stream.stop();
}
}
//when the stream is setup
AudioUnit.Microphone.prototype._onStream = function(stream) {
Tone.Microphone.prototype._onStream = function(stream) {
this.stream = stream;
// Wrap a MediaStreamSourceNode around the live input stream.
this.mediaStream = this.context.createMediaStreamSource(stream);
@ -48,7 +48,7 @@ AudioUnit.Microphone.prototype._onStream = function(stream) {
};
//on error
AudioUnit.Microphone.prototype._onStreamError = function(e) {
Tone.Microphone.prototype._onStreamError = function(e) {
console.error(e);
};

View file

@ -5,9 +5,9 @@
///////////////////////////////////////////////////////////////////////////////
//@param {string} type the noise type
AudioUnit.Noise = function(type){
Tone.Noise = function(type){
//extend Unit
AudioUnit.call(this);
Tone.call(this);
//components
this.jsNode = this.context.createScriptProcessor(this.bufferSize, 1, 1);
@ -20,10 +20,10 @@ AudioUnit.Noise = function(type){
this.setType(this.defaultArg(type, "white"));
}
AudioUnit.extend(AudioUnit.Noise, AudioUnit);
Tone.extend(Tone.Noise, Tone);
//@param {string} type ('white', 'pink', 'brown')
AudioUnit.Noise.prototype.setType = function(type){
Tone.Noise.prototype.setType = function(type){
switch (type){
case "white" :
this.jsNode.onaudioprocess = this._whiteNoise.bind(this);
@ -40,7 +40,7 @@ AudioUnit.Noise.prototype.setType = function(type){
}
//modified from http://noisehack.com/generate-noise-web-audio-api/
AudioUnit.Noise.prototype._pinkNoise = (function() {
Tone.Noise.prototype._pinkNoise = (function() {
var b0, b1, b2, b3, b4, b5, b6;
b0 = b1 = b2 = b3 = b4 = b5 = b6 = 0.0;
return function(e) {
@ -62,7 +62,7 @@ AudioUnit.Noise.prototype._pinkNoise = (function() {
})();
//modified from http://noisehack.com/generate-noise-web-audio-api/
AudioUnit.Noise.prototype._brownNoise = (function() {
Tone.Noise.prototype._brownNoise = (function() {
var lastOut = 0.0;
return function(e) {
var bufferSize = this.jsNode.bufferSize;
@ -78,7 +78,7 @@ AudioUnit.Noise.prototype._brownNoise = (function() {
})();
//modified from http://noisehack.com/generate-noise-web-audio-api/
AudioUnit.Noise.prototype._whiteNoise = function(e){
Tone.Noise.prototype._whiteNoise = function(e){
var bufferSize = this.jsNode.bufferSize;
var output = e.outputBuffer.getChannelData(0);
for (var i = 0; i < bufferSize; i++) {

View file

@ -4,9 +4,9 @@
//
///////////////////////////////////////////////////////////////////////////////
AudioUnit.Player = function(url){
Tone.Player = function(url){
//extend Unit
AudioUnit.call(this);
Tone.call(this);
//player vars
this.url = url;
@ -14,12 +14,12 @@ AudioUnit.Player = function(url){
this.buffer = null;
}
AudioUnit.extend(AudioUnit.Player, AudioUnit);
Tone.extend(Tone.Player, Tone);
//makes an xhr for the buffer at the url
//invokes the callback at the end
//@param {function(AudioUnit.Player)} callback
AudioUnit.Player.prototype.load = function(callback){
//@param {function(Tone.Player)} callback
Tone.Player.prototype.load = function(callback){
var request = new XMLHttpRequest();
request.open('GET', this.url, true);
request.responseType = 'arraybuffer';
@ -38,7 +38,7 @@ AudioUnit.Player.prototype.load = function(callback){
}
//play the buffer from start to finish at a time
AudioUnit.Player.prototype.start = function(startTime, offset, duration){
Tone.Player.prototype.start = function(startTime, offset, duration){
if (this.buffer){
//default args
startTime = this.defaultArg(startTime, this.now());
@ -54,7 +54,7 @@ AudioUnit.Player.prototype.start = function(startTime, offset, duration){
}
//play the buffer from start to finish at a time
AudioUnit.Player.prototype.loop = function(startTime, loopStart, loopEnd, offset, duration){
Tone.Player.prototype.loop = function(startTime, loopStart, loopEnd, offset, duration){
if (this.buffer){
//default args
startTime = this.defaultArg(startTime, this.now());
@ -74,7 +74,7 @@ AudioUnit.Player.prototype.loop = function(startTime, loopStart, loopEnd, offset
}
//stop playback
AudioUnit.Player.prototype.stop = function(stopTime){
Tone.Player.prototype.stop = function(stopTime){
if (this.buffer){
stopTime = this.defaultArg(stopTime, this.now());
this.source.stop(stopTime);
@ -82,7 +82,7 @@ AudioUnit.Player.prototype.stop = function(stopTime){
}
//@returns {number} the buffer duration
AudioUnit.Player.prototype.getDuration = function(){
Tone.Player.prototype.getDuration = function(){
if (this.buffer){
this.buffer.duration;
} else {

View file

@ -6,9 +6,9 @@
///////////////////////////////////////////////////////////////////////////////
AudioUnit.StereoSplit = function(){
Tone.StereoSplit = function(){
//extends Unit
AudioUnit.call(this);
Tone.call(this);
this.merger = this.context.createChannelMerger(2);
this.leftSend = this.context.createGain();
@ -24,12 +24,12 @@ AudioUnit.StereoSplit = function(){
this.merger.connect(this.output);
}
AudioUnit.extend(AudioUnit.StereoSplit, AudioUnit);
Tone.extend(Tone.StereoSplit, Tone);
AudioUnit.StereoSplit.prototype.connectLeft = function(unit){
Tone.StereoSplit.prototype.connectLeft = function(unit){
this.chain(this.leftSend, unit, this.leftReturn);
}
AudioUnit.StereoSplit.prototype.connectRight = function(unit){
Tone.StereoSplit.prototype.connectRight = function(unit){
this.chain(this.rightSend, unit, this.rightReturn);
}

View file

@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////
//
// AUDIO UNIT
// TONE
//
///////////////////////////////////////////////////////////////////////////////
@ -42,11 +42,11 @@
}
///////////////////////////////////////////////////////////////////////////
// AUDIO UNIT
// TONE
// @constructor
///////////////////////////////////////////////////////////////////////////
var AudioUnit = function(){
var Tone = function(){
this.input = audioContext.createGain();
this.output = audioContext.createGain();
}
@ -55,33 +55,33 @@
// CLASS VARS
///////////////////////////////////////////////////////////////////////////
AudioUnit.prototype.context = audioContext;
AudioUnit.prototype.fadeTime = .005; //5ms
AudioUnit.prototype.bufferSize = 1024; //default buffer size
Tone.prototype.context = audioContext;
Tone.prototype.fadeTime = .005; //5ms
Tone.prototype.bufferSize = 1024; //default buffer size
///////////////////////////////////////////////////////////////////////////
// CLASS METHODS
///////////////////////////////////////////////////////////////////////////
//@returns {number} the currentTime from the AudioContext
AudioUnit.prototype.now = function(){
Tone.prototype.now = function(){
return audioContext.currentTime;
}
//@param {AudioParam | AudioUnit} unit
AudioUnit.prototype.connect = function(unit){
//@param {AudioParam | Tone} unit
Tone.prototype.connect = function(unit){
this._connect(this, unit);
}
//disconnect the output
AudioUnit.prototype.disconnect = function(){
Tone.prototype.disconnect = function(){
this.output.disconnect();
}
//@private internal connect
//@param {AudioNode|AudioUnit} A
//@param {AudioNode|AudioUnit} B
AudioUnit.prototype._connect = function(A, B){
//@param {AudioNode|Tone} A
//@param {AudioNode|Tone} B
Tone.prototype._connect = function(A, B){
var compA = A;
if (A.output && A.output instanceof GainNode){
compA = A.output;
@ -94,8 +94,8 @@
}
//connect together an array of units in series
//@param {...AudioParam | AudioUnit} units
AudioUnit.prototype.chain = function(){
//@param {...AudioParam | Tone} units
Tone.prototype.chain = function(){
if (arguments.length > 1){
var currentUnit = arguments[0];
for (var i = 1; i < arguments.length; i++){
@ -108,14 +108,14 @@
//set the output volume
//@param {number} vol
AudioUnit.prototype.setVolume = function(vol){
Tone.prototype.setVolume = function(vol){
this.output.gain.value = vol;
}
//fade the output volume
//@param {number} value
//@param {number=} duration (in seconds)
AudioUnit.prototype.fadeTo = function(value, duration){
Tone.prototype.fadeTo = function(value, duration){
this.defaultArg(duration, this.fadeTime);
this.rampToValue(this.output.gain, value, duration);
}
@ -129,7 +129,7 @@
//@param {AudioParam} audioParam
//@param {number} value
//@param {number=} duration (in seconds)
AudioUnit.prototype.rampToValue = function(audioParam, value, duration){
Tone.prototype.rampToValue = function(audioParam, value, duration){
var currentValue = audioParam.value;
var now = this.now();
duration = this.defaultArg(duration, this.fadeTime);
@ -141,7 +141,7 @@
//@param {AudioParam} audioParam
//@param {number} value
//@param {number=} duration (in seconds)
AudioUnit.prototype.exponentialRampToValue = function(audioParam, value, duration){
Tone.prototype.exponentialRampToValue = function(audioParam, value, duration){
var currentValue = audioParam.value;
var now = this.now();
audioParam.setValueAtTime(currentValue, now);
@ -152,48 +152,48 @@
//@param {*} given
//@param {*} fallback
//@returns {*}
AudioUnit.prototype.defaultArg = function(given, fallback){
Tone.prototype.defaultArg = function(given, fallback){
return typeof(given) !== 'undefined' ? given : fallback;
}
//@param {number} percent (0-1)
//@returns {number} the equal power gain
//good for cross fades
AudioUnit.prototype.equalPowerGain = function(percent){
Tone.prototype.equalPowerGain = function(percent){
return Math.sin((percent) * 0.5*Math.PI);
}
//@param {number} db
//@returns {number} gain
AudioUnit.prototype.dbToGain = function(db) {
Tone.prototype.dbToGain = function(db) {
return Math.pow(2, db / 6);
}
//@param {number} gain
//@returns {number} db
AudioUnit.prototype.gainToDb = function(gain) {
Tone.prototype.gainToDb = function(gain) {
return 20 * (Math.log(gain) / Math.LN10);
}
//@param {number} gain
//@returns {number} gain (decibel scale but betwee 0-1)
AudioUnit.prototype.gainToLogScale = function(gain) {
Tone.prototype.gainToLogScale = function(gain) {
return Math.max(this.normalize(this.gainToDb(gain), -100, 0), 0);
}
//@param {number} gain
//@returns {number} gain (decibel scale but betwee 0-1)
AudioUnit.prototype.gainToPowScale = function(gain) {
Tone.prototype.gainToPowScale = function(gain) {
return this.dbToGain(this.interpolate(gain, -100, 0));
}
//@param {number} input 0-1
AudioUnit.prototype.interpolate = function(input, outputMin, outputMax){
Tone.prototype.interpolate = function(input, outputMin, outputMax){
return input*(outputMax - outputMin) + outputMin;
}
//@returns {number} 0-1
AudioUnit.prototype.normalize = function(input, inputMin, inputMax){
Tone.prototype.normalize = function(input, inputMin, inputMax){
//make sure that min < max
if (inputMin > inputMax){
var tmp = inputMax;
@ -205,19 +205,24 @@
return (input - inputMin) / (inputMax - inputMin);
}
//@param {AudioParam|AudioUnit=} unit
AudioUnit.prototype.toMaster = function(unit){
//@param {AudioParam|Tone=} unit
Tone.prototype.toMaster = function(unit){
unit = this.defaultArg(unit, this.output);
this._connect(unit, AudioUnit.Master);
this._connect(unit, Tone.Master);
}
///////////////////////////////////////////////////////////////////////////
// MUSICAL TIMING
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// STATIC METHODS
///////////////////////////////////////////////////////////////////////////
//based on closure library 'inherit' function
AudioUnit.extend = function(child, parent){
Tone.extend = function(child, parent){
/** @constructor */
function tempConstructor() {};
tempConstructor.prototype = parent.prototype;
@ -232,7 +237,7 @@
var Master = function(){
//extend audio unit
AudioUnit.call(this);
Tone.call(this);
//put a hard limiter on the output so we don't blow any eardrums
this.limiter = this.context.createDynamicsCompressor();
@ -240,10 +245,10 @@
this.limiter.ratio.value = 20;
this.chain(this.input, this.limiter, this.output, this.context.destination);
}
AudioUnit.extend(Master, AudioUnit);
AudioUnit.Master = new Master();
Tone.extend(Master, Tone);
Tone.Master = new Master();
//make it global
global.AudioUnit = AudioUnit;
global.Tone = Tone;
})(window);

View file

@ -6,9 +6,9 @@
///////////////////////////////////////////////////////////////////////////////
AudioUnit.Effect = function(){
Tone.Effect = function(){
//extends Unit
AudioUnit.call(this);
Tone.call(this);
//components
this.dry = this.context.createGain();
@ -25,11 +25,11 @@ AudioUnit.Effect = function(){
this.setDry(.5);
}
AudioUnit.extend(AudioUnit.Effect, AudioUnit);
Tone.extend(Tone.Effect, Tone);
//adjust the dry/wet balance
//dryness 0-1
AudioUnit.Effect.prototype.setDry = function(dryness, duration){
Tone.Effect.prototype.setDry = function(dryness, duration){
duration = this.defaultArg(duration, this.fadeTime);
var dryGain = this.equalPowerGain(dryness);
var wetGain = this.equalPowerGain(1 - dryness);
@ -38,14 +38,14 @@ AudioUnit.Effect.prototype.setDry = function(dryness, duration){
}
//adjust the wet/dry balance
AudioUnit.Effect.prototype.setWet = function(wetness, duration){
Tone.Effect.prototype.setWet = function(wetness, duration){
this.setDry(1 - wetness);
}
AudioUnit.Effect.prototype.bypass = function(){
Tone.Effect.prototype.bypass = function(){
this.setDry(1);
}
AudioUnit.Effect.prototype.connectEffect = function(effect){
Tone.Effect.prototype.connectEffect = function(effect){
this.chain(this.effectSend, effect, this.effectReturn);
}

View file

@ -5,8 +5,8 @@
///////////////////////////////////////////////////////////////////////////////
//@param {number} delayTime
AudioUnit.FeedbackDelay = function(delayTime){
AudioUnit.FeedbackEffect.call(this);
Tone.FeedbackDelay = function(delayTime){
Tone.FeedbackEffect.call(this);
this.delay = this.context.createDelay(4);
this.delay.delayTime.value = this.defaultArg(delayTime, .25);
@ -15,8 +15,8 @@ AudioUnit.FeedbackDelay = function(delayTime){
this.connectEffect(this.delay);
}
AudioUnit.extend(AudioUnit.FeedbackDelay, AudioUnit.FeedbackEffect);
Tone.extend(Tone.FeedbackDelay, Tone.FeedbackEffect);
AudioUnit.FeedbackDelay.prototype.setDelayTime = function(delayTime){
Tone.FeedbackDelay.prototype.setDelayTime = function(delayTime){
this.rampToValue(this.delay.delayTime, delayTime);
}

View file

@ -6,9 +6,9 @@
///////////////////////////////////////////////////////////////////////////////
AudioUnit.FeedbackEffect = function(){
Tone.FeedbackEffect = function(){
//extends Unit
AudioUnit.Effect.call(this);
Tone.Effect.call(this);
this.feedback = this.context.createGain();
//feedback loop
@ -18,9 +18,9 @@ AudioUnit.FeedbackEffect = function(){
this.setDry(.5);
}
AudioUnit.extend(AudioUnit.FeedbackEffect, AudioUnit.Effect);
Tone.extend(Tone.FeedbackEffect, Tone.Effect);
AudioUnit.Effect.prototype.setFeedback = function(fback){
Tone.Effect.prototype.setFeedback = function(fback){
this.rampToValue(this.feedback.gain, fback);
}

View file

@ -5,12 +5,12 @@
///////////////////////////////////////////////////////////////////////////////
//@param {number=} delayTime
AudioUnit.PingPongDelay = function(delayTime){
AudioUnit.StereoSplit.call(this);
Tone.PingPongDelay = function(delayTime){
Tone.StereoSplit.call(this);
//components
this.leftDelay = new AudioUnit.FeedbackDelay(delayTime);
this.rightDelay = new AudioUnit.FeedbackDelay(delayTime);
this.leftDelay = new Tone.FeedbackDelay(delayTime);
this.rightDelay = new Tone.FeedbackDelay(delayTime);
//connect it up
@ -28,28 +28,28 @@ AudioUnit.PingPongDelay = function(delayTime){
this.setDelayTime(delayTime);
}
AudioUnit.extend(AudioUnit.PingPongDelay, AudioUnit.StereoSplit);
Tone.extend(Tone.PingPongDelay, Tone.StereoSplit);
//@param {number} delayTime
AudioUnit.PingPongDelay.prototype.setDelayTime = function(delayTime){
Tone.PingPongDelay.prototype.setDelayTime = function(delayTime){
this.leftDelay.setDelayTime(delayTime);
this.rightDelay.setDelayTime(delayTime * 2);
}
//@param {number} feedback (0 - 1)
AudioUnit.PingPongDelay.prototype.setFeedback = function(feedback){
Tone.PingPongDelay.prototype.setFeedback = function(feedback){
this.leftDelay.setFeedback(feedback);
this.rightDelay.setFeedback(feedback);
}
//@param {number} wet (0 - 1)
AudioUnit.PingPongDelay.prototype.setWet = function(wet){
Tone.PingPongDelay.prototype.setWet = function(wet){
this.leftDelay.setWet(wet);
this.rightDelay.setWet(wet);
}
//@param {number} dry (0 - 1)
AudioUnit.PingPongDelay.prototype.setDry = function(dry){
Tone.PingPongDelay.prototype.setDry = function(dry){
this.leftDelay.setDry(dry);
this.rightDelay.setDry(dry);
}