[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).
This commit is contained in:
Fabio Alessandrelli 2020-09-28 15:43:48 +02:00
parent a57bd798cd
commit 61d4b8045c
5 changed files with 331 additions and 186 deletions

View file

@ -31,18 +31,33 @@
#ifndef AUDIO_DRIVER_JAVASCRIPT_H
#define AUDIO_DRIVER_JAVASCRIPT_H
#include "core/os/mutex.h"
#include "core/os/thread.h"
#include "servers/audio_server.h"
class AudioDriverJavaScript : public AudioDriver {
private:
float *internal_buffer;
int _driver_id;
int buffer_length;
int mix_rate;
int channel_count;
public:
#ifndef NO_THREADS
Mutex *mutex;
Thread *thread;
bool quit;
bool needs_process;
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;