Label runtime audio spectra

This commit is contained in:
Meta Vens 2026-05-25 07:56:08 +01:00
commit 31504718d9
6 changed files with 45 additions and 11 deletions

View file

@ -24,7 +24,13 @@
"asio-ch1",
"asio-ch2",
"asio-ch3"
]
],
"sourceLabels": {
"asio-ch0": "Focusrite Input 1",
"asio-ch1": "Focusrite Input 2",
"asio-ch2": "Focusrite Loopback 1",
"asio-ch3": "Focusrite Loopback 2"
}
}
]
}

View file

@ -404,7 +404,7 @@ public sealed class MimirRuntime : IAquariumRuntime
foreach (var spectrum in lastAudioSpectra.OrderBy(snapshot => snapshot.SourceId, StringComparer.Ordinal))
{
Console.WriteLine(
$"mimir-spectrum {spectrum.SourceId} rate={spectrum.SampleRate} fft={spectrum.FftSize} rms={spectrum.Rms:0.000000} peak={spectrum.Peak:0.000000} floorDb={spectrum.NoiseFloorDb:0.0} peaks={DescribeSpectrumPeaks(spectrum)}");
$"mimir-spectrum {spectrum.SourceId} label=\"{spectrum.Label}\" rate={spectrum.SampleRate} fft={spectrum.FftSize} rms={spectrum.Rms:0.000000} peak={spectrum.Peak:0.000000} floorDb={spectrum.NoiseFloorDb:0.0} peaks={DescribeSpectrumPeaks(spectrum)}");
}
foreach (var report in lastAudioSynchronizationReports.OrderBy(report => report.SourceId, StringComparer.Ordinal))
@ -501,7 +501,7 @@ public sealed class MimirRuntime : IAquariumRuntime
return string.Join(" | ", synchronization.Buffers.Buffers
.Where(buffer => buffer.Descriptor.Kind == MimirStreamKind.Audio)
.OrderBy(buffer => buffer.Descriptor.SourceId, StringComparer.Ordinal)
.Select(buffer => $"{buffer.Descriptor.SourceId}:{buffer.Count}@{buffer.EdgeNs}"));
.Select(buffer => $"{buffer.Descriptor.Label}[{buffer.Descriptor.SourceId}]:{buffer.Count}@{buffer.EdgeNs}"));
}
private string DescribeSpectra()
@ -520,7 +520,10 @@ public sealed class MimirRuntime : IAquariumRuntime
foreach (var spectrum in lastAudioSpectra)
{
builder
.Append(spectrum.Label)
.Append(" [")
.Append(spectrum.SourceId)
.Append("]")
.Append(" rms=")
.Append(spectrum.Rms.ToString("0.000000"))
.Append(" peak=")
@ -580,15 +583,15 @@ public sealed class MimirRuntime : IAquariumRuntime
var latest = buffer.Latest;
if (latest?.VideoFrame is { } frame)
{
return $"{buffer.Descriptor.SourceId}: {buffer.Count} {frame.Width}x{frame.Height} {frame.PixelFormat} bytes {latest.Value.ByteLength} edge {buffer.EdgeNs}";
return $"{buffer.Descriptor.Label} [{buffer.Descriptor.SourceId}]: {buffer.Count} {frame.Width}x{frame.Height} {frame.PixelFormat} bytes {latest.Value.ByteLength} edge {buffer.EdgeNs}";
}
if (latest?.AudioBlock is { } block)
{
return $"{buffer.Descriptor.SourceId}: {buffer.Count} {block.Channels}ch {block.SampleRate}Hz {block.SampleFormat} frames {block.FrameCount} bytes {latest.Value.ByteLength} edge {buffer.EdgeNs}";
return $"{buffer.Descriptor.Label} [{buffer.Descriptor.SourceId}]: {buffer.Count} {block.Channels}ch {block.SampleRate}Hz {block.SampleFormat} frames {block.FrameCount} bytes {latest.Value.ByteLength} edge {buffer.EdgeNs}";
}
return $"{buffer.Descriptor.SourceId}: {buffer.Count} edge {buffer.EdgeNs}";
return $"{buffer.Descriptor.Label} [{buffer.Descriptor.SourceId}]: {buffer.Count} edge {buffer.EdgeNs}";
}
private string DescribeAudioSync()

View file

