Permalink
Browse files

Update build

  • Loading branch information...
1 parent d5712d9 commit 631198cdbce8e146f4811d33dec4c31da7229bea @oampo oampo committed Jun 29, 2012
Showing with 295 additions and 118 deletions.
  1. +294 −117 src/audiolet/Audiolet.js
  2. +1 −1 src/audiolet/Audiolet.min.js
View
411 src/audiolet/Audiolet.js
@@ -5634,7 +5634,7 @@ var EqualTemperamentTuning = function(pitchesPerOctave) {
};
extend(EqualTemperamentTuning, Tuning);
-var Sink = this.Sink = (function(global){
+var Sink = this.Sink = function (global) {
/**
* Creates a Sink according to specified parameters, if possible.
@@ -5658,12 +5658,12 @@ var Sink = this.Sink = (function(global){
* @param {Number} default=0 ringOffset The current position of the ring buffer.
*/
function Sink (readFn, channelCount, bufferSize, sampleRate) {
- var sinks = Sink.sinks,
- dev;
- for (dev in sinks){
- if (sinks.hasOwnProperty(dev) && sinks[dev].enabled){
- try{
- return new sinks[dev](readFn, channelCount, bufferSize, sampleRate);
+ var sinks = Sink.sinks.list,
+ i;
+ for (i=0; i<sinks.length; i++) {
+ if (sinks[i].enabled) {
+ try {
+ return new sinks[i](readFn, channelCount, bufferSize, sampleRate);
} catch(e1){}
}
}
@@ -5686,6 +5686,7 @@ SinkClass.prototype = Sink.prototype = {
ringOffset: 0,
channelMode: 'interleaved',
+ isReady: false,
/**
* Does the initialization of the sink.
@@ -5697,7 +5698,7 @@ SinkClass.prototype = Sink.prototype = {
this.sampleRate = isNaN(sampleRate) || sampleRate === null ? this.sampleRate : sampleRate;
this.readFn = readFn;
this.activeRecordings = [];
- this.previousHit = +new Date;
+ this.previousHit = +new Date();
Sink.EventEmitter.call(this);
Sink.emit('init', [this].concat([].slice.call(arguments)));
},
@@ -5707,19 +5708,30 @@ SinkClass.prototype = Sink.prototype = {
*/
process: function (soundData, channelCount) {
this.emit('preprocess', arguments);
- this.ringBuffer && (this.channelMode === 'interleaved' ? this.ringSpin : this.ringSpinInterleaved).apply(this, arguments);
+
+ if (this.ringBuffer) {
+ (this.channelMode === 'interleaved' ? this.ringSpin : this.ringSpinInterleaved).apply(this, arguments);
+ }
+
if (this.channelMode === 'interleaved') {
this.emit('audioprocess', arguments);
- this.readFn && this.readFn.apply(this, arguments);
+
+ if (this.readFn) {
+ this.readFn.apply(this, arguments);
+ }
} else {
var soundDataSplit = Sink.deinterleave(soundData, this.channelCount),
args = [soundDataSplit].concat([].slice.call(arguments, 1));
this.emit('audioprocess', args);
- this.readFn && this.readFn.apply(this, args);
+
+ if (this.readFn) {
+ this.readFn.apply(this, args);
+ }
+
Sink.interleave(soundDataSplit, this.channelCount, soundData);
}
this.emit('postprocess', arguments);
- this.previousHit = +new Date;
+ this.previousHit = +new Date();
this.writePosition += soundData.length / channelCount;
},
/**
@@ -5732,6 +5744,16 @@ SinkClass.prototype = Sink.prototype = {
getPlaybackTime: function () {
return this.writePosition - this.bufferSize;
},
+/**
+ * Internal method to send the ready signal if not ready yet.
+ * @method Sink
+*/
+ ready: function () {
+ if (this.isReady) return;
+
+ this.isReady = true;
+ this.emit('ready', []);
+ }
};
/**
@@ -5746,20 +5768,25 @@ SinkClass.prototype = Sink.prototype = {
* @arg {Boolean} disabled Whether the Sink should be disabled at first.
*/
-function sinks (type, constructor, prototype, disabled) {
+function sinks (type, constructor, prototype, disabled, priority) {
prototype = prototype || constructor.prototype;
constructor.prototype = new Sink.SinkClass();
constructor.prototype.type = type;
constructor.enabled = !disabled;
- for (disabled in prototype) {
- if (prototype.hasOwnProperty(disabled)) {
- constructor.prototype[disabled] = prototype[disabled];
+
+ var k;
+ for (k in prototype) {
+ if (prototype.hasOwnProperty(k)) {
+ constructor.prototype[k] = prototype[k];
}
}
+
sinks[type] = constructor;
+ sinks.list[priority ? 'unshift' : 'push'](constructor);
}
Sink.sinks = Sink.devices = sinks;
+Sink.sinks.list = [];
Sink.singleton = function () {
var sink = Sink.apply(null, arguments);
@@ -5775,8 +5802,8 @@ global.Sink = Sink;
return Sink;
-}(function (){ return this; }()));
-(function (Sink) {
+}(function (){ return this; }());
+void function (Sink) {
/**
* A light event emitter.
@@ -5792,7 +5819,7 @@ function EventEmitter () {
}
}
this._listeners = {};
-};
+}
EventEmitter.prototype = {
_listeners: null,
@@ -5839,23 +5866,27 @@ EventEmitter.prototype = {
delete this._listeners[name];
return this;
}
+
for (var i=0; i<this._listeners[name].length; i++) {
if (this._listeners[name][i] === listener) {
this._listeners[name].splice(i--, 1);
}
}
- this._listeners[name].length || delete this._listeners[name];
+
+ if (!this._listeners[name].length) {
+ delete this._listeners[name];
+ }
}
return this;
- },
+ }
};
Sink.EventEmitter = EventEmitter;
EventEmitter.call(Sink);
-}(this.Sink));
-(function (Sink) {
+}(this.Sink);
+void function (Sink) {
/**
* Creates a timer with consistent (ie. not clamped) intervals even in background tabs.
@@ -5890,23 +5921,101 @@ Sink.doInterval = function (callback, timeout) {
}
}
- Sink.inlineWorker.ready ? create() : Sink.inlineWorker.on('ready', function () {
+ if (Sink.inlineWorker.ready) {
create();
- });
+ } else {
+ Sink.inlineWorker.on('ready', function () {
+ create();
+ });
+ }
return function () {
if (!kill) {
- Sink.inlineWorker.ready || Sink.inlineWorker.on('ready', function () {
- kill && kill();
- });
+ if (!Sink.inlineWorker.ready) {
+ Sink.inlineWorker.on('ready', function () {
+ if (kill) kill();
+ });
+ }
} else {
kill();
}
};
};
-}(this.Sink));
-(function (Sink) {
+}(this.Sink);
+void function (Sink) {
+
+var _Blob, _BlobBuilder, _URL, _btoa;
+
+void function (prefixes, urlPrefixes) {
+ function find (name, prefixes) {
+ var b, a = prefixes.slice();
+
+ for (b=a.shift(); typeof b !== 'undefined'; b=a.shift()) {
+ b = Function('return typeof ' + b + name +
+ '=== "undefined" ? undefined : ' +
+ b + name)();
+
+ if (b) return b;
+ }
+ }
+
+ _Blob = find('Blob', prefixes);
+ _BlobBuilder = find('BlobBuilder', prefixes);
+ _URL = find('URL', urlPrefixes);
+ _btoa = find('btoa', ['']);
+}([
+ '',
+ 'Moz',
+ 'WebKit',
+ 'MS'
+], [
+ '',
+ 'webkit'
+]);
+
+var createBlob = _Blob && _URL && function (content, type) {
+ return _URL.createObjectURL(new _Blob([content], { type: type }));
+};
+
+var createBlobBuilder = _BlobBuilder && _URL && function (content, type) {
+ var bb = new _BlobBuilder();
+ bb.append(content);
+
+ return _URL.createObjectURL(bb.getBlob(type));
+};
+
+var createData = _btoa && function (content, type) {
+ return 'data:' + type + ';base64,' + _btoa(content);
+};
+
+var createDynURL =
+ createBlob ||
+ createBlobBuilder ||
+ createData;
+
+if (!createDynURL) return;
+
+if (createBlob) createDynURL.createBlob = createBlob;
+if (createBlobBuilder) createDynURL.createBlobBuilder = createBlobBuilder;
+if (createData) createDynURL.createData = createData;
+
+if (_Blob) createDynURL.Blob = _Blob;
+if (_BlobBuilder) createDynURL.BlobBuilder = _BlobBuilder;
+if (_URL) createDynURL.URL = _URL;
+
+Sink.createDynURL = createDynURL;
+
+Sink.revokeDynURL = function (url) {
+ if (typeof url === 'string' && url.indexOf('data:') === 0) {
+ return false;
+ } else {
+ return _URL.revokeObjectURL(url);
+ }
+};
+
+}(this.Sink);
+void function (Sink) {
/*
* A Sink-specific error class.
@@ -5944,34 +6053,30 @@ SinkError.prototype.toString = function () {
SinkError[0x01] = {
message: 'No such error code.',
- explanation: 'The error code does not exist.',
+ explanation: 'The error code does not exist.'
};
SinkError[0x02] = {
message: 'No audio sink available.',
- explanation: 'The audio device may be busy, or no supported output API is available for this browser.',
+ explanation: 'The audio device may be busy, or no supported output API is available for this browser.'
};
SinkError[0x10] = {
message: 'Buffer underflow.',
- explanation: 'Trying to recover...',
+ explanation: 'Trying to recover...'
};
SinkError[0x11] = {
message: 'Critical recovery fail.',
- explanation: 'The buffer underflow has reached a critical point, trying to recover, but will probably fail anyway.',
+ explanation: 'The buffer underflow has reached a critical point, trying to recover, but will probably fail anyway.'
};
SinkError[0x12] = {
message: 'Buffer size too large.',
- explanation: 'Unable to allocate the buffer due to excessive length, please try a smaller buffer. Buffer size should probably be smaller than the sample rate.',
+ explanation: 'Unable to allocate the buffer due to excessive length, please try a smaller buffer. Buffer size should probably be smaller than the sample rate.'
};
Sink.Error = SinkError;
-}(this.Sink));
-(function (Sink) {
-
-var BlobBuilder = typeof window === 'undefined' ? undefined :
- window.MozBlobBuilder || window.WebKitBlobBuilder || window.MSBlobBuilder || window.OBlobBuilder || window.BlobBuilder,
- URL = typeof window === 'undefined' ? undefined : (window.MozURL || window.webkitURL || window.MSURL || window.OURL || window.URL);
+}(this.Sink);
+void function (Sink) {
/**
* Creates an inline worker using a data/blob URL, if possible.
@@ -5983,67 +6088,101 @@ var BlobBuilder = typeof window === 'undefined' ? undefined :
* @return {Worker} A web worker, or null if impossible to create.
*/
+var define = Object.defineProperty ? function (obj, name, value) {
+ Object.defineProperty(obj, name, {
+ value: value,
+ configurable: true,
+ writable: true
+ });
+} : function (obj, name, value) {
+ obj[name] = value;
+};
+
+function terminate () {
+ define(this, 'terminate', this._terminate);
+
+ Sink.revokeDynURL(this._url);
+
+ delete this._url;
+ delete this._terminate;
+ return this.terminate();
+}
+
function inlineWorker (script) {
- var worker = null,
- url, bb;
- try {
- bb = new BlobBuilder();
- bb.append(script);
- url = URL.createObjectURL(bb.getBlob());
- worker = new Worker(url);
-
- worker._terminate = worker.terminate;
- worker._url = url;
- bb = null;
-
- worker.terminate = function () {
- this._terminate;
- URL.revokeObjectURL(this._url);
- };
+ function wrap (type, content, typeName) {
+ try {
+ var url = type(content, 'text/javascript');
+ var worker = new Worker(url);
- inlineWorker.type = 'blob';
+ define(worker, '_url', url);
+ define(worker, '_terminate', worker.terminate);
+ define(worker, 'terminate', terminate);
- return worker;
+ if (inlineWorker.type) return worker;
- } catch (e) {}
+ inlineWorker.type = typeName;
+ inlineWorker.createURL = type;
- try {
- worker = new Worker('data:text/javascript;base64,' + btoa(script));
- inlineWorker.type = 'data';
+ return worker;
+ } catch (e) {
+ return null;
+ }
+ }
- return worker;
+ var createDynURL = Sink.createDynURL;
+ var worker;
- } catch (e) {}
+ if (inlineWorker.createURL) {
+ return wrap(inlineWorker.createURL, script, inlineWorker.type);
+ }
+
+ worker = wrap(createDynURL.createBlob, script, 'blob');
+ if (worker) return worker;
+
+ worker = wrap(createDynURL.createBlobBuilder, script, 'blobbuilder');
+ if (worker) return worker;
+
+ worker = wrap(createDynURL.createData, script, 'data');
return worker;
}
-inlineWorker.ready = inlineWorker.working = false;
-
Sink.EventEmitter.call(inlineWorker);
inlineWorker.test = function () {
- var worker = inlineWorker('this.onmessage=function (e){postMessage(e.data)}'),
- data = 'inlineWorker';
inlineWorker.ready = inlineWorker.working = false;
+ inlineWorker.type = '';
+ inlineWorker.createURL = null;
+
+ var worker = inlineWorker('this.onmessage=function(e){postMessage(e.data)}');
+ var data = 'inlineWorker';
function ready (success) {
if (inlineWorker.ready) return;
- inlineWorker.ready = true;
- inlineWorker.working = success;
+
+ inlineWorker.ready = true;
+ inlineWorker.working = success;
inlineWorker.emit('ready', [success]);
inlineWorker.off('ready');
- success && worker && worker.terminate();
+
+ if (success && worker) {
+ worker.terminate();
+ }
+
worker = null;
}
if (!worker) {
- ready(false);
+ setTimeout(function () {
+ ready(false);
+ }, 0);
} else {
worker.onmessage = function (e) {
ready(e.data === data);
};
+
worker.postMessage(data);
+
setTimeout(function () {
ready(false);
}, 1000);
@@ -6054,8 +6193,8 @@ Sink.inlineWorker = inlineWorker;
inlineWorker.test();
-}(this.Sink));
-(function (Sink) {
+}(this.Sink);
+void function (Sink) {
/**
* A Sink class for the Mozilla Audio Data API.
@@ -6072,7 +6211,7 @@ Sink.sinks('audiodata', function () {
self.preBufferSize = isNaN(arguments[4]) || arguments[4] === null ? this.preBufferSize : arguments[4];
function bufferFill() {
- if (tail){
+ if (tail) {
written = audioDevice.mozWriteAudio(tail);
currentWritePosition += written;
if (written < tail.length){
@@ -6084,8 +6223,14 @@ Sink.sinks('audiodata', function () {
currentPosition = audioDevice.mozCurrentSampleOffset();
available = Number(currentPosition + (prevPos !== currentPosition ? self.bufferSize : self.preBufferSize) * self.channelCount - currentWritePosition);
- currentPosition === prevPos && self.emit('error', [Sink.Error(0x10)]);
+
+ if (currentPosition === prevPos) {
+ self.emit('error', [Sink.Error(0x10)]);
+ }
+
if (available > 0 || prevPos === currentPosition){
+ self.ready();
+
try {
soundData = new Float32Array(prevPos === currentPosition ? self.preBufferSize * self.channelCount :
self.forceBufferSize ? available < self.bufferSize * 2 ? self.bufferSize * 2 : available : available);
@@ -6110,7 +6255,7 @@ Sink.sinks('audiodata', function () {
this._timers.push(Sink.doInterval(function () {
// Check for complete death of the output
- if (+new Date - self.previousHit > 2000) {
+ if (+new Date() - self.previousHit > 2000) {
self._audio = audioDevice = new Audio();
audioDevice.mozSetup(self.channelCount, self.sampleRate);
currentWritePosition = 0;
@@ -6127,30 +6272,32 @@ Sink.sinks('audiodata', function () {
bufferSize: 24576,
preBufferSize: 24576,
forceBufferSize: false,
- interval: 20,
+ interval: 100,
+
kill: function () {
- while(this._timers.length){
- this._timers[0]();
- this._timers.splice(0, 1);
+ while (this._timers.length) {
+ this._timers.shift()();
}
+
this.emit('kill');
},
+
getPlaybackTime: function () {
return this._audio.mozCurrentSampleOffset() / this.channelCount;
- },
-});
+ }
+}, false, true);
Sink.sinks.moz = Sink.sinks.audiodata;
-}(this.Sink));
-(function (Sink) {
+}(this.Sink);
+void function (Sink) {
/**
* A dummy Sink. (No output)
*/
Sink.sinks('dummy', function () {
- var self = this;
+ var self = this;
self.start.apply(self, arguments);
function bufferFill () {
@@ -6165,13 +6312,13 @@ Sink.sinks('dummy', function () {
kill: function () {
this._kill();
this.emit('kill');
- },
+ }
}, true);
-}(this.Sink));
+}(this.Sink);
(function (Sink, sinks) {
-var sinks = Sink.sinks;
+sinks = Sink.sinks;
function newAudio (src) {
var audio = document.createElement('audio');
@@ -6181,7 +6328,7 @@ function newAudio (src) {
return audio;
}
-/* TODO: Implement a <BGSOUND> hack for IE8.
+/* TODO: Implement a <BGSOUND> hack for IE8. */
/**
* A sink class for WAV data URLs
@@ -6190,7 +6337,7 @@ function newAudio (src) {
*/
sinks('wav', function () {
var self = this,
- audio = new sinks.wav.wavAudio,
+ audio = new sinks.wav.wavAudio(),
PCMData = typeof PCMData === 'undefined' ? audioLib.PCMData : PCMData;
self.start.apply(self, arguments);
var soundData = new Float32Array(self.bufferSize * self.channelCount),
@@ -6200,6 +6347,9 @@ sinks('wav', function () {
function bufferFill () {
if (self._audio.hasNextFrame) return;
+
+ self.ready();
+
Sink.memcpy(zeroData, 0, soundData, 0);
self.process(soundData, self.channelCount);
@@ -6208,7 +6358,7 @@ sinks('wav', function () {
data: soundData,
sampleRate: self.sampleRate,
channelCount: self.channelCount,
- bytesPerSample: self.quality,
+ bytesPerSample: self.quality
})
));
@@ -6225,7 +6375,7 @@ sinks('wav', function () {
getPlaybackTime: function () {
var audio = this._audio;
return (audio.currentFrame ? audio.currentFrame.currentTime * this.sampleRate : 0) + audio.samples;
- },
+ }
});
function wavAudio () {
@@ -6260,13 +6410,15 @@ wavAudio.prototype = {
this.nextFrame.addEventListener('ended', this._onended, true);
this.hasNextFrame = true;
- },
+ }
};
sinks.wav.wavAudio = wavAudio;
}(this.Sink));
-(function (sinks, fixChrome82795) {
+ (function (sinks, fixChrome82795) {
+
+var AudioContext = typeof window === 'undefined' ? null : window.webkitAudioContext || window.AudioContext;
/**
* A sink class for the Web Audio API
@@ -6275,10 +6427,11 @@ sinks.wav.wavAudio = wavAudio;
sinks('webaudio', function (readFn, channelCount, bufferSize, sampleRate) {
var self = this,
context = sinks.webaudio.getContext(),
- node = context.createJavaScriptNode(bufferSize, 0, channelCount),
+ node = null,
soundData = null,
zeroBuffer = null;
self.start.apply(self, arguments);
+ node = context.createJavaScriptNode(self.bufferSize, 0, self.channelCount);
function bufferFill(e) {
var outputBuffer = e.outputBuffer,
@@ -6287,6 +6440,8 @@ sinks('webaudio', function (readFn, channelCount, bufferSize, sampleRate) {
size = outputBuffer.size,
channels = new Array(channelCount),
tail;
+
+ self.ready();
soundData = soundData && soundData.length === l * channelCount ? soundData : new Float32Array(l * channelCount);
zeroBuffer = zeroBuffer && zeroBuffer.length === soundData.length ? zeroBuffer : new Float32Array(l * channelCount);
@@ -6319,24 +6474,29 @@ sinks('webaudio', function (readFn, channelCount, bufferSize, sampleRate) {
}, {
kill: function () {
this._node.disconnect(0);
+
for (var i=0; i<fixChrome82795.length; i++) {
- fixChrome82795[i] === this._node && fixChrome82795.splice(i--, 1);
+ if (fixChrome82795[i] === this._node) {
+ fixChrome82795.splice(i--, 1);
+ }
}
+
this._node = this._context = null;
this.emit('kill');
},
+
getPlaybackTime: function () {
return this._context.currentTime * this.sampleRate;
- },
-});
+ }
+}, false, true);
sinks.webkit = sinks.webaudio;
sinks.webaudio.fix82795 = fixChrome82795;
sinks.webaudio.getContext = function () {
// For now, we have to accept that the AudioContext is at 48000Hz, or whatever it decides.
- var context = new (window.AudioContext || webkitAudioContext)(/*sampleRate*/);
+ var context = new AudioContext(/*sampleRate*/);
sinks.webaudio.getContext = function () {
return context;
@@ -6365,7 +6525,11 @@ Sink.sinks('worker', function () {
importScripts();
function mspBufferFill (e) {
- self.ready || self.initMSP(e);
+ if (!self.isReady) {
+ self.initMSP(e);
+ }
+
+ self.ready();
var channelCount = self.channelCount,
l = e.audioLength,
@@ -6390,7 +6554,11 @@ Sink.sinks('worker', function () {
}
function waBufferFill(e) {
- self.ready || self.initWA(e);
+ if (!self.isReady) {
+ self.initWA(e);
+ }
+
+ self.ready();
var outputBuffer = e.outputBuffer,
channelCount = outputBuffer.numberOfChannels,
@@ -6440,7 +6608,7 @@ Sink.sinks('worker', function () {
this.bufferSize = b.length * this.channelCount;
this.ready = true;
this.emit('ready', []);
- },
+ }
});
}(this.Sink));
@@ -6669,10 +6837,15 @@ Proxy.prototype = {
},
process: function (buffer, channelCount) {
- this.offset === null && this.loadBuffer();
+ if (this.offset === null) {
+ this.loadBuffer();
+ }
for (var i=0; i<buffer.length; i++) {
- this.offset >= this.buffer.length && this.loadBuffer();
+ if (this.offset >= this.buffer.length) {
+ this.loadBuffer();
+ }
+
buffer[i] = this.buffer[this.offset++];
}
},
@@ -6681,7 +6854,7 @@ Proxy.prototype = {
this.offset = 0;
Sink.memcpy(this.zeroBuffer, 0, this.buffer, 0);
this.emit('audioprocess', [this.buffer, this.channelCount]);
- },
+ }
};
Sink.Proxy = Proxy;
@@ -6788,7 +6961,7 @@ Sink.resample = function (buffer, fromRate /* or speed */, fromFrequency /* or t
};
}(this.Sink));
-(function (Sink) {
+void function (Sink) {
Sink.on('init', function (sink) {
sink.activeRecordings = [];
@@ -6896,16 +7069,18 @@ Recording.prototype = {
bufPos += buffers[i].length;
}
return newArray;
- },
+ }
};
Sink.Recording = Recording;
-}(this.Sink));
-(function (Sink) {
+}(this.Sink);
+void function (Sink) {
function processRingBuffer () {
- this.ringBuffer && (this.channelMode === 'interleaved' ? this.ringSpin : this.ringSpinInterleaved).apply(this, arguments);
+ if (this.ringBuffer) {
+ (this.channelMode === 'interleaved' ? this.ringSpin : this.ringSpinInterleaved).apply(this, arguments);
+ }
}
Sink.on('init', function (sink) {
@@ -6960,8 +7135,8 @@ Sink.prototype.ringSpinDeinterleaved = function (buffer) {
this.ringOffset = n;
};
-}(this.Sink));
-(function (Sink, proto) {
+}(this.Sink);
+void function (Sink, proto) {
proto = Sink.prototype;
@@ -7000,7 +7175,9 @@ proto.writeBuffersAsync = function (buffer) {
buffer[n + offset] += buf.b[n];
}
buf.b = buf.b.subarray(n + offset);
- i >= bufLength && buffers.splice(i--, 1);
+ if (i >= bufLength) {
+ buffers.splice(i--, 1);
+ }
}
}
};
@@ -7047,7 +7224,7 @@ proto.writeBufferAsync = function (buffer, delay) {
var buffers = this.asyncBuffers;
buffers.push({
b: buffer,
- d: isNaN(delay) ? ~~((+new Date - this.previousHit) / 1000 * this.sampleRate) : delay
+ d: isNaN(delay) ? ~~((+new Date() - this.previousHit) / 1000 * this.sampleRate) : delay
});
return buffers.length;
};
@@ -7100,5 +7277,5 @@ proto.getSyncWriteOffset = function () {
return offset;
};
-} (this.Sink));
+} (this.Sink);
View
2 src/audiolet/Audiolet.min.js
@@ -249,4 +249,4 @@ var MinorScale=function(){Scale.call(this,[0,2,3,5,7,8,10])};extend(MinorScale,S
/*!
* @depends Tuning.js
*/
-var EqualTemperamentTuning=function(b){var c=[];for(var a=0;a<b;a++){c.push(a)}Tuning.call(this,c,2)};extend(EqualTemperamentTuning,Tuning);var Sink=this.Sink=(function(d){function c(j,h,l,g){var e=c.sinks,f;for(f in e){if(e.hasOwnProperty(f)&&e[f].enabled){try{return new e[f](j,h,l,g)}catch(k){}}}throw c.Error(2)}function b(){}c.SinkClass=b;b.prototype=c.prototype={sampleRate:44100,channelCount:2,bufferSize:4096,writePosition:0,previousHit:0,ringOffset:0,channelMode:"interleaved",start:function(g,f,h,e){this.channelCount=isNaN(f)||f===null?this.channelCount:f;this.bufferSize=isNaN(h)||h===null?this.bufferSize:h;this.sampleRate=isNaN(e)||e===null?this.sampleRate:e;this.readFn=g;this.activeRecordings=[];this.previousHit=+new Date;c.EventEmitter.call(this);c.emit("init",[this].concat([].slice.call(arguments)))},process:function(g,h){this.emit("preprocess",arguments);this.ringBuffer&&(this.channelMode==="interleaved"?this.ringSpin:this.ringSpinInterleaved).apply(this,arguments);if(this.channelMode==="interleaved"){this.emit("audioprocess",arguments);this.readFn&&this.readFn.apply(this,arguments)}else{var e=c.deinterleave(g,this.channelCount),f=[e].concat([].slice.call(arguments,1));this.emit("audioprocess",f);this.readFn&&this.readFn.apply(this,f);c.interleave(e,this.channelCount,g)}this.emit("postprocess",arguments);this.previousHit=+new Date;this.writePosition+=g.length/h},getPlaybackTime:function(){return this.writePosition-this.bufferSize},};function a(h,g,e,f){e=e||g.prototype;g.prototype=new c.SinkClass();g.prototype.type=h;g.enabled=!f;for(f in e){if(e.hasOwnProperty(f)){g.prototype[f]=e[f]}}a[h]=g}c.sinks=c.devices=a;c.singleton=function(){var e=c.apply(null,arguments);c.singleton=function(){return e};return e};d.Sink=c;return c}(function(){return this}()));(function(a){function b(){var c;for(c in b.prototype){if(b.prototype.hasOwnProperty(c)){this[c]=b.prototype[c]}}this._listeners={}}b.prototype={_listeners:null,emit:function(d,c){if(this._listeners[d]){for(var e=0;e<this._listeners[d].length;e++){this._listeners[d][e].apply(this,c)}}return this},on:function(c,d){this._listeners[c]=this._listeners[c]||[];this._listeners[c].push(d);return this},off:function(c,e){if(this._listeners[c]){if(!e){delete this._listeners[c];return this}for(var d=0;d<this._listeners[c].length;d++){if(this._listeners[c][d]===e){this._listeners[c].splice(d--,1)}}this._listeners[c].length||delete this._listeners[c]}return this},};a.EventEmitter=b;b.call(a)}(this.Sink));(function(a){a.doInterval=function(f,d){var e,c;function b(g){if(a.inlineWorker.working&&!g){e=a.inlineWorker('setInterval(function (){ postMessage("tic"); }, '+d+");");e.onmessage=function(){f()};c=function(){e.terminate()}}else{e=setInterval(f,d);c=function(){clearInterval(e)}}}a.inlineWorker.ready?b():a.inlineWorker.on("ready",function(){b()});return function(){if(!c){a.inlineWorker.ready||a.inlineWorker.on("ready",function(){c&&c()})}else{c()}}}}(this.Sink));(function(a){function b(d){if(!b.hasOwnProperty(d)){throw b(1)}if(!(this instanceof b)){return new b(d)}var c;for(c in b[d]){if(b[d].hasOwnProperty(c)){this[c]=b[d][c]}}this.code=d}b.prototype=new Error();b.prototype.toString=function(){return"SinkError 0x"+this.code.toString(16)+": "+this.message};b[1]={message:"No such error code.",explanation:"The error code does not exist.",};b[2]={message:"No audio sink available.",explanation:"The audio device may be busy, or no supported output API is available for this browser.",};b[16]={message:"Buffer underflow.",explanation:"Trying to recover...",};b[17]={message:"Critical recovery fail.",explanation:"The buffer underflow has reached a critical point, trying to recover, but will probably fail anyway.",};b[18]={message:"Buffer size too large.",explanation:"Unable to allocate the buffer due to excessive length, please try a smaller buffer. Buffer size should probably be smaller than the sample rate.",};a.Error=b}(this.Sink));(function(c){var d=typeof window==="undefined"?undefined:window.MozBlobBuilder||window.WebKitBlobBuilder||window.MSBlobBuilder||window.OBlobBuilder||window.BlobBuilder,b=typeof window==="undefined"?undefined:(window.MozURL||window.webkitURL||window.MSURL||window.OURL||window.URL);function a(f){var k=null,g,j;try{j=new d();j.append(f);g=b.createObjectURL(j.getBlob());k=new Worker(g);k._terminate=k.terminate;k._url=g;j=null;k.terminate=function(){this._terminate;b.revokeObjectURL(this._url)};a.type="blob";return k}catch(h){}try{k=new Worker("data:text/javascript;base64,"+btoa(f));a.type="data";return k}catch(h){}return k}a.ready=a.working=false;c.EventEmitter.call(a);a.test=function(){var g=a("this.onmessage=function (e){postMessage(e.data)}"),f="inlineWorker";a.ready=a.working=false;function e(h){if(a.ready){return}a.ready=true;a.working=h;a.emit("ready",[h]);a.off("ready");h&&g&&g.terminate();g=null}if(!g){e(false)}else{g.onmessage=function(h){e(h.data===f)};g.postMessage(f);setTimeout(function(){e(false)},1000)}};c.inlineWorker=a;a.test()}(this.Sink));(function(a){a.sinks("audiodata",function(){var m=this,d=0,k=null,j=new Audio(),h,g,e,f,l,b;m.start.apply(m,arguments);m.preBufferSize=isNaN(arguments[4])||arguments[4]===null?this.preBufferSize:arguments[4];function c(){if(k){h=j.mozWriteAudio(k);d+=h;if(h<k.length){k=k.subarray(h);return k}k=null}g=j.mozCurrentSampleOffset();e=Number(g+(l!==g?m.bufferSize:m.preBufferSize)*m.channelCount-d);g===l&&m.emit("error",[a.Error(16)]);if(e>0||l===g){try{f=new Float32Array(l===g?m.preBufferSize*m.channelCount:m.forceBufferSize?e<m.bufferSize*2?m.bufferSize*2:e:e)}catch(n){m.emit("error",[a.Error(18)]);m.kill();return}m.process(f,m.channelCount);h=m._audio.mozWriteAudio(f);if(h<f.length){k=f.subarray(h)}d+=h}l=g}j.mozSetup(m.channelCount,m.sampleRate);this._timers=[];this._timers.push(a.doInterval(function(){if(+new Date-m.previousHit>2000){m._audio=j=new Audio();j.mozSetup(m.channelCount,m.sampleRate);d=0;m.emit("error",[a.Error(17)])}},1000));this._timers.push(a.doInterval(c,m.interval));m._bufferFill=c;m._audio=j},{bufferSize:24576,preBufferSize:24576,forceBufferSize:false,interval:20,kill:function(){while(this._timers.length){this._timers[0]();this._timers.splice(0,1)}this.emit("kill")},getPlaybackTime:function(){return this._audio.mozCurrentSampleOffset()/this.channelCount},});a.sinks.moz=a.sinks.audiodata}(this.Sink));(function(a){a.sinks("dummy",function(){var b=this;b.start.apply(b,arguments);function c(){var d=new Float32Array(b.bufferSize*b.channelCount);b.process(d,b.channelCount)}b._kill=a.doInterval(c,b.bufferSize/b.sampleRate*1000);b._callback=c},{kill:function(){this._kill();this.emit("kill")},},true)}(this.Sink));(function(b,a){var a=b.sinks;function d(f){var e=document.createElement("audio");if(f){e.src=f}return e}a("wav",function(){var e=this,j=new a.wav.wavAudio,k=typeof k==="undefined"?audioLib.PCMData:k;e.start.apply(e,arguments);var g=new Float32Array(e.bufferSize*e.channelCount),h=new Float32Array(e.bufferSize*e.channelCount);if(!d().canPlayType("audio/wav; codecs=1")||!btoa){throw 0}function f(){if(e._audio.hasNextFrame){return}b.memcpy(h,0,g,0);e.process(g,e.channelCount);e._audio.setSource("data:audio/wav;base64,"+btoa(audioLib.PCMData.encode({data:g,sampleRate:e.sampleRate,channelCount:e.channelCount,bytesPerSample:e.quality,})));if(!e._audio.currentFrame.src){e._audio.nextClip()}}e.kill=b.doInterval(f,40);e._bufferFill=f;e._audio=j},{quality:1,bufferSize:22050,getPlaybackTime:function(){var e=this._audio;return(e.currentFrame?e.currentFrame.currentTime*this.sampleRate:0)+e.samples},});function c(){var e=this;e.currentFrame=d();e.nextFrame=d();e._onended=function(){e.samples+=e.bufferSize;e.nextClip()}}c.prototype={samples:0,nextFrame:null,currentFrame:null,_onended:null,hasNextFrame:false,nextClip:function(){var e=this.currentFrame;this.currentFrame=this.nextFrame;this.nextFrame=e;this.hasNextFrame=false;this.currentFrame.play()},setSource:function(e){this.nextFrame.src=e;this.nextFrame.addEventListener("ended",this._onended,true);this.hasNextFrame=true},};a.wav.wavAudio=c}(this.Sink));(function(a,b){a("webaudio",function(k,j,f,l){var m=this,c=a.webaudio.getContext(),h=c.createJavaScriptNode(f,0,j),g=null,e=null;m.start.apply(m,arguments);function d(v){var o=v.outputBuffer,q=o.numberOfChannels,s,p,r=o.length,w=o.size,t=new Array(q),u;g=g&&g.length===r*q?g:new Float32Array(r*q);e=e&&e.length===g.length?e:new Float32Array(r*q);g.set(e);for(s=0;s<q;s++){t[s]=o.getChannelData(s)}m.process(g,m.channelCount);for(s=0;s<r;s++){for(p=0;p<q;p++){t[p][s]=g[s*m.channelCount+p]}}}m.sampleRate=c.sampleRate;h.onaudioprocess=d;h.connect(c.destination);m._context=c;m._node=h;m._callback=d;b.push(h)},{kill:function(){this._node.disconnect(0);for(var c=0;c<b.length;c++){b[c]===this._node&&b.splice(c--,1)}this._node=this._context=null;this.emit("kill")},getPlaybackTime:function(){return this._context.currentTime*this.sampleRate},});a.webkit=a.webaudio;a.webaudio.fix82795=b;a.webaudio.getContext=function(){var c=new (window.AudioContext||webkitAudioContext)();a.webaudio.getContext=function(){return c};return c}}(this.Sink.sinks,[]));(function(a){a.sinks("worker",function(){var b=this,e=(function(){return this}()),c=null,h=null,d=null;b.start.apply(b,arguments);importScripts();function f(o){b.ready||b.initMSP(o);var m=b.channelCount,j=o.audioLength,p,k;c=c&&c.length===j*m?c:new Float32Array(j*m);h=h&&h.length===c.length?h:new Float32Array(j*m);d=d&&d.length===c.length?d:new Float32Array(j*m);c.set(d);h.set(d);b.process(c,b.channelCount);for(p=0;p<m;p++){for(k=0;k<j;k++){h[p*o.audioLength+k]=c[p+k*m]}}o.writeAudio(h)}function g(s){b.ready||b.initWA(s);var j=s.outputBuffer,m=j.numberOfChannels,p,k,o=j.length,t=j.size,q=new Array(m),r;c=c&&c.length===o*m?c:new Float32Array(o*m);d=d&&d.length===c.length?d:new Float32Array(o*m);c.set(d);for(p=0;p<m;p++){q[p]=j.getChannelData(p)}b.process(c,b.channelCount);for(p=0;p<o;p++){for(k=0;k<m;k++){q[k][p]=c[p*b.channelCount+k]}}}e.onprocessmedia=f;e.onaudioprocess=g;b._mspBufferFill=f;b._waBufferFill=g},{ready:false,initMSP:function(b){this.channelCount=b.audioChannels;this.sampleRate=b.audioSampleRate;this.bufferSize=b.audioLength*this.channelCount;this.ready=true;this.emit("ready",[])},initWA:function(d){var c=d.outputBuffer;this.channelCount=c.numberOfChannels;this.sampleRate=c.sampleRate;this.bufferSize=c.length*this.channelCount;this.ready=true;this.emit("ready",[])},})}(this.Sink));(function(a){a.deinterleave=function(c,g){var b=c.length,f=b/g,d=[],e,h;for(e=0;e<g;e++){d[e]=new Float32Array(f);for(h=0;h<f;h++){d[e][h]=c[h*g+e]}}return d};a.interleave=function(d,g,c){g=g||d.length;var b=d[0].length,f=d.length,e,h;c=c||new Float32Array(b*g);for(e=0;e<f;e++){for(h=0;h<b;h++){c[e+h*g]=d[e][h]}}return c};a.mix=function(e){var d=[].slice.call(arguments,1),b,f,g;for(g=0;g<d.length;g++){b=Math.max(e.length,d[g].length);for(f=0;f<b;f++){e[f]+=d[g][f]}}return e};a.resetBuffer=function(c){var b=c.length,d;for(d=0;d<b;d++){c[d]=0}return c};a.clone=function(d,b){var c=d.length,e;b=b||new Float32Array(c);for(e=0;e<c;e++){b[e]=d[e]}return b};a.createDeinterleaved=function(e,d){var b=new Array(d),c;for(c=0;c<d;c++){b[c]=new Float32Array(e)}return b};a.memcpy=function(f,b,g,d,e){f=f.subarray||f.slice?f:f.buffer;g=g.subarray||g.slice?g:g.buffer;f=b?f.subarray?f.subarray(b,e&&b+e):f.slice(b,e&&b+e):f;if(g.set){g.set(f,d)}else{for(var c=0;c<f.length;c++){g[c+d]=f[c]}}return g};a.memslice=function(b,d,c){return b.subarray?b.subarray(d,c):b.slice(d,c)};a.mempad=function(b,c,d){c=c.length?c:new (b.constructor)(c);a.memcpy(b,0,c,d);return c};a.linspace=function(h,c,d){var b,e,g,f;d=d.length?(b=d.length)&&d:Array(b=d);f=(c-h)/--b;for(g=h+f,e=1;e<b;e++,g+=f){d[e]=g}d[0]=h;d[b]=c;return d};a.ftoi=function(d,f,c){var e,b=Math.pow(2,f-1);c=c||new (d.constructor)(d.length);for(e=0;e<d.length;e++){c[e]=~~(b*d[e])}return c}}(this.Sink));(function(a){function b(e,d){a.EventEmitter.call(this);this.bufferSize=isNaN(e)||e===null?this.bufferSize:e;this.channelCount=isNaN(d)||d===null?this.channelCount:d;var c=this;this.callback=function(){return c.process.apply(c,arguments)};this.resetBuffer()}b.prototype={buffer:null,zeroBuffer:null,parentSink:null,bufferSize:4096,channelCount:2,offset:null,resetBuffer:function(){this.buffer=new Float32Array(this.bufferSize);this.zeroBuffer=new Float32Array(this.bufferSize)},process:function(c,e){this.offset===null&&this.loadBuffer();for(var d=0;d<c.length;d++){this.offset>=this.buffer.length&&this.loadBuffer();c[d]=this.buffer[this.offset++]}},loadBuffer:function(){this.offset=0;a.memcpy(this.zeroBuffer,0,this.buffer,0);this.emit("audioprocess",[this.buffer,this.channelCount])},};a.Proxy=b;a.prototype.createProxy=function(d){var c=new a.Proxy(d,this.channelCount);c.parentSink=this;this.on("audioprocess",c.callback);return c}}(this.Sink));(function(a){(function(){function b(c,d){if(c&&d){b[c]=d}else{if(c&&b[c] instanceof Function){a.interpolate=b[c]}}return b[c]}a.interpolation=b;b("linear",function(c,g){var f=Math.floor(g),e=f+1,d=g-f;e=e<c.length?e:0;return c[f]*(1-d)+c[e]*d});b("nearest",function(c,d){return d>=c.length-0.5?c[0]:c[Math.round(d)]});b("linear")}());a.resample=function(j,b,o,p,d){var h=arguments.length,f=h===2?b:h===3?b/o:p/b*d/o,g=j.length,c=Math.ceil(g/f),m=new Float32Array(c),k,e;for(k=0,e=0;k<g;k+=f){m[e++]=a.interpolate(j,k)}return m}}(this.Sink));(function(b){b.on("init",function(c){c.activeRecordings=[];c.on("postprocess",c.recordData)});b.prototype.activeRecordings=null;b.prototype.record=function(){var c=new b.Recording(this);this.emit("record",[c]);return c};b.prototype.recordData=function(d){var f=this.activeRecordings,e,c=f.length;for(e=0;e<c;e++){f[e].add(d)}};function a(c){this.boundTo=c;this.buffers=[];c.activeRecordings.push(this)}a.prototype={add:function(c){this.buffers.push(c)},clear:function(){this.buffers=[]},stop:function(){var c=this.boundTo.activeRecordings,d;for(d=0;d<c.length;d++){if(c[d]===this){c.splice(d--,1)}}},join:function(){var g=0,h=0,e=this.buffers,c,j,f,d=e.length;for(f=0;f<d;f++){g+=e[f].length}c=new Float32Array(g);for(f=0;f<d;f++){for(j=0;j<e[f].length;j++){c[h+j]=e[f][j]}h+=e[f].length}return c},};b.Recording=a}(this.Sink));(function(b){function a(){this.ringBuffer&&(this.channelMode==="interleaved"?this.ringSpin:this.ringSpinInterleaved).apply(this,arguments)}b.on("init",function(c){c.on("preprocess",a)});b.prototype.ringBuffer=null;b.prototype.ringSpin=function(e){var f=this.ringBuffer,d=e.length,c=f.length,h=this.ringOffset,g;for(g=0;g<d;g++){e[g]+=f[h];h=(h+1)%c}this.ringOffset=h};b.prototype.ringSpinDeinterleaved=function(j){var h=this.ringBuffer,g=j.length,c=h.length,f=h[0].length,o=c*f,e=this.ringOffset,k,d;for(k=0;k<g;k+=c){for(d=0;d<c;d++){j[k+d]+=h[d][e]}e=(e+1)%f}this.ringOffset=d}}(this.Sink));(function(a,b){b=a.prototype;a.on("init",function(c){c.asyncBuffers=[];c.syncBuffers=[];c.on("preprocess",c.writeBuffersSync);c.on("postprocess",c.writeBuffersAsync)});b.writeMode="async";b.asyncBuffers=b.syncBuffers=null;b.writeBuffersAsync=function(e){var d=this.asyncBuffers,c=e.length,f,h,g,k,j;if(d){for(g=0;g<d.length;g++){f=d[g];h=f.b.length;j=f.d;f.d-=Math.min(j,c);for(k=0;k+j<c&&k<h;k++){e[k+j]+=f.b[k]}f.b=f.b.subarray(k+j);g>=h&&d.splice(g--,1)}}};b.writeBuffersSync=function(e){var d=this.syncBuffers,c=e.length,f=0,g=0;for(;f<c&&d.length;f++){e[f]+=d[0][g];if(d[0].length<=g){d.splice(0,1);g=0;continue}g++}if(d.length){d[0]=d[0].subarray(g)}};b.writeBufferAsync=function(d,e){d=this.mode==="deinterleaved"?a.interleave(d,this.channelCount):d;var c=this.asyncBuffers;c.push({b:d,d:isNaN(e)?~~((+new Date-this.previousHit)/1000*this.sampleRate):e});return c.length};b.writeBufferSync=function(d){d=this.mode==="deinterleaved"?a.interleave(d,this.channelCount):d;var c=this.syncBuffers;c.push(d);return c.length};b.writeBuffer=function(){return this[this.writeMode==="async"?"writeBufferAsync":"writeBufferSync"].apply(this,arguments)};b.getSyncWriteOffset=function(){var c=this.syncBuffers,e=0,d;for(d=0;d<c.length;d++){e+=c[d].length}return e}}(this.Sink));
+var EqualTemperamentTuning=function(b){var c=[];for(var a=0;a<b;a++){c.push(a)}Tuning.call(this,c,2)};extend(EqualTemperamentTuning,Tuning);var Sink=this.Sink=function(d){function c(j,h,l,f){var e=c.sinks.list,g;for(g=0;g<e.length;g++){if(e[g].enabled){try{return new e[g](j,h,l,f)}catch(k){}}}throw c.Error(2)}function b(){}c.SinkClass=b;b.prototype=c.prototype={sampleRate:44100,channelCount:2,bufferSize:4096,writePosition:0,previousHit:0,ringOffset:0,channelMode:"interleaved",isReady:false,start:function(g,f,h,e){this.channelCount=isNaN(f)||f===null?this.channelCount:f;this.bufferSize=isNaN(h)||h===null?this.bufferSize:h;this.sampleRate=isNaN(e)||e===null?this.sampleRate:e;this.readFn=g;this.activeRecordings=[];this.previousHit=+new Date();c.EventEmitter.call(this);c.emit("init",[this].concat([].slice.call(arguments)))},process:function(g,h){this.emit("preprocess",arguments);if(this.ringBuffer){(this.channelMode==="interleaved"?this.ringSpin:this.ringSpinInterleaved).apply(this,arguments)}if(this.channelMode==="interleaved"){this.emit("audioprocess",arguments);if(this.readFn){this.readFn.apply(this,arguments)}}else{var e=c.deinterleave(g,this.channelCount),f=[e].concat([].slice.call(arguments,1));this.emit("audioprocess",f);if(this.readFn){this.readFn.apply(this,f)}c.interleave(e,this.channelCount,g)}this.emit("postprocess",arguments);this.previousHit=+new Date();this.writePosition+=g.length/h},getPlaybackTime:function(){return this.writePosition-this.bufferSize},ready:function(){if(this.isReady){return}this.isReady=true;this.emit("ready",[])}};function a(l,j,f,h,g){f=f||j.prototype;j.prototype=new c.SinkClass();j.prototype.type=l;j.enabled=!h;var e;for(e in f){if(f.hasOwnProperty(e)){j.prototype[e]=f[e]}}a[l]=j;a.list[g?"unshift":"push"](j)}c.sinks=c.devices=a;c.sinks.list=[];c.singleton=function(){var e=c.apply(null,arguments);c.singleton=function(){return e};return e};d.Sink=c;return c}(function(){return this}());void function(a){function b(){var c;for(c in b.prototype){if(b.prototype.hasOwnProperty(c)){this[c]=b.prototype[c]}}this._listeners={}}b.prototype={_listeners:null,emit:function(d,c){if(this._listeners[d]){for(var e=0;e<this._listeners[d].length;e++){this._listeners[d][e].apply(this,c)}}return this},on:function(c,d){this._listeners[c]=this._listeners[c]||[];this._listeners[c].push(d);return this},off:function(c,e){if(this._listeners[c]){if(!e){delete this._listeners[c];return this}for(var d=0;d<this._listeners[c].length;d++){if(this._listeners[c][d]===e){this._listeners[c].splice(d--,1)}}if(!this._listeners[c].length){delete this._listeners[c]}}return this}};a.EventEmitter=b;b.call(a)}(this.Sink);void function(a){a.doInterval=function(f,d){var e,c;function b(g){if(a.inlineWorker.working&&!g){e=a.inlineWorker('setInterval(function (){ postMessage("tic"); }, '+d+");");e.onmessage=function(){f()};c=function(){e.terminate()}}else{e=setInterval(f,d);c=function(){clearInterval(e)}}}if(a.inlineWorker.ready){b()}else{a.inlineWorker.on("ready",function(){b()})}return function(){if(!c){if(!a.inlineWorker.ready){a.inlineWorker.on("ready",function(){if(c){c()}})}}else{c()}}}}(this.Sink);void function(d){var b,h,j,f;void function(k,m){function l(p,q){var n,o=q.slice();for(n=o.shift();typeof n!=="undefined";n=o.shift()){n=Function("return typeof "+n+p+'=== "undefined" ? undefined : '+n+p)();if(n){return n}}}b=l("Blob",k);h=l("BlobBuilder",k);j=l("URL",m);f=l("btoa",[""])}(["","Moz","WebKit","MS"],["","webkit"]);var g=b&&j&&function(l,k){return j.createObjectURL(new b([l],{type:k}))};var c=h&&j&&function(l,k){var m=new h();m.append(l);return j.createObjectURL(m.getBlob(k))};var a=f&&function(l,k){return"data:"+k+";base64,"+f(l)};var e=g||c||a;if(!e){return}if(g){e.createBlob=g}if(c){e.createBlobBuilder=c}if(a){e.createData=a}if(b){e.Blob=b}if(h){e.BlobBuilder=h}if(j){e.URL=j}d.createDynURL=e;d.revokeDynURL=function(k){if(typeof k==="string"&&k.indexOf("data:")===0){return false}else{return j.revokeObjectURL(k)}}}(this.Sink);void function(a){function b(d){if(!b.hasOwnProperty(d)){throw b(1)}if(!(this instanceof b)){return new b(d)}var c;for(c in b[d]){if(b[d].hasOwnProperty(c)){this[c]=b[d][c]}}this.code=d}b.prototype=new Error();b.prototype.toString=function(){return"SinkError 0x"+this.code.toString(16)+": "+this.message};b[1]={message:"No such error code.",explanation:"The error code does not exist."};b[2]={message:"No audio sink available.",explanation:"The audio device may be busy, or no supported output API is available for this browser."};b[16]={message:"Buffer underflow.",explanation:"Trying to recover..."};b[17]={message:"Critical recovery fail.",explanation:"The buffer underflow has reached a critical point, trying to recover, but will probably fail anyway."};b[18]={message:"Buffer size too large.",explanation:"Unable to allocate the buffer due to excessive length, please try a smaller buffer. Buffer size should probably be smaller than the sample rate."};a.Error=b}(this.Sink);void function(b){var d=Object.defineProperty?function(g,e,f){Object.defineProperty(g,e,{value:f,configurable:true,writable:true})}:function(g,e,f){g[e]=f};function c(){d(this,"terminate",this._terminate);b.revokeDynURL(this._url);delete this._url;delete this._terminate;return this.terminate()}function a(e){function f(l,m,j){try{var k=l(m,"text/javascript");var o=new Worker(k);d(o,"_url",k);d(o,"_terminate",o.terminate);d(o,"terminate",c);if(a.type){return o}a.type=j;a.createURL=l;return o}catch(n){return null}}var h=b.createDynURL;var g;if(a.createURL){return f(a.createURL,e,a.type)}g=f(h.createBlob,e,"blob");if(g){return g}g=f(h.createBlobBuilder,e,"blobbuilder");if(g){return g}g=f(h.createData,e,"data");return g}b.EventEmitter.call(a);a.test=function(){a.ready=a.working=false;a.type="";a.createURL=null;var g=a("this.onmessage=function(e){postMessage(e.data)}");var f="inlineWorker";function e(h){if(a.ready){return}a.ready=true;a.working=h;a.emit("ready",[h]);a.off("ready");if(h&&g){g.terminate()}g=null}if(!g){setTimeout(function(){e(false)},0)}else{g.onmessage=function(h){e(h.data===f)};g.postMessage(f);setTimeout(function(){e(false)},1000)}};b.inlineWorker=a;a.test()}(this.Sink);void function(a){a.sinks("audiodata",function(){var m=this,d=0,k=null,j=new Audio(),h,g,e,f,l,b;m.start.apply(m,arguments);m.preBufferSize=isNaN(arguments[4])||arguments[4]===null?this.preBufferSize:arguments[4];function c(){if(k){h=j.mozWriteAudio(k);d+=h;if(h<k.length){k=k.subarray(h);return k}k=null}g=j.mozCurrentSampleOffset();e=Number(g+(l!==g?m.bufferSize:m.preBufferSize)*m.channelCount-d);if(g===l){m.emit("error",[a.Error(16)])}if(e>0||l===g){m.ready();try{f=new Float32Array(l===g?m.preBufferSize*m.channelCount:m.forceBufferSize?e<m.bufferSize*2?m.bufferSize*2:e:e)}catch(n){m.emit("error",[a.Error(18)]);m.kill();return}m.process(f,m.channelCount);h=m._audio.mozWriteAudio(f);if(h<f.length){k=f.subarray(h)}d+=h}l=g}j.mozSetup(m.channelCount,m.sampleRate);this._timers=[];this._timers.push(a.doInterval(function(){if(+new Date()-m.previousHit>2000){m._audio=j=new Audio();j.mozSetup(m.channelCount,m.sampleRate);d=0;m.emit("error",[a.Error(17)])}},1000));this._timers.push(a.doInterval(c,m.interval));m._bufferFill=c;m._audio=j},{bufferSize:24576,preBufferSize:24576,forceBufferSize:false,interval:100,kill:function(){while(this._timers.length){this._timers.shift()()}this.emit("kill")},getPlaybackTime:function(){return this._audio.mozCurrentSampleOffset()/this.channelCount}},false,true);a.sinks.moz=a.sinks.audiodata}(this.Sink);void function(a){a.sinks("dummy",function(){var b=this;b.start.apply(b,arguments);function c(){var d=new Float32Array(b.bufferSize*b.channelCount);b.process(d,b.channelCount)}b._kill=a.doInterval(c,b.bufferSize/b.sampleRate*1000);b._callback=c},{kill:function(){this._kill();this.emit("kill")}},true)}(this.Sink);(function(b,a){a=b.sinks;function d(f){var e=document.createElement("audio");if(f){e.src=f}return e}a("wav",function(){var e=this,j=new a.wav.wavAudio(),k=typeof k==="undefined"?audioLib.PCMData:k;e.start.apply(e,arguments);var g=new Float32Array(e.bufferSize*e.channelCount),h=new Float32Array(e.bufferSize*e.channelCount);if(!d().canPlayType("audio/wav; codecs=1")||!btoa){throw 0}function f(){if(e._audio.hasNextFrame){return}e.ready();b.memcpy(h,0,g,0);e.process(g,e.channelCount);e._audio.setSource("data:audio/wav;base64,"+btoa(audioLib.PCMData.encode({data:g,sampleRate:e.sampleRate,channelCount:e.channelCount,bytesPerSample:e.quality})));if(!e._audio.currentFrame.src){e._audio.nextClip()}}e.kill=b.doInterval(f,40);e._bufferFill=f;e._audio=j},{quality:1,bufferSize:22050,getPlaybackTime:function(){var e=this._audio;return(e.currentFrame?e.currentFrame.currentTime*this.sampleRate:0)+e.samples}});function c(){var e=this;e.currentFrame=d();e.nextFrame=d();e._onended=function(){e.samples+=e.bufferSize;e.nextClip()}}c.prototype={samples:0,nextFrame:null,currentFrame:null,_onended:null,hasNextFrame:false,nextClip:function(){var e=this.currentFrame;this.currentFrame=this.nextFrame;this.nextFrame=e;this.hasNextFrame=false;this.currentFrame.play()},setSource:function(e){this.nextFrame.src=e;this.nextFrame.addEventListener("ended",this._onended,true);this.hasNextFrame=true}};a.wav.wavAudio=c}(this.Sink));(function(a,b){var c=typeof window==="undefined"?null:window.webkitAudioContext||window.AudioContext;a("webaudio",function(l,k,g,m){var n=this,d=a.webaudio.getContext(),j=null,h=null,f=null;n.start.apply(n,arguments);j=d.createJavaScriptNode(n.bufferSize,0,n.channelCount);function e(v){var o=v.outputBuffer,q=o.numberOfChannels,s,p,r=o.length,w=o.size,t=new Array(q),u;n.ready();h=h&&h.length===r*q?h:new Float32Array(r*q);f=f&&f.length===h.length?f:new Float32Array(r*q);h.set(f);for(s=0;s<q;s++){t[s]=o.getChannelData(s)}n.process(h,n.channelCount);for(s=0;s<r;s++){for(p=0;p<q;p++){t[p][s]=h[s*n.channelCount+p]}}}n.sampleRate=d.sampleRate;j.onaudioprocess=e;j.connect(d.destination);n._context=d;n._node=j;n._callback=e;b.push(j)},{kill:function(){this._node.disconnect(0);for(var d=0;d<b.length;d++){if(b[d]===this._node){b.splice(d--,1)}}this._node=this._context=null;this.emit("kill")},getPlaybackTime:function(){return this._context.currentTime*this.sampleRate}},false,true);a.webkit=a.webaudio;a.webaudio.fix82795=b;a.webaudio.getContext=function(){var d=new c();a.webaudio.getContext=function(){return d};return d}}(this.Sink.sinks,[]));(function(a){a.sinks("worker",function(){var b=this,e=(function(){return this}()),c=null,h=null,d=null;b.start.apply(b,arguments);importScripts();function f(o){if(!b.isReady){b.initMSP(o)}b.ready();var m=b.channelCount,j=o.audioLength,p,k;c=c&&c.length===j*m?c:new Float32Array(j*m);h=h&&h.length===c.length?h:new Float32Array(j*m);d=d&&d.length===c.length?d:new Float32Array(j*m);c.set(d);h.set(d);b.process(c,b.channelCount);for(p=0;p<m;p++){for(k=0;k<j;k++){h[p*o.audioLength+k]=c[p+k*m]}}o.writeAudio(h)}function g(s){if(!b.isReady){b.initWA(s)}b.ready();var j=s.outputBuffer,m=j.numberOfChannels,p,k,o=j.length,t=j.size,q=new Array(m),r;c=c&&c.length===o*m?c:new Float32Array(o*m);d=d&&d.length===c.length?d:new Float32Array(o*m);c.set(d);for(p=0;p<m;p++){q[p]=j.getChannelData(p)}b.process(c,b.channelCount);for(p=0;p<o;p++){for(k=0;k<m;k++){q[k][p]=c[p*b.channelCount+k]}}}e.onprocessmedia=f;e.onaudioprocess=g;b._mspBufferFill=f;b._waBufferFill=g},{ready:false,initMSP:function(b){this.channelCount=b.audioChannels;this.sampleRate=b.audioSampleRate;this.bufferSize=b.audioLength*this.channelCount;this.ready=true;this.emit("ready",[])},initWA:function(d){var c=d.outputBuffer;this.channelCount=c.numberOfChannels;this.sampleRate=c.sampleRate;this.bufferSize=c.length*this.channelCount;this.ready=true;this.emit("ready",[])}})}(this.Sink));(function(a){a.deinterleave=function(c,g){var b=c.length,f=b/g,d=[],e,h;for(e=0;e<g;e++){d[e]=new Float32Array(f);for(h=0;h<f;h++){d[e][h]=c[h*g+e]}}return d};a.interleave=function(d,g,c){g=g||d.length;var b=d[0].length,f=d.length,e,h;c=c||new Float32Array(b*g);for(e=0;e<f;e++){for(h=0;h<b;h++){c[e+h*g]=d[e][h]}}return c};a.mix=function(e){var d=[].slice.call(arguments,1),b,f,g;for(g=0;g<d.length;g++){b=Math.max(e.length,d[g].length);for(f=0;f<b;f++){e[f]+=d[g][f]}}return e};a.resetBuffer=function(c){var b=c.length,d;for(d=0;d<b;d++){c[d]=0}return c};a.clone=function(d,b){var c=d.length,e;b=b||new Float32Array(c);for(e=0;e<c;e++){b[e]=d[e]}return b};a.createDeinterleaved=function(e,d){var b=new Array(d),c;for(c=0;c<d;c++){b[c]=new Float32Array(e)}return b};a.memcpy=function(f,b,g,d,e){f=f.subarray||f.slice?f:f.buffer;g=g.subarray||g.slice?g:g.buffer;f=b?f.subarray?f.subarray(b,e&&b+e):f.slice(b,e&&b+e):f;if(g.set){g.set(f,d)}else{for(var c=0;c<f.length;c++){g[c+d]=f[c]}}return g};a.memslice=function(b,d,c){return b.subarray?b.subarray(d,c):b.slice(d,c)};a.mempad=function(b,c,d){c=c.length?c:new (b.constructor)(c);a.memcpy(b,0,c,d);return c};a.linspace=function(h,c,d){var b,e,g,f;d=d.length?(b=d.length)&&d:Array(b=d);f=(c-h)/--b;for(g=h+f,e=1;e<b;e++,g+=f){d[e]=g}d[0]=h;d[b]=c;return d};a.ftoi=function(d,f,c){var e,b=Math.pow(2,f-1);c=c||new (d.constructor)(d.length);for(e=0;e<d.length;e++){c[e]=~~(b*d[e])}return c}}(this.Sink));(function(a){function b(e,d){a.EventEmitter.call(this);this.bufferSize=isNaN(e)||e===null?this.bufferSize:e;this.channelCount=isNaN(d)||d===null?this.channelCount:d;var c=this;this.callback=function(){return c.process.apply(c,arguments)};this.resetBuffer()}b.prototype={buffer:null,zeroBuffer:null,parentSink:null,bufferSize:4096,channelCount:2,offset:null,resetBuffer:function(){this.buffer=new Float32Array(this.bufferSize);this.zeroBuffer=new Float32Array(this.bufferSize)},process:function(c,e){if(this.offset===null){this.loadBuffer()}for(var d=0;d<c.length;d++){if(this.offset>=this.buffer.length){this.loadBuffer()}c[d]=this.buffer[this.offset++]}},loadBuffer:function(){this.offset=0;a.memcpy(this.zeroBuffer,0,this.buffer,0);this.emit("audioprocess",[this.buffer,this.channelCount])}};a.Proxy=b;a.prototype.createProxy=function(d){var c=new a.Proxy(d,this.channelCount);c.parentSink=this;this.on("audioprocess",c.callback);return c}}(this.Sink));(function(a){(function(){function b(c,d){if(c&&d){b[c]=d}else{if(c&&b[c] instanceof Function){a.interpolate=b[c]}}return b[c]}a.interpolation=b;b("linear",function(c,g){var f=Math.floor(g),e=f+1,d=g-f;e=e<c.length?e:0;return c[f]*(1-d)+c[e]*d});b("nearest",function(c,d){return d>=c.length-0.5?c[0]:c[Math.round(d)]});b("linear")}());a.resample=function(j,b,o,p,d){var h=arguments.length,f=h===2?b:h===3?b/o:p/b*d/o,g=j.length,c=Math.ceil(g/f),m=new Float32Array(c),k,e;for(k=0,e=0;k<g;k+=f){m[e++]=a.interpolate(j,k)}return m}}(this.Sink));void function(b){b.on("init",function(c){c.activeRecordings=[];c.on("postprocess",c.recordData)});b.prototype.activeRecordings=null;b.prototype.record=function(){var c=new b.Recording(this);this.emit("record",[c]);return c};b.prototype.recordData=function(d){var f=this.activeRecordings,e,c=f.length;for(e=0;e<c;e++){f[e].add(d)}};function a(c){this.boundTo=c;this.buffers=[];c.activeRecordings.push(this)}a.prototype={add:function(c){this.buffers.push(c)},clear:function(){this.buffers=[]},stop:function(){var c=this.boundTo.activeRecordings,d;for(d=0;d<c.length;d++){if(c[d]===this){c.splice(d--,1)}}},join:function(){var g=0,h=0,e=this.buffers,c,j,f,d=e.length;for(f=0;f<d;f++){g+=e[f].length}c=new Float32Array(g);for(f=0;f<d;f++){for(j=0;j<e[f].length;j++){c[h+j]=e[f][j]}h+=e[f].length}return c}};b.Recording=a}(this.Sink);void function(b){function a(){if(this.ringBuffer){(this.channelMode==="interleaved"?this.ringSpin:this.ringSpinInterleaved).apply(this,arguments)}}b.on("init",function(c){c.on("preprocess",a)});b.prototype.ringBuffer=null;b.prototype.ringSpin=function(e){var f=this.ringBuffer,d=e.length,c=f.length,h=this.ringOffset,g;for(g=0;g<d;g++){e[g]+=f[h];h=(h+1)%c}this.ringOffset=h};b.prototype.ringSpinDeinterleaved=function(j){var h=this.ringBuffer,g=j.length,c=h.length,f=h[0].length,o=c*f,e=this.ringOffset,k,d;for(k=0;k<g;k+=c){for(d=0;d<c;d++){j[k+d]+=h[d][e]}e=(e+1)%f}this.ringOffset=d}}(this.Sink);void function(a,b){b=a.prototype;a.on("init",function(c){c.asyncBuffers=[];c.syncBuffers=[];c.on("preprocess",c.writeBuffersSync);c.on("postprocess",c.writeBuffersAsync)});b.writeMode="async";b.asyncBuffers=b.syncBuffers=null;b.writeBuffersAsync=function(e){var d=this.asyncBuffers,c=e.length,f,h,g,k,j;if(d){for(g=0;g<d.length;g++){f=d[g];h=f.b.length;j=f.d;f.d-=Math.min(j,c);for(k=0;k+j<c&&k<h;k++){e[k+j]+=f.b[k]}f.b=f.b.subarray(k+j);if(g>=h){d.splice(g--,1)}}}};b.writeBuffersSync=function(e){var d=this.syncBuffers,c=e.length,f=0,g=0;for(;f<c&&d.length;f++){e[f]+=d[0][g];if(d[0].length<=g){d.splice(0,1);g=0;continue}g++}if(d.length){d[0]=d[0].subarray(g)}};b.writeBufferAsync=function(d,e){d=this.mode==="deinterleaved"?a.interleave(d,this.channelCount):d;var c=this.asyncBuffers;c.push({b:d,d:isNaN(e)?~~((+new Date()-this.previousHit)/1000*this.sampleRate):e});return c.length};b.writeBufferSync=function(d){d=this.mode==="deinterleaved"?a.interleave(d,this.channelCount):d;var c=this.syncBuffers;c.push(d);return c.length};b.writeBuffer=function(){return this[this.writeMode==="async"?"writeBufferAsync":"writeBufferSync"].apply(this,arguments)};b.getSyncWriteOffset=function(){var c=this.syncBuffers,e=0,d;for(d=0;d<c.length;d++){e+=c[d].length}return e}}(this.Sink);

0 comments on commit 631198c

Please sign in to comment.