nx_dynaoracle.nx source
↩ module page · 390 lines · 20414 B
1// nx_dynaoracle.nx -- MEASURE SOFT-TISSUE DYNAMICS FROM VIDEO, IN THE SUBJECT'S OWN UNITS, WITH
2// THE SAME ESTIMATOR THE XPBD PLANT IS MEASURED WITH.
3//
4// WHY THIS EXISTS. Every fidelity claim on /world/beach until now was PLANT-against-CITED-BAND:
5// nx_dyna_bind_skin rings the XPBD cage down and compares fn/zeta to knowledge/gamefeel_oracle.conf.
6// That is sound for the plant and says NOTHING about the render, because correct fn and zeta do not
7// imply correct amplitude, correct phase relative to footfall, or correct mode shape. A source
8// comment in the craft world states the old doctrine outright -- "measuring our own tissue needs no
9// reference footage" -- and that was right for a ringdown and insufficient for a LOOK. This organ is
10// the other half: it measures REAL FOOTAGE and OUR OWN RENDER CAPTURE through one instrument, so the
11// comparison is like-for-like instead of two rulers pointed at two subjects.
12//
13// THE EXCEED, NAMED. gamefeel_oracle.conf's own closing note records that the 2025-26 differentiable
14// -simulation literature (MonoPhysics, PhysCoRe, EgoPhys) recovers Young's modulus, Poisson ratio and
15// yield stress and NEVER damping, never on human soft tissue. PhysRig [arXiv 2506.20936] fits
16// material prototypes and likewise not damping. Damping is the parameter that governs jiggle decay.
17// Fitting zeta from video is therefore a capability the field does not have, not a catch-up rung.
18//
19// WHAT IT CAN AND CANNOT MEASURE -- stated before any number, because a limit discovered later reads
20// as a defect and a limit declared up front is a contract:
21// CAN : natural frequency, damping ratio, drive frequency, drive-to-response phase lag, and
22// amplitude AS A RATIO of a body landmark. All DIMENSIONLESS, so they survive a clip with
23// no calibration, no known camera and no known subject size.
24// CANNOT: amplitude in MILLIMETRES. There is no scale reference in an arbitrary clip. The
25// tissue_amp_walk_mm row therefore stays CITED and unmeasured by this organ, and closing
26// that gap needs a metric parametric-mesh recovery (Multi-HMR/Anny class) used as an
27// ORACLE ONLY, never as product -- the rule this estate already applies to BodyParts3D.
28//
29// HOW CAMERA AND BODY MOTION ARE CANCELLED. Three signals come off every frame pair:
30// tissue ROI flow = camera + body translation + tissue oscillation
31// reference ROI = camera + body translation (a RIGID torso patch)
32// tissue - reference = tissue oscillation alone.
33// The NOISE FLOOR is not a tunable. It is measured from the reference ROI's OWN TOP AND BOTTOM
34// HALVES differenced: both halves sit on the same rigid body and share camera and body motion
35// exactly, so their difference is pure measurement noise BY CONSTRUCTION. That is a negative control
36// the caller cannot forget to supply and cannot fudge, and it is why this organ has no deadband
37// constant. A deadband picked by taste decides how much real oscillation reads as noise, which is
38// the one number an author must never choose after seeing the result.
39//
40// usage: nx_dynaoracle measure <raw_gray8> <w> <h> <fps_milli> <tx0> <ty0> <tx1> <ty1> <rx0> <ry0> <rx1> <ry1>
41// <raw_gray8> is a headerless stream of w*h single-byte luma frames. Frame count is DERIVED from
42// the file size, never capped: a cap that has to be guessed truncates in silence.
43// BREAK-GLASS DECLARED (rule 29, NishiLang-for-everything): producing that stream from a webm or
44// mp4 currently uses ffmpeg as a pure DECODER. It computes nothing, decides nothing and judges
45// nothing -- every measurement below is NishiLang. The organ that would replace it is a sovereign
46// VP9/H.264 decode lane, and it is named here rather than left silent.
47// rc: 0 measured, 2 usage, 3 unreadable, 4 refused (geometry or frame count), 5 UNOBSERVABLE
48// license_tier: ORIGINAL
49import "nx_syscalls.nx"
50import "nx_image.nx"
51import "nx_motion.nx"
52import "nx_ringdown_lib.nx"
53
54const DO_OUTFD: i64 = 1
55const DO_EXIT_OK: i64 = 0
56const DO_EXIT_USAGE: i64 = 2
57const DO_EXIT_UNREADABLE: i64 = 3
58const DO_EXIT_REFUSED: i64 = 4
59const DO_EXIT_UNOBSERVABLE: i64 = 5
60
61const DO_PERMIL: i64 = 1000
62const DO_US_PER_S: i64 = 1000000
63const DO_MILLI: i64 = 1000
64const DO_MIN_FRAMES: i64 = 3
65
66// DERIVED, NOT CHOSEN. Lucas-Kanade skips a half-window border, so a rect narrower or shorter than
67// the integration window has ZERO interior pixels and its mean is structurally empty. The floor is
68// that window's area, computed from nx_motion's OWN constant so it can never drift from it.
69// knowledge/dynaoracle.conf carries the same figure and nx_dynaoracle_gate asserts the two are
70// equal -- the anti-drift mechanism the beach lane already proved, applied here.
71const DO_MIN_ROI_PX: i64 = NX_MOTION_WIN * NX_MOTION_WIN
72// One Q8 quantum: the smallest representable non-zero flow magnitude nx_motion can return. A
73// threshold below this admits nothing extra; one above silently discards real sub-pixel motion.
74const DO_FLOW_MIN_Q8: i64 = 1
75
76func do_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
77func do_out(s: *u8) -> i64 { sys_write(DO_OUTFD, s, do_slen(s)); return 0 }
78func do_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
79
80func do_num(v: i64) -> i64 {
81 let t: *u8 = sys_mmap(32) as *u8
82 var m: i64 = v
83 var w: i64 = 0
84 if m < 0 { t[w] = 45 as u8; w = w + 1; m = 0 - m }
85 if m == 0 { t[w] = 48 as u8; w = w + 1; sys_write(DO_OUTFD, t, w); return 0 }
86 let d: *u8 = sys_mmap(32) as *u8
87 var k: i64 = 0
88 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
89 var j: i64 = 0
90 while j < k { t[w] = d[k - 1 - j]; w = w + 1; j = j + 1 }
91 sys_write(DO_OUTFD, t, w)
92 return 0
93}
94
95func do_kv(k: *u8, v: i64) -> i64 { do_out(k); do_out("=" as *u8); do_num(v); do_out("\n" as *u8); return 0 }
96func do_ks(k: *u8, v: *u8) -> i64 { do_out(k); do_out("=" as *u8); do_out(v); do_out("\n" as *u8); return 0 }
97
98func do_atoi(s: *u8) -> i64 {
99 var v: i64 = 0
100 var i: i64 = 0
101 var neg: i64 = 0
102 if s[0] == (45 as u8) { neg = 1; i = 1 }
103 while s[i] != (0 as u8) {
104 let c: i64 = (s[i] & 0xff) as i64
105 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48) } }
106 i = i + 1
107 }
108 if neg == 1 { return 0 - v }
109 return v
110}
111
112// A CROP IS A VIEW, NOT A COPY. Image carries an explicit stride, so pointing pixels into the middle
113// of a mapped frame and keeping the PARENT stride yields a true zero-copy sub-image. This is what
114// makes per-frame optical flow affordable: only the two ROIs are ever touched, never the full frame.
115func do_crop(dst: *Image, base: *u8, frame_off: i64, parent_stride: i64,
116 x0: i64, y0: i64, x1: i64, y1: i64) -> i64 {
117 dst.pixels = ((base as i64) + frame_off + y0 * parent_stride + x0) as *u8
118 dst.width = x1 - x0
119 dst.height = y1 - y0
120 dst.channels = 1
121 dst.stride = parent_stride
122 return 0
123}
124
125// (the single-scale DoScratch workspace was REMOVED when the pyramid landed -- MotionPyr in
126// nx_motion.nx owns that allocation now, and leaving a dead twin here would land as an nx_unwired
127// regression naming this file.)
128
129func main(argc: i64, argv: *i64) -> i64 {
130 if argc < 14 {
131 do_out("usage: nx_dynaoracle measure <raw_gray8> <w> <h> <fps_milli> <tx0> <ty0> <tx1> <ty1> <rx0> <ry0> <rx1> <ry1>\n" as *u8)
132 return DO_EXIT_USAGE
133 }
134 let path: *u8 = argv[2] as *u8
135 let W: i64 = do_atoi(argv[3] as *u8)
136 let H: i64 = do_atoi(argv[4] as *u8)
137 let fps_milli: i64 = do_atoi(argv[5] as *u8)
138 let tx0: i64 = do_atoi(argv[6] as *u8)
139 let ty0: i64 = do_atoi(argv[7] as *u8)
140 let tx1: i64 = do_atoi(argv[8] as *u8)
141 let ty1: i64 = do_atoi(argv[9] as *u8)
142 let rx0: i64 = do_atoi(argv[10] as *u8)
143 let ry0: i64 = do_atoi(argv[11] as *u8)
144 let rx1: i64 = do_atoi(argv[12] as *u8)
145 let ry1: i64 = do_atoi(argv[13] as *u8)
146
147 if W <= 0 { do_out("REFUSED bad-width\n" as *u8); return DO_EXIT_REFUSED }
148 if H <= 0 { do_out("REFUSED bad-height\n" as *u8); return DO_EXIT_REFUSED }
149 if fps_milli <= 0 { do_out("REFUSED bad-fps\n" as *u8); return DO_EXIT_REFUSED }
150
151 let tw: i64 = tx1 - tx0
152 let th: i64 = ty1 - ty0
153 let rw: i64 = rx1 - rx0
154 let rh: i64 = ry1 - ry0
155 let half: i64 = rh / 2
156 // REFUSE a structurally empty ROI by NAME rather than returning a confident zero from it.
157 if tw * th < DO_MIN_ROI_PX {
158 do_out("REFUSED tissue-roi-below-lk-window min_roi_px=" as *u8); do_num(DO_MIN_ROI_PX); do_out("\n" as *u8)
159 return DO_EXIT_REFUSED
160 }
161 if rw * rh < DO_MIN_ROI_PX {
162 do_out("REFUSED reference-roi-below-lk-window min_roi_px=" as *u8); do_num(DO_MIN_ROI_PX); do_out("\n" as *u8)
163 return DO_EXIT_REFUSED
164 }
165 // The noise control splits the reference ROI in half, so it needs two halves that each clear the
166 // window. Refusing here beats silently measuring a noise floor from an empty half.
167 if rh < NX_MOTION_WIN * 2 {
168 do_out("REFUSED reference-roi-too-short-to-split-for-noise-control need_h=" as *u8)
169 do_num(NX_MOTION_WIN * 2); do_out("\n" as *u8)
170 return DO_EXIT_REFUSED
171 }
172
173 let lenp: *i64 = (sys_mmap(16)) as *i64
174 let base: *u8 = sys_read_file(path, lenp)
175 if (base as i64) == 0 { do_out("REFUSED unreadable-input\n" as *u8); return DO_EXIT_UNREADABLE }
176 let flen: i64 = lenp[0]
177 let stride: i64 = W * H
178 let nframes: i64 = flen / stride
179 if nframes < DO_MIN_FRAMES {
180 do_out("REFUSED too-few-frames frames=" as *u8); do_num(nframes)
181 do_out(" need=" as *u8); do_num(DO_MIN_FRAMES); do_out("\n" as *u8)
182 return DO_EXIT_REFUSED
183 }
184 let dt_us: i64 = DO_US_PER_S * DO_MILLI / fps_milli
185
186 let tA: *Image = nx_image_alloc(1, 1, 1)
187 let tB: *Image = nx_image_alloc(1, 1, 1)
188 let rA: *Image = nx_image_alloc(1, 1, 1)
189 let rB: *Image = nx_image_alloc(1, 1, 1)
190 // COARSE-TO-FINE. One pyramid per region, allocated ONCE and reused for every frame pair.
191 // Single-scale Lucas-Kanade could not see this subject: measured on a fixture with a 14-pixel
192 // oscillation at 2 Hz and 30 fps it recovered about 1 px, and the third state correctly said so.
193 // The two half-reference pyramids carry the noise control -- both halves sit on the same rigid
194 // body, so their differential is measurement noise by construction.
195 let pt: *MotionPyr = nx_motion_pyr_new(tw, th)
196 let pr: *MotionPyr = nx_motion_pyr_new(rw, rh)
197 let ph1: *MotionPyr = nx_motion_pyr_new(rw, half)
198 let ph2: *MotionPyr = nx_motion_pyr_new(rw, rh - half)
199 let h1A: *Image = nx_image_alloc(1, 1, 1)
200 let h1B: *Image = nx_image_alloc(1, 1, 1)
201 let h2A: *Image = nx_image_alloc(1, 1, 1)
202 let h2B: *Image = nx_image_alloc(1, 1, 1)
203
204 let tis: *i64 = (sys_mmap(nframes * 8 + 16)) as *i64
205 let drv: *i64 = (sys_mmap(nframes * 8 + 16)) as *i64
206 let ctl: *i64 = (sys_mmap(nframes * 8 + 16)) as *i64
207 tis[0] = 0
208 drv[0] = 0
209 ctl[0] = 0
210
211 let ou: *i64 = (sys_mmap(16)) as *i64
212 let ov: *i64 = (sys_mmap(16)) as *i64
213 let ou2: *i64 = (sys_mmap(16)) as *i64
214 let ov2: *i64 = (sys_mmap(16)) as *i64
215 let hu1: *i64 = (sys_mmap(16)) as *i64
216 let hv1: *i64 = (sys_mmap(16)) as *i64
217 let hu2: *i64 = (sys_mmap(16)) as *i64
218 let hv2: *i64 = (sys_mmap(16)) as *i64
219
220 var observed: i64 = 0
221 var unobserved: i64 = 0
222 var f: i64 = 0
223 while f < nframes - 1 {
224 let o1: i64 = f * stride
225 let o2: i64 = (f + 1) * stride
226 do_crop(tA, base, o1, W, tx0, ty0, tx1, ty1)
227 do_crop(tB, base, o2, W, tx0, ty0, tx1, ty1)
228 do_crop(rA, base, o1, W, rx0, ry0, rx1, ry1)
229 do_crop(rB, base, o2, W, rx0, ry0, rx1, ry1)
230
231 let nt: i64 = nx_motion_mean_flow_pyr(pt, tA, tB, DO_FLOW_MIN_Q8, ou, ov)
232 let nr: i64 = nx_motion_mean_flow_pyr(pr, rA, rB, DO_FLOW_MIN_Q8, ou2, ov2)
233 // NOISE CONTROL: two halves of the SAME rigid reference patch, each through its own pyramid.
234 do_crop(h1A, base, o1, W, rx0, ry0, rx1, ry0 + half)
235 do_crop(h1B, base, o2, W, rx0, ry0, rx1, ry0 + half)
236 do_crop(h2A, base, o1, W, rx0, ry0 + half, rx1, ry1)
237 do_crop(h2B, base, o2, W, rx0, ry0 + half, rx1, ry1)
238 nx_motion_mean_flow_pyr(ph1, h1A, h1B, DO_FLOW_MIN_Q8, hu1, hv1)
239 nx_motion_mean_flow_pyr(ph2, h2A, h2B, DO_FLOW_MIN_Q8, hu2, hv2)
240
241 var dv: i64 = 0
242 var rv: i64 = 0
243 var cv: i64 = 0
244 if nt > 0 {
245 if nr > 0 {
246 dv = ov[0] - ov2[0]
247 rv = ov2[0]
248 cv = hv1[0] - hv2[0]
249 observed = observed + 1
250 } else { unobserved = unobserved + 1 }
251 } else { unobserved = unobserved + 1 }
252 // An UNOBSERVED pair contributes zero VELOCITY, which holds the displacement flat rather
253 // than inventing motion. It is counted, and coverage is published beside every figure.
254 tis[f + 1] = tis[f] + dv
255 drv[f + 1] = drv[f] + rv
256 ctl[f + 1] = ctl[f] + cv
257 f = f + 1
258 }
259
260 // DEADBAND: MEASURED, never chosen. Peak excursion of the rigid-vs-rigid control.
261 var deadband: i64 = 0
262 var i: i64 = 0
263 while i < nframes { if do_abs(ctl[i]) > deadband { deadband = do_abs(ctl[i]) } i = i + 1 }
264
265 // BASELINE REMOVAL, BOTH HALVES PUBLISHED. Fit the ramp on the SETTLED half only -- a decaying
266 // cosine has a non-zero whole-window slope that is NOT drift, and removing it tilts the waveform
267 // (measured: 7500 mHz reported against a 1960 mHz truth). Then centre on the settled level,
268 // because a decay ends somewhere new and a line cannot remove a step.
269 let ta: *i64 = (sys_mmap(16)) as *i64
270 let tb: *i64 = (sys_mmap(16)) as *i64
271 let da: *i64 = (sys_mmap(16)) as *i64
272 let db: *i64 = (sys_mmap(16)) as *i64
273 let teq: *i64 = (sys_mmap(16)) as *i64
274 let deq: *i64 = (sys_mmap(16)) as *i64
275 rd_detrend_from(tis, nframes, nframes / 2, ta, tb)
276 rd_detrend_from(drv, nframes, nframes / 2, da, db)
277 rd_center_on_tail(tis, nframes, teq)
278 rd_center_on_tail(drv, nframes, deq)
279
280 // AMPLITUDE FROM THE FULL SERIES, FREQUENCY AND DAMPING FROM THE SKIPPED ONE -- two questions,
281 // two windows, both stated. Integrating velocity cannot recover the INITIAL displacement: that
282 // DC term is structurally unavailable from flow alone, so the FIRST lobe carries an
283 // unrecoverable offset. The log decrement is a RATIO of successive lobes, so a corrupted first
284 // lobe corrupts zeta directly -- measured 627 permil against an injected 200 while the frequency
285 // was already accurate to 4 percent. Frequency is timing and survives an offset; damping is
286 // amplitude and does not. Starting at the first crossing makes both analysed lobes offset-free.
287 var full_maxabs: i64 = 0
288 var fm: i64 = 0
289 while fm < nframes { if do_abs(tis[fm]) > full_maxabs { full_maxabs = do_abs(tis[fm]) } fm = fm + 1 }
290 var skip: i64 = 0
291 var sg0: i64 = 0
292 var sk: i64 = 0
293 while sk < nframes {
294 var sv: i64 = 0
295 if tis[sk] > deadband { sv = 1 }
296 if tis[sk] < 0 - deadband { sv = 0 - 1 }
297 if sv != 0 {
298 if sg0 == 0 { sg0 = sv }
299 else { if sv != sg0 { if skip == 0 { skip = sk } } }
300 }
301 sk = sk + 1
302 }
303 let tis2: *i64 = ((tis as i64) + skip * 8) as *i64
304 let rt: *i64 = (sys_mmap(RD_R_N * 8 + 16)) as *i64
305 let rdv: *i64 = (sys_mmap(RD_R_N * 8 + 16)) as *i64
306 let rc_t: i64 = rd_analyze(tis2, nframes - skip, dt_us, deadband, rt)
307 let rc_d: i64 = rd_analyze(drv, nframes, dt_us, deadband, rdv)
308
309 do_out("NX-DYNAORACLE v1\n" as *u8)
310 do_ks("input" as *u8, path)
311 do_kv("width" as *u8, W)
312 do_kv("height" as *u8, H)
313 do_kv("frames" as *u8, nframes)
314 do_kv("fps_milli" as *u8, fps_milli)
315 do_kv("dt_us" as *u8, dt_us)
316 do_kv("pairs_observed" as *u8, observed)
317 do_kv("pairs_unobserved" as *u8, unobserved)
318 // PARTITION, PRINTED AND CHECKED: a coverage claim whose parts do not sum is a leak.
319 do_kv("pairs_total" as *u8, observed + unobserved)
320 do_kv("coverage_permil" as *u8, observed * DO_PERMIL / (nframes - 1))
321 do_kv("tissue_equilibrium_removed_q8" as *u8, teq[0])
322 do_kv("drive_equilibrium_removed_q8" as *u8, deq[0])
323 do_kv("tissue_drift_removed_q8_per_frame_q16" as *u8, tb[0])
324 do_kv("drive_drift_removed_q8_per_frame_q16" as *u8, db[0])
325 do_kv("tissue_lead_samples_skipped" as *u8, skip)
326 do_ks("deadband_src" as *u8, "MEASURED-rigid-half-differential" as *u8)
327 do_kv("deadband_q8" as *u8, deadband)
328
329 do_ks("tissue_reason" as *u8, rd_reason(rc_t))
330 do_kv("tissue_fn_mhz" as *u8, rt[RD_R_FN_MHZ])
331 do_kv("tissue_zeta_permil" as *u8, rt[RD_R_ZETA])
332 do_kv("tissue_peak_a1_q8" as *u8, rt[RD_R_A1])
333 do_kv("tissue_peak_a2_q8" as *u8, rt[RD_R_A2])
334 do_kv("tissue_crossings" as *u8, rt[RD_R_PEAKS])
335 do_kv("tissue_maxabs_q8" as *u8, full_maxabs)
336 do_kv("tissue_maxabs_post_skip_q8" as *u8, rt[RD_R_MAXABS])
337 do_kv("tissue_residual_q8" as *u8, rt[RD_R_RESID])
338
339 // BOTH ESTIMATORS ARE PUBLISHED AND NEITHER REPLACES THE OTHER. The two-lobe decrement above
340 // reads ONE amplitude ratio one period apart, so every imprecision in that single ratio lands
341 // on zeta undivided. The span rows below read the SAME textbook identity across every
342 // half-period whose spacing proves it IS one, which divides the declared imprecision by the
343 // baseline -- and each carries the tolerance the arithmetic can support on THIS record rather
344 // than a constant. When the two disagree, the disagreement is the finding: it means the record
345 // stopped being periodic partway, which is a state no single confident number can express.
346 do_ks("tissue_span_reason" as *u8, rd_reason(rt[RD_R_SPAN_RC]))
347 do_kv("tissue_span_halves" as *u8, rt[RD_R_SPAN_HALVES])
348 do_kv("tissue_span_lobes_seen" as *u8, rt[RD_R_SPAN_LOBES])
349 do_kv("tissue_span_peak_a_q8" as *u8, rt[RD_R_SPAN_A])
350 do_kv("tissue_span_peak_b_q8" as *u8, rt[RD_R_SPAN_B])
351 do_kv("tissue_span_fn_mhz" as *u8, rt[RD_R_SPAN_FN_MHZ])
352 do_kv("tissue_span_fn_tol_permil" as *u8, rt[RD_R_SPAN_FN_TOL])
353 do_kv("tissue_span_zeta_permil" as *u8, rt[RD_R_SPAN_ZETA])
354 do_kv("tissue_span_zeta_tol_permil" as *u8, rt[RD_R_SPAN_ZETA_TOL])
355
356 do_ks("drive_reason" as *u8, rd_reason(rc_d))
357 do_kv("drive_fn_mhz" as *u8, rdv[RD_R_FN_MHZ])
358 do_kv("drive_crossings" as *u8, rdv[RD_R_PEAKS])
359 // The DRIVE is the control the tissue rows are read against: it is a rigid-body motion, so a
360 // clip whose drive frequency is not recovered has a front end that is not delivering
361 // displacement, and no tissue number taken from that clip means anything. Publishing the span
362 // estimator on the drive too is what makes that check one line instead of an investigation.
363 do_ks("drive_span_reason" as *u8, rd_reason(rdv[RD_R_SPAN_RC]))
364 do_kv("drive_span_halves" as *u8, rdv[RD_R_SPAN_HALVES])
365 do_kv("drive_span_fn_mhz" as *u8, rdv[RD_R_SPAN_FN_MHZ])
366 do_kv("drive_span_fn_tol_permil" as *u8, rdv[RD_R_SPAN_FN_TOL])
367
368 // AMPLITUDE AS A RATIO of the reference ROI height. Dimensionless on purpose: see the header.
369 // tis is accumulated Q8 pixels, so divide the Q8 out before ratioing against a pixel height.
370 do_kv("amp_permil_of_ref_roi_h" as *u8, full_maxabs * DO_PERMIL / (NX_MOTION_Q * rh))
371 do_ks("amp_mm" as *u8, "UNMEASURABLE-no-scale-reference-in-clip" as *u8)
372
373 var lag_state: *u8 = "UNOBSERVABLE-no-drive-period" as *u8
374 let lagp: *i64 = (sys_mmap(16)) as *i64
375 lagp[0] = 0
376 if rdv[RD_R_PER_US] > 0 {
377 let per_samples: i64 = rdv[RD_R_PER_US] / dt_us
378 let rcl: i64 = rd_phase_lag_permil(drv, tis, nframes, per_samples, lagp)
379 lag_state = rd_reason(rcl)
380 }
381 do_ks("phase_lag_reason" as *u8, lag_state)
382 do_kv("phase_lag_permil_of_period" as *u8, lagp[0])
383
384 // NUMBERS, NEVER A VERDICT. This organ is not calibrated against a labelled corpus, so it must
385 // not convert its own measurements into a pass. nx_dynaoracle_gate owns the band comparison
386 // against knowledge/gamefeel_oracle.conf, which is the ONE place those bands live.
387 if rc_t != RD_OK { do_out("verdict=UNOBSERVABLE\n" as *u8); return DO_EXIT_UNOBSERVABLE }
388 do_out("verdict=MEASURED\n" as *u8)
389 return DO_EXIT_OK
390}