Hey, I'm working on a sound system for a game I'm working on, and I'm using java's Audiosystem to load and play the sound files. The sounds are fine near max or loud volume, but if I lower it, to let's say, around -27 decibels, it's scratchy, bad, and distorted. Any clues on what I can do?
I'm also using the same thing to play MIDI files, and they play perfectly fine no matter the volume. It's only the .wav files that get distorted and scratchy.
I've tried changing the audio format, but defaultly, playing like this, Java is already playing it at its maximum quality.
Code
public void run()
{
try {
if (isSong)
stream = AudioSystem.getAudioInputStream(new File(location));
else
stream = AudioSystem.getAudioInputStream(soundStream);
info = new DataLine.Info(Clip.class, stream.getFormat());
sound = (Clip) AudioSystem.getLine(info);
sound.open(stream);
volumeControl = (FloatControl) sound.getControl(FloatControl.Type.MASTER_GAIN);
volumeControl.setValue(getDecibels(Configuration.volume));
if (delay > 0) {
Thread.sleep(delay);
}
sound.start();
playing = true;
while (sound.isRunning()) {
Thread.sleep(250);
}
if (!isSong) {
Thread.sleep(10000);
playing = false;
sound.close();
stream.close();
player.interrupt();
}
} catch (Exception e) {
player.interrupt();
e.printStackTrace();
}
}
public static float getDecibels(int level)
{
System.err.println("GetDecibels: Volume:" + level + ", lvl:" + (-35.0 + ((level * 4) / 10)));
return (float) -35.0 + ((level * 4) / 10);
}I'm also using the same thing to play MIDI files, and they play perfectly fine no matter the volume. It's only the .wav files that get distorted and scratchy.
I've tried changing the audio format, but defaultly, playing like this, Java is already playing it at its maximum quality.



![[Image: folks.gif]](https://gfxf.net/images/2017/04/17/folks.gif)