From 5c4a88b739858694659edee8ff8ae6dc16df64ea Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Wed, 14 Jun 2017 09:10:35 -0400 Subject: [PATCH] Make a copy before using audio buffer --- src/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index bb544b0..fff1330 100644 --- a/src/index.js +++ b/src/index.js @@ -232,12 +232,15 @@ class AudioEngine { let loaderPromise = null; + // Make a copy of the buffer because decoding detaches the original buffer + var bufferCopy = sound.data.buffer.slice(0); + switch (sound.format) { case '': - loaderPromise = Tone.context.decodeAudioData(sound.data.buffer); + loaderPromise = Tone.context.decodeAudioData(bufferCopy); break; case 'adpcm': - loaderPromise = (new ADPCMSoundDecoder()).decode(sound.data.buffer); + loaderPromise = (new ADPCMSoundDecoder()).decode(bufferCopy); break; default: return log.warn('unknown sound format', sound.format);