summaryrefslogtreecommitdiff
path: root/src/tests/test_tracker_timing.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-05 19:59:21 +0100
committerskal <pascal.massimino@gmail.com>2026-02-05 19:59:21 +0100
commit6c09e3bdb5128dca64c457c3a6ebeb32adf98c10 (patch)
treed943db66547776c295c1895852eaf9a8cbec506b /src/tests/test_tracker_timing.cc
parent64c19b368db4aea748467b5f763add99c7deb701 (diff)
feat(audio): Complete Phase 2 - Migrate tests to AudioEngine (Task #56)
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).
Diffstat (limited to 'src/tests/test_tracker_timing.cc')
-rw-r--r--src/tests/test_tracker_timing.cc72
1 files changed, 41 insertions, 31 deletions
diff --git a/src/tests/test_tracker_timing.cc b/src/tests/test_tracker_timing.cc
index cf2519d..2f39a16 100644
--- a/src/tests/test_tracker_timing.cc
+++ b/src/tests/test_tracker_timing.cc
@@ -2,19 +2,20 @@
// It tests tracker timing and synchronization using MockAudioBackend.
// Verifies pattern triggers occur at correct times with proper BPM scaling.
-#include "audio/mock_audio_backend.h"
#include "audio/audio.h"
+#include "audio/audio_engine.h"
+#include "audio/mock_audio_backend.h"
#include "audio/synth.h"
#include "audio/tracker.h"
#include <assert.h>
-#include <stdio.h>
#include <cmath>
+#include <stdio.h>
#if !defined(STRIP_ALL)
// Helper: Check if a timestamp exists in events within tolerance
static bool has_event_at_time(const std::vector<VoiceTriggerEvent>& events,
- float expected_time, float tolerance = 0.001f) {
+ float expected_time, float tolerance = 0.001f) {
for (const auto& evt : events) {
if (std::abs(evt.timestamp_sec - expected_time) < tolerance) {
return true;
@@ -25,7 +26,7 @@ static bool has_event_at_time(const std::vector<VoiceTriggerEvent>& events,
// Helper: Count events at a specific time
static int count_events_at_time(const std::vector<VoiceTriggerEvent>& events,
- float expected_time, float tolerance = 0.001f) {
+ float expected_time, float tolerance = 0.001f) {
int count = 0;
for (const auto& evt : events) {
if (std::abs(evt.timestamp_sec - expected_time) < tolerance) {
@@ -36,8 +37,9 @@ static int count_events_at_time(const std::vector<VoiceTriggerEvent>& events,
}
// Helper: Get all unique timestamps in events
-static std::vector<float> get_unique_timestamps(
- const std::vector<VoiceTriggerEvent>& events, float tolerance = 0.001f) {
+static std::vector<float>
+get_unique_timestamps(const std::vector<VoiceTriggerEvent>& events,
+ float tolerance = 0.001f) {
std::vector<float> timestamps;
for (const auto& evt : events) {
bool found = false;
@@ -60,11 +62,11 @@ void test_basic_event_recording() {
MockAudioBackend backend;
audio_set_backend(&backend);
- synth_init();
- tracker_init();
+ AudioEngine engine;
+ engine.init();
// Trigger at t=0.0 (should trigger initial patterns)
- tracker_update(0.0f);
+ engine.update(0.0f);
const auto& events = backend.get_events();
printf(" Events triggered at t=0.0: %zu\n", events.size());
@@ -77,6 +79,7 @@ void test_basic_event_recording() {
assert(evt.timestamp_sec < 0.1f); // Within 100ms of start
}
+ engine.shutdown();
printf(" ✓ Basic event recording works\n");
}
@@ -86,21 +89,21 @@ void test_progressive_triggering() {
MockAudioBackend backend;
audio_set_backend(&backend);
- synth_init();
- tracker_init();
+ AudioEngine engine;
+ engine.init();
// Update at t=0
- tracker_update(0.0f);
+ engine.update(0.0f);
const size_t events_at_0 = backend.get_events().size();
printf(" Events at t=0.0: %zu\n", events_at_0);
// Update at t=1.0
- tracker_update(1.0f);
+ engine.update(1.0f);
const size_t events_at_1 = backend.get_events().size();
printf(" Events at t=1.0: %zu\n", events_at_1);
// Update at t=2.0
- tracker_update(2.0f);
+ engine.update(2.0f);
const size_t events_at_2 = backend.get_events().size();
printf(" Events at t=2.0: %zu\n", events_at_2);
@@ -108,6 +111,7 @@ void test_progressive_triggering() {
assert(events_at_1 >= events_at_0);
assert(events_at_2 >= events_at_1);
+ engine.shutdown();
printf(" ✓ Events accumulate over time\n");
}
@@ -117,12 +121,12 @@ void test_simultaneous_triggers() {
MockAudioBackend backend;
audio_set_backend(&backend);
- synth_init();
- tracker_init();
+ AudioEngine engine;
+ engine.init();
// Clear and update to first trigger point
backend.clear_events();
- tracker_update(0.0f);
+ engine.update(0.0f);
const auto& events = backend.get_events();
if (events.size() == 0) {
@@ -155,6 +159,8 @@ void test_simultaneous_triggers() {
} else {
printf(" ℹ Only one event at t=0.0, cannot verify simultaneity\n");
}
+
+ engine.shutdown();
}
void test_timing_monotonicity() {
@@ -163,12 +169,12 @@ void test_timing_monotonicity() {
MockAudioBackend backend;
audio_set_backend(&backend);
- synth_init();
- tracker_init();
+ AudioEngine engine;
+ engine.init();
// Update through several time points
for (float t = 0.0f; t <= 5.0f; t += 0.5f) {
- tracker_update(t);
+ engine.update(t);
}
const auto& events = backend.get_events();
@@ -179,6 +185,7 @@ void test_timing_monotonicity() {
assert(events[i].timestamp_sec >= events[i - 1].timestamp_sec);
}
+ engine.shutdown();
printf(" ✓ All timestamps monotonically increasing\n");
}
@@ -189,8 +196,8 @@ void test_seek_simulation() {
audio_set_backend(&backend);
audio_init();
- synth_init();
- tracker_init();
+ AudioEngine engine;
+ engine.init();
// Simulate seeking to t=3.0s by rendering silent audio
// This should trigger all patterns in range [0, 3.0]
@@ -200,10 +207,10 @@ void test_seek_simulation() {
float t = 0.0f;
const float step = 0.1f;
while (t <= seek_target) {
- tracker_update(t);
+ engine.update(t);
// Simulate audio rendering
float dummy_buffer[512 * 2];
- synth_render(dummy_buffer, 512);
+ engine.render(dummy_buffer, 512);
t += step;
}
@@ -220,6 +227,7 @@ void test_seek_simulation() {
assert(evt.timestamp_sec <= seek_target + 0.5f);
}
+ engine.shutdown();
audio_shutdown();
printf(" ✓ Seek simulation works correctly\n");
@@ -231,12 +239,12 @@ void test_timestamp_clustering() {
MockAudioBackend backend;
audio_set_backend(&backend);
- synth_init();
- tracker_init();
+ AudioEngine engine;
+ engine.init();
// Update through the first 4 seconds
for (float t = 0.0f; t <= 4.0f; t += 0.1f) {
- tracker_update(t);
+ engine.update(t);
}
const auto& events = backend.get_events();
@@ -254,6 +262,7 @@ void test_timestamp_clustering() {
}
}
+ engine.shutdown();
printf(" ✓ Timestamp clustering analyzed\n");
}
@@ -264,11 +273,11 @@ void test_render_integration() {
audio_set_backend(&backend);
audio_init();
- synth_init();
- tracker_init();
+ AudioEngine engine;
+ engine.init();
// Trigger some patterns
- tracker_update(0.0f);
+ engine.update(0.0f);
const size_t events_before = backend.get_events().size();
// Render 1 second of silent audio
@@ -280,12 +289,13 @@ void test_render_integration() {
assert(backend_time >= 0.9f && backend_time <= 1.1f);
// Trigger more patterns after time advance
- tracker_update(1.0f);
+ engine.update(1.0f);
const size_t events_after = backend.get_events().size();
printf(" Events before: %zu, after: %zu\n", events_before, events_after);
assert(events_after >= events_before);
+ engine.shutdown();
audio_shutdown();
printf(" ✓ audio_render_silent integration works\n");