summaryrefslogtreecommitdiff
path: root/src/main.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cc')
-rw-r--r--src/main.cc49
1 files changed, 38 insertions, 11 deletions
diff --git a/src/main.cc b/src/main.cc
index 6132841..45a642a 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -13,6 +13,9 @@
#include "audio/backend/wav_dump_backend.h"
#include "util/file_watcher.h"
#include <vector>
+#if defined(DEMO_HEADLESS)
+#include <csignal>
+#endif
#endif
#include "generated/assets.h" // Include generated asset header
#include "gpu/demo_effects.h" // For GetDemoDuration()
@@ -24,6 +27,17 @@
#include <cstdlib>
#include <cstring>
+#if !defined(STRIP_ALL) && defined(DEMO_HEADLESS)
+static WavDumpBackend* g_wav_backend_ptr = nullptr;
+static void signal_handler(int sig) {
+ if (g_wav_backend_ptr != nullptr) {
+ g_wav_backend_ptr->shutdown();
+ g_wav_backend_ptr = nullptr;
+ }
+ exit(sig);
+}
+#endif
+
int main(int argc, char** argv) {
PlatformState platform_state;
bool fullscreen_enabled = false;
@@ -93,6 +107,11 @@ int main(int argc, char** argv) {
if (dump_wav) {
wav_backend.set_output_file(wav_output_file);
audio_set_backend(&wav_backend);
+#if defined(DEMO_HEADLESS)
+ g_wav_backend_ptr = &wav_backend;
+ signal(SIGINT, signal_handler);
+ signal(SIGTERM, signal_handler);
+#endif
printf("WAV dump mode enabled: %s\n", wav_output_file);
}
#endif
@@ -262,6 +281,9 @@ int main(int argc, char** argv) {
printf("\nWAV dump complete: %.2fs physical, %.2fs music time\n",
physical_time, g_music_time);
+#if defined(DEMO_HEADLESS)
+ g_wav_backend_ptr = nullptr;
+#endif
audio_shutdown();
gpu_shutdown();
platform_shutdown(&platform_state);
@@ -269,6 +291,7 @@ int main(int argc, char** argv) {
}
#endif
+#if !defined(DEMO_HEADLESS)
int last_width = platform_state.width;
int last_height = platform_state.height;
@@ -325,11 +348,10 @@ int main(int argc, char** argv) {
const float raw_peak = audio_get_realtime_peak();
const float visual_peak = fminf(raw_peak * 8.0f, 1.0f);
- // Beat calculation should use audio time to align with audio events.
- // The graphics loop time (current_physical_time) is used for frame rate.
- const float beat_time = current_audio_time * g_tracker_score.bpm / 60.0f;
- const int beat_number = (int)beat_time;
- const float beat = fmodf(beat_time, 1.0f); // Fractional part (0.0 to 1.0)
+ // Beat calculation: convert audio time to musical beats
+ const float absolute_beat_time = current_audio_time * g_tracker_score.bpm / 60.0f;
+ const int beat_number = (int)absolute_beat_time;
+ const float beat_phase = fmodf(absolute_beat_time, 1.0f); // Fractional part (0.0 to 1.0)
// Print beat/time info periodically for identifying sync points
// Use graphics time for the print interval to avoid excessive output if
@@ -339,20 +361,21 @@ int main(int argc, char** argv) {
0.5f) { // Print every 0.5 seconds
if (tempo_test_enabled) {
printf(
- "[GraphicsT=%.2f, AudioT=%.2f, MusicT=%.2f, Beat=%d, Frac=%.2f, "
+ "[GraphicsT=%.2f, AudioT=%.2f, MusicT=%.2f, Beat=%d, Phase=%.2f, "
"Peak=%.2f, Tempo=%.2fx]\n",
current_physical_time, current_audio_time, g_music_time,
- beat_number, beat, visual_peak, g_tempo_scale);
+ beat_number, beat_phase, visual_peak, g_tempo_scale);
} else {
- printf("[GraphicsT=%.2f, AudioT=%.2f, Beat=%d, Frac=%.2f, Peak=%.2f]\n",
- current_physical_time, current_audio_time, beat_number, beat,
+ printf("[GraphicsT=%.2f, AudioT=%.2f, Beat=%d, Phase=%.2f, Peak=%.2f]\n",
+ current_physical_time, current_audio_time, beat_number, beat_phase,
visual_peak);
}
last_graphics_print_time = current_physical_time;
}
- // Draw graphics using the graphics frame time and synchronized audio events
- gpu_draw(visual_peak, aspect_ratio, (float)current_physical_time, beat);
+ // Draw graphics using physical time and musical beat time
+ gpu_draw(visual_peak, aspect_ratio, (float)current_physical_time,
+ absolute_beat_time, beat_phase);
last_frame_time = current_physical_time;
// Update audio systems (tracker, synth, etc.) based on audio time
@@ -360,8 +383,12 @@ int main(int argc, char** argv) {
audio_update();
}
+#if !defined(STRIP_ALL) && defined(DEMO_HEADLESS)
+ g_wav_backend_ptr = nullptr;
+#endif
audio_shutdown();
gpu_shutdown();
platform_shutdown(&platform_state);
+#endif /* !defined(DEMO_HEADLESS) */
return 0;
} \ No newline at end of file