diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-09-15 20:33:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-15 20:33:42 +0200 |
commit | e902347a8cefbced8898dfc9f000afdf3be0d36a (patch) | |
tree | 76da65450a57b77066b9eb7e74ff82be5e36f814 /platform/javascript/js | |
parent | a2b727ed38c59128a580827f77c7a10ea9950e93 (diff) | |
parent | d187bb4e11182ee3edbc0008dba5762148bc530d (diff) |
Merge pull request #52695 from Faless/js/4.x_audio_mix_rate
[HTML5] Use browser mix rate by default on the Web.
Diffstat (limited to 'platform/javascript/js')
-rw-r--r-- | platform/javascript/js/libs/library_godot_audio.js | 17 |
1 files changed, 12 insertions, 5 deletions
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', |