Lemon64 threads: SID and ADSR re-triggering? (2008) / Hard restart – what's the story? (2015)

author Schema, tfg, iAN CooG, Lasse (Öörni); commodorejohn, flavioweb, encore
date 2008-05-12 to 2008-05-13; 2015-02-01 to 2015-02-02
article two short forum threads on the SID envelope bug and hard restart
source url https://www.lemon64.com/forum/viewtopic.php?t=26968 and https://www.lemon64.com/forum/viewtopic.php?p=659158
created 2026-08-30 · updated 2026-08-31

Two short Lemon64 forum threads that between them give the practical understanding of the sid envelope problem behind hard-restart. In the first (2008, 4 posts) a game coder cannot retrigger a sound effect; lasse-oorni explains why. In the second (2015, 6 posts) someone writing their own play routine asks what the failure mode actually is and gets three workable strategies.

Key claims#

  • Symptom (Schema, 2008): a "boom" effect on voice 2 — AD $0F, SR $0B (2.4 s release), waveform $81 written then $80 immediately — plays once, but retriggering it "within 2.4 seconds" gives nothing.
  • Fix (iAN CooG): before retriggering, write $09 (gate + test bit) to the control register, wait at least two frames, then $00, then set up ADSR/pitch and gate on. Posted as a complete BASIC-stub assembly listing with a frame-wait loop on $D012.
  • Why (Lasse): "the sid oscillator will be reset immediately when setting testbit. But the testbit doesn't affect the envelope generator at all, and you need the minimum 2 frame period with gatebit off to be safe. … trying to trigger a sound when the envelope is still at max. volume will result in silence and lockup that lasts until the gatebit gets cleared again."
  • What hard restart is and isn't (2015 thread): commodorejohn, building a player with "a synthesizer-style envelope+LFO approach" rather than GoatTracker's "list-of-delta-values", finds explanations amount to "recite the magic incantation x frames before the next note" and dislikes cutting notes "a very audible fraction of a second" early. encore: the test-bit pulse trick from codebase64 (flavioweb's link) is a different subject ("reset"); the envelope bug is "completely deterministic from an emulators point of view" — read reSID's envelope.h around line 118 (also in VICE) — but hard to be deterministic about from 6502 code. His three routes: 1. hard restart; 2. find "safe ADSR-values in a song where the bug never triggers (and this depends entirely on the situation/arrangement/instrument/bpm)"; 3. "keep a voice continuously in its sustain mode and simulating new notes with changes in pwm or filter instead."
  • Pointers given: codebase64 for the pulse-by-test-bit technique; an earlier Lemon64 thread with Cadaver's detailed replies; the reSID/VICE envelope source.

Practical takeaways#

Two frames of gate-off before every note is the whole recipe; the test bit is for the oscillator (and the noise lock-up), not for the envelope. If hard restart's clipped tails bother you, the alternatives are ADSR values chosen per song or a sustained voice animated by PWM/filter.

Notable quotes#

Lasse: "the testbit doesn't affect the envelope generator at all, and you need the minimum 2 frame period with gatebit off to be safe."

commodorejohn: "in order to ward off the Envelope Gremlins you must recite the magic incantation x frames before the next note."

Pages touched#

hard-restart · adsr-envelope · sid · ring-modulation-and-sync · lasse-oorni · goattracker · sound-effects

source file wiki/summaries/s-lemon64-hard-restart-threads.md · graph