mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Bring in Karishmas changes from save-load to ensure the sound gets updated in storage when edited
This commit is contained in:
parent
2239d1b92b
commit
10789cd779
1 changed files with 24 additions and 2 deletions
|
@ -414,12 +414,34 @@ class VirtualMachine extends EventEmitter {
|
|||
* 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.
|
||||
* @param {ArrayBuffer} soundEncoding - the new (wav) encoded sound to be stored
|
||||
*/
|
||||
updateSoundBuffer (soundIndex, newBuffer) {
|
||||
const id = this.editingTarget.sprite.sounds[soundIndex].soundId;
|
||||
updateSoundBuffer (soundIndex, newBuffer, soundEncoding) {
|
||||
const sound = this.editingTarget.sprite.sounds[soundIndex];
|
||||
const id = sound ? sound.soundId : null;
|
||||
if (id && this.runtime && this.runtime.audioEngine) {
|
||||
this.runtime.audioEngine.updateSoundBuffer(id, newBuffer);
|
||||
}
|
||||
// Update sound in runtime
|
||||
if (soundEncoding) {
|
||||
// Now that we updated the sound, the format should also be updated
|
||||
// so that the sound can eventually be decoded the right way.
|
||||
// Sounds that were formerly 'adpcm', but were updated in sound editor
|
||||
// will not get decoded by the audio engine correctly unless the format
|
||||
// is updated as below.
|
||||
sound.format = '';
|
||||
const storage = this.runtime.storage;
|
||||
sound.assetId = storage.builtinHelper.cache(
|
||||
storage.AssetType.Sound,
|
||||
storage.DataFormat.WAV,
|
||||
soundEncoding
|
||||
);
|
||||
sound.md5 = `${sound.assetId}.${sound.dataFormat}`;
|
||||
}
|
||||
// If soundEncoding is null, it's because gui had a problem
|
||||
// encoding the updated sound. We don't want to store anything in this
|
||||
// case, and gui should have logged an error.
|
||||
|
||||
this.emitTargetsUpdate();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue