src/virtual-machine.js
/**
     * 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
     */
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
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, 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);
        }
        if (soundEncoding) {
            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}`;
        }
        this.emitTargetsUpdate();
    }
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 ) ; } if ( soundEncoding ) { 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 } ` ; } this . emitTargetsUpdate ( ) ; }
Update a sound buffer.
Update a sound buffer .
// Update sound in runtime // 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. // 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.