import cloud.molberg.mgutility.LiquidSoundBalanceCurve; import cloud.molberg.mgutility.LiquidSoundBalanceMotion; public final class LiquidSoundBalanceCurveTest { private static void check(boolean ok, String message) { if (!ok) throw new AssertionError(message); } private static void advance(LiquidSoundBalanceMotion motion, float acceleration, float speed, float steering, boolean sway, boolean bounce, int anchorX, int anchorY, int samples) { for (int index = 0; index < samples; index++) { motion.update(acceleration, speed, steering, 1f, 100, sway, false, bounce, anchorX, anchorY, 0.1f); check(motion.balance(anchorX) >= 0 && motion.balance(anchorX) <= 14, "X stays in OEM range"); check(motion.fader(anchorY) >= 0 && motion.fader(anchorY) <= 14, "Y stays in OEM range"); } } public static void main(String[] args) { check(LiquidSoundBalanceCurve.parseSteering("-520.0000") == -520f, "right lock property parses"); check(LiquidSoundBalanceCurve.parseSteering("+520.0000") == 520f, "left lock property parses"); check(LiquidSoundBalanceCurve.parseSteering("0.0000") == 0f, "center property parses"); for (String invalid : new String[] {null, "", "NaN", "Infinity", "-521", "521", "unavailable"}) { check(Float.isNaN(LiquidSoundBalanceCurve.parseSteering(invalid)), "invalid property fails neutral"); } check(LiquidSoundBalanceCurve.volumeMultiplier(7, 7, 7, 7, true, 100) == 1f, "no volume boost at center"); check(LiquidSoundBalanceCurve.volumeMultiplier(3, 11, 3, 11, true, 100) == 1f, "no boost at custom anchor"); check(LiquidSoundBalanceCurve.volumeMultiplier(7, 14, 7, 7, true, 50) == 1.5f, "rear endpoint gets selected boost"); check(LiquidSoundBalanceCurve.volumeMultiplier(7, 0, 7, 7, true, 50) == 1.5f, "front endpoint gets selected boost"); check(LiquidSoundBalanceCurve.volumeMultiplier(0, 0, 7, 7, true, 50) == 1.5f, "corners never exceed selected boost"); check(LiquidSoundBalanceCurve.volumeMultiplier(8, 8, 7, 7, true, 50) > LiquidSoundBalanceCurve.volumeMultiplier(8, 7, 7, 7, true, 50), "diagonal distance increases compensation"); check(LiquidSoundBalanceCurve.volumeMultiplier(0, 14, 7, 7, false, 100) == 1f, "disabled compensation is neutral"); check(LiquidSoundBalanceCurve.volumeMultiplier(-1, 14, 7, 7, true, 100) == 1f, "unknown actual position cannot boost"); check(LiquidSoundBalanceCurve.volumeMultiplier(0, 14, 7, 7, true, 0) == 1f, "zero slider cannot boost"); for (int step = 0; step < 7; step++) { check(LiquidSoundBalanceCurve.volumeMultiplier(7, 7 + step, 7, 7, true, 50) < LiquidSoundBalanceCurve.volumeMultiplier(7, 8 + step, 7, 7, true, 50), "boost grows with distance"); } check(LiquidSoundBalanceCurve.targetFader(0f, 1f, 100) == 0, "stationary has no longitudinal force"); check(LiquidSoundBalanceCurve.targetFader(0.2f, 1f, 100) == 0, "small fluctuations ignored"); check(LiquidSoundBalanceCurve.targetFader(1f, 1f, 100) > 0, "acceleration moves rearward"); check(LiquidSoundBalanceCurve.targetFader(-1f, 1f, 100) < 0, "braking moves forward"); check(LiquidSoundBalanceCurve.targetFader(20f, 1f, 100) == 7, "full movement limited to seven steps"); check(LiquidSoundBalanceCurve.targetFader(20f, 1f, 0) == 0, "zero power disables movement"); check(LiquidSoundBalanceCurve.targetFader(Float.NaN, 1f, 100) == 0, "invalid acceleration ignored"); check(LiquidSoundBalanceCurve.positionForOffset(0) == 7, "default OEM center is seven"); check(LiquidSoundBalanceCurve.positionForOffset(3, 0) == 3, "custom anchor is preserved"); check(LiquidSoundBalanceCurve.positionForOffset(3, -7) == 0, "custom anchor clips at left edge"); check(LiquidSoundBalanceCurve.positionForOffset(12, 7) == 14, "custom anchor clips at right edge"); check(LiquidSoundBalanceCurve.positionForOffset(Integer.MIN_VALUE) == 0, "negative overflow avoided"); check(LiquidSoundBalanceCurve.positionForOffset(Integer.MAX_VALUE) == 14, "positive overflow avoided"); float gentle = LiquidSoundBalanceCurve.lateralAcceleration(30f, 10f, false); float faster = LiquidSoundBalanceCurve.lateralAcceleration(60f, 10f, false); check(gentle > 0f, "positive-left steering pushes audio right"); check(Math.abs(faster - 4f * gentle) < 0.001f, "cornering force scales with speed squared"); check(LiquidSoundBalanceCurve.lateralAcceleration(30f, 20f, false) > gentle, "tighter turn increases force"); check(LiquidSoundBalanceCurve.lateralAcceleration(30f, -10f, false) == -gentle, "right turn pushes audio left"); check(LiquidSoundBalanceCurve.lateralAcceleration(30f, 10f, true) == -gentle, "direction calibration reverses sign"); check(LiquidSoundBalanceCurve.lateralAcceleration(0f, 500f, false) == 0f, "parked steering causes no sway"); check(LiquidSoundBalanceCurve.lateralAcceleration(90f, 0f, false) == 0f, "straight cruising causes no sway"); check(LiquidSoundBalanceCurve.lateralAcceleration(90f, Float.NaN, false) == 0f, "missing steering is neutral"); check(LiquidSoundBalanceCurve.lateralAcceleration(90f, 65535f, false) == 0f, "invalid steering sentinel ignored"); check(LiquidSoundBalanceCurve.lateralAcceleration(Float.POSITIVE_INFINITY, 20f, false) == 0f, "invalid speed ignored"); LiquidSoundBalanceMotion motion = new LiquidSoundBalanceMotion(); advance(motion, 0f, 60f, 30f, true, true, 7, 7, 40); check(motion.balance(7) > 7, "steady left turn maintains outward X displacement without accelerating"); check(motion.fader(7) == 7, "cornering does not move Y"); int sustained = motion.balance(7); advance(motion, 0f, 60f, 30f, true, true, 7, 7, 40); check(motion.balance(7) == sustained, "steady turn does not oscillate on a timer"); advance(motion, 0f, 60f, -30f, true, true, 7, 7, 40); check(motion.balance(7) < 7, "opposite turn changes outward direction"); advance(motion, 0f, 60f, Float.NaN, true, true, 7, 7, 1); check(motion.balance(7) == 7, "lost steering immediately locks X to anchor"); advance(motion, 5f, 60f, 0f, true, true, 7, 7, 40); check(motion.balance(7) == 7 && motion.fader(7) > 7, "straight acceleration only moves Y"); advance(motion, -5f, 60f, 30f, false, true, 3, 10, 40); check(motion.balance(3) == 3 && motion.fader(10) < 10, "disabled sway locks custom X while braking moves Y"); for (int anchor = 0; anchor <= 14; anchor++) { for (boolean bounce : new boolean[] {false, true}) { motion.reset(); advance(motion, 20f, 100f, 500f, true, bounce, anchor, 14 - anchor, 30); advance(motion, -20f, 100f, -500f, true, bounce, anchor, 14 - anchor, 30); advance(motion, 0f, 0f, 0f, true, bounce, anchor, 14 - anchor, 100); check(motion.balance(anchor) == anchor, "X settles exactly at every custom anchor"); check(motion.fader(14 - anchor) == 14 - anchor, "Y settles exactly at every custom anchor"); } } motion.reset(); advance(motion, 4f, 60f, 30f, true, true, 4, 9, 20); motion.update(4f, 60f, 30f, 1f, 0, true, false, true, 4, 9, 0.1f); check(motion.balance(4) == 4 && motion.fader(9) == 9, "zero power resets both axes immediately"); advance(motion, 4f, 60f, 30f, true, true, 4, 9, 20); motion.update(4f, 60f, 30f, 1f, 100, true, false, true, 4, 9, 5f); check(motion.balance(4) == 4 && motion.fader(9) == 9, "long polling gap clears stale momentum"); for (boolean bounce : new boolean[] {false, true}) { motion.reset(); advance(motion, 2f, 60f, 0f, false, bounce, 7, 7, 50); boolean crossedAnchor = false; for (int index = 0; index < 80; index++) { advance(motion, 0f, 60f, 0f, false, bounce, 7, 7, 1); crossedAnchor |= motion.fader(7) < 7; } check(crossedAnchor == bounce, "only bounce mode rebounds across the anchor"); } motion.reset(); for (int index = 0; index < 100; index++) { motion.update(20f, 100f, 520f, 1f, 30, true, false, true, 3, 3, 0.1f); check(Math.abs(motion.balance(3) - 3) <= 2 && Math.abs(motion.fader(3) - 3) <= 2, "spring overshoot respects the selected power limit"); } System.out.println("LiquidSoundBalanceCurveTest: OK"); } }