From 726ae79dd3ba8f368d3a671f371e747c33195edd Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 7 Feb 2026 19:22:43 +0100 Subject: refactor(audio): Convert tracker to unit-less timing system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes tracker timing from beat-based to unit-less system to separate musical structure from BPM-dependent playback speed. TIMING CONVENTION: - 1 unit = 4 beats (by convention) - Conversion: seconds = units * (4 / BPM) * 60 - At 120 BPM: 1 unit = 2 seconds BENEFITS: - Pattern structure independent of BPM - BPM changes only affect playback speed, not structure - Easier pattern composition (0.00-1.00 for typical 4-beat pattern) - Fixes issue where patterns played for 2s instead of expected duration DATA STRUCTURES (tracker.h): - TrackerEvent.beat → TrackerEvent.unit_time - TrackerPattern.num_beats → TrackerPattern.unit_length - TrackerPatternTrigger.time_sec → TrackerPatternTrigger.unit_time RUNTIME (tracker.cc): - Added BEATS_PER_UNIT constant (4.0) - Convert units to seconds at playback time using BPM - Pattern remains active for full unit_length duration - Fixed premature pattern deactivation bug COMPILER (tracker_compiler.cc): - Parse LENGTH parameter from PATTERN lines (defaults to 1.0) - Parse unit_time instead of beat values - Generate code with unit-less timing ASSETS: - test_demo.track: converted to unit-less (8 score triggers) - music.track: converted to unit-less (all patterns) - Events: beat/4 conversion (e.g., beat 2.0 → unit 0.50) - Score: seconds/unit_duration (e.g., 4s → 2.0 units at 120 BPM) VISUALIZER (track_visualizer/index.html): - Parse LENGTH parameter and BPM directive - Convert unit-less time to seconds for rendering - Update tick positioning to use unit_time - Display correct pattern durations DOCUMENTATION (doc/TRACKER.md): - Added complete .track format specification - Timing conversion reference table - Examples with unit-less timing - Pattern LENGTH parameter documentation FILES MODIFIED: - src/audio/tracker.{h,cc} (data structures + runtime conversion) - tools/tracker_compiler.cc (parser + code generation) - assets/{test_demo,music}.track (converted to unit-less) - tools/track_visualizer/index.html (BPM-aware rendering) - doc/TRACKER.md (format documentation) - convert_track.py (conversion utility script) TEST RESULTS: - test_demo builds and runs correctly - demo64k builds successfully - Generated code verified (unit-less values in music_data.cc) Co-Authored-By: Claude Sonnet 4.5 --- assets/test_demo.track | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'assets/test_demo.track') diff --git a/assets/test_demo.track b/assets/test_demo.track index 9d6bdf4..6ae5c67 100644 --- a/assets/test_demo.track +++ b/assets/test_demo.track @@ -1,28 +1,36 @@ # Minimal drum beat for audio/visual sync testing # Pattern: kick-snare-kick-snare, crash every 4th bar # Includes NOTE_A4 (440 Hz) at start of each bar for testing +# +# TIMING: Unit-less (1 unit = 4 beats at 120 BPM = 2 seconds) +# Pattern events use unit-less time (0.0-1.0 for 4-beat pattern) +# Score triggers use unit-less time SAMPLE ASSET_KICK_1 SAMPLE ASSET_SNARE_1 SAMPLE ASSET_CRASH_1 -PATTERN drums_basic - 0.0, ASSET_KICK_1, 1.0, 0.0 - 0.0, NOTE_A4, 0.5, 0.0 - 1.0, ASSET_SNARE_1, 0.9, 0.0 - 2.0, ASSET_KICK_1, 1.0, 0.0 - 3.0, ASSET_SNARE_1, 0.9, 0.0 +PATTERN drums_basic LENGTH 1.0 + 0.00, ASSET_KICK_1, 1.0, 0.0 + 0.00, NOTE_A4, 0.5, 0.0 + 0.25, ASSET_SNARE_1, 0.9, 0.0 + 0.50, ASSET_KICK_1, 1.0, 0.0 + 0.75, ASSET_SNARE_1, 0.9, 0.0 -PATTERN drums_with_crash - 0.0, ASSET_KICK_1, 1.0, 0.0 - 0.0, ASSET_CRASH_1, 0.85, 0.0 - 0.0, NOTE_A4, 0.5, 0.0 - 1.0, ASSET_SNARE_1, 0.9, 0.0 - 2.0, ASSET_KICK_1, 1.0, 0.0 - 3.0, ASSET_SNARE_1, 0.9, 0.0 +PATTERN drums_with_crash LENGTH 1.0 + 0.00, ASSET_KICK_1, 1.0, 0.0 + 0.00, ASSET_CRASH_1, 0.85, 0.0 + 0.00, NOTE_A4, 0.5, 0.0 + 0.25, ASSET_SNARE_1, 0.9, 0.0 + 0.50, ASSET_KICK_1, 1.0, 0.0 + 0.75, ASSET_SNARE_1, 0.9, 0.0 SCORE 0.0, drums_basic - 4.0, drums_with_crash - 8.0, drums_basic - 12.0, drums_with_crash + 1.0, drums_basic + 2.0, drums_with_crash + 3.0, drums_basic + 4.0, drums_basic + 5.0, drums_basic + 6.0, drums_with_crash + 7.0, drums_basic -- cgit v1.2.3