From dca92707305af9fd9277484c2adfef0e0379a2ab Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Fri, 13 Apr 2018 11:20:16 -0400 Subject: [PATCH 1/2] Use sound returned from audio engine to set sample rate and sample count since the sound gets resampled by the audio engine. Also, check for an mp3 format in deserialize assets, and otherwise default to wav. --- src/import/load-sound.js | 7 +++++++ src/serialization/deserialize-assets.js | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/import/load-sound.js b/src/import/load-sound.js index c14e5276d..517cb6848 100644 --- a/src/import/load-sound.js +++ b/src/import/load-sound.js @@ -22,6 +22,13 @@ const loadSoundFromAsset = function (sound, soundAsset, runtime) { {data: soundAsset.data} )).then(soundId => { sound.soundId = soundId; + // Set the sound sample rate and sample count based on the + // the audio buffer from the audio engine since the sound + // gets resampled by the audio engine + const soundBuffer = runtime.udioEngine.getSoundBuffer(soundId); + sound.rate = soundBuffer.sampleRate; + sound.sampleCount = soundBuffer.length; + return sound; }); }; diff --git a/src/serialization/deserialize-assets.js b/src/serialization/deserialize-assets.js index 29cae9109..6a49b9a2e 100644 --- a/src/serialization/deserialize-assets.js +++ b/src/serialization/deserialize-assets.js @@ -38,10 +38,8 @@ const deserializeSound = function (sound, runtime, zip, assetFileName) { log.error(`Could not find sound file associated with the ${sound.name} sound.`); return Promise.resolve(null); } - let dataFormat = null; - if (sound.dataFormat.toLowerCase() === 'wav') { - dataFormat = storage.DataFormat.WAV; - } + const dataFormat = sound.dataFormat.toLowerCase() === 'mp3' ? + storage.DataFormat.MP3 : storage.DataFormat.WAV; if (!JSZip.support.uint8array) { log.error('JSZip uint8array is not supported in this browser.'); return Promise.resolve(null); From e71e51866fd56a080aca28bfc1ea3f33101c7663 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Fri, 13 Apr 2018 11:28:04 -0400 Subject: [PATCH 2/2] Fix typo. --- src/import/load-sound.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/import/load-sound.js b/src/import/load-sound.js index 517cb6848..e13db14d2 100644 --- a/src/import/load-sound.js +++ b/src/import/load-sound.js @@ -25,7 +25,7 @@ const loadSoundFromAsset = function (sound, soundAsset, runtime) { // Set the sound sample rate and sample count based on the // the audio buffer from the audio engine since the sound // gets resampled by the audio engine - const soundBuffer = runtime.udioEngine.getSoundBuffer(soundId); + const soundBuffer = runtime.audioEngine.getSoundBuffer(soundId); sound.rate = soundBuffer.sampleRate; sound.sampleCount = soundBuffer.length;