22 lines
1.3 KiB
Java
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");
|
|
}
|
|
}
|