From 6f32a0bec7869bd6d0085330fda51687ee3ffc62 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 8 Jan 2019 11:28:40 -0500 Subject: [PATCH 1/3] Handle empty sounds --- src/AudioEngine.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AudioEngine.js b/src/AudioEngine.js index db3ddad..c4e5805 100644 --- a/src/AudioEngine.js +++ b/src/AudioEngine.js @@ -154,6 +154,11 @@ class AudioEngine { // decoder If that fails, attempt to decode as ADPCM const decoding = decodeAudioData(this.audioContext, bufferCopy1) .catch(() => { + // If the file is empty, create an empty sound + if (sound.data.length === 0) { + return Promise.resolve(this.audioContext.createBuffer(1, 1, this.audioContext.sampleRate)); + } + // The audio context failed to parse the sound data // we gave it, so try to decode as 'adpcm' From db1c89fa34d63cbc30b99bb7f9f969969667f074 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 8 Jan 2019 12:11:53 -0500 Subject: [PATCH 2/3] Prevent error due to LIST chunks --- src/ArrayBufferStream.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ArrayBufferStream.js b/src/ArrayBufferStream.js index 86d62f2..e5b8a84 100644 --- a/src/ArrayBufferStream.js +++ b/src/ArrayBufferStream.js @@ -150,7 +150,17 @@ class ArrayBufferStream { * @return {number} the next 32 bit integer in the stream */ readInt32 () { - const val = new Int32Array(this.arrayBuffer, this._position, 1)[0]; + // const sliced = this.arrayBuffer.slice + let val; + if (this._position % 4 === 0) { + val = new Int32Array(this.arrayBuffer, this._position, 1)[0]; + } else { + // Cannot read Int32 directly out because offset is not multiple of 4 + // Need to slice out the values first + val = new Int32Array( + this.arrayBuffer.slice(this._position, this._position + 4) + )[0]; + } this._position += 4; // one 32 bit int is 4 bytes return val; } From 195be39c6e671d2cc9ec3d727e2675846dfe2f11 Mon Sep 17 00:00:00 2001 From: Eric Rosenbaum Date: Tue, 8 Jan 2019 12:40:32 -0500 Subject: [PATCH 3/3] Remove stray comment --- src/ArrayBufferStream.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ArrayBufferStream.js b/src/ArrayBufferStream.js index e5b8a84..92a3e1a 100644 --- a/src/ArrayBufferStream.js +++ b/src/ArrayBufferStream.js @@ -150,7 +150,6 @@ class ArrayBufferStream { * @return {number} the next 32 bit integer in the stream */ readInt32 () { - // const sliced = this.arrayBuffer.slice let val; if (this._position % 4 === 0) { val = new Int32Array(this.arrayBuffer, this._position, 1)[0];