From 6495facb029699a32d0fe3b47181cd44c63ff675 Mon Sep 17 00:00:00 2001 From: Shawn Date: Thu, 18 Jun 2026 18:23:01 -0400 Subject: [PATCH] fix: disable Python garbage collector to prevent 1s periodic audio pops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Default GC threshold (700 allocs) triggers ~every 1.4s in the real-time audio callback due to ~500 numpy allocs/sec. Each GC pause (10-50ms) exceeds the 5.3ms callback window at 256/48k, producing audible pops at ~1Hz intervals. Reference counting handles 99% of object cleanup — GC only handles cyclic garbage. Disabling it is safe for a process that exits cleanly (os reclaims everything). --- main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 4990488..a337ff0 100644 --- a/main.py +++ b/main.py @@ -838,7 +838,18 @@ def main() -> int: except Exception as exc: logger.warning("Could not set CPU governor (non-root?): %s", exc) - import argparse + # Disable Python garbage collector to prevent 10-50ms GC pauses in + # the real-time audio callback. At ~500 numpy allocs/sec in the + # pipeline, default GC (threshold=700) triggers every ~1.4s, + # causing audible pops. Reference counting handles 99% of cleanup. + try: + import gc + gc.disable() + logger.info("GC disabled for RT audio stability") + except Exception as exc: + logger.warning("Could not disable GC: %s", exc) + + logger.info("Pedal v2 starting up...") parser = argparse.ArgumentParser( description="Pi Multi-FX Pedal — real-time guitar multi-effects",