I’m experiencing a problem where the sound has a crackle in it when when the player is turning their head, the crackle is worse the faster the head is turned. See this video for what I mean:
Originally I was setting the listener location and rotation to the camera’s location and rotation but that seems to be happening automatically so I’ve now removed that
Hmmm… This is weird. Your code also looks fine so far. You could try to use another sound file (maybe another format), just for testing, and see if this noise still occurs.
I’ve tried the built in test sounds Sound/Effects/kick.wav and Sound/Effects/Beep.ogg. Both give the same problem. I’m going to see if I can create a test program that displays the same results
I’m fairly sure this is something to do with my hardware now. Basically the hello audio tutorial displays the effect (but with the sound exchanged for Sound/Effects/Beep.ogg which is more of a continuous tone which displays the effect most strongly. This will crackle if you spin your camera (the jme3-test-data library added for the sound) :
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.audio.AudioNode;
import com.jme3.audio.AudioData.DataType;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
//NOTE! Added the jme3-test-data library over standard libraries
public class Main extends SimpleApplication {
private AudioNode audio_gun;
private AudioNode audio_nature;
private Geometry marker;
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
flyCam.setMoveSpeed(40);
/** just a blue box floating in space */
Box box1 = new Box(1, 1, 1);
marker = new Geometry("Player", box1);
Material mat1 = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Blue);
marker.setMaterial(mat1);
rootNode.attachChild(marker);
initAudio();
}
/** We create two audio nodes. */
private void initAudio() {
/* nature sound - keeps playing in a loop. */
audio_nature = new AudioNode(assetManager, "Sound/Effects/Beep.ogg", DataType.Stream);
audio_nature.setLooping(true);
audio_nature.setPositional(true);
audio_nature.setVolume(1);
rootNode.attachChild(audio_nature);
audio_nature.play(); // play continuously!
}
/** Move the listener with the a camera - for 3D audio. */
@Override
public void simpleUpdate(float tpf) {
listener.setLocation(cam.getLocation());
listener.setRotation(cam.getRotation());
}
}
I’m assuming this doesn’t crackle for anyone but me
This is what my device manger says about my sound card, it seems oddly generic
I ran your code and observed audio noise when I rotate the camera. I wouldn’t describe it as a “crackle” – more like a brief pulse of low-frequency buzz, but it’s likely the same issue. So perhaps it’s not specific to your hardware.