diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-15 23:56:43 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-15 23:56:43 +0100 |
| commit | 5c7feffd3749ce4b355d0db6334cf39ca94d8d82 (patch) | |
| tree | 7105aea12d0367208a37777cf53b348f35a66dad /src/app | |
| parent | e21127a3fc4797805d49ae2d95fc7ed6f94ac456 (diff) | |
perf(audio): smooth playback time and RMS-based peak at 60Hz
Interpolates audio playback time between callbacks using CLOCK_MONOTONIC
for smooth 60Hz updates instead of coarse 8-10Hz steps.
Replaces artificial peak decay with true RMS calculation over 50ms
window. Ring buffer computes RMS directly on internal buffer without
copies for efficiency.
All backends updated with get_callback_state() interface for time
interpolation. Tests passing (34/34).
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/app')
| -rw-r--r-- | src/app/main.cc | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/app/main.cc b/src/app/main.cc index 3c80520..9bbbaaf 100644 --- a/src/app/main.cc +++ b/src/app/main.cc @@ -168,7 +168,7 @@ int main(int argc, char** argv) { #if !defined(STRIP_ALL) // Debug output when tempo changes significantly if (fabsf(g_tempo_scale - prev_tempo) > 0.05f) { - printf("[Tempo] t=%.2fs, tempo=%.3fx, music_time=%.3fs\n", + printf("[Tempo] t=%.3fs, tempo=%.3fx, music_time=%.3fs\n", (float)physical_time, g_tempo_scale, g_music_time); } #endif @@ -191,7 +191,7 @@ int main(int argc, char** argv) { #if !defined(STRIP_ALL) if (seek_time > 0.0) { - printf("Seeking to %.2f seconds...\n", seek_time); + printf("Seeking to %.3f seconds...\n", seek_time); // Simulate audio/game logic // We step at ~60hz @@ -213,7 +213,7 @@ int main(int argc, char** argv) { } audio_start(); - g_last_audio_time = audio_get_playback_time(); // Initialize after start + g_last_audio_time = 0.0f; // Initialize to zero (will use smooth interpolation) #if !defined(STRIP_ALL) // Hot-reload setup @@ -351,7 +351,7 @@ int main(int argc, char** argv) { // Graphics frame time - derived from platform's clock const double current_physical_time = platform_state.time + seek_time; const double graphics_frame_time = current_physical_time - last_frame_time; - // Audio playback time - master clock for audio events + // Audio playback time - smoothly interpolated at 60Hz const float current_audio_time = audio_get_playback_time(); // Delta time for audio processing, based on audio clock const float audio_dt = current_audio_time - g_last_audio_time; @@ -398,17 +398,18 @@ int main(int argc, char** argv) { // Use graphics time for the print interval to avoid excessive output if // audio clock is slow static float last_graphics_print_time = -1.0f; - if (current_physical_time - last_graphics_print_time >= + if (true || + current_physical_time - last_graphics_print_time >= 0.5f) { // Print every 0.5 seconds if (tempo_test_enabled) { printf( - "[GraphicsT=%.2f, AudioT=%.2f, MusicT=%.2f, Beat=%d, Phase=%.2f, " - "Peak=%.2f, Tempo=%.2fx]\n", + "[GraphicsT=%.3f, AudioT=%.3f, MusicT=%.3f, Beat=%d, Phase=%.3f, " + "Peak=%.3f, Tempo=%.3fx]\n", current_physical_time, current_audio_time, g_music_time, beat_number, beat_phase, visual_peak, g_tempo_scale); } else { printf( - "[GraphicsT=%.2f, AudioT=%.2f, Beat=%d, Phase=%.2f, Peak=%.2f]\n", + "[GraphicsT=%.3f, AudioT=%.3f, Beat=%d, Phase=%.3f, Peak=%.3f]\n", current_physical_time, current_audio_time, beat_number, beat_phase, visual_peak); } |
