From 2334ad1d5b2f2b22325f2773927d120e5f95f096 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Thu, 14 Jan 2021 17:07:43 +0100 Subject: [PATCH] try a list of sample rates; prefer 48kHz --- htdocs/lib/AudioEngine.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/htdocs/lib/AudioEngine.js b/htdocs/lib/AudioEngine.js index eb7fa4f..fb08bfc 100644 --- a/htdocs/lib/AudioEngine.js +++ b/htdocs/lib/AudioEngine.js @@ -14,9 +14,17 @@ function AudioEngine(maxBufferLength, audioReporter) { this.onStartCallbacks = []; this.started = false; - try { - this.audioContext = new ctx({sampleRate: 44100}); - } catch (error) { + // try common working sample rates + if (![48000, 44100].some(function(sr) { + try { + this.audioContext = new ctx({sampleRate: sr}); + return true; + } catch (e) { + return false; + } + }, this)) { + // fallback: let the browser decide + // this may cause playback problems down the line this.audioContext = new ctx(); } var me = this;