Skip to content

Commit 618830a

Browse files
committed
Finished variable slot count
Finished Variable slot count, the first major feature unique to Resounding! This can be thought of as the reverb "resolution", higher slot counts mean smoother reverb and more detail, but at the cost of memory and performance This setting can be changed with the `reverbResolution` setting in the config Also: - updated config. This will work until i can get around to a full rewrite - rewrote `dev.thedocruby.resounding.openal.*`, since i needed to to get the variable slot count working. - fixed a critical error with material properties inherited from Sound Physics that forced all materials to use fallback values. Material properties should now be applied correctly - fixed a bug from the last commit that prevented the mod from updating properly when the config was changed - Improved the reverb quality by no longer hard-coding some things, like reverb diffusion. Most of these are also now configurable - a few more minor things
1 parent ffb5117 commit 618830a

File tree

11 files changed

+531
-434
lines changed

11 files changed

+531
-434
lines changed

src/main/java/dev/thedocruby/resounding/Resounding.java

Lines changed: 148 additions & 100 deletions
Large diffs are not rendered by default.

src/main/java/dev/thedocruby/resounding/ResoundingLog.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class ResoundingLog {
99

1010
private ResoundingLog() {}
1111

12-
public static void checkErrorLog(final String errorMessage) {
12+
public static boolean checkErrorLog(final String errorMessage) {
1313
final int error = AL10.alGetError();
1414
if (error == AL10.AL_NO_ERROR) {
15-
return;
15+
return false;
1616
}
1717

1818
String errorName;
@@ -27,6 +27,7 @@ public static void checkErrorLog(final String errorMessage) {
2727
};
2828

2929
Resounding.LOGGER.error(errorMessage + " Caused by: OpenAL \"" + errorName + "\" error.");
30+
return true;
3031
}
3132

3233
}

src/main/java/dev/thedocruby/resounding/ResoundingModClient.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,6 @@ public class ResoundingModClient implements ClientModInitializer {
1414
@Override
1515
public void onInitializeClient() {
1616
Resounding.env = EnvType.CLIENT;
17-
Resounding.blockSoundGroups = Arrays.stream(BlockSoundGroup.class.getDeclaredFields())
18-
.filter((f) -> {
19-
try {
20-
return Modifier.isStatic(f.getModifiers()) && Modifier.isPublic(f.getModifiers())
21-
&& (f.get(null) instanceof BlockSoundGroup group) && !Resounding.redirectMap.containsKey(group);
22-
} catch (IllegalAccessException e) {
23-
e.printStackTrace();
24-
}
25-
return false;
26-
})
27-
.collect(Collectors.toMap(
28-
(f) -> {
29-
try {
30-
return (BlockSoundGroup)f.get(null);
31-
} catch (IllegalAccessException | ClassCastException e) {
32-
e.printStackTrace();
33-
}
34-
return null;
35-
},
36-
(f) -> {
37-
try {
38-
return new Pair<>(f.getName(), (f.get(null) instanceof BlockSoundGroup g ? (Resounding.groupMap.containsKey(f.getName()) ? Resounding.groupMap.get(f.getName()) : g.getBreakSound().getId().getPath().split("\\.")[1] ): "not a group"));
39-
} catch (IllegalAccessException e) {
40-
e.printStackTrace();
41-
}
42-
return new Pair<>("", "");
43-
}));
44-
Resounding.groupSoundBlocks = Arrays.stream(BlockSoundGroup.class.getDeclaredFields())
45-
.filter((f) -> {
46-
try {
47-
return Modifier.isStatic(f.getModifiers()) && Modifier.isPublic(f.getModifiers())
48-
&& (f.get(null) instanceof BlockSoundGroup group) && !Resounding.redirectMap.containsKey(group);
49-
} catch (IllegalAccessException e) {
50-
e.printStackTrace();
51-
}
52-
return false;
53-
}).map((f)-> {
54-
BlockSoundGroup b;
55-
try { b = (BlockSoundGroup)f.get(null); }
56-
catch (IllegalAccessException | ClassCastException e) { e.printStackTrace(); b = null;}
57-
return new Pair<>(f.getName(),b);
58-
}).filter((f) -> f.getRight() != null)
59-
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight));
60-
6117
ConfigManager.registerAutoConfig();
6218
}
6319
}

src/main/java/dev/thedocruby/resounding/config/BlueTapePack/ConfigManager.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dev.thedocruby.resounding.config.PrecomputedConfig;
66
import dev.thedocruby.resounding.config.ResoundingConfig;
77
import dev.thedocruby.resounding.config.presets.ConfigPresets;
8+
import dev.thedocruby.resounding.openal.ResoundingEFX;
89
import me.shedaniel.autoconfig.AutoConfig;
910
import me.shedaniel.autoconfig.ConfigHolder;
1011
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
@@ -23,12 +24,13 @@ private ConfigManager() {}
2324

