From 778f525c5d22b332a9828cc437f88f79f97a978e Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 15 Feb 2026 11:54:42 +0100 Subject: feat(audio): add --dump-wav-start and --dump-wav-duration options Adds CLI options to control WAV dump time range: - --dump-wav-start TIME: Start dumping at specified time (seeks first) - --dump-wav-duration TIME: Limit dump duration Enables efficient rendering of specific segments without dumping entire demo. Co-Authored-By: Claude Sonnet 4.5 --- src/app/main.cc | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/app/main.cc b/src/app/main.cc index 03434a0..537da74 100644 --- a/src/app/main.cc +++ b/src/app/main.cc @@ -45,6 +45,8 @@ int main(int argc, char** argv) { int width = 1280; int height = 720; bool dump_wav = false; + float dump_wav_start = -1.0f; + float dump_wav_duration = -1.0f; bool tempo_test_enabled = false; bool headless_mode = false; float headless_duration = 30.0f; @@ -73,6 +75,12 @@ int main(int argc, char** argv) { if (i + 1 < argc && argv[i + 1][0] != '-') { wav_output_file = argv[++i]; } + } else if (strcmp(argv[i], "--dump-wav-start") == 0 && i + 1 < argc) { + dump_wav_start = atof(argv[i + 1]); + ++i; + } else if (strcmp(argv[i], "--dump-wav-duration") == 0 && i + 1 < argc) { + dump_wav_duration = atof(argv[i + 1]); + ++i; } else if (strcmp(argv[i], "--tempo") == 0) { tempo_test_enabled = true; #if defined(DEMO_HEADLESS) @@ -247,10 +255,29 @@ int main(int argc, char** argv) { #if !defined(STRIP_ALL) // In WAV dump mode, run headless simulation and write audio to file if (dump_wav) { - printf("Running WAV dump simulation...\n"); - + // Determine start and end times + const float start_time = (dump_wav_start >= 0.0f) ? dump_wav_start : 0.0f; const float demo_duration = GetDemoDuration(); - const float max_duration = (demo_duration > 0.0f) ? demo_duration : 60.0f; + float end_time; + if (dump_wav_duration >= 0.0f) { + end_time = start_time + dump_wav_duration; + } else { + end_time = (demo_duration > 0.0f) ? demo_duration : 60.0f; + } + + printf("Running WAV dump simulation (%.1fs - %.1fs)...\n", start_time, + end_time); + + // Seek to start time if needed + if (start_time > 0.0f) { + const double step = 1.0 / 60.0; + for (double t = 0.0; t < start_time; t += step) { + fill_audio_buffer(step, t); + audio_render_silent((float)step); + } + printf("Seeked to %.1fs\n", start_time); + } + const float update_dt = 1.0f / 60.0f; // 60Hz update rate const int frames_per_update = (int)(32000 * update_dt); // ~533 frames const int samples_per_update = frames_per_update * 2; // Stereo @@ -258,8 +285,8 @@ int main(int argc, char** argv) { AudioRingBuffer* ring_buffer = audio_get_ring_buffer(); std::vector chunk_buffer(samples_per_update); - double physical_time = 0.0; - while (physical_time < max_duration) { + double physical_time = start_time; + while (physical_time < end_time) { // Update music time and tracker (using tempo logic from // fill_audio_buffer) fill_audio_buffer(update_dt, physical_time); @@ -278,13 +305,13 @@ int main(int argc, char** argv) { if ((int)physical_time % 1 == 0 && physical_time - update_dt < (int)physical_time) { printf(" Rendering: %.1fs / %.1fs (music: %.1fs, tempo: %.2fx)\r", - physical_time, max_duration, g_music_time, g_tempo_scale); + physical_time, end_time, g_music_time, g_tempo_scale); fflush(stdout); } } - printf("\nWAV dump complete: %.2fs physical, %.2fs music time\n", - physical_time, g_music_time); + printf("\nWAV dump complete: %.2fs (%.2fs - %.2fs), music: %.2fs\n", + physical_time - start_time, start_time, physical_time, g_music_time); #if defined(DEMO_HEADLESS) g_wav_backend_ptr = nullptr; -- cgit v1.2.3