From d48458b80f8e0e15025d86307d04cb6758294e8f Mon Sep 17 00:00:00 2001 From: meew0 Date: Tue, 5 Apr 2016 17:33:14 +0200 Subject: [PATCH] Add an extra range check to the volume transformer, should hopefully fix #193 --- lib/Voice/VolumeTransformer.js | 7 +++++++ src/Voice/VolumeTransformer.js | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/Voice/VolumeTransformer.js b/lib/Voice/VolumeTransformer.js index 29cbfb176..ad01b6614 100644 --- a/lib/Voice/VolumeTransformer.js +++ b/lib/Voice/VolumeTransformer.js @@ -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)); diff --git a/src/Voice/VolumeTransformer.js b/src/Voice/VolumeTransformer.js index 87b9d0521..17cfb8136 100644 --- a/src/Voice/VolumeTransformer.js +++ b/src/Voice/VolumeTransformer.js @@ -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));