[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-10-02 13:49:00 +02:00
parent 80b34ccee1
commit a618535628
5 changed files with 314 additions and 185 deletions

View File

@ -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;