summaryrefslogtreecommitdiff
path: root/doc/archive/PEAK_FIX_SUMMARY.md
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-08 21:28:40 +0100
committerskal <pascal.massimino@gmail.com>2026-02-08 21:28:40 +0100
commitd3a609fad91744c45f6bc59b625a26f8870e271d (patch)
tree002b224a216f0710cb6df9823570814628b05203 /doc/archive/PEAK_FIX_SUMMARY.md
parentf6324b0b5d65aef6e713e8b902a6b689659dd27f (diff)
docs: Archive historical documentation (26 files → doc/archive/)
Moved completed/historical docs to doc/archive/ for cleaner context: Archived (26 files): - Analysis docs: variable tempo, audio architecture, build optimization - Handoff docs: 6 agent handoff documents - Debug reports: shadows, peak meter, timing fixes - Task summaries and planning docs Kept (16 files): - Essential: AI_RULES, HOWTO, CONTRIBUTING, CONTEXT_MAINTENANCE - Active subsystems: 3D, ASSET_SYSTEM, TRACKER, SEQUENCE - Current work: MASKING_SYSTEM, SPECTRAL_BRUSH_EDITOR Updated COMPLETED.md with archive index for easy reference.
Diffstat (limited to 'doc/archive/PEAK_FIX_SUMMARY.md')
-rw-r--r--doc/archive/PEAK_FIX_SUMMARY.md78
1 files changed, 78 insertions, 0 deletions
diff --git a/doc/archive/PEAK_FIX_SUMMARY.md b/doc/archive/PEAK_FIX_SUMMARY.md
new file mode 100644
index 0000000..cf42233
--- /dev/null
+++ b/doc/archive/PEAK_FIX_SUMMARY.md
@@ -0,0 +1,78 @@
+# Audio Peak Measurement Fix Summary
+
+## Issues Found and Fixed
+
+### Issue #1: Peak Measured at Wrong Time (❌ FIXED)
+**Problem:** Peak was measured when audio was written to ring buffer (~400ms before playback), causing visual effects to trigger 400ms early.
+
+**Solution:**
+- Added `get_realtime_peak()` to AudioBackend interface
+- Implemented real-time peak measurement in audio callback when samples are actually played
+- Updated main.cc and test_demo.cc to use `audio_get_realtime_peak()` instead of `synth_get_output_peak()`
+
+**Files Modified:**
+- src/audio/audio_backend.h
+- src/audio/miniaudio_backend.h/cc
+- src/audio/mock_audio_backend.h/cc
+- src/audio/wav_dump_backend.h/cc
+- src/audio/jittered_audio_backend.h/cc
+- src/audio/audio.h/cc
+- src/main.cc
+- src/test_demo.cc
+- src/tests/test_audio_backend.cc
+
+### Issue #2: Peak Decay Too Slow (❌ FIXED)
+**Problem:** Peak decay rate of 0.95 per callback meant visual effects stayed bright for ~6 seconds after a drum hit, causing constant flashing.
+
+**Root Cause Analysis:**
+- Decay rate: 0.95 per callback
+- Callback interval: ~128ms
+- Time to decay to 10%: **~5.76 seconds** (45 callbacks)
+- Result: Screen stays white for 6+ seconds after each drum hit
+
+**Solution:**
+- Changed decay rate from 0.95 to 0.7
+- New decay timing:
+ - 50% intensity: ~256ms (2 callbacks)
+ - 10% intensity: ~1.15 seconds (9 callbacks)
+- Result: Quick flash with smooth fade, proper visual sync
+
+**Decay Comparison:**
+```
+Old (0.95): ████████████████████████████ (6 seconds to fade)
+New (0.7): ████ (1 second to fade)
+```
+
+**File Modified:**
+- src/audio/miniaudio_backend.cc (line 164)
+
+## Verification
+
+✅ All 27 tests pass
+✅ demo64k builds successfully
+✅ test_demo builds successfully
+✅ Peak decay timing verified mathematically
+✅ Audio-visual sync should now be accurate
+
+## Testing Instructions
+
+Run test_demo to verify the fix:
+```bash
+./build/test_demo
+```
+
+Expected behavior:
+- Screen should flash white on drum hits (every ~0.5 seconds)
+- Flash should fade quickly (~1 second)
+- No constant white screen
+- Audio and visual should be synchronized
+
+## Known Build Issues (Pre-existing)
+
+The following tests have linker errors (unrelated to peak measurement fix):
+- test_effect_base (missing WebGPUTestFixture)
+- test_post_process_helper (missing main)
+- test_texture_manager (missing main)
+- test_demo_effects (missing main)
+
+These appear to be incomplete test implementations and should be addressed separately.