Files
mg-utility/tests/AudioLevelTest.java
bonzi dcbd41d37b feat: automatic settings/trip backup that survives uninstall, mic and camera tests
Dev build 0.4.1.24. Also includes previously uncommitted work in the tree.
2026-11-03 18:49:53 +00:00

22 lines
1.3 KiB
Java

package cloud.molberg.mgutility;
public final class AudioLevelTest {
static void check(boolean ok, String what) { if (!ok) throw new AssertionError(what); System.out.println("ok - " + what); }
public static void main(String[] args) {
short[] silence = new short[1000];
check(AudioLevel.rms(silence, 1000) == 0, "silence rms is zero");
check(AudioLevel.verdict(AudioLevel.peak(silence, 1000)).startsWith("SILENT"), "silence flagged");
short[] loud = new short[1000]; for (int i = 0; i < loud.length; i++) loud[i] = (short) (i % 2 == 0 ? 16384 : -16384);
check(Math.abs(AudioLevel.rms(loud, 1000) - 0.5) < 1e-6, "square wave rms is half scale");
check(Math.abs(AudioLevel.peak(loud, 1000) - 0.5) < 1e-6, "peak is half scale");
check(Math.abs(AudioLevel.dbfs(0.5) + 6.0206) < 1e-3, "-6 dBFS at half scale");
check(AudioLevel.dbfs(0) == -100.0, "dbfs floor");
check(AudioLevel.verdict(0.5).startsWith("OK"), "loud is OK");
short[] faint = new short[100]; faint[3] = 200;
check(AudioLevel.verdict(AudioLevel.peak(faint, 100)).startsWith("VERY QUIET"), "faint flagged quiet");
short[] neg = { Short.MIN_VALUE };
check(AudioLevel.peak(neg, 1) == 1.0, "min value peak does not overflow");
check(AudioLevel.rms(loud, 0) == 0, "zero count safe");
}
}