Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Clean it up a bit

  • Loading branch information...
commit 3727f68f2808d8e3897a21c560b312c5c6208b11 1 parent 58f12f7
@jussi-kalliokoski authored
View
16 src/core/do-interval.js
@@ -33,15 +33,21 @@ 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();
}
View
6 src/core/inline-worker.js
@@ -64,7 +64,11 @@ inlineWorker.test = function () {
inlineWorker.working = success;
inlineWorker.emit('ready', [success]);
inlineWorker.off('ready');
- success && worker && worker.terminate();
+
+ if (success && worker) {
+ worker.terminate();
+ }
+
worker = null;
}
View
8 src/event-emitter.js
@@ -14,7 +14,7 @@ function EventEmitter () {
}
}
this._listeners = {};
-};
+}
EventEmitter.prototype = {
_listeners: null,
@@ -61,12 +61,16 @@ 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;
}
View
4 src/extra/ring-buffer.js
@@ -1,7 +1,9 @@
(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) {
View
6 src/extra/write-buffers.js
@@ -37,7 +37,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);
+ }
}
}
};
@@ -84,7 +86,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;
};
View
30 src/main.js
@@ -62,7 +62,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)));
},
@@ -72,19 +72,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;
},
/**
@@ -126,11 +137,14 @@ function sinks (type, constructor, prototype, disabled, priority) {
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);
}
View
8 src/sinks/audio-data-api.js
@@ -27,7 +27,11 @@ 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();
@@ -55,7 +59,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;
View
2  src/sinks/dummy.js
@@ -5,7 +5,7 @@
*/
Sink.sinks('dummy', function () {
- var self = this;
+ var self = this;
self.start.apply(self, arguments);
function bufferFill () {
View
12 src/sinks/wav-data-uri.js
@@ -1,6 +1,6 @@
(function (Sink, sinks) {
-var sinks = Sink.sinks;
+sinks = Sink.sinks;
function newAudio (src) {
var audio = document.createElement('audio');
@@ -10,7 +10,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
@@ -19,7 +19,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),
@@ -40,7 +40,7 @@ sinks('wav', function () {
data: soundData,
sampleRate: self.sampleRate,
channelCount: self.channelCount,
- bytesPerSample: self.quality,
+ bytesPerSample: self.quality
})
));
@@ -57,7 +57,7 @@ sinks('wav', function () {
getPlaybackTime: function () {
var audio = this._audio;
return (audio.currentFrame ? audio.currentFrame.currentTime * this.sampleRate : 0) + audio.samples;
- },
+ }
});
function wavAudio () {
@@ -92,7 +92,7 @@ wavAudio.prototype = {
this.nextFrame.addEventListener('ended', this._onended, true);
this.hasNextFrame = true;
- },
+ }
};
sinks.wav.wavAudio = wavAudio;
View
12 src/sinks/web-audio-api.js
@@ -1,5 +1,7 @@
(function (sinks, fixChrome82795) {
+var AudioContext = typeof window === 'undefined' ? null : window.webkitAudioContext || window.AudioContext;
+
/**
* A sink class for the Web Audio API
*/
@@ -53,16 +55,20 @@ 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;
@@ -71,7 +77,7 @@ 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;
View
12 src/sinks/workers.js
@@ -17,7 +17,10 @@ Sink.sinks('worker', function () {
importScripts();
function mspBufferFill (e) {
- self.isReady || self.initMSP(e);
+ if (!self.isReady) {
+ self.initMSP(e);
+ }
+
self.ready();
var channelCount = self.channelCount,
@@ -43,7 +46,10 @@ Sink.sinks('worker', function () {
}
function waBufferFill(e) {
- self.isReady || self.initWA(e);
+ if (!self.isReady) {
+ self.initWA(e);
+ }
+
self.ready();
var outputBuffer = e.outputBuffer,
@@ -94,7 +100,7 @@ Sink.sinks('worker', function () {
this.bufferSize = b.length * this.channelCount;
this.ready = true;
this.emit('ready', []);
- },
+ }
});
}(this.Sink));
View
11 src/utils/proxy.js
@@ -28,10 +28,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++];
}
},
@@ -40,7 +45,7 @@ Proxy.prototype = {
this.offset = 0;
Sink.memcpy(this.zeroBuffer, 0, this.buffer, 0);
this.emit('audioprocess', [this.buffer, this.channelCount]);
- },
+ }
};
Sink.Proxy = Proxy;
Please sign in to comment.
Something went wrong with that request. Please try again.