Cubic percent <-> linear channelVolumes conversions (pavucontrol scale, up to 150%), dB formatting, balance-preserving linked slider, a reducer applying WirePlumber node/link/default events and per-tab view rows, all covered by moon tests that run on any target. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.3 KiB
MoonBit
71 lines
2.3 KiB
MoonBit
///|
|
|
fn approx(a : Double, b : Double) -> Bool {
|
|
(a - b).abs() < 1.0e-9
|
|
}
|
|
|
|
///|
|
|
test "linear <-> percent uses the cubic scale" {
|
|
assert_true(approx(@model.linear_to_percent(1.0), 100.0))
|
|
assert_true(approx(@model.linear_to_percent(0.125), 50.0))
|
|
assert_true(approx(@model.linear_to_percent(0.0), 0.0))
|
|
assert_true(approx(@model.linear_to_percent(-1.0), 0.0))
|
|
assert_true(approx(@model.percent_to_linear(50.0), 0.125))
|
|
assert_true(approx(@model.percent_to_linear(150.0), 3.375))
|
|
}
|
|
|
|
///|
|
|
test "percent_to_linear clamps to 0..150" {
|
|
assert_true(approx(@model.percent_to_linear(200.0), 3.375))
|
|
assert_true(approx(@model.percent_to_linear(-5.0), 0.0))
|
|
assert_true(approx(@model.percent_to_linear(0.0 / 0.0), 0.0))
|
|
}
|
|
|
|
///|
|
|
test "round trip" {
|
|
for p in [0.0, 1.0, 33.3, 64.0, 100.0, 123.4, 150.0] {
|
|
assert_true(
|
|
(@model.linear_to_percent(@model.percent_to_linear(p)) - p).abs() < 1.0e-9,
|
|
)
|
|
}
|
|
}
|
|
|
|
///|
|
|
test "decibels" {
|
|
assert_eq(@model.linear_to_db(0.0), None)
|
|
assert_true(approx(@model.linear_to_db(1.0).unwrap(), 0.0))
|
|
assert_eq(@model.format_db(1.0), "0.00 dB")
|
|
assert_eq(@model.format_db(0.0), "-∞ dB")
|
|
// 50% cubic = 0.125 linear = -18.06 dB
|
|
assert_eq(@model.format_db(0.125), "-18.06 dB")
|
|
assert_eq(@model.format_db(3.375), "10.57 dB")
|
|
}
|
|
|
|
///|
|
|
test "format percent rounds" {
|
|
assert_eq(@model.format_percent(74.5), "75%")
|
|
assert_eq(@model.format_percent(74.4), "74%")
|
|
assert_eq(@model.format_percent(0.0), "0%")
|
|
assert_eq(@model.format_volume([0.125, 0.0]), "50% (-18.06 dB)")
|
|
}
|
|
|
|
///|
|
|
test "linked slider follows the loudest channel and keeps balance" {
|
|
assert_true(approx(@model.linked_percent([0.125, 1.0]), 100.0))
|
|
assert_true(approx(@model.linked_percent([]), 0.0))
|
|
let scaled = @model.scale_linked([0.5, 1.0], 50.0)
|
|
assert_true(approx(scaled[0], 0.0625))
|
|
assert_true(approx(scaled[1], 0.125))
|
|
// all silent: every channel gets the target
|
|
let from_zero = @model.scale_linked([0.0, 0.0], 100.0)
|
|
assert_true(approx(from_zero[0], 1.0) && approx(from_zero[1], 1.0))
|
|
// no channel info: a single value
|
|
assert_eq(@model.scale_linked([], 100.0).length(), 1)
|
|
}
|
|
|
|
///|
|
|
test "echo suppression window" {
|
|
assert_false(@model.should_apply_remote(1_000_000L, 1_100_000L))
|
|
assert_true(@model.should_apply_remote(1_000_000L, 1_300_000L))
|
|
assert_true(@model.should_apply_remote(0L, 1_000_000L, window_us=0L))
|
|
}
|