Skip to content

Commit

Permalink
Log baseLatency only once
Browse files Browse the repository at this point in the history
  • Loading branch information
sonph committed Apr 23, 2020
1 parent 702dbae commit 8f1c399
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/js/audio.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Audio {
constructor() {
/** @type {!AudioContext} */
this.audioContext = new AudioContext({ latencyHint: 'interactive' });
this.baseLatency = 0;
this.baseLatency = null;

/** @type {boolean} Whether audio context has been unlocked. */
this.unlocked = false;
Expand Down Expand Up @@ -48,12 +48,11 @@ class Audio {
* See https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/baseLatency
*/
getBaseLatency() {
if (this.baseLatency != 0) {
if (this.baseLatency !== null) {
return this.baseLatency;
}
if (this.audioContext.state === 'running'
&& 'baseLatency' in this.audioContext) {
this.baseLatency = this.audioContext.baseLatency;
if (this.audioContext.state === 'running') {
this.baseLatency = this.audioContext.baseLatency || 0;
utils.log('AudioContext base latency: $ secs',
this.baseLatency.toFixed(6));
return this.baseLatency;
Expand Down

0 comments on commit 8f1c399

Please # to comment.