You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Add THREADS_ENABLED macro in order to compile Godot to run on the main thread
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
|
||||
#include "audio_driver_web.h"
|
||||
|
||||
#include "godot_audio.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
|
||||
#include <emscripten.h>
|
||||
@@ -184,6 +186,8 @@ Error AudioDriverWeb::input_stop() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
#ifdef THREADS_ENABLED
|
||||
|
||||
/// AudioWorkletNode implementation (threads)
|
||||
void AudioDriverWorklet::_audio_thread_func(void *p_data) {
|
||||
AudioDriverWorklet *driver = static_cast<AudioDriverWorklet *>(p_data);
|
||||
@@ -245,3 +249,51 @@ void AudioDriverWorklet::finish_driver() {
|
||||
quit = true; // Ask thread to quit.
|
||||
thread.wait_to_finish();
|
||||
}
|
||||
|
||||
#else // No threads.
|
||||
|
||||
/// AudioWorkletNode implementation (no threads)
|
||||
AudioDriverWorklet *AudioDriverWorklet::singleton = nullptr;
|
||||
|
||||
Error AudioDriverWorklet::create(int &p_buffer_size, int p_channels) {
|
||||
if (!godot_audio_has_worklet()) {
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
return (Error)godot_audio_worklet_create(p_channels);
|
||||
}
|
||||
|
||||
void AudioDriverWorklet::start(float *p_out_buf, int p_out_buf_size, float *p_in_buf, int p_in_buf_size) {
|
||||
_audio_driver_process();
|
||||
godot_audio_worklet_start_no_threads(p_out_buf, p_out_buf_size, &_process_callback, p_in_buf, p_in_buf_size, &_capture_callback);
|
||||
}
|
||||
|
||||
void AudioDriverWorklet::_process_callback(int p_pos, int p_samples) {
|
||||
AudioDriverWorklet *driver = AudioDriverWorklet::get_singleton();
|
||||
driver->_audio_driver_process(p_pos, p_samples);
|
||||
}
|
||||
|
||||
void AudioDriverWorklet::_capture_callback(int p_pos, int p_samples) {
|
||||
AudioDriverWorklet *driver = AudioDriverWorklet::get_singleton();
|
||||
driver->_audio_driver_capture(p_pos, p_samples);
|
||||
}
|
||||
|
||||
/// ScriptProcessorNode implementation
|
||||
AudioDriverScriptProcessor *AudioDriverScriptProcessor::singleton = nullptr;
|
||||
|
||||
void AudioDriverScriptProcessor::_process_callback() {
|
||||
AudioDriverScriptProcessor::get_singleton()->_audio_driver_capture();
|
||||
AudioDriverScriptProcessor::get_singleton()->_audio_driver_process();
|
||||
}
|
||||
|
||||
Error AudioDriverScriptProcessor::create(int &p_buffer_samples, int p_channels) {
|
||||
if (!godot_audio_has_script_processor()) {
|
||||
return ERR_UNAVAILABLE;
|
||||
}
|
||||
return (Error)godot_audio_script_create(&p_buffer_samples, p_channels);
|
||||
}
|
||||
|
||||
void AudioDriverScriptProcessor::start(float *p_out_buf, int p_out_buf_size, float *p_in_buf, int p_in_buf_size) {
|
||||
godot_audio_script_start(p_in_buf, p_in_buf_size, p_out_buf, p_out_buf_size, &_process_callback);
|
||||
}
|
||||
|
||||
#endif // THREADS_ENABLED
|
||||
|
||||
Reference in New Issue
Block a user