Skip to content

Commit e477fa2

Browse files
authored
fixed repeated initilisation of audioWorklet (#593)
* fixed repeated initilisation of audioWorklet * fixed some mistakes
1 parent 0dc20e2 commit e477fa2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/audioWorklet/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const moduleSources = [
55
require('raw-loader!./amplitudeProcessor').default,
66
];
77
const ac = p5sound.audiocontext;
8+
let initializedAudioWorklets = false;
89

910
function loadAudioWorkletModules() {
1011
return Promise.all(
@@ -17,6 +18,7 @@ function loadAudioWorkletModules() {
1718
}
1819

1920
p5.prototype.registerMethod('init', function () {
21+
if (initializedAudioWorklets) return;
2022
// ensure that a preload function exists so that p5 will wait for preloads to finish
2123
if (!this.preload && !window.preload) {
2224
this.preload = function () {};
@@ -25,6 +27,7 @@ p5.prototype.registerMethod('init', function () {
2527
// use p5's preload system to load necessary AudioWorklet modules before setup()
2628
this._incrementPreload();
2729
const onWorkletModulesLoad = function () {
30+
initializedAudioWorklets = true;
2831
this._decrementPreload();
2932
}.bind(this);
3033
loadAudioWorkletModules().then(onWorkletModulesLoad);

0 commit comments

Comments
 (0)