From d26004c6db833858b9ac5dcaa36f3f412ab3c643 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 19 May 2026 01:06:23 +0100 Subject: [PATCH] Expose phase-field runtime feedback mode --- docs/implementation-plan.md | 3 +- notes/current-system-map.md | 1 + scripts/live_status.py | 18 +++++++++- scripts/stream_phase_field.py | 62 +++++++++++++++++++++++++++++++++++ state/map.yaml | 6 ++-- 5 files changed, 86 insertions(+), 4 deletions(-) diff --git a/docs/implementation-plan.md b/docs/implementation-plan.md index f6f4217..8150d7e 100644 --- a/docs/implementation-plan.md +++ b/docs/implementation-plan.md @@ -46,6 +46,7 @@ - `audio_field.phase_meaning` extracts actionable delay, coherence, confidence, suppression, correction-energy, and active-probe need from internal phase/chirplet evidence. - `localcast.audio.phase_field` is a typed CultCache document at `calibration/runs/audio-phase-field.msgpack`. - `scripts/stream_phase_field.py` publishes the live meaning document from an aligned mic field plus known program/loopback reference without exposing raw phase bands as the renderer API. + - `stream_phase_field.py` also writes `audio-phase-field-status.json`, which declares whether the phase estimator is running against replayed WAVs or closed-loop live capture. Current deadline mode is explicit `wav-replay` with open-loop probe playback. - `audio_field.active_probe` wires low phase-field confidence into `ActiveProbeOptimizer`, emits bounded chirplet WAVs plus `active-probes.jsonl`, and can play probes through the default output device. - `scripts/start-live-audio-phase-field.ps1` starts the live dense harmonic confidence loop with near-ultrasonic probes; `scripts/stop-live-audio-phase-field.ps1` stops the PID recorded in `logs/audio-phase-field.pid`. - Faust voice-separation boundary: @@ -80,4 +81,4 @@ 16. Fix the live Leap capture backend so actual Leap frames, not fallback frames, populate `leap-ground-truth` cells in the multi-LOD cache. 17. Keep the neighbor loopback leg running through the scheduled interactive WASAPI capture path and use it as the timing witness once actual neighbor app audio is present. 18. Let the co-streamer surface delay drive the shared presentation buffer horizon for audio stems, AmbiX, and remote video. -19. Wire `stream_phase_field.py` and `stream_faust_mic_field.py` to the real live aligned-field producer instead of replaying WAV artifacts, then feed emitted active chirps back through loopback/mic capture so confidence maintenance closes against fresh observations instead of dry-run probe manifests. +19. Wire `stream_phase_field.py` and `stream_faust_mic_field.py` to the real live aligned-field producer instead of replaying WAV artifacts, then feed emitted active chirps back through loopback/mic capture so `audio-phase-field-status.json` can report closed-loop probe capture. diff --git a/notes/current-system-map.md b/notes/current-system-map.md index afc8eb8..0077809 100644 --- a/notes/current-system-map.md +++ b/notes/current-system-map.md @@ -73,6 +73,7 @@ Ownership: - `audio_field/` owns unit-testable buffering, bounded-latency convergence, injectable port protocols, and pipeline orchestration. - Runtime sync owns per-block chirplet observations from known speaker output and updates delay/SRO/phase estimates with confidence gates before alignment. - `audio_field.phase_meaning` owns extracting usable meaning from internal phase/chirplet evidence. The live cache publishes delay correction, coherence, confidence, distance-equivalent delta, reference-bleed/suppression estimates, correction energy, and active-probe need; raw phase bands stay inside the estimator. +- `stream_phase_field.py` writes `audio-phase-field-status.json` beside the typed phase cache. That status declares the current input mode and whether active probes are actually closed-loop. Current deadline mode is `wav-replay` with open-loop playback, so low confidence is a data-path truth rather than a mysterious estimator mood. - Active probe optimization owns extra chirplet emission when confidence drops, bounded by level/spacing/audibility budget. `audio_field.active_probe` is the runtime join that converts phase-field confidence into emitted chirplet WAVs/manifests and optional default-device playback. - The camera/sensor-fusion pipeline may publish world poses later; it does not own audio clocks or channel timing. - OBS may ingest rendered output later; it is not the authority for the Ambisonic field. diff --git a/scripts/live_status.py b/scripts/live_status.py index 8dddc90..766f5e1 100644 --- a/scripts/live_status.py +++ b/scripts/live_status.py @@ -80,6 +80,7 @@ def msgpack_head(path: Path): } ) elif summary["type"] == "localcast.audio.phase_field": + sources = payload[7] if len(payload) > 7 else [] summary.update( { "frameId": payload[1], @@ -87,9 +88,22 @@ def msgpack_head(path: Path): "startSample": payload[4], "frameCount": payload[5], "referenceId": payload[6], - "sourceCount": len(payload[7]) if len(payload) > 7 else 0, + "sourceCount": len(sources), "globalConfidence": payload[8] if len(payload) > 8 else 0.0, "needsActiveProbe": payload[9] if len(payload) > 9 else True, + "sources": [ + { + "sourceId": source.get("sourceId"), + "delayMs": source.get("delayMs"), + "distanceDeltaMeters": source.get("distanceDeltaMeters"), + "coherence": source.get("coherence"), + "fitErrorRadians": source.get("fitErrorRadians"), + "confidence": source.get("confidence"), + "referenceBleed": source.get("referenceBleed"), + "suppressionWeight": source.get("suppressionWeight"), + } + for source in sources + ], } ) elif summary["type"] == "localcast.audio.mic_field": @@ -149,6 +163,7 @@ def main() -> None: "visual-stream-status.msgpack", "audio-stream-status.msgpack", "audio-phase-field.msgpack", + "audio-phase-field-status.json", "audio-mic-field.msgpack", "clap-events.msgpack", "active-probes/active-probes.jsonl", @@ -166,6 +181,7 @@ def main() -> None: "audioHead": msgpack_head(runs / "audio-state.msgpack"), "eventsHead": msgpack_head(runs / "audio-events.msgpack"), "phaseFieldHead": msgpack_head(runs / "audio-phase-field.msgpack"), + "phaseRuntime": read_json(runs / "audio-phase-field-status.json"), "micFieldHead": msgpack_head(runs / "audio-mic-field.msgpack"), "clapHead": msgpack_head(runs / "clap-events.msgpack"), "lastActiveProbe": read_last_jsonl(runs / "active-probes" / "active-probes.jsonl"), diff --git a/scripts/stream_phase_field.py b/scripts/stream_phase_field.py index 5ae6cb3..c39d1a1 100644 --- a/scripts/stream_phase_field.py +++ b/scripts/stream_phase_field.py @@ -27,6 +27,52 @@ def read_float_wav(path: Path) -> tuple[int, np.ndarray]: return int(rate), samples +def write_phase_runtime_status( + path: Path, + *, + field: Path, + reference: Path, + frame_id: int, + global_confidence: float, + needs_active_probe: bool, + emitted_probe, + maintain_confidence: bool, + play_probes: bool, +) -> None: + import json + + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text( + json.dumps( + { + "input_mode": "wav-replay", + "field": str(field), + "reference": str(reference), + "frame_id": int(frame_id), + "global_confidence": float(global_confidence), + "needs_active_probe": bool(needs_active_probe), + "maintain_confidence": bool(maintain_confidence), + "play_probes": bool(play_probes), + "probe_feedback_mode": "open-loop-playback" if play_probes else "dry-run", + "closed_loop_probe_capture": False, + "last_probe": None + if emitted_probe is None + else { + "source_id": emitted_probe.request.source_id, + "reason": emitted_probe.request.reason, + "urgency": emitted_probe.request.urgency, + "path": str(emitted_probe.path), + "emitted_monotonic_ns": emitted_probe.emitted_monotonic_ns, + }, + "updated_monotonic_ns": time.monotonic_ns(), + }, + indent=2, + sort_keys=True, + ), + encoding="utf-8", + ) + + def parse_frequencies(values: list[str]) -> list[float]: out: list[float] = [] for value in values: @@ -68,6 +114,7 @@ def main() -> None: parser.add_argument("--field", type=Path, required=True, help="Aligned frames-by-channel mic field WAV.") parser.add_argument("--reference", type=Path, required=True, help="Known program/loopback reference WAV.") parser.add_argument("--cache", type=Path, default=ROOT / "calibration" / "runs" / "audio-phase-field.msgpack") + parser.add_argument("--status", type=Path, default=ROOT / "calibration" / "runs" / "audio-phase-field-status.json") parser.add_argument("--source-id", action="append", default=[]) parser.add_argument("--reference-id", default="program-reference") parser.add_argument("--frequency", action="append", default=["250,500,1000,2000,4000,8000,12000"]) @@ -139,6 +186,7 @@ def main() -> None: frame_id = 0 cursor = 0 max_samples = min(len(reference_mono), len(field)) + last_status = 0.0 while cursor + args.chunk_frames <= max_samples: if args.duration is not None and time.monotonic() - start_monotonic >= args.duration: break @@ -167,10 +215,24 @@ def main() -> None: active_probe_reason=meaning.active_probe_reason, ), ) + emitted = None if maintainer is not None: emitted = maintainer.update(meaning, block_ref, force_masked=args.probe_unmasked) if emitted is not None and args.play_probes: play_probe_file(emitted.path) + if time.monotonic() - last_status >= 1.0: + write_phase_runtime_status( + args.status, + field=args.field, + reference=args.reference, + frame_id=meaning.frame_id, + global_confidence=meaning.global_confidence, + needs_active_probe=meaning.needs_active_probe, + emitted_probe=emitted, + maintain_confidence=args.maintain_confidence, + play_probes=args.play_probes, + ) + last_status = time.monotonic() frame_id += 1 cursor += args.hop_frames if cursor + args.chunk_frames > max_samples and args.loop: diff --git a/state/map.yaml b/state/map.yaml index 4da0807..947963f 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -141,8 +141,10 @@ research: ActiveProbeOptimizer and emitting bounded chirplet WAVs/manifests, with optional default-device playback. The live launcher now uses dense harmonic near-ultrasonic probe textures so aliases have a musical - relationship instead of arbitrary squeal. This is learned audio-field - state, not a phase display. + relationship instead of arbitrary squeal. `audio-phase-field-status.json` + declares input mode and whether active probes are closed-loop; current + deadline mode is explicit `wav-replay` with open-loop probe playback. + This is learned audio-field state, not a phase display. faust_voice_separation: summary: docs/aquarium-spatial-audio.md key_decision: >