From 212a39507d5fd3cfbc0b0a62a18d723a4a49fe70 Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Sat, 1 Jul 2017 23:00:07 -0400 Subject: [PATCH] Clamp volume levels for hit sounds. (fixes #306) Signed-off-by: Jeffrey Han --- src/itdelatrisu/opsu/audio/MultiClip.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/itdelatrisu/opsu/audio/MultiClip.java b/src/itdelatrisu/opsu/audio/MultiClip.java index cf24a1d9..0afcc8a8 100644 --- a/src/itdelatrisu/opsu/audio/MultiClip.java +++ b/src/itdelatrisu/opsu/audio/MultiClip.java @@ -19,6 +19,7 @@ package itdelatrisu.opsu.audio; import itdelatrisu.opsu.ErrorHandler; +import itdelatrisu.opsu.Utils; import java.io.IOException; import java.util.Iterator; @@ -140,13 +141,13 @@ public void start(float volume, LineListener listener) throws LineUnavailableExc // set volume FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN); float dB = (float) (Math.log(volume) / Math.log(10.0) * 20.0); - gainControl.setValue(dB); + gainControl.setValue(Utils.clamp(dB, gainControl.getMinimum(), gainControl.getMaximum())); } else if (clip.isControlSupported(FloatControl.Type.VOLUME)) { // The docs don't mention what unit "volume" is supposed to be, // but for PulseAudio it seems to be amplitude FloatControl volumeControl = (FloatControl) clip.getControl(FloatControl.Type.VOLUME); float amplitude = (float) Math.sqrt(volume) * volumeControl.getMaximum(); - volumeControl.setValue(amplitude); + volumeControl.setValue(Utils.clamp(amplitude, volumeControl.getMinimum(), volumeControl.getMaximum())); } if (listener != null)