1/*
2 * Copyright (c) 2009-2010 jMonkeyEngine All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * * Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 *
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29package jme3test.audio;
30
31import com.jme3.app.SimpleApplication;
32import com.jme3.audio.AudioNode;
33import com.jme3.audio.Environment;
34import com.jme3.math.FastMath;
35import com.jme3.math.Vector3f;
36
37public class TestReverb extends SimpleApplication {
38
39  private AudioNode audioSource;
40  private float time = 0;
41  private float nextTime = 1;
42
43  public static void main(String[] args) {
44    TestReverb test = new TestReverb();
45    test.start();
46  }
47
48  @Override
49  public void simpleInitApp() {
50    audioSource = new AudioNode(assetManager, "Sound/Effects/Bang.wav");
51
52    float[] eax = new float[]{15, 38.0f, 0.300f, -1000, -3300, 0,
53      1.49f, 0.54f, 1.00f, -2560, 0.162f, 0.00f, 0.00f, 0.00f,
54      -229, 0.088f, 0.00f, 0.00f, 0.00f, 0.125f, 1.000f, 0.250f,
55      0.000f, -5.0f, 5000.0f, 250.0f, 0.00f, 0x3f};
56    audioRenderer.setEnvironment(new Environment(eax));
57    Environment env = Environment.Cavern;
58    audioRenderer.setEnvironment(env);
59  }
60
61  @Override
62  public void simpleUpdate(float tpf) {
63    time += tpf;
64
65    if (time > nextTime) {
66      Vector3f v = new Vector3f();
67      v.setX(FastMath.nextRandomFloat());
68      v.setY(FastMath.nextRandomFloat());
69      v.setZ(FastMath.nextRandomFloat());
70      v.multLocal(40, 2, 40);
71      v.subtractLocal(20, 1, 20);
72
73      audioSource.setLocalTranslation(v);
74      audioSource.playInstance();
75      time = 0;
76      nextTime = FastMath.nextRandomFloat() * 2 + 0.5f;
77    }
78  }
79}
80