Expose chirp-bin response calibration surface
This commit is contained in:
parent
7f4f6cb7bc
commit
353031858a
12 changed files with 60 additions and 26 deletions
|
|
@ -72,7 +72,10 @@ and `hybrid`. `MimirChirpBinTimeline` uses a common chirp duration, chirp slope,
|
|||
and window for every symbol. Acquisition is a cheap bounded energy/onset pass;
|
||||
classification is dechirp plus a fixed Goertzel bin bank; timeline placement is
|
||||
the de Bruijn triplet trellis. A constrained local waveform correlation around
|
||||
the decoded anchor delay provides the final fractional offset. The synthetic invariant is
|
||||
the decoded anchor delay provides the final fractional offset. The decoder keeps
|
||||
the full bin-energy surface for each classified chirp and aggregates it into
|
||||
per-band response evidence, so the same stream can calibrate timing and the
|
||||
speaker/room/mic transfer function. The synthetic invariant is
|
||||
`dotnet run --project .\src\Mimir.BufferSmoke\Mimir.BufferSmoke.csproj -- --chirp-bin-self-test`;
|
||||
it renders the chirp-bin timeline, decodes by dechirp plus Goertzel bins, and
|
||||
requires code-valid triplet anchors plus a stable source clock. `chirp-only`
|
||||
|
|
@ -165,11 +168,11 @@ produce at least three matched canonical anchors, it has not decoded timing for
|
|||
that window. Reports carry rounded integer delay, fractional delay, and the
|
||||
count/confidence of timeline-symbol anchors used to derive the report.
|
||||
|
||||
The same timeline also starts the frequency-response path. Each report includes
|
||||
per-band matched energy for the chirplet atoms. That is not a finished room/mic
|
||||
normalizer yet, but it is the live surface that will become response-curve
|
||||
estimation: loopback carries what was emitted, each mic carries what survived
|
||||
speaker, air, room, and capsule, and the ratio over the continuous chirplet
|
||||
The same timeline also starts the frequency-response path. Each active report
|
||||
includes per-band dechirped energy for the chirp-bin bank. That is not a
|
||||
finished room/mic normalizer yet, but it is the live surface that will become
|
||||
response-curve estimation: loopback carries what was emitted, each mic carries
|
||||
what survived speaker, air, room, and capsule, and the ratio over the continuous
|
||||
timeline becomes gain/phase correction evidence.
|
||||
|
||||
`MimirAudioSynchronizationStateTracker` turns continuous observations into
|
||||
|
|
|
|||
|
|
@ -100,7 +100,10 @@ a named invariant that the native runtime cannot protect yet.
|
|||
time/frequency ambiguity as candidate symbol/offset pairs so code constraints
|
||||
can choose the coherent path. The analyzer refines the final fractional delay
|
||||
with constrained local waveform correlation around the decoded active delay.
|
||||
Reports/states expose delay in microseconds as well as fractional samples.
|
||||
Each classified chirp carries the full bin-energy response surface, and stream
|
||||
decodes aggregate that into per-band calibration evidence for frequency
|
||||
response normalization. Reports/states expose delay in microseconds as well
|
||||
as fractional samples.
|
||||
Hybrid emits this as low-gain half-second bursts every two seconds only while
|
||||
passive confidence is weak.
|
||||
Use `--chirp-bin-self-test` to prove the codebook/decoder and
|
||||
|
|
|
|||
|
|
@ -110,7 +110,10 @@ Goertzel bins, explicit time/frequency ambiguity candidates, and a constrained
|
|||
scheduled-waveform correlation for standalone source-offset refinement. Pairwise
|
||||
sync compares matched anchors first, then only accepts independent clock-fit
|
||||
offsets inside the live latency horizon so period aliases do not become absurd
|
||||
reports. Reports/states expose `delayUs` next to fractional sample delay.
|
||||
reports. Each classified chirp carries the full dechirped bin-energy surface,
|
||||
and decodes aggregate that into per-band response evidence for future
|
||||
frequency-response normalization. Reports/states expose `delayUs` next to
|
||||
fractional sample delay.
|
||||
`Mimir.BufferSmoke
|
||||
--chirp-only-sync-self-test --sample-rate 192000` and `--hybrid-sync-self-test
|
||||
--sample-rate 192000` both recover a 1269.5-sample synthetic delay with printed
|
||||
|
|
|
|||
|
|
@ -89,6 +89,9 @@ Get-Content .\state\evidence.jsonl -Tail 8
|
|||
explicit time/frequency ambiguity candidates, and constrained local waveform
|
||||
correlation for final fractional delay. It also supports standalone source
|
||||
offset recovery from schedule/codebook state, which is the Raven/phone shape.
|
||||
Each classified chirp carries the full dechirped bin-energy surface; sync
|
||||
reports expose those bands so the same stream can become frequency-response
|
||||
calibration evidence.
|
||||
`Mimir.BufferSmoke
|
||||
--chirp-only-sync-self-test --sample-rate 192000` and
|
||||
`--hybrid-sync-self-test --sample-rate 192000` both recover a 1269.5-sample
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ static int RunChirpletSelfTest()
|
|||
{
|
||||
var timeline = MimirChirpletTimeline.Default;
|
||||
var decoder = new MimirChirpletStreamDecoder(windowDuration: TimeSpan.FromSeconds(2));
|
||||
MimirChirpletStreamDecode decode = new([], [], [], null);
|
||||
MimirChirpletStreamDecode decode = new([], [], [], null, []);
|
||||
for (ulong segment = 0; segment < 4; segment++)
|
||||
{
|
||||
decode = decoder.Append(timeline.RenderSegmentMonoFloat(segment));
|
||||
|
|
@ -528,7 +528,7 @@ static int AnalyzeAsioFloat32(string inputPath, int sampleRate, int channels, in
|
|||
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}");
|
||||
$"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} bands={DescribeBands(report.BandResponses)} compared={report.ComparedSamples}");
|
||||
}
|
||||
|
||||
return reports.Count > 0 ? 0 : 1;
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ public sealed class MimirAudioSynchronizationAnalyzer
|
|||
? RefineDelayFromWaveform(referenceWindow, candidateWindow, deterministicFit.DelaySamples, activeReferenceBlock.SampleRate)
|
||||
: deterministicFit.DelaySamples;
|
||||
var bandResponses = useChirpBinTimeline
|
||||
? []
|
||||
? candidateDecode.BandResponses
|
||||
: MimirChirpletTimeline.Default.EstimateBandResponse(candidateWindow, activeReferenceBlock.SampleRate);
|
||||
reports.Add(new MimirAudioSynchronizationReport(
|
||||
reference.Descriptor.SourceId,
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public sealed class MimirChirpBinTimeline
|
|||
{
|
||||
if (samples.Length == 0)
|
||||
{
|
||||
return new MimirChirpletStreamDecode([], [], [], null);
|
||||
return new MimirChirpletStreamDecode([], [], [], null, []);
|
||||
}
|
||||
|
||||
var frames = DetectFrames(samples, sampleRate);
|
||||
|
|
@ -79,7 +79,7 @@ public sealed class MimirChirpBinTimeline
|
|||
clock = clock with { SourceOffsetSamples = refinedOffset };
|
||||
}
|
||||
|
||||
return new MimirChirpletStreamDecode(frames, symbols, anchors, clock);
|
||||
return new MimirChirpletStreamDecode(frames, symbols, anchors, clock, EstimateBandResponse(frames));
|
||||
}
|
||||
|
||||
public MimirChirpletTimelineEvent EventForIndex(ulong eventIndex)
|
||||
|
|
@ -232,7 +232,8 @@ public sealed class MimirChirpBinTimeline
|
|||
correctedCandidates.Add(new MimirChirpletSymbolCandidate(
|
||||
canonicalSymbol,
|
||||
correctedOffset,
|
||||
Math.Max(candidate.Energy, correctedEnergy) / (1.0 + Math.Abs(timingBinShift) * 0.15)));
|
||||
Math.Max(candidate.Energy, correctedEnergy) / (1.0 + Math.Abs(timingBinShift) * 0.15),
|
||||
candidate.BandResponses));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +250,7 @@ public sealed class MimirChirpBinTimeline
|
|||
int sampleOffset)
|
||||
{
|
||||
var kernels = KernelSets.GetOrAdd(sampleRate, BuildKernelSet);
|
||||
var scores = new MimirChirpletSymbolCandidate[Symbols.Length];
|
||||
var scores = new double[Symbols.Length];
|
||||
var sampleEnergy = 0.0;
|
||||
for (var index = 0; index < samples.Length; index++)
|
||||
{
|
||||
|
|
@ -264,13 +265,15 @@ public sealed class MimirChirpBinTimeline
|
|||
for (var symbol = 0; symbol < Symbols.Length; symbol++)
|
||||
{
|
||||
var score = DechirpedBin(samples, kernels.Symbols[symbol]);
|
||||
scores[symbol] = new MimirChirpletSymbolCandidate(
|
||||
symbol,
|
||||
sampleOffset,
|
||||
2.0 * score / Math.Sqrt(sampleEnergy * kernels.ReferenceEnergy));
|
||||
scores[symbol] = 2.0 * score / Math.Sqrt(sampleEnergy * kernels.ReferenceEnergy);
|
||||
}
|
||||
|
||||
var bandResponses = scores
|
||||
.Select((energy, symbol) => new MimirChirpletBandResponse(SymbolCenterHz(Symbols[symbol]), energy))
|
||||
.ToArray();
|
||||
|
||||
return scores
|
||||
.Select((energy, symbol) => new MimirChirpletSymbolCandidate(symbol, sampleOffset, energy, bandResponses))
|
||||
.OrderByDescending(candidate => candidate.Energy)
|
||||
.Take(MaxSymbolCandidatesPerFrame)
|
||||
.ToArray();
|
||||
|
|
@ -509,6 +512,17 @@ public sealed class MimirChirpBinTimeline
|
|||
meanAbsoluteError);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<MimirChirpletBandResponse> EstimateBandResponse(IReadOnlyList<MimirChirpletTransformFrame> frames)
|
||||
{
|
||||
var responses = frames
|
||||
.SelectMany(frame => frame.BestCandidate.BandResponses ?? [])
|
||||
.GroupBy(response => response.CenterHz)
|
||||
.Select(group => new MimirChirpletBandResponse(group.Key, group.Average(response => response.Energy)))
|
||||
.OrderBy(response => response.CenterHz)
|
||||
.ToArray();
|
||||
return responses;
|
||||
}
|
||||
|
||||
private static double RefineSourceOffset(ReadOnlySpan<float> samples, int sampleRate, double initialOffsetSamples)
|
||||
{
|
||||
var radius = Math.Max(4, (int)Math.Ceiling(sampleRate * 0.00008));
|
||||
|
|
@ -665,6 +679,9 @@ public sealed class MimirChirpBinTimeline
|
|||
return 2.0 * Math.PI * (BaseStartHz * t + 0.5 * slope * t * t);
|
||||
}
|
||||
|
||||
private static double SymbolCenterHz(MimirChirpBinSymbolDefinition symbol) =>
|
||||
(BaseStartHz + BaseEndHz) * 0.5 + symbol.OffsetHz;
|
||||
|
||||
private static int ShiftSymbol(int symbolId, int shift) =>
|
||||
(symbolId + shift + SymbolCount) % SymbolCount;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ namespace Mimir.Runtime.Synchronization;
|
|||
public sealed record MimirChirpletSymbolCandidate(
|
||||
int SymbolId,
|
||||
double SampleOffset,
|
||||
double Energy);
|
||||
double Energy,
|
||||
IReadOnlyList<MimirChirpletBandResponse>? BandResponses = null);
|
||||
|
||||
public sealed record MimirChirpletTransformFrame(
|
||||
double SampleOffset,
|
||||
|
|
@ -40,4 +41,5 @@ public sealed record MimirChirpletStreamDecode(
|
|||
IReadOnlyList<MimirChirpletTransformFrame> Frames,
|
||||
IReadOnlyList<MimirChirpletSymbolObservation> Symbols,
|
||||
IReadOnlyList<MimirChirpletTimelineAnchor> Anchors,
|
||||
MimirChirpletClockFit? ClockFit);
|
||||
MimirChirpletClockFit? ClockFit,
|
||||
IReadOnlyList<MimirChirpletBandResponse> BandResponses);
|
||||
|
|
|
|||
|
|
@ -83,6 +83,6 @@ public sealed class MimirChirpletStreamDecoder
|
|||
.ToArray(),
|
||||
})
|
||||
.ToArray();
|
||||
return new MimirChirpletStreamDecode(frames, symbols, anchors, clock);
|
||||
return new MimirChirpletStreamDecode(frames, symbols, anchors, clock, decode.BandResponses);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ public sealed class MimirChirpletTimeline
|
|||
{
|
||||
if (samples.Length == 0)
|
||||
{
|
||||
return new MimirChirpletStreamDecode([], [], [], null);
|
||||
return new MimirChirpletStreamDecode([], [], [], null, []);
|
||||
}
|
||||
|
||||
var frames = DetectTransformFrames(samples, sampleRate, Math.Max(1, sampleRate / 200));
|
||||
|
|
@ -127,7 +127,7 @@ public sealed class MimirChirpletTimeline
|
|||
.ToArray();
|
||||
var anchors = DecodeTrellisAnchors(frames, sampleRate);
|
||||
var clock = FitClock(anchors, sampleRate);
|
||||
return new MimirChirpletStreamDecode(frames, symbols, anchors, clock);
|
||||
return new MimirChirpletStreamDecode(frames, symbols, anchors, clock, EstimateBandResponse(samples, sampleRate));
|
||||
}
|
||||
|
||||
public MimirChirpletTimelineEvent EventForIndex(ulong eventIndex)
|
||||
|
|
|
|||
|
|
@ -69,3 +69,4 @@
|
|||
{"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."}
|
||||
{"ts": "2026-05-23T19:22:00+01:00", "type": "implementation", "status": "ok", "note": "Made the active audio sync path use the receiver-cheap chirp-bin decoder for both chirp-only and hybrid modes. The old arbitrary chirplet matcher remains diagnostic/reference only. The chirp-bin decoder now uses bounded energy/onset proposals, dechirp plus fixed Goertzel bins, explicit time/frequency ambiguity candidates, and constrained local waveform correlation for final fractional delay. Synthetic 192 kHz chirp-only and hybrid self-tests both recover a 1269.5-sample delay with printed 0.000 us error; a real Scarlett ASIO chirp-bin artifact decodes Loopback 1 -> Loopback 2 at 0.000 us with 12 anchors and 0.999 confidence, while physical mic channels still need acoustic robustness work."}
|
||||
{"ts": "2026-05-23T19:40:50+01:00", "type": "implementation", "status": "ok", "note": "Extended active chirp-bin decoding toward the Perfect Machine receiver shape: standalone DecodeStreamWindow now refines source offset against the scheduled waveform so a listener with only codebook/schedule state can place delayed audio on canonical time. Synthetic 192 kHz standalone tests recover 1269.5 samples exactly, 96000 samples / 500 ms to below printed microsecond precision, and 13789.75 samples within 0.021 us. Pairwise Mimir sync now rejects independent clock-fit differences outside a 10s live horizon so coherent period aliases do not become absurd delays. Fensalir project references were updated from removed Aquarium.LocalCast to Aquarium.Fensalir."}
|
||||
{"ts": "2026-05-23T19:47:34+01:00", "type": "implementation", "status": "ok", "note": "Active chirp-bin decoding now preserves calibration evidence as well as timing: each classified chirp carries the full dechirped 32-bin energy surface, stream decodes aggregate those bins into BandResponses, and sync reports print/expose those per-band response estimates. This makes the chirp stream a timing witness and a frequency-response calibration surface. Verified dotnet build, 192 kHz chirp-only self-test, 500 ms standalone self-test, and Scarlett ASIO loopback artifact with response bands."}
|
||||
|
|
|
|||
|
|
@ -108,8 +108,10 @@ accepted_design:
|
|||
classification, explicit time/frequency ambiguity candidates, then the
|
||||
existing de Bruijn triplet anchor and clock-fit machine. The analyzer refines
|
||||
final active delay with constrained local waveform correlation around the
|
||||
decoded anchor delay. Reports and sync states expose delay in microseconds
|
||||
as well as fractional samples. Hybrid emits it as low-gain half-second
|
||||
decoded anchor delay. Each classified chirp carries the full dechirped
|
||||
bin-energy surface, and decodes aggregate that into per-band response
|
||||
evidence for frequency-response normalization. Reports and sync states expose
|
||||
delay in microseconds as well as fractional samples. Hybrid emits it as low-gain half-second
|
||||
bursts every two seconds while passive confidence is weak, never as catch-up
|
||||
backlog. The analyzer no longer applies the passive two-second window floor
|
||||
to active fallback; `dotnet run --project
|
||||
|
|
|
|||
Loading…
Reference in a new issue