Fix no-signal noise: wrap time to [0,1000) to preserve float32 precision

CLOCK_MONOTONIC returns seconds since boot (~50000+s on a running system).
At that magnitude, float32 loses fractional precision in the hash function
and all cells evaluate to near-zero, producing a black screen instead of noise.
Wrapping to fmod(now, 1000.0) keeps the value small enough for the shader.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-29 19:31:09 +00:00
parent d6fe653a2e
commit 30ad5fbeae
2 changed files with 4 additions and 2 deletions

View File

@@ -23,7 +23,7 @@ $(NODE_BUILD)/video-node: $(MAIN_OBJ) \
$(COMMON_OBJ) $(MEDIA_OBJ) $(V4L2_OBJ) $(SERIAL_OBJ) \
$(TRANSPORT_OBJ) $(DISCOVERY_OBJ) $(CONFIG_OBJ) $(PROTOCOL_OBJ) \
$(RECONCILER_OBJ) $(INGEST_OBJ) $(XORG_OBJ)
$(CC) $(CFLAGS) -o $@ $^ -lpthread $(PKG_LDFLAGS)
$(CC) $(CFLAGS) -o $@ $^ -lpthread -lm $(PKG_LDFLAGS)
$(MAIN_OBJ): main.c | $(NODE_BUILD)
$(CC) $(CFLAGS) $(DEPFLAGS) -c -o $@ $<

View File

@@ -8,6 +8,7 @@
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <time.h>
#include <math.h>
#include <sys/sysmacros.h>
#include <linux/videodev2.h>
@@ -533,7 +534,8 @@ static void display_loop_tick(struct Node *node)
double now = (double)ts.tv_sec + (double)ts.tv_nsec * 1e-9;
double interval = 1.0 / (double)(d->no_signal_fps > 0 ? d->no_signal_fps : 15);
if (now - d->last_no_signal_t >= interval) {
xorg_viewer_render_no_signal(d->viewer, (float)now, 80.0f);
/* Wrap to [0, 1000) to preserve float32 fractional precision in shader */
xorg_viewer_render_no_signal(d->viewer, (float)fmod(now, 1000.0), 80.0f);
d->last_no_signal_t = now;
}
}