2425
private static ConfigHolder<ResoundingConfig> holder;
2526

27+
public static String configVersion = "1.0.0-alpha.2";
28+
2629
@Environment(EnvType.CLIENT)
2730
public static final ResoundingConfig DEFAULT = Resounding.env == EnvType.CLIENT ? new ResoundingConfig(){{
28-
Map<String, MaterialData> map =
29-
Resounding.blockSoundGroups.entrySet().stream()
30-
.collect(Collectors.toMap((e)-> e.getValue().getLeft(), (e) -> new MaterialData(e.getValue().getRight(), 0.5, 0.5)));
31-
map.putIfAbsent("DEFAULT", new MaterialData(Resounding.groupMap.get("DEFAULT"), 0.5, 0.5));
31+
Map<String, MaterialData> map = Resounding.nameToGroup.keySet().stream()
32+
.collect(Collectors.toMap(e -> e, e -> new MaterialData(e, 0.5, 0.5)));
33+
map.putIfAbsent("DEFAULT", new MaterialData("DEFAULT", 0.5, 0.5));
3234
Materials.materialProperties = map;
3335
}} : null;
3436

@@ -73,17 +75,18 @@ public static void handleUnstableConfig( ResoundingConfig c ){
7375
Resounding.LOGGER.error("Error: Config file is not from a compatible version! Resetting the config...");
7476
ConfigPresets.DEFAULT_PERFORMANCE.configChanger.accept(c);
7577
ConfigPresets.RESET_MATERIALS.configChanger.accept(c);
76-
c.version = "1.0.0-alpha.1";
78+
c.version = configVersion;
7779
}
7880

7981
public static ActionResult onSave(ResoundingConfig c) {
8082
if (Resounding.env == EnvType.CLIENT && (c.Materials.materialProperties == null || c.Materials.materialProperties.get("DEFAULT") == null)) handleBrokenMaterials(c);
8183
if (Resounding.env == EnvType.CLIENT && c.preset != ConfigPresets.LOAD_SUCCESS) c.preset.configChanger.accept(c);
82-
if (c.version == null || !Objects.equals(c.version, "1.0.0-alpha.1")) handleUnstableConfig(c);
84+
if (c.version == null || !Objects.equals(c.version, configVersion)) handleUnstableConfig(c);
8385
if (PrecomputedConfig.pC != null) PrecomputedConfig.pC.deactivate();
8486
try {PrecomputedConfig.pC = new PrecomputedConfig(c);} catch (CloneNotSupportedException e) {e.printStackTrace(); return ActionResult.FAIL;}
8587
if (Resounding.env == EnvType.CLIENT) {
8688
Resounding.updateRays();
89+
ResoundingEFX.initEAXReverb();
8790
}
8891
return ActionResult.SUCCESS;
8992
}

src/main/java/dev/thedocruby/resounding/config/PrecomputedConfig.java

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.thedocruby.resounding.config;
22

33
import dev.thedocruby.resounding.Resounding;
4-
import dev.thedocruby.resounding.ResoundingLog;
54
import it.unimi.dsi.fastutil.objects.Reference2DoubleOpenHashMap;
65
import net.fabricmc.api.EnvType;
76
import net.fabricmc.api.Environment;
@@ -11,6 +10,8 @@
1110
import java.util.*;
1211
import java.util.stream.Collectors;
1312