@ -7,6 +7,7 @@ public sealed record MimirAudioSpectrumBin(double FrequencyHz, double Decibels,
public sealed record MimirAudioSpectrumSnapshot(
string SourceId,
string Label,
int SampleRate,
int FftSize,
int WindowSamples,
@ -85,7 +86,7 @@ public sealed class MimirAudioSpectrumAnalyzer
spectrum[index] = new Complex(window[index], 0.0);
}
return AnalyzePreparedSpectrum(sourceId, sampleRate, written, edgeNs: 0);
return AnalyzePreparedSpectrum(sourceId, sourceId, sampleRate, written, edgeNs: 0);
}
private MimirAudioSpectrumSnapshot? AnalyzeBuffer(MimirRollingStreamBuffer buffer)
@ -103,11 +104,12 @@ public sealed class MimirAudioSpectrumAnalyzer
return null;
}
return AnalyzePreparedSpectrum(buffer.Descriptor.SourceId, latestBlock.SampleRate, written, buffer.EdgeNs);
return AnalyzePreparedSpectrum(buffer.Descriptor.SourceId, buffer.Descriptor.Label, latestBlock.SampleRate, written, buffer.EdgeNs);
}
private MimirAudioSpectrumSnapshot AnalyzePreparedSpectrum(
string sourceId,
string label,
int sampleRate,
int written,
long edgeNs)
@ -136,6 +138,7 @@ public sealed class MimirAudioSpectrumAnalyzer
var floor = bands.Count == 0 ? -120.0 : bands.OrderBy(value => value).ElementAt(Math.Clamp(bands.Count / 4, 0, bands.Count - 1));
return new MimirAudioSpectrumSnapshot(
sourceId,
label,
sampleRate,
fftSize,
written,

View file

@ -101,7 +101,8 @@ public sealed class MimirRuntimeConfiguration
stream.SourceId,
ParseKind(stream.Kind),
ParseOrigin(stream.Origin),
stream.Enabled);
stream.Enabled,
stream.DisplayName);
}
private static IEnumerable<MimirStreamDescriptor> ToDescriptors(MimirStreamConfig stream)
@ -118,7 +119,8 @@ public sealed class MimirRuntimeConfiguration
sourceId,
ParseKind(stream.Kind),
ParseOrigin(stream.Origin),
stream.Enabled);
stream.Enabled,
stream.DisplayNameForSource(sourceId));
}
}
@ -282,6 +284,8 @@ public sealed class MimirStreamConfig
{
public string SourceId { get; set; } = "";
public string DisplayName { get; set; } = "";
public string Kind { get; set; } = "Video";
public string Origin { get; set; } = "LocalDevice";
@ -296,9 +300,21 @@ public sealed class MimirStreamConfig
public string[] AcceptSourceIds { get; set; } = [];
public Dictionary<string, string> SourceLabels { get; set; } = new(StringComparer.OrdinalIgnoreCase);
public int ChunkBytes { get; set; } = 65_536;
public int SampleRate { get; set; } = 192_000;
public string DriverClsid { get; set; } = "";
public string DisplayNameForSource(string sourceId)
{
if (SourceLabels.TryGetValue(sourceId, out var label) && !string.IsNullOrWhiteSpace(label))
{
return label.Trim();
}
return sourceId;
}
}

View file

@ -4,7 +4,12 @@ public sealed record MimirStreamDescriptor(
string SourceId,
MimirStreamKind Kind,
MimirStreamOrigin Origin,
bool Enabled = true)
bool Enabled = true,
string DisplayName = "")
{
public string BufferKey => $"{Kind}:{Origin}:{SourceId}";
public string Label => string.IsNullOrWhiteSpace(DisplayName)
? SourceId
: DisplayName;
}

View file

@ -112,3 +112,4 @@
{"ts": "2026-05-25T07:05:34+01:00", "type": "implementation", "status": "ok", "note": "Added runtime FFT spectra and Fensalir readiness gating. Fensalir now calls IAquariumRuntime.OnSceneReady after the first presented ready frame; Mimir waits for that callback before emitting bioacoustic test audio, running sync analysis, or updating the cached spectrum diagnostics. MimirAudioSpectrumAnalyzer computes bounded Hann-windowed radix-2 FFT snapshots from rolling audio buffers, exposes top peaks/log bands/RMS/peak, and Mimir renders cached spectra in the DirectWrite UI plus telemetry. Verification run with ASIO config showed scene-ready before bioacoustic chunks and live 8192-point spectra for asio-ch0 through asio-ch3; asio-ch0 remains flat low-level noise while loopback/mic-bearing channels show song-band peaks."}
{"ts": "2026-05-25T07:11:48+01:00", "type": "correction", "status": "ok", "note": "Tightened the Fensalir scene-ready gate after runtime spectra testing showed the app still created sources and emitted telemetry before the render path was ready. Runtime config now stores lazy stream-source factories; Mimir.App creates/registers ASIO/process/native sources only inside OnSceneReady, MimirRuntime.Update returns without polling, spectra, sync, telemetry, or audio emission until that callback, and Fensalir constructs the WASAPI/AquaSynth host only after the first presented ready frame. Verification log artifacts/runtime/mimir-ready-gate-20260525-071121.out.log shows no ASIO buffer polling, spectrum telemetry, or bioacoustic batch before D3D12 shader pipelines ready and Mimir Fensalir scene ready."}
{"ts": "2026-05-25T07:51:20+01:00", "type": "verification", "status": "ok", "note": "Audacity WASAPI speech spectrogram corresponds to live physical mic input, not the previously invalidated ASIO noise lane. Focusrite ASIO channel enumeration reports input[0]=Input 1, input[1]=Input 2, input[2]=Loopback 1, input[3]=Loopback 2. A fresh 5s raw ASIO capture artifacts/asio/scarlett-channel-id-20260525-075058-f32.raw inspected with --inspect-asio-f32 shows ch1/Input 2 carrying real speech-band energy (rms 0.009809, peak 0.069316, speechRms 0.007206), ch0/Input 1 at low floor (rms 0.002092), and loopbacks ch2/ch3 silent with no playback. Treat Audacity channel 2 as one-based physical Input 2 => Mimir asio-ch1; do not interpret it as loopback asio-ch2."}
{"ts": "2026-05-25T07:55:48+01:00", "type": "implementation", "status": "ok", "note": "Made runtime audio spectra labels first-class. MimirStreamDescriptor now carries an optional DisplayName/Label, MimirRuntimeConfigFile can assign per-source labels through sourceLabels, and the ASIO example labels Focusrite Input 1, Focusrite Input 2, Focusrite Loopback 1, and Focusrite Loopback 2. The FFT panel and telemetry now render human labels alongside machine source ids, so buffer sanity checks show both meaning and id. Verification with mimir-labeled-fft-20260525-075447.out.log showed labeled spectra for all four Focusrite ASIO lanes."}