Skip to content

Added a reset cache button because after prolonged use (2 days ish) the app begun ...#320

Open
alexandrosaur wants to merge 1 commit into
ronitsingh10:mainfrom
alexandrosaur:main
Open

Added a reset cache button because after prolonged use (2 days ish) the app begun ...#320
alexandrosaur wants to merge 1 commit into
ronitsingh10:mainfrom
alexandrosaur:main

Conversation

@alexandrosaur

Copy link
Copy Markdown

…corrupting sound having me close/reopen the app, now that can be accomplished by just going to the settings and clicking one button, The function does not affect any preexisting features and the test runs fine. The culprit was Opera playing Youtube and AppleMusic (lates versions both). tested with 2 output devs, unplug test and 4 diff audio input tests.

…corrupting sound having me close/reopen the app, now that can be accomplished by just going to the settings and clicking one button, The function does not affect any preexisting features and the test runs fine
@djbob2000

Copy link
Copy Markdown

Thanks for the PR! While the button works as a quick workaround, the actual sound corruption after prolonged use is caused by two underlying issues:

  1. Floating-point drift in LoudnessDetector:
    Updating the runningSquareSum incrementally (runningSquareSum += new - old) over billions of samples accumulates float precision rounding errors. After a couple of days, the sum drifts significantly. If it drifts negative, it clamps to -120 dB (silence), causing the equalizer to apply maximum gain boost, which leads to heavy digital clipping and distortion.

    • A cleaner fix: We can completely eliminate the drift by re-summing the ring buffer from scratch once every hop boundary (e.g., using ringBuffer.reduce(0, +)). Since this only happens every 10–40ms, the CPU impact is negligible.
  2. CoreAudio resampler clock drift with Opera/Apple Music:
    Because aggregate devices use drift compensation, they expect a stable clock. Opera (YouTube) and Apple Music frequently pause, resume, and switch sample rates (AAC vs Lossless tracks). This makes the tap clock unstable, causing CoreAudio’s drift compensation resampler to lose sync and start crackling after a long time.

Why the button helps: Pushing a cache reset in AudioEngine.swift triggers a device switch which destroys the old aggregate device/tap and creates a new one. This resets both CoreAudio's resampler and the loudness math sum.

@sjoerdiepro12

Copy link
Copy Markdown

i second this issue

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.

3 participants