diff --git a/api/common/src/main/java/su/plo/voice/api/util/AudioUtil.java b/api/common/src/main/java/su/plo/voice/api/util/AudioUtil.java index c4c917821..9eb72461b 100644 --- a/api/common/src/main/java/su/plo/voice/api/util/AudioUtil.java +++ b/api/common/src/main/java/su/plo/voice/api/util/AudioUtil.java @@ -60,7 +60,15 @@ public static short[] floatsToShorts(float[] floats) { short[] shorts = new short[floats.length]; for(int i = 0; i < floats.length; i++) { - shorts[i] = Float.valueOf(floats[i]).shortValue(); + shorts[i] = Float.valueOf( + Math.min( // Clamp to prevent overdrive causing clipping (https://github.com/remjey/mumble/commit/f16b47c81aceaf0c8704b355d9316bf685cb3704) + Short.MAX_VALUE, + Math.max( + Short.MIN_VALUE, + floats[i] + ) + ) + ).shortValue(); } return shorts;