Audio tests: Using play() and playInstance() on AudioNodes instead of 'deprecated' playSource() on AudioRenderer.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8150 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
1acd324d02
commit
26f2fe8c8d
@ -31,7 +31,11 @@ package jme3test.audio;
|
|||||||
import com.jme3.app.SimpleApplication;
|
import com.jme3.app.SimpleApplication;
|
||||||
import com.jme3.audio.AudioNode;
|
import com.jme3.audio.AudioNode;
|
||||||
import com.jme3.audio.Environment;
|
import com.jme3.audio.Environment;
|
||||||
|
import com.jme3.material.Material;
|
||||||
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
|
import com.jme3.scene.Geometry;
|
||||||
|
import com.jme3.scene.shape.Box;
|
||||||
|
|
||||||
public class TestAmbient extends SimpleApplication {
|
public class TestAmbient extends SimpleApplication {
|
||||||
|
|
||||||
@ -53,14 +57,24 @@ public class TestAmbient extends SimpleApplication {
|
|||||||
|
|
||||||
waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
|
waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
|
||||||
waves.setPositional(true);
|
waves.setPositional(true);
|
||||||
waves.setLocalTranslation(new Vector3f(4, -1, 30));
|
waves.setLocalTranslation(new Vector3f(0, 0,0));
|
||||||
waves.setMaxDistance(5);
|
waves.setMaxDistance(100);
|
||||||
waves.setRefDistance(1);
|
waves.setRefDistance(5);
|
||||||
|
|
||||||
nature = new AudioNode(assetManager, "Sound/Environment/River.ogg", true);
|
nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", true);
|
||||||
nature.setVolume(3);
|
nature.setVolume(3);
|
||||||
audioRenderer.playSourceInstance(waves);
|
|
||||||
audioRenderer.playSource(nature);
|
waves.playInstance();
|
||||||
|
nature.play();
|
||||||
|
|
||||||
|
// just a blue box to mark the spot
|
||||||
|
Box box1 = new Box(Vector3f.ZERO, .5f, .5f, .5f);
|
||||||
|
Geometry player = new Geometry("Player", box1);
|
||||||
|
Material mat1 = new Material(assetManager,
|
||||||
|
"Common/MatDefs/Misc/Unshaded.j3md");
|
||||||
|
mat1.setColor("Color", ColorRGBA.Blue);
|
||||||
|
player.setMaterial(mat1);
|
||||||
|
rootNode.attachChild(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -69,7 +69,7 @@ public class TestDoppler extends SimpleApplication {
|
|||||||
ufo.setReverbEnabled(true);
|
ufo.setReverbEnabled(true);
|
||||||
ufo.setRefDistance(100000000);
|
ufo.setRefDistance(100000000);
|
||||||
ufo.setMaxDistance(100000000);
|
ufo.setMaxDistance(100000000);
|
||||||
audioRenderer.playSource(ufo);
|
ufo.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -197,7 +197,7 @@ public class TestMusicPlayer extends javax.swing.JFrame {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
musicSource = new AudioNode(ar, musicData, key);
|
musicSource = new AudioNode(musicData, key);
|
||||||
musicLength = musicData.getDuration();
|
musicLength = musicData.getDuration();
|
||||||
updateTime();
|
updateTime();
|
||||||
}
|
}
|
||||||
@ -229,7 +229,7 @@ public class TestMusicPlayer extends javax.swing.JFrame {
|
|||||||
ar.pauseSource(musicSource);
|
ar.pauseSource(musicSource);
|
||||||
}else{
|
}else{
|
||||||
musicSource.setPitch(1);
|
musicSource.setPitch(1);
|
||||||
ar.playSource(musicSource);
|
musicSource.play();
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_btnPlayActionPerformed
|
}//GEN-LAST:event_btnPlayActionPerformed
|
||||||
|
|
||||||
@ -263,8 +263,8 @@ public class TestMusicPlayer extends javax.swing.JFrame {
|
|||||||
|
|
||||||
musicSource.setTimeOffset(curTime);
|
musicSource.setTimeOffset(curTime);
|
||||||
if (musicSource.getStatus() == Status.Playing){
|
if (musicSource.getStatus() == Status.Playing){
|
||||||
ar.stopSource(musicSource);
|
musicSource.stop();
|
||||||
ar.playSource(musicSource);
|
musicSource.play();
|
||||||
}
|
}
|
||||||
updateTime();
|
updateTime();
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ public class TestMusicStreaming extends SimpleApplication {
|
|||||||
@Override
|
@Override
|
||||||
public void simpleInitApp(){
|
public void simpleInitApp(){
|
||||||
assetManager.registerLocator("http://www.vorbis.com/music/", UrlLocator.class);
|
assetManager.registerLocator("http://www.vorbis.com/music/", UrlLocator.class);
|
||||||
AudioNode src = new AudioNode(assetManager, "Lumme-Badloop.ogg", true);
|
AudioNode audioSource = new AudioNode(assetManager, "Lumme-Badloop.ogg", true);
|
||||||
audioRenderer.playSource(src);
|
audioSource.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,7 +38,7 @@ import com.jme3.audio.LowPassFilter;
|
|||||||
|
|
||||||
public class TestOgg extends SimpleApplication {
|
public class TestOgg extends SimpleApplication {
|
||||||
|
|
||||||
private AudioNode src;
|
private AudioNode audioSource;
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static void main(String[] args){
|
||||||
TestOgg test = new TestOgg();
|
TestOgg test = new TestOgg();
|
||||||
@ -48,20 +48,20 @@ public class TestOgg extends SimpleApplication {
|
|||||||
@Override
|
@Override
|
||||||
public void simpleInitApp(){
|
public void simpleInitApp(){
|
||||||
System.out.println("Playing without filter");
|
System.out.println("Playing without filter");
|
||||||
src = new AudioNode(assetManager, "Sound/Effects/Foot steps.ogg", true);
|
audioSource = new AudioNode(assetManager, "Sound/Effects/Foot steps.ogg", true);
|
||||||
audioRenderer.playSource(src);
|
audioSource.play();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf){
|
public void simpleUpdate(float tpf){
|
||||||
if (src.getStatus() != AudioNode.Status.Playing){
|
if (audioSource.getStatus() != AudioNode.Status.Playing){
|
||||||
audioRenderer.deleteAudioData(src.getAudioData());
|
audioRenderer.deleteAudioData(audioSource.getAudioData());
|
||||||
|
|
||||||
System.out.println("Playing with low pass filter");
|
System.out.println("Playing with low pass filter");
|
||||||
src = new AudioNode(assetManager, "Sound/Effects/Foot steps.ogg", true);
|
audioSource = new AudioNode(assetManager, "Sound/Effects/Foot steps.ogg", true);
|
||||||
src.setDryFilter(new LowPassFilter(1f, .1f));
|
audioSource.setDryFilter(new LowPassFilter(1f, .1f));
|
||||||
src.setVolume(3);
|
audioSource.setVolume(3);
|
||||||
audioRenderer.playSource(src);
|
audioSource.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ import com.jme3.math.Vector3f;
|
|||||||
|
|
||||||
public class TestReverb extends SimpleApplication {
|
public class TestReverb extends SimpleApplication {
|
||||||
|
|
||||||
private AudioNode src;
|
private AudioNode audioSource;
|
||||||
private float time = 0;
|
private float time = 0;
|
||||||
private float nextTime = 1;
|
private float nextTime = 1;
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public class TestReverb extends SimpleApplication {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
src = new AudioNode(assetManager, "Sound/Effects/Bang.wav");
|
audioSource = new AudioNode(assetManager, "Sound/Effects/Bang.wav");
|
||||||
|
|
||||||
float[] eax = new float[]{15, 38.0f, 0.300f, -1000, -3300, 0,
|
float[] eax = new float[]{15, 38.0f, 0.300f, -1000, -3300, 0,
|
||||||
1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f, 0.00f,
|
1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f, 0.00f,
|
||||||
@ -70,8 +70,8 @@ public class TestReverb extends SimpleApplication {
|
|||||||
v.multLocal(40, 2, 40);
|
v.multLocal(40, 2, 40);
|
||||||
v.subtractLocal(20, 1, 20);
|
v.subtractLocal(20, 1, 20);
|
||||||
|
|
||||||
src.setLocalTranslation(v);
|
audioSource.setLocalTranslation(v);
|
||||||
audioRenderer.playSourceInstance(src);
|
audioSource.playInstance();
|
||||||
time = 0;
|
time = 0;
|
||||||
nextTime = FastMath.nextRandomFloat() * 2 + 0.5f;
|
nextTime = FastMath.nextRandomFloat() * 2 + 0.5f;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ import com.jme3.audio.AudioNode;
|
|||||||
public class TestWav extends SimpleApplication {
|
public class TestWav extends SimpleApplication {
|
||||||
|
|
||||||
private float time = 0;
|
private float time = 0;
|
||||||
private AudioNode src;
|
private AudioNode audioSource;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
TestWav test = new TestWav();
|
TestWav test = new TestWav();
|
||||||
@ -46,7 +46,7 @@ public class TestWav extends SimpleApplication {
|
|||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
time += tpf;
|
time += tpf;
|
||||||
if (time > 1f) {
|
if (time > 1f) {
|
||||||
audioRenderer.playSourceInstance(src);
|
audioSource.playInstance();
|
||||||
time = 0;
|
time = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ public class TestWav extends SimpleApplication {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
src = new AudioNode(assetManager, "Sound/Effects/Gun.wav", false);
|
audioSource = new AudioNode(assetManager, "Sound/Effects/Gun.wav", false);
|
||||||
src.setLooping(false);
|
audioSource.setLooping(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user