diff --git a/audio_field/active_probe.py b/audio_field/active_probe.py index dd64342..637e763 100644 --- a/audio_field/active_probe.py +++ b/audio_field/active_probe.py @@ -46,6 +46,7 @@ class ActiveConfidenceMaintainer: harmonic_voices: int = 24, max_artifacts: int = 512, manifest_max_bytes: int = 1_000_000, + eligible_source_ids: set[str] | frozenset[str] | None = None, ): self.optimizer = optimizer self.sample_rate = int(sample_rate) @@ -60,6 +61,7 @@ class ActiveConfidenceMaintainer: self.harmonic_voices = int(harmonic_voices) self.max_artifacts = int(max_artifacts) self.manifest_max_bytes = int(manifest_max_bytes) + self.eligible_source_ids = None if eligible_source_ids is None else frozenset(str(source_id) for source_id in eligible_source_ids) if self.channels <= 0: raise ValueError("channels must be positive") if self.channel < 0 or self.channel >= self.channels: @@ -70,6 +72,10 @@ class ActiveConfidenceMaintainer: def update(self, meaning: PhaseFieldMeaning, reference_block: np.ndarray, *, force_masked: bool = False) -> EmittedProbe | None: states = sync_states_from_phase_meaning(meaning) + if self.eligible_source_ids is not None: + states = {source_id: state for source_id, state in states.items() if source_id in self.eligible_source_ids} + if not states: + return None masked = force_masked or is_masked_window(reference_block) request = self.optimizer.choose_probe(meaning.frame_id, states, masked_window=masked) if request is None: diff --git a/docs/audio-field.md b/docs/audio-field.md index a6a6cbf..c4645be 100644 --- a/docs/audio-field.md +++ b/docs/audio-field.md @@ -146,7 +146,7 @@ For the current deadline rig, `scripts/stream_live_audio_field.py` owns the live .\.venv\Scripts\python.exe .\scripts\stream_live_audio_field.py --profile .\config\audio-field.example.json --loopback-query Scarlett --maintain-confidence --play-probes --probe-output-query Scarlett ``` -It publishes both `audio-mic-field.msgpack` and `audio-phase-field.msgpack` from visible local mics, records missing distributed channels as explicit placeholders, captures Scarlett loopback as the known reference, and resamples probe playback when the Scarlett output is exposed as 44.1 kHz while the capture field remains 48 kHz. +It publishes both `audio-mic-field.msgpack` and `audio-phase-field.msgpack` from visible local mics, records missing distributed channels as explicit placeholders, captures Scarlett loopback as the known reference, and resamples probe playback when the Scarlett output is exposed as 44.1 kHz while the capture field remains 48 kHz. Active probe scheduling is restricted to source ids with a live local capture device; placeholders stay in the cache for channel stability, but the calibration loop does not waste chirps trying to synchronize silence. For the current live app, start the dense harmonic confidence-maintenance loop: diff --git a/docs/implementation-plan.md b/docs/implementation-plan.md index 5a4761e..0b36a8c 100644 --- a/docs/implementation-plan.md +++ b/docs/implementation-plan.md @@ -54,6 +54,7 @@ - `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/stream_live_audio_field.py` is the live local capture owner for the deadline rig. It publishes `localcast.audio.mic_field` and `localcast.audio.phase_field` from visible local WASAPI/PortAudio mics plus Scarlett loopback, reports missing rig channels as explicit placeholders, plays confidence probes through the selected Scarlett output, and resamples probe playback when the output device runs at 44.1 kHz while the field timeline remains 48 kHz. + - Active probe maintenance only targets source ids backed by live local capture devices. Missing distributed channels remain stable placeholders in the mic/phase field, but they do not consume chirp budget. - Active probe artifacts are bounded: emitted chirps rotate through a fixed slot set and the manifest rotates at a byte cap. The calibration loop is allowed to be noisy; it is not allowed to become an unbounded filesystem leak. - `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: diff --git a/scripts/stream_live_audio_field.py b/scripts/stream_live_audio_field.py index 80486a5..c3ab478 100644 --- a/scripts/stream_live_audio_field.py +++ b/scripts/stream_live_audio_field.py @@ -307,6 +307,7 @@ def main() -> None: extractor = LivePhaseMeaningExtractor(channels, sample_rate, [250.0, 500.0, 1000.0, 2000.0, 4000.0, 8000.0, 12000.0]) maintainer = None if args.maintain_confidence: + live_source_ids = {source_id_for_microphone(mic) for group in groups.values() for mic in group["mics"]} maintainer = ActiveConfidenceMaintainer( ActiveProbeOptimizer( ProbePolicy( @@ -329,6 +330,7 @@ def main() -> None: harmonic_voices=args.harmonic_voices, max_artifacts=args.probe_artifact_slots, manifest_max_bytes=args.probe_manifest_max_bytes, + eligible_source_ids={source_id for source_id in live_source_ids if source_id}, ) start = time.monotonic() origin_ns = time.monotonic_ns() diff --git a/state/map.yaml b/state/map.yaml index 5c59072..1c5fe12 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -147,7 +147,9 @@ research: phase-field CultCache documents from visible local mics plus Scarlett loopback, sends probes through the selected Scarlett output, resamples probe playback when that output is 44.1 kHz, and reports missing - distributed channels as explicit placeholders. `audio-phase-field-status.json` + distributed channels as explicit placeholders. Active probe scheduling is + restricted to source ids with live local capture devices, so placeholders + do not consume chirp budget. `audio-phase-field-status.json` declares input mode and whether active probes are closed-loop; current deadline mode is `live-local-capture` with closed-loop probe capture when Scarlett loopback is available. diff --git a/tests/test_active_probe.py b/tests/test_active_probe.py index 1a8d0d1..dcd019f 100644 --- a/tests/test_active_probe.py +++ b/tests/test_active_probe.py @@ -74,6 +74,37 @@ class ActiveProbeTests(unittest.TestCase): self.assertEqual("probe-slot-0000-weak.wav", paths[0]) self.assertEqual("probe-slot-0000-weak.wav", paths[-1]) + def test_probe_maintainer_ignores_ineligible_placeholder_sources(self): + meaning = PhaseFieldMeaning( + frame_id=10, + audio_time_ns=1, + sample_rate=48000, + start_sample=0, + frame_count=1024, + reference_id="program", + sources=( + SourcePhaseMeaning("placeholder", 0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.1, 0.0, 0.0), + SourcePhaseMeaning("live", 1, 0.0, 0.0, 0.0, 0.0, 0.6, 1.0, 0.6, 0.1, 0.0, 0.0), + ), + global_confidence=0.3, + needs_active_probe=True, + active_probe_reason="weak", + ) + reference = np.full(1024, 0.05, dtype=np.float32) + + with tempfile.TemporaryDirectory() as tmp: + maintainer = ActiveConfidenceMaintainer( + ActiveProbeOptimizer(ProbePolicy(trigger_confidence=0.35, min_interval_frames=1)), + sample_rate=48000, + output_dir=Path(tmp), + eligible_source_ids={"live"}, + ) + + emitted = maintainer.update(meaning, reference, force_masked=True) + + self.assertIsNone(emitted) + self.assertFalse((Path(tmp) / "active-probes.jsonl").exists()) + def test_probe_chirplet_respects_level_and_channel(self): chirp = make_probe_chirplet(48000, duration_seconds=0.02, start_hz=1000, end_hz=4000, level_dbfs=-20, channels=2, channel=1)