diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-09-13 03:06:34 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-09-15 11:56:21 +0200 |
commit | d187bb4e11182ee3edbc0008dba5762148bc530d (patch) | |
tree | d0d3b7b75610599bce87d35e40012605cce11fdf /platform | |
parent | f2c44949c07e5ec2aadf519fca98e5bb1517f74c (diff) |
[HTML5] Use browser mix rate by default on the Web.
Browsers doesn't really like forcing the mix rate, e.g. Firefox does not
allow input (microphone) if the mix rate is not the default one, Chrom*
will exhibit worse performances, etc.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/javascript/audio_driver_javascript.cpp | 2 | ||||
-rw-r--r-- | platform/javascript/godot_audio.h | 2 | ||||
-rw-r--r-- | platform/javascript/js/libs/library_godot_audio.js | 17 |
3 files changed, 14 insertions, 7 deletions
diff --git a/platform/javascript/audio_driver_javascript.cpp b/platform/javascript/audio_driver_javascript.cpp index 478e848675..420cb2f2f7 100644 --- a/platform/javascript/audio_driver_javascript.cpp +++ b/platform/javascript/audio_driver_javascript.cpp @@ -108,7 +108,7 @@ Error AudioDriverJavaScript::init() { mix_rate = GLOBAL_GET("audio/driver/mix_rate"); int latency = GLOBAL_GET("audio/driver/output_latency"); - channel_count = godot_audio_init(mix_rate, latency, &_state_change_callback, &_latency_update_callback); + channel_count = godot_audio_init(&mix_rate, latency, &_state_change_callback, &_latency_update_callback); buffer_length = closest_power_of_2((latency * mix_rate / 1000)); #ifndef NO_THREADS node = memnew(WorkletNode); diff --git a/platform/javascript/godot_audio.h b/platform/javascript/godot_audio.h index 54fc8fa3b5..de8f046bbd 100644 --- a/platform/javascript/godot_audio.h +++ b/platform/javascript/godot_audio.h @@ -38,7 +38,7 @@ extern "C" { #include "stddef.h" extern int godot_audio_is_available(); -extern int godot_audio_init(int p_mix_rate, int p_latency, void (*_state_cb)(int), void (*_latency_cb)(float)); +extern int godot_audio_init(int *p_mix_rate, int p_latency, void (*_state_cb)(int), void (*_latency_cb)(float)); extern void godot_audio_resume(); extern int godot_audio_capture_start(); diff --git a/platform/javascript/js/libs/library_godot_audio.js b/platform/javascript/js/libs/library_godot_audio.js index 45c3a3fe2e..c9dae1a7af 100644 --- a/platform/javascript/js/libs/library_godot_audio.js +++ b/platform/javascript/js/libs/library_godot_audio.js @@ -37,10 +37,14 @@ const GodotAudio = { interval: 0, init: function (mix_rate, latency, onstatechange, onlatencyupdate) { - const ctx = new (window.AudioContext || window.webkitAudioContext)({ - sampleRate: mix_rate, - // latencyHint: latency / 1000 // Do not specify, leave 'interactive' for good performance. - }); + const opts = {}; + // If mix_rate is 0, let the browser choose. + if (mix_rate) { + opts['sampleRate'] = mix_rate; + } + // Do not specify, leave 'interactive' for good performance. + // opts['latencyHint'] = latency / 1000; + const ctx = new (window.AudioContext || window.webkitAudioContext)(opts); GodotAudio.ctx = ctx; ctx.onstatechange = function () { let state = 0; @@ -159,7 +163,10 @@ const GodotAudio = { godot_audio_init: function (p_mix_rate, p_latency, p_state_change, p_latency_update) { const statechange = GodotRuntime.get_func(p_state_change); const latencyupdate = GodotRuntime.get_func(p_latency_update); - return GodotAudio.init(p_mix_rate, p_latency, statechange, latencyupdate); + const mix_rate = GodotRuntime.getHeapValue(p_mix_rate, 'i32'); + const channels = GodotAudio.init(mix_rate, p_latency, statechange, latencyupdate); + GodotRuntime.setHeapValue(p_mix_rate, GodotAudio.ctx.sampleRate, 'i32'); + return channels; }, godot_audio_resume__sig: 'v', |