From 87ba4ea524a0b9ddc99dbd9f4362d8aef2a263bf Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Fri, 11 Sep 2020 00:09:07 +0200 Subject: [PATCH] fix audioworklet callbacks --- htdocs/lib/AudioEngine.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/htdocs/lib/AudioEngine.js b/htdocs/lib/AudioEngine.js index c907409..da6663c 100644 --- a/htdocs/lib/AudioEngine.js +++ b/htdocs/lib/AudioEngine.js @@ -54,6 +54,12 @@ AudioEngine.prototype._start = function() { } me.started = true; + var runCallbacks = function(workletType) { + var callbacks = me.onStartCallbacks; + me.onStartCallbacks = false; + callbacks.forEach(function(c) { c(workletType); }); + }; + me.gainNode = me.audioContext.createGain(); me.gainNode.connect(me.audioContext.destination); @@ -80,7 +86,7 @@ AudioEngine.prototype._start = function() { } }); me.audioNode.port.start(); - me.workletType = 'AudioWorklet'; + runCallbacks('AudioWorklet'); }); } else { me.audioBuffers = []; @@ -135,14 +141,10 @@ AudioEngine.prototype._start = function() { me.audioNode = me.audioContext[method](bufferSize, 0, 1); me.audioNode.onaudioprocess = audio_onprocess; me.audioNode.connect(me.gainNode); - me.workletType = 'ScriptProcessorNode'; + runCallbacks('ScriptProcessorNode') } setInterval(me.reportStats.bind(me), 1000); - - var callbacks = this.onStartCallbacks; - this.onStartCallbacks = false; - callbacks.forEach(function(c) { c(me.workletType); }); }; AudioEngine.prototype.onStart = function(callback) {