New feature: speed reactive audio (Settings > Misc). Pick an MP3 and a dedicated volume; the always-on trip tracker shifts the clip's pitch and playback rate from min to max speed while you drive. Loop-with-speed is the default; a toggle enables layered overlap so speed changes never cut the clip off. Build script already compiles every module included in this commit.
40 lines
2.1 KiB
Java
40 lines
2.1 KiB
Java
import cloud.molberg.mgutility.SpeedAudioCurve;
|
|
|
|
public final class SpeedAudioCurveTest {
|
|
private static void check(boolean condition, String message) {
|
|
if (!condition) throw new AssertionError(message);
|
|
}
|
|
|
|
private static void close(float a, float b, String message) {
|
|
if (Math.abs(a - b) > 0.0005f) throw new AssertionError(message + " (" + a + " vs " + b + ")");
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
// progress: at min = 0, at max = 1, in-between linear.
|
|
close(SpeedAudioCurve.progress(0f, 5f, 120f), 0f, "progress at min");
|
|
close(SpeedAudioCurve.progress(5f, 5f, 120f), 0f, "progress at exact min");
|
|
close(SpeedAudioCurve.progress(62.5f, 5f, 120f), 0.5f, "progress midway");
|
|
close(SpeedAudioCurve.progress(120f, 5f, 120f), 1f, "progress at max");
|
|
close(SpeedAudioCurve.progress(400f, 5f, 120f), 1f, "progress above max clamps");
|
|
close(SpeedAudioCurve.progress(-50f, 5f, 120f), 0f, "progress below min clamps");
|
|
check(SpeedAudioCurve.progress(Float.NaN, 5f, 120f) == 0f, "progress NaN -> 0");
|
|
|
|
// value: lerp between min and max by progress.
|
|
close(SpeedAudioCurve.value(0f, 0.5f, 2.0f), 0.5f, "value at 0");
|
|
close(SpeedAudioCurve.value(1f, 0.5f, 2.0f), 2.0f, "value at 1");
|
|
close(SpeedAudioCurve.value(0.5f, 0.5f, 2.0f), 1.25f, "value midway");
|
|
close(SpeedAudioCurve.value(2f, 0.5f, 2.0f), 2.0f, "value over 1 clamps");
|
|
close(SpeedAudioCurve.value(-1f, 0.5f, 2.0f), 0.5f, "value under 0 clamps");
|
|
|
|
// End-to-end: typical driving speeds yield a believable progression.
|
|
close(SpeedAudioCurve.value(SpeedAudioCurve.progress(60f, 5f, 120f), 0.5f, 2.0f), 1.2174f, "end-to-end 60");
|
|
close(SpeedAudioCurve.value(SpeedAudioCurve.progress(20f, 5f, 120f), 0.5f, 2.0f), 0.6957f, "end-to-end 20");
|
|
|
|
// Equal bounds should short-circuit to max-when-reached / zero-otherwise.
|
|
close(SpeedAudioCurve.progress(50f, 50f, 50f), 1f, "equal bounds >=");
|
|
close(SpeedAudioCurve.progress(40f, 50f, 50f), 0f, "equal bounds <");
|
|
|
|
System.out.println("SpeedAudioCurveTest: OK");
|
|
}
|
|
}
|