diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-04 14:38:04 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-04 14:38:04 +0100 |
| commit | af4b27dfb0862bc4a76d716dacd24acf73ee059a (patch) | |
| tree | 2d17b230ef69d6567b85e8bf31970e4490af1bad /src/tests/test_tracker.cc | |
| parent | 02336d13cbb5c3109583cd258696e88afe7cf9bb (diff) | |
feat(audio): Trigger pattern events individually for tempo scaling
Refactored tracker system to trigger individual events as separate voices
instead of compositing patterns into single spectrograms. This enables
notes within patterns to respect tempo scaling dynamically.
Key Changes:
- Added ActivePattern tracking with start_music_time and next_event_idx
- Individual events trigger when their beat time is reached
- Elapsed beats calculated dynamically: (music_time - start_time) / beat_duration
- Removed pattern compositing logic (paste_spectrogram)
- Each note now triggers as separate voice with volume/pan parameters
Behavior:
- Tempo scaling (via music_time) now affects note spacing within patterns
- At 2.0x tempo: patterns trigger 2x faster AND notes within play 2x faster
- At 0.5x tempo: patterns trigger 2x slower AND notes within play 2x slower
Testing:
- Updated test_tracker to verify event-based triggering at specific beat times
- All 17 tests pass (100%)
- WAV dump confirms tempo scaling works correctly:
* 0-10s: steady 1.00x tempo
* 10-15s: acceleration to 2.00x tempo
* 15-20s: reset to 1.00x tempo
* 20-25s: deceleration to 0.50x tempo
* 25s+: return to normal
Result: Music time advances at variable rates (61.24s in 60s physical time),
and notes within patterns correctly accelerate/decelerate with tempo changes.
handoff(Claude): Tempo scaling now affects notes within patterns
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/tests/test_tracker.cc')
| -rw-r--r-- | src/tests/test_tracker.cc | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/tests/test_tracker.cc b/src/tests/test_tracker.cc index ea1debd..7ef7172 100644 --- a/src/tests/test_tracker.cc +++ b/src/tests/test_tracker.cc @@ -24,25 +24,42 @@ void test_tracker_pattern_triggering() { synth_init(); tracker_init(); - // Test 1: Trigger patterns at 0.0f + // At time 0.0f, 4 patterns are triggered: + // - crash (1 event at beat 0.0) + // - kick_basic (events at beat 0.0, 2.0, 2.5) + // - snare_basic (events at beat 1.0, 3.0) + // - hihat_stressed (events at beat 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5) + // With the new event-based triggering, only events at beat 0.0 trigger immediately. + + // Test 1: At music_time = 0.0f, events at beat 0.0 trigger tracker_update(0.0f); - printf("Actual active voice count: %d\n", synth_get_active_voice_count()); - // 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); + printf("Actual active voice count at 0.0f: %d\n", + synth_get_active_voice_count()); + // Expect 3 voices: crash (beat 0.0), kick_basic (beat 0.0), hihat_stressed + // (beat 0.0) + assert(synth_get_active_voice_count() == 3); - // Test 2: Advance time slightly - tracker_update(0.1f); + // Test 2: At music_time = 0.25f (beat 0.5 @ 120 BPM), hihat event triggers + // beat_duration = 60.0f / 120.0f = 0.5s per beat + // beat 0.5 = 0.25s + tracker_update(0.25f); + printf("Actual active voice count at 0.25f: %d\n", + synth_get_active_voice_count()); + // Expect 4 voices (3 previous + 1 new hihat) assert(synth_get_active_voice_count() == 4); - // Test 3: Advance further, no new triggers until 4.0f - tracker_update(3.0f); - // Voices from 0.0f triggers might have ended, but new ones haven't started. - // synth_get_active_voice_count might drop if previous voices ended. - // For this test, we assume voices triggered at 0.0f are still active for a - // short duration. A more robust test would check for specific spectrograms or - // mock synth. For now, we expect voices to still be somewhat active or new - // ones to be triggered if there's overlap + // Test 3: At music_time = 0.5f (beat 1.0), snare event triggers + tracker_update(0.5f); + printf("Actual active voice count at 0.5f: %d\n", + synth_get_active_voice_count()); + // Expect 6 voices (4 previous + snare + hihat at beat 1.0) + assert(synth_get_active_voice_count() == 6); + + // Test 4: Advance further to 2.0f (beat 4.0), new pattern triggers at 2.0f + tracker_update(2.0f); + printf("Actual active voice count at 2.0f: %d\n", + synth_get_active_voice_count()); + // Multiple events have triggered by now assert(synth_get_active_voice_count() > 0); printf("Tracker pattern triggering test PASSED\n"); |
