Skip to content

fix(Oscillator): cache periodic waves by sample rate - #1528

Merged
tambien merged 2 commits into
Tonejs:devfrom
snowyukitty:fix/oscillator-wave-cache-sample-rate
Oct 22, 2026
Merged

tambien merged 2 commits into
Tonejs:devfrom
snowyukitty:fix/oscillator-wave-cache-sample-rate

Conversation

@snowyukitty

Copy link
Copy Markdown
Contributor

Fixes #1323.

The static Oscillator cache can reuse a native PeriodicWave created at a different sample rate. In Chromium, a 440 Hz rotated sine renders at approximately 480 Hz after warming the cache at 44.1 kHz and rendering at 48 kHz; reversing the rates gives approximately 404 Hz. FatOscillator also reaches this cache through its phase-shifted oscillators.

Include the context's sampleRate in both cache lookups and in each entry. Same-rate reuse and the existing 100-entry limit are preserved.

Eight browser regression tests compare rendered rotated/custom sine waves with an analytic reference in both rate orders, plus same-rate controls that verify cache reuse. Against the original production source, the complete Oscillator test file has 54 passing tests and four failing mixed-rate cases; with the fix, all 58 pass.

Validation on Linux, Node 22.14.0 and Chromium 149:

  • npm test: 3,108 passed, 0 failed, 43 skipped (upstream: 3,100 passed, 43 skipped).
  • npm run lint, npm run spellcheck, npm run build, and Prettier checks for both changed files: passed. The build retains the upstream webpack bundle-size warnings.
  • Additional offline rendering checks confirmed creation-order independence for the default sawtooth FatOscillator and same-rate reuse after closing an online context.

Firefox validation was blocked by a browser automation timeout before a page could be created. Safari was not tested.

@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.92%. Comparing base (97cfc4d) to head (a16d53f).
⚠️ Report is 5 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #1528   +/-   ##
=======================================
  Coverage   98.92%   98.92%           
=======================================
  Files         209      209           
  Lines       23584    23608   +24     
  Branches     1030     1032    +2     
=======================================
+ Hits        23330    23354   +24     
  Misses        251      251           
  Partials        3        3           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tambien
tambien merged commit c10c498 into Tonejs:dev Oct 22, 2026
9 checks passed
@tambien

tambien commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

thanks so much for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent audio output between interactive and offline contexts when using Synths with Fat Oscillators

2 participants