Skip to content

Commit

Permalink
Added backend priorization, fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
jussi-kalliokoski committed Feb 20, 2012
1 parent 894581c commit bf2e62a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions src/main.js
Expand Up @@ -22,12 +22,12 @@ var Sink = this.Sink = (function(global){
* @param {Number} default=0 ringOffset The current position of the ring buffer. * @param {Number} default=0 ringOffset The current position of the ring buffer.
*/ */
function Sink (readFn, channelCount, bufferSize, sampleRate) { function Sink (readFn, channelCount, bufferSize, sampleRate) {
var sinks = Sink.sinks, var sinks = Sink.sinks.list,
dev; i;
for (dev in sinks){ for (i=0; i<sinks.length; i++) {
if (sinks.hasOwnProperty(dev) && sinks[dev].enabled){ if (sinks[i].enabled) {
try{ try {
return new sinks[dev](readFn, channelCount, bufferSize, sampleRate); return new sinks[i](readFn, channelCount, bufferSize, sampleRate);
} catch(e1){} } catch(e1){}
} }
} }
Expand Down Expand Up @@ -121,7 +121,7 @@ SinkClass.prototype = Sink.prototype = {
* @arg {Boolean} disabled Whether the Sink should be disabled at first. * @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; prototype = prototype || constructor.prototype;
constructor.prototype = new Sink.SinkClass(); constructor.prototype = new Sink.SinkClass();
constructor.prototype.type = type; constructor.prototype.type = type;
Expand All @@ -132,9 +132,11 @@ function sinks (type, constructor, prototype, disabled) {
} }
} }
sinks[type] = constructor; sinks[type] = constructor;
sinks.list[priority ? 'unshift' : 'push'](constructor);
} }


Sink.sinks = Sink.devices = sinks; Sink.sinks = Sink.devices = sinks;
Sink.sinks.list = [];


Sink.singleton = function () { Sink.singleton = function () {
var sink = Sink.apply(null, arguments); var sink = Sink.apply(null, arguments);
Expand Down
2 changes: 1 addition & 1 deletion src/sinks/audio-data-api.js
Expand Up @@ -85,7 +85,7 @@ Sink.sinks('audiodata', function () {
getPlaybackTime: function () { getPlaybackTime: function () {
return this._audio.mozCurrentSampleOffset() / this.channelCount; return this._audio.mozCurrentSampleOffset() / this.channelCount;
}, },
}); }, false, true);


Sink.sinks.moz = Sink.sinks.audiodata; Sink.sinks.moz = Sink.sinks.audiodata;


Expand Down
2 changes: 1 addition & 1 deletion src/sinks/web-audio-api.js
Expand Up @@ -63,7 +63,7 @@ sinks('webaudio', function (readFn, channelCount, bufferSize, sampleRate) {
getPlaybackTime: function () { getPlaybackTime: function () {
return this._context.currentTime * this.sampleRate; return this._context.currentTime * this.sampleRate;
}, },
}); }, false, true);


sinks.webkit = sinks.webaudio; sinks.webkit = sinks.webaudio;


Expand Down

0 comments on commit bf2e62a

Please sign in to comment.