From 25a0e2ffaff936187397b1ec384ecdb979cebc59 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Tue, 25 Jul 2017 12:39:30 -0400 Subject: [PATCH] Use new audio engine api to retreive and set sound buffers --- src/virtual-machine.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 0cc3b7bb..29d35f3f 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -333,6 +333,32 @@ class VirtualMachine extends EventEmitter { this.emitTargetsUpdate(); } + /** + * Get a sound buffer from the audio engine. + * @param {int} soundIndex - the index of the sound to be got. + * @return {AudioBuffer} the sound's audio buffer. + */ + getSoundBuffer (soundIndex) { + const id = this.editingTarget.sprite.sounds[soundIndex].soundId; + if (id && this.runtime && this.runtime.audioEngine) { + return this.runtime.audioEngine.getSoundBuffer(id); + } + return null; + } + + /** + * Update a sound buffer. + * @param {int} soundIndex - the index of the sound to be updated. + * @param {AudioBuffer} newBuffer - new audio buffer for the audio engine. + */ + updateSoundBuffer (soundIndex, newBuffer) { + const id = this.editingTarget.sprite.sounds[soundIndex].soundId; + if (id && this.runtime && this.runtime.audioEngine) { + this.runtime.audioEngine.updateSoundBuffer(id, newBuffer); + } + this.emitTargetsUpdate(); + } + /** * Delete a sound from the current editing target. * @param {int} soundIndex - the index of the sound to be removed.