summaryrefslogtreecommitdiffstats
path: root/platform/javascript/audio_driver_javascript.cpp
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-10-23 18:33:20 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-11-10 11:42:51 +0100
commite2083871eb57e56fe637c3d8f6647ddb4ff539e0 (patch)
treea58669c68065541e0062f82d7edb45789d8f354f /platform/javascript/audio_driver_javascript.cpp
parent54cda5c3b8622c9168fcd5d1c68964ef7697b27e (diff)
downloadredot-engine-e2083871eb57e56fe637c3d8f6647ddb4ff539e0.tar.gz
[HTML5] Port JavaScript inline code to libraries.
The API is implemented in javascript, and generates C functions that can be called from godot. This allows much cleaner code replacing all `EM_ASM` calls in our C++ code with plain C function calls. This also gets rid of few hacks and comes with few optimizations (e.g. custom cursor shapes should be much faster now).
Diffstat (limited to 'platform/javascript/audio_driver_javascript.cpp')
-rw-r--r--platform/javascript/audio_driver_javascript.cpp34
1 files changed, 14 insertions, 20 deletions
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp
index ab6ed54cc8..2535ad1812 100644
--- a/platform/javascript/audio_driver_javascript.cpp
+++ b/platform/javascript/audio_driver_javascript.cpp
@@ -55,33 +55,33 @@ void AudioDriverJavaScript::_audio_thread_func(void *p_data) {
OS::get_singleton()->delay_usec(1000); // Give the browser some slack.
continue;
}
- obj->_js_driver_process();
+ obj->_audio_driver_process();
obj->needs_process = false;
obj->unlock();
}
}
#endif
-extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_process_start() {
+void AudioDriverJavaScript::_audio_driver_process_start() {
#ifndef NO_THREADS
- AudioDriverJavaScript::singleton->lock();
+ singleton->lock();
#else
- AudioDriverJavaScript::singleton->_js_driver_process();
+ singleton->_audio_driver_process();
#endif
}
-extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_process_end() {
+void AudioDriverJavaScript::_audio_driver_process_end() {
#ifndef NO_THREADS
- AudioDriverJavaScript::singleton->needs_process = true;
- AudioDriverJavaScript::singleton->unlock();
+ singleton->needs_process = true;
+ singleton->unlock();
#endif
}
-extern "C" EMSCRIPTEN_KEEPALIVE void audio_driver_process_capture(float sample) {
- AudioDriverJavaScript::singleton->process_capture(sample);
+void AudioDriverJavaScript::_audio_driver_process_capture(float p_sample) {
+ singleton->process_capture(p_sample);
}
-void AudioDriverJavaScript::_js_driver_process() {
+void AudioDriverJavaScript::_audio_driver_process() {
int sample_count = memarr_len(internal_buffer) / channel_count;
int32_t *stream_buffer = reinterpret_cast<int32_t *>(internal_buffer);
audio_server_process(sample_count, stream_buffer);
@@ -122,7 +122,7 @@ void AudioDriverJavaScript::start() {
#ifndef NO_THREADS
thread = Thread::create(_audio_thread_func, this);
#endif
- godot_audio_start(internal_buffer);
+ godot_audio_start(internal_buffer, &_audio_driver_process_start, &_audio_driver_process_end, &_audio_driver_process_capture);
}
void AudioDriverJavaScript::resume() {
@@ -153,18 +153,12 @@ void AudioDriverJavaScript::unlock() {
#endif
}
-void AudioDriverJavaScript::finish_async() {
-#ifndef NO_THREADS
- quit = true; // Ask thread to quit.
-#endif
- godot_audio_finish_async();
-}
-
void AudioDriverJavaScript::finish() {
#ifndef NO_THREADS
+ quit = true; // Ask thread to quit.
Thread::wait_to_finish(thread);
memdelete(thread);
- thread = NULL;
+ thread = nullptr;
#endif
if (internal_buffer) {
memdelete_arr(internal_buffer);
@@ -173,13 +167,13 @@ void AudioDriverJavaScript::finish() {
}
Error AudioDriverJavaScript::capture_start() {
- godot_audio_capture_stop();
input_buffer_init(buffer_length);
godot_audio_capture_start();
return OK;
}
Error AudioDriverJavaScript::capture_stop() {
+ godot_audio_capture_stop();
input_buffer.clear();
return OK;
}