From 8667f6450d23a6e45cc76b67949658b5f83f6991 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 23 May 2026 19:04:16 +0100 Subject: [PATCH] Measure Scarlett chirp-only sync --- .gitignore | 1 + docs/implementation-plan.md | 26 +++- .../asio_audio_cadence/asio_audio_cadence.cpp | 132 +++++++++++++++--- notes/current-system-map.md | 12 ++ notes/fresh-workspace-handoff.md | 18 ++- src/Mimir.App/Mimir.App.csproj | 2 +- src/Mimir.BufferSmoke/Program.cs | 127 +++++++++++++++++ src/Mimir.Runtime/Mimir.Runtime.csproj | 4 +- .../Synchronization/MimirChirpletTimeline.cs | 9 +- state/evidence.jsonl | 1 + state/map.yaml | 15 +- 11 files changed, 306 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index ff8a03b..0dcce20 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ logs/ *.tmp calibration/runs/ artifacts/drivers/ +artifacts/asio/ tools/drivers/ tools/obs-spout2-plugin/ tools/src/ diff --git a/docs/implementation-plan.md b/docs/implementation-plan.md index 07c282d..a3e6041 100644 --- a/docs/implementation-plan.md +++ b/docs/implementation-plan.md @@ -52,7 +52,9 @@ a named invariant that the native runtime cannot protect yet. `Loopback 1/2`, 192-frame preferred buffers, 44.1-192 kHz support, and nonzero 4-channel `Int32LSB` input callbacks at 192 kHz. `--monitor-sweep` emits low-gain ASIO output bursts and synchronously measures loopback/mic - response per frequency so ultrasonic acoustic claims stay measured. + response per frequency so ultrasonic acoustic claims stay measured. The probe + can also play raw mono Float32 timeline audio with `--play-f32-mono` and + capture raw interleaved Float32 ASIO input with `--record-f32-interleaved`. - `MimirChirpletTimeline` owns the structured birdsong-like calibration stream, PCM segment rendering, matched timing trace, and per-band response kernels. The default timeline is an order-3 de Bruijn symbol sequence over 32 @@ -102,6 +104,14 @@ a named invariant that the native runtime cannot protect yet. `--hybrid-sync-self-test` to prove that the analyzer can recover a fractional delay from a one-second rolling-buffer chirp-bin window. The current synthetic microsecond proof recovers a 317.375-sample delay with 0.369 us error. +- `Mimir.BufferSmoke --render-chirplet-f32` and `--analyze-asio-f32` provide the + current chirp-only Scarlett artifact proof. A 192 kHz run decoded Focusrite + `Loopback 1 -> Loopback 2` at `0.000 us` with 7 matched anchors and 0.896 + confidence. Physical input 2 decoded at about 616.226 samples / 3209.508 us + with 3 matched anchors and 0.516 confidence; physical input 1 did not decode + in that capture. This proves the timing evidence can survive the real ASIO + path, but the matched-kernel chirplet decoder took roughly 100 seconds for one + 2-second 192 kHz comparison and is not the runtime hot path. - `MimirVideoFrameDescriptor` for dimensions, pixel format, stride, device timestamp, and native/GPU handle metadata. - `IMimirVideoCaptureDriver` and `MimirVideoCaptureDriverSource` as the live @@ -137,19 +147,21 @@ a named invariant that the native runtime cannot protect yet. workers for local mic, loopback, and network audio feeds. Use the verified Focusrite ASIO path for Scarlett capture; WASAPI remains a diagnostic witness, not the Scarlett hot path. -4. Add the synchronization actuator: drive a variable-rate resampler and +4. Replace the diagnostic chirp-only matched-kernel decoder with the efficient + streaming transform before using chirp-only at 192 kHz in the hot path. +5. Add the synchronization actuator: drive a variable-rate resampler and fractional delay line per non-reference stream from the smoothed `MimirAudioSynchronizationState`. First, prove the constrained chirplet decoder through real loopback and microphone paths so every correctly heard triplet becomes a deterministic timeline anchor before the actuator moves samples. -5. Prove the chirp-bin hybrid fallback through real loopback and microphones +6. Prove the chirp-bin hybrid fallback through real loopback and microphones with probe durations long enough to keep loopback and mic windows live. -6. Bind Fensalir UI to the synchronization hub so buffer depth, stream cadence, +7. Bind Fensalir UI to the synchronization hub so buffer depth, stream cadence, source timestamps, and output settings are visible and adjustable. -7. Move GPU feature extraction, fusion, material fitting, render budgeting, and +8. Move GPU feature extraction, fusion, material fitting, render budgeting, and Spout2 publication into Fensalir. -8. Move mic alignment, room suppression, voice separation, spatialization, and +9. Move mic alignment, room suppression, voice separation, spatialization, and stem generation into Faust/native DSP. -9. Keep the OBS bridge witness ledger as evidence before expanding receiver +10. Keep the OBS bridge witness ledger as evidence before expanding receiver machinery. diff --git a/native/probes/asio_audio_cadence/asio_audio_cadence.cpp b/native/probes/asio_audio_cadence/asio_audio_cadence.cpp index d1713bc..5dc8a91 100644 --- a/native/probes/asio_audio_cadence/asio_audio_cadence.cpp +++ b/native/probes/asio_audio_cadence/asio_audio_cadence.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -121,6 +122,10 @@ struct CaptureState std::vector sweepSin; std::vector sweepCos; std::vector sweepSamples; + std::vector* playbackSamples = nullptr; + double playbackGain = 1.0; + std::vector* recordedInput = nullptr; + unsigned long long recordFrames = 0; unsigned long long sweepFrame = 0; std::atomic callbacks{0}; std::atomic frames{0}; @@ -216,7 +221,9 @@ void writeSample(unsigned char* sample, ASIOSampleType type, double value) void processOutput(long doubleBufferIndex) { - if (!g_capture.outputBuffers || !g_capture.outputChannels || g_capture.sweepFrequencies.empty()) + const bool hasPlayback = g_capture.playbackSamples && !g_capture.playbackSamples->empty(); + const bool hasSweep = !g_capture.sweepFrequencies.empty(); + if (!g_capture.outputBuffers || !g_capture.outputChannels || (!hasPlayback && !hasSweep)) { return; } @@ -224,7 +231,7 @@ void processOutput(long doubleBufferIndex) const auto toneFrames = static_cast(g_capture.sweepToneSeconds * g_capture.sampleRate); const auto gapFrames = static_cast(g_capture.sweepGapSeconds * g_capture.sampleRate); const auto slotFrames = toneFrames + gapFrames; - if (slotFrames == 0) + if (hasSweep && slotFrames == 0) { return; } @@ -232,25 +239,35 @@ void processOutput(long doubleBufferIndex) for (long frame = 0; frame < g_capture.bufferSize; ++frame) { const auto absoluteFrame = g_capture.sweepFrame + static_cast(frame); - const auto slot = absoluteFrame / slotFrames; - const auto slotOffset = absoluteFrame % slotFrames; double sampleValue = 0.0; - if (slot < g_capture.sweepFrequencies.size() && slotOffset < toneFrames) + if (hasPlayback) { - const auto fadeFrames = static_cast(0.01 * g_capture.sampleRate); - auto envelope = 1.0; - if (fadeFrames > 0 && slotOffset < fadeFrames) + if (absoluteFrame < g_capture.playbackSamples->size()) { - envelope = static_cast(slotOffset) / static_cast(fadeFrames); + sampleValue = (*g_capture.playbackSamples)[static_cast(absoluteFrame)] * g_capture.playbackGain; } - else if (fadeFrames > 0 && toneFrames - slotOffset < fadeFrames) + } + else + { + const auto slot = absoluteFrame / slotFrames; + const auto slotOffset = absoluteFrame % slotFrames; + if (slot < g_capture.sweepFrequencies.size() && slotOffset < toneFrames) { - envelope = static_cast(toneFrames - slotOffset) / static_cast(fadeFrames); - } + const auto fadeFrames = static_cast(0.01 * g_capture.sampleRate); + auto envelope = 1.0; + if (fadeFrames > 0 && slotOffset < fadeFrames) + { + envelope = static_cast(slotOffset) / static_cast(fadeFrames); + } + else if (fadeFrames > 0 && toneFrames - slotOffset < fadeFrames) + { + envelope = static_cast(toneFrames - slotOffset) / static_cast(fadeFrames); + } - const auto phase = 2.0 * Pi * g_capture.sweepFrequencies[slot] * - (static_cast(slotOffset) / g_capture.sampleRate); - sampleValue = std::sin(phase) * envelope * g_capture.sweepGain; + const auto phase = 2.0 * Pi * g_capture.sweepFrequencies[slot] * + (static_cast(slotOffset) / g_capture.sampleRate); + sampleValue = std::sin(phase) * envelope * g_capture.sweepGain; + } } for (size_t channel = 0; channel < g_capture.outputBuffers->size(); ++channel) @@ -342,6 +359,13 @@ void bufferSwitch(long doubleBufferIndex, ASIOBool) for (long frame = 0; frame < g_capture.bufferSize; ++frame) { + const auto absoluteFrame = g_capture.sweepFrame + static_cast(frame); + if (g_capture.recordedInput && absoluteFrame < g_capture.recordFrames) + { + (*g_capture.recordedInput)[static_cast(absoluteFrame) * static_cast(g_capture.inputCount) + channel] = + static_cast(readSample(raw + frame * sampleBytes, info.type)); + } + if (sampleIsNonZero(raw + frame * sampleBytes, sampleBytes)) { ++nonZero; @@ -485,6 +509,9 @@ int main(int argc, char** argv) const auto captureSeconds = doubleOption(argc, argv, "--capture-seconds", 0.0); const auto setSampleRate = doubleOption(argc, argv, "--set-sample-rate", 0.0); const bool monitorSweep = hasArg(argc, argv, "--monitor-sweep"); + const char* playFloat32MonoPath = option(argc, argv, "--play-f32-mono", nullptr); + const char* recordFloat32InterleavedPath = option(argc, argv, "--record-f32-interleaved", nullptr); + const auto playGain = doubleOption(argc, argv, "--play-gain", 1.0); const auto sweepGain = doubleOption(argc, argv, "--sweep-gain", 0.03); const auto sweepToneSeconds = doubleOption(argc, argv, "--sweep-tone-seconds", 0.55); const auto sweepGapSeconds = doubleOption(argc, argv, "--sweep-gap-seconds", 0.20); @@ -622,7 +649,28 @@ int main(int argc, char** argv) info.name); } - if (captureSeconds > 0.0 || monitorSweep) + std::vector playbackSamples; + if (playFloat32MonoPath) + { + std::ifstream input(playFloat32MonoPath, std::ios::binary); + if (!input) + { + std::fprintf(stderr, "failed to open --play-f32-mono file: %s\n", playFloat32MonoPath); + return 9; + } + + input.seekg(0, std::ios::end); + const auto byteCount = input.tellg(); + input.seekg(0, std::ios::beg); + if (byteCount > 0) + { + playbackSamples.resize(static_cast(byteCount) / sizeof(float)); + input.read(reinterpret_cast(playbackSamples.data()), static_cast(playbackSamples.size() * sizeof(float))); + } + std::printf("asio playback-f32-mono: path=%s samples=%zu gain=%.5f\n", playFloat32MonoPath, playbackSamples.size(), playGain); + } + + if (captureSeconds > 0.0 || monitorSweep || !playbackSamples.empty()) { std::vector sweepFrequencies; if (monitorSweep) @@ -630,13 +678,18 @@ int main(int argc, char** argv) sweepFrequencies = {8000.0, 10000.0, 12000.0, 14000.0, 16000.0, 18000.0, 20000.0, 22000.0, 24000.0, 28000.0, 32000.0, 40000.0}; } - const auto runSeconds = monitorSweep + auto runSeconds = monitorSweep ? (sweepToneSeconds + sweepGapSeconds) * static_cast(sweepFrequencies.size()) + 0.25 : captureSeconds; + if (runSeconds <= 0.0 && !playbackSamples.empty() && currentRate > 0.0) + { + runSeconds = static_cast(playbackSamples.size()) / currentRate; + } - std::vector buffers(static_cast(inputs + (monitorSweep ? outputs : 0))); + const bool needsOutput = monitorSweep || !playbackSamples.empty(); + std::vector buffers(static_cast(inputs + (needsOutput ? outputs : 0))); std::vector channels(static_cast(inputs)); - std::vector outputChannels(static_cast(monitorSweep ? outputs : 0)); + std::vector outputChannels(static_cast(needsOutput ? outputs : 0)); for (long channel = 0; channel < inputs; ++channel) { buffers[static_cast(channel)].isInput = 1; @@ -645,7 +698,7 @@ int main(int argc, char** argv) channels[static_cast(channel)].isInput = 1; driver->getChannelInfo(&channels[static_cast(channel)]); } - if (monitorSweep) + if (needsOutput) { for (long channel = 0; channel < outputs; ++channel) { @@ -673,14 +726,22 @@ int main(int argc, char** argv) g_capture.buffers = &buffers; g_capture.channels = &channels; - g_capture.outputBuffers = monitorSweep ? reinterpret_cast*>(nullptr) : nullptr; + g_capture.outputBuffers = needsOutput ? reinterpret_cast*>(nullptr) : nullptr; std::vector outputBuffers; - if (monitorSweep) + if (needsOutput) { outputBuffers.assign(buffers.begin() + inputs, buffers.end()); g_capture.outputBuffers = &outputBuffers; g_capture.outputChannels = &outputChannels; } + std::vector recordedInput; + if (recordFloat32InterleavedPath) + { + const auto requestedFrames = static_cast(std::ceil(runSeconds * currentRate)) + static_cast(preferredSize); + recordedInput.assign(static_cast(requestedFrames) * static_cast(inputs), 0.0f); + g_capture.recordedInput = &recordedInput; + g_capture.recordFrames = requestedFrames; + } g_capture.bufferSize = preferredSize; g_capture.inputCount = inputs; g_capture.outputCount = outputs; @@ -689,6 +750,8 @@ int main(int argc, char** argv) g_capture.sweepToneSeconds = sweepToneSeconds; g_capture.sweepGapSeconds = sweepGapSeconds; g_capture.sweepGain = sweepGain; + g_capture.playbackSamples = playbackSamples.empty() ? nullptr : &playbackSamples; + g_capture.playbackGain = playGain; g_capture.sweepFrame = 0; g_capture.sweepEnergy.assign(sweepFrequencies.size() * static_cast(inputs), 0.0); g_capture.sweepPeak.assign(sweepFrequencies.size() * static_cast(inputs), 0.0); @@ -762,10 +825,35 @@ int main(int argc, char** argv) } } + if (recordFloat32InterleavedPath) + { + const auto capturedFrames = std::min( + g_capture.frames.load(std::memory_order_relaxed), + g_capture.recordFrames); + std::ofstream output(recordFloat32InterleavedPath, std::ios::binary); + if (!output) + { + std::fprintf(stderr, "failed to open --record-f32-interleaved file: %s\n", recordFloat32InterleavedPath); + driver->disposeBuffers(); + return 10; + } + + output.write( + reinterpret_cast(recordedInput.data()), + static_cast(capturedFrames * static_cast(inputs) * sizeof(float))); + std::printf("asio record-f32-interleaved: path=%s frames=%llu channels=%ld sampleRate=%.0f\n", + recordFloat32InterleavedPath, + capturedFrames, + inputs, + currentRate); + } + g_capture.buffers = nullptr; g_capture.channels = nullptr; g_capture.outputBuffers = nullptr; g_capture.outputChannels = nullptr; + g_capture.playbackSamples = nullptr; + g_capture.recordedInput = nullptr; driver->disposeBuffers(); } diff --git a/notes/current-system-map.md b/notes/current-system-map.md index d010116..de49db9 100644 --- a/notes/current-system-map.md +++ b/notes/current-system-map.md @@ -144,6 +144,18 @@ runtime analyzer accepts Float32, Int16, Int24, and Int32 PCM windows so ASIO/native capture can preserve the interface format. Raven also has a loopback-capable Scarlett ASIO path at 192 kHz for co-streamer/game timing evidence; Starfire still owns the heavy soundfield and sensor-fusion work. +The ASIO probe can now play a raw mono Float32 chirplet timeline through the +Focusrite outputs while capturing every ASIO input as raw interleaved Float32. +`Mimir.BufferSmoke --analyze-asio-f32` feeds those captured channels into the +same runtime chirp-only analyzer. A real 192 kHz Scarlett artifact decoded +`Loopback 1 -> Loopback 2` at exactly `0.000 us` with 7 matched anchors and +0.896 confidence. The physical input path decoded on channel 1 at about +616.226 samples / 3209.508 us with 3 matched anchors and 0.516 confidence; +channel 0 did not produce anchors in that window. The result proves chirp-only +hardware alignment can reach microsecond reporting on clean loopback, but the +current matched-kernel chirplet decoder took roughly 100 seconds for one +2-second 192 kHz comparison. That implementation is diagnostic, not the final +runtime hot path. ## Visual Fusion diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 5d0dab5..54bc4ff 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -101,16 +101,24 @@ Get-Content .\state\evidence.jsonl -Tail 8 (`USB\VID_1235&PID_8218`) is now local; `native/probes/asio_audio_cadence` opens `Focusrite USB ASIO`, sees 4 inputs / 2 outputs including `Loopback 1/2`, 192-frame preferred buffers, 44.1-192 kHz support, and - captures nonzero 4-channel `Int32LSB` input callbacks at 192 kHz. The next - audio cut is feeding ASIO buffers into `Mimir.Runtime`, not more WASAPI - probing or Raven loopback offload. + captures nonzero 4-channel `Int32LSB` input callbacks at 192 kHz. It can play + raw mono Float32 chirplet timelines through ASIO outputs and capture all ASIO + inputs as raw interleaved Float32 for runtime analysis. A real Scarlett + chirp-only artifact run at 192 kHz decoded `Loopback 1 -> Loopback 2` at + `0.000 us` delay with 7 matched anchors and 0.896 confidence. Physical input + 2 decoded against loopback at about 616.226 samples / 3209.508 us with 3 + matched anchors and 0.516 confidence; physical input 1 did not decode in that + window. One 2-second 192 kHz chirp-only matched-kernel decode took roughly + 100 seconds. Accuracy is present; the current chirplet transform is not a hot + path. - Raven also has a 192 kHz loopback-capable Scarlett for co-streamer/game timing evidence. Do not move the heavy soundfield or sensor-fusion workload there. ## Immediate Re-entry Instruction -Feed Scarlett ASIO callbacks into `Mimir.Runtime`, then prove the constrained -chirplet-transform decoder through real loopback and mic paths and turn decoded +Replace the diagnostic chirp-only matched-kernel decoder with the planned +efficient streaming transform before calling chirp-only runtime-ready at +192 kHz, then feed Scarlett ASIO callbacks into `Mimir.Runtime` and turn decoded clock fits into the SRO/fractional-delay actuator. Keep loopback as timing authority. Do not call synchronization analysis from UI/telemetry readouts. Do not restore deleted script infrastructure because a stale doc once missed it. diff --git a/src/Mimir.App/Mimir.App.csproj b/src/Mimir.App/Mimir.App.csproj index c62c758..a27b9b3 100644 --- a/src/Mimir.App/Mimir.App.csproj +++ b/src/Mimir.App/Mimir.App.csproj @@ -11,7 +11,7 @@ - + diff --git a/src/Mimir.BufferSmoke/Program.cs b/src/Mimir.BufferSmoke/Program.cs index 584e49e..3ea816a 100644 --- a/src/Mimir.BufferSmoke/Program.cs +++ b/src/Mimir.BufferSmoke/Program.cs @@ -20,6 +20,24 @@ if (args.Any(arg => string.Equals(arg, "--hybrid-sync-self-test", StringComparis return RunHybridSyncSelfTest(ParseIntOption(args, "--sample-rate", MimirChirpBinTimeline.SampleRate)); } +if (args.Any(arg => string.Equals(arg, "--render-chirplet-f32", StringComparison.OrdinalIgnoreCase))) +{ + return RenderChirpletFloat32( + ParseStringOption(args, "--output", "artifacts/asio/chirplet-f32.raw"), + ParseIntOption(args, "--sample-rate", MimirChirpletTimeline.SampleRate), + ParseDoubleOption(args, "--seconds", 3.0)); +} + +if (args.Any(arg => string.Equals(arg, "--analyze-asio-f32", StringComparison.OrdinalIgnoreCase))) +{ + return AnalyzeAsioFloat32( + ParseStringOption(args, "--input", "artifacts/asio/scarlett-chirplet-f32.raw"), + ParseIntOption(args, "--sample-rate", MimirChirpletTimeline.SampleRate), + ParseIntOption(args, "--channels", 4), + ParseIntOption(args, "--reference-channel", 2), + ParseIntOption(args, "--candidate-channel", -1)); +} + var duration = TimeSpan.FromSeconds(ParseDoubleOption(args, "--seconds", 10.0)); var pollDelay = TimeSpan.FromMilliseconds(ParseDoubleOption(args, "--poll-ms", 10.0)); var requireSamples = args.Any(arg => string.Equals(arg, "--require-samples", StringComparison.OrdinalIgnoreCase)); @@ -305,6 +323,115 @@ static int RunHybridSyncSelfTest(int sampleRate) : 1; } +static int RenderChirpletFloat32(string outputPath, int sampleRate, double seconds) +{ + var segmentCount = Math.Max(1, (int)Math.Ceiling(seconds / MimirChirpletTimeline.SegmentSeconds)); + var samples = new List(Math.Max(1, (int)Math.Ceiling(seconds * sampleRate))); + for (var segment = 0; segment < segmentCount; segment++) + { + samples.AddRange(MimirChirpletTimeline.Default.RenderSegmentMonoFloat((ulong)segment, sampleRate)); + } + + var requestedSamples = Math.Max(1, (int)Math.Round(seconds * sampleRate)); + if (samples.Count > requestedSamples) + { + samples.RemoveRange(requestedSamples, samples.Count - requestedSamples); + } + + var directory = Path.GetDirectoryName(Path.GetFullPath(outputPath)); + if (!string.IsNullOrEmpty(directory)) + { + Directory.CreateDirectory(directory); + } + + var bytes = new byte[samples.Count * sizeof(float)]; + for (var index = 0; index < samples.Count; index++) + { + BitConverter.TryWriteBytes(bytes.AsSpan(index * sizeof(float), sizeof(float)), samples[index]); + } + + File.WriteAllBytes(outputPath, bytes); + Console.WriteLine($"chirplet-render-f32 path={outputPath} sampleRate={sampleRate} seconds={seconds:0.000} samples={samples.Count}"); + return 0; +} + +static int AnalyzeAsioFloat32(string inputPath, int sampleRate, int channels, int referenceChannel, int candidateChannel) +{ + if (channels <= 0) + { + Console.Error.WriteLine("asio-f32 analysis failed: channel count must be positive"); + return 1; + } + + if (referenceChannel < 0 || referenceChannel >= channels) + { + Console.Error.WriteLine("asio-f32 analysis failed: reference channel is outside the capture channel count"); + return 1; + } + + if (candidateChannel >= channels) + { + Console.Error.WriteLine("asio-f32 analysis failed: candidate channel is outside the capture channel count"); + return 1; + } + + var bytes = File.ReadAllBytes(inputPath); + var frameCount = bytes.Length / (sizeof(float) * channels); + if (frameCount == 0) + { + Console.Error.WriteLine("asio-f32 analysis failed: capture file contains no complete frames"); + return 1; + } + + var channelSamples = new float[channels][]; + for (var channel = 0; channel < channels; channel++) + { + channelSamples[channel] = new float[frameCount]; + } + + var span = bytes.AsSpan(0, frameCount * channels * sizeof(float)); + for (var frame = 0; frame < frameCount; frame++) + { + for (var channel = 0; channel < channels; channel++) + { + channelSamples[channel][frame] = BitConverter.ToSingle(span.Slice((frame * channels + channel) * sizeof(float), sizeof(float))); + } + } + + var buffers = new List(channels); + for (var channel = 0; channel < channels; channel++) + { + var sourceId = $"asio-ch{channel}"; + var buffer = new MimirRollingStreamBuffer( + new MimirStreamDescriptor(sourceId, MimirStreamKind.Audio, MimirStreamOrigin.LocalDevice), + TimeSpan.FromSeconds(10)); + AppendFloatBlock(buffer, sourceId, channelSamples[channel], sampleRate); + buffers.Add(buffer); + } + + var referenceSourceId = $"asio-ch{referenceChannel}"; + var candidates = candidateChannel >= 0 + ? new HashSet(StringComparer.Ordinal) { $"asio-ch{candidateChannel}" } + : null; + var analyzer = new MimirAudioSynchronizationAnalyzer(); + var reports = analyzer.Analyze(buffers, referenceSourceId, MimirAudioSyncMode.ChirpOnly, candidates); + + Console.WriteLine($"asio-f32-analysis input={inputPath} sampleRate={sampleRate} channels={channels} frames={frameCount} reference={referenceSourceId} candidate={(candidateChannel >= 0 ? $"asio-ch{candidateChannel}" : "all")}"); + foreach (var trace in analyzer.LastDecodeTraces.OrderBy(trace => trace.SourceId, StringComparer.Ordinal)) + { + Console.WriteLine( + $"asio-f32-trace {trace.ReferenceSourceId}->{trace.SourceId}: status={trace.Status} compared={trace.ComparedSamples} refFrames={trace.ReferenceFrames} refAnchors={trace.ReferenceAnchors} refClock={trace.ReferenceClockConfidence:0.000} candFrames={trace.CandidateFrames} candAnchors={trace.CandidateAnchors} candClock={trace.CandidateClockConfidence:0.000} matched={trace.MatchedEvents} confidence={trace.Confidence:0.000}"); + } + + foreach (var report in reports.OrderBy(report => report.SourceId, StringComparer.Ordinal)) + { + Console.WriteLine( + $"asio-f32-sync {report.ReferenceSourceId}->{report.SourceId}: evidence={report.EvidenceKind} delaySamples={report.FractionalDelaySamples:0.000000} delayUs={report.DelayMicroseconds:0.000} confidence={report.Confidence:0.000} events={report.TimelineMatchedEvents} compared={report.ComparedSamples}"); + } + + return reports.Count > 0 ? 0 : 1; +} + static int ParseIntOption(string[] args, string name, int fallback) { for (var index = 0; index < args.Length - 1; index++) diff --git a/src/Mimir.Runtime/Mimir.Runtime.csproj b/src/Mimir.Runtime/Mimir.Runtime.csproj index 4836b09..ad50eeb 100644 --- a/src/Mimir.Runtime/Mimir.Runtime.csproj +++ b/src/Mimir.Runtime/Mimir.Runtime.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/src/Mimir.Runtime/Synchronization/MimirChirpletTimeline.cs b/src/Mimir.Runtime/Synchronization/MimirChirpletTimeline.cs index 31d9bd8..e478675 100644 --- a/src/Mimir.Runtime/Synchronization/MimirChirpletTimeline.cs +++ b/src/Mimir.Runtime/Synchronization/MimirChirpletTimeline.cs @@ -56,12 +56,17 @@ public sealed class MimirChirpletTimeline public static MimirChirpletTimeline Default { get; } = new(); public float[] RenderSegmentMonoFloat(ulong segmentIndex) + { + return RenderSegmentMonoFloat(segmentIndex, SampleRate); + } + + public float[] RenderSegmentMonoFloat(ulong segmentIndex, int sampleRate) { var segmentStartSeconds = segmentIndex * SegmentSeconds; - var samples = new float[(int)Math.Round(SegmentSeconds * SampleRate)]; + var samples = new float[(int)Math.Round(SegmentSeconds * sampleRate)]; foreach (var timelineEvent in EventsOverlapping(segmentStartSeconds, SegmentSeconds)) { - AddTone(samples, SampleRate, timelineEvent.Tone, segmentStartSeconds); + AddTone(samples, sampleRate, timelineEvent.Tone, segmentStartSeconds); } for (var index = 0; index < samples.Length; index++) diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 3779a89..e6f4a18 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -66,3 +66,4 @@ {"ts": "2026-05-23T17:06:31+01:00", "type": "verification", "status": "ok", "note": "Starfire now has the Scarlett Solo 4th Gen attached locally: USB VID_1235 PID_8218 serial S1DE2FP360D5F6. Focusrite USB ASIO exposes 4 inputs / 2 outputs locally: Input 1, Input 2, Loopback 1, Loopback 2, all Int32LSB. The ASIO probe set 192000 Hz and captured nonzero 4-channel callbacks for 5 seconds with 192-frame preferred buffers. This restores local ASIO loopback ownership to the Mimir host; Raven no longer needs to carry game-audio loopback for the soundfield timing path."} {"ts": "2026-05-23T17:56:26+01:00", "type": "verification", "status": "partial", "note": "Added monitor-sweep mode to the ASIO cadence probe and ran Starfire Scarlett Solo 4th Gen at 192 kHz with 0.02 full-scale output bursts from 8-40 kHz. ASIO loopback channels detected the emitted tone at about 0.01949 amplitude for every tested frequency through 40 kHz. Acoustic input channel 1 detected weak tone energy around 8 kHz and 12 kHz (~0.00041, about -33.5 dB relative to loopback), dropped by 14-16 kHz, and was extremely weak above 20 kHz (roughly -58 dB at 20 kHz, -62 dB at 24 kHz, -80 dB at 32 kHz). Current studio-monitor/acoustic path is not a strong ultrasonic sync carrier; ASIO loopback is excellent for local reference and acoustic calibration should stay near the highest measured robust audible band unless stronger transducers/mics prove otherwise."} {"ts": "2026-05-23T18:46:59+01:00", "type": "verification", "status": "ok", "note": "Added sample-rate selection to the hybrid chirp-bin self-test and removed the high-rate timing plateau bias from MimirChirpBinTimeline while preserving the 48 kHz compatibility behavior. Synthetic active chirp-bin timing now scales with sample rate: 48 kHz recovered 317.392716 vs 317.375 samples (0.369 us error), 96 kHz recovered 634.766098 vs 634.75 samples (0.168 us error), and 192 kHz recovered 1269.499997 vs 1269.5 samples (about 0.000003 samples, below printed microsecond precision). This proves the timing kernel benefits from 192 kHz in memory; live hardware proof still requires feeding ASIO callbacks into Mimir.Runtime instead of the diagnostic WASAPI/process path."} +{"ts": "2026-05-23T19:03:44+01:00", "type": "measurement", "status": "ok", "note": "Scarlett ASIO chirp-only artifact at 192 kHz: Loopback 1 -> Loopback 2 decoded at 0.000 us with 7 anchors and 0.896 confidence; physical input 2 decoded at 616.226 samples / 3209.508 us with 3 anchors and 0.516 confidence; physical input 1 had no anchors. One 2-second matched-kernel chirplet comparison took roughly 100 seconds, so the current chirp-only decoder is diagnostic, not the runtime hot path."} diff --git a/state/map.yaml b/state/map.yaml index c6d23df..f85d760 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -116,6 +116,15 @@ accepted_design: 317.375-sample fractional delay from code-valid anchors with 0.369 us error. The synthetic codebook proof remains `dotnet run --project .\src\Mimir.BufferSmoke\Mimir.BufferSmoke.csproj -- --chirp-bin-self-test`. + `Mimir.BufferSmoke --render-chirplet-f32` plus + `native/probes/asio_audio_cadence --play-f32-mono --record-f32-interleaved` + now provides a real Scarlett ASIO artifact proof for chirp-only mode. + At 192 kHz, Loopback 1 -> Loopback 2 decoded at 0.000 us with 7 anchors and + 0.896 confidence. Physical input 2 decoded at about 616.226 samples / + 3209.508 us with 3 anchors and 0.516 confidence; physical input 1 did not + decode in that capture. The proof cost roughly 100 seconds for one 2-second + 192 kHz matched-kernel comparison, so the current chirplet decoder is a + diagnostic witness, not the runtime hot path. - `IMimirVideoCaptureDriver` and `MimirVideoCaptureDriverSource` are the live seam for Leap, Media Foundation, DirectShow, libusb, LeapC, or shared texture capture. @@ -214,8 +223,10 @@ current_status: Kiyo 30.18 fps, PS3 Eye 0 59.66 fps, and PS3 Eye 1 59.95 fps. A mouse in the Leap USB neighborhood does not reproduce the Focusrite-induced collapse. next_action: > - Prove the constrained chirplet-transform decoder through real loopback and - microphone paths before adding the synchronization actuator. + Replace the diagnostic chirp-only matched-kernel decoder with the efficient + streaming transform before calling chirp-only runtime-ready at 192 kHz, then + feed Scarlett ASIO callbacks directly into Mimir.Runtime and add the + synchronization actuator. Current app testing proves Fensalir WASAPI output wakes Scarlett speaker loopback, live mic buffers stay populated, runtime sync analysis now runs as a bounded rotating service without UI/telemetry re-entry, and the continuous