rlm@0
|
1 package com.aurellem.capture.hello;
|
rlm@0
|
2
|
rlm@0
|
3 import java.io.File;
|
rlm@0
|
4
|
rlm@4
|
5 import com.aurellem.capture.IsoTimer;
|
rlm@9
|
6 import com.aurellem.capture.audio.MultiListener;
|
rlm@9
|
7 import com.aurellem.capture.audio.WaveFileWriter;
|
rlm@0
|
8 import com.jme3.app.SimpleApplication;
|
rlm@0
|
9 import com.jme3.audio.AudioNode;
|
rlm@0
|
10 import com.jme3.audio.Listener;
|
rlm@0
|
11 import com.jme3.input.controls.ActionListener;
|
rlm@0
|
12 import com.jme3.input.controls.MouseButtonTrigger;
|
rlm@0
|
13 import com.jme3.material.Material;
|
rlm@0
|
14 import com.jme3.math.ColorRGBA;
|
rlm@0
|
15 import com.jme3.math.Quaternion;
|
rlm@0
|
16 import com.jme3.math.Vector3f;
|
rlm@0
|
17 import com.jme3.scene.Geometry;
|
rlm@0
|
18 import com.jme3.scene.shape.Box;
|
rlm@0
|
19 import com.jme3.system.AppSettings;
|
rlm@0
|
20
|
rlm@0
|
21 /** Sample 11 - playing 3D audio. */
|
rlm@0
|
22 public class HelloAudio extends SimpleApplication {
|
rlm@0
|
23
|
rlm@0
|
24 private AudioNode audio_gun;
|
rlm@0
|
25 private AudioNode audio_nature;
|
rlm@0
|
26 private Geometry player;
|
rlm@0
|
27 private Listener auxListener = new Listener();
|
rlm@0
|
28 public File data1 = new File("/home/r/tmp/data1.wav");
|
rlm@0
|
29 public File data2 = new File("/home/r/tmp/data2.wav");
|
rlm@0
|
30 public File data3 = new File("/home/r/tmp/data3.wav");
|
rlm@9
|
31
|
rlm@0
|
32 private File makeTarget(int n){
|
rlm@0
|
33 return new File("/home/r/tmp/assload-" + n + ".wav");
|
rlm@0
|
34 }
|
rlm@0
|
35
|
rlm@0
|
36
|
rlm@0
|
37 public static void main(String[] args) {
|
rlm@0
|
38
|
rlm@0
|
39 // Logger.getLogger("com.jme3").setLevel(Level.OFF);
|
rlm@0
|
40
|
rlm@0
|
41 HelloAudio app = new HelloAudio();
|
rlm@0
|
42 AppSettings settings = new AppSettings(true);
|
rlm@9
|
43
|
rlm@0
|
44 settings.setAudioRenderer("Send");
|
rlm@0
|
45 app.setSettings(settings);
|
rlm@0
|
46 app.setShowSettings(false);
|
rlm@0
|
47 app.start();
|
rlm@0
|
48 app.setPauseOnLostFocus(false);
|
rlm@0
|
49 }
|
rlm@0
|
50
|
rlm@0
|
51 @Override
|
rlm@0
|
52 public void simpleInitApp() {
|
rlm@0
|
53 this.setTimer(new IsoTimer(60));
|
rlm@0
|
54
|
rlm@0
|
55
|
rlm@0
|
56 if (this.audioRenderer instanceof MultiListener){
|
rlm@0
|
57 MultiListener rf = (MultiListener)this.audioRenderer;
|
rlm@0
|
58
|
rlm@0
|
59 for (int n = 0; n < 0; n++){
|
rlm@0
|
60 Listener zzz = new Listener();
|
rlm@0
|
61 rf.addListener(zzz);
|
rlm@0
|
62 rf.registerSoundProcessor(
|
rlm@0
|
63 zzz, new WaveFileWriter(makeTarget(n)));
|
rlm@0
|
64 }
|
rlm@0
|
65 Listener listener3 = new Listener();
|
rlm@0
|
66 rf.addListener(auxListener);
|
rlm@0
|
67 rf.addListener(listener3);
|
rlm@0
|
68 rf.registerSoundProcessor(new WaveFileWriter(data1));
|
rlm@0
|
69 rf.registerSoundProcessor(auxListener, new WaveFileWriter(data2));
|
rlm@0
|
70 rf.registerSoundProcessor(listener3, new WaveFileWriter(data3));
|
rlm@0
|
71 }
|
rlm@0
|
72 flyCam.setMoveSpeed(40);
|
rlm@0
|
73
|
rlm@0
|
74 /** just a blue box floating in space */
|
rlm@0
|
75 Box box1 = new Box(Vector3f.ZERO, 1, 1, 1);
|
rlm@0
|
76 player = new Geometry("Player", box1);
|
rlm@0
|
77 Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
rlm@0
|
78 mat1.setColor("Color", ColorRGBA.Blue);
|
rlm@0
|
79 player.setMaterial(mat1);
|
rlm@0
|
80 rootNode.attachChild(player);
|
rlm@0
|
81
|
rlm@0
|
82 /** custom init methods, see below */
|
rlm@0
|
83 initKeys();
|
rlm@0
|
84 initAudio();
|
rlm@0
|
85
|
rlm@0
|
86 this.audioRenderer.playSource(audio_gun);
|
rlm@0
|
87
|
rlm@0
|
88
|
rlm@0
|
89
|
rlm@0
|
90 }
|
rlm@0
|
91
|
rlm@0
|
92 /** We create two audio nodes. */
|
rlm@0
|
93 private void initAudio() {
|
rlm@0
|
94 //audioRenderer.setEnvironment(Environment.Cavern);
|
rlm@0
|
95 /* gun shot sound is to be triggered by a mouse click. */
|
rlm@8
|
96 audio_gun = new AudioNode(audioRenderer, assetManager, "Sound/Effects/Gun.wav", false);
|
rlm@8
|
97 //audio_gun = new AudioNode(assetManager, "Sound/Effects/dream.wav", false, false);
|
rlm@0
|
98 audio_gun.setLooping(false);
|
rlm@0
|
99 audio_gun.setVolume(2);
|
rlm@0
|
100 audio_gun.setPositional(true);
|
rlm@0
|
101
|
rlm@0
|
102
|
rlm@0
|
103 /* nature sound - keeps playing in a loop. */
|
rlm@0
|
104 audio_nature = new AudioNode(assetManager, "Sound/Environment/Nature.ogg", false, false);
|
rlm@0
|
105 audio_nature.setLooping(true);
|
rlm@0
|
106 audio_nature.setPositional(true);
|
rlm@0
|
107 audio_nature.setLocalTranslation(Vector3f.ZERO.clone());
|
rlm@0
|
108 audio_nature.setVolume(3);
|
rlm@0
|
109 audio_nature.updateGeometricState();
|
rlm@0
|
110 }
|
rlm@0
|
111
|
rlm@0
|
112 /** Declaring the "Shoot" action, and
|
rlm@0
|
113 * mapping it to a trigger (mouse click). */
|
rlm@0
|
114 private void initKeys() {
|
rlm@0
|
115 inputManager.addMapping("Shoot", new MouseButtonTrigger(0));
|
rlm@0
|
116 inputManager.addListener(actionListener, "Shoot");
|
rlm@0
|
117 }
|
rlm@0
|
118
|
rlm@0
|
119 /** Defining the "Shoot" action: Play a gun sound. */
|
rlm@0
|
120 private ActionListener actionListener = new ActionListener() {
|
rlm@0
|
121 @Override
|
rlm@0
|
122 public void onAction(String name, boolean keyPressed, float tpf) {
|
rlm@0
|
123 if (name.equals("Shoot") && !keyPressed) {
|
rlm@0
|
124 audioRenderer.playSource(audio_gun); // play once!
|
rlm@0
|
125 }
|
rlm@0
|
126 }
|
rlm@0
|
127 };
|
rlm@0
|
128
|
rlm@0
|
129 /** Move the listener with the camera - for 3D audio. */
|
rlm@0
|
130 @Override
|
rlm@0
|
131 public void simpleUpdate(float tpf) {
|
rlm@0
|
132 Vector3f loc = cam.getLocation();
|
rlm@0
|
133 Quaternion rot = cam.getRotation();
|
rlm@0
|
134 listener.setLocation(loc);
|
rlm@0
|
135 listener.setRotation(rot);
|
rlm@0
|
136 auxListener.setLocation(loc);
|
rlm@0
|
137 auxListener.setRotation(rot);
|
rlm@9
|
138 if (audio_gun.getStatus() == AudioNode.Status.Stopped){
|
rlm@9
|
139 System.out.println("I'm Stopped!");
|
rlm@9
|
140 this.requestClose(false);
|
rlm@9
|
141 }
|
rlm@9
|
142
|
rlm@9
|
143
|
rlm@0
|
144 }
|
rlm@0
|
145
|
rlm@0
|
146 }
|