summaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-04 13:38:16 +0100
committerskal <pascal.massimino@gmail.com>2026-02-04 13:38:16 +0100
commit25d7e4ef3713e805a272fb84df7ba0c66e533caf (patch)
tree5b842a39e5607a3790ccee0ccbb60cf25633c873 /src/main.cc
parent829e2112db2c6ee05ed3fa787476456cb137222f (diff)
feat(audio): Variable tempo system with music time abstraction
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>
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/main.cc b/src/main.cc
index aba8d4b..9f61f07 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -92,10 +92,20 @@ int main(int argc, char** argv) {
// int melody_id = generate_melody();
// synth_trigger_voice(melody_id, 0.6f, 0.0f);
+ // Music time state for variable tempo
+ static float g_music_time = 0.0f;
+ static float g_tempo_scale = 1.0f; // 1.0 = normal speed
+ static double g_last_physical_time = 0.0;
+
double last_beat_time = 0.0;
int beat_count = 0;
auto update_game_logic = [&](double t) {
+ // Calculate delta time and advance music time at scaled rate
+ const float dt = (float)(t - g_last_physical_time);
+ g_last_physical_time = t;
+ g_music_time += dt * g_tempo_scale;
+
if (t - last_beat_time > (60.0f / g_tracker_score.bpm) / 2.0) { // 8th notes
last_beat_time = t; // Sync to t
@@ -115,7 +125,9 @@ int main(int argc, char** argv) {
*/
++beat_count;
}
- tracker_update((float)t);
+
+ // Pass music_time (not physical time) to tracker
+ tracker_update(g_music_time);
};
#if !defined(STRIP_ALL)