Fix volume handling of battle/silly music
This commit is contained in:
parent
bba99d4e6a
commit
86cbc5e7ba
2 changed files with 17 additions and 3 deletions
|
@ -1,5 +1,8 @@
|
||||||
# Upcoming changes
|
# 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
|
# Version NeoForge-1.25.2
|
||||||
|
|
||||||
Fix invalid use of throwable potions. (Previously, the Player would "drink"
|
Fix invalid use of throwable potions. (Previously, the Player would "drink"
|
||||||
|
|
|
@ -259,7 +259,7 @@ public class BattleMusic
|
||||||
|
|
||||||
// set volume
|
// set volume
|
||||||
FloatControl gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
|
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.loop(Clip.LOOP_CONTINUOUSLY);
|
||||||
clip.start();
|
clip.start();
|
||||||
|
@ -387,6 +387,17 @@ public class BattleMusic
|
||||||
return !sillyMusic.isEmpty();
|
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 class MP3Streamer implements Runnable
|
||||||
{
|
{
|
||||||
private AtomicBoolean keepPlaying;
|
private AtomicBoolean keepPlaying;
|
||||||
|
@ -438,7 +449,7 @@ public class BattleMusic
|
||||||
sdl.open(audioFormat);
|
sdl.open(audioFormat);
|
||||||
{
|
{
|
||||||
FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
|
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();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
@ -536,7 +547,7 @@ public class BattleMusic
|
||||||
sdl.open(audioFormat);
|
sdl.open(audioFormat);
|
||||||
{
|
{
|
||||||
FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
|
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);
|
AudioInputStream ais = reader.getAudioInputStream(oggVorbisFile);
|
||||||
|
|
Loading…
Reference in a new issue