From a618535628176e519494a84fd3b04c32fa2a9d64 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Fri, 2 Oct 2020 13:49:00 +0200 Subject: [HTML5] Run Audio process in thread when available This should fix some of the audio stuttering issues when the HTML5 export is compiled with threads support. The API should be ported to AudioWorklet to (hopefully) be perfect. That though, cannot be backported to 3.2 due to extra restriction of AudioWorklet (which only runs in SecureContext, and needs a polyfill for Safari). --- platform/javascript/audio_driver_javascript.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'platform/javascript/audio_driver_javascript.h') diff --git a/platform/javascript/audio_driver_javascript.h b/platform/javascript/audio_driver_javascript.h index c1607301d7..56a7da0307 100644 --- a/platform/javascript/audio_driver_javascript.h +++ b/platform/javascript/audio_driver_javascript.h @@ -33,15 +33,30 @@ #include "servers/audio_server.h" +#include "core/os/mutex.h" +#include "core/os/thread.h" + class AudioDriverJavaScript : public AudioDriver { +private: float *internal_buffer = nullptr; - int _driver_id = 0; int buffer_length = 0; + int mix_rate = 0; + int channel_count = 0; public: +#ifndef NO_THREADS + Mutex mutex; + Thread *thread = nullptr; + bool quit = false; + bool needs_process = true; + + static void _audio_thread_func(void *p_data); +#endif + + void _js_driver_process(); + static bool is_available(); - void mix_to_js(); void process_capture(float sample); static AudioDriverJavaScript *singleton; -- cgit v1.2.3