feat(mix-visualizer): Phase 10 tuning — smooth waveform, bouncy collision, 8 knobs

Smooth the loudness contour (~50 ms envelope at preprocessing + decode-time, plus
smootherstep render reconstruction); retune wax↔waveform collision to bouncy/sub-unity
(no explosion/stuck/jitter); split the bubbles knob into fluid-amount + fluid-viscosity
(cohesion via uniform-only smin/wobble); retune scroll/gravity/heat/width ranges; make
the colour rotation visible and boost OKLab chroma; the controls bar now holds its
layout and hides only its knobs via a Visible parameter.
This commit is contained in:
daniel-c-harvey
2026-06-17 05:12:15 -04:00
parent ba1a1cd8ec
commit 4e34696719
9 changed files with 500 additions and 183 deletions
+56 -2
View File
@@ -36,9 +36,13 @@ public class RmsLoudnessAlgorithmTests
var silentAverage = profile.Take(8).Average();
var loudAverage = profile.Skip(8).Average();
Assert.That(silentAverage, Is.LessThan(0.01), "silent region should read near zero");
// The ~50 ms envelope smoothing intentionally bleeds a little loud energy across the
// silence/loud boundary, so the silent-half average is no longer ~0 — it sits low but
// non-zero (the boundary bucket lifts). The contract that matters is preserved: the silent
// region reads LOW, the loud region reads near peak, and loud dwarfs silent by a wide margin.
Assert.That(silentAverage, Is.LessThan(0.1), "silent region should still read low (smoothing lifts only the boundary)");
Assert.That(loudAverage, Is.GreaterThan(0.9), "loud region should read near peak after normalization");
Assert.That(loudAverage, Is.GreaterThan(silentAverage * 10),
Assert.That(loudAverage, Is.GreaterThan(silentAverage * 5),
"loud region must be significantly higher than the silent region");
}
@@ -90,6 +94,56 @@ public class RmsLoudnessAlgorithmTests
Assert.That(profile.Max(), Is.GreaterThan(0.0), "mixed-channel signal must not read as silence");
}
[Test]
public void Compute_AlternatingLoudSilentFrames_SmoothsTheSpikeyContour()
{
// A signal that alternates full-scale and silent across many short buckets would, without
// smoothing, produce a sawtooth (high, ~0, high, ~0). The ~50 ms envelope smoothing must round
// that into a contour whose neighbouring buckets differ far less than the raw alternation would.
const int frames = 44100; // 1 second
var pcm = new byte[frames * 2];
for (var i = 0; i < frames; i++)
{
// 100 Hz square: ~441 frames per half-cycle — alternating loud/silent blocks well above
// the per-bucket duration so an unsmoothed profile would alternate sharply bucket-to-bucket.
var loud = (i / 441) % 2 == 0;
WriteInt16(pcm, i * 2, loud ? short.MaxValue : (short)0);
}
// 256 buckets over 1 s = ~3.9 ms/bucket, far finer than the 50 ms time constant → heavy smoothing.
var profile = _algorithm.Compute(pcm, Channels, SampleRate, BitsPerSample, bucketCount: 256);
// Max bucket-to-bucket step in the interior should be small relative to the full [0,1] range —
// an unsmoothed alternation would show steps near 1.0 between adjacent buckets.
var maxStep = 0.0;
for (var i = 1; i < profile.Length; i++)
{
maxStep = Math.Max(maxStep, Math.Abs(profile[i] - profile[i - 1]));
}
Assert.That(maxStep, Is.LessThan(0.5),
"the ~50 ms envelope smoothing must round the loud/silent alternation into a smooth contour");
}
[Test]
public void Compute_Smoothing_PreservesPeakNormalization()
{
// Smoothing runs before peak-normalization, so the loudest bucket must still land at exactly 1.
const int frames = 8192;
var pcm = new byte[frames * 2];
for (var i = 0; i < frames; i++)
{
var amplitude = (short)(short.MaxValue * ((double)i / frames));
WriteInt16(pcm, i * 2, amplitude);
}
var profile = _algorithm.Compute(pcm, Channels, SampleRate, BitsPerSample, bucketCount: 64);
Assert.That(profile, Is.All.InRange(0.0, 1.0));
Assert.That(profile.Max(), Is.EqualTo(1.0).Within(1e-9),
"peak normalization must still put the loudest smoothed bucket at 1");
}
private static void WriteInt16(byte[] buffer, int offset, short value)
{
buffer[offset] = (byte)(value & 0xFF);