diff --git a/artifacts/runtime/mimir-mel-spectrum-stack.png b/artifacts/runtime/mimir-mel-spectrum-stack.png new file mode 100644 index 0000000..4dfab35 Binary files /dev/null and b/artifacts/runtime/mimir-mel-spectrum-stack.png differ diff --git a/src/Mimir.Runtime/MimirRuntime.cs b/src/Mimir.Runtime/MimirRuntime.cs index 94ae6f8..e2d088f 100644 --- a/src/Mimir.Runtime/MimirRuntime.cs +++ b/src/Mimir.Runtime/MimirRuntime.cs @@ -202,6 +202,15 @@ public sealed class MimirRuntime : IAquariumRuntime acceptsReturn: false, monospace: true, tooltip: "Cached FFT spectra from the runtime rolling audio buffers."); + }) + .Panel("Mimir Audio Spectra", 18.0f, 18.0f, 1180.0f, fadeWhenMouseDistant: true, panel => + { + panel.MelSpectrumStack( + "Mel-space FFT", + BuildMelSpectrumLanes, + laneBins: 64, + laneHeight: 116.0f, + tooltip: "Live mel-spaced FFT lanes from the same rolling audio buffers used by synchronization."); }); } @@ -540,6 +549,26 @@ public sealed class MimirRuntime : IAquariumRuntime return builder.ToString().TrimEnd(); } + private IReadOnlyList BuildMelSpectrumLanes() + { + if (!sceneReady) + { + return []; + } + + return lastAudioSpectra + .OrderBy(spectrum => spectrum.SourceId, StringComparer.Ordinal) + .Select(spectrum => new AquariumUiMelSpectrumLane( + spectrum.Label, + spectrum.SourceId, + spectrum.Rms, + spectrum.Peak, + spectrum.NoiseFloorDb, + spectrum.BandDecibels, + spectrum.Peaks.Select(peak => $"{peak.FrequencyHz / 1000.0:0.00}kHz {peak.Decibels:0.0}dB").ToArray())) + .ToArray(); + } + private static string SpectrumBars(MimirAudioSpectrumSnapshot spectrum) { const string ramp = " .:-=+*#%@"; diff --git a/src/Mimir.Runtime/Synchronization/MimirAudioSpectrumAnalyzer.cs b/src/Mimir.Runtime/Synchronization/MimirAudioSpectrumAnalyzer.cs index 3284314..9200622 100644 --- a/src/Mimir.Runtime/Synchronization/MimirAudioSpectrumAnalyzer.cs +++ b/src/Mimir.Runtime/Synchronization/MimirAudioSpectrumAnalyzer.cs @@ -133,7 +133,7 @@ public sealed class MimirAudioSpectrumAnalyzer magnitudes[index] = spectrum[index].Magnitude / Math.Max(1, written); } - var bands = BuildLogBands(magnitudes, sampleRate); + var bands = BuildMelBands(magnitudes, sampleRate); var peaks = FindPeaks(magnitudes, sampleRate, count: 6); var floor = bands.Count == 0 ? -120.0 : bands.OrderBy(value => value).ElementAt(Math.Clamp(bands.Count / 4, 0, bands.Count - 1)); return new MimirAudioSpectrumSnapshot( @@ -191,18 +191,20 @@ public sealed class MimirAudioSpectrumAnalyzer return written; } - private IReadOnlyList BuildLogBands(IReadOnlyList magnitudes, int sampleRate) + private IReadOnlyList BuildMelBands(IReadOnlyList magnitudes, int sampleRate) { var bands = new double[displayBandCount]; var nyquist = sampleRate * 0.5; var minHz = 40.0; var maxHz = Math.Max(minHz * 2.0, nyquist); + var minMel = HertzToMel(minHz); + var maxMel = HertzToMel(maxHz); for (var band = 0; band < bands.Length; band++) { var start = band / (double)bands.Length; var end = (band + 1) / (double)bands.Length; - var lowHz = minHz * Math.Pow(maxHz / minHz, start); - var highHz = minHz * Math.Pow(maxHz / minHz, end); + var lowHz = MelToHertz(minMel + (maxMel - minMel) * start); + var highHz = MelToHertz(minMel + (maxMel - minMel) * end); var firstBin = Math.Clamp((int)Math.Floor(lowHz * fftSize / sampleRate), 1, magnitudes.Count - 1); var lastBin = Math.Clamp((int)Math.Ceiling(highHz * fftSize / sampleRate), firstBin, magnitudes.Count - 1); var sum = 0.0; @@ -219,6 +221,10 @@ public sealed class MimirAudioSpectrumAnalyzer return bands; } + private static double HertzToMel(double hertz) => 2595.0 * Math.Log10(1.0 + hertz / 700.0); + + private static double MelToHertz(double mel) => 700.0 * (Math.Pow(10.0, mel / 2595.0) - 1.0); + private IReadOnlyList FindPeaks(IReadOnlyList magnitudes, int sampleRate, int count) { var peaks = new List(); diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 1986fbc..cd0b064 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -113,3 +113,4 @@ {"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."} +{"ts": "2026-05-25T08:16:14+01:00", "type": "verification", "status": "ok", "note": "Rendered Fensalir MelSpectrumStack from Mimir ASIO rolling buffers with canary-packet-trill chirp-only song after scene-ready; captured artifacts/runtime/mimir-mel-spectrum-stack.png with four labeled 192 kHz Focusrite lanes."}