Turns out that I had to set the AL_ROLLOFF_FACTOR to get the effect I wanted, which is very close range attenuation of sound. At close distances the rolloff factor dominates the equation for sound attenuation, given the current default sound attenuation model which JME uses.
I had to do something like this:
org.lwjgl.openal.AL10.alSourcef(1, org.lwjgl.openal.AL10.AL_ROLLOFF_FACTOR, 5f);
Since jMonkeyEngine3 does not currently expose the AL_ROLLOFF_FACTOR parameter, I propose to add it to the audio system.
It involves three patches to jme3
Index: src/core/com/jme3/audio/AudioParam.java
===================================================================
--- src/core/com/jme3/audio/AudioParam.java (revision 8529)
+++ src/core/com/jme3/audio/AudioParam.java (working copy)
@@ -15,5 +15,6 @@
MaxDistance,
DryFilter,
ReverbFilter,
+ RolloffFactor,
ReverbEnabled;
}
Index: src/core/com/jme3/audio/AudioNode.java
===================================================================
--- src/core/com/jme3/audio/AudioNode.java (revision 8529)
+++ src/core/com/jme3/audio/AudioNode.java (working copy)
@@ -72,6 +72,7 @@
protected boolean reverbEnabled = true;
protected float maxDistance = 200; // 200 meters
protected float refDistance = 10; // 10 meters
+ protected float rolloffFactor = 1f; // unitless
protected Filter reverbFilter;
private boolean directional = false;
protected Vector3f direction = new Vector3f(0, 0, 1);
@@ -398,7 +399,38 @@
getRenderer().updateSourceParam(this, AudioParam.Pitch);
}
+
/**
+ * @return The rolloff factor of the audio node.
+ *
+ * @see AudioNode#setRolloffFactor
+ */
+ public float getRolloffFactor(){
+ return rolloffFactor;
+ }
+
+
+ /**
+ * Set the rolloff factor for this node. Larger values cause the
+ * node's sound to attenuate more severely with distance. Setting the
+ * rolloff factor to zero prevents all attenuation.
+ *
+ * @param rolloffFactor the rolloffFactor to set
+ * @throws IllegalArgumentException if rolloffFactor is negative.
+ *
+ */
+ public void setRolloffFactor(float rolloffFactor){
+ if (rolloffFactor < 0){
+ throw new IllegalArgumentException("rolloffFactor cannot be negative");
+ }
+ this.rolloffFactor = rolloffFactor;
+ if (channel >= 0){
+ getRenderer().updateSourceParam(this, AudioParam.RolloffFactor);
+ }
+ }
+
+
+ /**
* @return The volume of this audio node.
*
* @see AudioNode#setVolume(float)
@@ -457,7 +489,7 @@
/**
* Set the velocity of the audio node. The velocity is expected
- * to be in meters. Does nothing if the audio node is not positional.
+ * to be in meters/second. Does nothing if the audio node is not positional.
*
* @param velocity The velocity to set.
* @see AudioNode#setPositional(boolean)
Index: src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java
===================================================================
--- src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java (revision 8529)
+++ src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java (working copy)
@@ -460,6 +462,9 @@
case Pitch:
alSourcef(id, AL_PITCH, src.getPitch());
break;
+ case RolloffFactor:
+ alSourcef(id, AL_ROLLOFF_FACTOR, src.getRolloffFactor());
+ break;
}
}
}
Do people like this and want to add it to JME?
sincerely,
–Robert McIntyre