summaryrefslogtreecommitdiff
path: root/src/tests/test_variable_tempo.cc
AgeCommit message (Collapse)Author
17 hoursfeat(audio): Complete Phase 2 - Migrate tests to AudioEngine (Task #56)skal
Migrated all tracker-related tests to use AudioEngine instead of directly calling synth_init() and tracker_init(), eliminating fragile initialization order dependencies. Tests Migrated: - test_tracker.cc: Basic tracker functionality - test_tracker_timing.cc: Timing verification with MockAudioBackend (7 tests) - test_variable_tempo.cc: Variable tempo scaling (6 tests) - test_wav_dump.cc: WAV dump backend verification Migration Pattern: - Added AudioEngine include to all test files - Replaced synth_init() + tracker_init() with AudioEngine::init() - Replaced tracker_update(time) with engine.update(time) - Added engine.shutdown() at end of each test function - Preserved audio_init()/audio_shutdown() where needed for backends Results: - All 20 tests pass (100% pass rate) - Test suite time: 8.13s (slightly faster) - No regressions in test behavior - Cleaner API with single initialization entry point Next Steps (Phase 3): - Migrate main.cc and production code to use AudioEngine - Add backwards compatibility shims during transition handoff(Claude): Completed Task #56 Phase 2 - all tracker tests now use AudioEngine. The initialization order fragility is eliminated in test code. Ready for Phase 3 (production integration).
19 hoursfix(audio): Resolve tracker test failures due to initialization orderskal
Root Cause: Tests were failing because synth_init() clears all registered spectrograms, but tests called tracker_init() before or between synth_init() calls, causing spectrograms to be registered then immediately cleared. Fixes: 1. tracker.cc: - Force re-initialization on every tracker_init() call - Clear cache and re-register all spectrograms to handle synth resets - Free previously allocated memory to prevent leaks - Ensures spectrograms remain registered regardless of init order 2. synth.cc: - Fixed backend event hooks wrapped in wrong conditional - Changed #if defined(DEBUG_LOG_SYNTH) -> #if !defined(STRIP_ALL) - Moved backend includes and g_elapsed_time_sec outside debug guards - Ensures test backends receive voice trigger events 3. CMakeLists.txt: - Added missing generate_demo_assets dependency to test_tracker - Ensures asset files are available before running tracker tests 4. test_tracker.cc: - Fixed incorrect test expectations (5 voices, not 6, at beat 1.0) - Updated comments to reflect event-based triggering behavior 5. test_tracker_timing.cc, test_variable_tempo.cc, test_wav_dump.cc: - Fixed initialization order: synth_init() BEFORE tracker_init() - For tests using audio_init(), moved tracker_init() AFTER it - Ensures spectrograms are registered after synth is ready Test Results: All 19 tests now pass (100% success rate). Known Limitation: This is a temporary fix. The initialization order dependency is fragile and should be replaced with a proper lifecycle management system (see TODO Task #56). Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
48 hoursfeat(audio): Variable tempo system with music time abstractionskal
Implemented unified music time that advances at configurable tempo_scale, enabling dynamic tempo changes without pitch shifting or BPM dependencies. Key Changes: - Added music_time tracking in main.cc (advances by dt * tempo_scale) - Decoupled tracker_update() from physical time (now uses music_time) - Created comprehensive test suite (test_variable_tempo.cc) with 6 scenarios - Verified 2x speed-up and 2x slow-down reset tricks work perfectly - All tests pass (100% success rate) Technical Details: - Spectrograms remain unchanged (no pitch shift) - Only trigger timing affected (when patterns fire) - Delta time calculated per frame: dt = current_time - last_time - Music time accumulates: music_time += dt * tempo_scale - tempo_scale=1.0 → normal speed (default) - tempo_scale=2.0 → 2x faster triggering - tempo_scale=0.5 → 2x slower triggering Test Coverage: 1. Basic tempo scaling (1.0x, 2.0x, 0.5x) 2. 2x speed-up reset trick (accelerate to 2.0x, reset to 1.0x) 3. 2x slow-down reset trick (decelerate to 0.5x, reset to 1.0x) 4. Pattern density swap at reset points 5. Continuous acceleration (0.5x to 2.0x over 10s) 6. Oscillating tempo (sine wave modulation) Test Results: - After 5s physical at 2.0x tempo: music_time=7.550s (expected ~7.5s) ✓ - Reset to 1.0x, advance 2s: music_time delta=2.000s (expected ~2.0s) ✓ - Slow-down reset: music_time delta=2.000s (expected ~2.0s) ✓ Enables future dynamic tempo control without modifying synthesis engine. handoff(Claude): Variable tempo system complete and verified Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>