You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-22 15:06:45 +00:00
[Web] Restore ScriptProcessorNode audio driver fallback
Godot has a ScriptProcessorNode audio driver implementation for the (deprecated) Web API. As reported by some users, this fallback was not properly re-added during the Godot 4 transition, and was left as "dead code". While the API is deprecated, it is still supported by most browsers, and some WebView may not implement AudioWorklet correctly (the new recommended API). This commit re-adds the ScriptProcessorNode implementation as a fallback if the AudioWorklet driver fails to initialized (and can be forced if desired via project settings as usual).
This commit is contained in:
@@ -479,6 +479,8 @@ void AudioDriverWorklet::_capture_callback(int p_pos, int p_samples) {
|
|||||||
driver->_audio_driver_capture(p_pos, p_samples);
|
driver->_audio_driver_capture(p_pos, p_samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // THREADS_ENABLED
|
||||||
|
|
||||||
/// ScriptProcessorNode implementation
|
/// ScriptProcessorNode implementation
|
||||||
AudioDriverScriptProcessor *AudioDriverScriptProcessor::singleton = nullptr;
|
AudioDriverScriptProcessor *AudioDriverScriptProcessor::singleton = nullptr;
|
||||||
|
|
||||||
@@ -497,5 +499,3 @@ Error AudioDriverScriptProcessor::create(int &p_buffer_samples, int p_channels)
|
|||||||
void AudioDriverScriptProcessor::start(float *p_out_buf, int p_out_buf_size, float *p_in_buf, int p_in_buf_size) {
|
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);
|
godot_audio_script_start(p_in_buf, p_in_buf_size, p_out_buf, p_out_buf_size, &_process_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // THREADS_ENABLED
|
|
||||||
|
|||||||
@@ -169,6 +169,8 @@ public:
|
|||||||
AudioDriverWorklet() { singleton = this; }
|
AudioDriverWorklet() { singleton = this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // THREADS_ENABLED
|
||||||
|
|
||||||
class AudioDriverScriptProcessor : public AudioDriverWeb {
|
class AudioDriverScriptProcessor : public AudioDriverWeb {
|
||||||
private:
|
private:
|
||||||
static void _process_callback();
|
static void _process_callback();
|
||||||
@@ -178,7 +180,6 @@ private:
|
|||||||
protected:
|
protected:
|
||||||
virtual Error create(int &p_buffer_size, int p_output_channels) override;
|
virtual Error create(int &p_buffer_size, int p_output_channels) override;
|
||||||
virtual void start(float *p_out_buf, int p_out_buf_size, float *p_in_buf, int p_in_buf_size) override;
|
virtual void start(float *p_out_buf, int p_out_buf_size, float *p_in_buf, int p_in_buf_size) override;
|
||||||
virtual void finish_driver() override;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual const char *get_name() const override { return "ScriptProcessor"; }
|
virtual const char *get_name() const override { return "ScriptProcessor"; }
|
||||||
@@ -191,6 +192,4 @@ public:
|
|||||||
AudioDriverScriptProcessor() { singleton = this; }
|
AudioDriverScriptProcessor() { singleton = this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // THREADS_ENABLED
|
|
||||||
|
|
||||||
#endif // AUDIO_DRIVER_WEB_H
|
#endif // AUDIO_DRIVER_WEB_H
|
||||||
|
|||||||
@@ -2160,7 +2160,7 @@ autoAddDeps(GodotAudioWorklet, '$GodotAudioWorklet');
|
|||||||
mergeInto(LibraryManager.library, GodotAudioWorklet);
|
mergeInto(LibraryManager.library, GodotAudioWorklet);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The ScriptProcessorNode API, used when threads are disabled.
|
* The ScriptProcessorNode API, used as a fallback if AudioWorklet is not available.
|
||||||
*/
|
*/
|
||||||
const GodotAudioScript = {
|
const GodotAudioScript = {
|
||||||
$GodotAudioScript__deps: ['$GodotAudio'],
|
$GodotAudioScript__deps: ['$GodotAudio'],
|
||||||
|
|||||||
@@ -275,6 +275,7 @@ OS_Web::OS_Web() {
|
|||||||
|
|
||||||
if (AudioDriverWeb::is_available()) {
|
if (AudioDriverWeb::is_available()) {
|
||||||
audio_drivers.push_back(memnew(AudioDriverWorklet));
|
audio_drivers.push_back(memnew(AudioDriverWorklet));
|
||||||
|
audio_drivers.push_back(memnew(AudioDriverScriptProcessor));
|
||||||
}
|
}
|
||||||
for (AudioDriverWeb *audio_driver : audio_drivers) {
|
for (AudioDriverWeb *audio_driver : audio_drivers) {
|
||||||
AudioDriverManager::add_driver(audio_driver);
|
AudioDriverManager::add_driver(audio_driver);
|
||||||
|
|||||||
Reference in New Issue
Block a user