summaryrefslogtreecommitdiff
path: root/src/test_demo.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-08 11:13:53 +0100
committerskal <pascal.massimino@gmail.com>2026-02-08 11:13:53 +0100
commit392d03c0c05f24be3210a04d9a50cd9714d1e265 (patch)
tree3c4985879bdf614536020f2061c299ecf442677f /src/test_demo.cc
parentd2d20763ac61f59187d261bb7d6dedcab525bc54 (diff)
refactor(audio): Finalize audio sync, update docs, and clean up test artifacts
- Implemented sample-accurate audio-visual synchronization by using the hardware audio clock as the master time source. - Ensured tracker updates and visual rendering are slaved to the stable audio clock. - Corrected to accept and use delta time for sample-accurate event scheduling. - Updated all relevant tests (, , , , ) to use the new delta time parameter. - Added function. - Marked Task #71 as completed in . - Updated to reflect the audio system's current status. - Created a handoff document: . - Removed temporary peak log files (, ).
Diffstat (limited to 'src/test_demo.cc')
-rw-r--r--src/test_demo.cc31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/test_demo.cc b/src/test_demo.cc
index 8209eca..bb92446 100644
--- a/src/test_demo.cc
+++ b/src/test_demo.cc
@@ -219,20 +219,18 @@ int main(int argc, char** argv) {
// Music time tracking with optional tempo variation
static float g_music_time = 0.0f;
- static double g_last_physical_time = 0.0;
+ static float g_last_audio_time = 0.0f;
static float g_tempo_scale = 1.0f;
- auto fill_audio_buffer = [&](double t) {
- const float dt = (float)(t - g_last_physical_time);
- g_last_physical_time = t;
-
+ auto fill_audio_buffer = [&](float audio_dt, double physical_time) {
// Calculate tempo scale if --tempo flag enabled
if (tempo_test_enabled) {
// Each bar = 2 seconds at 120 BPM (4 beats)
const float bar_duration = 2.0f;
- const int bar_number = (int)(t / bar_duration);
+ const int bar_number = (int)(physical_time / bar_duration);
const float bar_progress =
- fmodf((float)t, bar_duration) / bar_duration; // 0.0-1.0 within bar
+ fmodf((float)physical_time, bar_duration) /
+ bar_duration; // 0.0-1.0 within bar
if (bar_number % 2 == 0) {
// Even bars: Ramp from 1.0x → 1.5x
@@ -245,16 +243,17 @@ int main(int argc, char** argv) {
g_tempo_scale = 1.0f; // No tempo variation
}
- g_music_time += dt * g_tempo_scale;
+ g_music_time += audio_dt * g_tempo_scale;
- g_audio_engine.update(g_music_time);
- audio_render_ahead(g_music_time, dt * g_tempo_scale);
+ g_audio_engine.update(g_music_time, audio_dt * g_tempo_scale);
+ audio_render_ahead(g_music_time, audio_dt * g_tempo_scale);
};
// Pre-fill audio buffer
- g_audio_engine.update(g_music_time);
+ g_audio_engine.update(g_music_time, 1.0f / 60.0f);
audio_render_ahead(g_music_time, 1.0f / 60.0f);
audio_start();
+ g_last_audio_time = audio_get_playback_time();
int last_width = platform_state.width;
int last_height = platform_state.height;
@@ -312,13 +311,17 @@ int main(int argc, char** argv) {
break;
}
- fill_audio_buffer(physical_time);
+ // Calculate stable audio dt for jitter-free tracker updates
+ const float audio_time = audio_get_playback_time();
+ const float audio_dt = audio_time - g_last_audio_time;
+ g_last_audio_time = audio_time;
+
+ fill_audio_buffer(audio_dt, physical_time);
// Audio-visual synchronization: Use audio playback time (not physical
// time!) This accounts for ring buffer latency automatically (no hardcoded
// constants)
- const float audio_time = audio_get_playback_time();
-
+
// Audio/visual sync parameters
const float aspect_ratio = platform_state.aspect_ratio;
// Peak is measured at audio playback time, so it matches audio_time