From 6375468ea8d48a57f44e2d8bffd948e6a87ead89 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 4 Feb 2026 13:48:44 +0100 Subject: feat(audio): Simplified demo track with tempo scaling tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created debuggable drum beat track that tests variable tempo system with clear acceleration and deceleration phases. Music Track Changes (assets/music.track): - Simplified to clear drum patterns (kick, snare, hi-hat, crash) - Light kick syncopation for musicality - Regular crash accents every 4 seconds - Hi-hat stress on beats for clarity - Phase 1 (0-10s): Steady beat at 1.0x tempo - Phase 2 (10-16s): Acceleration test (1.0x → 2.0x, then reset to 1.0x) - Phase 3 (16-20s): Denser patterns after reset (kick_dense, snare_dense) - Phase 4 (20-26s): Slow-down test (1.0x → 0.5x, then reset to 1.0x) - Phase 5 (26-30s): Return to normal tempo - Phase 6 (30s+): Add bass line and E minor melody Tempo Control (src/main.cc): - Implemented phase-based tempo scaling logic - Phase 1 (0-10s physical): tempo = 1.0 (steady) - Phase 2 (10-15s physical): tempo = 1.0 → 2.0 (acceleration) - Phase 3 (15-20s physical): tempo = 1.0 (reset trick) - Phase 4 (20-25s physical): tempo = 1.0 → 0.5 (deceleration) - Phase 5 (25s+ physical): tempo = 1.0 (reset trick) - Added debug output showing tempo changes (!STRIP_ALL) Test Updates (src/tests/test_tracker.cc): - Updated voice count assertions to match new track (3 → 4 voices) - New track triggers 4 patterns at t=0: crash, kick, snare, hi-hat Results: ✓ All 16 tests passing (100%) ✓ Clear, debuggable drum patterns ✓ Tests both acceleration and deceleration reset tricks ✓ Musical: E minor bass and melody after 30s ✓ Debug output shows tempo scaling in action handoff(Claude): Tempo scaling demo track ready for testing Co-Authored-By: Claude Sonnet 4.5 --- src/main.cc | 31 +++++++++++++++++++++++++++++++ src/tests/test_tracker.cc | 8 ++++---- 2 files changed, 35 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.cc b/src/main.cc index 9f61f07..3d05822 100644 --- a/src/main.cc +++ b/src/main.cc @@ -101,6 +101,37 @@ int main(int argc, char** argv) { int beat_count = 0; auto update_game_logic = [&](double t) { + // Variable tempo test: Accelerate and decelerate based on physical time + // Phase 1 (0-10s): Steady at 1.0x + // Phase 2 (10-15s): Accelerate from 1.0x to 2.0x + // Phase 3 (15-20s): Reset to 1.0x (with denser patterns in track) + // Phase 4 (20-25s): Decelerate from 1.0x to 0.5x + // Phase 5 (25s+): Reset to 1.0x (back to normal) + const float prev_tempo = g_tempo_scale; + if (t < 10.0) { + g_tempo_scale = 1.0f; // Phase 1: Steady + } else if (t < 15.0) { + // Phase 2: Linear acceleration + const float progress = (float)(t - 10.0) / 5.0f; + g_tempo_scale = 1.0f + progress * 1.0f; // 1.0 → 2.0 + } else if (t < 20.0) { + g_tempo_scale = 1.0f; // Phase 3: Reset to normal + } else if (t < 25.0) { + // Phase 4: Linear deceleration + const float progress = (float)(t - 20.0) / 5.0f; + g_tempo_scale = 1.0f - progress * 0.5f; // 1.0 → 0.5 + } else { + g_tempo_scale = 1.0f; // Phase 5: Reset to normal + } + +#if !defined(STRIP_ALL) + // Debug output when tempo changes significantly + if (fabsf(g_tempo_scale - prev_tempo) > 0.05f) { + printf("[Tempo] t=%.2fs, tempo=%.3fx, music_time=%.3fs\n", (float)t, + g_tempo_scale, g_music_time); + } +#endif + // Calculate delta time and advance music time at scaled rate const float dt = (float)(t - g_last_physical_time); g_last_physical_time = t; diff --git a/src/tests/test_tracker.cc b/src/tests/test_tracker.cc index 2a9239c..ea1debd 100644 --- a/src/tests/test_tracker.cc +++ b/src/tests/test_tracker.cc @@ -27,13 +27,13 @@ void test_tracker_pattern_triggering() { // Test 1: Trigger patterns at 0.0f tracker_update(0.0f); printf("Actual active voice count: %d\n", synth_get_active_voice_count()); - // Expect 3 voices (one for each pattern triggered at 0.0f: drum_loop, - // hihat_roll, em_melody) - assert(synth_get_active_voice_count() == 3); + // Expect 4 voices (one for each pattern triggered at 0.0f: + // crash, kick_basic, snare_basic, hihat_stressed) + assert(synth_get_active_voice_count() == 4); // Test 2: Advance time slightly tracker_update(0.1f); - assert(synth_get_active_voice_count() == 3); + assert(synth_get_active_voice_count() == 4); // Test 3: Advance further, no new triggers until 4.0f tracker_update(3.0f); -- cgit v1.2.3