Skip to content

Commit

Permalink
TODOisms
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgodbolt committed Dec 31, 2024
1 parent 40b71ba commit 7c04315
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/web/audio-renderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// TODO look into using https://www.npmjs.com/package/@alexanderolsen/libsamplerate-js or similar (the full API).
/*global sampleRate, currentTime*/
/*global sampleRate, currentTime */

const lowPassFilterFreq = sampleRate / 2;
const RC = 1 / (2 * Math.PI * lowPassFilterFreq);
Expand Down Expand Up @@ -82,6 +81,8 @@ class SoundChipProcessor extends AudioWorkletProcessor {
this.cleanQueue();
if (this.queue.length === 0) return true;

// I looked into using https://www.npmjs.com/package/@alexanderolsen/libsamplerate-js or similar (the full API),
// but we fiddle the sample rate here to catch up with the target latency, which is harder to do with that API.
const outByMs = this._queueAge() - this.targetLatencyMs;
const maxAdjust = this.inputSampleRate * 0.01;
const adjustment = Math.min(maxAdjust, Math.max(-maxAdjust, outByMs * 100));
Expand Down

0 comments on commit 7c04315

Please sign in to comment.