import javax.sound.sampled.*; import javax.sound.sampled.spi.*; import com.sun.media.sound.*; // Create the audio format for the sound file AudioFormat format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 44100, 16, 2, 4, 44100, false); // Create the audio input stream for the sound file AudioInputStream stream = AudioSystem.getAudioInputStream(new File("soundfile.wav")); // Create the clip for the sound file DataLine.Info info = new DataLine.Info(Clip.class, format); Clip clip = (Clip) AudioSystem.getLine(info); clip.open(stream); // Create the 3D audio environment Mixer mixer = AudioSystem.getMixer(null); JavaSoundMixer soundMixer = (JavaSoundMixer) mixer; JavaSoundAudioIO io = new JavaSoundAudioIO(soundMixer); JavaSound3DL2 jl2 = new JavaSound3DL2(io); jl2.initialize(); jl2.setEnable(true); // Create the sound source Point3f position = new Point3f(0.0f, 0.0f, 0.0f); Vector3f velocity = new Vector3f(0.0f, 0.0f, 0.0f); Point3f attenuation = new Point3f(1.0f, 0.0f, 0.0f); JavaSound3DL2Source source = jl2.createSource(clip, position, velocity, attenuation); // Set the listener position and orientation Point3f listenerPos = new Point3f(0.0f, 0.0f, 0.0f); Vector3f listenerOrientation = new Vector3f(0.0f, 0.0f, -1.0f); jl2.setListener(listenerPos, listenerOrientation); // Play the sound clip.start();