Skip to content

Commit

Permalink
fixed repeated initilisation of audioWorklet (#593)
Browse files Browse the repository at this point in the history
* fixed repeated initilisation of audioWorklet

* fixed some mistakes
  • Loading branch information
endurance21 authored Mar 20, 2021
1 parent 0dc20e2 commit e477fa2
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/audioWorklet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const moduleSources = [
require('raw-loader!./amplitudeProcessor').default,
];
const ac = p5sound.audiocontext;
let initializedAudioWorklets = false;

function loadAudioWorkletModules() {
return Promise.all(
Expand All @@ -17,6 +18,7 @@ function loadAudioWorkletModules() {
}

p5.prototype.registerMethod('init', function () {
if (initializedAudioWorklets) return;
// ensure that a preload function exists so that p5 will wait for preloads to finish
if (!this.preload && !window.preload) {
this.preload = function () {};
Expand All @@ -25,6 +27,7 @@ p5.prototype.registerMethod('init', function () {
// use p5's preload system to load necessary AudioWorklet modules before setup()
this._incrementPreload();
const onWorkletModulesLoad = function () {
initializedAudioWorklets = true;
this._decrementPreload();
}.bind(this);
loadAudioWorkletModules().then(onWorkletModulesLoad);
Expand Down

0 comments on commit e477fa2

Please sign in to comment.