Unit 1 of the sound-bar refactor. The model stores linear gain; the dock shows decibels, because "−6 dB" is readable and "0.50" is not. `Helpers/GainDb` owns the mapping: - 0 dB = unity (the old 1.0), range −60 dB (true silence, exactly 0 gain) … +6 dB. - Labels for the fader readout: "−∞", "-6.0", "+1.5". - `MonoFold(L,R)` = (L+R)/2, the accessible downmix: hard-panned content becomes audible on both sides at half amplitude instead of absent from one. Creator context: profoundly deaf on the right, so single-sided audio is inaudible, not merely annoying. Guard: GainDbTests pins unity, the −6 dB half, the exact-zero floor, the +6 dB ceiling, a round-trip across the range, the labels, and the fold arithmetic (a right-only 0.5 arrives on the left at 0.25).
44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using Xunit;
|
||
using ytLive.Helpers;
|
||
|
||
namespace ytLive.Tests;
|
||
|
||
/// <summary>The dock's faders speak dB while the model stores linear gain, so the mapping is load
|
||
/// bearing: get it wrong and every reported level is wrong by a constant. Unity, the floor and
|
||
/// the +6 dB ceiling are the three values a creator actually checks.</summary>
|
||
public class GainDbTests
|
||
{
|
||
[Fact]
|
||
public void Db_and_linear_gain_round_trip_and_the_ends_are_honest()
|
||
{
|
||
// Unity is the anchor: 1.0 ↔ 0 dB, and the default mic volume reads −1.9 dB.
|
||
Assert.Equal(0, GainDb.ToDb(1.0), 6);
|
||
Assert.Equal(1.0, GainDb.FromDb(0), 6);
|
||
Assert.Equal(-1.9, GainDb.ToDb(0.8), 1);
|
||
|
||
// Halving is −6 dB — the number a creator reads as "half".
|
||
Assert.Equal(-6.02, GainDb.ToDb(0.5), 1);
|
||
|
||
// The floor is TRUE silence: no residue left at the bottom of the fader.
|
||
Assert.Equal(0.0, GainDb.FromDb(GainDb.FloorDb));
|
||
Assert.Equal(0.0, GainDb.FromDb(-999));
|
||
|
||
// Ceiling: +6 dB is twice the amplitude and nothing beyond it.
|
||
Assert.Equal(2.0, GainDb.FromDb(6), 2);
|
||
Assert.Equal(6, GainDb.ToDb(GainDb.FromDb(99)), 6);
|
||
|
||
// Round-trip across the usable range.
|
||
foreach (var db in new[] { -60.0, -40, -20, -12, -6, -3, 0, 3, 6 })
|
||
Assert.Equal(db, GainDb.ToDb(GainDb.FromDb(db)), 6);
|
||
|
||
// Labels are what the creator reads.
|
||
Assert.Equal("−∞", GainDb.Label(GainDb.FloorDb));
|
||
Assert.Equal("-6.0", GainDb.Label(-6));
|
||
Assert.Equal("+1.5", GainDb.Label(1.5));
|
||
|
||
// The mono fold: a hard-right signal becomes audible on the left at half amplitude.
|
||
Assert.Equal(0.25f, GainDb.MonoFold(0f, 0.5f));
|
||
Assert.Equal(0.5f, GainDb.MonoFold(0.5f, 0.5f));
|
||
}
|
||
}
|