summaryrefslogtreecommitdiff
path: root/src/test_demo.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-08 07:40:29 +0100
committerskal <pascal.massimino@gmail.com>2026-02-08 07:40:29 +0100
commitc9195f997f3e797f03ab90464e4158717198a167 (patch)
tree331304f42870246efdc64cc97ad42de59444ef3a /src/test_demo.cc
parentb8e6929cafa41681f0b27ac104c9cf1d4e510837 (diff)
style: Apply clang-format to all source files
Diffstat (limited to 'src/test_demo.cc')
-rw-r--r--src/test_demo.cc85
1 files changed, 57 insertions, 28 deletions
diff --git a/src/test_demo.cc b/src/test_demo.cc
index 491968c..8209eca 100644
--- a/src/test_demo.cc
+++ b/src/test_demo.cc
@@ -4,7 +4,7 @@
#include "audio/audio.h"
#include "audio/audio_engine.h"
#include "audio/synth.h"
-#include "generated/assets.h" // Note: uses main demo asset bundle
+#include "generated/assets.h" // Note: uses main demo asset bundle
#include "gpu/demo_effects.h"
#include "gpu/gpu.h"
#include "platform/platform.h"
@@ -21,8 +21,7 @@ extern void LoadTimeline(MainSequence& main_seq, const GpuContext& ctx);
#include "gpu/effects/post_process_helper.h"
class PeakMeterEffect : public PostProcessEffect {
public:
- PeakMeterEffect(const GpuContext& ctx)
- : PostProcessEffect(ctx) {
+ PeakMeterEffect(const GpuContext& ctx) : PostProcessEffect(ctx) {
// Use standard post-process binding macros
const char* shader_code = R"(
struct VertexOutput {
@@ -77,13 +76,15 @@ class PeakMeterEffect : public PostProcessEffect {
}
)";
- pipeline_ = create_post_process_pipeline(ctx_.device, ctx_.format, shader_code);
+ pipeline_ =
+ create_post_process_pipeline(ctx_.device, ctx_.format, shader_code);
uniforms_ = gpu_create_buffer(
ctx_.device, 16, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst);
}
void update_bind_group(WGPUTextureView input_view) {
- pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view, uniforms_);
+ pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view,
+ uniforms_);
}
void render(WGPURenderPassEncoder pass, float time, float beat,
@@ -93,11 +94,12 @@ class PeakMeterEffect : public PostProcessEffect {
(void)aspect_ratio;
float uniforms[4] = {peak_value, 0.0f, 0.0f, 0.0f};
- wgpuQueueWriteBuffer(ctx_.queue, uniforms_.buffer, 0, uniforms, sizeof(uniforms));
+ wgpuQueueWriteBuffer(ctx_.queue, uniforms_.buffer, 0, uniforms,
+ sizeof(uniforms));
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Full-screen triangle
+ wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Full-screen triangle
}
};
@@ -111,10 +113,18 @@ static void print_usage(const char* prog_name) {
printf(" --fullscreen Run in fullscreen mode\n");
printf(" --resolution WxH Set window resolution (e.g., 1024x768)\n");
printf(" --tempo Enable tempo variation test mode\n");
- printf(" (alternates between acceleration and deceleration)\n");
- printf(" --log-peaks FILE Log audio peaks at each beat (32 samples for 16s)\n");
- printf(" --log-peaks-fine Log at each frame for fine analysis (~960 samples)\n");
- printf(" (use with --log-peaks for millisecond resolution)\n");
+ printf(
+ " (alternates between acceleration and "
+ "deceleration)\n");
+ printf(
+ " --log-peaks FILE Log audio peaks at each beat (32 samples for "
+ "16s)\n");
+ printf(
+ " --log-peaks-fine Log at each frame for fine analysis (~960 "
+ "samples)\n");
+ printf(
+ " (use with --log-peaks for millisecond "
+ "resolution)\n");
printf("\nExamples:\n");
printf(" %s --fullscreen\n", prog_name);
printf(" %s --resolution 1024x768 --tempo\n", prog_name);
@@ -154,12 +164,17 @@ int main(int argc, char** argv) {
width = w;
height = h;
} else {
- fprintf(stderr, "Error: Invalid resolution format '%s' (expected WxH, e.g., 1024x768)\n\n", res_str);
+ fprintf(stderr,
+ "Error: Invalid resolution format '%s' (expected WxH, e.g., "
+ "1024x768)\n\n",
+ res_str);
print_usage(argv[0]);
return 1;
}
} else {
- fprintf(stderr, "Error: --resolution requires an argument (e.g., 1024x768)\n\n");
+ fprintf(
+ stderr,
+ "Error: --resolution requires an argument (e.g., 1024x768)\n\n");
print_usage(argv[0]);
return 1;
}
@@ -193,7 +208,8 @@ int main(int argc, char** argv) {
#if !defined(STRIP_ALL)
const GpuContext* gpu_ctx = gpu_get_context();
auto* peak_meter = new PeakMeterEffect(*gpu_ctx);
- gpu_add_custom_effect(peak_meter, 0.0f, 99999.0f, 999); // High priority = renders last
+ gpu_add_custom_effect(peak_meter, 0.0f, 99999.0f,
+ 999); // High priority = renders last
#endif
audio_init();
@@ -215,7 +231,8 @@ int main(int argc, char** argv) {
// Each bar = 2 seconds at 120 BPM (4 beats)
const float bar_duration = 2.0f;
const int bar_number = (int)(t / bar_duration);
- const float bar_progress = fmodf((float)t, bar_duration) / bar_duration; // 0.0-1.0 within bar
+ const float bar_progress =
+ fmodf((float)t, bar_duration) / bar_duration; // 0.0-1.0 within bar
if (bar_number % 2 == 0) {
// Even bars: Ramp from 1.0x → 1.5x
@@ -225,7 +242,7 @@ int main(int argc, char** argv) {
g_tempo_scale = 1.0f - (0.34f * bar_progress);
}
} else {
- g_tempo_scale = 1.0f; // No tempo variation
+ g_tempo_scale = 1.0f; // No tempo variation
}
g_music_time += dt * g_tempo_scale;
@@ -250,17 +267,23 @@ int main(int argc, char** argv) {
peak_log = fopen(log_peaks_file, "w");
if (peak_log) {
fprintf(peak_log, "# Audio peak log from test_demo\n");
- fprintf(peak_log, "# Mode: %s\n", log_peaks_fine ? "fine (per-frame)" : "beat-aligned");
+ fprintf(peak_log, "# Mode: %s\n",
+ log_peaks_fine ? "fine (per-frame)" : "beat-aligned");
fprintf(peak_log, "# To plot with gnuplot:\n");
- fprintf(peak_log, "# gnuplot -p -e \"set xlabel 'Time (s)'; set ylabel 'Peak'; plot '%s' using 2:3 with lines title 'Raw Peak'\"\n", log_peaks_file);
+ fprintf(peak_log,
+ "# gnuplot -p -e \"set xlabel 'Time (s)'; set ylabel 'Peak'; "
+ "plot '%s' using 2:3 with lines title 'Raw Peak'\"\n",
+ log_peaks_file);
if (log_peaks_fine) {
- fprintf(peak_log, "# Columns: frame_number clock_time raw_peak beat_number\n");
+ fprintf(peak_log,
+ "# Columns: frame_number clock_time raw_peak beat_number\n");
} else {
fprintf(peak_log, "# Columns: beat_number clock_time raw_peak\n");
}
fprintf(peak_log, "#\n");
} else {
- fprintf(stderr, "Warning: Could not open log file '%s'\n", log_peaks_file);
+ fprintf(stderr, "Warning: Could not open log file '%s'\n",
+ log_peaks_file);
}
}
int last_beat_logged = -1;
@@ -291,8 +314,9 @@ int main(int argc, char** argv) {
fill_audio_buffer(physical_time);
- // Audio-visual synchronization: Use audio playback time (not physical time!)
- // This accounts for ring buffer latency automatically (no hardcoded constants)
+ // 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
@@ -311,9 +335,11 @@ int main(int argc, char** argv) {
if (peak_log) {
if (log_peaks_fine) {
// Log every frame for fine-grained analysis
- // Use platform_get_time() for high-resolution timestamps (not audio_time which advances in chunks)
+ // Use platform_get_time() for high-resolution timestamps (not
+ // audio_time which advances in chunks)
const double frame_time = platform_get_time();
- fprintf(peak_log, "%d %.6f %.6f %d\n", frame_number, frame_time, raw_peak, beat_number);
+ fprintf(peak_log, "%d %.6f %.6f %d\n", frame_number, frame_time,
+ raw_peak, beat_number);
} else if (beat_number != last_beat_logged) {
// Log only at beat boundaries
fprintf(peak_log, "%d %.6f %.6f\n", beat_number, audio_time, raw_peak);
@@ -326,11 +352,14 @@ int main(int argc, char** argv) {
static float last_print_time = -1.0f;
if (audio_time - last_print_time >= 0.5f) {
if (tempo_test_enabled) {
- printf("[AudioT=%.2f, PhysT=%.2f, MusicT=%.2f, Beat=%d, Frac=%.2f, Peak=%.2f, Tempo=%.2fx]\n",
- audio_time, (float)physical_time, g_music_time, beat_number, beat, visual_peak, g_tempo_scale);
+ printf(
+ "[AudioT=%.2f, PhysT=%.2f, MusicT=%.2f, Beat=%d, Frac=%.2f, "
+ "Peak=%.2f, Tempo=%.2fx]\n",
+ audio_time, (float)physical_time, g_music_time, beat_number, beat,
+ visual_peak, g_tempo_scale);
} else {
- printf("[AudioT=%.2f, Beat=%d, Frac=%.2f, Peak=%.2f]\n",
- audio_time, beat_number, beat, visual_peak);
+ printf("[AudioT=%.2f, Beat=%d, Frac=%.2f, Peak=%.2f]\n", audio_time,
+ beat_number, beat, visual_peak);
}
last_print_time = audio_time;
}