add a latencyHint to improve audio playback

This commit is contained in:
Jakob Ketterl 2021-05-01 16:55:08 +02:00
parent 11568256ed
commit 53c5c0f045
1 changed files with 3 additions and 3 deletions

View File

@ -41,7 +41,7 @@ AudioEngine.prototype.buildAudioContext = function() {
var goodRates = [48000, 44100, 96000] var goodRates = [48000, 44100, 96000]
// let the browser chose the sample rate, if it is good, use it // let the browser chose the sample rate, if it is good, use it
var ctx = new ctxClass(); var ctx = new ctxClass({latencyHint: 'playback'});
if (goodRates.indexOf(ctx.sampleRate) >= 0) { if (goodRates.indexOf(ctx.sampleRate) >= 0) {
return ctx; return ctx;
} }
@ -49,7 +49,7 @@ AudioEngine.prototype.buildAudioContext = function() {
// if that didn't work, try if any of the good rates work // if that didn't work, try if any of the good rates work
if (goodRates.some(function(sr) { if (goodRates.some(function(sr) {
try { try {
ctx = new ctxClass({sampleRate: sr}); ctx = new ctxClass({sampleRate: sr, latencyHint: 'playback'});
return true; return true;
} catch (e) { } catch (e) {
return false; return false;
@ -60,7 +60,7 @@ AudioEngine.prototype.buildAudioContext = function() {
// fallback: let the browser decide // fallback: let the browser decide
// this may cause playback problems down the line // this may cause playback problems down the line
return new ctxClass(); return new ctxClass({latencyHint: 'playback'});
} }
AudioEngine.prototype.resume = function(){ AudioEngine.prototype.resume = function(){