Add an extra range check to the volume transformer, should hopefully fix #193

This commit is contained in:
meew0
2016-04-05 17:33:14 +02:00
parent 0e54d77025
commit d48458b80f
2 changed files with 14 additions and 0 deletions

View File

@@ -47,6 +47,13 @@ var Volume = (function (_Transform) {
var out = new Buffer(buffer.length);
for (var i = 0; i < buffer.length; i += 2) {
// Check whether the index is actually in range - sometimes it's possible
// that it skips ahead too far before the end condition of the for can
// kick in.
if (i >= buffer.length) {
break;
}
// Read Int16, multiple with multiplier and round down
//console.log(this.volume, this.multiplier, buffer.readInt16LE(i));
var uint = Math.floor(this.multiplier * buffer.readInt16LE(i));

View File

@@ -44,6 +44,13 @@ class Volume extends Transform {
let out = new Buffer(buffer.length);
for (let i = 0; i < buffer.length; i += 2) {
// Check whether the index is actually in range - sometimes it's possible
// that it skips ahead too far before the end condition of the for can
// kick in.
if (i >= buffer.length) {
break;
}
// Read Int16, multiple with multiplier and round down
//console.log(this.volume, this.multiplier, buffer.readInt16LE(i));
let uint = Math.floor(this.multiplier * buffer.readInt16LE(i));