From 8122a8d00cf2970435ff60fbebf49126c54e0224 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 1 Jun 2026 05:16:09 +0100 Subject: [PATCH] Record Kiyo with Faust cleaner chain --- docs/audio-field.md | 20 ++- docs/implementation-plan.md | 20 ++- notes/current-system-map.md | 25 +-- notes/fresh-workspace-handoff.md | 9 + scripts/record-kiyo-dual-mic-composite.ps1 | 2 +- .../Mimir.BufferSmoke.csproj | 1 + src/Mimir.BufferSmoke/Program.cs | 166 ++++++++++++++++++ state/evidence.jsonl | 1 + state/map.yaml | 25 +-- 9 files changed, 231 insertions(+), 38 deletions(-) diff --git a/docs/audio-field.md b/docs/audio-field.md index 6eb2711..6634a6b 100644 --- a/docs/audio-field.md +++ b/docs/audio-field.md @@ -150,15 +150,19 @@ to `16.304 dB`. This is still the C# diagnostic/offline contract; Faust/native DSP owns the production hot lane. The first listenable bridge receipt is `scripts/record-kiyo-dual-mic-composite.ps1`. It records Kiyo video and -Scarlett ASIO raw channels together, converts Scarlett channels 0/1 into a -computed dual-mic composite WAV with `--asio-dual-mic-composite-wav`, then muxes -that WAV with the Kiyo video. The 2026-06-01 receipt at +Scarlett ASIO raw channels together, converts Scarlett channels 0/1 through +the offline Faust chain with `--asio-dual-mic-faust-cleaner-wav`, then muxes +the dialogue WAV with the Kiyo video. That command compiles and runs +`faust/mimir_alignment_actuator.dsp` first, then feeds the aligned +shotgun/cardioid stems into `faust/mimir_dual_mic_dialogue_cleaner.dsp`; it is a +listening receipt for the real DSP chain, not the older C# composite audition. +The fresh 2026-06-01 receipt at `artifacts/runtime/kiyo-dual-mic-composite/kiyo-dual-mic-composite-latest.mp4` -contains 10.000 s of 640x480 30 fps Kiyo video and 9.994 s of mono AAC from the -computed composite. After listening feedback, the bridge tightened its audition -defaults: measured-band gain is capped at `1.18x`, incoherent calibrated bands -are suppressed more aggressively, and the choppy post-sum residual expander is -not enabled by default. The next hot owner is +contains 10.000 s of 640x480 30 fps Kiyo video and 10.000 s of mono AAC from the +Faust dialogue stem. Run `20260601-051044` estimated the cardioid 359.398 +samples late at 48 kHz (7487.452 us), applied holdback 359.398/0.000 samples to +shotgun/cardioid before cleanup, wrote a residual WAV, and reported dialogue +RMS `0.002678`. The hot owner is `faust/mimir_dual_mic_dialogue_cleaner.dsp`: a two-input/two-output Faust graph for aligned shotgun/cardioid witnesses that emits a dialogue composite stem and a rejected residual witness using smooth multiband voice shaping, witness diff --git a/docs/implementation-plan.md b/docs/implementation-plan.md index 1fca34b..72e58b9 100644 --- a/docs/implementation-plan.md +++ b/docs/implementation-plan.md @@ -814,13 +814,19 @@ a named invariant that the native runtime cannot protect yet. calibrated-band coherence and suppresses incoherent measured-band components before summing; `--dual-mic-coherence-cancellation-smoke` proves the two-mic case by cutting a mic-local 3.52 kHz interferer while preserving coherent - shared tones. `scripts/record-kiyo-dual-mic-composite.ps1` is the first - listenable bridge: it records Kiyo video plus Scarlett ASIO raw channels, - renders the channels 0/1 composite WAV with `--asio-dual-mic-composite-wav`, - and muxes the computed mono composite into the Kiyo MP4. The bridge defaults - now cap measured-band boost at 1.18x, apply stronger incoherent-band - suppression, and do not enable the choppy C# residual expander by default. - The Faust hot-lane target now exists as + shared tones. `scripts/record-kiyo-dual-mic-composite.ps1` is now the first + listenable Faust-chain bridge: it records Kiyo video plus Scarlett ASIO raw + channels, renders channels 0/1 through + `--asio-dual-mic-faust-cleaner-wav`, and muxes the Faust dialogue stem into + the Kiyo MP4. That offline command compiles and runs + `faust/mimir_alignment_actuator.dsp` before + `faust/mimir_dual_mic_dialogue_cleaner.dsp`, so the receipt exercises the + actual alignment-then-cleaner chain. The fresh 2026-06-01 run + `artifacts/runtime/kiyo-dual-mic-composite/20260601-051044` estimated a + 359.398-sample cardioid delay at 48 kHz, applied holdback 359.398/0.000 to + shotgun/cardioid, wrote dialogue and residual WAVs, and muxed a 10.000 s + 640x480@30 Kiyo MP4 with 10.000 s 48 kHz mono AAC. The Faust hot-lane target + exists as `faust/mimir_dual_mic_dialogue_cleaner.dsp`; Mimir queues it as `dual-mic-dialogue-cleaner`, consuming the alignment actuator's published `aligned_source_*` stem frame rather than raw mic buffers, and emitting diff --git a/notes/current-system-map.md b/notes/current-system-map.md index abb8d25..2cce94e 100644 --- a/notes/current-system-map.md +++ b/notes/current-system-map.md @@ -317,18 +317,21 @@ two-witness cancellation cut: shared tones keep about 0.999 coherence, a mic-local 3.52 kHz interferer scores about 0.001 coherence and 0.948 suppression, its measured energy falls from 0.039195 to 0.001306, and SNR rises from 1.366 dB to 16.304 dB. -`scripts/record-kiyo-dual-mic-composite.ps1` is the first listenable bridge -receipt for that path. It starts Kiyo FFmpeg capture and Scarlett ASIO raw -capture together, converts ASIO channels 0/1 to a computed composite WAV through -`--asio-dual-mic-composite-wav`, then muxes the composite WAV with Kiyo video. -The 2026-06-01 receipt +`scripts/record-kiyo-dual-mic-composite.ps1` is the first listenable Faust-chain +bridge receipt for that path. It starts Kiyo FFmpeg capture and Scarlett ASIO +raw capture together, converts ASIO channels 0/1 through +`--asio-dual-mic-faust-cleaner-wav`, and muxes the Faust dialogue WAV with Kiyo +video. The offline command compiles/runs +`faust/mimir_alignment_actuator.dsp` first, then feeds the aligned +shotgun/cardioid stems into `faust/mimir_dual_mic_dialogue_cleaner.dsp`; the +older C# composite stays a scoring/audition contract, not the current listening +receipt. The fresh 2026-06-01 receipt at +`artifacts/runtime/kiyo-dual-mic-composite/20260601-051044` and `artifacts/runtime/kiyo-dual-mic-composite/kiyo-dual-mic-composite-latest.mp4` -has 10.000 s of 640x480 30 fps Kiyo video and 9.994 s of mono AAC composite -audio; the composite report estimated channel-1 delay at about -141.019 samples -(-2937.889 us). After user listening feedback, the bridge tightened audition -defaults: measured-band boost is capped at 1.18x, incoherent calibrated bands -are suppressed harder, and the choppy residual expander is not enabled by -default. The actual denoise authority is moving to Faust: +has 10.000 s of 640x480 30 fps Kiyo video and 10.000 s of 48 kHz mono AAC from +the Faust dialogue stem. It estimated the cardioid 359.398 samples late +(7487.452 us), applied holdback 359.398/0.000 samples to shotgun/cardioid, and +wrote both dialogue and residual WAVs. The actual denoise authority is Faust: `faust/mimir_dual_mic_dialogue_cleaner.dsp` compiles as a two-input/two-output aligned shotgun/cardioid dialogue cleaner with smooth multiband voice shaping, witness subtraction, and slow downward expansion. `MimirRuntime` queues it as diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index dcc2abc..930cb3b 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -157,6 +157,15 @@ Get-Content .\state\evidence.jsonl -Tail 8 app owns that path. - Faust/native DSP owns hot audio alignment, separation, spatialization, and synchronized stems. +- The current listenable dual-mic receipt is the Faust-chain bridge, not the + older C# composite. `scripts/record-kiyo-dual-mic-composite.ps1` records Kiyo + plus Scarlett ASIO, then `--asio-dual-mic-faust-cleaner-wav` compiles/runs + `faust/mimir_alignment_actuator.dsp` before + `faust/mimir_dual_mic_dialogue_cleaner.dsp` and muxes the dialogue stem into + `artifacts/runtime/kiyo-dual-mic-composite/kiyo-dual-mic-composite-latest.mp4`. + Fresh run `20260601-051044` measured cardioid delay 359.398 samples + (7487.452 us) at 48 kHz and applied holdback 359.398/0.000 to + shotgun/cardioid before cleanup. - OBS receives final program surfaces; it does not own synchronization. ## Current Pressure diff --git a/scripts/record-kiyo-dual-mic-composite.ps1 b/scripts/record-kiyo-dual-mic-composite.ps1 index d3f8f35..4d061f5 100644 --- a/scripts/record-kiyo-dual-mic-composite.ps1 +++ b/scripts/record-kiyo-dual-mic-composite.ps1 @@ -124,7 +124,7 @@ Wait-LoggedProcess $asio ($DurationSeconds + 15) "ASIO capture" Wait-LoggedProcess $kiyo ($DurationSeconds + 15) "Kiyo capture" dotnet run --project (Join-Path $repo "src\Mimir.BufferSmoke\Mimir.BufferSmoke.csproj") -- ` - --asio-dual-mic-composite-wav ` + --asio-dual-mic-faust-cleaner-wav ` --input $asioRaw ` --output $compositeWav ` --sample-rate $SampleRate ` diff --git a/src/Mimir.BufferSmoke/Mimir.BufferSmoke.csproj b/src/Mimir.BufferSmoke/Mimir.BufferSmoke.csproj index 7209bb8..476ec32 100644 --- a/src/Mimir.BufferSmoke/Mimir.BufferSmoke.csproj +++ b/src/Mimir.BufferSmoke/Mimir.BufferSmoke.csproj @@ -10,6 +10,7 @@ + diff --git a/src/Mimir.BufferSmoke/Program.cs b/src/Mimir.BufferSmoke/Program.cs index 06085ae..1faf2a0 100644 --- a/src/Mimir.BufferSmoke/Program.cs +++ b/src/Mimir.BufferSmoke/Program.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Numerics; using System.Security.Cryptography; using System.Text.Json; +using AquaSynth.Faust; using Aquarium.Engine; using Aquarium.Engine.Audio; using Aquarium.Engine.Input; @@ -96,6 +97,17 @@ if (args.Any(arg => string.Equals(arg, "--asio-dual-mic-composite-wav", StringCo ParseIntOption(args, "--cardioid-channel", 1)); } +if (args.Any(arg => string.Equals(arg, "--asio-dual-mic-faust-cleaner-wav", StringComparison.OrdinalIgnoreCase))) +{ + return RunAsioDualMicFaustCleanerWave( + ParseStringOption(args, "--input", ""), + ParseStringOption(args, "--output", ""), + ParseIntOption(args, "--sample-rate", 48_000), + ParseIntOption(args, "--channels", 4), + ParseIntOption(args, "--shotgun-channel", 0), + ParseIntOption(args, "--cardioid-channel", 1)); +} + if (args.Any(arg => string.Equals(arg, "--targeted-bioacoustic-probe-smoke", StringComparison.OrdinalIgnoreCase))) { return RunTargetedBioacousticProbeSmoke(); @@ -3565,6 +3577,160 @@ static int RunAsioDualMicCompositeWave( return 0; } +static int RunAsioDualMicFaustCleanerWave( + string inputPath, + string outputPath, + int sampleRate, + int channels, + int shotgunChannel, + int cardioidChannel) +{ + if (string.IsNullOrWhiteSpace(inputPath) || !File.Exists(inputPath)) + { + Console.Error.WriteLine("asio-dual-mic-faust-cleaner-wav failed: --input must name an existing f32 interleaved ASIO capture."); + return 1; + } + + if (string.IsNullOrWhiteSpace(outputPath)) + { + Console.Error.WriteLine("asio-dual-mic-faust-cleaner-wav failed: --output is required."); + return 1; + } + + if (shotgunChannel < 0 || cardioidChannel < 0 || shotgunChannel >= channels || cardioidChannel >= channels) + { + Console.Error.WriteLine($"asio-dual-mic-faust-cleaner-wav failed: channel indices must fit 0..{channels - 1}."); + return 1; + } + + var channelSamples = ReadInterleavedFloat32(inputPath, channels, out var frameCount); + if (frameCount == 0) + { + Console.Error.WriteLine("asio-dual-mic-faust-cleaner-wav failed: capture has no frames."); + return 1; + } + + var shotgun = channelSamples[shotgunChannel]; + var cardioid = channelSamples[cardioidChannel]; + var delay = EstimateRelativeDelaySamples(shotgun, cardioid, maxLagSamples: Math.Min(sampleRate / 100, 960)); + var referenceHoldback = Math.Max(0.0, Math.Max(0.0, delay)); + var shotgunHoldback = Math.Max(0.0, referenceHoldback); + var cardioidHoldback = Math.Max(0.0, referenceHoldback - delay); + if (delay < 0.0) + { + shotgunHoldback = 0.0; + cardioidHoldback = -delay; + } + + if (!TryRunFaustCleaner(shotgun, cardioid, frameCount, sampleRate, shotgunHoldback, cardioidHoldback, out var dialogue, out var residual, out var error)) + { + Console.Error.WriteLine($"asio-dual-mic-faust-cleaner-wav failed: {error}"); + return 1; + } + + var normalized = NormalizePeak(dialogue, peak: 0.92f); + WriteWave(outputPath, normalized, sampleRate); + var residualPath = Path.Combine( + Path.GetDirectoryName(outputPath) ?? ".", + $"{Path.GetFileNameWithoutExtension(outputPath)}-residual.wav"); + WriteWave(residualPath, residual, sampleRate); + var reportPath = Path.ChangeExtension(outputPath, ".json"); + var report = new + { + input = Path.GetFullPath(inputPath), + output = Path.GetFullPath(outputPath), + residual = Path.GetFullPath(residualPath), + sampleRate, + frameCount, + shotgunChannel, + cardioidChannel, + estimatedCardioidDelaySamples = delay, + estimatedCardioidDelayMicroseconds = delay * 1_000_000.0 / sampleRate, + shotgunHoldbackSamples = shotgunHoldback, + cardioidHoldbackSamples = cardioidHoldback, + dialogueRms = RootMeanSquare(dialogue), + residualRms = RootMeanSquare(residual), + pipeline = "faust/mimir_alignment_actuator.dsp -> faust/mimir_dual_mic_dialogue_cleaner.dsp" + }; + File.WriteAllText(reportPath, JsonSerializer.Serialize(report, new JsonSerializerOptions { WriteIndented = true })); + Console.WriteLine( + $"asio-dual-mic-faust-cleaner-wav input={inputPath} output={outputPath} residual={residualPath} report={reportPath} frames={frameCount} " + + $"delaySamples={delay:0.000} delayUs={delay * 1_000_000.0 / sampleRate:0.000} holdback={shotgunHoldback:0.000}/{cardioidHoldback:0.000} rms={RootMeanSquare(dialogue):0.000000}"); + return 0; +} + +static bool TryRunFaustCleaner( + float[] shotgun, + float[] cardioid, + int frameCount, + int sampleRate, + double shotgunHoldback, + double cardioidHoldback, + out float[] dialogue, + out float[] residual, + out string error) +{ + dialogue = []; + residual = []; + error = ""; + var alignmentPath = Path.GetFullPath("faust/mimir_alignment_actuator.dsp"); + var cleanerPath = Path.GetFullPath("faust/mimir_dual_mic_dialogue_cleaner.dsp"); + if (!File.Exists(alignmentPath) || !File.Exists(cleanerPath)) + { + error = "required Faust DSP files are missing."; + return false; + } + + using var compiler = new AquaSynthPatchCompiler(new AquaSynthNativeOptions(SampleRate: sampleRate)); + if (!compiler.TryCompileSource( + new AquaSynthCompileIdentity("mimir-alignment-offline", "mimir_alignment_actuator", File.ReadAllText(alignmentPath), unchecked((int)File.GetLastWriteTimeUtc(alignmentPath).Ticks)), + File.ReadAllText(alignmentPath), + 0.05f, + out var alignmentPatch, + out var alignmentError)) + { + error = alignmentError ?? "alignment Faust compile failed."; + return false; + } + + if (!compiler.TryCompileSource( + new AquaSynthCompileIdentity("mimir-dialogue-cleaner-offline", "mimir_dual_mic_dialogue_cleaner", File.ReadAllText(cleanerPath), unchecked((int)File.GetLastWriteTimeUtc(cleanerPath).Ticks)), + File.ReadAllText(cleanerPath), + 0.05f, + out var cleanerPatch, + out var cleanerError)) + { + error = cleanerError ?? "dialogue cleaner Faust compile failed."; + return false; + } + + using var alignment = alignmentPatch!.CreateStreamingPatch(); + using var cleaner = cleanerPatch!.CreateStreamingPatch(); + var aligned = Enumerable.Range(0, Math.Max(2, alignment.OutputCount)) + .Select(_ => new float[frameCount]) + .ToArray(); + var silence = new float[frameCount]; + alignment.ProcessBlock( + [shotgun, cardioid, silence, silence, silence, silence], + aligned, + frameCount, + new Dictionary(StringComparer.Ordinal) + { + ["source0/delay_samples"] = (float)Math.Clamp(shotgunHoldback, 0.0, 4096.0), + ["source1/delay_samples"] = (float)Math.Clamp(cardioidHoldback, 0.0, 4096.0), + ["source0/gain"] = 1.0f, + ["source1/gain"] = 1.0f + }); + + var cleaned = Enumerable.Range(0, Math.Max(2, cleaner.OutputCount)) + .Select(_ => new float[frameCount]) + .ToArray(); + cleaner.ProcessBlock([aligned[0], aligned[1]], cleaned, frameCount); + dialogue = cleaned[0]; + residual = cleaned[1]; + return true; +} + static int RunTargetedBioacousticProbeSmoke() { var residuals = new[] diff --git a/state/evidence.jsonl b/state/evidence.jsonl index de4f5c2..81dc958 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -322,3 +322,4 @@ {"ts": "2026-06-01T04:44:10+01:00", "type": "decision", "status": "ok", "note": "Moved dual-mic cleanup authority toward Faust after listening feedback showed the C# residual expander made the Kiyo composite choppier rather than cleaner. Disabled the expander in --asio-dual-mic-composite-wav defaults, added faust/mimir_dual_mic_dialogue_cleaner.dsp as a smooth two-input shotgun/cardioid dialogue cleaner, and queued it from MimirRuntime as dual-mic-dialogue-cleaner with host_voice plus residual ambient stems. Verified dotnet build and Faust 2.85.5 C++ generation for the DSP."} {"ts": "2026-06-01T04:46:01+01:00", "type": "decision", "status": "ok", "note": "Corrected the Faust cleaner wiring after user caught the prerequisite: dual-mic cleanup must consume post-alignment audio. The runtime no longer queues dual-mic-dialogue-cleaner from raw rolling buffers in parallel with the actuator. It now waits for the alignment actuator's published aligned_source_* stem frame from Fensalir's audio stem bus, then queues that aligned pair into the cleaner profile on the next tick. Alignment is a structural precursor to cleanup."} {"ts": "2026-06-01T04:54:24+01:00", "type": "verification", "status": "ok", "note": "Added and verified --dialogue-cleaner-routing-smoke. The smoke publishes a synthetic post-alignment aligned_source_* stem frame into MimirRuntime's Fensalir audio stem bus, then verifies Mimir queues the dual-mic-dialogue-cleaner Faust program and a two-channel cleaner StreamingAudioBlock sourced from asio-ch0-shotgun and asio-ch1-cardioid. Runtime publication now treats alignment frames as the cleaner input boundary and cleaner frames as NativeProgram stem publication, so host_voice is the publishable program stem rather than raw aligned_source lanes."} +{"ts": "2026-06-01T05:14:25+01:00", "type": "verification", "status": "ok", "note": "Recorded a fresh 10s Kiyo + Scarlett live receipt through the actual offline Faust chain. scripts/record-kiyo-dual-mic-composite.ps1 now calls --asio-dual-mic-faust-cleaner-wav, which compiles/runs faust/mimir_alignment_actuator.dsp before faust/mimir_dual_mic_dialogue_cleaner.dsp. Fresh run artifacts/runtime/kiyo-dual-mic-composite/20260601-051044 measured cardioid delay 359.398 samples (7487.452 us), applied holdback 359.398/0.000 to shotgun/cardioid, wrote dialogue and residual WAVs, and muxed artifacts/runtime/kiyo-dual-mic-composite/kiyo-dual-mic-composite-latest.mp4. ffprobe verified 10.000 s 640x480@30 H.264 plus 10.000 s 48 kHz mono AAC."} diff --git a/state/map.yaml b/state/map.yaml index 347d6d4..46f79be 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -649,18 +649,21 @@ accepted_design: mic-local 3.52 kHz interferer scores about 0.001 coherence and 0.948 suppression, its measured energy falls from 0.039195 to 0.001306, and SNR rises from 1.366 dB to 16.304 dB. - `scripts/record-kiyo-dual-mic-composite.ps1` is the first listenable bridge - receipt for that path. It starts Kiyo FFmpeg capture and Scarlett ASIO raw - capture together, converts ASIO channels 0/1 to a computed composite WAV - through `--asio-dual-mic-composite-wav`, then muxes the composite WAV with - Kiyo video. The 2026-06-01 receipt + `scripts/record-kiyo-dual-mic-composite.ps1` is the first listenable + Faust-chain bridge receipt for that path. It starts Kiyo FFmpeg capture and + Scarlett ASIO raw capture together, converts ASIO channels 0/1 through + `--asio-dual-mic-faust-cleaner-wav`, then muxes the Faust dialogue WAV with + Kiyo video. The offline command compiles/runs + `faust/mimir_alignment_actuator.dsp` before + `faust/mimir_dual_mic_dialogue_cleaner.dsp`, so the receipt exercises the + real alignment-then-cleaner chain. The fresh 2026-06-01 receipt + `artifacts/runtime/kiyo-dual-mic-composite/20260601-051044` and latest MP4 `artifacts/runtime/kiyo-dual-mic-composite/kiyo-dual-mic-composite-latest.mp4` - has 10.000 s of 640x480 30 fps Kiyo video and 9.994 s of mono AAC composite - audio; the composite report estimated channel-1 delay at about -141.019 - samples (-2937.889 us). After listening feedback, the bridge audition - defaults now cap measured-band boost at 1.18x, suppress incoherent - calibrated bands harder, and leave the choppy residual expander disabled by - default. Faust/native DSP now has the first actual cleaner socket: + has 10.000 s of 640x480 30 fps Kiyo video and 10.000 s of 48 kHz mono AAC + from the Faust dialogue stem; the report estimated the cardioid 359.398 + samples late (7487.452 us), applied holdback 359.398/0.000 samples to + shotgun/cardioid, and wrote both dialogue and residual WAVs. + Faust/native DSP now has the first actual cleaner socket: `faust/mimir_dual_mic_dialogue_cleaner.dsp` compiles as a smooth two-input shotgun/cardioid dialogue cleaner and Mimir queues it as `dual-mic-dialogue-cleaner`, fed from the alignment actuator's published