diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2020-10-02 13:49:00 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2020-10-02 14:28:20 +0200 |
commit | a618535628176e519494a84fd3b04c32fa2a9d64 (patch) | |
tree | ef18f3ae3aab8e2da31ebbf0dc3533d231fd945b /platform/javascript/audio_driver_javascript.h | |
parent | 80b34ccee13967abfc40bfca993be9034f9fdfc4 (diff) | |
download | redot-engine-a618535628176e519494a84fd3b04c32fa2a9d64.tar.gz |
[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).
Diffstat (limited to 'platform/javascript/audio_driver_javascript.h')
-rw-r--r-- | platform/javascript/audio_driver_javascript.h | 19 |
1 files changed, 17 insertions, 2 deletions
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; |