13+
import static dev.thedocruby.resounding.Resounding.nameToGroup;
14+
1415
/*
1516
Values, which remain constant after the config has changed
1617
Only one instance allowed
@@ -25,8 +26,13 @@ public class PrecomputedConfig {
2526
public final boolean off;
2627

2728
public final float globalReverbGain;
29+
public final double minEnergy;
30+
public final int resolution;
31+
public final double warpFactor;
2832
public final float globalReverbBrightness;
33+
public final double reverbCondensationFactor;
2934
public final double globalBlockAbsorption;
35+
public final double globalAbsorptionBrightness;
3036
public final double globalBlockReflectance;
3137
public final double globalReflRcp;
3238
public final float airAbsorption;
@@ -45,6 +51,8 @@ public class PrecomputedConfig {
4551
@Environment(EnvType.CLIENT)
4652
public double rcpTotRays;
4753
@Environment(EnvType.CLIENT)
54+
public double maxDistance;
55+
@Environment(EnvType.CLIENT)
4856
public boolean simplerSharedAirspaceSimulation;
4957

5058
@Environment(EnvType.CLIENT)
@@ -81,25 +89,22 @@ public class PrecomputedConfig {
8189
public final boolean pLog;
8290
public final boolean dRays;
8391

84-
public final int resolution;
85-
public final double warpFactor;
86-
public final double globalAbsorptionBrightness;
87-
public final double maxDecayTime;
88-
public final int traceRange;
89-
public final double minEnergy;
90-
public final double maxDistance;
91-
9292
private boolean active = true;
9393

9494
public PrecomputedConfig(ResoundingConfig c) throws CloneNotSupportedException {
9595
if (pC != null && pC.active) throw new CloneNotSupportedException("Tried creating second instance of precomputedConfig");
9696
off = !c.enabled;
9797

9898
defaultAttenuationFactor = c.General.attenuationFactor;
99-
globalReverbGain = (float) (1 / c.General.globalReverbGain);
99+
globalReverbGain = (float) c.General.globalReverbGain;
100+
minEnergy = Math.exp(-1 * c.General.globalReverbStrength);
101+
resolution = c.General.reverbResolution;
102+
warpFactor = c.General.reverbWarpFactor;
100103
globalReverbBrightness = (float) c.General.globalReverbBrightness;
104+
reverbCondensationFactor = 1 - c.General.globalReverbSmoothness;
101105
globalBlockAbsorption = c.General.globalBlockAbsorption;
102-
soundDistanceAllowance = c.General.soundDistanceAllowance;
106+
globalAbsorptionBrightness = c.General.globalAbsorptionBrightness;
107+
soundDistanceAllowance = c.General.soundDistanceAllowance; // TODO: Refactor to sound render distance
103108
globalBlockReflectance = c.General.globalBlockReflectance;
104109
globalReflRcp = 1 / globalBlockReflectance;
105110
airAbsorption = (float) c.General.airAbsorption;
@@ -113,6 +118,7 @@ public PrecomputedConfig(ResoundingConfig c) throws CloneNotSupportedException {
113118
rcpNRays = 1d / nRays;
114119
nRayBounces = c.Performance.environmentEvaluationRayBounces;
115120
rcpTotRays = rcpNRays / nRayBounces;
121+
maxDistance = c.Performance.traceRange * nRayBounces * Math.sqrt(2 * (16*16)) * 2;
116122
simplerSharedAirspaceSimulation = c.Performance.simplerSharedAirspaceSimulation;
117123

118124
blockWhiteSet = new HashSet<>(c.Materials.blockWhiteList);
@@ -133,13 +139,13 @@ public PrecomputedConfig(ResoundingConfig c) throws CloneNotSupportedException {
133139
absorptionMap = new Reference2DoubleOpenHashMap<>();
134140
final List<String> wrong = new java.util.ArrayList<>();
135141
final List<String> toRemove = new java.util.ArrayList<>();
136-
c.Materials.materialProperties.forEach((k, v) -> {
137-
BlockSoundGroup bsg = Resounding.groupSoundBlocks.get(k);
138-
if (bsg != null) {
142+
c.Materials.materialProperties.forEach((k, v) -> { //TODO Materials need to be reworked.
143+
if (nameToGroup.containsKey(k)) {
144+
BlockSoundGroup bsg = nameToGroup.get(k);
139145
reflectivityMap.put(bsg, v.reflectivity);
140-
absorptionMap.put(bsg, v.absorption * 2);
146+
absorptionMap.put(bsg, v.absorption);
141147
} else {
142-
if (!k.equals("DEFAULT") && !blockWhiteSet.contains(k)) {
148+
if (!blockWhiteSet.contains(k) && !k.equals("DEFAULT")) {
143149
wrong.add(k + " (" + v.example + ")");
144150
toRemove.add(k);
145151
}
@@ -150,28 +156,20 @@ public PrecomputedConfig(ResoundingConfig c) throws CloneNotSupportedException {
150156
toRemove.forEach(c.Materials.materialProperties::remove);
151157
}
152158

153-
recordsDisable = c.Vlads_Tweaks.recordsDisable;
154-
continuousRefreshRate = c.Vlads_Tweaks.continuousRefreshRate;
155-
maxDirectOcclusionFromBlocks = c.Vlads_Tweaks.maxDirectOcclusionFromBlocks;
156-
_9Ray = c.Vlads_Tweaks._9RayDirectOcclusion;
157-
soundDirectionEvaluation = c.Vlads_Tweaks.soundDirectionEvaluation;
158-
directRaysDirEvalMultiplier = Math.pow(c.Vlads_Tweaks.directRaysDirEvalMultiplier, 10.66);
159-
notOccludedRedirect = !c.Vlads_Tweaks.notOccludedNoRedirect;
159+
recordsDisable = c.Misc.recordsDisable;
160+
continuousRefreshRate = c.Misc.continuousRefreshRate;
161+
maxDirectOcclusionFromBlocks = c.Misc.maxDirectOcclusionFromBlocks;
162+
_9Ray = c.Misc._9RayDirectOcclusion;
163+
soundDirectionEvaluation = c.Misc.soundDirectionEvaluation; // TODO: DirEval
164+
directRaysDirEvalMultiplier = Math.pow(c.Misc.directRaysDirEvalMultiplier, 10.66); // TODO: DirEval
165+
notOccludedRedirect = !c.Misc.notOccludedNoRedirect;
160166
}
161167

162-
dLog = c.Misc.debugLogging;
163-
oLog = c.Misc.occlusionLogging;
164-
eLog = c.Misc.environmentLogging;
165-
pLog = c.Misc.performanceLogging;
166-
dRays = c.Misc.raytraceParticles;
167-
168-
resolution = 4;
169-
warpFactor = 4;
170-
globalAbsorptionBrightness = 1d / 1d;
171-
maxDecayTime = Math.min(20, 4.142);
172-
traceRange = 256;
173-
minEnergy = Math.exp(-1 * c.Misc.minEnergy);
174-
maxDistance = traceRange * nRayBounces;
168+
dLog = c.Debug.debugLogging;
169+
oLog = c.Debug.occlusionLogging;
170+
eLog = c.Debug.environmentLogging;
171+
pLog = c.Debug.performanceLogging;
172+
dRays = c.Debug.raytraceParticles;
175173
}
176174

177175
public void deactivate(){ active = false;}

src/main/java/dev/thedocruby/resounding/config/ResoundingConfig.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.List;
1313
import java.util.Map;
1414

15+
import static dev.thedocruby.resounding.config.BlueTapePack.ConfigManager.configVersion;
16+
1517
@SuppressWarnings("CanBeFinal")
1618
@Config(name = "resounding")
1719
@Config.Gui.Background("minecraft:textures/block/note_block.png")
@@ -32,20 +34,30 @@ public class ResoundingConfig implements ConfigData {
3234
public Materials Materials = new Materials();
3335

3436
@ConfigEntry.Gui.CollapsibleObject
35-
public Vlads_Tweaks Vlads_Tweaks = new Vlads_Tweaks();
37+
public ResoundingConfig.Misc Misc = new Misc();
3638

3739
@ConfigEntry.Gui.CollapsibleObject
38-
public Misc Misc = new Misc();
40+
public Debug Debug = new Debug();
3941

4042
public static class General{
43+
@ConfigEntry.Gui.Excluded // TODO: remove this
4144
@Comment("Affects how quiet a sound gets based on distance. Lower values mean distant sounds are louder.\n1.0 is the physically correct value.\n0.2 - 1.0 or just don't set it to 0")
4245
public double attenuationFactor = 1.0;
46+
@ConfigEntry.Gui.Excluded // TODO: remove this
4347
@Comment("The global volume of simulated reverberations.\n0.1 - 2.0")
4448
public double globalReverbGain = 1.0;
49+
@ConfigEntry.BoundedDiscrete(max = 32, min = 4)
50+
public int reverbResolution = 12;
51+
public double globalReverbStrength = 5.0;
52+
public double reverbWarpFactor = 4;
53+
public double globalReverbSmoothness = 0.62;
4554
@Comment("The brightness of reverberation.\nHigher values result in more high frequencies in reverberation.\nLower values give a more muffled sound to the reverb.\n0.1 - 2.0")
4655
public double globalReverbBrightness = 1.0;
56+
@ConfigEntry.Gui.Excluded // TODO: Occlusion
4757
@Comment("The global amount of sound that will be absorbed when traveling through blocks.\n 0.1 - 4.0")
4858
public double globalBlockAbsorption = 1.0;
59+
@ConfigEntry.Gui.Excluded // TODO: Occlusion
60+
public double globalAbsorptionBrightness = 1.0;
4961
@Comment("The global amount of sound reflectance energy of all blocks.\nLower values result in more conservative reverb simulation with shorter reverb tails.\nHigher values result in more generous reverb simulation with higher reverb tails.\n0.1 - 4.0")
5062
public double globalBlockReflectance = 1.0;
5163
@Comment("Minecraft won't allow sounds to play past a certain distance;\nResounding makes that configurable by multiplying this parameter by the default distance.\nValues too high can cause polyphony issues.\n1.0 - 6.0")
@@ -62,6 +74,7 @@ public static class General{
6274

6375
public static class Performance{
6476
@Environment(EnvType.CLIENT)
77+
@ConfigEntry.Gui.Excluded // TODO: Occlusion
6578
@Comment("If true, rain sound sources won't trace for sound occlusion.\nThis can help performance during rain.")
6679
public boolean skipRainOcclusionTracing = true;
6780
@Environment(EnvType.CLIENT)
@@ -73,6 +86,9 @@ public static class Performance{
7386
@ConfigEntry.BoundedDiscrete(max = 32, min = 2)
7487
public int environmentEvaluationRayBounces = 12;
7588
@Environment(EnvType.CLIENT)
89+
public double traceRange = 6;
90+
@Environment(EnvType.CLIENT)
91+
@ConfigEntry.Gui.Excluded // TODO: Remove
7692
@Comment("If true, enables a simpler technique for determining when the player and a sound source share airspace.\nMight sometimes miss recognizing shared airspace, but it's faster to calculate.")
7793
public boolean simplerSharedAirspaceSimulation = false;
7894
}
@@ -87,33 +103,39 @@ public static class Materials {
87103
public List<String> blockWhiteList = new ArrayList<>();
88104
}
89105

90-
public static class Vlads_Tweaks {
106+
public static class Misc {
91107
@Environment(EnvType.CLIENT)
92108
@Comment("Disable occlusion of jukeboxes and note blocks.\nUseful if you have an audio signaling system that you need to hear clearly")
93109
public boolean recordsDisable = false;
94110
@Environment(EnvType.CLIENT)
95111
@Comment("Continuous sources reverb refresh interval (ticks per refresh or 1/(20Hz))")
96112
public int continuousRefreshRate = 4;
97113
@Environment(EnvType.CLIENT)
114+
@ConfigEntry.Gui.Excluded // TODO: Occlusion
98115
@Comment("The amount at which occlusion is capped. 10 * block_occlusion is the theoretical limit")
99116
public double maxDirectOcclusionFromBlocks = 10;
100117
@Environment(EnvType.CLIENT)
118+
@ConfigEntry.Gui.Excluded // TODO: Occlusion
101119
@Comment("Calculate direct occlusion as the minimum of 9 rays from vertices of a block")
102120
public boolean _9RayDirectOcclusion = true;
103121
@Environment(EnvType.CLIENT)
122+
@ConfigEntry.Gui.Excluded // TODO: DirEval
104123
@Comment("Whether to try calculating where the sound should come from based on reflections")
105124
public boolean soundDirectionEvaluation = true;
106125
@Environment(EnvType.CLIENT)
126+
@ConfigEntry.Gui.Excluded // TODO: DirEval
107127
@Comment("How much the sound direction depends on reflected sounds.\nRequires \"Re-calculate sound direction\" to be enabled.\n0.0 is no reflected sounds, 1.0 is 100% reflected sounds.\n0.5 is approximately physically accurate.")
108128
public double directRaysDirEvalMultiplier = 0.5;
109129
@Environment(EnvType.CLIENT)
130+
@ConfigEntry.Gui.Excluded // TODO: DirEval, Occlusion
110131
@Comment("Skip redirecting non-occluded sounds (the ones you can see directly).\nCan be inaccurate in some situations, especially when \"Re-calculate sound direction\" is enabled.")
111132
public boolean notOccludedNoRedirect = false;
112133
}
113134

114-
public static class Misc {
135+
public static class Debug {
115136
@Comment("General debug logging")
116137
public boolean debugLogging = false;
138+
@ConfigEntry.Gui.Excluded // TODO: Occlusion
117139
@Comment("Occlusion tracing information logging")
118140
public boolean occlusionLogging = false;
119141
@Comment("Environment evaluation information logging")
@@ -122,14 +144,13 @@ public static class Misc {
122144
public boolean performanceLogging = false;
123145
@Comment("Particles on traced blocks (structure_void is a block)")
124146
public boolean raytraceParticles = false;
125-
public double minEnergy = 5;
126147
}
127148

128149
// TODO: change preset back to "Balanced" when performance permits
129-
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.DROPDOWN)
150+
@ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON)
130151
@Comment("Soft presets. Some of these can be applied one after another to stack effects onto a base profile.")
131152
public ConfigPresets preset = ConfigPresets.DEFAULT_PERFORMANCE;
132153

133154
@ConfigEntry.Gui.Excluded
134-
public String version = "1.0.0-alpha.1";
155+
public String version = configVersion;
135156
}

0 commit comments

Comments
 (0)