aboutsummaryrefslogtreecommitdiffstats
path: root/unit_tests/src
diff options
context:
space:
mode:
Diffstat (limited to 'unit_tests/src')
-rw-r--r--unit_tests/src/OpenALTest.java153
-rw-r--r--unit_tests/src/Sound3DTest.java8
-rw-r--r--unit_tests/src/net/java/games/joal/ALTest.java16
3 files changed, 96 insertions, 81 deletions
diff --git a/unit_tests/src/OpenALTest.java b/unit_tests/src/OpenALTest.java
index a64653d..37a982d 100644
--- a/unit_tests/src/OpenALTest.java
+++ b/unit_tests/src/OpenALTest.java
@@ -35,6 +35,7 @@ import java.nio.IntBuffer;
import net.java.games.joal.AL;
import net.java.games.joal.ALC;
import net.java.games.joal.ALFactory;
+import net.java.games.joal.OpenALException;
import net.java.games.joal.eax.EAX;
import net.java.games.joal.eax.EAXFactory;
import net.java.games.joal.util.BufferUtils;
@@ -47,79 +48,83 @@ import net.java.games.joal.util.WAVLoader;
*/
public class OpenALTest {
public static void main(String[] args) {
- ALFactory.initialize();
-
- ALC alc = ALFactory.getALC();
- ALC.Device device = alc.alcOpenDevice("DirectSound3D");
- ALC.Context context = alc.alcCreateContext(device, null);
- alc.alcMakeContextCurrent(context);
- AL al = ALFactory.getAL();
- boolean eaxPresent = al.alIsExtensionPresent("EAX2.0");
- System.out.println("EAX present:" + eaxPresent);
- EAX eax = EAXFactory.getEAX();
-
- try {
- int[] buffers = new int[1];
- al.alGenBuffers(1, buffers);
-
- WAVData wd = WAVLoader.loadFromFile("lewiscarroll.wav");
- al.alBufferData(buffers[0], wd.format, wd.data, wd.size, wd.freq);
-
- int[] sources = new int[1];
- al.alGenSources(1, sources);
- al.alSourcei(sources[0], AL.AL_BUFFER, buffers[0]);
- System.out.println(
- "Looping 1: "
- + (al.alGetSourcei(sources[0], AL.AL_LOOPING) == AL.AL_TRUE));
- int[] loopArray = new int[1];
- al.alGetSourcei(sources[0], AL.AL_LOOPING, loopArray);
- System.out.println("Looping 2: " + (loopArray[0] == AL.AL_TRUE));
- int[] loopBuffer = new int[1];
- al.alGetSourcei(sources[0], AL.AL_LOOPING, loopBuffer);
- System.out.println("Looping 3: " + (loopBuffer[0] == AL.AL_TRUE));
-
- if (eaxPresent) {
- IntBuffer env = BufferUtils.newIntBuffer(1);
- env.put(EAX.EAX_ENVIRONMENT_BATHROOM);
- eax.setListenerProperty(
- EAX.DSPROPERTY_EAXLISTENER_ENVIRONMENT,
- env);
- }
-
- al.alSourcePlay(sources[0]);
-
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- }
-
- al.alSource3f(sources[0], AL.AL_POSITION, 2f, 2f, 2f);
-
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- }
-
- al.alListener3f(AL.AL_POSITION, 3f, 3f, 3f);
-
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- }
-
- al.alSource3f(sources[0], AL.AL_POSITION, 0, 0, 0);
-
- try {
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- }
-
- al.alSourceStop(sources[0]);
- al.alDeleteSources(1, sources);
- alc.alcDestroyContext(context);
- alc.alcCloseDevice(device);
- } catch (Exception e) {
- e.printStackTrace();
- }
+ try {
+ ALFactory.initialize();
+
+ ALC alc = ALFactory.getALC();
+ ALC.Device device = alc.alcOpenDevice("DirectSound3D");
+ ALC.Context context = alc.alcCreateContext(device, null);
+ alc.alcMakeContextCurrent(context);
+ AL al = ALFactory.getAL();
+ boolean eaxPresent = al.alIsExtensionPresent("EAX2.0");
+ System.out.println("EAX present:" + eaxPresent);
+ EAX eax = EAXFactory.getEAX();
+
+ try {
+ int[] buffers = new int[1];
+ al.alGenBuffers(1, buffers);
+
+ WAVData wd = WAVLoader.loadFromFile("lewiscarroll.wav");
+ al.alBufferData(buffers[0], wd.format, wd.data, wd.size, wd.freq);
+
+ int[] sources = new int[1];
+ al.alGenSources(1, sources);
+ al.alSourcei(sources[0], AL.AL_BUFFER, buffers[0]);
+ System.out.println(
+ "Looping 1: "
+ + (al.alGetSourcei(sources[0], AL.AL_LOOPING) == AL.AL_TRUE));
+ int[] loopArray = new int[1];
+ al.alGetSourcei(sources[0], AL.AL_LOOPING, loopArray);
+ System.out.println("Looping 2: " + (loopArray[0] == AL.AL_TRUE));
+ int[] loopBuffer = new int[1];
+ al.alGetSourcei(sources[0], AL.AL_LOOPING, loopBuffer);
+ System.out.println("Looping 3: " + (loopBuffer[0] == AL.AL_TRUE));
+
+ if (eaxPresent) {
+ IntBuffer env = BufferUtils.newIntBuffer(1);
+ env.put(EAX.EAX_ENVIRONMENT_BATHROOM);
+ eax.setListenerProperty(
+ EAX.DSPROPERTY_EAXLISTENER_ENVIRONMENT,
+ env);
+ }
+
+ al.alSourcePlay(sources[0]);
+
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ }
+
+ al.alSource3f(sources[0], AL.AL_POSITION, 2f, 2f, 2f);
+
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ }
+
+ al.alListener3f(AL.AL_POSITION, 3f, 3f, 3f);
+
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ }
+
+ al.alSource3f(sources[0], AL.AL_POSITION, 0, 0, 0);
+
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ }
+
+ al.alSourceStop(sources[0]);
+ al.alDeleteSources(1, sources);
+ alc.alcDestroyContext(context);
+ alc.alcCloseDevice(device);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } catch (OpenALException e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/unit_tests/src/Sound3DTest.java b/unit_tests/src/Sound3DTest.java
index df697e0..7adbc50 100644
--- a/unit_tests/src/Sound3DTest.java
+++ b/unit_tests/src/Sound3DTest.java
@@ -38,6 +38,7 @@ import net.java.games.sound3d.AudioSystem3D;
import net.java.games.sound3d.Context;
import net.java.games.sound3d.Device;
import net.java.games.sound3d.Listener;
+import net.java.games.sound3d.Sound3DException;
import net.java.games.sound3d.Source;
/**
@@ -53,7 +54,12 @@ public class Sound3DTest {
}
public static void main(String[] args) {
- AudioSystem3D.init();
+ try {
+ AudioSystem3D.init();
+ } catch (Sound3DException e) {
+ e.printStackTrace();
+ return;
+ }
// create the initial context - this can be collapsed into the init.
Device device = AudioSystem3D.openDevice("DirectSound3D");
diff --git a/unit_tests/src/net/java/games/joal/ALTest.java b/unit_tests/src/net/java/games/joal/ALTest.java
index a30068c..51bdf87 100644
--- a/unit_tests/src/net/java/games/joal/ALTest.java
+++ b/unit_tests/src/net/java/games/joal/ALTest.java
@@ -36,12 +36,16 @@ public class ALTest extends TestCase {
}
public void setUp() {
- ALFactory.initialize();
- al = ALFactory.getAL();
- alc = ALFactory.getALC();
- device = alc.alcOpenDevice("DirectSound3D");
- context = alc.alcCreateContext(device, null);
- alc.alcMakeContextCurrent(context);
+ try {
+ ALFactory.initialize();
+ al = ALFactory.getAL();
+ alc = ALFactory.getALC();
+ device = alc.alcOpenDevice("DirectSound3D");
+ context = alc.alcCreateContext(device, null);
+ alc.alcMakeContextCurrent(context);
+ } catch (OpenALException e) {
+ e.printStackTrace();
+ }
}
public void tearDown() {