Fix volume handling of battle/silly music

This commit is contained in:
Stephen Seo 2024-01-31 11:57:52 +09:00
parent bba99d4e6a
commit 86cbc5e7ba
2 changed files with 17 additions and 3 deletions

View file

@ -1,5 +1,8 @@
# Upcoming changes
Fix volume handling of battle/silly music. (Previous implementation did not
properly reduce volume based on Minecraft's "music volume" setting.)
# Version NeoForge-1.25.2
Fix invalid use of throwable potions. (Previously, the Player would "drink"

View file

@ -259,7 +259,7 @@ public class BattleMusic
// set volume
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
gainControl.setValue(volume * 20.0f - 20.0f); // in decibels
gainControl.setValue(BattleMusic.percentageToDecibels(volume));
clip.loop(Clip.LOOP_CONTINUOUSLY);
clip.start();
@ -387,6 +387,17 @@ public class BattleMusic
return !sillyMusic.isEmpty();
}
/// Percentage must be between 0 and 1.
public static float percentageToDecibels(float percentage) {
if (percentage > 1.0F) {
return 0.0F;
} else if (percentage <= 0.0F) {
return Float.NEGATIVE_INFINITY;
} else {
return (float) (Math.log10(percentage) * 20.0);
}
}
private class MP3Streamer implements Runnable
{
private AtomicBoolean keepPlaying;
@ -438,7 +449,7 @@ public class BattleMusic
sdl.open(audioFormat);
{
FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
volumeControl.setValue(volume * 20.0f - 20.0f); // in decibels
volumeControl.setValue(BattleMusic.percentageToDecibels(volume));
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -536,7 +547,7 @@ public class BattleMusic
sdl.open(audioFormat);
{
FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
volumeControl.setValue(volume * 20.0f - 20.0f); // in decibels
volumeControl.setValue(BattleMusic.percentageToDecibels(volume));
}
AudioInputStream ais = reader.getAudioInputStream(oggVorbisFile);