diff --git a/notes/current-system-map.md b/notes/current-system-map.md index 5817178..e09405f 100644 --- a/notes/current-system-map.md +++ b/notes/current-system-map.md @@ -319,6 +319,19 @@ then about 9.9 kHz weak response, 3.6 kHz phase instability, and 910 Hz magnitude residual. This is the intended first physical strategy: improve shotgun/cardioid confidence at 192 kHz before asking every connected mic to help solve the room field. +The first live run preserves two artifacts: +`artifacts/asio/targeted-bioacoustic-live/20260601-030836` at playback gain +1.0 and `artifacts/asio/targeted-bioacoustic-live/20260601-030857` at gain +2.0. Loopback energy scaled, but 18.6 kHz stayed nearly absent in the physical +mics; the second pass measured shotgun -51.475 dB and cardioid -56.585 dB +relative to loopback at that band. The 910 Hz probe was strongest physically, +especially shotgun at -21.994 dB relative to loopback. Current high-band +probing should be treated as failed path evidence, not a calibration win. +Louder follow-ups at gain 4 and gain 8 stayed below clipping; gain 8 reached +shotgun peak 0.140715 and cardioid peak 0.027774. Even then, 18.6 kHz remained +unusable at shotgun -54.910 dB and cardioid -63.258 dB relative to loopback. +Bias the next probe language toward usable low/mid anchors unless the speaker, +mic placement, or output path changes enough to make high-band evidence real. That real-world proof now has a first receipt: `calibration/bioacoustic/complex-contour-live-20260525-063229.md`. A freshly rendered canary-packet witness was played through Focusrite ASIO and captured diff --git a/src/Mimir.BufferSmoke/Program.cs b/src/Mimir.BufferSmoke/Program.cs index 4dc1a9f..37d5ce4 100644 --- a/src/Mimir.BufferSmoke/Program.cs +++ b/src/Mimir.BufferSmoke/Program.cs @@ -85,6 +85,17 @@ if (args.Any(arg => string.Equals(arg, "--targeted-bioacoustic-probe-smoke", Str return RunTargetedBioacousticProbeSmoke(); } +if (args.Any(arg => string.Equals(arg, "--targeted-bioacoustic-probe-live", StringComparison.OrdinalIgnoreCase))) +{ + return RunTargetedBioacousticProbeLive( + ParseStringOption(args, "--probe", "native/probes/asio_audio_cadence/build/Release/asio_audio_cadence.exe"), + ParseStringOption(args, "--output", "artifacts/asio/targeted-bioacoustic-live"), + ParseIntOption(args, "--sample-rate", 192_000), + ParseDoubleOption(args, "--gain", 1.0), + ParseIntOption(args, "--channels", 4), + ParseIntOption(args, "--reference-channel", 2)); +} + if (args.Any(arg => string.Equals(arg, "--synchronized-buffer-planner-smoke", StringComparison.OrdinalIgnoreCase))) { return RunSynchronizedBufferPlannerSmoke(); @@ -3421,6 +3432,88 @@ static int RunTargetedBioacousticProbeSmoke() : 1; } +static int RunTargetedBioacousticProbeLive( + string probePath, + string outputDirectory, + int sampleRate, + double gain, + int channels, + int referenceChannel) +{ + var residuals = ScarlettProfessionalMicProbeResiduals(); + var pathologies = ScarlettProfessionalMicPathologies(); + var plan = new MimirTargetedBioacousticProbePlanner(new MimirTargetedBioacousticProbeOptions(SampleRate: sampleRate)).Plan( + residuals, + ["asio-ch0-shotgun", "asio-ch1-cardioid"], + pathologies); + if (plan.Bands.Count == 0) + { + Console.Error.WriteLine("targeted bioacoustic live failed: planner emitted no probe bands"); + return 1; + } + + var stamp = DateTimeOffset.Now.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture); + var runDirectory = Path.Combine(outputDirectory, stamp); + Directory.CreateDirectory(runDirectory); + var renderPath = Path.Combine(runDirectory, "targeted-probe-f32.raw"); + var capturePath = Path.Combine(runDirectory, "scarlett-targeted-probe-f32.raw"); + var samples = RenderTargetedProbePlan(plan); + WriteFloat32(renderPath, samples); + Console.WriteLine( + $"targeted-bioacoustic-live-plan dir={runDirectory} sampleRate={sampleRate} samples={samples.Length} bands={plan.Bands.Count} selected={string.Join(",", plan.Bands.Select(band => $"{band.CenterHz:0}Hz/{band.Reason}/{band.Gain:0.000}"))}"); + + var captureSeconds = samples.Length / (double)sampleRate + 0.35; + var captureExit = RunAsioProbeCapture(probePath, renderPath, capturePath, sampleRate, captureSeconds, gain); + if (captureExit != 0) + { + Console.Error.WriteLine($"targeted bioacoustic live failed: ASIO probe exited {captureExit}"); + return captureExit; + } + + if (!File.Exists(capturePath)) + { + Console.Error.WriteLine($"targeted bioacoustic live failed: capture file missing {capturePath}"); + return 1; + } + + var channelSamples = ReadInterleavedFloat32(capturePath, channels, out var frameCount); + if (frameCount == 0 || referenceChannel < 0 || referenceChannel >= channels) + { + Console.Error.WriteLine($"targeted bioacoustic live failed: invalid capture frames={frameCount} channels={channels} reference={referenceChannel}"); + return 1; + } + + Console.WriteLine($"targeted-bioacoustic-live-capture path={capturePath} frames={frameCount} seconds={frameCount / (double)sampleRate:0.000} reference=asio-ch{referenceChannel}"); + var failures = 0; + foreach (var channel in new[] { 0, 1 }) + { + if (channel >= channels) + { + failures++; + continue; + } + + var label = channel == 0 ? "shotgun" : "cardioid"; + var stats = SignalStats(channelSamples[channel]); + var low = BandLimitedStats(channelSamples[channel], sampleRate, 80.0, 1000.0); + var high = BandLimitedStats(channelSamples[channel], sampleRate, 8000.0, 24000.0); + var tiltDb = 20.0 * Math.Log10(Math.Max(1.0e-9, low.Rms) / Math.Max(1.0e-9, high.Rms)); + Console.WriteLine( + $"targeted-bioacoustic-live-source ch={channel} label={label} rms={stats.Rms:0.000000} peak={stats.Peak:0.000000} lowHighTiltDb={tiltDb:0.000}"); + foreach (var band in plan.Bands) + { + var referenceEnergy = ToneEnergy(channelSamples[referenceChannel], sampleRate, band.CenterHz); + var candidateEnergy = ToneEnergy(channelSamples[channel], sampleRate, band.CenterHz); + var ratioDb = 20.0 * Math.Log10(Math.Max(1.0e-12, candidateEnergy) / Math.Max(1.0e-12, referenceEnergy)); + var bandConfidence = candidateEnergy / (candidateEnergy + Math.Max(1.0e-9, stats.Rms * 0.20)); + Console.WriteLine( + $"targeted-bioacoustic-live-band ch={channel} label={label} centerHz={band.CenterHz:0.0} reason={band.Reason} refEnergy={referenceEnergy:0.000000} micEnergy={candidateEnergy:0.000000} ratioDb={ratioDb:0.000} confidence={bandConfidence:0.000}"); + } + } + + return failures == 0 ? 0 : 1; +} + static int RunSynchronizedBufferPlannerSmoke() { const long t0 = 1_000_000_000; @@ -3698,6 +3791,113 @@ static MimirCalibratedAudioCompositeSource NewCompositeSource( return new MimirCalibratedAudioCompositeSource(sourceId, 48_000, samples, state, responses, noiseRms); } +static MimirAudioCalibrationBandResidual[] ScarlettProfessionalMicProbeResiduals() => +[ + new MimirAudioCalibrationBandResidual("asio-ch0-shotgun", 240.0, 0.91, 0.4, ResponseEnergy: 0.62), + new MimirAudioCalibrationBandResidual("asio-ch1-cardioid", 240.0, 0.87, 0.6, ResponseEnergy: 0.58), + new MimirAudioCalibrationBandResidual("asio-ch0-shotgun", 890.0, 0.52, 4.8, DelayResidualMicroseconds: 11.0, ResponseEnergy: 0.30), + new MimirAudioCalibrationBandResidual("asio-ch1-cardioid", 910.0, 0.47, 5.2, DelayResidualMicroseconds: 14.0, ResponseEnergy: 0.27), + new MimirAudioCalibrationBandResidual("asio-ch0-shotgun", 3_600.0, 0.44, -6.4, PhaseResidualRadians: 1.4, ResponseEnergy: 0.11), + new MimirAudioCalibrationBandResidual("asio-ch1-cardioid", 3_690.0, 0.41, -5.8, PhaseResidualRadians: 1.2, ResponseEnergy: 0.09), + new MimirAudioCalibrationBandResidual("asio-ch0-shotgun", 9_800.0, 0.28, -9.5, PhaseResidualRadians: 2.0, ResponseEnergy: 0.035), + new MimirAudioCalibrationBandResidual("asio-ch1-cardioid", 9_950.0, 0.22, -10.2, PhaseResidualRadians: 1.8, ResponseEnergy: 0.030), + new MimirAudioCalibrationBandResidual("asio-ch0-shotgun", 18_500.0, 0.03, -18.0, DelayResidualMicroseconds: 34.0, PhaseResidualRadians: 2.7, ResponseEnergy: 0.0), + new MimirAudioCalibrationBandResidual("asio-ch1-cardioid", 18_700.0, 0.02, -16.0, DelayResidualMicroseconds: 28.0, PhaseResidualRadians: 2.4, ResponseEnergy: 0.0), +]; + +static MimirAudioCalibrationSourcePathology[] ScarlettProfessionalMicPathologies() => +[ + new MimirAudioCalibrationSourcePathology( + "asio-ch0-shotgun", + NoiseFloorRms: 0.055, + LowHighTiltDb: 17.0, + HighBandConfidenceBias: 0.35), + new MimirAudioCalibrationSourcePathology( + "asio-ch1-cardioid", + NoiseFloorRms: 0.018, + LowHighTiltDb: 4.0), +]; + +static float[] RenderTargetedProbePlan(MimirTargetedBioacousticProbePlan plan) +{ + const double preRollSeconds = 0.08; + const double chirpSeconds = 0.090; + const double gapSeconds = 0.035; + var totalSeconds = preRollSeconds + plan.Bands.Count * (chirpSeconds + gapSeconds) + 0.12; + var samples = new float[Math.Max(1, (int)Math.Round(totalSeconds * plan.SampleRate))]; + var cursorSeconds = preRollSeconds; + foreach (var band in plan.Bands) + { + AddTargetedProbeChirp(samples, plan.SampleRate, cursorSeconds, chirpSeconds, band.StartHz, band.EndHz, band.Gain); + cursorSeconds += chirpSeconds + gapSeconds; + } + + return samples; +} + +static void AddTargetedProbeChirp( + float[] samples, + int sampleRate, + double startSeconds, + double durationSeconds, + double startHz, + double endHz, + double gain) +{ + var start = Math.Max(0, (int)Math.Round(startSeconds * sampleRate)); + var count = Math.Max(1, (int)Math.Round(durationSeconds * sampleRate)); + var end = Math.Min(samples.Length, start + count); + var phase = 0.0; + var previousHz = startHz; + for (var index = start; index < end; index++) + { + var t = (index - start) / (double)Math.Max(1, count - 1); + var curve = t * t * (3.0 - 2.0 * t); + var hz = startHz + (endHz - startHz) * curve; + phase += Math.Tau * (previousHz + hz) * 0.5 / sampleRate; + previousHz = hz; + var envelope = Math.Sin(Math.PI * t); + var shaped = Math.Sin(phase) + 0.22 * Math.Sin(phase * 2.0 + 0.31) + 0.08 * Math.Sin(phase * 3.0 + 0.77); + samples[index] += (float)(gain * envelope * shaped); + } +} + +static void WriteFloat32(string outputPath, float[] samples) +{ + var directory = Path.GetDirectoryName(Path.GetFullPath(outputPath)); + if (!string.IsNullOrWhiteSpace(directory)) + { + Directory.CreateDirectory(directory); + } + + var bytes = new byte[samples.Length * sizeof(float)]; + Buffer.BlockCopy(samples, 0, bytes, 0, bytes.Length); + File.WriteAllBytes(outputPath, bytes); +} + +static double ToneEnergy(ReadOnlySpan samples, int sampleRate, double centerHz) +{ + if (samples.Length == 0) + { + return 0.0; + } + + var omega = Math.Tau * centerHz / sampleRate; + var sine = 0.0; + var cosine = 0.0; + var step = Math.Max(1, samples.Length / 262_144); + var count = 0; + for (var index = 0; index < samples.Length; index += step) + { + var phase = omega * index; + sine += samples[index] * Math.Sin(phase); + cosine += samples[index] * Math.Cos(phase); + count++; + } + + return Math.Sqrt(sine * sine + cosine * cosine) * 2.0 / Math.Max(1, count); +} + static float[] RenderCalibrationToneStack( int frameCount, int sampleRate, diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 935d2b0..188ccf8 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -309,3 +309,5 @@ {"ts": "2026-06-01T02:45:51+01:00", "type": "verification", "status": "ok", "note": "Direct LAN SRT Raven proof is healthy after removing the SSH tunnel. Starfire listened on srt://0.0.0.0:5204 while Raven called 192.168.1.66:5204 with ddagrab + h264_nvenc + Mimir.WasapiLoopback AAC; artifact artifacts/runtime/stream-proof/raven-nvenc-ddagrab-lan-srt-20260601-024525.mp4 contains 564 video frames over 10.005 s (~56.5 fps) plus 48 kHz stereo AAC. The earlier sparse-frame recordings were the TCP/SSH proof path, not Raven GPU/capture/encode or LAN SRT."} {"ts": "2026-06-01T02:54:52+01:00", "type": "verification", "status": "ok", "note": "Calibrated audio composite contract now exists as MimirCalibratedAudioCompositeBuilder. The smoke consumes synthetic delayed/noisy/colored mic windows plus sync states and band responses, applies fractional alignment plus sparse measured-band equalization and confidence/noise weighting, and improves SNR from -3.171 dB uncalibrated to 15.135 dB calibrated while response flatness rises from 0.548 to 1.000. This is an offline/diagnostic contract for the future Faust/native hot lane, not a claim that live room nulls are perfectly flattened."} {"ts": "2026-06-01T03:04:44+01:00", "type": "decision", "status": "ok", "note": "Targeted bioacoustic probing is now residual-driven instead of generic sweep-driven. MimirTargetedBioacousticProbePlanner consumes per-source spectral residuals and optional mic pathology notes such as shotgun noise floor and low-heavy tilt, then emits gain-bounded probe bands. The first smoke scopes authority to the 192 kHz Scarlett shotgun/cardioid pair and selects about 18.6 kHz unmeasured high-band evidence first, then about 9.9 kHz weak response, 3.6 kHz phase instability, and 910 Hz magnitude residual. Wider room-field use of every connected mic remains later evidence, not the initial calibration owner."} +{"ts": "2026-06-01T03:09:15+01:00", "type": "verification", "status": "ok", "note": "Live targeted bioacoustic probe ran through Focusrite ASIO at 192 kHz with the shotgun/cardioid pair. Gain 1.0 artifact artifacts/asio/targeted-bioacoustic-live/20260601-030836 selected 18.6 kHz, 9.9 kHz, 3.6 kHz, and 910 Hz; shotgun measured low/high tilt 20.199 dB and cardioid 15.082 dB. Gain 2.0 artifact artifacts/asio/targeted-bioacoustic-live/20260601-030857 doubled loopback energy but physical 18.6 kHz remained nearly absent: shotgun -51.475 dB vs loopback, cardioid -56.585 dB. 910 Hz was the strongest physical band, especially shotgun at -21.994 dB. Treat current high-band path as weak/unusable until a better speaker/mic placement or probe shape proves otherwise."} +{"ts": "2026-06-01T03:11:14+01:00", "type": "verification", "status": "ok", "note": "Louder targeted bioacoustic probes ran at playback gains 4.0 and 8.0. Gain 4 artifact artifacts/asio/targeted-bioacoustic-live/20260601-031030 had shotgun peak 0.020941 and cardioid peak 0.016305; gain 8 artifact artifacts/asio/targeted-bioacoustic-live/20260601-031051 had shotgun peak 0.140715 and cardioid peak 0.027774, so the pass was audible but not clipped. Even at gain 8, 18.6 kHz stayed unusable: shotgun -54.910 dB and cardioid -63.258 dB vs loopback. Shotgun 910 Hz reached -26.549 dB with 0.237 confidence and 3.6 kHz reached -32.637 dB with 0.082 confidence. Current probe loop should bias usable low/mid anchors while treating ultrasonic/high band as failed path evidence."} diff --git a/state/map.yaml b/state/map.yaml index bd6a6a2..3bf9aca 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -656,6 +656,23 @@ accepted_design: residual. Use the two good mics first; every connected mic can become room field evidence later, but it should not dilute the initial direct-path calibration loop. + The first live targeted probe ran through Focusrite ASIO at 192 kHz. Gain + 1.0 artifact `artifacts/asio/targeted-bioacoustic-live/20260601-030836` + measured shotgun low/high tilt 20.199 dB and cardioid 15.082 dB. Gain 2.0 + artifact `artifacts/asio/targeted-bioacoustic-live/20260601-030857` + doubled loopback energy but did not make 18.6 kHz usable in the physical + mics: shotgun stayed -51.475 dB vs loopback and cardioid -56.585 dB. 910 Hz + was the strongest physical probe band, with shotgun at -21.994 dB. Current + high-band acoustic path is therefore weak or absent until speaker/mic + placement, output device, or probe shape changes. + Louder follow-ups kept the signal honest: gain 4 artifact + `artifacts/asio/targeted-bioacoustic-live/20260601-031030` still did not + clip, and gain 8 artifact + `artifacts/asio/targeted-bioacoustic-live/20260601-031051` reached only + shotgun peak 0.140715 and cardioid peak 0.027774. Even there, 18.6 kHz + stayed unusable at shotgun -54.910 dB and cardioid -63.258 dB relative to + loopback. The current physical path should bias usable low/mid anchors + while treating ultrasonic/high-band probes as failed-path evidence. A fresh live Scarlett proof is preserved at `calibration/bioacoustic/complex-contour-live-20260525-063229.md`: Focusrite ASIO playback/capture measured Loopback 1 -> Loopback 2 at