audio-vs1053b
Advanced tools
Comparing version 0.1.3 to 0.1.4
60
index.js
@@ -45,6 +45,5 @@ // Copyright 2014 Technical Machine, Inc. See the COPYRIGHT | ||
var _audioCallbacks = {}; | ||
var _fillBuff = new Buffer(15000); | ||
var _fillBuff = new Buffer(25000); | ||
_fillBuff.fill(0); | ||
function use (hardware, next) { | ||
@@ -154,3 +153,6 @@ return new Audio(hardware, next); | ||
Audio.prototype._handleRecordedData = function(length) { | ||
this.emit('data', _fillBuff.slice(0, length)); | ||
// Copy the recorded data into a new buff for consumption | ||
var cp = new Buffer(length); | ||
_fillBuff.copy(cp, 0, 0, length); | ||
this.emit('data', cp); | ||
} | ||
@@ -180,3 +182,3 @@ | ||
// Check if this chunk is too small to be played solo | ||
if (this.bufferedLen >= 10000) { | ||
if (this.bufferedLen >= 5000) { | ||
var audioData = Buffer.concat(this.bufs); | ||
@@ -187,2 +189,3 @@ this.bufs = []; this.bufferedLen = 0; | ||
if (ret < 0) { | ||
err = new Error("Unable to queue the streamed buffer."); | ||
@@ -214,8 +217,19 @@ } | ||
var pusher = recordStream.push.bind(recordStream); | ||
var bufQueue = []; | ||
audio.on('data', pusher); | ||
audio.on('data', function(data) { | ||
bufQueue = bufQueue.concat(data); | ||
}); | ||
process.once('audio_recording_complete', recordStream.push.bind(recordStream)); | ||
recordStream._read = function(size) { | ||
var toSend = size > bufQueue.length ? bufQueue.length : size; | ||
for (var i = 0; i < toSend; i++) { | ||
recordStream.push(bufQueue[i]); | ||
} | ||
} | ||
process.once('audio_recording_complete', function() { | ||
recordStream.push(null) | ||
}); | ||
recordStream._write = function() {}; | ||
@@ -483,2 +497,9 @@ | ||
if (buff.length === 0) { | ||
if (callback) { | ||
callback(); | ||
} | ||
return; | ||
} | ||
self.spi.lock(function(err, lock) { | ||
@@ -551,6 +572,20 @@ if (err) { | ||
if (buff.length === 0) { | ||
if (callback) { | ||
callback(); | ||
} | ||
return; | ||
} | ||
// Initialize SPI to the correct settings | ||
self.spi.initialize(); | ||
// If there was a lock in place, wait until it's released | ||
self.spi.lock(function(err, lock) { | ||
// Release the lock so that we don't wait until complete for next queue | ||
lock.release(); | ||
self.lock = null; | ||
if (err) { | ||
@@ -564,3 +599,2 @@ if (callback) { | ||
else { | ||
self.lock = lock; | ||
@@ -697,2 +731,3 @@ var streamID = hw.audio_queue_buffer(self.MP3_XCS.pin, self.MP3_DCS.pin, self.MP3_DREQ.pin, buff, buff.length); | ||
} | ||
} | ||
@@ -705,2 +740,5 @@ | ||
process.once('audio_recording_complete', function recStopped(length) { | ||
process.unref(); | ||
// If a callback was provided, return it | ||
@@ -715,3 +753,2 @@ if (callback) { | ||
var ret = hw.audio_stop_recording(); | ||
if (ret < 0) { | ||
@@ -725,7 +762,8 @@ var err = new Error("Not in valid state to stop recording."); | ||
this.emit('error', err); | ||
return; | ||
} | ||
else { | ||
process.ref(); | ||
} | ||
} | ||
exports.use = use; |
{ | ||
"name": "audio-vs1053b", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 10 instances in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1976979
31
918
12