Skip to content

Commit

Permalink
Merge pull request #155 from LostLuma/fix-master-category-sounds-supp…
Browse files Browse the repository at this point in the history
…ression

Fix sounds without more specific categories being quieter
  • Loading branch information
LostLuma committed Jan 14, 2024
2 parents c9aa11c + f8c48de commit db94f04
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/main/java/dynamic_fps/impl/mixin/SoundEngineMixin.java
Expand Up @@ -39,11 +39,6 @@ public class SoundEngineMixin implements DuckSoundEngine {
@Final
private Map<SoundInstance, ChannelAccess.ChannelHandle> instanceToChannel;

@Shadow
private float getVolume(@Nullable SoundSource source) {
throw new RuntimeException("Failed to find SoundEngine#getVolume.");
}

@Shadow
private float calculateVolume(SoundInstance instance) {
throw new RuntimeException("Failed to find SoundEngine#calculateVolume.");
Expand All @@ -55,7 +50,8 @@ private float calculateVolume(SoundInstance instance) {
}

if (source.equals(SoundSource.MASTER)) {
this.listener.setGain(this.getVolume(source));
var volume = this.options.getSoundSourceVolume(source);
this.listener.setGain(this.adjustVolume(volume, source));
return;
}

Expand All @@ -65,7 +61,7 @@ private float calculateVolume(SoundInstance instance) {
var isMusic = source.equals(SoundSource.MUSIC) || source.equals(SoundSource.RECORDS);

this.instanceToChannel.forEach((instance, handle) -> {
float volume = this.calculateVolume((SoundInstance) instance);
float volume = this.calculateVolume(instance);

if (instance.getSource().equals(source)) {
handle.execute(channel -> {
Expand Down Expand Up @@ -105,12 +101,14 @@ private void play(SoundInstance instance, CallbackInfo callbackInfo) {
*/
@ModifyReturnValue(method = "getVolume", at = @At("RETURN"))
private float getVolume(float original, @Local @Nullable SoundSource source) {
// Note: The original doesn't consider the user's setting when the source is MASTER
// In vanilla this doesn't matter because it's never called, but we use it when setting the gain
if (SoundSource.MASTER.equals(source)) {
original = this.options.getSoundSourceVolume(source);
return this.adjustVolume(original, source);
}

private float adjustVolume(float value, @Nullable SoundSource source) {
if (source == null) {
source = SoundSource.MASTER;
}

return original * DynamicFPSMod.volumeMultiplier(source);
return value * DynamicFPSMod.volumeMultiplier(source);
}
}

0 comments on commit db94f04

Please sign in to comment.